aboutsummaryrefslogtreecommitdiffstats
path: root/arch/cris/arch-v32/kernel/io.c
diff options
context:
space:
mode:
Diffstat (limited to 'arch/cris/arch-v32/kernel/io.c')
-rw-r--r--arch/cris/arch-v32/kernel/io.c154
1 files changed, 154 insertions, 0 deletions
diff --git a/arch/cris/arch-v32/kernel/io.c b/arch/cris/arch-v32/kernel/io.c
new file mode 100644
index 000000000000..6bc9f263c3d6
--- /dev/null
+++ b/arch/cris/arch-v32/kernel/io.c
@@ -0,0 +1,154 @@
1/*
2 * Helper functions for I/O pins.
3 *
4 * Copyright (c) 2004 Axis Communications AB.
5 */
6
7#include <linux/config.h>
8#include <linux/types.h>
9#include <linux/errno.h>
10#include <linux/init.h>
11#include <linux/string.h>
12#include <linux/ctype.h>
13#include <linux/kernel.h>
14#include <linux/module.h>
15#include <asm/io.h>
16#include <asm/arch/pinmux.h>
17#include <asm/arch/hwregs/gio_defs.h>
18
19struct crisv32_ioport crisv32_ioports[] =
20{
21 {
22 (unsigned long*)REG_ADDR(gio, regi_gio, rw_pa_oe),
23 (unsigned long*)REG_ADDR(gio, regi_gio, rw_pa_dout),
24 (unsigned long*)REG_ADDR(gio, regi_gio, r_pa_din),
25 8
26 },
27 {
28 (unsigned long*)REG_ADDR(gio, regi_gio, rw_pb_oe),
29 (unsigned long*)REG_ADDR(gio, regi_gio, rw_pb_dout),
30 (unsigned long*)REG_ADDR(gio, regi_gio, r_pb_din),
31 18
32 },
33 {
34 (unsigned long*)REG_ADDR(gio, regi_gio, rw_pc_oe),
35 (unsigned long*)REG_ADDR(gio, regi_gio, rw_pc_dout),
36 (unsigned long*)REG_ADDR(gio, regi_gio, r_pc_din),
37 18
38 },
39 {
40 (unsigned long*)REG_ADDR(gio, regi_gio, rw_pd_oe),
41 (unsigned long*)REG_ADDR(gio, regi_gio, rw_pd_dout),
42 (unsigned long*)REG_ADDR(gio, regi_gio, r_pd_din),
43 18
44 },
45 {
46 (unsigned long*)REG_ADDR(gio, regi_gio, rw_pe_oe),
47 (unsigned long*)REG_ADDR(gio, regi_gio, rw_pe_dout),
48 (unsigned long*)REG_ADDR(gio, regi_gio, r_pe_din),
49 18
50 }
51};
52
53#define NBR_OF_PORTS sizeof(crisv32_ioports)/sizeof(struct crisv32_ioport)
54
55struct crisv32_iopin crisv32_led1_green;
56struct crisv32_iopin crisv32_led1_red;
57struct crisv32_iopin crisv32_led2_green;
58struct crisv32_iopin crisv32_led2_red;
59struct crisv32_iopin crisv32_led3_green;
60struct crisv32_iopin crisv32_led3_red;
61
62/* Dummy port used when green LED and red LED is on the same bit */
63static unsigned long io_dummy;
64static struct crisv32_ioport dummy_port =
65{
66 &io_dummy,
67 &io_dummy,
68 &io_dummy,
69 18
70};
71static struct crisv32_iopin dummy_led =
72{
73 &dummy_port,
74 0
75};
76
77static int __init crisv32_io_init(void)
78{
79 int ret = 0;
80 /* Initialize LEDs */
81 ret += crisv32_io_get_name(&crisv32_led1_green, CONFIG_ETRAX_LED1G);
82 ret += crisv32_io_get_name(&crisv32_led1_red, CONFIG_ETRAX_LED1R);
83 ret += crisv32_io_get_name(&crisv32_led2_green, CONFIG_ETRAX_LED2G);
84 ret += crisv32_io_get_name(&crisv32_led2_red, CONFIG_ETRAX_LED2R);
85 ret += crisv32_io_get_name(&crisv32_led3_green, CONFIG_ETRAX_LED3G);
86 ret += crisv32_io_get_name(&crisv32_led3_red, CONFIG_ETRAX_LED3R);
87 crisv32_io_set_dir(&crisv32_led1_green, crisv32_io_dir_out);
88 crisv32_io_set_dir(&crisv32_led1_red, crisv32_io_dir_out);
89 crisv32_io_set_dir(&crisv32_led2_green, crisv32_io_dir_out);
90 crisv32_io_set_dir(&crisv32_led2_red, crisv32_io_dir_out);
91 crisv32_io_set_dir(&crisv32_led3_green, crisv32_io_dir_out);
92 crisv32_io_set_dir(&crisv32_led3_red, crisv32_io_dir_out);
93
94 if (!strcmp(CONFIG_ETRAX_LED1G, CONFIG_ETRAX_LED1R))
95 crisv32_led1_red = dummy_led;
96 if (!strcmp(CONFIG_ETRAX_LED2G, CONFIG_ETRAX_LED2R))
97 crisv32_led2_red = dummy_led;
98
99 return ret;
100}
101
102__initcall(crisv32_io_init);
103
104int crisv32_io_get(struct crisv32_iopin* iopin,
105 unsigned int port, unsigned int pin)
106{
107 if (port > NBR_OF_PORTS)
108 return -EINVAL;
109 if (port > crisv32_ioports[port].pin_count)
110 return -EINVAL;
111
112 iopin->bit = 1 << pin;
113 iopin->port = &crisv32_ioports[port];
114
115 if (crisv32_pinmux_alloc(port, pin, pin, pinmux_gpio))
116 return -EIO;
117
118 return 0;
119}
120
121int crisv32_io_get_name(struct crisv32_iopin* iopin,
122 char* name)
123{
124 int port;
125 int pin;
126
127 if (toupper(*name) == 'P')
128 name++;
129
130 if (toupper(*name) < 'A' || toupper(*name) > 'E')
131 return -EINVAL;
132
133 port = toupper(*name) - 'A';
134 name++;
135 pin = simple_strtoul(name, NULL, 10);
136
137 if (pin < 0 || pin > crisv32_ioports[port].pin_count)
138 return -EINVAL;
139
140 iopin->bit = 1 << pin;
141 iopin->port = &crisv32_ioports[port];
142
143 if (crisv32_pinmux_alloc(port, pin, pin, pinmux_gpio))
144 return -EIO;
145
146 return 0;
147}
148
149#ifdef CONFIG_PCI
150/* PCI I/O access stuff */
151struct cris_io_operations* cris_iops = NULL;
152EXPORT_SYMBOL(cris_iops);
153#endif
154