| 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 | |
| Adrian Bunk | d9b5444 | 2005-11-07 00:58:44 -0800 | [diff] [blame] | 44 | static inline void crisv32_io_set(struct crisv32_iopin* iopin, |
| Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 45 | int val) |
| 46 | { |
| Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame^] | 47 | long flags; |
| 48 | spin_lock_irqsave(&iopin->port->lock, flags); |
| 49 | |
| Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 50 | if (val) |
| 51 | *iopin->port->data |= iopin->bit; |
| 52 | else |
| 53 | *iopin->port->data &= ~iopin->bit; |
| Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame^] | 54 | |
| 55 | spin_unlock_irqrestore(&iopin->port->lock, flags); |
| Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 56 | } |
| 57 | |
| Adrian Bunk | d9b5444 | 2005-11-07 00:58:44 -0800 | [diff] [blame] | 58 | static inline void crisv32_io_set_dir(struct crisv32_iopin* iopin, |
| Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 59 | enum crisv32_io_dir dir) |
| 60 | { |
| Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame^] | 61 | long flags; |
| 62 | spin_lock_irqsave(&iopin->port->lock, flags); |
| 63 | |
| Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 64 | if (dir == crisv32_io_dir_in) |
| 65 | *iopin->port->oe &= ~iopin->bit; |
| 66 | else |
| 67 | *iopin->port->oe |= iopin->bit; |
| Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame^] | 68 | |
| 69 | spin_unlock_irqrestore(&iopin->port->lock, flags); |
| Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 70 | } |
| 71 | |
| Adrian Bunk | d9b5444 | 2005-11-07 00:58:44 -0800 | [diff] [blame] | 72 | static inline int crisv32_io_rd(struct crisv32_iopin* iopin) |
| Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 73 | { |
| 74 | return ((*iopin->port->data_in & iopin->bit) ? 1 : 0); |
| 75 | } |
| 76 | |
| 77 | int crisv32_io_get(struct crisv32_iopin* iopin, |
| 78 | unsigned int port, unsigned int pin); |
| 79 | int crisv32_io_get_name(struct crisv32_iopin* iopin, |
| Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame^] | 80 | const char *name); |
| Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 81 | |
| 82 | #define LED_OFF 0x00 |
| 83 | #define LED_GREEN 0x01 |
| 84 | #define LED_RED 0x02 |
| 85 | #define LED_ORANGE (LED_GREEN | LED_RED) |
| 86 | |
| Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame^] | 87 | #if (defined(CONFIG_ETRAX_NBR_LED_GRP_ONE) || defined(CONFIG_ETRAX_NBR_LED_GRP_TWO)) |
| 88 | #define LED_NETWORK_GRP0_SET(x) \ |
| 89 | do { \ |
| 90 | LED_NETWORK_GRP0_SET_G((x) & LED_GREEN); \ |
| 91 | LED_NETWORK_GRP0_SET_R((x) & LED_RED); \ |
| Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 92 | } while (0) |
| Jesper Nilsson | d8ca6b1 | 2007-12-03 11:16:25 +0100 | [diff] [blame^] | 93 | #else |
| 94 | #define LED_NETWORK_GRP0_SET(x) while (0) {} |
| 95 | #endif |
| 96 | |
| 97 | #define LED_NETWORK_GRP0_SET_G(x) \ |
| 98 | crisv32_io_set(&crisv32_led_net0_green, !(x)); |
| 99 | |
| 100 | #define LED_NETWORK_GRP0_SET_R(x) \ |
| 101 | crisv32_io_set(&crisv32_led_net0_red, !(x)); |
| 102 | |
| 103 | #if defined(CONFIG_ETRAX_NBR_LED_GRP_TWO) |
| 104 | #define LED_NETWORK_GRP1_SET(x) \ |
| 105 | do { \ |
| 106 | LED_NETWORK_GRP1_SET_G((x) & LED_GREEN); \ |
| 107 | LED_NETWORK_GRP1_SET_R((x) & LED_RED); \ |
| 108 | } while (0) |
| 109 | #else |
| 110 | #define LED_NETWORK_GRP1_SET(x) while (0) {} |
| 111 | #endif |
| 112 | |
| 113 | #define LED_NETWORK_GRP1_SET_G(x) \ |
| 114 | crisv32_io_set(&crisv32_led_net1_green, !(x)); |
| 115 | |
| 116 | #define LED_NETWORK_GRP1_SET_R(x) \ |
| 117 | crisv32_io_set(&crisv32_led_net1_red, !(x)); |
| 118 | |
| Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 119 | #define LED_ACTIVE_SET(x) \ |
| 120 | do { \ |
| 121 | LED_ACTIVE_SET_G((x) & LED_GREEN); \ |
| 122 | LED_ACTIVE_SET_R((x) & LED_RED); \ |
| 123 | } while (0) |
| 124 | |
| Mikael Starvik | 51533b6 | 2005-07-27 11:44:44 -0700 | [diff] [blame] | 125 | #define LED_ACTIVE_SET_G(x) \ |
| 126 | crisv32_io_set(&crisv32_led2_green, !(x)); |
| 127 | #define LED_ACTIVE_SET_R(x) \ |
| 128 | crisv32_io_set(&crisv32_led2_red, !(x)); |
| 129 | #define LED_DISK_WRITE(x) \ |
| 130 | do{\ |
| 131 | crisv32_io_set(&crisv32_led3_green, !(x)); \ |
| 132 | crisv32_io_set(&crisv32_led3_red, !(x)); \ |
| 133 | }while(0) |
| 134 | #define LED_DISK_READ(x) \ |
| 135 | crisv32_io_set(&crisv32_led3_green, !(x)); |
| 136 | |
| 137 | #endif |