Skip to content

Commit 11c923c

Browse files
pabigotcarlescufi
authored andcommitted
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 <[email protected]>
1 parent c70cc93 commit 11c923c

File tree

3 files changed

+52
-29
lines changed

3 files changed

+52
-29
lines changed

boards/arm/efr32mg_sltb004a/board.c

Lines changed: 38 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,55 @@
55
*/
66

77
#include <init.h>
8-
#include "board.h"
98
#include <drivers/gpio.h>
109
#include <sys/printk.h>
1110

11+
struct supply_cfg {
12+
const struct device *gpio;
13+
gpio_pin_t pin;
14+
gpio_dt_flags_t flags;
15+
};
16+
17+
static int enable_supply(const struct supply_cfg *cfg)
18+
{
19+
int rv = -ENODEV;
20+
21+
if (device_is_ready(cfg->gpio)) {
22+
gpio_pin_configure(cfg->gpio, cfg->pin,
23+
GPIO_OUTPUT | cfg->flags);
24+
gpio_pin_set(cfg->gpio, cfg->pin, 1);
25+
rv = 0;
26+
}
27+
28+
return rv;
29+
}
30+
1231
static int efr32mg_sltb004a_init(const struct device *dev)
1332
{
14-
const struct device *cur_dev;
33+
struct supply_cfg cfg;
34+
int rc = 0;
1535

1636
ARG_UNUSED(dev);
37+
(void)cfg;
1738

18-
#ifdef CONFIG_CCS811
19-
/* Enable the CCS811 power */
20-
cur_dev = device_get_binding(CCS811_PWR_ENABLE_GPIO_NAME);
21-
if (!cur_dev) {
22-
printk("CCS811 power gpio port was not found!\n");
23-
return -ENODEV;
24-
}
39+
#define CCS811 DT_NODELABEL(ccs811)
2540

26-
gpio_pin_configure(cur_dev, CCS811_PWR_ENABLE_GPIO_PIN, GPIO_OUTPUT);
27-
gpio_pin_set(cur_dev, CCS811_PWR_ENABLE_GPIO_PIN, 1);
41+
#if DT_NODE_HAS_STATUS(CCS811, okay)
42+
DEVICE_DT_DECLARE(DT_GPIO_CTLR(CCS811, supply_gpios));
43+
cfg = (struct supply_cfg){
44+
.gpio = DEVICE_DT_GET(DT_GPIO_CTLR(CCS811, supply_gpios)),
45+
.pin = DT_GPIO_PIN(CCS811, supply_gpios),
46+
.flags = DT_GPIO_FLAGS(CCS811, supply_gpios),
47+
};
2848

29-
#endif /* CONFIG_CCS811 */
49+
/* Enable the CCS811 power */
50+
rc = enable_supply(&cfg);
51+
if (rc < 0) {
52+
printk("CCS811 supply not enabled: %d\n", rc);
53+
}
54+
#endif
3055

31-
return 0;
56+
return rc;
3257
}
3358

3459
/* needs to be done after GPIO driver init */

boards/arm/efr32mg_sltb004a/board.h

Lines changed: 0 additions & 16 deletions
This file was deleted.

boards/arm/efr32mg_sltb004a/efr32mg_sltb004a.dts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,16 +110,30 @@
110110
};
111111

112112
&i2c1 {
113+
/* This set selects for CCS811_I2C supporting CCS811 */
113114
location-sda = <GECKO_LOCATION(6) GECKO_PORT_B GECKO_PIN(6)>;
114115
location-scl = <GECKO_LOCATION(6) GECKO_PORT_B GECKO_PIN(7)>;
115116

116117
ccs811: ccs811@5a {
117118
compatible = "ams,ccs811";
118119
reg = <0x5a>;
119120
label = "CCS811";
121+
supply-gpios = <&gpiof 14 GPIO_ACTIVE_HIGH>;
120122
irq-gpios = <&gpiof 13 GPIO_ACTIVE_LOW>;
121123
wake-gpios = <&gpiof 15 GPIO_ACTIVE_LOW>;
122124
};
125+
126+
/* This set selects for ENV_I2C supporting Si7021, Si11330, BMP280 */
127+
/*
128+
location-sda = <GECKO_LOCATION(17) GECKO_PORT_C GECKO_PIN(4)>;
129+
location-scl = <GECKO_LOCATION(17) GECKO_PORT_C GECKO_PIN(5)>;
130+
*/
131+
132+
/* This set selects for HALL_I2C supporting Si7210 */
133+
/*
134+
location-sda = <GECKO_LOCATION(8) GECKO_PORT_B GECKO_PIN(8)>;
135+
location-scl = <GECKO_LOCATION(8) GECKO_PORT_B GECKO_PIN(9)>;
136+
*/
123137
};
124138

125139
&rtcc0 {

0 commit comments

Comments
 (0)