1 /*
2  * Copyright (c) 2023 Nordic Semiconductor ASA
3  * SPDX-License-Identifier: Apache-2.0
4  */
5 
6 #ifndef ZEPHYR_SOC_ARM_TI_SIMPLELINK_CC32XX_PINCTRL_SOC_H_
7 #define ZEPHYR_SOC_ARM_TI_SIMPLELINK_CC32XX_PINCTRL_SOC_H_
8 
9 #include <stdint.h>
10 
11 #include <zephyr/devicetree.h>
12 #include <zephyr/sys/util.h>
13 
14 #ifdef __cplusplus
15 extern "C" {
16 #endif
17 
18 /** @cond INTERNAL_HIDDEN */
19 
20 /** Type for TI CC32XX pin. */
21 typedef uint32_t pinctrl_soc_pin_t;
22 
23 /**
24  * @name TI CC32XX pin configuration bit field positions and masks.
25  */
26 
27 #define TI_CC32XX_OPEN_DRAIN           BIT(4)
28 #define TI_CC32XX_DRIVE_STRENGTH_MSK   0x7U
29 #define TI_CC32XX_DRIVE_STRENGTH_POS   5U
30 #define TI_CC32XX_PULL_UP              BIT(8)
31 #define TI_CC32XX_PULL_DOWN            BIT(9)
32 #define TI_CC32XX_PAD_OUT_OVERRIDE     BIT(10)
33 #define TI_CC32XX_PAD_OUT_BUF_OVERRIDE BIT(11)
34 
35 /** @} */
36 
37 /**
38  * @brief Utility macro to initialize each pin.
39  *
40  * @param node_id Node identifier.
41  * @param prop Property name.
42  * @param idx Property entry index.
43  */
44 #define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx)                                               \
45 	(DT_PROP_BY_IDX(node_id, prop, idx) |                                                      \
46 	 (TI_CC32XX_OPEN_DRAIN * DT_PROP(node_id, drive_open_drain)) |                             \
47 	 (TI_CC32XX_PULL_UP * DT_PROP(node_id, bias_pull_down)) |                                  \
48 	 (TI_CC32XX_PULL_DOWN * DT_PROP(node_id, bias_pull_up)) |                                  \
49 	 ((DT_ENUM_IDX(node_id, drive_strength) & TI_CC32XX_DRIVE_STRENGTH_MSK)                    \
50 	  << TI_CC32XX_DRIVE_STRENGTH_POS) |                                                       \
51 	 TI_CC32XX_PAD_OUT_OVERRIDE | TI_CC32XX_PAD_OUT_BUF_OVERRIDE),
52 
53 /**
54  * @brief Utility macro to initialize state pins contained in a given property.
55  *
56  * @param node_id Node identifier.
57  * @param prop Property name describing state pins.
58  */
59 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop)                                                   \
60 	{                                                                                          \
61 		DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux,    \
62 				       Z_PINCTRL_STATE_PIN_INIT)                                   \
63 	}
64 
65 /** @endcond */
66 
67 #ifdef __cplusplus
68 }
69 #endif
70 
71 #endif /* ZEPHYR_SOC_ARM_TI_SIMPLELINK_CC32XX_PINCTRL_SOC_H_ */
72