sensor: ccs811: Convert GPIOs to device tree

Update ccs811 dts binding to include GPIO pins for wakeup, reset, and
interrupt and change driver code to get the GPIO pin and controller
info from DT instead of Kconfig.

Signed-off-by: Kumar Gala <kumar.gala@linaro.org>
This commit is contained in:
Kumar Gala 2019-11-05 08:04:34 -06:00 committed by Kumar Gala
commit 819276e082
5 changed files with 46 additions and 50 deletions

View file

@ -165,19 +165,31 @@ int ccs811_init(struct device *dev)
return -EINVAL;
}
#if defined(CONFIG_CCS811_GPIO_WAKEUP) || defined(CONFIG_CCS811_GPIO_RESET)
drv_data->gpio = device_get_binding(CONFIG_CCS811_GPIO_DEV_NAME);
if (drv_data->gpio == NULL) {
#ifdef DT_INST_0_AMS_CCS811_WAKE_GPIOS_CONTROLLER
drv_data->gpio_wakeup =
device_get_binding(DT_INST_0_AMS_CCS811_WAKE_GPIOS_CONTROLLER);
if (drv_data->gpio_wakeup == NULL) {
LOG_ERR("Failed to get pointer to %s device!",
CONFIG_CCS811_GPIO_DEV_NAME);
DT_INST_0_AMS_CCS811_WAKE_GPIOS_CONTROLLER);
return -EINVAL;
}
#endif
#ifdef CONFIG_CCS811_GPIO_RESET
gpio_pin_configure(drv_data->gpio, CONFIG_CCS811_GPIO_RESET_PIN_NUM,
#ifdef DT_INST_0_AMS_CCS811_RESET_GPIOS_CONTROLLER
drv_data->gpio_reset =
device_get_binding(DT_INST_0_AMS_CCS811_RESET_GPIOS_CONTROLLER);
if (drv_data->gpio_reset == NULL) {
LOG_ERR("Failed to get pointer to %s device!",
DT_INST_0_AMS_CCS811_RESET_GPIOS_CONTROLLER);
return -EINVAL;
}
#endif
#ifdef DT_INST_0_AMS_CCS811_RESET_GPIOS_CONTROLLER
gpio_pin_configure(drv_data->gpio_reset,
DT_INST_0_AMS_CCS811_RESET_GPIOS_PIN,
GPIO_DIR_OUT);
gpio_pin_write(drv_data->gpio, CONFIG_CCS811_GPIO_RESET_PIN_NUM, 1);
gpio_pin_write(drv_data->gpio_reset,
DT_INST_0_AMS_CCS811_RESET_GPIOS_PIN, 1);
k_sleep(K_MSEC(1));
#endif
@ -186,10 +198,12 @@ int ccs811_init(struct device *dev)
* Wakeup pin should be pulled low before initiating any I2C transfer.
* If it has been tied to GND by default, skip this part.
*/
#ifdef CONFIG_CCS811_GPIO_WAKEUP
gpio_pin_configure(drv_data->gpio, CONFIG_CCS811_GPIO_WAKEUP_PIN_NUM,
#ifdef DT_INST_0_AMS_CCS811_WAKE_GPIOS_CONTROLLER
gpio_pin_configure(drv_data->gpio_wakeup,
DT_INST_0_AMS_CCS811_WAKE_GPIOS_PIN,
GPIO_DIR_OUT);
gpio_pin_write(drv_data->gpio, CONFIG_CCS811_GPIO_WAKEUP_PIN_NUM, 0);
gpio_pin_write(drv_data->gpio_wakeup,
DT_INST_0_AMS_CCS811_WAKE_GPIOS_PIN, 0);
k_sleep(K_MSEC(1));
#endif