reset-uniphier.c 9.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376
  1. /*
  2. * Copyright (C) 2016 Socionext Inc.
  3. * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
  4. *
  5. * SPDX-License-Identifier: GPL-2.0+
  6. */
  7. #include <common.h>
  8. #include <reset-uclass.h>
  9. #include <dm/device.h>
  10. #include <linux/bitops.h>
  11. #include <linux/io.h>
  12. #include <linux/sizes.h>
  13. struct uniphier_reset_data {
  14. unsigned int id;
  15. unsigned int reg;
  16. unsigned int bit;
  17. unsigned int flags;
  18. #define UNIPHIER_RESET_ACTIVE_LOW BIT(0)
  19. };
  20. #define UNIPHIER_RESET_ID_END (unsigned int)(-1)
  21. #define UNIPHIER_RESET_END \
  22. { .id = UNIPHIER_RESET_ID_END }
  23. #define UNIPHIER_RESET(_id, _reg, _bit) \
  24. { \
  25. .id = (_id), \
  26. .reg = (_reg), \
  27. .bit = (_bit), \
  28. }
  29. #define UNIPHIER_RESETX(_id, _reg, _bit) \
  30. { \
  31. .id = (_id), \
  32. .reg = (_reg), \
  33. .bit = (_bit), \
  34. .flags = UNIPHIER_RESET_ACTIVE_LOW, \
  35. }
  36. /* System reset data */
  37. #define UNIPHIER_SLD3_SYS_RESET_STDMAC(id) \
  38. UNIPHIER_RESETX((id), 0x2000, 10)
  39. #define UNIPHIER_LD11_SYS_RESET_STDMAC(id) \
  40. UNIPHIER_RESETX((id), 0x200c, 8)
  41. #define UNIPHIER_PRO4_SYS_RESET_GIO(id) \
  42. UNIPHIER_RESETX((id), 0x2000, 6)
  43. #define UNIPHIER_LD20_SYS_RESET_GIO(id) \
  44. UNIPHIER_RESETX((id), 0x200c, 5)
  45. #define UNIPHIER_PRO4_SYS_RESET_USB3(id, ch) \
  46. UNIPHIER_RESETX((id), 0x2000 + 0x4 * (ch), 17)
  47. const struct uniphier_reset_data uniphier_sld3_sys_reset_data[] = {
  48. UNIPHIER_SLD3_SYS_RESET_STDMAC(8), /* Ether, HSC, MIO */
  49. UNIPHIER_RESET_END,
  50. };
  51. const struct uniphier_reset_data uniphier_pro4_sys_reset_data[] = {
  52. UNIPHIER_SLD3_SYS_RESET_STDMAC(8), /* HSC, MIO, RLE */
  53. UNIPHIER_PRO4_SYS_RESET_GIO(12), /* Ether, SATA, USB3 */
  54. UNIPHIER_PRO4_SYS_RESET_USB3(14, 0),
  55. UNIPHIER_PRO4_SYS_RESET_USB3(15, 1),
  56. UNIPHIER_RESET_END,
  57. };
  58. const struct uniphier_reset_data uniphier_pro5_sys_reset_data[] = {
  59. UNIPHIER_SLD3_SYS_RESET_STDMAC(8), /* HSC */
  60. UNIPHIER_PRO4_SYS_RESET_GIO(12), /* PCIe, USB3 */
  61. UNIPHIER_PRO4_SYS_RESET_USB3(14, 0),
  62. UNIPHIER_PRO4_SYS_RESET_USB3(15, 1),
  63. UNIPHIER_RESET_END,
  64. };
  65. const struct uniphier_reset_data uniphier_pxs2_sys_reset_data[] = {
  66. UNIPHIER_SLD3_SYS_RESET_STDMAC(8), /* HSC, RLE */
  67. UNIPHIER_PRO4_SYS_RESET_USB3(14, 0),
  68. UNIPHIER_PRO4_SYS_RESET_USB3(15, 1),
  69. UNIPHIER_RESETX(16, 0x2014, 4), /* USB30-PHY0 */
  70. UNIPHIER_RESETX(17, 0x2014, 0), /* USB30-PHY1 */
  71. UNIPHIER_RESETX(18, 0x2014, 2), /* USB30-PHY2 */
  72. UNIPHIER_RESETX(20, 0x2014, 5), /* USB31-PHY0 */
  73. UNIPHIER_RESETX(21, 0x2014, 1), /* USB31-PHY1 */
  74. UNIPHIER_RESETX(28, 0x2014, 12), /* SATA */
  75. UNIPHIER_RESET(29, 0x2014, 8), /* SATA-PHY (active high) */
  76. UNIPHIER_RESET_END,
  77. };
  78. const struct uniphier_reset_data uniphier_ld11_sys_reset_data[] = {
  79. UNIPHIER_LD11_SYS_RESET_STDMAC(8), /* HSC, MIO */
  80. UNIPHIER_RESET_END,
  81. };
  82. const struct uniphier_reset_data uniphier_ld20_sys_reset_data[] = {
  83. UNIPHIER_LD11_SYS_RESET_STDMAC(8), /* HSC */
  84. UNIPHIER_LD20_SYS_RESET_GIO(12), /* PCIe, USB3 */
  85. UNIPHIER_RESETX(16, 0x200c, 12), /* USB30-PHY0 */
  86. UNIPHIER_RESETX(17, 0x200c, 13), /* USB30-PHY1 */
  87. UNIPHIER_RESETX(18, 0x200c, 14), /* USB30-PHY2 */
  88. UNIPHIER_RESETX(19, 0x200c, 15), /* USB30-PHY3 */
  89. UNIPHIER_RESET_END,
  90. };
  91. /* Media I/O reset data */
  92. #define UNIPHIER_MIO_RESET_SD(id, ch) \
  93. UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 0)
  94. #define UNIPHIER_MIO_RESET_SD_BRIDGE(id, ch) \
  95. UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 26)
  96. #define UNIPHIER_MIO_RESET_EMMC_HW_RESET(id, ch) \
  97. UNIPHIER_RESETX((id), 0x80 + 0x200 * (ch), 0)
  98. #define UNIPHIER_MIO_RESET_USB2(id, ch) \
  99. UNIPHIER_RESETX((id), 0x114 + 0x200 * (ch), 0)
  100. #define UNIPHIER_MIO_RESET_USB2_BRIDGE(id, ch) \
  101. UNIPHIER_RESETX((id), 0x110 + 0x200 * (ch), 24)
  102. #define UNIPHIER_MIO_RESET_DMAC(id) \
  103. UNIPHIER_RESETX((id), 0x110, 17)
  104. const struct uniphier_reset_data uniphier_mio_reset_data[] = {
  105. UNIPHIER_MIO_RESET_SD(0, 0),
  106. UNIPHIER_MIO_RESET_SD(1, 1),
  107. UNIPHIER_MIO_RESET_SD(2, 2),
  108. UNIPHIER_MIO_RESET_SD_BRIDGE(3, 0),
  109. UNIPHIER_MIO_RESET_SD_BRIDGE(4, 1),
  110. UNIPHIER_MIO_RESET_SD_BRIDGE(5, 2),
  111. UNIPHIER_MIO_RESET_EMMC_HW_RESET(6, 1),
  112. UNIPHIER_MIO_RESET_DMAC(7),
  113. UNIPHIER_MIO_RESET_USB2(8, 0),
  114. UNIPHIER_MIO_RESET_USB2(9, 1),
  115. UNIPHIER_MIO_RESET_USB2(10, 2),
  116. UNIPHIER_MIO_RESET_USB2(11, 3),
  117. UNIPHIER_MIO_RESET_USB2_BRIDGE(12, 0),
  118. UNIPHIER_MIO_RESET_USB2_BRIDGE(13, 1),
  119. UNIPHIER_MIO_RESET_USB2_BRIDGE(14, 2),
  120. UNIPHIER_MIO_RESET_USB2_BRIDGE(15, 3),
  121. UNIPHIER_RESET_END,
  122. };
  123. /* Peripheral reset data */
  124. #define UNIPHIER_PERI_RESET_UART(id, ch) \
  125. UNIPHIER_RESETX((id), 0x114, 19 + (ch))
  126. #define UNIPHIER_PERI_RESET_I2C(id, ch) \
  127. UNIPHIER_RESETX((id), 0x114, 5 + (ch))
  128. #define UNIPHIER_PERI_RESET_FI2C(id, ch) \
  129. UNIPHIER_RESETX((id), 0x114, 24 + (ch))
  130. const struct uniphier_reset_data uniphier_ld4_peri_reset_data[] = {
  131. UNIPHIER_PERI_RESET_UART(0, 0),
  132. UNIPHIER_PERI_RESET_UART(1, 1),
  133. UNIPHIER_PERI_RESET_UART(2, 2),
  134. UNIPHIER_PERI_RESET_UART(3, 3),
  135. UNIPHIER_PERI_RESET_I2C(4, 0),
  136. UNIPHIER_PERI_RESET_I2C(5, 1),
  137. UNIPHIER_PERI_RESET_I2C(6, 2),
  138. UNIPHIER_PERI_RESET_I2C(7, 3),
  139. UNIPHIER_PERI_RESET_I2C(8, 4),
  140. UNIPHIER_RESET_END,
  141. };
  142. const struct uniphier_reset_data uniphier_pro4_peri_reset_data[] = {
  143. UNIPHIER_PERI_RESET_UART(0, 0),
  144. UNIPHIER_PERI_RESET_UART(1, 1),
  145. UNIPHIER_PERI_RESET_UART(2, 2),
  146. UNIPHIER_PERI_RESET_UART(3, 3),
  147. UNIPHIER_PERI_RESET_FI2C(4, 0),
  148. UNIPHIER_PERI_RESET_FI2C(5, 1),
  149. UNIPHIER_PERI_RESET_FI2C(6, 2),
  150. UNIPHIER_PERI_RESET_FI2C(7, 3),
  151. UNIPHIER_PERI_RESET_FI2C(8, 4),
  152. UNIPHIER_PERI_RESET_FI2C(9, 5),
  153. UNIPHIER_PERI_RESET_FI2C(10, 6),
  154. UNIPHIER_RESET_END,
  155. };
  156. /* core implementaton */
  157. struct uniphier_reset_priv {
  158. void __iomem *base;
  159. const struct uniphier_reset_data *data;
  160. };
  161. static int uniphier_reset_request(struct reset_ctl *reset_ctl)
  162. {
  163. return 0;
  164. }
  165. static int uniphier_reset_free(struct reset_ctl *reset_ctl)
  166. {
  167. return 0;
  168. }
  169. static int uniphier_reset_update(struct reset_ctl *reset_ctl, int assert)
  170. {
  171. struct uniphier_reset_priv *priv = dev_get_priv(reset_ctl->dev);
  172. unsigned long id = reset_ctl->id;
  173. const struct uniphier_reset_data *p;
  174. for (p = priv->data; p->id != UNIPHIER_RESET_ID_END; p++) {
  175. u32 mask, val;
  176. if (p->id != id)
  177. continue;
  178. val = readl(priv->base + p->reg);
  179. if (p->flags & UNIPHIER_RESET_ACTIVE_LOW)
  180. assert = !assert;
  181. mask = BIT(p->bit);
  182. if (assert)
  183. val |= mask;
  184. else
  185. val &= ~mask;
  186. writel(val, priv->base + p->reg);
  187. return 0;
  188. }
  189. dev_err(priv->dev, "reset_id=%lu was not handled\n", id);
  190. return -EINVAL;
  191. }
  192. static int uniphier_reset_assert(struct reset_ctl *reset_ctl)
  193. {
  194. return uniphier_reset_update(reset_ctl, 1);
  195. }
  196. static int uniphier_reset_deassert(struct reset_ctl *reset_ctl)
  197. {
  198. return uniphier_reset_update(reset_ctl, 0);
  199. }
  200. static const struct reset_ops uniphier_reset_ops = {
  201. .request = uniphier_reset_request,
  202. .free = uniphier_reset_free,
  203. .rst_assert = uniphier_reset_assert,
  204. .rst_deassert = uniphier_reset_deassert,
  205. };
  206. static int uniphier_reset_probe(struct udevice *dev)
  207. {
  208. struct uniphier_reset_priv *priv = dev_get_priv(dev);
  209. fdt_addr_t addr;
  210. addr = dev_get_addr(dev->parent);
  211. if (addr == FDT_ADDR_T_NONE)
  212. return -EINVAL;
  213. priv->base = devm_ioremap(dev, addr, SZ_4K);
  214. if (!priv->base)
  215. return -ENOMEM;
  216. priv->data = (void *)dev_get_driver_data(dev);
  217. return 0;
  218. }
  219. static const struct udevice_id uniphier_reset_match[] = {
  220. /* System reset */
  221. {
  222. .compatible = "socionext,uniphier-sld3-reset",
  223. .data = (ulong)uniphier_sld3_sys_reset_data,
  224. },
  225. {
  226. .compatible = "socionext,uniphier-ld4-reset",
  227. .data = (ulong)uniphier_sld3_sys_reset_data,
  228. },
  229. {
  230. .compatible = "socionext,uniphier-pro4-reset",
  231. .data = (ulong)uniphier_pro4_sys_reset_data,
  232. },
  233. {
  234. .compatible = "socionext,uniphier-sld8-reset",
  235. .data = (ulong)uniphier_sld3_sys_reset_data,
  236. },
  237. {
  238. .compatible = "socionext,uniphier-pro5-reset",
  239. .data = (ulong)uniphier_pro5_sys_reset_data,
  240. },
  241. {
  242. .compatible = "socionext,uniphier-pxs2-reset",
  243. .data = (ulong)uniphier_pxs2_sys_reset_data,
  244. },
  245. {
  246. .compatible = "socionext,uniphier-ld11-reset",
  247. .data = (ulong)uniphier_ld11_sys_reset_data,
  248. },
  249. {
  250. .compatible = "socionext,uniphier-ld20-reset",
  251. .data = (ulong)uniphier_ld20_sys_reset_data,
  252. },
  253. /* Media I/O reset */
  254. {
  255. .compatible = "socionext,uniphier-sld3-mio-clock",
  256. .data = (ulong)uniphier_mio_reset_data,
  257. },
  258. {
  259. .compatible = "socionext,uniphier-ld4-mio-reset",
  260. .data = (ulong)uniphier_mio_reset_data,
  261. },
  262. {
  263. .compatible = "socionext,uniphier-pro4-mio-reset",
  264. .data = (ulong)uniphier_mio_reset_data,
  265. },
  266. {
  267. .compatible = "socionext,uniphier-sld8-mio-reset",
  268. .data = (ulong)uniphier_mio_reset_data,
  269. },
  270. {
  271. .compatible = "socionext,uniphier-pro5-mio-reset",
  272. .data = (ulong)uniphier_mio_reset_data,
  273. },
  274. {
  275. .compatible = "socionext,uniphier-pxs2-mio-reset",
  276. .data = (ulong)uniphier_mio_reset_data,
  277. },
  278. {
  279. .compatible = "socionext,uniphier-ld11-mio-reset",
  280. .data = (ulong)uniphier_mio_reset_data,
  281. },
  282. {
  283. .compatible = "socionext,uniphier-ld20-mio-reset",
  284. .data = (ulong)uniphier_mio_reset_data,
  285. },
  286. /* Peripheral reset */
  287. {
  288. .compatible = "socionext,uniphier-ld4-peri-reset",
  289. .data = (ulong)uniphier_ld4_peri_reset_data,
  290. },
  291. {
  292. .compatible = "socionext,uniphier-pro4-peri-reset",
  293. .data = (ulong)uniphier_pro4_peri_reset_data,
  294. },
  295. {
  296. .compatible = "socionext,uniphier-sld8-peri-reset",
  297. .data = (ulong)uniphier_ld4_peri_reset_data,
  298. },
  299. {
  300. .compatible = "socionext,uniphier-pro5-peri-reset",
  301. .data = (ulong)uniphier_pro4_peri_reset_data,
  302. },
  303. {
  304. .compatible = "socionext,uniphier-pxs2-peri-reset",
  305. .data = (ulong)uniphier_pro4_peri_reset_data,
  306. },
  307. {
  308. .compatible = "socionext,uniphier-ld11-peri-reset",
  309. .data = (ulong)uniphier_pro4_peri_reset_data,
  310. },
  311. {
  312. .compatible = "socionext,uniphier-ld20-peri-reset",
  313. .data = (ulong)uniphier_pro4_peri_reset_data,
  314. },
  315. { /* sentinel */ }
  316. };
  317. U_BOOT_DRIVER(uniphier_reset) = {
  318. .name = "uniphier-reset",
  319. .id = UCLASS_RESET,
  320. .of_match = uniphier_reset_match,
  321. .probe = uniphier_reset_probe,
  322. .priv_auto_alloc_size = sizeof(struct uniphier_reset_priv),
  323. .ops = &uniphier_reset_ops,
  324. };