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