2 * linux/arch/h8300/kernel/gpio.c
4 * Yoshinori Sato <ysato@users.sourceforge.jp>
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>
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
),
30 #if defined(CONFIG_H83002) || defined(CONFIG_H8048)
32 #include <asm/regs306x.h>
33 static volatile unsigned char *ddrs
[] = {
34 _(P1DDR
),_(P2DDR
),_(P3DDR
),_(P4DDR
),_(P5DDR
),_(P6DDR
),
35 NULL
, _(P8DDR
),_(P9DDR
),_(PADDR
),_(PBDDR
),
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
),
54 #error Unsuppoted CPU Selection
60 } gpio_regs
[MAX_PORT
];
62 extern char *_platform_gpio_table(int length
);
64 int h8300_reserved_gpio(int port
, unsigned int bits
)
68 if (port
< 0 || port
>= MAX_PORT
)
70 used
= &(gpio_regs
[port
].used
);
71 if ((*used
& bits
) != 0)
77 int h8300_free_gpio(int port
, unsigned int bits
)
81 if (port
< 0 || port
>= MAX_PORT
)
83 used
= &(gpio_regs
[port
].used
);
84 if ((*used
& bits
) != bits
)
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
)
97 if (gpio_regs
[port
].used
& bit
) {
99 gpio_regs
[port
].ddr
|= bit
;
101 gpio_regs
[port
].ddr
&= ~bit
;
102 *ddrs
[port
] = gpio_regs
[port
].ddr
;
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
)
115 if (gpio_regs
[port
].used
& bit
) {
116 return (gpio_regs
[port
].ddr
& bit
) != 0;
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'};
128 unsigned char used
,ddr
;
130 used
= gpio_regs
[portno
].used
;
131 ddr
= gpio_regs
[portno
].ddr
;
134 for (c
= 8; c
> 0; c
--,rp
--,used
>>= 1, ddr
>>= 1)
136 *rp
= io
[ ddr
& 0x01];
142 static int gpio_proc_read(char *buf
, char **start
, off_t offset
,
143 int len
, int *unused_i
, void *unused_v
)
146 const static char port_name
[]="123456789ABCDEFGH";
148 for (c
= 0; c
< MAX_PORT
; c
++) {
151 len
= sprintf(buf
,"P%c: %s\n",port_name
[c
],port_status(c
));
158 static __init
int register_proc(void)
160 struct proc_dir_entry
*proc_gpio
;
162 proc_gpio
= create_proc_entry("gpio", S_IRUGO
, NULL
);
164 proc_gpio
->read_proc
= gpio_proc_read
;
165 return proc_gpio
!= NULL
;
168 __initcall(register_proc
);
171 void __init
h8300_gpio_init(void)
173 memcpy(gpio_regs
,_platform_gpio_table(sizeof(gpio_regs
)),sizeof(gpio_regs
));