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