Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
| 2 | * File: arch/blackfin/kernel/bfin_gpio.h |
| 3 | * Based on: |
| 4 | * Author: Michael Hennerich (hennerich@blackfin.uclinux.org) |
| 5 | * |
| 6 | * Created: |
| 7 | * Description: |
| 8 | * |
| 9 | * Modified: |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 10 | * Copyright 2004-2008 Analog Devices Inc. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 11 | * |
| 12 | * Bugs: Enter bugs at http://blackfin.uclinux.org/ |
| 13 | * |
| 14 | * This program is free software; you can redistribute it and/or modify |
| 15 | * it under the terms of the GNU General Public License as published by |
| 16 | * the Free Software Foundation; either version 2 of the License, or |
| 17 | * (at your option) any later version. |
| 18 | * |
| 19 | * This program is distributed in the hope that it will be useful, |
| 20 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | * GNU General Public License for more details. |
| 23 | * |
| 24 | * You should have received a copy of the GNU General Public License |
| 25 | * along with this program; if not, see the file COPYING, or write |
| 26 | * to the Free Software Foundation, Inc., |
| 27 | * 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 28 | */ |
| 29 | |
| 30 | /* |
| 31 | * Number BF537/6/4 BF561 BF533/2/1 |
Michael Hennerich | 5900314 | 2007-10-21 16:54:27 +0800 | [diff] [blame] | 32 | * BF527/5/2 |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 33 | * |
| 34 | * GPIO_0 PF0 PF0 PF0 |
| 35 | * GPIO_1 PF1 PF1 PF1 |
| 36 | * GPIO_2 PF2 PF2 PF2 |
| 37 | * GPIO_3 PF3 PF3 PF3 |
| 38 | * GPIO_4 PF4 PF4 PF4 |
| 39 | * GPIO_5 PF5 PF5 PF5 |
| 40 | * GPIO_6 PF6 PF6 PF6 |
| 41 | * GPIO_7 PF7 PF7 PF7 |
| 42 | * GPIO_8 PF8 PF8 PF8 |
| 43 | * GPIO_9 PF9 PF9 PF9 |
| 44 | * GPIO_10 PF10 PF10 PF10 |
| 45 | * GPIO_11 PF11 PF11 PF11 |
| 46 | * GPIO_12 PF12 PF12 PF12 |
| 47 | * GPIO_13 PF13 PF13 PF13 |
| 48 | * GPIO_14 PF14 PF14 PF14 |
| 49 | * GPIO_15 PF15 PF15 PF15 |
| 50 | * GPIO_16 PG0 PF16 |
| 51 | * GPIO_17 PG1 PF17 |
| 52 | * GPIO_18 PG2 PF18 |
| 53 | * GPIO_19 PG3 PF19 |
| 54 | * GPIO_20 PG4 PF20 |
| 55 | * GPIO_21 PG5 PF21 |
| 56 | * GPIO_22 PG6 PF22 |
| 57 | * GPIO_23 PG7 PF23 |
| 58 | * GPIO_24 PG8 PF24 |
| 59 | * GPIO_25 PG9 PF25 |
| 60 | * GPIO_26 PG10 PF26 |
| 61 | * GPIO_27 PG11 PF27 |
| 62 | * GPIO_28 PG12 PF28 |
| 63 | * GPIO_29 PG13 PF29 |
| 64 | * GPIO_30 PG14 PF30 |
| 65 | * GPIO_31 PG15 PF31 |
| 66 | * GPIO_32 PH0 PF32 |
| 67 | * GPIO_33 PH1 PF33 |
| 68 | * GPIO_34 PH2 PF34 |
| 69 | * GPIO_35 PH3 PF35 |
| 70 | * GPIO_36 PH4 PF36 |
| 71 | * GPIO_37 PH5 PF37 |
| 72 | * GPIO_38 PH6 PF38 |
| 73 | * GPIO_39 PH7 PF39 |
| 74 | * GPIO_40 PH8 PF40 |
| 75 | * GPIO_41 PH9 PF41 |
| 76 | * GPIO_42 PH10 PF42 |
| 77 | * GPIO_43 PH11 PF43 |
| 78 | * GPIO_44 PH12 PF44 |
| 79 | * GPIO_45 PH13 PF45 |
| 80 | * GPIO_46 PH14 PF46 |
| 81 | * GPIO_47 PH15 PF47 |
| 82 | */ |
| 83 | |
| 84 | #ifndef __ARCH_BLACKFIN_GPIO_H__ |
| 85 | #define __ARCH_BLACKFIN_GPIO_H__ |
| 86 | |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 87 | #define gpio_bank(x) ((x) >> 4) |
| 88 | #define gpio_bit(x) (1<<((x) & 0xF)) |
| 89 | #define gpio_sub_n(x) ((x) & 0xF) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 90 | |
Bryan Wu | 2e8ca59 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 91 | #define GPIO_BANKSIZE 16 |
| 92 | #define GPIO_BANK_NUM DIV_ROUND_UP(MAX_BLACKFIN_GPIOS, GPIO_BANKSIZE) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 93 | |
Michael Hennerich | 983e101 | 2009-01-07 23:14:39 +0800 | [diff] [blame^] | 94 | #include <mach/gpio.h> |
| 95 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 96 | #define GPIO_0 0 |
| 97 | #define GPIO_1 1 |
| 98 | #define GPIO_2 2 |
| 99 | #define GPIO_3 3 |
| 100 | #define GPIO_4 4 |
| 101 | #define GPIO_5 5 |
| 102 | #define GPIO_6 6 |
| 103 | #define GPIO_7 7 |
| 104 | #define GPIO_8 8 |
| 105 | #define GPIO_9 9 |
| 106 | #define GPIO_10 10 |
| 107 | #define GPIO_11 11 |
| 108 | #define GPIO_12 12 |
| 109 | #define GPIO_13 13 |
| 110 | #define GPIO_14 14 |
| 111 | #define GPIO_15 15 |
| 112 | #define GPIO_16 16 |
| 113 | #define GPIO_17 17 |
| 114 | #define GPIO_18 18 |
| 115 | #define GPIO_19 19 |
| 116 | #define GPIO_20 20 |
| 117 | #define GPIO_21 21 |
| 118 | #define GPIO_22 22 |
| 119 | #define GPIO_23 23 |
| 120 | #define GPIO_24 24 |
| 121 | #define GPIO_25 25 |
| 122 | #define GPIO_26 26 |
| 123 | #define GPIO_27 27 |
| 124 | #define GPIO_28 28 |
| 125 | #define GPIO_29 29 |
| 126 | #define GPIO_30 30 |
| 127 | #define GPIO_31 31 |
| 128 | #define GPIO_32 32 |
| 129 | #define GPIO_33 33 |
| 130 | #define GPIO_34 34 |
| 131 | #define GPIO_35 35 |
| 132 | #define GPIO_36 36 |
| 133 | #define GPIO_37 37 |
| 134 | #define GPIO_38 38 |
| 135 | #define GPIO_39 39 |
| 136 | #define GPIO_40 40 |
| 137 | #define GPIO_41 41 |
| 138 | #define GPIO_42 42 |
| 139 | #define GPIO_43 43 |
| 140 | #define GPIO_44 44 |
| 141 | #define GPIO_45 45 |
| 142 | #define GPIO_46 46 |
| 143 | #define GPIO_47 47 |
| 144 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 145 | #define PERIPHERAL_USAGE 1 |
| 146 | #define GPIO_USAGE 0 |
| 147 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 148 | #ifndef __ASSEMBLY__ |
| 149 | |
| 150 | /*********************************************************** |
| 151 | * |
| 152 | * FUNCTIONS: Blackfin General Purpose Ports Access Functions |
| 153 | * |
| 154 | * INPUTS/OUTPUTS: |
| 155 | * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS |
| 156 | * |
| 157 | * |
| 158 | * DESCRIPTION: These functions abstract direct register access |
| 159 | * to Blackfin processor General Purpose |
| 160 | * Ports Regsiters |
| 161 | * |
| 162 | * CAUTION: These functions do not belong to the GPIO Driver API |
| 163 | ************************************************************* |
| 164 | * MODIFICATION HISTORY : |
| 165 | **************************************************************/ |
| 166 | |
Michael Hennerich | cefe658 | 2007-07-02 11:45:50 +0800 | [diff] [blame] | 167 | #ifndef BF548_FAMILY |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 168 | void set_gpio_dir(unsigned, unsigned short); |
| 169 | void set_gpio_inen(unsigned, unsigned short); |
| 170 | void set_gpio_polar(unsigned, unsigned short); |
| 171 | void set_gpio_edge(unsigned, unsigned short); |
| 172 | void set_gpio_both(unsigned, unsigned short); |
| 173 | void set_gpio_data(unsigned, unsigned short); |
| 174 | void set_gpio_maska(unsigned, unsigned short); |
| 175 | void set_gpio_maskb(unsigned, unsigned short); |
| 176 | void set_gpio_toggle(unsigned); |
| 177 | void set_gpiop_dir(unsigned, unsigned short); |
| 178 | void set_gpiop_inen(unsigned, unsigned short); |
| 179 | void set_gpiop_polar(unsigned, unsigned short); |
| 180 | void set_gpiop_edge(unsigned, unsigned short); |
| 181 | void set_gpiop_both(unsigned, unsigned short); |
| 182 | void set_gpiop_data(unsigned, unsigned short); |
| 183 | void set_gpiop_maska(unsigned, unsigned short); |
| 184 | void set_gpiop_maskb(unsigned, unsigned short); |
| 185 | unsigned short get_gpio_dir(unsigned); |
| 186 | unsigned short get_gpio_inen(unsigned); |
| 187 | unsigned short get_gpio_polar(unsigned); |
| 188 | unsigned short get_gpio_edge(unsigned); |
| 189 | unsigned short get_gpio_both(unsigned); |
| 190 | unsigned short get_gpio_maska(unsigned); |
| 191 | unsigned short get_gpio_maskb(unsigned); |
| 192 | unsigned short get_gpio_data(unsigned); |
| 193 | unsigned short get_gpiop_dir(unsigned); |
| 194 | unsigned short get_gpiop_inen(unsigned); |
| 195 | unsigned short get_gpiop_polar(unsigned); |
| 196 | unsigned short get_gpiop_edge(unsigned); |
| 197 | unsigned short get_gpiop_both(unsigned); |
| 198 | unsigned short get_gpiop_maska(unsigned); |
| 199 | unsigned short get_gpiop_maskb(unsigned); |
| 200 | unsigned short get_gpiop_data(unsigned); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 201 | |
| 202 | struct gpio_port_t { |
| 203 | unsigned short data; |
| 204 | unsigned short dummy1; |
| 205 | unsigned short data_clear; |
| 206 | unsigned short dummy2; |
| 207 | unsigned short data_set; |
| 208 | unsigned short dummy3; |
| 209 | unsigned short toggle; |
| 210 | unsigned short dummy4; |
| 211 | unsigned short maska; |
| 212 | unsigned short dummy5; |
| 213 | unsigned short maska_clear; |
| 214 | unsigned short dummy6; |
| 215 | unsigned short maska_set; |
| 216 | unsigned short dummy7; |
| 217 | unsigned short maska_toggle; |
| 218 | unsigned short dummy8; |
| 219 | unsigned short maskb; |
| 220 | unsigned short dummy9; |
| 221 | unsigned short maskb_clear; |
| 222 | unsigned short dummy10; |
| 223 | unsigned short maskb_set; |
| 224 | unsigned short dummy11; |
| 225 | unsigned short maskb_toggle; |
| 226 | unsigned short dummy12; |
| 227 | unsigned short dir; |
| 228 | unsigned short dummy13; |
| 229 | unsigned short polar; |
| 230 | unsigned short dummy14; |
| 231 | unsigned short edge; |
| 232 | unsigned short dummy15; |
| 233 | unsigned short both; |
| 234 | unsigned short dummy16; |
| 235 | unsigned short inen; |
| 236 | }; |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 237 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 238 | |
| 239 | #ifdef CONFIG_PM |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 240 | |
| 241 | unsigned int bfin_pm_standby_setup(void); |
| 242 | void bfin_pm_standby_restore(void); |
| 243 | |
| 244 | void bfin_gpio_pm_hibernate_restore(void); |
| 245 | void bfin_gpio_pm_hibernate_suspend(void); |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 246 | |
| 247 | #ifndef CONFIG_BF54x |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 248 | #define PM_WAKE_RISING 0x1 |
| 249 | #define PM_WAKE_FALLING 0x2 |
| 250 | #define PM_WAKE_HIGH 0x4 |
| 251 | #define PM_WAKE_LOW 0x8 |
| 252 | #define PM_WAKE_BOTH_EDGES (PM_WAKE_RISING | PM_WAKE_FALLING) |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 253 | #define PM_WAKE_IGNORE 0xF0 |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 254 | |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 255 | int gpio_pm_wakeup_request(unsigned gpio, unsigned char type); |
| 256 | void gpio_pm_wakeup_free(unsigned gpio); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 257 | |
| 258 | struct gpio_port_s { |
| 259 | unsigned short data; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 260 | unsigned short maska; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 261 | unsigned short maskb; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 262 | unsigned short dir; |
| 263 | unsigned short polar; |
| 264 | unsigned short edge; |
| 265 | unsigned short both; |
| 266 | unsigned short inen; |
| 267 | |
| 268 | unsigned short fer; |
Michael Hennerich | 581d62a | 2007-06-14 13:30:23 +0800 | [diff] [blame] | 269 | unsigned short reserved; |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 270 | unsigned short mux; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 271 | }; |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 272 | #endif /*CONFIG_BF54x*/ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 273 | #endif /*CONFIG_PM*/ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 274 | /*********************************************************** |
| 275 | * |
| 276 | * FUNCTIONS: Blackfin GPIO Driver |
| 277 | * |
| 278 | * INPUTS/OUTPUTS: |
| 279 | * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS |
| 280 | * |
| 281 | * |
| 282 | * DESCRIPTION: Blackfin GPIO Driver API |
| 283 | * |
| 284 | * CAUTION: |
| 285 | ************************************************************* |
| 286 | * MODIFICATION HISTORY : |
| 287 | **************************************************************/ |
| 288 | |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 289 | int bfin_gpio_request(unsigned gpio, const char *label); |
| 290 | void bfin_gpio_free(unsigned gpio); |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 291 | int bfin_gpio_irq_request(unsigned gpio, const char *label); |
| 292 | void bfin_gpio_irq_free(unsigned gpio); |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 293 | int bfin_gpio_direction_input(unsigned gpio); |
| 294 | int bfin_gpio_direction_output(unsigned gpio, int value); |
| 295 | int bfin_gpio_get_value(unsigned gpio); |
| 296 | void bfin_gpio_set_value(unsigned gpio, int value); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 297 | |
Michael Hennerich | cefe658 | 2007-07-02 11:45:50 +0800 | [diff] [blame] | 298 | #ifndef BF548_FAMILY |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 299 | #define bfin_gpio_set_value(gpio, value) set_gpio_data(gpio, value) |
Michael Hennerich | cefe658 | 2007-07-02 11:45:50 +0800 | [diff] [blame] | 300 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 301 | |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 302 | #ifdef CONFIG_GPIOLIB |
| 303 | #include <asm-generic/gpio.h> /* cansleep wrappers */ |
| 304 | |
| 305 | static inline int gpio_get_value(unsigned int gpio) |
| 306 | { |
| 307 | if (gpio < MAX_BLACKFIN_GPIOS) |
| 308 | return bfin_gpio_get_value(gpio); |
| 309 | else |
| 310 | return __gpio_get_value(gpio); |
| 311 | } |
| 312 | |
| 313 | static inline void gpio_set_value(unsigned int gpio, int value) |
| 314 | { |
| 315 | if (gpio < MAX_BLACKFIN_GPIOS) |
| 316 | bfin_gpio_set_value(gpio, value); |
| 317 | else |
| 318 | __gpio_set_value(gpio, value); |
| 319 | } |
| 320 | |
| 321 | static inline int gpio_cansleep(unsigned int gpio) |
| 322 | { |
| 323 | return __gpio_cansleep(gpio); |
| 324 | } |
| 325 | |
| 326 | #else /* !CONFIG_GPIOLIB */ |
| 327 | |
| 328 | static inline int gpio_request(unsigned gpio, const char *label) |
| 329 | { |
| 330 | return bfin_gpio_request(gpio, label); |
| 331 | } |
| 332 | |
| 333 | static inline void gpio_free(unsigned gpio) |
| 334 | { |
| 335 | return bfin_gpio_free(gpio); |
| 336 | } |
| 337 | |
| 338 | static inline int gpio_direction_input(unsigned gpio) |
| 339 | { |
| 340 | return bfin_gpio_direction_input(gpio); |
| 341 | } |
| 342 | |
| 343 | static inline int gpio_direction_output(unsigned gpio, int value) |
| 344 | { |
| 345 | return bfin_gpio_direction_output(gpio, value); |
| 346 | } |
| 347 | |
| 348 | static inline int gpio_get_value(unsigned gpio) |
| 349 | { |
| 350 | return bfin_gpio_get_value(gpio); |
| 351 | } |
| 352 | |
| 353 | static inline void gpio_set_value(unsigned gpio, int value) |
| 354 | { |
| 355 | return bfin_gpio_set_value(gpio, value); |
| 356 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 357 | |
Michael Hennerich | 301af29 | 2007-07-24 15:35:53 +0800 | [diff] [blame] | 358 | #include <asm-generic/gpio.h> /* cansleep wrappers */ |
Michael Hennerich | a4f0b32c | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 359 | #endif /* !CONFIG_GPIOLIB */ |
Michael Hennerich | 301af29 | 2007-07-24 15:35:53 +0800 | [diff] [blame] | 360 | #include <asm/irq.h> |
| 361 | |
| 362 | static inline int gpio_to_irq(unsigned gpio) |
| 363 | { |
| 364 | return (gpio + GPIO_IRQ_BASE); |
| 365 | } |
| 366 | |
| 367 | static inline int irq_to_gpio(unsigned irq) |
| 368 | { |
| 369 | return (irq - GPIO_IRQ_BASE); |
| 370 | } |
| 371 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 372 | #endif /* __ASSEMBLY__ */ |
| 373 | |
| 374 | #endif /* __ARCH_BLACKFIN_GPIO_H__ */ |