blob: cff8712122bb95f71c355bf6829aa0030e8ed552 [file] [log] [blame]
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01001/*
2 * linux/arch/arm/plat-omap/mux.c
3 *
4 * Utility to set the Omap MUX and PULL_DWN registers from a table in mux.h
5 *
Tony Lindgren93308992008-01-24 17:24:15 -08006 * Copyright (C) 2003 - 2008 Nokia Corporation
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01007 *
Tony Lindgren93308992008-01-24 17:24:15 -08008 * Written by Tony Lindgren
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +01009 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 2 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program; if not, write to the Free Software
22 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 *
24 */
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010025#include <linux/module.h>
26#include <linux/init.h>
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000027#include <linux/kernel.h>
Russell Kingfced80c2008-09-06 12:10:45 +010028#include <linux/io.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010029#include <linux/spinlock.h>
Tony Lindgren2c799ce2012-02-24 10:34:35 -080030
31#include <asm/system.h>
32
33#include <plat/cpu.h>
Tony Lindgrence491cf2009-10-20 09:40:47 -070034#include <plat/mux.h>
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010035
36#ifdef CONFIG_OMAP_MUX
37
Tony Lindgren7d7f6652008-01-25 00:42:48 -080038static struct omap_mux_cfg *mux_cfg;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000039
Tony Lindgren7d7f6652008-01-25 00:42:48 -080040int __init omap_mux_register(struct omap_mux_cfg *arch_mux_cfg)
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000041{
Tony Lindgren7d7f6652008-01-25 00:42:48 -080042 if (!arch_mux_cfg || !arch_mux_cfg->pins || arch_mux_cfg->size == 0
43 || !arch_mux_cfg->cfg_reg) {
44 printk(KERN_ERR "Invalid pin table\n");
45 return -EINVAL;
46 }
47
48 mux_cfg = arch_mux_cfg;
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000049
50 return 0;
51}
52
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010053/*
54 * Sets the Omap MUX and PULL_DWN registers based on the table
55 */
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000056int __init_or_module omap_cfg_reg(const unsigned long index)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010057{
Tony Lindgren225dfda2008-01-25 00:42:48 -080058 struct pin_config *reg;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010059
Tony Lindgrenc9d82302010-07-05 16:31:40 +030060 if (!cpu_class_is_omap1()) {
Tony Lindgren15ac7af2009-12-11 16:16:32 -080061 printk(KERN_ERR "mux: Broken omap_cfg_reg(%lu) entry\n",
62 index);
63 WARN_ON(1);
64 return -EINVAL;
65 }
Santosh Shilimkar44169072009-05-28 14:16:04 -070066
Tony Lindgren7d7f6652008-01-25 00:42:48 -080067 if (mux_cfg == NULL) {
68 printk(KERN_ERR "Pin mux table not initialized\n");
69 return -ENODEV;
70 }
Tony Lindgren92105bb2005-09-07 17:20:26 +010071
Tony Lindgren7d7f6652008-01-25 00:42:48 -080072 if (index >= mux_cfg->size) {
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000073 printk(KERN_ERR "Invalid pin mux index: %lu (%lu)\n",
Tony Lindgren7d7f6652008-01-25 00:42:48 -080074 index, mux_cfg->size);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000075 dump_stack();
76 return -ENODEV;
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010077 }
78
Tony Lindgren225dfda2008-01-25 00:42:48 -080079 reg = (struct pin_config *)&mux_cfg->pins[index];
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000080
Tony Lindgren225dfda2008-01-25 00:42:48 -080081 if (!mux_cfg->cfg_reg)
82 return -ENODEV;
Kyungmin Park7bbb3cc2006-12-06 17:13:54 -080083
Tony Lindgren225dfda2008-01-25 00:42:48 -080084 return mux_cfg->cfg_reg(reg);
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010085}
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010086EXPORT_SYMBOL(omap_cfg_reg);
Tony Lindgren1a8bfa12005-11-10 14:26:50 +000087#else
88#define omap_mux_init() do {} while(0)
89#define omap_cfg_reg(x) do {} while(0)
Tony Lindgren5e1c5ff2005-07-10 19:58:15 +010090#endif /* CONFIG_OMAP_MUX */