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 */
10 #include "mux2420.h"
11 #include "mux2430.h"
12 #include "mux34xx.h"
13 #include "mux44xx.h"
14 #include "mux33xx.h"
16 #define OMAP_MUX_TERMINATOR 0xffff
18 /* 34xx mux mode options for each pin. See TRM for options */
19 #define OMAP_MUX_MODE0 0
20 #define OMAP_MUX_MODE1 1
21 #define OMAP_MUX_MODE2 2
22 #define OMAP_MUX_MODE3 3
23 #define OMAP_MUX_MODE4 4
24 #define OMAP_MUX_MODE5 5
25 #define OMAP_MUX_MODE6 6
26 #define OMAP_MUX_MODE7 7
28 /* 24xx/34xx mux bit defines */
29 #define OMAP_PULL_ENA (1 << 3)
30 #define OMAP_PULL_UP (1 << 4)
31 #define OMAP_ALTELECTRICALSEL (1 << 5)
33 /* 34xx specific mux bit defines */
34 #define OMAP_INPUT_EN (1 << 8)
35 #define OMAP_OFF_EN (1 << 9)
36 #define OMAP_OFFOUT_EN (1 << 10)
37 #define OMAP_OFFOUT_VAL (1 << 11)
38 #define OMAP_OFF_PULL_EN (1 << 12)
39 #define OMAP_OFF_PULL_UP (1 << 13)
40 #define OMAP_WAKEUP_EN (1 << 14)
42 /* 44xx specific mux bit defines */
43 #define OMAP_WAKEUP_EVENT (1 << 15)
45 /* am33xx specific mux bit defines */
46 #define AM33XX_SLEWCTRL_FAST (0 << 6)
47 #define AM33XX_SLEWCTRL_SLOW (1 << 6)
48 #define AM33XX_INPUT_EN (1 << 5)
49 #define AM33XX_PULL_UP (1 << 4)
50 /* bit 3: 0 - enable, 1 - disable for pull enable */
51 #define AM33XX_PULL_DISA (1 << 3)
52 #define AM33XX_PULL_ENBL (0 << 3)
54 /* Definition of output pin could have pull disabled, but
55 * this has not been done due to two reasons
56 * 1. AM33XX_MUX will take care of it
57 * 2. If pull was disabled for out macro, combining out & in pull on macros
58 * would disable pull resistor and AM33XX_MUX cannot take care of the
59 * correct pull setting and unintentionally pull would get disabled
60 */
61 #define AM33XX_PIN_OUTPUT (0)
62 #define AM33XX_PIN_OUTPUT_PULLUP (AM33XX_PULL_UP)
63 #define AM33XX_PIN_INPUT (AM33XX_INPUT_EN | AM33XX_PULL_DISA)
64 #define AM33XX_PIN_INPUT_PULLUP (AM33XX_INPUT_EN | AM33XX_PULL_UP)
65 #define AM33XX_PIN_INPUT_PULLDOWN (AM33XX_INPUT_EN)
67 /* Active pin states */
68 #define OMAP_PIN_OUTPUT 0
69 #define OMAP_PIN_INPUT OMAP_INPUT_EN
70 #define OMAP_PIN_INPUT_PULLUP (OMAP_PULL_ENA | OMAP_INPUT_EN \
71 | OMAP_PULL_UP)
72 #define OMAP_PIN_INPUT_PULLDOWN (OMAP_PULL_ENA | OMAP_INPUT_EN)
74 /* Off mode states */
75 #define OMAP_PIN_OFF_NONE 0
76 #define OMAP_PIN_OFF_OUTPUT_HIGH (OMAP_OFF_EN | OMAP_OFFOUT_EN \
77 | OMAP_OFFOUT_VAL)
78 #define OMAP_PIN_OFF_OUTPUT_LOW (OMAP_OFF_EN | OMAP_OFFOUT_EN)
79 #define OMAP_PIN_OFF_INPUT_PULLUP (OMAP_OFF_EN | OMAP_OFF_PULL_EN \
80 | OMAP_OFF_PULL_UP)
81 #define OMAP_PIN_OFF_INPUT_PULLDOWN (OMAP_OFF_EN | OMAP_OFF_PULL_EN)
82 #define OMAP_PIN_OFF_WAKEUPENABLE OMAP_WAKEUP_EN
84 #define OMAP_MODE_GPIO(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE4)
86 /* Flags for omapX_mux_init */
87 #define OMAP_PACKAGE_MASK 0xffff
88 #define OMAP_PACKAGE_CBS 8 /* 547-pin 0.40 0.40 */
89 #define OMAP_PACKAGE_CBL 7 /* 547-pin 0.40 0.40 */
90 #define OMAP_PACKAGE_CBP 6 /* 515-pin 0.40 0.50 */
91 #define OMAP_PACKAGE_CUS 5 /* 423-pin 0.65 */
92 #define OMAP_PACKAGE_CBB 4 /* 515-pin 0.40 0.50 */
93 #define OMAP_PACKAGE_CBC 3 /* 515-pin 0.50 0.65 */
94 #define OMAP_PACKAGE_ZAC 2 /* 24xx 447-pin POP */
95 #define OMAP_PACKAGE_ZAF 1 /* 2420 447-pin SIP */
98 #define OMAP_MUX_NR_MODES 8 /* Available modes */
99 #define OMAP_MUX_NR_SIDES 2 /* Bottom & top */
101 /*
102 * omap_mux_init flags definition:
103 *
104 * OMAP_MUX_REG_8BIT: Ensure that access to padconf is done in 8 bits.
105 * The default value is 16 bits.
106 * OMAP_MUX_GPIO_IN_MODE3: The GPIO is selected in mode3.
107 * The default is mode4.
108 */
109 #define OMAP_MUX_REG_8BIT (1 << 0)
110 #define OMAP_MUX_GPIO_IN_MODE3 (1 << 1)
112 /**
113 * struct omap_board_data - board specific device data
114 * @id: instance id
115 * @flags: additional flags for platform init code
116 * @pads: array of device specific pads
117 * @pads_cnt: ARRAY_SIZE() of pads
118 */
119 struct omap_board_data {
120 int id;
121 u32 flags;
122 struct omap_device_pad *pads;
123 int pads_cnt;
124 };
126 /**
127 * struct mux_partition - contain partition related information
128 * @name: name of the current partition
129 * @flags: flags specific to this partition
130 * @phys: physical address
131 * @size: partition size
132 * @base: virtual address after ioremap
133 * @muxmodes: list of nodes that belong to a partition
134 * @node: list node for the partitions linked list
135 */
136 struct omap_mux_partition {
137 const char *name;
138 u32 flags;
139 u32 phys;
140 u32 size;
141 void __iomem *base;
142 struct list_head muxmodes;
143 struct list_head node;
144 };
146 /**
147 * struct omap_mux - data for omap mux register offset and it's value
148 * @reg_offset: mux register offset from the mux base
149 * @gpio: GPIO number
150 * @muxnames: available signal modes for a ball
151 * @balls: available balls on the package
152 * @partition: mux partition
153 */
154 struct omap_mux {
155 u16 reg_offset;
156 u16 gpio;
157 #ifdef CONFIG_OMAP_MUX
158 char *muxnames[OMAP_MUX_NR_MODES];
159 #ifdef CONFIG_DEBUG_FS
160 char *balls[OMAP_MUX_NR_SIDES];
161 #endif
162 #endif
163 };
165 /**
166 * struct omap_ball - data for balls on omap package
167 * @reg_offset: mux register offset from the mux base
168 * @balls: available balls on the package
169 */
170 struct omap_ball {
171 u16 reg_offset;
172 char *balls[OMAP_MUX_NR_SIDES];
173 };
175 /**
176 * struct omap_board_mux - data for initializing mux registers
177 * @reg_offset: mux register offset from the mux base
178 * @mux_value: desired mux value to set
179 */
180 struct omap_board_mux {
181 u16 reg_offset;
182 u16 value;
183 };
185 #define OMAP_DEVICE_PAD_REMUX BIT(1) /* Dynamically remux a pad,
186 needs enable, idle and off
187 values */
188 #define OMAP_DEVICE_PAD_WAKEUP BIT(0) /* Pad is wake-up capable */
190 /**
191 * struct omap_device_pad - device specific pad configuration
192 * @name: signal name
193 * @flags: pad specific runtime flags
194 * @enable: runtime value for a pad
195 * @idle: idle value for a pad
196 * @off: off value for a pad, defaults to safe mode
197 * @partition: mux partition
198 * @mux: mux register
199 */
200 struct omap_device_pad {
201 char *name;
202 u8 flags;
203 u16 enable;
204 u16 idle;
205 u16 off;
206 struct omap_mux_partition *partition;
207 struct omap_mux *mux;
208 };
210 struct omap_hwmod_mux_info;
212 #define OMAP_MUX_STATIC(signal, mode) \
213 { \
214 .name = (signal), \
215 .enable = (mode), \
216 }
218 #if defined(CONFIG_OMAP_MUX)
220 /**
221 * omap_mux_init_gpio - initialize a signal based on the GPIO number
222 * @gpio: GPIO number
223 * @val: Options for the mux register value
224 */
225 int omap_mux_init_gpio(int gpio, int val);
227 /**
228 * omap_mux_init_signal - initialize a signal based on the signal name
229 * @muxname: Mux name in mode0_name.signal_name format
230 * @val: Options for the mux register value
231 */
232 int omap_mux_init_signal(const char *muxname, int val);
234 /**
235 * omap_hwmod_mux_init - initialize hwmod specific mux data
236 * @bpads: Board specific device signal names
237 * @nr_pads: Number of signal names for the device
238 */
239 extern struct omap_hwmod_mux_info *
240 omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads);
242 /**
243 * omap_hwmod_mux - omap hwmod specific pin muxing
244 * @hmux: Pads for a hwmod
245 * @state: Desired _HWMOD_STATE
246 *
247 * Called only from omap_hwmod.c, do not use.
248 */
249 void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state);
251 #else
253 static inline int omap_mux_init_gpio(int gpio, int val)
254 {
255 return 0;
256 }
257 static inline int omap_mux_init_signal(char *muxname, int val)
258 {
259 return 0;
260 }
262 static inline struct omap_hwmod_mux_info *
263 omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads)
264 {
265 return NULL;
266 }
268 static inline void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state)
269 {
270 }
272 static struct omap_board_mux *board_mux __initdata __maybe_unused;
274 #endif
276 /**
277 * omap_mux_get_gpio() - get mux register value based on GPIO number
278 * @gpio: GPIO number
279 *
280 */
281 u16 omap_mux_get_gpio(int gpio);
283 /**
284 * omap_mux_set_gpio() - set mux register value based on GPIO number
285 * @val: New mux register value
286 * @gpio: GPIO number
287 *
288 */
289 void omap_mux_set_gpio(u16 val, int gpio);
291 /**
292 * omap_mux_get() - get a mux partition by name
293 * @name: Name of the mux partition
294 *
295 */
296 struct omap_mux_partition *omap_mux_get(const char *name);
298 /**
299 * omap_mux_read() - read mux register
300 * @partition: Mux partition
301 * @mux_offset: Offset of the mux register
302 *
303 */
304 u16 omap_mux_read(struct omap_mux_partition *p, u16 mux_offset);
306 /**
307 * omap_mux_write() - write mux register
308 * @partition: Mux partition
309 * @val: New mux register value
310 * @mux_offset: Offset of the mux register
311 *
312 * This should be only needed for dynamic remuxing of non-gpio signals.
313 */
314 void omap_mux_write(struct omap_mux_partition *p, u16 val, u16 mux_offset);
316 /**
317 * omap_mux_write_array() - write an array of mux registers
318 * @partition: Mux partition
319 * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR
320 *
321 * This should be only needed for dynamic remuxing of non-gpio signals.
322 */
323 void omap_mux_write_array(struct omap_mux_partition *p,
324 struct omap_board_mux *board_mux);
326 /**
327 * omap2420_mux_init() - initialize mux system with board specific set
328 * @board_mux: Board specific mux table
329 * @flags: OMAP package type used for the board
330 */
331 int omap2420_mux_init(struct omap_board_mux *board_mux, int flags);
333 /**
334 * omap2430_mux_init() - initialize mux system with board specific set
335 * @board_mux: Board specific mux table
336 * @flags: OMAP package type used for the board
337 */
338 int omap2430_mux_init(struct omap_board_mux *board_mux, int flags);
340 /**
341 * omap3_mux_init() - initialize mux system with board specific set
342 * @board_mux: Board specific mux table
343 * @flags: OMAP package type used for the board
344 */
345 int omap3_mux_init(struct omap_board_mux *board_mux, int flags);
347 /**
348 * omap4_mux_init() - initialize mux system with board specific set
349 * @board_subset: Board specific mux table
350 * @board_wkup_subset: Board specific mux table for wakeup instance
351 * @flags: OMAP package type used for the board
352 */
353 int omap4_mux_init(struct omap_board_mux *board_subset,
354 struct omap_board_mux *board_wkup_subset, int flags);
356 /**
357 * am33xx_mux_init() - initialize mux system along with board specific set
358 * @board_mux: Board specific mux table
359 */
360 int am33xx_mux_init(struct omap_board_mux *board_mux);
362 /**
363 * omap_mux_init - private mux init function, do not call
364 */
365 int omap_mux_init(const char *name, u32 flags,
366 u32 mux_pbase, u32 mux_size,
367 struct omap_mux *superset,
368 struct omap_mux *package_subset,
369 struct omap_board_mux *board_mux,
370 struct omap_ball *package_balls);