374-gpio-add-a-simple-GPIO-driver-for-bcm63xx.patch 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  1. From dbe94a8daaa63ef81b7414f2a17bca8e36dd6daa Mon Sep 17 00:00:00 2001
  2. From: Jonas Gorski <[email protected]>
  3. Date: Fri, 20 Feb 2015 19:55:32 +0100
  4. Subject: [PATCH 1/6] gpio: add a simple GPIO driver for bcm63xx
  5. Signed-off-by: Jonas Gorski <[email protected]>
  6. ---
  7. drivers/gpio/Kconfig | 8 +++
  8. drivers/gpio/Makefile | 1 +
  9. drivers/gpio/gpio-bcm63xx.c | 135 +++++++++++++++++++++++++++++++++++++++++++
  10. 3 files changed, 131 insertions(+)
  11. create mode 100644 drivers/gpio/gpio-bcm63xx.c
  12. --- a/drivers/gpio/Kconfig
  13. +++ b/drivers/gpio/Kconfig
  14. @@ -134,6 +134,13 @@ config GPIO_BCM_KONA
  15. help
  16. Turn on GPIO support for Broadcom "Kona" chips.
  17. +config GPIO_BCM63XX
  18. + bool "Broadcom BCM63XX GPIO"
  19. + depends on MIPS || COMPILE_TEST
  20. + select GPIO_GENERIC
  21. + help
  22. + Turn on GPIO support for Broadcom BCM63XX xDSL chips.
  23. +
  24. config GPIO_BRCMSTB
  25. tristate "BRCMSTB GPIO support"
  26. default y if (ARCH_BRCMSTB || BMIPS_GENERIC)
  27. --- a/drivers/gpio/Makefile
  28. +++ b/drivers/gpio/Makefile
  29. @@ -31,6 +31,7 @@ obj-$(CONFIG_GPIO_ATH79) += gpio-ath79.o
  30. obj-$(CONFIG_GPIO_ASPEED) += gpio-aspeed.o
  31. obj-$(CONFIG_GPIO_AXP209) += gpio-axp209.o
  32. obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o
  33. +obj-$(CONFIG_GPIO_BCM63XX) += gpio-bcm63xx.o
  34. obj-$(CONFIG_GPIO_BRCMSTB) += gpio-brcmstb.o
  35. obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o
  36. obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o
  37. --- /dev/null
  38. +++ b/drivers/gpio/gpio-bcm63xx.c
  39. @@ -0,0 +1,135 @@
  40. +/*
  41. + * Driver for BCM63XX memory-mapped GPIO controllers, based on
  42. + * Generic driver for memory-mapped GPIO controllers.
  43. + *
  44. + * Copyright 2008 MontaVista Software, Inc.
  45. + * Copyright 2008,2010 Anton Vorontsov <[email protected]>
  46. + * Copyright 2015 Jonas Gorski <[email protected]>
  47. + *
  48. + * This program is free software; you can redistribute it and/or modify it
  49. + * under the terms of the GNU General Public License as published by the
  50. + * Free Software Foundation; either version 2 of the License, or (at your
  51. + * option) any later version.
  52. + */
  53. +
  54. +#include <linux/init.h>
  55. +#include <linux/err.h>
  56. +#include <linux/bug.h>
  57. +#include <linux/kernel.h>
  58. +#include <linux/module.h>
  59. +#include <linux/spinlock.h>
  60. +#include <linux/compiler.h>
  61. +#include <linux/types.h>
  62. +#include <linux/errno.h>
  63. +#include <linux/log2.h>
  64. +#include <linux/ioport.h>
  65. +#include <linux/io.h>
  66. +#include <linux/gpio.h>
  67. +#include <linux/gpio/driver.h>
  68. +#include <linux/slab.h>
  69. +#include <linux/platform_device.h>
  70. +#include <linux/mod_devicetable.h>
  71. +#include <linux/of.h>
  72. +#include <linux/of_irq.h>
  73. +#include <linux/of_gpio.h>
  74. +
  75. +static int bcm63xx_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  76. +{
  77. + char irq_name[7]; /* "gpioXX" */
  78. +
  79. + sprintf(irq_name, "gpio%d", gpio);
  80. + return of_irq_get_byname(chip->of_node, irq_name);
  81. +}
  82. +
  83. +static int bcm63xx_gpio_probe(struct platform_device *pdev)
  84. +{
  85. + struct device *dev = &pdev->dev;
  86. + struct resource *dat_r, *dirout_r;
  87. + void __iomem *dat;
  88. + void __iomem *dirout;
  89. + unsigned long sz;
  90. + int err;
  91. + struct gpio_chip *gc;
  92. + struct bgpio_pdata *pdata = dev_get_platdata(dev);
  93. +
  94. + dirout_r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  95. + dat_r = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  96. + if (!dat_r || !dirout_r)
  97. + return -EINVAL;
  98. +
  99. + if (resource_size(dat_r) != resource_size(dirout_r))
  100. + return -EINVAL;
  101. +
  102. + sz = resource_size(dat_r);
  103. +
  104. + dat = devm_ioremap_resource(dev, dat_r);
  105. + if (IS_ERR(dat))
  106. + return PTR_ERR(dat);
  107. +
  108. + dirout = devm_ioremap_resource(dev, dirout_r);
  109. + if (IS_ERR(dirout))
  110. + return PTR_ERR(dirout);
  111. +
  112. + gc = devm_kzalloc(&pdev->dev, sizeof(*gc), GFP_KERNEL);
  113. + if (!gc)
  114. + return -ENOMEM;
  115. +
  116. + err = bgpio_init(gc, dev, sz, dat, NULL, NULL, dirout, NULL,
  117. + BGPIOF_BIG_ENDIAN_BYTE_ORDER);
  118. + if (err)
  119. + return err;
  120. +
  121. + platform_set_drvdata(pdev, gc);
  122. +
  123. + if (dev->of_node) {
  124. + int id = of_alias_get_id(dev->of_node, "gpio");
  125. + u32 ngpios;
  126. +
  127. + if (id >= 0)
  128. + gc->label = devm_kasprintf(dev, GFP_KERNEL,
  129. + "bcm63xx-gpio.%d", id);
  130. +
  131. + if (!of_property_read_u32(dev->of_node, "ngpios", &ngpios))
  132. + gc->ngpio = ngpios;
  133. +
  134. + if (of_get_property(dev->of_node, "interrupt-names", NULL))
  135. + gc->to_irq = bcm63xx_gpio_to_irq;
  136. +
  137. + } else if (pdata) {
  138. + gc->base = pdata->base;
  139. + if (pdata->ngpio > 0)
  140. + gc->ngpio = pdata->ngpio;
  141. + }
  142. +
  143. + return gpiochip_add(gc);
  144. +}
  145. +
  146. +static int bcm63xx_gpio_remove(struct platform_device *pdev)
  147. +{
  148. + struct gpio_chip *gc = platform_get_drvdata(pdev);
  149. +
  150. + gpiochip_remove(gc);
  151. + return 0;
  152. +}
  153. +
  154. +#ifdef CONFIG_OF
  155. +static struct of_device_id bcm63xx_gpio_of_match[] = {
  156. + { .compatible = "brcm,bcm6345-gpio" },
  157. + { },
  158. +};
  159. +#endif
  160. +
  161. +static struct platform_driver bcm63xx_gpio_driver = {
  162. + .probe = bcm63xx_gpio_probe,
  163. + .remove = bcm63xx_gpio_remove,
  164. + .driver = {
  165. + .name = "bcm63xx-gpio",
  166. + .of_match_table = of_match_ptr(bcm63xx_gpio_of_match),
  167. + },
  168. +};
  169. +
  170. +module_platform_driver(bcm63xx_gpio_driver);
  171. +
  172. +MODULE_DESCRIPTION("Driver for BCM63XX memory-mapped GPIO controllers");
  173. +MODULE_AUTHOR("Jonas Gorski <[email protected]>");
  174. +MODULE_LICENSE("GPL");