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