drivers: sensor: adt7420: 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:
parent
6563245300
commit
ef6146d802
3 changed files with 12 additions and 20 deletions
|
@ -214,9 +214,7 @@ static struct adt7420_data adt7420_driver;
|
|||
static const struct adt7420_dev_config adt7420_config = {
|
||||
.i2c = I2C_DT_SPEC_INST_GET(0),
|
||||
#ifdef CONFIG_ADT7420_TRIGGER
|
||||
.int_pin = DT_INST_GPIO_PIN(0, int_gpios),
|
||||
.int_flags = DT_INST_GPIO_FLAGS(0, int_gpios),
|
||||
.int_name = DT_INST_GPIO_LABEL(0, int_gpios),
|
||||
.int_gpio = GPIO_DT_SPEC_INST_GET(0, int_gpios),
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -61,7 +61,6 @@
|
|||
struct adt7420_data {
|
||||
int16_t sample;
|
||||
#ifdef CONFIG_ADT7420_TRIGGER
|
||||
const struct device *gpio;
|
||||
struct gpio_callback gpio_cb;
|
||||
|
||||
sensor_trigger_handler_t th_handler;
|
||||
|
@ -83,9 +82,7 @@ struct adt7420_data {
|
|||
struct adt7420_dev_config {
|
||||
struct i2c_dt_spec i2c;
|
||||
#ifdef CONFIG_ADT7420_TRIGGER
|
||||
gpio_pin_t int_pin;
|
||||
gpio_flags_t int_flags;
|
||||
const char *int_name;
|
||||
struct gpio_dt_spec int_gpio;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -19,13 +19,12 @@ LOG_MODULE_DECLARE(ADT7420, CONFIG_SENSOR_LOG_LEVEL);
|
|||
static void setup_int(const struct device *dev,
|
||||
bool enable)
|
||||
{
|
||||
struct adt7420_data *drv_data = dev->data;
|
||||
const struct adt7420_dev_config *cfg = dev->config;
|
||||
gpio_flags_t flags = enable
|
||||
? GPIO_INT_EDGE_TO_ACTIVE
|
||||
: GPIO_INT_DISABLE;
|
||||
|
||||
gpio_pin_interrupt_configure(drv_data->gpio, cfg->int_pin, flags);
|
||||
gpio_pin_interrupt_configure_dt(&cfg->int_gpio, flags);
|
||||
}
|
||||
|
||||
static void handle_int(const struct device *dev)
|
||||
|
@ -60,7 +59,7 @@ static void process_int(const struct device *dev)
|
|||
setup_int(dev, true);
|
||||
|
||||
/* Check for pin that asserted while we were offline */
|
||||
int pv = gpio_pin_get(drv_data->gpio, cfg->int_pin);
|
||||
int pv = gpio_pin_get_dt(&cfg->int_gpio);
|
||||
|
||||
if (pv > 0) {
|
||||
handle_int(dev);
|
||||
|
@ -116,7 +115,7 @@ int adt7420_trigger_set(const struct device *dev,
|
|||
setup_int(dev, true);
|
||||
|
||||
/* Check whether already asserted */
|
||||
int pv = gpio_pin_get(drv_data->gpio, cfg->int_pin);
|
||||
int pv = gpio_pin_get_dt(&cfg->int_gpio);
|
||||
|
||||
if (pv > 0) {
|
||||
handle_int(dev);
|
||||
|
@ -132,24 +131,22 @@ int adt7420_init_interrupt(const struct device *dev)
|
|||
const struct adt7420_dev_config *cfg = dev->config;
|
||||
int rc;
|
||||
|
||||
drv_data->gpio = device_get_binding(cfg->int_name);
|
||||
if (drv_data->gpio == NULL) {
|
||||
LOG_DBG("Failed to get pointer to %s device!",
|
||||
cfg->int_name);
|
||||
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;
|
||||
}
|
||||
|
||||
gpio_init_callback(&drv_data->gpio_cb,
|
||||
adt7420_gpio_callback,
|
||||
BIT(cfg->int_pin));
|
||||
BIT(cfg->int_gpio.pin));
|
||||
|
||||
rc = gpio_pin_configure(drv_data->gpio, cfg->int_pin,
|
||||
GPIO_INPUT | cfg->int_flags);
|
||||
rc = gpio_pin_configure_dt(&cfg->int_gpio, GPIO_INPUT | cfg->int_gpio.dt_flags);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
||||
rc = gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb);
|
||||
rc = gpio_add_callback(cfg->int_gpio.port, &drv_data->gpio_cb);
|
||||
if (rc < 0) {
|
||||
return rc;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue