Commit | Line | Data |
---|---|---|
15ac7afe TL |
1 | /* |
2 | * Copyright (C) 2009 Nokia | |
112485e9 | 3 | * Copyright (C) 2009-2010 Texas Instruments |
15ac7afe TL |
4 | * |
5 | * This program is free software; you can redistribute it and/or modify | |
6 | * it under the terms of the GNU General Public License version 2 as | |
7 | * published by the Free Software Foundation. | |
8 | */ | |
9 | ||
fc440461 | 10 | #include "mux2420.h" |
89ba1092 | 11 | #include "mux2430.h" |
ddaa912a TL |
12 | #include "mux34xx.h" |
13 | ||
15ac7afe TL |
14 | #define OMAP_MUX_TERMINATOR 0xffff |
15 | ||
16 | /* 34xx mux mode options for each pin. See TRM for options */ | |
17 | #define OMAP_MUX_MODE0 0 | |
18 | #define OMAP_MUX_MODE1 1 | |
19 | #define OMAP_MUX_MODE2 2 | |
20 | #define OMAP_MUX_MODE3 3 | |
21 | #define OMAP_MUX_MODE4 4 | |
22 | #define OMAP_MUX_MODE5 5 | |
23 | #define OMAP_MUX_MODE6 6 | |
24 | #define OMAP_MUX_MODE7 7 | |
25 | ||
26 | /* 24xx/34xx mux bit defines */ | |
27 | #define OMAP_PULL_ENA (1 << 3) | |
28 | #define OMAP_PULL_UP (1 << 4) | |
29 | #define OMAP_ALTELECTRICALSEL (1 << 5) | |
30 | ||
31 | /* 34xx specific mux bit defines */ | |
32 | #define OMAP_INPUT_EN (1 << 8) | |
33 | #define OMAP_OFF_EN (1 << 9) | |
34 | #define OMAP_OFFOUT_EN (1 << 10) | |
35 | #define OMAP_OFFOUT_VAL (1 << 11) | |
36 | #define OMAP_OFF_PULL_EN (1 << 12) | |
37 | #define OMAP_OFF_PULL_UP (1 << 13) | |
38 | #define OMAP_WAKEUP_EN (1 << 14) | |
39 | ||
a041a52c BC |
40 | /* 44xx specific mux bit defines */ |
41 | #define OMAP_WAKEUP_EVENT (1 << 15) | |
42 | ||
15ac7afe TL |
43 | /* Active pin states */ |
44 | #define OMAP_PIN_OUTPUT 0 | |
45 | #define OMAP_PIN_INPUT OMAP_INPUT_EN | |
46 | #define OMAP_PIN_INPUT_PULLUP (OMAP_PULL_ENA | OMAP_INPUT_EN \ | |
47 | | OMAP_PULL_UP) | |
48 | #define OMAP_PIN_INPUT_PULLDOWN (OMAP_PULL_ENA | OMAP_INPUT_EN) | |
49 | ||
50 | /* Off mode states */ | |
51 | #define OMAP_PIN_OFF_NONE 0 | |
52 | #define OMAP_PIN_OFF_OUTPUT_HIGH (OMAP_OFF_EN | OMAP_OFFOUT_EN \ | |
53 | | OMAP_OFFOUT_VAL) | |
54 | #define OMAP_PIN_OFF_OUTPUT_LOW (OMAP_OFF_EN | OMAP_OFFOUT_EN) | |
55 | #define OMAP_PIN_OFF_INPUT_PULLUP (OMAP_OFF_EN | OMAP_OFF_PULL_EN \ | |
56 | | OMAP_OFF_PULL_UP) | |
57 | #define OMAP_PIN_OFF_INPUT_PULLDOWN (OMAP_OFF_EN | OMAP_OFF_PULL_EN) | |
58 | #define OMAP_PIN_OFF_WAKEUPENABLE OMAP_WAKEUP_EN | |
59 | ||
421e8450 OM |
60 | #define OMAP_MODE_GPIO(partition, x) (((x) & OMAP_MUX_MODE7) == \ |
61 | partition->gpio) | |
91930652 | 62 | #define OMAP_MODE_UART(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE0) |
15ac7afe | 63 | |
112485e9 | 64 | /* Flags for omapX_mux_init */ |
15ac7afe | 65 | #define OMAP_PACKAGE_MASK 0xffff |
6dd8a682 TL |
66 | #define OMAP_PACKAGE_CBP 6 /* 515-pin 0.40 0.50 */ |
67 | #define OMAP_PACKAGE_CUS 5 /* 423-pin 0.65 */ | |
68 | #define OMAP_PACKAGE_CBB 4 /* 515-pin 0.40 0.50 */ | |
69 | #define OMAP_PACKAGE_CBC 3 /* 515-pin 0.50 0.65 */ | |
70 | #define OMAP_PACKAGE_ZAC 2 /* 24xx 447-pin POP */ | |
71 | #define OMAP_PACKAGE_ZAF 1 /* 2420 447-pin SIP */ | |
15ac7afe TL |
72 | |
73 | ||
112485e9 BC |
74 | #define OMAP_MUX_NR_MODES 8 /* Available modes */ |
75 | #define OMAP_MUX_NR_SIDES 2 /* Bottom & top */ | |
76 | ||
77 | /* | |
78 | * omap_mux_init flags definition: | |
79 | * | |
421e8450 OM |
80 | * OMAP_GPIO_MUX_MODE, bits 0-2: gpio muxing mode, same like pad control |
81 | * register which includes values from 0-7. | |
112485e9 BC |
82 | * OMAP_MUX_REG_8BIT: Ensure that access to padconf is done in 8 bits. |
83 | * The default value is 16 bits. | |
112485e9 | 84 | */ |
421e8450 OM |
85 | #define OMAP_MUX_GPIO_IN_MODE0 OMAP_MUX_MODE0 |
86 | #define OMAP_MUX_GPIO_IN_MODE1 OMAP_MUX_MODE1 | |
87 | #define OMAP_MUX_GPIO_IN_MODE2 OMAP_MUX_MODE2 | |
88 | #define OMAP_MUX_GPIO_IN_MODE3 OMAP_MUX_MODE3 | |
89 | #define OMAP_MUX_GPIO_IN_MODE4 OMAP_MUX_MODE4 | |
90 | #define OMAP_MUX_GPIO_IN_MODE5 OMAP_MUX_MODE5 | |
91 | #define OMAP_MUX_GPIO_IN_MODE6 OMAP_MUX_MODE6 | |
92 | #define OMAP_MUX_GPIO_IN_MODE7 OMAP_MUX_MODE7 | |
93 | #define OMAP_MUX_REG_8BIT (1 << 3) | |
112485e9 | 94 | |
40e44399 TL |
95 | /** |
96 | * struct omap_board_data - board specific device data | |
97 | * @id: instance id | |
98 | * @flags: additional flags for platform init code | |
99 | * @pads: array of device specific pads | |
100 | * @pads_cnt: ARRAY_SIZE() of pads | |
101 | */ | |
102 | struct omap_board_data { | |
103 | int id; | |
104 | u32 flags; | |
105 | struct omap_device_pad *pads; | |
106 | int pads_cnt; | |
107 | }; | |
108 | ||
112485e9 BC |
109 | /** |
110 | * struct mux_partition - contain partition related information | |
111 | * @name: name of the current partition | |
112 | * @flags: flags specific to this partition | |
421e8450 | 113 | * @gpio: gpio mux mode |
112485e9 BC |
114 | * @phys: physical address |
115 | * @size: partition size | |
116 | * @base: virtual address after ioremap | |
117 | * @muxmodes: list of nodes that belong to a partition | |
118 | * @node: list node for the partitions linked list | |
119 | */ | |
120 | struct omap_mux_partition { | |
121 | const char *name; | |
122 | u32 flags; | |
421e8450 | 123 | u32 gpio; |
112485e9 BC |
124 | u32 phys; |
125 | u32 size; | |
126 | void __iomem *base; | |
127 | struct list_head muxmodes; | |
128 | struct list_head node; | |
129 | }; | |
15ac7afe TL |
130 | |
131 | /** | |
132 | * struct omap_mux - data for omap mux register offset and it's value | |
133 | * @reg_offset: mux register offset from the mux base | |
134 | * @gpio: GPIO number | |
135 | * @muxnames: available signal modes for a ball | |
112485e9 | 136 | * @balls: available balls on the package |
15ac7afe TL |
137 | */ |
138 | struct omap_mux { | |
139 | u16 reg_offset; | |
140 | u16 gpio; | |
141 | #ifdef CONFIG_OMAP_MUX | |
142 | char *muxnames[OMAP_MUX_NR_MODES]; | |
143 | #ifdef CONFIG_DEBUG_FS | |
144 | char *balls[OMAP_MUX_NR_SIDES]; | |
145 | #endif | |
146 | #endif | |
147 | }; | |
148 | ||
149 | /** | |
150 | * struct omap_ball - data for balls on omap package | |
151 | * @reg_offset: mux register offset from the mux base | |
152 | * @balls: available balls on the package | |
153 | */ | |
154 | struct omap_ball { | |
155 | u16 reg_offset; | |
156 | char *balls[OMAP_MUX_NR_SIDES]; | |
157 | }; | |
158 | ||
159 | /** | |
160 | * struct omap_board_mux - data for initializing mux registers | |
161 | * @reg_offset: mux register offset from the mux base | |
162 | * @mux_value: desired mux value to set | |
163 | */ | |
164 | struct omap_board_mux { | |
165 | u16 reg_offset; | |
166 | u16 value; | |
167 | }; | |
168 | ||
9796b323 TL |
169 | #define OMAP_DEVICE_PAD_REMUX BIT(1) /* Dynamically remux a pad, |
170 | needs enable, idle and off | |
171 | values */ | |
172 | #define OMAP_DEVICE_PAD_WAKEUP BIT(0) /* Pad is wake-up capable */ | |
173 | ||
174 | /** | |
175 | * struct omap_device_pad - device specific pad configuration | |
176 | * @name: signal name | |
177 | * @flags: pad specific runtime flags | |
178 | * @enable: runtime value for a pad | |
179 | * @idle: idle value for a pad | |
180 | * @off: off value for a pad, defaults to safe mode | |
181 | * @partition: mux partition | |
182 | * @mux: mux register | |
183 | */ | |
184 | struct omap_device_pad { | |
185 | char *name; | |
186 | u8 flags; | |
187 | u16 enable; | |
188 | u16 idle; | |
189 | u16 off; | |
190 | struct omap_mux_partition *partition; | |
191 | struct omap_mux *mux; | |
192 | }; | |
193 | ||
8d9af88f TL |
194 | struct omap_hwmod_mux_info; |
195 | ||
8aee6039 TL |
196 | #define OMAP_MUX_STATIC(signal, mode) \ |
197 | { \ | |
198 | .name = (signal), \ | |
199 | .enable = (mode), \ | |
200 | } | |
201 | ||
ac3dbeef | 202 | #if defined(CONFIG_OMAP_MUX) |
15ac7afe TL |
203 | |
204 | /** | |
205 | * omap_mux_init_gpio - initialize a signal based on the GPIO number | |
206 | * @gpio: GPIO number | |
207 | * @val: Options for the mux register value | |
208 | */ | |
209 | int omap_mux_init_gpio(int gpio, int val); | |
210 | ||
211 | /** | |
212 | * omap_mux_init_signal - initialize a signal based on the signal name | |
213 | * @muxname: Mux name in mode0_name.signal_name format | |
214 | * @val: Options for the mux register value | |
215 | */ | |
5a3b2f7a | 216 | int omap_mux_init_signal(const char *muxname, int val); |
15ac7afe | 217 | |
9796b323 TL |
218 | /** |
219 | * omap_hwmod_mux_init - initialize hwmod specific mux data | |
220 | * @bpads: Board specific device signal names | |
221 | * @nr_pads: Number of signal names for the device | |
222 | */ | |
223 | extern struct omap_hwmod_mux_info * | |
224 | omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads); | |
225 | ||
8d9af88f TL |
226 | /** |
227 | * omap_hwmod_mux - omap hwmod specific pin muxing | |
228 | * @hmux: Pads for a hwmod | |
229 | * @state: Desired _HWMOD_STATE | |
230 | * | |
231 | * Called only from omap_hwmod.c, do not use. | |
232 | */ | |
233 | void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state); | |
234 | ||
91930652 G |
235 | int omap_mux_get_by_name(const char *muxname, |
236 | struct omap_mux_partition **found_partition, | |
237 | struct omap_mux **found_mux); | |
15ac7afe TL |
238 | #else |
239 | ||
91930652 G |
240 | static inline int omap_mux_get_by_name(const char *muxname, |
241 | struct omap_mux_partition **found_partition, | |
242 | struct omap_mux **found_mux) | |
243 | { | |
244 | return 0; | |
245 | } | |
246 | ||
15ac7afe TL |
247 | static inline int omap_mux_init_gpio(int gpio, int val) |
248 | { | |
249 | return 0; | |
250 | } | |
251 | static inline int omap_mux_init_signal(char *muxname, int val) | |
252 | { | |
253 | return 0; | |
254 | } | |
255 | ||
9796b323 TL |
256 | static inline struct omap_hwmod_mux_info * |
257 | omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads) | |
258 | { | |
259 | return NULL; | |
260 | } | |
261 | ||
8d9af88f TL |
262 | static inline void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state) |
263 | { | |
264 | } | |
265 | ||
cc4915d8 | 266 | static struct omap_board_mux *board_mux __maybe_unused; |
7203f8a4 | 267 | |
15ac7afe TL |
268 | #endif |
269 | ||
270 | /** | |
271 | * omap_mux_get_gpio() - get mux register value based on GPIO number | |
272 | * @gpio: GPIO number | |
273 | * | |
274 | */ | |
275 | u16 omap_mux_get_gpio(int gpio); | |
276 | ||
277 | /** | |
278 | * omap_mux_set_gpio() - set mux register value based on GPIO number | |
279 | * @val: New mux register value | |
280 | * @gpio: GPIO number | |
281 | * | |
282 | */ | |
283 | void omap_mux_set_gpio(u16 val, int gpio); | |
284 | ||
112485e9 BC |
285 | /** |
286 | * omap_mux_get() - get a mux partition by name | |
287 | * @name: Name of the mux partition | |
288 | * | |
289 | */ | |
290 | struct omap_mux_partition *omap_mux_get(const char *name); | |
291 | ||
d4bb72e5 TL |
292 | /** |
293 | * omap_mux_read() - read mux register | |
112485e9 | 294 | * @partition: Mux partition |
d4bb72e5 TL |
295 | * @mux_offset: Offset of the mux register |
296 | * | |
297 | */ | |
112485e9 | 298 | u16 omap_mux_read(struct omap_mux_partition *p, u16 mux_offset); |
d4bb72e5 TL |
299 | |
300 | /** | |
301 | * omap_mux_write() - write mux register | |
112485e9 | 302 | * @partition: Mux partition |
d4bb72e5 TL |
303 | * @val: New mux register value |
304 | * @mux_offset: Offset of the mux register | |
305 | * | |
306 | * This should be only needed for dynamic remuxing of non-gpio signals. | |
307 | */ | |
112485e9 | 308 | void omap_mux_write(struct omap_mux_partition *p, u16 val, u16 mux_offset); |
d4bb72e5 TL |
309 | |
310 | /** | |
311 | * omap_mux_write_array() - write an array of mux registers | |
112485e9 | 312 | * @partition: Mux partition |
d4bb72e5 TL |
313 | * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR |
314 | * | |
315 | * This should be only needed for dynamic remuxing of non-gpio signals. | |
316 | */ | |
112485e9 BC |
317 | void omap_mux_write_array(struct omap_mux_partition *p, |
318 | struct omap_board_mux *board_mux); | |
d4bb72e5 | 319 | |
fc440461 TL |
320 | /** |
321 | * omap2420_mux_init() - initialize mux system with board specific set | |
322 | * @board_mux: Board specific mux table | |
323 | * @flags: OMAP package type used for the board | |
324 | */ | |
325 | int omap2420_mux_init(struct omap_board_mux *board_mux, int flags); | |
326 | ||
89ba1092 TL |
327 | /** |
328 | * omap2430_mux_init() - initialize mux system with board specific set | |
329 | * @board_mux: Board specific mux table | |
330 | * @flags: OMAP package type used for the board | |
331 | */ | |
332 | int omap2430_mux_init(struct omap_board_mux *board_mux, int flags); | |
333 | ||
15ac7afe TL |
334 | /** |
335 | * omap3_mux_init() - initialize mux system with board specific set | |
336 | * @board_mux: Board specific mux table | |
337 | * @flags: OMAP package type used for the board | |
338 | */ | |
339 | int omap3_mux_init(struct omap_board_mux *board_mux, int flags); | |
340 | ||
a041a52c BC |
341 | /** |
342 | * omap4_mux_init() - initialize mux system with board specific set | |
21a42c92 CC |
343 | * @board_subset: Board specific mux table |
344 | * @board_wkup_subset: Board specific mux table for wakeup instance | |
a041a52c BC |
345 | * @flags: OMAP package type used for the board |
346 | */ | |
21a42c92 CC |
347 | int omap4_mux_init(struct omap_board_mux *board_subset, |
348 | struct omap_board_mux *board_wkup_subset, int flags); | |
a041a52c | 349 | |
15ac7afe TL |
350 | /** |
351 | * omap_mux_init - private mux init function, do not call | |
352 | */ | |
112485e9 BC |
353 | int omap_mux_init(const char *name, u32 flags, |
354 | u32 mux_pbase, u32 mux_size, | |
355 | struct omap_mux *superset, | |
356 | struct omap_mux *package_subset, | |
357 | struct omap_board_mux *board_mux, | |
358 | struct omap_ball *package_balls); | |
359 |