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 | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 6 | * Copyright (C) 2003 - 2005 Nokia Corporation |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 7 | * |
| 8 | * Written by Tony Lindgren <tony.lindgren@nokia.com> |
| 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> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 28 | #include <asm/system.h> |
| 29 | #include <asm/io.h> |
| 30 | #include <linux/spinlock.h> |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 31 | #include <asm/arch/mux.h> |
| 32 | |
| 33 | #ifdef CONFIG_OMAP_MUX |
| 34 | |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 35 | #define OMAP24XX_L4_BASE 0x48000000 |
| 36 | #define OMAP24XX_PULL_ENA (1 << 3) |
| 37 | #define OMAP24XX_PULL_UP (1 << 4) |
| 38 | |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame^] | 39 | static struct omap_mux_cfg *mux_cfg; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 40 | |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame^] | 41 | int __init omap_mux_register(struct omap_mux_cfg *arch_mux_cfg) |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 42 | { |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame^] | 43 | if (!arch_mux_cfg || !arch_mux_cfg->pins || arch_mux_cfg->size == 0 |
| 44 | || !arch_mux_cfg->cfg_reg) { |
| 45 | printk(KERN_ERR "Invalid pin table\n"); |
| 46 | return -EINVAL; |
| 47 | } |
| 48 | |
| 49 | mux_cfg = arch_mux_cfg; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 50 | |
| 51 | return 0; |
| 52 | } |
| 53 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 54 | /* |
| 55 | * Sets the Omap MUX and PULL_DWN registers based on the table |
| 56 | */ |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 57 | int __init_or_module omap_cfg_reg(const unsigned long index) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 58 | { |
| 59 | static DEFINE_SPINLOCK(mux_spin_lock); |
| 60 | |
| 61 | unsigned long flags; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 62 | struct pin_config *cfg; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 63 | unsigned int reg_orig = 0, reg = 0, pu_pd_orig = 0, pu_pd = 0, |
| 64 | pull_orig = 0, pull = 0; |
| 65 | unsigned int mask, warn = 0; |
| 66 | |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame^] | 67 | if (mux_cfg == NULL) { |
| 68 | printk(KERN_ERR "Pin mux table not initialized\n"); |
| 69 | return -ENODEV; |
| 70 | } |
Tony Lindgren | 92105bb | 2005-09-07 17:20:26 +0100 | [diff] [blame] | 71 | |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame^] | 72 | if (index >= mux_cfg->size) { |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 73 | printk(KERN_ERR "Invalid pin mux index: %lu (%lu)\n", |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame^] | 74 | index, mux_cfg->size); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 75 | dump_stack(); |
| 76 | return -ENODEV; |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 77 | } |
| 78 | |
Tony Lindgren | 7d7f665 | 2008-01-25 00:42:48 -0800 | [diff] [blame^] | 79 | cfg = (struct pin_config *)&mux_cfg->pins[index]; |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 80 | if (cpu_is_omap24xx()) { |
| 81 | u8 reg = 0; |
| 82 | |
| 83 | reg |= cfg->mask & 0x7; |
| 84 | if (cfg->pull_val) |
| 85 | reg |= OMAP24XX_PULL_ENA; |
| 86 | if(cfg->pu_pd_val) |
| 87 | reg |= OMAP24XX_PULL_UP; |
Kyungmin Park | 7bbb3cc | 2006-12-06 17:13:54 -0800 | [diff] [blame] | 88 | #if defined(CONFIG_OMAP_MUX_DEBUG) || defined(CONFIG_OMAP_MUX_WARNINGS) |
| 89 | { |
| 90 | u8 orig = omap_readb(OMAP24XX_L4_BASE + cfg->mux_reg); |
| 91 | u8 debug = 0; |
| 92 | |
| 93 | #ifdef CONFIG_OMAP_MUX_DEBUG |
| 94 | debug = cfg->debug; |
| 95 | #endif |
| 96 | warn = (orig != reg); |
| 97 | if (debug || warn) |
| 98 | printk("MUX: setup %s (0x%08x): 0x%02x -> 0x%02x\n", |
| 99 | cfg->name, |
| 100 | OMAP24XX_L4_BASE + cfg->mux_reg, |
| 101 | orig, reg); |
| 102 | } |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 103 | #endif |
| 104 | omap_writeb(reg, OMAP24XX_L4_BASE + cfg->mux_reg); |
| 105 | |
| 106 | return 0; |
| 107 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 108 | |
| 109 | /* Check the mux register in question */ |
| 110 | if (cfg->mux_reg) { |
| 111 | unsigned tmp1, tmp2; |
| 112 | |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 113 | spin_lock_irqsave(&mux_spin_lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 114 | reg_orig = omap_readl(cfg->mux_reg); |
| 115 | |
| 116 | /* The mux registers always seem to be 3 bits long */ |
| 117 | mask = (0x7 << cfg->mask_offset); |
| 118 | tmp1 = reg_orig & mask; |
| 119 | reg = reg_orig & ~mask; |
| 120 | |
| 121 | tmp2 = (cfg->mask << cfg->mask_offset); |
| 122 | reg |= tmp2; |
| 123 | |
| 124 | if (tmp1 != tmp2) |
| 125 | warn = 1; |
| 126 | |
| 127 | omap_writel(reg, cfg->mux_reg); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 128 | spin_unlock_irqrestore(&mux_spin_lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 129 | } |
| 130 | |
| 131 | /* Check for pull up or pull down selection on 1610 */ |
Vladimir Ananiev | 99c658a | 2006-12-11 13:30:21 -0800 | [diff] [blame] | 132 | if (!cpu_is_omap15xx()) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 133 | if (cfg->pu_pd_reg && cfg->pull_val) { |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 134 | spin_lock_irqsave(&mux_spin_lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 135 | pu_pd_orig = omap_readl(cfg->pu_pd_reg); |
| 136 | mask = 1 << cfg->pull_bit; |
| 137 | |
| 138 | if (cfg->pu_pd_val) { |
| 139 | if (!(pu_pd_orig & mask)) |
| 140 | warn = 1; |
| 141 | /* Use pull up */ |
| 142 | pu_pd = pu_pd_orig | mask; |
| 143 | } else { |
| 144 | if (pu_pd_orig & mask) |
| 145 | warn = 1; |
| 146 | /* Use pull down */ |
| 147 | pu_pd = pu_pd_orig & ~mask; |
| 148 | } |
| 149 | omap_writel(pu_pd, cfg->pu_pd_reg); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 150 | spin_unlock_irqrestore(&mux_spin_lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 151 | } |
| 152 | } |
| 153 | |
| 154 | /* Check for an associated pull down register */ |
| 155 | if (cfg->pull_reg) { |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 156 | spin_lock_irqsave(&mux_spin_lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 157 | pull_orig = omap_readl(cfg->pull_reg); |
| 158 | mask = 1 << cfg->pull_bit; |
| 159 | |
| 160 | if (cfg->pull_val) { |
| 161 | if (pull_orig & mask) |
| 162 | warn = 1; |
| 163 | /* Low bit = pull enabled */ |
| 164 | pull = pull_orig & ~mask; |
| 165 | } else { |
| 166 | if (!(pull_orig & mask)) |
| 167 | warn = 1; |
| 168 | /* High bit = pull disabled */ |
| 169 | pull = pull_orig | mask; |
| 170 | } |
| 171 | |
| 172 | omap_writel(pull, cfg->pull_reg); |
Tony Lindgren | bb13b5f | 2005-07-10 19:58:18 +0100 | [diff] [blame] | 173 | spin_unlock_irqrestore(&mux_spin_lock, flags); |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 174 | } |
| 175 | |
| 176 | if (warn) { |
| 177 | #ifdef CONFIG_OMAP_MUX_WARNINGS |
| 178 | printk(KERN_WARNING "MUX: initialized %s\n", cfg->name); |
| 179 | #endif |
| 180 | } |
| 181 | |
| 182 | #ifdef CONFIG_OMAP_MUX_DEBUG |
| 183 | if (cfg->debug || warn) { |
| 184 | printk("MUX: Setting register %s\n", cfg->name); |
| 185 | printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n", |
| 186 | cfg->mux_reg_name, cfg->mux_reg, reg_orig, reg); |
| 187 | |
Vladimir Ananiev | 99c658a | 2006-12-11 13:30:21 -0800 | [diff] [blame] | 188 | if (!cpu_is_omap15xx()) { |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 189 | if (cfg->pu_pd_reg && cfg->pull_val) { |
| 190 | printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n", |
| 191 | cfg->pu_pd_name, cfg->pu_pd_reg, |
| 192 | pu_pd_orig, pu_pd); |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | if (cfg->pull_reg) |
| 197 | printk(" %s (0x%08x) = 0x%08x -> 0x%08x\n", |
| 198 | cfg->pull_name, cfg->pull_reg, pull_orig, pull); |
| 199 | } |
| 200 | #endif |
| 201 | |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 202 | #ifdef CONFIG_OMAP_MUX_ERRORS |
| 203 | return warn ? -ETXTBSY : 0; |
| 204 | #else |
| 205 | return 0; |
| 206 | #endif |
| 207 | } |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 208 | EXPORT_SYMBOL(omap_cfg_reg); |
Tony Lindgren | 1a8bfa1 | 2005-11-10 14:26:50 +0000 | [diff] [blame] | 209 | #else |
| 210 | #define omap_mux_init() do {} while(0) |
| 211 | #define omap_cfg_reg(x) do {} while(0) |
Tony Lindgren | 5e1c5ff | 2005-07-10 19:58:15 +0100 | [diff] [blame] | 212 | #endif /* CONFIG_OMAP_MUX */ |