Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 1 | #ifndef _ASM_ARCH_CRIS_IO_H |
| 2 | #define _ASM_ARCH_CRIS_IO_H |
| 3 | |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 4 | #include <linux/spinlock.h> |
| 5 | #include <hwregs/reg_map.h> |
| 6 | #include <hwregs/reg_rdwr.h> |
| 7 | #include <hwregs/gio_defs.h> |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 8 | |
| 9 | enum crisv32_io_dir |
| 10 | { |
| 11 | crisv32_io_dir_in = 0, |
| 12 | crisv32_io_dir_out = 1 |
| 13 | }; |
| 14 | |
| 15 | struct crisv32_ioport |
| 16 | { |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 17 | volatile unsigned long *oe; |
| 18 | volatile unsigned long *data; |
| 19 | volatile unsigned long *data_in; |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 20 | unsigned int pin_count; |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 21 | spinlock_t lock; |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 22 | }; |
| 23 | |
| 24 | struct crisv32_iopin |
| 25 | { |
| 26 | struct crisv32_ioport* port; |
| 27 | int bit; |
| 28 | }; |
| 29 | |
| 30 | extern struct crisv32_ioport crisv32_ioports[]; |
| 31 | |
| 32 | extern struct crisv32_iopin crisv32_led1_green; |
| 33 | extern struct crisv32_iopin crisv32_led1_red; |
| 34 | extern struct crisv32_iopin crisv32_led2_green; |
| 35 | extern struct crisv32_iopin crisv32_led2_red; |
| 36 | extern struct crisv32_iopin crisv32_led3_green; |
| 37 | extern struct crisv32_iopin crisv32_led3_red; |
| 38 | |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 39 | extern struct crisv32_iopin crisv32_led_net0_green; |
| 40 | extern struct crisv32_iopin crisv32_led_net0_red; |
| 41 | extern struct crisv32_iopin crisv32_led_net1_green; |
| 42 | extern struct crisv32_iopin crisv32_led_net1_red; |
| 43 | |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 44 | static inline void crisv32_io_set(struct crisv32_iopin *iopin, int val) |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 45 | { |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 46 | long flags; |
| 47 | spin_lock_irqsave(&iopin->port->lock, flags); |
| 48 | |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 49 | if (val) |
| 50 | *iopin->port->data |= iopin->bit; |
| 51 | else |
| 52 | *iopin->port->data &= ~iopin->bit; |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 53 | |
| 54 | spin_unlock_irqrestore(&iopin->port->lock, flags); |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 55 | } |
| 56 | |
Adrian Bunk | d9b5444 | 2005-11-07 00:58:44 -0800 | [diff] [blame] | 57 | static inline void crisv32_io_set_dir(struct crisv32_iopin* iopin, |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 58 | enum crisv32_io_dir dir) |
| 59 | { |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 60 | long flags; |
| 61 | spin_lock_irqsave(&iopin->port->lock, flags); |
| 62 | |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 63 | if (dir == crisv32_io_dir_in) |
| 64 | *iopin->port->oe &= ~iopin->bit; |
| 65 | else |
| 66 | *iopin->port->oe |= iopin->bit; |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 67 | |
| 68 | spin_unlock_irqrestore(&iopin->port->lock, flags); |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 69 | } |
| 70 | |
Adrian Bunk | d9b5444 | 2005-11-07 00:58:44 -0800 | [diff] [blame] | 71 | static inline int crisv32_io_rd(struct crisv32_iopin* iopin) |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 72 | { |
| 73 | return ((*iopin->port->data_in & iopin->bit) ? 1 : 0); |
| 74 | } |
| 75 | |
| 76 | int crisv32_io_get(struct crisv32_iopin* iopin, |
| 77 | unsigned int port, unsigned int pin); |
| 78 | int crisv32_io_get_name(struct crisv32_iopin* iopin, |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 79 | const char *name); |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 80 | |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 81 | #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 Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 85 | |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 86 | #if (defined(CONFIG_ETRAX_NBR_LED_GRP_ONE) || defined(CONFIG_ETRAX_NBR_LED_GRP_TWO)) |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 87 | #define CRIS_LED_NETWORK_GRP0_SET(x) \ |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 88 | do { \ |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 89 | CRIS_LED_NETWORK_GRP0_SET_G((x) & CRIS_LED_GREEN); \ |
| 90 | CRIS_LED_NETWORK_GRP0_SET_R((x) & CRIS_LED_RED); \ |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 91 | } while (0) |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 92 | #else |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 93 | #define CRIS_LED_NETWORK_GRP0_SET(x) while (0) {} |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 94 | #endif |
| 95 | |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 96 | #define CRIS_LED_NETWORK_GRP0_SET_G(x) \ |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 97 | crisv32_io_set(&crisv32_led_net0_green, !(x)); |
| 98 | |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 99 | #define CRIS_LED_NETWORK_GRP0_SET_R(x) \ |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 100 | crisv32_io_set(&crisv32_led_net0_red, !(x)); |
| 101 | |
| 102 | #if defined(CONFIG_ETRAX_NBR_LED_GRP_TWO) |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 103 | #define CRIS_LED_NETWORK_GRP1_SET(x) \ |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 104 | do { \ |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 105 | CRIS_LED_NETWORK_GRP1_SET_G((x) & CRIS_LED_GREEN); \ |
| 106 | CRIS_LED_NETWORK_GRP1_SET_R((x) & CRIS_LED_RED); \ |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 107 | } while (0) |
| 108 | #else |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 109 | #define CRIS_LED_NETWORK_GRP1_SET(x) while (0) {} |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 110 | #endif |
| 111 | |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 112 | #define CRIS_LED_NETWORK_GRP1_SET_G(x) \ |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 113 | crisv32_io_set(&crisv32_led_net1_green, !(x)); |
| 114 | |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 115 | #define CRIS_LED_NETWORK_GRP1_SET_R(x) \ |
Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame] | 116 | crisv32_io_set(&crisv32_led_net1_red, !(x)); |
| 117 | |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 118 | #define CRIS_LED_ACTIVE_SET(x) \ |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 119 | do { \ |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 120 | CRIS_LED_ACTIVE_SET_G((x) & CRIS_LED_GREEN); \ |
| 121 | CRIS_LED_ACTIVE_SET_R((x) & CRIS_LED_RED); \ |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 122 | } while (0) |
| 123 | |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 124 | #define CRIS_LED_ACTIVE_SET_G(x) \ |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 125 | crisv32_io_set(&crisv32_led2_green, !(x)); |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 126 | #define CRIS_LED_ACTIVE_SET_R(x) \ |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 127 | crisv32_io_set(&crisv32_led2_red, !(x)); |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 128 | #define CRIS_LED_DISK_WRITE(x) \ |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 129 | do{\ |
| 130 | crisv32_io_set(&crisv32_led3_green, !(x)); \ |
| 131 | crisv32_io_set(&crisv32_led3_red, !(x)); \ |
| 132 | }while(0) |
Jesper Nilsson | 0d9f2e6 | 2008-01-28 16:49:39 +0100 | [diff] [blame] | 133 | #define CRIS_LED_DISK_READ(x) \ |
Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 134 | crisv32_io_set(&crisv32_led3_green, !(x)); |
| 135 | |
| 136 | #endif |