1 /*
2  * Copyright (c) 2023-2024 Analog Devices, Inc.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_SOC_ARM_ADI_MAX32_COMMON_PINCTRL_SOC_H_
8 #define ZEPHYR_SOC_ARM_ADI_MAX32_COMMON_PINCTRL_SOC_H_
9 
10 #include <zephyr/devicetree.h>
11 #include <zephyr/types.h>
12 
13 #include <zephyr/dt-bindings/pinctrl/max32-pinctrl.h>
14 
15 #ifdef __cplusplus
16 extern "C" {
17 #endif
18 
19 typedef struct pinctrl_soc_pin {
20 	uint32_t pinmux;
21 	uint32_t pincfg;
22 } pinctrl_soc_pin_t;
23 
24 #define Z_PINCTRL_MAX32_PINMUX_INIT(node_id) DT_PROP(node_id, pinmux)
25 
26 #define Z_PINCTRL_MAX32_PINCFG_INIT(node)                                                          \
27 	((DT_PROP_OR(node, input_enable, 0) << MAX32_INPUT_ENABLE_SHIFT) |                         \
28 	 (DT_PROP_OR(node, output_enable, 0) << MAX32_OUTPUT_ENABLE_SHIFT) |                       \
29 	 (DT_PROP_OR(node, bias_pull_up, 0) << MAX32_BIAS_PULL_UP_SHIFT) |                         \
30 	 (DT_PROP_OR(node, bias_pull_down, 0) << MAX32_BIAS_PULL_DOWN_SHIFT) |                     \
31 	 (DT_PROP_OR(node, power_source, 0) << MAX32_POWER_SOURCE_SHIFT) |                         \
32 	 (DT_PROP_OR(node, output_high, 0) << MAX32_OUTPUT_HIGH_SHIFT) |                           \
33 	 (DT_PROP_OR(node, drive_strength, 0) << MAX32_DRV_STRENGTH_SHIFT))
34 
35 #define Z_PINCTRL_STATE_PIN_INIT(node_id, state_prop, idx)                                         \
36 	{.pinmux = Z_PINCTRL_MAX32_PINMUX_INIT(DT_PROP_BY_IDX(node_id, state_prop, idx)),          \
37 	 .pincfg = Z_PINCTRL_MAX32_PINCFG_INIT(DT_PROP_BY_IDX(node_id, state_prop, idx))},
38 
39 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop)                                                   \
40 	{                                                                                          \
41 		DT_FOREACH_PROP_ELEM(node_id, prop, Z_PINCTRL_STATE_PIN_INIT)                      \
42 	}
43 
44 #ifdef __cplusplus
45 }
46 #endif
47 
48 #endif /* ZEPHYR_SOC_ARM_ADI_MAX32_COMMON_PINCTRL_SOC_H_ */
49