2 * Helper functions for I/O pins.
4 * Copyright (c) 2005-2007 Axis Communications AB.
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>
15 #include <mach/pinmux.h>
16 #include <hwregs/gio_defs.h>
18 struct crisv32_ioport crisv32_ioports
[] = {
20 (unsigned long *)REG_ADDR(gio
, regi_gio
, rw_pa_oe
),
21 (unsigned long *)REG_ADDR(gio
, regi_gio
, rw_pa_dout
),
22 (unsigned long *)REG_ADDR(gio
, regi_gio
, r_pa_din
),
26 (unsigned long *)REG_ADDR(gio
, regi_gio
, rw_pb_oe
),
27 (unsigned long *)REG_ADDR(gio
, regi_gio
, rw_pb_dout
),
28 (unsigned long *)REG_ADDR(gio
, regi_gio
, r_pb_din
),
32 (unsigned long *)REG_ADDR(gio
, regi_gio
, rw_pc_oe
),
33 (unsigned long *)REG_ADDR(gio
, regi_gio
, rw_pc_dout
),
34 (unsigned long *)REG_ADDR(gio
, regi_gio
, r_pc_din
),
39 #define NBR_OF_PORTS ARRAY_SIZE(crisv32_ioports)
41 struct crisv32_iopin crisv32_led_net0_green
;
42 struct crisv32_iopin crisv32_led_net0_red
;
43 struct crisv32_iopin crisv32_led2_green
;
44 struct crisv32_iopin crisv32_led2_red
;
45 struct crisv32_iopin crisv32_led3_green
;
46 struct crisv32_iopin crisv32_led3_red
;
48 /* Dummy port used when green LED and red LED is on the same bit */
49 static unsigned long io_dummy
;
50 static struct crisv32_ioport dummy_port
= {
56 static struct crisv32_iopin dummy_led
= {
61 static int __init
crisv32_io_init(void)
67 /* Locks *should* be dynamically initialized. */
68 for (i
= 0; i
< ARRAY_SIZE(crisv32_ioports
); i
++)
69 spin_lock_init(&crisv32_ioports
[i
].lock
);
70 spin_lock_init(&dummy_port
.lock
);
73 #if (defined(CONFIG_ETRAX_NBR_LED_GRP_ONE) || defined(CONFIG_ETRAX_NBR_LED_GRP_TWO))
74 ret
+= crisv32_io_get_name(&crisv32_led_net0_green
,
75 CONFIG_ETRAX_LED_G_NET0
);
76 crisv32_io_set_dir(&crisv32_led_net0_green
, crisv32_io_dir_out
);
77 if (strcmp(CONFIG_ETRAX_LED_G_NET0
, CONFIG_ETRAX_LED_R_NET0
)) {
78 ret
+= crisv32_io_get_name(&crisv32_led_net0_red
,
79 CONFIG_ETRAX_LED_R_NET0
);
80 crisv32_io_set_dir(&crisv32_led_net0_red
, crisv32_io_dir_out
);
82 crisv32_led_net0_red
= dummy_led
;
85 ret
+= crisv32_io_get_name(&crisv32_led2_green
, CONFIG_ETRAX_V32_LED2G
);
86 ret
+= crisv32_io_get_name(&crisv32_led2_red
, CONFIG_ETRAX_V32_LED2R
);
87 ret
+= crisv32_io_get_name(&crisv32_led3_green
, CONFIG_ETRAX_V32_LED3G
);
88 ret
+= crisv32_io_get_name(&crisv32_led3_red
, CONFIG_ETRAX_V32_LED3R
);
90 crisv32_io_set_dir(&crisv32_led2_green
, crisv32_io_dir_out
);
91 crisv32_io_set_dir(&crisv32_led2_red
, crisv32_io_dir_out
);
92 crisv32_io_set_dir(&crisv32_led3_green
, crisv32_io_dir_out
);
93 crisv32_io_set_dir(&crisv32_led3_red
, crisv32_io_dir_out
);
98 __initcall(crisv32_io_init
);
100 int crisv32_io_get(struct crisv32_iopin
*iopin
,
101 unsigned int port
, unsigned int pin
)
103 if (port
> NBR_OF_PORTS
)
105 if (port
> crisv32_ioports
[port
].pin_count
)
108 iopin
->bit
= 1 << pin
;
109 iopin
->port
= &crisv32_ioports
[port
];
111 if (crisv32_pinmux_alloc(port
, pin
, pin
, pinmux_gpio
))
117 int crisv32_io_get_name(struct crisv32_iopin
*iopin
, const char *name
)
122 if (toupper(*name
) == 'P')
125 if (toupper(*name
) < 'A' || toupper(*name
) > 'E')
128 port
= toupper(*name
) - 'A';
130 pin
= simple_strtoul(name
, NULL
, 10);
132 if (pin
< 0 || pin
> crisv32_ioports
[port
].pin_count
)
135 iopin
->bit
= 1 << pin
;
136 iopin
->port
= &crisv32_ioports
[port
];
138 if (crisv32_pinmux_alloc(port
, pin
, pin
, pinmux_gpio
))
145 /* PCI I/O access stuff */
146 struct cris_io_operations
*cris_iops
= NULL
;
147 EXPORT_SYMBOL(cris_iops
);