Prefetch inodes in readdir
[pohmelfs.git] / arch / cris / arch-v32 / mach-fs / io.c
bloba6958661fa8e0bbd1b2fde30d3c6de8764a404ed
1 /*
2 * Helper functions for I/O pins.
4 * Copyright (c) 2004-2007 Axis Communications AB.
5 */
7 #include <linux/types.h>
8 #include <linux/errno.h>
9 #include <linux/init.h>
10 #include <linux/string.h>
11 #include <linux/ctype.h>
12 #include <linux/kernel.h>
13 #include <linux/module.h>
14 #include <asm/io.h>
15 #include <mach/pinmux.h>
16 #include <hwregs/gio_defs.h>
18 #ifndef DEBUG
19 #define DEBUG(x)
20 #endif
22 struct crisv32_ioport crisv32_ioports[] = {
24 (unsigned long *)REG_ADDR(gio, regi_gio, rw_pa_oe),
25 (unsigned long *)REG_ADDR(gio, regi_gio, rw_pa_dout),
26 (unsigned long *)REG_ADDR(gio, regi_gio, r_pa_din),
30 (unsigned long *)REG_ADDR(gio, regi_gio, rw_pb_oe),
31 (unsigned long *)REG_ADDR(gio, regi_gio, rw_pb_dout),
32 (unsigned long *)REG_ADDR(gio, regi_gio, r_pb_din),
36 (unsigned long *)REG_ADDR(gio, regi_gio, rw_pc_oe),
37 (unsigned long *)REG_ADDR(gio, regi_gio, rw_pc_dout),
38 (unsigned long *)REG_ADDR(gio, regi_gio, r_pc_din),
42 (unsigned long *)REG_ADDR(gio, regi_gio, rw_pd_oe),
43 (unsigned long *)REG_ADDR(gio, regi_gio, rw_pd_dout),
44 (unsigned long *)REG_ADDR(gio, regi_gio, r_pd_din),
48 (unsigned long *)REG_ADDR(gio, regi_gio, rw_pe_oe),
49 (unsigned long *)REG_ADDR(gio, regi_gio, rw_pe_dout),
50 (unsigned long *)REG_ADDR(gio, regi_gio, r_pe_din),
55 #define NBR_OF_PORTS ARRAY_SIZE(crisv32_ioports)
57 struct crisv32_iopin crisv32_led_net0_green;
58 struct crisv32_iopin crisv32_led_net0_red;
59 struct crisv32_iopin crisv32_led_net1_green;
60 struct crisv32_iopin crisv32_led_net1_red;
61 struct crisv32_iopin crisv32_led2_green;
62 struct crisv32_iopin crisv32_led2_red;
63 struct crisv32_iopin crisv32_led3_green;
64 struct crisv32_iopin crisv32_led3_red;
66 /* Dummy port used when green LED and red LED is on the same bit */
67 static unsigned long io_dummy;
68 static struct crisv32_ioport dummy_port = {
69 &io_dummy,
70 &io_dummy,
71 &io_dummy,
74 static struct crisv32_iopin dummy_led = {
75 &dummy_port,
79 static int __init crisv32_io_init(void)
81 int ret = 0;
83 u32 i;
85 /* Locks *should* be dynamically initialized. */
86 for (i = 0; i < ARRAY_SIZE(crisv32_ioports); i++)
87 spin_lock_init(&crisv32_ioports[i].lock);
88 spin_lock_init(&dummy_port.lock);
90 /* Initialize LEDs */
91 #if (defined(CONFIG_ETRAX_NBR_LED_GRP_ONE) || defined(CONFIG_ETRAX_NBR_LED_GRP_TWO))
92 ret +=
93 crisv32_io_get_name(&crisv32_led_net0_green,
94 CONFIG_ETRAX_LED_G_NET0);
95 crisv32_io_set_dir(&crisv32_led_net0_green, crisv32_io_dir_out);
96 if (strcmp(CONFIG_ETRAX_LED_G_NET0, CONFIG_ETRAX_LED_R_NET0)) {
97 ret +=
98 crisv32_io_get_name(&crisv32_led_net0_red,
99 CONFIG_ETRAX_LED_R_NET0);
100 crisv32_io_set_dir(&crisv32_led_net0_red, crisv32_io_dir_out);
101 } else
102 crisv32_led_net0_red = dummy_led;
103 #endif
105 #ifdef CONFIG_ETRAX_NBR_LED_GRP_TWO
106 ret +=
107 crisv32_io_get_name(&crisv32_led_net1_green,
108 CONFIG_ETRAX_LED_G_NET1);
109 crisv32_io_set_dir(&crisv32_led_net1_green, crisv32_io_dir_out);
110 if (strcmp(CONFIG_ETRAX_LED_G_NET1, CONFIG_ETRAX_LED_R_NET1)) {
111 crisv32_io_get_name(&crisv32_led_net1_red,
112 CONFIG_ETRAX_LED_R_NET1);
113 crisv32_io_set_dir(&crisv32_led_net1_red, crisv32_io_dir_out);
114 } else
115 crisv32_led_net1_red = dummy_led;
116 #endif
118 ret += crisv32_io_get_name(&crisv32_led2_green, CONFIG_ETRAX_V32_LED2G);
119 ret += crisv32_io_get_name(&crisv32_led2_red, CONFIG_ETRAX_V32_LED2R);
120 ret += crisv32_io_get_name(&crisv32_led3_green, CONFIG_ETRAX_V32_LED3G);
121 ret += crisv32_io_get_name(&crisv32_led3_red, CONFIG_ETRAX_V32_LED3R);
123 crisv32_io_set_dir(&crisv32_led2_green, crisv32_io_dir_out);
124 crisv32_io_set_dir(&crisv32_led2_red, crisv32_io_dir_out);
125 crisv32_io_set_dir(&crisv32_led3_green, crisv32_io_dir_out);
126 crisv32_io_set_dir(&crisv32_led3_red, crisv32_io_dir_out);
128 return ret;
131 __initcall(crisv32_io_init);
133 int crisv32_io_get(struct crisv32_iopin *iopin,
134 unsigned int port, unsigned int pin)
136 if (port > NBR_OF_PORTS)
137 return -EINVAL;
138 if (port > crisv32_ioports[port].pin_count)
139 return -EINVAL;
141 iopin->bit = 1 << pin;
142 iopin->port = &crisv32_ioports[port];
144 /* Only allocate pinmux gpiopins if port != PORT_A (port 0) */
145 /* NOTE! crisv32_pinmux_alloc thinks PORT_B is port 0 */
146 if (port != 0 && crisv32_pinmux_alloc(port - 1, pin, pin, pinmux_gpio))
147 return -EIO;
148 DEBUG(printk(KERN_DEBUG "crisv32_io_get: Allocated pin %d on port %d\n",
149 pin, port));
151 return 0;
154 int crisv32_io_get_name(struct crisv32_iopin *iopin, const char *name)
156 int port;
157 int pin;
159 if (toupper(*name) == 'P')
160 name++;
162 if (toupper(*name) < 'A' || toupper(*name) > 'E')
163 return -EINVAL;
165 port = toupper(*name) - 'A';
166 name++;
167 pin = simple_strtoul(name, NULL, 10);
169 if (pin < 0 || pin > crisv32_ioports[port].pin_count)
170 return -EINVAL;
172 iopin->bit = 1 << pin;
173 iopin->port = &crisv32_ioports[port];
175 /* Only allocate pinmux gpiopins if port != PORT_A (port 0) */
176 /* NOTE! crisv32_pinmux_alloc thinks PORT_B is port 0 */
177 if (port != 0 && crisv32_pinmux_alloc(port - 1, pin, pin, pinmux_gpio))
178 return -EIO;
180 DEBUG(printk(KERN_DEBUG
181 "crisv32_io_get_name: Allocated pin %d on port %d\n",
182 pin, port));
184 return 0;
187 #ifdef CONFIG_PCI
188 /* PCI I/O access stuff */
189 struct cris_io_operations *cris_iops = NULL;
190 EXPORT_SYMBOL(cris_iops);
191 #endif