Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 1 | /* |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 2 | * Copyright 2006-2009 Analog Devices Inc. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 3 | * |
Robin Getz | 96f1050 | 2009-09-24 14:11:24 +0000 | [diff] [blame] | 4 | * Licensed under the GPL-2 or later. |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 7 | #ifndef __ARCH_BLACKFIN_GPIO_H__ |
| 8 | #define __ARCH_BLACKFIN_GPIO_H__ |
| 9 | |
Michael Hennerich | a4f0b32 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 10 | #define gpio_bank(x) ((x) >> 4) |
| 11 | #define gpio_bit(x) (1<<((x) & 0xF)) |
| 12 | #define gpio_sub_n(x) ((x) & 0xF) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 13 | |
Bryan Wu | 2e8ca59 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 14 | #define GPIO_BANKSIZE 16 |
| 15 | #define GPIO_BANK_NUM DIV_ROUND_UP(MAX_BLACKFIN_GPIOS, GPIO_BANKSIZE) |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 16 | |
Michael Hennerich | 983e101 | 2009-01-07 23:14:39 +0800 | [diff] [blame] | 17 | #include <mach/gpio.h> |
| 18 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 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 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 68 | #define PERIPHERAL_USAGE 1 |
| 69 | #define GPIO_USAGE 0 |
| 70 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 71 | #ifndef __ASSEMBLY__ |
| 72 | |
Joachim Eastwood | 7f4f69f | 2010-02-10 12:31:41 +0100 | [diff] [blame] | 73 | #include <linux/compiler.h> |
| 74 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 75 | /*********************************************************** |
| 76 | * |
| 77 | * FUNCTIONS: Blackfin General Purpose Ports Access Functions |
| 78 | * |
| 79 | * INPUTS/OUTPUTS: |
| 80 | * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS |
| 81 | * |
| 82 | * |
| 83 | * DESCRIPTION: These functions abstract direct register access |
| 84 | * to Blackfin processor General Purpose |
| 85 | * Ports Regsiters |
| 86 | * |
| 87 | * CAUTION: These functions do not belong to the GPIO Driver API |
| 88 | ************************************************************* |
| 89 | * MODIFICATION HISTORY : |
| 90 | **************************************************************/ |
| 91 | |
Mike Frysinger | 269647d | 2009-03-28 20:32:57 +0800 | [diff] [blame] | 92 | #ifndef CONFIG_BF54x |
Michael Hennerich | a2c8cfe | 2008-01-22 17:20:10 +0800 | [diff] [blame] | 93 | void set_gpio_dir(unsigned, unsigned short); |
| 94 | void set_gpio_inen(unsigned, unsigned short); |
| 95 | void set_gpio_polar(unsigned, unsigned short); |
| 96 | void set_gpio_edge(unsigned, unsigned short); |
| 97 | void set_gpio_both(unsigned, unsigned short); |
| 98 | void set_gpio_data(unsigned, unsigned short); |
| 99 | void set_gpio_maska(unsigned, unsigned short); |
| 100 | void set_gpio_maskb(unsigned, unsigned short); |
| 101 | void set_gpio_toggle(unsigned); |
| 102 | void set_gpiop_dir(unsigned, unsigned short); |
| 103 | void set_gpiop_inen(unsigned, unsigned short); |
| 104 | void set_gpiop_polar(unsigned, unsigned short); |
| 105 | void set_gpiop_edge(unsigned, unsigned short); |
| 106 | void set_gpiop_both(unsigned, unsigned short); |
| 107 | void set_gpiop_data(unsigned, unsigned short); |
| 108 | void set_gpiop_maska(unsigned, unsigned short); |
| 109 | void set_gpiop_maskb(unsigned, unsigned short); |
| 110 | unsigned short get_gpio_dir(unsigned); |
| 111 | unsigned short get_gpio_inen(unsigned); |
| 112 | unsigned short get_gpio_polar(unsigned); |
| 113 | unsigned short get_gpio_edge(unsigned); |
| 114 | unsigned short get_gpio_both(unsigned); |
| 115 | unsigned short get_gpio_maska(unsigned); |
| 116 | unsigned short get_gpio_maskb(unsigned); |
| 117 | unsigned short get_gpio_data(unsigned); |
| 118 | unsigned short get_gpiop_dir(unsigned); |
| 119 | unsigned short get_gpiop_inen(unsigned); |
| 120 | unsigned short get_gpiop_polar(unsigned); |
| 121 | unsigned short get_gpiop_edge(unsigned); |
| 122 | unsigned short get_gpiop_both(unsigned); |
| 123 | unsigned short get_gpiop_maska(unsigned); |
| 124 | unsigned short get_gpiop_maskb(unsigned); |
| 125 | unsigned short get_gpiop_data(unsigned); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 126 | |
| 127 | struct gpio_port_t { |
| 128 | unsigned short data; |
| 129 | unsigned short dummy1; |
| 130 | unsigned short data_clear; |
| 131 | unsigned short dummy2; |
| 132 | unsigned short data_set; |
| 133 | unsigned short dummy3; |
| 134 | unsigned short toggle; |
| 135 | unsigned short dummy4; |
| 136 | unsigned short maska; |
| 137 | unsigned short dummy5; |
| 138 | unsigned short maska_clear; |
| 139 | unsigned short dummy6; |
| 140 | unsigned short maska_set; |
| 141 | unsigned short dummy7; |
| 142 | unsigned short maska_toggle; |
| 143 | unsigned short dummy8; |
| 144 | unsigned short maskb; |
| 145 | unsigned short dummy9; |
| 146 | unsigned short maskb_clear; |
| 147 | unsigned short dummy10; |
| 148 | unsigned short maskb_set; |
| 149 | unsigned short dummy11; |
| 150 | unsigned short maskb_toggle; |
| 151 | unsigned short dummy12; |
| 152 | unsigned short dir; |
| 153 | unsigned short dummy13; |
| 154 | unsigned short polar; |
| 155 | unsigned short dummy14; |
| 156 | unsigned short edge; |
| 157 | unsigned short dummy15; |
| 158 | unsigned short both; |
| 159 | unsigned short dummy16; |
| 160 | unsigned short inen; |
| 161 | }; |
Roy Huang | 24a07a1 | 2007-07-12 22:41:45 +0800 | [diff] [blame] | 162 | #endif |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 163 | |
Michael Hennerich | 621dd24 | 2009-09-28 12:23:41 +0000 | [diff] [blame] | 164 | #ifdef BFIN_SPECIAL_GPIO_BANKS |
| 165 | void bfin_special_gpio_free(unsigned gpio); |
| 166 | int bfin_special_gpio_request(unsigned gpio, const char *label); |
| 167 | #endif |
| 168 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 169 | #ifdef CONFIG_PM |
Michael Hennerich | bb84dbf | 2010-03-10 14:26:06 +0000 | [diff] [blame] | 170 | int bfin_pm_standby_ctrl(unsigned ctrl); |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 171 | |
Michael Hennerich | bb84dbf | 2010-03-10 14:26:06 +0000 | [diff] [blame] | 172 | static inline int bfin_pm_standby_setup(void) |
| 173 | { |
| 174 | return bfin_pm_standby_ctrl(1); |
| 175 | } |
| 176 | |
| 177 | static inline void bfin_pm_standby_restore(void) |
| 178 | { |
| 179 | bfin_pm_standby_ctrl(0); |
| 180 | } |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 181 | |
| 182 | void bfin_gpio_pm_hibernate_restore(void); |
| 183 | void bfin_gpio_pm_hibernate_suspend(void); |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 184 | |
| 185 | #ifndef CONFIG_BF54x |
Michael Hennerich | bb84dbf | 2010-03-10 14:26:06 +0000 | [diff] [blame] | 186 | int gpio_pm_wakeup_ctrl(unsigned gpio, unsigned ctrl); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 187 | |
| 188 | struct gpio_port_s { |
| 189 | unsigned short data; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 190 | unsigned short maska; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 191 | unsigned short maskb; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 192 | unsigned short dir; |
| 193 | unsigned short polar; |
| 194 | unsigned short edge; |
| 195 | unsigned short both; |
| 196 | unsigned short inen; |
| 197 | |
| 198 | unsigned short fer; |
Michael Hennerich | 581d62a | 2007-06-14 13:30:23 +0800 | [diff] [blame] | 199 | unsigned short reserved; |
Michael Hennerich | 1efc80b | 2008-07-19 16:57:32 +0800 | [diff] [blame] | 200 | unsigned short mux; |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 201 | }; |
Michael Hennerich | cfefe3c | 2008-02-09 04:12:37 +0800 | [diff] [blame] | 202 | #endif /*CONFIG_BF54x*/ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 203 | #endif /*CONFIG_PM*/ |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 204 | /*********************************************************** |
| 205 | * |
| 206 | * FUNCTIONS: Blackfin GPIO Driver |
| 207 | * |
| 208 | * INPUTS/OUTPUTS: |
| 209 | * gpio - GPIO Number between 0 and MAX_BLACKFIN_GPIOS |
| 210 | * |
| 211 | * |
| 212 | * DESCRIPTION: Blackfin GPIO Driver API |
| 213 | * |
| 214 | * CAUTION: |
| 215 | ************************************************************* |
| 216 | * MODIFICATION HISTORY : |
| 217 | **************************************************************/ |
| 218 | |
Michael Hennerich | a4f0b32 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 219 | int bfin_gpio_request(unsigned gpio, const char *label); |
| 220 | void bfin_gpio_free(unsigned gpio); |
Graf Yang | 9570ff4 | 2009-01-07 23:14:38 +0800 | [diff] [blame] | 221 | int bfin_gpio_irq_request(unsigned gpio, const char *label); |
| 222 | void bfin_gpio_irq_free(unsigned gpio); |
Michael Hennerich | a4f0b32 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 223 | int bfin_gpio_direction_input(unsigned gpio); |
| 224 | int bfin_gpio_direction_output(unsigned gpio, int value); |
| 225 | int bfin_gpio_get_value(unsigned gpio); |
| 226 | void bfin_gpio_set_value(unsigned gpio, int value); |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 227 | |
Joachim Eastwood | 7f4f69f | 2010-02-10 12:31:41 +0100 | [diff] [blame] | 228 | #include <asm/irq.h> |
| 229 | #include <asm/errno.h> |
| 230 | |
Michael Hennerich | a4f0b32 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 231 | #ifdef CONFIG_GPIOLIB |
| 232 | #include <asm-generic/gpio.h> /* cansleep wrappers */ |
| 233 | |
| 234 | static inline int gpio_get_value(unsigned int gpio) |
| 235 | { |
| 236 | if (gpio < MAX_BLACKFIN_GPIOS) |
| 237 | return bfin_gpio_get_value(gpio); |
| 238 | else |
| 239 | return __gpio_get_value(gpio); |
| 240 | } |
| 241 | |
| 242 | static inline void gpio_set_value(unsigned int gpio, int value) |
| 243 | { |
| 244 | if (gpio < MAX_BLACKFIN_GPIOS) |
| 245 | bfin_gpio_set_value(gpio, value); |
| 246 | else |
| 247 | __gpio_set_value(gpio, value); |
| 248 | } |
| 249 | |
| 250 | static inline int gpio_cansleep(unsigned int gpio) |
| 251 | { |
| 252 | return __gpio_cansleep(gpio); |
| 253 | } |
| 254 | |
Joachim Eastwood | 7f4f69f | 2010-02-10 12:31:41 +0100 | [diff] [blame] | 255 | static inline int gpio_to_irq(unsigned gpio) |
| 256 | { |
| 257 | return __gpio_to_irq(gpio); |
| 258 | } |
| 259 | |
Michael Hennerich | a4f0b32 | 2008-11-18 17:48:22 +0800 | [diff] [blame] | 260 | #else /* !CONFIG_GPIOLIB */ |
| 261 | |
| 262 | static inline int gpio_request(unsigned gpio, const char *label) |
| 263 | { |
| 264 | return bfin_gpio_request(gpio, label); |
| 265 | } |
| 266 | |
| 267 | static inline void gpio_free(unsigned gpio) |
| 268 | { |
| 269 | return bfin_gpio_free(gpio); |
| 270 | } |
| 271 | |
| 272 | static inline int gpio_direction_input(unsigned gpio) |
| 273 | { |
| 274 | return bfin_gpio_direction_input(gpio); |
| 275 | } |
| 276 | |
| 277 | static inline int gpio_direction_output(unsigned gpio, int value) |
| 278 | { |
| 279 | return bfin_gpio_direction_output(gpio, value); |
| 280 | } |
| 281 | |
| 282 | static inline int gpio_get_value(unsigned gpio) |
| 283 | { |
| 284 | return bfin_gpio_get_value(gpio); |
| 285 | } |
| 286 | |
| 287 | static inline void gpio_set_value(unsigned gpio, int value) |
| 288 | { |
| 289 | return bfin_gpio_set_value(gpio, value); |
| 290 | } |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 291 | |
Michael Hennerich | 301af29 | 2007-07-24 15:35:53 +0800 | [diff] [blame] | 292 | static inline int gpio_to_irq(unsigned gpio) |
| 293 | { |
Michael Hennerich | e1312bf | 2009-03-28 21:18:45 +0800 | [diff] [blame] | 294 | if (likely(gpio < MAX_BLACKFIN_GPIOS)) |
| 295 | return gpio + GPIO_IRQ_BASE; |
| 296 | |
| 297 | return -EINVAL; |
Michael Hennerich | 301af29 | 2007-07-24 15:35:53 +0800 | [diff] [blame] | 298 | } |
| 299 | |
Joachim Eastwood | 7f4f69f | 2010-02-10 12:31:41 +0100 | [diff] [blame] | 300 | #include <asm-generic/gpio.h> /* cansleep wrappers */ |
| 301 | #endif /* !CONFIG_GPIOLIB */ |
| 302 | |
Michael Hennerich | 301af29 | 2007-07-24 15:35:53 +0800 | [diff] [blame] | 303 | static inline int irq_to_gpio(unsigned irq) |
| 304 | { |
| 305 | return (irq - GPIO_IRQ_BASE); |
| 306 | } |
| 307 | |
Bryan Wu | 1394f03 | 2007-05-06 14:50:22 -0700 | [diff] [blame] | 308 | #endif /* __ASSEMBLY__ */ |
| 309 | |
| 310 | #endif /* __ARCH_BLACKFIN_GPIO_H__ */ |