1 /*
2  * Copyright (c) 2023 Nuvoton Technology Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef _NUVOTON_NUMAKER_PINCTRL_SOC_H_
8 #define _NUVOTON_NUMAKER_PINCTRL_SOC_H_
9 
10 #include <zephyr/devicetree.h>
11 #include <stdint.h>
12 
13 #define PORT_INDEX(pinmux)    (((pinmux)&0xF0000000) >> 28)
14 #define PIN_INDEX(pinmux)     (((pinmux)&0x0F000000) >> 24)
15 #define MFP_CFG(pinmux)       (((pinmux)&0x000000FF) << ((PIN_INDEX(pinmux) % 4) * 8))
16 #define NU_MFP_POS(pinindex)  ((pinindex % 4) * 8)
17 #define NU_MFP_MASK(pinindex) (0x1f << NU_MFP_POS(pinindex))
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 typedef struct pinctrl_soc_pin_t {
24 	uint32_t pin_mux;
25 	uint32_t open_drain: 1;
26 	uint32_t schmitt_enable: 1;
27 	uint32_t slew_rate: 2;
28 } pinctrl_soc_pin_t;
29 
30 #define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx)						\
31 	{											\
32 		.pin_mux = DT_PROP_BY_IDX(node_id, prop, idx),					\
33 		.open_drain = DT_PROP(node_id, drive_open_drain),				\
34 		.schmitt_enable = DT_PROP(node_id, input_schmitt_enable),			\
35 		.slew_rate = DT_ENUM_IDX(node_id, slew_rate),					\
36 	},
37 
38 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop)						\
39 	{											\
40 		DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop), DT_FOREACH_PROP_ELEM, pinmux,	\
41 					Z_PINCTRL_STATE_PIN_INIT)				\
42 	}
43 
44 #ifdef __cplusplus
45 }
46 #endif
47 
48 #endif /* _NUVOTON_NUMAKER_PINCTRL_SOC_H_ */
49