1 /*
2  * Copyright (c) 2022 Telink Semiconductor
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef SOC_RISCV_TELINK_B91_PINCTRL_SOC_H
8 #define SOC_RISCV_TELINK_B91_PINCTRL_SOC_H
9 
10 #include <stdint.h>
11 #include <zephyr/devicetree.h>
12 #include <zephyr/dt-bindings/pinctrl/b91-pinctrl.h>
13 
14 /**
15  * @brief Telink B91 pin type.
16  */
17 typedef uint32_t pinctrl_soc_pin_t;
18 
19 /**
20  * @brief Utility macro to initialize each pin.
21  *
22  * @param node_id Node identifier.
23  * @param prop Property name.
24  * @param idx Property entry index.
25  */
26 #define Z_PINCTRL_STATE_PIN_INIT(node_id, prop, idx)					\
27 	(DT_PROP(DT_PROP_BY_IDX(node_id, prop, idx), pinmux) |				\
28 	 ((B91_PULL_DOWN * DT_PROP(DT_PROP_BY_IDX(node_id, prop, idx), bias_pull_down))	\
29 		<< B91_PULL_POS) |							\
30 	 ((B91_PULL_UP * DT_PROP(DT_PROP_BY_IDX(node_id, prop, idx), bias_pull_up))	\
31 		<< B91_PULL_POS)							\
32 	),
33 
34 /**
35  * @brief Utility macro to initialize state pins contained in a given property.
36  *
37  * @param node_id Node identifier.
38  * @param prop Property name describing state pins.
39  */
40 #define Z_PINCTRL_STATE_PINS_INIT(node_id, prop) \
41 	{ DT_FOREACH_PROP_ELEM(node_id, prop, Z_PINCTRL_STATE_PIN_INIT) }
42 
43 #endif  /* SOC_RISCV_TELINK_B91_PINCTRL_SOC_H */
44