drivers: gpio: pca95xx: use gpio_dt_spec

Simplify implementation by using gpio_dt_spec.

Signed-off-by: Gerard Marull-Paretas <gerard.marull@nordicsemi.no>
This commit is contained in:
Gerard Marull-Paretas 2022-01-28 12:29:56 +01:00 committed by Anas Nashif
commit 80ee515c9c

View file

@ -70,12 +70,7 @@ struct gpio_pca95xx_config {
uint8_t capabilities; uint8_t capabilities;
#ifdef CONFIG_GPIO_PCA95XX_INTERRUPT #ifdef CONFIG_GPIO_PCA95XX_INTERRUPT
/* Interrupt pin definition */ struct gpio_dt_spec int_gpio;
const char *int_gpio_port;
gpio_pin_t int_gpio_pin;
gpio_flags_t int_gpio_flags;
#endif #endif
}; };
@ -568,7 +563,6 @@ static int gpio_pca95xx_pin_interrupt_configure(const struct device *dev,
const struct gpio_pca95xx_config * const config = dev->config; const struct gpio_pca95xx_config * const config = dev->config;
struct gpio_pca95xx_drv_data * const drv_data = struct gpio_pca95xx_drv_data * const drv_data =
(struct gpio_pca95xx_drv_data * const)dev->data; (struct gpio_pca95xx_drv_data * const)dev->data;
const struct device *int_gpio_dev;
uint16_t reg; uint16_t reg;
bool enabled, edge, level, active; bool enabled, edge, level, active;
@ -612,15 +606,14 @@ static int gpio_pca95xx_pin_interrupt_configure(const struct device *dev,
/* Enable / disable interrupt as needed */ /* Enable / disable interrupt as needed */
if (active != drv_data->interrupt_active) { if (active != drv_data->interrupt_active) {
int_gpio_dev = device_get_binding(config->int_gpio_port); ret = gpio_pin_interrupt_configure_dt(
ret = gpio_pin_interrupt_configure(int_gpio_dev, &int_gpio, active ?
config->int_gpio_pin, (active ? GPIO_INT_EDGE_TO_ACTIVE :
GPIO_INT_EDGE_TO_ACTIVE : GPIO_INT_MODE_DISABLED);
GPIO_INT_MODE_DISABLED));
if (ret != 0) { if (ret != 0) {
LOG_ERR("PCA95XX[0x%X]: failed to configure interrupt " LOG_ERR("PCA95XX[0x%X]: failed to configure interrupt "
"on pin %d (%d)", config->i2c_slave_addr, "on pin %d (%d)", config->i2c_slave_addr,
config->int_gpio_pin, ret); config->int_gpio.pin, ret);
goto err; goto err;
} }
drv_data->interrupt_active = active; drv_data->interrupt_active = active;
@ -699,7 +692,6 @@ static int gpio_pca95xx_init(const struct device *dev)
#ifdef CONFIG_GPIO_PCA95XX_INTERRUPT #ifdef CONFIG_GPIO_PCA95XX_INTERRUPT
/* Check if GPIO port supports interrupts */ /* Check if GPIO port supports interrupts */
if ((config->capabilities & PCA_HAS_INTERRUPT) != 0) { if ((config->capabilities & PCA_HAS_INTERRUPT) != 0) {
const struct device *int_gpio_dev;
int ret; int ret;
/* Store self-reference for interrupt handling */ /* Store self-reference for interrupt handling */
@ -710,28 +702,26 @@ static int gpio_pca95xx_init(const struct device *dev)
gpio_pca95xx_interrupt_worker); gpio_pca95xx_interrupt_worker);
/* Configure GPIO interrupt pin */ /* Configure GPIO interrupt pin */
int_gpio_dev = device_get_binding(config->int_gpio_port); if (!device_is_ready(config->int_gpio.port)) {
if (int_gpio_dev == NULL) { LOG_ERR("PCA95XX[0x%X]: interrupt GPIO not ready",
LOG_ERR("PCA95XX[0x%X]: error getting interrupt GPIO" config->i2c_slave_addr);
" device (%s)", config->i2c_slave_addr, err = -ENODEV;
config->int_gpio_port); goto err;
return -ENODEV;
} }
ret = gpio_pin_configure(int_gpio_dev, config->int_gpio_pin, ret = gpio_pin_configure_dt(&config->int_gpio, GPIO_INPUT);
(config->int_gpio_flags | GPIO_INPUT));
if (ret != 0) { if (ret != 0) {
LOG_ERR("PCA95XX[0x%X]: failed to configure interrupt" LOG_ERR("PCA95XX[0x%X]: failed to configure interrupt"
" pin %d (%d)", config->i2c_slave_addr, " pin %d (%d)", config->i2c_slave_addr,
config->int_gpio_pin, ret); config->int_gpio.pin, ret);
return ret; return ret;
} }
/* Prepare GPIO callback for interrupt pin */ /* Prepare GPIO callback for interrupt pin */
gpio_init_callback(&drv_data->gpio_callback, gpio_init_callback(&drv_data->gpio_callback,
gpio_pca95xx_interrupt_callback, gpio_pca95xx_interrupt_callback,
BIT(config->int_gpio_pin)); BIT(config->int_gpio.pin));
gpio_add_callback(int_gpio_dev, &drv_data->gpio_callback); gpio_add_callback(cfg->int_gpio.port, &drv_data->gpio_callback);
} }
#endif #endif
@ -753,12 +743,8 @@ static const struct gpio_pca95xx_config gpio_pca95xx_##inst##_cfg = { \
PCA_HAS_INTERRUPT : 0) | \ PCA_HAS_INTERRUPT : 0) | \
)) \ )) \
0, \ 0, \
IF_ENABLED(CONFIG_GPIO_PCA95XX_INTERRUPT, ( \ IF_ENABLED(CONFIG_GPIO_PCA95XX_INTERRUPT, \
IF_ENABLED(DT_INST_NODE_HAS_PROP(inst, interrupt_gpios), ( \ (.int_gpio = GPIO_DT_SPEC_INST_GET_OR(inst, interrupt_gpios, {}),)) \
.int_gpio_port = DT_INST_GPIO_LABEL(inst, interrupt_gpios), \
.int_gpio_pin = DT_INST_GPIO_PIN(inst, interrupt_gpios), \
.int_gpio_flags = DT_INST_GPIO_FLAGS(inst, interrupt_gpios), \
)))) \
}; \ }; \
\ \
static struct gpio_pca95xx_drv_data gpio_pca95xx_##inst##_drvdata = { \ static struct gpio_pca95xx_drv_data gpio_pca95xx_##inst##_drvdata = { \