drivers: sensor: sx9500: Update driver to use gpio_dt_spec

Move driver to use gpio_dt_spec for GPIO interrupt handling.

Signed-off-by: Kumar Gala <galak@kernel.org>
This commit is contained in:
Kumar Gala 2022-06-28 09:58:31 -05:00 committed by Carles Cufí
parent 5c93b3d79a
commit e70933d7dc
3 changed files with 15 additions and 14 deletions

View File

@ -130,6 +130,9 @@ int sx9500_init(const struct device *dev)
static const struct sx9500_config sx9500_config = {
.i2c = I2C_DT_SPEC_INST_GET(0),
#ifdef CONFIG_SX9500_TRIGGER
.int_gpio = GPIO_DT_SPEC_INST_GET(0, int_gpios),
#endif
};
struct sx9500_data sx9500_data;

View File

@ -27,6 +27,9 @@
struct sx9500_config {
struct i2c_dt_spec i2c;
#ifdef CONFIG_SX9500_TRIGGER
struct gpio_dt_spec int_gpio;
#endif
};
struct sx9500_data {

View File

@ -129,7 +129,7 @@ static void sx9500_work_cb(struct k_work *work)
int sx9500_setup_interrupt(const struct device *dev)
{
struct sx9500_data *data = dev->data;
const struct device *gpio;
const struct sx9500_config *cfg = dev->config;
int ret;
#ifdef CONFIG_SX9500_TRIGGER_OWN_THREAD
@ -140,30 +140,25 @@ int sx9500_setup_interrupt(const struct device *dev)
data->dev = dev;
gpio = device_get_binding(DT_INST_GPIO_LABEL(0, int_gpios));
if (!gpio) {
LOG_DBG("sx9500: gpio controller %s not found",
DT_INST_GPIO_LABEL(0, int_gpios));
return -EINVAL;
if (!device_is_ready(cfg->int_gpio.port)) {
LOG_ERR("%s: device %s is not ready", dev->name,
cfg->int_gpio.port->name);
return -ENODEV;
}
ret = gpio_pin_configure(gpio, DT_INST_GPIO_PIN(0, int_gpios),
GPIO_INPUT | DT_INST_GPIO_FLAGS(0, int_gpios));
ret = gpio_pin_configure_dt(&cfg->int_gpio, GPIO_INPUT);
if (ret < 0) {
return ret;
}
gpio_init_callback(&data->gpio_cb,
sx9500_gpio_cb,
BIT(DT_INST_GPIO_PIN(0, int_gpios)));
gpio_init_callback(&data->gpio_cb, sx9500_gpio_cb, BIT(cfg->int_gpio.pin));
ret = gpio_add_callback(gpio, &data->gpio_cb);
ret = gpio_add_callback(cfg->int_gpio.port, &data->gpio_cb);
if (ret < 0) {
return ret;
}
ret = gpio_pin_interrupt_configure(gpio, DT_INST_GPIO_PIN(0, int_gpios),
GPIO_INT_EDGE_TO_ACTIVE);
ret = gpio_pin_interrupt_configure_dt(&cfg->int_gpio, GPIO_INT_EDGE_TO_ACTIVE);
if (ret < 0) {
return ret;
}