drivers: hmc5883l: update to new GPIO API

This commit updates the HMC5883L driver to use the new GPIO API.

Also add a note explicitly describing the active state of the DRDY
pin in the binding file.

Tested on frdm_k64f.

Signed-off-by: Kevin Townsend <kevin@ktownsend.com>
This commit is contained in:
Kevin Townsend 2020-01-06 15:19:32 +01:00 committed by Carles Cufí
commit f800c7266e
3 changed files with 23 additions and 13 deletions

View file

@ -23,8 +23,9 @@ int hmc5883l_trigger_set(struct device *dev,
__ASSERT_NO_MSG(trig->type == SENSOR_TRIG_DATA_READY); __ASSERT_NO_MSG(trig->type == SENSOR_TRIG_DATA_READY);
gpio_pin_disable_callback(drv_data->gpio, gpio_pin_interrupt_configure(drv_data->gpio,
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN); DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN,
GPIO_INT_DISABLE);
drv_data->data_ready_handler = handler; drv_data->data_ready_handler = handler;
if (handler == NULL) { if (handler == NULL) {
@ -33,8 +34,9 @@ int hmc5883l_trigger_set(struct device *dev,
drv_data->data_ready_trigger = *trig; drv_data->data_ready_trigger = *trig;
gpio_pin_enable_callback(drv_data->gpio, gpio_pin_interrupt_configure(drv_data->gpio,
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN); DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN,
GPIO_INT_EDGE_TO_ACTIVE);
return 0; return 0;
} }
@ -47,8 +49,9 @@ static void hmc5883l_gpio_callback(struct device *dev,
ARG_UNUSED(pins); ARG_UNUSED(pins);
gpio_pin_disable_callback(dev, gpio_pin_interrupt_configure(dev,
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN); DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN,
GPIO_INT_DISABLE);
#if defined(CONFIG_HMC5883L_TRIGGER_OWN_THREAD) #if defined(CONFIG_HMC5883L_TRIGGER_OWN_THREAD)
k_sem_give(&drv_data->gpio_sem); k_sem_give(&drv_data->gpio_sem);
@ -67,8 +70,9 @@ static void hmc5883l_thread_cb(void *arg)
&drv_data->data_ready_trigger); &drv_data->data_ready_trigger);
} }
gpio_pin_enable_callback(drv_data->gpio, gpio_pin_interrupt_configure(drv_data->gpio,
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN); DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN,
GPIO_INT_EDGE_TO_ACTIVE);
} }
#ifdef CONFIG_HMC5883L_TRIGGER_OWN_THREAD #ifdef CONFIG_HMC5883L_TRIGGER_OWN_THREAD
@ -111,8 +115,8 @@ int hmc5883l_init_interrupt(struct device *dev)
gpio_pin_configure(drv_data->gpio, gpio_pin_configure(drv_data->gpio,
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN, DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN,
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE | GPIO_INPUT |
GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE); DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_FLAGS);
gpio_init_callback(&drv_data->gpio_cb, gpio_init_callback(&drv_data->gpio_cb,
hmc5883l_gpio_callback, hmc5883l_gpio_callback,
@ -136,8 +140,9 @@ int hmc5883l_init_interrupt(struct device *dev)
drv_data->dev = dev; drv_data->dev = dev;
#endif #endif
gpio_pin_enable_callback(drv_data->gpio, gpio_pin_interrupt_configure(drv_data->gpio,
DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN); DT_INST_0_HONEYWELL_HMC5883L_INT_GPIOS_PIN,
GPIO_INT_EDGE_TO_ACTIVE);
return 0; return 0;
} }

View file

@ -11,3 +11,8 @@ properties:
int-gpios: int-gpios:
type: phandle-array type: phandle-array
required: false required: false
description: DRDY pin
This pin is active low, with an internal pullup in the sensor.
The property value should ensure the flags properly describe
the signal that is presented to the driver.

View file

@ -8,7 +8,7 @@
hmc5883l@1e { hmc5883l@1e {
compatible = "honeywell,hmc5883l"; compatible = "honeywell,hmc5883l";
reg = <0x1E>; reg = <0x1E>;
int-gpios = <&gpioc 12 0>; int-gpios = <&gpioc 12 GPIO_ACTIVE_LOW>;
label = "HMC5883L"; label = "HMC5883L";
}; };
}; };