Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 1 | /* |
| 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 Lindgren | 9330899 | 2008-01-24 17:24:15 -0800 | [diff] [blame] | 6 | * Copyright (C) 2003 - 2008 Nokia Corporation |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 7 | * |
Tony Lindgren | 9330899 | 2008-01-24 17:24:15 -0800 | [diff] [blame] | 8 | * Written by Tony Lindgren |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 9 | * |
| 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 Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 25 | #include <linux/module.h> |
| 26 | #include <linux/init.h> |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 27 | #include <linux/kernel.h> |
Russell King | fced80c | 2008-09-06 12:10:45 +0100 | [diff] [blame] | 28 | #include <linux/io.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 29 | #include <asm/system.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 30 | #include <linux/spinlock.h> |
Tony Lindgren | ce491cf | 2009-10-20 09:40:47 -0700 | [diff] [blame] | 31 | #include <plat/mux.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 32 | |
| 33 | #ifdef CONFIG_OMAP_MUX |
| 34 | |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame] | 35 | static struct omap_mux_cfg *mux_cfg; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 36 | |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame] | 37 | int __init omap_mux_register(struct omap_mux_cfg *arch_mux_cfg) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 38 | { |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame] | 39 | if (!arch_mux_cfg || !arch_mux_cfg->pins || arch_mux_cfg->size == 0 |
| 40 | || !arch_mux_cfg->cfg_reg) { |
| 41 | printk(KERN_ERR "Invalid pin table\n"); |
| 42 | return -EINVAL; |
| 43 | } |
| 44 | |
| 45 | mux_cfg = arch_mux_cfg; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 46 | |
| 47 | return 0; |
| 48 | } |
| 49 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 50 | /* |
| 51 | * Sets the Omap MUX and PULL_DWN registers based on the table |
| 52 | */ |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 53 | int __init_or_module omap_cfg_reg(const unsigned long index) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 54 | { |
Tony Lindgren | 225dfda | 2008-01-25 00:42:48 -0800 | [diff] [blame] | 55 | struct pin_config *reg; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 56 | |
Tony Lindgren | 15ac7af | 2009-12-11 16:16:32 -0800 | [diff] [blame^] | 57 | if (cpu_is_omap34xx() || cpu_is_omap44xx()) { |
| 58 | printk(KERN_ERR "mux: Broken omap_cfg_reg(%lu) entry\n", |
| 59 | index); |
| 60 | WARN_ON(1); |
| 61 | return -EINVAL; |
| 62 | } |
Santosh Shilimkar | 4416907 | 2009-05-28 14:16:04 -0700 | [diff] [blame] | 63 | |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame] | 64 | if (mux_cfg == NULL) { |
| 65 | printk(KERN_ERR "Pin mux table not initialized\n"); |
| 66 | return -ENODEV; |
| 67 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 68 | |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame] | 69 | if (index >= mux_cfg->size) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 70 | printk(KERN_ERR "Invalid pin mux index: %lu (%lu)\n", |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame] | 71 | index, mux_cfg->size); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 72 | dump_stack(); |
| 73 | return -ENODEV; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 74 | } |
| 75 | |
Tony Lindgren | 225dfda | 2008-01-25 00:42:48 -0800 | [diff] [blame] | 76 | reg = (struct pin_config *)&mux_cfg->pins[index]; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 77 | |
Tony Lindgren | 225dfda | 2008-01-25 00:42:48 -0800 | [diff] [blame] | 78 | if (!mux_cfg->cfg_reg) |
| 79 | return -ENODEV; |
Kyungmin Park | 7bbb3cc | 2006-12-06 17:13:54 -0800 | [diff] [blame] | 80 | |
Tony Lindgren | 225dfda | 2008-01-25 00:42:48 -0800 | [diff] [blame] | 81 | return mux_cfg->cfg_reg(reg); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 82 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 83 | EXPORT_SYMBOL(omap_cfg_reg); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 84 | #else |
| 85 | #define omap_mux_init() do {} while(0) |
| 86 | #define omap_cfg_reg(x) do {} while(0) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 87 | #endif /* CONFIG_OMAP_MUX */ |