a735798cc30ab9b58e8ce8486588ae4eeeefcec9
[openwrt.git] / target / linux / brcm2708 / patches-4.1 / 0002-Add-bcm2708_gpio-driver.patch
1 From c7eee1285590f15010feaf91970b9e3447e757f4 Mon Sep 17 00:00:00 2001
2 From: popcornmix <popcornmix@gmail.com>
3 Date: Wed, 8 Oct 2014 18:50:05 +0100
4 Subject: [PATCH 002/222] Add bcm2708_gpio driver
5
6 Signed-off-by: popcornmix <popcornmix@gmail.com>
7
8 bcm2708: Add extension to configure internal pulls
9
10 The bcm2708 gpio controller supports internal pulls to be used as pull-up,
11 pull-down or being entirely disabled. As it can be useful for a driver to
12 change the pull configuration from it's default pull-down state, add an
13 extension which allows configuring the pull per gpio.
14
15 Signed-off-by: Julian Scheel <julian@jusst.de>
16
17 bcm2708-gpio: Revert the use of pinctrl_request_gpio
18
19 In non-DT systems, pinctrl_request_gpio always fails causing
20 "requests probe deferral" messages. In DT systems, it isn't useful
21 because the reference counting is independent of the normal pinctrl
22 pin reservations.
23
24 gpio: Only clear the currently occurring interrupt. Avoids losing interrupts
25
26 See: linux #760
27
28 bcm2708_gpio: Avoid calling irq_unmask for all interrupts
29
30 When setting up the interrupts, specify that the handle_simple_irq
31 handler should be used. This leaves interrupt acknowledgement to
32 the caller, and prevents irq_unmask from being called for all
33 interrupts.
34
35 Issue: linux #760
36 ---
37  arch/arm/mach-bcm2708/Kconfig             |   8 +
38  arch/arm/mach-bcm2708/Makefile            |   1 +
39  arch/arm/mach-bcm2708/bcm2708.c           |  25 ++
40  arch/arm/mach-bcm2708/bcm2708_gpio.c      | 426 ++++++++++++++++++++++++++++++
41  arch/arm/mach-bcm2708/include/mach/gpio.h |  17 ++
42  arch/arm/mach-bcm2709/bcm2709.c           |  25 ++
43  include/linux/platform_data/bcm2708.h     |  23 ++
44  7 files changed, 525 insertions(+)
45  create mode 100644 arch/arm/mach-bcm2708/bcm2708_gpio.c
46  create mode 100644 arch/arm/mach-bcm2708/include/mach/gpio.h
47  create mode 100644 include/linux/platform_data/bcm2708.h
48
49 --- a/arch/arm/mach-bcm2708/Kconfig
50 +++ b/arch/arm/mach-bcm2708/Kconfig
51 @@ -20,6 +20,14 @@ config BCM2708_DT
52         help
53           Enable Device Tree support for BCM2708
54  
55 +config BCM2708_GPIO
56 +       bool "BCM2708 gpio support"
57 +       depends on MACH_BCM2708
58 +       select ARCH_REQUIRE_GPIOLIB
59 +        default y
60 +       help
61 +         Include support for the Broadcom(R) BCM2708 gpio.
62 +
63  config BCM2708_NOL2CACHE
64         bool "Videocore L2 cache disable"
65         depends on MACH_BCM2708
66 --- a/arch/arm/mach-bcm2708/Makefile
67 +++ b/arch/arm/mach-bcm2708/Makefile
68 @@ -3,3 +3,4 @@
69  #
70  
71  obj-$(CONFIG_MACH_BCM2708)     += bcm2708.o armctrl.o
72 +obj-$(CONFIG_BCM2708_GPIO)     += bcm2708_gpio.o
73 --- a/arch/arm/mach-bcm2708/bcm2708.c
74 +++ b/arch/arm/mach-bcm2708/bcm2708.c
75 @@ -298,6 +298,31 @@ static struct platform_device bcm2708_vc
76                 },
77  };
78  
79 +#ifdef CONFIG_BCM2708_GPIO
80 +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
81 +
82 +static struct resource bcm2708_gpio_resources[] = {
83 +       [0] = {                 /* general purpose I/O */
84 +              .start = GPIO_BASE,
85 +              .end = GPIO_BASE + SZ_4K - 1,
86 +              .flags = IORESOURCE_MEM,
87 +              },
88 +};
89 +
90 +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
91 +
92 +static struct platform_device bcm2708_gpio_device = {
93 +       .name = BCM_GPIO_DRIVER_NAME,
94 +       .id = -1,               /* only one VideoCore I/O area */
95 +       .resource = bcm2708_gpio_resources,
96 +       .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
97 +       .dev = {
98 +               .dma_mask = &gpio_dmamask,
99 +               .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
100 +               },
101 +};
102 +#endif
103 +
104  int __init bcm_register_device(struct platform_device *pdev)
105  {
106         int ret;
107 --- /dev/null
108 +++ b/arch/arm/mach-bcm2708/bcm2708_gpio.c
109 @@ -0,0 +1,426 @@
110 +/*
111 + *  linux/arch/arm/mach-bcm2708/bcm2708_gpio.c
112 + *
113 + *  Copyright (C) 2010 Broadcom
114 + *
115 + * This program is free software; you can redistribute it and/or modify
116 + * it under the terms of the GNU General Public License version 2 as
117 + * published by the Free Software Foundation.
118 + *
119 + */
120 +
121 +#include <linux/spinlock.h>
122 +#include <linux/module.h>
123 +#include <linux/delay.h>
124 +#include <linux/list.h>
125 +#include <linux/io.h>
126 +#include <linux/irq.h>
127 +#include <linux/interrupt.h>
128 +#include <linux/slab.h>
129 +#include <mach/gpio.h>
130 +#include <linux/gpio.h>
131 +#include <linux/platform_device.h>
132 +#include <mach/platform.h>
133 +#include <linux/pinctrl/consumer.h>
134 +
135 +#include <linux/platform_data/bcm2708.h>
136 +
137 +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
138 +#define DRIVER_NAME BCM_GPIO_DRIVER_NAME
139 +#define BCM_GPIO_USE_IRQ 1
140 +
141 +#define GPIOFSEL(x)  (0x00+(x)*4)
142 +#define GPIOSET(x)   (0x1c+(x)*4)
143 +#define GPIOCLR(x)   (0x28+(x)*4)
144 +#define GPIOLEV(x)   (0x34+(x)*4)
145 +#define GPIOEDS(x)   (0x40+(x)*4)
146 +#define GPIOREN(x)   (0x4c+(x)*4)
147 +#define GPIOFEN(x)   (0x58+(x)*4)
148 +#define GPIOHEN(x)   (0x64+(x)*4)
149 +#define GPIOLEN(x)   (0x70+(x)*4)
150 +#define GPIOAREN(x)  (0x7c+(x)*4)
151 +#define GPIOAFEN(x)  (0x88+(x)*4)
152 +#define GPIOUD(x)    (0x94+(x)*4)
153 +#define GPIOUDCLK(x) (0x98+(x)*4)
154 +
155 +#define GPIO_BANKS 2
156 +
157 +enum { GPIO_FSEL_INPUT, GPIO_FSEL_OUTPUT,
158 +       GPIO_FSEL_ALT5, GPIO_FSEL_ALT_4,
159 +       GPIO_FSEL_ALT0, GPIO_FSEL_ALT1,
160 +       GPIO_FSEL_ALT2, GPIO_FSEL_ALT3,
161 +};
162 +
163 +       /* Each of the two spinlocks protects a different set of hardware
164 +        * regiters and data structurs. This decouples the code of the IRQ from
165 +        * the GPIO code. This also makes the case of a GPIO routine call from
166 +        * the IRQ code simpler.
167 +        */
168 +static DEFINE_SPINLOCK(lock);  /* GPIO registers */
169 +
170 +struct bcm2708_gpio {
171 +       struct list_head list;
172 +       void __iomem *base;
173 +       struct gpio_chip gc;
174 +       unsigned long rising[(BCM2708_NR_GPIOS + 31) / 32];
175 +       unsigned long falling[(BCM2708_NR_GPIOS + 31) / 32];
176 +       unsigned long high[(BCM2708_NR_GPIOS + 31) / 32];
177 +       unsigned long low[(BCM2708_NR_GPIOS + 31) / 32];
178 +};
179 +
180 +static int bcm2708_set_function(struct gpio_chip *gc, unsigned offset,
181 +                               int function)
182 +{
183 +       struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
184 +       unsigned long flags;
185 +       unsigned gpiodir;
186 +       unsigned gpio_bank = offset / 10;
187 +       unsigned gpio_field_offset = (offset - 10 * gpio_bank) * 3;
188 +
189 +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set_function %p (%d,%d)\n", gc, offset, function);
190 +       if (offset >= BCM2708_NR_GPIOS)
191 +               return -EINVAL;
192 +
193 +       spin_lock_irqsave(&lock, flags);
194 +
195 +       gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
196 +       gpiodir &= ~(7 << gpio_field_offset);
197 +       gpiodir |= function << gpio_field_offset;
198 +       writel(gpiodir, gpio->base + GPIOFSEL(gpio_bank));
199 +       spin_unlock_irqrestore(&lock, flags);
200 +       gpiodir = readl(gpio->base + GPIOFSEL(gpio_bank));
201 +
202 +       return 0;
203 +}
204 +
205 +static int bcm2708_gpio_dir_in(struct gpio_chip *gc, unsigned offset)
206 +{
207 +       return bcm2708_set_function(gc, offset, GPIO_FSEL_INPUT);
208 +}
209 +
210 +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value);
211 +static int bcm2708_gpio_dir_out(struct gpio_chip *gc, unsigned offset,
212 +                               int value)
213 +{
214 +       int ret;
215 +       ret = bcm2708_set_function(gc, offset, GPIO_FSEL_OUTPUT);
216 +       if (ret >= 0)
217 +               bcm2708_gpio_set(gc, offset, value);
218 +       return ret;
219 +}
220 +
221 +static int bcm2708_gpio_get(struct gpio_chip *gc, unsigned offset)
222 +{
223 +       struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
224 +       unsigned gpio_bank = offset / 32;
225 +       unsigned gpio_field_offset = (offset - 32 * gpio_bank);
226 +       unsigned lev;
227 +
228 +       if (offset >= BCM2708_NR_GPIOS)
229 +               return 0;
230 +       lev = readl(gpio->base + GPIOLEV(gpio_bank));
231 +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_get %p (%d)=%d\n", gc, offset, 0x1 & (lev>>gpio_field_offset));
232 +       return 0x1 & (lev >> gpio_field_offset);
233 +}
234 +
235 +static void bcm2708_gpio_set(struct gpio_chip *gc, unsigned offset, int value)
236 +{
237 +       struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
238 +       unsigned gpio_bank = offset / 32;
239 +       unsigned gpio_field_offset = (offset - 32 * gpio_bank);
240 +//printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_set %p (%d=%d)\n", gc, offset, value);
241 +       if (offset >= BCM2708_NR_GPIOS)
242 +               return;
243 +       if (value)
244 +               writel(1 << gpio_field_offset, gpio->base + GPIOSET(gpio_bank));
245 +       else
246 +               writel(1 << gpio_field_offset, gpio->base + GPIOCLR(gpio_bank));
247 +}
248 +
249 +/**********************
250 + * extension to configure pullups
251 + */
252 +int bcm2708_gpio_setpull(struct gpio_chip *gc, unsigned offset,
253 +               bcm2708_gpio_pull_t value)
254 +{
255 +       struct bcm2708_gpio *gpio = container_of(gc, struct bcm2708_gpio, gc);
256 +       unsigned gpio_bank = offset / 32;
257 +       unsigned gpio_field_offset = (offset - 32 * gpio_bank);
258 +
259 +       if (offset >= BCM2708_NR_GPIOS)
260 +               return -EINVAL;
261 +
262 +       switch (value) {
263 +       case BCM2708_PULL_UP:
264 +               writel(2, gpio->base + GPIOUD(0));
265 +               break;
266 +       case BCM2708_PULL_DOWN:
267 +               writel(1, gpio->base + GPIOUD(0));
268 +               break;
269 +       case BCM2708_PULL_OFF:
270 +               writel(0, gpio->base + GPIOUD(0));
271 +               break;
272 +       }
273 +
274 +       udelay(5);
275 +       writel(1 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));
276 +       udelay(5);
277 +       writel(0, gpio->base + GPIOUD(0));
278 +       writel(0 << gpio_field_offset, gpio->base + GPIOUDCLK(gpio_bank));
279 +
280 +       return 0;
281 +}
282 +EXPORT_SYMBOL(bcm2708_gpio_setpull);
283 +
284 +/*************************************************************************************************************************
285 + * bcm2708 GPIO IRQ
286 + */
287 +
288 +#if BCM_GPIO_USE_IRQ
289 +
290 +static int bcm2708_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
291 +{
292 +       return gpio_to_irq(gpio);
293 +}
294 +
295 +static int bcm2708_gpio_irq_set_type(struct irq_data *d, unsigned type)
296 +{
297 +       unsigned irq = d->irq;
298 +       struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
299 +       unsigned gn = irq_to_gpio(irq);
300 +       unsigned gb = gn / 32;
301 +       unsigned go = gn % 32;
302 +
303 +       gpio->rising[gb]  &= ~(1 << go);
304 +       gpio->falling[gb] &= ~(1 << go);
305 +       gpio->high[gb]    &= ~(1 << go);
306 +       gpio->low[gb]     &= ~(1 << go);
307 +
308 +       if (type & ~(IRQ_TYPE_EDGE_FALLING | IRQ_TYPE_EDGE_RISING | IRQ_TYPE_LEVEL_LOW | IRQ_TYPE_LEVEL_HIGH))
309 +               return -EINVAL;
310 +
311 +       if (type & IRQ_TYPE_EDGE_RISING)
312 +               gpio->rising[gb] |= (1 << go);
313 +       if (type & IRQ_TYPE_EDGE_FALLING)
314 +               gpio->falling[gb] |= (1 << go);
315 +       if (type & IRQ_TYPE_LEVEL_HIGH)
316 +               gpio->high[gb] |= (1 << go);
317 +       if (type & IRQ_TYPE_LEVEL_LOW)
318 +               gpio->low[gb] |= (1 << go);
319 +       return 0;
320 +}
321 +
322 +static void bcm2708_gpio_irq_mask(struct irq_data *d)
323 +{
324 +       unsigned irq = d->irq;
325 +       struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
326 +       unsigned gn = irq_to_gpio(irq);
327 +       unsigned gb = gn / 32;
328 +       unsigned long rising  = readl(gpio->base + GPIOREN(gb));
329 +       unsigned long falling = readl(gpio->base + GPIOFEN(gb));
330 +       unsigned long high    = readl(gpio->base + GPIOHEN(gb));
331 +       unsigned long low     = readl(gpio->base + GPIOLEN(gb));
332 +
333 +       gn = gn % 32;
334 +
335 +       writel(rising  & ~(1 << gn), gpio->base + GPIOREN(gb));
336 +       writel(falling & ~(1 << gn), gpio->base + GPIOFEN(gb));
337 +       writel(high    & ~(1 << gn), gpio->base + GPIOHEN(gb));
338 +       writel(low     & ~(1 << gn), gpio->base + GPIOLEN(gb));
339 +}
340 +
341 +static void bcm2708_gpio_irq_unmask(struct irq_data *d)
342 +{
343 +       unsigned irq = d->irq;
344 +       struct bcm2708_gpio *gpio = irq_get_chip_data(irq);
345 +       unsigned gn = irq_to_gpio(irq);
346 +       unsigned gb = gn / 32;
347 +       unsigned go = gn % 32;
348 +       unsigned long rising  = readl(gpio->base + GPIOREN(gb));
349 +       unsigned long falling = readl(gpio->base + GPIOFEN(gb));
350 +       unsigned long high    = readl(gpio->base + GPIOHEN(gb));
351 +       unsigned long low     = readl(gpio->base + GPIOLEN(gb));
352 +
353 +       if (gpio->rising[gb] & (1 << go)) {
354 +               writel(rising |  (1 << go), gpio->base + GPIOREN(gb));
355 +       } else {
356 +               writel(rising & ~(1 << go), gpio->base + GPIOREN(gb));
357 +       }
358 +
359 +       if (gpio->falling[gb] & (1 << go)) {
360 +               writel(falling |  (1 << go), gpio->base + GPIOFEN(gb));
361 +       } else {
362 +               writel(falling & ~(1 << go), gpio->base + GPIOFEN(gb));
363 +       }
364 +
365 +       if (gpio->high[gb] & (1 << go)) {
366 +               writel(high |  (1 << go), gpio->base + GPIOHEN(gb));
367 +       } else {
368 +               writel(high & ~(1 << go), gpio->base + GPIOHEN(gb));
369 +       }
370 +
371 +       if (gpio->low[gb] & (1 << go)) {
372 +               writel(low |  (1 << go), gpio->base + GPIOLEN(gb));
373 +       } else {
374 +               writel(low & ~(1 << go), gpio->base + GPIOLEN(gb));
375 +       }
376 +}
377 +
378 +static struct irq_chip bcm2708_irqchip = {
379 +       .name = "GPIO",
380 +       .irq_enable = bcm2708_gpio_irq_unmask,
381 +       .irq_disable = bcm2708_gpio_irq_mask,
382 +       .irq_unmask = bcm2708_gpio_irq_unmask,
383 +       .irq_mask = bcm2708_gpio_irq_mask,
384 +       .irq_set_type = bcm2708_gpio_irq_set_type,
385 +};
386 +
387 +static irqreturn_t bcm2708_gpio_interrupt(int irq, void *dev_id)
388 +{
389 +       unsigned long edsr;
390 +       unsigned bank;
391 +       int i;
392 +       unsigned gpio;
393 +       unsigned level_bits;
394 +       struct bcm2708_gpio *gpio_data = dev_id;
395 +
396 +       for (bank = 0; bank < GPIO_BANKS; bank++) {
397 +               edsr = readl(__io_address(GPIO_BASE) + GPIOEDS(bank));
398 +               level_bits = gpio_data->high[bank] | gpio_data->low[bank];
399 +
400 +               for_each_set_bit(i, &edsr, 32) {
401 +                       gpio = i + bank * 32;
402 +                       /* ack edge triggered IRQs immediately */
403 +                       if (!(level_bits & (1<<i)))
404 +                               writel(1<<i,
405 +                                      __io_address(GPIO_BASE) + GPIOEDS(bank));
406 +                       generic_handle_irq(gpio_to_irq(gpio));
407 +                       /* ack level triggered IRQ after handling them */
408 +                       if (level_bits & (1<<i))
409 +                               writel(1<<i,
410 +                                      __io_address(GPIO_BASE) + GPIOEDS(bank));
411 +               }
412 +       }
413 +       return IRQ_HANDLED;
414 +}
415 +
416 +static struct irqaction bcm2708_gpio_irq = {
417 +       .name = "BCM2708 GPIO catchall handler",
418 +       .flags = IRQF_TIMER | IRQF_IRQPOLL,
419 +       .handler = bcm2708_gpio_interrupt,
420 +};
421 +
422 +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
423 +{
424 +       unsigned irq;
425 +
426 +       ucb->gc.to_irq = bcm2708_gpio_to_irq;
427 +
428 +       for (irq = GPIO_IRQ_START; irq < (GPIO_IRQ_START + GPIO_IRQS); irq++) {
429 +               irq_set_chip_data(irq, ucb);
430 +               irq_set_chip_and_handler(irq, &bcm2708_irqchip,
431 +                                        handle_simple_irq);
432 +               set_irq_flags(irq, IRQF_VALID);
433 +       }
434 +
435 +       bcm2708_gpio_irq.dev_id = ucb;
436 +       setup_irq(IRQ_GPIO3, &bcm2708_gpio_irq);
437 +}
438 +
439 +#else
440 +
441 +static void bcm2708_gpio_irq_init(struct bcm2708_gpio *ucb)
442 +{
443 +}
444 +
445 +#endif /* #if BCM_GPIO_USE_IRQ ***************************************************************************************************************** */
446 +
447 +static int bcm2708_gpio_probe(struct platform_device *dev)
448 +{
449 +       struct bcm2708_gpio *ucb;
450 +       struct resource *res;
451 +       int bank;
452 +       int err = 0;
453 +
454 +       printk(KERN_INFO DRIVER_NAME ": bcm2708_gpio_probe %p\n", dev);
455 +
456 +       ucb = kzalloc(sizeof(*ucb), GFP_KERNEL);
457 +       if (NULL == ucb) {
458 +               printk(KERN_ERR DRIVER_NAME ": failed to allocate "
459 +                      "mailbox memory\n");
460 +               err = -ENOMEM;
461 +               goto err;
462 +       }
463 +
464 +       res = platform_get_resource(dev, IORESOURCE_MEM, 0);
465 +
466 +       platform_set_drvdata(dev, ucb);
467 +       ucb->base = __io_address(GPIO_BASE);
468 +
469 +       ucb->gc.label = "bcm2708_gpio";
470 +       ucb->gc.base = 0;
471 +       ucb->gc.ngpio = BCM2708_NR_GPIOS;
472 +       ucb->gc.owner = THIS_MODULE;
473 +
474 +       ucb->gc.direction_input = bcm2708_gpio_dir_in;
475 +       ucb->gc.direction_output = bcm2708_gpio_dir_out;
476 +       ucb->gc.get = bcm2708_gpio_get;
477 +       ucb->gc.set = bcm2708_gpio_set;
478 +       ucb->gc.can_sleep = 0;
479 +
480 +       for (bank = 0; bank < GPIO_BANKS; bank++) {
481 +               writel(0, ucb->base + GPIOREN(bank));
482 +               writel(0, ucb->base + GPIOFEN(bank));
483 +               writel(0, ucb->base + GPIOHEN(bank));
484 +               writel(0, ucb->base + GPIOLEN(bank));
485 +               writel(0, ucb->base + GPIOAREN(bank));
486 +               writel(0, ucb->base + GPIOAFEN(bank));
487 +               writel(~0, ucb->base + GPIOEDS(bank));
488 +       }
489 +
490 +       bcm2708_gpio_irq_init(ucb);
491 +
492 +       err = gpiochip_add(&ucb->gc);
493 +
494 +err:
495 +       return err;
496 +
497 +}
498 +
499 +static int bcm2708_gpio_remove(struct platform_device *dev)
500 +{
501 +       int err = 0;
502 +       struct bcm2708_gpio *ucb = platform_get_drvdata(dev);
503 +
504 +       printk(KERN_ERR DRIVER_NAME ": bcm2708_gpio_remove %p\n", dev);
505 +
506 +       gpiochip_remove(&ucb->gc);
507 +
508 +       platform_set_drvdata(dev, NULL);
509 +       kfree(ucb);
510 +
511 +       return err;
512 +}
513 +
514 +static struct platform_driver bcm2708_gpio_driver = {
515 +       .probe = bcm2708_gpio_probe,
516 +       .remove = bcm2708_gpio_remove,
517 +       .driver = {
518 +                  .name = "bcm2708_gpio"},
519 +};
520 +
521 +static int __init bcm2708_gpio_init(void)
522 +{
523 +       return platform_driver_register(&bcm2708_gpio_driver);
524 +}
525 +
526 +static void __exit bcm2708_gpio_exit(void)
527 +{
528 +       platform_driver_unregister(&bcm2708_gpio_driver);
529 +}
530 +
531 +module_init(bcm2708_gpio_init);
532 +module_exit(bcm2708_gpio_exit);
533 +
534 +MODULE_DESCRIPTION("Broadcom BCM2708 GPIO driver");
535 +MODULE_LICENSE("GPL");
536 --- /dev/null
537 +++ b/arch/arm/mach-bcm2708/include/mach/gpio.h
538 @@ -0,0 +1,17 @@
539 +/*
540 + * arch/arm/mach-bcm2708/include/mach/gpio.h
541 + *
542 + * This file is licensed under the terms of the GNU General Public
543 + * License version 2.  This program is licensed "as is" without any
544 + * warranty of any kind, whether express or implied.
545 + */
546 +
547 +#ifndef __ASM_ARCH_GPIO_H
548 +#define __ASM_ARCH_GPIO_H
549 +
550 +#define BCM2708_NR_GPIOS 54 // number of gpio lines
551 +
552 +#define gpio_to_irq(x) ((x) + GPIO_IRQ_START)
553 +#define irq_to_gpio(x) ((x) - GPIO_IRQ_START)
554 +
555 +#endif
556 --- a/arch/arm/mach-bcm2709/bcm2709.c
557 +++ b/arch/arm/mach-bcm2709/bcm2709.c
558 @@ -329,6 +329,31 @@ static struct platform_device bcm2708_vc
559                 },
560  };
561  
562 +#ifdef CONFIG_BCM2708_GPIO
563 +#define BCM_GPIO_DRIVER_NAME "bcm2708_gpio"
564 +
565 +static struct resource bcm2708_gpio_resources[] = {
566 +       [0] = {                 /* general purpose I/O */
567 +              .start = GPIO_BASE,
568 +              .end = GPIO_BASE + SZ_4K - 1,
569 +              .flags = IORESOURCE_MEM,
570 +              },
571 +};
572 +
573 +static u64 gpio_dmamask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON);
574 +
575 +static struct platform_device bcm2708_gpio_device = {
576 +       .name = BCM_GPIO_DRIVER_NAME,
577 +       .id = -1,               /* only one VideoCore I/O area */
578 +       .resource = bcm2708_gpio_resources,
579 +       .num_resources = ARRAY_SIZE(bcm2708_gpio_resources),
580 +       .dev = {
581 +               .dma_mask = &gpio_dmamask,
582 +               .coherent_dma_mask = DMA_BIT_MASK(DMA_MASK_BITS_COMMON),
583 +               },
584 +};
585 +#endif
586 +
587  int __init bcm_register_device(struct platform_device *pdev)
588  {
589         int ret;
590 --- /dev/null
591 +++ b/include/linux/platform_data/bcm2708.h
592 @@ -0,0 +1,23 @@
593 +/*
594 + * include/linux/platform_data/bcm2708.h
595 + *
596 + * This program is free software; you can redistribute it and/or modify
597 + * it under the terms of the GNU General Public License version 2 as
598 + * published by the Free Software Foundation.
599 + *
600 + * (C) 2014 Julian Scheel <julian@jusst.de>
601 + *
602 + */
603 +#ifndef __BCM2708_H_
604 +#define __BCM2708_H_
605 +
606 +typedef enum {
607 +       BCM2708_PULL_OFF,
608 +       BCM2708_PULL_UP,
609 +       BCM2708_PULL_DOWN
610 +} bcm2708_gpio_pull_t;
611 +
612 +extern int bcm2708_gpio_setpull(struct gpio_chip *gc, unsigned offset,
613 +               bcm2708_gpio_pull_t value);
614 +
615 +#endif