Loading...
1/*
2 * linux/arch/arm/mach-omap2/mux.c
3 *
4 * OMAP2, OMAP3 and OMAP4 pin multiplexing configurations
5 *
6 * Copyright (C) 2004 - 2010 Texas Instruments Inc.
7 * Copyright (C) 2003 - 2008 Nokia Corporation
8 *
9 * Written by Tony Lindgren
10 *
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 */
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/io.h>
29#include <linux/list.h>
30#include <linux/slab.h>
31#include <linux/ctype.h>
32#include <linux/debugfs.h>
33#include <linux/seq_file.h>
34#include <linux/uaccess.h>
35#include <linux/irq.h>
36#include <linux/interrupt.h>
37
38
39#include <plat/omap_hwmod.h>
40
41#include "control.h"
42#include "mux.h"
43#include "prm.h"
44#include "common.h"
45
46#define OMAP_MUX_BASE_OFFSET 0x30 /* Offset from CTRL_BASE */
47#define OMAP_MUX_BASE_SZ 0x5ca
48
49struct omap_mux_entry {
50 struct omap_mux mux;
51 struct list_head node;
52};
53
54static LIST_HEAD(mux_partitions);
55static DEFINE_MUTEX(muxmode_mutex);
56
57struct omap_mux_partition *omap_mux_get(const char *name)
58{
59 struct omap_mux_partition *partition;
60
61 list_for_each_entry(partition, &mux_partitions, node) {
62 if (!strcmp(name, partition->name))
63 return partition;
64 }
65
66 return NULL;
67}
68
69u16 omap_mux_read(struct omap_mux_partition *partition, u16 reg)
70{
71 if (partition->flags & OMAP_MUX_REG_8BIT)
72 return __raw_readb(partition->base + reg);
73 else
74 return __raw_readw(partition->base + reg);
75}
76
77void omap_mux_write(struct omap_mux_partition *partition, u16 val,
78 u16 reg)
79{
80 if (partition->flags & OMAP_MUX_REG_8BIT)
81 __raw_writeb(val, partition->base + reg);
82 else
83 __raw_writew(val, partition->base + reg);
84}
85
86void omap_mux_write_array(struct omap_mux_partition *partition,
87 struct omap_board_mux *board_mux)
88{
89 if (!board_mux)
90 return;
91
92 while (board_mux->reg_offset != OMAP_MUX_TERMINATOR) {
93 omap_mux_write(partition, board_mux->value,
94 board_mux->reg_offset);
95 board_mux++;
96 }
97}
98
99#ifdef CONFIG_OMAP_MUX
100
101static char *omap_mux_options;
102
103static int __init _omap_mux_init_gpio(struct omap_mux_partition *partition,
104 int gpio, int val)
105{
106 struct omap_mux_entry *e;
107 struct omap_mux *gpio_mux = NULL;
108 u16 old_mode;
109 u16 mux_mode;
110 int found = 0;
111 struct list_head *muxmodes = &partition->muxmodes;
112
113 if (!gpio)
114 return -EINVAL;
115
116 list_for_each_entry(e, muxmodes, node) {
117 struct omap_mux *m = &e->mux;
118 if (gpio == m->gpio) {
119 gpio_mux = m;
120 found++;
121 }
122 }
123
124 if (found == 0) {
125 pr_err("%s: Could not set gpio%i\n", __func__, gpio);
126 return -ENODEV;
127 }
128
129 if (found > 1) {
130 pr_info("%s: Multiple gpio paths (%d) for gpio%i\n", __func__,
131 found, gpio);
132 return -EINVAL;
133 }
134
135 old_mode = omap_mux_read(partition, gpio_mux->reg_offset);
136 mux_mode = val & ~(OMAP_MUX_NR_MODES - 1);
137 if (partition->flags & OMAP_MUX_GPIO_IN_MODE3)
138 mux_mode |= OMAP_MUX_MODE3;
139 else
140 mux_mode |= OMAP_MUX_MODE4;
141 pr_debug("%s: Setting signal %s.gpio%i 0x%04x -> 0x%04x\n", __func__,
142 gpio_mux->muxnames[0], gpio, old_mode, mux_mode);
143 omap_mux_write(partition, mux_mode, gpio_mux->reg_offset);
144
145 return 0;
146}
147
148int __init omap_mux_init_gpio(int gpio, int val)
149{
150 struct omap_mux_partition *partition;
151 int ret;
152
153 list_for_each_entry(partition, &mux_partitions, node) {
154 ret = _omap_mux_init_gpio(partition, gpio, val);
155 if (!ret)
156 return ret;
157 }
158
159 return -ENODEV;
160}
161
162static int __init _omap_mux_get_by_name(struct omap_mux_partition *partition,
163 const char *muxname,
164 struct omap_mux **found_mux)
165{
166 struct omap_mux *mux = NULL;
167 struct omap_mux_entry *e;
168 const char *mode_name;
169 int found = 0, found_mode = 0, mode0_len = 0;
170 struct list_head *muxmodes = &partition->muxmodes;
171
172 mode_name = strchr(muxname, '.');
173 if (mode_name) {
174 mode0_len = strlen(muxname) - strlen(mode_name);
175 mode_name++;
176 } else {
177 mode_name = muxname;
178 }
179
180 list_for_each_entry(e, muxmodes, node) {
181 char *m0_entry;
182 int i;
183
184 mux = &e->mux;
185 m0_entry = mux->muxnames[0];
186
187 /* First check for full name in mode0.muxmode format */
188 if (mode0_len && strncmp(muxname, m0_entry, mode0_len))
189 continue;
190
191 /* Then check for muxmode only */
192 for (i = 0; i < OMAP_MUX_NR_MODES; i++) {
193 char *mode_cur = mux->muxnames[i];
194
195 if (!mode_cur)
196 continue;
197
198 if (!strcmp(mode_name, mode_cur)) {
199 *found_mux = mux;
200 found++;
201 found_mode = i;
202 }
203 }
204 }
205
206 if (found == 1) {
207 return found_mode;
208 }
209
210 if (found > 1) {
211 pr_err("%s: Multiple signal paths (%i) for %s\n", __func__,
212 found, muxname);
213 return -EINVAL;
214 }
215
216 pr_err("%s: Could not find signal %s\n", __func__, muxname);
217
218 return -ENODEV;
219}
220
221int __init omap_mux_get_by_name(const char *muxname,
222 struct omap_mux_partition **found_partition,
223 struct omap_mux **found_mux)
224{
225 struct omap_mux_partition *partition;
226
227 list_for_each_entry(partition, &mux_partitions, node) {
228 struct omap_mux *mux = NULL;
229 int mux_mode = _omap_mux_get_by_name(partition, muxname, &mux);
230 if (mux_mode < 0)
231 continue;
232
233 *found_partition = partition;
234 *found_mux = mux;
235
236 return mux_mode;
237 }
238
239 return -ENODEV;
240}
241
242int __init omap_mux_init_signal(const char *muxname, int val)
243{
244 struct omap_mux_partition *partition = NULL;
245 struct omap_mux *mux = NULL;
246 u16 old_mode;
247 int mux_mode;
248
249 mux_mode = omap_mux_get_by_name(muxname, &partition, &mux);
250 if (mux_mode < 0 || !mux)
251 return mux_mode;
252
253 old_mode = omap_mux_read(partition, mux->reg_offset);
254 mux_mode |= val;
255 pr_debug("%s: Setting signal %s 0x%04x -> 0x%04x\n",
256 __func__, muxname, old_mode, mux_mode);
257 omap_mux_write(partition, mux_mode, mux->reg_offset);
258
259 return 0;
260}
261
262struct omap_hwmod_mux_info * __init
263omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads)
264{
265 struct omap_hwmod_mux_info *hmux;
266 int i, nr_pads_dynamic = 0;
267
268 if (!bpads || nr_pads < 1)
269 return NULL;
270
271 hmux = kzalloc(sizeof(struct omap_hwmod_mux_info), GFP_KERNEL);
272 if (!hmux)
273 goto err1;
274
275 hmux->nr_pads = nr_pads;
276
277 hmux->pads = kzalloc(sizeof(struct omap_device_pad) *
278 nr_pads, GFP_KERNEL);
279 if (!hmux->pads)
280 goto err2;
281
282 for (i = 0; i < hmux->nr_pads; i++) {
283 struct omap_mux_partition *partition;
284 struct omap_device_pad *bpad = &bpads[i], *pad = &hmux->pads[i];
285 struct omap_mux *mux;
286 int mux_mode;
287
288 mux_mode = omap_mux_get_by_name(bpad->name, &partition, &mux);
289 if (mux_mode < 0)
290 goto err3;
291 if (!pad->partition)
292 pad->partition = partition;
293 if (!pad->mux)
294 pad->mux = mux;
295
296 pad->name = kzalloc(strlen(bpad->name) + 1, GFP_KERNEL);
297 if (!pad->name) {
298 int j;
299
300 for (j = i - 1; j >= 0; j--)
301 kfree(hmux->pads[j].name);
302 goto err3;
303 }
304 strcpy(pad->name, bpad->name);
305
306 pad->flags = bpad->flags;
307 pad->enable = bpad->enable;
308 pad->idle = bpad->idle;
309 pad->off = bpad->off;
310
311 if (pad->flags &
312 (OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP))
313 nr_pads_dynamic++;
314
315 pr_debug("%s: Initialized %s\n", __func__, pad->name);
316 }
317
318 if (!nr_pads_dynamic)
319 return hmux;
320
321 /*
322 * Add pads that need dynamic muxing into a separate list
323 */
324
325 hmux->nr_pads_dynamic = nr_pads_dynamic;
326 hmux->pads_dynamic = kzalloc(sizeof(struct omap_device_pad *) *
327 nr_pads_dynamic, GFP_KERNEL);
328 if (!hmux->pads_dynamic) {
329 pr_err("%s: Could not allocate dynamic pads\n", __func__);
330 return hmux;
331 }
332
333 nr_pads_dynamic = 0;
334 for (i = 0; i < hmux->nr_pads; i++) {
335 struct omap_device_pad *pad = &hmux->pads[i];
336
337 if (pad->flags &
338 (OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP)) {
339 pr_debug("%s: pad %s tagged dynamic\n",
340 __func__, pad->name);
341 hmux->pads_dynamic[nr_pads_dynamic] = pad;
342 nr_pads_dynamic++;
343 }
344 }
345
346 return hmux;
347
348err3:
349 kfree(hmux->pads);
350err2:
351 kfree(hmux);
352err1:
353 pr_err("%s: Could not allocate device mux entry\n", __func__);
354
355 return NULL;
356}
357
358/**
359 * omap_hwmod_mux_scan_wakeups - omap hwmod scan wakeup pads
360 * @hmux: Pads for a hwmod
361 * @mpu_irqs: MPU irq array for a hwmod
362 *
363 * Scans the wakeup status of pads for a single hwmod. If an irq
364 * array is defined for this mux, the parser will call the registered
365 * ISRs for corresponding pads, otherwise the parser will stop at the
366 * first wakeup active pad and return. Returns true if there is a
367 * pending and non-served wakeup event for the mux, otherwise false.
368 */
369static bool omap_hwmod_mux_scan_wakeups(struct omap_hwmod_mux_info *hmux,
370 struct omap_hwmod_irq_info *mpu_irqs)
371{
372 int i, irq;
373 unsigned int val;
374 u32 handled_irqs = 0;
375
376 for (i = 0; i < hmux->nr_pads_dynamic; i++) {
377 struct omap_device_pad *pad = hmux->pads_dynamic[i];
378
379 if (!(pad->flags & OMAP_DEVICE_PAD_WAKEUP) ||
380 !(pad->idle & OMAP_WAKEUP_EN))
381 continue;
382
383 val = omap_mux_read(pad->partition, pad->mux->reg_offset);
384 if (!(val & OMAP_WAKEUP_EVENT))
385 continue;
386
387 if (!hmux->irqs)
388 return true;
389
390 irq = hmux->irqs[i];
391 /* make sure we only handle each irq once */
392 if (handled_irqs & 1 << irq)
393 continue;
394
395 handled_irqs |= 1 << irq;
396
397 generic_handle_irq(mpu_irqs[irq].irq);
398 }
399
400 return false;
401}
402
403/**
404 * _omap_hwmod_mux_handle_irq - Process wakeup events for a single hwmod
405 *
406 * Checks a single hwmod for every wakeup capable pad to see if there is an
407 * active wakeup event. If this is the case, call the corresponding ISR.
408 */
409static int _omap_hwmod_mux_handle_irq(struct omap_hwmod *oh, void *data)
410{
411 if (!oh->mux || !oh->mux->enabled)
412 return 0;
413 if (omap_hwmod_mux_scan_wakeups(oh->mux, oh->mpu_irqs))
414 generic_handle_irq(oh->mpu_irqs[0].irq);
415 return 0;
416}
417
418/**
419 * omap_hwmod_mux_handle_irq - Process pad wakeup irqs.
420 *
421 * Calls a function for each registered omap_hwmod to check
422 * pad wakeup statuses.
423 */
424static irqreturn_t omap_hwmod_mux_handle_irq(int irq, void *unused)
425{
426 omap_hwmod_for_each(_omap_hwmod_mux_handle_irq, NULL);
427 return IRQ_HANDLED;
428}
429
430/* Assumes the calling function takes care of locking */
431void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state)
432{
433 int i;
434
435 /* Runtime idling of dynamic pads */
436 if (state == _HWMOD_STATE_IDLE && hmux->enabled) {
437 for (i = 0; i < hmux->nr_pads_dynamic; i++) {
438 struct omap_device_pad *pad = hmux->pads_dynamic[i];
439 int val = -EINVAL;
440
441 val = pad->idle;
442 omap_mux_write(pad->partition, val,
443 pad->mux->reg_offset);
444 }
445
446 return;
447 }
448
449 /* Runtime enabling of dynamic pads */
450 if ((state == _HWMOD_STATE_ENABLED) && hmux->pads_dynamic
451 && hmux->enabled) {
452 for (i = 0; i < hmux->nr_pads_dynamic; i++) {
453 struct omap_device_pad *pad = hmux->pads_dynamic[i];
454 int val = -EINVAL;
455
456 val = pad->enable;
457 omap_mux_write(pad->partition, val,
458 pad->mux->reg_offset);
459 }
460
461 return;
462 }
463
464 /* Enabling or disabling of all pads */
465 for (i = 0; i < hmux->nr_pads; i++) {
466 struct omap_device_pad *pad = &hmux->pads[i];
467 int flags, val = -EINVAL;
468
469 flags = pad->flags;
470
471 switch (state) {
472 case _HWMOD_STATE_ENABLED:
473 val = pad->enable;
474 pr_debug("%s: Enabling %s %x\n", __func__,
475 pad->name, val);
476 break;
477 case _HWMOD_STATE_DISABLED:
478 /* Use safe mode unless OMAP_DEVICE_PAD_REMUX */
479 if (flags & OMAP_DEVICE_PAD_REMUX)
480 val = pad->off;
481 else
482 val = OMAP_MUX_MODE7;
483 pr_debug("%s: Disabling %s %x\n", __func__,
484 pad->name, val);
485 break;
486 default:
487 /* Nothing to be done */
488 break;
489 };
490
491 if (val >= 0) {
492 omap_mux_write(pad->partition, val,
493 pad->mux->reg_offset);
494 pad->flags = flags;
495 }
496 }
497
498 if (state == _HWMOD_STATE_ENABLED)
499 hmux->enabled = true;
500 else
501 hmux->enabled = false;
502}
503
504#ifdef CONFIG_DEBUG_FS
505
506#define OMAP_MUX_MAX_NR_FLAGS 10
507#define OMAP_MUX_TEST_FLAG(val, mask) \
508 if (((val) & (mask)) == (mask)) { \
509 i++; \
510 flags[i] = #mask; \
511 }
512
513/* REVISIT: Add checking for non-optimal mux settings */
514static inline void omap_mux_decode(struct seq_file *s, u16 val)
515{
516 char *flags[OMAP_MUX_MAX_NR_FLAGS];
517 char mode[sizeof("OMAP_MUX_MODE") + 1];
518 int i = -1;
519
520 sprintf(mode, "OMAP_MUX_MODE%d", val & 0x7);
521 i++;
522 flags[i] = mode;
523
524 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_OFF_WAKEUPENABLE);
525 if (val & OMAP_OFF_EN) {
526 if (!(val & OMAP_OFFOUT_EN)) {
527 if (!(val & OMAP_OFF_PULL_UP)) {
528 OMAP_MUX_TEST_FLAG(val,
529 OMAP_PIN_OFF_INPUT_PULLDOWN);
530 } else {
531 OMAP_MUX_TEST_FLAG(val,
532 OMAP_PIN_OFF_INPUT_PULLUP);
533 }
534 } else {
535 if (!(val & OMAP_OFFOUT_VAL)) {
536 OMAP_MUX_TEST_FLAG(val,
537 OMAP_PIN_OFF_OUTPUT_LOW);
538 } else {
539 OMAP_MUX_TEST_FLAG(val,
540 OMAP_PIN_OFF_OUTPUT_HIGH);
541 }
542 }
543 }
544
545 if (val & OMAP_INPUT_EN) {
546 if (val & OMAP_PULL_ENA) {
547 if (!(val & OMAP_PULL_UP)) {
548 OMAP_MUX_TEST_FLAG(val,
549 OMAP_PIN_INPUT_PULLDOWN);
550 } else {
551 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT_PULLUP);
552 }
553 } else {
554 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT);
555 }
556 } else {
557 i++;
558 flags[i] = "OMAP_PIN_OUTPUT";
559 }
560
561 do {
562 seq_printf(s, "%s", flags[i]);
563 if (i > 0)
564 seq_printf(s, " | ");
565 } while (i-- > 0);
566}
567
568#define OMAP_MUX_DEFNAME_LEN 32
569
570static int omap_mux_dbg_board_show(struct seq_file *s, void *unused)
571{
572 struct omap_mux_partition *partition = s->private;
573 struct omap_mux_entry *e;
574 u8 omap_gen = omap_rev() >> 28;
575
576 list_for_each_entry(e, &partition->muxmodes, node) {
577 struct omap_mux *m = &e->mux;
578 char m0_def[OMAP_MUX_DEFNAME_LEN];
579 char *m0_name = m->muxnames[0];
580 u16 val;
581 int i, mode;
582
583 if (!m0_name)
584 continue;
585
586 /* REVISIT: Needs to be updated if mode0 names get longer */
587 for (i = 0; i < OMAP_MUX_DEFNAME_LEN; i++) {
588 if (m0_name[i] == '\0') {
589 m0_def[i] = m0_name[i];
590 break;
591 }
592 m0_def[i] = toupper(m0_name[i]);
593 }
594 val = omap_mux_read(partition, m->reg_offset);
595 mode = val & OMAP_MUX_MODE7;
596 if (mode != 0)
597 seq_printf(s, "/* %s */\n", m->muxnames[mode]);
598
599 /*
600 * XXX: Might be revisited to support differences across
601 * same OMAP generation.
602 */
603 seq_printf(s, "OMAP%d_MUX(%s, ", omap_gen, m0_def);
604 omap_mux_decode(s, val);
605 seq_printf(s, "),\n");
606 }
607
608 return 0;
609}
610
611static int omap_mux_dbg_board_open(struct inode *inode, struct file *file)
612{
613 return single_open(file, omap_mux_dbg_board_show, inode->i_private);
614}
615
616static const struct file_operations omap_mux_dbg_board_fops = {
617 .open = omap_mux_dbg_board_open,
618 .read = seq_read,
619 .llseek = seq_lseek,
620 .release = single_release,
621};
622
623static struct omap_mux_partition *omap_mux_get_partition(struct omap_mux *mux)
624{
625 struct omap_mux_partition *partition;
626
627 list_for_each_entry(partition, &mux_partitions, node) {
628 struct list_head *muxmodes = &partition->muxmodes;
629 struct omap_mux_entry *e;
630
631 list_for_each_entry(e, muxmodes, node) {
632 struct omap_mux *m = &e->mux;
633
634 if (m == mux)
635 return partition;
636 }
637 }
638
639 return NULL;
640}
641
642static int omap_mux_dbg_signal_show(struct seq_file *s, void *unused)
643{
644 struct omap_mux *m = s->private;
645 struct omap_mux_partition *partition;
646 const char *none = "NA";
647 u16 val;
648 int mode;
649
650 partition = omap_mux_get_partition(m);
651 if (!partition)
652 return 0;
653
654 val = omap_mux_read(partition, m->reg_offset);
655 mode = val & OMAP_MUX_MODE7;
656
657 seq_printf(s, "name: %s.%s (0x%08x/0x%03x = 0x%04x), b %s, t %s\n",
658 m->muxnames[0], m->muxnames[mode],
659 partition->phys + m->reg_offset, m->reg_offset, val,
660 m->balls[0] ? m->balls[0] : none,
661 m->balls[1] ? m->balls[1] : none);
662 seq_printf(s, "mode: ");
663 omap_mux_decode(s, val);
664 seq_printf(s, "\n");
665 seq_printf(s, "signals: %s | %s | %s | %s | %s | %s | %s | %s\n",
666 m->muxnames[0] ? m->muxnames[0] : none,
667 m->muxnames[1] ? m->muxnames[1] : none,
668 m->muxnames[2] ? m->muxnames[2] : none,
669 m->muxnames[3] ? m->muxnames[3] : none,
670 m->muxnames[4] ? m->muxnames[4] : none,
671 m->muxnames[5] ? m->muxnames[5] : none,
672 m->muxnames[6] ? m->muxnames[6] : none,
673 m->muxnames[7] ? m->muxnames[7] : none);
674
675 return 0;
676}
677
678#define OMAP_MUX_MAX_ARG_CHAR 7
679
680static ssize_t omap_mux_dbg_signal_write(struct file *file,
681 const char __user *user_buf,
682 size_t count, loff_t *ppos)
683{
684 char buf[OMAP_MUX_MAX_ARG_CHAR];
685 struct seq_file *seqf;
686 struct omap_mux *m;
687 unsigned long val;
688 int buf_size, ret;
689 struct omap_mux_partition *partition;
690
691 if (count > OMAP_MUX_MAX_ARG_CHAR)
692 return -EINVAL;
693
694 memset(buf, 0, sizeof(buf));
695 buf_size = min(count, sizeof(buf) - 1);
696
697 if (copy_from_user(buf, user_buf, buf_size))
698 return -EFAULT;
699
700 ret = strict_strtoul(buf, 0x10, &val);
701 if (ret < 0)
702 return ret;
703
704 if (val > 0xffff)
705 return -EINVAL;
706
707 seqf = file->private_data;
708 m = seqf->private;
709
710 partition = omap_mux_get_partition(m);
711 if (!partition)
712 return -ENODEV;
713
714 omap_mux_write(partition, (u16)val, m->reg_offset);
715 *ppos += count;
716
717 return count;
718}
719
720static int omap_mux_dbg_signal_open(struct inode *inode, struct file *file)
721{
722 return single_open(file, omap_mux_dbg_signal_show, inode->i_private);
723}
724
725static const struct file_operations omap_mux_dbg_signal_fops = {
726 .open = omap_mux_dbg_signal_open,
727 .read = seq_read,
728 .write = omap_mux_dbg_signal_write,
729 .llseek = seq_lseek,
730 .release = single_release,
731};
732
733static struct dentry *mux_dbg_dir;
734
735static void __init omap_mux_dbg_create_entry(
736 struct omap_mux_partition *partition,
737 struct dentry *mux_dbg_dir)
738{
739 struct omap_mux_entry *e;
740
741 list_for_each_entry(e, &partition->muxmodes, node) {
742 struct omap_mux *m = &e->mux;
743
744 (void)debugfs_create_file(m->muxnames[0], S_IWUSR, mux_dbg_dir,
745 m, &omap_mux_dbg_signal_fops);
746 }
747}
748
749static void __init omap_mux_dbg_init(void)
750{
751 struct omap_mux_partition *partition;
752 static struct dentry *mux_dbg_board_dir;
753
754 mux_dbg_dir = debugfs_create_dir("omap_mux", NULL);
755 if (!mux_dbg_dir)
756 return;
757
758 mux_dbg_board_dir = debugfs_create_dir("board", mux_dbg_dir);
759 if (!mux_dbg_board_dir)
760 return;
761
762 list_for_each_entry(partition, &mux_partitions, node) {
763 omap_mux_dbg_create_entry(partition, mux_dbg_dir);
764 (void)debugfs_create_file(partition->name, S_IRUGO,
765 mux_dbg_board_dir, partition,
766 &omap_mux_dbg_board_fops);
767 }
768}
769
770#else
771static inline void omap_mux_dbg_init(void)
772{
773}
774#endif /* CONFIG_DEBUG_FS */
775
776static void __init omap_mux_free_names(struct omap_mux *m)
777{
778 int i;
779
780 for (i = 0; i < OMAP_MUX_NR_MODES; i++)
781 kfree(m->muxnames[i]);
782
783#ifdef CONFIG_DEBUG_FS
784 for (i = 0; i < OMAP_MUX_NR_SIDES; i++)
785 kfree(m->balls[i]);
786#endif
787
788}
789
790/* Free all data except for GPIO pins unless CONFIG_DEBUG_FS is set */
791int __init omap_mux_late_init(void)
792{
793 struct omap_mux_partition *partition;
794 int ret;
795
796 list_for_each_entry(partition, &mux_partitions, node) {
797 struct omap_mux_entry *e, *tmp;
798 list_for_each_entry_safe(e, tmp, &partition->muxmodes, node) {
799 struct omap_mux *m = &e->mux;
800 u16 mode = omap_mux_read(partition, m->reg_offset);
801
802 if (OMAP_MODE_GPIO(mode))
803 continue;
804
805#ifndef CONFIG_DEBUG_FS
806 mutex_lock(&muxmode_mutex);
807 list_del(&e->node);
808 mutex_unlock(&muxmode_mutex);
809 omap_mux_free_names(m);
810 kfree(m);
811#endif
812 }
813 }
814
815 ret = request_irq(omap_prcm_event_to_irq("io"),
816 omap_hwmod_mux_handle_irq, IRQF_SHARED | IRQF_NO_SUSPEND,
817 "hwmod_io", omap_mux_late_init);
818
819 if (ret)
820 pr_warning("mux: Failed to setup hwmod io irq %d\n", ret);
821
822 omap_mux_dbg_init();
823
824 return 0;
825}
826
827static void __init omap_mux_package_fixup(struct omap_mux *p,
828 struct omap_mux *superset)
829{
830 while (p->reg_offset != OMAP_MUX_TERMINATOR) {
831 struct omap_mux *s = superset;
832 int found = 0;
833
834 while (s->reg_offset != OMAP_MUX_TERMINATOR) {
835 if (s->reg_offset == p->reg_offset) {
836 *s = *p;
837 found++;
838 break;
839 }
840 s++;
841 }
842 if (!found)
843 pr_err("%s: Unknown entry offset 0x%x\n", __func__,
844 p->reg_offset);
845 p++;
846 }
847}
848
849#ifdef CONFIG_DEBUG_FS
850
851static void __init omap_mux_package_init_balls(struct omap_ball *b,
852 struct omap_mux *superset)
853{
854 while (b->reg_offset != OMAP_MUX_TERMINATOR) {
855 struct omap_mux *s = superset;
856 int found = 0;
857
858 while (s->reg_offset != OMAP_MUX_TERMINATOR) {
859 if (s->reg_offset == b->reg_offset) {
860 s->balls[0] = b->balls[0];
861 s->balls[1] = b->balls[1];
862 found++;
863 break;
864 }
865 s++;
866 }
867 if (!found)
868 pr_err("%s: Unknown ball offset 0x%x\n", __func__,
869 b->reg_offset);
870 b++;
871 }
872}
873
874#else /* CONFIG_DEBUG_FS */
875
876static inline void omap_mux_package_init_balls(struct omap_ball *b,
877 struct omap_mux *superset)
878{
879}
880
881#endif /* CONFIG_DEBUG_FS */
882
883static int __init omap_mux_setup(char *options)
884{
885 if (!options)
886 return 0;
887
888 omap_mux_options = options;
889
890 return 1;
891}
892__setup("omap_mux=", omap_mux_setup);
893
894/*
895 * Note that the omap_mux=some.signal1=0x1234,some.signal2=0x1234
896 * cmdline options only override the bootloader values.
897 * During development, please enable CONFIG_DEBUG_FS, and use the
898 * signal specific entries under debugfs.
899 */
900static void __init omap_mux_set_cmdline_signals(void)
901{
902 char *options, *next_opt, *token;
903
904 if (!omap_mux_options)
905 return;
906
907 options = kstrdup(omap_mux_options, GFP_KERNEL);
908 if (!options)
909 return;
910
911 next_opt = options;
912
913 while ((token = strsep(&next_opt, ",")) != NULL) {
914 char *keyval, *name;
915 unsigned long val;
916
917 keyval = token;
918 name = strsep(&keyval, "=");
919 if (name) {
920 int res;
921
922 res = strict_strtoul(keyval, 0x10, &val);
923 if (res < 0)
924 continue;
925
926 omap_mux_init_signal(name, (u16)val);
927 }
928 }
929
930 kfree(options);
931}
932
933static int __init omap_mux_copy_names(struct omap_mux *src,
934 struct omap_mux *dst)
935{
936 int i;
937
938 for (i = 0; i < OMAP_MUX_NR_MODES; i++) {
939 if (src->muxnames[i]) {
940 dst->muxnames[i] = kstrdup(src->muxnames[i],
941 GFP_KERNEL);
942 if (!dst->muxnames[i])
943 goto free;
944 }
945 }
946
947#ifdef CONFIG_DEBUG_FS
948 for (i = 0; i < OMAP_MUX_NR_SIDES; i++) {
949 if (src->balls[i]) {
950 dst->balls[i] = kstrdup(src->balls[i], GFP_KERNEL);
951 if (!dst->balls[i])
952 goto free;
953 }
954 }
955#endif
956
957 return 0;
958
959free:
960 omap_mux_free_names(dst);
961 return -ENOMEM;
962
963}
964
965#endif /* CONFIG_OMAP_MUX */
966
967static struct omap_mux *omap_mux_get_by_gpio(
968 struct omap_mux_partition *partition,
969 int gpio)
970{
971 struct omap_mux_entry *e;
972 struct omap_mux *ret = NULL;
973
974 list_for_each_entry(e, &partition->muxmodes, node) {
975 struct omap_mux *m = &e->mux;
976 if (m->gpio == gpio) {
977 ret = m;
978 break;
979 }
980 }
981
982 return ret;
983}
984
985/* Needed for dynamic muxing of GPIO pins for off-idle */
986u16 omap_mux_get_gpio(int gpio)
987{
988 struct omap_mux_partition *partition;
989 struct omap_mux *m = NULL;
990
991 list_for_each_entry(partition, &mux_partitions, node) {
992 m = omap_mux_get_by_gpio(partition, gpio);
993 if (m)
994 return omap_mux_read(partition, m->reg_offset);
995 }
996
997 if (!m || m->reg_offset == OMAP_MUX_TERMINATOR)
998 pr_err("%s: Could not get gpio%i\n", __func__, gpio);
999
1000 return OMAP_MUX_TERMINATOR;
1001}
1002
1003/* Needed for dynamic muxing of GPIO pins for off-idle */
1004void omap_mux_set_gpio(u16 val, int gpio)
1005{
1006 struct omap_mux_partition *partition;
1007 struct omap_mux *m = NULL;
1008
1009 list_for_each_entry(partition, &mux_partitions, node) {
1010 m = omap_mux_get_by_gpio(partition, gpio);
1011 if (m) {
1012 omap_mux_write(partition, val, m->reg_offset);
1013 return;
1014 }
1015 }
1016
1017 if (!m || m->reg_offset == OMAP_MUX_TERMINATOR)
1018 pr_err("%s: Could not set gpio%i\n", __func__, gpio);
1019}
1020
1021static struct omap_mux * __init omap_mux_list_add(
1022 struct omap_mux_partition *partition,
1023 struct omap_mux *src)
1024{
1025 struct omap_mux_entry *entry;
1026 struct omap_mux *m;
1027
1028 entry = kzalloc(sizeof(struct omap_mux_entry), GFP_KERNEL);
1029 if (!entry)
1030 return NULL;
1031
1032 m = &entry->mux;
1033 entry->mux = *src;
1034
1035#ifdef CONFIG_OMAP_MUX
1036 if (omap_mux_copy_names(src, m)) {
1037 kfree(entry);
1038 return NULL;
1039 }
1040#endif
1041
1042 mutex_lock(&muxmode_mutex);
1043 list_add_tail(&entry->node, &partition->muxmodes);
1044 mutex_unlock(&muxmode_mutex);
1045
1046 return m;
1047}
1048
1049/*
1050 * Note if CONFIG_OMAP_MUX is not selected, we will only initialize
1051 * the GPIO to mux offset mapping that is needed for dynamic muxing
1052 * of GPIO pins for off-idle.
1053 */
1054static void __init omap_mux_init_list(struct omap_mux_partition *partition,
1055 struct omap_mux *superset)
1056{
1057 while (superset->reg_offset != OMAP_MUX_TERMINATOR) {
1058 struct omap_mux *entry;
1059
1060#ifdef CONFIG_OMAP_MUX
1061 if (!superset->muxnames || !superset->muxnames[0]) {
1062 superset++;
1063 continue;
1064 }
1065#else
1066 /* Skip pins that are not muxed as GPIO by bootloader */
1067 if (!OMAP_MODE_GPIO(omap_mux_read(partition,
1068 superset->reg_offset))) {
1069 superset++;
1070 continue;
1071 }
1072#endif
1073
1074 entry = omap_mux_list_add(partition, superset);
1075 if (!entry) {
1076 pr_err("%s: Could not add entry\n", __func__);
1077 return;
1078 }
1079 superset++;
1080 }
1081}
1082
1083#ifdef CONFIG_OMAP_MUX
1084
1085static void omap_mux_init_package(struct omap_mux *superset,
1086 struct omap_mux *package_subset,
1087 struct omap_ball *package_balls)
1088{
1089 if (package_subset)
1090 omap_mux_package_fixup(package_subset, superset);
1091 if (package_balls)
1092 omap_mux_package_init_balls(package_balls, superset);
1093}
1094
1095static void __init omap_mux_init_signals(struct omap_mux_partition *partition,
1096 struct omap_board_mux *board_mux)
1097{
1098 omap_mux_set_cmdline_signals();
1099 omap_mux_write_array(partition, board_mux);
1100}
1101
1102#else
1103
1104static void omap_mux_init_package(struct omap_mux *superset,
1105 struct omap_mux *package_subset,
1106 struct omap_ball *package_balls)
1107{
1108}
1109
1110static void __init omap_mux_init_signals(struct omap_mux_partition *partition,
1111 struct omap_board_mux *board_mux)
1112{
1113}
1114
1115#endif
1116
1117static u32 mux_partitions_cnt;
1118
1119int __init omap_mux_init(const char *name, u32 flags,
1120 u32 mux_pbase, u32 mux_size,
1121 struct omap_mux *superset,
1122 struct omap_mux *package_subset,
1123 struct omap_board_mux *board_mux,
1124 struct omap_ball *package_balls)
1125{
1126 struct omap_mux_partition *partition;
1127
1128 partition = kzalloc(sizeof(struct omap_mux_partition), GFP_KERNEL);
1129 if (!partition)
1130 return -ENOMEM;
1131
1132 partition->name = name;
1133 partition->flags = flags;
1134 partition->size = mux_size;
1135 partition->phys = mux_pbase;
1136 partition->base = ioremap(mux_pbase, mux_size);
1137 if (!partition->base) {
1138 pr_err("%s: Could not ioremap mux partition at 0x%08x\n",
1139 __func__, partition->phys);
1140 kfree(partition);
1141 return -ENODEV;
1142 }
1143
1144 INIT_LIST_HEAD(&partition->muxmodes);
1145
1146 list_add_tail(&partition->node, &mux_partitions);
1147 mux_partitions_cnt++;
1148 pr_info("%s: Add partition: #%d: %s, flags: %x\n", __func__,
1149 mux_partitions_cnt, partition->name, partition->flags);
1150
1151 omap_mux_init_package(superset, package_subset, package_balls);
1152 omap_mux_init_list(partition, superset);
1153 omap_mux_init_signals(partition, board_mux);
1154
1155 return 0;
1156}
1157
1/*
2 * linux/arch/arm/mach-omap2/mux.c
3 *
4 * OMAP2, OMAP3 and OMAP4 pin multiplexing configurations
5 *
6 * Copyright (C) 2004 - 2010 Texas Instruments Inc.
7 * Copyright (C) 2003 - 2008 Nokia Corporation
8 *
9 * Written by Tony Lindgren
10 *
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 */
26#include <linux/kernel.h>
27#include <linux/init.h>
28#include <linux/io.h>
29#include <linux/list.h>
30#include <linux/slab.h>
31#include <linux/ctype.h>
32#include <linux/debugfs.h>
33#include <linux/seq_file.h>
34#include <linux/uaccess.h>
35#include <linux/irq.h>
36#include <linux/interrupt.h>
37
38
39#include "omap_hwmod.h"
40
41#include "soc.h"
42#include "control.h"
43#include "mux.h"
44#include "prm.h"
45#include "common.h"
46
47#define OMAP_MUX_BASE_OFFSET 0x30 /* Offset from CTRL_BASE */
48#define OMAP_MUX_BASE_SZ 0x5ca
49
50struct omap_mux_entry {
51 struct omap_mux mux;
52 struct list_head node;
53};
54
55static LIST_HEAD(mux_partitions);
56static DEFINE_MUTEX(muxmode_mutex);
57
58struct omap_mux_partition *omap_mux_get(const char *name)
59{
60 struct omap_mux_partition *partition;
61
62 list_for_each_entry(partition, &mux_partitions, node) {
63 if (!strcmp(name, partition->name))
64 return partition;
65 }
66
67 return NULL;
68}
69
70u16 omap_mux_read(struct omap_mux_partition *partition, u16 reg)
71{
72 if (partition->flags & OMAP_MUX_REG_8BIT)
73 return __raw_readb(partition->base + reg);
74 else
75 return __raw_readw(partition->base + reg);
76}
77
78void omap_mux_write(struct omap_mux_partition *partition, u16 val,
79 u16 reg)
80{
81 if (partition->flags & OMAP_MUX_REG_8BIT)
82 __raw_writeb(val, partition->base + reg);
83 else
84 __raw_writew(val, partition->base + reg);
85}
86
87void omap_mux_write_array(struct omap_mux_partition *partition,
88 struct omap_board_mux *board_mux)
89{
90 if (!board_mux)
91 return;
92
93 while (board_mux->reg_offset != OMAP_MUX_TERMINATOR) {
94 omap_mux_write(partition, board_mux->value,
95 board_mux->reg_offset);
96 board_mux++;
97 }
98}
99
100#ifdef CONFIG_OMAP_MUX
101
102static char *omap_mux_options;
103
104static int __init _omap_mux_init_gpio(struct omap_mux_partition *partition,
105 int gpio, int val)
106{
107 struct omap_mux_entry *e;
108 struct omap_mux *gpio_mux = NULL;
109 u16 old_mode;
110 u16 mux_mode;
111 int found = 0;
112 struct list_head *muxmodes = &partition->muxmodes;
113
114 if (!gpio)
115 return -EINVAL;
116
117 list_for_each_entry(e, muxmodes, node) {
118 struct omap_mux *m = &e->mux;
119 if (gpio == m->gpio) {
120 gpio_mux = m;
121 found++;
122 }
123 }
124
125 if (found == 0) {
126 pr_err("%s: Could not set gpio%i\n", __func__, gpio);
127 return -ENODEV;
128 }
129
130 if (found > 1) {
131 pr_info("%s: Multiple gpio paths (%d) for gpio%i\n", __func__,
132 found, gpio);
133 return -EINVAL;
134 }
135
136 old_mode = omap_mux_read(partition, gpio_mux->reg_offset);
137 mux_mode = val & ~(OMAP_MUX_NR_MODES - 1);
138 mux_mode |= partition->gpio;
139 pr_debug("%s: Setting signal %s.gpio%i 0x%04x -> 0x%04x\n", __func__,
140 gpio_mux->muxnames[0], gpio, old_mode, mux_mode);
141 omap_mux_write(partition, mux_mode, gpio_mux->reg_offset);
142
143 return 0;
144}
145
146int __init omap_mux_init_gpio(int gpio, int val)
147{
148 struct omap_mux_partition *partition;
149 int ret;
150
151 list_for_each_entry(partition, &mux_partitions, node) {
152 ret = _omap_mux_init_gpio(partition, gpio, val);
153 if (!ret)
154 return ret;
155 }
156
157 return -ENODEV;
158}
159
160static int __init _omap_mux_get_by_name(struct omap_mux_partition *partition,
161 const char *muxname,
162 struct omap_mux **found_mux)
163{
164 struct omap_mux *mux = NULL;
165 struct omap_mux_entry *e;
166 const char *mode_name;
167 int found = 0, found_mode = 0, mode0_len = 0;
168 struct list_head *muxmodes = &partition->muxmodes;
169
170 mode_name = strchr(muxname, '.');
171 if (mode_name) {
172 mode0_len = strlen(muxname) - strlen(mode_name);
173 mode_name++;
174 } else {
175 mode_name = muxname;
176 }
177
178 list_for_each_entry(e, muxmodes, node) {
179 char *m0_entry;
180 int i;
181
182 mux = &e->mux;
183 m0_entry = mux->muxnames[0];
184
185 /* First check for full name in mode0.muxmode format */
186 if (mode0_len && strncmp(muxname, m0_entry, mode0_len))
187 continue;
188
189 /* Then check for muxmode only */
190 for (i = 0; i < OMAP_MUX_NR_MODES; i++) {
191 char *mode_cur = mux->muxnames[i];
192
193 if (!mode_cur)
194 continue;
195
196 if (!strcmp(mode_name, mode_cur)) {
197 *found_mux = mux;
198 found++;
199 found_mode = i;
200 }
201 }
202 }
203
204 if (found == 1) {
205 return found_mode;
206 }
207
208 if (found > 1) {
209 pr_err("%s: Multiple signal paths (%i) for %s\n", __func__,
210 found, muxname);
211 return -EINVAL;
212 }
213
214 return -ENODEV;
215}
216
217int __init omap_mux_get_by_name(const char *muxname,
218 struct omap_mux_partition **found_partition,
219 struct omap_mux **found_mux)
220{
221 struct omap_mux_partition *partition;
222
223 list_for_each_entry(partition, &mux_partitions, node) {
224 struct omap_mux *mux = NULL;
225 int mux_mode = _omap_mux_get_by_name(partition, muxname, &mux);
226 if (mux_mode < 0)
227 continue;
228
229 *found_partition = partition;
230 *found_mux = mux;
231
232 return mux_mode;
233 }
234
235 pr_err("%s: Could not find signal %s\n", __func__, muxname);
236
237 return -ENODEV;
238}
239
240int __init omap_mux_init_signal(const char *muxname, int val)
241{
242 struct omap_mux_partition *partition = NULL;
243 struct omap_mux *mux = NULL;
244 u16 old_mode;
245 int mux_mode;
246
247 mux_mode = omap_mux_get_by_name(muxname, &partition, &mux);
248 if (mux_mode < 0 || !mux)
249 return mux_mode;
250
251 old_mode = omap_mux_read(partition, mux->reg_offset);
252 mux_mode |= val;
253 pr_debug("%s: Setting signal %s 0x%04x -> 0x%04x\n",
254 __func__, muxname, old_mode, mux_mode);
255 omap_mux_write(partition, mux_mode, mux->reg_offset);
256
257 return 0;
258}
259
260struct omap_hwmod_mux_info * __init
261omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads)
262{
263 struct omap_hwmod_mux_info *hmux;
264 int i, nr_pads_dynamic = 0;
265
266 if (!bpads || nr_pads < 1)
267 return NULL;
268
269 hmux = kzalloc(sizeof(struct omap_hwmod_mux_info), GFP_KERNEL);
270 if (!hmux)
271 goto err1;
272
273 hmux->nr_pads = nr_pads;
274
275 hmux->pads = kzalloc(sizeof(struct omap_device_pad) *
276 nr_pads, GFP_KERNEL);
277 if (!hmux->pads)
278 goto err2;
279
280 for (i = 0; i < hmux->nr_pads; i++) {
281 struct omap_mux_partition *partition;
282 struct omap_device_pad *bpad = &bpads[i], *pad = &hmux->pads[i];
283 struct omap_mux *mux;
284 int mux_mode;
285
286 mux_mode = omap_mux_get_by_name(bpad->name, &partition, &mux);
287 if (mux_mode < 0)
288 goto err3;
289 if (!pad->partition)
290 pad->partition = partition;
291 if (!pad->mux)
292 pad->mux = mux;
293
294 pad->name = kzalloc(strlen(bpad->name) + 1, GFP_KERNEL);
295 if (!pad->name) {
296 int j;
297
298 for (j = i - 1; j >= 0; j--)
299 kfree(hmux->pads[j].name);
300 goto err3;
301 }
302 strcpy(pad->name, bpad->name);
303
304 pad->flags = bpad->flags;
305 pad->enable = bpad->enable;
306 pad->idle = bpad->idle;
307 pad->off = bpad->off;
308
309 if (pad->flags &
310 (OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP))
311 nr_pads_dynamic++;
312
313 pr_debug("%s: Initialized %s\n", __func__, pad->name);
314 }
315
316 if (!nr_pads_dynamic)
317 return hmux;
318
319 /*
320 * Add pads that need dynamic muxing into a separate list
321 */
322
323 hmux->nr_pads_dynamic = nr_pads_dynamic;
324 hmux->pads_dynamic = kzalloc(sizeof(struct omap_device_pad *) *
325 nr_pads_dynamic, GFP_KERNEL);
326 if (!hmux->pads_dynamic) {
327 pr_err("%s: Could not allocate dynamic pads\n", __func__);
328 return hmux;
329 }
330
331 nr_pads_dynamic = 0;
332 for (i = 0; i < hmux->nr_pads; i++) {
333 struct omap_device_pad *pad = &hmux->pads[i];
334
335 if (pad->flags &
336 (OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP)) {
337 pr_debug("%s: pad %s tagged dynamic\n",
338 __func__, pad->name);
339 hmux->pads_dynamic[nr_pads_dynamic] = pad;
340 nr_pads_dynamic++;
341 }
342 }
343
344 return hmux;
345
346err3:
347 kfree(hmux->pads);
348err2:
349 kfree(hmux);
350err1:
351 pr_err("%s: Could not allocate device mux entry\n", __func__);
352
353 return NULL;
354}
355
356/**
357 * omap_hwmod_mux_scan_wakeups - omap hwmod scan wakeup pads
358 * @hmux: Pads for a hwmod
359 * @mpu_irqs: MPU irq array for a hwmod
360 *
361 * Scans the wakeup status of pads for a single hwmod. If an irq
362 * array is defined for this mux, the parser will call the registered
363 * ISRs for corresponding pads, otherwise the parser will stop at the
364 * first wakeup active pad and return. Returns true if there is a
365 * pending and non-served wakeup event for the mux, otherwise false.
366 */
367static bool omap_hwmod_mux_scan_wakeups(struct omap_hwmod_mux_info *hmux,
368 struct omap_hwmod_irq_info *mpu_irqs)
369{
370 int i, irq;
371 unsigned int val;
372 u32 handled_irqs = 0;
373
374 for (i = 0; i < hmux->nr_pads_dynamic; i++) {
375 struct omap_device_pad *pad = hmux->pads_dynamic[i];
376
377 if (!(pad->flags & OMAP_DEVICE_PAD_WAKEUP) ||
378 !(pad->idle & OMAP_WAKEUP_EN))
379 continue;
380
381 val = omap_mux_read(pad->partition, pad->mux->reg_offset);
382 if (!(val & OMAP_WAKEUP_EVENT))
383 continue;
384
385 if (!hmux->irqs)
386 return true;
387
388 irq = hmux->irqs[i];
389 /* make sure we only handle each irq once */
390 if (handled_irqs & 1 << irq)
391 continue;
392
393 handled_irqs |= 1 << irq;
394
395 generic_handle_irq(mpu_irqs[irq].irq);
396 }
397
398 return false;
399}
400
401/**
402 * _omap_hwmod_mux_handle_irq - Process wakeup events for a single hwmod
403 *
404 * Checks a single hwmod for every wakeup capable pad to see if there is an
405 * active wakeup event. If this is the case, call the corresponding ISR.
406 */
407static int _omap_hwmod_mux_handle_irq(struct omap_hwmod *oh, void *data)
408{
409 if (!oh->mux || !oh->mux->enabled)
410 return 0;
411 if (omap_hwmod_mux_scan_wakeups(oh->mux, oh->mpu_irqs))
412 generic_handle_irq(oh->mpu_irqs[0].irq);
413 return 0;
414}
415
416/**
417 * omap_hwmod_mux_handle_irq - Process pad wakeup irqs.
418 *
419 * Calls a function for each registered omap_hwmod to check
420 * pad wakeup statuses.
421 */
422static irqreturn_t omap_hwmod_mux_handle_irq(int irq, void *unused)
423{
424 omap_hwmod_for_each(_omap_hwmod_mux_handle_irq, NULL);
425 return IRQ_HANDLED;
426}
427
428/* Assumes the calling function takes care of locking */
429void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state)
430{
431 int i;
432
433 /* Runtime idling of dynamic pads */
434 if (state == _HWMOD_STATE_IDLE && hmux->enabled) {
435 for (i = 0; i < hmux->nr_pads_dynamic; i++) {
436 struct omap_device_pad *pad = hmux->pads_dynamic[i];
437 int val = -EINVAL;
438
439 val = pad->idle;
440 omap_mux_write(pad->partition, val,
441 pad->mux->reg_offset);
442 }
443
444 return;
445 }
446
447 /* Runtime enabling of dynamic pads */
448 if ((state == _HWMOD_STATE_ENABLED) && hmux->pads_dynamic
449 && hmux->enabled) {
450 for (i = 0; i < hmux->nr_pads_dynamic; i++) {
451 struct omap_device_pad *pad = hmux->pads_dynamic[i];
452 int val = -EINVAL;
453
454 val = pad->enable;
455 omap_mux_write(pad->partition, val,
456 pad->mux->reg_offset);
457 }
458
459 return;
460 }
461
462 /* Enabling or disabling of all pads */
463 for (i = 0; i < hmux->nr_pads; i++) {
464 struct omap_device_pad *pad = &hmux->pads[i];
465 int flags, val = -EINVAL;
466
467 flags = pad->flags;
468
469 switch (state) {
470 case _HWMOD_STATE_ENABLED:
471 val = pad->enable;
472 pr_debug("%s: Enabling %s %x\n", __func__,
473 pad->name, val);
474 break;
475 case _HWMOD_STATE_DISABLED:
476 /* Use safe mode unless OMAP_DEVICE_PAD_REMUX */
477 if (flags & OMAP_DEVICE_PAD_REMUX)
478 val = pad->off;
479 else
480 val = OMAP_MUX_MODE7;
481 pr_debug("%s: Disabling %s %x\n", __func__,
482 pad->name, val);
483 break;
484 default:
485 /* Nothing to be done */
486 break;
487 }
488
489 if (val >= 0) {
490 omap_mux_write(pad->partition, val,
491 pad->mux->reg_offset);
492 pad->flags = flags;
493 }
494 }
495
496 if (state == _HWMOD_STATE_ENABLED)
497 hmux->enabled = true;
498 else
499 hmux->enabled = false;
500}
501
502#ifdef CONFIG_DEBUG_FS
503
504#define OMAP_MUX_MAX_NR_FLAGS 10
505#define OMAP_MUX_TEST_FLAG(val, mask) \
506 if (((val) & (mask)) == (mask)) { \
507 i++; \
508 flags[i] = #mask; \
509 }
510
511/* REVISIT: Add checking for non-optimal mux settings */
512static inline void omap_mux_decode(struct seq_file *s, u16 val)
513{
514 char *flags[OMAP_MUX_MAX_NR_FLAGS];
515 char mode[sizeof("OMAP_MUX_MODE") + 1];
516 int i = -1;
517
518 sprintf(mode, "OMAP_MUX_MODE%d", val & 0x7);
519 i++;
520 flags[i] = mode;
521
522 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_OFF_WAKEUPENABLE);
523 if (val & OMAP_OFF_EN) {
524 if (!(val & OMAP_OFFOUT_EN)) {
525 if (!(val & OMAP_OFF_PULL_UP)) {
526 OMAP_MUX_TEST_FLAG(val,
527 OMAP_PIN_OFF_INPUT_PULLDOWN);
528 } else {
529 OMAP_MUX_TEST_FLAG(val,
530 OMAP_PIN_OFF_INPUT_PULLUP);
531 }
532 } else {
533 if (!(val & OMAP_OFFOUT_VAL)) {
534 OMAP_MUX_TEST_FLAG(val,
535 OMAP_PIN_OFF_OUTPUT_LOW);
536 } else {
537 OMAP_MUX_TEST_FLAG(val,
538 OMAP_PIN_OFF_OUTPUT_HIGH);
539 }
540 }
541 }
542
543 if (val & OMAP_INPUT_EN) {
544 if (val & OMAP_PULL_ENA) {
545 if (!(val & OMAP_PULL_UP)) {
546 OMAP_MUX_TEST_FLAG(val,
547 OMAP_PIN_INPUT_PULLDOWN);
548 } else {
549 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT_PULLUP);
550 }
551 } else {
552 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT);
553 }
554 } else {
555 i++;
556 flags[i] = "OMAP_PIN_OUTPUT";
557 }
558
559 do {
560 seq_printf(s, "%s", flags[i]);
561 if (i > 0)
562 seq_printf(s, " | ");
563 } while (i-- > 0);
564}
565
566#define OMAP_MUX_DEFNAME_LEN 32
567
568static int omap_mux_dbg_board_show(struct seq_file *s, void *unused)
569{
570 struct omap_mux_partition *partition = s->private;
571 struct omap_mux_entry *e;
572 u8 omap_gen = omap_rev() >> 28;
573
574 list_for_each_entry(e, &partition->muxmodes, node) {
575 struct omap_mux *m = &e->mux;
576 char m0_def[OMAP_MUX_DEFNAME_LEN];
577 char *m0_name = m->muxnames[0];
578 u16 val;
579 int i, mode;
580
581 if (!m0_name)
582 continue;
583
584 /* REVISIT: Needs to be updated if mode0 names get longer */
585 for (i = 0; i < OMAP_MUX_DEFNAME_LEN; i++) {
586 if (m0_name[i] == '\0') {
587 m0_def[i] = m0_name[i];
588 break;
589 }
590 m0_def[i] = toupper(m0_name[i]);
591 }
592 val = omap_mux_read(partition, m->reg_offset);
593 mode = val & OMAP_MUX_MODE7;
594 if (mode != 0)
595 seq_printf(s, "/* %s */\n", m->muxnames[mode]);
596
597 /*
598 * XXX: Might be revisited to support differences across
599 * same OMAP generation.
600 */
601 seq_printf(s, "OMAP%d_MUX(%s, ", omap_gen, m0_def);
602 omap_mux_decode(s, val);
603 seq_printf(s, "),\n");
604 }
605
606 return 0;
607}
608
609static int omap_mux_dbg_board_open(struct inode *inode, struct file *file)
610{
611 return single_open(file, omap_mux_dbg_board_show, inode->i_private);
612}
613
614static const struct file_operations omap_mux_dbg_board_fops = {
615 .open = omap_mux_dbg_board_open,
616 .read = seq_read,
617 .llseek = seq_lseek,
618 .release = single_release,
619};
620
621static struct omap_mux_partition *omap_mux_get_partition(struct omap_mux *mux)
622{
623 struct omap_mux_partition *partition;
624
625 list_for_each_entry(partition, &mux_partitions, node) {
626 struct list_head *muxmodes = &partition->muxmodes;
627 struct omap_mux_entry *e;
628
629 list_for_each_entry(e, muxmodes, node) {
630 struct omap_mux *m = &e->mux;
631
632 if (m == mux)
633 return partition;
634 }
635 }
636
637 return NULL;
638}
639
640static int omap_mux_dbg_signal_show(struct seq_file *s, void *unused)
641{
642 struct omap_mux *m = s->private;
643 struct omap_mux_partition *partition;
644 const char *none = "NA";
645 u16 val;
646 int mode;
647
648 partition = omap_mux_get_partition(m);
649 if (!partition)
650 return 0;
651
652 val = omap_mux_read(partition, m->reg_offset);
653 mode = val & OMAP_MUX_MODE7;
654
655 seq_printf(s, "name: %s.%s (0x%08x/0x%03x = 0x%04x), b %s, t %s\n",
656 m->muxnames[0], m->muxnames[mode],
657 partition->phys + m->reg_offset, m->reg_offset, val,
658 m->balls[0] ? m->balls[0] : none,
659 m->balls[1] ? m->balls[1] : none);
660 seq_printf(s, "mode: ");
661 omap_mux_decode(s, val);
662 seq_printf(s, "\n");
663 seq_printf(s, "signals: %s | %s | %s | %s | %s | %s | %s | %s\n",
664 m->muxnames[0] ? m->muxnames[0] : none,
665 m->muxnames[1] ? m->muxnames[1] : none,
666 m->muxnames[2] ? m->muxnames[2] : none,
667 m->muxnames[3] ? m->muxnames[3] : none,
668 m->muxnames[4] ? m->muxnames[4] : none,
669 m->muxnames[5] ? m->muxnames[5] : none,
670 m->muxnames[6] ? m->muxnames[6] : none,
671 m->muxnames[7] ? m->muxnames[7] : none);
672
673 return 0;
674}
675
676#define OMAP_MUX_MAX_ARG_CHAR 7
677
678static ssize_t omap_mux_dbg_signal_write(struct file *file,
679 const char __user *user_buf,
680 size_t count, loff_t *ppos)
681{
682 char buf[OMAP_MUX_MAX_ARG_CHAR];
683 struct seq_file *seqf;
684 struct omap_mux *m;
685 unsigned long val;
686 int buf_size, ret;
687 struct omap_mux_partition *partition;
688
689 if (count > OMAP_MUX_MAX_ARG_CHAR)
690 return -EINVAL;
691
692 memset(buf, 0, sizeof(buf));
693 buf_size = min(count, sizeof(buf) - 1);
694
695 if (copy_from_user(buf, user_buf, buf_size))
696 return -EFAULT;
697
698 ret = strict_strtoul(buf, 0x10, &val);
699 if (ret < 0)
700 return ret;
701
702 if (val > 0xffff)
703 return -EINVAL;
704
705 seqf = file->private_data;
706 m = seqf->private;
707
708 partition = omap_mux_get_partition(m);
709 if (!partition)
710 return -ENODEV;
711
712 omap_mux_write(partition, (u16)val, m->reg_offset);
713 *ppos += count;
714
715 return count;
716}
717
718static int omap_mux_dbg_signal_open(struct inode *inode, struct file *file)
719{
720 return single_open(file, omap_mux_dbg_signal_show, inode->i_private);
721}
722
723static const struct file_operations omap_mux_dbg_signal_fops = {
724 .open = omap_mux_dbg_signal_open,
725 .read = seq_read,
726 .write = omap_mux_dbg_signal_write,
727 .llseek = seq_lseek,
728 .release = single_release,
729};
730
731static struct dentry *mux_dbg_dir;
732
733static void __init omap_mux_dbg_create_entry(
734 struct omap_mux_partition *partition,
735 struct dentry *mux_dbg_dir)
736{
737 struct omap_mux_entry *e;
738
739 list_for_each_entry(e, &partition->muxmodes, node) {
740 struct omap_mux *m = &e->mux;
741
742 (void)debugfs_create_file(m->muxnames[0], S_IWUSR | S_IRUGO,
743 mux_dbg_dir, m,
744 &omap_mux_dbg_signal_fops);
745 }
746}
747
748static void __init omap_mux_dbg_init(void)
749{
750 struct omap_mux_partition *partition;
751 static struct dentry *mux_dbg_board_dir;
752
753 mux_dbg_dir = debugfs_create_dir("omap_mux", NULL);
754 if (!mux_dbg_dir)
755 return;
756
757 mux_dbg_board_dir = debugfs_create_dir("board", mux_dbg_dir);
758 if (!mux_dbg_board_dir)
759 return;
760
761 list_for_each_entry(partition, &mux_partitions, node) {
762 omap_mux_dbg_create_entry(partition, mux_dbg_dir);
763 (void)debugfs_create_file(partition->name, S_IRUGO,
764 mux_dbg_board_dir, partition,
765 &omap_mux_dbg_board_fops);
766 }
767}
768
769#else
770static inline void omap_mux_dbg_init(void)
771{
772}
773#endif /* CONFIG_DEBUG_FS */
774
775static void __init omap_mux_free_names(struct omap_mux *m)
776{
777 int i;
778
779 for (i = 0; i < OMAP_MUX_NR_MODES; i++)
780 kfree(m->muxnames[i]);
781
782#ifdef CONFIG_DEBUG_FS
783 for (i = 0; i < OMAP_MUX_NR_SIDES; i++)
784 kfree(m->balls[i]);
785#endif
786
787}
788
789/* Free all data except for GPIO pins unless CONFIG_DEBUG_FS is set */
790int __init omap_mux_late_init(void)
791{
792 struct omap_mux_partition *partition;
793 int ret;
794
795 list_for_each_entry(partition, &mux_partitions, node) {
796 struct omap_mux_entry *e, *tmp;
797 list_for_each_entry_safe(e, tmp, &partition->muxmodes, node) {
798 struct omap_mux *m = &e->mux;
799 u16 mode = omap_mux_read(partition, m->reg_offset);
800
801 if (OMAP_MODE_GPIO(partition, mode))
802 continue;
803
804#ifndef CONFIG_DEBUG_FS
805 mutex_lock(&muxmode_mutex);
806 list_del(&e->node);
807 mutex_unlock(&muxmode_mutex);
808 omap_mux_free_names(m);
809 kfree(m);
810#endif
811 }
812 }
813
814 omap_mux_dbg_init();
815
816 /* see pinctrl-single-omap for the wake-up interrupt handling */
817 if (of_have_populated_dt())
818 return 0;
819
820 ret = request_irq(omap_prcm_event_to_irq("io"),
821 omap_hwmod_mux_handle_irq, IRQF_SHARED | IRQF_NO_SUSPEND,
822 "hwmod_io", omap_mux_late_init);
823
824 if (ret)
825 pr_warning("mux: Failed to setup hwmod io irq %d\n", ret);
826
827 return 0;
828}
829
830static void __init omap_mux_package_fixup(struct omap_mux *p,
831 struct omap_mux *superset)
832{
833 while (p->reg_offset != OMAP_MUX_TERMINATOR) {
834 struct omap_mux *s = superset;
835 int found = 0;
836
837 while (s->reg_offset != OMAP_MUX_TERMINATOR) {
838 if (s->reg_offset == p->reg_offset) {
839 *s = *p;
840 found++;
841 break;
842 }
843 s++;
844 }
845 if (!found)
846 pr_err("%s: Unknown entry offset 0x%x\n", __func__,
847 p->reg_offset);
848 p++;
849 }
850}
851
852#ifdef CONFIG_DEBUG_FS
853
854static void __init omap_mux_package_init_balls(struct omap_ball *b,
855 struct omap_mux *superset)
856{
857 while (b->reg_offset != OMAP_MUX_TERMINATOR) {
858 struct omap_mux *s = superset;
859 int found = 0;
860
861 while (s->reg_offset != OMAP_MUX_TERMINATOR) {
862 if (s->reg_offset == b->reg_offset) {
863 s->balls[0] = b->balls[0];
864 s->balls[1] = b->balls[1];
865 found++;
866 break;
867 }
868 s++;
869 }
870 if (!found)
871 pr_err("%s: Unknown ball offset 0x%x\n", __func__,
872 b->reg_offset);
873 b++;
874 }
875}
876
877#else /* CONFIG_DEBUG_FS */
878
879static inline void omap_mux_package_init_balls(struct omap_ball *b,
880 struct omap_mux *superset)
881{
882}
883
884#endif /* CONFIG_DEBUG_FS */
885
886static int __init omap_mux_setup(char *options)
887{
888 if (!options)
889 return 0;
890
891 omap_mux_options = options;
892
893 return 1;
894}
895__setup("omap_mux=", omap_mux_setup);
896
897/*
898 * Note that the omap_mux=some.signal1=0x1234,some.signal2=0x1234
899 * cmdline options only override the bootloader values.
900 * During development, please enable CONFIG_DEBUG_FS, and use the
901 * signal specific entries under debugfs.
902 */
903static void __init omap_mux_set_cmdline_signals(void)
904{
905 char *options, *next_opt, *token;
906
907 if (!omap_mux_options)
908 return;
909
910 options = kstrdup(omap_mux_options, GFP_KERNEL);
911 if (!options)
912 return;
913
914 next_opt = options;
915
916 while ((token = strsep(&next_opt, ",")) != NULL) {
917 char *keyval, *name;
918 unsigned long val;
919
920 keyval = token;
921 name = strsep(&keyval, "=");
922 if (name) {
923 int res;
924
925 res = strict_strtoul(keyval, 0x10, &val);
926 if (res < 0)
927 continue;
928
929 omap_mux_init_signal(name, (u16)val);
930 }
931 }
932
933 kfree(options);
934}
935
936static int __init omap_mux_copy_names(struct omap_mux *src,
937 struct omap_mux *dst)
938{
939 int i;
940
941 for (i = 0; i < OMAP_MUX_NR_MODES; i++) {
942 if (src->muxnames[i]) {
943 dst->muxnames[i] = kstrdup(src->muxnames[i],
944 GFP_KERNEL);
945 if (!dst->muxnames[i])
946 goto free;
947 }
948 }
949
950#ifdef CONFIG_DEBUG_FS
951 for (i = 0; i < OMAP_MUX_NR_SIDES; i++) {
952 if (src->balls[i]) {
953 dst->balls[i] = kstrdup(src->balls[i], GFP_KERNEL);
954 if (!dst->balls[i])
955 goto free;
956 }
957 }
958#endif
959
960 return 0;
961
962free:
963 omap_mux_free_names(dst);
964 return -ENOMEM;
965
966}
967
968#endif /* CONFIG_OMAP_MUX */
969
970static struct omap_mux *omap_mux_get_by_gpio(
971 struct omap_mux_partition *partition,
972 int gpio)
973{
974 struct omap_mux_entry *e;
975 struct omap_mux *ret = NULL;
976
977 list_for_each_entry(e, &partition->muxmodes, node) {
978 struct omap_mux *m = &e->mux;
979 if (m->gpio == gpio) {
980 ret = m;
981 break;
982 }
983 }
984
985 return ret;
986}
987
988/* Needed for dynamic muxing of GPIO pins for off-idle */
989u16 omap_mux_get_gpio(int gpio)
990{
991 struct omap_mux_partition *partition;
992 struct omap_mux *m = NULL;
993
994 list_for_each_entry(partition, &mux_partitions, node) {
995 m = omap_mux_get_by_gpio(partition, gpio);
996 if (m)
997 return omap_mux_read(partition, m->reg_offset);
998 }
999
1000 if (!m || m->reg_offset == OMAP_MUX_TERMINATOR)
1001 pr_err("%s: Could not get gpio%i\n", __func__, gpio);
1002
1003 return OMAP_MUX_TERMINATOR;
1004}
1005
1006/* Needed for dynamic muxing of GPIO pins for off-idle */
1007void omap_mux_set_gpio(u16 val, int gpio)
1008{
1009 struct omap_mux_partition *partition;
1010 struct omap_mux *m = NULL;
1011
1012 list_for_each_entry(partition, &mux_partitions, node) {
1013 m = omap_mux_get_by_gpio(partition, gpio);
1014 if (m) {
1015 omap_mux_write(partition, val, m->reg_offset);
1016 return;
1017 }
1018 }
1019
1020 if (!m || m->reg_offset == OMAP_MUX_TERMINATOR)
1021 pr_err("%s: Could not set gpio%i\n", __func__, gpio);
1022}
1023
1024static struct omap_mux * __init omap_mux_list_add(
1025 struct omap_mux_partition *partition,
1026 struct omap_mux *src)
1027{
1028 struct omap_mux_entry *entry;
1029 struct omap_mux *m;
1030
1031 entry = kzalloc(sizeof(struct omap_mux_entry), GFP_KERNEL);
1032 if (!entry)
1033 return NULL;
1034
1035 m = &entry->mux;
1036 entry->mux = *src;
1037
1038#ifdef CONFIG_OMAP_MUX
1039 if (omap_mux_copy_names(src, m)) {
1040 kfree(entry);
1041 return NULL;
1042 }
1043#endif
1044
1045 mutex_lock(&muxmode_mutex);
1046 list_add_tail(&entry->node, &partition->muxmodes);
1047 mutex_unlock(&muxmode_mutex);
1048
1049 return m;
1050}
1051
1052/*
1053 * Note if CONFIG_OMAP_MUX is not selected, we will only initialize
1054 * the GPIO to mux offset mapping that is needed for dynamic muxing
1055 * of GPIO pins for off-idle.
1056 */
1057static void __init omap_mux_init_list(struct omap_mux_partition *partition,
1058 struct omap_mux *superset)
1059{
1060 while (superset->reg_offset != OMAP_MUX_TERMINATOR) {
1061 struct omap_mux *entry;
1062
1063#ifdef CONFIG_OMAP_MUX
1064 if (!superset->muxnames || !superset->muxnames[0]) {
1065 superset++;
1066 continue;
1067 }
1068#else
1069 /* Skip pins that are not muxed as GPIO by bootloader */
1070 if (!OMAP_MODE_GPIO(partition, omap_mux_read(partition,
1071 superset->reg_offset))) {
1072 superset++;
1073 continue;
1074 }
1075#endif
1076
1077 entry = omap_mux_list_add(partition, superset);
1078 if (!entry) {
1079 pr_err("%s: Could not add entry\n", __func__);
1080 return;
1081 }
1082 superset++;
1083 }
1084}
1085
1086#ifdef CONFIG_OMAP_MUX
1087
1088static void omap_mux_init_package(struct omap_mux *superset,
1089 struct omap_mux *package_subset,
1090 struct omap_ball *package_balls)
1091{
1092 if (package_subset)
1093 omap_mux_package_fixup(package_subset, superset);
1094 if (package_balls)
1095 omap_mux_package_init_balls(package_balls, superset);
1096}
1097
1098static void __init omap_mux_init_signals(struct omap_mux_partition *partition,
1099 struct omap_board_mux *board_mux)
1100{
1101 omap_mux_set_cmdline_signals();
1102 omap_mux_write_array(partition, board_mux);
1103}
1104
1105#else
1106
1107static void omap_mux_init_package(struct omap_mux *superset,
1108 struct omap_mux *package_subset,
1109 struct omap_ball *package_balls)
1110{
1111}
1112
1113static void __init omap_mux_init_signals(struct omap_mux_partition *partition,
1114 struct omap_board_mux *board_mux)
1115{
1116}
1117
1118#endif
1119
1120static u32 mux_partitions_cnt;
1121
1122int __init omap_mux_init(const char *name, u32 flags,
1123 u32 mux_pbase, u32 mux_size,
1124 struct omap_mux *superset,
1125 struct omap_mux *package_subset,
1126 struct omap_board_mux *board_mux,
1127 struct omap_ball *package_balls)
1128{
1129 struct omap_mux_partition *partition;
1130
1131 partition = kzalloc(sizeof(struct omap_mux_partition), GFP_KERNEL);
1132 if (!partition)
1133 return -ENOMEM;
1134
1135 partition->name = name;
1136 partition->flags = flags;
1137 partition->gpio = flags & OMAP_MUX_MODE7;
1138 partition->size = mux_size;
1139 partition->phys = mux_pbase;
1140 partition->base = ioremap(mux_pbase, mux_size);
1141 if (!partition->base) {
1142 pr_err("%s: Could not ioremap mux partition at 0x%08x\n",
1143 __func__, partition->phys);
1144 kfree(partition);
1145 return -ENODEV;
1146 }
1147
1148 INIT_LIST_HEAD(&partition->muxmodes);
1149
1150 list_add_tail(&partition->node, &mux_partitions);
1151 mux_partitions_cnt++;
1152 pr_info("%s: Add partition: #%d: %s, flags: %x\n", __func__,
1153 mux_partitions_cnt, partition->name, partition->flags);
1154
1155 omap_mux_init_package(superset, package_subset, package_balls);
1156 omap_mux_init_list(partition, superset);
1157 omap_mux_init_signals(partition, board_mux);
1158
1159 return 0;
1160}
1161