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