1 /*
2  * Copyright (c) 2020 Linaro Limited
3  * Copyright (c) 2021 ATL Electronics
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 #ifndef PINCTRL_CYPRESS_PSOC6_H_
8 #define PINCTRL_CYPRESS_PSOC6_H_
9 
10 #include <zephyr/dt-bindings/dt-util.h>
11 
12 /**
13  * Functions are defined using HSIOM SEL
14  */
15 
16 #define HSIOM_SEL_gpio          0
17 #define HSIOM_SEL_gpio_dsi      1
18 #define HSIOM_SEL_dsi_dsi       2
19 #define HSIOM_SEL_dsi_gpio      3
20 #define HSIOM_SEL_amuxa         4
21 #define HSIOM_SEL_amuxb         5
22 #define HSIOM_SEL_amuxa_dsi     6
23 #define HSIOM_SEL_amuxb_dsi     7
24 #define HSIOM_SEL_act_0         8
25 #define HSIOM_SEL_act_1         9
26 #define HSIOM_SEL_act_2        10
27 #define HSIOM_SEL_act_3        11
28 #define HSIOM_SEL_ds_0         12
29 #define HSIOM_SEL_ds_1         13
30 #define HSIOM_SEL_ds_2         14
31 #define HSIOM_SEL_ds_3         15
32 #define HSIOM_SEL_act_4        16
33 #define HSIOM_SEL_act_5        17
34 #define HSIOM_SEL_act_6        18
35 #define HSIOM_SEL_act_7        19
36 #define HSIOM_SEL_act_8        20
37 #define HSIOM_SEL_act_9        21
38 #define HSIOM_SEL_act_10       22
39 #define HSIOM_SEL_act_11       23
40 #define HSIOM_SEL_act_12       24
41 #define HSIOM_SEL_act_13       25
42 #define HSIOM_SEL_act_14       26
43 #define HSIOM_SEL_act_15       27
44 #define HSIOM_SEL_ds_4         28
45 #define HSIOM_SEL_ds_5         29
46 #define HSIOM_SEL_ds_6         30
47 #define HSIOM_SEL_ds_7         31
48 
49 
50 /* Create a pincfg device tree node:
51  *
52  * The node name and nodelabel will be of the form:
53  *
54  * NODE = p<port>_<pin>_<inst>_<signal>
55  *
56  * NODE: NODE {
57  *	cypress,pins = < &gpio_prt<port> <pin> HSIOM_SEL_<hsiom> >;
58  *	flags_1;
59  *	  ...
60  *	flags_N;
61  * }
62  *
63  * So for example:
64  *
65  * DT_CYPRESS_PIN(uart5, rx, 5, 0, act_6);
66  *
67  * Will become:
68  *
69  * p5_0_uart5_rx: p5_0_uart5_rx {
70  *    cypress,pins = <&gpio_prt5 0x0 0x12 >;
71  * }
72  *
73  * Flags are optional and should be pass one by one as arguments:
74  *
75  * DT_CYPRESS_PIN(uart5, rx, 5, 0, act_6, bias-pull-up, input-enable);
76  *
77  * Will become:
78  *
79  * p5_0_uart5_rx: p5_0_uart5_rx {
80  *    cypress,pins = <&gpio_prt5 0x0 0x12 >;
81  *    bias-pull-up;
82  *    input-enable;
83  * }
84  *
85  * For the complete list of flags see cypress,psoc6-pinctrl.yaml
86  *
87  */
88 
89 #define DT_CYPRESS_HSIOM_FLAG(flag) flag;
90 #define DT_CYPRESS_HSIOM_FLAGS(...) \
91 	MACRO_MAP_CAT(DT_CYPRESS_HSIOM_FLAG __VA_OPT__(,) __VA_ARGS__)
92 
93 #define DT_CYPRESS_HSIOM(inst, signal, port, pin, hsiom, ...) \
94 	p##port##_##pin##_##inst##_##signal: \
95 	p##port##_##pin##_##inst##_##signal { \
96 	cypress,pins = < &gpio_prt##port pin HSIOM_SEL_##hsiom > ; \
97 		DT_CYPRESS_HSIOM_FLAGS(__VA_ARGS__) \
98 	}
99 
100 #endif /* PINCTRL_CYPRESS_PSOC6_H_ */
101