cmd_ddrmphy.c 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345
  1. // SPDX-License-Identifier: GPL-2.0+
  2. /*
  3. * Copyright (C) 2015-2017 Socionext Inc.
  4. * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
  5. */
  6. #include <common.h>
  7. #include <stdio.h>
  8. #include <linux/io.h>
  9. #include <linux/printk.h>
  10. #include <linux/sizes.h>
  11. #include "../soc-info.h"
  12. #include "ddrmphy-regs.h"
  13. /* Select either decimal or hexadecimal */
  14. #if 1
  15. #define PRINTF_FORMAT "%2d"
  16. #else
  17. #define PRINTF_FORMAT "%02x"
  18. #endif
  19. /* field separator */
  20. #define FS " "
  21. #define ptr_to_uint(p) ((unsigned int)(unsigned long)(p))
  22. #define UNIPHIER_MAX_NR_DDRMPHY 3
  23. struct uniphier_ddrmphy_param {
  24. unsigned int soc_id;
  25. unsigned int nr_phy;
  26. struct {
  27. resource_size_t base;
  28. unsigned int nr_zq;
  29. unsigned int nr_dx;
  30. } phy[UNIPHIER_MAX_NR_DDRMPHY];
  31. };
  32. static const struct uniphier_ddrmphy_param uniphier_ddrmphy_param[] = {
  33. {
  34. .soc_id = UNIPHIER_PXS2_ID,
  35. .nr_phy = 3,
  36. .phy = {
  37. { .base = 0x5b830000, .nr_zq = 3, .nr_dx = 4, },
  38. { .base = 0x5ba30000, .nr_zq = 3, .nr_dx = 4, },
  39. { .base = 0x5bc30000, .nr_zq = 2, .nr_dx = 2, },
  40. },
  41. },
  42. {
  43. .soc_id = UNIPHIER_LD6B_ID,
  44. .nr_phy = 3,
  45. .phy = {
  46. { .base = 0x5b830000, .nr_zq = 3, .nr_dx = 4, },
  47. { .base = 0x5ba30000, .nr_zq = 3, .nr_dx = 4, },
  48. { .base = 0x5bc30000, .nr_zq = 2, .nr_dx = 2, },
  49. },
  50. },
  51. };
  52. UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_ddrmphy_param, uniphier_ddrmphy_param)
  53. static void print_bdl(void __iomem *reg, int n)
  54. {
  55. u32 val = readl(reg);
  56. int i;
  57. for (i = 0; i < n; i++)
  58. printf(FS PRINTF_FORMAT, (val >> i * 8) & 0x1f);
  59. }
  60. static void dump_loop(const struct uniphier_ddrmphy_param *param,
  61. void (*callback)(void __iomem *))
  62. {
  63. void __iomem *phy_base, *dx_base;
  64. int phy, dx;
  65. for (phy = 0; phy < param->nr_phy; phy++) {
  66. phy_base = ioremap(param->phy[phy].base, SZ_4K);
  67. dx_base = phy_base + MPHY_DX_BASE;
  68. for (dx = 0; dx < param->phy[phy].nr_dx; dx++) {
  69. printf("PHY%dDX%d:", phy, dx);
  70. (*callback)(dx_base);
  71. dx_base += MPHY_DX_STRIDE;
  72. printf("\n");
  73. }
  74. iounmap(phy_base);
  75. }
  76. }
  77. static void zq_dump(const struct uniphier_ddrmphy_param *param)
  78. {
  79. void __iomem *phy_base, *zq_base;
  80. u32 val;
  81. int phy, zq, i;
  82. printf("\n--- Impedance Data ---\n");
  83. printf(" ZPD ZPU OPD OPU ZDV ODV\n");
  84. for (phy = 0; phy < param->nr_phy; phy++) {
  85. phy_base = ioremap(param->phy[phy].base, SZ_4K);
  86. zq_base = phy_base + MPHY_ZQ_BASE;
  87. for (zq = 0; zq < param->phy[phy].nr_zq; zq++) {
  88. printf("PHY%dZQ%d:", phy, zq);
  89. val = readl(zq_base + MPHY_ZQ_DR);
  90. for (i = 0; i < 4; i++) {
  91. printf(FS PRINTF_FORMAT, val & 0x7f);
  92. val >>= 7;
  93. }
  94. val = readl(zq_base + MPHY_ZQ_PR);
  95. for (i = 0; i < 2; i++) {
  96. printf(FS PRINTF_FORMAT, val & 0xf);
  97. val >>= 4;
  98. }
  99. zq_base += MPHY_ZQ_STRIDE;
  100. printf("\n");
  101. }
  102. iounmap(phy_base);
  103. }
  104. }
  105. static void __wbdl_dump(void __iomem *dx_base)
  106. {
  107. print_bdl(dx_base + MPHY_DX_BDLR0, 4);
  108. print_bdl(dx_base + MPHY_DX_BDLR1, 4);
  109. print_bdl(dx_base + MPHY_DX_BDLR2, 2);
  110. printf(FS "(+" PRINTF_FORMAT ")",
  111. readl(dx_base + MPHY_DX_LCDLR1) & 0xff);
  112. }
  113. static void wbdl_dump(const struct uniphier_ddrmphy_param *param)
  114. {
  115. printf("\n--- Write Bit Delay Line ---\n");
  116. printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM DQS (WDQD)\n");
  117. dump_loop(param, &__wbdl_dump);
  118. }
  119. static void __rbdl_dump(void __iomem *dx_base)
  120. {
  121. print_bdl(dx_base + MPHY_DX_BDLR3, 4);
  122. print_bdl(dx_base + MPHY_DX_BDLR4, 4);
  123. print_bdl(dx_base + MPHY_DX_BDLR5, 1);
  124. printf(FS "(+" PRINTF_FORMAT ")",
  125. (readl(dx_base + MPHY_DX_LCDLR1) >> 8) & 0xff);
  126. printf(FS "(+" PRINTF_FORMAT ")",
  127. (readl(dx_base + MPHY_DX_LCDLR1) >> 16) & 0xff);
  128. }
  129. static void rbdl_dump(const struct uniphier_ddrmphy_param *param)
  130. {
  131. printf("\n--- Read Bit Delay Line ---\n");
  132. printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM (RDQSD) (RDQSND)\n");
  133. dump_loop(param, &__rbdl_dump);
  134. }
  135. static void __wld_dump(void __iomem *dx_base)
  136. {
  137. int rank;
  138. u32 lcdlr0 = readl(dx_base + MPHY_DX_LCDLR0);
  139. u32 gtr = readl(dx_base + MPHY_DX_GTR);
  140. for (rank = 0; rank < 4; rank++) {
  141. u32 wld = (lcdlr0 >> (8 * rank)) & 0xff; /* Delay */
  142. u32 wlsl = (gtr >> (12 + 2 * rank)) & 0x3; /* System Latency */
  143. printf(FS PRINTF_FORMAT "%sT", wld,
  144. wlsl == 0 ? "-1" : wlsl == 1 ? "+0" : "+1");
  145. }
  146. }
  147. static void wld_dump(const struct uniphier_ddrmphy_param *param)
  148. {
  149. printf("\n--- Write Leveling Delay ---\n");
  150. printf(" Rank0 Rank1 Rank2 Rank3\n");
  151. dump_loop(param, &__wld_dump);
  152. }
  153. static void __dqsgd_dump(void __iomem *dx_base)
  154. {
  155. int rank;
  156. u32 lcdlr2 = readl(dx_base + MPHY_DX_LCDLR2);
  157. u32 gtr = readl(dx_base + MPHY_DX_GTR);
  158. for (rank = 0; rank < 4; rank++) {
  159. u32 dqsgd = (lcdlr2 >> (8 * rank)) & 0xff; /* Delay */
  160. u32 dgsl = (gtr >> (3 * rank)) & 0x7; /* System Latency */
  161. printf(FS PRINTF_FORMAT "+%dT", dqsgd, dgsl);
  162. }
  163. }
  164. static void dqsgd_dump(const struct uniphier_ddrmphy_param *param)
  165. {
  166. printf("\n--- DQS Gating Delay ---\n");
  167. printf(" Rank0 Rank1 Rank2 Rank3\n");
  168. dump_loop(param, &__dqsgd_dump);
  169. }
  170. static void __mdl_dump(void __iomem *dx_base)
  171. {
  172. int i;
  173. u32 mdl = readl(dx_base + MPHY_DX_MDLR);
  174. for (i = 0; i < 3; i++)
  175. printf(FS PRINTF_FORMAT, (mdl >> (8 * i)) & 0xff);
  176. }
  177. static void mdl_dump(const struct uniphier_ddrmphy_param *param)
  178. {
  179. printf("\n--- Master Delay Line ---\n");
  180. printf(" IPRD TPRD MDLD\n");
  181. dump_loop(param, &__mdl_dump);
  182. }
  183. #define REG_DUMP(x) \
  184. { int ofst = MPHY_ ## x; void __iomem *reg = phy_base + ofst; \
  185. printf("%3d: %-10s: %p : %08x\n", \
  186. ofst >> MPHY_SHIFT, #x, reg, readl(reg)); }
  187. #define DX_REG_DUMP(dx, x) \
  188. { int ofst = MPHY_DX_BASE + MPHY_DX_STRIDE * (dx) + \
  189. MPHY_DX_## x; \
  190. void __iomem *reg = phy_base + ofst; \
  191. printf("%3d: DX%d%-7s: %p : %08x\n", \
  192. ofst >> MPHY_SHIFT, (dx), #x, reg, readl(reg)); }
  193. static void reg_dump(const struct uniphier_ddrmphy_param *param)
  194. {
  195. void __iomem *phy_base;
  196. int phy, dx;
  197. printf("\n--- DDR Multi PHY registers ---\n");
  198. for (phy = 0; phy < param->nr_phy; phy++) {
  199. phy_base = ioremap(param->phy[phy].base, SZ_4K);
  200. printf("== PHY%d (base: %08x) ==\n", phy,
  201. ptr_to_uint(phy_base));
  202. printf(" No: Name : Address : Data\n");
  203. REG_DUMP(RIDR);
  204. REG_DUMP(PIR);
  205. REG_DUMP(PGCR0);
  206. REG_DUMP(PGCR1);
  207. REG_DUMP(PGCR2);
  208. REG_DUMP(PGCR3);
  209. REG_DUMP(PGSR0);
  210. REG_DUMP(PGSR1);
  211. REG_DUMP(PLLCR);
  212. REG_DUMP(PTR0);
  213. REG_DUMP(PTR1);
  214. REG_DUMP(PTR2);
  215. REG_DUMP(PTR3);
  216. REG_DUMP(PTR4);
  217. REG_DUMP(ACMDLR);
  218. REG_DUMP(ACBDLR0);
  219. REG_DUMP(DXCCR);
  220. REG_DUMP(DSGCR);
  221. REG_DUMP(DCR);
  222. REG_DUMP(DTPR0);
  223. REG_DUMP(DTPR1);
  224. REG_DUMP(DTPR2);
  225. REG_DUMP(DTPR3);
  226. REG_DUMP(MR0);
  227. REG_DUMP(MR1);
  228. REG_DUMP(MR2);
  229. REG_DUMP(MR3);
  230. for (dx = 0; dx < param->phy[phy].nr_dx; dx++) {
  231. DX_REG_DUMP(dx, GCR0);
  232. DX_REG_DUMP(dx, GCR1);
  233. DX_REG_DUMP(dx, GCR2);
  234. DX_REG_DUMP(dx, GCR3);
  235. DX_REG_DUMP(dx, GTR);
  236. }
  237. iounmap(phy_base);
  238. }
  239. }
  240. static int do_ddrm(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
  241. {
  242. const struct uniphier_ddrmphy_param *param;
  243. char *cmd;
  244. param = uniphier_get_ddrmphy_param();
  245. if (!param) {
  246. pr_err("unsupported SoC\n");
  247. return CMD_RET_FAILURE;
  248. }
  249. if (argc == 1)
  250. cmd = "all";
  251. else
  252. cmd = argv[1];
  253. if (!strcmp(cmd, "zq") || !strcmp(cmd, "all"))
  254. zq_dump(param);
  255. if (!strcmp(cmd, "wbdl") || !strcmp(cmd, "all"))
  256. wbdl_dump(param);
  257. if (!strcmp(cmd, "rbdl") || !strcmp(cmd, "all"))
  258. rbdl_dump(param);
  259. if (!strcmp(cmd, "wld") || !strcmp(cmd, "all"))
  260. wld_dump(param);
  261. if (!strcmp(cmd, "dqsgd") || !strcmp(cmd, "all"))
  262. dqsgd_dump(param);
  263. if (!strcmp(cmd, "mdl") || !strcmp(cmd, "all"))
  264. mdl_dump(param);
  265. if (!strcmp(cmd, "reg") || !strcmp(cmd, "all"))
  266. reg_dump(param);
  267. return CMD_RET_SUCCESS;
  268. }
  269. U_BOOT_CMD(
  270. ddrm, 2, 1, do_ddrm,
  271. "UniPhier DDR Multi PHY parameters dumper",
  272. "- dump all of the following\n"
  273. "ddrm zq - dump Impedance Data\n"
  274. "ddrm wbdl - dump Write Bit Delay\n"
  275. "ddrm rbdl - dump Read Bit Delay\n"
  276. "ddrm wld - dump Write Leveling\n"
  277. "ddrm dqsgd - dump DQS Gating Delay\n"
  278. "ddrm mdl - dump Master Delay Line\n"
  279. "ddrm reg - dump registers\n"
  280. );