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 #include <asm/mach-rdc/rdc321x_defs.h>
20 static inline int rdc_gpio_is_valid(unsigned gpio
)
22 return (gpio
<= RDC_MAX_GPIO
);
25 static unsigned int rdc_gpio_read(unsigned gpio
)
29 val
= 0x80000000 | (7 << 11) | ((gpio
&0x20?0x84:0x48));
30 outl(val
, RDC3210_CFGREG_ADDR
);
32 val
= inl(RDC3210_CFGREG_DATA
);
33 val
|= (0x1 << (gpio
& 0x1F));
34 outl(val
, RDC3210_CFGREG_DATA
);
36 val
= 0x80000000 | (7 << 11) | ((gpio
&0x20?0x88:0x4C));
37 outl(val
, RDC3210_CFGREG_ADDR
);
39 val
= inl(RDC3210_CFGREG_DATA
);
44 static void rdc_gpio_write(unsigned int val
)
47 outl(val
, RDC3210_CFGREG_DATA
);
52 int rdc_gpio_get_value(unsigned gpio
)
54 if (rdc_gpio_is_valid(gpio
))
55 return (int)rdc_gpio_read(gpio
);
59 EXPORT_SYMBOL(rdc_gpio_get_value
);
61 void rdc_gpio_set_value(unsigned gpio
, int value
)
65 if (!rdc_gpio_is_valid(gpio
))
68 val
= rdc_gpio_read(gpio
);
71 val
&= ~(0x1 << (gpio
& 0x1F));
73 val
|= (0x1 << (gpio
& 0x1F));
77 EXPORT_SYMBOL(rdc_gpio_set_value
);
79 int rdc_gpio_direction_input(unsigned gpio
)
83 EXPORT_SYMBOL(rdc_gpio_direction_input
);
85 int rdc_gpio_direction_output(unsigned gpio
, int value
)
89 EXPORT_SYMBOL(rdc_gpio_direction_output
);