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> |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 35 | |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 36 | #include <asm/system.h> |
| 37 | |
Paul Walmsley | 4814ced | 2010-10-08 11:40:20 -0600 | [diff] [blame] | 38 | #include "control.h" |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 39 | #include "mux.h" |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 40 | |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 41 | #define OMAP_MUX_BASE_OFFSET 0x30 /* Offset from CTRL_BASE */ |
| 42 | #define OMAP_MUX_BASE_SZ 0x5ca |
| 43 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 44 | struct omap_mux_entry { |
| 45 | struct omap_mux mux; |
| 46 | struct list_head node; |
| 47 | }; |
| 48 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 49 | static LIST_HEAD(mux_partitions); |
| 50 | static DEFINE_MUTEX(muxmode_mutex); |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 51 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 52 | struct omap_mux_partition *omap_mux_get(const char *name) |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 53 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 54 | struct omap_mux_partition *partition; |
| 55 | |
| 56 | list_for_each_entry(partition, &mux_partitions, node) { |
| 57 | if (!strcmp(name, partition->name)) |
| 58 | return partition; |
| 59 | } |
| 60 | |
| 61 | return NULL; |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 62 | } |
| 63 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 64 | u16 omap_mux_read(struct omap_mux_partition *partition, u16 reg) |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 65 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 66 | if (partition->flags & OMAP_MUX_REG_8BIT) |
| 67 | return __raw_readb(partition->base + reg); |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 68 | else |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 69 | return __raw_readw(partition->base + reg); |
Mike Rapoport | 92c9f50 | 2009-12-11 16:16:31 -0800 | [diff] [blame] | 70 | } |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame] | 71 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 72 | void omap_mux_write(struct omap_mux_partition *partition, u16 val, |
| 73 | u16 reg) |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 74 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 75 | if (partition->flags & OMAP_MUX_REG_8BIT) |
| 76 | __raw_writeb(val, partition->base + reg); |
| 77 | else |
| 78 | __raw_writew(val, partition->base + reg); |
| 79 | } |
| 80 | |
| 81 | void omap_mux_write_array(struct omap_mux_partition *partition, |
| 82 | struct omap_board_mux *board_mux) |
| 83 | { |
| 84 | while (board_mux->reg_offset != OMAP_MUX_TERMINATOR) { |
| 85 | omap_mux_write(partition, board_mux->value, |
| 86 | board_mux->reg_offset); |
Tony Lindgren | d4bb72e | 2010-01-19 15:15:24 -0800 | [diff] [blame] | 87 | board_mux++; |
| 88 | } |
| 89 | } |
| 90 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 91 | #ifdef CONFIG_OMAP_MUX |
| 92 | |
| 93 | static char *omap_mux_options; |
| 94 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 95 | static int __init _omap_mux_init_gpio(struct omap_mux_partition *partition, |
| 96 | int gpio, int val) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 97 | { |
| 98 | struct omap_mux_entry *e; |
Sanjeev Premi | ca82876 | 2010-09-23 18:27:18 -0700 | [diff] [blame] | 99 | struct omap_mux *gpio_mux = NULL; |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 100 | u16 old_mode; |
| 101 | u16 mux_mode; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 102 | int found = 0; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 103 | struct list_head *muxmodes = &partition->muxmodes; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 104 | |
| 105 | if (!gpio) |
| 106 | return -EINVAL; |
| 107 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 108 | list_for_each_entry(e, muxmodes, node) { |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 109 | struct omap_mux *m = &e->mux; |
| 110 | if (gpio == m->gpio) { |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 111 | gpio_mux = m; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 112 | found++; |
| 113 | } |
| 114 | } |
| 115 | |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 116 | if (found == 0) { |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame^] | 117 | pr_err("%s: Could not set gpio%i\n", __func__, gpio); |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 118 | return -ENODEV; |
| 119 | } |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 120 | |
| 121 | if (found > 1) { |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame^] | 122 | pr_info("%s: Multiple gpio paths (%d) for gpio%i\n", __func__, |
Benoit Cousson | 1cbb3a9 | 2010-08-10 17:33:01 +0200 | [diff] [blame] | 123 | found, gpio); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 124 | return -EINVAL; |
| 125 | } |
| 126 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 127 | old_mode = omap_mux_read(partition, gpio_mux->reg_offset); |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 128 | mux_mode = val & ~(OMAP_MUX_NR_MODES - 1); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 129 | if (partition->flags & OMAP_MUX_GPIO_IN_MODE3) |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 130 | mux_mode |= OMAP_MUX_MODE3; |
| 131 | else |
| 132 | mux_mode |= OMAP_MUX_MODE4; |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame^] | 133 | 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] | 134 | gpio_mux->muxnames[0], gpio, old_mode, mux_mode); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 135 | omap_mux_write(partition, mux_mode, gpio_mux->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 136 | |
Grazvydas Ignotas | 8a6f7e1 | 2010-08-02 13:18:28 +0300 | [diff] [blame] | 137 | return 0; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 138 | } |
| 139 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 140 | int __init omap_mux_init_gpio(int gpio, int val) |
| 141 | { |
| 142 | struct omap_mux_partition *partition; |
| 143 | int ret; |
| 144 | |
| 145 | list_for_each_entry(partition, &mux_partitions, node) { |
| 146 | ret = _omap_mux_init_gpio(partition, gpio, val); |
| 147 | if (!ret) |
| 148 | return ret; |
| 149 | } |
| 150 | |
| 151 | return -ENODEV; |
| 152 | } |
| 153 | |
| 154 | static int __init _omap_mux_init_signal(struct omap_mux_partition *partition, |
| 155 | const char *muxname, int val) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 156 | { |
| 157 | struct omap_mux_entry *e; |
Tony Lindgren | 5a3b2f7 | 2010-10-01 16:35:24 -0700 | [diff] [blame] | 158 | const char *mode_name; |
| 159 | int found = 0, mode0_len = 0; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 160 | struct list_head *muxmodes = &partition->muxmodes; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 161 | |
| 162 | mode_name = strchr(muxname, '.'); |
| 163 | if (mode_name) { |
Tony Lindgren | 5a3b2f7 | 2010-10-01 16:35:24 -0700 | [diff] [blame] | 164 | mode0_len = strlen(muxname) - strlen(mode_name); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 165 | mode_name++; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 166 | } else { |
| 167 | mode_name = muxname; |
| 168 | } |
| 169 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 170 | list_for_each_entry(e, muxmodes, node) { |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 171 | struct omap_mux *m = &e->mux; |
| 172 | char *m0_entry = m->muxnames[0]; |
| 173 | int i; |
| 174 | |
Tony Lindgren | 5a3b2f7 | 2010-10-01 16:35:24 -0700 | [diff] [blame] | 175 | /* First check for full name in mode0.muxmode format */ |
| 176 | if (mode0_len && strncmp(muxname, m0_entry, mode0_len)) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 177 | continue; |
| 178 | |
Tony Lindgren | 5a3b2f7 | 2010-10-01 16:35:24 -0700 | [diff] [blame] | 179 | /* Then check for muxmode only */ |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 180 | for (i = 0; i < OMAP_MUX_NR_MODES; i++) { |
| 181 | char *mode_cur = m->muxnames[i]; |
| 182 | |
| 183 | if (!mode_cur) |
| 184 | continue; |
| 185 | |
| 186 | if (!strcmp(mode_name, mode_cur)) { |
| 187 | u16 old_mode; |
| 188 | u16 mux_mode; |
| 189 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 190 | old_mode = omap_mux_read(partition, |
| 191 | m->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 192 | mux_mode = val | i; |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame^] | 193 | pr_debug("%s: Setting signal " |
| 194 | "%s.%s 0x%04x -> 0x%04x\n", __func__, |
Benoit Cousson | 1cbb3a9 | 2010-08-10 17:33:01 +0200 | [diff] [blame] | 195 | m0_entry, muxname, old_mode, mux_mode); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 196 | omap_mux_write(partition, mux_mode, |
| 197 | m->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 198 | found++; |
| 199 | } |
| 200 | } |
| 201 | } |
| 202 | |
| 203 | if (found == 1) |
| 204 | return 0; |
| 205 | |
| 206 | if (found > 1) { |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame^] | 207 | pr_err("%s: Multiple signal paths (%i) for %s\n", __func__, |
Benoit Cousson | 1cbb3a9 | 2010-08-10 17:33:01 +0200 | [diff] [blame] | 208 | found, muxname); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 209 | return -EINVAL; |
| 210 | } |
| 211 | |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame^] | 212 | pr_err("%s: Could not set signal %s\n", __func__, muxname); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 213 | |
| 214 | return -ENODEV; |
| 215 | } |
| 216 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 217 | int __init omap_mux_init_signal(const char *muxname, int val) |
| 218 | { |
| 219 | struct omap_mux_partition *partition; |
| 220 | int ret; |
| 221 | |
| 222 | list_for_each_entry(partition, &mux_partitions, node) { |
| 223 | ret = _omap_mux_init_signal(partition, muxname, val); |
| 224 | if (!ret) |
| 225 | return ret; |
| 226 | } |
| 227 | |
| 228 | return -ENODEV; |
| 229 | |
| 230 | } |
| 231 | |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 232 | #ifdef CONFIG_DEBUG_FS |
| 233 | |
| 234 | #define OMAP_MUX_MAX_NR_FLAGS 10 |
| 235 | #define OMAP_MUX_TEST_FLAG(val, mask) \ |
| 236 | if (((val) & (mask)) == (mask)) { \ |
| 237 | i++; \ |
| 238 | flags[i] = #mask; \ |
| 239 | } |
| 240 | |
| 241 | /* REVISIT: Add checking for non-optimal mux settings */ |
| 242 | static inline void omap_mux_decode(struct seq_file *s, u16 val) |
| 243 | { |
| 244 | char *flags[OMAP_MUX_MAX_NR_FLAGS]; |
Tony Lindgren | 78737ae | 2010-02-01 13:03:42 -0800 | [diff] [blame] | 245 | char mode[sizeof("OMAP_MUX_MODE") + 1]; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 246 | int i = -1; |
| 247 | |
| 248 | sprintf(mode, "OMAP_MUX_MODE%d", val & 0x7); |
| 249 | i++; |
| 250 | flags[i] = mode; |
| 251 | |
| 252 | OMAP_MUX_TEST_FLAG(val, OMAP_PIN_OFF_WAKEUPENABLE); |
| 253 | if (val & OMAP_OFF_EN) { |
| 254 | if (!(val & OMAP_OFFOUT_EN)) { |
| 255 | if (!(val & OMAP_OFF_PULL_UP)) { |
| 256 | OMAP_MUX_TEST_FLAG(val, |
| 257 | OMAP_PIN_OFF_INPUT_PULLDOWN); |
| 258 | } else { |
| 259 | OMAP_MUX_TEST_FLAG(val, |
| 260 | OMAP_PIN_OFF_INPUT_PULLUP); |
| 261 | } |
| 262 | } else { |
| 263 | if (!(val & OMAP_OFFOUT_VAL)) { |
| 264 | OMAP_MUX_TEST_FLAG(val, |
| 265 | OMAP_PIN_OFF_OUTPUT_LOW); |
| 266 | } else { |
| 267 | OMAP_MUX_TEST_FLAG(val, |
| 268 | OMAP_PIN_OFF_OUTPUT_HIGH); |
| 269 | } |
| 270 | } |
| 271 | } |
| 272 | |
| 273 | if (val & OMAP_INPUT_EN) { |
| 274 | if (val & OMAP_PULL_ENA) { |
| 275 | if (!(val & OMAP_PULL_UP)) { |
| 276 | OMAP_MUX_TEST_FLAG(val, |
| 277 | OMAP_PIN_INPUT_PULLDOWN); |
| 278 | } else { |
| 279 | OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT_PULLUP); |
| 280 | } |
| 281 | } else { |
| 282 | OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT); |
| 283 | } |
| 284 | } else { |
| 285 | i++; |
| 286 | flags[i] = "OMAP_PIN_OUTPUT"; |
| 287 | } |
| 288 | |
| 289 | do { |
| 290 | seq_printf(s, "%s", flags[i]); |
| 291 | if (i > 0) |
| 292 | seq_printf(s, " | "); |
| 293 | } while (i-- > 0); |
| 294 | } |
| 295 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 296 | #define OMAP_MUX_DEFNAME_LEN 32 |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 297 | |
| 298 | static int omap_mux_dbg_board_show(struct seq_file *s, void *unused) |
| 299 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 300 | struct omap_mux_partition *partition = s->private; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 301 | struct omap_mux_entry *e; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 302 | u8 omap_gen = omap_rev() >> 28; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 303 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 304 | list_for_each_entry(e, &partition->muxmodes, node) { |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 305 | struct omap_mux *m = &e->mux; |
| 306 | char m0_def[OMAP_MUX_DEFNAME_LEN]; |
| 307 | char *m0_name = m->muxnames[0]; |
| 308 | u16 val; |
| 309 | int i, mode; |
| 310 | |
| 311 | if (!m0_name) |
| 312 | continue; |
| 313 | |
Tony Lindgren | 78737ae | 2010-02-01 13:03:42 -0800 | [diff] [blame] | 314 | /* REVISIT: Needs to be updated if mode0 names get longer */ |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 315 | for (i = 0; i < OMAP_MUX_DEFNAME_LEN; i++) { |
| 316 | if (m0_name[i] == '\0') { |
| 317 | m0_def[i] = m0_name[i]; |
| 318 | break; |
| 319 | } |
| 320 | m0_def[i] = toupper(m0_name[i]); |
| 321 | } |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 322 | val = omap_mux_read(partition, m->reg_offset); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 323 | mode = val & OMAP_MUX_MODE7; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 324 | if (mode != 0) |
| 325 | seq_printf(s, "/* %s */\n", m->muxnames[mode]); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 326 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 327 | /* |
| 328 | * XXX: Might be revisited to support differences accross |
| 329 | * same OMAP generation. |
| 330 | */ |
| 331 | seq_printf(s, "OMAP%d_MUX(%s, ", omap_gen, m0_def); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 332 | omap_mux_decode(s, val); |
| 333 | seq_printf(s, "),\n"); |
| 334 | } |
| 335 | |
| 336 | return 0; |
| 337 | } |
| 338 | |
| 339 | static int omap_mux_dbg_board_open(struct inode *inode, struct file *file) |
| 340 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 341 | return single_open(file, omap_mux_dbg_board_show, inode->i_private); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 342 | } |
| 343 | |
| 344 | static const struct file_operations omap_mux_dbg_board_fops = { |
| 345 | .open = omap_mux_dbg_board_open, |
| 346 | .read = seq_read, |
| 347 | .llseek = seq_lseek, |
| 348 | .release = single_release, |
| 349 | }; |
| 350 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 351 | static struct omap_mux_partition *omap_mux_get_partition(struct omap_mux *mux) |
| 352 | { |
| 353 | struct omap_mux_partition *partition; |
| 354 | |
| 355 | list_for_each_entry(partition, &mux_partitions, node) { |
| 356 | struct list_head *muxmodes = &partition->muxmodes; |
| 357 | struct omap_mux_entry *e; |
| 358 | |
| 359 | list_for_each_entry(e, muxmodes, node) { |
| 360 | struct omap_mux *m = &e->mux; |
| 361 | |
| 362 | if (m == mux) |
| 363 | return partition; |
| 364 | } |
| 365 | } |
| 366 | |
| 367 | return NULL; |
| 368 | } |
| 369 | |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 370 | static int omap_mux_dbg_signal_show(struct seq_file *s, void *unused) |
| 371 | { |
| 372 | struct omap_mux *m = s->private; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 373 | struct omap_mux_partition *partition; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 374 | const char *none = "NA"; |
| 375 | u16 val; |
| 376 | int mode; |
| 377 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 378 | partition = omap_mux_get_partition(m); |
| 379 | if (!partition) |
| 380 | return 0; |
| 381 | |
| 382 | val = omap_mux_read(partition, m->reg_offset); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 383 | mode = val & OMAP_MUX_MODE7; |
| 384 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 385 | 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] | 386 | m->muxnames[0], m->muxnames[mode], |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 387 | partition->phys + m->reg_offset, m->reg_offset, val, |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 388 | m->balls[0] ? m->balls[0] : none, |
| 389 | m->balls[1] ? m->balls[1] : none); |
| 390 | seq_printf(s, "mode: "); |
| 391 | omap_mux_decode(s, val); |
| 392 | seq_printf(s, "\n"); |
| 393 | seq_printf(s, "signals: %s | %s | %s | %s | %s | %s | %s | %s\n", |
| 394 | m->muxnames[0] ? m->muxnames[0] : none, |
| 395 | m->muxnames[1] ? m->muxnames[1] : none, |
| 396 | m->muxnames[2] ? m->muxnames[2] : none, |
| 397 | m->muxnames[3] ? m->muxnames[3] : none, |
| 398 | m->muxnames[4] ? m->muxnames[4] : none, |
| 399 | m->muxnames[5] ? m->muxnames[5] : none, |
| 400 | m->muxnames[6] ? m->muxnames[6] : none, |
| 401 | m->muxnames[7] ? m->muxnames[7] : none); |
| 402 | |
| 403 | return 0; |
| 404 | } |
| 405 | |
| 406 | #define OMAP_MUX_MAX_ARG_CHAR 7 |
| 407 | |
| 408 | static ssize_t omap_mux_dbg_signal_write(struct file *file, |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 409 | const char __user *user_buf, |
| 410 | size_t count, loff_t *ppos) |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 411 | { |
| 412 | char buf[OMAP_MUX_MAX_ARG_CHAR]; |
| 413 | struct seq_file *seqf; |
| 414 | struct omap_mux *m; |
| 415 | unsigned long val; |
| 416 | int buf_size, ret; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 417 | struct omap_mux_partition *partition; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 418 | |
| 419 | if (count > OMAP_MUX_MAX_ARG_CHAR) |
| 420 | return -EINVAL; |
| 421 | |
| 422 | memset(buf, 0, sizeof(buf)); |
| 423 | buf_size = min(count, sizeof(buf) - 1); |
| 424 | |
| 425 | if (copy_from_user(buf, user_buf, buf_size)) |
| 426 | return -EFAULT; |
| 427 | |
| 428 | ret = strict_strtoul(buf, 0x10, &val); |
| 429 | if (ret < 0) |
| 430 | return ret; |
| 431 | |
| 432 | if (val > 0xffff) |
| 433 | return -EINVAL; |
| 434 | |
| 435 | seqf = file->private_data; |
| 436 | m = seqf->private; |
| 437 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 438 | partition = omap_mux_get_partition(m); |
| 439 | if (!partition) |
| 440 | return -ENODEV; |
| 441 | |
| 442 | omap_mux_write(partition, (u16)val, m->reg_offset); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 443 | *ppos += count; |
| 444 | |
| 445 | return count; |
| 446 | } |
| 447 | |
| 448 | static int omap_mux_dbg_signal_open(struct inode *inode, struct file *file) |
| 449 | { |
| 450 | return single_open(file, omap_mux_dbg_signal_show, inode->i_private); |
| 451 | } |
| 452 | |
| 453 | static const struct file_operations omap_mux_dbg_signal_fops = { |
| 454 | .open = omap_mux_dbg_signal_open, |
| 455 | .read = seq_read, |
| 456 | .write = omap_mux_dbg_signal_write, |
| 457 | .llseek = seq_lseek, |
| 458 | .release = single_release, |
| 459 | }; |
| 460 | |
| 461 | static struct dentry *mux_dbg_dir; |
| 462 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 463 | static void __init omap_mux_dbg_create_entry( |
| 464 | struct omap_mux_partition *partition, |
| 465 | struct dentry *mux_dbg_dir) |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 466 | { |
| 467 | struct omap_mux_entry *e; |
| 468 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 469 | list_for_each_entry(e, &partition->muxmodes, node) { |
| 470 | struct omap_mux *m = &e->mux; |
| 471 | |
| 472 | (void)debugfs_create_file(m->muxnames[0], S_IWUGO, mux_dbg_dir, |
| 473 | m, &omap_mux_dbg_signal_fops); |
| 474 | } |
| 475 | } |
| 476 | |
| 477 | static void __init omap_mux_dbg_init(void) |
| 478 | { |
| 479 | struct omap_mux_partition *partition; |
| 480 | static struct dentry *mux_dbg_board_dir; |
| 481 | |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 482 | mux_dbg_dir = debugfs_create_dir("omap_mux", NULL); |
| 483 | if (!mux_dbg_dir) |
| 484 | return; |
| 485 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 486 | mux_dbg_board_dir = debugfs_create_dir("board", mux_dbg_dir); |
| 487 | if (!mux_dbg_board_dir) |
| 488 | return; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 489 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 490 | list_for_each_entry(partition, &mux_partitions, node) { |
| 491 | omap_mux_dbg_create_entry(partition, mux_dbg_dir); |
| 492 | (void)debugfs_create_file(partition->name, S_IRUGO, |
| 493 | mux_dbg_board_dir, partition, |
| 494 | &omap_mux_dbg_board_fops); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 495 | } |
| 496 | } |
| 497 | |
| 498 | #else |
| 499 | static inline void omap_mux_dbg_init(void) |
| 500 | { |
| 501 | } |
| 502 | #endif /* CONFIG_DEBUG_FS */ |
| 503 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 504 | static void __init omap_mux_free_names(struct omap_mux *m) |
| 505 | { |
| 506 | int i; |
| 507 | |
| 508 | for (i = 0; i < OMAP_MUX_NR_MODES; i++) |
| 509 | kfree(m->muxnames[i]); |
| 510 | |
| 511 | #ifdef CONFIG_DEBUG_FS |
| 512 | for (i = 0; i < OMAP_MUX_NR_SIDES; i++) |
| 513 | kfree(m->balls[i]); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 514 | #endif |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 515 | |
| 516 | } |
| 517 | |
| 518 | /* Free all data except for GPIO pins unless CONFIG_DEBUG_FS is set */ |
| 519 | static int __init omap_mux_late_init(void) |
| 520 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 521 | struct omap_mux_partition *partition; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 522 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 523 | list_for_each_entry(partition, &mux_partitions, node) { |
| 524 | struct omap_mux_entry *e, *tmp; |
| 525 | list_for_each_entry_safe(e, tmp, &partition->muxmodes, node) { |
| 526 | struct omap_mux *m = &e->mux; |
| 527 | u16 mode = omap_mux_read(partition, m->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 528 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 529 | if (OMAP_MODE_GPIO(mode)) |
| 530 | continue; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 531 | |
| 532 | #ifndef CONFIG_DEBUG_FS |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 533 | mutex_lock(&muxmode_mutex); |
| 534 | list_del(&e->node); |
| 535 | mutex_unlock(&muxmode_mutex); |
| 536 | omap_mux_free_names(m); |
| 537 | kfree(m); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 538 | #endif |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 539 | } |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 540 | } |
| 541 | |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 542 | omap_mux_dbg_init(); |
| 543 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 544 | return 0; |
| 545 | } |
| 546 | late_initcall(omap_mux_late_init); |
| 547 | |
| 548 | static void __init omap_mux_package_fixup(struct omap_mux *p, |
| 549 | struct omap_mux *superset) |
| 550 | { |
| 551 | while (p->reg_offset != OMAP_MUX_TERMINATOR) { |
| 552 | struct omap_mux *s = superset; |
| 553 | int found = 0; |
| 554 | |
| 555 | while (s->reg_offset != OMAP_MUX_TERMINATOR) { |
| 556 | if (s->reg_offset == p->reg_offset) { |
| 557 | *s = *p; |
| 558 | found++; |
| 559 | break; |
| 560 | } |
| 561 | s++; |
| 562 | } |
| 563 | if (!found) |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame^] | 564 | pr_err("%s: Unknown entry offset 0x%x\n", __func__, |
Benoit Cousson | 1cbb3a9 | 2010-08-10 17:33:01 +0200 | [diff] [blame] | 565 | p->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 566 | p++; |
| 567 | } |
| 568 | } |
| 569 | |
| 570 | #ifdef CONFIG_DEBUG_FS |
| 571 | |
| 572 | static void __init omap_mux_package_init_balls(struct omap_ball *b, |
| 573 | struct omap_mux *superset) |
| 574 | { |
| 575 | while (b->reg_offset != OMAP_MUX_TERMINATOR) { |
| 576 | struct omap_mux *s = superset; |
| 577 | int found = 0; |
| 578 | |
| 579 | while (s->reg_offset != OMAP_MUX_TERMINATOR) { |
| 580 | if (s->reg_offset == b->reg_offset) { |
| 581 | s->balls[0] = b->balls[0]; |
| 582 | s->balls[1] = b->balls[1]; |
| 583 | found++; |
| 584 | break; |
| 585 | } |
| 586 | s++; |
| 587 | } |
| 588 | if (!found) |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame^] | 589 | pr_err("%s: Unknown ball offset 0x%x\n", __func__, |
Benoit Cousson | 1cbb3a9 | 2010-08-10 17:33:01 +0200 | [diff] [blame] | 590 | b->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 591 | b++; |
| 592 | } |
| 593 | } |
| 594 | |
| 595 | #else /* CONFIG_DEBUG_FS */ |
| 596 | |
| 597 | static inline void omap_mux_package_init_balls(struct omap_ball *b, |
| 598 | struct omap_mux *superset) |
| 599 | { |
| 600 | } |
| 601 | |
| 602 | #endif /* CONFIG_DEBUG_FS */ |
| 603 | |
| 604 | static int __init omap_mux_setup(char *options) |
| 605 | { |
| 606 | if (!options) |
| 607 | return 0; |
| 608 | |
| 609 | omap_mux_options = options; |
| 610 | |
| 611 | return 1; |
| 612 | } |
| 613 | __setup("omap_mux=", omap_mux_setup); |
| 614 | |
| 615 | /* |
| 616 | * Note that the omap_mux=some.signal1=0x1234,some.signal2=0x1234 |
| 617 | * cmdline options only override the bootloader values. |
| 618 | * During development, please enable CONFIG_DEBUG_FS, and use the |
| 619 | * signal specific entries under debugfs. |
| 620 | */ |
| 621 | static void __init omap_mux_set_cmdline_signals(void) |
| 622 | { |
| 623 | char *options, *next_opt, *token; |
| 624 | |
| 625 | if (!omap_mux_options) |
| 626 | return; |
| 627 | |
| 628 | options = kmalloc(strlen(omap_mux_options) + 1, GFP_KERNEL); |
| 629 | if (!options) |
| 630 | return; |
| 631 | |
| 632 | strcpy(options, omap_mux_options); |
| 633 | next_opt = options; |
| 634 | |
| 635 | while ((token = strsep(&next_opt, ",")) != NULL) { |
| 636 | char *keyval, *name; |
| 637 | unsigned long val; |
| 638 | |
| 639 | keyval = token; |
| 640 | name = strsep(&keyval, "="); |
| 641 | if (name) { |
| 642 | int res; |
| 643 | |
| 644 | res = strict_strtoul(keyval, 0x10, &val); |
| 645 | if (res < 0) |
| 646 | continue; |
| 647 | |
| 648 | omap_mux_init_signal(name, (u16)val); |
| 649 | } |
| 650 | } |
| 651 | |
| 652 | kfree(options); |
| 653 | } |
| 654 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 655 | static int __init omap_mux_copy_names(struct omap_mux *src, |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 656 | struct omap_mux *dst) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 657 | { |
| 658 | int i; |
| 659 | |
| 660 | for (i = 0; i < OMAP_MUX_NR_MODES; i++) { |
| 661 | if (src->muxnames[i]) { |
| 662 | dst->muxnames[i] = |
| 663 | kmalloc(strlen(src->muxnames[i]) + 1, |
| 664 | GFP_KERNEL); |
| 665 | if (!dst->muxnames[i]) |
| 666 | goto free; |
| 667 | strcpy(dst->muxnames[i], src->muxnames[i]); |
| 668 | } |
| 669 | } |
| 670 | |
| 671 | #ifdef CONFIG_DEBUG_FS |
| 672 | for (i = 0; i < OMAP_MUX_NR_SIDES; i++) { |
| 673 | if (src->balls[i]) { |
| 674 | dst->balls[i] = |
| 675 | kmalloc(strlen(src->balls[i]) + 1, |
| 676 | GFP_KERNEL); |
| 677 | if (!dst->balls[i]) |
| 678 | goto free; |
| 679 | strcpy(dst->balls[i], src->balls[i]); |
| 680 | } |
| 681 | } |
| 682 | #endif |
| 683 | |
| 684 | return 0; |
| 685 | |
| 686 | free: |
| 687 | omap_mux_free_names(dst); |
| 688 | return -ENOMEM; |
| 689 | |
| 690 | } |
| 691 | |
| 692 | #endif /* CONFIG_OMAP_MUX */ |
| 693 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 694 | static struct omap_mux *omap_mux_get_by_gpio( |
| 695 | struct omap_mux_partition *partition, |
| 696 | int gpio) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 697 | { |
| 698 | struct omap_mux_entry *e; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 699 | struct omap_mux *ret = NULL; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 700 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 701 | list_for_each_entry(e, &partition->muxmodes, node) { |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 702 | struct omap_mux *m = &e->mux; |
| 703 | if (m->gpio == gpio) { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 704 | ret = m; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 705 | break; |
| 706 | } |
| 707 | } |
| 708 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 709 | return ret; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 710 | } |
| 711 | |
| 712 | /* Needed for dynamic muxing of GPIO pins for off-idle */ |
| 713 | u16 omap_mux_get_gpio(int gpio) |
| 714 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 715 | struct omap_mux_partition *partition; |
| 716 | struct omap_mux *m; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 717 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 718 | list_for_each_entry(partition, &mux_partitions, node) { |
| 719 | m = omap_mux_get_by_gpio(partition, gpio); |
| 720 | if (m) |
| 721 | return omap_mux_read(partition, m->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 722 | } |
| 723 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 724 | if (!m || m->reg_offset == OMAP_MUX_TERMINATOR) |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame^] | 725 | pr_err("%s: Could not get gpio%i\n", __func__, gpio); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 726 | |
| 727 | return OMAP_MUX_TERMINATOR; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 728 | } |
| 729 | |
| 730 | /* Needed for dynamic muxing of GPIO pins for off-idle */ |
| 731 | void omap_mux_set_gpio(u16 val, int gpio) |
| 732 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 733 | struct omap_mux_partition *partition; |
| 734 | struct omap_mux *m = NULL; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 735 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 736 | list_for_each_entry(partition, &mux_partitions, node) { |
| 737 | m = omap_mux_get_by_gpio(partition, gpio); |
| 738 | if (m) { |
| 739 | omap_mux_write(partition, val, m->reg_offset); |
| 740 | return; |
| 741 | } |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 742 | } |
| 743 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 744 | if (!m || m->reg_offset == OMAP_MUX_TERMINATOR) |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame^] | 745 | pr_err("%s: Could not set gpio%i\n", __func__, gpio); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 746 | } |
| 747 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 748 | static struct omap_mux * __init omap_mux_list_add( |
| 749 | struct omap_mux_partition *partition, |
| 750 | struct omap_mux *src) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 751 | { |
| 752 | struct omap_mux_entry *entry; |
| 753 | struct omap_mux *m; |
| 754 | |
| 755 | entry = kzalloc(sizeof(struct omap_mux_entry), GFP_KERNEL); |
| 756 | if (!entry) |
| 757 | return NULL; |
| 758 | |
| 759 | m = &entry->mux; |
| 760 | memcpy(m, src, sizeof(struct omap_mux_entry)); |
| 761 | |
| 762 | #ifdef CONFIG_OMAP_MUX |
| 763 | if (omap_mux_copy_names(src, m)) { |
| 764 | kfree(entry); |
| 765 | return NULL; |
| 766 | } |
| 767 | #endif |
| 768 | |
| 769 | mutex_lock(&muxmode_mutex); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 770 | list_add_tail(&entry->node, &partition->muxmodes); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 771 | mutex_unlock(&muxmode_mutex); |
| 772 | |
| 773 | return m; |
| 774 | } |
| 775 | |
| 776 | /* |
| 777 | * Note if CONFIG_OMAP_MUX is not selected, we will only initialize |
| 778 | * the GPIO to mux offset mapping that is needed for dynamic muxing |
| 779 | * of GPIO pins for off-idle. |
| 780 | */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 781 | static void __init omap_mux_init_list(struct omap_mux_partition *partition, |
| 782 | struct omap_mux *superset) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 783 | { |
| 784 | while (superset->reg_offset != OMAP_MUX_TERMINATOR) { |
| 785 | struct omap_mux *entry; |
| 786 | |
Ranjith Lohithakshan | b72c7d5 | 2010-02-17 17:17:01 +0000 | [diff] [blame] | 787 | #ifdef CONFIG_OMAP_MUX |
| 788 | if (!superset->muxnames || !superset->muxnames[0]) { |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 789 | superset++; |
| 790 | continue; |
| 791 | } |
Ranjith Lohithakshan | b72c7d5 | 2010-02-17 17:17:01 +0000 | [diff] [blame] | 792 | #else |
| 793 | /* Skip pins that are not muxed as GPIO by bootloader */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 794 | if (!OMAP_MODE_GPIO(omap_mux_read(partition, |
| 795 | superset->reg_offset))) { |
Tony Lindgren | 9ecef43 | 2010-02-01 11:22:54 -0800 | [diff] [blame] | 796 | superset++; |
| 797 | continue; |
| 798 | } |
| 799 | #endif |
| 800 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 801 | entry = omap_mux_list_add(partition, superset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 802 | if (!entry) { |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame^] | 803 | pr_err("%s: Could not add entry\n", __func__); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 804 | return; |
| 805 | } |
| 806 | superset++; |
| 807 | } |
| 808 | } |
| 809 | |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 810 | #ifdef CONFIG_OMAP_MUX |
| 811 | |
| 812 | static void omap_mux_init_package(struct omap_mux *superset, |
| 813 | struct omap_mux *package_subset, |
| 814 | struct omap_ball *package_balls) |
| 815 | { |
| 816 | if (package_subset) |
| 817 | omap_mux_package_fixup(package_subset, superset); |
| 818 | if (package_balls) |
| 819 | omap_mux_package_init_balls(package_balls, superset); |
| 820 | } |
| 821 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 822 | static void omap_mux_init_signals(struct omap_mux_partition *partition, |
| 823 | struct omap_board_mux *board_mux) |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 824 | { |
| 825 | omap_mux_set_cmdline_signals(); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 826 | omap_mux_write_array(partition, board_mux); |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 827 | } |
| 828 | |
| 829 | #else |
| 830 | |
| 831 | static void omap_mux_init_package(struct omap_mux *superset, |
| 832 | struct omap_mux *package_subset, |
| 833 | struct omap_ball *package_balls) |
| 834 | { |
| 835 | } |
| 836 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 837 | static void omap_mux_init_signals(struct omap_mux_partition *partition, |
| 838 | struct omap_board_mux *board_mux) |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 839 | { |
| 840 | } |
| 841 | |
| 842 | #endif |
| 843 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 844 | static u32 mux_partitions_cnt; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 845 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 846 | int __init omap_mux_init(const char *name, u32 flags, |
| 847 | u32 mux_pbase, u32 mux_size, |
| 848 | struct omap_mux *superset, |
| 849 | struct omap_mux *package_subset, |
| 850 | struct omap_board_mux *board_mux, |
| 851 | struct omap_ball *package_balls) |
| 852 | { |
| 853 | struct omap_mux_partition *partition; |
| 854 | |
| 855 | partition = kzalloc(sizeof(struct omap_mux_partition), GFP_KERNEL); |
| 856 | if (!partition) |
| 857 | return -ENOMEM; |
| 858 | |
| 859 | partition->name = name; |
| 860 | partition->flags = flags; |
| 861 | partition->size = mux_size; |
| 862 | partition->phys = mux_pbase; |
| 863 | partition->base = ioremap(mux_pbase, mux_size); |
| 864 | if (!partition->base) { |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame^] | 865 | pr_err("%s: Could not ioremap mux partition at 0x%08x\n", |
| 866 | __func__, partition->phys); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 867 | return -ENODEV; |
| 868 | } |
| 869 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 870 | INIT_LIST_HEAD(&partition->muxmodes); |
| 871 | |
| 872 | list_add_tail(&partition->node, &mux_partitions); |
| 873 | mux_partitions_cnt++; |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame^] | 874 | pr_info("%s: Add partition: #%d: %s, flags: %x\n", __func__, |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 875 | mux_partitions_cnt, partition->name, partition->flags); |
Tony Lindgren | d5425be | 2010-07-05 16:31:35 +0300 | [diff] [blame] | 876 | |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 877 | omap_mux_init_package(superset, package_subset, package_balls); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 878 | omap_mux_init_list(partition, superset); |
| 879 | omap_mux_init_signals(partition, board_mux); |
Tony Lindgren | 2cb0c54 | 2010-01-19 18:17:07 -0800 | [diff] [blame] | 880 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 881 | return 0; |
| 882 | } |
| 883 | |