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

View file

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

View file

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