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