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