drivers: sensor: Convert fxos8700 to new gpio api

Converts the fxos8700 sensor driver to the new gpio api. Updates device
trees for all boards with this sensor to active low gpio interrupts by
default.

Tested on frdm_k64f and rv32m1_vega_ri5cy boards. The latter verifies
that the reset output works correctly.

Signed-off-by: Maureen Helm <maureen.helm@nxp.com>
This commit is contained in:
Maureen Helm 2019-12-11 15:14:11 -06:00 committed by Carles Cufí
commit cadbc96d66
17 changed files with 53 additions and 31 deletions

View file

@ -71,8 +71,8 @@
status = "okay";
reg = <0x1d>;
label = "MMA8653FC";
int1-gpios = <&gpio0 28 0>;
int2-gpios = <&gpio0 27 0>;
int1-gpios = <&gpio0 28 GPIO_ACTIVE_LOW>;
int2-gpios = <&gpio0 27 GPIO_ACTIVE_LOW>;
};
/* v1.5 variant 1 LSM303AGR */

View file

@ -98,8 +98,8 @@
compatible = "nxp,fxos8700";
reg = <0x1d>;
label = "FXOS8700";
int1-gpios = <&gpiod 0 0>;
int2-gpios = <&gpiod 1 0>;
int1-gpios = <&gpiod 0 GPIO_ACTIVE_LOW>;
int2-gpios = <&gpiod 1 GPIO_ACTIVE_LOW>;
};
};

View file

@ -115,8 +115,8 @@ arduino_i2c: &i2c0 {
compatible = "nxp,fxos8700";
reg = <0x1d>;
label = "FXOS8700";
int1-gpios = <&gpioc 6 0>;
int2-gpios = <&gpioc 13 0>;
int1-gpios = <&gpioc 6 GPIO_ACTIVE_LOW>;
int2-gpios = <&gpioc 13 GPIO_ACTIVE_LOW>;
};
};

View file

@ -146,7 +146,7 @@
compatible = "nxp,fxos8700";
reg = <0x1c>;
label = "FXOS8700";
int1-gpios = <&gpioc 13 0>;
int1-gpios = <&gpioc 13 GPIO_ACTIVE_LOW>;
};
};

View file

@ -95,8 +95,8 @@
compatible = "nxp,fxos8700","nxp,mma8451q";
reg = <0x1d>;
label = "MMA8451Q";
int1-gpios = <&gpioa 14 0>;
int2-gpios = <&gpioa 15 0>;
int1-gpios = <&gpioa 14 GPIO_ACTIVE_LOW>;
int2-gpios = <&gpioa 15 GPIO_ACTIVE_LOW>;
};
};

View file

@ -91,7 +91,7 @@
compatible = "nxp,fxos8700";
reg = <0x1f>;
label = "FXOS8700";
int1-gpios = <&gpioc 1 0>;
int1-gpios = <&gpioc 1 GPIO_ACTIVE_LOW>;
};
};

View file

@ -92,8 +92,8 @@
compatible = "nxp,fxos8700";
reg = <0x1e>;
label = "FXOS8700";
int1-gpios = <&gpioc 1 0>;
int2-gpios = <&gpiod 13 0>;
int1-gpios = <&gpioc 1 GPIO_ACTIVE_LOW>;
int2-gpios = <&gpiod 13 GPIO_ACTIVE_LOW>;
};
fxas21002@20 {

View file

@ -117,8 +117,8 @@ arduino_serial: &uart3 {};
* Note that if you populate them, they conflict with LCD and
* Ethernet interrupt gpios.
*/
int1-gpios = <&gpio1 10 0>;
int2-gpios = <&gpio1 11 0>;
int1-gpios = <&gpio1 10 GPIO_ACTIVE_LOW>;
int2-gpios = <&gpio1 11 GPIO_ACTIVE_LOW>;
};
ft5336@38 {

View file

@ -124,8 +124,8 @@ arduino_i2c: &i2c0 {
compatible = "nxp,fxos8700","nxp,mma8652fc";
reg = <0x1d>;
label = "MMA8652FC";
int1-gpios = <&gpio0 24 0>;
int2-gpios = <&gpio0 25 0>;
int1-gpios = <&gpio0 24 GPIO_ACTIVE_LOW>;
int2-gpios = <&gpio0 25 GPIO_ACTIVE_LOW>;
};
ti_hdc@43 {

View file

@ -175,7 +175,7 @@
compatible = "nxp,fxos8700";
reg = <0x1d>;
label = "FXOS8700";
reset-gpios = <&gpioc 15 0>;
reset-gpios = <&gpioc 15 GPIO_ACTIVE_HIGH>;
};
};

View file

@ -113,8 +113,8 @@
compatible = "nxp,fxos8700";
reg = <0x1c>;
label = "FXOS8700";
int1-gpios = <&gpioc 18 0>;
int2-gpios = <&gpioc 19 0>;
int1-gpios = <&gpioc 18 GPIO_ACTIVE_LOW>;
int2-gpios = <&gpioc 19 GPIO_ACTIVE_LOW>;
};
};

View file

@ -55,7 +55,7 @@
compatible = "nxp,fxos8700";
reg = <0x1e>;
label = "FXOS8700";
int1-gpios = <&gpio7 0 0>;
int1-gpios = <&gpio7 0 GPIO_ACTIVE_LOW>;
};
fxas21002@20 {

View file

@ -125,9 +125,9 @@ arduino_i2c: &i2c0 {
compatible = "nxp,fxos8700";
reg = <0x1e>;
label = "FXOS8700";
reset-gpios = <&gpioe 27 0>;
int1-gpios = <&gpioe 1 0>;
int2-gpios = <&gpioe 22 0>;
reset-gpios = <&gpioe 27 GPIO_ACTIVE_HIGH>;
int1-gpios = <&gpioe 1 GPIO_ACTIVE_LOW>;
int2-gpios = <&gpioe 22 GPIO_ACTIVE_LOW>;
};
};

View file

@ -390,14 +390,16 @@ static int fxos8700_init(struct device *dev)
return -EINVAL;
}
gpio_pin_configure(rst, config->reset_pin, GPIO_DIR_OUT);
gpio_pin_write(rst, config->reset_pin, 1);
gpio_pin_configure(rst, config->reset_pin,
GPIO_OUTPUT_INACTIVE | config->reset_flags);
gpio_pin_set(rst, config->reset_pin, 1);
/* The datasheet does not mention how long to pulse
* the RST pin high in order to reset. Stay on the
* safe side and pulse for 1 millisecond.
*/
k_busy_wait(USEC_PER_MSEC);
gpio_pin_write(rst, config->reset_pin, 0);
gpio_pin_set(rst, config->reset_pin, 0);
} else {
/* Software reset the sensor. Upon issuing a software
* reset command over the I2C interface, the sensor
@ -524,9 +526,11 @@ static const struct fxos8700_config fxos8700_config = {
#ifdef DT_INST_0_NXP_FXOS8700_RESET_GPIOS_CONTROLLER
.reset_name = DT_INST_0_NXP_FXOS8700_RESET_GPIOS_CONTROLLER,
.reset_pin = DT_INST_0_NXP_FXOS8700_RESET_GPIOS_PIN,
.reset_flags = DT_INST_0_NXP_FXOS8700_RESET_GPIOS_FLAGS,
#else
.reset_name = NULL,
.reset_pin = 0,
.reset_flags = 0,
#endif
#ifdef CONFIG_FXOS8700_MODE_ACCEL
.mode = FXOS8700_MODE_ACCEL,
@ -564,9 +568,11 @@ static const struct fxos8700_config fxos8700_config = {
#ifdef CONFIG_FXOS8700_DRDY_INT1
.gpio_name = DT_INST_0_NXP_FXOS8700_INT1_GPIOS_CONTROLLER,
.gpio_pin = DT_INST_0_NXP_FXOS8700_INT1_GPIOS_PIN,
.gpio_flags = DT_INST_0_NXP_FXOS8700_INT1_GPIOS_FLAGS,
#else
.gpio_name = DT_INST_0_NXP_FXOS8700_INT2_GPIOS_CONTROLLER,
.gpio_pin = DT_INST_0_NXP_FXOS8700_INT2_GPIOS_PIN,
.gpio_flags = DT_INST_0_NXP_FXOS8700_INT2_GPIOS_FLAGS,
#endif
#endif
#ifdef CONFIG_FXOS8700_PULSE

View file

@ -124,10 +124,12 @@ struct fxos8700_config {
#ifdef CONFIG_FXOS8700_TRIGGER
char *gpio_name;
u8_t gpio_pin;
gpio_devicetree_flags_t gpio_flags;
#endif
u8_t i2c_address;
char *reset_name;
u8_t reset_pin;
gpio_devicetree_flags_t reset_flags;
enum fxos8700_mode mode;
enum fxos8700_power_mode power_mode;
enum fxos8700_range range;

View file

@ -21,7 +21,8 @@ static void fxos8700_gpio_callback(struct device *dev,
return;
}
gpio_pin_disable_callback(dev, data->gpio_pin);
gpio_pin_interrupt_configure(data->gpio, data->gpio_pin,
GPIO_INT_DISABLE);
#if defined(CONFIG_FXOS8700_TRIGGER_OWN_THREAD)
k_sem_give(&data->trig_sem);
@ -147,7 +148,8 @@ static void fxos8700_handle_int(void *arg)
}
#endif
gpio_pin_enable_callback(data->gpio, config->gpio_pin);
gpio_pin_interrupt_configure(data->gpio, config->gpio_pin,
GPIO_INT_EDGE_TO_ACTIVE);
}
#ifdef CONFIG_FXOS8700_TRIGGER_OWN_THREAD
@ -387,15 +389,15 @@ int fxos8700_trigger_init(struct device *dev)
data->gpio_pin = config->gpio_pin;
gpio_pin_configure(data->gpio, config->gpio_pin,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE);
GPIO_INPUT | config->gpio_flags);
gpio_init_callback(&data->gpio_cb, fxos8700_gpio_callback,
BIT(config->gpio_pin));
gpio_add_callback(data->gpio, &data->gpio_cb);
gpio_pin_enable_callback(data->gpio, config->gpio_pin);
gpio_pin_interrupt_configure(data->gpio, config->gpio_pin,
GPIO_INT_EDGE_TO_ACTIVE);
return 0;
}

View file

@ -11,11 +11,23 @@ properties:
reset-gpios:
type: phandle-array
required: false
description: RST pin
This pin defaults to active high when consumed by the sensor.
The property value should ensure the flags properly describe
the signal that is presented to the driver.
int1-gpios:
type: phandle-array
required: false
description: INT1 pin
This pin defaults to active low when produced by the sensor.
The property value should ensure the flags properly describe
the signal that is presented to the driver.
int2-gpios:
type: phandle-array
required: false
description: INT2 pin
This pin defaults to active low when produced by the sensor.
The property value should ensure the flags properly describe
the signal that is presented to the driver.