drivers: sensor: apds9960: 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
cf947c5b13
commit
7a9a5f525f
3 changed files with 19 additions and 32 deletions
|
@ -28,7 +28,7 @@ LOG_MODULE_REGISTER(APDS9960, CONFIG_SENSOR_LOG_LEVEL);
|
|||
|
||||
static void apds9960_handle_cb(struct apds9960_data *drv_data)
|
||||
{
|
||||
apds9960_setup_int(drv_data, false);
|
||||
apds9960_setup_int(drv_data->dev->config, false);
|
||||
|
||||
#ifdef CONFIG_APDS9960_TRIGGER
|
||||
k_work_submit(&drv_data->work);
|
||||
|
@ -59,7 +59,7 @@ static int apds9960_sample_fetch(const struct device *dev,
|
|||
}
|
||||
|
||||
#ifndef CONFIG_APDS9960_TRIGGER
|
||||
apds9960_setup_int(data, true);
|
||||
apds9960_setup_int(config, true);
|
||||
|
||||
#ifdef CONFIG_APDS9960_ENABLE_ALS
|
||||
tmp = APDS9960_ENABLE_PON | APDS9960_ENABLE_AIEN;
|
||||
|
@ -360,24 +360,19 @@ static int apds9960_init_interrupt(const struct device *dev)
|
|||
const struct apds9960_config *config = dev->config;
|
||||
struct apds9960_data *drv_data = dev->data;
|
||||
|
||||
/* setup gpio interrupt */
|
||||
drv_data->gpio = device_get_binding(config->gpio_name);
|
||||
if (drv_data->gpio == NULL) {
|
||||
LOG_ERR("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,
|
||||
apds9960_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;
|
||||
}
|
||||
|
@ -396,9 +391,9 @@ static int apds9960_init_interrupt(const struct device *dev)
|
|||
#else
|
||||
k_sem_init(&drv_data->data_sem, 0, K_SEM_MAX_LIMIT);
|
||||
#endif
|
||||
apds9960_setup_int(drv_data, true);
|
||||
apds9960_setup_int(drv_data->dev->config, true);
|
||||
|
||||
if (gpio_pin_get(drv_data->gpio, drv_data->gpio_pin) > 0) {
|
||||
if (gpio_pin_get_dt(&config->int_gpio) > 0) {
|
||||
apds9960_handle_cb(drv_data);
|
||||
}
|
||||
|
||||
|
@ -481,9 +476,7 @@ static const struct sensor_driver_api apds9960_driver_api = {
|
|||
|
||||
static const struct apds9960_config apds9960_config = {
|
||||
.i2c = I2C_DT_SPEC_INST_GET(0),
|
||||
.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),
|
||||
#if CONFIG_APDS9960_PGAIN_8X
|
||||
.pgain = APDS9960_PGAIN_8X,
|
||||
#elif CONFIG_APDS9960_PGAIN_4X
|
||||
|
|
|
@ -214,9 +214,7 @@
|
|||
|
||||
struct apds9960_config {
|
||||
struct i2c_dt_spec i2c;
|
||||
char *gpio_name;
|
||||
uint8_t gpio_pin;
|
||||
unsigned int gpio_flags;
|
||||
struct gpio_dt_spec int_gpio;
|
||||
uint8_t pgain;
|
||||
uint8_t again;
|
||||
uint8_t ppcount;
|
||||
|
@ -224,13 +222,11 @@ struct apds9960_config {
|
|||
};
|
||||
|
||||
struct apds9960_data {
|
||||
const struct device *gpio;
|
||||
struct gpio_callback gpio_cb;
|
||||
struct k_work work;
|
||||
const struct device *dev;
|
||||
uint16_t sample_crgb[4];
|
||||
uint8_t pdata;
|
||||
uint8_t gpio_pin;
|
||||
|
||||
#ifdef CONFIG_APDS9960_TRIGGER
|
||||
sensor_trigger_handler_t p_th_handler;
|
||||
|
@ -240,16 +236,14 @@ struct apds9960_data {
|
|||
#endif
|
||||
};
|
||||
|
||||
static inline void apds9960_setup_int(struct apds9960_data *drv_data,
|
||||
static inline void apds9960_setup_int(const struct apds9960_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);
|
||||
}
|
||||
|
||||
#ifdef CONFIG_APDS9960_TRIGGER
|
||||
|
|
|
@ -28,7 +28,7 @@ void apds9960_work_cb(struct k_work *work)
|
|||
data->p_th_handler(dev, &data->p_th_trigger);
|
||||
}
|
||||
|
||||
apds9960_setup_int(data, true);
|
||||
apds9960_setup_int(dev->config, true);
|
||||
}
|
||||
|
||||
int apds9960_attr_set(const struct device *dev,
|
||||
|
@ -69,7 +69,7 @@ int apds9960_trigger_set(const struct device *dev,
|
|||
const struct apds9960_config *config = dev->config;
|
||||
struct apds9960_data *data = dev->data;
|
||||
|
||||
apds9960_setup_int(data, false);
|
||||
apds9960_setup_int(dev->config, false);
|
||||
|
||||
switch (trig->type) {
|
||||
case SENSOR_TRIG_THRESHOLD:
|
||||
|
@ -90,8 +90,8 @@ int apds9960_trigger_set(const struct device *dev,
|
|||
return -ENOTSUP;
|
||||
}
|
||||
|
||||
apds9960_setup_int(data, true);
|
||||
if (gpio_pin_get(data->gpio, data->gpio_pin) > 0) {
|
||||
apds9960_setup_int(config, true);
|
||||
if (gpio_pin_get_dt(&config->int_gpio) > 0) {
|
||||
k_work_submit(&data->work);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue