reset-aspeed.c 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253
  1. // SPDX-License-Identifier: GPL-2.0-or-later
  2. /*
  3. * Copyright (c) 2024 ASPEED Technology Inc.
  4. */
  5. #include <linux/auxiliary_bus.h>
  6. #include <linux/cleanup.h>
  7. #include <linux/device.h>
  8. #include <linux/io.h>
  9. #include <linux/module.h>
  10. #include <linux/reset-controller.h>
  11. #include <linux/slab.h>
  12. #include <dt-bindings/reset/aspeed,ast2700-scu.h>
  13. #define SCU0_RESET_CTRL1 0x200
  14. #define SCU0_RESET_CTRL2 0x220
  15. #define SCU1_RESET_CTRL1 0x200
  16. #define SCU1_RESET_CTRL2 0x220
  17. #define SCU1_PCIE3_CTRL 0x908
  18. struct ast2700_reset_signal {
  19. bool dedicated_clr; /* dedicated reset clr offset */
  20. u32 offset, bit;
  21. };
  22. struct aspeed_reset_info {
  23. unsigned int nr_resets;
  24. const struct ast2700_reset_signal *signal;
  25. };
  26. struct aspeed_reset {
  27. struct reset_controller_dev rcdev;
  28. struct aspeed_reset_info *info;
  29. spinlock_t lock; /* Protect read-modify-write cycle */
  30. void __iomem *base;
  31. };
  32. static const struct ast2700_reset_signal ast2700_reset0_signals[] = {
  33. [SCU0_RESET_SDRAM] = { true, SCU0_RESET_CTRL1, BIT(0) },
  34. [SCU0_RESET_DDRPHY] = { true, SCU0_RESET_CTRL1, BIT(1) },
  35. [SCU0_RESET_RSA] = { true, SCU0_RESET_CTRL1, BIT(2) },
  36. [SCU0_RESET_SHA3] = { true, SCU0_RESET_CTRL1, BIT(3) },
  37. [SCU0_RESET_HACE] = { true, SCU0_RESET_CTRL1, BIT(4) },
  38. [SCU0_RESET_SOC] = { true, SCU0_RESET_CTRL1, BIT(5) },
  39. [SCU0_RESET_VIDEO] = { true, SCU0_RESET_CTRL1, BIT(6) },
  40. [SCU0_RESET_2D] = { true, SCU0_RESET_CTRL1, BIT(7) },
  41. [SCU0_RESET_PCIS] = { true, SCU0_RESET_CTRL1, BIT(8) },
  42. [SCU0_RESET_RVAS0] = { true, SCU0_RESET_CTRL1, BIT(9) },
  43. [SCU0_RESET_RVAS1] = { true, SCU0_RESET_CTRL1, BIT(10) },
  44. [SCU0_RESET_SM3] = { true, SCU0_RESET_CTRL1, BIT(11) },
  45. [SCU0_RESET_SM4] = { true, SCU0_RESET_CTRL1, BIT(12) },
  46. [SCU0_RESET_CRT0] = { true, SCU0_RESET_CTRL1, BIT(13) },
  47. [SCU0_RESET_ECC] = { true, SCU0_RESET_CTRL1, BIT(14) },
  48. [SCU0_RESET_DP_PCI] = { true, SCU0_RESET_CTRL1, BIT(15) },
  49. [SCU0_RESET_UFS] = { true, SCU0_RESET_CTRL1, BIT(16) },
  50. [SCU0_RESET_EMMC] = { true, SCU0_RESET_CTRL1, BIT(17) },
  51. [SCU0_RESET_PCIE1RST] = { true, SCU0_RESET_CTRL1, BIT(18) },
  52. [SCU0_RESET_PCIE1RSTOE] = { true, SCU0_RESET_CTRL1, BIT(19) },
  53. [SCU0_RESET_PCIE0RST] = { true, SCU0_RESET_CTRL1, BIT(20) },
  54. [SCU0_RESET_PCIE0RSTOE] = { true, SCU0_RESET_CTRL1, BIT(21) },
  55. [SCU0_RESET_JTAG] = { true, SCU0_RESET_CTRL1, BIT(22) },
  56. [SCU0_RESET_MCTP0] = { true, SCU0_RESET_CTRL1, BIT(23) },
  57. [SCU0_RESET_MCTP1] = { true, SCU0_RESET_CTRL1, BIT(24) },
  58. [SCU0_RESET_XDMA0] = { true, SCU0_RESET_CTRL1, BIT(25) },
  59. [SCU0_RESET_XDMA1] = { true, SCU0_RESET_CTRL1, BIT(26) },
  60. [SCU0_RESET_H2X1] = { true, SCU0_RESET_CTRL1, BIT(27) },
  61. [SCU0_RESET_DP] = { true, SCU0_RESET_CTRL1, BIT(28) },
  62. [SCU0_RESET_DP_MCU] = { true, SCU0_RESET_CTRL1, BIT(29) },
  63. [SCU0_RESET_SSP] = { true, SCU0_RESET_CTRL1, BIT(30) },
  64. [SCU0_RESET_H2X0] = { true, SCU0_RESET_CTRL1, BIT(31) },
  65. [SCU0_RESET_PORTA_VHUB] = { true, SCU0_RESET_CTRL2, BIT(0) },
  66. [SCU0_RESET_PORTA_PHY3] = { true, SCU0_RESET_CTRL2, BIT(1) },
  67. [SCU0_RESET_PORTA_XHCI] = { true, SCU0_RESET_CTRL2, BIT(2) },
  68. [SCU0_RESET_PORTB_VHUB] = { true, SCU0_RESET_CTRL2, BIT(3) },
  69. [SCU0_RESET_PORTB_PHY3] = { true, SCU0_RESET_CTRL2, BIT(4) },
  70. [SCU0_RESET_PORTB_XHCI] = { true, SCU0_RESET_CTRL2, BIT(5) },
  71. [SCU0_RESET_PORTA_VHUB_EHCI] = { true, SCU0_RESET_CTRL2, BIT(6) },
  72. [SCU0_RESET_PORTB_VHUB_EHCI] = { true, SCU0_RESET_CTRL2, BIT(7) },
  73. [SCU0_RESET_UHCI] = { true, SCU0_RESET_CTRL2, BIT(8) },
  74. [SCU0_RESET_TSP] = { true, SCU0_RESET_CTRL2, BIT(9) },
  75. [SCU0_RESET_E2M0] = { true, SCU0_RESET_CTRL2, BIT(10) },
  76. [SCU0_RESET_E2M1] = { true, SCU0_RESET_CTRL2, BIT(11) },
  77. [SCU0_RESET_VLINK] = { true, SCU0_RESET_CTRL2, BIT(12) },
  78. };
  79. static const struct ast2700_reset_signal ast2700_reset1_signals[] = {
  80. [SCU1_RESET_LPC0] = { true, SCU1_RESET_CTRL1, BIT(0) },
  81. [SCU1_RESET_LPC1] = { true, SCU1_RESET_CTRL1, BIT(1) },
  82. [SCU1_RESET_MII] = { true, SCU1_RESET_CTRL1, BIT(2) },
  83. [SCU1_RESET_PECI] = { true, SCU1_RESET_CTRL1, BIT(3) },
  84. [SCU1_RESET_PWM] = { true, SCU1_RESET_CTRL1, BIT(4) },
  85. [SCU1_RESET_MAC0] = { true, SCU1_RESET_CTRL1, BIT(5) },
  86. [SCU1_RESET_MAC1] = { true, SCU1_RESET_CTRL1, BIT(6) },
  87. [SCU1_RESET_MAC2] = { true, SCU1_RESET_CTRL1, BIT(7) },
  88. [SCU1_RESET_ADC] = { true, SCU1_RESET_CTRL1, BIT(8) },
  89. [SCU1_RESET_SD] = { true, SCU1_RESET_CTRL1, BIT(9) },
  90. [SCU1_RESET_ESPI0] = { true, SCU1_RESET_CTRL1, BIT(10) },
  91. [SCU1_RESET_ESPI1] = { true, SCU1_RESET_CTRL1, BIT(11) },
  92. [SCU1_RESET_JTAG1] = { true, SCU1_RESET_CTRL1, BIT(12) },
  93. [SCU1_RESET_SPI0] = { true, SCU1_RESET_CTRL1, BIT(13) },
  94. [SCU1_RESET_SPI1] = { true, SCU1_RESET_CTRL1, BIT(14) },
  95. [SCU1_RESET_SPI2] = { true, SCU1_RESET_CTRL1, BIT(15) },
  96. [SCU1_RESET_I3C0] = { true, SCU1_RESET_CTRL1, BIT(16) },
  97. [SCU1_RESET_I3C1] = { true, SCU1_RESET_CTRL1, BIT(17) },
  98. [SCU1_RESET_I3C2] = { true, SCU1_RESET_CTRL1, BIT(18) },
  99. [SCU1_RESET_I3C3] = { true, SCU1_RESET_CTRL1, BIT(19) },
  100. [SCU1_RESET_I3C4] = { true, SCU1_RESET_CTRL1, BIT(20) },
  101. [SCU1_RESET_I3C5] = { true, SCU1_RESET_CTRL1, BIT(21) },
  102. [SCU1_RESET_I3C6] = { true, SCU1_RESET_CTRL1, BIT(22) },
  103. [SCU1_RESET_I3C7] = { true, SCU1_RESET_CTRL1, BIT(23) },
  104. [SCU1_RESET_I3C8] = { true, SCU1_RESET_CTRL1, BIT(24) },
  105. [SCU1_RESET_I3C9] = { true, SCU1_RESET_CTRL1, BIT(25) },
  106. [SCU1_RESET_I3C10] = { true, SCU1_RESET_CTRL1, BIT(26) },
  107. [SCU1_RESET_I3C11] = { true, SCU1_RESET_CTRL1, BIT(27) },
  108. [SCU1_RESET_I3C12] = { true, SCU1_RESET_CTRL1, BIT(28) },
  109. [SCU1_RESET_I3C13] = { true, SCU1_RESET_CTRL1, BIT(29) },
  110. [SCU1_RESET_I3C14] = { true, SCU1_RESET_CTRL1, BIT(30) },
  111. [SCU1_RESET_I3C15] = { true, SCU1_RESET_CTRL1, BIT(31) },
  112. [SCU1_RESET_MCU0] = { true, SCU1_RESET_CTRL2, BIT(0) },
  113. [SCU1_RESET_MCU1] = { true, SCU1_RESET_CTRL2, BIT(1) },
  114. [SCU1_RESET_H2A_SPI1] = { true, SCU1_RESET_CTRL2, BIT(2) },
  115. [SCU1_RESET_H2A_SPI2] = { true, SCU1_RESET_CTRL2, BIT(3) },
  116. [SCU1_RESET_UART0] = { true, SCU1_RESET_CTRL2, BIT(4) },
  117. [SCU1_RESET_UART1] = { true, SCU1_RESET_CTRL2, BIT(5) },
  118. [SCU1_RESET_UART2] = { true, SCU1_RESET_CTRL2, BIT(6) },
  119. [SCU1_RESET_UART3] = { true, SCU1_RESET_CTRL2, BIT(7) },
  120. [SCU1_RESET_I2C_FILTER] = { true, SCU1_RESET_CTRL2, BIT(8) },
  121. [SCU1_RESET_CALIPTRA] = { true, SCU1_RESET_CTRL2, BIT(9) },
  122. [SCU1_RESET_XDMA] = { true, SCU1_RESET_CTRL2, BIT(10) },
  123. [SCU1_RESET_FSI] = { true, SCU1_RESET_CTRL2, BIT(12) },
  124. [SCU1_RESET_CAN] = { true, SCU1_RESET_CTRL2, BIT(13) },
  125. [SCU1_RESET_MCTP] = { true, SCU1_RESET_CTRL2, BIT(14) },
  126. [SCU1_RESET_I2C] = { true, SCU1_RESET_CTRL2, BIT(15) },
  127. [SCU1_RESET_UART6] = { true, SCU1_RESET_CTRL2, BIT(16) },
  128. [SCU1_RESET_UART7] = { true, SCU1_RESET_CTRL2, BIT(17) },
  129. [SCU1_RESET_UART8] = { true, SCU1_RESET_CTRL2, BIT(18) },
  130. [SCU1_RESET_UART9] = { true, SCU1_RESET_CTRL2, BIT(19) },
  131. [SCU1_RESET_LTPI0] = { true, SCU1_RESET_CTRL2, BIT(20) },
  132. [SCU1_RESET_VGAL] = { true, SCU1_RESET_CTRL2, BIT(21) },
  133. [SCU1_RESET_LTPI1] = { true, SCU1_RESET_CTRL2, BIT(22) },
  134. [SCU1_RESET_ACE] = { true, SCU1_RESET_CTRL2, BIT(23) },
  135. [SCU1_RESET_E2M] = { true, SCU1_RESET_CTRL2, BIT(24) },
  136. [SCU1_RESET_UHCI] = { true, SCU1_RESET_CTRL2, BIT(25) },
  137. [SCU1_RESET_PORTC_USB2UART] = { true, SCU1_RESET_CTRL2, BIT(26) },
  138. [SCU1_RESET_PORTC_VHUB_EHCI] = { true, SCU1_RESET_CTRL2, BIT(27) },
  139. [SCU1_RESET_PORTD_USB2UART] = { true, SCU1_RESET_CTRL2, BIT(28) },
  140. [SCU1_RESET_PORTD_VHUB_EHCI] = { true, SCU1_RESET_CTRL2, BIT(29) },
  141. [SCU1_RESET_H2X] = { true, SCU1_RESET_CTRL2, BIT(30) },
  142. [SCU1_RESET_I3CDMA] = { true, SCU1_RESET_CTRL2, BIT(31) },
  143. [SCU1_RESET_PCIE2RST] = { false, SCU1_PCIE3_CTRL, BIT(0) },
  144. };
  145. static inline struct aspeed_reset *to_aspeed_reset(struct reset_controller_dev *rcdev)
  146. {
  147. return container_of(rcdev, struct aspeed_reset, rcdev);
  148. }
  149. static int aspeed_reset_assert(struct reset_controller_dev *rcdev, unsigned long id)
  150. {
  151. struct aspeed_reset *rc = to_aspeed_reset(rcdev);
  152. void __iomem *reg_offset = rc->base + rc->info->signal[id].offset;
  153. if (rc->info->signal[id].dedicated_clr) {
  154. writel(rc->info->signal[id].bit, reg_offset);
  155. } else {
  156. guard(spinlock_irqsave)(&rc->lock);
  157. writel(readl(reg_offset) & ~rc->info->signal[id].bit, reg_offset);
  158. }
  159. return 0;
  160. }
  161. static int aspeed_reset_deassert(struct reset_controller_dev *rcdev, unsigned long id)
  162. {
  163. struct aspeed_reset *rc = to_aspeed_reset(rcdev);
  164. void __iomem *reg_offset = rc->base + rc->info->signal[id].offset;
  165. if (rc->info->signal[id].dedicated_clr) {
  166. writel(rc->info->signal[id].bit, reg_offset + 0x04);
  167. } else {
  168. guard(spinlock_irqsave)(&rc->lock);
  169. writel(readl(reg_offset) | rc->info->signal[id].bit, reg_offset);
  170. }
  171. return 0;
  172. }
  173. static int aspeed_reset_status(struct reset_controller_dev *rcdev, unsigned long id)
  174. {
  175. struct aspeed_reset *rc = to_aspeed_reset(rcdev);
  176. void __iomem *reg_offset = rc->base + rc->info->signal[id].offset;
  177. return (readl(reg_offset) & rc->info->signal[id].bit) ? 1 : 0;
  178. }
  179. static const struct reset_control_ops aspeed_reset_ops = {
  180. .assert = aspeed_reset_assert,
  181. .deassert = aspeed_reset_deassert,
  182. .status = aspeed_reset_status,
  183. };
  184. static int aspeed_reset_probe(struct auxiliary_device *adev,
  185. const struct auxiliary_device_id *id)
  186. {
  187. struct aspeed_reset *reset;
  188. struct device *dev = &adev->dev;
  189. reset = devm_kzalloc(dev, sizeof(*reset), GFP_KERNEL);
  190. if (!reset)
  191. return -ENOMEM;
  192. spin_lock_init(&reset->lock);
  193. reset->info = (struct aspeed_reset_info *)id->driver_data;
  194. reset->rcdev.owner = THIS_MODULE;
  195. reset->rcdev.nr_resets = reset->info->nr_resets;
  196. reset->rcdev.ops = &aspeed_reset_ops;
  197. reset->rcdev.of_node = dev->parent->of_node;
  198. reset->rcdev.dev = dev;
  199. reset->rcdev.of_reset_n_cells = 1;
  200. reset->base = (void __iomem *)adev->dev.platform_data;
  201. return devm_reset_controller_register(dev, &reset->rcdev);
  202. }
  203. static const struct aspeed_reset_info ast2700_reset0_info = {
  204. .nr_resets = ARRAY_SIZE(ast2700_reset0_signals),
  205. .signal = ast2700_reset0_signals,
  206. };
  207. static const struct aspeed_reset_info ast2700_reset1_info = {
  208. .nr_resets = ARRAY_SIZE(ast2700_reset1_signals),
  209. .signal = ast2700_reset1_signals,
  210. };
  211. static const struct auxiliary_device_id aspeed_reset_ids[] = {
  212. { .name = "clk_ast2700.reset0", .driver_data = (kernel_ulong_t)&ast2700_reset0_info },
  213. { .name = "clk_ast2700.reset1", .driver_data = (kernel_ulong_t)&ast2700_reset1_info },
  214. { }
  215. };
  216. MODULE_DEVICE_TABLE(auxiliary, aspeed_reset_ids);
  217. static struct auxiliary_driver aspeed_reset_driver = {
  218. .probe = aspeed_reset_probe,
  219. .id_table = aspeed_reset_ids,
  220. };
  221. module_auxiliary_driver(aspeed_reset_driver);
  222. MODULE_AUTHOR("Ryan Chen <ryan_chen@aspeedtech.com>");
  223. MODULE_DESCRIPTION("ASPEED SoC Reset Controller Driver");
  224. MODULE_LICENSE("GPL");