0002-Add-bcm2708_gpio-driver.patch 17 KB

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