blob: 2132308ad1e41fffc14856b48294ffd42e748c8b [file] [log] [blame]
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001/*
2 * Copyright (C) 2009 Nokia
Benoit Cousson112485e2010-08-16 10:55:35 +02003 * Copyright (C) 2009-2010 Texas Instruments
Tony Lindgren15ac7af2009-12-11 16:16:32 -08004 *
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
Tony Lindgrenfc440462010-07-05 16:31:36 +030010#include "mux2420.h"
Tony Lindgren89ba1092010-07-05 16:31:36 +030011#include "mux2430.h"
Tony Lindgrenddaa9122009-12-11 16:16:32 -080012#include "mux34xx.h"
Benoit Coussona041a522010-08-10 17:27:48 +020013#include "mux44xx.h"
Tony Lindgrenddaa9122009-12-11 16:16:32 -080014
Tony Lindgren15ac7af2009-12-11 16:16:32 -080015#define OMAP_MUX_TERMINATOR 0xffff
16
17/* 34xx mux mode options for each pin. See TRM for options */
18#define OMAP_MUX_MODE0 0
19#define OMAP_MUX_MODE1 1
20#define OMAP_MUX_MODE2 2
21#define OMAP_MUX_MODE3 3
22#define OMAP_MUX_MODE4 4
23#define OMAP_MUX_MODE5 5
24#define OMAP_MUX_MODE6 6
25#define OMAP_MUX_MODE7 7
26
27/* 24xx/34xx mux bit defines */
28#define OMAP_PULL_ENA (1 << 3)
29#define OMAP_PULL_UP (1 << 4)
30#define OMAP_ALTELECTRICALSEL (1 << 5)
31
32/* 34xx specific mux bit defines */
33#define OMAP_INPUT_EN (1 << 8)
34#define OMAP_OFF_EN (1 << 9)
35#define OMAP_OFFOUT_EN (1 << 10)
36#define OMAP_OFFOUT_VAL (1 << 11)
37#define OMAP_OFF_PULL_EN (1 << 12)
38#define OMAP_OFF_PULL_UP (1 << 13)
39#define OMAP_WAKEUP_EN (1 << 14)
40
Benoit Coussona041a522010-08-10 17:27:48 +020041/* 44xx specific mux bit defines */
42#define OMAP_WAKEUP_EVENT (1 << 15)
43
Tony Lindgren15ac7af2009-12-11 16:16:32 -080044/* Active pin states */
45#define OMAP_PIN_OUTPUT 0
46#define OMAP_PIN_INPUT OMAP_INPUT_EN
47#define OMAP_PIN_INPUT_PULLUP (OMAP_PULL_ENA | OMAP_INPUT_EN \
48 | OMAP_PULL_UP)
49#define OMAP_PIN_INPUT_PULLDOWN (OMAP_PULL_ENA | OMAP_INPUT_EN)
50
51/* Off mode states */
52#define OMAP_PIN_OFF_NONE 0
53#define OMAP_PIN_OFF_OUTPUT_HIGH (OMAP_OFF_EN | OMAP_OFFOUT_EN \
54 | OMAP_OFFOUT_VAL)
55#define OMAP_PIN_OFF_OUTPUT_LOW (OMAP_OFF_EN | OMAP_OFFOUT_EN)
56#define OMAP_PIN_OFF_INPUT_PULLUP (OMAP_OFF_EN | OMAP_OFF_PULL_EN \
57 | OMAP_OFF_PULL_UP)
58#define OMAP_PIN_OFF_INPUT_PULLDOWN (OMAP_OFF_EN | OMAP_OFF_PULL_EN)
59#define OMAP_PIN_OFF_WAKEUPENABLE OMAP_WAKEUP_EN
60
61#define OMAP_MODE_GPIO(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE4)
62
Benoit Cousson112485e2010-08-16 10:55:35 +020063/* Flags for omapX_mux_init */
Tony Lindgren15ac7af2009-12-11 16:16:32 -080064#define OMAP_PACKAGE_MASK 0xffff
Benoit Coussona7722d82010-09-24 16:56:59 +020065#define OMAP_PACKAGE_CBS 8 /* 547-pin 0.40 0.40 */
Benoit Coussona041a522010-08-10 17:27:48 +020066#define OMAP_PACKAGE_CBL 7 /* 547-pin 0.40 0.40 */
Tony Lindgren6dd8a682010-07-05 16:31:35 +030067#define OMAP_PACKAGE_CBP 6 /* 515-pin 0.40 0.50 */
68#define OMAP_PACKAGE_CUS 5 /* 423-pin 0.65 */
69#define OMAP_PACKAGE_CBB 4 /* 515-pin 0.40 0.50 */
70#define OMAP_PACKAGE_CBC 3 /* 515-pin 0.50 0.65 */
71#define OMAP_PACKAGE_ZAC 2 /* 24xx 447-pin POP */
72#define OMAP_PACKAGE_ZAF 1 /* 2420 447-pin SIP */
Tony Lindgren15ac7af2009-12-11 16:16:32 -080073
74
Benoit Cousson112485e2010-08-16 10:55:35 +020075#define OMAP_MUX_NR_MODES 8 /* Available modes */
76#define OMAP_MUX_NR_SIDES 2 /* Bottom & top */
77
78/*
79 * omap_mux_init flags definition:
80 *
81 * OMAP_MUX_REG_8BIT: Ensure that access to padconf is done in 8 bits.
82 * The default value is 16 bits.
83 * OMAP_MUX_GPIO_IN_MODE3: The GPIO is selected in mode3.
84 * The default is mode4.
85 */
86#define OMAP_MUX_REG_8BIT (1 << 0)
87#define OMAP_MUX_GPIO_IN_MODE3 (1 << 1)
88
89/**
Tony Lindgren40e44392010-12-22 18:42:35 -080090 * struct omap_board_data - board specific device data
91 * @id: instance id
92 * @flags: additional flags for platform init code
93 * @pads: array of device specific pads
94 * @pads_cnt: ARRAY_SIZE() of pads
95 */
96struct omap_board_data {
97 int id;
98 u32 flags;
99 struct omap_device_pad *pads;
100 int pads_cnt;
101};
102
103/**
Benoit Cousson112485e2010-08-16 10:55:35 +0200104 * struct mux_partition - contain partition related information
105 * @name: name of the current partition
106 * @flags: flags specific to this partition
107 * @phys: physical address
108 * @size: partition size
109 * @base: virtual address after ioremap
110 * @muxmodes: list of nodes that belong to a partition
111 * @node: list node for the partitions linked list
112 */
113struct omap_mux_partition {
114 const char *name;
115 u32 flags;
116 u32 phys;
117 u32 size;
118 void __iomem *base;
119 struct list_head muxmodes;
120 struct list_head node;
121};
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800122
123/**
124 * struct omap_mux - data for omap mux register offset and it's value
125 * @reg_offset: mux register offset from the mux base
126 * @gpio: GPIO number
127 * @muxnames: available signal modes for a ball
Benoit Cousson112485e2010-08-16 10:55:35 +0200128 * @balls: available balls on the package
129 * @partition: mux partition
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800130 */
131struct omap_mux {
132 u16 reg_offset;
133 u16 gpio;
134#ifdef CONFIG_OMAP_MUX
135 char *muxnames[OMAP_MUX_NR_MODES];
136#ifdef CONFIG_DEBUG_FS
137 char *balls[OMAP_MUX_NR_SIDES];
138#endif
139#endif
140};
141
142/**
143 * struct omap_ball - data for balls on omap package
144 * @reg_offset: mux register offset from the mux base
145 * @balls: available balls on the package
146 */
147struct omap_ball {
148 u16 reg_offset;
149 char *balls[OMAP_MUX_NR_SIDES];
150};
151
152/**
153 * struct omap_board_mux - data for initializing mux registers
154 * @reg_offset: mux register offset from the mux base
155 * @mux_value: desired mux value to set
156 */
157struct omap_board_mux {
158 u16 reg_offset;
159 u16 value;
160};
161
Tony Lindgren9796b322010-12-22 18:42:35 -0800162#define OMAP_DEVICE_PAD_REMUX BIT(1) /* Dynamically remux a pad,
163 needs enable, idle and off
164 values */
165#define OMAP_DEVICE_PAD_WAKEUP BIT(0) /* Pad is wake-up capable */
166
167/**
168 * struct omap_device_pad - device specific pad configuration
169 * @name: signal name
170 * @flags: pad specific runtime flags
171 * @enable: runtime value for a pad
172 * @idle: idle value for a pad
173 * @off: off value for a pad, defaults to safe mode
174 * @partition: mux partition
175 * @mux: mux register
176 */
177struct omap_device_pad {
178 char *name;
179 u8 flags;
180 u16 enable;
181 u16 idle;
182 u16 off;
183 struct omap_mux_partition *partition;
184 struct omap_mux *mux;
185};
186
Tony Lindgren8d9af882010-12-22 18:42:35 -0800187struct omap_hwmod_mux_info;
188
Tony Lindgren8aee6032011-03-11 11:32:26 -0800189#define OMAP_MUX_STATIC(signal, mode) \
190{ \
191 .name = (signal), \
192 .enable = (mode), \
193}
194
Tony Lindgrenac3dbee2010-07-05 16:31:36 +0300195#if defined(CONFIG_OMAP_MUX)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800196
197/**
198 * omap_mux_init_gpio - initialize a signal based on the GPIO number
199 * @gpio: GPIO number
200 * @val: Options for the mux register value
201 */
202int omap_mux_init_gpio(int gpio, int val);
203
204/**
205 * omap_mux_init_signal - initialize a signal based on the signal name
206 * @muxname: Mux name in mode0_name.signal_name format
207 * @val: Options for the mux register value
208 */
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700209int omap_mux_init_signal(const char *muxname, int val);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800210
Tony Lindgren9796b322010-12-22 18:42:35 -0800211/**
212 * omap_hwmod_mux_init - initialize hwmod specific mux data
213 * @bpads: Board specific device signal names
214 * @nr_pads: Number of signal names for the device
215 */
216extern struct omap_hwmod_mux_info *
217omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads);
218
Tony Lindgren8d9af882010-12-22 18:42:35 -0800219/**
220 * omap_hwmod_mux - omap hwmod specific pin muxing
221 * @hmux: Pads for a hwmod
222 * @state: Desired _HWMOD_STATE
223 *
224 * Called only from omap_hwmod.c, do not use.
225 */
226void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state);
227
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800228#else
229
230static inline int omap_mux_init_gpio(int gpio, int val)
231{
232 return 0;
233}
234static inline int omap_mux_init_signal(char *muxname, int val)
235{
236 return 0;
237}
238
Tony Lindgren9796b322010-12-22 18:42:35 -0800239static inline struct omap_hwmod_mux_info *
240omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads)
241{
242 return NULL;
243}
244
Tony Lindgren8d9af882010-12-22 18:42:35 -0800245static inline void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state)
246{
247}
248
Aaro Koskinen7203f8a2010-12-02 13:25:40 +0000249static struct omap_board_mux *board_mux __initdata __maybe_unused;
250
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800251#endif
252
253/**
254 * omap_mux_get_gpio() - get mux register value based on GPIO number
255 * @gpio: GPIO number
256 *
257 */
258u16 omap_mux_get_gpio(int gpio);
259
260/**
261 * omap_mux_set_gpio() - set mux register value based on GPIO number
262 * @val: New mux register value
263 * @gpio: GPIO number
264 *
265 */
266void omap_mux_set_gpio(u16 val, int gpio);
267
268/**
Benoit Cousson112485e2010-08-16 10:55:35 +0200269 * omap_mux_get() - get a mux partition by name
270 * @name: Name of the mux partition
271 *
272 */
273struct omap_mux_partition *omap_mux_get(const char *name);
274
275/**
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800276 * omap_mux_read() - read mux register
Benoit Cousson112485e2010-08-16 10:55:35 +0200277 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800278 * @mux_offset: Offset of the mux register
279 *
280 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200281u16 omap_mux_read(struct omap_mux_partition *p, u16 mux_offset);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800282
283/**
284 * omap_mux_write() - write mux register
Benoit Cousson112485e2010-08-16 10:55:35 +0200285 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800286 * @val: New mux register value
287 * @mux_offset: Offset of the mux register
288 *
289 * This should be only needed for dynamic remuxing of non-gpio signals.
290 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200291void omap_mux_write(struct omap_mux_partition *p, u16 val, u16 mux_offset);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800292
293/**
294 * omap_mux_write_array() - write an array of mux registers
Benoit Cousson112485e2010-08-16 10:55:35 +0200295 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800296 * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR
297 *
298 * This should be only needed for dynamic remuxing of non-gpio signals.
299 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200300void omap_mux_write_array(struct omap_mux_partition *p,
301 struct omap_board_mux *board_mux);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800302
303/**
Tony Lindgrenfc440462010-07-05 16:31:36 +0300304 * omap2420_mux_init() - initialize mux system with board specific set
305 * @board_mux: Board specific mux table
306 * @flags: OMAP package type used for the board
307 */
308int omap2420_mux_init(struct omap_board_mux *board_mux, int flags);
309
310/**
Tony Lindgren89ba1092010-07-05 16:31:36 +0300311 * omap2430_mux_init() - initialize mux system with board specific set
312 * @board_mux: Board specific mux table
313 * @flags: OMAP package type used for the board
314 */
315int omap2430_mux_init(struct omap_board_mux *board_mux, int flags);
316
317/**
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800318 * omap3_mux_init() - initialize mux system with board specific set
319 * @board_mux: Board specific mux table
320 * @flags: OMAP package type used for the board
321 */
322int omap3_mux_init(struct omap_board_mux *board_mux, int flags);
323
324/**
Benoit Coussona041a522010-08-10 17:27:48 +0200325 * omap4_mux_init() - initialize mux system with board specific set
Colin Cross21a42c92011-05-04 14:57:57 -0700326 * @board_subset: Board specific mux table
327 * @board_wkup_subset: Board specific mux table for wakeup instance
Benoit Coussona041a522010-08-10 17:27:48 +0200328 * @flags: OMAP package type used for the board
329 */
Colin Cross21a42c92011-05-04 14:57:57 -0700330int omap4_mux_init(struct omap_board_mux *board_subset,
331 struct omap_board_mux *board_wkup_subset, int flags);
Benoit Coussona041a522010-08-10 17:27:48 +0200332
333/**
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800334 * omap_mux_init - private mux init function, do not call
335 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200336int omap_mux_init(const char *name, u32 flags,
337 u32 mux_pbase, u32 mux_size,
338 struct omap_mux *superset,
339 struct omap_mux *package_subset,
340 struct omap_board_mux *board_mux,
341 struct omap_ball *package_balls);
342