8042-drivers-gpio-Port-gpio-driver-to-support-layerscape-.patch 9.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. From c2d0a12b5cfa61e43494483f5d1ee466b4998830 Mon Sep 17 00:00:00 2001
  2. From: Liu Gang <Gang.Liu@nxp.com>
  3. Date: Thu, 14 Jan 2016 19:48:09 +0800
  4. Subject: [PATCH 42/70] drivers/gpio: Port gpio driver to support layerscape
  5. platform
  6. Layerscape has the same ip block/controller as
  7. GPIO on powerpc platform(MPC8XXX).
  8. So use portable i/o accessors, as in_be32/out_be32
  9. accessors are Power architecture specific whereas
  10. ioread32/iowrite32 and ioread32be/iowrite32be are
  11. available in other architectures.
  12. Layerscape GPIO controller's registers may be big
  13. or little endian, so the code needs to get the
  14. endian property from DTB, then make additional
  15. functions to fit right register read/write
  16. operations.
  17. Currently the code can support ls2080a GPIO with
  18. little endian registers. And it can also work well
  19. on other layerscape platform with big endian GPIO
  20. registers.
  21. Signed-off-by: Liu Gang <Gang.Liu@nxp.com>
  22. ---
  23. drivers/gpio/Kconfig | 7 ++--
  24. drivers/gpio/gpio-mpc8xxx.c | 87 +++++++++++++++++++++++++++++++------------
  25. 2 files changed, 68 insertions(+), 26 deletions(-)
  26. --- a/drivers/gpio/Kconfig
  27. +++ b/drivers/gpio/Kconfig
  28. @@ -282,12 +282,13 @@ config GPIO_MPC5200
  29. depends on PPC_MPC52xx
  30. config GPIO_MPC8XXX
  31. - bool "MPC512x/MPC8xxx GPIO support"
  32. + bool "MPC512x/MPC8xxx/QorIQ GPIO support"
  33. depends on PPC_MPC512x || PPC_MPC831x || PPC_MPC834x || PPC_MPC837x || \
  34. - FSL_SOC_BOOKE || PPC_86xx
  35. + FSL_SOC_BOOKE || PPC_86xx || ARCH_LAYERSCAPE || ARM || \
  36. + COMPILE_TEST
  37. help
  38. Say Y here if you're going to use hardware that connects to the
  39. - MPC512x/831x/834x/837x/8572/8610 GPIOs.
  40. + MPC512x/831x/834x/837x/8572/8610/QorIQ GPIOs.
  41. config GPIO_MVEBU
  42. def_bool y
  43. --- a/drivers/gpio/gpio-mpc8xxx.c
  44. +++ b/drivers/gpio/gpio-mpc8xxx.c
  45. @@ -1,5 +1,5 @@
  46. /*
  47. - * GPIOs on MPC512x/8349/8572/8610 and compatible
  48. + * GPIOs on MPC512x/8349/8572/8610/QorIQ and compatible
  49. *
  50. * Copyright (C) 2008 Peter Korsgaard <jacmet@sunsite.dk>
  51. *
  52. @@ -19,6 +19,7 @@
  53. #include <linux/gpio.h>
  54. #include <linux/slab.h>
  55. #include <linux/irq.h>
  56. +#include <linux/irqdomain.h>
  57. #define MPC8XXX_GPIO_PINS 32
  58. @@ -44,6 +45,27 @@ struct mpc8xxx_gpio_chip {
  59. const void *of_dev_id_data;
  60. };
  61. +static bool gpio_little_endian;
  62. +static inline u32 gpio_in32(void __iomem *addr)
  63. +{
  64. + u32 val;
  65. +
  66. + if (gpio_little_endian)
  67. + val = ioread32(addr);
  68. + else
  69. + val = ioread32be(addr);
  70. +
  71. + return val;
  72. +}
  73. +
  74. +static inline void gpio_out32(u32 val, void __iomem *addr)
  75. +{
  76. + if (gpio_little_endian)
  77. + iowrite32(val, addr);
  78. + else
  79. + iowrite32be(val, addr);
  80. +}
  81. +
  82. static inline u32 mpc8xxx_gpio2mask(unsigned int gpio)
  83. {
  84. return 1u << (MPC8XXX_GPIO_PINS - 1 - gpio);
  85. @@ -59,9 +81,17 @@ static void mpc8xxx_gpio_save_regs(struc
  86. {
  87. struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
  88. - mpc8xxx_gc->data = in_be32(mm->regs + GPIO_DAT);
  89. + mpc8xxx_gc->data = gpio_in32(mm->regs + GPIO_DAT);
  90. }
  91. +/* Generic set and clear bits accessor ports */
  92. +#define bgpio_setbits32(_addr, _v) \
  93. + gpio_out32(gpio_in32(_addr) | (_v), (_addr))
  94. +#define bgpio_clrbits32(_addr, _v) \
  95. + gpio_out32(gpio_in32(_addr) & ~(_v), (_addr))
  96. +#define bgpio_clrsetbits32(addr, clear, set) \
  97. + gpio_out32((gpio_in32(addr) & ~(clear)) | (set), (addr))
  98. +
  99. /* Workaround GPIO 1 errata on MPC8572/MPC8536. The status of GPIOs
  100. * defined as output cannot be determined by reading GPDAT register,
  101. * so we use shadow data register instead. The status of input pins
  102. @@ -74,9 +104,9 @@ static int mpc8572_gpio_get(struct gpio_
  103. struct mpc8xxx_gpio_chip *mpc8xxx_gc = to_mpc8xxx_gpio_chip(mm);
  104. u32 out_mask, out_shadow;
  105. - out_mask = in_be32(mm->regs + GPIO_DIR);
  106. + out_mask = gpio_in32(mm->regs + GPIO_DIR);
  107. - val = in_be32(mm->regs + GPIO_DAT) & ~out_mask;
  108. + val = gpio_in32(mm->regs + GPIO_DAT) & ~out_mask;
  109. out_shadow = mpc8xxx_gc->data & out_mask;
  110. return (val | out_shadow) & mpc8xxx_gpio2mask(gpio);
  111. @@ -86,7 +116,7 @@ static int mpc8xxx_gpio_get(struct gpio_
  112. {
  113. struct of_mm_gpio_chip *mm = to_of_mm_gpio_chip(gc);
  114. - return in_be32(mm->regs + GPIO_DAT) & mpc8xxx_gpio2mask(gpio);
  115. + return gpio_in32(mm->regs + GPIO_DAT) & mpc8xxx_gpio2mask(gpio);
  116. }
  117. static void mpc8xxx_gpio_set(struct gpio_chip *gc, unsigned int gpio, int val)
  118. @@ -102,7 +132,7 @@ static void mpc8xxx_gpio_set(struct gpio
  119. else
  120. mpc8xxx_gc->data &= ~mpc8xxx_gpio2mask(gpio);
  121. - out_be32(mm->regs + GPIO_DAT, mpc8xxx_gc->data);
  122. + gpio_out32(mpc8xxx_gc->data, mm->regs + GPIO_DAT);
  123. raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
  124. }
  125. @@ -128,7 +158,7 @@ static void mpc8xxx_gpio_set_multiple(st
  126. }
  127. }
  128. - out_be32(mm->regs + GPIO_DAT, mpc8xxx_gc->data);
  129. + gpio_out32(mpc8xxx_gc->data, mm->regs + GPIO_DAT);
  130. raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
  131. }
  132. @@ -141,7 +171,7 @@ static int mpc8xxx_gpio_dir_in(struct gp
  133. raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
  134. - clrbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio));
  135. + bgpio_clrbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio));
  136. raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
  137. @@ -158,7 +188,7 @@ static int mpc8xxx_gpio_dir_out(struct g
  138. raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
  139. - setbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio));
  140. + bgpio_setbits32(mm->regs + GPIO_DIR, mpc8xxx_gpio2mask(gpio));
  141. raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
  142. @@ -201,7 +231,8 @@ static void mpc8xxx_gpio_irq_cascade(str
  143. struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc;
  144. unsigned int mask;
  145. - mask = in_be32(mm->regs + GPIO_IER) & in_be32(mm->regs + GPIO_IMR);
  146. + mask = gpio_in32(mm->regs + GPIO_IER)
  147. + & gpio_in32(mm->regs + GPIO_IMR);
  148. if (mask)
  149. generic_handle_irq(irq_linear_revmap(mpc8xxx_gc->irq,
  150. 32 - ffs(mask)));
  151. @@ -217,7 +248,8 @@ static void mpc8xxx_irq_unmask(struct ir
  152. raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
  153. - setbits32(mm->regs + GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
  154. + bgpio_setbits32(mm->regs + GPIO_IMR,
  155. + mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
  156. raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
  157. }
  158. @@ -230,7 +262,8 @@ static void mpc8xxx_irq_mask(struct irq_
  159. raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
  160. - clrbits32(mm->regs + GPIO_IMR, mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
  161. + bgpio_clrbits32(mm->regs + GPIO_IMR,
  162. + mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
  163. raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
  164. }
  165. @@ -240,7 +273,7 @@ static void mpc8xxx_irq_ack(struct irq_d
  166. struct mpc8xxx_gpio_chip *mpc8xxx_gc = irq_data_get_irq_chip_data(d);
  167. struct of_mm_gpio_chip *mm = &mpc8xxx_gc->mm_gc;
  168. - out_be32(mm->regs + GPIO_IER, mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
  169. + gpio_out32(mpc8xxx_gpio2mask(irqd_to_hwirq(d)), mm->regs + GPIO_IER);
  170. }
  171. static int mpc8xxx_irq_set_type(struct irq_data *d, unsigned int flow_type)
  172. @@ -252,15 +285,15 @@ static int mpc8xxx_irq_set_type(struct i
  173. switch (flow_type) {
  174. case IRQ_TYPE_EDGE_FALLING:
  175. raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
  176. - setbits32(mm->regs + GPIO_ICR,
  177. - mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
  178. + bgpio_setbits32(mm->regs + GPIO_ICR,
  179. + mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
  180. raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
  181. break;
  182. case IRQ_TYPE_EDGE_BOTH:
  183. raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
  184. - clrbits32(mm->regs + GPIO_ICR,
  185. - mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
  186. + bgpio_clrbits32(mm->regs + GPIO_ICR,
  187. + mpc8xxx_gpio2mask(irqd_to_hwirq(d)));
  188. raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
  189. break;
  190. @@ -292,20 +325,20 @@ static int mpc512x_irq_set_type(struct i
  191. case IRQ_TYPE_EDGE_FALLING:
  192. case IRQ_TYPE_LEVEL_LOW:
  193. raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
  194. - clrsetbits_be32(reg, 3 << shift, 2 << shift);
  195. + bgpio_clrsetbits32(reg, 3 << shift, 2 << shift);
  196. raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
  197. break;
  198. case IRQ_TYPE_EDGE_RISING:
  199. case IRQ_TYPE_LEVEL_HIGH:
  200. raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
  201. - clrsetbits_be32(reg, 3 << shift, 1 << shift);
  202. + bgpio_clrsetbits32(reg, 3 << shift, 1 << shift);
  203. raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
  204. break;
  205. case IRQ_TYPE_EDGE_BOTH:
  206. raw_spin_lock_irqsave(&mpc8xxx_gc->lock, flags);
  207. - clrbits32(reg, 3 << shift);
  208. + bgpio_clrbits32(reg, 3 << shift);
  209. raw_spin_unlock_irqrestore(&mpc8xxx_gc->lock, flags);
  210. break;
  211. @@ -398,6 +431,14 @@ static int mpc8xxx_probe(struct platform
  212. mm_gc = &mpc8xxx_gc->mm_gc;
  213. gc = &mm_gc->gc;
  214. + if (of_property_read_bool(np, "little-endian")) {
  215. + gpio_little_endian = true;
  216. + dev_dbg(&pdev->dev, "GPIO REGISTERS are LITTLE endian\n");
  217. + } else {
  218. + gpio_little_endian = false;
  219. + dev_dbg(&pdev->dev, "GPIO REGISTERS are BIG endian\n");
  220. + }
  221. +
  222. mm_gc->save_regs = mpc8xxx_gpio_save_regs;
  223. gc->ngpio = MPC8XXX_GPIO_PINS;
  224. gc->direction_input = mpc8xxx_gpio_dir_in;
  225. @@ -422,7 +463,7 @@ static int mpc8xxx_probe(struct platform
  226. return ret;
  227. mpc8xxx_gc->irqn = irq_of_parse_and_map(np, 0);
  228. - if (mpc8xxx_gc->irqn == NO_IRQ)
  229. + if (mpc8xxx_gc->irqn == 0)
  230. return 0;
  231. mpc8xxx_gc->irq = irq_domain_add_linear(np, MPC8XXX_GPIO_PINS,
  232. @@ -435,8 +476,8 @@ static int mpc8xxx_probe(struct platform
  233. mpc8xxx_gc->of_dev_id_data = id->data;
  234. /* ack and mask all irqs */
  235. - out_be32(mm_gc->regs + GPIO_IER, 0xffffffff);
  236. - out_be32(mm_gc->regs + GPIO_IMR, 0);
  237. + gpio_out32(0xffffffff, mm_gc->regs + GPIO_IER);
  238. + gpio_out32(0, mm_gc->regs + GPIO_IMR);
  239. irq_set_chained_handler_and_data(mpc8xxx_gc->irqn,
  240. mpc8xxx_gpio_irq_cascade, mpc8xxx_gc);