blob: 9fe6829f4c16f2dd0837862f5f4254ecba98230b [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>
Tero Kristo13a3fe52011-12-16 14:36:59 -070035#include <linux/irq.h>
36#include <linux/interrupt.h>
Tony Lindgren1dbae812005-11-10 14:26:51 +000037
Russell Kingfced80c2008-09-06 12:10:45 +010038
Tony Lindgren9796b322010-12-22 18:42:35 -080039#include <plat/omap_hwmod.h>
40
Paul Walmsley4814ced2010-10-08 11:40:20 -060041#include "control.h"
Tony Lindgren15ac7af2009-12-11 16:16:32 -080042#include "mux.h"
Tero Kristo13a3fe52011-12-16 14:36:59 -070043#include "prm.h"
Paul Walmsley65e25972012-06-17 12:00:58 -060044#include "common.h"
Tony Lindgren1dbae812005-11-10 14:26:51 +000045
Mike Rapoport92c9f502009-12-11 16:16:31 -080046#define OMAP_MUX_BASE_OFFSET 0x30 /* Offset from CTRL_BASE */
47#define OMAP_MUX_BASE_SZ 0x5ca
48
Tony Lindgren15ac7af2009-12-11 16:16:32 -080049struct omap_mux_entry {
50 struct omap_mux mux;
51 struct list_head node;
52};
53
Benoit Cousson112485e2010-08-16 10:55:35 +020054static LIST_HEAD(mux_partitions);
55static DEFINE_MUTEX(muxmode_mutex);
Mike Rapoport92c9f502009-12-11 16:16:31 -080056
Benoit Cousson112485e2010-08-16 10:55:35 +020057struct omap_mux_partition *omap_mux_get(const char *name)
Mike Rapoport92c9f502009-12-11 16:16:31 -080058{
Benoit Cousson112485e2010-08-16 10:55:35 +020059 struct omap_mux_partition *partition;
60
61 list_for_each_entry(partition, &mux_partitions, node) {
62 if (!strcmp(name, partition->name))
63 return partition;
64 }
65
66 return NULL;
Mike Rapoport92c9f502009-12-11 16:16:31 -080067}
68
Benoit Cousson112485e2010-08-16 10:55:35 +020069u16 omap_mux_read(struct omap_mux_partition *partition, u16 reg)
Mike Rapoport92c9f502009-12-11 16:16:31 -080070{
Benoit Cousson112485e2010-08-16 10:55:35 +020071 if (partition->flags & OMAP_MUX_REG_8BIT)
72 return __raw_readb(partition->base + reg);
Mike Rapoport92c9f502009-12-11 16:16:31 -080073 else
Benoit Cousson112485e2010-08-16 10:55:35 +020074 return __raw_readw(partition->base + reg);
Mike Rapoport92c9f502009-12-11 16:16:31 -080075}
Tony Lindgren7d7f6652008-01-25 00:42:48 -080076
Benoit Cousson112485e2010-08-16 10:55:35 +020077void omap_mux_write(struct omap_mux_partition *partition, u16 val,
78 u16 reg)
Tony Lindgrend4bb72e2010-01-19 15:15:24 -080079{
Benoit Cousson112485e2010-08-16 10:55:35 +020080 if (partition->flags & OMAP_MUX_REG_8BIT)
81 __raw_writeb(val, partition->base + reg);
82 else
83 __raw_writew(val, partition->base + reg);
84}
85
86void omap_mux_write_array(struct omap_mux_partition *partition,
87 struct omap_board_mux *board_mux)
88{
Colin Crossd4ff6122011-05-31 12:00:09 -070089 if (!board_mux)
90 return;
91
Benoit Cousson112485e2010-08-16 10:55:35 +020092 while (board_mux->reg_offset != OMAP_MUX_TERMINATOR) {
93 omap_mux_write(partition, board_mux->value,
94 board_mux->reg_offset);
Tony Lindgrend4bb72e2010-01-19 15:15:24 -080095 board_mux++;
96 }
97}
98
Tony Lindgren15ac7af2009-12-11 16:16:32 -080099#ifdef CONFIG_OMAP_MUX
100
101static char *omap_mux_options;
102
Tony Lindgrend1589f02012-02-20 09:43:30 -0800103static int __init _omap_mux_init_gpio(struct omap_mux_partition *partition,
104 int gpio, int val)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800105{
106 struct omap_mux_entry *e;
Sanjeev Premica828762010-09-23 18:27:18 -0700107 struct omap_mux *gpio_mux = NULL;
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300108 u16 old_mode;
109 u16 mux_mode;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800110 int found = 0;
Benoit Cousson112485e2010-08-16 10:55:35 +0200111 struct list_head *muxmodes = &partition->muxmodes;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800112
113 if (!gpio)
114 return -EINVAL;
115
Benoit Cousson112485e2010-08-16 10:55:35 +0200116 list_for_each_entry(e, muxmodes, node) {
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800117 struct omap_mux *m = &e->mux;
118 if (gpio == m->gpio) {
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300119 gpio_mux = m;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800120 found++;
121 }
122 }
123
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300124 if (found == 0) {
Dan Murphy032a6422010-11-15 09:50:50 -0600125 pr_err("%s: Could not set gpio%i\n", __func__, gpio);
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300126 return -ENODEV;
127 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800128
129 if (found > 1) {
Dan Murphy032a6422010-11-15 09:50:50 -0600130 pr_info("%s: Multiple gpio paths (%d) for gpio%i\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200131 found, gpio);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800132 return -EINVAL;
133 }
134
Benoit Cousson112485e2010-08-16 10:55:35 +0200135 old_mode = omap_mux_read(partition, gpio_mux->reg_offset);
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300136 mux_mode = val & ~(OMAP_MUX_NR_MODES - 1);
Benoit Cousson112485e2010-08-16 10:55:35 +0200137 if (partition->flags & OMAP_MUX_GPIO_IN_MODE3)
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300138 mux_mode |= OMAP_MUX_MODE3;
139 else
140 mux_mode |= OMAP_MUX_MODE4;
Dan Murphy032a6422010-11-15 09:50:50 -0600141 pr_debug("%s: Setting signal %s.gpio%i 0x%04x -> 0x%04x\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200142 gpio_mux->muxnames[0], gpio, old_mode, mux_mode);
Benoit Cousson112485e2010-08-16 10:55:35 +0200143 omap_mux_write(partition, mux_mode, gpio_mux->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800144
Grazvydas Ignotas8a6f7e12010-08-02 13:18:28 +0300145 return 0;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800146}
147
Tony Lindgrend1589f02012-02-20 09:43:30 -0800148int __init omap_mux_init_gpio(int gpio, int val)
Benoit Cousson112485e2010-08-16 10:55:35 +0200149{
150 struct omap_mux_partition *partition;
151 int ret;
152
153 list_for_each_entry(partition, &mux_partitions, node) {
154 ret = _omap_mux_init_gpio(partition, gpio, val);
155 if (!ret)
156 return ret;
157 }
158
159 return -ENODEV;
160}
161
Tony Lindgrend1589f02012-02-20 09:43:30 -0800162static int __init _omap_mux_get_by_name(struct omap_mux_partition *partition,
163 const char *muxname,
164 struct omap_mux **found_mux)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800165{
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800166 struct omap_mux *mux = NULL;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800167 struct omap_mux_entry *e;
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700168 const char *mode_name;
Felipe Balbiafb7d702011-01-17 06:31:18 +0200169 int found = 0, found_mode = 0, mode0_len = 0;
Benoit Cousson112485e2010-08-16 10:55:35 +0200170 struct list_head *muxmodes = &partition->muxmodes;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800171
172 mode_name = strchr(muxname, '.');
173 if (mode_name) {
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700174 mode0_len = strlen(muxname) - strlen(mode_name);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800175 mode_name++;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800176 } else {
177 mode_name = muxname;
178 }
179
Benoit Cousson112485e2010-08-16 10:55:35 +0200180 list_for_each_entry(e, muxmodes, node) {
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800181 char *m0_entry;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800182 int i;
183
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800184 mux = &e->mux;
185 m0_entry = mux->muxnames[0];
186
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700187 /* First check for full name in mode0.muxmode format */
188 if (mode0_len && strncmp(muxname, m0_entry, mode0_len))
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800189 continue;
190
Tony Lindgren5a3b2f72010-10-01 16:35:24 -0700191 /* Then check for muxmode only */
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800192 for (i = 0; i < OMAP_MUX_NR_MODES; i++) {
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800193 char *mode_cur = mux->muxnames[i];
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800194
195 if (!mode_cur)
196 continue;
197
198 if (!strcmp(mode_name, mode_cur)) {
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800199 *found_mux = mux;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800200 found++;
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800201 found_mode = i;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800202 }
203 }
204 }
205
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800206 if (found == 1) {
207 return found_mode;
208 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800209
210 if (found > 1) {
Dan Murphy032a6422010-11-15 09:50:50 -0600211 pr_err("%s: Multiple signal paths (%i) for %s\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200212 found, muxname);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800213 return -EINVAL;
214 }
215
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800216 pr_err("%s: Could not find signal %s\n", __func__, muxname);
217
218 return -ENODEV;
219}
220
Govindraj.R91930652012-06-05 04:04:11 -0700221int __init omap_mux_get_by_name(const char *muxname,
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800222 struct omap_mux_partition **found_partition,
223 struct omap_mux **found_mux)
224{
225 struct omap_mux_partition *partition;
226
227 list_for_each_entry(partition, &mux_partitions, node) {
228 struct omap_mux *mux = NULL;
229 int mux_mode = _omap_mux_get_by_name(partition, muxname, &mux);
230 if (mux_mode < 0)
231 continue;
232
233 *found_partition = partition;
234 *found_mux = mux;
235
236 return mux_mode;
237 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800238
239 return -ENODEV;
240}
241
Tony Lindgrend1589f02012-02-20 09:43:30 -0800242int __init omap_mux_init_signal(const char *muxname, int val)
Benoit Cousson112485e2010-08-16 10:55:35 +0200243{
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800244 struct omap_mux_partition *partition = NULL;
245 struct omap_mux *mux = NULL;
246 u16 old_mode;
247 int mux_mode;
Benoit Cousson112485e2010-08-16 10:55:35 +0200248
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800249 mux_mode = omap_mux_get_by_name(muxname, &partition, &mux);
Paul Walmsleyeeb37112012-04-13 06:34:32 -0600250 if (mux_mode < 0 || !mux)
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800251 return mux_mode;
Benoit Cousson112485e2010-08-16 10:55:35 +0200252
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800253 old_mode = omap_mux_read(partition, mux->reg_offset);
254 mux_mode |= val;
255 pr_debug("%s: Setting signal %s 0x%04x -> 0x%04x\n",
256 __func__, muxname, old_mode, mux_mode);
257 omap_mux_write(partition, mux_mode, mux->reg_offset);
Benoit Cousson112485e2010-08-16 10:55:35 +0200258
Tony Lindgren8419fdb2010-12-22 18:42:35 -0800259 return 0;
Benoit Cousson112485e2010-08-16 10:55:35 +0200260}
261
Tony Lindgren9796b322010-12-22 18:42:35 -0800262struct omap_hwmod_mux_info * __init
263omap_hwmod_mux_init(struct omap_device_pad *bpads, int nr_pads)
264{
265 struct omap_hwmod_mux_info *hmux;
Tony Lindgren029268e2011-03-11 11:32:25 -0800266 int i, nr_pads_dynamic = 0;
Tony Lindgren9796b322010-12-22 18:42:35 -0800267
268 if (!bpads || nr_pads < 1)
269 return NULL;
270
271 hmux = kzalloc(sizeof(struct omap_hwmod_mux_info), GFP_KERNEL);
272 if (!hmux)
273 goto err1;
274
275 hmux->nr_pads = nr_pads;
276
277 hmux->pads = kzalloc(sizeof(struct omap_device_pad) *
278 nr_pads, GFP_KERNEL);
279 if (!hmux->pads)
280 goto err2;
281
282 for (i = 0; i < hmux->nr_pads; i++) {
283 struct omap_mux_partition *partition;
284 struct omap_device_pad *bpad = &bpads[i], *pad = &hmux->pads[i];
285 struct omap_mux *mux;
286 int mux_mode;
287
288 mux_mode = omap_mux_get_by_name(bpad->name, &partition, &mux);
289 if (mux_mode < 0)
290 goto err3;
291 if (!pad->partition)
292 pad->partition = partition;
293 if (!pad->mux)
294 pad->mux = mux;
295
296 pad->name = kzalloc(strlen(bpad->name) + 1, GFP_KERNEL);
297 if (!pad->name) {
298 int j;
299
300 for (j = i - 1; j >= 0; j--)
301 kfree(hmux->pads[j].name);
302 goto err3;
303 }
304 strcpy(pad->name, bpad->name);
305
306 pad->flags = bpad->flags;
307 pad->enable = bpad->enable;
308 pad->idle = bpad->idle;
309 pad->off = bpad->off;
Tony Lindgren029268e2011-03-11 11:32:25 -0800310
Paul Walmsley96dc19f2011-12-16 14:36:57 -0700311 if (pad->flags &
312 (OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP))
Tony Lindgren029268e2011-03-11 11:32:25 -0800313 nr_pads_dynamic++;
314
Tony Lindgren9796b322010-12-22 18:42:35 -0800315 pr_debug("%s: Initialized %s\n", __func__, pad->name);
316 }
317
Tony Lindgren029268e2011-03-11 11:32:25 -0800318 if (!nr_pads_dynamic)
319 return hmux;
320
321 /*
322 * Add pads that need dynamic muxing into a separate list
323 */
324
325 hmux->nr_pads_dynamic = nr_pads_dynamic;
326 hmux->pads_dynamic = kzalloc(sizeof(struct omap_device_pad *) *
327 nr_pads_dynamic, GFP_KERNEL);
328 if (!hmux->pads_dynamic) {
329 pr_err("%s: Could not allocate dynamic pads\n", __func__);
330 return hmux;
331 }
332
333 nr_pads_dynamic = 0;
334 for (i = 0; i < hmux->nr_pads; i++) {
335 struct omap_device_pad *pad = &hmux->pads[i];
336
Paul Walmsley96dc19f2011-12-16 14:36:57 -0700337 if (pad->flags &
338 (OMAP_DEVICE_PAD_REMUX | OMAP_DEVICE_PAD_WAKEUP)) {
Tony Lindgren029268e2011-03-11 11:32:25 -0800339 pr_debug("%s: pad %s tagged dynamic\n",
340 __func__, pad->name);
341 hmux->pads_dynamic[nr_pads_dynamic] = pad;
342 nr_pads_dynamic++;
343 }
344 }
345
Tony Lindgren9796b322010-12-22 18:42:35 -0800346 return hmux;
347
348err3:
349 kfree(hmux->pads);
350err2:
351 kfree(hmux);
352err1:
353 pr_err("%s: Could not allocate device mux entry\n", __func__);
354
355 return NULL;
356}
357
Tero Kristo13a3fe52011-12-16 14:36:59 -0700358/**
359 * omap_hwmod_mux_scan_wakeups - omap hwmod scan wakeup pads
360 * @hmux: Pads for a hwmod
361 * @mpu_irqs: MPU irq array for a hwmod
362 *
363 * Scans the wakeup status of pads for a single hwmod. If an irq
364 * array is defined for this mux, the parser will call the registered
365 * ISRs for corresponding pads, otherwise the parser will stop at the
366 * first wakeup active pad and return. Returns true if there is a
367 * pending and non-served wakeup event for the mux, otherwise false.
368 */
369static bool omap_hwmod_mux_scan_wakeups(struct omap_hwmod_mux_info *hmux,
370 struct omap_hwmod_irq_info *mpu_irqs)
371{
372 int i, irq;
373 unsigned int val;
374 u32 handled_irqs = 0;
375
376 for (i = 0; i < hmux->nr_pads_dynamic; i++) {
377 struct omap_device_pad *pad = hmux->pads_dynamic[i];
378
379 if (!(pad->flags & OMAP_DEVICE_PAD_WAKEUP) ||
380 !(pad->idle & OMAP_WAKEUP_EN))
381 continue;
382
383 val = omap_mux_read(pad->partition, pad->mux->reg_offset);
384 if (!(val & OMAP_WAKEUP_EVENT))
385 continue;
386
387 if (!hmux->irqs)
388 return true;
389
390 irq = hmux->irqs[i];
391 /* make sure we only handle each irq once */
392 if (handled_irqs & 1 << irq)
393 continue;
394
395 handled_irqs |= 1 << irq;
396
397 generic_handle_irq(mpu_irqs[irq].irq);
398 }
399
400 return false;
401}
402
403/**
404 * _omap_hwmod_mux_handle_irq - Process wakeup events for a single hwmod
405 *
406 * Checks a single hwmod for every wakeup capable pad to see if there is an
407 * active wakeup event. If this is the case, call the corresponding ISR.
408 */
409static int _omap_hwmod_mux_handle_irq(struct omap_hwmod *oh, void *data)
410{
411 if (!oh->mux || !oh->mux->enabled)
412 return 0;
413 if (omap_hwmod_mux_scan_wakeups(oh->mux, oh->mpu_irqs))
414 generic_handle_irq(oh->mpu_irqs[0].irq);
415 return 0;
416}
417
418/**
419 * omap_hwmod_mux_handle_irq - Process pad wakeup irqs.
420 *
421 * Calls a function for each registered omap_hwmod to check
422 * pad wakeup statuses.
423 */
424static irqreturn_t omap_hwmod_mux_handle_irq(int irq, void *unused)
425{
426 omap_hwmod_for_each(_omap_hwmod_mux_handle_irq, NULL);
427 return IRQ_HANDLED;
428}
429
Tony Lindgren8d9af882010-12-22 18:42:35 -0800430/* Assumes the calling function takes care of locking */
431void omap_hwmod_mux(struct omap_hwmod_mux_info *hmux, u8 state)
432{
433 int i;
434
Tony Lindgren029268e2011-03-11 11:32:25 -0800435 /* Runtime idling of dynamic pads */
436 if (state == _HWMOD_STATE_IDLE && hmux->enabled) {
437 for (i = 0; i < hmux->nr_pads_dynamic; i++) {
438 struct omap_device_pad *pad = hmux->pads_dynamic[i];
439 int val = -EINVAL;
440
Tony Lindgren029268e2011-03-11 11:32:25 -0800441 val = pad->idle;
442 omap_mux_write(pad->partition, val,
443 pad->mux->reg_offset);
444 }
445
446 return;
447 }
448
449 /* Runtime enabling of dynamic pads */
R Sricharan86c79bf2011-03-11 11:32:25 -0800450 if ((state == _HWMOD_STATE_ENABLED) && hmux->pads_dynamic
451 && hmux->enabled) {
Tony Lindgren029268e2011-03-11 11:32:25 -0800452 for (i = 0; i < hmux->nr_pads_dynamic; i++) {
453 struct omap_device_pad *pad = hmux->pads_dynamic[i];
454 int val = -EINVAL;
455
Tony Lindgren029268e2011-03-11 11:32:25 -0800456 val = pad->enable;
457 omap_mux_write(pad->partition, val,
458 pad->mux->reg_offset);
Tony Lindgren029268e2011-03-11 11:32:25 -0800459 }
460
R Sricharan86c79bf2011-03-11 11:32:25 -0800461 return;
Tony Lindgren029268e2011-03-11 11:32:25 -0800462 }
463
464 /* Enabling or disabling of all pads */
Tony Lindgren8d9af882010-12-22 18:42:35 -0800465 for (i = 0; i < hmux->nr_pads; i++) {
466 struct omap_device_pad *pad = &hmux->pads[i];
467 int flags, val = -EINVAL;
468
469 flags = pad->flags;
470
471 switch (state) {
472 case _HWMOD_STATE_ENABLED:
Tony Lindgren8d9af882010-12-22 18:42:35 -0800473 val = pad->enable;
474 pr_debug("%s: Enabling %s %x\n", __func__,
475 pad->name, val);
476 break;
Tony Lindgren8d9af882010-12-22 18:42:35 -0800477 case _HWMOD_STATE_DISABLED:
Tony Lindgren8d9af882010-12-22 18:42:35 -0800478 /* Use safe mode unless OMAP_DEVICE_PAD_REMUX */
479 if (flags & OMAP_DEVICE_PAD_REMUX)
480 val = pad->off;
481 else
482 val = OMAP_MUX_MODE7;
Tony Lindgren8d9af882010-12-22 18:42:35 -0800483 pr_debug("%s: Disabling %s %x\n", __func__,
484 pad->name, val);
R Sricharan86c79bf2011-03-11 11:32:25 -0800485 break;
486 default:
487 /* Nothing to be done */
488 break;
Tony Lindgren8d9af882010-12-22 18:42:35 -0800489 };
490
491 if (val >= 0) {
492 omap_mux_write(pad->partition, val,
493 pad->mux->reg_offset);
494 pad->flags = flags;
495 }
496 }
Tony Lindgren029268e2011-03-11 11:32:25 -0800497
498 if (state == _HWMOD_STATE_ENABLED)
499 hmux->enabled = true;
500 else
501 hmux->enabled = false;
Tony Lindgren8d9af882010-12-22 18:42:35 -0800502}
503
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800504#ifdef CONFIG_DEBUG_FS
505
506#define OMAP_MUX_MAX_NR_FLAGS 10
507#define OMAP_MUX_TEST_FLAG(val, mask) \
508 if (((val) & (mask)) == (mask)) { \
509 i++; \
510 flags[i] = #mask; \
511 }
512
513/* REVISIT: Add checking for non-optimal mux settings */
514static inline void omap_mux_decode(struct seq_file *s, u16 val)
515{
516 char *flags[OMAP_MUX_MAX_NR_FLAGS];
Tony Lindgren78737ae2010-02-01 13:03:42 -0800517 char mode[sizeof("OMAP_MUX_MODE") + 1];
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800518 int i = -1;
519
520 sprintf(mode, "OMAP_MUX_MODE%d", val & 0x7);
521 i++;
522 flags[i] = mode;
523
524 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_OFF_WAKEUPENABLE);
525 if (val & OMAP_OFF_EN) {
526 if (!(val & OMAP_OFFOUT_EN)) {
527 if (!(val & OMAP_OFF_PULL_UP)) {
528 OMAP_MUX_TEST_FLAG(val,
529 OMAP_PIN_OFF_INPUT_PULLDOWN);
530 } else {
531 OMAP_MUX_TEST_FLAG(val,
532 OMAP_PIN_OFF_INPUT_PULLUP);
533 }
534 } else {
535 if (!(val & OMAP_OFFOUT_VAL)) {
536 OMAP_MUX_TEST_FLAG(val,
537 OMAP_PIN_OFF_OUTPUT_LOW);
538 } else {
539 OMAP_MUX_TEST_FLAG(val,
540 OMAP_PIN_OFF_OUTPUT_HIGH);
541 }
542 }
543 }
544
545 if (val & OMAP_INPUT_EN) {
546 if (val & OMAP_PULL_ENA) {
547 if (!(val & OMAP_PULL_UP)) {
548 OMAP_MUX_TEST_FLAG(val,
549 OMAP_PIN_INPUT_PULLDOWN);
550 } else {
551 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT_PULLUP);
552 }
553 } else {
554 OMAP_MUX_TEST_FLAG(val, OMAP_PIN_INPUT);
555 }
556 } else {
557 i++;
558 flags[i] = "OMAP_PIN_OUTPUT";
559 }
560
561 do {
562 seq_printf(s, "%s", flags[i]);
563 if (i > 0)
564 seq_printf(s, " | ");
565 } while (i-- > 0);
566}
567
Benoit Cousson112485e2010-08-16 10:55:35 +0200568#define OMAP_MUX_DEFNAME_LEN 32
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800569
570static int omap_mux_dbg_board_show(struct seq_file *s, void *unused)
571{
Benoit Cousson112485e2010-08-16 10:55:35 +0200572 struct omap_mux_partition *partition = s->private;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800573 struct omap_mux_entry *e;
Benoit Cousson112485e2010-08-16 10:55:35 +0200574 u8 omap_gen = omap_rev() >> 28;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800575
Benoit Cousson112485e2010-08-16 10:55:35 +0200576 list_for_each_entry(e, &partition->muxmodes, node) {
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800577 struct omap_mux *m = &e->mux;
578 char m0_def[OMAP_MUX_DEFNAME_LEN];
579 char *m0_name = m->muxnames[0];
580 u16 val;
581 int i, mode;
582
583 if (!m0_name)
584 continue;
585
Tony Lindgren78737ae2010-02-01 13:03:42 -0800586 /* REVISIT: Needs to be updated if mode0 names get longer */
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800587 for (i = 0; i < OMAP_MUX_DEFNAME_LEN; i++) {
588 if (m0_name[i] == '\0') {
589 m0_def[i] = m0_name[i];
590 break;
591 }
592 m0_def[i] = toupper(m0_name[i]);
593 }
Benoit Cousson112485e2010-08-16 10:55:35 +0200594 val = omap_mux_read(partition, m->reg_offset);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800595 mode = val & OMAP_MUX_MODE7;
Benoit Cousson112485e2010-08-16 10:55:35 +0200596 if (mode != 0)
597 seq_printf(s, "/* %s */\n", m->muxnames[mode]);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800598
Benoit Cousson112485e2010-08-16 10:55:35 +0200599 /*
Lucas De Marchi25985ed2011-03-30 22:57:33 -0300600 * XXX: Might be revisited to support differences across
Benoit Cousson112485e2010-08-16 10:55:35 +0200601 * same OMAP generation.
602 */
603 seq_printf(s, "OMAP%d_MUX(%s, ", omap_gen, m0_def);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800604 omap_mux_decode(s, val);
605 seq_printf(s, "),\n");
606 }
607
608 return 0;
609}
610
611static int omap_mux_dbg_board_open(struct inode *inode, struct file *file)
612{
Benoit Cousson112485e2010-08-16 10:55:35 +0200613 return single_open(file, omap_mux_dbg_board_show, inode->i_private);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800614}
615
616static const struct file_operations omap_mux_dbg_board_fops = {
617 .open = omap_mux_dbg_board_open,
618 .read = seq_read,
619 .llseek = seq_lseek,
620 .release = single_release,
621};
622
Benoit Cousson112485e2010-08-16 10:55:35 +0200623static struct omap_mux_partition *omap_mux_get_partition(struct omap_mux *mux)
624{
625 struct omap_mux_partition *partition;
626
627 list_for_each_entry(partition, &mux_partitions, node) {
628 struct list_head *muxmodes = &partition->muxmodes;
629 struct omap_mux_entry *e;
630
631 list_for_each_entry(e, muxmodes, node) {
632 struct omap_mux *m = &e->mux;
633
634 if (m == mux)
635 return partition;
636 }
637 }
638
639 return NULL;
640}
641
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800642static int omap_mux_dbg_signal_show(struct seq_file *s, void *unused)
643{
644 struct omap_mux *m = s->private;
Benoit Cousson112485e2010-08-16 10:55:35 +0200645 struct omap_mux_partition *partition;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800646 const char *none = "NA";
647 u16 val;
648 int mode;
649
Benoit Cousson112485e2010-08-16 10:55:35 +0200650 partition = omap_mux_get_partition(m);
651 if (!partition)
652 return 0;
653
654 val = omap_mux_read(partition, m->reg_offset);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800655 mode = val & OMAP_MUX_MODE7;
656
Benoit Cousson112485e2010-08-16 10:55:35 +0200657 seq_printf(s, "name: %s.%s (0x%08x/0x%03x = 0x%04x), b %s, t %s\n",
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800658 m->muxnames[0], m->muxnames[mode],
Benoit Cousson112485e2010-08-16 10:55:35 +0200659 partition->phys + m->reg_offset, m->reg_offset, val,
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800660 m->balls[0] ? m->balls[0] : none,
661 m->balls[1] ? m->balls[1] : none);
662 seq_printf(s, "mode: ");
663 omap_mux_decode(s, val);
664 seq_printf(s, "\n");
665 seq_printf(s, "signals: %s | %s | %s | %s | %s | %s | %s | %s\n",
666 m->muxnames[0] ? m->muxnames[0] : none,
667 m->muxnames[1] ? m->muxnames[1] : none,
668 m->muxnames[2] ? m->muxnames[2] : none,
669 m->muxnames[3] ? m->muxnames[3] : none,
670 m->muxnames[4] ? m->muxnames[4] : none,
671 m->muxnames[5] ? m->muxnames[5] : none,
672 m->muxnames[6] ? m->muxnames[6] : none,
673 m->muxnames[7] ? m->muxnames[7] : none);
674
675 return 0;
676}
677
678#define OMAP_MUX_MAX_ARG_CHAR 7
679
680static ssize_t omap_mux_dbg_signal_write(struct file *file,
Benoit Cousson112485e2010-08-16 10:55:35 +0200681 const char __user *user_buf,
682 size_t count, loff_t *ppos)
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800683{
684 char buf[OMAP_MUX_MAX_ARG_CHAR];
685 struct seq_file *seqf;
686 struct omap_mux *m;
687 unsigned long val;
688 int buf_size, ret;
Benoit Cousson112485e2010-08-16 10:55:35 +0200689 struct omap_mux_partition *partition;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800690
691 if (count > OMAP_MUX_MAX_ARG_CHAR)
692 return -EINVAL;
693
694 memset(buf, 0, sizeof(buf));
695 buf_size = min(count, sizeof(buf) - 1);
696
697 if (copy_from_user(buf, user_buf, buf_size))
698 return -EFAULT;
699
700 ret = strict_strtoul(buf, 0x10, &val);
701 if (ret < 0)
702 return ret;
703
704 if (val > 0xffff)
705 return -EINVAL;
706
707 seqf = file->private_data;
708 m = seqf->private;
709
Benoit Cousson112485e2010-08-16 10:55:35 +0200710 partition = omap_mux_get_partition(m);
711 if (!partition)
712 return -ENODEV;
713
714 omap_mux_write(partition, (u16)val, m->reg_offset);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800715 *ppos += count;
716
717 return count;
718}
719
720static int omap_mux_dbg_signal_open(struct inode *inode, struct file *file)
721{
722 return single_open(file, omap_mux_dbg_signal_show, inode->i_private);
723}
724
725static const struct file_operations omap_mux_dbg_signal_fops = {
726 .open = omap_mux_dbg_signal_open,
727 .read = seq_read,
728 .write = omap_mux_dbg_signal_write,
729 .llseek = seq_lseek,
730 .release = single_release,
731};
732
733static struct dentry *mux_dbg_dir;
734
Benoit Cousson112485e2010-08-16 10:55:35 +0200735static void __init omap_mux_dbg_create_entry(
736 struct omap_mux_partition *partition,
737 struct dentry *mux_dbg_dir)
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800738{
739 struct omap_mux_entry *e;
740
Benoit Cousson112485e2010-08-16 10:55:35 +0200741 list_for_each_entry(e, &partition->muxmodes, node) {
742 struct omap_mux *m = &e->mux;
743
Vasiliy Kulikov9b127712011-02-04 12:23:13 +0000744 (void)debugfs_create_file(m->muxnames[0], S_IWUSR, mux_dbg_dir,
Benoit Cousson112485e2010-08-16 10:55:35 +0200745 m, &omap_mux_dbg_signal_fops);
746 }
747}
748
749static void __init omap_mux_dbg_init(void)
750{
751 struct omap_mux_partition *partition;
752 static struct dentry *mux_dbg_board_dir;
753
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800754 mux_dbg_dir = debugfs_create_dir("omap_mux", NULL);
755 if (!mux_dbg_dir)
756 return;
757
Benoit Cousson112485e2010-08-16 10:55:35 +0200758 mux_dbg_board_dir = debugfs_create_dir("board", mux_dbg_dir);
759 if (!mux_dbg_board_dir)
760 return;
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800761
Benoit Cousson112485e2010-08-16 10:55:35 +0200762 list_for_each_entry(partition, &mux_partitions, node) {
763 omap_mux_dbg_create_entry(partition, mux_dbg_dir);
764 (void)debugfs_create_file(partition->name, S_IRUGO,
765 mux_dbg_board_dir, partition,
766 &omap_mux_dbg_board_fops);
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800767 }
768}
769
770#else
771static inline void omap_mux_dbg_init(void)
772{
773}
774#endif /* CONFIG_DEBUG_FS */
775
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800776static void __init omap_mux_free_names(struct omap_mux *m)
777{
778 int i;
779
780 for (i = 0; i < OMAP_MUX_NR_MODES; i++)
781 kfree(m->muxnames[i]);
782
783#ifdef CONFIG_DEBUG_FS
784 for (i = 0; i < OMAP_MUX_NR_SIDES; i++)
785 kfree(m->balls[i]);
Tony Lindgren1dbae812005-11-10 14:26:51 +0000786#endif
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800787
788}
789
790/* Free all data except for GPIO pins unless CONFIG_DEBUG_FS is set */
Shawn Guobbd707a2012-04-26 16:06:50 +0800791int __init omap_mux_late_init(void)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800792{
Benoit Cousson112485e2010-08-16 10:55:35 +0200793 struct omap_mux_partition *partition;
Tero Kristo13a3fe52011-12-16 14:36:59 -0700794 int ret;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800795
Benoit Cousson112485e2010-08-16 10:55:35 +0200796 list_for_each_entry(partition, &mux_partitions, node) {
797 struct omap_mux_entry *e, *tmp;
798 list_for_each_entry_safe(e, tmp, &partition->muxmodes, node) {
799 struct omap_mux *m = &e->mux;
800 u16 mode = omap_mux_read(partition, m->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800801
Benoit Cousson112485e2010-08-16 10:55:35 +0200802 if (OMAP_MODE_GPIO(mode))
803 continue;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800804
805#ifndef CONFIG_DEBUG_FS
Benoit Cousson112485e2010-08-16 10:55:35 +0200806 mutex_lock(&muxmode_mutex);
807 list_del(&e->node);
808 mutex_unlock(&muxmode_mutex);
809 omap_mux_free_names(m);
810 kfree(m);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800811#endif
Benoit Cousson112485e2010-08-16 10:55:35 +0200812 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800813 }
814
Tero Kristo13a3fe52011-12-16 14:36:59 -0700815 ret = request_irq(omap_prcm_event_to_irq("io"),
816 omap_hwmod_mux_handle_irq, IRQF_SHARED | IRQF_NO_SUSPEND,
817 "hwmod_io", omap_mux_late_init);
818
819 if (ret)
820 pr_warning("mux: Failed to setup hwmod io irq %d\n", ret);
821
Tony Lindgren4b715ef2009-12-11 16:16:32 -0800822 omap_mux_dbg_init();
823
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800824 return 0;
825}
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800826
827static void __init omap_mux_package_fixup(struct omap_mux *p,
828 struct omap_mux *superset)
829{
830 while (p->reg_offset != OMAP_MUX_TERMINATOR) {
831 struct omap_mux *s = superset;
832 int found = 0;
833
834 while (s->reg_offset != OMAP_MUX_TERMINATOR) {
835 if (s->reg_offset == p->reg_offset) {
836 *s = *p;
837 found++;
838 break;
839 }
840 s++;
841 }
842 if (!found)
Dan Murphy032a6422010-11-15 09:50:50 -0600843 pr_err("%s: Unknown entry offset 0x%x\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200844 p->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800845 p++;
846 }
847}
848
849#ifdef CONFIG_DEBUG_FS
850
851static void __init omap_mux_package_init_balls(struct omap_ball *b,
852 struct omap_mux *superset)
853{
854 while (b->reg_offset != OMAP_MUX_TERMINATOR) {
855 struct omap_mux *s = superset;
856 int found = 0;
857
858 while (s->reg_offset != OMAP_MUX_TERMINATOR) {
859 if (s->reg_offset == b->reg_offset) {
860 s->balls[0] = b->balls[0];
861 s->balls[1] = b->balls[1];
862 found++;
863 break;
864 }
865 s++;
866 }
867 if (!found)
Dan Murphy032a6422010-11-15 09:50:50 -0600868 pr_err("%s: Unknown ball offset 0x%x\n", __func__,
Benoit Cousson1cbb3a92010-08-10 17:33:01 +0200869 b->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800870 b++;
871 }
872}
873
874#else /* CONFIG_DEBUG_FS */
875
876static inline void omap_mux_package_init_balls(struct omap_ball *b,
877 struct omap_mux *superset)
878{
879}
880
881#endif /* CONFIG_DEBUG_FS */
882
883static int __init omap_mux_setup(char *options)
884{
885 if (!options)
886 return 0;
887
888 omap_mux_options = options;
889
890 return 1;
891}
892__setup("omap_mux=", omap_mux_setup);
893
894/*
895 * Note that the omap_mux=some.signal1=0x1234,some.signal2=0x1234
896 * cmdline options only override the bootloader values.
897 * During development, please enable CONFIG_DEBUG_FS, and use the
898 * signal specific entries under debugfs.
899 */
900static void __init omap_mux_set_cmdline_signals(void)
901{
902 char *options, *next_opt, *token;
903
904 if (!omap_mux_options)
905 return;
906
Thomas Meyerdccb3b02011-08-06 09:29:10 +0000907 options = kstrdup(omap_mux_options, GFP_KERNEL);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800908 if (!options)
909 return;
910
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800911 next_opt = options;
912
913 while ((token = strsep(&next_opt, ",")) != NULL) {
914 char *keyval, *name;
915 unsigned long val;
916
917 keyval = token;
918 name = strsep(&keyval, "=");
919 if (name) {
920 int res;
921
922 res = strict_strtoul(keyval, 0x10, &val);
923 if (res < 0)
924 continue;
925
926 omap_mux_init_signal(name, (u16)val);
927 }
928 }
929
930 kfree(options);
931}
932
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800933static int __init omap_mux_copy_names(struct omap_mux *src,
Benoit Cousson112485e2010-08-16 10:55:35 +0200934 struct omap_mux *dst)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800935{
936 int i;
937
938 for (i = 0; i < OMAP_MUX_NR_MODES; i++) {
939 if (src->muxnames[i]) {
Thomas Meyerdccb3b02011-08-06 09:29:10 +0000940 dst->muxnames[i] = kstrdup(src->muxnames[i],
941 GFP_KERNEL);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800942 if (!dst->muxnames[i])
943 goto free;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800944 }
945 }
946
947#ifdef CONFIG_DEBUG_FS
948 for (i = 0; i < OMAP_MUX_NR_SIDES; i++) {
949 if (src->balls[i]) {
Thomas Meyerdccb3b02011-08-06 09:29:10 +0000950 dst->balls[i] = kstrdup(src->balls[i], GFP_KERNEL);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800951 if (!dst->balls[i])
952 goto free;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800953 }
954 }
955#endif
956
957 return 0;
958
959free:
960 omap_mux_free_names(dst);
961 return -ENOMEM;
962
963}
964
965#endif /* CONFIG_OMAP_MUX */
966
Benoit Cousson112485e2010-08-16 10:55:35 +0200967static struct omap_mux *omap_mux_get_by_gpio(
968 struct omap_mux_partition *partition,
969 int gpio)
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800970{
971 struct omap_mux_entry *e;
Benoit Cousson112485e2010-08-16 10:55:35 +0200972 struct omap_mux *ret = NULL;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800973
Benoit Cousson112485e2010-08-16 10:55:35 +0200974 list_for_each_entry(e, &partition->muxmodes, node) {
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800975 struct omap_mux *m = &e->mux;
976 if (m->gpio == gpio) {
Benoit Cousson112485e2010-08-16 10:55:35 +0200977 ret = m;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800978 break;
979 }
980 }
981
Benoit Cousson112485e2010-08-16 10:55:35 +0200982 return ret;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800983}
984
985/* Needed for dynamic muxing of GPIO pins for off-idle */
986u16 omap_mux_get_gpio(int gpio)
987{
Benoit Cousson112485e2010-08-16 10:55:35 +0200988 struct omap_mux_partition *partition;
Govindraj.R30ebad92011-06-01 11:28:56 +0530989 struct omap_mux *m = NULL;
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800990
Benoit Cousson112485e2010-08-16 10:55:35 +0200991 list_for_each_entry(partition, &mux_partitions, node) {
992 m = omap_mux_get_by_gpio(partition, gpio);
993 if (m)
994 return omap_mux_read(partition, m->reg_offset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -0800995 }
996
Benoit Cousson112485e2010-08-16 10:55:35 +0200997 if (!m || m->reg_offset == OMAP_MUX_TERMINATOR)
Dan Murphy032a6422010-11-15 09:50:50 -0600998 pr_err("%s: Could not get gpio%i\n", __func__, gpio);
Benoit Cousson112485e2010-08-16 10:55:35 +0200999
1000 return OMAP_MUX_TERMINATOR;
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001001}
1002
1003/* Needed for dynamic muxing of GPIO pins for off-idle */
1004void omap_mux_set_gpio(u16 val, int gpio)
1005{
Benoit Cousson112485e2010-08-16 10:55:35 +02001006 struct omap_mux_partition *partition;
1007 struct omap_mux *m = NULL;
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001008
Benoit Cousson112485e2010-08-16 10:55:35 +02001009 list_for_each_entry(partition, &mux_partitions, node) {
1010 m = omap_mux_get_by_gpio(partition, gpio);
1011 if (m) {
1012 omap_mux_write(partition, val, m->reg_offset);
1013 return;
1014 }
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001015 }
1016
Benoit Cousson112485e2010-08-16 10:55:35 +02001017 if (!m || m->reg_offset == OMAP_MUX_TERMINATOR)
Dan Murphy032a6422010-11-15 09:50:50 -06001018 pr_err("%s: Could not set gpio%i\n", __func__, gpio);
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001019}
1020
Benoit Cousson112485e2010-08-16 10:55:35 +02001021static struct omap_mux * __init omap_mux_list_add(
1022 struct omap_mux_partition *partition,
1023 struct omap_mux *src)
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001024{
1025 struct omap_mux_entry *entry;
1026 struct omap_mux *m;
1027
1028 entry = kzalloc(sizeof(struct omap_mux_entry), GFP_KERNEL);
1029 if (!entry)
1030 return NULL;
1031
1032 m = &entry->mux;
Aaro Koskinen30833142011-01-06 19:49:28 -08001033 entry->mux = *src;
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001034
1035#ifdef CONFIG_OMAP_MUX
1036 if (omap_mux_copy_names(src, m)) {
1037 kfree(entry);
1038 return NULL;
1039 }
1040#endif
1041
1042 mutex_lock(&muxmode_mutex);
Benoit Cousson112485e2010-08-16 10:55:35 +02001043 list_add_tail(&entry->node, &partition->muxmodes);
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001044 mutex_unlock(&muxmode_mutex);
1045
1046 return m;
1047}
1048
1049/*
1050 * Note if CONFIG_OMAP_MUX is not selected, we will only initialize
1051 * the GPIO to mux offset mapping that is needed for dynamic muxing
1052 * of GPIO pins for off-idle.
1053 */
Benoit Cousson112485e2010-08-16 10:55:35 +02001054static void __init omap_mux_init_list(struct omap_mux_partition *partition,
1055 struct omap_mux *superset)
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001056{
1057 while (superset->reg_offset != OMAP_MUX_TERMINATOR) {
1058 struct omap_mux *entry;
1059
Ranjith Lohithakshanb72c7d52010-02-17 17:17:01 +00001060#ifdef CONFIG_OMAP_MUX
1061 if (!superset->muxnames || !superset->muxnames[0]) {
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001062 superset++;
1063 continue;
1064 }
Ranjith Lohithakshanb72c7d52010-02-17 17:17:01 +00001065#else
1066 /* Skip pins that are not muxed as GPIO by bootloader */
Benoit Cousson112485e2010-08-16 10:55:35 +02001067 if (!OMAP_MODE_GPIO(omap_mux_read(partition,
1068 superset->reg_offset))) {
Tony Lindgren9ecef432010-02-01 11:22:54 -08001069 superset++;
1070 continue;
1071 }
1072#endif
1073
Benoit Cousson112485e2010-08-16 10:55:35 +02001074 entry = omap_mux_list_add(partition, superset);
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001075 if (!entry) {
Dan Murphy032a6422010-11-15 09:50:50 -06001076 pr_err("%s: Could not add entry\n", __func__);
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001077 return;
1078 }
1079 superset++;
1080 }
1081}
1082
Tony Lindgren321cfc82010-02-15 10:03:35 -08001083#ifdef CONFIG_OMAP_MUX
1084
1085static void omap_mux_init_package(struct omap_mux *superset,
1086 struct omap_mux *package_subset,
1087 struct omap_ball *package_balls)
1088{
1089 if (package_subset)
1090 omap_mux_package_fixup(package_subset, superset);
1091 if (package_balls)
1092 omap_mux_package_init_balls(package_balls, superset);
1093}
1094
Russell King27d8d3b2012-02-07 10:18:34 +00001095static void __init omap_mux_init_signals(struct omap_mux_partition *partition,
1096 struct omap_board_mux *board_mux)
Tony Lindgren321cfc82010-02-15 10:03:35 -08001097{
1098 omap_mux_set_cmdline_signals();
Benoit Cousson112485e2010-08-16 10:55:35 +02001099 omap_mux_write_array(partition, board_mux);
Tony Lindgren321cfc82010-02-15 10:03:35 -08001100}
1101
1102#else
1103
1104static void omap_mux_init_package(struct omap_mux *superset,
1105 struct omap_mux *package_subset,
1106 struct omap_ball *package_balls)
1107{
1108}
1109
Russell King27d8d3b2012-02-07 10:18:34 +00001110static void __init omap_mux_init_signals(struct omap_mux_partition *partition,
1111 struct omap_board_mux *board_mux)
Tony Lindgren321cfc82010-02-15 10:03:35 -08001112{
1113}
1114
1115#endif
1116
Benoit Cousson112485e2010-08-16 10:55:35 +02001117static u32 mux_partitions_cnt;
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001118
Benoit Cousson112485e2010-08-16 10:55:35 +02001119int __init omap_mux_init(const char *name, u32 flags,
1120 u32 mux_pbase, u32 mux_size,
1121 struct omap_mux *superset,
1122 struct omap_mux *package_subset,
1123 struct omap_board_mux *board_mux,
1124 struct omap_ball *package_balls)
1125{
1126 struct omap_mux_partition *partition;
1127
1128 partition = kzalloc(sizeof(struct omap_mux_partition), GFP_KERNEL);
1129 if (!partition)
1130 return -ENOMEM;
1131
1132 partition->name = name;
1133 partition->flags = flags;
1134 partition->size = mux_size;
1135 partition->phys = mux_pbase;
1136 partition->base = ioremap(mux_pbase, mux_size);
1137 if (!partition->base) {
Dan Murphy032a6422010-11-15 09:50:50 -06001138 pr_err("%s: Could not ioremap mux partition at 0x%08x\n",
1139 __func__, partition->phys);
Aaro Koskinen9d47e302011-01-28 14:50:55 +00001140 kfree(partition);
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001141 return -ENODEV;
1142 }
1143
Benoit Cousson112485e2010-08-16 10:55:35 +02001144 INIT_LIST_HEAD(&partition->muxmodes);
1145
1146 list_add_tail(&partition->node, &mux_partitions);
1147 mux_partitions_cnt++;
Dan Murphy032a6422010-11-15 09:50:50 -06001148 pr_info("%s: Add partition: #%d: %s, flags: %x\n", __func__,
Benoit Cousson112485e2010-08-16 10:55:35 +02001149 mux_partitions_cnt, partition->name, partition->flags);
Tony Lindgrend5425be2010-07-05 16:31:35 +03001150
Tony Lindgren321cfc82010-02-15 10:03:35 -08001151 omap_mux_init_package(superset, package_subset, package_balls);
Benoit Cousson112485e2010-08-16 10:55:35 +02001152 omap_mux_init_list(partition, superset);
1153 omap_mux_init_signals(partition, board_mux);
Tony Lindgren2cb0c542010-01-19 18:17:07 -08001154
Tony Lindgren15ac7af2009-12-11 16:16:32 -08001155 return 0;
1156}
1157