Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 1 | /* |
| 2 | * Generic GPIO driver for logic cells found in the Nomadik SoC |
| 3 | * |
| 4 | * Copyright (C) 2008,2009 STMicroelectronics |
| 5 | * Copyright (C) 2009 Alessandro Rubini <rubini@unipv.it> |
| 6 | * Rewritten based on work by Prafulla WADASKAR <prafulla.wadaskar@st.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License version 2 as |
| 10 | * published by the Free Software Foundation. |
| 11 | */ |
| 12 | #include <linux/kernel.h> |
| 13 | #include <linux/module.h> |
| 14 | #include <linux/init.h> |
| 15 | #include <linux/device.h> |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 16 | #include <linux/platform_device.h> |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 17 | #include <linux/io.h> |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 18 | #include <linux/clk.h> |
| 19 | #include <linux/err.h> |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 20 | #include <linux/gpio.h> |
| 21 | #include <linux/spinlock.h> |
| 22 | #include <linux/interrupt.h> |
| 23 | #include <linux/irq.h> |
Tejun Heo | 5a0e3ad | 2010-03-24 17:04:11 +0900 | [diff] [blame] | 24 | #include <linux/slab.h> |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 25 | |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 26 | #include <plat/pincfg.h> |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 27 | #include <mach/hardware.h> |
| 28 | #include <mach/gpio.h> |
| 29 | |
| 30 | /* |
| 31 | * The GPIO module in the Nomadik family of Systems-on-Chip is an |
| 32 | * AMBA device, managing 32 pins and alternate functions. The logic block |
| 33 | * is currently only used in the Nomadik. |
| 34 | * |
| 35 | * Symbols in this file are called "nmk_gpio" for "nomadik gpio" |
| 36 | */ |
| 37 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 38 | struct nmk_gpio_chip { |
| 39 | struct gpio_chip chip; |
| 40 | void __iomem *addr; |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 41 | struct clk *clk; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 42 | unsigned int parent_irq; |
Rabin Vincent | c0fcb8d | 2010-03-03 04:48:54 +0100 | [diff] [blame] | 43 | spinlock_t lock; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 44 | /* Keep track of configured edges */ |
| 45 | u32 edge_rising; |
| 46 | u32 edge_falling; |
| 47 | }; |
| 48 | |
Rabin Vincent | 6f9a974 | 2010-06-02 05:50:28 +0100 | [diff] [blame] | 49 | static void __nmk_gpio_set_mode(struct nmk_gpio_chip *nmk_chip, |
| 50 | unsigned offset, int gpio_mode) |
| 51 | { |
| 52 | u32 bit = 1 << offset; |
| 53 | u32 afunc, bfunc; |
| 54 | |
| 55 | afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & ~bit; |
| 56 | bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & ~bit; |
| 57 | if (gpio_mode & NMK_GPIO_ALT_A) |
| 58 | afunc |= bit; |
| 59 | if (gpio_mode & NMK_GPIO_ALT_B) |
| 60 | bfunc |= bit; |
| 61 | writel(afunc, nmk_chip->addr + NMK_GPIO_AFSLA); |
| 62 | writel(bfunc, nmk_chip->addr + NMK_GPIO_AFSLB); |
| 63 | } |
| 64 | |
Rabin Vincent | 81a3c29 | 2010-05-27 12:39:23 +0100 | [diff] [blame] | 65 | static void __nmk_gpio_set_slpm(struct nmk_gpio_chip *nmk_chip, |
| 66 | unsigned offset, enum nmk_gpio_slpm mode) |
| 67 | { |
| 68 | u32 bit = 1 << offset; |
| 69 | u32 slpm; |
| 70 | |
| 71 | slpm = readl(nmk_chip->addr + NMK_GPIO_SLPC); |
| 72 | if (mode == NMK_GPIO_SLPM_NOCHANGE) |
| 73 | slpm |= bit; |
| 74 | else |
| 75 | slpm &= ~bit; |
| 76 | writel(slpm, nmk_chip->addr + NMK_GPIO_SLPC); |
| 77 | } |
| 78 | |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 79 | static void __nmk_gpio_set_pull(struct nmk_gpio_chip *nmk_chip, |
| 80 | unsigned offset, enum nmk_gpio_pull pull) |
| 81 | { |
| 82 | u32 bit = 1 << offset; |
| 83 | u32 pdis; |
| 84 | |
| 85 | pdis = readl(nmk_chip->addr + NMK_GPIO_PDIS); |
| 86 | if (pull == NMK_GPIO_PULL_NONE) |
| 87 | pdis |= bit; |
| 88 | else |
| 89 | pdis &= ~bit; |
| 90 | writel(pdis, nmk_chip->addr + NMK_GPIO_PDIS); |
| 91 | |
| 92 | if (pull == NMK_GPIO_PULL_UP) |
| 93 | writel(bit, nmk_chip->addr + NMK_GPIO_DATS); |
| 94 | else if (pull == NMK_GPIO_PULL_DOWN) |
| 95 | writel(bit, nmk_chip->addr + NMK_GPIO_DATC); |
| 96 | } |
| 97 | |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 98 | static void __nmk_gpio_make_input(struct nmk_gpio_chip *nmk_chip, |
| 99 | unsigned offset) |
| 100 | { |
| 101 | writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC); |
| 102 | } |
| 103 | |
Rabin Vincent | 6720db7 | 2010-09-02 11:28:48 +0100 | [diff] [blame] | 104 | static void __nmk_gpio_set_output(struct nmk_gpio_chip *nmk_chip, |
| 105 | unsigned offset, int val) |
| 106 | { |
| 107 | if (val) |
| 108 | writel(1 << offset, nmk_chip->addr + NMK_GPIO_DATS); |
| 109 | else |
| 110 | writel(1 << offset, nmk_chip->addr + NMK_GPIO_DATC); |
| 111 | } |
| 112 | |
| 113 | static void __nmk_gpio_make_output(struct nmk_gpio_chip *nmk_chip, |
| 114 | unsigned offset, int val) |
| 115 | { |
| 116 | writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRS); |
| 117 | __nmk_gpio_set_output(nmk_chip, offset, val); |
| 118 | } |
| 119 | |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 120 | static void __nmk_config_pin(struct nmk_gpio_chip *nmk_chip, unsigned offset, |
Rabin Vincent | dacdc96 | 2010-12-03 20:35:37 +0530 | [diff] [blame] | 121 | pin_cfg_t cfg, bool sleep) |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 122 | { |
| 123 | static const char *afnames[] = { |
| 124 | [NMK_GPIO_ALT_GPIO] = "GPIO", |
| 125 | [NMK_GPIO_ALT_A] = "A", |
| 126 | [NMK_GPIO_ALT_B] = "B", |
| 127 | [NMK_GPIO_ALT_C] = "C" |
| 128 | }; |
| 129 | static const char *pullnames[] = { |
| 130 | [NMK_GPIO_PULL_NONE] = "none", |
| 131 | [NMK_GPIO_PULL_UP] = "up", |
| 132 | [NMK_GPIO_PULL_DOWN] = "down", |
| 133 | [3] /* illegal */ = "??" |
| 134 | }; |
| 135 | static const char *slpmnames[] = { |
Rabin Vincent | 7e3f7e5 | 2010-09-02 11:28:05 +0100 | [diff] [blame] | 136 | [NMK_GPIO_SLPM_INPUT] = "input/wakeup", |
| 137 | [NMK_GPIO_SLPM_NOCHANGE] = "no-change/no-wakeup", |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | int pin = PIN_NUM(cfg); |
| 141 | int pull = PIN_PULL(cfg); |
| 142 | int af = PIN_ALT(cfg); |
| 143 | int slpm = PIN_SLPM(cfg); |
Rabin Vincent | 6720db7 | 2010-09-02 11:28:48 +0100 | [diff] [blame] | 144 | int output = PIN_DIR(cfg); |
| 145 | int val = PIN_VAL(cfg); |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 146 | |
Rabin Vincent | dacdc96 | 2010-12-03 20:35:37 +0530 | [diff] [blame] | 147 | dev_dbg(nmk_chip->chip.dev, "pin %d [%#lx]: af %s, pull %s, slpm %s (%s%s)\n", |
| 148 | pin, cfg, afnames[af], pullnames[pull], slpmnames[slpm], |
Rabin Vincent | 6720db7 | 2010-09-02 11:28:48 +0100 | [diff] [blame] | 149 | output ? "output " : "input", |
| 150 | output ? (val ? "high" : "low") : ""); |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 151 | |
Rabin Vincent | dacdc96 | 2010-12-03 20:35:37 +0530 | [diff] [blame] | 152 | if (sleep) { |
| 153 | int slpm_pull = PIN_SLPM_PULL(cfg); |
| 154 | int slpm_output = PIN_SLPM_DIR(cfg); |
| 155 | int slpm_val = PIN_SLPM_VAL(cfg); |
| 156 | |
| 157 | /* |
| 158 | * The SLPM_* values are normal values + 1 to allow zero to |
| 159 | * mean "same as normal". |
| 160 | */ |
| 161 | if (slpm_pull) |
| 162 | pull = slpm_pull - 1; |
| 163 | if (slpm_output) |
| 164 | output = slpm_output - 1; |
| 165 | if (slpm_val) |
| 166 | val = slpm_val - 1; |
| 167 | |
| 168 | dev_dbg(nmk_chip->chip.dev, "pin %d: sleep pull %s, dir %s, val %s\n", |
| 169 | pin, |
| 170 | slpm_pull ? pullnames[pull] : "same", |
| 171 | slpm_output ? (output ? "output" : "input") : "same", |
| 172 | slpm_val ? (val ? "high" : "low") : "same"); |
| 173 | } |
| 174 | |
Rabin Vincent | 6720db7 | 2010-09-02 11:28:48 +0100 | [diff] [blame] | 175 | if (output) |
| 176 | __nmk_gpio_make_output(nmk_chip, offset, val); |
| 177 | else { |
| 178 | __nmk_gpio_make_input(nmk_chip, offset); |
| 179 | __nmk_gpio_set_pull(nmk_chip, offset, pull); |
| 180 | } |
| 181 | |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 182 | __nmk_gpio_set_slpm(nmk_chip, offset, slpm); |
| 183 | __nmk_gpio_set_mode(nmk_chip, offset, af); |
| 184 | } |
| 185 | |
| 186 | /** |
| 187 | * nmk_config_pin - configure a pin's mux attributes |
| 188 | * @cfg: pin confguration |
| 189 | * |
| 190 | * Configures a pin's mode (alternate function or GPIO), its pull up status, |
| 191 | * and its sleep mode based on the specified configuration. The @cfg is |
| 192 | * usually one of the SoC specific macros defined in mach/<soc>-pins.h. These |
| 193 | * are constructed using, and can be further enhanced with, the macros in |
| 194 | * plat/pincfg.h. |
| 195 | * |
| 196 | * If a pin's mode is set to GPIO, it is configured as an input to avoid |
| 197 | * side-effects. The gpio can be manipulated later using standard GPIO API |
| 198 | * calls. |
| 199 | */ |
Rabin Vincent | dacdc96 | 2010-12-03 20:35:37 +0530 | [diff] [blame] | 200 | int nmk_config_pin(pin_cfg_t cfg, bool sleep) |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 201 | { |
| 202 | struct nmk_gpio_chip *nmk_chip; |
| 203 | int gpio = PIN_NUM(cfg); |
| 204 | unsigned long flags; |
| 205 | |
| 206 | nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio)); |
| 207 | if (!nmk_chip) |
| 208 | return -EINVAL; |
| 209 | |
| 210 | spin_lock_irqsave(&nmk_chip->lock, flags); |
Rabin Vincent | dacdc96 | 2010-12-03 20:35:37 +0530 | [diff] [blame] | 211 | __nmk_config_pin(nmk_chip, gpio - nmk_chip->chip.base, cfg, sleep); |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 212 | spin_unlock_irqrestore(&nmk_chip->lock, flags); |
| 213 | |
| 214 | return 0; |
| 215 | } |
| 216 | EXPORT_SYMBOL(nmk_config_pin); |
| 217 | |
| 218 | /** |
| 219 | * nmk_config_pins - configure several pins at once |
| 220 | * @cfgs: array of pin configurations |
| 221 | * @num: number of elments in the array |
| 222 | * |
| 223 | * Configures several pins using nmk_config_pin(). Refer to that function for |
| 224 | * further information. |
| 225 | */ |
| 226 | int nmk_config_pins(pin_cfg_t *cfgs, int num) |
| 227 | { |
| 228 | int ret = 0; |
| 229 | int i; |
| 230 | |
| 231 | for (i = 0; i < num; i++) { |
Rabin Vincent | dacdc96 | 2010-12-03 20:35:37 +0530 | [diff] [blame] | 232 | ret = nmk_config_pin(cfgs[i], false); |
Rabin Vincent | 378be06 | 2010-06-02 06:06:29 +0100 | [diff] [blame] | 233 | if (ret) |
| 234 | break; |
| 235 | } |
| 236 | |
| 237 | return ret; |
| 238 | } |
| 239 | EXPORT_SYMBOL(nmk_config_pins); |
| 240 | |
Rabin Vincent | dacdc96 | 2010-12-03 20:35:37 +0530 | [diff] [blame] | 241 | int nmk_config_pins_sleep(pin_cfg_t *cfgs, int num) |
| 242 | { |
| 243 | int ret = 0; |
| 244 | int i; |
| 245 | |
| 246 | for (i = 0; i < num; i++) { |
| 247 | ret = nmk_config_pin(cfgs[i], true); |
| 248 | if (ret) |
| 249 | break; |
| 250 | } |
| 251 | |
| 252 | return ret; |
| 253 | } |
| 254 | EXPORT_SYMBOL(nmk_config_pins_sleep); |
| 255 | |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 256 | /** |
Rabin Vincent | 81a3c29 | 2010-05-27 12:39:23 +0100 | [diff] [blame] | 257 | * nmk_gpio_set_slpm() - configure the sleep mode of a pin |
| 258 | * @gpio: pin number |
| 259 | * @mode: NMK_GPIO_SLPM_INPUT or NMK_GPIO_SLPM_NOCHANGE, |
| 260 | * |
| 261 | * Sets the sleep mode of a pin. If @mode is NMK_GPIO_SLPM_INPUT, the pin is |
| 262 | * changed to an input (with pullup/down enabled) in sleep and deep sleep. If |
| 263 | * @mode is NMK_GPIO_SLPM_NOCHANGE, the pin remains in the state it was |
| 264 | * configured even when in sleep and deep sleep. |
Rabin Vincent | 7e3f7e5 | 2010-09-02 11:28:05 +0100 | [diff] [blame] | 265 | * |
| 266 | * On DB8500v2 onwards, this setting loses the previous meaning and instead |
| 267 | * indicates if wakeup detection is enabled on the pin. Note that |
| 268 | * enable_irq_wake() will automatically enable wakeup detection. |
Rabin Vincent | 81a3c29 | 2010-05-27 12:39:23 +0100 | [diff] [blame] | 269 | */ |
| 270 | int nmk_gpio_set_slpm(int gpio, enum nmk_gpio_slpm mode) |
| 271 | { |
| 272 | struct nmk_gpio_chip *nmk_chip; |
| 273 | unsigned long flags; |
| 274 | |
| 275 | nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio)); |
| 276 | if (!nmk_chip) |
| 277 | return -EINVAL; |
| 278 | |
| 279 | spin_lock_irqsave(&nmk_chip->lock, flags); |
| 280 | __nmk_gpio_set_slpm(nmk_chip, gpio - nmk_chip->chip.base, mode); |
| 281 | spin_unlock_irqrestore(&nmk_chip->lock, flags); |
| 282 | |
| 283 | return 0; |
| 284 | } |
| 285 | |
| 286 | /** |
Rabin Vincent | 5b327ed | 2010-05-27 12:29:50 +0100 | [diff] [blame] | 287 | * nmk_gpio_set_pull() - enable/disable pull up/down on a gpio |
| 288 | * @gpio: pin number |
| 289 | * @pull: one of NMK_GPIO_PULL_DOWN, NMK_GPIO_PULL_UP, and NMK_GPIO_PULL_NONE |
| 290 | * |
| 291 | * Enables/disables pull up/down on a specified pin. This only takes effect if |
| 292 | * the pin is configured as an input (either explicitly or by the alternate |
| 293 | * function). |
| 294 | * |
| 295 | * NOTE: If enabling the pull up/down, the caller must ensure that the GPIO is |
| 296 | * configured as an input. Otherwise, due to the way the controller registers |
| 297 | * work, this function will change the value output on the pin. |
| 298 | */ |
| 299 | int nmk_gpio_set_pull(int gpio, enum nmk_gpio_pull pull) |
| 300 | { |
| 301 | struct nmk_gpio_chip *nmk_chip; |
| 302 | unsigned long flags; |
| 303 | |
| 304 | nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio)); |
| 305 | if (!nmk_chip) |
| 306 | return -EINVAL; |
| 307 | |
| 308 | spin_lock_irqsave(&nmk_chip->lock, flags); |
| 309 | __nmk_gpio_set_pull(nmk_chip, gpio - nmk_chip->chip.base, pull); |
| 310 | spin_unlock_irqrestore(&nmk_chip->lock, flags); |
| 311 | |
| 312 | return 0; |
| 313 | } |
| 314 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 315 | /* Mode functions */ |
| 316 | int nmk_gpio_set_mode(int gpio, int gpio_mode) |
| 317 | { |
| 318 | struct nmk_gpio_chip *nmk_chip; |
| 319 | unsigned long flags; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 320 | |
| 321 | nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio)); |
| 322 | if (!nmk_chip) |
| 323 | return -EINVAL; |
| 324 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 325 | spin_lock_irqsave(&nmk_chip->lock, flags); |
Rabin Vincent | 6f9a974 | 2010-06-02 05:50:28 +0100 | [diff] [blame] | 326 | __nmk_gpio_set_mode(nmk_chip, gpio - nmk_chip->chip.base, gpio_mode); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 327 | spin_unlock_irqrestore(&nmk_chip->lock, flags); |
| 328 | |
| 329 | return 0; |
| 330 | } |
| 331 | EXPORT_SYMBOL(nmk_gpio_set_mode); |
| 332 | |
| 333 | int nmk_gpio_get_mode(int gpio) |
| 334 | { |
| 335 | struct nmk_gpio_chip *nmk_chip; |
| 336 | u32 afunc, bfunc, bit; |
| 337 | |
| 338 | nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio)); |
| 339 | if (!nmk_chip) |
| 340 | return -EINVAL; |
| 341 | |
| 342 | bit = 1 << (gpio - nmk_chip->chip.base); |
| 343 | |
| 344 | afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & bit; |
| 345 | bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & bit; |
| 346 | |
| 347 | return (afunc ? NMK_GPIO_ALT_A : 0) | (bfunc ? NMK_GPIO_ALT_B : 0); |
| 348 | } |
| 349 | EXPORT_SYMBOL(nmk_gpio_get_mode); |
| 350 | |
| 351 | |
| 352 | /* IRQ functions */ |
| 353 | static inline int nmk_gpio_get_bitmask(int gpio) |
| 354 | { |
| 355 | return 1 << (gpio % 32); |
| 356 | } |
| 357 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 358 | static void nmk_gpio_irq_ack(struct irq_data *d) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 359 | { |
| 360 | int gpio; |
| 361 | struct nmk_gpio_chip *nmk_chip; |
| 362 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 363 | gpio = NOMADIK_IRQ_TO_GPIO(d->irq); |
| 364 | nmk_chip = irq_data_get_irq_chip_data(d); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 365 | if (!nmk_chip) |
| 366 | return; |
| 367 | writel(nmk_gpio_get_bitmask(gpio), nmk_chip->addr + NMK_GPIO_IC); |
| 368 | } |
| 369 | |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 370 | enum nmk_gpio_irq_type { |
| 371 | NORMAL, |
| 372 | WAKE, |
| 373 | }; |
| 374 | |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 375 | static void __nmk_gpio_irq_modify(struct nmk_gpio_chip *nmk_chip, |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 376 | int gpio, enum nmk_gpio_irq_type which, |
| 377 | bool enable) |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 378 | { |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 379 | u32 rimsc = which == WAKE ? NMK_GPIO_RWIMSC : NMK_GPIO_RIMSC; |
| 380 | u32 fimsc = which == WAKE ? NMK_GPIO_FWIMSC : NMK_GPIO_FIMSC; |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 381 | u32 bitmask = nmk_gpio_get_bitmask(gpio); |
| 382 | u32 reg; |
| 383 | |
| 384 | /* we must individually set/clear the two edges */ |
| 385 | if (nmk_chip->edge_rising & bitmask) { |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 386 | reg = readl(nmk_chip->addr + rimsc); |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 387 | if (enable) |
| 388 | reg |= bitmask; |
| 389 | else |
| 390 | reg &= ~bitmask; |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 391 | writel(reg, nmk_chip->addr + rimsc); |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 392 | } |
| 393 | if (nmk_chip->edge_falling & bitmask) { |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 394 | reg = readl(nmk_chip->addr + fimsc); |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 395 | if (enable) |
| 396 | reg |= bitmask; |
| 397 | else |
| 398 | reg &= ~bitmask; |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 399 | writel(reg, nmk_chip->addr + fimsc); |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 400 | } |
| 401 | } |
| 402 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 403 | static int nmk_gpio_irq_modify(struct irq_data *d, enum nmk_gpio_irq_type which, |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 404 | bool enable) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 405 | { |
| 406 | int gpio; |
| 407 | struct nmk_gpio_chip *nmk_chip; |
| 408 | unsigned long flags; |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 409 | u32 bitmask; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 410 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 411 | gpio = NOMADIK_IRQ_TO_GPIO(d->irq); |
| 412 | nmk_chip = irq_data_get_irq_chip_data(d); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 413 | bitmask = nmk_gpio_get_bitmask(gpio); |
| 414 | if (!nmk_chip) |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 415 | return -EINVAL; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 416 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 417 | spin_lock_irqsave(&nmk_chip->lock, flags); |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 418 | __nmk_gpio_irq_modify(nmk_chip, gpio, which, enable); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 419 | spin_unlock_irqrestore(&nmk_chip->lock, flags); |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 420 | |
| 421 | return 0; |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 422 | } |
| 423 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 424 | static void nmk_gpio_irq_mask(struct irq_data *d) |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 425 | { |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 426 | nmk_gpio_irq_modify(d, NORMAL, false); |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 427 | } |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 428 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 429 | static void nmk_gpio_irq_unmask(struct irq_data *d) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 430 | { |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 431 | nmk_gpio_irq_modify(d, NORMAL, true); |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 432 | } |
| 433 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 434 | static int nmk_gpio_irq_set_wake(struct irq_data *d, unsigned int on) |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 435 | { |
Rabin Vincent | 7e3f7e5 | 2010-09-02 11:28:05 +0100 | [diff] [blame] | 436 | struct nmk_gpio_chip *nmk_chip; |
| 437 | unsigned long flags; |
| 438 | int gpio; |
| 439 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 440 | gpio = NOMADIK_IRQ_TO_GPIO(d->irq); |
| 441 | nmk_chip = irq_data_get_irq_chip_data(d); |
Rabin Vincent | 7e3f7e5 | 2010-09-02 11:28:05 +0100 | [diff] [blame] | 442 | if (!nmk_chip) |
| 443 | return -EINVAL; |
| 444 | |
| 445 | spin_lock_irqsave(&nmk_chip->lock, flags); |
| 446 | #ifdef CONFIG_ARCH_U8500 |
| 447 | if (cpu_is_u8500v2()) { |
| 448 | __nmk_gpio_set_slpm(nmk_chip, gpio, |
| 449 | on ? NMK_GPIO_SLPM_WAKEUP_ENABLE |
| 450 | : NMK_GPIO_SLPM_WAKEUP_DISABLE); |
| 451 | } |
| 452 | #endif |
| 453 | __nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, on); |
| 454 | spin_unlock_irqrestore(&nmk_chip->lock, flags); |
| 455 | |
| 456 | return 0; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 457 | } |
| 458 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 459 | static int nmk_gpio_irq_set_type(struct irq_data *d, unsigned int type) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 460 | { |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 461 | struct irq_desc *desc = irq_to_desc(d->irq); |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 462 | bool enabled = !(desc->status & IRQ_DISABLED); |
| 463 | bool wake = desc->wake_depth; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 464 | int gpio; |
| 465 | struct nmk_gpio_chip *nmk_chip; |
| 466 | unsigned long flags; |
| 467 | u32 bitmask; |
| 468 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 469 | gpio = NOMADIK_IRQ_TO_GPIO(d->irq); |
| 470 | nmk_chip = irq_data_get_irq_chip_data(d); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 471 | bitmask = nmk_gpio_get_bitmask(gpio); |
| 472 | if (!nmk_chip) |
| 473 | return -EINVAL; |
| 474 | |
| 475 | if (type & IRQ_TYPE_LEVEL_HIGH) |
| 476 | return -EINVAL; |
| 477 | if (type & IRQ_TYPE_LEVEL_LOW) |
| 478 | return -EINVAL; |
| 479 | |
| 480 | spin_lock_irqsave(&nmk_chip->lock, flags); |
| 481 | |
Rabin Vincent | 7a852d8 | 2010-05-06 10:43:55 +0100 | [diff] [blame] | 482 | if (enabled) |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 483 | __nmk_gpio_irq_modify(nmk_chip, gpio, NORMAL, false); |
| 484 | |
| 485 | if (wake) |
| 486 | __nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, false); |
Rabin Vincent | 7a852d8 | 2010-05-06 10:43:55 +0100 | [diff] [blame] | 487 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 488 | nmk_chip->edge_rising &= ~bitmask; |
| 489 | if (type & IRQ_TYPE_EDGE_RISING) |
| 490 | nmk_chip->edge_rising |= bitmask; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 491 | |
| 492 | nmk_chip->edge_falling &= ~bitmask; |
| 493 | if (type & IRQ_TYPE_EDGE_FALLING) |
| 494 | nmk_chip->edge_falling |= bitmask; |
Rabin Vincent | 7a852d8 | 2010-05-06 10:43:55 +0100 | [diff] [blame] | 495 | |
| 496 | if (enabled) |
Rabin Vincent | 4d4e20f | 2010-06-16 06:09:34 +0100 | [diff] [blame] | 497 | __nmk_gpio_irq_modify(nmk_chip, gpio, NORMAL, true); |
| 498 | |
| 499 | if (wake) |
| 500 | __nmk_gpio_irq_modify(nmk_chip, gpio, WAKE, true); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 501 | |
| 502 | spin_unlock_irqrestore(&nmk_chip->lock, flags); |
| 503 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 504 | return 0; |
| 505 | } |
| 506 | |
| 507 | static struct irq_chip nmk_gpio_irq_chip = { |
| 508 | .name = "Nomadik-GPIO", |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 509 | .irq_ack = nmk_gpio_irq_ack, |
| 510 | .irq_mask = nmk_gpio_irq_mask, |
| 511 | .irq_unmask = nmk_gpio_irq_unmask, |
| 512 | .irq_set_type = nmk_gpio_irq_set_type, |
| 513 | .irq_set_wake = nmk_gpio_irq_set_wake, |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 514 | }; |
| 515 | |
| 516 | static void nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) |
| 517 | { |
| 518 | struct nmk_gpio_chip *nmk_chip; |
Rabin Vincent | aaedaa2 | 2010-03-03 04:50:27 +0100 | [diff] [blame] | 519 | struct irq_chip *host_chip = get_irq_chip(irq); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 520 | unsigned int gpio_irq; |
| 521 | u32 pending; |
| 522 | unsigned int first_irq; |
| 523 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 524 | if (host_chip->irq_mask_ack) |
| 525 | host_chip->irq_mask_ack(&desc->irq_data); |
Rabin Vincent | aaedaa2 | 2010-03-03 04:50:27 +0100 | [diff] [blame] | 526 | else { |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 527 | host_chip->irq_mask(&desc->irq_data); |
| 528 | if (host_chip->irq_ack) |
| 529 | host_chip->irq_ack(&desc->irq_data); |
Rabin Vincent | aaedaa2 | 2010-03-03 04:50:27 +0100 | [diff] [blame] | 530 | } |
| 531 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 532 | nmk_chip = get_irq_data(irq); |
| 533 | first_irq = NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base); |
| 534 | while ( (pending = readl(nmk_chip->addr + NMK_GPIO_IS)) ) { |
| 535 | gpio_irq = first_irq + __ffs(pending); |
| 536 | generic_handle_irq(gpio_irq); |
| 537 | } |
Rabin Vincent | aaedaa2 | 2010-03-03 04:50:27 +0100 | [diff] [blame] | 538 | |
Lennert Buytenhek | f272c00 | 2010-11-29 11:16:48 +0100 | [diff] [blame] | 539 | host_chip->irq_unmask(&desc->irq_data); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 540 | } |
| 541 | |
| 542 | static int nmk_gpio_init_irq(struct nmk_gpio_chip *nmk_chip) |
| 543 | { |
| 544 | unsigned int first_irq; |
| 545 | int i; |
| 546 | |
| 547 | first_irq = NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base); |
Rabin Vincent | e493e06 | 2010-03-18 12:35:22 +0530 | [diff] [blame^] | 548 | for (i = first_irq; i < first_irq + nmk_chip->chip.ngpio; i++) { |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 549 | set_irq_chip(i, &nmk_gpio_irq_chip); |
| 550 | set_irq_handler(i, handle_edge_irq); |
| 551 | set_irq_flags(i, IRQF_VALID); |
| 552 | set_irq_chip_data(i, nmk_chip); |
Rabin Vincent | 2210d64 | 2010-05-06 10:45:18 +0100 | [diff] [blame] | 553 | set_irq_type(i, IRQ_TYPE_EDGE_FALLING); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 554 | } |
| 555 | set_irq_chained_handler(nmk_chip->parent_irq, nmk_gpio_irq_handler); |
| 556 | set_irq_data(nmk_chip->parent_irq, nmk_chip); |
| 557 | return 0; |
| 558 | } |
| 559 | |
| 560 | /* I/O Functions */ |
| 561 | static int nmk_gpio_make_input(struct gpio_chip *chip, unsigned offset) |
| 562 | { |
| 563 | struct nmk_gpio_chip *nmk_chip = |
| 564 | container_of(chip, struct nmk_gpio_chip, chip); |
| 565 | |
| 566 | writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC); |
| 567 | return 0; |
| 568 | } |
| 569 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 570 | static int nmk_gpio_get_input(struct gpio_chip *chip, unsigned offset) |
| 571 | { |
| 572 | struct nmk_gpio_chip *nmk_chip = |
| 573 | container_of(chip, struct nmk_gpio_chip, chip); |
| 574 | u32 bit = 1 << offset; |
| 575 | |
| 576 | return (readl(nmk_chip->addr + NMK_GPIO_DAT) & bit) != 0; |
| 577 | } |
| 578 | |
| 579 | static void nmk_gpio_set_output(struct gpio_chip *chip, unsigned offset, |
| 580 | int val) |
| 581 | { |
| 582 | struct nmk_gpio_chip *nmk_chip = |
| 583 | container_of(chip, struct nmk_gpio_chip, chip); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 584 | |
Rabin Vincent | 6720db7 | 2010-09-02 11:28:48 +0100 | [diff] [blame] | 585 | __nmk_gpio_set_output(nmk_chip, offset, val); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 586 | } |
| 587 | |
Rabin Vincent | 6647c6c | 2010-05-27 12:22:42 +0100 | [diff] [blame] | 588 | static int nmk_gpio_make_output(struct gpio_chip *chip, unsigned offset, |
| 589 | int val) |
| 590 | { |
| 591 | struct nmk_gpio_chip *nmk_chip = |
| 592 | container_of(chip, struct nmk_gpio_chip, chip); |
| 593 | |
Rabin Vincent | 6720db7 | 2010-09-02 11:28:48 +0100 | [diff] [blame] | 594 | __nmk_gpio_make_output(nmk_chip, offset, val); |
Rabin Vincent | 6647c6c | 2010-05-27 12:22:42 +0100 | [diff] [blame] | 595 | |
| 596 | return 0; |
| 597 | } |
| 598 | |
Rabin Vincent | 0d2aec9 | 2010-06-16 06:10:43 +0100 | [diff] [blame] | 599 | static int nmk_gpio_to_irq(struct gpio_chip *chip, unsigned offset) |
| 600 | { |
| 601 | struct nmk_gpio_chip *nmk_chip = |
| 602 | container_of(chip, struct nmk_gpio_chip, chip); |
| 603 | |
| 604 | return NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base) + offset; |
| 605 | } |
| 606 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 607 | /* This structure is replicated for each GPIO block allocated at probe time */ |
| 608 | static struct gpio_chip nmk_gpio_template = { |
| 609 | .direction_input = nmk_gpio_make_input, |
| 610 | .get = nmk_gpio_get_input, |
| 611 | .direction_output = nmk_gpio_make_output, |
| 612 | .set = nmk_gpio_set_output, |
Rabin Vincent | 0d2aec9 | 2010-06-16 06:10:43 +0100 | [diff] [blame] | 613 | .to_irq = nmk_gpio_to_irq, |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 614 | .can_sleep = 0, |
| 615 | }; |
| 616 | |
Uwe Kleine-König | fd0d67d | 2010-09-02 16:13:35 +0100 | [diff] [blame] | 617 | static int __devinit nmk_gpio_probe(struct platform_device *dev) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 618 | { |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 619 | struct nmk_gpio_platform_data *pdata = dev->dev.platform_data; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 620 | struct nmk_gpio_chip *nmk_chip; |
| 621 | struct gpio_chip *chip; |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 622 | struct resource *res; |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 623 | struct clk *clk; |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 624 | int irq; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 625 | int ret; |
| 626 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 627 | if (!pdata) |
| 628 | return -ENODEV; |
| 629 | |
| 630 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); |
| 631 | if (!res) { |
| 632 | ret = -ENOENT; |
| 633 | goto out; |
| 634 | } |
| 635 | |
| 636 | irq = platform_get_irq(dev, 0); |
| 637 | if (irq < 0) { |
| 638 | ret = irq; |
| 639 | goto out; |
| 640 | } |
| 641 | |
| 642 | if (request_mem_region(res->start, resource_size(res), |
| 643 | dev_name(&dev->dev)) == NULL) { |
| 644 | ret = -EBUSY; |
| 645 | goto out; |
| 646 | } |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 647 | |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 648 | clk = clk_get(&dev->dev, NULL); |
| 649 | if (IS_ERR(clk)) { |
| 650 | ret = PTR_ERR(clk); |
| 651 | goto out_release; |
| 652 | } |
| 653 | |
| 654 | clk_enable(clk); |
| 655 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 656 | nmk_chip = kzalloc(sizeof(*nmk_chip), GFP_KERNEL); |
| 657 | if (!nmk_chip) { |
| 658 | ret = -ENOMEM; |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 659 | goto out_clk; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 660 | } |
| 661 | /* |
| 662 | * The virt address in nmk_chip->addr is in the nomadik register space, |
| 663 | * so we can simply convert the resource address, without remapping |
| 664 | */ |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 665 | nmk_chip->clk = clk; |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 666 | nmk_chip->addr = io_p2v(res->start); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 667 | nmk_chip->chip = nmk_gpio_template; |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 668 | nmk_chip->parent_irq = irq; |
Rabin Vincent | c0fcb8d | 2010-03-03 04:48:54 +0100 | [diff] [blame] | 669 | spin_lock_init(&nmk_chip->lock); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 670 | |
| 671 | chip = &nmk_chip->chip; |
| 672 | chip->base = pdata->first_gpio; |
Rabin Vincent | e493e06 | 2010-03-18 12:35:22 +0530 | [diff] [blame^] | 673 | chip->ngpio = pdata->num_gpio; |
Rabin Vincent | 8d568ae | 2010-12-08 11:07:54 +0530 | [diff] [blame] | 674 | chip->label = pdata->name ?: dev_name(&dev->dev); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 675 | chip->dev = &dev->dev; |
| 676 | chip->owner = THIS_MODULE; |
| 677 | |
| 678 | ret = gpiochip_add(&nmk_chip->chip); |
| 679 | if (ret) |
| 680 | goto out_free; |
| 681 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 682 | platform_set_drvdata(dev, nmk_chip); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 683 | |
| 684 | nmk_gpio_init_irq(nmk_chip); |
| 685 | |
| 686 | dev_info(&dev->dev, "Bits %i-%i at address %p\n", |
| 687 | nmk_chip->chip.base, nmk_chip->chip.base+31, nmk_chip->addr); |
| 688 | return 0; |
| 689 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 690 | out_free: |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 691 | kfree(nmk_chip); |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 692 | out_clk: |
| 693 | clk_disable(clk); |
| 694 | clk_put(clk); |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 695 | out_release: |
| 696 | release_mem_region(res->start, resource_size(res)); |
| 697 | out: |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 698 | dev_err(&dev->dev, "Failure %i for GPIO %i-%i\n", ret, |
| 699 | pdata->first_gpio, pdata->first_gpio+31); |
| 700 | return ret; |
| 701 | } |
| 702 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 703 | static struct platform_driver nmk_gpio_driver = { |
| 704 | .driver = { |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 705 | .owner = THIS_MODULE, |
| 706 | .name = "gpio", |
| 707 | }, |
| 708 | .probe = nmk_gpio_probe, |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 709 | .suspend = NULL, /* to be done */ |
| 710 | .resume = NULL, |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 711 | }; |
| 712 | |
| 713 | static int __init nmk_gpio_init(void) |
| 714 | { |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 715 | return platform_driver_register(&nmk_gpio_driver); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 716 | } |
| 717 | |
Rabin Vincent | 33f45ea | 2010-06-02 06:09:52 +0100 | [diff] [blame] | 718 | core_initcall(nmk_gpio_init); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 719 | |
| 720 | MODULE_AUTHOR("Prafulla WADASKAR and Alessandro Rubini"); |
| 721 | MODULE_DESCRIPTION("Nomadik GPIO Driver"); |
| 722 | MODULE_LICENSE("GPL"); |
| 723 | |
| 724 | |