1 /*
2  * Copyright (c) 2024 Norik Systems
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #include <zephyr/init.h>
7 #include <zephyr/device.h>
8 #include <zephyr/devicetree.h>
9 #include <zephyr/drivers/gpio.h>
10 #include <zephyr/logging/log.h>
11 
12 LOG_MODULE_REGISTER(board_control, CONFIG_OCTOPUS_IO_BOARD_CONTROL_LOG_LEVEL);
13 
14 #define SIM_SELECT_NODE DT_PATH(sim_select)
15 
board_late_init_hook(void)16 void board_late_init_hook(void)
17 {
18 	const struct gpio_dt_spec simctrl = GPIO_DT_SPEC_GET(DT_PATH(sim_select), sim_gpios);
19 
20 	if (!gpio_is_ready_dt(&simctrl)) {
21 		LOG_ERR("SIM select GPIO not available");
22 		return;
23 	}
24 
25 	if (DT_ENUM_IDX(SIM_SELECT_NODE, sim) == 0) {
26 		(void)gpio_pin_configure_dt(&simctrl, GPIO_OUTPUT_LOW);
27 		LOG_INF("On-board SIM selected");
28 	} else {
29 		(void)gpio_pin_configure_dt(&simctrl, GPIO_OUTPUT_HIGH);
30 		LOG_INF("External SIM selected");
31 	}
32 }
33