2 * Copyright (C) 2007, OpenWrt.org, Florian Fainelli <florian@openwrt.org>
3 * RDC321x architecture specific GPIO support
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.
11 #include <linux/autoconf.h>
12 #include <linux/init.h>
14 #include <linux/types.h>
15 #include <linux/module.h>
16 #include <linux/delay.h>
18 #define RDC3210_CFGREG_ADDR 0x0CF8
19 #define RDC3210_CFGREG_DATA 0x0CFC
21 static unsigned int rdc_gpio_read(unsigned gpio)
25 val = 0x80000000 | (7 << 11) | ((gpio&0x20?0x84:0x48));
26 outl(val, RDC3210_CFGREG_ADDR);
28 val = inl(RDC3210_CFGREG_DATA);
29 val |= (0x1 << (gpio & 0x1F));
30 outl(val, RDC3210_CFGREG_DATA);
32 val = 0x80000000 | (7 << 11) | ((gpio&0x20?0x88:0x4C));
33 outl(val, RDC3210_CFGREG_ADDR);
35 val = inl(RDC3210_CFGREG_DATA);
40 static void rdc_gpio_write(unsigned int val)
43 outl(val, RDC3210_CFGREG_DATA);
48 int rdc_gpio_get_value(unsigned gpio)
50 return (gpio>0x3A?-EINVAL:(int)rdc_gpio_read(gpio));
52 EXPORT_SYMBOL(rdc_gpio_get_value);
54 void rdc_gpio_set_value(unsigned gpio, int value)
58 if (gpio > 0x3A) return;
59 val = rdc_gpio_read(gpio);
62 val &= ~(0x1 << (gpio & 0x1F));
64 val |= (0x1 << (gpio & 0x1F));
68 EXPORT_SYMBOL(rdc_gpio_set_value);
70 int rdc_gpio_direction_input(unsigned gpio)
74 EXPORT_SYMBOL(rdc_gpio_direction_input);
76 int rdc_gpio_direction_output(unsigned gpio, int value)
80 EXPORT_SYMBOL(rdc_gpio_direction_output);