reset-uniphier.c 9.6 KB

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