GNU Linux-libre 5.4.200-gnu1
[releases.git] / drivers / gpio / gpio-tegra186.c
1 // SPDX-License-Identifier: GPL-2.0-only
2 /*
3  * Copyright (c) 2016-2017 NVIDIA Corporation
4  *
5  * Author: Thierry Reding <treding@nvidia.com>
6  */
7
8 #include <linux/gpio/driver.h>
9 #include <linux/interrupt.h>
10 #include <linux/irq.h>
11 #include <linux/module.h>
12 #include <linux/of_device.h>
13 #include <linux/platform_device.h>
14
15 #include <dt-bindings/gpio/tegra186-gpio.h>
16 #include <dt-bindings/gpio/tegra194-gpio.h>
17
18 #define TEGRA186_GPIO_ENABLE_CONFIG 0x00
19 #define  TEGRA186_GPIO_ENABLE_CONFIG_ENABLE BIT(0)
20 #define  TEGRA186_GPIO_ENABLE_CONFIG_OUT BIT(1)
21 #define  TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_NONE (0x0 << 2)
22 #define  TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_LEVEL (0x1 << 2)
23 #define  TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE (0x2 << 2)
24 #define  TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE (0x3 << 2)
25 #define  TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_MASK (0x3 << 2)
26 #define  TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL BIT(4)
27 #define  TEGRA186_GPIO_ENABLE_CONFIG_INTERRUPT BIT(6)
28
29 #define TEGRA186_GPIO_DEBOUNCE_CONTROL 0x04
30 #define  TEGRA186_GPIO_DEBOUNCE_CONTROL_THRESHOLD(x) ((x) & 0xff)
31
32 #define TEGRA186_GPIO_INPUT 0x08
33 #define  TEGRA186_GPIO_INPUT_HIGH BIT(0)
34
35 #define TEGRA186_GPIO_OUTPUT_CONTROL 0x0c
36 #define  TEGRA186_GPIO_OUTPUT_CONTROL_FLOATED BIT(0)
37
38 #define TEGRA186_GPIO_OUTPUT_VALUE 0x10
39 #define  TEGRA186_GPIO_OUTPUT_VALUE_HIGH BIT(0)
40
41 #define TEGRA186_GPIO_INTERRUPT_CLEAR 0x14
42
43 #define TEGRA186_GPIO_INTERRUPT_STATUS(x) (0x100 + (x) * 4)
44
45 struct tegra_gpio_port {
46         const char *name;
47         unsigned int offset;
48         unsigned int pins;
49         unsigned int irq;
50 };
51
52 struct tegra_gpio_soc {
53         const struct tegra_gpio_port *ports;
54         unsigned int num_ports;
55         const char *name;
56 };
57
58 struct tegra_gpio {
59         struct gpio_chip gpio;
60         struct irq_chip intc;
61         unsigned int num_irq;
62         unsigned int *irq;
63
64         const struct tegra_gpio_soc *soc;
65
66         void __iomem *base;
67 };
68
69 static const struct tegra_gpio_port *
70 tegra186_gpio_get_port(struct tegra_gpio *gpio, unsigned int *pin)
71 {
72         unsigned int start = 0, i;
73
74         for (i = 0; i < gpio->soc->num_ports; i++) {
75                 const struct tegra_gpio_port *port = &gpio->soc->ports[i];
76
77                 if (*pin >= start && *pin < start + port->pins) {
78                         *pin -= start;
79                         return port;
80                 }
81
82                 start += port->pins;
83         }
84
85         return NULL;
86 }
87
88 static void __iomem *tegra186_gpio_get_base(struct tegra_gpio *gpio,
89                                             unsigned int pin)
90 {
91         const struct tegra_gpio_port *port;
92
93         port = tegra186_gpio_get_port(gpio, &pin);
94         if (!port)
95                 return NULL;
96
97         return gpio->base + port->offset + pin * 0x20;
98 }
99
100 static int tegra186_gpio_get_direction(struct gpio_chip *chip,
101                                        unsigned int offset)
102 {
103         struct tegra_gpio *gpio = gpiochip_get_data(chip);
104         void __iomem *base;
105         u32 value;
106
107         base = tegra186_gpio_get_base(gpio, offset);
108         if (WARN_ON(base == NULL))
109                 return -ENODEV;
110
111         value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
112         if (value & TEGRA186_GPIO_ENABLE_CONFIG_OUT)
113                 return 0;
114
115         return 1;
116 }
117
118 static int tegra186_gpio_direction_input(struct gpio_chip *chip,
119                                          unsigned int offset)
120 {
121         struct tegra_gpio *gpio = gpiochip_get_data(chip);
122         void __iomem *base;
123         u32 value;
124
125         base = tegra186_gpio_get_base(gpio, offset);
126         if (WARN_ON(base == NULL))
127                 return -ENODEV;
128
129         value = readl(base + TEGRA186_GPIO_OUTPUT_CONTROL);
130         value |= TEGRA186_GPIO_OUTPUT_CONTROL_FLOATED;
131         writel(value, base + TEGRA186_GPIO_OUTPUT_CONTROL);
132
133         value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
134         value |= TEGRA186_GPIO_ENABLE_CONFIG_ENABLE;
135         value &= ~TEGRA186_GPIO_ENABLE_CONFIG_OUT;
136         writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
137
138         return 0;
139 }
140
141 static int tegra186_gpio_direction_output(struct gpio_chip *chip,
142                                           unsigned int offset, int level)
143 {
144         struct tegra_gpio *gpio = gpiochip_get_data(chip);
145         void __iomem *base;
146         u32 value;
147
148         /* configure output level first */
149         chip->set(chip, offset, level);
150
151         base = tegra186_gpio_get_base(gpio, offset);
152         if (WARN_ON(base == NULL))
153                 return -EINVAL;
154
155         /* set the direction */
156         value = readl(base + TEGRA186_GPIO_OUTPUT_CONTROL);
157         value &= ~TEGRA186_GPIO_OUTPUT_CONTROL_FLOATED;
158         writel(value, base + TEGRA186_GPIO_OUTPUT_CONTROL);
159
160         value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
161         value |= TEGRA186_GPIO_ENABLE_CONFIG_ENABLE;
162         value |= TEGRA186_GPIO_ENABLE_CONFIG_OUT;
163         writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
164
165         return 0;
166 }
167
168 static int tegra186_gpio_get(struct gpio_chip *chip, unsigned int offset)
169 {
170         struct tegra_gpio *gpio = gpiochip_get_data(chip);
171         void __iomem *base;
172         u32 value;
173
174         base = tegra186_gpio_get_base(gpio, offset);
175         if (WARN_ON(base == NULL))
176                 return -ENODEV;
177
178         value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
179         if (value & TEGRA186_GPIO_ENABLE_CONFIG_OUT)
180                 value = readl(base + TEGRA186_GPIO_OUTPUT_VALUE);
181         else
182                 value = readl(base + TEGRA186_GPIO_INPUT);
183
184         return value & BIT(0);
185 }
186
187 static void tegra186_gpio_set(struct gpio_chip *chip, unsigned int offset,
188                               int level)
189 {
190         struct tegra_gpio *gpio = gpiochip_get_data(chip);
191         void __iomem *base;
192         u32 value;
193
194         base = tegra186_gpio_get_base(gpio, offset);
195         if (WARN_ON(base == NULL))
196                 return;
197
198         value = readl(base + TEGRA186_GPIO_OUTPUT_VALUE);
199         if (level == 0)
200                 value &= ~TEGRA186_GPIO_OUTPUT_VALUE_HIGH;
201         else
202                 value |= TEGRA186_GPIO_OUTPUT_VALUE_HIGH;
203
204         writel(value, base + TEGRA186_GPIO_OUTPUT_VALUE);
205 }
206
207 static int tegra186_gpio_of_xlate(struct gpio_chip *chip,
208                                   const struct of_phandle_args *spec,
209                                   u32 *flags)
210 {
211         struct tegra_gpio *gpio = gpiochip_get_data(chip);
212         unsigned int port, pin, i, offset = 0;
213
214         if (WARN_ON(chip->of_gpio_n_cells < 2))
215                 return -EINVAL;
216
217         if (WARN_ON(spec->args_count < chip->of_gpio_n_cells))
218                 return -EINVAL;
219
220         port = spec->args[0] / 8;
221         pin = spec->args[0] % 8;
222
223         if (port >= gpio->soc->num_ports) {
224                 dev_err(chip->parent, "invalid port number: %u\n", port);
225                 return -EINVAL;
226         }
227
228         for (i = 0; i < port; i++)
229                 offset += gpio->soc->ports[i].pins;
230
231         if (flags)
232                 *flags = spec->args[1];
233
234         return offset + pin;
235 }
236
237 #define to_tegra_gpio(x) container_of((x), struct tegra_gpio, gpio)
238
239 static void tegra186_irq_ack(struct irq_data *data)
240 {
241         struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
242         struct tegra_gpio *gpio = to_tegra_gpio(gc);
243         void __iomem *base;
244
245         base = tegra186_gpio_get_base(gpio, data->hwirq);
246         if (WARN_ON(base == NULL))
247                 return;
248
249         writel(1, base + TEGRA186_GPIO_INTERRUPT_CLEAR);
250 }
251
252 static void tegra186_irq_mask(struct irq_data *data)
253 {
254         struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
255         struct tegra_gpio *gpio = to_tegra_gpio(gc);
256         void __iomem *base;
257         u32 value;
258
259         base = tegra186_gpio_get_base(gpio, data->hwirq);
260         if (WARN_ON(base == NULL))
261                 return;
262
263         value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
264         value &= ~TEGRA186_GPIO_ENABLE_CONFIG_INTERRUPT;
265         writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
266 }
267
268 static void tegra186_irq_unmask(struct irq_data *data)
269 {
270         struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
271         struct tegra_gpio *gpio = to_tegra_gpio(gc);
272         void __iomem *base;
273         u32 value;
274
275         base = tegra186_gpio_get_base(gpio, data->hwirq);
276         if (WARN_ON(base == NULL))
277                 return;
278
279         value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
280         value |= TEGRA186_GPIO_ENABLE_CONFIG_INTERRUPT;
281         writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
282 }
283
284 static int tegra186_irq_set_type(struct irq_data *data, unsigned int type)
285 {
286         struct gpio_chip *gc = irq_data_get_irq_chip_data(data);
287         struct tegra_gpio *gpio = to_tegra_gpio(gc);
288         void __iomem *base;
289         u32 value;
290
291         base = tegra186_gpio_get_base(gpio, data->hwirq);
292         if (WARN_ON(base == NULL))
293                 return -ENODEV;
294
295         value = readl(base + TEGRA186_GPIO_ENABLE_CONFIG);
296         value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_MASK;
297         value &= ~TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
298
299         switch (type & IRQ_TYPE_SENSE_MASK) {
300         case IRQ_TYPE_NONE:
301                 break;
302
303         case IRQ_TYPE_EDGE_RISING:
304                 value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
305                 value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
306                 break;
307
308         case IRQ_TYPE_EDGE_FALLING:
309                 value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_SINGLE_EDGE;
310                 break;
311
312         case IRQ_TYPE_EDGE_BOTH:
313                 value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_DOUBLE_EDGE;
314                 break;
315
316         case IRQ_TYPE_LEVEL_HIGH:
317                 value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_LEVEL;
318                 value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_LEVEL;
319                 break;
320
321         case IRQ_TYPE_LEVEL_LOW:
322                 value |= TEGRA186_GPIO_ENABLE_CONFIG_TRIGGER_TYPE_LEVEL;
323                 break;
324
325         default:
326                 return -EINVAL;
327         }
328
329         writel(value, base + TEGRA186_GPIO_ENABLE_CONFIG);
330
331         if ((type & IRQ_TYPE_EDGE_BOTH) == 0)
332                 irq_set_handler_locked(data, handle_level_irq);
333         else
334                 irq_set_handler_locked(data, handle_edge_irq);
335
336         return 0;
337 }
338
339 static void tegra186_gpio_irq(struct irq_desc *desc)
340 {
341         struct tegra_gpio *gpio = irq_desc_get_handler_data(desc);
342         struct irq_domain *domain = gpio->gpio.irq.domain;
343         struct irq_chip *chip = irq_desc_get_chip(desc);
344         unsigned int parent = irq_desc_get_irq(desc);
345         unsigned int i, offset = 0;
346
347         chained_irq_enter(chip, desc);
348
349         for (i = 0; i < gpio->soc->num_ports; i++) {
350                 const struct tegra_gpio_port *port = &gpio->soc->ports[i];
351                 void __iomem *base = gpio->base + port->offset;
352                 unsigned int pin, irq;
353                 unsigned long value;
354
355                 /* skip ports that are not associated with this controller */
356                 if (parent != gpio->irq[port->irq])
357                         goto skip;
358
359                 value = readl(base + TEGRA186_GPIO_INTERRUPT_STATUS(1));
360
361                 for_each_set_bit(pin, &value, port->pins) {
362                         irq = irq_find_mapping(domain, offset + pin);
363                         if (WARN_ON(irq == 0))
364                                 continue;
365
366                         generic_handle_irq(irq);
367                 }
368
369 skip:
370                 offset += port->pins;
371         }
372
373         chained_irq_exit(chip, desc);
374 }
375
376 static int tegra186_gpio_irq_domain_xlate(struct irq_domain *domain,
377                                           struct device_node *np,
378                                           const u32 *spec, unsigned int size,
379                                           unsigned long *hwirq,
380                                           unsigned int *type)
381 {
382         struct tegra_gpio *gpio = gpiochip_get_data(domain->host_data);
383         unsigned int port, pin, i, offset = 0;
384
385         if (size < 2)
386                 return -EINVAL;
387
388         port = spec[0] / 8;
389         pin = spec[0] % 8;
390
391         if (port >= gpio->soc->num_ports) {
392                 dev_err(gpio->gpio.parent, "invalid port number: %u\n", port);
393                 return -EINVAL;
394         }
395
396         for (i = 0; i < port; i++)
397                 offset += gpio->soc->ports[i].pins;
398
399         *type = spec[1] & IRQ_TYPE_SENSE_MASK;
400         *hwirq = offset + pin;
401
402         return 0;
403 }
404
405 static const struct irq_domain_ops tegra186_gpio_irq_domain_ops = {
406         .map = gpiochip_irq_map,
407         .unmap = gpiochip_irq_unmap,
408         .xlate = tegra186_gpio_irq_domain_xlate,
409 };
410
411 static int tegra186_gpio_probe(struct platform_device *pdev)
412 {
413         unsigned int i, j, offset;
414         struct gpio_irq_chip *irq;
415         struct tegra_gpio *gpio;
416         struct resource *res;
417         char **names;
418         int err;
419
420         gpio = devm_kzalloc(&pdev->dev, sizeof(*gpio), GFP_KERNEL);
421         if (!gpio)
422                 return -ENOMEM;
423
424         gpio->soc = of_device_get_match_data(&pdev->dev);
425
426         res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "gpio");
427         gpio->base = devm_ioremap_resource(&pdev->dev, res);
428         if (IS_ERR(gpio->base))
429                 return PTR_ERR(gpio->base);
430
431         err = platform_irq_count(pdev);
432         if (err < 0)
433                 return err;
434
435         gpio->num_irq = err;
436
437         gpio->irq = devm_kcalloc(&pdev->dev, gpio->num_irq, sizeof(*gpio->irq),
438                                  GFP_KERNEL);
439         if (!gpio->irq)
440                 return -ENOMEM;
441
442         for (i = 0; i < gpio->num_irq; i++) {
443                 err = platform_get_irq(pdev, i);
444                 if (err < 0)
445                         return err;
446
447                 gpio->irq[i] = err;
448         }
449
450         gpio->gpio.label = gpio->soc->name;
451         gpio->gpio.parent = &pdev->dev;
452
453         gpio->gpio.get_direction = tegra186_gpio_get_direction;
454         gpio->gpio.direction_input = tegra186_gpio_direction_input;
455         gpio->gpio.direction_output = tegra186_gpio_direction_output;
456         gpio->gpio.get = tegra186_gpio_get,
457         gpio->gpio.set = tegra186_gpio_set;
458
459         gpio->gpio.base = -1;
460
461         for (i = 0; i < gpio->soc->num_ports; i++)
462                 gpio->gpio.ngpio += gpio->soc->ports[i].pins;
463
464         names = devm_kcalloc(gpio->gpio.parent, gpio->gpio.ngpio,
465                              sizeof(*names), GFP_KERNEL);
466         if (!names)
467                 return -ENOMEM;
468
469         for (i = 0, offset = 0; i < gpio->soc->num_ports; i++) {
470                 const struct tegra_gpio_port *port = &gpio->soc->ports[i];
471                 char *name;
472
473                 for (j = 0; j < port->pins; j++) {
474                         name = devm_kasprintf(gpio->gpio.parent, GFP_KERNEL,
475                                               "P%s.%02x", port->name, j);
476                         if (!name)
477                                 return -ENOMEM;
478
479                         names[offset + j] = name;
480                 }
481
482                 offset += port->pins;
483         }
484
485         gpio->gpio.names = (const char * const *)names;
486
487         gpio->gpio.of_node = pdev->dev.of_node;
488         gpio->gpio.of_gpio_n_cells = 2;
489         gpio->gpio.of_xlate = tegra186_gpio_of_xlate;
490
491         gpio->intc.name = pdev->dev.of_node->name;
492         gpio->intc.irq_ack = tegra186_irq_ack;
493         gpio->intc.irq_mask = tegra186_irq_mask;
494         gpio->intc.irq_unmask = tegra186_irq_unmask;
495         gpio->intc.irq_set_type = tegra186_irq_set_type;
496
497         irq = &gpio->gpio.irq;
498         irq->chip = &gpio->intc;
499         irq->domain_ops = &tegra186_gpio_irq_domain_ops;
500         irq->handler = handle_simple_irq;
501         irq->default_type = IRQ_TYPE_NONE;
502         irq->parent_handler = tegra186_gpio_irq;
503         irq->parent_handler_data = gpio;
504         irq->num_parents = gpio->num_irq;
505         irq->parents = gpio->irq;
506
507         irq->map = devm_kcalloc(&pdev->dev, gpio->gpio.ngpio,
508                                 sizeof(*irq->map), GFP_KERNEL);
509         if (!irq->map)
510                 return -ENOMEM;
511
512         for (i = 0, offset = 0; i < gpio->soc->num_ports; i++) {
513                 const struct tegra_gpio_port *port = &gpio->soc->ports[i];
514
515                 for (j = 0; j < port->pins; j++)
516                         irq->map[offset + j] = irq->parents[port->irq];
517
518                 offset += port->pins;
519         }
520
521         platform_set_drvdata(pdev, gpio);
522
523         err = devm_gpiochip_add_data(&pdev->dev, &gpio->gpio, gpio);
524         if (err < 0)
525                 return err;
526
527         return 0;
528 }
529
530 static int tegra186_gpio_remove(struct platform_device *pdev)
531 {
532         return 0;
533 }
534
535 #define TEGRA186_MAIN_GPIO_PORT(port, base, count, controller)  \
536         [TEGRA186_MAIN_GPIO_PORT_##port] = {                    \
537                 .name = #port,                                  \
538                 .offset = base,                                 \
539                 .pins = count,                                  \
540                 .irq = controller,                              \
541         }
542
543 static const struct tegra_gpio_port tegra186_main_ports[] = {
544         TEGRA186_MAIN_GPIO_PORT( A, 0x2000, 7, 2),
545         TEGRA186_MAIN_GPIO_PORT( B, 0x3000, 7, 3),
546         TEGRA186_MAIN_GPIO_PORT( C, 0x3200, 7, 3),
547         TEGRA186_MAIN_GPIO_PORT( D, 0x3400, 6, 3),
548         TEGRA186_MAIN_GPIO_PORT( E, 0x2200, 8, 2),
549         TEGRA186_MAIN_GPIO_PORT( F, 0x2400, 6, 2),
550         TEGRA186_MAIN_GPIO_PORT( G, 0x4200, 6, 4),
551         TEGRA186_MAIN_GPIO_PORT( H, 0x1000, 7, 1),
552         TEGRA186_MAIN_GPIO_PORT( I, 0x0800, 8, 0),
553         TEGRA186_MAIN_GPIO_PORT( J, 0x5000, 8, 5),
554         TEGRA186_MAIN_GPIO_PORT( K, 0x5200, 1, 5),
555         TEGRA186_MAIN_GPIO_PORT( L, 0x1200, 8, 1),
556         TEGRA186_MAIN_GPIO_PORT( M, 0x5600, 6, 5),
557         TEGRA186_MAIN_GPIO_PORT( N, 0x0000, 7, 0),
558         TEGRA186_MAIN_GPIO_PORT( O, 0x0200, 4, 0),
559         TEGRA186_MAIN_GPIO_PORT( P, 0x4000, 7, 4),
560         TEGRA186_MAIN_GPIO_PORT( Q, 0x0400, 6, 0),
561         TEGRA186_MAIN_GPIO_PORT( R, 0x0a00, 6, 0),
562         TEGRA186_MAIN_GPIO_PORT( T, 0x0600, 4, 0),
563         TEGRA186_MAIN_GPIO_PORT( X, 0x1400, 8, 1),
564         TEGRA186_MAIN_GPIO_PORT( Y, 0x1600, 7, 1),
565         TEGRA186_MAIN_GPIO_PORT(BB, 0x2600, 2, 2),
566         TEGRA186_MAIN_GPIO_PORT(CC, 0x5400, 4, 5),
567 };
568
569 static const struct tegra_gpio_soc tegra186_main_soc = {
570         .num_ports = ARRAY_SIZE(tegra186_main_ports),
571         .ports = tegra186_main_ports,
572         .name = "tegra186-gpio",
573 };
574
575 #define TEGRA186_AON_GPIO_PORT(port, base, count, controller)   \
576         [TEGRA186_AON_GPIO_PORT_##port] = {                     \
577                 .name = #port,                                  \
578                 .offset = base,                                 \
579                 .pins = count,                                  \
580                 .irq = controller,                              \
581         }
582
583 static const struct tegra_gpio_port tegra186_aon_ports[] = {
584         TEGRA186_AON_GPIO_PORT( S, 0x0200, 5, 0),
585         TEGRA186_AON_GPIO_PORT( U, 0x0400, 6, 0),
586         TEGRA186_AON_GPIO_PORT( V, 0x0800, 8, 0),
587         TEGRA186_AON_GPIO_PORT( W, 0x0a00, 8, 0),
588         TEGRA186_AON_GPIO_PORT( Z, 0x0e00, 4, 0),
589         TEGRA186_AON_GPIO_PORT(AA, 0x0c00, 8, 0),
590         TEGRA186_AON_GPIO_PORT(EE, 0x0600, 3, 0),
591         TEGRA186_AON_GPIO_PORT(FF, 0x0000, 5, 0),
592 };
593
594 static const struct tegra_gpio_soc tegra186_aon_soc = {
595         .num_ports = ARRAY_SIZE(tegra186_aon_ports),
596         .ports = tegra186_aon_ports,
597         .name = "tegra186-gpio-aon",
598 };
599
600 #define TEGRA194_MAIN_GPIO_PORT(port, base, count, controller)  \
601         [TEGRA194_MAIN_GPIO_PORT_##port] = {                    \
602                 .name = #port,                                  \
603                 .offset = base,                                 \
604                 .pins = count,                                  \
605                 .irq = controller,                              \
606         }
607
608 static const struct tegra_gpio_port tegra194_main_ports[] = {
609         TEGRA194_MAIN_GPIO_PORT( A, 0x1400, 8, 1),
610         TEGRA194_MAIN_GPIO_PORT( B, 0x4e00, 2, 4),
611         TEGRA194_MAIN_GPIO_PORT( C, 0x4600, 8, 4),
612         TEGRA194_MAIN_GPIO_PORT( D, 0x4800, 4, 4),
613         TEGRA194_MAIN_GPIO_PORT( E, 0x4a00, 8, 4),
614         TEGRA194_MAIN_GPIO_PORT( F, 0x4c00, 6, 4),
615         TEGRA194_MAIN_GPIO_PORT( G, 0x4000, 8, 4),
616         TEGRA194_MAIN_GPIO_PORT( H, 0x4200, 8, 4),
617         TEGRA194_MAIN_GPIO_PORT( I, 0x4400, 5, 4),
618         TEGRA194_MAIN_GPIO_PORT( J, 0x5200, 6, 5),
619         TEGRA194_MAIN_GPIO_PORT( K, 0x3000, 8, 3),
620         TEGRA194_MAIN_GPIO_PORT( L, 0x3200, 4, 3),
621         TEGRA194_MAIN_GPIO_PORT( M, 0x2600, 8, 2),
622         TEGRA194_MAIN_GPIO_PORT( N, 0x2800, 3, 2),
623         TEGRA194_MAIN_GPIO_PORT( O, 0x5000, 6, 5),
624         TEGRA194_MAIN_GPIO_PORT( P, 0x2a00, 8, 2),
625         TEGRA194_MAIN_GPIO_PORT( Q, 0x2c00, 8, 2),
626         TEGRA194_MAIN_GPIO_PORT( R, 0x2e00, 6, 2),
627         TEGRA194_MAIN_GPIO_PORT( S, 0x3600, 8, 3),
628         TEGRA194_MAIN_GPIO_PORT( T, 0x3800, 8, 3),
629         TEGRA194_MAIN_GPIO_PORT( U, 0x3a00, 1, 3),
630         TEGRA194_MAIN_GPIO_PORT( V, 0x1000, 8, 1),
631         TEGRA194_MAIN_GPIO_PORT( W, 0x1200, 2, 1),
632         TEGRA194_MAIN_GPIO_PORT( X, 0x2000, 8, 2),
633         TEGRA194_MAIN_GPIO_PORT( Y, 0x2200, 8, 2),
634         TEGRA194_MAIN_GPIO_PORT( Z, 0x2400, 8, 2),
635         TEGRA194_MAIN_GPIO_PORT(FF, 0x3400, 2, 3),
636         TEGRA194_MAIN_GPIO_PORT(GG, 0x0000, 2, 0)
637 };
638
639 static const struct tegra_gpio_soc tegra194_main_soc = {
640         .num_ports = ARRAY_SIZE(tegra194_main_ports),
641         .ports = tegra194_main_ports,
642         .name = "tegra194-gpio",
643 };
644
645 #define TEGRA194_AON_GPIO_PORT(port, base, count, controller)   \
646         [TEGRA194_AON_GPIO_PORT_##port] = {                     \
647                 .name = #port,                                  \
648                 .offset = base,                                 \
649                 .pins = count,                                  \
650                 .irq = controller,                              \
651         }
652
653 static const struct tegra_gpio_port tegra194_aon_ports[] = {
654         TEGRA194_AON_GPIO_PORT(AA, 0x0600, 8, 0),
655         TEGRA194_AON_GPIO_PORT(BB, 0x0800, 4, 0),
656         TEGRA194_AON_GPIO_PORT(CC, 0x0200, 8, 0),
657         TEGRA194_AON_GPIO_PORT(DD, 0x0400, 3, 0),
658         TEGRA194_AON_GPIO_PORT(EE, 0x0000, 7, 0)
659 };
660
661 static const struct tegra_gpio_soc tegra194_aon_soc = {
662         .num_ports = ARRAY_SIZE(tegra194_aon_ports),
663         .ports = tegra194_aon_ports,
664         .name = "tegra194-gpio-aon",
665 };
666
667 static const struct of_device_id tegra186_gpio_of_match[] = {
668         {
669                 .compatible = "nvidia,tegra186-gpio",
670                 .data = &tegra186_main_soc
671         }, {
672                 .compatible = "nvidia,tegra186-gpio-aon",
673                 .data = &tegra186_aon_soc
674         }, {
675                 .compatible = "nvidia,tegra194-gpio",
676                 .data = &tegra194_main_soc
677         }, {
678                 .compatible = "nvidia,tegra194-gpio-aon",
679                 .data = &tegra194_aon_soc
680         }, {
681                 /* sentinel */
682         }
683 };
684
685 static struct platform_driver tegra186_gpio_driver = {
686         .driver = {
687                 .name = "tegra186-gpio",
688                 .of_match_table = tegra186_gpio_of_match,
689         },
690         .probe = tegra186_gpio_probe,
691         .remove = tegra186_gpio_remove,
692 };
693 module_platform_driver(tegra186_gpio_driver);
694
695 MODULE_DESCRIPTION("NVIDIA Tegra186 GPIO controller driver");
696 MODULE_AUTHOR("Thierry Reding <treding@nvidia.com>");
697 MODULE_LICENSE("GPL v2");