[TG3]: Set minimal hw interrupt mitigation.
[linux-2.6/verdex.git] / arch / h8300 / kernel / gpio.c
blob795682b873e201e3af44149fcfb51f302735b086
1 /*
2 * linux/arch/h8300/kernel/gpio.c
4 * Yoshinori Sato <ysato@users.sourceforge.jp>
6 */
8 /*
9 * Internal I/O Port Management
12 #include <linux/config.h>
13 #include <linux/stddef.h>
14 #include <linux/proc_fs.h>
15 #include <linux/kernel.h>
16 #include <linux/string.h>
17 #include <linux/fs.h>
18 #include <linux/init.h>
20 #define _(addr) (volatile unsigned char *)(addr)
21 #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
22 #include <asm/regs306x.h>
23 static volatile unsigned char *ddrs[] = {
24 _(P1DDR),_(P2DDR),_(P3DDR),_(P4DDR),_(P5DDR),_(P6DDR),
25 NULL, _(P8DDR),_(P9DDR),_(PADDR),_(PBDDR),
27 #define MAX_PORT 11
28 #endif
30 #if defined(CONFIG_H83002) || defined(CONFIG_H8048)
31 /* Fix me!! */
32 #include <asm/regs306x.h>
33 static volatile unsigned char *ddrs[] = {
34 _(P1DDR),_(P2DDR),_(P3DDR),_(P4DDR),_(P5DDR),_(P6DDR),
35 NULL, _(P8DDR),_(P9DDR),_(PADDR),_(PBDDR),
37 #define MAX_PORT 11
38 #endif
40 #if defined(CONFIG_H8S2678)
41 #include <asm/regs267x.h>
42 static volatile unsigned char *ddrs[] = {
43 _(P1DDR),_(P2DDR),_(P3DDR),NULL ,_(P5DDR),_(P6DDR),
44 _(P7DDR),_(P8DDR),NULL, _(PADDR),_(PBDDR),_(PCDDR),
45 _(PDDDR),_(PEDDR),_(PFDDR),_(PGDDR),_(PHDDR),
46 _(PADDR),_(PBDDR),_(PCDDR),_(PDDDR),_(PEDDR),_(PFDDR),
47 _(PGDDR),_(PHDDR)
49 #define MAX_PORT 17
50 #endif
51 #undef _
53 #if !defined(P1DDR)
54 #error Unsuppoted CPU Selection
55 #endif
57 static struct {
58 unsigned char used;
59 unsigned char ddr;
60 } gpio_regs[MAX_PORT];
62 extern char *_platform_gpio_table(int length);
64 int h8300_reserved_gpio(int port, unsigned int bits)
66 unsigned char *used;
68 if (port < 0 || port >= MAX_PORT)
69 return -1;
70 used = &(gpio_regs[port].used);
71 if ((*used & bits) != 0)
72 return 0;
73 *used |= bits;
74 return 1;
77 int h8300_free_gpio(int port, unsigned int bits)
79 unsigned char *used;
81 if (port < 0 || port >= MAX_PORT)
82 return -1;
83 used = &(gpio_regs[port].used);
84 if ((*used & bits) != bits)
85 return 0;
86 *used &= (~bits);
87 return 1;
90 int h8300_set_gpio_dir(int port_bit,int dir)
92 int port = (port_bit >> 8) & 0xff;
93 int bit = port_bit & 0xff;
95 if (ddrs[port] == NULL)
96 return 0;
97 if (gpio_regs[port].used & bit) {
98 if (dir)
99 gpio_regs[port].ddr |= bit;
100 else
101 gpio_regs[port].ddr &= ~bit;
102 *ddrs[port] = gpio_regs[port].ddr;
103 return 1;
104 } else
105 return 0;
108 int h8300_get_gpio_dir(int port_bit)
110 int port = (port_bit >> 8) & 0xff;
111 int bit = port_bit & 0xff;
113 if (ddrs[port] == NULL)
114 return 0;
115 if (gpio_regs[port].used & bit) {
116 return (gpio_regs[port].ddr & bit) != 0;
117 } else
118 return -1;
121 #if defined(CONFIG_PROC_FS)
122 static char *port_status(int portno)
124 static char result[10];
125 const static char io[2]={'I','O'};
126 char *rp;
127 int c;
128 unsigned char used,ddr;
130 used = gpio_regs[portno].used;
131 ddr = gpio_regs[portno].ddr;
132 result[8]='\0';
133 rp = result + 7;
134 for (c = 8; c > 0; c--,rp--,used >>= 1, ddr >>= 1)
135 if (used & 0x01)
136 *rp = io[ ddr & 0x01];
137 else
138 *rp = '-';
139 return result;
142 static int gpio_proc_read(char *buf, char **start, off_t offset,
143 int len, int *unused_i, void *unused_v)
145 int c,outlen;
146 const static char port_name[]="123456789ABCDEFGH";
147 outlen = 0;
148 for (c = 0; c < MAX_PORT; c++) {
149 if (ddrs[c] == NULL)
150 continue ;
151 len = sprintf(buf,"P%c: %s\n",port_name[c],port_status(c));
152 buf += len;
153 outlen += len;
155 return outlen;
158 static __init int register_proc(void)
160 struct proc_dir_entry *proc_gpio;
162 proc_gpio = create_proc_entry("gpio", S_IRUGO, NULL);
163 if (proc_gpio)
164 proc_gpio->read_proc = gpio_proc_read;
165 return proc_gpio != NULL;
168 __initcall(register_proc);
169 #endif
171 void __init h8300_gpio_init(void)
173 memcpy(gpio_regs,_platform_gpio_table(sizeof(gpio_regs)),sizeof(gpio_regs));