Skip to content

Commit ed738ed

Browse files
galakcarlescufi
authored andcommitted
drivers: sensor: ti_hdc: Update driver to use gpio_dt_spec
Move driver to use gpio_dt_spec for DRDY GPIO handling. Signed-off-by: Kumar Gala <[email protected]>
1 parent c738c99 commit ed738ed

File tree

2 files changed

+20
-20
lines changed

2 files changed

+20
-20
lines changed

drivers/sensor/ti_hdc/ti_hdc.c

Lines changed: 16 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,11 @@ static void ti_hdc_gpio_callback(const struct device *dev,
2525
{
2626
struct ti_hdc_data *drv_data =
2727
CONTAINER_OF(cb, struct ti_hdc_data, gpio_cb);
28+
const struct ti_hdc_config *cfg = drv_data->dev->config;
2829

2930
ARG_UNUSED(pins);
3031

31-
gpio_pin_interrupt_configure(drv_data->gpio,
32-
DT_INST_GPIO_PIN(0, drdy_gpios),
33-
GPIO_INT_DISABLE);
32+
gpio_pin_interrupt_configure_dt(&cfg->drdy, GPIO_INT_DISABLE);
3433
k_sem_give(&drv_data->data_sem);
3534
}
3635
#endif
@@ -45,9 +44,7 @@ static int ti_hdc_sample_fetch(const struct device *dev,
4544
__ASSERT_NO_MSG(chan == SENSOR_CHAN_ALL);
4645

4746
#if DT_INST_NODE_HAS_PROP(0, drdy_gpios)
48-
gpio_pin_interrupt_configure(drv_data->gpio,
49-
DT_INST_GPIO_PIN(0, drdy_gpios),
50-
GPIO_INT_EDGE_TO_ACTIVE);
47+
gpio_pin_interrupt_configure_dt(&cfg->drdy, GPIO_INT_EDGE_TO_ACTIVE);
5148
#endif
5249

5350
buf[0] = TI_HDC_REG_TEMP;
@@ -142,32 +139,29 @@ static int ti_hdc_init(const struct device *dev)
142139
#if DT_INST_NODE_HAS_PROP(0, drdy_gpios)
143140
struct ti_hdc_data *drv_data = dev->data;
144141

142+
drv_data->dev = dev;
143+
145144
k_sem_init(&drv_data->data_sem, 0, K_SEM_MAX_LIMIT);
146145

147146
/* setup data ready gpio interrupt */
148-
drv_data->gpio = device_get_binding(
149-
DT_INST_GPIO_LABEL(0, drdy_gpios));
150-
if (drv_data->gpio == NULL) {
151-
LOG_DBG("Failed to get pointer to %s device",
152-
DT_INST_GPIO_LABEL(0, drdy_gpios));
153-
return -EINVAL;
147+
if (!device_is_ready(cfg->drdy.port)) {
148+
LOG_ERR("%s: device %s is not ready", dev->name,
149+
cfg->drdy.port->name);
150+
return -ENODEV;
154151
}
155152

156-
gpio_pin_configure(drv_data->gpio, DT_INST_GPIO_PIN(0, drdy_gpios),
157-
GPIO_INPUT | DT_INST_GPIO_FLAGS(0, drdy_gpios));
153+
gpio_pin_configure_dt(&cfg->drdy, GPIO_INPUT);
158154

159155
gpio_init_callback(&drv_data->gpio_cb,
160156
ti_hdc_gpio_callback,
161-
BIT(DT_INST_GPIO_PIN(0, drdy_gpios)));
157+
BIT(cfg->drdy.pin));
162158

163-
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
159+
if (gpio_add_callback(cfg->drdy.port, &drv_data->gpio_cb) < 0) {
164160
LOG_DBG("Failed to set GPIO callback");
165161
return -EIO;
166162
}
167163

168-
gpio_pin_interrupt_configure(drv_data->gpio,
169-
DT_INST_GPIO_PIN(0, drdy_gpios),
170-
GPIO_INT_EDGE_TO_ACTIVE);
164+
gpio_pin_interrupt_configure_dt(&cfg->drdy, GPIO_INT_EDGE_TO_ACTIVE);
171165
#endif
172166

173167
LOG_INF("Initialized device successfully");
@@ -177,6 +171,9 @@ static int ti_hdc_init(const struct device *dev)
177171

178172
static const struct ti_hdc_config ti_hdc_config = {
179173
.i2c = I2C_DT_SPEC_INST_GET(0),
174+
#if DT_INST_NODE_HAS_PROP(0, drdy_gpios)
175+
.drdy = GPIO_DT_SPEC_INST_GET(0, drdy_gpios),
176+
#endif
180177
};
181178

182179
static struct ti_hdc_data ti_hdc_data;

drivers/sensor/ti_hdc/ti_hdc.h

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,16 +23,19 @@
2323

2424
struct ti_hdc_config {
2525
struct i2c_dt_spec i2c;
26+
#if DT_INST_NODE_HAS_PROP(0, drdy_gpios)
27+
struct gpio_dt_spec drdy;
28+
#endif
2629
};
2730

2831
struct ti_hdc_data {
2932
uint16_t t_sample;
3033
uint16_t rh_sample;
3134

3235
#if DT_INST_NODE_HAS_PROP(0, drdy_gpios)
33-
const struct device *gpio;
3436
struct gpio_callback gpio_cb;
3537
struct k_sem data_sem;
38+
const struct device *dev;
3639
#endif /* DT_INST_NODE_HAS_PROP(0, drdy_gpios) */
3740
};
3841

0 commit comments

Comments
 (0)