Skip to content

Commit 3c976b8

Browse files
committed
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 <[email protected]>
1 parent 31cd5ac commit 3c976b8

File tree

4 files changed

+15
-14
lines changed

4 files changed

+15
-14
lines changed

drivers/sensor/mcp9808/mcp9808_trigger.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,11 @@ static inline void setup_int(struct device *dev,
6262
{
6363
const struct mcp9808_data *data = dev->driver_data;
6464
const struct mcp9808_config *cfg = dev->config->config_info;
65+
unsigned int flags = enable
66+
? GPIO_INT_EDGE_TO_ACTIVE
67+
: GPIO_INT_DISABLE;
6568

66-
if (enable) {
67-
gpio_pin_enable_callback(data->alert_gpio, cfg->alert_pin);
68-
} else {
69-
gpio_pin_disable_callback(data->alert_gpio, cfg->alert_pin);
70-
}
69+
gpio_pin_interrupt_configure(data->alert_gpio, cfg->alert_pin, flags);
7170
}
7271

7372
static void handle_int(struct device *dev)
@@ -110,13 +109,12 @@ int mcp9808_trigger_set(struct device *dev,
110109
data->trigger_handler = handler;
111110

112111
if (handler != NULL) {
113-
u32_t val;
114-
115112
setup_int(dev, true);
116113

117-
rv = gpio_pin_read(data->alert_gpio, cfg->alert_pin, &val);
118-
if ((rv == 0) && (val == 0)) {
114+
rv = gpio_pin_get(data->alert_gpio, cfg->alert_pin);
115+
if (rv > 0) {
119116
handle_int(dev);
117+
rv = 0;
120118
}
121119
}
122120

@@ -196,9 +194,7 @@ int mcp9808_setup_interrupt(struct device *dev)
196194

197195
if (rc == 0) {
198196
rc = gpio_pin_configure(gpio, cfg->alert_pin,
199-
GPIO_DIR_IN | GPIO_INT | GPIO_INT_EDGE |
200-
GPIO_PUD_PULL_UP |
201-
GPIO_INT_ACTIVE_LOW | GPIO_INT_DEBOUNCE);
197+
GPIO_INPUT | cfg->alert_flags);
202198
}
203199

204200
if (rc == 0) {

dts/bindings/sensor/microchip,mcp9808.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,3 +13,8 @@ properties:
1313
int-gpios:
1414
type: phandle-array
1515
required: false
16+
description: |
17+
The alert pin defaults to active low when produced by the
18+
sensor, and is open-drain. A pull-up may be appropriate. The
19+
property value should ensure the flags properly describe the
20+
signal that is presented to the driver.

samples/sensor/mcp9808/boards/frdm_k64f.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
mcp9808@18 {
99
compatible = "microchip,mcp9808";
1010
reg = <0x18>;
11-
int-gpios = <&gpioc 16 0>;
11+
int-gpios = <&gpioc 16 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
1212
label = "MCP9808";
1313
};
1414
};

samples/sensor/mcp9808/boards/particle_xenon.overlay

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
mcp9808@18 {
99
compatible = "microchip,mcp9808";
1010
reg = <0x18>;
11-
int-gpios = <&gpio1 1 0>;
11+
int-gpios = <&gpio1 1 (GPIO_PULL_UP | GPIO_ACTIVE_LOW)>;
1212
label = "MCP9808";
1313
};
1414
};

0 commit comments

Comments
 (0)