blob: 5d2080ef7923585c1313f598a40961c3b241d1ce [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"
13
Tony Lindgren15ac7af2009-12-11 16:16:32 -080014#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
Benoit Coussona041a522010-08-10 17:27:48 +020040/* 44xx specific mux bit defines */
41#define OMAP_WAKEUP_EVENT (1 << 15)
42
Tony Lindgren15ac7af2009-12-11 16:16:32 -080043/* 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
Oleg Matcovschi421e8452012-11-26 17:02:03 -080060#define OMAP_MODE_GPIO(partition, x) (((x) & OMAP_MUX_MODE7) == \
61 partition->gpio)
Govindraj.R91930652012-06-05 04:04:11 -070062#define OMAP_MODE_UART(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE0)
Tony Lindgren15ac7af2009-12-11 16:16:32 -080063
Benoit Cousson112485e2010-08-16 10:55:35 +020064/* Flags for omapX_mux_init */
Tony Lindgren15ac7af2009-12-11 16:16:32 -080065#define OMAP_PACKAGE_MASK 0xffff
Tony Lindgren6dd8a682010-07-05 16:31:35 +030066#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 */
Tony Lindgren15ac7af2009-12-11 16:16:32 -080072
73
Benoit Cousson112485e2010-08-16 10:55:35 +020074#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 *
Oleg Matcovschi421e8452012-11-26 17:02:03 -080080 * OMAP_GPIO_MUX_MODE, bits 0-2: gpio muxing mode, same like pad control
81 * register which includes values from 0-7.
Benoit Cousson112485e2010-08-16 10:55:35 +020082 * OMAP_MUX_REG_8BIT: Ensure that access to padconf is done in 8 bits.
83 * The default value is 16 bits.
Benoit Cousson112485e2010-08-16 10:55:35 +020084 */
Oleg Matcovschi421e8452012-11-26 17:02:03 -080085#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)
Benoit Cousson112485e2010-08-16 10:55:35 +020094
95/**
Tony Lindgren40e44392010-12-22 18:42:35 -080096 * 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 */
102struct omap_board_data {
103 int id;
104 u32 flags;
105 struct omap_device_pad *pads;
106 int pads_cnt;
107};
108
109/**
Benoit Cousson112485e2010-08-16 10:55:35 +0200110 * struct mux_partition - contain partition related information
111 * @name: name of the current partition
112 * @flags: flags specific to this partition
Oleg Matcovschi421e8452012-11-26 17:02:03 -0800113 * @gpio: gpio mux mode
Benoit Cousson112485e2010-08-16 10:55:35 +0200114 * @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 */
120struct omap_mux_partition {
121 const char *name;
122 u32 flags;
Oleg Matcovschi421e8452012-11-26 17:02:03 -0800123 u32 gpio;
Benoit Cousson112485e2010-08-16 10:55:35 +0200124 u32 phys;
125 u32 size;
126 void __iomem *base;
127 struct list_head muxmodes;
128 struct list_head node;
129};
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800130
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
Benoit Cousson112485e2010-08-16 10:55:35 +0200136 * @balls: available balls on the package
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800137 */
138struct 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 */
154struct 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 */
164struct omap_board_mux {
165 u16 reg_offset;
166 u16 value;
167};
168
Tony Lindgren9796b322010-12-22 18:42:35 -0800169#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 */
184struct 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
Tony Lindgren8d9af882010-12-22 18:42:35 -0800194struct omap_hwmod_mux_info;
195
Tony Lindgren8aee6032011-03-11 11:32:26 -0800196#define OMAP_MUX_STATIC(signal, mode) \
197{ \
198 .name = (signal), \
199 .enable = (mode), \
200}
201
Tony Lindgrenac3dbee2010-07-05 16:31:36 +0300202#if defined(CONFIG_OMAP_MUX)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800203
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 */
209int 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 */
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700216int omap_mux_init_signal(const char *muxname, int val);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800217
Tony Lindgren9796b322010-12-22 18:42:35 -0800218/**
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 */
223extern struct omap_hwmod_mux_info *
224omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads);
225
Tony Lindgren8d9af882010-12-22 18:42:35 -0800226/**
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 */
233void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state);
234
Govindraj.R91930652012-06-05 04:04:11 -0700235int omap_mux_get_by_name(const char *muxname,
236 struct omap_mux_partition **found_partition,
237 struct omap_mux **found_mux);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800238#else
239
Govindraj.R91930652012-06-05 04:04:11 -0700240static 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
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800247static inline int omap_mux_init_gpio(int gpio, int val)
248{
249 return 0;
250}
251static inline int omap_mux_init_signal(char *muxname, int val)
252{
253 return 0;
254}
255
Tony Lindgren9796b322010-12-22 18:42:35 -0800256static inline struct omap_hwmod_mux_info *
257omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads)
258{
259 return NULL;
260}
261
Tony Lindgren8d9af882010-12-22 18:42:35 -0800262static inline void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state)
263{
264}
265
Tony Lindgrencc4915d2012-02-23 14:21:28 -0800266static struct omap_board_mux *board_mux __maybe_unused;
Aaro Koskinen7203f8a2010-12-02 13:25:40 +0000267
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800268#endif
269
270/**
271 * omap_mux_get_gpio() - get mux register value based on GPIO number
272 * @gpio: GPIO number
273 *
274 */
275u16 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 */
283void omap_mux_set_gpio(u16 val, int gpio);
284
285/**
Benoit Cousson112485e2010-08-16 10:55:35 +0200286 * omap_mux_get() - get a mux partition by name
287 * @name: Name of the mux partition
288 *
289 */
290struct omap_mux_partition *omap_mux_get(const char *name);
291
292/**
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800293 * omap_mux_read() - read mux register
Benoit Cousson112485e2010-08-16 10:55:35 +0200294 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800295 * @mux_offset: Offset of the mux register
296 *
297 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200298u16 omap_mux_read(struct omap_mux_partition *p, u16 mux_offset);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800299
300/**
301 * omap_mux_write() - write mux register
Benoit Cousson112485e2010-08-16 10:55:35 +0200302 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800303 * @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 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200308void omap_mux_write(struct omap_mux_partition *p, u16 val, u16 mux_offset);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800309
310/**
311 * omap_mux_write_array() - write an array of mux registers
Benoit Cousson112485e2010-08-16 10:55:35 +0200312 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800313 * @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 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200317void omap_mux_write_array(struct omap_mux_partition *p,
318 struct omap_board_mux *board_mux);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800319
320/**
Tony Lindgrenfc440462010-07-05 16:31:36 +0300321 * 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 */
325int omap2420_mux_init(struct omap_board_mux *board_mux, int flags);
326
327/**
Tony Lindgren89ba1092010-07-05 16:31:36 +0300328 * 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 */
332int omap2430_mux_init(struct omap_board_mux *board_mux, int flags);
333
334/**
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800335 * 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 */
339int omap3_mux_init(struct omap_board_mux *board_mux, int flags);
340
341/**
Benoit Coussona041a522010-08-10 17:27:48 +0200342 * omap4_mux_init() - initialize mux system with board specific set
Colin Cross21a42c92011-05-04 14:57:57 -0700343 * @board_subset: Board specific mux table
344 * @board_wkup_subset: Board specific mux table for wakeup instance
Benoit Coussona041a522010-08-10 17:27:48 +0200345 * @flags: OMAP package type used for the board
346 */
Colin Cross21a42c92011-05-04 14:57:57 -0700347int omap4_mux_init(struct omap_board_mux *board_subset,
348 struct omap_board_mux *board_wkup_subset, int flags);
Benoit Coussona041a522010-08-10 17:27:48 +0200349
350/**
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800351 * omap_mux_init - private mux init function, do not call
352 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200353int 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