blob: 7b7393f96a9caca3b1f5718e4ac6b70c65ef2336 [file] [log] [blame]
Alessandro Rubini2ec1d352009-07-02 15:29:12 +01001/*
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 Vincent3e3c62c2010-03-03 04:52:34 +010016#include <linux/platform_device.h>
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010017#include <linux/io.h>
Rabin Vincentaf7dc222010-05-06 11:14:17 +010018#include <linux/clk.h>
19#include <linux/err.h>
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010020#include <linux/gpio.h>
21#include <linux/spinlock.h>
22#include <linux/interrupt.h>
23#include <linux/irq.h>
Tejun Heo5a0e3ad2010-03-24 17:04:11 +090024#include <linux/slab.h>
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010025
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
38struct nmk_gpio_chip {
39 struct gpio_chip chip;
40 void __iomem *addr;
Rabin Vincentaf7dc222010-05-06 11:14:17 +010041 struct clk *clk;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010042 unsigned int parent_irq;
Rabin Vincentc0fcb8d2010-03-03 04:48:54 +010043 spinlock_t lock;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +010044 /* Keep track of configured edges */
45 u32 edge_rising;
46 u32 edge_falling;
47};
48
Rabin Vincent6f9a9742010-06-02 05:50:28 +010049static 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 Vincent81a3c292010-05-27 12:39:23 +010065static 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 Vincent5b327ed2010-05-27 12:29:50 +010079static 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
98/**
Rabin Vincent81a3c292010-05-27 12:39:23 +010099 * nmk_gpio_set_slpm() - configure the sleep mode of a pin
100 * @gpio: pin number
101 * @mode: NMK_GPIO_SLPM_INPUT or NMK_GPIO_SLPM_NOCHANGE,
102 *
103 * Sets the sleep mode of a pin. If @mode is NMK_GPIO_SLPM_INPUT, the pin is
104 * changed to an input (with pullup/down enabled) in sleep and deep sleep. If
105 * @mode is NMK_GPIO_SLPM_NOCHANGE, the pin remains in the state it was
106 * configured even when in sleep and deep sleep.
107 */
108int nmk_gpio_set_slpm(int gpio, enum nmk_gpio_slpm mode)
109{
110 struct nmk_gpio_chip *nmk_chip;
111 unsigned long flags;
112
113 nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
114 if (!nmk_chip)
115 return -EINVAL;
116
117 spin_lock_irqsave(&nmk_chip->lock, flags);
118 __nmk_gpio_set_slpm(nmk_chip, gpio - nmk_chip->chip.base, mode);
119 spin_unlock_irqrestore(&nmk_chip->lock, flags);
120
121 return 0;
122}
123
124/**
Rabin Vincent5b327ed2010-05-27 12:29:50 +0100125 * nmk_gpio_set_pull() - enable/disable pull up/down on a gpio
126 * @gpio: pin number
127 * @pull: one of NMK_GPIO_PULL_DOWN, NMK_GPIO_PULL_UP, and NMK_GPIO_PULL_NONE
128 *
129 * Enables/disables pull up/down on a specified pin. This only takes effect if
130 * the pin is configured as an input (either explicitly or by the alternate
131 * function).
132 *
133 * NOTE: If enabling the pull up/down, the caller must ensure that the GPIO is
134 * configured as an input. Otherwise, due to the way the controller registers
135 * work, this function will change the value output on the pin.
136 */
137int nmk_gpio_set_pull(int gpio, enum nmk_gpio_pull pull)
138{
139 struct nmk_gpio_chip *nmk_chip;
140 unsigned long flags;
141
142 nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
143 if (!nmk_chip)
144 return -EINVAL;
145
146 spin_lock_irqsave(&nmk_chip->lock, flags);
147 __nmk_gpio_set_pull(nmk_chip, gpio - nmk_chip->chip.base, pull);
148 spin_unlock_irqrestore(&nmk_chip->lock, flags);
149
150 return 0;
151}
152
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100153/* Mode functions */
154int nmk_gpio_set_mode(int gpio, int gpio_mode)
155{
156 struct nmk_gpio_chip *nmk_chip;
157 unsigned long flags;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100158
159 nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
160 if (!nmk_chip)
161 return -EINVAL;
162
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100163 spin_lock_irqsave(&nmk_chip->lock, flags);
Rabin Vincent6f9a9742010-06-02 05:50:28 +0100164 __nmk_gpio_set_mode(nmk_chip, gpio - nmk_chip->chip.base, gpio_mode);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100165 spin_unlock_irqrestore(&nmk_chip->lock, flags);
166
167 return 0;
168}
169EXPORT_SYMBOL(nmk_gpio_set_mode);
170
171int nmk_gpio_get_mode(int gpio)
172{
173 struct nmk_gpio_chip *nmk_chip;
174 u32 afunc, bfunc, bit;
175
176 nmk_chip = get_irq_chip_data(NOMADIK_GPIO_TO_IRQ(gpio));
177 if (!nmk_chip)
178 return -EINVAL;
179
180 bit = 1 << (gpio - nmk_chip->chip.base);
181
182 afunc = readl(nmk_chip->addr + NMK_GPIO_AFSLA) & bit;
183 bfunc = readl(nmk_chip->addr + NMK_GPIO_AFSLB) & bit;
184
185 return (afunc ? NMK_GPIO_ALT_A : 0) | (bfunc ? NMK_GPIO_ALT_B : 0);
186}
187EXPORT_SYMBOL(nmk_gpio_get_mode);
188
189
190/* IRQ functions */
191static inline int nmk_gpio_get_bitmask(int gpio)
192{
193 return 1 << (gpio % 32);
194}
195
196static void nmk_gpio_irq_ack(unsigned int irq)
197{
198 int gpio;
199 struct nmk_gpio_chip *nmk_chip;
200
201 gpio = NOMADIK_IRQ_TO_GPIO(irq);
202 nmk_chip = get_irq_chip_data(irq);
203 if (!nmk_chip)
204 return;
205 writel(nmk_gpio_get_bitmask(gpio), nmk_chip->addr + NMK_GPIO_IC);
206}
207
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100208static void __nmk_gpio_irq_modify(struct nmk_gpio_chip *nmk_chip,
209 int gpio, bool enable)
210{
211 u32 bitmask = nmk_gpio_get_bitmask(gpio);
212 u32 reg;
213
214 /* we must individually set/clear the two edges */
215 if (nmk_chip->edge_rising & bitmask) {
216 reg = readl(nmk_chip->addr + NMK_GPIO_RIMSC);
217 if (enable)
218 reg |= bitmask;
219 else
220 reg &= ~bitmask;
221 writel(reg, nmk_chip->addr + NMK_GPIO_RIMSC);
222 }
223 if (nmk_chip->edge_falling & bitmask) {
224 reg = readl(nmk_chip->addr + NMK_GPIO_FIMSC);
225 if (enable)
226 reg |= bitmask;
227 else
228 reg &= ~bitmask;
229 writel(reg, nmk_chip->addr + NMK_GPIO_FIMSC);
230 }
231}
232
233static void nmk_gpio_irq_modify(unsigned int irq, bool enable)
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100234{
235 int gpio;
236 struct nmk_gpio_chip *nmk_chip;
237 unsigned long flags;
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100238 u32 bitmask;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100239
240 gpio = NOMADIK_IRQ_TO_GPIO(irq);
241 nmk_chip = get_irq_chip_data(irq);
242 bitmask = nmk_gpio_get_bitmask(gpio);
243 if (!nmk_chip)
244 return;
245
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100246 spin_lock_irqsave(&nmk_chip->lock, flags);
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100247 __nmk_gpio_irq_modify(nmk_chip, gpio, enable);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100248 spin_unlock_irqrestore(&nmk_chip->lock, flags);
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100249}
250
251static void nmk_gpio_irq_mask(unsigned int irq)
252{
253 nmk_gpio_irq_modify(irq, false);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100254};
255
256static void nmk_gpio_irq_unmask(unsigned int irq)
257{
Rabin Vincent040e5ec2010-05-06 10:42:42 +0100258 nmk_gpio_irq_modify(irq, true);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100259}
260
261static int nmk_gpio_irq_set_type(unsigned int irq, unsigned int type)
262{
Rabin Vincent7a852d82010-05-06 10:43:55 +0100263 bool enabled = !(irq_to_desc(irq)->status & IRQ_DISABLED);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100264 int gpio;
265 struct nmk_gpio_chip *nmk_chip;
266 unsigned long flags;
267 u32 bitmask;
268
269 gpio = NOMADIK_IRQ_TO_GPIO(irq);
270 nmk_chip = get_irq_chip_data(irq);
271 bitmask = nmk_gpio_get_bitmask(gpio);
272 if (!nmk_chip)
273 return -EINVAL;
274
275 if (type & IRQ_TYPE_LEVEL_HIGH)
276 return -EINVAL;
277 if (type & IRQ_TYPE_LEVEL_LOW)
278 return -EINVAL;
279
280 spin_lock_irqsave(&nmk_chip->lock, flags);
281
Rabin Vincent7a852d82010-05-06 10:43:55 +0100282 if (enabled)
283 __nmk_gpio_irq_modify(nmk_chip, gpio, false);
284
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100285 nmk_chip->edge_rising &= ~bitmask;
286 if (type & IRQ_TYPE_EDGE_RISING)
287 nmk_chip->edge_rising |= bitmask;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100288
289 nmk_chip->edge_falling &= ~bitmask;
290 if (type & IRQ_TYPE_EDGE_FALLING)
291 nmk_chip->edge_falling |= bitmask;
Rabin Vincent7a852d82010-05-06 10:43:55 +0100292
293 if (enabled)
294 __nmk_gpio_irq_modify(nmk_chip, gpio, true);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100295
296 spin_unlock_irqrestore(&nmk_chip->lock, flags);
297
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100298 return 0;
299}
300
301static struct irq_chip nmk_gpio_irq_chip = {
302 .name = "Nomadik-GPIO",
303 .ack = nmk_gpio_irq_ack,
304 .mask = nmk_gpio_irq_mask,
305 .unmask = nmk_gpio_irq_unmask,
306 .set_type = nmk_gpio_irq_set_type,
307};
308
309static void nmk_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
310{
311 struct nmk_gpio_chip *nmk_chip;
Rabin Vincentaaedaa22010-03-03 04:50:27 +0100312 struct irq_chip *host_chip = get_irq_chip(irq);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100313 unsigned int gpio_irq;
314 u32 pending;
315 unsigned int first_irq;
316
Rabin Vincentaaedaa22010-03-03 04:50:27 +0100317 if (host_chip->mask_ack)
318 host_chip->mask_ack(irq);
319 else {
320 host_chip->mask(irq);
321 if (host_chip->ack)
322 host_chip->ack(irq);
323 }
324
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100325 nmk_chip = get_irq_data(irq);
326 first_irq = NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base);
327 while ( (pending = readl(nmk_chip->addr + NMK_GPIO_IS)) ) {
328 gpio_irq = first_irq + __ffs(pending);
329 generic_handle_irq(gpio_irq);
330 }
Rabin Vincentaaedaa22010-03-03 04:50:27 +0100331
332 host_chip->unmask(irq);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100333}
334
335static int nmk_gpio_init_irq(struct nmk_gpio_chip *nmk_chip)
336{
337 unsigned int first_irq;
338 int i;
339
340 first_irq = NOMADIK_GPIO_TO_IRQ(nmk_chip->chip.base);
341 for (i = first_irq; i < first_irq + NMK_GPIO_PER_CHIP; i++) {
342 set_irq_chip(i, &nmk_gpio_irq_chip);
343 set_irq_handler(i, handle_edge_irq);
344 set_irq_flags(i, IRQF_VALID);
345 set_irq_chip_data(i, nmk_chip);
Rabin Vincent2210d642010-05-06 10:45:18 +0100346 set_irq_type(i, IRQ_TYPE_EDGE_FALLING);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100347 }
348 set_irq_chained_handler(nmk_chip->parent_irq, nmk_gpio_irq_handler);
349 set_irq_data(nmk_chip->parent_irq, nmk_chip);
350 return 0;
351}
352
353/* I/O Functions */
354static int nmk_gpio_make_input(struct gpio_chip *chip, unsigned offset)
355{
356 struct nmk_gpio_chip *nmk_chip =
357 container_of(chip, struct nmk_gpio_chip, chip);
358
359 writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRC);
360 return 0;
361}
362
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100363static int nmk_gpio_get_input(struct gpio_chip *chip, unsigned offset)
364{
365 struct nmk_gpio_chip *nmk_chip =
366 container_of(chip, struct nmk_gpio_chip, chip);
367 u32 bit = 1 << offset;
368
369 return (readl(nmk_chip->addr + NMK_GPIO_DAT) & bit) != 0;
370}
371
372static void nmk_gpio_set_output(struct gpio_chip *chip, unsigned offset,
373 int val)
374{
375 struct nmk_gpio_chip *nmk_chip =
376 container_of(chip, struct nmk_gpio_chip, chip);
377 u32 bit = 1 << offset;
378
379 if (val)
380 writel(bit, nmk_chip->addr + NMK_GPIO_DATS);
381 else
382 writel(bit, nmk_chip->addr + NMK_GPIO_DATC);
383}
384
Rabin Vincent6647c6c2010-05-27 12:22:42 +0100385static int nmk_gpio_make_output(struct gpio_chip *chip, unsigned offset,
386 int val)
387{
388 struct nmk_gpio_chip *nmk_chip =
389 container_of(chip, struct nmk_gpio_chip, chip);
390
391 writel(1 << offset, nmk_chip->addr + NMK_GPIO_DIRS);
392 nmk_gpio_set_output(chip, offset, val);
393
394 return 0;
395}
396
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100397/* This structure is replicated for each GPIO block allocated at probe time */
398static struct gpio_chip nmk_gpio_template = {
399 .direction_input = nmk_gpio_make_input,
400 .get = nmk_gpio_get_input,
401 .direction_output = nmk_gpio_make_output,
402 .set = nmk_gpio_set_output,
403 .ngpio = NMK_GPIO_PER_CHIP,
404 .can_sleep = 0,
405};
406
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100407static int __init nmk_gpio_probe(struct platform_device *dev)
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100408{
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100409 struct nmk_gpio_platform_data *pdata = dev->dev.platform_data;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100410 struct nmk_gpio_chip *nmk_chip;
411 struct gpio_chip *chip;
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100412 struct resource *res;
Rabin Vincentaf7dc222010-05-06 11:14:17 +0100413 struct clk *clk;
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100414 int irq;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100415 int ret;
416
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100417 if (!pdata)
418 return -ENODEV;
419
420 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
421 if (!res) {
422 ret = -ENOENT;
423 goto out;
424 }
425
426 irq = platform_get_irq(dev, 0);
427 if (irq < 0) {
428 ret = irq;
429 goto out;
430 }
431
432 if (request_mem_region(res->start, resource_size(res),
433 dev_name(&dev->dev)) == NULL) {
434 ret = -EBUSY;
435 goto out;
436 }
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100437
Rabin Vincentaf7dc222010-05-06 11:14:17 +0100438 clk = clk_get(&dev->dev, NULL);
439 if (IS_ERR(clk)) {
440 ret = PTR_ERR(clk);
441 goto out_release;
442 }
443
444 clk_enable(clk);
445
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100446 nmk_chip = kzalloc(sizeof(*nmk_chip), GFP_KERNEL);
447 if (!nmk_chip) {
448 ret = -ENOMEM;
Rabin Vincentaf7dc222010-05-06 11:14:17 +0100449 goto out_clk;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100450 }
451 /*
452 * The virt address in nmk_chip->addr is in the nomadik register space,
453 * so we can simply convert the resource address, without remapping
454 */
Rabin Vincentaf7dc222010-05-06 11:14:17 +0100455 nmk_chip->clk = clk;
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100456 nmk_chip->addr = io_p2v(res->start);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100457 nmk_chip->chip = nmk_gpio_template;
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100458 nmk_chip->parent_irq = irq;
Rabin Vincentc0fcb8d2010-03-03 04:48:54 +0100459 spin_lock_init(&nmk_chip->lock);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100460
461 chip = &nmk_chip->chip;
462 chip->base = pdata->first_gpio;
463 chip->label = pdata->name;
464 chip->dev = &dev->dev;
465 chip->owner = THIS_MODULE;
466
467 ret = gpiochip_add(&nmk_chip->chip);
468 if (ret)
469 goto out_free;
470
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100471 platform_set_drvdata(dev, nmk_chip);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100472
473 nmk_gpio_init_irq(nmk_chip);
474
475 dev_info(&dev->dev, "Bits %i-%i at address %p\n",
476 nmk_chip->chip.base, nmk_chip->chip.base+31, nmk_chip->addr);
477 return 0;
478
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100479out_free:
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100480 kfree(nmk_chip);
Rabin Vincentaf7dc222010-05-06 11:14:17 +0100481out_clk:
482 clk_disable(clk);
483 clk_put(clk);
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100484out_release:
485 release_mem_region(res->start, resource_size(res));
486out:
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100487 dev_err(&dev->dev, "Failure %i for GPIO %i-%i\n", ret,
488 pdata->first_gpio, pdata->first_gpio+31);
489 return ret;
490}
491
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100492static int __exit nmk_gpio_remove(struct platform_device *dev)
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100493{
494 struct nmk_gpio_chip *nmk_chip;
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100495 struct resource *res;
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100496
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100497 res = platform_get_resource(dev, IORESOURCE_MEM, 0);
498
499 nmk_chip = platform_get_drvdata(dev);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100500 gpiochip_remove(&nmk_chip->chip);
Rabin Vincentaf7dc222010-05-06 11:14:17 +0100501 clk_disable(nmk_chip->clk);
502 clk_put(nmk_chip->clk);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100503 kfree(nmk_chip);
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100504 release_mem_region(res->start, resource_size(res));
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100505 return 0;
506}
507
508
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100509static struct platform_driver nmk_gpio_driver = {
510 .driver = {
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100511 .owner = THIS_MODULE,
512 .name = "gpio",
513 },
514 .probe = nmk_gpio_probe,
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100515 .remove = __exit_p(nmk_gpio_remove),
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100516 .suspend = NULL, /* to be done */
517 .resume = NULL,
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100518};
519
520static int __init nmk_gpio_init(void)
521{
Rabin Vincent3e3c62c2010-03-03 04:52:34 +0100522 return platform_driver_register(&nmk_gpio_driver);
Alessandro Rubini2ec1d352009-07-02 15:29:12 +0100523}
524
525arch_initcall(nmk_gpio_init);
526
527MODULE_AUTHOR("Prafulla WADASKAR and Alessandro Rubini");
528MODULE_DESCRIPTION("Nomadik GPIO Driver");
529MODULE_LICENSE("GPL");
530
531