mwl8k: increase firmware loading timeouts
[linux/fpc-iii.git] / arch / arm / mach-mxc91231 / iomux.c
blob405d9b19d891ee636c7591ea827a0f1def0da0d4
1 /*
2 * Copyright 2004-2006 Freescale Semiconductor, Inc. All Rights Reserved.
3 * Copyright (C) 2008 by Sascha Hauer <kernel@pengutronix.de>
4 * Copyright (C) 2009 by Valentin Longchamp <valentin.longchamp@epfl.ch>
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU General Public License
8 * as published by the Free Software Foundation; either version 2
9 * of the License, or (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
18 * MA 02110-1301, USA.
21 #include <linux/module.h>
22 #include <linux/spinlock.h>
23 #include <linux/io.h>
24 #include <linux/kernel.h>
25 #include <mach/hardware.h>
26 #include <mach/gpio.h>
27 #include <mach/iomux-mxc91231.h>
30 * IOMUX register (base) addresses
32 #define IOMUX_AP_BASE MXC91231_IO_ADDRESS(MXC91231_IOMUX_AP_BASE_ADDR)
33 #define IOMUX_COM_BASE MXC91231_IO_ADDRESS(MXC91231_IOMUX_COM_BASE_ADDR)
34 #define IOMUXSW_AP_MUX_CTL (IOMUX_AP_BASE + 0x000)
35 #define IOMUXSW_SP_MUX_CTL (IOMUX_COM_BASE + 0x000)
36 #define IOMUXSW_PAD_CTL (IOMUX_COM_BASE + 0x200)
38 #define IOMUXINT_OBS1 (IOMUX_AP_BASE + 0x600)
39 #define IOMUXINT_OBS2 (IOMUX_AP_BASE + 0x004)
41 static DEFINE_SPINLOCK(gpio_mux_lock);
43 #define NB_PORTS ((PIN_MAX + 32) / 32)
44 #define PIN_GLOBAL_NUM(pin) \
45 (((pin & MUX_SIDE_MASK) >> MUX_SIDE_SHIFT)*PIN_AP_MAX + \
46 ((pin & MUX_REG_MASK) >> MUX_REG_SHIFT)*4 + \
47 ((pin & MUX_FIELD_MASK) >> MUX_FIELD_SHIFT))
49 unsigned long mxc_pin_alloc_map[NB_PORTS * 32 / BITS_PER_LONG];
51 * set the mode for a IOMUX pin.
53 int mxc_iomux_mode(const unsigned int pin_mode)
55 u32 side, field, l, mode, ret = 0;
56 void __iomem *reg;
58 side = (pin_mode & MUX_SIDE_MASK) >> MUX_SIDE_SHIFT;
59 switch (side) {
60 case MUX_SIDE_AP:
61 reg = IOMUXSW_AP_MUX_CTL;
62 break;
63 case MUX_SIDE_SP:
64 reg = IOMUXSW_SP_MUX_CTL;
65 break;
66 default:
67 return -EINVAL;
69 reg += ((pin_mode & MUX_REG_MASK) >> MUX_REG_SHIFT) * 4;
70 field = (pin_mode & MUX_FIELD_MASK) >> MUX_FIELD_SHIFT;
71 mode = (pin_mode & MUX_MODE_MASK) >> MUX_MODE_SHIFT;
73 spin_lock(&gpio_mux_lock);
75 l = __raw_readl(reg);
76 l &= ~(0xff << (field * 8));
77 l |= mode << (field * 8);
78 __raw_writel(l, reg);
80 spin_unlock(&gpio_mux_lock);
82 return ret;
84 EXPORT_SYMBOL(mxc_iomux_mode);
87 * This function configures the pad value for a IOMUX pin.
89 void mxc_iomux_set_pad(enum iomux_pins pin, u32 config)
91 u32 padgrp, field, l;
92 void __iomem *reg;
94 padgrp = (pin & MUX_PADGRP_MASK) >> MUX_PADGRP_SHIFT;
95 reg = IOMUXSW_PAD_CTL + (pin + 2) / 3 * 4;
96 field = (pin + 2) % 3;
98 pr_debug("%s: reg offset = 0x%x, field = %d\n",
99 __func__, (pin + 2) / 3, field);
101 spin_lock(&gpio_mux_lock);
103 l = __raw_readl(reg);
104 l &= ~(0x1ff << (field * 10));
105 l |= config << (field * 10);
106 __raw_writel(l, reg);
108 spin_unlock(&gpio_mux_lock);
110 EXPORT_SYMBOL(mxc_iomux_set_pad);
113 * allocs a single pin:
114 * - reserves the pin so that it is not claimed by another driver
115 * - setups the iomux according to the configuration
117 int mxc_iomux_alloc_pin(const unsigned int pin_mode, const char *label)
119 unsigned pad = PIN_GLOBAL_NUM(pin_mode);
120 if (pad >= (PIN_MAX + 1)) {
121 printk(KERN_ERR "mxc_iomux: Attempt to request nonexistant pin %u for \"%s\"\n",
122 pad, label ? label : "?");
123 return -EINVAL;
126 if (test_and_set_bit(pad, mxc_pin_alloc_map)) {
127 printk(KERN_ERR "mxc_iomux: pin %u already used. Allocation for \"%s\" failed\n",
128 pad, label ? label : "?");
129 return -EBUSY;
131 mxc_iomux_mode(pin_mode);
133 return 0;
135 EXPORT_SYMBOL(mxc_iomux_alloc_pin);
137 int mxc_iomux_setup_multiple_pins(unsigned int *pin_list, unsigned count,
138 const char *label)
140 unsigned int *p = pin_list;
141 int i;
142 int ret = -EINVAL;
144 for (i = 0; i < count; i++) {
145 ret = mxc_iomux_alloc_pin(*p, label);
146 if (ret)
147 goto setup_error;
148 p++;
150 return 0;
152 setup_error:
153 mxc_iomux_release_multiple_pins(pin_list, i);
154 return ret;
156 EXPORT_SYMBOL(mxc_iomux_setup_multiple_pins);
158 void mxc_iomux_release_pin(const unsigned int pin_mode)
160 unsigned pad = PIN_GLOBAL_NUM(pin_mode);
162 if (pad < (PIN_MAX + 1))
163 clear_bit(pad, mxc_pin_alloc_map);
165 EXPORT_SYMBOL(mxc_iomux_release_pin);
167 void mxc_iomux_release_multiple_pins(unsigned int *pin_list, int count)
169 unsigned int *p = pin_list;
170 int i;
172 for (i = 0; i < count; i++) {
173 mxc_iomux_release_pin(*p);
174 p++;
177 EXPORT_SYMBOL(mxc_iomux_release_multiple_pins);