1 /*
2 * Copyright (c) 2020 Christian Taedcke
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/init.h>
8 #include <zephyr/drivers/gpio.h>
9 #include <zephyr/sys/printk.h>
10
11 struct supply_cfg {
12 const struct device *gpio;
13 gpio_pin_t pin;
14 gpio_dt_flags_t flags;
15 };
16
enable_supply(const struct supply_cfg * cfg)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
efr32mg_sltb004a_init(void)31 static int efr32mg_sltb004a_init(void)
32 {
33 struct supply_cfg cfg;
34 int rc = 0;
35
36 (void)cfg;
37
38 #define CCS811 DT_NODELABEL(ccs811)
39
40 #if DT_NODE_HAS_STATUS_OKAY(CCS811)
41 cfg = (struct supply_cfg){
42 .gpio = DEVICE_DT_GET(DT_GPIO_CTLR(CCS811, supply_gpios)),
43 .pin = DT_GPIO_PIN(CCS811, supply_gpios),
44 .flags = DT_GPIO_FLAGS(CCS811, supply_gpios),
45 };
46
47 /* Enable the CCS811 power */
48 rc = enable_supply(&cfg);
49 if (rc < 0) {
50 printk("CCS811 supply not enabled: %d\n", rc);
51 }
52 #endif
53
54 return rc;
55 }
56
57 /* needs to be done after GPIO driver init */
58 SYS_INIT(efr32mg_sltb004a_init, POST_KERNEL,
59 CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
60