1 /* SPDX-License-Identifier: GPL-2.0+ */
2 /*
3  * Copyright (C) 2009 by Jan Weitzel Phytec Messtechnik GmbH,
4  *			<armlinux@phytec.de>
5  * Copyright (C) 2010 Freescale Semiconductor, Inc. All Rights Reserved.
6  */
7 
8 #ifndef __MACH_MXS_IOMUX_H__
9 #define __MACH_MXS_IOMUX_H__
10 
11 #ifndef __ASSEMBLY__
12 
13 #include <asm/types.h>
14 
15 /*
16  * IOMUX/PAD Bit field definitions
17  *
18  * PAD_BANK:		 0..2	(3)
19  * PAD_PIN:		 3..7	(5)
20  * PAD_MUXSEL:		 8..9	(2)
21  * PAD_MA:		10..11	(2)
22  * PAD_MA_VALID:	12	(1)
23  * PAD_VOL:		13	(1)
24  * PAD_VOL_VALID:	14	(1)
25  * PAD_PULL:		15	(1)
26  * PAD_PULL_VALID:	16	(1)
27  * RESERVED:		17..31	(15)
28  */
29 typedef u32 iomux_cfg_t;
30 
31 #define MXS_PAD_BANK_SHIFT	0
32 #define MXS_PAD_BANK_MASK	((iomux_cfg_t)0x7 << MXS_PAD_BANK_SHIFT)
33 #define MXS_PAD_PIN_SHIFT	3
34 #define MXS_PAD_PIN_MASK	((iomux_cfg_t)0x1f << MXS_PAD_PIN_SHIFT)
35 #define MXS_PAD_MUXSEL_SHIFT	8
36 #define MXS_PAD_MUXSEL_MASK	((iomux_cfg_t)0x3 << MXS_PAD_MUXSEL_SHIFT)
37 #define MXS_PAD_MA_SHIFT	10
38 #define MXS_PAD_MA_MASK		((iomux_cfg_t)0x3 << MXS_PAD_MA_SHIFT)
39 #define MXS_PAD_MA_VALID_SHIFT	12
40 #define MXS_PAD_MA_VALID_MASK	((iomux_cfg_t)0x1 << MXS_PAD_MA_VALID_SHIFT)
41 #define MXS_PAD_VOL_SHIFT	13
42 #define MXS_PAD_VOL_MASK	((iomux_cfg_t)0x1 << MXS_PAD_VOL_SHIFT)
43 #define MXS_PAD_VOL_VALID_SHIFT	14
44 #define MXS_PAD_VOL_VALID_MASK	((iomux_cfg_t)0x1 << MXS_PAD_VOL_VALID_SHIFT)
45 #define MXS_PAD_PULL_SHIFT	15
46 #define MXS_PAD_PULL_MASK	((iomux_cfg_t)0x1 << MXS_PAD_PULL_SHIFT)
47 #define MXS_PAD_PULL_VALID_SHIFT 16
48 #define MXS_PAD_PULL_VALID_MASK	((iomux_cfg_t)0x1 << MXS_PAD_PULL_VALID_SHIFT)
49 
50 #define PAD_MUXSEL_0		0
51 #define PAD_MUXSEL_1		1
52 #define PAD_MUXSEL_2		2
53 #define PAD_MUXSEL_GPIO		3
54 
55 #define PAD_4MA			0
56 #define PAD_8MA			1
57 #define PAD_12MA		2
58 #define PAD_16MA		3
59 
60 #define PAD_1V8			0
61 #if defined(CONFIG_MX28)
62 #define PAD_3V3			1
63 #else
64 #define PAD_3V3			0
65 #endif
66 
67 #define PAD_NOPULL		0
68 #define PAD_PULLUP		1
69 
70 #define MXS_PAD_4MA	((PAD_4MA << MXS_PAD_MA_SHIFT) | \
71 					MXS_PAD_MA_VALID_MASK)
72 #define MXS_PAD_8MA	((PAD_8MA << MXS_PAD_MA_SHIFT) | \
73 					MXS_PAD_MA_VALID_MASK)
74 #define MXS_PAD_12MA	((PAD_12MA << MXS_PAD_MA_SHIFT) | \
75 					MXS_PAD_MA_VALID_MASK)
76 #define MXS_PAD_16MA	((PAD_16MA << MXS_PAD_MA_SHIFT) | \
77 					MXS_PAD_MA_VALID_MASK)
78 
79 #define MXS_PAD_1V8	((PAD_1V8 << MXS_PAD_VOL_SHIFT) | \
80 					MXS_PAD_VOL_VALID_MASK)
81 #define MXS_PAD_3V3	((PAD_3V3 << MXS_PAD_VOL_SHIFT) | \
82 					MXS_PAD_VOL_VALID_MASK)
83 
84 #define MXS_PAD_NOPULL	((PAD_NOPULL << MXS_PAD_PULL_SHIFT) | \
85 					MXS_PAD_PULL_VALID_MASK)
86 #define MXS_PAD_PULLUP	((PAD_PULLUP << MXS_PAD_PULL_SHIFT) | \
87 					MXS_PAD_PULL_VALID_MASK)
88 
89 /* generic pad control used in most cases */
90 #define MXS_PAD_CTRL	(MXS_PAD_4MA | MXS_PAD_3V3 | MXS_PAD_NOPULL)
91 
92 #define MXS_IOMUX_PAD(_bank, _pin, _muxsel, _ma, _vol, _pull)		\
93 		(((iomux_cfg_t)(_bank) << MXS_PAD_BANK_SHIFT) |		\
94 		((iomux_cfg_t)(_pin) << MXS_PAD_PIN_SHIFT) |		\
95 		((iomux_cfg_t)(_muxsel) << MXS_PAD_MUXSEL_SHIFT) |	\
96 		((iomux_cfg_t)(_ma) << MXS_PAD_MA_SHIFT) |		\
97 		((iomux_cfg_t)(_vol) << MXS_PAD_VOL_SHIFT) |		\
98 		((iomux_cfg_t)(_pull) << MXS_PAD_PULL_SHIFT))
99 
100 /*
101  * A pad becomes naked, when none of mA, vol or pull
102  * validity bits is set.
103  */
104 #define MXS_IOMUX_PAD_NAKED(_bank, _pin, _muxsel) \
105 		MXS_IOMUX_PAD(_bank, _pin, _muxsel, 0, 0, 0)
106 
PAD_BANK(iomux_cfg_t pad)107 static inline unsigned int PAD_BANK(iomux_cfg_t pad)
108 {
109 	return (pad & MXS_PAD_BANK_MASK) >> MXS_PAD_BANK_SHIFT;
110 }
111 
PAD_PIN(iomux_cfg_t pad)112 static inline unsigned int PAD_PIN(iomux_cfg_t pad)
113 {
114 	return (pad & MXS_PAD_PIN_MASK) >> MXS_PAD_PIN_SHIFT;
115 }
116 
PAD_MUXSEL(iomux_cfg_t pad)117 static inline unsigned int PAD_MUXSEL(iomux_cfg_t pad)
118 {
119 	return (pad & MXS_PAD_MUXSEL_MASK) >> MXS_PAD_MUXSEL_SHIFT;
120 }
121 
PAD_MA(iomux_cfg_t pad)122 static inline unsigned int PAD_MA(iomux_cfg_t pad)
123 {
124 	return (pad & MXS_PAD_MA_MASK) >> MXS_PAD_MA_SHIFT;
125 }
126 
PAD_MA_VALID(iomux_cfg_t pad)127 static inline unsigned int PAD_MA_VALID(iomux_cfg_t pad)
128 {
129 	return (pad & MXS_PAD_MA_VALID_MASK) >> MXS_PAD_MA_VALID_SHIFT;
130 }
131 
PAD_VOL(iomux_cfg_t pad)132 static inline unsigned int PAD_VOL(iomux_cfg_t pad)
133 {
134 	return (pad & MXS_PAD_VOL_MASK) >> MXS_PAD_VOL_SHIFT;
135 }
136 
PAD_VOL_VALID(iomux_cfg_t pad)137 static inline unsigned int PAD_VOL_VALID(iomux_cfg_t pad)
138 {
139 	return (pad & MXS_PAD_VOL_VALID_MASK) >> MXS_PAD_VOL_VALID_SHIFT;
140 }
141 
PAD_PULL(iomux_cfg_t pad)142 static inline unsigned int PAD_PULL(iomux_cfg_t pad)
143 {
144 	return (pad & MXS_PAD_PULL_MASK) >> MXS_PAD_PULL_SHIFT;
145 }
146 
PAD_PULL_VALID(iomux_cfg_t pad)147 static inline unsigned int PAD_PULL_VALID(iomux_cfg_t pad)
148 {
149 	return (pad & MXS_PAD_PULL_VALID_MASK) >> MXS_PAD_PULL_VALID_SHIFT;
150 }
151 
152 /*
153  * configures a single pad in the iomuxer
154  */
155 int mxs_iomux_setup_pad(iomux_cfg_t pad);
156 
157 /*
158  * configures multiple pads
159  * convenient way to call the above function with tables
160  */
161 int mxs_iomux_setup_multiple_pads(const iomux_cfg_t *pad_list, unsigned count);
162 
163 #endif /* __ASSEMBLY__ */
164 #endif /* __MACH_MXS_IOMUX_H__*/
165