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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. From dbe94a8daaa63ef81b7414f2a17bca8e36dd6daa Mon Sep 17 00:00:00 2001
  2. From: Jonas Gorski <jogo@openwrt.org>
  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 <jogo@openwrt.org>
  6. ---
  7. drivers/gpio/Kconfig | 8 +++
  8. drivers/gpio/Makefile | 1 +
  9. drivers/gpio/gpio-bcm63xx.c | 122 +++++++++++++++++++++++++++++++++++++++++++
  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. @@ -893,6 +893,14 @@ 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. +
  25. comment "USB GPIO expanders:"
  26. config GPIO_VIPERBOARD
  27. --- a/drivers/gpio/Makefile
  28. +++ b/drivers/gpio/Makefile
  29. @@ -19,6 +19,7 @@ obj-$(CONFIG_GPIO_ADP5588) += gpio-adp55
  30. obj-$(CONFIG_GPIO_AMD8111) += gpio-amd8111.o
  31. obj-$(CONFIG_GPIO_ARIZONA) += gpio-arizona.o
  32. obj-$(CONFIG_GPIO_BCM_KONA) += gpio-bcm-kona.o
  33. +obj-$(CONFIG_GPIO_BCM63XX) += gpio-bcm63xx.o
  34. obj-$(CONFIG_GPIO_BT8XX) += gpio-bt8xx.o
  35. obj-$(CONFIG_GPIO_CLPS711X) += gpio-clps711x.o
  36. obj-$(CONFIG_GPIO_CS5535) += gpio-cs5535.o
  37. --- /dev/null
  38. +++ b/drivers/gpio/gpio-bcm63xx.c
  39. @@ -0,0 +1,122 @@
  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 <cbouatmailru@gmail.com>
  46. + * Copyright 2015 Jonas Gorski <jogo@openwrt.org>
  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/slab.h>
  68. +#include <linux/platform_device.h>
  69. +#include <linux/mod_devicetable.h>
  70. +#include <linux/basic_mmio_gpio.h>
  71. +#include <linux/of.h>
  72. +#include <linux/of_gpio.h>
  73. +
  74. +static int bcm63xx_gpio_probe(struct platform_device *pdev)
  75. +{
  76. + struct device *dev = &pdev->dev;
  77. + struct resource *dat_r, *dirout_r;
  78. + void __iomem *dat;
  79. + void __iomem *dirout;
  80. + unsigned long sz;
  81. + int err;
  82. + struct bgpio_chip *bgc;
  83. + struct bgpio_pdata *pdata = dev_get_platdata(dev);
  84. +
  85. + dirout_r = platform_get_resource(pdev, IORESOURCE_MEM, 0);
  86. + dat_r = platform_get_resource(pdev, IORESOURCE_MEM, 1);
  87. + if (!dat_r || !dirout_r)
  88. + return -EINVAL;
  89. +
  90. + if (resource_size(dat_r) != resource_size(dirout_r))
  91. + return -EINVAL;
  92. +
  93. + sz = resource_size(dat_r);
  94. +
  95. + dat = devm_ioremap_resource(dev, dat_r);
  96. + if (IS_ERR(dat))
  97. + return PTR_ERR(dat);
  98. +
  99. + dirout = devm_ioremap_resource(dev, dirout_r);
  100. + if (IS_ERR(dirout))
  101. + return PTR_ERR(dirout);
  102. +
  103. + bgc = devm_kzalloc(&pdev->dev, sizeof(*bgc), GFP_KERNEL);
  104. + if (!bgc)
  105. + return -ENOMEM;
  106. +
  107. + err = bgpio_init(bgc, dev, sz, dat, NULL, NULL, dirout, NULL,
  108. + BGPIOF_BIG_ENDIAN_BYTE_ORDER);
  109. + if (err)
  110. + return err;
  111. +
  112. + platform_set_drvdata(pdev, bgc);
  113. +
  114. + if (dev->of_node) {
  115. + int id = of_alias_get_id(dev->of_node, "gpio");
  116. + u32 ngpios;
  117. +
  118. + if (id >= 0)
  119. + bgc->gc.label = devm_kasprintf(dev, GFP_KERNEL,
  120. + "bcm63xx-gpio.%d", id);
  121. +
  122. + if (!of_property_read_u32(dev->of_node, "ngpios", &ngpios))
  123. + bgc->gc.ngpio = ngpios;
  124. +
  125. + } else if (pdata) {
  126. + bgc->gc.base = pdata->base;
  127. + if (pdata->ngpio > 0)
  128. + bgc->gc.ngpio = pdata->ngpio;
  129. + }
  130. +
  131. + return gpiochip_add(&bgc->gc);
  132. +}
  133. +
  134. +static int bcm63xx_gpio_remove(struct platform_device *pdev)
  135. +{
  136. + struct bgpio_chip *bgc = platform_get_drvdata(pdev);
  137. +
  138. + return bgpio_remove(bgc);
  139. +}
  140. +
  141. +#ifdef CONFIG_OF
  142. +static struct of_device_id bcm63xx_gpio_of_match[] = {
  143. + { .compatible = "brcm,bcm6345-gpio" },
  144. + { },
  145. +};
  146. +#endif
  147. +
  148. +static struct platform_driver bcm63xx_gpio_driver = {
  149. + .probe = bcm63xx_gpio_probe,
  150. + .remove = bcm63xx_gpio_remove,
  151. + .driver = {
  152. + .name = "bcm63xx-gpio",
  153. + .of_match_table = of_match_ptr(bcm63xx_gpio_of_match),
  154. + },
  155. +};
  156. +
  157. +module_platform_driver(bcm63xx_gpio_driver);
  158. +
  159. +MODULE_DESCRIPTION("Driver for BCM63XX memory-mapped GPIO controllers");
  160. +MODULE_AUTHOR("Jonas Gorski <jogo@openwrt.org>");
  161. +MODULE_LICENSE("GPL");