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

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