diff --git a/boards/arm/efr32mg_sltb004a/board.c b/boards/arm/efr32mg_sltb004a/board.c index aff8fbd5706..cff8bc4ad6a 100644 --- a/boards/arm/efr32mg_sltb004a/board.c +++ b/boards/arm/efr32mg_sltb004a/board.c @@ -5,30 +5,55 @@ */ #include -#include "board.h" #include #include -static int efr32mg_sltb004a_init(const struct device *dev) +struct supply_cfg { + const struct device *gpio; + gpio_pin_t pin; + gpio_dt_flags_t flags; +}; + +static int enable_supply(const struct supply_cfg *cfg) { - const struct device *cur_dev; + int rv = -ENODEV; - ARG_UNUSED(dev); - -#ifdef CONFIG_CCS811 - /* Enable the CCS811 power */ - cur_dev = device_get_binding(CCS811_PWR_ENABLE_GPIO_NAME); - if (!cur_dev) { - printk("CCS811 power gpio port was not found!\n"); - return -ENODEV; + if (device_is_ready(cfg->gpio)) { + gpio_pin_configure(cfg->gpio, cfg->pin, + GPIO_OUTPUT | cfg->flags); + gpio_pin_set(cfg->gpio, cfg->pin, 1); + rv = 0; } - gpio_pin_configure(cur_dev, CCS811_PWR_ENABLE_GPIO_PIN, GPIO_OUTPUT); - gpio_pin_set(cur_dev, CCS811_PWR_ENABLE_GPIO_PIN, 1); + return rv; +} -#endif /* CONFIG_CCS811 */ +static int efr32mg_sltb004a_init(const struct device *dev) +{ + struct supply_cfg cfg; + int rc = 0; - return 0; + ARG_UNUSED(dev); + (void)cfg; + +#define CCS811 DT_NODELABEL(ccs811) + +#if DT_NODE_HAS_STATUS(CCS811, okay) + DEVICE_DT_DECLARE(DT_GPIO_CTLR(CCS811, supply_gpios)); + cfg = (struct supply_cfg){ + .gpio = DEVICE_DT_GET(DT_GPIO_CTLR(CCS811, supply_gpios)), + .pin = DT_GPIO_PIN(CCS811, supply_gpios), + .flags = DT_GPIO_FLAGS(CCS811, supply_gpios), + }; + + /* Enable the CCS811 power */ + rc = enable_supply(&cfg); + if (rc < 0) { + printk("CCS811 supply not enabled: %d\n", rc); + } +#endif + + return rc; } /* needs to be done after GPIO driver init */ diff --git a/boards/arm/efr32mg_sltb004a/board.h b/boards/arm/efr32mg_sltb004a/board.h deleted file mode 100644 index 8b98abdb417..00000000000 --- a/boards/arm/efr32mg_sltb004a/board.h +++ /dev/null @@ -1,16 +0,0 @@ -/* - * Copyright (c) 2020 Christian Taedcke - * - * SPDX-License-Identifier: Apache-2.0 - */ - -#ifndef __INC_BOARD_H -#define __INC_BOARD_H - -/* CCS811 specific pins */ -#ifdef CONFIG_CCS811 -#define CCS811_PWR_ENABLE_GPIO_NAME "GPIO_F" -#define CCS811_PWR_ENABLE_GPIO_PIN 14 -#endif /* CONFIG_CCS811 */ - -#endif /* __INC_BOARD_H */ diff --git a/boards/arm/efr32mg_sltb004a/efr32mg_sltb004a.dts b/boards/arm/efr32mg_sltb004a/efr32mg_sltb004a.dts index 9ae63b0e18a..e116b69bba6 100644 --- a/boards/arm/efr32mg_sltb004a/efr32mg_sltb004a.dts +++ b/boards/arm/efr32mg_sltb004a/efr32mg_sltb004a.dts @@ -110,6 +110,7 @@ }; &i2c1 { + /* This set selects for CCS811_I2C supporting CCS811 */ location-sda = ; location-scl = ; @@ -117,9 +118,22 @@ compatible = "ams,ccs811"; reg = <0x5a>; label = "CCS811"; + supply-gpios = <&gpiof 14 GPIO_ACTIVE_HIGH>; irq-gpios = <&gpiof 13 GPIO_ACTIVE_LOW>; wake-gpios = <&gpiof 15 GPIO_ACTIVE_LOW>; }; + + /* This set selects for ENV_I2C supporting Si7021, Si11330, BMP280 */ + /* + location-sda = ; + location-scl = ; + */ + + /* This set selects for HALL_I2C supporting Si7210 */ + /* + location-sda = ; + location-scl = ; + */ }; &rtcc0 {