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; |
Felipe Balbi | afb7d70 | 2011-01-17 06:31:18 +0200 | [diff] [blame] | 163 | int found = 0, found_mode = 0, 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; |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame^] | 261 | int i, nr_pads_dynamic = 0; |
Tony Lindgren | 9796b32 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 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; |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame^] | 305 | |
| 306 | if (pad->flags & OMAP_DEVICE_PAD_REMUX) |
| 307 | nr_pads_dynamic++; |
| 308 | |
Tony Lindgren | 9796b32 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 309 | pr_debug("%s: Initialized %s\n", __func__, pad->name); |
| 310 | } |
| 311 | |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame^] | 312 | if (!nr_pads_dynamic) |
| 313 | return hmux; |
| 314 | |
| 315 | /* |
| 316 | * Add pads that need dynamic muxing into a separate list |
| 317 | */ |
| 318 | |
| 319 | hmux->nr_pads_dynamic = nr_pads_dynamic; |
| 320 | hmux->pads_dynamic = kzalloc(sizeof(struct omap_device_pad *) * |
| 321 | nr_pads_dynamic, GFP_KERNEL); |
| 322 | if (!hmux->pads_dynamic) { |
| 323 | pr_err("%s: Could not allocate dynamic pads\n", __func__); |
| 324 | return hmux; |
| 325 | } |
| 326 | |
| 327 | nr_pads_dynamic = 0; |
| 328 | for (i = 0; i < hmux->nr_pads; i++) { |
| 329 | struct omap_device_pad *pad = &hmux->pads[i]; |
| 330 | |
| 331 | if (pad->flags & OMAP_DEVICE_PAD_REMUX) { |
| 332 | pr_debug("%s: pad %s tagged dynamic\n", |
| 333 | __func__, pad->name); |
| 334 | hmux->pads_dynamic[nr_pads_dynamic] = pad; |
| 335 | nr_pads_dynamic++; |
| 336 | } |
| 337 | } |
| 338 | |
Tony Lindgren | 9796b32 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 339 | return hmux; |
| 340 | |
| 341 | err3: |
| 342 | kfree(hmux->pads); |
| 343 | err2: |
| 344 | kfree(hmux); |
| 345 | err1: |
| 346 | pr_err("%s: Could not allocate device mux entry\n", __func__); |
| 347 | |
| 348 | return NULL; |
| 349 | } |
| 350 | |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 351 | /* Assumes the calling function takes care of locking */ |
| 352 | void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state) |
| 353 | { |
| 354 | int i; |
| 355 | |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame^] | 356 | /* Runtime idling of dynamic pads */ |
| 357 | if (state == _HWMOD_STATE_IDLE && hmux->enabled) { |
| 358 | for (i = 0; i < hmux->nr_pads_dynamic; i++) { |
| 359 | struct omap_device_pad *pad = hmux->pads_dynamic[i]; |
| 360 | int val = -EINVAL; |
| 361 | |
| 362 | pad->flags |= OMAP_DEVICE_PAD_IDLE; |
| 363 | val = pad->idle; |
| 364 | omap_mux_write(pad->partition, val, |
| 365 | pad->mux->reg_offset); |
| 366 | } |
| 367 | |
| 368 | return; |
| 369 | } |
| 370 | |
| 371 | /* Runtime enabling of dynamic pads */ |
| 372 | if ((state == _HWMOD_STATE_ENABLED) && hmux->pads_dynamic) { |
| 373 | int idled = 0; |
| 374 | |
| 375 | for (i = 0; i < hmux->nr_pads_dynamic; i++) { |
| 376 | struct omap_device_pad *pad = hmux->pads_dynamic[i]; |
| 377 | int val = -EINVAL; |
| 378 | |
| 379 | if (!(pad->flags & OMAP_DEVICE_PAD_IDLE)) |
| 380 | continue; |
| 381 | |
| 382 | pad->flags &= ~OMAP_DEVICE_PAD_IDLE; |
| 383 | val = pad->enable; |
| 384 | omap_mux_write(pad->partition, val, |
| 385 | pad->mux->reg_offset); |
| 386 | idled++; |
| 387 | } |
| 388 | |
| 389 | if (idled) |
| 390 | return; |
| 391 | } |
| 392 | |
| 393 | /* Enabling or disabling of all pads */ |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 394 | for (i = 0; i < hmux->nr_pads; i++) { |
| 395 | struct omap_device_pad *pad = &hmux->pads[i]; |
| 396 | int flags, val = -EINVAL; |
| 397 | |
| 398 | flags = pad->flags; |
| 399 | |
| 400 | switch (state) { |
| 401 | case _HWMOD_STATE_ENABLED: |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 402 | val = pad->enable; |
| 403 | pr_debug("%s: Enabling %s %x\n", __func__, |
| 404 | pad->name, val); |
| 405 | break; |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 406 | case _HWMOD_STATE_DISABLED: |
| 407 | default: |
| 408 | /* Use safe mode unless OMAP_DEVICE_PAD_REMUX */ |
| 409 | if (flags & OMAP_DEVICE_PAD_REMUX) |
| 410 | val = pad->off; |
| 411 | else |
| 412 | val = OMAP_MUX_MODE7; |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 413 | pr_debug("%s: Disabling %s %x\n", __func__, |
| 414 | pad->name, val); |
| 415 | }; |
| 416 | |
| 417 | if (val >= 0) { |
| 418 | omap_mux_write(pad->partition, val, |
| 419 | pad->mux->reg_offset); |
| 420 | pad->flags = flags; |
| 421 | } |
| 422 | } |
Tony Lindgren | 029268e | 2011-03-11 11:32:25 -0800 | [diff] [blame^] | 423 | |
| 424 | if (state == _HWMOD_STATE_ENABLED) |
| 425 | hmux->enabled = true; |
| 426 | else |
| 427 | hmux->enabled = false; |
Tony Lindgren | 8d9af88 | 2010-12-22 18:42:35 -0800 | [diff] [blame] | 428 | } |
| 429 | |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 430 | #ifdef CONFIG_DEBUG_FS |
| 431 | |
| 432 | #define OMAP_MUX_MAX_NR_FLAGS 10 |
| 433 | #define OMAP_MUX_TEST_FLAG(val, mask) \ |
| 434 | if (((val) & (mask)) == (mask)) { \ |
| 435 | i++; \ |
| 436 | flags[i] = #mask; \ |
| 437 | } |
| 438 | |
| 439 | /* REVISIT: Add checking for non-optimal mux settings */ |
| 440 | static inline void omap_mux_decode(struct seq_file *s, u16 val) |
| 441 | { |
| 442 | char *flags[OMAP_MUX_MAX_NR_FLAGS]; |
Tony Lindgren | 78737ae | 2010-02-01 13:03:42 -0800 | [diff] [blame] | 443 | char mode[sizeof("OMAP_MUX_MODE") + 1]; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 444 | int i = -1; |
| 445 | |
| 446 | sprintf(mode, "OMAP_MUX_MODE%d", val & 0x7); |
| 447 | i++; |
| 448 | flags[i] = mode; |
| 449 | |
| 450 | OMAP_MUX_TEST_FLAG(val, OMAP_PIN_OFF_WAKEUPENABLE); |
| 451 | if (val & OMAP_OFF_EN) { |
| 452 | if (!(val & OMAP_OFFOUT_EN)) { |
| 453 | if (!(val & OMAP_OFF_PULL_UP)) { |
| 454 | OMAP_MUX_TEST_FLAG(val, |
| 455 | OMAP_PIN_OFF_INPUT_PULLDOWN); |
| 456 | } else { |
| 457 | OMAP_MUX_TEST_FLAG(val, |
| 458 | OMAP_PIN_OFF_INPUT_PULLUP); |
| 459 | } |
| 460 | } else { |
| 461 | if (!(val & OMAP_OFFOUT_VAL)) { |
| 462 | OMAP_MUX_TEST_FLAG(val, |
| 463 | OMAP_PIN_OFF_OUTPUT_LOW); |
| 464 | } else { |
| 465 | OMAP_MUX_TEST_FLAG(val, |
| 466 | OMAP_PIN_OFF_OUTPUT_HIGH); |
| 467 | } |
| 468 | } |
| 469 | } |
| 470 | |
| 471 | if (val & OMAP_INPUT_EN) { |
| 472 | if (val & OMAP_PULL_ENA) { |
| 473 | if (!(val & OMAP_PULL_UP)) { |
| 474 | OMAP_MUX_TEST_FLAG(val, |
| 475 | OMAP_PIN_INPUT_PULLDOWN); |
| 476 | } else { |
| 477 | OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT_PULLUP); |
| 478 | } |
| 479 | } else { |
| 480 | OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT); |
| 481 | } |
| 482 | } else { |
| 483 | i++; |
| 484 | flags[i] = "OMAP_PIN_OUTPUT"; |
| 485 | } |
| 486 | |
| 487 | do { |
| 488 | seq_printf(s, "%s", flags[i]); |
| 489 | if (i > 0) |
| 490 | seq_printf(s, " | "); |
| 491 | } while (i-- > 0); |
| 492 | } |
| 493 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 494 | #define OMAP_MUX_DEFNAME_LEN 32 |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 495 | |
| 496 | static int omap_mux_dbg_board_show(struct seq_file *s, void *unused) |
| 497 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 498 | struct omap_mux_partition *partition = s->private; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 499 | struct omap_mux_entry *e; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 500 | u8 omap_gen = omap_rev() >> 28; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 501 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 502 | list_for_each_entry(e, &partition->muxmodes, node) { |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 503 | struct omap_mux *m = &e->mux; |
| 504 | char m0_def[OMAP_MUX_DEFNAME_LEN]; |
| 505 | char *m0_name = m->muxnames[0]; |
| 506 | u16 val; |
| 507 | int i, mode; |
| 508 | |
| 509 | if (!m0_name) |
| 510 | continue; |
| 511 | |
Tony Lindgren | 78737ae | 2010-02-01 13:03:42 -0800 | [diff] [blame] | 512 | /* REVISIT: Needs to be updated if mode0 names get longer */ |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 513 | for (i = 0; i < OMAP_MUX_DEFNAME_LEN; i++) { |
| 514 | if (m0_name[i] == '\0') { |
| 515 | m0_def[i] = m0_name[i]; |
| 516 | break; |
| 517 | } |
| 518 | m0_def[i] = toupper(m0_name[i]); |
| 519 | } |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 520 | val = omap_mux_read(partition, m->reg_offset); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 521 | mode = val & OMAP_MUX_MODE7; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 522 | if (mode != 0) |
| 523 | seq_printf(s, "/* %s */\n", m->muxnames[mode]); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 524 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 525 | /* |
| 526 | * XXX: Might be revisited to support differences accross |
| 527 | * same OMAP generation. |
| 528 | */ |
| 529 | seq_printf(s, "OMAP%d_MUX(%s, ", omap_gen, m0_def); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 530 | omap_mux_decode(s, val); |
| 531 | seq_printf(s, "),\n"); |
| 532 | } |
| 533 | |
| 534 | return 0; |
| 535 | } |
| 536 | |
| 537 | static int omap_mux_dbg_board_open(struct inode *inode, struct file *file) |
| 538 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 539 | return single_open(file, omap_mux_dbg_board_show, inode->i_private); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static const struct file_operations omap_mux_dbg_board_fops = { |
| 543 | .open = omap_mux_dbg_board_open, |
| 544 | .read = seq_read, |
| 545 | .llseek = seq_lseek, |
| 546 | .release = single_release, |
| 547 | }; |
| 548 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 549 | static struct omap_mux_partition *omap_mux_get_partition(struct omap_mux *mux) |
| 550 | { |
| 551 | struct omap_mux_partition *partition; |
| 552 | |
| 553 | list_for_each_entry(partition, &mux_partitions, node) { |
| 554 | struct list_head *muxmodes = &partition->muxmodes; |
| 555 | struct omap_mux_entry *e; |
| 556 | |
| 557 | list_for_each_entry(e, muxmodes, node) { |
| 558 | struct omap_mux *m = &e->mux; |
| 559 | |
| 560 | if (m == mux) |
| 561 | return partition; |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | return NULL; |
| 566 | } |
| 567 | |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 568 | static int omap_mux_dbg_signal_show(struct seq_file *s, void *unused) |
| 569 | { |
| 570 | struct omap_mux *m = s->private; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 571 | struct omap_mux_partition *partition; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 572 | const char *none = "NA"; |
| 573 | u16 val; |
| 574 | int mode; |
| 575 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 576 | partition = omap_mux_get_partition(m); |
| 577 | if (!partition) |
| 578 | return 0; |
| 579 | |
| 580 | val = omap_mux_read(partition, m->reg_offset); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 581 | mode = val & OMAP_MUX_MODE7; |
| 582 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 583 | 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] | 584 | m->muxnames[0], m->muxnames[mode], |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 585 | partition->phys + m->reg_offset, m->reg_offset, val, |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 586 | m->balls[0] ? m->balls[0] : none, |
| 587 | m->balls[1] ? m->balls[1] : none); |
| 588 | seq_printf(s, "mode: "); |
| 589 | omap_mux_decode(s, val); |
| 590 | seq_printf(s, "\n"); |
| 591 | seq_printf(s, "signals: %s | %s | %s | %s | %s | %s | %s | %s\n", |
| 592 | m->muxnames[0] ? m->muxnames[0] : none, |
| 593 | m->muxnames[1] ? m->muxnames[1] : none, |
| 594 | m->muxnames[2] ? m->muxnames[2] : none, |
| 595 | m->muxnames[3] ? m->muxnames[3] : none, |
| 596 | m->muxnames[4] ? m->muxnames[4] : none, |
| 597 | m->muxnames[5] ? m->muxnames[5] : none, |
| 598 | m->muxnames[6] ? m->muxnames[6] : none, |
| 599 | m->muxnames[7] ? m->muxnames[7] : none); |
| 600 | |
| 601 | return 0; |
| 602 | } |
| 603 | |
| 604 | #define OMAP_MUX_MAX_ARG_CHAR 7 |
| 605 | |
| 606 | static ssize_t omap_mux_dbg_signal_write(struct file *file, |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 607 | const char __user *user_buf, |
| 608 | size_t count, loff_t *ppos) |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 609 | { |
| 610 | char buf[OMAP_MUX_MAX_ARG_CHAR]; |
| 611 | struct seq_file *seqf; |
| 612 | struct omap_mux *m; |
| 613 | unsigned long val; |
| 614 | int buf_size, ret; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 615 | struct omap_mux_partition *partition; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 616 | |
| 617 | if (count > OMAP_MUX_MAX_ARG_CHAR) |
| 618 | return -EINVAL; |
| 619 | |
| 620 | memset(buf, 0, sizeof(buf)); |
| 621 | buf_size = min(count, sizeof(buf) - 1); |
| 622 | |
| 623 | if (copy_from_user(buf, user_buf, buf_size)) |
| 624 | return -EFAULT; |
| 625 | |
| 626 | ret = strict_strtoul(buf, 0x10, &val); |
| 627 | if (ret < 0) |
| 628 | return ret; |
| 629 | |
| 630 | if (val > 0xffff) |
| 631 | return -EINVAL; |
| 632 | |
| 633 | seqf = file->private_data; |
| 634 | m = seqf->private; |
| 635 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 636 | partition = omap_mux_get_partition(m); |
| 637 | if (!partition) |
| 638 | return -ENODEV; |
| 639 | |
| 640 | omap_mux_write(partition, (u16)val, m->reg_offset); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 641 | *ppos += count; |
| 642 | |
| 643 | return count; |
| 644 | } |
| 645 | |
| 646 | static int omap_mux_dbg_signal_open(struct inode *inode, struct file *file) |
| 647 | { |
| 648 | return single_open(file, omap_mux_dbg_signal_show, inode->i_private); |
| 649 | } |
| 650 | |
| 651 | static const struct file_operations omap_mux_dbg_signal_fops = { |
| 652 | .open = omap_mux_dbg_signal_open, |
| 653 | .read = seq_read, |
| 654 | .write = omap_mux_dbg_signal_write, |
| 655 | .llseek = seq_lseek, |
| 656 | .release = single_release, |
| 657 | }; |
| 658 | |
| 659 | static struct dentry *mux_dbg_dir; |
| 660 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 661 | static void __init omap_mux_dbg_create_entry( |
| 662 | struct omap_mux_partition *partition, |
| 663 | struct dentry *mux_dbg_dir) |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 664 | { |
| 665 | struct omap_mux_entry *e; |
| 666 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 667 | list_for_each_entry(e, &partition->muxmodes, node) { |
| 668 | struct omap_mux *m = &e->mux; |
| 669 | |
Vasiliy Kulikov | 9b12771 | 2011-02-04 12:23:13 +0000 | [diff] [blame] | 670 | (void)debugfs_create_file(m->muxnames[0], S_IWUSR, mux_dbg_dir, |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 671 | m, &omap_mux_dbg_signal_fops); |
| 672 | } |
| 673 | } |
| 674 | |
| 675 | static void __init omap_mux_dbg_init(void) |
| 676 | { |
| 677 | struct omap_mux_partition *partition; |
| 678 | static struct dentry *mux_dbg_board_dir; |
| 679 | |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 680 | mux_dbg_dir = debugfs_create_dir("omap_mux", NULL); |
| 681 | if (!mux_dbg_dir) |
| 682 | return; |
| 683 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 684 | mux_dbg_board_dir = debugfs_create_dir("board", mux_dbg_dir); |
| 685 | if (!mux_dbg_board_dir) |
| 686 | return; |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 687 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 688 | list_for_each_entry(partition, &mux_partitions, node) { |
| 689 | omap_mux_dbg_create_entry(partition, mux_dbg_dir); |
| 690 | (void)debugfs_create_file(partition->name, S_IRUGO, |
| 691 | mux_dbg_board_dir, partition, |
| 692 | &omap_mux_dbg_board_fops); |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 693 | } |
| 694 | } |
| 695 | |
| 696 | #else |
| 697 | static inline void omap_mux_dbg_init(void) |
| 698 | { |
| 699 | } |
| 700 | #endif /* CONFIG_DEBUG_FS */ |
| 701 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 702 | static void __init omap_mux_free_names(struct omap_mux *m) |
| 703 | { |
| 704 | int i; |
| 705 | |
| 706 | for (i = 0; i < OMAP_MUX_NR_MODES; i++) |
| 707 | kfree(m->muxnames[i]); |
| 708 | |
| 709 | #ifdef CONFIG_DEBUG_FS |
| 710 | for (i = 0; i < OMAP_MUX_NR_SIDES; i++) |
| 711 | kfree(m->balls[i]); |
Tony Lindgren | 1dbae81 | 2005-11-10 14:26:51 +0000 | [diff] [blame] | 712 | #endif |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 713 | |
| 714 | } |
| 715 | |
| 716 | /* Free all data except for GPIO pins unless CONFIG_DEBUG_FS is set */ |
| 717 | static int __init omap_mux_late_init(void) |
| 718 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 719 | struct omap_mux_partition *partition; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 720 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 721 | list_for_each_entry(partition, &mux_partitions, node) { |
| 722 | struct omap_mux_entry *e, *tmp; |
| 723 | list_for_each_entry_safe(e, tmp, &partition->muxmodes, node) { |
| 724 | struct omap_mux *m = &e->mux; |
| 725 | u16 mode = omap_mux_read(partition, m->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 726 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 727 | if (OMAP_MODE_GPIO(mode)) |
| 728 | continue; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 729 | |
| 730 | #ifndef CONFIG_DEBUG_FS |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 731 | mutex_lock(&muxmode_mutex); |
| 732 | list_del(&e->node); |
| 733 | mutex_unlock(&muxmode_mutex); |
| 734 | omap_mux_free_names(m); |
| 735 | kfree(m); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 736 | #endif |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 737 | } |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 738 | } |
| 739 | |
Tony Lindgren | 4b715ef | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 740 | omap_mux_dbg_init(); |
| 741 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 742 | return 0; |
| 743 | } |
| 744 | late_initcall(omap_mux_late_init); |
| 745 | |
| 746 | static void __init omap_mux_package_fixup(struct omap_mux *p, |
| 747 | struct omap_mux *superset) |
| 748 | { |
| 749 | while (p->reg_offset != OMAP_MUX_TERMINATOR) { |
| 750 | struct omap_mux *s = superset; |
| 751 | int found = 0; |
| 752 | |
| 753 | while (s->reg_offset != OMAP_MUX_TERMINATOR) { |
| 754 | if (s->reg_offset == p->reg_offset) { |
| 755 | *s = *p; |
| 756 | found++; |
| 757 | break; |
| 758 | } |
| 759 | s++; |
| 760 | } |
| 761 | if (!found) |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 762 | pr_err("%s: Unknown entry offset 0x%x\n", __func__, |
Benoit Cousson | 1cbb3a9 | 2010-08-10 17:33:01 +0200 | [diff] [blame] | 763 | p->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 764 | p++; |
| 765 | } |
| 766 | } |
| 767 | |
| 768 | #ifdef CONFIG_DEBUG_FS |
| 769 | |
| 770 | static void __init omap_mux_package_init_balls(struct omap_ball *b, |
| 771 | struct omap_mux *superset) |
| 772 | { |
| 773 | while (b->reg_offset != OMAP_MUX_TERMINATOR) { |
| 774 | struct omap_mux *s = superset; |
| 775 | int found = 0; |
| 776 | |
| 777 | while (s->reg_offset != OMAP_MUX_TERMINATOR) { |
| 778 | if (s->reg_offset == b->reg_offset) { |
| 779 | s->balls[0] = b->balls[0]; |
| 780 | s->balls[1] = b->balls[1]; |
| 781 | found++; |
| 782 | break; |
| 783 | } |
| 784 | s++; |
| 785 | } |
| 786 | if (!found) |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 787 | pr_err("%s: Unknown ball offset 0x%x\n", __func__, |
Benoit Cousson | 1cbb3a9 | 2010-08-10 17:33:01 +0200 | [diff] [blame] | 788 | b->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 789 | b++; |
| 790 | } |
| 791 | } |
| 792 | |
| 793 | #else /* CONFIG_DEBUG_FS */ |
| 794 | |
| 795 | static inline void omap_mux_package_init_balls(struct omap_ball *b, |
| 796 | struct omap_mux *superset) |
| 797 | { |
| 798 | } |
| 799 | |
| 800 | #endif /* CONFIG_DEBUG_FS */ |
| 801 | |
| 802 | static int __init omap_mux_setup(char *options) |
| 803 | { |
| 804 | if (!options) |
| 805 | return 0; |
| 806 | |
| 807 | omap_mux_options = options; |
| 808 | |
| 809 | return 1; |
| 810 | } |
| 811 | __setup("omap_mux=", omap_mux_setup); |
| 812 | |
| 813 | /* |
| 814 | * Note that the omap_mux=some.signal1=0x1234,some.signal2=0x1234 |
| 815 | * cmdline options only override the bootloader values. |
| 816 | * During development, please enable CONFIG_DEBUG_FS, and use the |
| 817 | * signal specific entries under debugfs. |
| 818 | */ |
| 819 | static void __init omap_mux_set_cmdline_signals(void) |
| 820 | { |
| 821 | char *options, *next_opt, *token; |
| 822 | |
| 823 | if (!omap_mux_options) |
| 824 | return; |
| 825 | |
| 826 | options = kmalloc(strlen(omap_mux_options) + 1, GFP_KERNEL); |
| 827 | if (!options) |
| 828 | return; |
| 829 | |
| 830 | strcpy(options, omap_mux_options); |
| 831 | next_opt = options; |
| 832 | |
| 833 | while ((token = strsep(&next_opt, ",")) != NULL) { |
| 834 | char *keyval, *name; |
| 835 | unsigned long val; |
| 836 | |
| 837 | keyval = token; |
| 838 | name = strsep(&keyval, "="); |
| 839 | if (name) { |
| 840 | int res; |
| 841 | |
| 842 | res = strict_strtoul(keyval, 0x10, &val); |
| 843 | if (res < 0) |
| 844 | continue; |
| 845 | |
| 846 | omap_mux_init_signal(name, (u16)val); |
| 847 | } |
| 848 | } |
| 849 | |
| 850 | kfree(options); |
| 851 | } |
| 852 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 853 | static int __init omap_mux_copy_names(struct omap_mux *src, |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 854 | struct omap_mux *dst) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 855 | { |
| 856 | int i; |
| 857 | |
| 858 | for (i = 0; i < OMAP_MUX_NR_MODES; i++) { |
| 859 | if (src->muxnames[i]) { |
| 860 | dst->muxnames[i] = |
| 861 | kmalloc(strlen(src->muxnames[i]) + 1, |
| 862 | GFP_KERNEL); |
| 863 | if (!dst->muxnames[i]) |
| 864 | goto free; |
| 865 | strcpy(dst->muxnames[i], src->muxnames[i]); |
| 866 | } |
| 867 | } |
| 868 | |
| 869 | #ifdef CONFIG_DEBUG_FS |
| 870 | for (i = 0; i < OMAP_MUX_NR_SIDES; i++) { |
| 871 | if (src->balls[i]) { |
| 872 | dst->balls[i] = |
| 873 | kmalloc(strlen(src->balls[i]) + 1, |
| 874 | GFP_KERNEL); |
| 875 | if (!dst->balls[i]) |
| 876 | goto free; |
| 877 | strcpy(dst->balls[i], src->balls[i]); |
| 878 | } |
| 879 | } |
| 880 | #endif |
| 881 | |
| 882 | return 0; |
| 883 | |
| 884 | free: |
| 885 | omap_mux_free_names(dst); |
| 886 | return -ENOMEM; |
| 887 | |
| 888 | } |
| 889 | |
| 890 | #endif /* CONFIG_OMAP_MUX */ |
| 891 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 892 | static struct omap_mux *omap_mux_get_by_gpio( |
| 893 | struct omap_mux_partition *partition, |
| 894 | int gpio) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 895 | { |
| 896 | struct omap_mux_entry *e; |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 897 | struct omap_mux *ret = NULL; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 898 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 899 | list_for_each_entry(e, &partition->muxmodes, node) { |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 900 | struct omap_mux *m = &e->mux; |
| 901 | if (m->gpio == gpio) { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 902 | ret = m; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 903 | break; |
| 904 | } |
| 905 | } |
| 906 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 907 | return ret; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | /* Needed for dynamic muxing of GPIO pins for off-idle */ |
| 911 | u16 omap_mux_get_gpio(int gpio) |
| 912 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 913 | struct omap_mux_partition *partition; |
| 914 | struct omap_mux *m; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 915 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 916 | list_for_each_entry(partition, &mux_partitions, node) { |
| 917 | m = omap_mux_get_by_gpio(partition, gpio); |
| 918 | if (m) |
| 919 | return omap_mux_read(partition, m->reg_offset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 920 | } |
| 921 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 922 | if (!m || m->reg_offset == OMAP_MUX_TERMINATOR) |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 923 | pr_err("%s: Could not get gpio%i\n", __func__, gpio); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 924 | |
| 925 | return OMAP_MUX_TERMINATOR; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 926 | } |
| 927 | |
| 928 | /* Needed for dynamic muxing of GPIO pins for off-idle */ |
| 929 | void omap_mux_set_gpio(u16 val, int gpio) |
| 930 | { |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 931 | struct omap_mux_partition *partition; |
| 932 | struct omap_mux *m = NULL; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 933 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 934 | list_for_each_entry(partition, &mux_partitions, node) { |
| 935 | m = omap_mux_get_by_gpio(partition, gpio); |
| 936 | if (m) { |
| 937 | omap_mux_write(partition, val, m->reg_offset); |
| 938 | return; |
| 939 | } |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 940 | } |
| 941 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 942 | if (!m || m->reg_offset == OMAP_MUX_TERMINATOR) |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 943 | pr_err("%s: Could not set gpio%i\n", __func__, gpio); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 944 | } |
| 945 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 946 | static struct omap_mux * __init omap_mux_list_add( |
| 947 | struct omap_mux_partition *partition, |
| 948 | struct omap_mux *src) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 949 | { |
| 950 | struct omap_mux_entry *entry; |
| 951 | struct omap_mux *m; |
| 952 | |
| 953 | entry = kzalloc(sizeof(struct omap_mux_entry), GFP_KERNEL); |
| 954 | if (!entry) |
| 955 | return NULL; |
| 956 | |
| 957 | m = &entry->mux; |
Aaro Koskinen | 3083314 | 2011-01-06 19:49:28 -0800 | [diff] [blame] | 958 | entry->mux = *src; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 959 | |
| 960 | #ifdef CONFIG_OMAP_MUX |
| 961 | if (omap_mux_copy_names(src, m)) { |
| 962 | kfree(entry); |
| 963 | return NULL; |
| 964 | } |
| 965 | #endif |
| 966 | |
| 967 | mutex_lock(&muxmode_mutex); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 968 | list_add_tail(&entry->node, &partition->muxmodes); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 969 | mutex_unlock(&muxmode_mutex); |
| 970 | |
| 971 | return m; |
| 972 | } |
| 973 | |
| 974 | /* |
| 975 | * Note if CONFIG_OMAP_MUX is not selected, we will only initialize |
| 976 | * the GPIO to mux offset mapping that is needed for dynamic muxing |
| 977 | * of GPIO pins for off-idle. |
| 978 | */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 979 | static void __init omap_mux_init_list(struct omap_mux_partition *partition, |
| 980 | struct omap_mux *superset) |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 981 | { |
| 982 | while (superset->reg_offset != OMAP_MUX_TERMINATOR) { |
| 983 | struct omap_mux *entry; |
| 984 | |
Ranjith Lohithakshan | b72c7d5 | 2010-02-17 17:17:01 +0000 | [diff] [blame] | 985 | #ifdef CONFIG_OMAP_MUX |
| 986 | if (!superset->muxnames || !superset->muxnames[0]) { |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 987 | superset++; |
| 988 | continue; |
| 989 | } |
Ranjith Lohithakshan | b72c7d5 | 2010-02-17 17:17:01 +0000 | [diff] [blame] | 990 | #else |
| 991 | /* Skip pins that are not muxed as GPIO by bootloader */ |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 992 | if (!OMAP_MODE_GPIO(omap_mux_read(partition, |
| 993 | superset->reg_offset))) { |
Tony Lindgren | 9ecef43 | 2010-02-01 11:22:54 -0800 | [diff] [blame] | 994 | superset++; |
| 995 | continue; |
| 996 | } |
| 997 | #endif |
| 998 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 999 | entry = omap_mux_list_add(partition, superset); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1000 | if (!entry) { |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 1001 | pr_err("%s: Could not add entry\n", __func__); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1002 | return; |
| 1003 | } |
| 1004 | superset++; |
| 1005 | } |
| 1006 | } |
| 1007 | |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 1008 | #ifdef CONFIG_OMAP_MUX |
| 1009 | |
| 1010 | static void omap_mux_init_package(struct omap_mux *superset, |
| 1011 | struct omap_mux *package_subset, |
| 1012 | struct omap_ball *package_balls) |
| 1013 | { |
| 1014 | if (package_subset) |
| 1015 | omap_mux_package_fixup(package_subset, superset); |
| 1016 | if (package_balls) |
| 1017 | omap_mux_package_init_balls(package_balls, superset); |
| 1018 | } |
| 1019 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1020 | static void omap_mux_init_signals(struct omap_mux_partition *partition, |
| 1021 | struct omap_board_mux *board_mux) |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 1022 | { |
| 1023 | omap_mux_set_cmdline_signals(); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1024 | omap_mux_write_array(partition, board_mux); |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 1025 | } |
| 1026 | |
| 1027 | #else |
| 1028 | |
| 1029 | static void omap_mux_init_package(struct omap_mux *superset, |
| 1030 | struct omap_mux *package_subset, |
| 1031 | struct omap_ball *package_balls) |
| 1032 | { |
| 1033 | } |
| 1034 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1035 | static void omap_mux_init_signals(struct omap_mux_partition *partition, |
| 1036 | struct omap_board_mux *board_mux) |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 1037 | { |
| 1038 | } |
| 1039 | |
| 1040 | #endif |
| 1041 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1042 | static u32 mux_partitions_cnt; |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1043 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1044 | int __init omap_mux_init(const char *name, u32 flags, |
| 1045 | u32 mux_pbase, u32 mux_size, |
| 1046 | struct omap_mux *superset, |
| 1047 | struct omap_mux *package_subset, |
| 1048 | struct omap_board_mux *board_mux, |
| 1049 | struct omap_ball *package_balls) |
| 1050 | { |
| 1051 | struct omap_mux_partition *partition; |
| 1052 | |
| 1053 | partition = kzalloc(sizeof(struct omap_mux_partition), GFP_KERNEL); |
| 1054 | if (!partition) |
| 1055 | return -ENOMEM; |
| 1056 | |
| 1057 | partition->name = name; |
| 1058 | partition->flags = flags; |
| 1059 | partition->size = mux_size; |
| 1060 | partition->phys = mux_pbase; |
| 1061 | partition->base = ioremap(mux_pbase, mux_size); |
| 1062 | if (!partition->base) { |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 1063 | pr_err("%s: Could not ioremap mux partition at 0x%08x\n", |
| 1064 | __func__, partition->phys); |
Aaro Koskinen | 9d47e30 | 2011-01-28 14:50:55 +0000 | [diff] [blame] | 1065 | kfree(partition); |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1066 | return -ENODEV; |
| 1067 | } |
| 1068 | |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1069 | INIT_LIST_HEAD(&partition->muxmodes); |
| 1070 | |
| 1071 | list_add_tail(&partition->node, &mux_partitions); |
| 1072 | mux_partitions_cnt++; |
Dan Murphy | 032a642 | 2010-11-15 09:50:50 -0600 | [diff] [blame] | 1073 | pr_info("%s: Add partition: #%d: %s, flags: %x\n", __func__, |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1074 | mux_partitions_cnt, partition->name, partition->flags); |
Tony Lindgren | d5425be | 2010-07-05 16:31:35 +0300 | [diff] [blame] | 1075 | |
Tony Lindgren | 321cfc8 | 2010-02-15 10:03:35 -0800 | [diff] [blame] | 1076 | omap_mux_init_package(superset, package_subset, package_balls); |
Benoit Cousson | 112485e | 2010-08-16 10:55:35 +0200 | [diff] [blame] | 1077 | omap_mux_init_list(partition, superset); |
| 1078 | omap_mux_init_signals(partition, board_mux); |
Tony Lindgren | 2cb0c54 | 2010-01-19 18:17:07 -0800 | [diff] [blame] | 1079 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame] | 1080 | return 0; |
| 1081 | } |
| 1082 | |