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 __raw_readb(partition
->base
+ reg
);
75 return __raw_readw(partition
->base
+ reg
);
78 void omap_mux_write(struct omap_mux_partition
*partition
, u16 val
,
81 if (partition
->flags
& OMAP_MUX_REG_8BIT
)
82 __raw_writeb(val
, partition
->base
+ reg
);
84 __raw_writew(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 */
186 if (mode0_len
&& strncmp(muxname
, m0_entry
, mode0_len
))
189 /* Then check for muxmode only */
190 for (i
= 0; i
< OMAP_MUX_NR_MODES
; i
++) {
191 char *mode_cur
= mux
->muxnames
[i
];
196 if (!strcmp(mode_name
, mode_cur
)) {
209 pr_err("%s: Multiple signal paths (%i) for %s\n", __func__
,
217 int __init
omap_mux_get_by_name(const char *muxname
,
218 struct omap_mux_partition
**found_partition
,
219 struct omap_mux
**found_mux
)
221 struct omap_mux_partition
*partition
;
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
);
229 *found_partition
= partition
;
235 pr_err("%s: Could not find signal %s\n", __func__
, muxname
);
240 int __init
omap_mux_init_signal(const char *muxname
, int val
)
242 struct omap_mux_partition
*partition
= NULL
;
243 struct omap_mux
*mux
= NULL
;
247 mux_mode
= omap_mux_get_by_name(muxname
, &partition
, &mux
);
248 if (mux_mode
< 0 || !mux
)
251 old_mode
= omap_mux_read(partition
, mux
->reg_offset
);
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
);
260 struct omap_hwmod_mux_info
* __init
261 omap_hwmod_mux_init(struct omap_device_pad
*bpads
, int nr_pads
)
263 struct omap_hwmod_mux_info
*hmux
;
264 int i
, nr_pads_dynamic
= 0;
266 if (!bpads
|| nr_pads
< 1)
269 hmux
= kzalloc(sizeof(struct omap_hwmod_mux_info
), GFP_KERNEL
);
273 hmux
->nr_pads
= nr_pads
;
275 hmux
->pads
= kzalloc(sizeof(struct omap_device_pad
) *
276 nr_pads
, GFP_KERNEL
);
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
;
286 mux_mode
= omap_mux_get_by_name(bpad
->name
, &partition
, &mux
);
290 pad
->partition
= partition
;
294 pad
->name
= kzalloc(strlen(bpad
->name
) + 1, GFP_KERNEL
);
298 for (j
= i
- 1; j
>= 0; j
--)
299 kfree(hmux
->pads
[j
].name
);
302 strcpy(pad
->name
, bpad
->name
);
304 pad
->flags
= bpad
->flags
;
305 pad
->enable
= bpad
->enable
;
306 pad
->idle
= bpad
->idle
;
307 pad
->off
= bpad
->off
;
310 (OMAP_DEVICE_PAD_REMUX
| OMAP_DEVICE_PAD_WAKEUP
))
313 pr_debug("%s: Initialized %s\n", __func__
, pad
->name
);
316 if (!nr_pads_dynamic
)
320 * Add pads that need dynamic muxing into a separate list
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__
);
332 for (i
= 0; i
< hmux
->nr_pads
; i
++) {
333 struct omap_device_pad
*pad
= &hmux
->pads
[i
];
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
;
351 pr_err("%s: Could not allocate device mux entry\n", __func__
);
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
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.
367 static bool omap_hwmod_mux_scan_wakeups(struct omap_hwmod_mux_info
*hmux
,
368 struct omap_hwmod_irq_info
*mpu_irqs
)
372 u32 handled_irqs
= 0;
374 for (i
= 0; i
< hmux
->nr_pads_dynamic
; i
++) {
375 struct omap_device_pad
*pad
= hmux
->pads_dynamic
[i
];
377 if (!(pad
->flags
& OMAP_DEVICE_PAD_WAKEUP
) ||
378 !(pad
->idle
& OMAP_WAKEUP_EN
))
381 val
= omap_mux_read(pad
->partition
, pad
->mux
->reg_offset
);
382 if (!(val
& OMAP_WAKEUP_EVENT
))
389 /* make sure we only handle each irq once */
390 if (handled_irqs
& 1 << irq
)
393 handled_irqs
|= 1 << irq
;
395 generic_handle_irq(mpu_irqs
[irq
].irq
);
402 * _omap_hwmod_mux_handle_irq - Process wakeup events for a single hwmod
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.
407 static int _omap_hwmod_mux_handle_irq(struct omap_hwmod
*oh
, void *data
)
409 if (!oh
->mux
|| !oh
->mux
->enabled
)
411 if (omap_hwmod_mux_scan_wakeups(oh
->mux
, oh
->mpu_irqs
))
412 generic_handle_irq(oh
->mpu_irqs
[0].irq
);
417 * omap_hwmod_mux_handle_irq - Process pad wakeup irqs.
419 * Calls a function for each registered omap_hwmod to check
420 * pad wakeup statuses.
422 static irqreturn_t
omap_hwmod_mux_handle_irq(int irq
, void *unused
)
424 omap_hwmod_for_each(_omap_hwmod_mux_handle_irq
, NULL
);
428 /* Assumes the calling function takes care of locking */
429 void omap_hwmod_mux(struct omap_hwmod_mux_info
*hmux
, u8 state
)
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
];
440 omap_mux_write(pad
->partition
, val
,
441 pad
->mux
->reg_offset
);
447 /* Runtime enabling of dynamic pads */
448 if ((state
== _HWMOD_STATE_ENABLED
) && hmux
->pads_dynamic
450 for (i
= 0; i
< hmux
->nr_pads_dynamic
; i
++) {
451 struct omap_device_pad
*pad
= hmux
->pads_dynamic
[i
];
455 omap_mux_write(pad
->partition
, val
,
456 pad
->mux
->reg_offset
);
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
;
470 case _HWMOD_STATE_ENABLED
:
472 pr_debug("%s: Enabling %s %x\n", __func__
,
475 case _HWMOD_STATE_DISABLED
:
476 /* Use safe mode unless OMAP_DEVICE_PAD_REMUX */
477 if (flags
& OMAP_DEVICE_PAD_REMUX
)
480 val
= OMAP_MUX_MODE7
;
481 pr_debug("%s: Disabling %s %x\n", __func__
,
485 /* Nothing to be done */
490 omap_mux_write(pad
->partition
, val
,
491 pad
->mux
->reg_offset
);
496 if (state
== _HWMOD_STATE_ENABLED
)
497 hmux
->enabled
= true;
499 hmux
->enabled
= false;
502 #ifdef CONFIG_DEBUG_FS
504 #define OMAP_MUX_MAX_NR_FLAGS 10
505 #define OMAP_MUX_TEST_FLAG(val, mask) \
506 if (((val) & (mask)) == (mask)) { \
511 /* REVISIT: Add checking for non-optimal mux settings */
512 static inline void omap_mux_decode(struct seq_file
*s
, u16 val
)
514 char *flags
[OMAP_MUX_MAX_NR_FLAGS
];
515 char mode
[sizeof("OMAP_MUX_MODE") + 1];
518 sprintf(mode
, "OMAP_MUX_MODE%d", val
& 0x7);
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
);
529 OMAP_MUX_TEST_FLAG(val
,
530 OMAP_PIN_OFF_INPUT_PULLUP
);
533 if (!(val
& OMAP_OFFOUT_VAL
)) {
534 OMAP_MUX_TEST_FLAG(val
,
535 OMAP_PIN_OFF_OUTPUT_LOW
);
537 OMAP_MUX_TEST_FLAG(val
,
538 OMAP_PIN_OFF_OUTPUT_HIGH
);
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
);
549 OMAP_MUX_TEST_FLAG(val
, OMAP_PIN_INPUT_PULLUP
);
552 OMAP_MUX_TEST_FLAG(val
, OMAP_PIN_INPUT
);
556 flags
[i
] = "OMAP_PIN_OUTPUT";
560 seq_printf(s
, "%s", flags
[i
]);
562 seq_printf(s
, " | ");
566 #define OMAP_MUX_DEFNAME_LEN 32
568 static int omap_mux_dbg_board_show(struct seq_file
*s
, void *unused
)
570 struct omap_mux_partition
*partition
= s
->private;
571 struct omap_mux_entry
*e
;
572 u8 omap_gen
= omap_rev() >> 28;
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];
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
];
590 m0_def
[i
] = toupper(m0_name
[i
]);
592 val
= omap_mux_read(partition
, m
->reg_offset
);
593 mode
= val
& OMAP_MUX_MODE7
;
595 seq_printf(s
, "/* %s */\n", m
->muxnames
[mode
]);
598 * XXX: Might be revisited to support differences across
599 * same OMAP generation.
601 seq_printf(s
, "OMAP%d_MUX(%s, ", omap_gen
, m0_def
);
602 omap_mux_decode(s
, val
);
603 seq_printf(s
, "),\n");
609 static int omap_mux_dbg_board_open(struct inode
*inode
, struct file
*file
)
611 return single_open(file
, omap_mux_dbg_board_show
, inode
->i_private
);
614 static const struct file_operations omap_mux_dbg_board_fops
= {
615 .open
= omap_mux_dbg_board_open
,
618 .release
= single_release
,
621 static struct omap_mux_partition
*omap_mux_get_partition(struct omap_mux
*mux
)
623 struct omap_mux_partition
*partition
;
625 list_for_each_entry(partition
, &mux_partitions
, node
) {
626 struct list_head
*muxmodes
= &partition
->muxmodes
;
627 struct omap_mux_entry
*e
;
629 list_for_each_entry(e
, muxmodes
, node
) {
630 struct omap_mux
*m
= &e
->mux
;
640 static int omap_mux_dbg_signal_show(struct seq_file
*s
, void *unused
)
642 struct omap_mux
*m
= s
->private;
643 struct omap_mux_partition
*partition
;
644 const char *none
= "NA";
648 partition
= omap_mux_get_partition(m
);
652 val
= omap_mux_read(partition
, m
->reg_offset
);
653 mode
= val
& OMAP_MUX_MODE7
;
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
);
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
);
676 #define OMAP_MUX_MAX_ARG_CHAR 7
678 static ssize_t
omap_mux_dbg_signal_write(struct file
*file
,
679 const char __user
*user_buf
,
680 size_t count
, loff_t
*ppos
)
682 char buf
[OMAP_MUX_MAX_ARG_CHAR
];
683 struct seq_file
*seqf
;
687 struct omap_mux_partition
*partition
;
689 if (count
> OMAP_MUX_MAX_ARG_CHAR
)
692 memset(buf
, 0, sizeof(buf
));
693 buf_size
= min(count
, sizeof(buf
) - 1);
695 if (copy_from_user(buf
, user_buf
, buf_size
))
698 ret
= strict_strtoul(buf
, 0x10, &val
);
705 seqf
= file
->private_data
;
708 partition
= omap_mux_get_partition(m
);
712 omap_mux_write(partition
, (u16
)val
, m
->reg_offset
);
718 static int omap_mux_dbg_signal_open(struct inode
*inode
, struct file
*file
)
720 return single_open(file
, omap_mux_dbg_signal_show
, inode
->i_private
);
723 static const struct file_operations omap_mux_dbg_signal_fops
= {
724 .open
= omap_mux_dbg_signal_open
,
726 .write
= omap_mux_dbg_signal_write
,
728 .release
= single_release
,
731 static struct dentry
*mux_dbg_dir
;
733 static void __init
omap_mux_dbg_create_entry(
734 struct omap_mux_partition
*partition
,
735 struct dentry
*mux_dbg_dir
)
737 struct omap_mux_entry
*e
;
739 list_for_each_entry(e
, &partition
->muxmodes
, node
) {
740 struct omap_mux
*m
= &e
->mux
;
742 (void)debugfs_create_file(m
->muxnames
[0], S_IWUSR
| S_IRUGO
,
744 &omap_mux_dbg_signal_fops
);
748 static void __init
omap_mux_dbg_init(void)
750 struct omap_mux_partition
*partition
;
751 static struct dentry
*mux_dbg_board_dir
;
753 mux_dbg_dir
= debugfs_create_dir("omap_mux", NULL
);
757 mux_dbg_board_dir
= debugfs_create_dir("board", mux_dbg_dir
);
758 if (!mux_dbg_board_dir
)
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
);
770 static inline void omap_mux_dbg_init(void)
773 #endif /* CONFIG_DEBUG_FS */
775 static void __init
omap_mux_free_names(struct omap_mux
*m
)
779 for (i
= 0; i
< OMAP_MUX_NR_MODES
; i
++)
780 kfree(m
->muxnames
[i
]);
782 #ifdef CONFIG_DEBUG_FS
783 for (i
= 0; i
< OMAP_MUX_NR_SIDES
; i
++)
789 /* Free all data except for GPIO pins unless CONFIG_DEBUG_FS is set */
790 int __init
omap_mux_late_init(void)
792 struct omap_mux_partition
*partition
;
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
);
801 if (OMAP_MODE_GPIO(partition
, mode
))
804 #ifndef CONFIG_DEBUG_FS
805 mutex_lock(&muxmode_mutex
);
807 mutex_unlock(&muxmode_mutex
);
808 omap_mux_free_names(m
);
816 /* see pinctrl-single-omap for the wake-up interrupt handling */
817 if (of_have_populated_dt())
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
);
825 pr_warning("mux: Failed to setup hwmod io irq %d\n", ret
);
830 static void __init
omap_mux_package_fixup(struct omap_mux
*p
,
831 struct omap_mux
*superset
)
833 while (p
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
834 struct omap_mux
*s
= superset
;
837 while (s
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
838 if (s
->reg_offset
== p
->reg_offset
) {
846 pr_err("%s: Unknown entry offset 0x%x\n", __func__
,
852 #ifdef CONFIG_DEBUG_FS
854 static void __init
omap_mux_package_init_balls(struct omap_ball
*b
,
855 struct omap_mux
*superset
)
857 while (b
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
858 struct omap_mux
*s
= superset
;
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];
871 pr_err("%s: Unknown ball offset 0x%x\n", __func__
,
877 #else /* CONFIG_DEBUG_FS */
879 static inline void omap_mux_package_init_balls(struct omap_ball
*b
,
880 struct omap_mux
*superset
)
884 #endif /* CONFIG_DEBUG_FS */
886 static int __init
omap_mux_setup(char *options
)
891 omap_mux_options
= options
;
895 __setup("omap_mux=", omap_mux_setup
);
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.
903 static void __init
omap_mux_set_cmdline_signals(void)
905 char *options
, *next_opt
, *token
;
907 if (!omap_mux_options
)
910 options
= kstrdup(omap_mux_options
, GFP_KERNEL
);
916 while ((token
= strsep(&next_opt
, ",")) != NULL
) {
921 name
= strsep(&keyval
, "=");
925 res
= strict_strtoul(keyval
, 0x10, &val
);
929 omap_mux_init_signal(name
, (u16
)val
);
936 static int __init
omap_mux_copy_names(struct omap_mux
*src
,
937 struct omap_mux
*dst
)
941 for (i
= 0; i
< OMAP_MUX_NR_MODES
; i
++) {
942 if (src
->muxnames
[i
]) {
943 dst
->muxnames
[i
] = kstrdup(src
->muxnames
[i
],
945 if (!dst
->muxnames
[i
])
950 #ifdef CONFIG_DEBUG_FS
951 for (i
= 0; i
< OMAP_MUX_NR_SIDES
; i
++) {
953 dst
->balls
[i
] = kstrdup(src
->balls
[i
], GFP_KERNEL
);
963 omap_mux_free_names(dst
);
968 #endif /* CONFIG_OMAP_MUX */
970 static struct omap_mux
*omap_mux_get_by_gpio(
971 struct omap_mux_partition
*partition
,
974 struct omap_mux_entry
*e
;
975 struct omap_mux
*ret
= NULL
;
977 list_for_each_entry(e
, &partition
->muxmodes
, node
) {
978 struct omap_mux
*m
= &e
->mux
;
979 if (m
->gpio
== gpio
) {
988 /* Needed for dynamic muxing of GPIO pins for off-idle */
989 u16
omap_mux_get_gpio(int gpio
)
991 struct omap_mux_partition
*partition
;
992 struct omap_mux
*m
= NULL
;
994 list_for_each_entry(partition
, &mux_partitions
, node
) {
995 m
= omap_mux_get_by_gpio(partition
, gpio
);
997 return omap_mux_read(partition
, m
->reg_offset
);
1000 if (!m
|| m
->reg_offset
== OMAP_MUX_TERMINATOR
)
1001 pr_err("%s: Could not get gpio%i\n", __func__
, gpio
);
1003 return OMAP_MUX_TERMINATOR
;
1006 /* Needed for dynamic muxing of GPIO pins for off-idle */
1007 void omap_mux_set_gpio(u16 val
, int gpio
)
1009 struct omap_mux_partition
*partition
;
1010 struct omap_mux
*m
= NULL
;
1012 list_for_each_entry(partition
, &mux_partitions
, node
) {
1013 m
= omap_mux_get_by_gpio(partition
, gpio
);
1015 omap_mux_write(partition
, val
, m
->reg_offset
);
1020 if (!m
|| m
->reg_offset
== OMAP_MUX_TERMINATOR
)
1021 pr_err("%s: Could not set gpio%i\n", __func__
, gpio
);
1024 static struct omap_mux
* __init
omap_mux_list_add(
1025 struct omap_mux_partition
*partition
,
1026 struct omap_mux
*src
)
1028 struct omap_mux_entry
*entry
;
1031 entry
= kzalloc(sizeof(struct omap_mux_entry
), GFP_KERNEL
);
1038 #ifdef CONFIG_OMAP_MUX
1039 if (omap_mux_copy_names(src
, m
)) {
1045 mutex_lock(&muxmode_mutex
);
1046 list_add_tail(&entry
->node
, &partition
->muxmodes
);
1047 mutex_unlock(&muxmode_mutex
);
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.
1057 static void __init
omap_mux_init_list(struct omap_mux_partition
*partition
,
1058 struct omap_mux
*superset
)
1060 while (superset
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
1061 struct omap_mux
*entry
;
1063 #ifdef CONFIG_OMAP_MUX
1064 if (!superset
->muxnames
|| !superset
->muxnames
[0]) {
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
))) {
1077 entry
= omap_mux_list_add(partition
, superset
);
1079 pr_err("%s: Could not add entry\n", __func__
);
1086 #ifdef CONFIG_OMAP_MUX
1088 static void omap_mux_init_package(struct omap_mux
*superset
,
1089 struct omap_mux
*package_subset
,
1090 struct omap_ball
*package_balls
)
1093 omap_mux_package_fixup(package_subset
, superset
);
1095 omap_mux_package_init_balls(package_balls
, superset
);
1098 static void __init
omap_mux_init_signals(struct omap_mux_partition
*partition
,
1099 struct omap_board_mux
*board_mux
)
1101 omap_mux_set_cmdline_signals();
1102 omap_mux_write_array(partition
, board_mux
);
1107 static void omap_mux_init_package(struct omap_mux
*superset
,
1108 struct omap_mux
*package_subset
,
1109 struct omap_ball
*package_balls
)
1113 static void __init
omap_mux_init_signals(struct omap_mux_partition
*partition
,
1114 struct omap_board_mux
*board_mux
)
1120 static u32 mux_partitions_cnt
;
1122 int __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
)
1129 struct omap_mux_partition
*partition
;
1131 partition
= kzalloc(sizeof(struct omap_mux_partition
), GFP_KERNEL
);
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
);
1148 INIT_LIST_HEAD(&partition
->muxmodes
);
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
);
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
);