drivers: sensor: ccs811: use device tree for control GPIOs

Replace Kconfig GPIO pin configuration with device tree gpios.

Signed-off-by: Peter A. Bigot <pab@pabigot.com>
This commit is contained in:
Peter A. Bigot 2018-11-19 22:21:15 -06:00 committed by Maureen Helm
commit 11dd504f2a
3 changed files with 42 additions and 34 deletions

View file

@ -1,4 +1,5 @@
/*
* Copyright (c) 2018 Peter Bigot Consulting, LLC
* Copyright (c) 2018 Linaro Ltd.
*
* SPDX-License-Identifier: Apache-2.0
@ -165,49 +166,57 @@ int ccs811_init(struct device *dev)
return -EINVAL;
}
struct device *gpio = NULL;
(void)gpio;
#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!",
gpio = device_get_binding(DT_INST_0_AMS_CCS811_WAKE_GPIOS_CONTROLLER);
if (gpio == NULL) {
LOG_ERR("Failed to get pointer to WAKE device: %s",
DT_INST_0_AMS_CCS811_WAKE_GPIOS_CONTROLLER);
return -EINVAL;
}
#endif
drv_data->gpio = gpio;
#endif
#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!",
gpio = device_get_binding(DT_INST_0_AMS_CCS811_RESET_GPIOS_CONTROLLER);
if (gpio == NULL) {
LOG_ERR("Failed to get pointer to RESET device: %s",
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_reset,
DT_INST_0_AMS_CCS811_RESET_GPIOS_PIN, 1);
k_sleep(K_MSEC(1));
if (drv_data->gpio == NULL) {
drv_data->gpio = gpio;
} else if (drv_data->gpio != gpio) {
LOG_ERR("Crossing GPIO devices not supported");
return -EINVAL;
}
#endif
/*
* Wakeup pin should be pulled low before initiating any I2C transfer.
* If it has been tied to GND by default, skip this part.
*/
#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_wakeup,
DT_INST_0_AMS_CCS811_WAKE_GPIOS_PIN, 0);
if (drv_data->gpio) {
#ifdef DT_INST_0_AMS_CCS811_RESET_GPIOS_PIN
gpio_pin_configure(drv_data->gpio, DT_INST_0_AMS_CCS811_RESET_GPIOS_PIN,
GPIO_DIR_OUT);
gpio_pin_write(drv_data->gpio, DT_INST_0_AMS_CCS811_RESET_GPIOS_PIN, 1);
k_sleep(K_MSEC(1));
k_sleep(K_MSEC(1));
#endif
/*
* Wakeup pin should be pulled low before initiating
* any I2C transfer. If it has been tied to GND by
* default, skip this part.
*/
#ifdef DT_INST_0_AMS_CCS811_WAKE_GPIOS_PIN
gpio_pin_configure(drv_data->gpio, DT_INST_0_AMS_CCS811_WAKE_GPIOS_PIN,
GPIO_DIR_OUT);
gpio_pin_write(drv_data->gpio, DT_INST_0_AMS_CCS811_WAKE_GPIOS_PIN, 0);
k_sleep(K_MSEC(1));
#endif
}
/* Switch device to application mode */
ret = switch_to_app_mode(drv_data->i2c);
if (ret) {

View file

@ -1,4 +1,5 @@
/*
* Copyright (c) 2018 Peter Bigot Consulting, LLC
* Copyright (c) 2018 Linaro Ltd.
*
* SPDX-License-Identifier: Apache-2.0
@ -44,12 +45,7 @@
struct ccs811_data {
struct device *i2c;
#ifdef DT_INST_0_AMS_CCS811_WAKE_GPIOS_CONTROLLER
struct device *gpio_wakeup;
#endif
#ifdef DT_INST_0_AMS_CCS811_RESET_GPIOS_CONTROLLER
struct device *gpio_reset;
#endif
struct device *gpio;
u16_t co2;
u16_t voc;
u8_t status;

View file

@ -11,11 +11,14 @@ properties:
wake-gpios:
type: phandle-array
required: false
description: WAKEn pin
reset-gpios:
type: phandle-array
required: false
description: RESETn pin
irq-gpios:
type: phandle-array
required: false
description: INTn pin