]> rtime.felk.cvut.cz Git - sojka/nv-tegra/linux-3.10.git/blob - drivers/gpio/gpio-tegra.c
gpio: tegra: Enable pinctrl_request_gpio
[sojka/nv-tegra/linux-3.10.git] / drivers / gpio / gpio-tegra.c
1 /*
2  * arch/arm/mach-tegra/gpio.c
3  *
4  * Copyright (c) 2010 Google, Inc
5  *
6  * Author:
7  *      Erik Gilling <konkers@google.com>
8  *
9  * Copyright (c) 2011-2013, NVIDIA CORPORATION.  All rights reserved.
10  *
11  * This software is licensed under the terms of the GNU General Public
12  * License version 2, as published by the Free Software Foundation, and
13  * may be copied, distributed, and modified under those terms.
14  *
15  * This program is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU General Public License for more details.
19  *
20  */
21
22 #include <linux/err.h>
23 #include <linux/init.h>
24 #include <linux/irq.h>
25 #include <linux/interrupt.h>
26 #include <linux/io.h>
27 #include <linux/gpio.h>
28 #include <linux/of_device.h>
29 #include <linux/platform_device.h>
30 #include <linux/module.h>
31 #include <linux/delay.h>
32 #include <linux/irqdomain.h>
33 #include <linux/irqchip/chained_irq.h>
34 #include <linux/pinctrl/consumer.h>
35 #include <linux/pm.h>
36 #include <linux/syscore_ops.h>
37 #include <linux/tegra-soc.h>
38 #include <linux/irqchip/tegra.h>
39
40 #define GPIO_BANK(x)            ((x) >> 5)
41 #define GPIO_PORT(x)            (((x) >> 3) & 0x3)
42 #define GPIO_BIT(x)             ((x) & 0x7)
43
44 #define GPIO_REG(x)             (GPIO_BANK(x) * tegra_gpio_bank_stride + \
45                                         GPIO_PORT(x) * 4)
46
47 #define GPIO_CNF(x)             (GPIO_REG(x) + 0x00)
48 #define GPIO_OE(x)              (GPIO_REG(x) + 0x10)
49 #define GPIO_OUT(x)             (GPIO_REG(x) + 0X20)
50 #define GPIO_IN(x)              (GPIO_REG(x) + 0x30)
51 #define GPIO_INT_STA(x)         (GPIO_REG(x) + 0x40)
52 #define GPIO_INT_ENB(x)         (GPIO_REG(x) + 0x50)
53 #define GPIO_INT_LVL(x)         (GPIO_REG(x) + 0x60)
54 #define GPIO_INT_CLR(x)         (GPIO_REG(x) + 0x70)
55
56 #define GPIO_MSK_CNF(x)         (GPIO_REG(x) + tegra_gpio_upper_offset + 0x00)
57 #define GPIO_MSK_OE(x)          (GPIO_REG(x) + tegra_gpio_upper_offset + 0x10)
58 #define GPIO_MSK_OUT(x)         (GPIO_REG(x) + tegra_gpio_upper_offset + 0X20)
59 #define GPIO_MSK_INT_STA(x)     (GPIO_REG(x) + tegra_gpio_upper_offset + 0x40)
60 #define GPIO_MSK_INT_ENB(x)     (GPIO_REG(x) + tegra_gpio_upper_offset + 0x50)
61 #define GPIO_MSK_INT_LVL(x)     (GPIO_REG(x) + tegra_gpio_upper_offset + 0x60)
62
63 #define GPIO_INT_LVL_MASK               0x010101
64 #define GPIO_INT_LVL_EDGE_RISING        0x000101
65 #define GPIO_INT_LVL_EDGE_FALLING       0x000100
66 #define GPIO_INT_LVL_EDGE_BOTH          0x010100
67 #define GPIO_INT_LVL_LEVEL_HIGH         0x000001
68 #define GPIO_INT_LVL_LEVEL_LOW          0x000000
69
70 struct tegra_gpio_bank {
71         int bank;
72         int irq;
73         spinlock_t lvl_lock[4];
74 #ifdef CONFIG_PM_SLEEP
75         u32 cnf[4];
76         u32 out[4];
77         u32 oe[4];
78         u32 int_enb[4];
79         u32 int_lvl[4];
80         u32 wake_enb[4];
81         int wake_depth;
82 #endif
83 };
84
85 static struct irq_domain *irq_domain;
86 static void __iomem *regs;
87
88 static u32 tegra_gpio_bank_count;
89 static u32 tegra_gpio_bank_stride;
90 static u32 tegra_gpio_upper_offset;
91 static struct tegra_gpio_bank *tegra_gpio_banks;
92
93 static inline void tegra_gpio_writel(u32 val, u32 reg)
94 {
95         __raw_writel(val, regs + reg);
96 }
97
98 static inline u32 tegra_gpio_readl(u32 reg)
99 {
100         return __raw_readl(regs + reg);
101 }
102
103 static int tegra_gpio_compose(int bank, int port, int bit)
104 {
105         return (bank << 5) | ((port & 0x3) << 3) | (bit & 0x7);
106 }
107
108 static void tegra_gpio_mask_write(u32 reg, int gpio, int value)
109 {
110         u32 val;
111
112         val = 0x100 << GPIO_BIT(gpio);
113         if (value)
114                 val |= 1 << GPIO_BIT(gpio);
115         tegra_gpio_writel(val, reg);
116 }
117
118 int tegra_gpio_get_bank_int_nr(int gpio)
119 {
120         int bank;
121         int irq;
122         bank = gpio >> 5;
123         irq = tegra_gpio_banks[bank].irq;
124         return irq;
125 }
126
127 static void tegra_gpio_enable(int gpio)
128 {
129         tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 1);
130 }
131
132 int tegra_is_gpio(int gpio)
133 {
134         return (tegra_gpio_readl(GPIO_CNF(gpio)) >> GPIO_BIT(gpio)) & 0x1;
135 }
136 EXPORT_SYMBOL(tegra_is_gpio);
137
138
139 static void tegra_gpio_disable(int gpio)
140 {
141         tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 0);
142 }
143
144 void tegra_gpio_init_configure(unsigned gpio, bool is_input, int value)
145 {
146         if (is_input) {
147                 tegra_gpio_mask_write(GPIO_MSK_OE(gpio), gpio, 0);
148         } else {
149                 tegra_gpio_mask_write(GPIO_MSK_OUT(gpio), gpio, value);
150                 tegra_gpio_mask_write(GPIO_MSK_OE(gpio), gpio, 1);
151         }
152         tegra_gpio_mask_write(GPIO_MSK_CNF(gpio), gpio, 1);
153 }
154
155 static int tegra_gpio_request(struct gpio_chip *chip, unsigned offset)
156 {
157         return pinctrl_request_gpio(offset);
158 }
159
160 static void tegra_gpio_free(struct gpio_chip *chip, unsigned offset)
161 {
162         pinctrl_free_gpio(offset);
163         tegra_gpio_disable(offset);
164 }
165
166 static void tegra_gpio_set(struct gpio_chip *chip, unsigned offset, int value)
167 {
168         tegra_gpio_mask_write(GPIO_MSK_OUT(offset), offset, value);
169 }
170
171 static int tegra_gpio_get(struct gpio_chip *chip, unsigned offset)
172 {
173         /* If gpio is in output mode then read from the out value */
174         if ((tegra_gpio_readl(GPIO_OE(offset)) >> GPIO_BIT(offset)) & 1)
175                 return (tegra_gpio_readl(GPIO_OUT(offset)) >>
176                                 GPIO_BIT(offset)) & 0x1;
177
178         return (tegra_gpio_readl(GPIO_IN(offset)) >> GPIO_BIT(offset)) & 0x1;
179 }
180
181 static int tegra_gpio_direction_input(struct gpio_chip *chip, unsigned offset)
182 {
183         tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 0);
184         tegra_gpio_enable(offset);
185         return 0;
186 }
187
188 static int tegra_gpio_direction_output(struct gpio_chip *chip, unsigned offset,
189                                         int value)
190 {
191         tegra_gpio_set(chip, offset, value);
192         tegra_gpio_mask_write(GPIO_MSK_OE(offset), offset, 1);
193         tegra_gpio_enable(offset);
194         return 0;
195 }
196
197 static int tegra_gpio_set_debounce(struct gpio_chip *chip, unsigned offset,
198                                 unsigned debounce)
199 {
200         return -ENOSYS;
201 }
202
203 static int tegra_gpio_to_irq(struct gpio_chip *chip, unsigned offset)
204 {
205         return irq_find_mapping(irq_domain, offset);
206 }
207
208 static struct gpio_chip tegra_gpio_chip = {
209         .label                  = "tegra-gpio",
210         .request                = tegra_gpio_request,
211         .free                   = tegra_gpio_free,
212         .direction_input        = tegra_gpio_direction_input,
213         .get                    = tegra_gpio_get,
214         .direction_output       = tegra_gpio_direction_output,
215         .set                    = tegra_gpio_set,
216         .set_debounce           = tegra_gpio_set_debounce,
217         .to_irq                 = tegra_gpio_to_irq,
218         .base                   = 0,
219 };
220
221 static void tegra_gpio_irq_ack(struct irq_data *d)
222 {
223         int gpio = d->hwirq;
224
225         tegra_gpio_writel(1 << GPIO_BIT(gpio), GPIO_INT_CLR(gpio));
226
227         /* FPGA platforms have a serializer between the GPIO
228            block and interrupt controller. Allow time for
229            clearing of the GPIO interrupt to propagate to the
230            interrupt controller before re-enabling the IRQ
231            to prevent double interrupts. */
232         if (tegra_platform_is_fpga())
233                 udelay(15);
234 }
235
236 static void tegra_gpio_irq_mask(struct irq_data *d)
237 {
238         int gpio = d->hwirq;
239
240         tegra_gpio_mask_write(GPIO_MSK_INT_ENB(gpio), gpio, 0);
241 }
242
243 static void tegra_gpio_irq_unmask(struct irq_data *d)
244 {
245         int gpio = d->hwirq;
246
247         tegra_gpio_mask_write(GPIO_MSK_INT_ENB(gpio), gpio, 1);
248 }
249
250 static int tegra_gpio_irq_set_type(struct irq_data *d, unsigned int type)
251 {
252         int gpio = d->hwirq;
253         struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d);
254         int port = GPIO_PORT(gpio);
255         int lvl_type;
256         int val;
257         unsigned long flags;
258         int wake = tegra_gpio_to_wake(d->hwirq);
259
260         switch (type & IRQ_TYPE_SENSE_MASK) {
261         case IRQ_TYPE_EDGE_RISING:
262                 lvl_type = GPIO_INT_LVL_EDGE_RISING;
263                 break;
264
265         case IRQ_TYPE_EDGE_FALLING:
266                 lvl_type = GPIO_INT_LVL_EDGE_FALLING;
267                 break;
268
269         case IRQ_TYPE_EDGE_BOTH:
270                 lvl_type = GPIO_INT_LVL_EDGE_BOTH;
271                 break;
272
273         case IRQ_TYPE_LEVEL_HIGH:
274                 lvl_type = GPIO_INT_LVL_LEVEL_HIGH;
275                 break;
276
277         case IRQ_TYPE_LEVEL_LOW:
278                 lvl_type = GPIO_INT_LVL_LEVEL_LOW;
279                 break;
280
281         default:
282                 return -EINVAL;
283         }
284
285         spin_lock_irqsave(&bank->lvl_lock[port], flags);
286
287         val = tegra_gpio_readl(GPIO_INT_LVL(gpio));
288         val &= ~(GPIO_INT_LVL_MASK << GPIO_BIT(gpio));
289         val |= lvl_type << GPIO_BIT(gpio);
290         tegra_gpio_writel(val, GPIO_INT_LVL(gpio));
291
292         spin_unlock_irqrestore(&bank->lvl_lock[port], flags);
293
294         tegra_gpio_mask_write(GPIO_MSK_OE(gpio), gpio, 0);
295         tegra_gpio_enable(gpio);
296
297         if (type & (IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
298                 __irq_set_handler_locked(d->irq, handle_level_irq);
299         else if (type & (IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING))
300                 __irq_set_handler_locked(d->irq, handle_edge_irq);
301
302         tegra_pm_irq_set_wake_type(wake, type);
303
304         return 0;
305 }
306
307 static void tegra_gpio_irq_handler(unsigned int irq, struct irq_desc *desc)
308 {
309         struct tegra_gpio_bank *bank;
310         int port;
311         int pin;
312         struct irq_chip *chip = irq_desc_get_chip(desc);
313
314         chained_irq_enter(chip, desc);
315
316         bank = irq_get_handler_data(irq);
317
318         for (port = 0; port < 4; port++) {
319                 int gpio = tegra_gpio_compose(bank->bank, port, 0);
320                 unsigned long sta = tegra_gpio_readl(GPIO_INT_STA(gpio)) &
321                         tegra_gpio_readl(GPIO_INT_ENB(gpio));
322
323                 for_each_set_bit(pin, &sta, 8)
324                         generic_handle_irq(gpio_to_irq(gpio + pin));
325         }
326
327         chained_irq_exit(chip, desc);
328
329 }
330
331 #ifdef CONFIG_PM_SLEEP
332 static void tegra_gpio_resume(void)
333 {
334         unsigned long flags;
335         int b;
336         int p;
337
338         local_irq_save(flags);
339
340         for (b = 0; b < tegra_gpio_bank_count; b++) {
341                 struct tegra_gpio_bank *bank = &tegra_gpio_banks[b];
342
343                 for (p = 0; p < ARRAY_SIZE(bank->oe); p++) {
344                         unsigned int gpio = (b<<5) | (p<<3);
345                         tegra_gpio_writel(bank->cnf[p], GPIO_CNF(gpio));
346                         tegra_gpio_writel(bank->out[p], GPIO_OUT(gpio));
347                         tegra_gpio_writel(bank->oe[p], GPIO_OE(gpio));
348                         tegra_gpio_writel(bank->int_lvl[p], GPIO_INT_LVL(gpio));
349                         tegra_gpio_writel(bank->int_enb[p], GPIO_INT_ENB(gpio));
350                 }
351         }
352
353         local_irq_restore(flags);
354 }
355
356 static int tegra_gpio_suspend(void)
357 {
358         unsigned long flags;
359         int b;
360         int p;
361
362         local_irq_save(flags);
363         for (b = 0; b < tegra_gpio_bank_count; b++) {
364                 struct tegra_gpio_bank *bank = &tegra_gpio_banks[b];
365
366                 for (p = 0; p < ARRAY_SIZE(bank->oe); p++) {
367                         unsigned int gpio = (b<<5) | (p<<3);
368                         bank->cnf[p] = tegra_gpio_readl(GPIO_CNF(gpio));
369                         bank->out[p] = tegra_gpio_readl(GPIO_OUT(gpio));
370                         bank->oe[p] = tegra_gpio_readl(GPIO_OE(gpio));
371                         bank->int_enb[p] = tegra_gpio_readl(GPIO_INT_ENB(gpio));
372                         bank->int_lvl[p] = tegra_gpio_readl(GPIO_INT_LVL(gpio));
373
374                         /* disable gpio interrupts that are not wake sources */
375                         tegra_gpio_writel(bank->wake_enb[p], GPIO_INT_ENB(gpio));
376                 }
377         }
378         local_irq_restore(flags);
379
380         return 0;
381 }
382
383 static int tegra_update_lp1_gpio_wake(struct irq_data *d, bool enable)
384 {
385 #ifdef CONFIG_PM_SLEEP
386         struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d);
387         u8 mask;
388         u8 port_index;
389         u8 pin_index_in_bank;
390         u8 pin_in_port;
391         int gpio = d->hwirq;
392
393         if (gpio < 0)
394                 return -EIO;
395         pin_index_in_bank = (gpio & 0x1F);
396         port_index = pin_index_in_bank >> 3;
397         pin_in_port = (pin_index_in_bank & 0x7);
398         mask = BIT(pin_in_port);
399         if (enable)
400                 bank->wake_enb[port_index] |= mask;
401         else
402                 bank->wake_enb[port_index] &= ~mask;
403 #endif
404
405         return 0;
406 }
407
408 static int tegra_gpio_irq_set_wake(struct irq_data *d, unsigned int enable)
409 {
410         struct tegra_gpio_bank *bank = irq_data_get_irq_chip_data(d);
411         int ret = 0;
412         int wake = tegra_gpio_to_wake(d->hwirq);
413
414         /*
415          * update LP1 mask for gpio port/pin interrupt
416          * LP1 enable independent of LP0 wake support
417          */
418         ret = tegra_update_lp1_gpio_wake(d, enable);
419         if (ret) {
420                 pr_err("Failed gpio lp1 %s for irq=%d, error=%d\n",
421                         (enable ? "enable" : "disable"), d->irq, ret);
422                 goto fail;
423         }
424
425         /* LP1 enable for bank interrupt */
426         if (enable) {
427                 if (bank->wake_depth++ == 0) {
428                         ret = tegra_update_lp1_irq_wake(bank->irq, enable);
429                         if (ret)
430                                 bank->wake_depth = 0;
431                 }
432         } else {
433                 if (bank->wake_depth == 0) {
434                         WARN(1, "Unbalanced IRQ %d wake disable\n", bank->irq);
435                 } else if (--bank->wake_depth == 0) {
436                         ret = tegra_update_lp1_irq_wake(bank->irq, enable);
437                         if (ret)
438                                 bank->wake_depth = 1;
439                 }
440         }
441         if (ret)
442                 pr_err("Failed gpio lp1 %s for irq=%d, error=%d\n",
443                         (enable ? "enable" : "disable"), bank->irq, ret);
444
445         if (wake < 0)
446                 pr_err("Warning: enabling a non-LP0 wake source %lu\n",
447                         d->hwirq);
448         else {
449                 ret = tegra_pm_irq_set_wake(wake, enable);
450                 if (ret)
451                         pr_err("Failed gpio lp0 %s for irq=%d, error=%d\n",
452                                 (enable ? "enable" : "disable"), d->irq, ret);
453         }
454
455 fail:
456         return ret;
457 }
458 #else
459 #define tegra_gpio_irq_set_wake NULL
460 #define tegra_update_lp1_gpio_wake NULL
461 #endif
462
463 static struct syscore_ops tegra_gpio_syscore_ops = {
464         .suspend = tegra_gpio_suspend,
465         .resume = tegra_gpio_resume,
466         .save = tegra_gpio_suspend,
467         .restore = tegra_gpio_resume,
468 };
469
470 static struct irq_chip tegra_gpio_irq_chip = {
471         .name           = "GPIO",
472         .irq_ack        = tegra_gpio_irq_ack,
473         .irq_mask       = tegra_gpio_irq_mask,
474         .irq_unmask     = tegra_gpio_irq_unmask,
475         .irq_set_type   = tegra_gpio_irq_set_type,
476         .irq_set_wake   = tegra_gpio_irq_set_wake,
477         .flags          = IRQCHIP_MASK_ON_SUSPEND,
478 };
479
480 struct tegra_gpio_soc_config {
481         u32 bank_stride;
482         u32 upper_offset;
483 };
484
485 static struct tegra_gpio_soc_config tegra20_gpio_config = {
486         .bank_stride = 0x80,
487         .upper_offset = 0x800,
488 };
489
490 static struct tegra_gpio_soc_config tegra30_gpio_config = {
491         .bank_stride = 0x100,
492         .upper_offset = 0x80,
493 };
494
495 static struct of_device_id tegra_gpio_of_match[] = {
496         { .compatible = "nvidia,tegra124-gpio", .data = &tegra30_gpio_config },
497         { .compatible = "nvidia,tegra148-gpio", .data = &tegra30_gpio_config },
498         { .compatible = "nvidia,tegra114-gpio", .data = &tegra30_gpio_config },
499         { .compatible = "nvidia,tegra30-gpio", .data = &tegra30_gpio_config },
500         { .compatible = "nvidia,tegra20-gpio", .data = &tegra20_gpio_config },
501         { },
502 };
503
504 /* This lock class tells lockdep that GPIO irqs are in a different
505  * category than their parents, so it won't report false recursion.
506  */
507 static struct lock_class_key gpio_lock_class;
508
509 static int tegra_gpio_probe(struct platform_device *pdev)
510 {
511         const struct of_device_id *match;
512         struct tegra_gpio_soc_config *config;
513         struct resource *res;
514         struct tegra_gpio_bank *bank;
515         int gpio;
516         int i;
517         int j;
518
519         match = of_match_device(tegra_gpio_of_match, &pdev->dev);
520         if (!match) {
521                 dev_err(&pdev->dev, "Error: No device match found\n");
522                 return -ENODEV;
523         }
524         config = (struct tegra_gpio_soc_config *)match->data;
525
526         tegra_gpio_bank_stride = config->bank_stride;
527         tegra_gpio_upper_offset = config->upper_offset;
528
529         for (;;) {
530                 res = platform_get_resource(pdev, IORESOURCE_IRQ, tegra_gpio_bank_count);
531                 if (!res)
532                         break;
533                 tegra_gpio_bank_count++;
534         }
535         if (!tegra_gpio_bank_count) {
536                 dev_err(&pdev->dev, "Missing IRQ resource\n");
537                 return -ENODEV;
538         }
539
540         tegra_gpio_chip.dev = &pdev->dev;
541         tegra_gpio_chip.ngpio = tegra_gpio_bank_count * 32;
542
543         tegra_gpio_banks = devm_kzalloc(&pdev->dev,
544                         tegra_gpio_bank_count * sizeof(*tegra_gpio_banks),
545                         GFP_KERNEL);
546         if (!tegra_gpio_banks) {
547                 dev_err(&pdev->dev, "Couldn't allocate bank structure\n");
548                 return -ENODEV;
549         }
550
551         irq_domain = irq_domain_add_linear(pdev->dev.of_node,
552                                            tegra_gpio_chip.ngpio,
553                                            &irq_domain_simple_ops, NULL);
554         if (!irq_domain)
555                 return -ENODEV;
556
557         for (i = 0; i < tegra_gpio_bank_count; i++) {
558                 res = platform_get_resource(pdev, IORESOURCE_IRQ, i);
559                 if (!res) {
560                         dev_err(&pdev->dev, "Missing IRQ resource\n");
561                         return -ENODEV;
562                 }
563
564                 bank = &tegra_gpio_banks[i];
565                 bank->bank = i;
566                 bank->irq = res->start;
567         }
568
569         res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
570         if (!res) {
571                 dev_err(&pdev->dev, "Missing MEM resource\n");
572                 return -ENODEV;
573         }
574
575         regs = devm_ioremap_resource(&pdev->dev, res);
576         if (IS_ERR(regs))
577                 return PTR_ERR(regs);
578
579         for (i = 0; i < tegra_gpio_bank_count; i++) {
580                 for (j = 0; j < 4; j++) {
581                         int gpio = tegra_gpio_compose(i, j, 0);
582                         tegra_gpio_writel(0x00, GPIO_INT_ENB(gpio));
583                         tegra_gpio_writel(0x00, GPIO_INT_STA(gpio));
584                 }
585         }
586
587         tegra_gpio_chip.of_node = pdev->dev.of_node;
588
589         gpiochip_add(&tegra_gpio_chip);
590
591         for (gpio = 0; gpio < tegra_gpio_chip.ngpio; gpio++) {
592                 int irq = irq_create_mapping(irq_domain, gpio);
593                 /* No validity check; all Tegra GPIOs are valid IRQs */
594
595                 bank = &tegra_gpio_banks[GPIO_BANK(gpio)];
596
597                 irq_set_lockdep_class(irq, &gpio_lock_class);
598                 irq_set_chip_data(irq, bank);
599                 irq_set_chip_and_handler(irq, &tegra_gpio_irq_chip,
600                                          handle_simple_irq);
601                 set_irq_flags(irq, IRQF_VALID);
602         }
603
604         for (i = 0; i < tegra_gpio_bank_count; i++) {
605                 bank = &tegra_gpio_banks[i];
606
607                 for (j = 0; j < 4; j++)
608                         spin_lock_init(&bank->lvl_lock[j]);
609
610                 irq_set_handler_data(bank->irq, bank);
611                 irq_set_chained_handler(bank->irq, tegra_gpio_irq_handler);
612
613         }
614
615         return 0;
616 }
617
618 static struct platform_driver tegra_gpio_driver = {
619         .driver         = {
620                 .name   = "tegra-gpio",
621                 .owner  = THIS_MODULE,
622                 .of_match_table = tegra_gpio_of_match,
623         },
624         .probe          = tegra_gpio_probe,
625 };
626
627 static int __init tegra_gpio_init(void)
628 {
629         register_syscore_ops(&tegra_gpio_syscore_ops);
630         return platform_driver_register(&tegra_gpio_driver);
631 }
632 postcore_initcall(tegra_gpio_init);
633
634 #ifdef  CONFIG_DEBUG_FS
635
636 #include <linux/debugfs.h>
637 #include <linux/seq_file.h>
638
639 static int dbg_gpio_show(struct seq_file *s, void *unused)
640 {
641         int i;
642         int j;
643         char x,y;
644
645         x = ' ';
646         y = 'A';
647
648         seq_printf(s, "Name:Bank:Port CNF OE OUT IN INT_STA INT_ENB INT_LVL\n");
649         for (i = 0; i < tegra_gpio_bank_count; i++) {
650                 for (j = 0; j < 4; j++) {
651                         int gpio = tegra_gpio_compose(i, j, 0);
652                         seq_printf(s,
653                                 "%c%c: %d:%d %02x %02x %02x %02x %02x %02x %06x\n",
654                                 x, y, i, j,
655                                 tegra_gpio_readl(GPIO_CNF(gpio)),
656                                 tegra_gpio_readl(GPIO_OE(gpio)),
657                                 tegra_gpio_readl(GPIO_OUT(gpio)),
658                                 tegra_gpio_readl(GPIO_IN(gpio)),
659                                 tegra_gpio_readl(GPIO_INT_STA(gpio)),
660                                 tegra_gpio_readl(GPIO_INT_ENB(gpio)),
661                                 tegra_gpio_readl(GPIO_INT_LVL(gpio)));
662
663                         if (x != ' ')
664                                 x++;
665                         if (y == 'Z') {
666                                 y = 'A';
667                                 x = 'A';
668                         } else {
669                                 y++;
670                         };
671                 }
672         }
673         return 0;
674 }
675
676 static int dbg_gpio_open(struct inode *inode, struct file *file)
677 {
678         return single_open(file, dbg_gpio_show, &inode->i_private);
679 }
680
681 static const struct file_operations debug_fops = {
682         .open           = dbg_gpio_open,
683         .read           = seq_read,
684         .llseek         = seq_lseek,
685         .release        = single_release,
686 };
687
688 static int __init tegra_gpio_debuginit(void)
689 {
690         (void) debugfs_create_file("tegra_gpio", S_IRUGO,
691                                         NULL, NULL, &debug_fops);
692         return 0;
693 }
694 late_initcall(tegra_gpio_debuginit);
695 #endif