Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 1 | /* |
| 2 | * linux/arch/arm/mach-omap2/mux.c |
| 3 | * |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 4 | * OMAP2, OMAP3 and OMAP4 pin multiplexing configurations |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 5 | * |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 6 | * Copyright (C) 2004 - 2010 Texas Instruments Inc. |
Tony Lindgren | 9330899 | 2008-01-24 17:24:15 -0800 | [diff] [blame] | 7 | * Copyright (C) 2003 - 2008 Nokia Corporation |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 8 | * |
Tony Lindgren | 9330899 | 2008-01-24 17:24:15 -0800 | [diff] [blame] | 9 | * Written by Tony Lindgren |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 10 | * |
| 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. |
| 15 | * |
| 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. |
| 20 | * |
| 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 |
| 24 | * |
| 25 | */ |
Paul Walmsley | 4814ced | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 26 | #include <linux/kernel.h> |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 27 | #include <linux/init.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 28 | #include <linux/io.h> |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 29 | #include <linux/list.h> |
Paul Walmsley | 4814ced | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 30 | #include <linux/slab.h> |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 31 | #include <linux/ctype.h> |
| 32 | #include <linux/debugfs.h> |
| 33 | #include <linux/seq_file.h> |
| 34 | #include <linux/uaccess.h> |
Tero Kristo | 13a3fe5 | 2011-12-16 14:36:59 -0700 | [diff] [blame] | 35 | #include <linux/irq.h> |
| 36 | #include <linux/interrupt.h> |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 37 | |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 38 | #include <asm/system.h> |
| 39 | |
Tony Lindgren | 9796b32 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 40 | #include <plat/omap_hwmod.h> |
| 41 | |
Paul Walmsley | 4814ced | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 42 | #include "control.h" |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 43 | #include "mux.h" |
Tero Kristo | 13a3fe5 | 2011-12-16 14:36:59 -0700 | [diff] [blame] | 44 | #include "prm.h" |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 45 | |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 46 | #define OMAP_MUX_BASE_OFFSET 0x30 /* Offset from CTRL_BASE */ |
| 47 | #define OMAP_MUX_BASE_SZ 0x5ca |
| 48 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 49 | struct omap_mux_entry { |
| 50 | struct omap_mux mux; |
| 51 | struct list_head node; |
| 52 | }; |
| 53 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 54 | static LIST_HEAD(mux_partitions); |
| 55 | static DEFINE_MUTEX(muxmode_mutex); |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 56 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 57 | struct omap_mux_partition *omap_mux_get(const char *name) |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 58 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 59 | struct omap_mux_partition *partition; |
| 60 | |
| 61 | list_for_each_entry(partition, &mux_partitions, node) { |
| 62 | if (!strcmp(name, partition->name)) |
| 63 | return partition; |
| 64 | } |
| 65 | |
| 66 | return NULL; |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 67 | } |
| 68 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 69 | u16 omap_mux_read(struct omap_mux_partition *partition, u16 reg) |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 70 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 71 | if (partition->flags & OMAP_MUX_REG_8BIT) |
| 72 | return __raw_readb(partition->base + reg); |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 73 | else |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 74 | return __raw_readw(partition->base + reg); |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 75 | } |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame] | 76 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 77 | void omap_mux_write(struct omap_mux_partition *partition, u16 val, |
| 78 | u16 reg) |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 79 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 80 | if (partition->flags & OMAP_MUX_REG_8BIT) |
| 81 | __raw_writeb(val, partition->base + reg); |
| 82 | else |
| 83 | __raw_writew(val, partition->base + reg); |
| 84 | } |
| 85 | |
| 86 | void omap_mux_write_array(struct omap_mux_partition *partition, |
| 87 | struct omap_board_mux *board_mux) |
| 88 | { |
Colin Cross | d4ff612 | 2011-05-31 12:00:09 -0700 | [diff] [blame] | 89 | if (!board_mux) |
| 90 | return; |
| 91 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 92 | while (board_mux->reg_offset != OMAP_MUX_TERMINATOR) { |
| 93 | omap_mux_write(partition, board_mux->value, |
| 94 | board_mux->reg_offset); |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 95 | board_mux++; |
| 96 | } |
| 97 | } |
| 98 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 99 | #ifdef CONFIG_OMAP_MUX |
| 100 | |
| 101 | static char *omap_mux_options; |
| 102 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 103 | static int __init _omap_mux_init_gpio(struct omap_mux_partition *partition, |
| 104 | int gpio, int val) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 105 | { |
| 106 | struct omap_mux_entry *e; |
Sanjeev Premi | ca82876 | 2010-09-23 18:27:18 -0700 | [diff] [blame] | 107 | struct omap_mux *gpio_mux = NULL; |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 108 | u16 old_mode; |
| 109 | u16 mux_mode; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 110 | int found = 0; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 111 | struct list_head *muxmodes = &partition->muxmodes; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 112 | |
| 113 | if (!gpio) |
| 114 | return -EINVAL; |
| 115 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 116 | list_for_each_entry(e, muxmodes, node) { |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 117 | struct omap_mux *m = &e->mux; |
| 118 | if (gpio == m->gpio) { |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 119 | gpio_mux = m; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 120 | found++; |
| 121 | } |
| 122 | } |
| 123 | |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 124 | if (found == 0) { |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 125 | pr_err("%s: Could not set gpio%i\n", __func__, gpio); |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 126 | return -ENODEV; |
| 127 | } |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 128 | |
| 129 | if (found > 1) { |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 130 | pr_info("%s: Multiple gpio paths (%d) for gpio%i\n", __func__, |
Benoit Cousson | 1cbb3a9 | 2010-08-10 17:33:01 +0200 | [diff] [blame] | 131 | found, gpio); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 132 | return -EINVAL; |
| 133 | } |
| 134 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 135 | old_mode = omap_mux_read(partition, gpio_mux->reg_offset); |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 136 | mux_mode = val & ~(OMAP_MUX_NR_MODES - 1); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 137 | if (partition->flags & OMAP_MUX_GPIO_IN_MODE3) |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 138 | mux_mode |= OMAP_MUX_MODE3; |
| 139 | else |
| 140 | mux_mode |= OMAP_MUX_MODE4; |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 141 | pr_debug("%s: Setting signal %s.gpio%i 0x%04x -> 0x%04x\n", __func__, |
Benoit Cousson | 1cbb3a9 | 2010-08-10 17:33:01 +0200 | [diff] [blame] | 142 | gpio_mux->muxnames[0], gpio, old_mode, mux_mode); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 143 | omap_mux_write(partition, mux_mode, gpio_mux->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 144 | |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 145 | return 0; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 146 | } |
| 147 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 148 | int __init omap_mux_init_gpio(int gpio, int val) |
| 149 | { |
| 150 | struct omap_mux_partition *partition; |
| 151 | int ret; |
| 152 | |
| 153 | list_for_each_entry(partition, &mux_partitions, node) { |
| 154 | ret = _omap_mux_init_gpio(partition, gpio, val); |
| 155 | if (!ret) |
| 156 | return ret; |
| 157 | } |
| 158 | |
| 159 | return -ENODEV; |
| 160 | } |
| 161 | |
Tony Lindgren | 8419fdb | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 162 | static int __init _omap_mux_get_by_name(struct omap_mux_partition *partition, |
| 163 | const char *muxname, |
| 164 | struct omap_mux **found_mux) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 165 | { |
Tony Lindgren | 8419fdb | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 166 | struct omap_mux *mux = NULL; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 167 | struct omap_mux_entry *e; |
Tony Lindgren | 5a3b2f7 | 2010-10-01 16:35:24 -0700 | [diff] [blame] | 168 | const char *mode_name; |
Felipe Balbi | afb7d70 | 2011-01-17 06:31:18 +0200 | [diff] [blame] | 169 | int found = 0, found_mode = 0, mode0_len = 0; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 170 | struct list_head *muxmodes = &partition->muxmodes; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 171 | |
| 172 | mode_name = strchr(muxname, '.'); |
| 173 | if (mode_name) { |
Tony Lindgren | 5a3b2f7 | 2010-10-01 16:35:24 -0700 | [diff] [blame] | 174 | mode0_len = strlen(muxname) - strlen(mode_name); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 175 | mode_name++; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 176 | } else { |
| 177 | mode_name = muxname; |
| 178 | } |
| 179 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 180 | list_for_each_entry(e, muxmodes, node) { |
Tony Lindgren | 8419fdb | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 181 | char *m0_entry; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 182 | int i; |
| 183 | |
Tony Lindgren | 8419fdb | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 184 | mux = &e->mux; |
| 185 | m0_entry = mux->muxnames[0]; |
| 186 | |
Tony Lindgren | 5a3b2f7 | 2010-10-01 16:35:24 -0700 | [diff] [blame] | 187 | /* First check for full name in mode0.muxmode format */ |
| 188 | if (mode0_len && strncmp(muxname, m0_entry, mode0_len)) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 189 | continue; |
| 190 | |
Tony Lindgren | 5a3b2f7 | 2010-10-01 16:35:24 -0700 | [diff] [blame] | 191 | /* Then check for muxmode only */ |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 192 | for (i = 0; i < OMAP_MUX_NR_MODES; i++) { |
Tony Lindgren | 8419fdb | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 193 | char *mode_cur = mux->muxnames[i]; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 194 | |
| 195 | if (!mode_cur) |
| 196 | continue; |
| 197 | |
| 198 | if (!strcmp(mode_name, mode_cur)) { |
Tony Lindgren | 8419fdb | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 199 | *found_mux = mux; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 200 | found++; |
Tony Lindgren | 8419fdb | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 201 | found_mode = i; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 202 | } |
| 203 | } |
| 204 | } |
| 205 | |
Tony Lindgren | 8419fdb | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 206 | if (found == 1) { |
| 207 | return found_mode; |
| 208 | } |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 209 | |
| 210 | if (found > 1) { |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 211 | pr_err("%s: Multiple signal paths (%i) for %s\n", __func__, |
Benoit Cousson | 1cbb3a9 | 2010-08-10 17:33:01 +0200 | [diff] [blame] | 212 | found, muxname); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 213 | return -EINVAL; |
| 214 | } |
| 215 | |
Tony Lindgren | 8419fdb | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 216 | pr_err("%s: Could not find signal %s\n", __func__, muxname); |
| 217 | |
| 218 | return -ENODEV; |
| 219 | } |
| 220 | |
| 221 | static int __init |
| 222 | omap_mux_get_by_name(const char *muxname, |
| 223 | struct omap_mux_partition **found_partition, |
| 224 | struct omap_mux **found_mux) |
| 225 | { |
| 226 | struct omap_mux_partition *partition; |
| 227 | |
| 228 | list_for_each_entry(partition, &mux_partitions, node) { |
| 229 | struct omap_mux *mux = NULL; |
| 230 | int mux_mode = _omap_mux_get_by_name(partition, muxname, &mux); |
| 231 | if (mux_mode < 0) |
| 232 | continue; |
| 233 | |
| 234 | *found_partition = partition; |
| 235 | *found_mux = mux; |
| 236 | |
| 237 | return mux_mode; |
| 238 | } |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 239 | |
| 240 | return -ENODEV; |
| 241 | } |
| 242 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 243 | int __init omap_mux_init_signal(const char *muxname, int val) |
| 244 | { |
Tony Lindgren | 8419fdb | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 245 | struct omap_mux_partition *partition = NULL; |
| 246 | struct omap_mux *mux = NULL; |
| 247 | u16 old_mode; |
| 248 | int mux_mode; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 249 | |
Tony Lindgren | 8419fdb | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 250 | mux_mode = omap_mux_get_by_name(muxname, &partition, &mux); |
| 251 | if (mux_mode < 0) |
| 252 | return mux_mode; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 253 | |
Tony Lindgren | 8419fdb | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 254 | old_mode = omap_mux_read(partition, mux->reg_offset); |
| 255 | mux_mode |= val; |
| 256 | pr_debug("%s: Setting signal %s 0x%04x -> 0x%04x\n", |
| 257 | __func__, muxname, old_mode, mux_mode); |
| 258 | omap_mux_write(partition, mux_mode, mux->reg_offset); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 259 | |
Tony Lindgren | 8419fdb | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 260 | return 0; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 261 | } |
| 262 | |
Tony Lindgren | 9796b32 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 263 | struct omap_hwmod_mux_info * __init |
| 264 | omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads) |
| 265 | { |
| 266 | struct omap_hwmod_mux_info *hmux; |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 267 | int i, nr_pads_dynamic = 0; |
Tony Lindgren | 9796b32 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 268 | |
| 269 | if (!bpads || nr_pads < 1) |
| 270 | return NULL; |
| 271 | |
| 272 | hmux = kzalloc(sizeof(struct omap_hwmod_mux_info), GFP_KERNEL); |
| 273 | if (!hmux) |
| 274 | goto err1; |
| 275 | |
| 276 | hmux->nr_pads = nr_pads; |
| 277 | |
| 278 | hmux->pads = kzalloc(sizeof(struct omap_device_pad) * |
| 279 | nr_pads, GFP_KERNEL); |
| 280 | if (!hmux->pads) |
| 281 | goto err2; |
| 282 | |
| 283 | for (i = 0; i < hmux->nr_pads; i++) { |
| 284 | struct omap_mux_partition *partition; |
| 285 | struct omap_device_pad *bpad = &bpads[i], *pad = &hmux->pads[i]; |
| 286 | struct omap_mux *mux; |
| 287 | int mux_mode; |
| 288 | |
| 289 | mux_mode = omap_mux_get_by_name(bpad->name, &partition, &mux); |
| 290 | if (mux_mode < 0) |
| 291 | goto err3; |
| 292 | if (!pad->partition) |
| 293 | pad->partition = partition; |
| 294 | if (!pad->mux) |
| 295 | pad->mux = mux; |
| 296 | |
| 297 | pad->name = kzalloc(strlen(bpad->name) + 1, GFP_KERNEL); |
| 298 | if (!pad->name) { |
| 299 | int j; |
| 300 | |
| 301 | for (j = i - 1; j >= 0; j--) |
| 302 | kfree(hmux->pads[j].name); |
| 303 | goto err3; |
| 304 | } |
| 305 | strcpy(pad->name, bpad->name); |
| 306 | |
| 307 | pad->flags = bpad->flags; |
| 308 | pad->enable = bpad->enable; |
| 309 | pad->idle = bpad->idle; |
| 310 | pad->off = bpad->off; |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 311 | |
Paul Walmsley | 96dc19f | 2011-12-16 14:36:57 -0700 | [diff] [blame] | 312 | if (pad->flags & |
| 313 | (OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP)) |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 314 | nr_pads_dynamic++; |
| 315 | |
Tony Lindgren | 9796b32 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 316 | pr_debug("%s: Initialized %s\n", __func__, pad->name); |
| 317 | } |
| 318 | |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 319 | if (!nr_pads_dynamic) |
| 320 | return hmux; |
| 321 | |
| 322 | /* |
| 323 | * Add pads that need dynamic muxing into a separate list |
| 324 | */ |
| 325 | |
| 326 | hmux->nr_pads_dynamic = nr_pads_dynamic; |
| 327 | hmux->pads_dynamic = kzalloc(sizeof(struct omap_device_pad *) * |
| 328 | nr_pads_dynamic, GFP_KERNEL); |
| 329 | if (!hmux->pads_dynamic) { |
| 330 | pr_err("%s: Could not allocate dynamic pads\n", __func__); |
| 331 | return hmux; |
| 332 | } |
| 333 | |
| 334 | nr_pads_dynamic = 0; |
| 335 | for (i = 0; i < hmux->nr_pads; i++) { |
| 336 | struct omap_device_pad *pad = &hmux->pads[i]; |
| 337 | |
Paul Walmsley | 96dc19f | 2011-12-16 14:36:57 -0700 | [diff] [blame] | 338 | if (pad->flags & |
| 339 | (OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP)) { |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 340 | pr_debug("%s: pad %s tagged dynamic\n", |
| 341 | __func__, pad->name); |
| 342 | hmux->pads_dynamic[nr_pads_dynamic] = pad; |
| 343 | nr_pads_dynamic++; |
| 344 | } |
| 345 | } |
| 346 | |
Tony Lindgren | 9796b32 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 347 | return hmux; |
| 348 | |
| 349 | err3: |
| 350 | kfree(hmux->pads); |
| 351 | err2: |
| 352 | kfree(hmux); |
| 353 | err1: |
| 354 | pr_err("%s: Could not allocate device mux entry\n", __func__); |
| 355 | |
| 356 | return NULL; |
| 357 | } |
| 358 | |
Tero Kristo | 13a3fe5 | 2011-12-16 14:36:59 -0700 | [diff] [blame] | 359 | /** |
| 360 | * omap_hwmod_mux_scan_wakeups - omap hwmod scan wakeup pads |
| 361 | * @hmux: Pads for a hwmod |
| 362 | * @mpu_irqs: MPU irq array for a hwmod |
| 363 | * |
| 364 | * Scans the wakeup status of pads for a single hwmod. If an irq |
| 365 | * array is defined for this mux, the parser will call the registered |
| 366 | * ISRs for corresponding pads, otherwise the parser will stop at the |
| 367 | * first wakeup active pad and return. Returns true if there is a |
| 368 | * pending and non-served wakeup event for the mux, otherwise false. |
| 369 | */ |
| 370 | static bool omap_hwmod_mux_scan_wakeups(struct omap_hwmod_mux_info *hmux, |
| 371 | struct omap_hwmod_irq_info *mpu_irqs) |
| 372 | { |
| 373 | int i, irq; |
| 374 | unsigned int val; |
| 375 | u32 handled_irqs = 0; |
| 376 | |
| 377 | for (i = 0; i < hmux->nr_pads_dynamic; i++) { |
| 378 | struct omap_device_pad *pad = hmux->pads_dynamic[i]; |
| 379 | |
| 380 | if (!(pad->flags & OMAP_DEVICE_PAD_WAKEUP) || |
| 381 | !(pad->idle & OMAP_WAKEUP_EN)) |
| 382 | continue; |
| 383 | |
| 384 | val = omap_mux_read(pad->partition, pad->mux->reg_offset); |
| 385 | if (!(val & OMAP_WAKEUP_EVENT)) |
| 386 | continue; |
| 387 | |
| 388 | if (!hmux->irqs) |
| 389 | return true; |
| 390 | |
| 391 | irq = hmux->irqs[i]; |
| 392 | /* make sure we only handle each irq once */ |
| 393 | if (handled_irqs & 1 << irq) |
| 394 | continue; |
| 395 | |
| 396 | handled_irqs |= 1 << irq; |
| 397 | |
| 398 | generic_handle_irq(mpu_irqs[irq].irq); |
| 399 | } |
| 400 | |
| 401 | return false; |
| 402 | } |
| 403 | |
| 404 | /** |
| 405 | * _omap_hwmod_mux_handle_irq - Process wakeup events for a single hwmod |
| 406 | * |
| 407 | * Checks a single hwmod for every wakeup capable pad to see if there is an |
| 408 | * active wakeup event. If this is the case, call the corresponding ISR. |
| 409 | */ |
| 410 | static int _omap_hwmod_mux_handle_irq(struct omap_hwmod *oh, void *data) |
| 411 | { |
| 412 | if (!oh->mux || !oh->mux->enabled) |
| 413 | return 0; |
| 414 | if (omap_hwmod_mux_scan_wakeups(oh->mux, oh->mpu_irqs)) |
| 415 | generic_handle_irq(oh->mpu_irqs[0].irq); |
| 416 | return 0; |
| 417 | } |
| 418 | |
| 419 | /** |
| 420 | * omap_hwmod_mux_handle_irq - Process pad wakeup irqs. |
| 421 | * |
| 422 | * Calls a function for each registered omap_hwmod to check |
| 423 | * pad wakeup statuses. |
| 424 | */ |
| 425 | static irqreturn_t omap_hwmod_mux_handle_irq(int irq, void *unused) |
| 426 | { |
| 427 | omap_hwmod_for_each(_omap_hwmod_mux_handle_irq, NULL); |
| 428 | return IRQ_HANDLED; |
| 429 | } |
| 430 | |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 431 | /* Assumes the calling function takes care of locking */ |
| 432 | void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state) |
| 433 | { |
| 434 | int i; |
| 435 | |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 436 | /* Runtime idling of dynamic pads */ |
| 437 | if (state == _HWMOD_STATE_IDLE && hmux->enabled) { |
| 438 | for (i = 0; i < hmux->nr_pads_dynamic; i++) { |
| 439 | struct omap_device_pad *pad = hmux->pads_dynamic[i]; |
| 440 | int val = -EINVAL; |
| 441 | |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 442 | val = pad->idle; |
| 443 | omap_mux_write(pad->partition, val, |
| 444 | pad->mux->reg_offset); |
| 445 | } |
| 446 | |
| 447 | return; |
| 448 | } |
| 449 | |
| 450 | /* Runtime enabling of dynamic pads */ |
R Sricharan | 86c79bf | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 451 | if ((state == _HWMOD_STATE_ENABLED) && hmux->pads_dynamic |
| 452 | && hmux->enabled) { |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 453 | for (i = 0; i < hmux->nr_pads_dynamic; i++) { |
| 454 | struct omap_device_pad *pad = hmux->pads_dynamic[i]; |
| 455 | int val = -EINVAL; |
| 456 | |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 457 | val = pad->enable; |
| 458 | omap_mux_write(pad->partition, val, |
| 459 | pad->mux->reg_offset); |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 460 | } |
| 461 | |
R Sricharan | 86c79bf | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 462 | return; |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 463 | } |
| 464 | |
| 465 | /* Enabling or disabling of all pads */ |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 466 | for (i = 0; i < hmux->nr_pads; i++) { |
| 467 | struct omap_device_pad *pad = &hmux->pads[i]; |
| 468 | int flags, val = -EINVAL; |
| 469 | |
| 470 | flags = pad->flags; |
| 471 | |
| 472 | switch (state) { |
| 473 | case _HWMOD_STATE_ENABLED: |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 474 | val = pad->enable; |
| 475 | pr_debug("%s: Enabling %s %x\n", __func__, |
| 476 | pad->name, val); |
| 477 | break; |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 478 | case _HWMOD_STATE_DISABLED: |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 479 | /* Use safe mode unless OMAP_DEVICE_PAD_REMUX */ |
| 480 | if (flags & OMAP_DEVICE_PAD_REMUX) |
| 481 | val = pad->off; |
| 482 | else |
| 483 | val = OMAP_MUX_MODE7; |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 484 | pr_debug("%s: Disabling %s %x\n", __func__, |
| 485 | pad->name, val); |
R Sricharan | 86c79bf | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 486 | break; |
| 487 | default: |
| 488 | /* Nothing to be done */ |
| 489 | break; |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 490 | }; |
| 491 | |
| 492 | if (val >= 0) { |
| 493 | omap_mux_write(pad->partition, val, |
| 494 | pad->mux->reg_offset); |
| 495 | pad->flags = flags; |
| 496 | } |
| 497 | } |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame] | 498 | |
| 499 | if (state == _HWMOD_STATE_ENABLED) |
| 500 | hmux->enabled = true; |
| 501 | else |
| 502 | hmux->enabled = false; |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 503 | } |
| 504 | |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 505 | #ifdef CONFIG_DEBUG_FS |
| 506 | |
| 507 | #define OMAP_MUX_MAX_NR_FLAGS 10 |
| 508 | #define OMAP_MUX_TEST_FLAG(val, mask) \ |
| 509 | if (((val) & (mask)) == (mask)) { \ |
| 510 | i++; \ |
| 511 | flags[i] = #mask; \ |
| 512 | } |
| 513 | |
| 514 | /* REVISIT: Add checking for non-optimal mux settings */ |
| 515 | static inline void omap_mux_decode(struct seq_file *s, u16 val) |
| 516 | { |
| 517 | char *flags[OMAP_MUX_MAX_NR_FLAGS]; |
Tony Lindgren | 78737ae | 2010-02-01 13:03:42 -0800 | [diff] [blame] | 518 | char mode[sizeof("OMAP_MUX_MODE") + 1]; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 519 | int i = -1; |
| 520 | |
| 521 | sprintf(mode, "OMAP_MUX_MODE%d", val & 0x7); |
| 522 | i++; |
| 523 | flags[i] = mode; |
| 524 | |
| 525 | OMAP_MUX_TEST_FLAG(val, OMAP_PIN_OFF_WAKEUPENABLE); |
| 526 | if (val & OMAP_OFF_EN) { |
| 527 | if (!(val & OMAP_OFFOUT_EN)) { |
| 528 | if (!(val & OMAP_OFF_PULL_UP)) { |
| 529 | OMAP_MUX_TEST_FLAG(val, |
| 530 | OMAP_PIN_OFF_INPUT_PULLDOWN); |
| 531 | } else { |
| 532 | OMAP_MUX_TEST_FLAG(val, |
| 533 | OMAP_PIN_OFF_INPUT_PULLUP); |
| 534 | } |
| 535 | } else { |
| 536 | if (!(val & OMAP_OFFOUT_VAL)) { |
| 537 | OMAP_MUX_TEST_FLAG(val, |
| 538 | OMAP_PIN_OFF_OUTPUT_LOW); |
| 539 | } else { |
| 540 | OMAP_MUX_TEST_FLAG(val, |
| 541 | OMAP_PIN_OFF_OUTPUT_HIGH); |
| 542 | } |
| 543 | } |
| 544 | } |
| 545 | |
| 546 | if (val & OMAP_INPUT_EN) { |
| 547 | if (val & OMAP_PULL_ENA) { |
| 548 | if (!(val & OMAP_PULL_UP)) { |
| 549 | OMAP_MUX_TEST_FLAG(val, |
| 550 | OMAP_PIN_INPUT_PULLDOWN); |
| 551 | } else { |
| 552 | OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT_PULLUP); |
| 553 | } |
| 554 | } else { |
| 555 | OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT); |
| 556 | } |
| 557 | } else { |
| 558 | i++; |
| 559 | flags[i] = "OMAP_PIN_OUTPUT"; |
| 560 | } |
| 561 | |
| 562 | do { |
| 563 | seq_printf(s, "%s", flags[i]); |
| 564 | if (i > 0) |
| 565 | seq_printf(s, " | "); |
| 566 | } while (i-- > 0); |
| 567 | } |
| 568 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 569 | #define OMAP_MUX_DEFNAME_LEN 32 |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 570 | |
| 571 | static int omap_mux_dbg_board_show(struct seq_file *s, void *unused) |
| 572 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 573 | struct omap_mux_partition *partition = s->private; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 574 | struct omap_mux_entry *e; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 575 | u8 omap_gen = omap_rev() >> 28; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 576 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 577 | list_for_each_entry(e, &partition->muxmodes, node) { |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 578 | struct omap_mux *m = &e->mux; |
| 579 | char m0_def[OMAP_MUX_DEFNAME_LEN]; |
| 580 | char *m0_name = m->muxnames[0]; |
| 581 | u16 val; |
| 582 | int i, mode; |
| 583 | |
| 584 | if (!m0_name) |
| 585 | continue; |
| 586 | |
Tony Lindgren | 78737ae | 2010-02-01 13:03:42 -0800 | [diff] [blame] | 587 | /* REVISIT: Needs to be updated if mode0 names get longer */ |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 588 | for (i = 0; i < OMAP_MUX_DEFNAME_LEN; i++) { |
| 589 | if (m0_name[i] == '\0') { |
| 590 | m0_def[i] = m0_name[i]; |
| 591 | break; |
| 592 | } |
| 593 | m0_def[i] = toupper(m0_name[i]); |
| 594 | } |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 595 | val = omap_mux_read(partition, m->reg_offset); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 596 | mode = val & OMAP_MUX_MODE7; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 597 | if (mode != 0) |
| 598 | seq_printf(s, "/* %s */\n", m->muxnames[mode]); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 599 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 600 | /* |
Lucas De Marchi | 25985ed | 2011-03-30 22:57:33 -0300 | [diff] [blame] | 601 | * XXX: Might be revisited to support differences across |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 602 | * same OMAP generation. |
| 603 | */ |
| 604 | seq_printf(s, "OMAP%d_MUX(%s, ", omap_gen, m0_def); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 605 | omap_mux_decode(s, val); |
| 606 | seq_printf(s, "),\n"); |
| 607 | } |
| 608 | |
| 609 | return 0; |
| 610 | } |
| 611 | |
| 612 | static int omap_mux_dbg_board_open(struct inode *inode, struct file *file) |
| 613 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 614 | return single_open(file, omap_mux_dbg_board_show, inode->i_private); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 615 | } |
| 616 | |
| 617 | static const struct file_operations omap_mux_dbg_board_fops = { |
| 618 | .open = omap_mux_dbg_board_open, |
| 619 | .read = seq_read, |
| 620 | .llseek = seq_lseek, |
| 621 | .release = single_release, |
| 622 | }; |
| 623 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 624 | static struct omap_mux_partition *omap_mux_get_partition(struct omap_mux *mux) |
| 625 | { |
| 626 | struct omap_mux_partition *partition; |
| 627 | |
| 628 | list_for_each_entry(partition, &mux_partitions, node) { |
| 629 | struct list_head *muxmodes = &partition->muxmodes; |
| 630 | struct omap_mux_entry *e; |
| 631 | |
| 632 | list_for_each_entry(e, muxmodes, node) { |
| 633 | struct omap_mux *m = &e->mux; |
| 634 | |
| 635 | if (m == mux) |
| 636 | return partition; |
| 637 | } |
| 638 | } |
| 639 | |
| 640 | return NULL; |
| 641 | } |
| 642 | |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 643 | static int omap_mux_dbg_signal_show(struct seq_file *s, void *unused) |
| 644 | { |
| 645 | struct omap_mux *m = s->private; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 646 | struct omap_mux_partition *partition; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 647 | const char *none = "NA"; |
| 648 | u16 val; |
| 649 | int mode; |
| 650 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 651 | partition = omap_mux_get_partition(m); |
| 652 | if (!partition) |
| 653 | return 0; |
| 654 | |
| 655 | val = omap_mux_read(partition, m->reg_offset); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 656 | mode = val & OMAP_MUX_MODE7; |
| 657 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 658 | seq_printf(s, "name: %s.%s (0x%08x/0x%03x = 0x%04x), b %s, t %s\n", |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 659 | m->muxnames[0], m->muxnames[mode], |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 660 | partition->phys + m->reg_offset, m->reg_offset, val, |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 661 | m->balls[0] ? m->balls[0] : none, |
| 662 | m->balls[1] ? m->balls[1] : none); |
| 663 | seq_printf(s, "mode: "); |
| 664 | omap_mux_decode(s, val); |
| 665 | seq_printf(s, "\n"); |
| 666 | seq_printf(s, "signals: %s | %s | %s | %s | %s | %s | %s | %s\n", |
| 667 | m->muxnames[0] ? m->muxnames[0] : none, |
| 668 | m->muxnames[1] ? m->muxnames[1] : none, |
| 669 | m->muxnames[2] ? m->muxnames[2] : none, |
| 670 | m->muxnames[3] ? m->muxnames[3] : none, |
| 671 | m->muxnames[4] ? m->muxnames[4] : none, |
| 672 | m->muxnames[5] ? m->muxnames[5] : none, |
| 673 | m->muxnames[6] ? m->muxnames[6] : none, |
| 674 | m->muxnames[7] ? m->muxnames[7] : none); |
| 675 | |
| 676 | return 0; |
| 677 | } |
| 678 | |
| 679 | #define OMAP_MUX_MAX_ARG_CHAR 7 |
| 680 | |
| 681 | static ssize_t omap_mux_dbg_signal_write(struct file *file, |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 682 | const char __user *user_buf, |
| 683 | size_t count, loff_t *ppos) |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 684 | { |
| 685 | char buf[OMAP_MUX_MAX_ARG_CHAR]; |
| 686 | struct seq_file *seqf; |
| 687 | struct omap_mux *m; |
| 688 | unsigned long val; |
| 689 | int buf_size, ret; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 690 | struct omap_mux_partition *partition; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 691 | |
| 692 | if (count > OMAP_MUX_MAX_ARG_CHAR) |
| 693 | return -EINVAL; |
| 694 | |
| 695 | memset(buf, 0, sizeof(buf)); |
| 696 | buf_size = min(count, sizeof(buf) - 1); |
| 697 | |
| 698 | if (copy_from_user(buf, user_buf, buf_size)) |
| 699 | return -EFAULT; |
| 700 | |
| 701 | ret = strict_strtoul(buf, 0x10, &val); |
| 702 | if (ret < 0) |
| 703 | return ret; |
| 704 | |
| 705 | if (val > 0xffff) |
| 706 | return -EINVAL; |
| 707 | |
| 708 | seqf = file->private_data; |
| 709 | m = seqf->private; |
| 710 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 711 | partition = omap_mux_get_partition(m); |
| 712 | if (!partition) |
| 713 | return -ENODEV; |
| 714 | |
| 715 | omap_mux_write(partition, (u16)val, m->reg_offset); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 716 | *ppos += count; |
| 717 | |
| 718 | return count; |
| 719 | } |
| 720 | |
| 721 | static int omap_mux_dbg_signal_open(struct inode *inode, struct file *file) |
| 722 | { |
| 723 | return single_open(file, omap_mux_dbg_signal_show, inode->i_private); |
| 724 | } |
| 725 | |
| 726 | static const struct file_operations omap_mux_dbg_signal_fops = { |
| 727 | .open = omap_mux_dbg_signal_open, |
| 728 | .read = seq_read, |
| 729 | .write = omap_mux_dbg_signal_write, |
| 730 | .llseek = seq_lseek, |
| 731 | .release = single_release, |
| 732 | }; |
| 733 | |
| 734 | static struct dentry *mux_dbg_dir; |
| 735 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 736 | static void __init omap_mux_dbg_create_entry( |
| 737 | struct omap_mux_partition *partition, |
| 738 | struct dentry *mux_dbg_dir) |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 739 | { |
| 740 | struct omap_mux_entry *e; |
| 741 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 742 | list_for_each_entry(e, &partition->muxmodes, node) { |
| 743 | struct omap_mux *m = &e->mux; |
| 744 | |
Vasiliy Kulikov | 9b12771 | 2011-02-04 12:23:13 +0000 | [diff] [blame] | 745 | (void)debugfs_create_file(m->muxnames[0], S_IWUSR, mux_dbg_dir, |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 746 | m, &omap_mux_dbg_signal_fops); |
| 747 | } |
| 748 | } |
| 749 | |
| 750 | static void __init omap_mux_dbg_init(void) |
| 751 | { |
| 752 | struct omap_mux_partition *partition; |
| 753 | static struct dentry *mux_dbg_board_dir; |
| 754 | |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 755 | mux_dbg_dir = debugfs_create_dir("omap_mux", NULL); |
| 756 | if (!mux_dbg_dir) |
| 757 | return; |
| 758 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 759 | mux_dbg_board_dir = debugfs_create_dir("board", mux_dbg_dir); |
| 760 | if (!mux_dbg_board_dir) |
| 761 | return; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 762 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 763 | list_for_each_entry(partition, &mux_partitions, node) { |
| 764 | omap_mux_dbg_create_entry(partition, mux_dbg_dir); |
| 765 | (void)debugfs_create_file(partition->name, S_IRUGO, |
| 766 | mux_dbg_board_dir, partition, |
| 767 | &omap_mux_dbg_board_fops); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 768 | } |
| 769 | } |
| 770 | |
| 771 | #else |
| 772 | static inline void omap_mux_dbg_init(void) |
| 773 | { |
| 774 | } |
| 775 | #endif /* CONFIG_DEBUG_FS */ |
| 776 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 777 | static void __init omap_mux_free_names(struct omap_mux *m) |
| 778 | { |
| 779 | int i; |
| 780 | |
| 781 | for (i = 0; i < OMAP_MUX_NR_MODES; i++) |
| 782 | kfree(m->muxnames[i]); |
| 783 | |
| 784 | #ifdef CONFIG_DEBUG_FS |
| 785 | for (i = 0; i < OMAP_MUX_NR_SIDES; i++) |
| 786 | kfree(m->balls[i]); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 787 | #endif |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 788 | |
| 789 | } |
| 790 | |
| 791 | /* Free all data except for GPIO pins unless CONFIG_DEBUG_FS is set */ |
| 792 | static int __init omap_mux_late_init(void) |
| 793 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 794 | struct omap_mux_partition *partition; |
Tero Kristo | 13a3fe5 | 2011-12-16 14:36:59 -0700 | [diff] [blame] | 795 | int ret; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 796 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 797 | list_for_each_entry(partition, &mux_partitions, node) { |
| 798 | struct omap_mux_entry *e, *tmp; |
| 799 | list_for_each_entry_safe(e, tmp, &partition->muxmodes, node) { |
| 800 | struct omap_mux *m = &e->mux; |
| 801 | u16 mode = omap_mux_read(partition, m->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 802 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 803 | if (OMAP_MODE_GPIO(mode)) |
| 804 | continue; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 805 | |
| 806 | #ifndef CONFIG_DEBUG_FS |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 807 | mutex_lock(&muxmode_mutex); |
| 808 | list_del(&e->node); |
| 809 | mutex_unlock(&muxmode_mutex); |
| 810 | omap_mux_free_names(m); |
| 811 | kfree(m); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 812 | #endif |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 813 | } |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 814 | } |
| 815 | |
Tero Kristo | 13a3fe5 | 2011-12-16 14:36:59 -0700 | [diff] [blame] | 816 | ret = request_irq(omap_prcm_event_to_irq("io"), |
| 817 | omap_hwmod_mux_handle_irq, IRQF_SHARED | IRQF_NO_SUSPEND, |
| 818 | "hwmod_io", omap_mux_late_init); |
| 819 | |
| 820 | if (ret) |
| 821 | pr_warning("mux: Failed to setup hwmod io irq %d\n", ret); |
| 822 | |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 823 | omap_mux_dbg_init(); |
| 824 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 825 | return 0; |
| 826 | } |
| 827 | late_initcall(omap_mux_late_init); |
| 828 | |
| 829 | static void __init omap_mux_package_fixup(struct omap_mux *p, |
| 830 | struct omap_mux *superset) |
| 831 | { |
| 832 | while (p->reg_offset != OMAP_MUX_TERMINATOR) { |
| 833 | struct omap_mux *s = superset; |
| 834 | int found = 0; |
| 835 | |
| 836 | while (s->reg_offset != OMAP_MUX_TERMINATOR) { |
| 837 | if (s->reg_offset == p->reg_offset) { |
| 838 | *s = *p; |
| 839 | found++; |
| 840 | break; |
| 841 | } |
| 842 | s++; |
| 843 | } |
| 844 | if (!found) |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 845 | pr_err("%s: Unknown entry offset 0x%x\n", __func__, |
Benoit Cousson | 1cbb3a9 | 2010-08-10 17:33:01 +0200 | [diff] [blame] | 846 | p->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 847 | p++; |
| 848 | } |
| 849 | } |
| 850 | |
| 851 | #ifdef CONFIG_DEBUG_FS |
| 852 | |
| 853 | static void __init omap_mux_package_init_balls(struct omap_ball *b, |
| 854 | struct omap_mux *superset) |
| 855 | { |
| 856 | while (b->reg_offset != OMAP_MUX_TERMINATOR) { |
| 857 | struct omap_mux *s = superset; |
| 858 | int found = 0; |
| 859 | |
| 860 | while (s->reg_offset != OMAP_MUX_TERMINATOR) { |
| 861 | if (s->reg_offset == b->reg_offset) { |
| 862 | s->balls[0] = b->balls[0]; |
| 863 | s->balls[1] = b->balls[1]; |
| 864 | found++; |
| 865 | break; |
| 866 | } |
| 867 | s++; |
| 868 | } |
| 869 | if (!found) |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 870 | pr_err("%s: Unknown ball offset 0x%x\n", __func__, |
Benoit Cousson | 1cbb3a9 | 2010-08-10 17:33:01 +0200 | [diff] [blame] | 871 | b->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 872 | b++; |
| 873 | } |
| 874 | } |
| 875 | |
| 876 | #else /* CONFIG_DEBUG_FS */ |
| 877 | |
| 878 | static inline void omap_mux_package_init_balls(struct omap_ball *b, |
| 879 | struct omap_mux *superset) |
| 880 | { |
| 881 | } |
| 882 | |
| 883 | #endif /* CONFIG_DEBUG_FS */ |
| 884 | |
| 885 | static int __init omap_mux_setup(char *options) |
| 886 | { |
| 887 | if (!options) |
| 888 | return 0; |
| 889 | |
| 890 | omap_mux_options = options; |
| 891 | |
| 892 | return 1; |
| 893 | } |
| 894 | __setup("omap_mux=", omap_mux_setup); |
| 895 | |
| 896 | /* |
| 897 | * Note that the omap_mux=some.signal1=0x1234,some.signal2=0x1234 |
| 898 | * cmdline options only override the bootloader values. |
| 899 | * During development, please enable CONFIG_DEBUG_FS, and use the |
| 900 | * signal specific entries under debugfs. |
| 901 | */ |
| 902 | static void __init omap_mux_set_cmdline_signals(void) |
| 903 | { |
| 904 | char *options, *next_opt, *token; |
| 905 | |
| 906 | if (!omap_mux_options) |
| 907 | return; |
| 908 | |
Thomas Meyer | dccb3b0 | 2011-08-06 09:29:10 +0000 | [diff] [blame] | 909 | options = kstrdup(omap_mux_options, GFP_KERNEL); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 910 | if (!options) |
| 911 | return; |
| 912 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 913 | next_opt = options; |
| 914 | |
| 915 | while ((token = strsep(&next_opt, ",")) != NULL) { |
| 916 | char *keyval, *name; |
| 917 | unsigned long val; |
| 918 | |
| 919 | keyval = token; |
| 920 | name = strsep(&keyval, "="); |
| 921 | if (name) { |
| 922 | int res; |
| 923 | |
| 924 | res = strict_strtoul(keyval, 0x10, &val); |
| 925 | if (res < 0) |
| 926 | continue; |
| 927 | |
| 928 | omap_mux_init_signal(name, (u16)val); |
| 929 | } |
| 930 | } |
| 931 | |
| 932 | kfree(options); |
| 933 | } |
| 934 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 935 | static int __init omap_mux_copy_names(struct omap_mux *src, |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 936 | struct omap_mux *dst) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 937 | { |
| 938 | int i; |
| 939 | |
| 940 | for (i = 0; i < OMAP_MUX_NR_MODES; i++) { |
| 941 | if (src->muxnames[i]) { |
Thomas Meyer | dccb3b0 | 2011-08-06 09:29:10 +0000 | [diff] [blame] | 942 | dst->muxnames[i] = kstrdup(src->muxnames[i], |
| 943 | GFP_KERNEL); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 944 | if (!dst->muxnames[i]) |
| 945 | goto free; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 946 | } |
| 947 | } |
| 948 | |
| 949 | #ifdef CONFIG_DEBUG_FS |
| 950 | for (i = 0; i < OMAP_MUX_NR_SIDES; i++) { |
| 951 | if (src->balls[i]) { |
Thomas Meyer | dccb3b0 | 2011-08-06 09:29:10 +0000 | [diff] [blame] | 952 | dst->balls[i] = kstrdup(src->balls[i], GFP_KERNEL); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 953 | if (!dst->balls[i]) |
| 954 | goto free; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 955 | } |
| 956 | } |
| 957 | #endif |
| 958 | |
| 959 | return 0; |
| 960 | |
| 961 | free: |
| 962 | omap_mux_free_names(dst); |
| 963 | return -ENOMEM; |
| 964 | |
| 965 | } |
| 966 | |
| 967 | #endif /* CONFIG_OMAP_MUX */ |
| 968 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 969 | static struct omap_mux *omap_mux_get_by_gpio( |
| 970 | struct omap_mux_partition *partition, |
| 971 | int gpio) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 972 | { |
| 973 | struct omap_mux_entry *e; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 974 | struct omap_mux *ret = NULL; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 975 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 976 | list_for_each_entry(e, &partition->muxmodes, node) { |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 977 | struct omap_mux *m = &e->mux; |
| 978 | if (m->gpio == gpio) { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 979 | ret = m; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 980 | break; |
| 981 | } |
| 982 | } |
| 983 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 984 | return ret; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 985 | } |
| 986 | |
| 987 | /* Needed for dynamic muxing of GPIO pins for off-idle */ |
| 988 | u16 omap_mux_get_gpio(int gpio) |
| 989 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 990 | struct omap_mux_partition *partition; |
Govindraj.R | 30ebad9 | 2011-06-01 11:28:56 +0530 | [diff] [blame] | 991 | struct omap_mux *m = NULL; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 992 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 993 | list_for_each_entry(partition, &mux_partitions, node) { |
| 994 | m = omap_mux_get_by_gpio(partition, gpio); |
| 995 | if (m) |
| 996 | return omap_mux_read(partition, m->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 997 | } |
| 998 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 999 | if (!m || m->reg_offset == OMAP_MUX_TERMINATOR) |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 1000 | pr_err("%s: Could not get gpio%i\n", __func__, gpio); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1001 | |
| 1002 | return OMAP_MUX_TERMINATOR; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1003 | } |
| 1004 | |
| 1005 | /* Needed for dynamic muxing of GPIO pins for off-idle */ |
| 1006 | void omap_mux_set_gpio(u16 val, int gpio) |
| 1007 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1008 | struct omap_mux_partition *partition; |
| 1009 | struct omap_mux *m = NULL; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1010 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1011 | list_for_each_entry(partition, &mux_partitions, node) { |
| 1012 | m = omap_mux_get_by_gpio(partition, gpio); |
| 1013 | if (m) { |
| 1014 | omap_mux_write(partition, val, m->reg_offset); |
| 1015 | return; |
| 1016 | } |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1017 | } |
| 1018 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1019 | if (!m || m->reg_offset == OMAP_MUX_TERMINATOR) |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 1020 | pr_err("%s: Could not set gpio%i\n", __func__, gpio); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1021 | } |
| 1022 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1023 | static struct omap_mux * __init omap_mux_list_add( |
| 1024 | struct omap_mux_partition *partition, |
| 1025 | struct omap_mux *src) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1026 | { |
| 1027 | struct omap_mux_entry *entry; |
| 1028 | struct omap_mux *m; |
| 1029 | |
| 1030 | entry = kzalloc(sizeof(struct omap_mux_entry), GFP_KERNEL); |
| 1031 | if (!entry) |
| 1032 | return NULL; |
| 1033 | |
| 1034 | m = &entry->mux; |
Aaro Koskinen | 3083314 | 2011-01-06 19:49:28 -0800 | [diff] [blame] | 1035 | entry->mux = *src; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1036 | |
| 1037 | #ifdef CONFIG_OMAP_MUX |
| 1038 | if (omap_mux_copy_names(src, m)) { |
| 1039 | kfree(entry); |
| 1040 | return NULL; |
| 1041 | } |
| 1042 | #endif |
| 1043 | |
| 1044 | mutex_lock(&muxmode_mutex); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1045 | list_add_tail(&entry->node, &partition->muxmodes); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1046 | mutex_unlock(&muxmode_mutex); |
| 1047 | |
| 1048 | return m; |
| 1049 | } |
| 1050 | |
| 1051 | /* |
| 1052 | * Note if CONFIG_OMAP_MUX is not selected, we will only initialize |
| 1053 | * the GPIO to mux offset mapping that is needed for dynamic muxing |
| 1054 | * of GPIO pins for off-idle. |
| 1055 | */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1056 | static void __init omap_mux_init_list(struct omap_mux_partition *partition, |
| 1057 | struct omap_mux *superset) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1058 | { |
| 1059 | while (superset->reg_offset != OMAP_MUX_TERMINATOR) { |
| 1060 | struct omap_mux *entry; |
| 1061 | |
Ranjith Lohithakshan | b72c7d5 | 2010-02-17 17:17:01 +0000 | [diff] [blame] | 1062 | #ifdef CONFIG_OMAP_MUX |
| 1063 | if (!superset->muxnames || !superset->muxnames[0]) { |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1064 | superset++; |
| 1065 | continue; |
| 1066 | } |
Ranjith Lohithakshan | b72c7d5 | 2010-02-17 17:17:01 +0000 | [diff] [blame] | 1067 | #else |
| 1068 | /* Skip pins that are not muxed as GPIO by bootloader */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1069 | if (!OMAP_MODE_GPIO(omap_mux_read(partition, |
| 1070 | superset->reg_offset))) { |
Tony Lindgren | 9ecef43 | 2010-02-01 11:22:54 -0800 | [diff] [blame] | 1071 | superset++; |
| 1072 | continue; |
| 1073 | } |
| 1074 | #endif |
| 1075 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1076 | entry = omap_mux_list_add(partition, superset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1077 | if (!entry) { |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 1078 | pr_err("%s: Could not add entry\n", __func__); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1079 | return; |
| 1080 | } |
| 1081 | superset++; |
| 1082 | } |
| 1083 | } |
| 1084 | |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 1085 | #ifdef CONFIG_OMAP_MUX |
| 1086 | |
| 1087 | static void omap_mux_init_package(struct omap_mux *superset, |
| 1088 | struct omap_mux *package_subset, |
| 1089 | struct omap_ball *package_balls) |
| 1090 | { |
| 1091 | if (package_subset) |
| 1092 | omap_mux_package_fixup(package_subset, superset); |
| 1093 | if (package_balls) |
| 1094 | omap_mux_package_init_balls(package_balls, superset); |
| 1095 | } |
| 1096 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1097 | static void omap_mux_init_signals(struct omap_mux_partition *partition, |
| 1098 | struct omap_board_mux *board_mux) |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 1099 | { |
| 1100 | omap_mux_set_cmdline_signals(); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1101 | omap_mux_write_array(partition, board_mux); |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 1102 | } |
| 1103 | |
| 1104 | #else |
| 1105 | |
| 1106 | static void omap_mux_init_package(struct omap_mux *superset, |
| 1107 | struct omap_mux *package_subset, |
| 1108 | struct omap_ball *package_balls) |
| 1109 | { |
| 1110 | } |
| 1111 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1112 | static void omap_mux_init_signals(struct omap_mux_partition *partition, |
| 1113 | struct omap_board_mux *board_mux) |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 1114 | { |
| 1115 | } |
| 1116 | |
| 1117 | #endif |
| 1118 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1119 | static u32 mux_partitions_cnt; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1120 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1121 | int __init omap_mux_init(const char *name, u32 flags, |
| 1122 | u32 mux_pbase, u32 mux_size, |
| 1123 | struct omap_mux *superset, |
| 1124 | struct omap_mux *package_subset, |
| 1125 | struct omap_board_mux *board_mux, |
| 1126 | struct omap_ball *package_balls) |
| 1127 | { |
| 1128 | struct omap_mux_partition *partition; |
| 1129 | |
| 1130 | partition = kzalloc(sizeof(struct omap_mux_partition), GFP_KERNEL); |
| 1131 | if (!partition) |
| 1132 | return -ENOMEM; |
| 1133 | |
| 1134 | partition->name = name; |
| 1135 | partition->flags = flags; |
| 1136 | partition->size = mux_size; |
| 1137 | partition->phys = mux_pbase; |
| 1138 | partition->base = ioremap(mux_pbase, mux_size); |
| 1139 | if (!partition->base) { |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 1140 | pr_err("%s: Could not ioremap mux partition at 0x%08x\n", |
| 1141 | __func__, partition->phys); |
Aaro Koskinen | 9d47e30 | 2011-01-28 14:50:55 +0000 | [diff] [blame] | 1142 | kfree(partition); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1143 | return -ENODEV; |
| 1144 | } |
| 1145 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1146 | INIT_LIST_HEAD(&partition->muxmodes); |
| 1147 | |
| 1148 | list_add_tail(&partition->node, &mux_partitions); |
| 1149 | mux_partitions_cnt++; |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 1150 | pr_info("%s: Add partition: #%d: %s, flags: %x\n", __func__, |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1151 | mux_partitions_cnt, partition->name, partition->flags); |
Tony Lindgren | d5425be | 2010-07-05 16:31:35 +0300 | [diff] [blame] | 1152 | |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 1153 | omap_mux_init_package(superset, package_subset, package_balls); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1154 | omap_mux_init_list(partition, superset); |
| 1155 | omap_mux_init_signals(partition, board_mux); |
Tony Lindgren | 2cb0c54 | 2010-01-19 18:17:07 -0800 | [diff] [blame] | 1156 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1157 | return 0; |
| 1158 | } |
| 1159 | |