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>
36 #include <asm/system.h>
38 #include <plat/omap_hwmod.h>
43 #define OMAP_MUX_BASE_OFFSET 0x30 /* Offset from CTRL_BASE */
44 #define OMAP_MUX_BASE_SZ 0x5ca
46 struct omap_mux_entry
{
48 struct list_head node
;
51 static LIST_HEAD(mux_partitions
);
52 static DEFINE_MUTEX(muxmode_mutex
);
54 struct omap_mux_partition
*omap_mux_get(const char *name
)
56 struct omap_mux_partition
*partition
;
58 list_for_each_entry(partition
, &mux_partitions
, node
) {
59 if (!strcmp(name
, partition
->name
))
66 u16
omap_mux_read(struct omap_mux_partition
*partition
, u16 reg
)
68 if (partition
->flags
& OMAP_MUX_REG_8BIT
)
69 return __raw_readb(partition
->base
+ reg
);
71 return __raw_readw(partition
->base
+ reg
);
74 void omap_mux_write(struct omap_mux_partition
*partition
, u16 val
,
77 if (partition
->flags
& OMAP_MUX_REG_8BIT
)
78 __raw_writeb(val
, partition
->base
+ reg
);
80 __raw_writew(val
, partition
->base
+ reg
);
83 void omap_mux_write_array(struct omap_mux_partition
*partition
,
84 struct omap_board_mux
*board_mux
)
86 while (board_mux
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
87 omap_mux_write(partition
, board_mux
->value
,
88 board_mux
->reg_offset
);
93 #ifdef CONFIG_OMAP_MUX
95 static char *omap_mux_options
;
97 static int __init
_omap_mux_init_gpio(struct omap_mux_partition
*partition
,
100 struct omap_mux_entry
*e
;
101 struct omap_mux
*gpio_mux
= NULL
;
105 struct list_head
*muxmodes
= &partition
->muxmodes
;
110 list_for_each_entry(e
, muxmodes
, node
) {
111 struct omap_mux
*m
= &e
->mux
;
112 if (gpio
== m
->gpio
) {
119 pr_err("%s: Could not set gpio%i\n", __func__
, gpio
);
124 pr_info("%s: Multiple gpio paths (%d) for gpio%i\n", __func__
,
129 old_mode
= omap_mux_read(partition
, gpio_mux
->reg_offset
);
130 mux_mode
= val
& ~(OMAP_MUX_NR_MODES
- 1);
131 if (partition
->flags
& OMAP_MUX_GPIO_IN_MODE3
)
132 mux_mode
|= OMAP_MUX_MODE3
;
134 mux_mode
|= OMAP_MUX_MODE4
;
135 pr_debug("%s: Setting signal %s.gpio%i 0x%04x -> 0x%04x\n", __func__
,
136 gpio_mux
->muxnames
[0], gpio
, old_mode
, mux_mode
);
137 omap_mux_write(partition
, mux_mode
, gpio_mux
->reg_offset
);
142 int __init
omap_mux_init_gpio(int gpio
, int val
)
144 struct omap_mux_partition
*partition
;
147 list_for_each_entry(partition
, &mux_partitions
, node
) {
148 ret
= _omap_mux_init_gpio(partition
, gpio
, val
);
156 static int __init
_omap_mux_get_by_name(struct omap_mux_partition
*partition
,
158 struct omap_mux
**found_mux
)
160 struct omap_mux
*mux
= NULL
;
161 struct omap_mux_entry
*e
;
162 const char *mode_name
;
163 int found
= 0, found_mode
= 0, mode0_len
= 0;
164 struct list_head
*muxmodes
= &partition
->muxmodes
;
166 mode_name
= strchr(muxname
, '.');
168 mode0_len
= strlen(muxname
) - strlen(mode_name
);
174 list_for_each_entry(e
, muxmodes
, node
) {
179 m0_entry
= mux
->muxnames
[0];
181 /* First check for full name in mode0.muxmode format */
182 if (mode0_len
&& strncmp(muxname
, m0_entry
, mode0_len
))
185 /* Then check for muxmode only */
186 for (i
= 0; i
< OMAP_MUX_NR_MODES
; i
++) {
187 char *mode_cur
= mux
->muxnames
[i
];
192 if (!strcmp(mode_name
, mode_cur
)) {
205 pr_err("%s: Multiple signal paths (%i) for %s\n", __func__
,
210 pr_err("%s: Could not find signal %s\n", __func__
, muxname
);
216 omap_mux_get_by_name(const char *muxname
,
217 struct omap_mux_partition
**found_partition
,
218 struct omap_mux
**found_mux
)
220 struct omap_mux_partition
*partition
;
222 list_for_each_entry(partition
, &mux_partitions
, node
) {
223 struct omap_mux
*mux
= NULL
;
224 int mux_mode
= _omap_mux_get_by_name(partition
, muxname
, &mux
);
228 *found_partition
= partition
;
237 int __init
omap_mux_init_signal(const char *muxname
, int val
)
239 struct omap_mux_partition
*partition
= NULL
;
240 struct omap_mux
*mux
= NULL
;
244 mux_mode
= omap_mux_get_by_name(muxname
, &partition
, &mux
);
248 old_mode
= omap_mux_read(partition
, mux
->reg_offset
);
250 pr_debug("%s: Setting signal %s 0x%04x -> 0x%04x\n",
251 __func__
, muxname
, old_mode
, mux_mode
);
252 omap_mux_write(partition
, mux_mode
, mux
->reg_offset
);
257 struct omap_hwmod_mux_info
* __init
258 omap_hwmod_mux_init(struct omap_device_pad
*bpads
, int nr_pads
)
260 struct omap_hwmod_mux_info
*hmux
;
261 int i
, nr_pads_dynamic
= 0;
263 if (!bpads
|| nr_pads
< 1)
266 hmux
= kzalloc(sizeof(struct omap_hwmod_mux_info
), GFP_KERNEL
);
270 hmux
->nr_pads
= nr_pads
;
272 hmux
->pads
= kzalloc(sizeof(struct omap_device_pad
) *
273 nr_pads
, GFP_KERNEL
);
277 for (i
= 0; i
< hmux
->nr_pads
; i
++) {
278 struct omap_mux_partition
*partition
;
279 struct omap_device_pad
*bpad
= &bpads
[i
], *pad
= &hmux
->pads
[i
];
280 struct omap_mux
*mux
;
283 mux_mode
= omap_mux_get_by_name(bpad
->name
, &partition
, &mux
);
287 pad
->partition
= partition
;
291 pad
->name
= kzalloc(strlen(bpad
->name
) + 1, GFP_KERNEL
);
295 for (j
= i
- 1; j
>= 0; j
--)
296 kfree(hmux
->pads
[j
].name
);
299 strcpy(pad
->name
, bpad
->name
);
301 pad
->flags
= bpad
->flags
;
302 pad
->enable
= bpad
->enable
;
303 pad
->idle
= bpad
->idle
;
304 pad
->off
= bpad
->off
;
306 if (pad
->flags
& OMAP_DEVICE_PAD_REMUX
)
309 pr_debug("%s: Initialized %s\n", __func__
, pad
->name
);
312 if (!nr_pads_dynamic
)
316 * Add pads that need dynamic muxing into a separate list
319 hmux
->nr_pads_dynamic
= nr_pads_dynamic
;
320 hmux
->pads_dynamic
= kzalloc(sizeof(struct omap_device_pad
*) *
321 nr_pads_dynamic
, GFP_KERNEL
);
322 if (!hmux
->pads_dynamic
) {
323 pr_err("%s: Could not allocate dynamic pads\n", __func__
);
328 for (i
= 0; i
< hmux
->nr_pads
; i
++) {
329 struct omap_device_pad
*pad
= &hmux
->pads
[i
];
331 if (pad
->flags
& OMAP_DEVICE_PAD_REMUX
) {
332 pr_debug("%s: pad %s tagged dynamic\n",
333 __func__
, pad
->name
);
334 hmux
->pads_dynamic
[nr_pads_dynamic
] = pad
;
346 pr_err("%s: Could not allocate device mux entry\n", __func__
);
351 /* Assumes the calling function takes care of locking */
352 void omap_hwmod_mux(struct omap_hwmod_mux_info
*hmux
, u8 state
)
356 /* Runtime idling of dynamic pads */
357 if (state
== _HWMOD_STATE_IDLE
&& hmux
->enabled
) {
358 for (i
= 0; i
< hmux
->nr_pads_dynamic
; i
++) {
359 struct omap_device_pad
*pad
= hmux
->pads_dynamic
[i
];
363 omap_mux_write(pad
->partition
, val
,
364 pad
->mux
->reg_offset
);
370 /* Runtime enabling of dynamic pads */
371 if ((state
== _HWMOD_STATE_ENABLED
) && hmux
->pads_dynamic
373 for (i
= 0; i
< hmux
->nr_pads_dynamic
; i
++) {
374 struct omap_device_pad
*pad
= hmux
->pads_dynamic
[i
];
378 omap_mux_write(pad
->partition
, val
,
379 pad
->mux
->reg_offset
);
385 /* Enabling or disabling of all pads */
386 for (i
= 0; i
< hmux
->nr_pads
; i
++) {
387 struct omap_device_pad
*pad
= &hmux
->pads
[i
];
388 int flags
, val
= -EINVAL
;
393 case _HWMOD_STATE_ENABLED
:
395 pr_debug("%s: Enabling %s %x\n", __func__
,
398 case _HWMOD_STATE_DISABLED
:
399 /* Use safe mode unless OMAP_DEVICE_PAD_REMUX */
400 if (flags
& OMAP_DEVICE_PAD_REMUX
)
403 val
= OMAP_MUX_MODE7
;
404 pr_debug("%s: Disabling %s %x\n", __func__
,
408 /* Nothing to be done */
413 omap_mux_write(pad
->partition
, val
,
414 pad
->mux
->reg_offset
);
419 if (state
== _HWMOD_STATE_ENABLED
)
420 hmux
->enabled
= true;
422 hmux
->enabled
= false;
425 #ifdef CONFIG_DEBUG_FS
427 #define OMAP_MUX_MAX_NR_FLAGS 10
428 #define OMAP_MUX_TEST_FLAG(val, mask) \
429 if (((val) & (mask)) == (mask)) { \
434 /* REVISIT: Add checking for non-optimal mux settings */
435 static inline void omap_mux_decode(struct seq_file
*s
, u16 val
)
437 char *flags
[OMAP_MUX_MAX_NR_FLAGS
];
438 char mode
[sizeof("OMAP_MUX_MODE") + 1];
441 sprintf(mode
, "OMAP_MUX_MODE%d", val
& 0x7);
445 OMAP_MUX_TEST_FLAG(val
, OMAP_PIN_OFF_WAKEUPENABLE
);
446 if (val
& OMAP_OFF_EN
) {
447 if (!(val
& OMAP_OFFOUT_EN
)) {
448 if (!(val
& OMAP_OFF_PULL_UP
)) {
449 OMAP_MUX_TEST_FLAG(val
,
450 OMAP_PIN_OFF_INPUT_PULLDOWN
);
452 OMAP_MUX_TEST_FLAG(val
,
453 OMAP_PIN_OFF_INPUT_PULLUP
);
456 if (!(val
& OMAP_OFFOUT_VAL
)) {
457 OMAP_MUX_TEST_FLAG(val
,
458 OMAP_PIN_OFF_OUTPUT_LOW
);
460 OMAP_MUX_TEST_FLAG(val
,
461 OMAP_PIN_OFF_OUTPUT_HIGH
);
466 if (val
& OMAP_INPUT_EN
) {
467 if (val
& OMAP_PULL_ENA
) {
468 if (!(val
& OMAP_PULL_UP
)) {
469 OMAP_MUX_TEST_FLAG(val
,
470 OMAP_PIN_INPUT_PULLDOWN
);
472 OMAP_MUX_TEST_FLAG(val
, OMAP_PIN_INPUT_PULLUP
);
475 OMAP_MUX_TEST_FLAG(val
, OMAP_PIN_INPUT
);
479 flags
[i
] = "OMAP_PIN_OUTPUT";
483 seq_printf(s
, "%s", flags
[i
]);
485 seq_printf(s
, " | ");
489 #define OMAP_MUX_DEFNAME_LEN 32
491 static int omap_mux_dbg_board_show(struct seq_file
*s
, void *unused
)
493 struct omap_mux_partition
*partition
= s
->private;
494 struct omap_mux_entry
*e
;
495 u8 omap_gen
= omap_rev() >> 28;
497 list_for_each_entry(e
, &partition
->muxmodes
, node
) {
498 struct omap_mux
*m
= &e
->mux
;
499 char m0_def
[OMAP_MUX_DEFNAME_LEN
];
500 char *m0_name
= m
->muxnames
[0];
507 /* REVISIT: Needs to be updated if mode0 names get longer */
508 for (i
= 0; i
< OMAP_MUX_DEFNAME_LEN
; i
++) {
509 if (m0_name
[i
] == '\0') {
510 m0_def
[i
] = m0_name
[i
];
513 m0_def
[i
] = toupper(m0_name
[i
]);
515 val
= omap_mux_read(partition
, m
->reg_offset
);
516 mode
= val
& OMAP_MUX_MODE7
;
518 seq_printf(s
, "/* %s */\n", m
->muxnames
[mode
]);
521 * XXX: Might be revisited to support differences across
522 * same OMAP generation.
524 seq_printf(s
, "OMAP%d_MUX(%s, ", omap_gen
, m0_def
);
525 omap_mux_decode(s
, val
);
526 seq_printf(s
, "),\n");
532 static int omap_mux_dbg_board_open(struct inode
*inode
, struct file
*file
)
534 return single_open(file
, omap_mux_dbg_board_show
, inode
->i_private
);
537 static const struct file_operations omap_mux_dbg_board_fops
= {
538 .open
= omap_mux_dbg_board_open
,
541 .release
= single_release
,
544 static struct omap_mux_partition
*omap_mux_get_partition(struct omap_mux
*mux
)
546 struct omap_mux_partition
*partition
;
548 list_for_each_entry(partition
, &mux_partitions
, node
) {
549 struct list_head
*muxmodes
= &partition
->muxmodes
;
550 struct omap_mux_entry
*e
;
552 list_for_each_entry(e
, muxmodes
, node
) {
553 struct omap_mux
*m
= &e
->mux
;
563 static int omap_mux_dbg_signal_show(struct seq_file
*s
, void *unused
)
565 struct omap_mux
*m
= s
->private;
566 struct omap_mux_partition
*partition
;
567 const char *none
= "NA";
571 partition
= omap_mux_get_partition(m
);
575 val
= omap_mux_read(partition
, m
->reg_offset
);
576 mode
= val
& OMAP_MUX_MODE7
;
578 seq_printf(s
, "name: %s.%s (0x%08x/0x%03x = 0x%04x), b %s, t %s\n",
579 m
->muxnames
[0], m
->muxnames
[mode
],
580 partition
->phys
+ m
->reg_offset
, m
->reg_offset
, val
,
581 m
->balls
[0] ? m
->balls
[0] : none
,
582 m
->balls
[1] ? m
->balls
[1] : none
);
583 seq_printf(s
, "mode: ");
584 omap_mux_decode(s
, val
);
586 seq_printf(s
, "signals: %s | %s | %s | %s | %s | %s | %s | %s\n",
587 m
->muxnames
[0] ? m
->muxnames
[0] : none
,
588 m
->muxnames
[1] ? m
->muxnames
[1] : none
,
589 m
->muxnames
[2] ? m
->muxnames
[2] : none
,
590 m
->muxnames
[3] ? m
->muxnames
[3] : none
,
591 m
->muxnames
[4] ? m
->muxnames
[4] : none
,
592 m
->muxnames
[5] ? m
->muxnames
[5] : none
,
593 m
->muxnames
[6] ? m
->muxnames
[6] : none
,
594 m
->muxnames
[7] ? m
->muxnames
[7] : none
);
599 #define OMAP_MUX_MAX_ARG_CHAR 7
601 static ssize_t
omap_mux_dbg_signal_write(struct file
*file
,
602 const char __user
*user_buf
,
603 size_t count
, loff_t
*ppos
)
605 char buf
[OMAP_MUX_MAX_ARG_CHAR
];
606 struct seq_file
*seqf
;
610 struct omap_mux_partition
*partition
;
612 if (count
> OMAP_MUX_MAX_ARG_CHAR
)
615 memset(buf
, 0, sizeof(buf
));
616 buf_size
= min(count
, sizeof(buf
) - 1);
618 if (copy_from_user(buf
, user_buf
, buf_size
))
621 ret
= strict_strtoul(buf
, 0x10, &val
);
628 seqf
= file
->private_data
;
631 partition
= omap_mux_get_partition(m
);
635 omap_mux_write(partition
, (u16
)val
, m
->reg_offset
);
641 static int omap_mux_dbg_signal_open(struct inode
*inode
, struct file
*file
)
643 return single_open(file
, omap_mux_dbg_signal_show
, inode
->i_private
);
646 static const struct file_operations omap_mux_dbg_signal_fops
= {
647 .open
= omap_mux_dbg_signal_open
,
649 .write
= omap_mux_dbg_signal_write
,
651 .release
= single_release
,
654 static struct dentry
*mux_dbg_dir
;
656 static void __init
omap_mux_dbg_create_entry(
657 struct omap_mux_partition
*partition
,
658 struct dentry
*mux_dbg_dir
)
660 struct omap_mux_entry
*e
;
662 list_for_each_entry(e
, &partition
->muxmodes
, node
) {
663 struct omap_mux
*m
= &e
->mux
;
665 (void)debugfs_create_file(m
->muxnames
[0], S_IWUSR
, mux_dbg_dir
,
666 m
, &omap_mux_dbg_signal_fops
);
670 static void __init
omap_mux_dbg_init(void)
672 struct omap_mux_partition
*partition
;
673 static struct dentry
*mux_dbg_board_dir
;
675 mux_dbg_dir
= debugfs_create_dir("omap_mux", NULL
);
679 mux_dbg_board_dir
= debugfs_create_dir("board", mux_dbg_dir
);
680 if (!mux_dbg_board_dir
)
683 list_for_each_entry(partition
, &mux_partitions
, node
) {
684 omap_mux_dbg_create_entry(partition
, mux_dbg_dir
);
685 (void)debugfs_create_file(partition
->name
, S_IRUGO
,
686 mux_dbg_board_dir
, partition
,
687 &omap_mux_dbg_board_fops
);
692 static inline void omap_mux_dbg_init(void)
695 #endif /* CONFIG_DEBUG_FS */
697 static void __init
omap_mux_free_names(struct omap_mux
*m
)
701 for (i
= 0; i
< OMAP_MUX_NR_MODES
; i
++)
702 kfree(m
->muxnames
[i
]);
704 #ifdef CONFIG_DEBUG_FS
705 for (i
= 0; i
< OMAP_MUX_NR_SIDES
; i
++)
711 /* Free all data except for GPIO pins unless CONFIG_DEBUG_FS is set */
712 static int __init
omap_mux_late_init(void)
714 struct omap_mux_partition
*partition
;
716 list_for_each_entry(partition
, &mux_partitions
, node
) {
717 struct omap_mux_entry
*e
, *tmp
;
718 list_for_each_entry_safe(e
, tmp
, &partition
->muxmodes
, node
) {
719 struct omap_mux
*m
= &e
->mux
;
720 u16 mode
= omap_mux_read(partition
, m
->reg_offset
);
722 if (OMAP_MODE_GPIO(mode
))
725 #ifndef CONFIG_DEBUG_FS
726 mutex_lock(&muxmode_mutex
);
728 mutex_unlock(&muxmode_mutex
);
729 omap_mux_free_names(m
);
739 late_initcall(omap_mux_late_init
);
741 static void __init
omap_mux_package_fixup(struct omap_mux
*p
,
742 struct omap_mux
*superset
)
744 while (p
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
745 struct omap_mux
*s
= superset
;
748 while (s
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
749 if (s
->reg_offset
== p
->reg_offset
) {
757 pr_err("%s: Unknown entry offset 0x%x\n", __func__
,
763 #ifdef CONFIG_DEBUG_FS
765 static void __init
omap_mux_package_init_balls(struct omap_ball
*b
,
766 struct omap_mux
*superset
)
768 while (b
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
769 struct omap_mux
*s
= superset
;
772 while (s
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
773 if (s
->reg_offset
== b
->reg_offset
) {
774 s
->balls
[0] = b
->balls
[0];
775 s
->balls
[1] = b
->balls
[1];
782 pr_err("%s: Unknown ball offset 0x%x\n", __func__
,
788 #else /* CONFIG_DEBUG_FS */
790 static inline void omap_mux_package_init_balls(struct omap_ball
*b
,
791 struct omap_mux
*superset
)
795 #endif /* CONFIG_DEBUG_FS */
797 static int __init
omap_mux_setup(char *options
)
802 omap_mux_options
= options
;
806 __setup("omap_mux=", omap_mux_setup
);
809 * Note that the omap_mux=some.signal1=0x1234,some.signal2=0x1234
810 * cmdline options only override the bootloader values.
811 * During development, please enable CONFIG_DEBUG_FS, and use the
812 * signal specific entries under debugfs.
814 static void __init
omap_mux_set_cmdline_signals(void)
816 char *options
, *next_opt
, *token
;
818 if (!omap_mux_options
)
821 options
= kmalloc(strlen(omap_mux_options
) + 1, GFP_KERNEL
);
825 strcpy(options
, omap_mux_options
);
828 while ((token
= strsep(&next_opt
, ",")) != NULL
) {
833 name
= strsep(&keyval
, "=");
837 res
= strict_strtoul(keyval
, 0x10, &val
);
841 omap_mux_init_signal(name
, (u16
)val
);
848 static int __init
omap_mux_copy_names(struct omap_mux
*src
,
849 struct omap_mux
*dst
)
853 for (i
= 0; i
< OMAP_MUX_NR_MODES
; i
++) {
854 if (src
->muxnames
[i
]) {
856 kmalloc(strlen(src
->muxnames
[i
]) + 1,
858 if (!dst
->muxnames
[i
])
860 strcpy(dst
->muxnames
[i
], src
->muxnames
[i
]);
864 #ifdef CONFIG_DEBUG_FS
865 for (i
= 0; i
< OMAP_MUX_NR_SIDES
; i
++) {
868 kmalloc(strlen(src
->balls
[i
]) + 1,
872 strcpy(dst
->balls
[i
], src
->balls
[i
]);
880 omap_mux_free_names(dst
);
885 #endif /* CONFIG_OMAP_MUX */
887 static struct omap_mux
*omap_mux_get_by_gpio(
888 struct omap_mux_partition
*partition
,
891 struct omap_mux_entry
*e
;
892 struct omap_mux
*ret
= NULL
;
894 list_for_each_entry(e
, &partition
->muxmodes
, node
) {
895 struct omap_mux
*m
= &e
->mux
;
896 if (m
->gpio
== gpio
) {
905 /* Needed for dynamic muxing of GPIO pins for off-idle */
906 u16
omap_mux_get_gpio(int gpio
)
908 struct omap_mux_partition
*partition
;
911 list_for_each_entry(partition
, &mux_partitions
, node
) {
912 m
= omap_mux_get_by_gpio(partition
, gpio
);
914 return omap_mux_read(partition
, m
->reg_offset
);
917 if (!m
|| m
->reg_offset
== OMAP_MUX_TERMINATOR
)
918 pr_err("%s: Could not get gpio%i\n", __func__
, gpio
);
920 return OMAP_MUX_TERMINATOR
;
923 /* Needed for dynamic muxing of GPIO pins for off-idle */
924 void omap_mux_set_gpio(u16 val
, int gpio
)
926 struct omap_mux_partition
*partition
;
927 struct omap_mux
*m
= NULL
;
929 list_for_each_entry(partition
, &mux_partitions
, node
) {
930 m
= omap_mux_get_by_gpio(partition
, gpio
);
932 omap_mux_write(partition
, val
, m
->reg_offset
);
937 if (!m
|| m
->reg_offset
== OMAP_MUX_TERMINATOR
)
938 pr_err("%s: Could not set gpio%i\n", __func__
, gpio
);
941 static struct omap_mux
* __init
omap_mux_list_add(
942 struct omap_mux_partition
*partition
,
943 struct omap_mux
*src
)
945 struct omap_mux_entry
*entry
;
948 entry
= kzalloc(sizeof(struct omap_mux_entry
), GFP_KERNEL
);
955 #ifdef CONFIG_OMAP_MUX
956 if (omap_mux_copy_names(src
, m
)) {
962 mutex_lock(&muxmode_mutex
);
963 list_add_tail(&entry
->node
, &partition
->muxmodes
);
964 mutex_unlock(&muxmode_mutex
);
970 * Note if CONFIG_OMAP_MUX is not selected, we will only initialize
971 * the GPIO to mux offset mapping that is needed for dynamic muxing
972 * of GPIO pins for off-idle.
974 static void __init
omap_mux_init_list(struct omap_mux_partition
*partition
,
975 struct omap_mux
*superset
)
977 while (superset
->reg_offset
!= OMAP_MUX_TERMINATOR
) {
978 struct omap_mux
*entry
;
980 #ifdef CONFIG_OMAP_MUX
981 if (!superset
->muxnames
|| !superset
->muxnames
[0]) {
986 /* Skip pins that are not muxed as GPIO by bootloader */
987 if (!OMAP_MODE_GPIO(omap_mux_read(partition
,
988 superset
->reg_offset
))) {
994 entry
= omap_mux_list_add(partition
, superset
);
996 pr_err("%s: Could not add entry\n", __func__
);
1003 #ifdef CONFIG_OMAP_MUX
1005 static void omap_mux_init_package(struct omap_mux
*superset
,
1006 struct omap_mux
*package_subset
,
1007 struct omap_ball
*package_balls
)
1010 omap_mux_package_fixup(package_subset
, superset
);
1012 omap_mux_package_init_balls(package_balls
, superset
);
1015 static void omap_mux_init_signals(struct omap_mux_partition
*partition
,
1016 struct omap_board_mux
*board_mux
)
1018 omap_mux_set_cmdline_signals();
1019 omap_mux_write_array(partition
, board_mux
);
1024 static void omap_mux_init_package(struct omap_mux
*superset
,
1025 struct omap_mux
*package_subset
,
1026 struct omap_ball
*package_balls
)
1030 static void omap_mux_init_signals(struct omap_mux_partition
*partition
,
1031 struct omap_board_mux
*board_mux
)
1037 static u32 mux_partitions_cnt
;
1039 int __init
omap_mux_init(const char *name
, u32 flags
,
1040 u32 mux_pbase
, u32 mux_size
,
1041 struct omap_mux
*superset
,
1042 struct omap_mux
*package_subset
,
1043 struct omap_board_mux
*board_mux
,
1044 struct omap_ball
*package_balls
)
1046 struct omap_mux_partition
*partition
;
1048 partition
= kzalloc(sizeof(struct omap_mux_partition
), GFP_KERNEL
);
1052 partition
->name
= name
;
1053 partition
->flags
= flags
;
1054 partition
->size
= mux_size
;
1055 partition
->phys
= mux_pbase
;
1056 partition
->base
= ioremap(mux_pbase
, mux_size
);
1057 if (!partition
->base
) {
1058 pr_err("%s: Could not ioremap mux partition at 0x%08x\n",
1059 __func__
, partition
->phys
);
1064 INIT_LIST_HEAD(&partition
->muxmodes
);
1066 list_add_tail(&partition
->node
, &mux_partitions
);
1067 mux_partitions_cnt
++;
1068 pr_info("%s: Add partition: #%d: %s, flags: %x\n", __func__
,
1069 mux_partitions_cnt
, partition
->name
, partition
->flags
);
1071 omap_mux_init_package(superset
, package_subset
, package_balls
);
1072 omap_mux_init_list(partition
, superset
);
1073 omap_mux_init_signals(partition
, board_mux
);