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>
This commit is contained in:
parent
9bb7c9771f
commit
6cff868c70
3 changed files with 17 additions and 30 deletions
|
@ -463,7 +463,7 @@ static int fdc2x1x_set_shutdown(const struct device *dev, bool enable)
|
|||
const struct fdc2x1x_config *cfg = dev->config;
|
||||
int ret = 0;
|
||||
|
||||
gpio_pin_set(cfg->sd_gpio, cfg->sd_pin, enable);
|
||||
gpio_pin_set_dt(&cfg->sd_gpio, enable);
|
||||
|
||||
if (!enable) {
|
||||
ret = fdc2x1x_restart(dev);
|
||||
|
@ -516,7 +516,7 @@ static int fdc2x1x_device_pm_action(const struct device *dev,
|
|||
|
||||
break;
|
||||
case PM_DEVICE_ACTION_TURN_OFF:
|
||||
if (cfg->sd_gpio->name) {
|
||||
if (cfg->sd_gpio->port.name) {
|
||||
ret = fdc2x1x_set_shutdown(dev, true);
|
||||
} else {
|
||||
LOG_ERR("SD pin not defined");
|
||||
|
@ -886,13 +886,12 @@ static int fdc2x1x_init_sd_pin(const struct device *dev)
|
|||
{
|
||||
const struct fdc2x1x_config *cfg = dev->config;
|
||||
|
||||
if (!device_is_ready(cfg->sd_gpio)) {
|
||||
LOG_ERR("%s: sd_gpio device not ready", cfg->sd_gpio->name);
|
||||
if (!device_is_ready(cfg->sd_gpio.port)) {
|
||||
LOG_ERR("%s: sd_gpio device not ready", cfg->sd_gpio.port->name);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
gpio_pin_configure(cfg->sd_gpio, cfg->sd_pin,
|
||||
GPIO_OUTPUT_INACTIVE | cfg->sd_flags);
|
||||
gpio_pin_configure_dt(&cfg->sd_gpio, GPIO_OUTPUT_INACTIVE);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
@ -921,7 +920,7 @@ static int fdc2x1x_init(const struct device *dev)
|
|||
return -EINVAL;
|
||||
}
|
||||
|
||||
if (cfg->sd_gpio->name) {
|
||||
if (cfg->sd_gpio.port->name) {
|
||||
if (fdc2x1x_init_sd_pin(dev) < 0) {
|
||||
return -ENODEV;
|
||||
}
|
||||
|
@ -959,18 +958,14 @@ static int fdc2x1x_init(const struct device *dev)
|
|||
}
|
||||
|
||||
#define FDC2X1X_SD_PROPS(n) \
|
||||
.sd_gpio = DEVICE_DT_GET(DT_GPIO_CTLR(DT_DRV_INST(n), sd_gpios)), \
|
||||
.sd_pin = DT_INST_GPIO_PIN(n, sd_gpios), \
|
||||
.sd_flags = DT_INST_GPIO_FLAGS(n, sd_gpios), \
|
||||
.sd_gpio = GPIO_DT_SPEC_INST_GET(n, sd_gpios), \
|
||||
|
||||
#define FDC2X1X_SD(n) \
|
||||
IF_ENABLED(DT_INST_NODE_HAS_PROP(n, sd_gpios), \
|
||||
(FDC2X1X_SD_PROPS(n)))
|
||||
|
||||
#define FDC2X1X_INTB_PROPS(n) \
|
||||
.intb_gpio = DEVICE_DT_GET(DT_GPIO_CTLR(DT_DRV_INST(n), intb_gpios)), \
|
||||
.intb_pin = DT_INST_GPIO_PIN(n, intb_gpios), \
|
||||
.intb_flags = DT_INST_GPIO_FLAGS(n, intb_gpios), \
|
||||
.intb_gpio = GPIO_DT_SPEC_INST_GET(n, intb_gpios), \
|
||||
|
||||
#define FDC2X1X_INTB(n) \
|
||||
IF_ENABLED(CONFIG_FDC2X1X_TRIGGER, \
|
||||
|
|
|
@ -182,15 +182,10 @@ struct fdc2x1x_chx_config {
|
|||
|
||||
struct fdc2x1x_config {
|
||||
struct i2c_dt_spec i2c;
|
||||
|
||||
const struct device *sd_gpio;
|
||||
gpio_pin_t sd_pin;
|
||||
gpio_dt_flags_t sd_flags;
|
||||
struct gpio_dt_spec sd_gpio;
|
||||
|
||||
#ifdef CONFIG_FDC2X1X_TRIGGER
|
||||
const struct device *intb_gpio;
|
||||
gpio_pin_t intb_pin;
|
||||
gpio_dt_flags_t intb_flags;
|
||||
struct gpio_dt_spec intb_gpio;
|
||||
#endif
|
||||
|
||||
bool fdc2x14;
|
||||
|
|
|
@ -87,8 +87,7 @@ int fdc2x1x_trigger_set(const struct device *dev,
|
|||
uint16_t status, int_mask, int_en;
|
||||
int ret;
|
||||
|
||||
gpio_pin_interrupt_configure(cfg->intb_gpio, cfg->intb_pin,
|
||||
GPIO_INT_DISABLE);
|
||||
gpio_pin_interrupt_configure_dt(&cfg->intb_gpio, GPIO_INT_DISABLE);
|
||||
|
||||
switch (trig->type) {
|
||||
case SENSOR_TRIG_DATA_READY:
|
||||
|
@ -118,8 +117,7 @@ int fdc2x1x_trigger_set(const struct device *dev,
|
|||
/* Clear INTB pin by reading STATUS register */
|
||||
fdc2x1x_get_status(dev, &status);
|
||||
out:
|
||||
gpio_pin_interrupt_configure(cfg->intb_gpio, cfg->intb_pin,
|
||||
GPIO_INT_EDGE_TO_ACTIVE);
|
||||
gpio_pin_interrupt_configure_dt(&cfg->intb_gpio, GPIO_INT_EDGE_TO_ACTIVE);
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
@ -132,8 +130,8 @@ int fdc2x1x_init_interrupt(const struct device *dev)
|
|||
|
||||
k_mutex_init(&drv_data->trigger_mutex);
|
||||
|
||||
if (!device_is_ready(cfg->intb_gpio)) {
|
||||
LOG_ERR("%s: intb_gpio device not ready", cfg->intb_gpio->name);
|
||||
if (!device_is_ready(cfg->intb_gpio.port)) {
|
||||
LOG_ERR("%s: intb_gpio device not ready", cfg->intb_gpio.port->name);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
|
@ -142,14 +140,13 @@ int fdc2x1x_init_interrupt(const struct device *dev)
|
|||
return ret;
|
||||
}
|
||||
|
||||
gpio_pin_configure(cfg->intb_gpio, cfg->intb_pin,
|
||||
GPIO_INPUT | cfg->intb_flags);
|
||||
gpio_pin_configure_dt(&cfg->intb_gpio, GPIO_INPUT);
|
||||
|
||||
gpio_init_callback(&drv_data->gpio_cb,
|
||||
fdc2x1x_gpio_callback,
|
||||
BIT(cfg->intb_pin));
|
||||
BIT(cfg->intb_gpio.pin));
|
||||
|
||||
if (gpio_add_callback(cfg->intb_gpio, &drv_data->gpio_cb) < 0) {
|
||||
if (gpio_add_callback(cfg->intb_gpio.port, &drv_data->gpio_cb) < 0) {
|
||||
LOG_ERR("Failed to set gpio callback!");
|
||||
return -EIO;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue