From 3c976b8d96e92f6adbe1fbf4fe8004bb367b67c9 Mon Sep 17 00:00:00 2001 From: Peter Bigot Date: Fri, 20 Dec 2019 17:00:01 -0600 Subject: [PATCH] drivers: sensor: mcp9808: update to new GPIO API Since this was converted to the setup/handle/process idiom in master the conversion is straightforward. Signed-off-by: Peter Bigot --- drivers/sensor/mcp9808/mcp9808_trigger.c | 20 ++++++++----------- dts/bindings/sensor/microchip,mcp9808.yaml | 5 +++++ .../sensor/mcp9808/boards/frdm_k64f.overlay | 2 +- .../mcp9808/boards/particle_xenon.overlay | 2 +- 4 files changed, 15 insertions(+), 14 deletions(-) diff --git a/drivers/sensor/mcp9808/mcp9808_trigger.c b/drivers/sensor/mcp9808/mcp9808_trigger.c index 12eaae36c8b5c..53b8dc8198075 100644 --- a/drivers/sensor/mcp9808/mcp9808_trigger.c +++ b/drivers/sensor/mcp9808/mcp9808_trigger.c @@ -62,12 +62,11 @@ static inline void setup_int(struct device *dev, { const struct mcp9808_data *data = dev->driver_data; const struct mcp9808_config *cfg = dev->config->config_info; + unsigned int flags = enable + ? GPIO_INT_EDGE_TO_ACTIVE + : GPIO_INT_DISABLE; - if (enable) { - gpio_pin_enable_callback(data->alert_gpio, cfg->alert_pin); - } else { - gpio_pin_disable_callback(data->alert_gpio, cfg->alert_pin); - } + gpio_pin_interrupt_configure(data->alert_gpio, cfg->alert_pin, flags); } static void handle_int(struct device *dev) @@ -110,13 +109,12 @@ int mcp9808_trigger_set(struct device *dev, data->trigger_handler = handler; if (handler != NULL) { - u32_t val; - setup_int(dev, true); - rv = gpio_pin_read(data->alert_gpio, cfg->alert_pin, &val); - if ((rv == 0) && (val == 0)) { + rv = gpio_pin_get(data->alert_gpio, cfg->alert_pin); + if (rv > 0) { handle_int(dev); + rv = 0; } } @@ -196,9 +194,7 @@ int mcp9808_setup_interrupt(struct device *dev) if (rc == 0) { rc = gpio_pin_configure(gpio, cfg->alert_pin, - GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE | - GPIO_PUD_PULL_UP | - GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE); + GPIO_INPUT | cfg->alert_flags); } if (rc == 0) { diff --git a/dts/bindings/sensor/microchip,mcp9808.yaml b/dts/bindings/sensor/microchip,mcp9808.yaml index 3d377188258d8..6834c89b9fb9d 100644 --- a/dts/bindings/sensor/microchip,mcp9808.yaml +++ b/dts/bindings/sensor/microchip,mcp9808.yaml @@ -13,3 +13,8 @@ properties: int-gpios: type: phandle-array required: false + description: | + The alert pin defaults to active low when produced by the + sensor, and is open-drain. A pull-up may be appropriate. The + property value should ensure the flags properly describe the + signal that is presented to the driver. diff --git a/samples/sensor/mcp9808/boards/frdm_k64f.overlay b/samples/sensor/mcp9808/boards/frdm_k64f.overlay index 6fdcb2a4749e7..ff918e47444e0 100644 --- a/samples/sensor/mcp9808/boards/frdm_k64f.overlay +++ b/samples/sensor/mcp9808/boards/frdm_k64f.overlay @@ -8,7 +8,7 @@ mcp9808@18 { compatible = "microchip,mcp9808"; reg = <0x18>; - int-gpios = <&gpioc 16 0>; + int-gpios = <&gpioc 16 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; label = "MCP9808"; }; }; diff --git a/samples/sensor/mcp9808/boards/particle_xenon.overlay b/samples/sensor/mcp9808/boards/particle_xenon.overlay index 9ce59c08f2f26..12c3d25e662d9 100644 --- a/samples/sensor/mcp9808/boards/particle_xenon.overlay +++ b/samples/sensor/mcp9808/boards/particle_xenon.overlay @@ -8,7 +8,7 @@ mcp9808@18 { compatible = "microchip,mcp9808"; reg = <0x18>; - int-gpios = <&gpio1 1 0>; + int-gpios = <&gpio1 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>; label = "MCP9808"; }; };