boards: efr32mg_sltb004a: rework sensor power enable infrastructure

There are three groups of sensors on this board, each of which
requires a different I2C bus configuration and a different power
supply.  Currently only the CCS811 is supported.

Change the board configuration to pull the necessary information about
the CCS811 supply switch from devicetree, and to supply power based on
whether the device is enabled in devicetree (rather than whether a
driver is selected).  The implementation is designed to support
additional supply switches (there are at least six on the board, most
of which are dedicated).

Also document the I2C configuration necessary for the other sensors.
There is currently no way to select alternative configurations without
editing the devicetree binding, but at least they're available for use
in overlays.

Signed-off-by: Peter Bigot <peter.bigot@nordicsemi.no>
This commit is contained in:
Peter Bigot 2020-12-02 11:48:39 -06:00 committed by Carles Cufí
parent c70cc93833
commit 11c923cfc8
3 changed files with 54 additions and 31 deletions

View File

@ -5,30 +5,55 @@
*/
#include <init.h>
#include "board.h"
#include <drivers/gpio.h>
#include <sys/printk.h>
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 */

View File

@ -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 */

View File

@ -110,6 +110,7 @@
};
&i2c1 {
/* This set selects for CCS811_I2C supporting CCS811 */
location-sda = <GECKO_LOCATION(6) GECKO_PORT_B GECKO_PIN(6)>;
location-scl = <GECKO_LOCATION(6) GECKO_PORT_B GECKO_PIN(7)>;
@ -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 = <GECKO_LOCATION(17) GECKO_PORT_C GECKO_PIN(4)>;
location-scl = <GECKO_LOCATION(17) GECKO_PORT_C GECKO_PIN(5)>;
*/
/* This set selects for HALL_I2C supporting Si7210 */
/*
location-sda = <GECKO_LOCATION(8) GECKO_PORT_B GECKO_PIN(8)>;
location-scl = <GECKO_LOCATION(8) GECKO_PORT_B GECKO_PIN(9)>;
*/
};
&rtcc0 {