blob: c9ec50de99c9943f0fa9b96dfe91603a92c749c2 [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/**
90 * struct mux_partition - contain partition related information
91 * @name: name of the current partition
92 * @flags: flags specific to this partition
93 * @phys: physical address
94 * @size: partition size
95 * @base: virtual address after ioremap
96 * @muxmodes: list of nodes that belong to a partition
97 * @node: list node for the partitions linked list
98 */
99struct omap_mux_partition {
100 const char *name;
101 u32 flags;
102 u32 phys;
103 u32 size;
104 void __iomem *base;
105 struct list_head muxmodes;
106 struct list_head node;
107};
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800108
109/**
110 * struct omap_mux - data for omap mux register offset and it's value
111 * @reg_offset: mux register offset from the mux base
112 * @gpio: GPIO number
113 * @muxnames: available signal modes for a ball
Benoit Cousson112485e2010-08-16 10:55:35 +0200114 * @balls: available balls on the package
115 * @partition: mux partition
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800116 */
117struct omap_mux {
118 u16 reg_offset;
119 u16 gpio;
120#ifdef CONFIG_OMAP_MUX
121 char *muxnames[OMAP_MUX_NR_MODES];
122#ifdef CONFIG_DEBUG_FS
123 char *balls[OMAP_MUX_NR_SIDES];
124#endif
125#endif
126};
127
128/**
129 * struct omap_ball - data for balls on omap package
130 * @reg_offset: mux register offset from the mux base
131 * @balls: available balls on the package
132 */
133struct omap_ball {
134 u16 reg_offset;
135 char *balls[OMAP_MUX_NR_SIDES];
136};
137
138/**
139 * struct omap_board_mux - data for initializing mux registers
140 * @reg_offset: mux register offset from the mux base
141 * @mux_value: desired mux value to set
142 */
143struct omap_board_mux {
144 u16 reg_offset;
145 u16 value;
146};
147
Tony Lindgren9796b322010-12-22 18:42:35 -0800148#define OMAP_DEVICE_PAD_ENABLED BIT(7) /* Not needed for board-*.c */
149#define OMAP_DEVICE_PAD_REMUX BIT(1) /* Dynamically remux a pad,
150 needs enable, idle and off
151 values */
152#define OMAP_DEVICE_PAD_WAKEUP BIT(0) /* Pad is wake-up capable */
153
154/**
155 * struct omap_device_pad - device specific pad configuration
156 * @name: signal name
157 * @flags: pad specific runtime flags
158 * @enable: runtime value for a pad
159 * @idle: idle value for a pad
160 * @off: off value for a pad, defaults to safe mode
161 * @partition: mux partition
162 * @mux: mux register
163 */
164struct omap_device_pad {
165 char *name;
166 u8 flags;
167 u16 enable;
168 u16 idle;
169 u16 off;
170 struct omap_mux_partition *partition;
171 struct omap_mux *mux;
172};
173
Tony Lindgren8d9af882010-12-22 18:42:35 -0800174struct omap_hwmod_mux_info;
175
Tony Lindgrenac3dbee2010-07-05 16:31:36 +0300176#if defined(CONFIG_OMAP_MUX)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800177
178/**
179 * omap_mux_init_gpio - initialize a signal based on the GPIO number
180 * @gpio: GPIO number
181 * @val: Options for the mux register value
182 */
183int omap_mux_init_gpio(int gpio, int val);
184
185/**
186 * omap_mux_init_signal - initialize a signal based on the signal name
187 * @muxname: Mux name in mode0_name.signal_name format
188 * @val: Options for the mux register value
189 */
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700190int omap_mux_init_signal(const char *muxname, int val);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800191
Tony Lindgren9796b322010-12-22 18:42:35 -0800192/**
193 * omap_hwmod_mux_init - initialize hwmod specific mux data
194 * @bpads: Board specific device signal names
195 * @nr_pads: Number of signal names for the device
196 */
197extern struct omap_hwmod_mux_info *
198omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads);
199
Tony Lindgren8d9af882010-12-22 18:42:35 -0800200/**
201 * omap_hwmod_mux - omap hwmod specific pin muxing
202 * @hmux: Pads for a hwmod
203 * @state: Desired _HWMOD_STATE
204 *
205 * Called only from omap_hwmod.c, do not use.
206 */
207void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state);
208
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800209#else
210
211static inline int omap_mux_init_gpio(int gpio, int val)
212{
213 return 0;
214}
215static inline int omap_mux_init_signal(char *muxname, int val)
216{
217 return 0;
218}
219
Tony Lindgren9796b322010-12-22 18:42:35 -0800220static inline struct omap_hwmod_mux_info *
221omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads)
222{
223 return NULL;
224}
225
Tony Lindgren8d9af882010-12-22 18:42:35 -0800226static inline void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state)
227{
228}
229
Aaro Koskinen7203f8a2010-12-02 13:25:40 +0000230static struct omap_board_mux *board_mux __initdata __maybe_unused;
231
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800232#endif
233
234/**
235 * omap_mux_get_gpio() - get mux register value based on GPIO number
236 * @gpio: GPIO number
237 *
238 */
239u16 omap_mux_get_gpio(int gpio);
240
241/**
242 * omap_mux_set_gpio() - set mux register value based on GPIO number
243 * @val: New mux register value
244 * @gpio: GPIO number
245 *
246 */
247void omap_mux_set_gpio(u16 val, int gpio);
248
249/**
Benoit Cousson112485e2010-08-16 10:55:35 +0200250 * omap_mux_get() - get a mux partition by name
251 * @name: Name of the mux partition
252 *
253 */
254struct omap_mux_partition *omap_mux_get(const char *name);
255
256/**
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800257 * omap_mux_read() - read mux register
Benoit Cousson112485e2010-08-16 10:55:35 +0200258 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800259 * @mux_offset: Offset of the mux register
260 *
261 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200262u16 omap_mux_read(struct omap_mux_partition *p, u16 mux_offset);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800263
264/**
265 * omap_mux_write() - write mux register
Benoit Cousson112485e2010-08-16 10:55:35 +0200266 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800267 * @val: New mux register value
268 * @mux_offset: Offset of the mux register
269 *
270 * This should be only needed for dynamic remuxing of non-gpio signals.
271 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200272void omap_mux_write(struct omap_mux_partition *p, u16 val, u16 mux_offset);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800273
274/**
275 * omap_mux_write_array() - write an array of mux registers
Benoit Cousson112485e2010-08-16 10:55:35 +0200276 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800277 * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR
278 *
279 * This should be only needed for dynamic remuxing of non-gpio signals.
280 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200281void omap_mux_write_array(struct omap_mux_partition *p,
282 struct omap_board_mux *board_mux);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800283
284/**
Tony Lindgrenfc440462010-07-05 16:31:36 +0300285 * omap2420_mux_init() - initialize mux system with board specific set
286 * @board_mux: Board specific mux table
287 * @flags: OMAP package type used for the board
288 */
289int omap2420_mux_init(struct omap_board_mux *board_mux, int flags);
290
291/**
Tony Lindgren89ba1092010-07-05 16:31:36 +0300292 * omap2430_mux_init() - initialize mux system with board specific set
293 * @board_mux: Board specific mux table
294 * @flags: OMAP package type used for the board
295 */
296int omap2430_mux_init(struct omap_board_mux *board_mux, int flags);
297
298/**
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800299 * omap3_mux_init() - initialize mux system with board specific set
300 * @board_mux: Board specific mux table
301 * @flags: OMAP package type used for the board
302 */
303int omap3_mux_init(struct omap_board_mux *board_mux, int flags);
304
305/**
Benoit Coussona041a522010-08-10 17:27:48 +0200306 * omap4_mux_init() - initialize mux system with board specific set
307 * @board_mux: Board specific mux table
308 * @flags: OMAP package type used for the board
309 */
310int omap4_mux_init(struct omap_board_mux *board_mux, int flags);
311
312/**
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800313 * omap_mux_init - private mux init function, do not call
314 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200315int omap_mux_init(const char *name, u32 flags,
316 u32 mux_pbase, u32 mux_size,
317 struct omap_mux *superset,
318 struct omap_mux *package_subset,
319 struct omap_board_mux *board_mux,
320 struct omap_ball *package_balls);
321