2 * linux/arch/arm/mach-omap2/mux.c
4 * OMAP2, OMAP3 and OMAP4 pin multiplexing configurations
6 * Copyright (C) 2004 - 2010 Texas Instruments Inc.
7 * Copyright (C) 2003 - 2008 Nokia Corporation
9 * Written by Tony Lindgren
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.
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.
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
26 #include <linux/kernel.h>
27 #include <linux/init.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>
39 #include "omap_hwmod.h"
47 #define OMAP_MUX_BASE_OFFSET 0x30 /* Offset from CTRL_BASE */
48 #define OMAP_MUX_BASE_SZ 0x5ca
50 struct omap_mux_entry
{
52 struct list_head node
;
55 static LIST_HEAD(mux_partitions
);
56 static DEFINE_MUTEX(muxmode_mutex
);
58 struct omap_mux_partition
*omap_mux_get(const char *name
)
60 struct omap_mux_partition
*partition
;
62 list_for_each_entry(partition
, &mux_partitions
, node
) {
63 if (!strcmp(name
, partition
->name
))
70 u16
omap_mux_read(struct omap_mux_partition
*partition
, u16 reg
)
72 if (partition
->flags
& OMAP_MUX_REG_8BIT
)
73 return readb_relaxed(partition
->base
+ reg
);
75 return readw_relaxed(partition
->base
+ reg
);
78 void omap_mux_write(struct omap_mux_partition
*partition
, u16 val
,
81 if (partition
->flags
& OMAP_MUX_REG_8BIT
)
82 writeb_relaxed(val
, partition
->base
+ reg
);
84 writew_relaxed(val
, partition
->base
+ reg
);
87 void omap_mux_write_array(struct omap_mux_partition
*partition
,
88 struct omap_board_mux
*board_mux
)
93 while (board_mux
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
94 omap_mux_write(partition
, board_mux
->value
,
95 board_mux
->reg_offset
);
100 #ifdef CONFIG_OMAP_MUX
102 static char *omap_mux_options
;
104 static int __init
_omap_mux_init_gpio(struct omap_mux_partition
*partition
,
107 struct omap_mux_entry
*e
;
108 struct omap_mux
*gpio_mux
= NULL
;
112 struct list_head
*muxmodes
= &partition
->muxmodes
;
117 list_for_each_entry(e
, muxmodes
, node
) {
118 struct omap_mux
*m
= &e
->mux
;
119 if (gpio
== m
->gpio
) {
126 pr_err("%s: Could not set gpio%i\n", __func__
, gpio
);
131 pr_info("%s: Multiple gpio paths (%d) for gpio%i\n", __func__
,
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
);
146 int __init
omap_mux_init_gpio(int gpio
, int val
)
148 struct omap_mux_partition
*partition
;
151 list_for_each_entry(partition
, &mux_partitions
, node
) {
152 ret
= _omap_mux_init_gpio(partition
, gpio
, val
);
160 static int __init
_omap_mux_get_by_name(struct omap_mux_partition
*partition
,
162 struct omap_mux
**found_mux
)
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
;
170 mode_name
= strchr(muxname
, '.');
172 mode0_len
= strlen(muxname
) - strlen(mode_name
);
178 list_for_each_entry(e
, muxmodes
, node
) {
183 m0_entry
= mux
->muxnames
[0];
185 /* First check for full name in mode0.muxmode format */
187 if (strncmp(muxname
, m0_entry
, mode0_len
) ||
188 (strlen(m0_entry
) != mode0_len
))
191 /* Then check for muxmode only */
192 for (i
= 0; i
< OMAP_MUX_NR_MODES
; i
++) {
193 char *mode_cur
= mux
->muxnames
[i
];
198 if (!strcmp(mode_name
, mode_cur
)) {
211 pr_err("%s: Multiple signal paths (%i) for %s\n", __func__
,
219 int __init
omap_mux_get_by_name(const char *muxname
,
220 struct omap_mux_partition
**found_partition
,
221 struct omap_mux
**found_mux
)
223 struct omap_mux_partition
*partition
;
225 list_for_each_entry(partition
, &mux_partitions
, node
) {
226 struct omap_mux
*mux
= NULL
;
227 int mux_mode
= _omap_mux_get_by_name(partition
, muxname
, &mux
);
231 *found_partition
= partition
;
237 pr_err("%s: Could not find signal %s\n", __func__
, muxname
);
242 int __init
omap_mux_init_signal(const char *muxname
, int val
)
244 struct omap_mux_partition
*partition
= NULL
;
245 struct omap_mux
*mux
= NULL
;
249 mux_mode
= omap_mux_get_by_name(muxname
, &partition
, &mux
);
250 if (mux_mode
< 0 || !mux
)
253 old_mode
= omap_mux_read(partition
, mux
->reg_offset
);
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
);
262 struct omap_hwmod_mux_info
* __init
263 omap_hwmod_mux_init(struct omap_device_pad
*bpads
, int nr_pads
)
265 struct omap_hwmod_mux_info
*hmux
;
266 int i
, nr_pads_dynamic
= 0;
268 if (!bpads
|| nr_pads
< 1)
271 hmux
= kzalloc(sizeof(struct omap_hwmod_mux_info
), GFP_KERNEL
);
275 hmux
->nr_pads
= nr_pads
;
277 hmux
->pads
= kzalloc(sizeof(struct omap_device_pad
) *
278 nr_pads
, GFP_KERNEL
);
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
;
288 mux_mode
= omap_mux_get_by_name(bpad
->name
, &partition
, &mux
);
292 pad
->partition
= partition
;
296 pad
->name
= kzalloc(strlen(bpad
->name
) + 1, GFP_KERNEL
);
300 for (j
= i
- 1; j
>= 0; j
--)
301 kfree(hmux
->pads
[j
].name
);
304 strcpy(pad
->name
, bpad
->name
);
306 pad
->flags
= bpad
->flags
;
307 pad
->enable
= bpad
->enable
;
308 pad
->idle
= bpad
->idle
;
309 pad
->off
= bpad
->off
;
312 (OMAP_DEVICE_PAD_REMUX
| OMAP_DEVICE_PAD_WAKEUP
))
315 pr_debug("%s: Initialized %s\n", __func__
, pad
->name
);
318 if (!nr_pads_dynamic
)
322 * Add pads that need dynamic muxing into a separate list
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__
);
334 for (i
= 0; i
< hmux
->nr_pads
; i
++) {
335 struct omap_device_pad
*pad
= &hmux
->pads
[i
];
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
;
353 pr_err("%s: Could not allocate device mux entry\n", __func__
);
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
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.
369 static bool omap_hwmod_mux_scan_wakeups(struct omap_hwmod_mux_info
*hmux
,
370 struct omap_hwmod_irq_info
*mpu_irqs
)
374 u32 handled_irqs
= 0;
376 for (i
= 0; i
< hmux
->nr_pads_dynamic
; i
++) {
377 struct omap_device_pad
*pad
= hmux
->pads_dynamic
[i
];
379 if (!(pad
->flags
& OMAP_DEVICE_PAD_WAKEUP
) ||
380 !(pad
->idle
& OMAP_WAKEUP_EN
))
383 val
= omap_mux_read(pad
->partition
, pad
->mux
->reg_offset
);
384 if (!(val
& OMAP_WAKEUP_EVENT
))
391 /* make sure we only handle each irq once */
392 if (handled_irqs
& 1 << irq
)
395 handled_irqs
|= 1 << irq
;
397 generic_handle_irq(mpu_irqs
[irq
].irq
);
404 * _omap_hwmod_mux_handle_irq - Process wakeup events for a single hwmod
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.
409 static int _omap_hwmod_mux_handle_irq(struct omap_hwmod
*oh
, void *data
)
411 if (!oh
->mux
|| !oh
->mux
->enabled
)
413 if (omap_hwmod_mux_scan_wakeups(oh
->mux
, oh
->mpu_irqs
))
414 generic_handle_irq(oh
->mpu_irqs
[0].irq
);
419 * omap_hwmod_mux_handle_irq - Process pad wakeup irqs.
421 * Calls a function for each registered omap_hwmod to check
422 * pad wakeup statuses.
424 static irqreturn_t
omap_hwmod_mux_handle_irq(int irq
, void *unused
)
426 omap_hwmod_for_each(_omap_hwmod_mux_handle_irq
, NULL
);
430 /* Assumes the calling function takes care of locking */
431 void omap_hwmod_mux(struct omap_hwmod_mux_info
*hmux
, u8 state
)
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
];
442 omap_mux_write(pad
->partition
, val
,
443 pad
->mux
->reg_offset
);
449 /* Runtime enabling of dynamic pads */
450 if ((state
== _HWMOD_STATE_ENABLED
) && hmux
->pads_dynamic
452 for (i
= 0; i
< hmux
->nr_pads_dynamic
; i
++) {
453 struct omap_device_pad
*pad
= hmux
->pads_dynamic
[i
];
457 omap_mux_write(pad
->partition
, val
,
458 pad
->mux
->reg_offset
);
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
;
472 case _HWMOD_STATE_ENABLED
:
474 pr_debug("%s: Enabling %s %x\n", __func__
,
477 case _HWMOD_STATE_DISABLED
:
478 /* Use safe mode unless OMAP_DEVICE_PAD_REMUX */
479 if (flags
& OMAP_DEVICE_PAD_REMUX
)
482 val
= OMAP_MUX_MODE7
;
483 pr_debug("%s: Disabling %s %x\n", __func__
,
487 /* Nothing to be done */
492 omap_mux_write(pad
->partition
, val
,
493 pad
->mux
->reg_offset
);
498 if (state
== _HWMOD_STATE_ENABLED
)
499 hmux
->enabled
= true;
501 hmux
->enabled
= false;
504 #ifdef CONFIG_DEBUG_FS
506 #define OMAP_MUX_MAX_NR_FLAGS 10
507 #define OMAP_MUX_TEST_FLAG(val, mask) \
508 if (((val) & (mask)) == (mask)) { \
513 /* REVISIT: Add checking for non-optimal mux settings */
514 static inline void omap_mux_decode(struct seq_file
*s
, u16 val
)
516 char *flags
[OMAP_MUX_MAX_NR_FLAGS
];
517 char mode
[sizeof("OMAP_MUX_MODE") + 1];
520 sprintf(mode
, "OMAP_MUX_MODE%d", val
& 0x7);
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
);
531 OMAP_MUX_TEST_FLAG(val
,
532 OMAP_PIN_OFF_INPUT_PULLUP
);
535 if (!(val
& OMAP_OFFOUT_VAL
)) {
536 OMAP_MUX_TEST_FLAG(val
,
537 OMAP_PIN_OFF_OUTPUT_LOW
);
539 OMAP_MUX_TEST_FLAG(val
,
540 OMAP_PIN_OFF_OUTPUT_HIGH
);
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
);
551 OMAP_MUX_TEST_FLAG(val
, OMAP_PIN_INPUT_PULLUP
);
554 OMAP_MUX_TEST_FLAG(val
, OMAP_PIN_INPUT
);
558 flags
[i
] = "OMAP_PIN_OUTPUT";
562 seq_printf(s
, "%s", flags
[i
]);
564 seq_printf(s
, " | ");
568 #define OMAP_MUX_DEFNAME_LEN 32
570 static int omap_mux_dbg_board_show(struct seq_file
*s
, void *unused
)
572 struct omap_mux_partition
*partition
= s
->private;
573 struct omap_mux_entry
*e
;
574 u8 omap_gen
= omap_rev() >> 28;
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];
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
];
592 m0_def
[i
] = toupper(m0_name
[i
]);
594 val
= omap_mux_read(partition
, m
->reg_offset
);
595 mode
= val
& OMAP_MUX_MODE7
;
597 seq_printf(s
, "/* %s */\n", m
->muxnames
[mode
]);
600 * XXX: Might be revisited to support differences across
601 * same OMAP generation.
603 seq_printf(s
, "OMAP%d_MUX(%s, ", omap_gen
, m0_def
);
604 omap_mux_decode(s
, val
);
605 seq_printf(s
, "),\n");
611 static int omap_mux_dbg_board_open(struct inode
*inode
, struct file
*file
)
613 return single_open(file
, omap_mux_dbg_board_show
, inode
->i_private
);
616 static const struct file_operations omap_mux_dbg_board_fops
= {
617 .open
= omap_mux_dbg_board_open
,
620 .release
= single_release
,
623 static struct omap_mux_partition
*omap_mux_get_partition(struct omap_mux
*mux
)
625 struct omap_mux_partition
*partition
;
627 list_for_each_entry(partition
, &mux_partitions
, node
) {
628 struct list_head
*muxmodes
= &partition
->muxmodes
;
629 struct omap_mux_entry
*e
;
631 list_for_each_entry(e
, muxmodes
, node
) {
632 struct omap_mux
*m
= &e
->mux
;
642 static int omap_mux_dbg_signal_show(struct seq_file
*s
, void *unused
)
644 struct omap_mux
*m
= s
->private;
645 struct omap_mux_partition
*partition
;
646 const char *none
= "NA";
650 partition
= omap_mux_get_partition(m
);
654 val
= omap_mux_read(partition
, m
->reg_offset
);
655 mode
= val
& OMAP_MUX_MODE7
;
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
);
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
);
678 #define OMAP_MUX_MAX_ARG_CHAR 7
680 static ssize_t
omap_mux_dbg_signal_write(struct file
*file
,
681 const char __user
*user_buf
,
682 size_t count
, loff_t
*ppos
)
684 struct seq_file
*seqf
;
688 struct omap_mux_partition
*partition
;
690 if (count
> OMAP_MUX_MAX_ARG_CHAR
)
693 ret
= kstrtou16_from_user(user_buf
, count
, 0x10, &val
);
697 seqf
= file
->private_data
;
700 partition
= omap_mux_get_partition(m
);
704 omap_mux_write(partition
, val
, m
->reg_offset
);
710 static int omap_mux_dbg_signal_open(struct inode
*inode
, struct file
*file
)
712 return single_open(file
, omap_mux_dbg_signal_show
, inode
->i_private
);
715 static const struct file_operations omap_mux_dbg_signal_fops
= {
716 .open
= omap_mux_dbg_signal_open
,
718 .write
= omap_mux_dbg_signal_write
,
720 .release
= single_release
,
723 static struct dentry
*mux_dbg_dir
;
725 static void __init
omap_mux_dbg_create_entry(
726 struct omap_mux_partition
*partition
,
727 struct dentry
*mux_dbg_dir
)
729 struct omap_mux_entry
*e
;
731 list_for_each_entry(e
, &partition
->muxmodes
, node
) {
732 struct omap_mux
*m
= &e
->mux
;
734 (void)debugfs_create_file(m
->muxnames
[0], S_IWUSR
| S_IRUGO
,
736 &omap_mux_dbg_signal_fops
);
740 static void __init
omap_mux_dbg_init(void)
742 struct omap_mux_partition
*partition
;
743 static struct dentry
*mux_dbg_board_dir
;
745 mux_dbg_dir
= debugfs_create_dir("omap_mux", NULL
);
749 mux_dbg_board_dir
= debugfs_create_dir("board", mux_dbg_dir
);
750 if (!mux_dbg_board_dir
)
753 list_for_each_entry(partition
, &mux_partitions
, node
) {
754 omap_mux_dbg_create_entry(partition
, mux_dbg_dir
);
755 (void)debugfs_create_file(partition
->name
, S_IRUGO
,
756 mux_dbg_board_dir
, partition
,
757 &omap_mux_dbg_board_fops
);
762 static inline void omap_mux_dbg_init(void)
765 #endif /* CONFIG_DEBUG_FS */
767 static void __init
omap_mux_free_names(struct omap_mux
*m
)
771 for (i
= 0; i
< OMAP_MUX_NR_MODES
; i
++)
772 kfree(m
->muxnames
[i
]);
774 #ifdef CONFIG_DEBUG_FS
775 for (i
= 0; i
< OMAP_MUX_NR_SIDES
; i
++)
781 /* Free all data except for GPIO pins unless CONFIG_DEBUG_FS is set */
782 int __init
omap_mux_late_init(void)
784 struct omap_mux_partition
*partition
;
787 list_for_each_entry(partition
, &mux_partitions
, node
) {
788 struct omap_mux_entry
*e
, *tmp
;
789 list_for_each_entry_safe(e
, tmp
, &partition
->muxmodes
, node
) {
790 struct omap_mux
*m
= &e
->mux
;
791 u16 mode
= omap_mux_read(partition
, m
->reg_offset
);
793 if (OMAP_MODE_GPIO(partition
, mode
))
796 #ifndef CONFIG_DEBUG_FS
797 mutex_lock(&muxmode_mutex
);
799 mutex_unlock(&muxmode_mutex
);
800 omap_mux_free_names(m
);
808 /* see pinctrl-single-omap for the wake-up interrupt handling */
809 if (of_have_populated_dt())
812 ret
= request_irq(omap_prcm_event_to_irq("io"),
813 omap_hwmod_mux_handle_irq
, IRQF_SHARED
| IRQF_NO_SUSPEND
,
814 "hwmod_io", omap_mux_late_init
);
817 pr_warn("mux: Failed to setup hwmod io irq %d\n", ret
);
822 static void __init
omap_mux_package_fixup(struct omap_mux
*p
,
823 struct omap_mux
*superset
)
825 while (p
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
826 struct omap_mux
*s
= superset
;
829 while (s
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
830 if (s
->reg_offset
== p
->reg_offset
) {
838 pr_err("%s: Unknown entry offset 0x%x\n", __func__
,
844 #ifdef CONFIG_DEBUG_FS
846 static void __init
omap_mux_package_init_balls(struct omap_ball
*b
,
847 struct omap_mux
*superset
)
849 while (b
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
850 struct omap_mux
*s
= superset
;
853 while (s
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
854 if (s
->reg_offset
== b
->reg_offset
) {
855 s
->balls
[0] = b
->balls
[0];
856 s
->balls
[1] = b
->balls
[1];
863 pr_err("%s: Unknown ball offset 0x%x\n", __func__
,
869 #else /* CONFIG_DEBUG_FS */
871 static inline void omap_mux_package_init_balls(struct omap_ball
*b
,
872 struct omap_mux
*superset
)
876 #endif /* CONFIG_DEBUG_FS */
878 static int __init
omap_mux_setup(char *options
)
883 omap_mux_options
= options
;
887 __setup("omap_mux=", omap_mux_setup
);
890 * Note that the omap_mux=some.signal1=0x1234,some.signal2=0x1234
891 * cmdline options only override the bootloader values.
892 * During development, please enable CONFIG_DEBUG_FS, and use the
893 * signal specific entries under debugfs.
895 static void __init
omap_mux_set_cmdline_signals(void)
897 char *options
, *next_opt
, *token
;
899 if (!omap_mux_options
)
902 options
= kstrdup(omap_mux_options
, GFP_KERNEL
);
908 while ((token
= strsep(&next_opt
, ",")) != NULL
) {
913 name
= strsep(&keyval
, "=");
917 res
= kstrtou16(keyval
, 0x10, &val
);
921 omap_mux_init_signal(name
, (u16
)val
);
928 static int __init
omap_mux_copy_names(struct omap_mux
*src
,
929 struct omap_mux
*dst
)
933 for (i
= 0; i
< OMAP_MUX_NR_MODES
; i
++) {
934 if (src
->muxnames
[i
]) {
935 dst
->muxnames
[i
] = kstrdup(src
->muxnames
[i
],
937 if (!dst
->muxnames
[i
])
942 #ifdef CONFIG_DEBUG_FS
943 for (i
= 0; i
< OMAP_MUX_NR_SIDES
; i
++) {
945 dst
->balls
[i
] = kstrdup(src
->balls
[i
], GFP_KERNEL
);
955 omap_mux_free_names(dst
);
960 #endif /* CONFIG_OMAP_MUX */
962 static struct omap_mux
*omap_mux_get_by_gpio(
963 struct omap_mux_partition
*partition
,
966 struct omap_mux_entry
*e
;
967 struct omap_mux
*ret
= NULL
;
969 list_for_each_entry(e
, &partition
->muxmodes
, node
) {
970 struct omap_mux
*m
= &e
->mux
;
971 if (m
->gpio
== gpio
) {
980 /* Needed for dynamic muxing of GPIO pins for off-idle */
981 u16
omap_mux_get_gpio(int gpio
)
983 struct omap_mux_partition
*partition
;
984 struct omap_mux
*m
= NULL
;
986 list_for_each_entry(partition
, &mux_partitions
, node
) {
987 m
= omap_mux_get_by_gpio(partition
, gpio
);
989 return omap_mux_read(partition
, m
->reg_offset
);
992 if (!m
|| m
->reg_offset
== OMAP_MUX_TERMINATOR
)
993 pr_err("%s: Could not get gpio%i\n", __func__
, gpio
);
995 return OMAP_MUX_TERMINATOR
;
998 /* Needed for dynamic muxing of GPIO pins for off-idle */
999 void omap_mux_set_gpio(u16 val
, int gpio
)
1001 struct omap_mux_partition
*partition
;
1002 struct omap_mux
*m
= NULL
;
1004 list_for_each_entry(partition
, &mux_partitions
, node
) {
1005 m
= omap_mux_get_by_gpio(partition
, gpio
);
1007 omap_mux_write(partition
, val
, m
->reg_offset
);
1012 if (!m
|| m
->reg_offset
== OMAP_MUX_TERMINATOR
)
1013 pr_err("%s: Could not set gpio%i\n", __func__
, gpio
);
1016 static struct omap_mux
* __init
omap_mux_list_add(
1017 struct omap_mux_partition
*partition
,
1018 struct omap_mux
*src
)
1020 struct omap_mux_entry
*entry
;
1023 entry
= kzalloc(sizeof(struct omap_mux_entry
), GFP_KERNEL
);
1030 #ifdef CONFIG_OMAP_MUX
1031 if (omap_mux_copy_names(src
, m
)) {
1037 mutex_lock(&muxmode_mutex
);
1038 list_add_tail(&entry
->node
, &partition
->muxmodes
);
1039 mutex_unlock(&muxmode_mutex
);
1045 * Note if CONFIG_OMAP_MUX is not selected, we will only initialize
1046 * the GPIO to mux offset mapping that is needed for dynamic muxing
1047 * of GPIO pins for off-idle.
1049 static void __init
omap_mux_init_list(struct omap_mux_partition
*partition
,
1050 struct omap_mux
*superset
)
1052 while (superset
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
1053 struct omap_mux
*entry
;
1055 #ifdef CONFIG_OMAP_MUX
1056 if (!superset
->muxnames
|| !superset
->muxnames
[0]) {
1061 /* Skip pins that are not muxed as GPIO by bootloader */
1062 if (!OMAP_MODE_GPIO(partition
, omap_mux_read(partition
,
1063 superset
->reg_offset
))) {
1069 entry
= omap_mux_list_add(partition
, superset
);
1071 pr_err("%s: Could not add entry\n", __func__
);
1078 #ifdef CONFIG_OMAP_MUX
1080 static void omap_mux_init_package(struct omap_mux
*superset
,
1081 struct omap_mux
*package_subset
,
1082 struct omap_ball
*package_balls
)
1085 omap_mux_package_fixup(package_subset
, superset
);
1087 omap_mux_package_init_balls(package_balls
, superset
);
1090 static void __init
omap_mux_init_signals(struct omap_mux_partition
*partition
,
1091 struct omap_board_mux
*board_mux
)
1093 omap_mux_set_cmdline_signals();
1094 omap_mux_write_array(partition
, board_mux
);
1099 static void omap_mux_init_package(struct omap_mux
*superset
,
1100 struct omap_mux
*package_subset
,
1101 struct omap_ball
*package_balls
)
1105 static void __init
omap_mux_init_signals(struct omap_mux_partition
*partition
,
1106 struct omap_board_mux
*board_mux
)
1112 static u32 mux_partitions_cnt
;
1114 int __init
omap_mux_init(const char *name
, u32 flags
,
1115 u32 mux_pbase
, u32 mux_size
,
1116 struct omap_mux
*superset
,
1117 struct omap_mux
*package_subset
,
1118 struct omap_board_mux
*board_mux
,
1119 struct omap_ball
*package_balls
)
1121 struct omap_mux_partition
*partition
;
1123 partition
= kzalloc(sizeof(struct omap_mux_partition
), GFP_KERNEL
);
1127 partition
->name
= name
;
1128 partition
->flags
= flags
;
1129 partition
->gpio
= flags
& OMAP_MUX_MODE7
;
1130 partition
->size
= mux_size
;
1131 partition
->phys
= mux_pbase
;
1132 partition
->base
= ioremap(mux_pbase
, mux_size
);
1133 if (!partition
->base
) {
1134 pr_err("%s: Could not ioremap mux partition at 0x%08x\n",
1135 __func__
, partition
->phys
);
1140 INIT_LIST_HEAD(&partition
->muxmodes
);
1142 list_add_tail(&partition
->node
, &mux_partitions
);
1143 mux_partitions_cnt
++;
1144 pr_info("%s: Add partition: #%d: %s, flags: %x\n", __func__
,
1145 mux_partitions_cnt
, partition
->name
, partition
->flags
);
1147 omap_mux_init_package(superset
, package_subset
, package_balls
);
1148 omap_mux_init_list(partition
, superset
);
1149 omap_mux_init_signals(partition
, board_mux
);