901-Revert-bcma-switch-GPIO-portions-to-use-GPIOLIB_IRQC.patch 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233
  1. From: =?UTF-8?q?Rafa=C5=82=20Mi=C5=82ecki?= <zajec5@gmail.com>
  2. Date: Fri, 18 Dec 2015 07:51:08 +0100
  3. Subject: [PATCH] Revert "bcma: switch GPIO portions to use GPIOLIB_IRQCHIP"
  4. MIME-Version: 1.0
  5. Content-Type: text/plain; charset=UTF-8
  6. Content-Transfer-Encoding: 8bit
  7. This reverts commit 74f4e0cc61080f63f28e8d519bdf437957e64217.
  8. On BCM47XX (MIPS) bcma_bus_get_host_dev returns NULL which results in:
  9. [ 0.157054] missing gpiochip .dev parent pointer
  10. [ 0.157287] bcma: bus0: Error registering GPIO driver: -22
  11. Signed-off-by: Rafał Miłecki <zajec5@gmail.com>
  12. ---
  13. drivers/bcma/Kconfig | 2 +-
  14. drivers/bcma/driver_gpio.c | 92 +++++++++++++++++++----------
  15. include/linux/bcma/bcma_driver_chipcommon.h | 1 +
  16. 3 files changed, 64 insertions(+), 31 deletions(-)
  17. --- a/drivers/bcma/Kconfig
  18. +++ b/drivers/bcma/Kconfig
  19. @@ -106,7 +106,7 @@ config BCMA_DRIVER_GMAC_CMN
  20. config BCMA_DRIVER_GPIO
  21. bool "BCMA GPIO driver"
  22. depends on BCMA && GPIOLIB
  23. - select GPIOLIB_IRQCHIP if BCMA_HOST_SOC
  24. + select IRQ_DOMAIN if BCMA_HOST_SOC
  25. help
  26. Driver to provide access to the GPIO pins of the bcma bus.
  27. --- a/drivers/bcma/driver_gpio.c
  28. +++ b/drivers/bcma/driver_gpio.c
  29. @@ -8,8 +8,10 @@
  30. * Licensed under the GNU/GPL. See COPYING for details.
  31. */
  32. -#include <linux/gpio/driver.h>
  33. +#include <linux/gpio.h>
  34. +#include <linux/irq.h>
  35. #include <linux/interrupt.h>
  36. +#include <linux/irqdomain.h>
  37. #include <linux/export.h>
  38. #include <linux/bcma/bcma.h>
  39. @@ -77,11 +79,19 @@ static void bcma_gpio_free(struct gpio_c
  40. }
  41. #if IS_BUILTIN(CONFIG_BCM47XX) || IS_BUILTIN(CONFIG_ARCH_BCM_5301X)
  42. +static int bcma_gpio_to_irq(struct gpio_chip *chip, unsigned gpio)
  43. +{
  44. + struct bcma_drv_cc *cc = bcma_gpio_get_cc(chip);
  45. +
  46. + if (cc->core->bus->hosttype == BCMA_HOSTTYPE_SOC)
  47. + return irq_find_mapping(cc->irq_domain, gpio);
  48. + else
  49. + return -EINVAL;
  50. +}
  51. static void bcma_gpio_irq_unmask(struct irq_data *d)
  52. {
  53. - struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  54. - struct bcma_drv_cc *cc = bcma_gpio_get_cc(gc);
  55. + struct bcma_drv_cc *cc = irq_data_get_irq_chip_data(d);
  56. int gpio = irqd_to_hwirq(d);
  57. u32 val = bcma_chipco_gpio_in(cc, BIT(gpio));
  58. @@ -91,8 +101,7 @@ static void bcma_gpio_irq_unmask(struct
  59. static void bcma_gpio_irq_mask(struct irq_data *d)
  60. {
  61. - struct gpio_chip *gc = irq_data_get_irq_chip_data(d);
  62. - struct bcma_drv_cc *cc = bcma_gpio_get_cc(gc);
  63. + struct bcma_drv_cc *cc = irq_data_get_irq_chip_data(d);
  64. int gpio = irqd_to_hwirq(d);
  65. bcma_chipco_gpio_intmask(cc, BIT(gpio), 0);
  66. @@ -107,7 +116,6 @@ static struct irq_chip bcma_gpio_irq_chi
  67. static irqreturn_t bcma_gpio_irq_handler(int irq, void *dev_id)
  68. {
  69. struct bcma_drv_cc *cc = dev_id;
  70. - struct gpio_chip *gc = &cc->gpio;
  71. u32 val = bcma_cc_read32(cc, BCMA_CC_GPIOIN);
  72. u32 mask = bcma_cc_read32(cc, BCMA_CC_GPIOIRQ);
  73. u32 pol = bcma_cc_read32(cc, BCMA_CC_GPIOPOL);
  74. @@ -117,58 +125,81 @@ static irqreturn_t bcma_gpio_irq_handler
  75. if (!irqs)
  76. return IRQ_NONE;
  77. - for_each_set_bit(gpio, &irqs, gc->ngpio)
  78. - generic_handle_irq(irq_find_mapping(gc->irqdomain, gpio));
  79. + for_each_set_bit(gpio, &irqs, cc->gpio.ngpio)
  80. + generic_handle_irq(bcma_gpio_to_irq(&cc->gpio, gpio));
  81. bcma_chipco_gpio_polarity(cc, irqs, val & irqs);
  82. return IRQ_HANDLED;
  83. }
  84. -static int bcma_gpio_irq_init(struct bcma_drv_cc *cc)
  85. +static int bcma_gpio_irq_domain_init(struct bcma_drv_cc *cc)
  86. {
  87. struct gpio_chip *chip = &cc->gpio;
  88. - int hwirq, err;
  89. + int gpio, hwirq, err;
  90. if (cc->core->bus->hosttype != BCMA_HOSTTYPE_SOC)
  91. return 0;
  92. + cc->irq_domain = irq_domain_add_linear(NULL, chip->ngpio,
  93. + &irq_domain_simple_ops, cc);
  94. + if (!cc->irq_domain) {
  95. + err = -ENODEV;
  96. + goto err_irq_domain;
  97. + }
  98. + for (gpio = 0; gpio < chip->ngpio; gpio++) {
  99. + int irq = irq_create_mapping(cc->irq_domain, gpio);
  100. +
  101. + irq_set_chip_data(irq, cc);
  102. + irq_set_chip_and_handler(irq, &bcma_gpio_irq_chip,
  103. + handle_simple_irq);
  104. + }
  105. +
  106. hwirq = bcma_core_irq(cc->core, 0);
  107. err = request_irq(hwirq, bcma_gpio_irq_handler, IRQF_SHARED, "gpio",
  108. cc);
  109. if (err)
  110. - return err;
  111. + goto err_req_irq;
  112. bcma_chipco_gpio_intmask(cc, ~0, 0);
  113. bcma_cc_set32(cc, BCMA_CC_IRQMASK, BCMA_CC_IRQ_GPIO);
  114. - err = gpiochip_irqchip_add(chip,
  115. - &bcma_gpio_irq_chip,
  116. - 0,
  117. - handle_simple_irq,
  118. - IRQ_TYPE_NONE);
  119. - if (err) {
  120. - free_irq(hwirq, cc);
  121. - return err;
  122. - }
  123. -
  124. return 0;
  125. +
  126. +err_req_irq:
  127. + for (gpio = 0; gpio < chip->ngpio; gpio++) {
  128. + int irq = irq_find_mapping(cc->irq_domain, gpio);
  129. +
  130. + irq_dispose_mapping(irq);
  131. + }
  132. + irq_domain_remove(cc->irq_domain);
  133. +err_irq_domain:
  134. + return err;
  135. }
  136. -static void bcma_gpio_irq_exit(struct bcma_drv_cc *cc)
  137. +static void bcma_gpio_irq_domain_exit(struct bcma_drv_cc *cc)
  138. {
  139. + struct gpio_chip *chip = &cc->gpio;
  140. + int gpio;
  141. +
  142. if (cc->core->bus->hosttype != BCMA_HOSTTYPE_SOC)
  143. return;
  144. bcma_cc_mask32(cc, BCMA_CC_IRQMASK, ~BCMA_CC_IRQ_GPIO);
  145. free_irq(bcma_core_irq(cc->core, 0), cc);
  146. + for (gpio = 0; gpio < chip->ngpio; gpio++) {
  147. + int irq = irq_find_mapping(cc->irq_domain, gpio);
  148. +
  149. + irq_dispose_mapping(irq);
  150. + }
  151. + irq_domain_remove(cc->irq_domain);
  152. }
  153. #else
  154. -static int bcma_gpio_irq_init(struct bcma_drv_cc *cc)
  155. +static int bcma_gpio_irq_domain_init(struct bcma_drv_cc *cc)
  156. {
  157. return 0;
  158. }
  159. -static void bcma_gpio_irq_exit(struct bcma_drv_cc *cc)
  160. +static void bcma_gpio_irq_domain_exit(struct bcma_drv_cc *cc)
  161. {
  162. }
  163. #endif
  164. @@ -187,8 +218,9 @@ int bcma_gpio_init(struct bcma_drv_cc *c
  165. chip->set = bcma_gpio_set_value;
  166. chip->direction_input = bcma_gpio_direction_input;
  167. chip->direction_output = bcma_gpio_direction_output;
  168. - chip->owner = THIS_MODULE;
  169. - chip->dev = bcma_bus_get_host_dev(bus);
  170. +#if IS_BUILTIN(CONFIG_BCM47XX) || IS_BUILTIN(CONFIG_ARCH_BCM_5301X)
  171. + chip->to_irq = bcma_gpio_to_irq;
  172. +#endif
  173. #if IS_BUILTIN(CONFIG_OF)
  174. if (cc->core->bus->hosttype == BCMA_HOSTTYPE_SOC)
  175. chip->of_node = cc->core->dev.of_node;
  176. @@ -217,13 +249,13 @@ int bcma_gpio_init(struct bcma_drv_cc *c
  177. else
  178. chip->base = -1;
  179. - err = gpiochip_add(chip);
  180. + err = bcma_gpio_irq_domain_init(cc);
  181. if (err)
  182. return err;
  183. - err = bcma_gpio_irq_init(cc);
  184. + err = gpiochip_add(chip);
  185. if (err) {
  186. - gpiochip_remove(chip);
  187. + bcma_gpio_irq_domain_exit(cc);
  188. return err;
  189. }
  190. @@ -232,7 +264,7 @@ int bcma_gpio_init(struct bcma_drv_cc *c
  191. int bcma_gpio_unregister(struct bcma_drv_cc *cc)
  192. {
  193. - bcma_gpio_irq_exit(cc);
  194. + bcma_gpio_irq_domain_exit(cc);
  195. gpiochip_remove(&cc->gpio);
  196. return 0;
  197. }
  198. --- a/include/linux/bcma/bcma_driver_chipcommon.h
  199. +++ b/include/linux/bcma/bcma_driver_chipcommon.h
  200. @@ -646,6 +646,7 @@ struct bcma_drv_cc {
  201. spinlock_t gpio_lock;
  202. #ifdef CONFIG_BCMA_DRIVER_GPIO
  203. struct gpio_chip gpio;
  204. + struct irq_domain *irq_domain;
  205. #endif
  206. };