1 /*
2 * Copyright (c) 2021 Sateesh Kotapati
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 #include <zephyr/logging/log.h>
11
12 #ifdef CONFIG_SOC_GECKO_DEV_INIT
13 #include "em_cmu.h"
14 #endif
15
16 LOG_MODULE_REGISTER(efr32xg24_dk2601b, CONFIG_BOARD_EFR32MG24_LOG_LEVEL);
17
18 static int efr32xg24_dk2601b_init_clocks(void);
19
efr32xg24_dk2601b_init(void)20 static int efr32xg24_dk2601b_init(void)
21 {
22 int ret;
23
24 #ifdef CONFIG_SOC_GECKO_DEV_INIT
25 efr32xg24_dk2601b_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
efr32xg24_dk2601b_init_clocks(void)43 static int efr32xg24_dk2601b_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 CMU_ClockSelectSet(cmuClock_EM4GRPACLK, cmuSelect_LFRCO);
54 #if defined(RTCC_PRESENT)
55 CMU_ClockSelectSet(cmuClock_RTCC, cmuSelect_LFRCO);
56 #endif
57 #if defined(SYSRTC_PRESENT)
58 CMU_ClockSelectSet(cmuClock_SYSRTC, cmuSelect_LFRCO);
59 #endif
60 CMU_ClockSelectSet(cmuClock_WDOG0, cmuSelect_LFRCO);
61 #if WDOG_COUNT > 1
62 CMU_ClockSelectSet(cmuClock_WDOG1, cmuSelect_LFRCO);
63 #endif
64
65 return 0;
66 }
67 #endif
68
69 /* needs to be done after GPIO driver init */
70 SYS_INIT(efr32xg24_dk2601b_init, POST_KERNEL, CONFIG_KERNEL_INIT_PRIORITY_DEVICE);
71