blob: 6b38912f29ba4460b3458fe376720c9a62bf911f [file] [log] [blame]
Mikael Starvik51533b62005-07-27 11:44:44 -07001#ifndef _ASM_ARCH_CRIS_IO_H
2#define _ASM_ARCH_CRIS_IO_H
3
Jesper Nilssond8ca6b12007-12-03 11:16:25 +01004#include <linux/spinlock.h>
5#include <hwregs/reg_map.h>
6#include <hwregs/reg_rdwr.h>
7#include <hwregs/gio_defs.h>
Mikael Starvik51533b62005-07-27 11:44:44 -07008
9enum crisv32_io_dir
10{
11 crisv32_io_dir_in = 0,
12 crisv32_io_dir_out = 1
13};
14
15struct crisv32_ioport
16{
Jesper Nilssond8ca6b12007-12-03 11:16:25 +010017 volatile unsigned long *oe;
18 volatile unsigned long *data;
19 volatile unsigned long *data_in;
Mikael Starvik51533b62005-07-27 11:44:44 -070020 unsigned int pin_count;
Jesper Nilssond8ca6b12007-12-03 11:16:25 +010021 spinlock_t lock;
Mikael Starvik51533b62005-07-27 11:44:44 -070022};
23
24struct crisv32_iopin
25{
26 struct crisv32_ioport* port;
27 int bit;
28};
29
30extern struct crisv32_ioport crisv32_ioports[];
31
32extern struct crisv32_iopin crisv32_led1_green;
33extern struct crisv32_iopin crisv32_led1_red;
34extern struct crisv32_iopin crisv32_led2_green;
35extern struct crisv32_iopin crisv32_led2_red;
36extern struct crisv32_iopin crisv32_led3_green;
37extern struct crisv32_iopin crisv32_led3_red;
38
Jesper Nilssond8ca6b12007-12-03 11:16:25 +010039extern struct crisv32_iopin crisv32_led_net0_green;
40extern struct crisv32_iopin crisv32_led_net0_red;
41extern struct crisv32_iopin crisv32_led_net1_green;
42extern struct crisv32_iopin crisv32_led_net1_red;
43
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +010044static inline void crisv32_io_set(struct crisv32_iopin *iopin, int val)
Mikael Starvik51533b62005-07-27 11:44:44 -070045{
Jesper Nilssond8ca6b12007-12-03 11:16:25 +010046 long flags;
47 spin_lock_irqsave(&iopin->port->lock, flags);
48
Mikael Starvik51533b62005-07-27 11:44:44 -070049 if (val)
50 *iopin->port->data |= iopin->bit;
51 else
52 *iopin->port->data &= ~iopin->bit;
Jesper Nilssond8ca6b12007-12-03 11:16:25 +010053
54 spin_unlock_irqrestore(&iopin->port->lock, flags);
Mikael Starvik51533b62005-07-27 11:44:44 -070055}
56
Adrian Bunkd9b54442005-11-07 00:58:44 -080057static inline void crisv32_io_set_dir(struct crisv32_iopin* iopin,
Mikael Starvik51533b62005-07-27 11:44:44 -070058 enum crisv32_io_dir dir)
59{
Jesper Nilssond8ca6b12007-12-03 11:16:25 +010060 long flags;
61 spin_lock_irqsave(&iopin->port->lock, flags);
62
Mikael Starvik51533b62005-07-27 11:44:44 -070063 if (dir == crisv32_io_dir_in)
64 *iopin->port->oe &= ~iopin->bit;
65 else
66 *iopin->port->oe |= iopin->bit;
Jesper Nilssond8ca6b12007-12-03 11:16:25 +010067
68 spin_unlock_irqrestore(&iopin->port->lock, flags);
Mikael Starvik51533b62005-07-27 11:44:44 -070069}
70
Adrian Bunkd9b54442005-11-07 00:58:44 -080071static inline int crisv32_io_rd(struct crisv32_iopin* iopin)
Mikael Starvik51533b62005-07-27 11:44:44 -070072{
73 return ((*iopin->port->data_in & iopin->bit) ? 1 : 0);
74}
75
76int crisv32_io_get(struct crisv32_iopin* iopin,
77 unsigned int port, unsigned int pin);
78int crisv32_io_get_name(struct crisv32_iopin* iopin,
Jesper Nilssond8ca6b12007-12-03 11:16:25 +010079 const char *name);
Mikael Starvik51533b62005-07-27 11:44:44 -070080
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +010081#define CRIS_LED_OFF 0x00
82#define CRIS_LED_GREEN 0x01
83#define CRIS_LED_RED 0x02
84#define CRIS_LED_ORANGE (CRIS_LED_GREEN | CRIS_LED_RED)
Mikael Starvik51533b62005-07-27 11:44:44 -070085
Jesper Nilssond8ca6b12007-12-03 11:16:25 +010086#if (defined(CONFIG_ETRAX_NBR_LED_GRP_ONE) || defined(CONFIG_ETRAX_NBR_LED_GRP_TWO))
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +010087#define CRIS_LED_NETWORK_GRP0_SET(x) \
Jesper Nilssond8ca6b12007-12-03 11:16:25 +010088 do { \
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +010089 CRIS_LED_NETWORK_GRP0_SET_G((x) & CRIS_LED_GREEN); \
90 CRIS_LED_NETWORK_GRP0_SET_R((x) & CRIS_LED_RED); \
Mikael Starvik51533b62005-07-27 11:44:44 -070091 } while (0)
Jesper Nilssond8ca6b12007-12-03 11:16:25 +010092#else
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +010093#define CRIS_LED_NETWORK_GRP0_SET(x) while (0) {}
Jesper Nilssond8ca6b12007-12-03 11:16:25 +010094#endif
95
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +010096#define CRIS_LED_NETWORK_GRP0_SET_G(x) \
Jesper Nilssond8ca6b12007-12-03 11:16:25 +010097 crisv32_io_set(&crisv32_led_net0_green, !(x));
98
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +010099#define CRIS_LED_NETWORK_GRP0_SET_R(x) \
Jesper Nilssond8ca6b12007-12-03 11:16:25 +0100100 crisv32_io_set(&crisv32_led_net0_red, !(x));
101
102#if defined(CONFIG_ETRAX_NBR_LED_GRP_TWO)
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +0100103#define CRIS_LED_NETWORK_GRP1_SET(x) \
Jesper Nilssond8ca6b12007-12-03 11:16:25 +0100104 do { \
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +0100105 CRIS_LED_NETWORK_GRP1_SET_G((x) & CRIS_LED_GREEN); \
106 CRIS_LED_NETWORK_GRP1_SET_R((x) & CRIS_LED_RED); \
Jesper Nilssond8ca6b12007-12-03 11:16:25 +0100107 } while (0)
108#else
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +0100109#define CRIS_LED_NETWORK_GRP1_SET(x) while (0) {}
Jesper Nilssond8ca6b12007-12-03 11:16:25 +0100110#endif
111
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +0100112#define CRIS_LED_NETWORK_GRP1_SET_G(x) \
Jesper Nilssond8ca6b12007-12-03 11:16:25 +0100113 crisv32_io_set(&crisv32_led_net1_green, !(x));
114
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +0100115#define CRIS_LED_NETWORK_GRP1_SET_R(x) \
Jesper Nilssond8ca6b12007-12-03 11:16:25 +0100116 crisv32_io_set(&crisv32_led_net1_red, !(x));
117
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +0100118#define CRIS_LED_ACTIVE_SET(x) \
Mikael Starvik51533b62005-07-27 11:44:44 -0700119 do { \
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +0100120 CRIS_LED_ACTIVE_SET_G((x) & CRIS_LED_GREEN); \
121 CRIS_LED_ACTIVE_SET_R((x) & CRIS_LED_RED); \
Mikael Starvik51533b62005-07-27 11:44:44 -0700122 } while (0)
123
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +0100124#define CRIS_LED_ACTIVE_SET_G(x) \
Mikael Starvik51533b62005-07-27 11:44:44 -0700125 crisv32_io_set(&crisv32_led2_green, !(x));
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +0100126#define CRIS_LED_ACTIVE_SET_R(x) \
Mikael Starvik51533b62005-07-27 11:44:44 -0700127 crisv32_io_set(&crisv32_led2_red, !(x));
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +0100128#define CRIS_LED_DISK_WRITE(x) \
Mikael Starvik51533b62005-07-27 11:44:44 -0700129 do{\
130 crisv32_io_set(&crisv32_led3_green, !(x)); \
131 crisv32_io_set(&crisv32_led3_red, !(x)); \
132 }while(0)
Jesper Nilsson0d9f2e62008-01-28 16:49:39 +0100133#define CRIS_LED_DISK_READ(x) \
Mikael Starvik51533b62005-07-27 11:44:44 -0700134 crisv32_io_set(&crisv32_led3_green, !(x));
135
136#endif