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