375-MIPS-BCM63XX-switch-to-new-gpio-driver.patch 5.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  1. From cc99dca188bb63ba390008e2f7fa62d0300233e0 Mon Sep 17 00:00:00 2001
  2. From: Jonas Gorski <jogo@openwrt.org>
  3. Date: Fri, 20 Feb 2015 23:58:54 +0100
  4. Subject: [PATCH 2/6] MIPS: BCM63XX: switch to new gpio driver
  5. Signed-off-by: Jonas Gorski <jogo@openwrt.org>
  6. ---
  7. arch/mips/bcm63xx/boards/board_common.c | 2 +
  8. arch/mips/bcm63xx/gpio.c | 147 +++++++------------------------
  9. arch/mips/bcm63xx/setup.c | 3 -
  10. 3 files changed, 33 insertions(+), 119 deletions(-)
  11. --- a/arch/mips/bcm63xx/boards/board_common.c
  12. +++ b/arch/mips/bcm63xx/boards/board_common.c
  13. @@ -189,6 +189,8 @@ int __init board_register_devices(void)
  14. }
  15. #endif
  16. + bcm63xx_gpio_init();
  17. +
  18. if (board.has_uart0)
  19. bcm63xx_uart_register(0);
  20. --- a/arch/mips/bcm63xx/gpio.c
  21. +++ b/arch/mips/bcm63xx/gpio.c
  22. @@ -5,147 +5,62 @@
  23. *
  24. * Copyright (C) 2008 Maxime Bizon <mbizon@freebox.fr>
  25. * Copyright (C) 2008-2011 Florian Fainelli <florian@openwrt.org>
  26. + * Copyright (C) Jonas Gorski <jogo@openwrt.org>
  27. */
  28. #include <linux/kernel.h>
  29. -#include <linux/module.h>
  30. -#include <linux/spinlock.h>
  31. #include <linux/platform_device.h>
  32. +#include <linux/basic_mmio_gpio.h>
  33. #include <linux/gpio.h>
  34. #include <bcm63xx_cpu.h>
  35. #include <bcm63xx_gpio.h>
  36. -#include <bcm63xx_io.h>
  37. #include <bcm63xx_regs.h>
  38. -static u32 gpio_out_low_reg;
  39. -
  40. -static void bcm63xx_gpio_out_low_reg_init(void)
  41. +static void __init bcm63xx_gpio_init_one(int id, int dir, int data, int ngpio)
  42. {
  43. - switch (bcm63xx_get_cpu_id()) {
  44. - case BCM6345_CPU_ID:
  45. - gpio_out_low_reg = GPIO_DATA_LO_REG_6345;
  46. - break;
  47. - default:
  48. - gpio_out_low_reg = GPIO_DATA_LO_REG;
  49. - break;
  50. - }
  51. -}
  52. -
  53. -static DEFINE_SPINLOCK(bcm63xx_gpio_lock);
  54. -static u32 gpio_out_low, gpio_out_high;
  55. + struct resource res[2];
  56. + struct bgpio_pdata pdata;
  57. -static void bcm63xx_gpio_set(struct gpio_chip *chip,
  58. - unsigned gpio, int val)
  59. -{
  60. - u32 reg;
  61. - u32 mask;
  62. - u32 *v;
  63. - unsigned long flags;
  64. -
  65. - if (gpio >= chip->ngpio)
  66. - BUG();
  67. -
  68. - if (gpio < 32) {
  69. - reg = gpio_out_low_reg;
  70. - mask = 1 << gpio;
  71. - v = &gpio_out_low;
  72. - } else {
  73. - reg = GPIO_DATA_HI_REG;
  74. - mask = 1 << (gpio - 32);
  75. - v = &gpio_out_high;
  76. - }
  77. -
  78. - spin_lock_irqsave(&bcm63xx_gpio_lock, flags);
  79. - if (val)
  80. - *v |= mask;
  81. - else
  82. - *v &= ~mask;
  83. - bcm_gpio_writel(*v, reg);
  84. - spin_unlock_irqrestore(&bcm63xx_gpio_lock, flags);
  85. -}
  86. + memset(res, 0, sizeof(res));
  87. + memset(&pdata, 0, sizeof(pdata));
  88. -static int bcm63xx_gpio_get(struct gpio_chip *chip, unsigned gpio)
  89. -{
  90. - u32 reg;
  91. - u32 mask;
  92. + res[0].flags = IORESOURCE_MEM;
  93. + res[0].start = bcm63xx_regset_address(RSET_GPIO);
  94. + res[0].start += dir;
  95. - if (gpio >= chip->ngpio)
  96. - BUG();
  97. + res[0].end = res[0].start + 3;
  98. - if (gpio < 32) {
  99. - reg = gpio_out_low_reg;
  100. - mask = 1 << gpio;
  101. - } else {
  102. - reg = GPIO_DATA_HI_REG;
  103. - mask = 1 << (gpio - 32);
  104. - }
  105. + res[1].flags = IORESOURCE_MEM;
  106. + res[1].start = bcm63xx_regset_address(RSET_GPIO);
  107. + res[1].start += data;
  108. - return !!(bcm_gpio_readl(reg) & mask);
  109. -}
  110. + res[1].end = res[1].start + 3;
  111. -static int bcm63xx_gpio_set_direction(struct gpio_chip *chip,
  112. - unsigned gpio, int dir)
  113. -{
  114. - u32 reg;
  115. - u32 mask;
  116. - u32 tmp;
  117. - unsigned long flags;
  118. -
  119. - if (gpio >= chip->ngpio)
  120. - BUG();
  121. -
  122. - if (gpio < 32) {
  123. - reg = GPIO_CTL_LO_REG;
  124. - mask = 1 << gpio;
  125. - } else {
  126. - reg = GPIO_CTL_HI_REG;
  127. - mask = 1 << (gpio - 32);
  128. - }
  129. -
  130. - spin_lock_irqsave(&bcm63xx_gpio_lock, flags);
  131. - tmp = bcm_gpio_readl(reg);
  132. - if (dir == BCM63XX_GPIO_DIR_IN)
  133. - tmp &= ~mask;
  134. - else
  135. - tmp |= mask;
  136. - bcm_gpio_writel(tmp, reg);
  137. - spin_unlock_irqrestore(&bcm63xx_gpio_lock, flags);
  138. + pdata.base = id * 32;
  139. + pdata.ngpio = ngpio;
  140. - return 0;
  141. + platform_device_register_resndata(NULL, "bcm63xx-gpio", id, res, 2,
  142. + &pdata, sizeof(pdata));
  143. }
  144. -static int bcm63xx_gpio_direction_input(struct gpio_chip *chip, unsigned gpio)
  145. +int __init bcm63xx_gpio_init(void)
  146. {
  147. - return bcm63xx_gpio_set_direction(chip, gpio, BCM63XX_GPIO_DIR_IN);
  148. -}
  149. + int ngpio = bcm63xx_gpio_count();
  150. + int data_low_reg;
  151. -static int bcm63xx_gpio_direction_output(struct gpio_chip *chip,
  152. - unsigned gpio, int value)
  153. -{
  154. - bcm63xx_gpio_set(chip, gpio, value);
  155. - return bcm63xx_gpio_set_direction(chip, gpio, BCM63XX_GPIO_DIR_OUT);
  156. -}
  157. + if (BCMCPU_IS_6345())
  158. + data_low_reg = GPIO_DATA_LO_REG_6345;
  159. + else
  160. + data_low_reg = GPIO_DATA_LO_REG;
  161. + bcm63xx_gpio_init_one(0, GPIO_CTL_LO_REG, data_low_reg, min(ngpio, 32));
  162. -static struct gpio_chip bcm63xx_gpio_chip = {
  163. - .label = "bcm63xx-gpio",
  164. - .direction_input = bcm63xx_gpio_direction_input,
  165. - .direction_output = bcm63xx_gpio_direction_output,
  166. - .get = bcm63xx_gpio_get,
  167. - .set = bcm63xx_gpio_set,
  168. - .base = 0,
  169. -};
  170. + if (ngpio <= 32)
  171. + return 0;
  172. -int __init bcm63xx_gpio_init(void)
  173. -{
  174. - bcm63xx_gpio_out_low_reg_init();
  175. + bcm63xx_gpio_init_one(1, GPIO_CTL_HI_REG, GPIO_DATA_HI_REG, ngpio - 32);
  176. - gpio_out_low = bcm_gpio_readl(gpio_out_low_reg);
  177. - if (!BCMCPU_IS_6345())
  178. - gpio_out_high = bcm_gpio_readl(GPIO_DATA_HI_REG);
  179. - bcm63xx_gpio_chip.ngpio = bcm63xx_gpio_count();
  180. - pr_info("registering %d GPIOs\n", bcm63xx_gpio_chip.ngpio);
  181. + return 0;
  182. - return gpiochip_add(&bcm63xx_gpio_chip);
  183. }
  184. --- a/arch/mips/bcm63xx/setup.c
  185. +++ b/arch/mips/bcm63xx/setup.c
  186. @@ -164,9 +164,6 @@ void __init plat_mem_setup(void)
  187. int __init bcm63xx_register_devices(void)
  188. {
  189. - /* register gpiochip */
  190. - bcm63xx_gpio_init();
  191. -
  192. return board_register_devices();
  193. }