2 * Miscellaneous functions for IDT EB434 board
4 * Copyright 2004 IDT Inc. (rischelp@idt.com)
5 * Copyright 2006 Phil Sutter <n0-1@freewrt.org>
6 * Copyright 2007 Florian Fainelli <florian@openwrt.org>
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the
10 * Free Software Foundation; either version 2 of the License, or (at your
11 * option) any later version.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
14 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
15 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
16 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
17 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
18 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
19 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
20 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
21 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
22 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
24 * You should have received a copy of the GNU General Public License along
25 * with this program; if not, write to the Free Software Foundation, Inc.,
26 * 675 Mass Ave, Cambridge, MA 02139, USA.
29 #include <linux/kernel.h>
30 #include <linux/init.h>
31 #include <linux/types.h>
32 #include <linux/pci.h>
33 #include <linux/spinlock.h>
35 #include <linux/platform_device.h>
37 #include <asm/addrspace.h>
40 #include <asm/rc32434/rb.h>
42 #define GPIO_BADDR 0x18050000
44 static volatile unsigned char *devCtl3Base
;
45 static unsigned char latchU5State
;
46 static spinlock_t clu5Lock
= SPIN_LOCK_UNLOCKED
;
48 struct rb500_gpio_reg __iomem
*rb500_gpio_reg0
;
49 EXPORT_SYMBOL(rb500_gpio_reg0
);
51 static struct resource rb500_gpio_reg0_res
[] = {
55 .end
= GPIO_BADDR
+ sizeof(struct rb500_gpio_reg
),
56 .flags
= IORESOURCE_MEM
,
60 void set434Reg(unsigned regOffs
, unsigned bit
, unsigned len
, unsigned val
)
65 spin_lock_irqsave(&clu5Lock
, flags
);
66 data
= *(volatile unsigned *) (IDT434_REG_BASE
+ regOffs
);
67 for (i
= 0; i
!= len
; ++i
) {
69 data
|= (1 << (i
+ bit
));
71 data
&= ~(1 << (i
+ bit
));
73 *(volatile unsigned *) (IDT434_REG_BASE
+ regOffs
) = data
;
74 spin_unlock_irqrestore(&clu5Lock
, flags
);
76 EXPORT_SYMBOL(set434Reg
);
78 void changeLatchU5(unsigned char orMask
, unsigned char nandMask
)
82 spin_lock_irqsave(&clu5Lock
, flags
);
83 latchU5State
= (latchU5State
| orMask
) & ~nandMask
;
85 devCtl3Base
= (volatile unsigned char *)
86 KSEG1ADDR(*(volatile unsigned *)
87 KSEG1ADDR(0x18010030));
88 *devCtl3Base
= latchU5State
;
89 spin_unlock_irqrestore(&clu5Lock
, flags
);
91 EXPORT_SYMBOL(changeLatchU5
);
93 unsigned char getLatchU5State(void)
97 EXPORT_SYMBOL(getLatchU5State
);
99 int rb500_gpio_get_value(unsigned gpio
)
101 return readl(&rb500_gpio_reg0
->gpiod
) & (1 << gpio
);
103 EXPORT_SYMBOL(rb500_gpio_get_value
);
105 void rb500_gpio_set_value(unsigned gpio
, int value
)
109 tmp
= readl(&rb500_gpio_reg0
->gpiod
) & ~(1 << gpio
);
113 writel(tmp
, (void *)&rb500_gpio_reg0
->gpiod
);
115 EXPORT_SYMBOL(rb500_gpio_set_value
);
117 int rb500_gpio_direction_input(unsigned gpio
)
119 writel(readl(&rb500_gpio_reg0
->gpiocfg
) & ~(1 << gpio
), (void *)&rb500_gpio_reg0
->gpiocfg
);
123 EXPORT_SYMBOL(rb500_gpio_direction_input
);
125 int rb500_gpio_direction_output(unsigned gpio
, int value
)
127 gpio_set_value(gpio
, value
);
128 writel(readl(&rb500_gpio_reg0
->gpiocfg
) | (1 << gpio
), (void *)&rb500_gpio_reg0
->gpiocfg
);
132 EXPORT_SYMBOL(rb500_gpio_direction_output
);
134 void rb500_gpio_set_int_level(unsigned gpio
, int value
)
138 tmp
= readl(&rb500_gpio_reg0
->gpioilevel
) & ~(1 << gpio
);
141 writel(tmp
, (void *)&rb500_gpio_reg0
->gpioilevel
);
143 EXPORT_SYMBOL(rb500_gpio_set_int_level
);
145 int rb500_gpio_get_int_level(unsigned gpio
)
147 return readl(&rb500_gpio_reg0
->gpioilevel
) & (1 << gpio
);
149 EXPORT_SYMBOL(rb500_gpio_get_int_level
);
151 void rb500_gpio_set_int_status(unsigned gpio
, int value
)
155 tmp
= readl(&rb500_gpio_reg0
->gpioistat
);
158 writel(tmp
, (void *)&rb500_gpio_reg0
->gpioistat
);
160 EXPORT_SYMBOL(rb500_gpio_set_int_status
);
162 int rb500_gpio_get_int_status(unsigned gpio
)
164 return readl(&rb500_gpio_reg0
->gpioistat
) & (1 << gpio
);
166 EXPORT_SYMBOL(rb500_gpio_get_int_status
);
168 void rb500_gpio_set_func(unsigned gpio
, int value
)
172 tmp
= readl(&rb500_gpio_reg0
->gpiofunc
);
175 writel(tmp
, (void *)&rb500_gpio_reg0
->gpiofunc
);
177 EXPORT_SYMBOL(rb500_gpio_set_func
);
179 int rb500_gpio_get_func(unsigned gpio
)
181 return readl(&rb500_gpio_reg0
->gpiofunc
) & (1 << gpio
);
183 EXPORT_SYMBOL(rb500_gpio_get_func
);
185 int __init
rb500_gpio_init(void)
187 rb500_gpio_reg0
= ioremap_nocache(rb500_gpio_reg0_res
[0].start
,
188 rb500_gpio_reg0_res
[0].end
-
189 rb500_gpio_reg0_res
[0].start
);
191 if (!rb500_gpio_reg0
) {
192 printk(KERN_ERR
"rb500: cannot remap GPIO register 0\n");
198 arch_initcall(rb500_gpio_init
);