1 /*
2  * Copyright (c) 2022 Henrik Brix Andersen <henrik@brixandersen.dk>
3  * Copyright (c) 2022 NXP
4  *
5  * SPDX-License-Identifier: Apache-2.0
6  */
7 
8 /*
9  * @file
10  * OpenISA RV32M1 SOC specific helpers for pinctrl driver
11  */
12 
13 #ifndef ZEPHYR_SOC_RISCV_OPENISA_RV32M1_PINCTRL_SOC_H_
14 #define ZEPHYR_SOC_RISCV_OPENISA_RV32M1_PINCTRL_SOC_H_
15 
16 #include <zephyr/devicetree.h>
17 #include <zephyr/types.h>
18 
19 #ifdef __cplusplus
20 extern "C" {
21 #endif
22 
23 typedef uint32_t pinctrl_soc_pin_t;
24 
25 #define Z_PINCTRL_RV32M1_PINCFG(node_id)					\
26 	(PORT_PCR_PS(DT_PROP(node_id, bias_pull_up)) |				\
27 	PORT_PCR_PE(DT_PROP(node_id, bias_pull_up)) |				\
28 	PORT_PCR_PE(DT_PROP(node_id, bias_pull_down)) |				\
29 	PORT_PCR_ODE(DT_PROP(node_id, drive_open_drain)) |			\
30 	PORT_PCR_SRE(DT_ENUM_IDX(node_id, slew_rate)) |				\
31 	PORT_PCR_PFE(DT_PROP(node_id, openisa_passive_filter)))
32 
33 #define Z_PINCTRL_RV32M1_PCR_MASK						\
34 	(PORT_PCR_MUX_MASK | PORT_PCR_ODE_MASK | PORT_PCR_PFE_MASK |		\
35 	PORT_PCR_SRE_MASK | PORT_PCR_PE_MASK | PORT_PCR_PS_MASK)
36 
37 #define Z_PINCTRL_STATE_PIN_INIT(group, pin_prop, idx)				\
38 	DT_PROP_BY_IDX(group, pin_prop, idx) | Z_PINCTRL_RV32M1_PINCFG(group),
39 
40 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop)				\
41 	{DT_FOREACH_CHILD_VARGS(DT_PHANDLE(node_id, prop),			\
42 		DT_FOREACH_PROP_ELEM, pinmux, Z_PINCTRL_STATE_PIN_INIT)};
43 
44 #ifdef __cplusplus
45 }
46 #endif
47 
48 #endif /* ZEPHYR_SOC_RISCV_OPENISA_RV32M1_PINCTRL_SOC_H_ */
49