1 /*
2  * Copyright (c) 2019 Peter Bigot Consulting, LLC
3  * Copyright (c) 2019 Foundries.io
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 #include <zephyr/init.h>
9 #include <zephyr/drivers/gpio.h>
10 
11 #define SKY_UFLn_GPIO_SPEC	GPIO_DT_SPEC_GET(DT_NODELABEL(sky13351), vctl1_gpios)
12 #define SKY_PCBn_GPIO_SPEC	GPIO_DT_SPEC_GET(DT_NODELABEL(sky13351), vctl2_gpios)
13 
external_antenna(bool on)14 static inline void external_antenna(bool on)
15 {
16 	struct gpio_dt_spec ufl_gpio = SKY_UFLn_GPIO_SPEC;
17 	struct gpio_dt_spec pcb_gpio = SKY_PCBn_GPIO_SPEC;
18 
19 	if (!gpio_is_ready_dt(&ufl_gpio)) {
20 		return;
21 	}
22 
23 	if (!gpio_is_ready_dt(&pcb_gpio)) {
24 		return;
25 	}
26 
27 	gpio_pin_configure_dt(&ufl_gpio, (on ? GPIO_OUTPUT_ACTIVE : GPIO_OUTPUT_INACTIVE));
28 	gpio_pin_configure_dt(&pcb_gpio, (on ? GPIO_OUTPUT_INACTIVE : GPIO_OUTPUT_ACTIVE));
29 }
30 
board_particle_argon_init(void)31 static int board_particle_argon_init(void)
32 {
33 
34 	/*
35 	 * On power-up the SKY13351 is left uncontrolled, so neither
36 	 * PCB nor external antenna is selected.  Select the PCB
37 	 * antenna.
38 	 */
39 	external_antenna(false);
40 
41 	return 0;
42 }
43 
44 /* needs to be done after GPIO driver init, which is at
45  * POST_KERNEL:KERNEL_INIT_PRIORITY_DEFAULT.
46  */
47 SYS_INIT(board_particle_argon_init, POST_KERNEL, 99);
48