0029-pinctrl-starfive-Add-StarFive-JH7110-aon-controller-.patch 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224
  1. From 9c1a9d6dfd6a9c28794536c8af002746a20d840f Mon Sep 17 00:00:00 2001
  2. From: Jianlong Huang <[email protected]>
  3. Date: Thu, 9 Feb 2023 22:37:02 +0800
  4. Subject: [PATCH 029/122] pinctrl: starfive: Add StarFive JH7110 aon controller
  5. driver
  6. Add pinctrl driver for StarFive JH7110 SoC aon pinctrl controller.
  7. Co-developed-by: Emil Renner Berthing <[email protected]>
  8. Signed-off-by: Emil Renner Berthing <[email protected]>
  9. Signed-off-by: Jianlong Huang <[email protected]>
  10. Signed-off-by: Hal Feng <[email protected]>
  11. ---
  12. drivers/pinctrl/starfive/Kconfig | 12 ++
  13. drivers/pinctrl/starfive/Makefile | 1 +
  14. .../starfive/pinctrl-starfive-jh7110-aon.c | 177 ++++++++++++++++++
  15. 3 files changed, 190 insertions(+)
  16. create mode 100644 drivers/pinctrl/starfive/pinctrl-starfive-jh7110-aon.c
  17. --- a/drivers/pinctrl/starfive/Kconfig
  18. +++ b/drivers/pinctrl/starfive/Kconfig
  19. @@ -37,3 +37,15 @@ config PINCTRL_STARFIVE_JH7110_SYS
  20. This also provides an interface to the GPIO pins not used by other
  21. peripherals supporting inputs, outputs, configuring pull-up/pull-down
  22. and interrupts on input changes.
  23. +
  24. +config PINCTRL_STARFIVE_JH7110_AON
  25. + tristate "Always-on pinctrl and GPIO driver for the StarFive JH7110 SoC"
  26. + depends on SOC_STARFIVE || COMPILE_TEST
  27. + depends on OF
  28. + select PINCTRL_STARFIVE_JH7110
  29. + default SOC_STARFIVE
  30. + help
  31. + Say yes here to support always-on pin control on the StarFive JH7110 SoC.
  32. + This also provides an interface to the GPIO pins not used by other
  33. + peripherals supporting inputs, outputs, configuring pull-up/pull-down
  34. + and interrupts on input changes.
  35. --- a/drivers/pinctrl/starfive/Makefile
  36. +++ b/drivers/pinctrl/starfive/Makefile
  37. @@ -4,3 +4,4 @@ obj-$(CONFIG_PINCTRL_STARFIVE_JH7100) +=
  38. obj-$(CONFIG_PINCTRL_STARFIVE_JH7110) += pinctrl-starfive-jh7110.o
  39. obj-$(CONFIG_PINCTRL_STARFIVE_JH7110_SYS) += pinctrl-starfive-jh7110-sys.o
  40. +obj-$(CONFIG_PINCTRL_STARFIVE_JH7110_AON) += pinctrl-starfive-jh7110-aon.o
  41. --- /dev/null
  42. +++ b/drivers/pinctrl/starfive/pinctrl-starfive-jh7110-aon.c
  43. @@ -0,0 +1,177 @@
  44. +// SPDX-License-Identifier: GPL-2.0
  45. +/*
  46. + * Pinctrl / GPIO driver for StarFive JH7110 SoC aon controller
  47. + *
  48. + * Copyright (C) 2022 StarFive Technology Co., Ltd.
  49. + */
  50. +
  51. +#include <linux/err.h>
  52. +#include <linux/gpio/driver.h>
  53. +#include <linux/init.h>
  54. +#include <linux/interrupt.h>
  55. +#include <linux/io.h>
  56. +#include <linux/module.h>
  57. +#include <linux/of.h>
  58. +#include <linux/of_device.h>
  59. +#include <linux/of_irq.h>
  60. +#include <linux/of_platform.h>
  61. +#include <linux/pinctrl/pinconf.h>
  62. +#include <linux/pinctrl/pinconf-generic.h>
  63. +#include <linux/pinctrl/pinctrl.h>
  64. +#include <linux/pinctrl/pinmux.h>
  65. +#include <linux/platform_device.h>
  66. +#include <linux/pm_runtime.h>
  67. +#include <linux/regmap.h>
  68. +#include <linux/slab.h>
  69. +
  70. +#include <dt-bindings/pinctrl/starfive,jh7110-pinctrl.h>
  71. +
  72. +#include "../core.h"
  73. +#include "../pinconf.h"
  74. +#include "../pinmux.h"
  75. +#include "pinctrl-starfive-jh7110.h"
  76. +
  77. +#define JH7110_AON_NGPIO 4
  78. +#define JH7110_AON_GC_BASE 64
  79. +
  80. +/* registers */
  81. +#define JH7110_AON_DOEN 0x0
  82. +#define JH7110_AON_DOUT 0x4
  83. +#define JH7110_AON_GPI 0x8
  84. +#define JH7110_AON_GPIOIN 0x2c
  85. +
  86. +#define JH7110_AON_GPIOEN 0xc
  87. +#define JH7110_AON_GPIOIS 0x10
  88. +#define JH7110_AON_GPIOIC 0x14
  89. +#define JH7110_AON_GPIOIBE 0x18
  90. +#define JH7110_AON_GPIOIEV 0x1c
  91. +#define JH7110_AON_GPIOIE 0x20
  92. +#define JH7110_AON_GPIORIS 0x28
  93. +#define JH7110_AON_GPIOMIS 0x28
  94. +
  95. +#define JH7110_AON_GPO_PDA_0_5_CFG 0x30
  96. +
  97. +static const struct pinctrl_pin_desc jh7110_aon_pins[] = {
  98. + PINCTRL_PIN(PAD_TESTEN, "TESTEN"),
  99. + PINCTRL_PIN(PAD_RGPIO0, "RGPIO0"),
  100. + PINCTRL_PIN(PAD_RGPIO1, "RGPIO1"),
  101. + PINCTRL_PIN(PAD_RGPIO2, "RGPIO2"),
  102. + PINCTRL_PIN(PAD_RGPIO3, "RGPIO3"),
  103. + PINCTRL_PIN(PAD_RSTN, "RSTN"),
  104. + PINCTRL_PIN(PAD_GMAC0_MDC, "GMAC0_MDC"),
  105. + PINCTRL_PIN(PAD_GMAC0_MDIO, "GMAC0_MDIO"),
  106. + PINCTRL_PIN(PAD_GMAC0_RXD0, "GMAC0_RXD0"),
  107. + PINCTRL_PIN(PAD_GMAC0_RXD1, "GMAC0_RXD1"),
  108. + PINCTRL_PIN(PAD_GMAC0_RXD2, "GMAC0_RXD2"),
  109. + PINCTRL_PIN(PAD_GMAC0_RXD3, "GMAC0_RXD3"),
  110. + PINCTRL_PIN(PAD_GMAC0_RXDV, "GMAC0_RXDV"),
  111. + PINCTRL_PIN(PAD_GMAC0_RXC, "GMAC0_RXC"),
  112. + PINCTRL_PIN(PAD_GMAC0_TXD0, "GMAC0_TXD0"),
  113. + PINCTRL_PIN(PAD_GMAC0_TXD1, "GMAC0_TXD1"),
  114. + PINCTRL_PIN(PAD_GMAC0_TXD2, "GMAC0_TXD2"),
  115. + PINCTRL_PIN(PAD_GMAC0_TXD3, "GMAC0_TXD3"),
  116. + PINCTRL_PIN(PAD_GMAC0_TXEN, "GMAC0_TXEN"),
  117. + PINCTRL_PIN(PAD_GMAC0_TXC, "GMAC0_TXC"),
  118. +};
  119. +
  120. +static int jh7110_aon_set_one_pin_mux(struct jh7110_pinctrl *sfp,
  121. + unsigned int pin,
  122. + unsigned int din, u32 dout,
  123. + u32 doen, u32 func)
  124. +{
  125. + if (pin < sfp->gc.ngpio && func == 0)
  126. + jh7110_set_gpiomux(sfp, pin, din, dout, doen);
  127. +
  128. + return 0;
  129. +}
  130. +
  131. +static int jh7110_aon_get_padcfg_base(struct jh7110_pinctrl *sfp,
  132. + unsigned int pin)
  133. +{
  134. + if (pin < PAD_GMAC0_MDC)
  135. + return JH7110_AON_GPO_PDA_0_5_CFG;
  136. +
  137. + return -1;
  138. +}
  139. +
  140. +static void jh7110_aon_irq_handler(struct irq_desc *desc)
  141. +{
  142. + struct jh7110_pinctrl *sfp = jh7110_from_irq_desc(desc);
  143. + struct irq_chip *chip = irq_desc_get_chip(desc);
  144. + unsigned long mis;
  145. + unsigned int pin;
  146. +
  147. + chained_irq_enter(chip, desc);
  148. +
  149. + mis = readl_relaxed(sfp->base + JH7110_AON_GPIOMIS);
  150. + for_each_set_bit(pin, &mis, JH7110_AON_NGPIO)
  151. + generic_handle_domain_irq(sfp->gc.irq.domain, pin);
  152. +
  153. + chained_irq_exit(chip, desc);
  154. +}
  155. +
  156. +static int jh7110_aon_init_hw(struct gpio_chip *gc)
  157. +{
  158. + struct jh7110_pinctrl *sfp = container_of(gc,
  159. + struct jh7110_pinctrl, gc);
  160. +
  161. + /* mask all GPIO interrupts */
  162. + writel_relaxed(0, sfp->base + JH7110_AON_GPIOIE);
  163. + /* clear edge interrupt flags */
  164. + writel_relaxed(0, sfp->base + JH7110_AON_GPIOIC);
  165. + writel_relaxed(0x0f, sfp->base + JH7110_AON_GPIOIC);
  166. + /* enable GPIO interrupts */
  167. + writel_relaxed(1, sfp->base + JH7110_AON_GPIOEN);
  168. + return 0;
  169. +}
  170. +
  171. +static const struct jh7110_gpio_irq_reg jh7110_aon_irq_reg = {
  172. + .is_reg_base = JH7110_AON_GPIOIS,
  173. + .ic_reg_base = JH7110_AON_GPIOIC,
  174. + .ibe_reg_base = JH7110_AON_GPIOIBE,
  175. + .iev_reg_base = JH7110_AON_GPIOIEV,
  176. + .ie_reg_base = JH7110_AON_GPIOIE,
  177. + .ris_reg_base = JH7110_AON_GPIORIS,
  178. + .mis_reg_base = JH7110_AON_GPIOMIS,
  179. +};
  180. +
  181. +static const struct jh7110_pinctrl_soc_info jh7110_aon_pinctrl_info = {
  182. + .pins = jh7110_aon_pins,
  183. + .npins = ARRAY_SIZE(jh7110_aon_pins),
  184. + .ngpios = JH7110_AON_NGPIO,
  185. + .gc_base = JH7110_AON_GC_BASE,
  186. + .dout_reg_base = JH7110_AON_DOUT,
  187. + .dout_mask = GENMASK(3, 0),
  188. + .doen_reg_base = JH7110_AON_DOEN,
  189. + .doen_mask = GENMASK(2, 0),
  190. + .gpi_reg_base = JH7110_AON_GPI,
  191. + .gpi_mask = GENMASK(3, 0),
  192. + .gpioin_reg_base = JH7110_AON_GPIOIN,
  193. + .irq_reg = &jh7110_aon_irq_reg,
  194. + .jh7110_set_one_pin_mux = jh7110_aon_set_one_pin_mux,
  195. + .jh7110_get_padcfg_base = jh7110_aon_get_padcfg_base,
  196. + .jh7110_gpio_irq_handler = jh7110_aon_irq_handler,
  197. + .jh7110_gpio_init_hw = jh7110_aon_init_hw,
  198. +};
  199. +
  200. +static const struct of_device_id jh7110_aon_pinctrl_of_match[] = {
  201. + {
  202. + .compatible = "starfive,jh7110-aon-pinctrl",
  203. + .data = &jh7110_aon_pinctrl_info,
  204. + },
  205. + { /* sentinel */ }
  206. +};
  207. +MODULE_DEVICE_TABLE(of, jh7110_aon_pinctrl_of_match);
  208. +
  209. +static struct platform_driver jh7110_aon_pinctrl_driver = {
  210. + .probe = jh7110_pinctrl_probe,
  211. + .driver = {
  212. + .name = "starfive-jh7110-aon-pinctrl",
  213. + .of_match_table = jh7110_aon_pinctrl_of_match,
  214. + },
  215. +};
  216. +module_platform_driver(jh7110_aon_pinctrl_driver);
  217. +
  218. +MODULE_DESCRIPTION("Pinctrl driver for the StarFive JH7110 SoC aon controller");
  219. +MODULE_AUTHOR("Jianlong Huang <[email protected]>");
  220. +MODULE_LICENSE("GPL");