2 * Helper functions for I/O pins.
4 * Copyright (c) 2004 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 <asm/arch/pinmux.h>
16 #include <asm/arch/hwregs/gio_defs.h>
18 struct crisv32_ioport crisv32_ioports
[] =
21 (unsigned long*)REG_ADDR(gio
, regi_gio
, rw_pa_oe
),
22 (unsigned long*)REG_ADDR(gio
, regi_gio
, rw_pa_dout
),
23 (unsigned long*)REG_ADDR(gio
, regi_gio
, r_pa_din
),
27 (unsigned long*)REG_ADDR(gio
, regi_gio
, rw_pb_oe
),
28 (unsigned long*)REG_ADDR(gio
, regi_gio
, rw_pb_dout
),
29 (unsigned long*)REG_ADDR(gio
, regi_gio
, r_pb_din
),
33 (unsigned long*)REG_ADDR(gio
, regi_gio
, rw_pc_oe
),
34 (unsigned long*)REG_ADDR(gio
, regi_gio
, rw_pc_dout
),
35 (unsigned long*)REG_ADDR(gio
, regi_gio
, r_pc_din
),
39 (unsigned long*)REG_ADDR(gio
, regi_gio
, rw_pd_oe
),
40 (unsigned long*)REG_ADDR(gio
, regi_gio
, rw_pd_dout
),
41 (unsigned long*)REG_ADDR(gio
, regi_gio
, r_pd_din
),
45 (unsigned long*)REG_ADDR(gio
, regi_gio
, rw_pe_oe
),
46 (unsigned long*)REG_ADDR(gio
, regi_gio
, rw_pe_dout
),
47 (unsigned long*)REG_ADDR(gio
, regi_gio
, r_pe_din
),
52 #define NBR_OF_PORTS sizeof(crisv32_ioports)/sizeof(struct crisv32_ioport)
54 struct crisv32_iopin crisv32_led1_green
;
55 struct crisv32_iopin crisv32_led1_red
;
56 struct crisv32_iopin crisv32_led2_green
;
57 struct crisv32_iopin crisv32_led2_red
;
58 struct crisv32_iopin crisv32_led3_green
;
59 struct crisv32_iopin crisv32_led3_red
;
61 /* Dummy port used when green LED and red LED is on the same bit */
62 static unsigned long io_dummy
;
63 static struct crisv32_ioport dummy_port
=
70 static struct crisv32_iopin dummy_led
=
76 static int __init
crisv32_io_init(void)
80 ret
+= crisv32_io_get_name(&crisv32_led1_green
, CONFIG_ETRAX_LED1G
);
81 ret
+= crisv32_io_get_name(&crisv32_led1_red
, CONFIG_ETRAX_LED1R
);
82 ret
+= crisv32_io_get_name(&crisv32_led2_green
, CONFIG_ETRAX_LED2G
);
83 ret
+= crisv32_io_get_name(&crisv32_led2_red
, CONFIG_ETRAX_LED2R
);
84 ret
+= crisv32_io_get_name(&crisv32_led3_green
, CONFIG_ETRAX_LED3G
);
85 ret
+= crisv32_io_get_name(&crisv32_led3_red
, CONFIG_ETRAX_LED3R
);
86 crisv32_io_set_dir(&crisv32_led1_green
, crisv32_io_dir_out
);
87 crisv32_io_set_dir(&crisv32_led1_red
, crisv32_io_dir_out
);
88 crisv32_io_set_dir(&crisv32_led2_green
, crisv32_io_dir_out
);
89 crisv32_io_set_dir(&crisv32_led2_red
, crisv32_io_dir_out
);
90 crisv32_io_set_dir(&crisv32_led3_green
, crisv32_io_dir_out
);
91 crisv32_io_set_dir(&crisv32_led3_red
, crisv32_io_dir_out
);
93 if (!strcmp(CONFIG_ETRAX_LED1G
, CONFIG_ETRAX_LED1R
))
94 crisv32_led1_red
= dummy_led
;
95 if (!strcmp(CONFIG_ETRAX_LED2G
, CONFIG_ETRAX_LED2R
))
96 crisv32_led2_red
= dummy_led
;
101 __initcall(crisv32_io_init
);
103 int crisv32_io_get(struct crisv32_iopin
* iopin
,
104 unsigned int port
, unsigned int pin
)
106 if (port
> NBR_OF_PORTS
)
108 if (port
> crisv32_ioports
[port
].pin_count
)
111 iopin
->bit
= 1 << pin
;
112 iopin
->port
= &crisv32_ioports
[port
];
114 if (crisv32_pinmux_alloc(port
, pin
, pin
, pinmux_gpio
))
120 int crisv32_io_get_name(struct crisv32_iopin
* iopin
,
126 if (toupper(*name
) == 'P')
129 if (toupper(*name
) < 'A' || toupper(*name
) > 'E')
132 port
= toupper(*name
) - 'A';
134 pin
= simple_strtoul(name
, NULL
, 10);
136 if (pin
< 0 || pin
> crisv32_ioports
[port
].pin_count
)
139 iopin
->bit
= 1 << pin
;
140 iopin
->port
= &crisv32_ioports
[port
];
142 if (crisv32_pinmux_alloc(port
, pin
, pin
, pinmux_gpio
))
149 /* PCI I/O access stuff */
150 struct cris_io_operations
* cris_iops
= NULL
;
151 EXPORT_SYMBOL(cris_iops
);