blob: a474c81355ec94213607c0dc418e5046eb6ab1fb [file] [log] [blame]
Tony Lindgren1dbae812005-11-10 14:26:51 +00001/*
2 * linux/arch/arm/mach-omap2/mux.c
3 *
Benoit Cousson112485e2010-08-16 10:55:35 +02004 * OMAP2, OMAP3 and OMAP4 pin multiplexing configurations
Tony Lindgren1dbae812005-11-10 14:26:51 +00005 *
Benoit Cousson112485e2010-08-16 10:55:35 +02006 * Copyright (C) 2004 - 2010 Texas Instruments Inc.
Tony Lindgren93308992008-01-24 17:24:15 -08007 * Copyright (C) 2003 - 2008 Nokia Corporation
Tony Lindgren1dbae812005-11-10 14:26:51 +00008 *
Tony Lindgren93308992008-01-24 17:24:15 -08009 * Written by Tony Lindgren
Tony Lindgren1dbae812005-11-10 14:26:51 +000010 *
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 Walmsley4814ced2010-10-08 11:40:20 -060026#include <linux/kernel.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000027#include <linux/init.h>
Russell Kingfced80c2008-09-06 12:10:45 +010028#include <linux/io.h>
Tony Lindgren15ac7af2009-12-11 16:16:32 -080029#include <linux/list.h>
Paul Walmsley4814ced2010-10-08 11:40:20 -060030#include <linux/slab.h>
Tony Lindgren4b715ef2009-12-11 16:16:32 -080031#include <linux/ctype.h>
32#include <linux/debugfs.h>
33#include <linux/seq_file.h>
34#include <linux/uaccess.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000035
Russell Kingfced80c2008-09-06 12:10:45 +010036#include <asm/system.h>
37
Tony Lindgren9796b322010-12-22 18:42:35 -080038#include <plat/omap_hwmod.h>
39
Paul Walmsley4814ced2010-10-08 11:40:20 -060040#include "control.h"
Tony Lindgren15ac7af2009-12-11 16:16:32 -080041#include "mux.h"
Tony Lindgren1dbae812005-11-10 14:26:51 +000042
Mike Rapoport92c9f502009-12-11 16:16:31 -080043#define OMAP_MUX_BASE_OFFSET 0x30 /* Offset from CTRL_BASE */
44#define OMAP_MUX_BASE_SZ 0x5ca
45
Tony Lindgren15ac7af2009-12-11 16:16:32 -080046struct omap_mux_entry {
47 struct omap_mux mux;
48 struct list_head node;
49};
50
Benoit Cousson112485e2010-08-16 10:55:35 +020051static LIST_HEAD(mux_partitions);
52static DEFINE_MUTEX(muxmode_mutex);
Mike Rapoport92c9f502009-12-11 16:16:31 -080053
Benoit Cousson112485e2010-08-16 10:55:35 +020054struct omap_mux_partition *omap_mux_get(const char *name)
Mike Rapoport92c9f502009-12-11 16:16:31 -080055{
Benoit Cousson112485e2010-08-16 10:55:35 +020056 struct omap_mux_partition *partition;
57
58 list_for_each_entry(partition, &mux_partitions, node) {
59 if (!strcmp(name, partition->name))
60 return partition;
61 }
62
63 return NULL;
Mike Rapoport92c9f502009-12-11 16:16:31 -080064}
65
Benoit Cousson112485e2010-08-16 10:55:35 +020066u16 omap_mux_read(struct omap_mux_partition *partition, u16 reg)
Mike Rapoport92c9f502009-12-11 16:16:31 -080067{
Benoit Cousson112485e2010-08-16 10:55:35 +020068 if (partition->flags & OMAP_MUX_REG_8BIT)
69 return __raw_readb(partition->base + reg);
Mike Rapoport92c9f502009-12-11 16:16:31 -080070 else
Benoit Cousson112485e2010-08-16 10:55:35 +020071 return __raw_readw(partition->base + reg);
Mike Rapoport92c9f502009-12-11 16:16:31 -080072}
Tony Lindgren7d7f6652008-01-25 00:42:48 -080073
Benoit Cousson112485e2010-08-16 10:55:35 +020074void omap_mux_write(struct omap_mux_partition *partition, u16 val,
75 u16 reg)
Tony Lindgrend4bb72e2010-01-19 15:15:24 -080076{
Benoit Cousson112485e2010-08-16 10:55:35 +020077 if (partition->flags & OMAP_MUX_REG_8BIT)
78 __raw_writeb(val, partition->base + reg);
79 else
80 __raw_writew(val, partition->base + reg);
81}
82
83void omap_mux_write_array(struct omap_mux_partition *partition,
84 struct omap_board_mux *board_mux)
85{
Colin Crossd4ff6122011-05-31 12:00:09 -070086 if (!board_mux)
87 return;
88
Benoit Cousson112485e2010-08-16 10:55:35 +020089 while (board_mux->reg_offset != OMAP_MUX_TERMINATOR) {
90 omap_mux_write(partition, board_mux->value,
91 board_mux->reg_offset);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -080092 board_mux++;
93 }
94}
95
Tony Lindgren15ac7af2009-12-11 16:16:32 -080096#ifdef CONFIG_OMAP_MUX
97
98static char *omap_mux_options;
99
Benoit Cousson112485e2010-08-16 10:55:35 +0200100static int __init _omap_mux_init_gpio(struct omap_mux_partition *partition,
101 int gpio, int val)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800102{
103 struct omap_mux_entry *e;
Sanjeev Premica828762010-09-23 18:27:18 -0700104 struct omap_mux *gpio_mux = NULL;
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300105 u16 old_mode;
106 u16 mux_mode;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800107 int found = 0;
Benoit Cousson112485e2010-08-16 10:55:35 +0200108 struct list_head *muxmodes = &partition->muxmodes;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800109
110 if (!gpio)
111 return -EINVAL;
112
Benoit Cousson112485e2010-08-16 10:55:35 +0200113 list_for_each_entry(e, muxmodes, node) {
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800114 struct omap_mux *m = &e->mux;
115 if (gpio == m->gpio) {
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300116 gpio_mux = m;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800117 found++;
118 }
119 }
120
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300121 if (found == 0) {
Dan Murphy032a6422010-11-15 09:50:50 -0600122 pr_err("%s: Could not set gpio%i\n", __func__, gpio);
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300123 return -ENODEV;
124 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800125
126 if (found > 1) {
Dan Murphy032a6422010-11-15 09:50:50 -0600127 pr_info("%s: Multiple gpio paths (%d) for gpio%i\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200128 found, gpio);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800129 return -EINVAL;
130 }
131
Benoit Cousson112485e2010-08-16 10:55:35 +0200132 old_mode = omap_mux_read(partition, gpio_mux->reg_offset);
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300133 mux_mode = val & ~(OMAP_MUX_NR_MODES - 1);
Benoit Cousson112485e2010-08-16 10:55:35 +0200134 if (partition->flags & OMAP_MUX_GPIO_IN_MODE3)
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300135 mux_mode |= OMAP_MUX_MODE3;
136 else
137 mux_mode |= OMAP_MUX_MODE4;
Dan Murphy032a6422010-11-15 09:50:50 -0600138 pr_debug("%s: Setting signal %s.gpio%i 0x%04x -> 0x%04x\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200139 gpio_mux->muxnames[0], gpio, old_mode, mux_mode);
Benoit Cousson112485e2010-08-16 10:55:35 +0200140 omap_mux_write(partition, mux_mode, gpio_mux->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800141
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300142 return 0;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800143}
144
Benoit Cousson112485e2010-08-16 10:55:35 +0200145int __init omap_mux_init_gpio(int gpio, int val)
146{
147 struct omap_mux_partition *partition;
148 int ret;
149
150 list_for_each_entry(partition, &mux_partitions, node) {
151 ret = _omap_mux_init_gpio(partition, gpio, val);
152 if (!ret)
153 return ret;
154 }
155
156 return -ENODEV;
157}
158
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800159static int __init _omap_mux_get_by_name(struct omap_mux_partition *partition,
160 const char *muxname,
161 struct omap_mux **found_mux)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800162{
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800163 struct omap_mux *mux = NULL;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800164 struct omap_mux_entry *e;
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700165 const char *mode_name;
Felipe Balbiafb7d702011-01-17 06:31:18 +0200166 int found = 0, found_mode = 0, mode0_len = 0;
Benoit Cousson112485e2010-08-16 10:55:35 +0200167 struct list_head *muxmodes = &partition->muxmodes;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800168
169 mode_name = strchr(muxname, '.');
170 if (mode_name) {
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700171 mode0_len = strlen(muxname) - strlen(mode_name);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800172 mode_name++;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800173 } else {
174 mode_name = muxname;
175 }
176
Benoit Cousson112485e2010-08-16 10:55:35 +0200177 list_for_each_entry(e, muxmodes, node) {
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800178 char *m0_entry;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800179 int i;
180
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800181 mux = &e->mux;
182 m0_entry = mux->muxnames[0];
183
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700184 /* First check for full name in mode0.muxmode format */
185 if (mode0_len && strncmp(muxname, m0_entry, mode0_len))
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800186 continue;
187
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700188 /* Then check for muxmode only */
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800189 for (i = 0; i < OMAP_MUX_NR_MODES; i++) {
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800190 char *mode_cur = mux->muxnames[i];
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800191
192 if (!mode_cur)
193 continue;
194
195 if (!strcmp(mode_name, mode_cur)) {
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800196 *found_mux = mux;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800197 found++;
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800198 found_mode = i;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800199 }
200 }
201 }
202
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800203 if (found == 1) {
204 return found_mode;
205 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800206
207 if (found > 1) {
Dan Murphy032a6422010-11-15 09:50:50 -0600208 pr_err("%s: Multiple signal paths (%i) for %s\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200209 found, muxname);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800210 return -EINVAL;
211 }
212
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800213 pr_err("%s: Could not find signal %s\n", __func__, muxname);
214
215 return -ENODEV;
216}
217
218static int __init
219omap_mux_get_by_name(const char *muxname,
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 Lindgren15ac7af2009-12-11 16:16:32 -0800236
237 return -ENODEV;
238}
239
Benoit Cousson112485e2010-08-16 10:55:35 +0200240int __init omap_mux_init_signal(const char *muxname, int val)
241{
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800242 struct omap_mux_partition *partition = NULL;
243 struct omap_mux *mux = NULL;
244 u16 old_mode;
245 int mux_mode;
Benoit Cousson112485e2010-08-16 10:55:35 +0200246
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800247 mux_mode = omap_mux_get_by_name(muxname, &partition, &mux);
248 if (mux_mode < 0)
249 return mux_mode;
Benoit Cousson112485e2010-08-16 10:55:35 +0200250
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800251 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 Cousson112485e2010-08-16 10:55:35 +0200256
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800257 return 0;
Benoit Cousson112485e2010-08-16 10:55:35 +0200258}
259
Tony Lindgren9796b322010-12-22 18:42:35 -0800260struct omap_hwmod_mux_info * __init
261omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads)
262{
263 struct omap_hwmod_mux_info *hmux;
Tony Lindgren029268e2011-03-11 11:32:25 -0800264 int i, nr_pads_dynamic = 0;
Tony Lindgren9796b322010-12-22 18:42:35 -0800265
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 Lindgren029268e2011-03-11 11:32:25 -0800308
Paul Walmsley96dc19f2011-12-16 14:36:57 -0700309 if (pad->flags &
310 (OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP))
Tony Lindgren029268e2011-03-11 11:32:25 -0800311 nr_pads_dynamic++;
312
Tony Lindgren9796b322010-12-22 18:42:35 -0800313 pr_debug("%s: Initialized %s\n", __func__, pad->name);
314 }
315
Tony Lindgren029268e2011-03-11 11:32:25 -0800316 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 Walmsley96dc19f2011-12-16 14:36:57 -0700335 if (pad->flags &
336 (OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP)) {
Tony Lindgren029268e2011-03-11 11:32:25 -0800337 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 Lindgren9796b322010-12-22 18:42:35 -0800344 return hmux;
345
346err3:
347 kfree(hmux->pads);
348err2:
349 kfree(hmux);
350err1:
351 pr_err("%s: Could not allocate device mux entry\n", __func__);
352
353 return NULL;
354}
355
Tony Lindgren8d9af882010-12-22 18:42:35 -0800356/* Assumes the calling function takes care of locking */
357void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state)
358{
359 int i;
360
Tony Lindgren029268e2011-03-11 11:32:25 -0800361 /* Runtime idling of dynamic pads */
362 if (state == _HWMOD_STATE_IDLE && hmux->enabled) {
363 for (i = 0; i < hmux->nr_pads_dynamic; i++) {
364 struct omap_device_pad *pad = hmux->pads_dynamic[i];
365 int val = -EINVAL;
366
Tony Lindgren029268e2011-03-11 11:32:25 -0800367 val = pad->idle;
368 omap_mux_write(pad->partition, val,
369 pad->mux->reg_offset);
370 }
371
372 return;
373 }
374
375 /* Runtime enabling of dynamic pads */
R Sricharan86c79bf2011-03-11 11:32:25 -0800376 if ((state == _HWMOD_STATE_ENABLED) && hmux->pads_dynamic
377 && hmux->enabled) {
Tony Lindgren029268e2011-03-11 11:32:25 -0800378 for (i = 0; i < hmux->nr_pads_dynamic; i++) {
379 struct omap_device_pad *pad = hmux->pads_dynamic[i];
380 int val = -EINVAL;
381
Tony Lindgren029268e2011-03-11 11:32:25 -0800382 val = pad->enable;
383 omap_mux_write(pad->partition, val,
384 pad->mux->reg_offset);
Tony Lindgren029268e2011-03-11 11:32:25 -0800385 }
386
R Sricharan86c79bf2011-03-11 11:32:25 -0800387 return;
Tony Lindgren029268e2011-03-11 11:32:25 -0800388 }
389
390 /* Enabling or disabling of all pads */
Tony Lindgren8d9af882010-12-22 18:42:35 -0800391 for (i = 0; i < hmux->nr_pads; i++) {
392 struct omap_device_pad *pad = &hmux->pads[i];
393 int flags, val = -EINVAL;
394
395 flags = pad->flags;
396
397 switch (state) {
398 case _HWMOD_STATE_ENABLED:
Tony Lindgren8d9af882010-12-22 18:42:35 -0800399 val = pad->enable;
400 pr_debug("%s: Enabling %s %x\n", __func__,
401 pad->name, val);
402 break;
Tony Lindgren8d9af882010-12-22 18:42:35 -0800403 case _HWMOD_STATE_DISABLED:
Tony Lindgren8d9af882010-12-22 18:42:35 -0800404 /* Use safe mode unless OMAP_DEVICE_PAD_REMUX */
405 if (flags & OMAP_DEVICE_PAD_REMUX)
406 val = pad->off;
407 else
408 val = OMAP_MUX_MODE7;
Tony Lindgren8d9af882010-12-22 18:42:35 -0800409 pr_debug("%s: Disabling %s %x\n", __func__,
410 pad->name, val);
R Sricharan86c79bf2011-03-11 11:32:25 -0800411 break;
412 default:
413 /* Nothing to be done */
414 break;
Tony Lindgren8d9af882010-12-22 18:42:35 -0800415 };
416
417 if (val >= 0) {
418 omap_mux_write(pad->partition, val,
419 pad->mux->reg_offset);
420 pad->flags = flags;
421 }
422 }
Tony Lindgren029268e2011-03-11 11:32:25 -0800423
424 if (state == _HWMOD_STATE_ENABLED)
425 hmux->enabled = true;
426 else
427 hmux->enabled = false;
Tony Lindgren8d9af882010-12-22 18:42:35 -0800428}
429
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800430#ifdef CONFIG_DEBUG_FS
431
432#define OMAP_MUX_MAX_NR_FLAGS 10
433#define OMAP_MUX_TEST_FLAG(val, mask) \
434 if (((val) & (mask)) == (mask)) { \
435 i++; \
436 flags[i] = #mask; \
437 }
438
439/* REVISIT: Add checking for non-optimal mux settings */
440static inline void omap_mux_decode(struct seq_file *s, u16 val)
441{
442 char *flags[OMAP_MUX_MAX_NR_FLAGS];
Tony Lindgren78737ae2010-02-01 13:03:42 -0800443 char mode[sizeof("OMAP_MUX_MODE") + 1];
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800444 int i = -1;
445
446 sprintf(mode, "OMAP_MUX_MODE%d", val & 0x7);
447 i++;
448 flags[i] = mode;
449
450 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_OFF_WAKEUPENABLE);
451 if (val & OMAP_OFF_EN) {
452 if (!(val & OMAP_OFFOUT_EN)) {
453 if (!(val & OMAP_OFF_PULL_UP)) {
454 OMAP_MUX_TEST_FLAG(val,
455 OMAP_PIN_OFF_INPUT_PULLDOWN);
456 } else {
457 OMAP_MUX_TEST_FLAG(val,
458 OMAP_PIN_OFF_INPUT_PULLUP);
459 }
460 } else {
461 if (!(val & OMAP_OFFOUT_VAL)) {
462 OMAP_MUX_TEST_FLAG(val,
463 OMAP_PIN_OFF_OUTPUT_LOW);
464 } else {
465 OMAP_MUX_TEST_FLAG(val,
466 OMAP_PIN_OFF_OUTPUT_HIGH);
467 }
468 }
469 }
470
471 if (val & OMAP_INPUT_EN) {
472 if (val & OMAP_PULL_ENA) {
473 if (!(val & OMAP_PULL_UP)) {
474 OMAP_MUX_TEST_FLAG(val,
475 OMAP_PIN_INPUT_PULLDOWN);
476 } else {
477 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT_PULLUP);
478 }
479 } else {
480 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT);
481 }
482 } else {
483 i++;
484 flags[i] = "OMAP_PIN_OUTPUT";
485 }
486
487 do {
488 seq_printf(s, "%s", flags[i]);
489 if (i > 0)
490 seq_printf(s, " | ");
491 } while (i-- > 0);
492}
493
Benoit Cousson112485e2010-08-16 10:55:35 +0200494#define OMAP_MUX_DEFNAME_LEN 32
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800495
496static int omap_mux_dbg_board_show(struct seq_file *s, void *unused)
497{
Benoit Cousson112485e2010-08-16 10:55:35 +0200498 struct omap_mux_partition *partition = s->private;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800499 struct omap_mux_entry *e;
Benoit Cousson112485e2010-08-16 10:55:35 +0200500 u8 omap_gen = omap_rev() >> 28;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800501
Benoit Cousson112485e2010-08-16 10:55:35 +0200502 list_for_each_entry(e, &partition->muxmodes, node) {
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800503 struct omap_mux *m = &e->mux;
504 char m0_def[OMAP_MUX_DEFNAME_LEN];
505 char *m0_name = m->muxnames[0];
506 u16 val;
507 int i, mode;
508
509 if (!m0_name)
510 continue;
511
Tony Lindgren78737ae2010-02-01 13:03:42 -0800512 /* REVISIT: Needs to be updated if mode0 names get longer */
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800513 for (i = 0; i < OMAP_MUX_DEFNAME_LEN; i++) {
514 if (m0_name[i] == '\0') {
515 m0_def[i] = m0_name[i];
516 break;
517 }
518 m0_def[i] = toupper(m0_name[i]);
519 }
Benoit Cousson112485e2010-08-16 10:55:35 +0200520 val = omap_mux_read(partition, m->reg_offset);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800521 mode = val & OMAP_MUX_MODE7;
Benoit Cousson112485e2010-08-16 10:55:35 +0200522 if (mode != 0)
523 seq_printf(s, "/* %s */\n", m->muxnames[mode]);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800524
Benoit Cousson112485e2010-08-16 10:55:35 +0200525 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300526 * XXX: Might be revisited to support differences across
Benoit Cousson112485e2010-08-16 10:55:35 +0200527 * same OMAP generation.
528 */
529 seq_printf(s, "OMAP%d_MUX(%s, ", omap_gen, m0_def);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800530 omap_mux_decode(s, val);
531 seq_printf(s, "),\n");
532 }
533
534 return 0;
535}
536
537static int omap_mux_dbg_board_open(struct inode *inode, struct file *file)
538{
Benoit Cousson112485e2010-08-16 10:55:35 +0200539 return single_open(file, omap_mux_dbg_board_show, inode->i_private);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800540}
541
542static const struct file_operations omap_mux_dbg_board_fops = {
543 .open = omap_mux_dbg_board_open,
544 .read = seq_read,
545 .llseek = seq_lseek,
546 .release = single_release,
547};
548
Benoit Cousson112485e2010-08-16 10:55:35 +0200549static struct omap_mux_partition *omap_mux_get_partition(struct omap_mux *mux)
550{
551 struct omap_mux_partition *partition;
552
553 list_for_each_entry(partition, &mux_partitions, node) {
554 struct list_head *muxmodes = &partition->muxmodes;
555 struct omap_mux_entry *e;
556
557 list_for_each_entry(e, muxmodes, node) {
558 struct omap_mux *m = &e->mux;
559
560 if (m == mux)
561 return partition;
562 }
563 }
564
565 return NULL;
566}
567
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800568static int omap_mux_dbg_signal_show(struct seq_file *s, void *unused)
569{
570 struct omap_mux *m = s->private;
Benoit Cousson112485e2010-08-16 10:55:35 +0200571 struct omap_mux_partition *partition;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800572 const char *none = "NA";
573 u16 val;
574 int mode;
575
Benoit Cousson112485e2010-08-16 10:55:35 +0200576 partition = omap_mux_get_partition(m);
577 if (!partition)
578 return 0;
579
580 val = omap_mux_read(partition, m->reg_offset);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800581 mode = val & OMAP_MUX_MODE7;
582
Benoit Cousson112485e2010-08-16 10:55:35 +0200583 seq_printf(s, "name: %s.%s (0x%08x/0x%03x = 0x%04x), b %s, t %s\n",
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800584 m->muxnames[0], m->muxnames[mode],
Benoit Cousson112485e2010-08-16 10:55:35 +0200585 partition->phys + m->reg_offset, m->reg_offset, val,
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800586 m->balls[0] ? m->balls[0] : none,
587 m->balls[1] ? m->balls[1] : none);
588 seq_printf(s, "mode: ");
589 omap_mux_decode(s, val);
590 seq_printf(s, "\n");
591 seq_printf(s, "signals: %s | %s | %s | %s | %s | %s | %s | %s\n",
592 m->muxnames[0] ? m->muxnames[0] : none,
593 m->muxnames[1] ? m->muxnames[1] : none,
594 m->muxnames[2] ? m->muxnames[2] : none,
595 m->muxnames[3] ? m->muxnames[3] : none,
596 m->muxnames[4] ? m->muxnames[4] : none,
597 m->muxnames[5] ? m->muxnames[5] : none,
598 m->muxnames[6] ? m->muxnames[6] : none,
599 m->muxnames[7] ? m->muxnames[7] : none);
600
601 return 0;
602}
603
604#define OMAP_MUX_MAX_ARG_CHAR 7
605
606static ssize_t omap_mux_dbg_signal_write(struct file *file,
Benoit Cousson112485e2010-08-16 10:55:35 +0200607 const char __user *user_buf,
608 size_t count, loff_t *ppos)
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800609{
610 char buf[OMAP_MUX_MAX_ARG_CHAR];
611 struct seq_file *seqf;
612 struct omap_mux *m;
613 unsigned long val;
614 int buf_size, ret;
Benoit Cousson112485e2010-08-16 10:55:35 +0200615 struct omap_mux_partition *partition;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800616
617 if (count > OMAP_MUX_MAX_ARG_CHAR)
618 return -EINVAL;
619
620 memset(buf, 0, sizeof(buf));
621 buf_size = min(count, sizeof(buf) - 1);
622
623 if (copy_from_user(buf, user_buf, buf_size))
624 return -EFAULT;
625
626 ret = strict_strtoul(buf, 0x10, &val);
627 if (ret < 0)
628 return ret;
629
630 if (val > 0xffff)
631 return -EINVAL;
632
633 seqf = file->private_data;
634 m = seqf->private;
635
Benoit Cousson112485e2010-08-16 10:55:35 +0200636 partition = omap_mux_get_partition(m);
637 if (!partition)
638 return -ENODEV;
639
640 omap_mux_write(partition, (u16)val, m->reg_offset);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800641 *ppos += count;
642
643 return count;
644}
645
646static int omap_mux_dbg_signal_open(struct inode *inode, struct file *file)
647{
648 return single_open(file, omap_mux_dbg_signal_show, inode->i_private);
649}
650
651static const struct file_operations omap_mux_dbg_signal_fops = {
652 .open = omap_mux_dbg_signal_open,
653 .read = seq_read,
654 .write = omap_mux_dbg_signal_write,
655 .llseek = seq_lseek,
656 .release = single_release,
657};
658
659static struct dentry *mux_dbg_dir;
660
Benoit Cousson112485e2010-08-16 10:55:35 +0200661static void __init omap_mux_dbg_create_entry(
662 struct omap_mux_partition *partition,
663 struct dentry *mux_dbg_dir)
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800664{
665 struct omap_mux_entry *e;
666
Benoit Cousson112485e2010-08-16 10:55:35 +0200667 list_for_each_entry(e, &partition->muxmodes, node) {
668 struct omap_mux *m = &e->mux;
669
Vasiliy Kulikov9b127712011-02-04 12:23:13 +0000670 (void)debugfs_create_file(m->muxnames[0], S_IWUSR, mux_dbg_dir,
Benoit Cousson112485e2010-08-16 10:55:35 +0200671 m, &omap_mux_dbg_signal_fops);
672 }
673}
674
675static void __init omap_mux_dbg_init(void)
676{
677 struct omap_mux_partition *partition;
678 static struct dentry *mux_dbg_board_dir;
679
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800680 mux_dbg_dir = debugfs_create_dir("omap_mux", NULL);
681 if (!mux_dbg_dir)
682 return;
683
Benoit Cousson112485e2010-08-16 10:55:35 +0200684 mux_dbg_board_dir = debugfs_create_dir("board", mux_dbg_dir);
685 if (!mux_dbg_board_dir)
686 return;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800687
Benoit Cousson112485e2010-08-16 10:55:35 +0200688 list_for_each_entry(partition, &mux_partitions, node) {
689 omap_mux_dbg_create_entry(partition, mux_dbg_dir);
690 (void)debugfs_create_file(partition->name, S_IRUGO,
691 mux_dbg_board_dir, partition,
692 &omap_mux_dbg_board_fops);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800693 }
694}
695
696#else
697static inline void omap_mux_dbg_init(void)
698{
699}
700#endif /* CONFIG_DEBUG_FS */
701
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800702static void __init omap_mux_free_names(struct omap_mux *m)
703{
704 int i;
705
706 for (i = 0; i < OMAP_MUX_NR_MODES; i++)
707 kfree(m->muxnames[i]);
708
709#ifdef CONFIG_DEBUG_FS
710 for (i = 0; i < OMAP_MUX_NR_SIDES; i++)
711 kfree(m->balls[i]);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000712#endif
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800713
714}
715
716/* Free all data except for GPIO pins unless CONFIG_DEBUG_FS is set */
717static int __init omap_mux_late_init(void)
718{
Benoit Cousson112485e2010-08-16 10:55:35 +0200719 struct omap_mux_partition *partition;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800720
Benoit Cousson112485e2010-08-16 10:55:35 +0200721 list_for_each_entry(partition, &mux_partitions, node) {
722 struct omap_mux_entry *e, *tmp;
723 list_for_each_entry_safe(e, tmp, &partition->muxmodes, node) {
724 struct omap_mux *m = &e->mux;
725 u16 mode = omap_mux_read(partition, m->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800726
Benoit Cousson112485e2010-08-16 10:55:35 +0200727 if (OMAP_MODE_GPIO(mode))
728 continue;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800729
730#ifndef CONFIG_DEBUG_FS
Benoit Cousson112485e2010-08-16 10:55:35 +0200731 mutex_lock(&muxmode_mutex);
732 list_del(&e->node);
733 mutex_unlock(&muxmode_mutex);
734 omap_mux_free_names(m);
735 kfree(m);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800736#endif
Benoit Cousson112485e2010-08-16 10:55:35 +0200737 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800738 }
739
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800740 omap_mux_dbg_init();
741
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800742 return 0;
743}
744late_initcall(omap_mux_late_init);
745
746static void __init omap_mux_package_fixup(struct omap_mux *p,
747 struct omap_mux *superset)
748{
749 while (p->reg_offset != OMAP_MUX_TERMINATOR) {
750 struct omap_mux *s = superset;
751 int found = 0;
752
753 while (s->reg_offset != OMAP_MUX_TERMINATOR) {
754 if (s->reg_offset == p->reg_offset) {
755 *s = *p;
756 found++;
757 break;
758 }
759 s++;
760 }
761 if (!found)
Dan Murphy032a6422010-11-15 09:50:50 -0600762 pr_err("%s: Unknown entry offset 0x%x\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200763 p->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800764 p++;
765 }
766}
767
768#ifdef CONFIG_DEBUG_FS
769
770static void __init omap_mux_package_init_balls(struct omap_ball *b,
771 struct omap_mux *superset)
772{
773 while (b->reg_offset != OMAP_MUX_TERMINATOR) {
774 struct omap_mux *s = superset;
775 int found = 0;
776
777 while (s->reg_offset != OMAP_MUX_TERMINATOR) {
778 if (s->reg_offset == b->reg_offset) {
779 s->balls[0] = b->balls[0];
780 s->balls[1] = b->balls[1];
781 found++;
782 break;
783 }
784 s++;
785 }
786 if (!found)
Dan Murphy032a6422010-11-15 09:50:50 -0600787 pr_err("%s: Unknown ball offset 0x%x\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200788 b->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800789 b++;
790 }
791}
792
793#else /* CONFIG_DEBUG_FS */
794
795static inline void omap_mux_package_init_balls(struct omap_ball *b,
796 struct omap_mux *superset)
797{
798}
799
800#endif /* CONFIG_DEBUG_FS */
801
802static int __init omap_mux_setup(char *options)
803{
804 if (!options)
805 return 0;
806
807 omap_mux_options = options;
808
809 return 1;
810}
811__setup("omap_mux=", omap_mux_setup);
812
813/*
814 * Note that the omap_mux=some.signal1=0x1234,some.signal2=0x1234
815 * cmdline options only override the bootloader values.
816 * During development, please enable CONFIG_DEBUG_FS, and use the
817 * signal specific entries under debugfs.
818 */
819static void __init omap_mux_set_cmdline_signals(void)
820{
821 char *options, *next_opt, *token;
822
823 if (!omap_mux_options)
824 return;
825
Thomas Meyerdccb3b02011-08-06 09:29:10 +0000826 options = kstrdup(omap_mux_options, GFP_KERNEL);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800827 if (!options)
828 return;
829
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800830 next_opt = options;
831
832 while ((token = strsep(&next_opt, ",")) != NULL) {
833 char *keyval, *name;
834 unsigned long val;
835
836 keyval = token;
837 name = strsep(&keyval, "=");
838 if (name) {
839 int res;
840
841 res = strict_strtoul(keyval, 0x10, &val);
842 if (res < 0)
843 continue;
844
845 omap_mux_init_signal(name, (u16)val);
846 }
847 }
848
849 kfree(options);
850}
851
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800852static int __init omap_mux_copy_names(struct omap_mux *src,
Benoit Cousson112485e2010-08-16 10:55:35 +0200853 struct omap_mux *dst)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800854{
855 int i;
856
857 for (i = 0; i < OMAP_MUX_NR_MODES; i++) {
858 if (src->muxnames[i]) {
Thomas Meyerdccb3b02011-08-06 09:29:10 +0000859 dst->muxnames[i] = kstrdup(src->muxnames[i],
860 GFP_KERNEL);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800861 if (!dst->muxnames[i])
862 goto free;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800863 }
864 }
865
866#ifdef CONFIG_DEBUG_FS
867 for (i = 0; i < OMAP_MUX_NR_SIDES; i++) {
868 if (src->balls[i]) {
Thomas Meyerdccb3b02011-08-06 09:29:10 +0000869 dst->balls[i] = kstrdup(src->balls[i], GFP_KERNEL);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800870 if (!dst->balls[i])
871 goto free;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800872 }
873 }
874#endif
875
876 return 0;
877
878free:
879 omap_mux_free_names(dst);
880 return -ENOMEM;
881
882}
883
884#endif /* CONFIG_OMAP_MUX */
885
Benoit Cousson112485e2010-08-16 10:55:35 +0200886static struct omap_mux *omap_mux_get_by_gpio(
887 struct omap_mux_partition *partition,
888 int gpio)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800889{
890 struct omap_mux_entry *e;
Benoit Cousson112485e2010-08-16 10:55:35 +0200891 struct omap_mux *ret = NULL;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800892
Benoit Cousson112485e2010-08-16 10:55:35 +0200893 list_for_each_entry(e, &partition->muxmodes, node) {
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800894 struct omap_mux *m = &e->mux;
895 if (m->gpio == gpio) {
Benoit Cousson112485e2010-08-16 10:55:35 +0200896 ret = m;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800897 break;
898 }
899 }
900
Benoit Cousson112485e2010-08-16 10:55:35 +0200901 return ret;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800902}
903
904/* Needed for dynamic muxing of GPIO pins for off-idle */
905u16 omap_mux_get_gpio(int gpio)
906{
Benoit Cousson112485e2010-08-16 10:55:35 +0200907 struct omap_mux_partition *partition;
Govindraj.R30ebad92011-06-01 11:28:56 +0530908 struct omap_mux *m = NULL;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800909
Benoit Cousson112485e2010-08-16 10:55:35 +0200910 list_for_each_entry(partition, &mux_partitions, node) {
911 m = omap_mux_get_by_gpio(partition, gpio);
912 if (m)
913 return omap_mux_read(partition, m->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800914 }
915
Benoit Cousson112485e2010-08-16 10:55:35 +0200916 if (!m || m->reg_offset == OMAP_MUX_TERMINATOR)
Dan Murphy032a6422010-11-15 09:50:50 -0600917 pr_err("%s: Could not get gpio%i\n", __func__, gpio);
Benoit Cousson112485e2010-08-16 10:55:35 +0200918
919 return OMAP_MUX_TERMINATOR;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800920}
921
922/* Needed for dynamic muxing of GPIO pins for off-idle */
923void omap_mux_set_gpio(u16 val, int gpio)
924{
Benoit Cousson112485e2010-08-16 10:55:35 +0200925 struct omap_mux_partition *partition;
926 struct omap_mux *m = NULL;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800927
Benoit Cousson112485e2010-08-16 10:55:35 +0200928 list_for_each_entry(partition, &mux_partitions, node) {
929 m = omap_mux_get_by_gpio(partition, gpio);
930 if (m) {
931 omap_mux_write(partition, val, m->reg_offset);
932 return;
933 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800934 }
935
Benoit Cousson112485e2010-08-16 10:55:35 +0200936 if (!m || m->reg_offset == OMAP_MUX_TERMINATOR)
Dan Murphy032a6422010-11-15 09:50:50 -0600937 pr_err("%s: Could not set gpio%i\n", __func__, gpio);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800938}
939
Benoit Cousson112485e2010-08-16 10:55:35 +0200940static struct omap_mux * __init omap_mux_list_add(
941 struct omap_mux_partition *partition,
942 struct omap_mux *src)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800943{
944 struct omap_mux_entry *entry;
945 struct omap_mux *m;
946
947 entry = kzalloc(sizeof(struct omap_mux_entry), GFP_KERNEL);
948 if (!entry)
949 return NULL;
950
951 m = &entry->mux;
Aaro Koskinen30833142011-01-06 19:49:28 -0800952 entry->mux = *src;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800953
954#ifdef CONFIG_OMAP_MUX
955 if (omap_mux_copy_names(src, m)) {
956 kfree(entry);
957 return NULL;
958 }
959#endif
960
961 mutex_lock(&muxmode_mutex);
Benoit Cousson112485e2010-08-16 10:55:35 +0200962 list_add_tail(&entry->node, &partition->muxmodes);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800963 mutex_unlock(&muxmode_mutex);
964
965 return m;
966}
967
968/*
969 * Note if CONFIG_OMAP_MUX is not selected, we will only initialize
970 * the GPIO to mux offset mapping that is needed for dynamic muxing
971 * of GPIO pins for off-idle.
972 */
Benoit Cousson112485e2010-08-16 10:55:35 +0200973static void __init omap_mux_init_list(struct omap_mux_partition *partition,
974 struct omap_mux *superset)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800975{
976 while (superset->reg_offset != OMAP_MUX_TERMINATOR) {
977 struct omap_mux *entry;
978
Ranjith Lohithakshanb72c7d52010-02-17 17:17:01 +0000979#ifdef CONFIG_OMAP_MUX
980 if (!superset->muxnames || !superset->muxnames[0]) {
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800981 superset++;
982 continue;
983 }
Ranjith Lohithakshanb72c7d52010-02-17 17:17:01 +0000984#else
985 /* Skip pins that are not muxed as GPIO by bootloader */
Benoit Cousson112485e2010-08-16 10:55:35 +0200986 if (!OMAP_MODE_GPIO(omap_mux_read(partition,
987 superset->reg_offset))) {
Tony Lindgren9ecef432010-02-01 11:22:54 -0800988 superset++;
989 continue;
990 }
991#endif
992
Benoit Cousson112485e2010-08-16 10:55:35 +0200993 entry = omap_mux_list_add(partition, superset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800994 if (!entry) {
Dan Murphy032a6422010-11-15 09:50:50 -0600995 pr_err("%s: Could not add entry\n", __func__);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800996 return;
997 }
998 superset++;
999 }
1000}
1001
Tony Lindgren321cfc82010-02-15 10:03:35 -08001002#ifdef CONFIG_OMAP_MUX
1003
1004static void omap_mux_init_package(struct omap_mux *superset,
1005 struct omap_mux *package_subset,
1006 struct omap_ball *package_balls)
1007{
1008 if (package_subset)
1009 omap_mux_package_fixup(package_subset, superset);
1010 if (package_balls)
1011 omap_mux_package_init_balls(package_balls, superset);
1012}
1013
Benoit Cousson112485e2010-08-16 10:55:35 +02001014static void omap_mux_init_signals(struct omap_mux_partition *partition,
1015 struct omap_board_mux *board_mux)
Tony Lindgren321cfc82010-02-15 10:03:35 -08001016{
1017 omap_mux_set_cmdline_signals();
Benoit Cousson112485e2010-08-16 10:55:35 +02001018 omap_mux_write_array(partition, board_mux);
Tony Lindgren321cfc82010-02-15 10:03:35 -08001019}
1020
1021#else
1022
1023static void omap_mux_init_package(struct omap_mux *superset,
1024 struct omap_mux *package_subset,
1025 struct omap_ball *package_balls)
1026{
1027}
1028
Benoit Cousson112485e2010-08-16 10:55:35 +02001029static void omap_mux_init_signals(struct omap_mux_partition *partition,
1030 struct omap_board_mux *board_mux)
Tony Lindgren321cfc82010-02-15 10:03:35 -08001031{
1032}
1033
1034#endif
1035
Benoit Cousson112485e2010-08-16 10:55:35 +02001036static u32 mux_partitions_cnt;
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001037
Benoit Cousson112485e2010-08-16 10:55:35 +02001038int __init omap_mux_init(const char *name, u32 flags,
1039 u32 mux_pbase, u32 mux_size,
1040 struct omap_mux *superset,
1041 struct omap_mux *package_subset,
1042 struct omap_board_mux *board_mux,
1043 struct omap_ball *package_balls)
1044{
1045 struct omap_mux_partition *partition;
1046
1047 partition = kzalloc(sizeof(struct omap_mux_partition), GFP_KERNEL);
1048 if (!partition)
1049 return -ENOMEM;
1050
1051 partition->name = name;
1052 partition->flags = flags;
1053 partition->size = mux_size;
1054 partition->phys = mux_pbase;
1055 partition->base = ioremap(mux_pbase, mux_size);
1056 if (!partition->base) {
Dan Murphy032a6422010-11-15 09:50:50 -06001057 pr_err("%s: Could not ioremap mux partition at 0x%08x\n",
1058 __func__, partition->phys);
Aaro Koskinen9d47e302011-01-28 14:50:55 +00001059 kfree(partition);
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001060 return -ENODEV;
1061 }
1062
Benoit Cousson112485e2010-08-16 10:55:35 +02001063 INIT_LIST_HEAD(&partition->muxmodes);
1064
1065 list_add_tail(&partition->node, &mux_partitions);
1066 mux_partitions_cnt++;
Dan Murphy032a6422010-11-15 09:50:50 -06001067 pr_info("%s: Add partition: #%d: %s, flags: %x\n", __func__,
Benoit Cousson112485e2010-08-16 10:55:35 +02001068 mux_partitions_cnt, partition->name, partition->flags);
Tony Lindgrend5425be2010-07-05 16:31:35 +03001069
Tony Lindgren321cfc82010-02-15 10:03:35 -08001070 omap_mux_init_package(superset, package_subset, package_balls);
Benoit Cousson112485e2010-08-16 10:55:35 +02001071 omap_mux_init_list(partition, superset);
1072 omap_mux_init_signals(partition, board_mux);
Tony Lindgren2cb0c542010-01-19 18:17:07 -08001073
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001074 return 0;
1075}
1076