28a33db076eba186f72f1eda551f9a4b34b8749c
[openwrt/staging/chunkeey.git] / target / linux / rdc-2.6 / files / arch / i386 / mach-rdc / gpio.c
1 /*
2 * Copyright (C) 2007, OpenWrt.org, Florian Fainelli <florian@openwrt.org>
3 * RDC321x architecture specific GPIO support
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the
7 * Free Software Foundation; either version 2 of the License, or (at your
8 * option) any later version.
9 */
10
11 #include <linux/autoconf.h>
12 #include <linux/init.h>
13 #include <linux/io.h>
14 #include <linux/types.h>
15 #include <linux/module.h>
16 #include <linux/delay.h>
17
18 #define RDC3210_CFGREG_ADDR 0x0CF8
19 #define RDC3210_CFGREG_DATA 0x0CFC
20
21 static unsigned int rdc_gpio_read(unsigned gpio)
22 {
23 unsigned int val;
24
25 val = 0x80000000 | (7 << 11) | ((gpio&0x20?0x84:0x48));
26 outl(val, RDC3210_CFGREG_ADDR);
27 udelay(10);
28 val = inl(RDC3210_CFGREG_DATA);
29 val |= (0x1 << (gpio & 0x1F));
30 outl(val, RDC3210_CFGREG_DATA);
31 udelay(10);
32 val = 0x80000000 | (7 << 11) | ((gpio&0x20?0x88:0x4C));
33 outl(val, RDC3210_CFGREG_ADDR);
34 udelay(10);
35 val = inl(RDC3210_CFGREG_DATA);
36
37 return val;
38 }
39
40 static void rdc_gpio_write(unsigned int val)
41 {
42 if (val) {
43 outl(val, RDC3210_CFGREG_DATA);
44 udelay(10);
45 }
46 }
47
48 int rdc_gpio_get_value(unsigned gpio)
49 {
50 return (gpio>0x3A?-EINVAL:(int)rdc_gpio_read(gpio));
51 }
52 EXPORT_SYMBOL(rdc_gpio_get_value);
53
54 void rdc_gpio_set_value(unsigned gpio, int value)
55 {
56 unsigned int val;
57
58 if (gpio > 0x3A) return;
59 val = rdc_gpio_read(gpio);
60
61 if (value)
62 val &= ~(0x1 << (gpio & 0x1F));
63 else
64 val |= (0x1 << (gpio & 0x1F));
65
66 rdc_gpio_write(val);
67 }
68 EXPORT_SYMBOL(rdc_gpio_set_value);
69
70 int rdc_gpio_direction_input(unsigned gpio)
71 {
72 return 0;
73 }
74 EXPORT_SYMBOL(rdc_gpio_direction_input);
75
76 int rdc_gpio_direction_output(unsigned gpio, int value)
77 {
78 return 0;
79 }
80 EXPORT_SYMBOL(rdc_gpio_direction_output);
81
82