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 | |
| 26 | #include <mach/hardware.h> |
| 27 | #include <mach/gpio.h> |
| 28 | |
| 29 | /* |
| 30 | * The GPIO module in the Nomadik family of Systems-on-Chip is an |
| 31 | * AMBA device, managing 32 pins and alternate functions. The logic block |
| 32 | * is currently only used in the Nomadik. |
| 33 | * |
| 34 | * Symbols in this file are called "nmk_gpio" for "nomadik gpio" |
| 35 | */ |
| 36 | |
| 37 | #define NMK_GPIO_PER_CHIP 32 |
| 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 | |
| 49 | /* Mode functions */ |
| 50 | int nmk_gpio_set_mode(int gpio, int gpio_mode) |
| 51 | { |
| 52 | struct nmk_gpio_chip *nmk_chip; |
| 53 | unsigned long flags; |
| 54 | u32 afunc, bfunc, bit; |
| 55 | |
| 56 | nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio)); |
| 57 | if (!nmk_chip) |
| 58 | return -EINVAL; |
| 59 | |
| 60 | bit = 1 << (gpio - nmk_chip->chip.base); |
| 61 | |
| 62 | spin_lock_irqsave(&nmk_chip->lock, flags); |
| 63 | afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & ~bit; |
| 64 | bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & ~bit; |
| 65 | if (gpio_mode & NMK_GPIO_ALT_A) |
| 66 | afunc |= bit; |
| 67 | if (gpio_mode & NMK_GPIO_ALT_B) |
| 68 | bfunc |= bit; |
| 69 | writel(afunc, nmk_chip->addr + NMK_GPIO_AFSLA); |
| 70 | writel(bfunc, nmk_chip->addr + NMK_GPIO_AFSLB); |
| 71 | spin_unlock_irqrestore(&nmk_chip->lock, flags); |
| 72 | |
| 73 | return 0; |
| 74 | } |
| 75 | EXPORT_SYMBOL(nmk_gpio_set_mode); |
| 76 | |
| 77 | int nmk_gpio_get_mode(int gpio) |
| 78 | { |
| 79 | struct nmk_gpio_chip *nmk_chip; |
| 80 | u32 afunc, bfunc, bit; |
| 81 | |
| 82 | nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio)); |
| 83 | if (!nmk_chip) |
| 84 | return -EINVAL; |
| 85 | |
| 86 | bit = 1 << (gpio - nmk_chip->chip.base); |
| 87 | |
| 88 | afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & bit; |
| 89 | bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & bit; |
| 90 | |
| 91 | return (afunc ? NMK_GPIO_ALT_A : 0) | (bfunc ? NMK_GPIO_ALT_B : 0); |
| 92 | } |
| 93 | EXPORT_SYMBOL(nmk_gpio_get_mode); |
| 94 | |
| 95 | |
| 96 | /* IRQ functions */ |
| 97 | static inline int nmk_gpio_get_bitmask(int gpio) |
| 98 | { |
| 99 | return 1 << (gpio % 32); |
| 100 | } |
| 101 | |
| 102 | static void nmk_gpio_irq_ack(unsigned int irq) |
| 103 | { |
| 104 | int gpio; |
| 105 | struct nmk_gpio_chip *nmk_chip; |
| 106 | |
| 107 | gpio = NOMADIK_IRQ_TO_GPIO(irq); |
| 108 | nmk_chip = get_irq_chip_data(irq); |
| 109 | if (!nmk_chip) |
| 110 | return; |
| 111 | writel(nmk_gpio_get_bitmask(gpio), nmk_chip->addr + NMK_GPIO_IC); |
| 112 | } |
| 113 | |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 114 | static void __nmk_gpio_irq_modify(struct nmk_gpio_chip *nmk_chip, |
| 115 | int gpio, bool enable) |
| 116 | { |
| 117 | u32 bitmask = nmk_gpio_get_bitmask(gpio); |
| 118 | u32 reg; |
| 119 | |
| 120 | /* we must individually set/clear the two edges */ |
| 121 | if (nmk_chip->edge_rising & bitmask) { |
| 122 | reg = readl(nmk_chip->addr + NMK_GPIO_RIMSC); |
| 123 | if (enable) |
| 124 | reg |= bitmask; |
| 125 | else |
| 126 | reg &= ~bitmask; |
| 127 | writel(reg, nmk_chip->addr + NMK_GPIO_RIMSC); |
| 128 | } |
| 129 | if (nmk_chip->edge_falling & bitmask) { |
| 130 | reg = readl(nmk_chip->addr + NMK_GPIO_FIMSC); |
| 131 | if (enable) |
| 132 | reg |= bitmask; |
| 133 | else |
| 134 | reg &= ~bitmask; |
| 135 | writel(reg, nmk_chip->addr + NMK_GPIO_FIMSC); |
| 136 | } |
| 137 | } |
| 138 | |
| 139 | static void nmk_gpio_irq_modify(unsigned int irq, bool enable) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 140 | { |
| 141 | int gpio; |
| 142 | struct nmk_gpio_chip *nmk_chip; |
| 143 | unsigned long flags; |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 144 | u32 bitmask; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 145 | |
| 146 | gpio = NOMADIK_IRQ_TO_GPIO(irq); |
| 147 | nmk_chip = get_irq_chip_data(irq); |
| 148 | bitmask = nmk_gpio_get_bitmask(gpio); |
| 149 | if (!nmk_chip) |
| 150 | return; |
| 151 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 152 | spin_lock_irqsave(&nmk_chip->lock, flags); |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 153 | __nmk_gpio_irq_modify(nmk_chip, gpio, enable); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 154 | spin_unlock_irqrestore(&nmk_chip->lock, flags); |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 155 | } |
| 156 | |
| 157 | static void nmk_gpio_irq_mask(unsigned int irq) |
| 158 | { |
| 159 | nmk_gpio_irq_modify(irq, false); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 160 | }; |
| 161 | |
| 162 | static void nmk_gpio_irq_unmask(unsigned int irq) |
| 163 | { |
Rabin Vincent | 040e5ec | 2010-05-06 10:42:42 +0100 | [diff] [blame] | 164 | nmk_gpio_irq_modify(irq, true); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 165 | } |
| 166 | |
| 167 | static int nmk_gpio_irq_set_type(unsigned int irq, unsigned int type) |
| 168 | { |
Rabin Vincent | 7a852d8 | 2010-05-06 10:43:55 +0100 | [diff] [blame] | 169 | bool enabled = !(irq_to_desc(irq)->status & IRQ_DISABLED); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 170 | int gpio; |
| 171 | struct nmk_gpio_chip *nmk_chip; |
| 172 | unsigned long flags; |
| 173 | u32 bitmask; |
| 174 | |
| 175 | gpio = NOMADIK_IRQ_TO_GPIO(irq); |
| 176 | nmk_chip = get_irq_chip_data(irq); |
| 177 | bitmask = nmk_gpio_get_bitmask(gpio); |
| 178 | if (!nmk_chip) |
| 179 | return -EINVAL; |
| 180 | |
| 181 | if (type & IRQ_TYPE_LEVEL_HIGH) |
| 182 | return -EINVAL; |
| 183 | if (type & IRQ_TYPE_LEVEL_LOW) |
| 184 | return -EINVAL; |
| 185 | |
| 186 | spin_lock_irqsave(&nmk_chip->lock, flags); |
| 187 | |
Rabin Vincent | 7a852d8 | 2010-05-06 10:43:55 +0100 | [diff] [blame] | 188 | if (enabled) |
| 189 | __nmk_gpio_irq_modify(nmk_chip, gpio, false); |
| 190 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 191 | nmk_chip->edge_rising &= ~bitmask; |
| 192 | if (type & IRQ_TYPE_EDGE_RISING) |
| 193 | nmk_chip->edge_rising |= bitmask; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 194 | |
| 195 | nmk_chip->edge_falling &= ~bitmask; |
| 196 | if (type & IRQ_TYPE_EDGE_FALLING) |
| 197 | nmk_chip->edge_falling |= bitmask; |
Rabin Vincent | 7a852d8 | 2010-05-06 10:43:55 +0100 | [diff] [blame] | 198 | |
| 199 | if (enabled) |
| 200 | __nmk_gpio_irq_modify(nmk_chip, gpio, true); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 201 | |
| 202 | spin_unlock_irqrestore(&nmk_chip->lock, flags); |
| 203 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 204 | return 0; |
| 205 | } |
| 206 | |
| 207 | static struct irq_chip nmk_gpio_irq_chip = { |
| 208 | .name = "Nomadik-GPIO", |
| 209 | .ack = nmk_gpio_irq_ack, |
| 210 | .mask = nmk_gpio_irq_mask, |
| 211 | .unmask = nmk_gpio_irq_unmask, |
| 212 | .set_type = nmk_gpio_irq_set_type, |
| 213 | }; |
| 214 | |
| 215 | static void nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc) |
| 216 | { |
| 217 | struct nmk_gpio_chip *nmk_chip; |
Rabin Vincent | aaedaa2 | 2010-03-03 04:50:27 +0100 | [diff] [blame] | 218 | struct irq_chip *host_chip = get_irq_chip(irq); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 219 | unsigned int gpio_irq; |
| 220 | u32 pending; |
| 221 | unsigned int first_irq; |
| 222 | |
Rabin Vincent | aaedaa2 | 2010-03-03 04:50:27 +0100 | [diff] [blame] | 223 | if (host_chip->mask_ack) |
| 224 | host_chip->mask_ack(irq); |
| 225 | else { |
| 226 | host_chip->mask(irq); |
| 227 | if (host_chip->ack) |
| 228 | host_chip->ack(irq); |
| 229 | } |
| 230 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 231 | nmk_chip = get_irq_data(irq); |
| 232 | first_irq = NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base); |
| 233 | while ( (pending = readl(nmk_chip->addr + NMK_GPIO_IS)) ) { |
| 234 | gpio_irq = first_irq + __ffs(pending); |
| 235 | generic_handle_irq(gpio_irq); |
| 236 | } |
Rabin Vincent | aaedaa2 | 2010-03-03 04:50:27 +0100 | [diff] [blame] | 237 | |
| 238 | host_chip->unmask(irq); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 239 | } |
| 240 | |
| 241 | static int nmk_gpio_init_irq(struct nmk_gpio_chip *nmk_chip) |
| 242 | { |
| 243 | unsigned int first_irq; |
| 244 | int i; |
| 245 | |
| 246 | first_irq = NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base); |
| 247 | for (i = first_irq; i < first_irq + NMK_GPIO_PER_CHIP; i++) { |
| 248 | set_irq_chip(i, &nmk_gpio_irq_chip); |
| 249 | set_irq_handler(i, handle_edge_irq); |
| 250 | set_irq_flags(i, IRQF_VALID); |
| 251 | set_irq_chip_data(i, nmk_chip); |
Rabin Vincent | 2210d64 | 2010-05-06 10:45:18 +0100 | [diff] [blame] | 252 | set_irq_type(i, IRQ_TYPE_EDGE_FALLING); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 253 | } |
| 254 | set_irq_chained_handler(nmk_chip->parent_irq, nmk_gpio_irq_handler); |
| 255 | set_irq_data(nmk_chip->parent_irq, nmk_chip); |
| 256 | return 0; |
| 257 | } |
| 258 | |
| 259 | /* I/O Functions */ |
| 260 | static int nmk_gpio_make_input(struct gpio_chip *chip, unsigned offset) |
| 261 | { |
| 262 | struct nmk_gpio_chip *nmk_chip = |
| 263 | container_of(chip, struct nmk_gpio_chip, chip); |
| 264 | |
| 265 | writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC); |
| 266 | return 0; |
| 267 | } |
| 268 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 269 | static int nmk_gpio_get_input(struct gpio_chip *chip, unsigned offset) |
| 270 | { |
| 271 | struct nmk_gpio_chip *nmk_chip = |
| 272 | container_of(chip, struct nmk_gpio_chip, chip); |
| 273 | u32 bit = 1 << offset; |
| 274 | |
| 275 | return (readl(nmk_chip->addr + NMK_GPIO_DAT) & bit) != 0; |
| 276 | } |
| 277 | |
| 278 | static void nmk_gpio_set_output(struct gpio_chip *chip, unsigned offset, |
| 279 | int val) |
| 280 | { |
| 281 | struct nmk_gpio_chip *nmk_chip = |
| 282 | container_of(chip, struct nmk_gpio_chip, chip); |
| 283 | u32 bit = 1 << offset; |
| 284 | |
| 285 | if (val) |
| 286 | writel(bit, nmk_chip->addr + NMK_GPIO_DATS); |
| 287 | else |
| 288 | writel(bit, nmk_chip->addr + NMK_GPIO_DATC); |
| 289 | } |
| 290 | |
Rabin Vincent | 6647c6c | 2010-05-27 12:22:42 +0100 | [diff] [blame^] | 291 | static int nmk_gpio_make_output(struct gpio_chip *chip, unsigned offset, |
| 292 | int val) |
| 293 | { |
| 294 | struct nmk_gpio_chip *nmk_chip = |
| 295 | container_of(chip, struct nmk_gpio_chip, chip); |
| 296 | |
| 297 | writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRS); |
| 298 | nmk_gpio_set_output(chip, offset, val); |
| 299 | |
| 300 | return 0; |
| 301 | } |
| 302 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 303 | /* This structure is replicated for each GPIO block allocated at probe time */ |
| 304 | static struct gpio_chip nmk_gpio_template = { |
| 305 | .direction_input = nmk_gpio_make_input, |
| 306 | .get = nmk_gpio_get_input, |
| 307 | .direction_output = nmk_gpio_make_output, |
| 308 | .set = nmk_gpio_set_output, |
| 309 | .ngpio = NMK_GPIO_PER_CHIP, |
| 310 | .can_sleep = 0, |
| 311 | }; |
| 312 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 313 | static int __init nmk_gpio_probe(struct platform_device *dev) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 314 | { |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 315 | struct nmk_gpio_platform_data *pdata = dev->dev.platform_data; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 316 | struct nmk_gpio_chip *nmk_chip; |
| 317 | struct gpio_chip *chip; |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 318 | struct resource *res; |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 319 | struct clk *clk; |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 320 | int irq; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 321 | int ret; |
| 322 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 323 | if (!pdata) |
| 324 | return -ENODEV; |
| 325 | |
| 326 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); |
| 327 | if (!res) { |
| 328 | ret = -ENOENT; |
| 329 | goto out; |
| 330 | } |
| 331 | |
| 332 | irq = platform_get_irq(dev, 0); |
| 333 | if (irq < 0) { |
| 334 | ret = irq; |
| 335 | goto out; |
| 336 | } |
| 337 | |
| 338 | if (request_mem_region(res->start, resource_size(res), |
| 339 | dev_name(&dev->dev)) == NULL) { |
| 340 | ret = -EBUSY; |
| 341 | goto out; |
| 342 | } |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 343 | |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 344 | clk = clk_get(&dev->dev, NULL); |
| 345 | if (IS_ERR(clk)) { |
| 346 | ret = PTR_ERR(clk); |
| 347 | goto out_release; |
| 348 | } |
| 349 | |
| 350 | clk_enable(clk); |
| 351 | |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 352 | nmk_chip = kzalloc(sizeof(*nmk_chip), GFP_KERNEL); |
| 353 | if (!nmk_chip) { |
| 354 | ret = -ENOMEM; |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 355 | goto out_clk; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 356 | } |
| 357 | /* |
| 358 | * The virt address in nmk_chip->addr is in the nomadik register space, |
| 359 | * so we can simply convert the resource address, without remapping |
| 360 | */ |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 361 | nmk_chip->clk = clk; |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 362 | nmk_chip->addr = io_p2v(res->start); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 363 | nmk_chip->chip = nmk_gpio_template; |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 364 | nmk_chip->parent_irq = irq; |
Rabin Vincent | c0fcb8d | 2010-03-03 04:48:54 +0100 | [diff] [blame] | 365 | spin_lock_init(&nmk_chip->lock); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 366 | |
| 367 | chip = &nmk_chip->chip; |
| 368 | chip->base = pdata->first_gpio; |
| 369 | chip->label = pdata->name; |
| 370 | chip->dev = &dev->dev; |
| 371 | chip->owner = THIS_MODULE; |
| 372 | |
| 373 | ret = gpiochip_add(&nmk_chip->chip); |
| 374 | if (ret) |
| 375 | goto out_free; |
| 376 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 377 | platform_set_drvdata(dev, nmk_chip); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 378 | |
| 379 | nmk_gpio_init_irq(nmk_chip); |
| 380 | |
| 381 | dev_info(&dev->dev, "Bits %i-%i at address %p\n", |
| 382 | nmk_chip->chip.base, nmk_chip->chip.base+31, nmk_chip->addr); |
| 383 | return 0; |
| 384 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 385 | out_free: |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 386 | kfree(nmk_chip); |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 387 | out_clk: |
| 388 | clk_disable(clk); |
| 389 | clk_put(clk); |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 390 | out_release: |
| 391 | release_mem_region(res->start, resource_size(res)); |
| 392 | out: |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 393 | dev_err(&dev->dev, "Failure %i for GPIO %i-%i\n", ret, |
| 394 | pdata->first_gpio, pdata->first_gpio+31); |
| 395 | return ret; |
| 396 | } |
| 397 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 398 | static int __exit nmk_gpio_remove(struct platform_device *dev) |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 399 | { |
| 400 | struct nmk_gpio_chip *nmk_chip; |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 401 | struct resource *res; |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 402 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 403 | res = platform_get_resource(dev, IORESOURCE_MEM, 0); |
| 404 | |
| 405 | nmk_chip = platform_get_drvdata(dev); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 406 | gpiochip_remove(&nmk_chip->chip); |
Rabin Vincent | af7dc22 | 2010-05-06 11:14:17 +0100 | [diff] [blame] | 407 | clk_disable(nmk_chip->clk); |
| 408 | clk_put(nmk_chip->clk); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 409 | kfree(nmk_chip); |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 410 | release_mem_region(res->start, resource_size(res)); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 411 | return 0; |
| 412 | } |
| 413 | |
| 414 | |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 415 | static struct platform_driver nmk_gpio_driver = { |
| 416 | .driver = { |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 417 | .owner = THIS_MODULE, |
| 418 | .name = "gpio", |
| 419 | }, |
| 420 | .probe = nmk_gpio_probe, |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 421 | .remove = __exit_p(nmk_gpio_remove), |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 422 | .suspend = NULL, /* to be done */ |
| 423 | .resume = NULL, |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 424 | }; |
| 425 | |
| 426 | static int __init nmk_gpio_init(void) |
| 427 | { |
Rabin Vincent | 3e3c62c | 2010-03-03 04:52:34 +0100 | [diff] [blame] | 428 | return platform_driver_register(&nmk_gpio_driver); |
Alessandro Rubini | 2ec1d35 | 2009-07-02 15:29:12 +0100 | [diff] [blame] | 429 | } |
| 430 | |
| 431 | arch_initcall(nmk_gpio_init); |
| 432 | |
| 433 | MODULE_AUTHOR("Prafulla WADASKAR and Alessandro Rubini"); |
| 434 | MODULE_DESCRIPTION("Nomadik GPIO Driver"); |
| 435 | MODULE_LICENSE("GPL"); |
| 436 | |
| 437 | |