2 * FILE NAME au1000_gpio.c
4 * BRIEF MODULE DESCRIPTION
5 * Driver for Alchemy Au1000 GPIO.
7 * Author: MontaVista Software, Inc. <source@mvista.com>
8 * Steve Longerbeam <stevel@mvista.com>
10 * Copyright 2001 MontaVista Software Inc.
12 * This program is free software; you can redistribute it and/or modify it
13 * under the terms of the GNU General Public License as published by the
14 * Free Software Foundation; either version 2 of the License, or (at your
15 * option) any later version.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN
20 * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
23 * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
24 * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
28 * You should have received a copy of the GNU General Public License along
29 * with this program; if not, write to the Free Software Foundation, Inc.,
30 * 675 Mass Ave, Cambridge, MA 02139, USA.
33 #include <linux/module.h>
34 #include <linux/config.h>
35 #include <linux/types.h>
36 #include <linux/kernel.h>
37 #include <linux/miscdevice.h>
38 #include <linux/init.h>
39 #include <asm/uaccess.h>
41 #include <asm/au1000.h>
42 #include <asm/au1000_gpio.h>
44 #define VERSION "0.01"
49 } pinfunc_to_avail[15] = {
50 {1, 0x7<<16}, // 0 = SSI0 / GPIO[18:16]
51 {-1, 0}, // 1 = AC97 / SSI1
52 {1, 1<<19}, // 2 = IRDA / GPIO19
53 {1, 1<<20}, // 3 = UART0 / GPIO20
54 {1, 0x1f<<24}, // 4 = NIC2 / GPIO[28:24]
55 {1, 0x7<<29}, // 5 = I2S / GPIO[31:29]
56 {0, 1<<8}, // 6 = I2SDI / GPIO8
57 {0, 0x3f<<9}, // 7 = UART3 / GPIO[14:9]
58 {0, 1<<15}, // 8 = IRFIRSEL / GPIO15
59 {0, 1<<2}, // 9 = EXTCLK0 or OSC / GPIO2
60 {0, 1<<3}, // 10 = EXTCLK1 / GPIO3
61 {0, 1<<6}, // 11 = SMROMCKE / GPIO6
62 {1, 1<<21}, // 12 = UART1 / GPIO21
63 {1, 1<<22}, // 13 = UART2 / GPIO22
64 {1, 1<<23} // 14 = UART3 / GPIO23
68 u32 get_au1000_avail_gpio_mask(void)
71 u32 pinfunc = inl(SYS_PINFUNC);
72 u32 avail_mask = 0; // start with no gpio available
74 // first, check for GPIO's reprogrammed as peripheral pins
75 for (i=0; i<15; i++) {
76 if (pinfunc_to_avail[i].active_hi < 0)
78 if (!(pinfunc_to_avail[i].active_hi ^
79 ((pinfunc & (1<<i)) ? 1:0)))
80 avail_mask |= pinfunc_to_avail[i].avail_mask;
83 // check for GPIO's used as interrupt sources
84 avail_mask &= ~(inl(IC1_MASKRD) &
85 (inl(IC1_CFG0RD) | inl(IC1_CFG1RD)));
87 #ifdef CONFIG_USB_OHCI
88 avail_mask &= ~((1<<4) | (1<<11));
89 #ifndef CONFIG_AU1000_USB_DEVICE
90 avail_mask &= ~((1<<5) | (1<<13));
99 * Tristate the requested GPIO pins specified in data.
100 * Only available GPIOs will be tristated.
102 int au1000gpio_tristate(u32 data)
104 data &= get_au1000_avail_gpio_mask();
107 outl(data, SYS_TRIOUTCLR);
114 * Return the pin state. Pins configured as outputs will return
115 * the output state, and pins configured as inputs (tri-stated)
116 * will return input pin state.
118 int au1000gpio_in(u32 *data)
120 *data = inl(SYS_PINSTATERD);
126 * Set/clear GPIO pins. Only available GPIOs will be affected.
128 int au1000gpio_set(u32 data)
130 data &= get_au1000_avail_gpio_mask();
133 outl(data, SYS_OUTPUTSET);
137 int au1000gpio_clear(u32 data)
139 data &= get_au1000_avail_gpio_mask();
142 outl(data, SYS_OUTPUTCLR);
147 * Output data to GPIO pins. Only available GPIOs will be affected.
149 int au1000gpio_out(u32 data)
151 au1000gpio_set(data);
152 au1000gpio_clear(~data);
157 EXPORT_SYMBOL(get_au1000_avail_gpio_mask);
158 EXPORT_SYMBOL(au1000gpio_tristate);
159 EXPORT_SYMBOL(au1000gpio_in);
160 EXPORT_SYMBOL(au1000gpio_set);
161 EXPORT_SYMBOL(au1000gpio_clear);
162 EXPORT_SYMBOL(au1000gpio_out);
165 static int au1000gpio_open(struct inode *inode, struct file *file)
173 static int au1000gpio_release(struct inode *inode, struct file *file)
181 static int au1000gpio_ioctl(struct inode *inode, struct file *file,
182 unsigned int cmd, unsigned long arg)
190 status = au1000gpio_in(&val);
194 return put_user(val, (u32 *)arg);
198 if (get_user(val, (u32 *)arg))
201 return au1000gpio_out(val);
205 if (get_user(val, (u32 *)arg))
208 return au1000gpio_set(val);
210 case AU1000GPIO_CLEAR:
212 if (get_user(val, (u32 *)arg))
215 return au1000gpio_clear(val);
217 case AU1000GPIO_TRISTATE:
219 if (get_user(val, (u32 *)arg))
222 return au1000gpio_tristate(val);
224 case AU1000GPIO_AVAIL_MASK:
226 return put_user(get_au1000_avail_gpio_mask(),
238 static struct file_operations au1000gpio_fops =
241 ioctl: au1000gpio_ioctl,
242 open: au1000gpio_open,
243 release: au1000gpio_release,
247 static struct miscdevice au1000gpio_miscdev =
255 int __init au1000gpio_init(void)
257 misc_register(&au1000gpio_miscdev);
258 printk("Au1000 gpio driver, version %s\n", VERSION);
263 void __exit au1000gpio_exit(void)
265 misc_deregister(&au1000gpio_miscdev);
269 module_init(au1000gpio_init);
270 module_exit(au1000gpio_exit);