1 /*
2  * Copyright (c) 2022 Renesas Electronics Corporation
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef ZEPHYR_SOC_ARM_RENESAS_SMARTBOND_DA1469X_PINCTRL_SOC_H_
8 #define ZEPHYR_SOC_ARM_RENESAS_SMARTBOND_DA1469X_PINCTRL_SOC_H_
9 
10 #include <zephyr/dt-bindings/pinctrl/smartbond-pinctrl.h>
11 
12 struct smartbond_pinctrl_soc_pin {
13 	uint32_t func : 6;
14 	uint32_t port : 1;
15 	uint32_t pin : 5;
16 	uint32_t bias_pull_up : 1;
17 	uint32_t bias_pull_down : 1;
18 	uint32_t output_enable : 1;
19 	uint32_t input_enable : 1;
20 };
21 
22 typedef struct smartbond_pinctrl_soc_pin pinctrl_soc_pin_t;
23 
24 #define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx)			\
25 	{								\
26 		SMARTBOND_GET_FUNC(DT_PROP_BY_IDX(node_id, prop, idx)),	\
27 		SMARTBOND_GET_PORT(DT_PROP_BY_IDX(node_id, prop, idx)),	\
28 		SMARTBOND_GET_PIN(DT_PROP_BY_IDX(node_id, prop, idx)),	\
29 		DT_PROP(node_id, bias_pull_up),				\
30 		DT_PROP(node_id, bias_pull_down),			\
31 		DT_PROP(node_id, output_enable),			\
32 		DT_PROP(node_id, input_enable),				\
33 	},
34 
35 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop)			\
36 	{DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop),		\
37 				DT_FOREACH_PROP_ELEM, pinmux,		\
38 				Z_PINCTRL_STATE_PIN_INIT)}
39 
40 #define SMARTBOND_GET_FUNC(pinmux) \
41 	(((pinmux) >> SMARTBOND_PINMUX_FUNC_POS) & SMARTBOND_PINMUX_FUNC_MASK)
42 #define SMARTBOND_GET_PORT(pinmux) \
43 	(((pinmux) >> SMARTBOND_PINMUX_PORT_POS) & SMARTBOND_PINMUX_PORT_MASK)
44 #define SMARTBOND_GET_PIN(pinmux) \
45 	(((pinmux) >> SMARTBOND_PINMUX_PIN_POS) & SMARTBOND_PINMUX_PIN_MASK)
46 
47 #endif /* ZEPHYR_SOC_ARM_RENESAS_SMARTBOND_DA1469X_PINCTRL_SOC_H_ */
48