blob: 16f78a990d04cafbd7dd1fcaa81b7d7dd061e979 [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
Tony Lindgrend623a0e2013-10-07 10:22:01 -070031/* omap3/4/5 specific mux bit defines */
Tony Lindgren15ac7af2009-12-11 16:16:32 -080032#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)
Benoit Coussona041a522010-08-10 17:27:48 +020039#define OMAP_WAKEUP_EVENT (1 << 15)
40
Tony Lindgren15ac7af2009-12-11 16:16:32 -080041/* 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
Oleg Matcovschi421e8452012-11-26 17:02:03 -080058#define OMAP_MODE_GPIO(partition, x) (((x) & OMAP_MUX_MODE7) == \
59 partition->gpio)
Govindraj.R91930652012-06-05 04:04:11 -070060#define OMAP_MODE_UART(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE0)
Tony Lindgren15ac7af2009-12-11 16:16:32 -080061
Benoit Cousson112485e2010-08-16 10:55:35 +020062/* Flags for omapX_mux_init */
Tony Lindgren15ac7af2009-12-11 16:16:32 -080063#define OMAP_PACKAGE_MASK 0xffff
Tony Lindgren6dd8a682010-07-05 16:31:35 +030064#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 */
Tony Lindgren15ac7af2009-12-11 16:16:32 -080070
71
Benoit Cousson112485e2010-08-16 10:55:35 +020072#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 *
Oleg Matcovschi421e8452012-11-26 17:02:03 -080078 * OMAP_GPIO_MUX_MODE, bits 0-2: gpio muxing mode, same like pad control
79 * register which includes values from 0-7.
Benoit Cousson112485e2010-08-16 10:55:35 +020080 * OMAP_MUX_REG_8BIT: Ensure that access to padconf is done in 8 bits.
81 * The default value is 16 bits.
Benoit Cousson112485e2010-08-16 10:55:35 +020082 */
Oleg Matcovschi421e8452012-11-26 17:02:03 -080083#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)
Benoit Cousson112485e2010-08-16 10:55:35 +020092
93/**
Tony Lindgren40e44392010-12-22 18:42:35 -080094 * 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 */
100struct omap_board_data {
101 int id;
102 u32 flags;
103 struct omap_device_pad *pads;
104 int pads_cnt;
105};
106
107/**
Benoit Cousson112485e2010-08-16 10:55:35 +0200108 * struct mux_partition - contain partition related information
109 * @name: name of the current partition
110 * @flags: flags specific to this partition
Oleg Matcovschi421e8452012-11-26 17:02:03 -0800111 * @gpio: gpio mux mode
Benoit Cousson112485e2010-08-16 10:55:35 +0200112 * @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 */
118struct omap_mux_partition {
119 const char *name;
120 u32 flags;
Oleg Matcovschi421e8452012-11-26 17:02:03 -0800121 u32 gpio;
Benoit Cousson112485e2010-08-16 10:55:35 +0200122 u32 phys;
123 u32 size;
124 void __iomem *base;
125 struct list_head muxmodes;
126 struct list_head node;
127};
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800128
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
Benoit Cousson112485e2010-08-16 10:55:35 +0200134 * @balls: available balls on the package
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800135 */
136struct 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 */
152struct 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 */
162struct omap_board_mux {
163 u16 reg_offset;
164 u16 value;
165};
166
Tony Lindgren9796b322010-12-22 18:42:35 -0800167#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 */
182struct 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
Tony Lindgren8d9af882010-12-22 18:42:35 -0800192struct omap_hwmod_mux_info;
193
Tony Lindgren8aee6032011-03-11 11:32:26 -0800194#define OMAP_MUX_STATIC(signal, mode) \
195{ \
196 .name = (signal), \
197 .enable = (mode), \
198}
199
Tony Lindgrenac3dbee2010-07-05 16:31:36 +0300200#if defined(CONFIG_OMAP_MUX)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800201
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 */
207int 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 */
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700214int omap_mux_init_signal(const char *muxname, int val);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800215
Tony Lindgren9796b322010-12-22 18:42:35 -0800216/**
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 */
221extern struct omap_hwmod_mux_info *
222omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads);
223
Tony Lindgren8d9af882010-12-22 18:42:35 -0800224/**
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 */
231void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state);
232
Govindraj.R91930652012-06-05 04:04:11 -0700233int omap_mux_get_by_name(const char *muxname,
234 struct omap_mux_partition **found_partition,
235 struct omap_mux **found_mux);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800236#else
237
Govindraj.R91930652012-06-05 04:04:11 -0700238static 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
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800245static inline int omap_mux_init_gpio(int gpio, int val)
246{
247 return 0;
248}
249static inline int omap_mux_init_signal(char *muxname, int val)
250{
251 return 0;
252}
253
Tony Lindgren9796b322010-12-22 18:42:35 -0800254static inline struct omap_hwmod_mux_info *
255omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads)
256{
257 return NULL;
258}
259
Tony Lindgren8d9af882010-12-22 18:42:35 -0800260static inline void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state)
261{
262}
263
Tony Lindgrencc4915d2012-02-23 14:21:28 -0800264static struct omap_board_mux *board_mux __maybe_unused;
Aaro Koskinen7203f8a2010-12-02 13:25:40 +0000265
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800266#endif
267
268/**
269 * omap_mux_get_gpio() - get mux register value based on GPIO number
270 * @gpio: GPIO number
271 *
272 */
273u16 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 */
281void omap_mux_set_gpio(u16 val, int gpio);
282
283/**
Benoit Cousson112485e2010-08-16 10:55:35 +0200284 * omap_mux_get() - get a mux partition by name
285 * @name: Name of the mux partition
286 *
287 */
288struct omap_mux_partition *omap_mux_get(const char *name);
289
290/**
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800291 * omap_mux_read() - read mux register
Benoit Cousson112485e2010-08-16 10:55:35 +0200292 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800293 * @mux_offset: Offset of the mux register
294 *
295 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200296u16 omap_mux_read(struct omap_mux_partition *p, u16 mux_offset);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800297
298/**
299 * omap_mux_write() - write mux register
Benoit Cousson112485e2010-08-16 10:55:35 +0200300 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800301 * @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 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200306void omap_mux_write(struct omap_mux_partition *p, u16 val, u16 mux_offset);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800307
308/**
309 * omap_mux_write_array() - write an array of mux registers
Benoit Cousson112485e2010-08-16 10:55:35 +0200310 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800311 * @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 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200315void omap_mux_write_array(struct omap_mux_partition *p,
316 struct omap_board_mux *board_mux);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800317
318/**
Tony Lindgrenfc440462010-07-05 16:31:36 +0300319 * 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 */
323int omap2420_mux_init(struct omap_board_mux *board_mux, int flags);
324
325/**
Tony Lindgren89ba1092010-07-05 16:31:36 +0300326 * 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 */
330int omap2430_mux_init(struct omap_board_mux *board_mux, int flags);
331
332/**
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800333 * 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 */
337int omap3_mux_init(struct omap_board_mux *board_mux, int flags);
338
339/**
Benoit Coussona041a522010-08-10 17:27:48 +0200340 * omap4_mux_init() - initialize mux system with board specific set
Colin Cross21a42c92011-05-04 14:57:57 -0700341 * @board_subset: Board specific mux table
342 * @board_wkup_subset: Board specific mux table for wakeup instance
Benoit Coussona041a522010-08-10 17:27:48 +0200343 * @flags: OMAP package type used for the board
344 */
Colin Cross21a42c92011-05-04 14:57:57 -0700345int omap4_mux_init(struct omap_board_mux *board_subset,
346 struct omap_board_mux *board_wkup_subset, int flags);
Benoit Coussona041a522010-08-10 17:27:48 +0200347
348/**
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800349 * omap_mux_init - private mux init function, do not call
350 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200351int 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