blob: a4ab1e364313693dcdef6292e3310a8afa9fe6be [file] [log] [blame]
Tony Lindgren1dbae812005-11-10 14:26:51 +00001/*
2 * linux/arch/arm/mach-omap2/mux.c
3 *
Benoit Cousson112485e2010-08-16 10:55:35 +02004 * OMAP2, OMAP3 and OMAP4 pin multiplexing configurations
Tony Lindgren1dbae812005-11-10 14:26:51 +00005 *
Benoit Cousson112485e2010-08-16 10:55:35 +02006 * Copyright (C) 2004 - 2010 Texas Instruments Inc.
Tony Lindgren93308992008-01-24 17:24:15 -08007 * Copyright (C) 2003 - 2008 Nokia Corporation
Tony Lindgren1dbae812005-11-10 14:26:51 +00008 *
Tony Lindgren93308992008-01-24 17:24:15 -08009 * Written by Tony Lindgren
Tony Lindgren1dbae812005-11-10 14:26:51 +000010 *
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License as published by
13 * the Free Software Foundation; either version 2 of the License, or
14 * (at your option) any later version.
15 *
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
20 *
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 *
25 */
Paul Walmsley4814ced2010-10-08 11:40:20 -060026#include <linux/kernel.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000027#include <linux/init.h>
Russell Kingfced80c2008-09-06 12:10:45 +010028#include <linux/io.h>
Tony Lindgren15ac7af2009-12-11 16:16:32 -080029#include <linux/list.h>
Paul Walmsley4814ced2010-10-08 11:40:20 -060030#include <linux/slab.h>
Tony Lindgren4b715ef2009-12-11 16:16:32 -080031#include <linux/ctype.h>
32#include <linux/debugfs.h>
33#include <linux/seq_file.h>
34#include <linux/uaccess.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000035
Russell Kingfced80c2008-09-06 12:10:45 +010036#include <asm/system.h>
37
Tony Lindgren9796b322010-12-22 18:42:35 -080038#include <plat/omap_hwmod.h>
39
Paul Walmsley4814ced2010-10-08 11:40:20 -060040#include "control.h"
Tony Lindgren15ac7af2009-12-11 16:16:32 -080041#include "mux.h"
Tony Lindgren1dbae812005-11-10 14:26:51 +000042
Mike Rapoport92c9f502009-12-11 16:16:31 -080043#define OMAP_MUX_BASE_OFFSET 0x30 /* Offset from CTRL_BASE */
44#define OMAP_MUX_BASE_SZ 0x5ca
45
Tony Lindgren15ac7af2009-12-11 16:16:32 -080046struct omap_mux_entry {
47 struct omap_mux mux;
48 struct list_head node;
49};
50
Benoit Cousson112485e2010-08-16 10:55:35 +020051static LIST_HEAD(mux_partitions);
52static DEFINE_MUTEX(muxmode_mutex);
Mike Rapoport92c9f502009-12-11 16:16:31 -080053
Benoit Cousson112485e2010-08-16 10:55:35 +020054struct omap_mux_partition *omap_mux_get(const char *name)
Mike Rapoport92c9f502009-12-11 16:16:31 -080055{
Benoit Cousson112485e2010-08-16 10:55:35 +020056 struct omap_mux_partition *partition;
57
58 list_for_each_entry(partition, &mux_partitions, node) {
59 if (!strcmp(name, partition->name))
60 return partition;
61 }
62
63 return NULL;
Mike Rapoport92c9f502009-12-11 16:16:31 -080064}
65
Benoit Cousson112485e2010-08-16 10:55:35 +020066u16 omap_mux_read(struct omap_mux_partition *partition, u16 reg)
Mike Rapoport92c9f502009-12-11 16:16:31 -080067{
Benoit Cousson112485e2010-08-16 10:55:35 +020068 if (partition->flags & OMAP_MUX_REG_8BIT)
69 return __raw_readb(partition->base + reg);
Mike Rapoport92c9f502009-12-11 16:16:31 -080070 else
Benoit Cousson112485e2010-08-16 10:55:35 +020071 return __raw_readw(partition->base + reg);
Mike Rapoport92c9f502009-12-11 16:16:31 -080072}
Tony Lindgren7d7f6652008-01-25 00:42:48 -080073
Benoit Cousson112485e2010-08-16 10:55:35 +020074void omap_mux_write(struct omap_mux_partition *partition, u16 val,
75 u16 reg)
Tony Lindgrend4bb72e2010-01-19 15:15:24 -080076{
Benoit Cousson112485e2010-08-16 10:55:35 +020077 if (partition->flags & OMAP_MUX_REG_8BIT)
78 __raw_writeb(val, partition->base + reg);
79 else
80 __raw_writew(val, partition->base + reg);
81}
82
83void omap_mux_write_array(struct omap_mux_partition *partition,
84 struct omap_board_mux *board_mux)
85{
86 while (board_mux->reg_offset != OMAP_MUX_TERMINATOR) {
87 omap_mux_write(partition, board_mux->value,
88 board_mux->reg_offset);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -080089 board_mux++;
90 }
91}
92
Tony Lindgren15ac7af2009-12-11 16:16:32 -080093#ifdef CONFIG_OMAP_MUX
94
95static char *omap_mux_options;
96
Benoit Cousson112485e2010-08-16 10:55:35 +020097static int __init _omap_mux_init_gpio(struct omap_mux_partition *partition,
98 int gpio, int val)
Tony Lindgren15ac7af2009-12-11 16:16:32 -080099{
100 struct omap_mux_entry *e;
Sanjeev Premica828762010-09-23 18:27:18 -0700101 struct omap_mux *gpio_mux = NULL;
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300102 u16 old_mode;
103 u16 mux_mode;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800104 int found = 0;
Benoit Cousson112485e2010-08-16 10:55:35 +0200105 struct list_head *muxmodes = &partition->muxmodes;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800106
107 if (!gpio)
108 return -EINVAL;
109
Benoit Cousson112485e2010-08-16 10:55:35 +0200110 list_for_each_entry(e, muxmodes, node) {
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800111 struct omap_mux *m = &e->mux;
112 if (gpio == m->gpio) {
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300113 gpio_mux = m;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800114 found++;
115 }
116 }
117
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300118 if (found == 0) {
Dan Murphy032a6422010-11-15 09:50:50 -0600119 pr_err("%s: Could not set gpio%i\n", __func__, gpio);
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300120 return -ENODEV;
121 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800122
123 if (found > 1) {
Dan Murphy032a6422010-11-15 09:50:50 -0600124 pr_info("%s: Multiple gpio paths (%d) for gpio%i\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200125 found, gpio);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800126 return -EINVAL;
127 }
128
Benoit Cousson112485e2010-08-16 10:55:35 +0200129 old_mode = omap_mux_read(partition, gpio_mux->reg_offset);
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300130 mux_mode = val & ~(OMAP_MUX_NR_MODES - 1);
Benoit Cousson112485e2010-08-16 10:55:35 +0200131 if (partition->flags & OMAP_MUX_GPIO_IN_MODE3)
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300132 mux_mode |= OMAP_MUX_MODE3;
133 else
134 mux_mode |= OMAP_MUX_MODE4;
Dan Murphy032a6422010-11-15 09:50:50 -0600135 pr_debug("%s: Setting signal %s.gpio%i 0x%04x -> 0x%04x\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200136 gpio_mux->muxnames[0], gpio, old_mode, mux_mode);
Benoit Cousson112485e2010-08-16 10:55:35 +0200137 omap_mux_write(partition, mux_mode, gpio_mux->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800138
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300139 return 0;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800140}
141
Benoit Cousson112485e2010-08-16 10:55:35 +0200142int __init omap_mux_init_gpio(int gpio, int val)
143{
144 struct omap_mux_partition *partition;
145 int ret;
146
147 list_for_each_entry(partition, &mux_partitions, node) {
148 ret = _omap_mux_init_gpio(partition, gpio, val);
149 if (!ret)
150 return ret;
151 }
152
153 return -ENODEV;
154}
155
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800156static int __init _omap_mux_get_by_name(struct omap_mux_partition *partition,
157 const char *muxname,
158 struct omap_mux **found_mux)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800159{
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800160 struct omap_mux *mux = NULL;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800161 struct omap_mux_entry *e;
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700162 const char *mode_name;
Felipe Balbiafb7d702011-01-17 06:31:18 +0200163 int found = 0, found_mode = 0, mode0_len = 0;
Benoit Cousson112485e2010-08-16 10:55:35 +0200164 struct list_head *muxmodes = &partition->muxmodes;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800165
166 mode_name = strchr(muxname, '.');
167 if (mode_name) {
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700168 mode0_len = strlen(muxname) - strlen(mode_name);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800169 mode_name++;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800170 } else {
171 mode_name = muxname;
172 }
173
Benoit Cousson112485e2010-08-16 10:55:35 +0200174 list_for_each_entry(e, muxmodes, node) {
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800175 char *m0_entry;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800176 int i;
177
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800178 mux = &e->mux;
179 m0_entry = mux->muxnames[0];
180
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700181 /* First check for full name in mode0.muxmode format */
182 if (mode0_len && strncmp(muxname, m0_entry, mode0_len))
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800183 continue;
184
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700185 /* Then check for muxmode only */
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800186 for (i = 0; i < OMAP_MUX_NR_MODES; i++) {
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800187 char *mode_cur = mux->muxnames[i];
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800188
189 if (!mode_cur)
190 continue;
191
192 if (!strcmp(mode_name, mode_cur)) {
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800193 *found_mux = mux;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800194 found++;
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800195 found_mode = i;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800196 }
197 }
198 }
199
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800200 if (found == 1) {
201 return found_mode;
202 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800203
204 if (found > 1) {
Dan Murphy032a6422010-11-15 09:50:50 -0600205 pr_err("%s: Multiple signal paths (%i) for %s\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200206 found, muxname);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800207 return -EINVAL;
208 }
209
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800210 pr_err("%s: Could not find signal %s\n", __func__, muxname);
211
212 return -ENODEV;
213}
214
215static int __init
216omap_mux_get_by_name(const char *muxname,
217 struct omap_mux_partition **found_partition,
218 struct omap_mux **found_mux)
219{
220 struct omap_mux_partition *partition;
221
222 list_for_each_entry(partition, &mux_partitions, node) {
223 struct omap_mux *mux = NULL;
224 int mux_mode = _omap_mux_get_by_name(partition, muxname, &mux);
225 if (mux_mode < 0)
226 continue;
227
228 *found_partition = partition;
229 *found_mux = mux;
230
231 return mux_mode;
232 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800233
234 return -ENODEV;
235}
236
Benoit Cousson112485e2010-08-16 10:55:35 +0200237int __init omap_mux_init_signal(const char *muxname, int val)
238{
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800239 struct omap_mux_partition *partition = NULL;
240 struct omap_mux *mux = NULL;
241 u16 old_mode;
242 int mux_mode;
Benoit Cousson112485e2010-08-16 10:55:35 +0200243
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800244 mux_mode = omap_mux_get_by_name(muxname, &partition, &mux);
245 if (mux_mode < 0)
246 return mux_mode;
Benoit Cousson112485e2010-08-16 10:55:35 +0200247
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800248 old_mode = omap_mux_read(partition, mux->reg_offset);
249 mux_mode |= val;
250 pr_debug("%s: Setting signal %s 0x%04x -> 0x%04x\n",
251 __func__, muxname, old_mode, mux_mode);
252 omap_mux_write(partition, mux_mode, mux->reg_offset);
Benoit Cousson112485e2010-08-16 10:55:35 +0200253
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800254 return 0;
Benoit Cousson112485e2010-08-16 10:55:35 +0200255}
256
Tony Lindgren9796b322010-12-22 18:42:35 -0800257struct omap_hwmod_mux_info * __init
258omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads)
259{
260 struct omap_hwmod_mux_info *hmux;
Tony Lindgren029268e2011-03-11 11:32:25 -0800261 int i, nr_pads_dynamic = 0;
Tony Lindgren9796b322010-12-22 18:42:35 -0800262
263 if (!bpads || nr_pads < 1)
264 return NULL;
265
266 hmux = kzalloc(sizeof(struct omap_hwmod_mux_info), GFP_KERNEL);
267 if (!hmux)
268 goto err1;
269
270 hmux->nr_pads = nr_pads;
271
272 hmux->pads = kzalloc(sizeof(struct omap_device_pad) *
273 nr_pads, GFP_KERNEL);
274 if (!hmux->pads)
275 goto err2;
276
277 for (i = 0; i < hmux->nr_pads; i++) {
278 struct omap_mux_partition *partition;
279 struct omap_device_pad *bpad = &bpads[i], *pad = &hmux->pads[i];
280 struct omap_mux *mux;
281 int mux_mode;
282
283 mux_mode = omap_mux_get_by_name(bpad->name, &partition, &mux);
284 if (mux_mode < 0)
285 goto err3;
286 if (!pad->partition)
287 pad->partition = partition;
288 if (!pad->mux)
289 pad->mux = mux;
290
291 pad->name = kzalloc(strlen(bpad->name) + 1, GFP_KERNEL);
292 if (!pad->name) {
293 int j;
294
295 for (j = i - 1; j >= 0; j--)
296 kfree(hmux->pads[j].name);
297 goto err3;
298 }
299 strcpy(pad->name, bpad->name);
300
301 pad->flags = bpad->flags;
302 pad->enable = bpad->enable;
303 pad->idle = bpad->idle;
304 pad->off = bpad->off;
Tony Lindgren029268e2011-03-11 11:32:25 -0800305
306 if (pad->flags & OMAP_DEVICE_PAD_REMUX)
307 nr_pads_dynamic++;
308
Tony Lindgren9796b322010-12-22 18:42:35 -0800309 pr_debug("%s: Initialized %s\n", __func__, pad->name);
310 }
311
Tony Lindgren029268e2011-03-11 11:32:25 -0800312 if (!nr_pads_dynamic)
313 return hmux;
314
315 /*
316 * Add pads that need dynamic muxing into a separate list
317 */
318
319 hmux->nr_pads_dynamic = nr_pads_dynamic;
320 hmux->pads_dynamic = kzalloc(sizeof(struct omap_device_pad *) *
321 nr_pads_dynamic, GFP_KERNEL);
322 if (!hmux->pads_dynamic) {
323 pr_err("%s: Could not allocate dynamic pads\n", __func__);
324 return hmux;
325 }
326
327 nr_pads_dynamic = 0;
328 for (i = 0; i < hmux->nr_pads; i++) {
329 struct omap_device_pad *pad = &hmux->pads[i];
330
331 if (pad->flags & OMAP_DEVICE_PAD_REMUX) {
332 pr_debug("%s: pad %s tagged dynamic\n",
333 __func__, pad->name);
334 hmux->pads_dynamic[nr_pads_dynamic] = pad;
335 nr_pads_dynamic++;
336 }
337 }
338
Tony Lindgren9796b322010-12-22 18:42:35 -0800339 return hmux;
340
341err3:
342 kfree(hmux->pads);
343err2:
344 kfree(hmux);
345err1:
346 pr_err("%s: Could not allocate device mux entry\n", __func__);
347
348 return NULL;
349}
350
Tony Lindgren8d9af882010-12-22 18:42:35 -0800351/* Assumes the calling function takes care of locking */
352void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state)
353{
354 int i;
355
Tony Lindgren029268e2011-03-11 11:32:25 -0800356 /* Runtime idling of dynamic pads */
357 if (state == _HWMOD_STATE_IDLE && hmux->enabled) {
358 for (i = 0; i < hmux->nr_pads_dynamic; i++) {
359 struct omap_device_pad *pad = hmux->pads_dynamic[i];
360 int val = -EINVAL;
361
Tony Lindgren029268e2011-03-11 11:32:25 -0800362 val = pad->idle;
363 omap_mux_write(pad->partition, val,
364 pad->mux->reg_offset);
365 }
366
367 return;
368 }
369
370 /* Runtime enabling of dynamic pads */
R Sricharan86c79bf2011-03-11 11:32:25 -0800371 if ((state == _HWMOD_STATE_ENABLED) && hmux->pads_dynamic
372 && hmux->enabled) {
Tony Lindgren029268e2011-03-11 11:32:25 -0800373 for (i = 0; i < hmux->nr_pads_dynamic; i++) {
374 struct omap_device_pad *pad = hmux->pads_dynamic[i];
375 int val = -EINVAL;
376
Tony Lindgren029268e2011-03-11 11:32:25 -0800377 val = pad->enable;
378 omap_mux_write(pad->partition, val,
379 pad->mux->reg_offset);
Tony Lindgren029268e2011-03-11 11:32:25 -0800380 }
381
R Sricharan86c79bf2011-03-11 11:32:25 -0800382 return;
Tony Lindgren029268e2011-03-11 11:32:25 -0800383 }
384
385 /* Enabling or disabling of all pads */
Tony Lindgren8d9af882010-12-22 18:42:35 -0800386 for (i = 0; i < hmux->nr_pads; i++) {
387 struct omap_device_pad *pad = &hmux->pads[i];
388 int flags, val = -EINVAL;
389
390 flags = pad->flags;
391
392 switch (state) {
393 case _HWMOD_STATE_ENABLED:
Tony Lindgren8d9af882010-12-22 18:42:35 -0800394 val = pad->enable;
395 pr_debug("%s: Enabling %s %x\n", __func__,
396 pad->name, val);
397 break;
Tony Lindgren8d9af882010-12-22 18:42:35 -0800398 case _HWMOD_STATE_DISABLED:
Tony Lindgren8d9af882010-12-22 18:42:35 -0800399 /* Use safe mode unless OMAP_DEVICE_PAD_REMUX */
400 if (flags & OMAP_DEVICE_PAD_REMUX)
401 val = pad->off;
402 else
403 val = OMAP_MUX_MODE7;
Tony Lindgren8d9af882010-12-22 18:42:35 -0800404 pr_debug("%s: Disabling %s %x\n", __func__,
405 pad->name, val);
R Sricharan86c79bf2011-03-11 11:32:25 -0800406 break;
407 default:
408 /* Nothing to be done */
409 break;
Tony Lindgren8d9af882010-12-22 18:42:35 -0800410 };
411
412 if (val >= 0) {
413 omap_mux_write(pad->partition, val,
414 pad->mux->reg_offset);
415 pad->flags = flags;
416 }
417 }
Tony Lindgren029268e2011-03-11 11:32:25 -0800418
419 if (state == _HWMOD_STATE_ENABLED)
420 hmux->enabled = true;
421 else
422 hmux->enabled = false;
Tony Lindgren8d9af882010-12-22 18:42:35 -0800423}
424
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800425#ifdef CONFIG_DEBUG_FS
426
427#define OMAP_MUX_MAX_NR_FLAGS 10
428#define OMAP_MUX_TEST_FLAG(val, mask) \
429 if (((val) & (mask)) == (mask)) { \
430 i++; \
431 flags[i] = #mask; \
432 }
433
434/* REVISIT: Add checking for non-optimal mux settings */
435static inline void omap_mux_decode(struct seq_file *s, u16 val)
436{
437 char *flags[OMAP_MUX_MAX_NR_FLAGS];
Tony Lindgren78737ae2010-02-01 13:03:42 -0800438 char mode[sizeof("OMAP_MUX_MODE") + 1];
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800439 int i = -1;
440
441 sprintf(mode, "OMAP_MUX_MODE%d", val & 0x7);
442 i++;
443 flags[i] = mode;
444
445 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_OFF_WAKEUPENABLE);
446 if (val & OMAP_OFF_EN) {
447 if (!(val & OMAP_OFFOUT_EN)) {
448 if (!(val & OMAP_OFF_PULL_UP)) {
449 OMAP_MUX_TEST_FLAG(val,
450 OMAP_PIN_OFF_INPUT_PULLDOWN);
451 } else {
452 OMAP_MUX_TEST_FLAG(val,
453 OMAP_PIN_OFF_INPUT_PULLUP);
454 }
455 } else {
456 if (!(val & OMAP_OFFOUT_VAL)) {
457 OMAP_MUX_TEST_FLAG(val,
458 OMAP_PIN_OFF_OUTPUT_LOW);
459 } else {
460 OMAP_MUX_TEST_FLAG(val,
461 OMAP_PIN_OFF_OUTPUT_HIGH);
462 }
463 }
464 }
465
466 if (val & OMAP_INPUT_EN) {
467 if (val & OMAP_PULL_ENA) {
468 if (!(val & OMAP_PULL_UP)) {
469 OMAP_MUX_TEST_FLAG(val,
470 OMAP_PIN_INPUT_PULLDOWN);
471 } else {
472 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT_PULLUP);
473 }
474 } else {
475 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT);
476 }
477 } else {
478 i++;
479 flags[i] = "OMAP_PIN_OUTPUT";
480 }
481
482 do {
483 seq_printf(s, "%s", flags[i]);
484 if (i > 0)
485 seq_printf(s, " | ");
486 } while (i-- > 0);
487}
488
Benoit Cousson112485e2010-08-16 10:55:35 +0200489#define OMAP_MUX_DEFNAME_LEN 32
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800490
491static int omap_mux_dbg_board_show(struct seq_file *s, void *unused)
492{
Benoit Cousson112485e2010-08-16 10:55:35 +0200493 struct omap_mux_partition *partition = s->private;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800494 struct omap_mux_entry *e;
Benoit Cousson112485e2010-08-16 10:55:35 +0200495 u8 omap_gen = omap_rev() >> 28;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800496
Benoit Cousson112485e2010-08-16 10:55:35 +0200497 list_for_each_entry(e, &partition->muxmodes, node) {
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800498 struct omap_mux *m = &e->mux;
499 char m0_def[OMAP_MUX_DEFNAME_LEN];
500 char *m0_name = m->muxnames[0];
501 u16 val;
502 int i, mode;
503
504 if (!m0_name)
505 continue;
506
Tony Lindgren78737ae2010-02-01 13:03:42 -0800507 /* REVISIT: Needs to be updated if mode0 names get longer */
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800508 for (i = 0; i < OMAP_MUX_DEFNAME_LEN; i++) {
509 if (m0_name[i] == '\0') {
510 m0_def[i] = m0_name[i];
511 break;
512 }
513 m0_def[i] = toupper(m0_name[i]);
514 }
Benoit Cousson112485e2010-08-16 10:55:35 +0200515 val = omap_mux_read(partition, m->reg_offset);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800516 mode = val & OMAP_MUX_MODE7;
Benoit Cousson112485e2010-08-16 10:55:35 +0200517 if (mode != 0)
518 seq_printf(s, "/* %s */\n", m->muxnames[mode]);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800519
Benoit Cousson112485e2010-08-16 10:55:35 +0200520 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300521 * XXX: Might be revisited to support differences across
Benoit Cousson112485e2010-08-16 10:55:35 +0200522 * same OMAP generation.
523 */
524 seq_printf(s, "OMAP%d_MUX(%s, ", omap_gen, m0_def);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800525 omap_mux_decode(s, val);
526 seq_printf(s, "),\n");
527 }
528
529 return 0;
530}
531
532static int omap_mux_dbg_board_open(struct inode *inode, struct file *file)
533{
Benoit Cousson112485e2010-08-16 10:55:35 +0200534 return single_open(file, omap_mux_dbg_board_show, inode->i_private);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800535}
536
537static const struct file_operations omap_mux_dbg_board_fops = {
538 .open = omap_mux_dbg_board_open,
539 .read = seq_read,
540 .llseek = seq_lseek,
541 .release = single_release,
542};
543
Benoit Cousson112485e2010-08-16 10:55:35 +0200544static struct omap_mux_partition *omap_mux_get_partition(struct omap_mux *mux)
545{
546 struct omap_mux_partition *partition;
547
548 list_for_each_entry(partition, &mux_partitions, node) {
549 struct list_head *muxmodes = &partition->muxmodes;
550 struct omap_mux_entry *e;
551
552 list_for_each_entry(e, muxmodes, node) {
553 struct omap_mux *m = &e->mux;
554
555 if (m == mux)
556 return partition;
557 }
558 }
559
560 return NULL;
561}
562
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800563static int omap_mux_dbg_signal_show(struct seq_file *s, void *unused)
564{
565 struct omap_mux *m = s->private;
Benoit Cousson112485e2010-08-16 10:55:35 +0200566 struct omap_mux_partition *partition;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800567 const char *none = "NA";
568 u16 val;
569 int mode;
570
Benoit Cousson112485e2010-08-16 10:55:35 +0200571 partition = omap_mux_get_partition(m);
572 if (!partition)
573 return 0;
574
575 val = omap_mux_read(partition, m->reg_offset);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800576 mode = val & OMAP_MUX_MODE7;
577
Benoit Cousson112485e2010-08-16 10:55:35 +0200578 seq_printf(s, "name: %s.%s (0x%08x/0x%03x = 0x%04x), b %s, t %s\n",
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800579 m->muxnames[0], m->muxnames[mode],
Benoit Cousson112485e2010-08-16 10:55:35 +0200580 partition->phys + m->reg_offset, m->reg_offset, val,
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800581 m->balls[0] ? m->balls[0] : none,
582 m->balls[1] ? m->balls[1] : none);
583 seq_printf(s, "mode: ");
584 omap_mux_decode(s, val);
585 seq_printf(s, "\n");
586 seq_printf(s, "signals: %s | %s | %s | %s | %s | %s | %s | %s\n",
587 m->muxnames[0] ? m->muxnames[0] : none,
588 m->muxnames[1] ? m->muxnames[1] : none,
589 m->muxnames[2] ? m->muxnames[2] : none,
590 m->muxnames[3] ? m->muxnames[3] : none,
591 m->muxnames[4] ? m->muxnames[4] : none,
592 m->muxnames[5] ? m->muxnames[5] : none,
593 m->muxnames[6] ? m->muxnames[6] : none,
594 m->muxnames[7] ? m->muxnames[7] : none);
595
596 return 0;
597}
598
599#define OMAP_MUX_MAX_ARG_CHAR 7
600
601static ssize_t omap_mux_dbg_signal_write(struct file *file,
Benoit Cousson112485e2010-08-16 10:55:35 +0200602 const char __user *user_buf,
603 size_t count, loff_t *ppos)
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800604{
605 char buf[OMAP_MUX_MAX_ARG_CHAR];
606 struct seq_file *seqf;
607 struct omap_mux *m;
608 unsigned long val;
609 int buf_size, ret;
Benoit Cousson112485e2010-08-16 10:55:35 +0200610 struct omap_mux_partition *partition;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800611
612 if (count > OMAP_MUX_MAX_ARG_CHAR)
613 return -EINVAL;
614
615 memset(buf, 0, sizeof(buf));
616 buf_size = min(count, sizeof(buf) - 1);
617
618 if (copy_from_user(buf, user_buf, buf_size))
619 return -EFAULT;
620
621 ret = strict_strtoul(buf, 0x10, &val);
622 if (ret < 0)
623 return ret;
624
625 if (val > 0xffff)
626 return -EINVAL;
627
628 seqf = file->private_data;
629 m = seqf->private;
630
Benoit Cousson112485e2010-08-16 10:55:35 +0200631 partition = omap_mux_get_partition(m);
632 if (!partition)
633 return -ENODEV;
634
635 omap_mux_write(partition, (u16)val, m->reg_offset);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800636 *ppos += count;
637
638 return count;
639}
640
641static int omap_mux_dbg_signal_open(struct inode *inode, struct file *file)
642{
643 return single_open(file, omap_mux_dbg_signal_show, inode->i_private);
644}
645
646static const struct file_operations omap_mux_dbg_signal_fops = {
647 .open = omap_mux_dbg_signal_open,
648 .read = seq_read,
649 .write = omap_mux_dbg_signal_write,
650 .llseek = seq_lseek,
651 .release = single_release,
652};
653
654static struct dentry *mux_dbg_dir;
655
Benoit Cousson112485e2010-08-16 10:55:35 +0200656static void __init omap_mux_dbg_create_entry(
657 struct omap_mux_partition *partition,
658 struct dentry *mux_dbg_dir)
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800659{
660 struct omap_mux_entry *e;
661
Benoit Cousson112485e2010-08-16 10:55:35 +0200662 list_for_each_entry(e, &partition->muxmodes, node) {
663 struct omap_mux *m = &e->mux;
664
Vasiliy Kulikov9b127712011-02-04 12:23:13 +0000665 (void)debugfs_create_file(m->muxnames[0], S_IWUSR, mux_dbg_dir,
Benoit Cousson112485e2010-08-16 10:55:35 +0200666 m, &omap_mux_dbg_signal_fops);
667 }
668}
669
670static void __init omap_mux_dbg_init(void)
671{
672 struct omap_mux_partition *partition;
673 static struct dentry *mux_dbg_board_dir;
674
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800675 mux_dbg_dir = debugfs_create_dir("omap_mux", NULL);
676 if (!mux_dbg_dir)
677 return;
678
Benoit Cousson112485e2010-08-16 10:55:35 +0200679 mux_dbg_board_dir = debugfs_create_dir("board", mux_dbg_dir);
680 if (!mux_dbg_board_dir)
681 return;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800682
Benoit Cousson112485e2010-08-16 10:55:35 +0200683 list_for_each_entry(partition, &mux_partitions, node) {
684 omap_mux_dbg_create_entry(partition, mux_dbg_dir);
685 (void)debugfs_create_file(partition->name, S_IRUGO,
686 mux_dbg_board_dir, partition,
687 &omap_mux_dbg_board_fops);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800688 }
689}
690
691#else
692static inline void omap_mux_dbg_init(void)
693{
694}
695#endif /* CONFIG_DEBUG_FS */
696
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800697static void __init omap_mux_free_names(struct omap_mux *m)
698{
699 int i;
700
701 for (i = 0; i < OMAP_MUX_NR_MODES; i++)
702 kfree(m->muxnames[i]);
703
704#ifdef CONFIG_DEBUG_FS
705 for (i = 0; i < OMAP_MUX_NR_SIDES; i++)
706 kfree(m->balls[i]);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000707#endif
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800708
709}
710
711/* Free all data except for GPIO pins unless CONFIG_DEBUG_FS is set */
712static int __init omap_mux_late_init(void)
713{
Benoit Cousson112485e2010-08-16 10:55:35 +0200714 struct omap_mux_partition *partition;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800715
Benoit Cousson112485e2010-08-16 10:55:35 +0200716 list_for_each_entry(partition, &mux_partitions, node) {
717 struct omap_mux_entry *e, *tmp;
718 list_for_each_entry_safe(e, tmp, &partition->muxmodes, node) {
719 struct omap_mux *m = &e->mux;
720 u16 mode = omap_mux_read(partition, m->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800721
Benoit Cousson112485e2010-08-16 10:55:35 +0200722 if (OMAP_MODE_GPIO(mode))
723 continue;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800724
725#ifndef CONFIG_DEBUG_FS
Benoit Cousson112485e2010-08-16 10:55:35 +0200726 mutex_lock(&muxmode_mutex);
727 list_del(&e->node);
728 mutex_unlock(&muxmode_mutex);
729 omap_mux_free_names(m);
730 kfree(m);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800731#endif
Benoit Cousson112485e2010-08-16 10:55:35 +0200732 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800733 }
734
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800735 omap_mux_dbg_init();
736
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800737 return 0;
738}
739late_initcall(omap_mux_late_init);
740
741static void __init omap_mux_package_fixup(struct omap_mux *p,
742 struct omap_mux *superset)
743{
744 while (p->reg_offset != OMAP_MUX_TERMINATOR) {
745 struct omap_mux *s = superset;
746 int found = 0;
747
748 while (s->reg_offset != OMAP_MUX_TERMINATOR) {
749 if (s->reg_offset == p->reg_offset) {
750 *s = *p;
751 found++;
752 break;
753 }
754 s++;
755 }
756 if (!found)
Dan Murphy032a6422010-11-15 09:50:50 -0600757 pr_err("%s: Unknown entry offset 0x%x\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200758 p->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800759 p++;
760 }
761}
762
763#ifdef CONFIG_DEBUG_FS
764
765static void __init omap_mux_package_init_balls(struct omap_ball *b,
766 struct omap_mux *superset)
767{
768 while (b->reg_offset != OMAP_MUX_TERMINATOR) {
769 struct omap_mux *s = superset;
770 int found = 0;
771
772 while (s->reg_offset != OMAP_MUX_TERMINATOR) {
773 if (s->reg_offset == b->reg_offset) {
774 s->balls[0] = b->balls[0];
775 s->balls[1] = b->balls[1];
776 found++;
777 break;
778 }
779 s++;
780 }
781 if (!found)
Dan Murphy032a6422010-11-15 09:50:50 -0600782 pr_err("%s: Unknown ball offset 0x%x\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200783 b->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800784 b++;
785 }
786}
787
788#else /* CONFIG_DEBUG_FS */
789
790static inline void omap_mux_package_init_balls(struct omap_ball *b,
791 struct omap_mux *superset)
792{
793}
794
795#endif /* CONFIG_DEBUG_FS */
796
797static int __init omap_mux_setup(char *options)
798{
799 if (!options)
800 return 0;
801
802 omap_mux_options = options;
803
804 return 1;
805}
806__setup("omap_mux=", omap_mux_setup);
807
808/*
809 * Note that the omap_mux=some.signal1=0x1234,some.signal2=0x1234
810 * cmdline options only override the bootloader values.
811 * During development, please enable CONFIG_DEBUG_FS, and use the
812 * signal specific entries under debugfs.
813 */
814static void __init omap_mux_set_cmdline_signals(void)
815{
816 char *options, *next_opt, *token;
817
818 if (!omap_mux_options)
819 return;
820
821 options = kmalloc(strlen(omap_mux_options) + 1, GFP_KERNEL);
822 if (!options)
823 return;
824
825 strcpy(options, omap_mux_options);
826 next_opt = options;
827
828 while ((token = strsep(&next_opt, ",")) != NULL) {
829 char *keyval, *name;
830 unsigned long val;
831
832 keyval = token;
833 name = strsep(&keyval, "=");
834 if (name) {
835 int res;
836
837 res = strict_strtoul(keyval, 0x10, &val);
838 if (res < 0)
839 continue;
840
841 omap_mux_init_signal(name, (u16)val);
842 }
843 }
844
845 kfree(options);
846}
847
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800848static int __init omap_mux_copy_names(struct omap_mux *src,
Benoit Cousson112485e2010-08-16 10:55:35 +0200849 struct omap_mux *dst)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800850{
851 int i;
852
853 for (i = 0; i < OMAP_MUX_NR_MODES; i++) {
854 if (src->muxnames[i]) {
855 dst->muxnames[i] =
856 kmalloc(strlen(src->muxnames[i]) + 1,
857 GFP_KERNEL);
858 if (!dst->muxnames[i])
859 goto free;
860 strcpy(dst->muxnames[i], src->muxnames[i]);
861 }
862 }
863
864#ifdef CONFIG_DEBUG_FS
865 for (i = 0; i < OMAP_MUX_NR_SIDES; i++) {
866 if (src->balls[i]) {
867 dst->balls[i] =
868 kmalloc(strlen(src->balls[i]) + 1,
869 GFP_KERNEL);
870 if (!dst->balls[i])
871 goto free;
872 strcpy(dst->balls[i], src->balls[i]);
873 }
874 }
875#endif
876
877 return 0;
878
879free:
880 omap_mux_free_names(dst);
881 return -ENOMEM;
882
883}
884
885#endif /* CONFIG_OMAP_MUX */
886
Benoit Cousson112485e2010-08-16 10:55:35 +0200887static struct omap_mux *omap_mux_get_by_gpio(
888 struct omap_mux_partition *partition,
889 int gpio)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800890{
891 struct omap_mux_entry *e;
Benoit Cousson112485e2010-08-16 10:55:35 +0200892 struct omap_mux *ret = NULL;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800893
Benoit Cousson112485e2010-08-16 10:55:35 +0200894 list_for_each_entry(e, &partition->muxmodes, node) {
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800895 struct omap_mux *m = &e->mux;
896 if (m->gpio == gpio) {
Benoit Cousson112485e2010-08-16 10:55:35 +0200897 ret = m;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800898 break;
899 }
900 }
901
Benoit Cousson112485e2010-08-16 10:55:35 +0200902 return ret;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800903}
904
905/* Needed for dynamic muxing of GPIO pins for off-idle */
906u16 omap_mux_get_gpio(int gpio)
907{
Benoit Cousson112485e2010-08-16 10:55:35 +0200908 struct omap_mux_partition *partition;
909 struct omap_mux *m;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800910
Benoit Cousson112485e2010-08-16 10:55:35 +0200911 list_for_each_entry(partition, &mux_partitions, node) {
912 m = omap_mux_get_by_gpio(partition, gpio);
913 if (m)
914 return omap_mux_read(partition, m->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800915 }
916
Benoit Cousson112485e2010-08-16 10:55:35 +0200917 if (!m || m->reg_offset == OMAP_MUX_TERMINATOR)
Dan Murphy032a6422010-11-15 09:50:50 -0600918 pr_err("%s: Could not get gpio%i\n", __func__, gpio);
Benoit Cousson112485e2010-08-16 10:55:35 +0200919
920 return OMAP_MUX_TERMINATOR;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800921}
922
923/* Needed for dynamic muxing of GPIO pins for off-idle */
924void omap_mux_set_gpio(u16 val, int gpio)
925{
Benoit Cousson112485e2010-08-16 10:55:35 +0200926 struct omap_mux_partition *partition;
927 struct omap_mux *m = NULL;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800928
Benoit Cousson112485e2010-08-16 10:55:35 +0200929 list_for_each_entry(partition, &mux_partitions, node) {
930 m = omap_mux_get_by_gpio(partition, gpio);
931 if (m) {
932 omap_mux_write(partition, val, m->reg_offset);
933 return;
934 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800935 }
936
Benoit Cousson112485e2010-08-16 10:55:35 +0200937 if (!m || m->reg_offset == OMAP_MUX_TERMINATOR)
Dan Murphy032a6422010-11-15 09:50:50 -0600938 pr_err("%s: Could not set gpio%i\n", __func__, gpio);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800939}
940
Benoit Cousson112485e2010-08-16 10:55:35 +0200941static struct omap_mux * __init omap_mux_list_add(
942 struct omap_mux_partition *partition,
943 struct omap_mux *src)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800944{
945 struct omap_mux_entry *entry;
946 struct omap_mux *m;
947
948 entry = kzalloc(sizeof(struct omap_mux_entry), GFP_KERNEL);
949 if (!entry)
950 return NULL;
951
952 m = &entry->mux;
Aaro Koskinen30833142011-01-06 19:49:28 -0800953 entry->mux = *src;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800954
955#ifdef CONFIG_OMAP_MUX
956 if (omap_mux_copy_names(src, m)) {
957 kfree(entry);
958 return NULL;
959 }
960#endif
961
962 mutex_lock(&muxmode_mutex);
Benoit Cousson112485e2010-08-16 10:55:35 +0200963 list_add_tail(&entry->node, &partition->muxmodes);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800964 mutex_unlock(&muxmode_mutex);
965
966 return m;
967}
968
969/*
970 * Note if CONFIG_OMAP_MUX is not selected, we will only initialize
971 * the GPIO to mux offset mapping that is needed for dynamic muxing
972 * of GPIO pins for off-idle.
973 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200974static void __init omap_mux_init_list(struct omap_mux_partition *partition,
975 struct omap_mux *superset)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800976{
977 while (superset->reg_offset != OMAP_MUX_TERMINATOR) {
978 struct omap_mux *entry;
979
Ranjith Lohithakshanb72c7d52010-02-17 17:17:01 +0000980#ifdef CONFIG_OMAP_MUX
981 if (!superset->muxnames || !superset->muxnames[0]) {
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800982 superset++;
983 continue;
984 }
Ranjith Lohithakshanb72c7d52010-02-17 17:17:01 +0000985#else
986 /* Skip pins that are not muxed as GPIO by bootloader */
Benoit Cousson112485e2010-08-16 10:55:35 +0200987 if (!OMAP_MODE_GPIO(omap_mux_read(partition,
988 superset->reg_offset))) {
Tony Lindgren9ecef432010-02-01 11:22:54 -0800989 superset++;
990 continue;
991 }
992#endif
993
Benoit Cousson112485e2010-08-16 10:55:35 +0200994 entry = omap_mux_list_add(partition, superset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800995 if (!entry) {
Dan Murphy032a6422010-11-15 09:50:50 -0600996 pr_err("%s: Could not add entry\n", __func__);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800997 return;
998 }
999 superset++;
1000 }
1001}
1002
Tony Lindgren321cfc82010-02-15 10:03:35 -08001003#ifdef CONFIG_OMAP_MUX
1004
1005static void omap_mux_init_package(struct omap_mux *superset,
1006 struct omap_mux *package_subset,
1007 struct omap_ball *package_balls)
1008{
1009 if (package_subset)
1010 omap_mux_package_fixup(package_subset, superset);
1011 if (package_balls)
1012 omap_mux_package_init_balls(package_balls, superset);
1013}
1014
Benoit Cousson112485e2010-08-16 10:55:35 +02001015static void omap_mux_init_signals(struct omap_mux_partition *partition,
1016 struct omap_board_mux *board_mux)
Tony Lindgren321cfc82010-02-15 10:03:35 -08001017{
1018 omap_mux_set_cmdline_signals();
Benoit Cousson112485e2010-08-16 10:55:35 +02001019 omap_mux_write_array(partition, board_mux);
Tony Lindgren321cfc82010-02-15 10:03:35 -08001020}
1021
1022#else
1023
1024static void omap_mux_init_package(struct omap_mux *superset,
1025 struct omap_mux *package_subset,
1026 struct omap_ball *package_balls)
1027{
1028}
1029
Benoit Cousson112485e2010-08-16 10:55:35 +02001030static void omap_mux_init_signals(struct omap_mux_partition *partition,
1031 struct omap_board_mux *board_mux)
Tony Lindgren321cfc82010-02-15 10:03:35 -08001032{
1033}
1034
1035#endif
1036
Benoit Cousson112485e2010-08-16 10:55:35 +02001037static u32 mux_partitions_cnt;
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001038
Benoit Cousson112485e2010-08-16 10:55:35 +02001039int __init omap_mux_init(const char *name, u32 flags,
1040 u32 mux_pbase, u32 mux_size,
1041 struct omap_mux *superset,
1042 struct omap_mux *package_subset,
1043 struct omap_board_mux *board_mux,
1044 struct omap_ball *package_balls)
1045{
1046 struct omap_mux_partition *partition;
1047
1048 partition = kzalloc(sizeof(struct omap_mux_partition), GFP_KERNEL);
1049 if (!partition)
1050 return -ENOMEM;
1051
1052 partition->name = name;
1053 partition->flags = flags;
1054 partition->size = mux_size;
1055 partition->phys = mux_pbase;
1056 partition->base = ioremap(mux_pbase, mux_size);
1057 if (!partition->base) {
Dan Murphy032a6422010-11-15 09:50:50 -06001058 pr_err("%s: Could not ioremap mux partition at 0x%08x\n",
1059 __func__, partition->phys);
Aaro Koskinen9d47e302011-01-28 14:50:55 +00001060 kfree(partition);
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001061 return -ENODEV;
1062 }
1063
Benoit Cousson112485e2010-08-16 10:55:35 +02001064 INIT_LIST_HEAD(&partition->muxmodes);
1065
1066 list_add_tail(&partition->node, &mux_partitions);
1067 mux_partitions_cnt++;
Dan Murphy032a6422010-11-15 09:50:50 -06001068 pr_info("%s: Add partition: #%d: %s, flags: %x\n", __func__,
Benoit Cousson112485e2010-08-16 10:55:35 +02001069 mux_partitions_cnt, partition->name, partition->flags);
Tony Lindgrend5425be2010-07-05 16:31:35 +03001070
Tony Lindgren321cfc82010-02-15 10:03:35 -08001071 omap_mux_init_package(superset, package_subset, package_balls);
Benoit Cousson112485e2010-08-16 10:55:35 +02001072 omap_mux_init_list(partition, superset);
1073 omap_mux_init_signals(partition, board_mux);
Tony Lindgren2cb0c542010-01-19 18:17:07 -08001074
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001075 return 0;
1076}
1077