drivers: sensor: amg88xx: 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
1fbc9632c1
commit
61c2b35335
3 changed files with 17 additions and 29 deletions
|
@ -141,9 +141,7 @@ static const struct sensor_driver_api amg88xx_driver_api = {
|
|||
static const struct amg88xx_config amg88xx_config = {
|
||||
.i2c = I2C_DT_SPEC_INST_GET(0),
|
||||
#ifdef CONFIG_AMG88XX_TRIGGER
|
||||
.gpio_name = DT_INST_GPIO_LABEL(0, int_gpios),
|
||||
.gpio_pin = DT_INST_GPIO_PIN(0, int_gpios),
|
||||
.gpio_flags = DT_INST_GPIO_FLAGS(0, int_gpios),
|
||||
.int_gpio = GPIO_DT_SPEC_INST_GET(0, int_gpios),
|
||||
#endif
|
||||
};
|
||||
|
||||
|
|
|
@ -69,9 +69,7 @@
|
|||
struct amg88xx_config {
|
||||
const struct i2c_dt_spec i2c;
|
||||
#ifdef CONFIG_AMG88XX_TRIGGER
|
||||
char *gpio_name;
|
||||
uint8_t gpio_pin;
|
||||
gpio_dt_flags_t gpio_flags;
|
||||
const struct gpio_dt_spec int_gpio;
|
||||
#endif
|
||||
};
|
||||
|
||||
|
@ -80,8 +78,6 @@ struct amg88xx_data {
|
|||
|
||||
#ifdef CONFIG_AMG88XX_TRIGGER
|
||||
const struct device *dev;
|
||||
const struct device *gpio;
|
||||
uint8_t gpio_pin;
|
||||
struct gpio_callback gpio_cb;
|
||||
|
||||
sensor_trigger_handler_t drdy_handler;
|
||||
|
|
|
@ -18,16 +18,14 @@ extern struct amg88xx_data amg88xx_driver;
|
|||
#include <zephyr/logging/log.h>
|
||||
LOG_MODULE_DECLARE(AMG88XX, CONFIG_SENSOR_LOG_LEVEL);
|
||||
|
||||
static inline void amg88xx_setup_int(struct amg88xx_data *drv_data,
|
||||
static inline void amg88xx_setup_int(const struct amg88xx_config *cfg,
|
||||
bool enable)
|
||||
{
|
||||
unsigned int flags = enable
|
||||
? GPIO_INT_EDGE_TO_ACTIVE
|
||||
: GPIO_INT_DISABLE;
|
||||
|
||||
gpio_pin_interrupt_configure(drv_data->gpio,
|
||||
drv_data->gpio_pin,
|
||||
flags);
|
||||
gpio_pin_interrupt_configure_dt(&cfg->int_gpio, flags);
|
||||
}
|
||||
|
||||
int amg88xx_attr_set(const struct device *dev,
|
||||
|
@ -77,8 +75,9 @@ static void amg88xx_gpio_callback(const struct device *dev,
|
|||
{
|
||||
struct amg88xx_data *drv_data =
|
||||
CONTAINER_OF(cb, struct amg88xx_data, gpio_cb);
|
||||
const struct amg88xx_config *config = drv_data->dev->config;
|
||||
|
||||
amg88xx_setup_int(drv_data, false);
|
||||
amg88xx_setup_int(config, false);
|
||||
|
||||
#if defined(CONFIG_AMG88XX_TRIGGER_OWN_THREAD)
|
||||
k_sem_give(&drv_data->gpio_sem);
|
||||
|
@ -106,7 +105,7 @@ static void amg88xx_thread_cb(const struct device *dev)
|
|||
drv_data->th_handler(dev, &drv_data->th_trigger);
|
||||
}
|
||||
|
||||
amg88xx_setup_int(drv_data, true);
|
||||
amg88xx_setup_int(config, true);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_AMG88XX_TRIGGER_OWN_THREAD
|
||||
|
@ -140,7 +139,7 @@ int amg88xx_trigger_set(const struct device *dev,
|
|||
return -EIO;
|
||||
}
|
||||
|
||||
amg88xx_setup_int(drv_data, false);
|
||||
amg88xx_setup_int(config, false);
|
||||
|
||||
if (trig->type == SENSOR_TRIG_THRESHOLD) {
|
||||
drv_data->th_handler = handler;
|
||||
|
@ -150,7 +149,7 @@ int amg88xx_trigger_set(const struct device *dev,
|
|||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
amg88xx_setup_int(drv_data, true);
|
||||
amg88xx_setup_int(config, true);
|
||||
|
||||
if (i2c_reg_write_byte_dt(&config->i2c,
|
||||
AMG88XX_INTC, AMG88XX_INTC_ABS_MODE)) {
|
||||
|
@ -165,24 +164,19 @@ int amg88xx_init_interrupt(const struct device *dev)
|
|||
struct amg88xx_data *drv_data = dev->data;
|
||||
const struct amg88xx_config *config = dev->config;
|
||||
|
||||
/* setup gpio interrupt */
|
||||
drv_data->gpio = device_get_binding(config->gpio_name);
|
||||
if (drv_data->gpio == NULL) {
|
||||
LOG_DBG("Failed to get pointer to %s device!",
|
||||
config->gpio_name);
|
||||
return -EINVAL;
|
||||
if (!device_is_ready(config->int_gpio.port)) {
|
||||
LOG_ERR("%s: device %s is not ready", dev->name,
|
||||
config->int_gpio.port->name);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
drv_data->gpio_pin = config->gpio_pin;
|
||||
|
||||
gpio_pin_configure(drv_data->gpio, config->gpio_pin,
|
||||
GPIO_INPUT | config->gpio_flags);
|
||||
gpio_pin_configure_dt(&config->int_gpio, GPIO_INPUT | config->int_gpio.dt_flags);
|
||||
|
||||
gpio_init_callback(&drv_data->gpio_cb,
|
||||
amg88xx_gpio_callback,
|
||||
BIT(config->gpio_pin));
|
||||
BIT(config->int_gpio.pin));
|
||||
|
||||
if (gpio_add_callback(drv_data->gpio, &drv_data->gpio_cb) < 0) {
|
||||
if (gpio_add_callback(config->int_gpio.port, &drv_data->gpio_cb) < 0) {
|
||||
LOG_DBG("Failed to set gpio callback!");
|
||||
return -EIO;
|
||||
}
|
||||
|
@ -200,7 +194,7 @@ int amg88xx_init_interrupt(const struct device *dev)
|
|||
#elif defined(CONFIG_AMG88XX_TRIGGER_GLOBAL_THREAD)
|
||||
drv_data->work.handler = amg88xx_work_cb;
|
||||
#endif
|
||||
amg88xx_setup_int(drv_data, true);
|
||||
amg88xx_setup_int(config, true);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue