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