2 * Helper functions for I/O pins.
4 * Copyright (c) 2004 Axis Communications AB.
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>
16 #include <asm/arch/pinmux.h>
17 #include <asm/arch/hwregs/gio_defs.h>
19 struct crisv32_ioport crisv32_ioports[] =
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),
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),
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),
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),
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),
53 #define NBR_OF_PORTS sizeof(crisv32_ioports)/sizeof(struct crisv32_ioport)
55 struct crisv32_iopin crisv32_led1_green;
56 struct crisv32_iopin crisv32_led1_red;
57 struct crisv32_iopin crisv32_led2_green;
58 struct crisv32_iopin crisv32_led2_red;
59 struct crisv32_iopin crisv32_led3_green;
60 struct crisv32_iopin crisv32_led3_red;
62 /* Dummy port used when green LED and red LED is on the same bit */
63 static unsigned long io_dummy;
64 static struct crisv32_ioport dummy_port =
71 static struct crisv32_iopin dummy_led =
77 static int __init crisv32_io_init(void)
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);
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;
102 __initcall(crisv32_io_init);
104 int crisv32_io_get(struct crisv32_iopin* iopin,
105 unsigned int port, unsigned int pin)
107 if (port > NBR_OF_PORTS)
109 if (port > crisv32_ioports[port].pin_count)
112 iopin->bit = 1 << pin;
113 iopin->port = &crisv32_ioports[port];
115 if (crisv32_pinmux_alloc(port, pin, pin, pinmux_gpio))
121 int crisv32_io_get_name(struct crisv32_iopin* iopin,
127 if (toupper(*name) == 'P')
130 if (toupper(*name) < 'A' || toupper(*name) > 'E')
133 port = toupper(*name) - 'A';
135 pin = simple_strtoul(name, NULL, 10);
137 if (pin < 0 || pin > crisv32_ioports[port].pin_count)
140 iopin->bit = 1 << pin;
141 iopin->port = &crisv32_ioports[port];
143 if (crisv32_pinmux_alloc(port, pin, pin, pinmux_gpio))
150 /* PCI I/O access stuff */
151 struct cris_io_operations* cris_iops = NULL;
152 EXPORT_SYMBOL(cris_iops);