blob: fdb22f14021fd87c015f9291b43adee959def5de [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
Oleg Matcovschi421e8452012-11-26 17:02:03 -080061#define OMAP_MODE_GPIO(partition, x) (((x) & OMAP_MUX_MODE7) == \
62 partition->gpio)
Govindraj.R91930652012-06-05 04:04:11 -070063#define OMAP_MODE_UART(x) (((x) & OMAP_MUX_MODE7) == OMAP_MUX_MODE0)
Tony Lindgren15ac7af2009-12-11 16:16:32 -080064
Benoit Cousson112485e2010-08-16 10:55:35 +020065/* Flags for omapX_mux_init */
Tony Lindgren15ac7af2009-12-11 16:16:32 -080066#define OMAP_PACKAGE_MASK 0xffff
Benoit Coussona7722d82010-09-24 16:56:59 +020067#define OMAP_PACKAGE_CBS 8 /* 547-pin 0.40 0.40 */
Benoit Coussona041a522010-08-10 17:27:48 +020068#define OMAP_PACKAGE_CBL 7 /* 547-pin 0.40 0.40 */
Tony Lindgren6dd8a682010-07-05 16:31:35 +030069#define OMAP_PACKAGE_CBP 6 /* 515-pin 0.40 0.50 */
70#define OMAP_PACKAGE_CUS 5 /* 423-pin 0.65 */
71#define OMAP_PACKAGE_CBB 4 /* 515-pin 0.40 0.50 */
72#define OMAP_PACKAGE_CBC 3 /* 515-pin 0.50 0.65 */
73#define OMAP_PACKAGE_ZAC 2 /* 24xx 447-pin POP */
74#define OMAP_PACKAGE_ZAF 1 /* 2420 447-pin SIP */
Tony Lindgren15ac7af2009-12-11 16:16:32 -080075
76
Benoit Cousson112485e2010-08-16 10:55:35 +020077#define OMAP_MUX_NR_MODES 8 /* Available modes */
78#define OMAP_MUX_NR_SIDES 2 /* Bottom & top */
79
80/*
81 * omap_mux_init flags definition:
82 *
Oleg Matcovschi421e8452012-11-26 17:02:03 -080083 * OMAP_GPIO_MUX_MODE, bits 0-2: gpio muxing mode, same like pad control
84 * register which includes values from 0-7.
Benoit Cousson112485e2010-08-16 10:55:35 +020085 * OMAP_MUX_REG_8BIT: Ensure that access to padconf is done in 8 bits.
86 * The default value is 16 bits.
Benoit Cousson112485e2010-08-16 10:55:35 +020087 */
Oleg Matcovschi421e8452012-11-26 17:02:03 -080088#define OMAP_MUX_GPIO_IN_MODE0 OMAP_MUX_MODE0
89#define OMAP_MUX_GPIO_IN_MODE1 OMAP_MUX_MODE1
90#define OMAP_MUX_GPIO_IN_MODE2 OMAP_MUX_MODE2
91#define OMAP_MUX_GPIO_IN_MODE3 OMAP_MUX_MODE3
92#define OMAP_MUX_GPIO_IN_MODE4 OMAP_MUX_MODE4
93#define OMAP_MUX_GPIO_IN_MODE5 OMAP_MUX_MODE5
94#define OMAP_MUX_GPIO_IN_MODE6 OMAP_MUX_MODE6
95#define OMAP_MUX_GPIO_IN_MODE7 OMAP_MUX_MODE7
96#define OMAP_MUX_REG_8BIT (1 << 3)
Benoit Cousson112485e2010-08-16 10:55:35 +020097
98/**
Tony Lindgren40e44392010-12-22 18:42:35 -080099 * struct omap_board_data - board specific device data
100 * @id: instance id
101 * @flags: additional flags for platform init code
102 * @pads: array of device specific pads
103 * @pads_cnt: ARRAY_SIZE() of pads
104 */
105struct omap_board_data {
106 int id;
107 u32 flags;
108 struct omap_device_pad *pads;
109 int pads_cnt;
110};
111
112/**
Benoit Cousson112485e2010-08-16 10:55:35 +0200113 * struct mux_partition - contain partition related information
114 * @name: name of the current partition
115 * @flags: flags specific to this partition
Oleg Matcovschi421e8452012-11-26 17:02:03 -0800116 * @gpio: gpio mux mode
Benoit Cousson112485e2010-08-16 10:55:35 +0200117 * @phys: physical address
118 * @size: partition size
119 * @base: virtual address after ioremap
120 * @muxmodes: list of nodes that belong to a partition
121 * @node: list node for the partitions linked list
122 */
123struct omap_mux_partition {
124 const char *name;
125 u32 flags;
Oleg Matcovschi421e8452012-11-26 17:02:03 -0800126 u32 gpio;
Benoit Cousson112485e2010-08-16 10:55:35 +0200127 u32 phys;
128 u32 size;
129 void __iomem *base;
130 struct list_head muxmodes;
131 struct list_head node;
132};
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800133
134/**
135 * struct omap_mux - data for omap mux register offset and it's value
136 * @reg_offset: mux register offset from the mux base
137 * @gpio: GPIO number
138 * @muxnames: available signal modes for a ball
Benoit Cousson112485e2010-08-16 10:55:35 +0200139 * @balls: available balls on the package
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800140 */
141struct omap_mux {
142 u16 reg_offset;
143 u16 gpio;
144#ifdef CONFIG_OMAP_MUX
145 char *muxnames[OMAP_MUX_NR_MODES];
146#ifdef CONFIG_DEBUG_FS
147 char *balls[OMAP_MUX_NR_SIDES];
148#endif
149#endif
150};
151
152/**
153 * struct omap_ball - data for balls on omap package
154 * @reg_offset: mux register offset from the mux base
155 * @balls: available balls on the package
156 */
157struct omap_ball {
158 u16 reg_offset;
159 char *balls[OMAP_MUX_NR_SIDES];
160};
161
162/**
163 * struct omap_board_mux - data for initializing mux registers
164 * @reg_offset: mux register offset from the mux base
165 * @mux_value: desired mux value to set
166 */
167struct omap_board_mux {
168 u16 reg_offset;
169 u16 value;
170};
171
Tony Lindgren9796b322010-12-22 18:42:35 -0800172#define OMAP_DEVICE_PAD_REMUX BIT(1) /* Dynamically remux a pad,
173 needs enable, idle and off
174 values */
175#define OMAP_DEVICE_PAD_WAKEUP BIT(0) /* Pad is wake-up capable */
176
177/**
178 * struct omap_device_pad - device specific pad configuration
179 * @name: signal name
180 * @flags: pad specific runtime flags
181 * @enable: runtime value for a pad
182 * @idle: idle value for a pad
183 * @off: off value for a pad, defaults to safe mode
184 * @partition: mux partition
185 * @mux: mux register
186 */
187struct omap_device_pad {
188 char *name;
189 u8 flags;
190 u16 enable;
191 u16 idle;
192 u16 off;
193 struct omap_mux_partition *partition;
194 struct omap_mux *mux;
195};
196
Tony Lindgren8d9af882010-12-22 18:42:35 -0800197struct omap_hwmod_mux_info;
198
Tony Lindgren8aee6032011-03-11 11:32:26 -0800199#define OMAP_MUX_STATIC(signal, mode) \
200{ \
201 .name = (signal), \
202 .enable = (mode), \
203}
204
Tony Lindgrenac3dbee2010-07-05 16:31:36 +0300205#if defined(CONFIG_OMAP_MUX)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800206
207/**
208 * omap_mux_init_gpio - initialize a signal based on the GPIO number
209 * @gpio: GPIO number
210 * @val: Options for the mux register value
211 */
212int omap_mux_init_gpio(int gpio, int val);
213
214/**
215 * omap_mux_init_signal - initialize a signal based on the signal name
216 * @muxname: Mux name in mode0_name.signal_name format
217 * @val: Options for the mux register value
218 */
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700219int omap_mux_init_signal(const char *muxname, int val);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800220
Tony Lindgren9796b322010-12-22 18:42:35 -0800221/**
222 * omap_hwmod_mux_init - initialize hwmod specific mux data
223 * @bpads: Board specific device signal names
224 * @nr_pads: Number of signal names for the device
225 */
226extern struct omap_hwmod_mux_info *
227omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads);
228
Tony Lindgren8d9af882010-12-22 18:42:35 -0800229/**
230 * omap_hwmod_mux - omap hwmod specific pin muxing
231 * @hmux: Pads for a hwmod
232 * @state: Desired _HWMOD_STATE
233 *
234 * Called only from omap_hwmod.c, do not use.
235 */
236void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state);
237
Govindraj.R91930652012-06-05 04:04:11 -0700238int omap_mux_get_by_name(const char *muxname,
239 struct omap_mux_partition **found_partition,
240 struct omap_mux **found_mux);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800241#else
242
Govindraj.R91930652012-06-05 04:04:11 -0700243static inline int omap_mux_get_by_name(const char *muxname,
244 struct omap_mux_partition **found_partition,
245 struct omap_mux **found_mux)
246{
247 return 0;
248}
249
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800250static inline int omap_mux_init_gpio(int gpio, int val)
251{
252 return 0;
253}
254static inline int omap_mux_init_signal(char *muxname, int val)
255{
256 return 0;
257}
258
Tony Lindgren9796b322010-12-22 18:42:35 -0800259static inline struct omap_hwmod_mux_info *
260omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads)
261{
262 return NULL;
263}
264
Tony Lindgren8d9af882010-12-22 18:42:35 -0800265static inline void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state)
266{
267}
268
Tony Lindgrencc4915d2012-02-23 14:21:28 -0800269static struct omap_board_mux *board_mux __maybe_unused;
Aaro Koskinen7203f8a2010-12-02 13:25:40 +0000270
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800271#endif
272
273/**
274 * omap_mux_get_gpio() - get mux register value based on GPIO number
275 * @gpio: GPIO number
276 *
277 */
278u16 omap_mux_get_gpio(int gpio);
279
280/**
281 * omap_mux_set_gpio() - set mux register value based on GPIO number
282 * @val: New mux register value
283 * @gpio: GPIO number
284 *
285 */
286void omap_mux_set_gpio(u16 val, int gpio);
287
288/**
Benoit Cousson112485e2010-08-16 10:55:35 +0200289 * omap_mux_get() - get a mux partition by name
290 * @name: Name of the mux partition
291 *
292 */
293struct omap_mux_partition *omap_mux_get(const char *name);
294
295/**
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800296 * omap_mux_read() - read mux register
Benoit Cousson112485e2010-08-16 10:55:35 +0200297 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800298 * @mux_offset: Offset of the mux register
299 *
300 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200301u16 omap_mux_read(struct omap_mux_partition *p, u16 mux_offset);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800302
303/**
304 * omap_mux_write() - write mux register
Benoit Cousson112485e2010-08-16 10:55:35 +0200305 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800306 * @val: New mux register value
307 * @mux_offset: Offset of the mux register
308 *
309 * This should be only needed for dynamic remuxing of non-gpio signals.
310 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200311void omap_mux_write(struct omap_mux_partition *p, u16 val, u16 mux_offset);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800312
313/**
314 * omap_mux_write_array() - write an array of mux registers
Benoit Cousson112485e2010-08-16 10:55:35 +0200315 * @partition: Mux partition
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800316 * @board_mux: Array of mux registers terminated by MAP_MUX_TERMINATOR
317 *
318 * This should be only needed for dynamic remuxing of non-gpio signals.
319 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200320void omap_mux_write_array(struct omap_mux_partition *p,
321 struct omap_board_mux *board_mux);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -0800322
323/**
Tony Lindgrenfc440462010-07-05 16:31:36 +0300324 * omap2420_mux_init() - initialize mux system with board specific set
325 * @board_mux: Board specific mux table
326 * @flags: OMAP package type used for the board
327 */
328int omap2420_mux_init(struct omap_board_mux *board_mux, int flags);
329
330/**
Tony Lindgren89ba1092010-07-05 16:31:36 +0300331 * omap2430_mux_init() - initialize mux system with board specific set
332 * @board_mux: Board specific mux table
333 * @flags: OMAP package type used for the board
334 */
335int omap2430_mux_init(struct omap_board_mux *board_mux, int flags);
336
337/**
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800338 * omap3_mux_init() - initialize mux system with board specific set
339 * @board_mux: Board specific mux table
340 * @flags: OMAP package type used for the board
341 */
342int omap3_mux_init(struct omap_board_mux *board_mux, int flags);
343
344/**
Benoit Coussona041a522010-08-10 17:27:48 +0200345 * omap4_mux_init() - initialize mux system with board specific set
Colin Cross21a42c92011-05-04 14:57:57 -0700346 * @board_subset: Board specific mux table
347 * @board_wkup_subset: Board specific mux table for wakeup instance
Benoit Coussona041a522010-08-10 17:27:48 +0200348 * @flags: OMAP package type used for the board
349 */
Colin Cross21a42c92011-05-04 14:57:57 -0700350int omap4_mux_init(struct omap_board_mux *board_subset,
351 struct omap_board_mux *board_wkup_subset, int flags);
Benoit Coussona041a522010-08-10 17:27:48 +0200352
353/**
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800354 * omap_mux_init - private mux init function, do not call
355 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200356int omap_mux_init(const char *name, u32 flags,
357 u32 mux_pbase, u32 mux_size,
358 struct omap_mux *superset,
359 struct omap_mux *package_subset,
360 struct omap_board_mux *board_mux,
361 struct omap_ball *package_balls);
362