1 /*
2  * Copyright (c) 2022 Silicon Labs
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * Silabs SoC specific helpers for pinctrl driver
10  */
11 
12 #ifndef ZEPHYR_SOC_ARM_SILABS_GECKO_COMMON_PINCTRL_SOC_H_
13 #define ZEPHYR_SOC_ARM_SILABS_GECKO_COMMON_PINCTRL_SOC_H_
14 
15 #include <stdint.h>
16 
17 #include <zephyr/devicetree.h>
18 #if CONFIG_SOC_GECKO_SERIES1
19 #include <zephyr/dt-bindings/pinctrl/gecko-pinctrl-s1.h>
20 #else
21 #include <zephyr/dt-bindings/pinctrl/gecko-pinctrl.h>
22 #endif
23 
24 #ifdef __cplusplus
25 extern "C" {
26 #endif
27 
28 /** @cond INTERNAL_HIDDEN */
29 
30 /** Type for gecko pin. */
31 typedef uint32_t pinctrl_soc_pin_t;
32 
33 /**
34  * @brief Utility macro to initialize each pin.
35  *
36  * @param node_id Node identifier.
37  * @param prop Property name.
38  * @param idx Property entry index.
39  */
40 #define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx) (DT_PROP_BY_IDX(node_id, prop, idx)),
41 
42 /**
43  * @brief Utility macro to initialize state pins contained in a given property.
44  *
45  * @param node_id Node identifier.
46  * @param prop Property name describing state pins.
47  */
48 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop)                                                   \
49 	{                                                                                          \
50 		DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, psels,     \
51 				       Z_PINCTRL_STATE_PIN_INIT)                                   \
52 	}
53 
54 /**
55  * @brief Utility macro to obtain pin function.
56  *
57  * @param pincfg Pin configuration bit field.
58  */
59 #define GECKO_GET_FUN(pincfg) (((pincfg) >> GECKO_FUN_POS) & GECKO_FUN_MSK)
60 
61 /**
62  * @brief Utility macro to obtain port configuration.
63  *
64  * @param pincfg port configuration bit field.
65  */
66 #define GECKO_GET_PORT(pincfg) (((pincfg) >> GECKO_PORT_POS) & GECKO_PORT_MSK)
67 
68 /**
69  * @brief Utility macro to obtain pin configuration.
70  *
71  * @param pincfg pin configuration bit field.
72  */
73 #define GECKO_GET_PIN(pincfg) (((pincfg) >> GECKO_PIN_POS) & GECKO_PIN_MSK)
74 
75 /**
76  * @brief Utility macro to obtain location configuration.
77  *
78  * @param pincfg Loc configuration bit field.
79  */
80 #define GECKO_GET_LOC(pincfg) (((pincfg) >> GECKO_LOC_POS) & GECKO_LOC_MSK)
81 
82 /**
83  * @brief Utility macro to obtain speed configuration.
84  *
85  * @param pincfg speed configuration bit field.
86  */
87 #define GECKO_GET_SPEED(pincfg) (((pincfg) >> GECKO_SPEED_POS) & GECKO_SPEED_MSK)
88 
89 /** @endcond */
90 
91 #ifdef __cplusplus
92 }
93 #endif
94 
95 #endif /* ZEPHYR_SOC_ARM_SILABS_GECKO_COMMON_PINCTRL_SOC_H_ */
96