Skip to content

Commit 6cff868

Browse files
benjaminbjornssonMaureenHelm
authored andcommitted
drivers: sensor: fdc2x1x: Update driver to use gpio_dt_spec
Simplify driver by using gpio_dt_spec for bus access. Signed-off-by: Benjamin Björnsson <benjamin.bjornsson@gmail.com>
1 parent 9bb7c97 commit 6cff868

File tree

3 files changed

+17
-30
lines changed

3 files changed

+17
-30
lines changed

drivers/sensor/fdc2x1x/fdc2x1x.c

Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -463,7 +463,7 @@ static int fdc2x1x_set_shutdown(const struct device *dev, bool enable)
463463
const struct fdc2x1x_config *cfg = dev->config;
464464
int ret = 0;
465465

466-
gpio_pin_set(cfg->sd_gpio, cfg->sd_pin, enable);
466+
gpio_pin_set_dt(&cfg->sd_gpio, enable);
467467

468468
if (!enable) {
469469
ret = fdc2x1x_restart(dev);
@@ -516,7 +516,7 @@ static int fdc2x1x_device_pm_action(const struct device *dev,
516516

517517
break;
518518
case PM_DEVICE_ACTION_TURN_OFF:
519-
if (cfg->sd_gpio->name) {
519+
if (cfg->sd_gpio->port.name) {
520520
ret = fdc2x1x_set_shutdown(dev, true);
521521
} else {
522522
LOG_ERR("SD pin not defined");
@@ -886,13 +886,12 @@ static int fdc2x1x_init_sd_pin(const struct device *dev)
886886
{
887887
const struct fdc2x1x_config *cfg = dev->config;
888888

889-
if (!device_is_ready(cfg->sd_gpio)) {
890-
LOG_ERR("%s: sd_gpio device not ready", cfg->sd_gpio->name);
889+
if (!device_is_ready(cfg->sd_gpio.port)) {
890+
LOG_ERR("%s: sd_gpio device not ready", cfg->sd_gpio.port->name);
891891
return -ENODEV;
892892
}
893893

894-
gpio_pin_configure(cfg->sd_gpio, cfg->sd_pin,
895-
GPIO_OUTPUT_INACTIVE | cfg->sd_flags);
894+
gpio_pin_configure_dt(&cfg->sd_gpio, GPIO_OUTPUT_INACTIVE);
896895

897896
return 0;
898897
}
@@ -921,7 +920,7 @@ static int fdc2x1x_init(const struct device *dev)
921920
return -EINVAL;
922921
}
923922

924-
if (cfg->sd_gpio->name) {
923+
if (cfg->sd_gpio.port->name) {
925924
if (fdc2x1x_init_sd_pin(dev) < 0) {
926925
return -ENODEV;
927926
}
@@ -959,18 +958,14 @@ static int fdc2x1x_init(const struct device *dev)
959958
}
960959

961960
#define FDC2X1X_SD_PROPS(n) \
962-
.sd_gpio = DEVICE_DT_GET(DT_GPIO_CTLR(DT_DRV_INST(n), sd_gpios)), \
963-
.sd_pin = DT_INST_GPIO_PIN(n, sd_gpios), \
964-
.sd_flags = DT_INST_GPIO_FLAGS(n, sd_gpios), \
961+
.sd_gpio = GPIO_DT_SPEC_INST_GET(n, sd_gpios), \
965962

966963
#define FDC2X1X_SD(n) \
967964
IF_ENABLED(DT_INST_NODE_HAS_PROP(n, sd_gpios), \
968965
(FDC2X1X_SD_PROPS(n)))
969966

970967
#define FDC2X1X_INTB_PROPS(n) \
971-
.intb_gpio = DEVICE_DT_GET(DT_GPIO_CTLR(DT_DRV_INST(n), intb_gpios)), \
972-
.intb_pin = DT_INST_GPIO_PIN(n, intb_gpios), \
973-
.intb_flags = DT_INST_GPIO_FLAGS(n, intb_gpios), \
968+
.intb_gpio = GPIO_DT_SPEC_INST_GET(n, intb_gpios), \
974969

975970
#define FDC2X1X_INTB(n) \
976971
IF_ENABLED(CONFIG_FDC2X1X_TRIGGER, \

drivers/sensor/fdc2x1x/fdc2x1x.h

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -182,15 +182,10 @@ struct fdc2x1x_chx_config {
182182

183183
struct fdc2x1x_config {
184184
struct i2c_dt_spec i2c;
185-
186-
const struct device *sd_gpio;
187-
gpio_pin_t sd_pin;
188-
gpio_dt_flags_t sd_flags;
185+
struct gpio_dt_spec sd_gpio;
189186

190187
#ifdef CONFIG_FDC2X1X_TRIGGER
191-
const struct device *intb_gpio;
192-
gpio_pin_t intb_pin;
193-
gpio_dt_flags_t intb_flags;
188+
struct gpio_dt_spec intb_gpio;
194189
#endif
195190

196191
bool fdc2x14;

drivers/sensor/fdc2x1x/fdc2x1x_trigger.c

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -87,8 +87,7 @@ int fdc2x1x_trigger_set(const struct device *dev,
8787
uint16_t status, int_mask, int_en;
8888
int ret;
8989

90-
gpio_pin_interrupt_configure(cfg->intb_gpio, cfg->intb_pin,
91-
GPIO_INT_DISABLE);
90+
gpio_pin_interrupt_configure_dt(&cfg->intb_gpio, GPIO_INT_DISABLE);
9291

9392
switch (trig->type) {
9493
case SENSOR_TRIG_DATA_READY:
@@ -118,8 +117,7 @@ int fdc2x1x_trigger_set(const struct device *dev,
118117
/* Clear INTB pin by reading STATUS register */
119118
fdc2x1x_get_status(dev, &status);
120119
out:
121-
gpio_pin_interrupt_configure(cfg->intb_gpio, cfg->intb_pin,
122-
GPIO_INT_EDGE_TO_ACTIVE);
120+
gpio_pin_interrupt_configure_dt(&cfg->intb_gpio, GPIO_INT_EDGE_TO_ACTIVE);
123121

124122
return ret;
125123
}
@@ -132,8 +130,8 @@ int fdc2x1x_init_interrupt(const struct device *dev)
132130

133131
k_mutex_init(&drv_data->trigger_mutex);
134132

135-
if (!device_is_ready(cfg->intb_gpio)) {
136-
LOG_ERR("%s: intb_gpio device not ready", cfg->intb_gpio->name);
133+
if (!device_is_ready(cfg->intb_gpio.port)) {
134+
LOG_ERR("%s: intb_gpio device not ready", cfg->intb_gpio.port->name);
137135
return -ENODEV;
138136
}
139137

@@ -142,14 +140,13 @@ int fdc2x1x_init_interrupt(const struct device *dev)
142140
return ret;
143141
}
144142

145-
gpio_pin_configure(cfg->intb_gpio, cfg->intb_pin,
146-
GPIO_INPUT | cfg->intb_flags);
143+
gpio_pin_configure_dt(&cfg->intb_gpio, GPIO_INPUT);
147144

148145
gpio_init_callback(&drv_data->gpio_cb,
149146
fdc2x1x_gpio_callback,
150-
BIT(cfg->intb_pin));
147+
BIT(cfg->intb_gpio.pin));
151148

152-
if (gpio_add_callback(cfg->intb_gpio, &drv_data->gpio_cb) < 0) {
149+
if (gpio_add_callback(cfg->intb_gpio.port, &drv_data->gpio_cb) < 0) {
153150
LOG_ERR("Failed to set gpio callback!");
154151
return -EIO;
155152
}

0 commit comments

Comments
 (0)