1 /*
2 * Copyright (c) 2021 Sateesh Kotapati
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7 #include <zephyr/drivers/gpio.h>
8 #include <zephyr/init.h>
9 #include <zephyr/logging/log.h>
10
11 #ifdef CONFIG_SOC_GECKO_DEV_INIT
12 #include "em_cmu.h"
13 #endif
14
15
16 LOG_MODULE_REGISTER(thunderboard, CONFIG_BOARD_THUNDERBOARD_LOG_LEVEL);
17
18 static int thunderboard_init_clocks(void);
19
thunderboard_init(void)20 static int thunderboard_init(void)
21 {
22 int ret;
23
24 #ifdef CONFIG_SOC_GECKO_DEV_INIT
25 thunderboard_init_clocks();
26 #endif
27 static struct gpio_dt_spec wake_up_gpio_dev =
28 GPIO_DT_SPEC_GET(DT_NODELABEL(wake_up_trigger), gpios);
29
30
31 if (!gpio_is_ready_dt(&wake_up_gpio_dev)) {
32 LOG_ERR("Wake-up GPIO device was not found!\n");
33 return -ENODEV;
34 }
35 ret = gpio_pin_configure_dt(&wake_up_gpio_dev, GPIO_OUTPUT_ACTIVE);
36 if (ret < 0)
37 return ret;
38
39 return 0;
40 }
41
42 #ifdef CONFIG_SOC_GECKO_DEV_INIT
thunderboard_init_clocks(void)43 static int thunderboard_init_clocks(void)
44 {
45 CMU_ClockSelectSet(cmuClock_SYSCLK, cmuSelect_HFRCODPLL);
46 #if defined(_CMU_EM01GRPACLKCTRL_MASK)
47 CMU_ClockSelectSet(cmuClock_EM01GRPACLK, cmuSelect_HFRCODPLL);
48 #endif
49 #if defined(_CMU_EM01GRPBCLKCTRL_MASK)
50 CMU_ClockSelectSet(cmuClock_EM01GRPBCLK, cmuSelect_HFRCODPLL);
51 #endif
52 CMU_ClockSelectSet(cmuClock_EM23GRPACLK, cmuSelect_LFRCO);
53 #if defined(RTCC_PRESENT)
54 CMU_ClockSelectSet(cmuClock_RTCC, cmuSelect_LFRCO);
55 #endif
56 CMU_ClockSelectSet(cmuClock_WDOG0, cmuSelect_LFRCO);
57
58 return 0;
59 }
60 #endif
61
62 /* needs to be done after GPIO driver init */
63 SYS_INIT(thunderboard_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
64