2 * linux/arch/h8300/kernel/gpio.c
4 * Yoshinori Sato <ysato@users.sourceforge.jp>
9 * Internal I/O Port Management
12 #include <linux/stddef.h>
13 #include <linux/proc_fs.h>
14 #include <linux/kernel.h>
15 #include <linux/string.h>
17 #include <linux/init.h>
19 #define _(addr) (volatile unsigned char *)(addr)
20 #if defined(CONFIG_H83007) || defined(CONFIG_H83068)
21 #include <asm/regs306x.h>
22 static volatile unsigned char *ddrs
[] = {
23 _(P1DDR
),_(P2DDR
),_(P3DDR
),_(P4DDR
),_(P5DDR
),_(P6DDR
),
24 NULL
, _(P8DDR
),_(P9DDR
),_(PADDR
),_(PBDDR
),
29 #if defined(CONFIG_H83002) || defined(CONFIG_H8048)
31 #include <asm/regs306x.h>
32 static volatile unsigned char *ddrs
[] = {
33 _(P1DDR
),_(P2DDR
),_(P3DDR
),_(P4DDR
),_(P5DDR
),_(P6DDR
),
34 NULL
, _(P8DDR
),_(P9DDR
),_(PADDR
),_(PBDDR
),
39 #if defined(CONFIG_H8S2678)
40 #include <asm/regs267x.h>
41 static volatile unsigned char *ddrs
[] = {
42 _(P1DDR
),_(P2DDR
),_(P3DDR
),NULL
,_(P5DDR
),_(P6DDR
),
43 _(P7DDR
),_(P8DDR
),NULL
, _(PADDR
),_(PBDDR
),_(PCDDR
),
44 _(PDDDR
),_(PEDDR
),_(PFDDR
),_(PGDDR
),_(PHDDR
),
45 _(PADDR
),_(PBDDR
),_(PCDDR
),_(PDDDR
),_(PEDDR
),_(PFDDR
),
53 #error Unsuppoted CPU Selection
59 } gpio_regs
[MAX_PORT
];
61 extern char *_platform_gpio_table(int length
);
63 int h8300_reserved_gpio(int port
, unsigned int bits
)
67 if (port
< 0 || port
>= MAX_PORT
)
69 used
= &(gpio_regs
[port
].used
);
70 if ((*used
& bits
) != 0)
76 int h8300_free_gpio(int port
, unsigned int bits
)
80 if (port
< 0 || port
>= MAX_PORT
)
82 used
= &(gpio_regs
[port
].used
);
83 if ((*used
& bits
) != bits
)
89 int h8300_set_gpio_dir(int port_bit
,int dir
)
91 int port
= (port_bit
>> 8) & 0xff;
92 int bit
= port_bit
& 0xff;
94 if (ddrs
[port
] == NULL
)
96 if (gpio_regs
[port
].used
& bit
) {
98 gpio_regs
[port
].ddr
|= bit
;
100 gpio_regs
[port
].ddr
&= ~bit
;
101 *ddrs
[port
] = gpio_regs
[port
].ddr
;
107 int h8300_get_gpio_dir(int port_bit
)
109 int port
= (port_bit
>> 8) & 0xff;
110 int bit
= port_bit
& 0xff;
112 if (ddrs
[port
] == NULL
)
114 if (gpio_regs
[port
].used
& bit
) {
115 return (gpio_regs
[port
].ddr
& bit
) != 0;
120 #if defined(CONFIG_PROC_FS)
121 static char *port_status(int portno
)
123 static char result
[10];
124 static const char io
[2]={'I','O'};
127 unsigned char used
,ddr
;
129 used
= gpio_regs
[portno
].used
;
130 ddr
= gpio_regs
[portno
].ddr
;
133 for (c
= 8; c
> 0; c
--,rp
--,used
>>= 1, ddr
>>= 1)
135 *rp
= io
[ ddr
& 0x01];
141 static int gpio_proc_read(char *buf
, char **start
, off_t offset
,
142 int len
, int *unused_i
, void *unused_v
)
145 static const char port_name
[]="123456789ABCDEFGH";
147 for (c
= 0; c
< MAX_PORT
; c
++) {
150 len
= sprintf(buf
,"P%c: %s\n",port_name
[c
],port_status(c
));
157 static __init
int register_proc(void)
159 struct proc_dir_entry
*proc_gpio
;
161 proc_gpio
= create_proc_entry("gpio", S_IRUGO
, NULL
);
163 proc_gpio
->read_proc
= gpio_proc_read
;
164 return proc_gpio
!= NULL
;
167 __initcall(register_proc
);
170 void __init
h8300_gpio_init(void)
172 memcpy(gpio_regs
,_platform_gpio_table(sizeof(gpio_regs
)),sizeof(gpio_regs
));