26 #include <linux/kernel.h>
29 #include <linux/list.h>
30 #include <linux/slab.h>
31 #include <linux/ctype.h>
46 #define OMAP_MUX_BASE_OFFSET 0x30
47 #define OMAP_MUX_BASE_SZ 0x5ca
99 #ifdef CONFIG_OMAP_MUX
101 static char *omap_mux_options;
118 if (gpio == m->
gpio) {
125 pr_err(
"%s: Could not set gpio%i\n", __func__, gpio);
130 pr_info(
"%s: Multiple gpio paths (%d) for gpio%i\n", __func__,
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);
148 int __init omap_mux_init_gpio(
int gpio,
int val)
154 ret = _omap_mux_init_gpio(partition, gpio, val);
168 const char *mode_name;
169 int found = 0, found_mode = 0, mode0_len = 0;
172 mode_name =
strchr(muxname,
'.');
185 m0_entry = mux->muxnames[0];
188 if (mode0_len &&
strncmp(muxname, m0_entry, mode0_len))
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__,
216 pr_err(
"%s: Could not find signal %s\n", __func__, muxname);
221 int __init omap_mux_get_by_name(
const char *muxname,
229 int mux_mode = _omap_mux_get_by_name(partition, muxname, &mux);
233 *found_partition = partition;
242 int __init omap_mux_init_signal(
const char *muxname,
int val)
249 mux_mode = omap_mux_get_by_name(muxname, &partition, &mux);
250 if (mux_mode < 0 || !mux)
255 pr_debug(
"%s: Setting signal %s 0x%04x -> 0x%04x\n",
256 __func__, muxname, old_mode, mux_mode);
268 if (!bpads || nr_pads < 1)
282 for (i = 0; i < hmux->
nr_pads; i++) {
288 mux_mode = omap_mux_get_by_name(bpad->
name, &partition, &mux);
292 pad->partition = partition;
300 for (j = i - 1; j >= 0; j--)
306 pad->flags = bpad->
flags;
307 pad->enable = bpad->
enable;
308 pad->idle = bpad->
idle;
309 pad->off = bpad->
off;
315 pr_debug(
"%s: Initialized %s\n", __func__, pad->name);
318 if (!nr_pads_dynamic)
329 pr_err(
"%s: Could not allocate dynamic pads\n", __func__);
334 for (i = 0; i < hmux->
nr_pads; i++) {
339 pr_debug(
"%s: pad %s tagged dynamic\n",
340 __func__, pad->
name);
353 pr_err(
"%s: Could not allocate device mux entry\n", __func__);
374 u32 handled_irqs = 0;
392 if (handled_irqs & 1 << irq)
395 handled_irqs |= 1 << irq;
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))
443 pad->
mux->reg_offset);
458 pad->
mux->reg_offset);
465 for (i = 0; i < hmux->
nr_pads; i++) {
474 pr_debug(
"%s: Enabling %s %x\n", __func__,
483 pr_debug(
"%s: Disabling %s %x\n", __func__,
493 pad->
mux->reg_offset);
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)) { \
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];
528 OMAP_MUX_TEST_FLAG(val,
531 OMAP_MUX_TEST_FLAG(val,
536 OMAP_MUX_TEST_FLAG(val,
539 OMAP_MUX_TEST_FLAG(val,
548 OMAP_MUX_TEST_FLAG(val,
558 flags[
i] =
"OMAP_PIN_OUTPUT";
568 #define OMAP_MUX_DEFNAME_LEN 32
570 static int omap_mux_dbg_board_show(
struct seq_file *s,
void *
unused)
578 char m0_def[OMAP_MUX_DEFNAME_LEN];
579 char *m0_name = m->muxnames[0];
587 for (i = 0; i < OMAP_MUX_DEFNAME_LEN; i++) {
588 if (m0_name[i] ==
'\0') {
589 m0_def[
i] = m0_name[
i];
597 seq_printf(s,
"/* %s */\n", m->muxnames[mode]);
603 seq_printf(s,
"OMAP%d_MUX(%s, ", omap_gen, m0_def);
604 omap_mux_decode(s, val);
617 .
open = omap_mux_dbg_board_open,
642 static int omap_mux_dbg_signal_show(
struct seq_file *s,
void *unused)
646 const char *
none =
"NA";
650 partition = omap_mux_get_partition(m);
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],
660 m->balls[0] ? m->balls[0] : none,
661 m->balls[1] ? m->balls[1] : none);
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
681 const char __user *user_buf,
682 size_t count, loff_t *ppos)
684 char buf[OMAP_MUX_MAX_ARG_CHAR];
691 if (count > OMAP_MUX_MAX_ARG_CHAR)
694 memset(buf, 0,
sizeof(buf));
695 buf_size =
min(count,
sizeof(buf) - 1);
710 partition = omap_mux_get_partition(m);
720 static int omap_mux_dbg_signal_open(
struct inode *
inode,
struct file *file)
726 .
open = omap_mux_dbg_signal_open,
728 .write = omap_mux_dbg_signal_write,
733 static struct dentry *mux_dbg_dir;
735 static void __init omap_mux_dbg_create_entry(
737 struct dentry *mux_dbg_dir)
745 m, &omap_mux_dbg_signal_fops);
749 static void __init omap_mux_dbg_init(
void)
752 static struct dentry *mux_dbg_board_dir;
759 if (!mux_dbg_board_dir)
763 omap_mux_dbg_create_entry(partition, mux_dbg_dir);
765 mux_dbg_board_dir, partition,
766 &omap_mux_dbg_board_fops);
771 static inline void omap_mux_dbg_init(
void)
781 kfree(m->muxnames[i]);
783 #ifdef CONFIG_DEBUG_FS
791 int __init omap_mux_late_init(
void)
805 #ifndef CONFIG_DEBUG_FS
809 omap_mux_free_names(m);
817 "hwmod_io", omap_mux_late_init);
820 pr_warning(
"mux: Failed to setup hwmod io irq %d\n", ret);
843 pr_err(
"%s: Unknown entry offset 0x%x\n", __func__,
849 #ifdef CONFIG_DEBUG_FS
860 s->balls[0] = b->
balls[0];
861 s->balls[1] = b->
balls[1];
868 pr_err(
"%s: Unknown ball offset 0x%x\n", __func__,
876 static inline void omap_mux_package_init_balls(
struct omap_ball *b,
892 __setup(
"omap_mux=", omap_mux_setup);
900 static void __init omap_mux_set_cmdline_signals(
void)
904 if (!omap_mux_options)
913 while ((token =
strsep(&next_opt,
",")) !=
NULL) {
918 name =
strsep(&keyval,
"=");
926 omap_mux_init_signal(name, (
u16)val);
939 if (src->muxnames[i]) {
940 dst->muxnames[
i] =
kstrdup(src->muxnames[i],
942 if (!dst->muxnames[i])
947 #ifdef CONFIG_DEBUG_FS
960 omap_mux_free_names(dst);
967 static struct omap_mux *omap_mux_get_by_gpio(
976 if (m->
gpio == gpio) {
992 m = omap_mux_get_by_gpio(partition, gpio);
998 pr_err(
"%s: Could not get gpio%i\n", __func__, gpio);
1010 m = omap_mux_get_by_gpio(partition, gpio);
1018 pr_err(
"%s: Could not set gpio%i\n", __func__, gpio);
1035 #ifdef CONFIG_OMAP_MUX
1036 if (omap_mux_copy_names(src, m)) {
1060 #ifdef CONFIG_OMAP_MUX
1061 if (!superset->muxnames || !superset->muxnames[0]) {
1074 entry = omap_mux_list_add(partition, superset);
1076 pr_err(
"%s: Could not add entry\n", __func__);
1083 #ifdef CONFIG_OMAP_MUX
1085 static void omap_mux_init_package(
struct omap_mux *superset,
1090 omap_mux_package_fixup(package_subset, superset);
1092 omap_mux_package_init_balls(package_balls, superset);
1098 omap_mux_set_cmdline_signals();
1104 static void omap_mux_init_package(
struct omap_mux *superset,
1117 static u32 mux_partitions_cnt;
1120 u32 mux_pbase,
u32 mux_size,
1134 partition->
size = mux_size;
1135 partition->
phys = mux_pbase;
1137 if (!partition->
base) {
1138 pr_err(
"%s: Could not ioremap mux partition at 0x%08x\n",
1139 __func__, partition->
phys);
1144 INIT_LIST_HEAD(&partition->
muxmodes);
1147 mux_partitions_cnt++;
1148 pr_info(
"%s: Add partition: #%d: %s, flags: %x\n", __func__,
1149 mux_partitions_cnt, partition->
name, partition->
flags);
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);