]> git.karo-electronics.de Git - mv-sheeva.git/blobdiff - arch/arm/mach-omap2/mux.c
omap2+: Add omap_mux_get_by_name
[mv-sheeva.git] / arch / arm / mach-omap2 / mux.c
index 92215703b6718d676756feaae059e2cffd152b6e..0fa3d74125bc25c5f48ee5c2507ca1c52cf19077 100644 (file)
@@ -114,12 +114,12 @@ static int __init _omap_mux_init_gpio(struct omap_mux_partition *partition,
        }
 
        if (found == 0) {
-               pr_err("mux: Could not set gpio%i\n", gpio);
+               pr_err("%s: Could not set gpio%i\n", __func__, gpio);
                return -ENODEV;
        }
 
        if (found > 1) {
-               pr_info("mux: Multiple gpio paths (%d) for gpio%i\n",
+               pr_info("%s: Multiple gpio paths (%d) for gpio%i\n", __func__,
                        found, gpio);
                return -EINVAL;
        }
@@ -130,7 +130,7 @@ static int __init _omap_mux_init_gpio(struct omap_mux_partition *partition,
                mux_mode |= OMAP_MUX_MODE3;
        else
                mux_mode |= OMAP_MUX_MODE4;
-       pr_debug("mux: Setting signal %s.gpio%i 0x%04x -> 0x%04x\n",
+       pr_debug("%s: Setting signal %s.gpio%i 0x%04x -> 0x%04x\n", __func__,
                 gpio_mux->muxnames[0], gpio, old_mode, mux_mode);
        omap_mux_write(partition, mux_mode, gpio_mux->reg_offset);
 
@@ -151,12 +151,14 @@ int __init omap_mux_init_gpio(int gpio, int val)
        return -ENODEV;
 }
 
-static int __init _omap_mux_init_signal(struct omap_mux_partition *partition,
-                                       const char *muxname, int val)
+static int __init _omap_mux_get_by_name(struct omap_mux_partition *partition,
+                                       const char *muxname,
+                                       struct omap_mux **found_mux)
 {
+       struct omap_mux *mux = NULL;
        struct omap_mux_entry *e;
        const char *mode_name;
-       int found = 0, mode0_len = 0;
+       int found = 0, found_mode, mode0_len = 0;
        struct list_head *muxmodes = &partition->muxmodes;
 
        mode_name = strchr(muxname, '.');
@@ -168,65 +170,86 @@ static int __init _omap_mux_init_signal(struct omap_mux_partition *partition,
        }
 
        list_for_each_entry(e, muxmodes, node) {
-               struct omap_mux *m = &e->mux;
-               char *m0_entry = m->muxnames[0];
+               char *m0_entry;
                int i;
 
+               mux = &e->mux;
+               m0_entry = mux->muxnames[0];
+
                /* First check for full name in mode0.muxmode format */
                if (mode0_len && strncmp(muxname, m0_entry, mode0_len))
                        continue;
 
                /* Then check for muxmode only */
                for (i = 0; i < OMAP_MUX_NR_MODES; i++) {
-                       char *mode_cur = m->muxnames[i];
+                       char *mode_cur = mux->muxnames[i];
 
                        if (!mode_cur)
                                continue;
 
                        if (!strcmp(mode_name, mode_cur)) {
-                               u16 old_mode;
-                               u16 mux_mode;
-
-                               old_mode = omap_mux_read(partition,
-                                                        m->reg_offset);
-                               mux_mode = val | i;
-                               pr_debug("mux: Setting signal "
-                                        "%s.%s 0x%04x -> 0x%04x\n",
-                                        m0_entry, muxname, old_mode, mux_mode);
-                               omap_mux_write(partition, mux_mode,
-                                              m->reg_offset);
+                               *found_mux = mux;
                                found++;
+                               found_mode = i;
                        }
                }
        }
 
-       if (found == 1)
-               return 0;
+       if (found == 1) {
+               return found_mode;
+       }
 
        if (found > 1) {
-               pr_err("mux: Multiple signal paths (%i) for %s\n",
+               pr_err("%s: Multiple signal paths (%i) for %s\n", __func__,
                       found, muxname);
                return -EINVAL;
        }
 
-       pr_err("mux: Could not set signal %s\n", muxname);
+       pr_err("%s: Could not find signal %s\n", __func__, muxname);
 
        return -ENODEV;
 }
 
-int __init omap_mux_init_signal(const char *muxname, int val)
+static int __init
+omap_mux_get_by_name(const char *muxname,
+                       struct omap_mux_partition **found_partition,
+                       struct omap_mux **found_mux)
 {
        struct omap_mux_partition *partition;
-       int ret;
 
        list_for_each_entry(partition, &mux_partitions, node) {
-               ret = _omap_mux_init_signal(partition, muxname, val);
-               if (!ret)
-                       return ret;
+               struct omap_mux *mux = NULL;
+               int mux_mode = _omap_mux_get_by_name(partition, muxname, &mux);
+               if (mux_mode < 0)
+                       continue;
+
+               *found_partition = partition;
+               *found_mux = mux;
+
+               return mux_mode;
        }
 
        return -ENODEV;
+}
 
+int __init omap_mux_init_signal(const char *muxname, int val)
+{
+       struct omap_mux_partition *partition = NULL;
+       struct omap_mux *mux = NULL;
+       u16 old_mode;
+       int mux_mode;
+
+       mux_mode = omap_mux_get_by_name(muxname, &partition, &mux);
+       if (mux_mode < 0)
+               return mux_mode;
+
+       old_mode = omap_mux_read(partition, mux->reg_offset);
+       mux_mode |= val;
+       pr_debug("%s: Setting signal %s 0x%04x -> 0x%04x\n",
+                        __func__, muxname, old_mode, mux_mode);
+       omap_mux_write(partition, mux_mode, mux->reg_offset);
+
+       return 0;
 }
 
 #ifdef CONFIG_DEBUG_FS
@@ -561,7 +584,7 @@ static void __init omap_mux_package_fixup(struct omap_mux *p,
                        s++;
                }
                if (!found)
-                       pr_err("mux: Unknown entry offset 0x%x\n",
+                       pr_err("%s: Unknown entry offset 0x%x\n", __func__,
                               p->reg_offset);
                p++;
        }
@@ -586,7 +609,7 @@ static void __init omap_mux_package_init_balls(struct omap_ball *b,
                        s++;
                }
                if (!found)
-                       pr_err("mux: Unknown ball offset 0x%x\n",
+                       pr_err("%s: Unknown ball offset 0x%x\n", __func__,
                               b->reg_offset);
                b++;
        }
@@ -722,7 +745,7 @@ u16 omap_mux_get_gpio(int gpio)
        }
 
        if (!m || m->reg_offset == OMAP_MUX_TERMINATOR)
-               pr_err("mux: Could not get gpio%i\n", gpio);
+               pr_err("%s: Could not get gpio%i\n", __func__, gpio);
 
        return OMAP_MUX_TERMINATOR;
 }
@@ -742,7 +765,7 @@ void omap_mux_set_gpio(u16 val, int gpio)
        }
 
        if (!m || m->reg_offset == OMAP_MUX_TERMINATOR)
-               pr_err("mux: Could not set gpio%i\n", gpio);
+               pr_err("%s: Could not set gpio%i\n", __func__, gpio);
 }
 
 static struct omap_mux * __init omap_mux_list_add(
@@ -800,7 +823,7 @@ static void __init omap_mux_init_list(struct omap_mux_partition *partition,
 
                entry = omap_mux_list_add(partition, superset);
                if (!entry) {
-                       pr_err("mux: Could not add entry\n");
+                       pr_err("%s: Could not add entry\n", __func__);
                        return;
                }
                superset++;
@@ -862,8 +885,8 @@ int __init omap_mux_init(const char *name, u32 flags,
        partition->phys = mux_pbase;
        partition->base = ioremap(mux_pbase, mux_size);
        if (!partition->base) {
-               pr_err("mux: Could not ioremap mux partition at 0x%08x\n",
-                       partition->phys);
+               pr_err("%s: Could not ioremap mux partition at 0x%08x\n",
+                       __func__, partition->phys);
                return -ENODEV;
        }
 
@@ -871,7 +894,7 @@ int __init omap_mux_init(const char *name, u32 flags,
 
        list_add_tail(&partition->node, &mux_partitions);
        mux_partitions_cnt++;
-       pr_info("MUX: Add partition: #%d: %s, flags: %x\n",
+       pr_info("%s: Add partition: #%d: %s, flags: %x\n", __func__,
                mux_partitions_cnt, partition->name, partition->flags);
 
        omap_mux_init_package(superset, package_subset, package_balls);