Mike Frysinger | 4638b21 | 2010-06-02 04:17:26 -0400 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2006-2009 Analog Devices Inc. |
| 3 | * |
| 4 | * Licensed under the GPL-2 or later. |
| 5 | */ |
| 6 | |
| 7 | #ifndef __ARCH_BLACKFIN_GPIO_H__ |
| 8 | #define __ARCH_BLACKFIN_GPIO_H__ |
| 9 | |
| 10 | #define gpio_bank(x) ((x) >> 4) |
| 11 | #define gpio_bit(x) (1<<((x) & 0xF)) |
| 12 | #define gpio_sub_n(x) ((x) & 0xF) |
| 13 | |
| 14 | #define GPIO_BANKSIZE 16 |
| 15 | #define GPIO_BANK_NUM DIV_ROUND_UP(MAX_BLACKFIN_GPIOS, GPIO_BANKSIZE) |
| 16 | |
| 17 | #define GPIO_0 0 |
| 18 | #define GPIO_1 1 |
| 19 | #define GPIO_2 2 |
| 20 | #define GPIO_3 3 |
| 21 | #define GPIO_4 4 |
| 22 | #define GPIO_5 5 |
| 23 | #define GPIO_6 6 |
| 24 | #define GPIO_7 7 |
| 25 | #define GPIO_8 8 |
| 26 | #define GPIO_9 9 |
| 27 | #define GPIO_10 10 |
| 28 | #define GPIO_11 11 |
| 29 | #define GPIO_12 12 |
| 30 | #define GPIO_13 13 |
| 31 | #define GPIO_14 14 |
| 32 | #define GPIO_15 15 |
| 33 | #define GPIO_16 16 |
| 34 | #define GPIO_17 17 |
| 35 | #define GPIO_18 18 |
| 36 | #define GPIO_19 19 |
| 37 | #define GPIO_20 20 |
| 38 | #define GPIO_21 21 |
| 39 | #define GPIO_22 22 |
| 40 | #define GPIO_23 23 |
| 41 | #define GPIO_24 24 |
| 42 | #define GPIO_25 25 |
| 43 | #define GPIO_26 26 |
| 44 | #define GPIO_27 27 |
| 45 | #define GPIO_28 28 |
| 46 | #define GPIO_29 29 |
| 47 | #define GPIO_30 30 |
| 48 | #define GPIO_31 31 |
| 49 | #define GPIO_32 32 |
| 50 | #define GPIO_33 33 |
| 51 | #define GPIO_34 34 |
| 52 | #define GPIO_35 35 |
| 53 | #define GPIO_36 36 |
| 54 | #define GPIO_37 37 |
| 55 | #define GPIO_38 38 |
| 56 | #define GPIO_39 39 |
| 57 | #define GPIO_40 40 |
| 58 | #define GPIO_41 41 |
| 59 | #define GPIO_42 42 |
| 60 | #define GPIO_43 43 |
| 61 | #define GPIO_44 44 |
| 62 | #define GPIO_45 45 |
| 63 | #define GPIO_46 46 |
| 64 | #define GPIO_47 47 |
| 65 | |
| 66 | #define PERIPHERAL_USAGE 1 |
| 67 | #define GPIO_USAGE 0 |
| 68 | |
| 69 | #ifndef __ASSEMBLY__ |
| 70 | |
| 71 | #ifndef CONFIG_BF54x |
| 72 | void set_gpio_dir(unsigned, unsigned short); |
| 73 | void set_gpio_inen(unsigned, unsigned short); |
| 74 | void set_gpio_polar(unsigned, unsigned short); |
| 75 | void set_gpio_edge(unsigned, unsigned short); |
| 76 | void set_gpio_both(unsigned, unsigned short); |
| 77 | void set_gpio_data(unsigned, unsigned short); |
| 78 | void set_gpio_maska(unsigned, unsigned short); |
| 79 | void set_gpio_maskb(unsigned, unsigned short); |
| 80 | void set_gpio_toggle(unsigned); |
| 81 | void set_gpiop_dir(unsigned, unsigned short); |
| 82 | void set_gpiop_inen(unsigned, unsigned short); |
| 83 | void set_gpiop_polar(unsigned, unsigned short); |
| 84 | void set_gpiop_edge(unsigned, unsigned short); |
| 85 | void set_gpiop_both(unsigned, unsigned short); |
| 86 | void set_gpiop_data(unsigned, unsigned short); |
| 87 | void set_gpiop_maska(unsigned, unsigned short); |
| 88 | void set_gpiop_maskb(unsigned, unsigned short); |
| 89 | unsigned short get_gpio_dir(unsigned); |
| 90 | unsigned short get_gpio_inen(unsigned); |
| 91 | unsigned short get_gpio_polar(unsigned); |
| 92 | unsigned short get_gpio_edge(unsigned); |
| 93 | unsigned short get_gpio_both(unsigned); |
| 94 | unsigned short get_gpio_maska(unsigned); |
| 95 | unsigned short get_gpio_maskb(unsigned); |
| 96 | unsigned short get_gpio_data(unsigned); |
| 97 | unsigned short get_gpiop_dir(unsigned); |
| 98 | unsigned short get_gpiop_inen(unsigned); |
| 99 | unsigned short get_gpiop_polar(unsigned); |
| 100 | unsigned short get_gpiop_edge(unsigned); |
| 101 | unsigned short get_gpiop_both(unsigned); |
| 102 | unsigned short get_gpiop_maska(unsigned); |
| 103 | unsigned short get_gpiop_maskb(unsigned); |
| 104 | unsigned short get_gpiop_data(unsigned); |
| 105 | |
| 106 | struct gpio_port_t { |
| 107 | unsigned short data; |
| 108 | unsigned short dummy1; |
| 109 | unsigned short data_clear; |
| 110 | unsigned short dummy2; |
| 111 | unsigned short data_set; |
| 112 | unsigned short dummy3; |
| 113 | unsigned short toggle; |
| 114 | unsigned short dummy4; |
| 115 | unsigned short maska; |
| 116 | unsigned short dummy5; |
| 117 | unsigned short maska_clear; |
| 118 | unsigned short dummy6; |
| 119 | unsigned short maska_set; |
| 120 | unsigned short dummy7; |
| 121 | unsigned short maska_toggle; |
| 122 | unsigned short dummy8; |
| 123 | unsigned short maskb; |
| 124 | unsigned short dummy9; |
| 125 | unsigned short maskb_clear; |
| 126 | unsigned short dummy10; |
| 127 | unsigned short maskb_set; |
| 128 | unsigned short dummy11; |
| 129 | unsigned short maskb_toggle; |
| 130 | unsigned short dummy12; |
| 131 | unsigned short dir; |
| 132 | unsigned short dummy13; |
| 133 | unsigned short polar; |
| 134 | unsigned short dummy14; |
| 135 | unsigned short edge; |
| 136 | unsigned short dummy15; |
| 137 | unsigned short both; |
| 138 | unsigned short dummy16; |
| 139 | unsigned short inen; |
| 140 | }; |
| 141 | #endif |
| 142 | |
| 143 | #ifdef CONFIG_BFIN_GPIO_TRACK |
| 144 | void bfin_gpio_labels(void); |
Mike Frysinger | 95b4b9d | 2011-05-10 12:56:58 -0400 | [diff] [blame^] | 145 | void bfin_gpio_free(unsigned gpio); |
Mike Frysinger | 4638b21 | 2010-06-02 04:17:26 -0400 | [diff] [blame] | 146 | #else |
| 147 | #define bfin_gpio_labels() |
Mike Frysinger | 95b4b9d | 2011-05-10 12:56:58 -0400 | [diff] [blame^] | 148 | #define bfin_gpio_free(gpio) |
Mike Frysinger | 4638b21 | 2010-06-02 04:17:26 -0400 | [diff] [blame] | 149 | #define bfin_gpio_request(gpio, label) bfin_gpio_request(gpio) |
| 150 | #define bfin_special_gpio_request(gpio, label) bfin_special_gpio_request(gpio) |
| 151 | #endif |
| 152 | |
| 153 | #ifdef BFIN_SPECIAL_GPIO_BANKS |
| 154 | void bfin_special_gpio_free(unsigned gpio); |
| 155 | int bfin_special_gpio_request(unsigned gpio, const char *label); |
| 156 | #endif |
| 157 | |
| 158 | int bfin_gpio_request(unsigned gpio, const char *label); |
Mike Frysinger | 4638b21 | 2010-06-02 04:17:26 -0400 | [diff] [blame] | 159 | int bfin_gpio_direction_input(unsigned gpio); |
| 160 | int bfin_gpio_direction_output(unsigned gpio, int value); |
| 161 | int bfin_gpio_get_value(unsigned gpio); |
| 162 | void bfin_gpio_set_value(unsigned gpio, int value); |
| 163 | void bfin_gpio_toggle_value(unsigned gpio); |
| 164 | |
| 165 | static inline int gpio_request(unsigned gpio, const char *label) |
| 166 | { |
| 167 | return bfin_gpio_request(gpio, label); |
| 168 | } |
| 169 | |
| 170 | static inline void gpio_free(unsigned gpio) |
| 171 | { |
| 172 | return bfin_gpio_free(gpio); |
| 173 | } |
| 174 | |
| 175 | static inline int gpio_direction_input(unsigned gpio) |
| 176 | { |
| 177 | return bfin_gpio_direction_input(gpio); |
| 178 | } |
| 179 | |
| 180 | static inline int gpio_direction_output(unsigned gpio, int value) |
| 181 | { |
| 182 | return bfin_gpio_direction_output(gpio, value); |
| 183 | } |
| 184 | |
| 185 | static inline int gpio_get_value(unsigned gpio) |
| 186 | { |
| 187 | return bfin_gpio_get_value(gpio); |
| 188 | } |
| 189 | |
| 190 | static inline void gpio_set_value(unsigned gpio, int value) |
| 191 | { |
| 192 | return bfin_gpio_set_value(gpio, value); |
| 193 | } |
| 194 | |
| 195 | static inline int gpio_is_valid(int number) |
| 196 | { |
| 197 | return number >= 0 && number < MAX_BLACKFIN_GPIOS; |
| 198 | } |
| 199 | |
Mike Frysinger | a972b8d | 2011-04-03 04:40:46 -0400 | [diff] [blame] | 200 | #include <linux/ctype.h> |
| 201 | |
| 202 | static inline int name_to_gpio(const char *name) |
| 203 | { |
| 204 | int port_base; |
| 205 | |
| 206 | if (tolower(*name) == 'p') { |
| 207 | ++name; |
| 208 | |
| 209 | switch (tolower(*name)) { |
| 210 | #ifdef GPIO_PA0 |
| 211 | case 'a': port_base = GPIO_PA0; break; |
| 212 | #endif |
| 213 | #ifdef GPIO_PB0 |
| 214 | case 'b': port_base = GPIO_PB0; break; |
| 215 | #endif |
| 216 | #ifdef GPIO_PC0 |
| 217 | case 'c': port_base = GPIO_PC0; break; |
| 218 | #endif |
| 219 | #ifdef GPIO_PD0 |
| 220 | case 'd': port_base = GPIO_PD0; break; |
| 221 | #endif |
| 222 | #ifdef GPIO_PE0 |
| 223 | case 'e': port_base = GPIO_PE0; break; |
| 224 | #endif |
| 225 | #ifdef GPIO_PF0 |
| 226 | case 'f': port_base = GPIO_PF0; break; |
| 227 | #endif |
| 228 | #ifdef GPIO_PG0 |
| 229 | case 'g': port_base = GPIO_PG0; break; |
| 230 | #endif |
| 231 | #ifdef GPIO_PH0 |
| 232 | case 'h': port_base = GPIO_PH0; break; |
| 233 | #endif |
| 234 | #ifdef GPIO_PI0 |
| 235 | case 'i': port_base = GPIO_PI0; break; |
| 236 | #endif |
| 237 | #ifdef GPIO_PJ |
| 238 | case 'j': port_base = GPIO_PJ0; break; |
| 239 | #endif |
| 240 | default: return -1; |
| 241 | } |
| 242 | |
| 243 | ++name; |
| 244 | } else |
| 245 | port_base = 0; |
| 246 | |
| 247 | return port_base + simple_strtoul(name, NULL, 10); |
| 248 | } |
| 249 | #define name_to_gpio(n) name_to_gpio(n) |
| 250 | |
| 251 | #define gpio_status() bfin_gpio_labels() |
| 252 | |
Mike Frysinger | 4638b21 | 2010-06-02 04:17:26 -0400 | [diff] [blame] | 253 | #endif /* __ASSEMBLY__ */ |
| 254 | |
| 255 | #endif /* __ARCH_BLACKFIN_GPIO_H__ */ |