blob: 629f8b90c9d869b5b2a082f15499d63f74524e1b [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +09002/*
Masahiro Yamadad421af22017-01-28 06:53:47 +09003 * Copyright (C) 2015-2017 Socionext Inc.
4 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +09005 */
6
Simon Glassed38aef2020-05-10 11:40:03 -06007#include <command.h>
Masahiro Yamada609cd532017-10-13 19:21:55 +09008#include <stdio.h>
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +09009#include <linux/io.h>
Masahiro Yamada609cd532017-10-13 19:21:55 +090010#include <linux/printk.h>
Masahiro Yamadad421af22017-01-28 06:53:47 +090011#include <linux/sizes.h>
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090012
Masahiro Yamadad421af22017-01-28 06:53:47 +090013#include "../soc-info.h"
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090014#include "ddrmphy-regs.h"
15
16/* Select either decimal or hexadecimal */
17#if 1
18#define PRINTF_FORMAT "%2d"
19#else
20#define PRINTF_FORMAT "%02x"
21#endif
22/* field separator */
23#define FS " "
24
Masahiro Yamadad421af22017-01-28 06:53:47 +090025#define ptr_to_uint(p) ((unsigned int)(unsigned long)(p))
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090026
Masahiro Yamadad421af22017-01-28 06:53:47 +090027#define UNIPHIER_MAX_NR_DDRMPHY 3
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090028
Masahiro Yamadad421af22017-01-28 06:53:47 +090029struct uniphier_ddrmphy_param {
30 unsigned int soc_id;
31 unsigned int nr_phy;
32 struct {
33 resource_size_t base;
34 unsigned int nr_zq;
35 unsigned int nr_dx;
36 } phy[UNIPHIER_MAX_NR_DDRMPHY];
37};
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090038
Masahiro Yamadad421af22017-01-28 06:53:47 +090039static const struct uniphier_ddrmphy_param uniphier_ddrmphy_param[] = {
40 {
41 .soc_id = UNIPHIER_PXS2_ID,
42 .nr_phy = 3,
43 .phy = {
44 { .base = 0x5b830000, .nr_zq = 3, .nr_dx = 4, },
45 { .base = 0x5ba30000, .nr_zq = 3, .nr_dx = 4, },
46 { .base = 0x5bc30000, .nr_zq = 2, .nr_dx = 2, },
47 },
48 },
49 {
50 .soc_id = UNIPHIER_LD6B_ID,
51 .nr_phy = 3,
52 .phy = {
53 { .base = 0x5b830000, .nr_zq = 3, .nr_dx = 4, },
54 { .base = 0x5ba30000, .nr_zq = 3, .nr_dx = 4, },
55 { .base = 0x5bc30000, .nr_zq = 2, .nr_dx = 2, },
56 },
57 },
58};
59UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_ddrmphy_param, uniphier_ddrmphy_param)
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090060
61static void print_bdl(void __iomem *reg, int n)
62{
63 u32 val = readl(reg);
64 int i;
65
66 for (i = 0; i < n; i++)
67 printf(FS PRINTF_FORMAT, (val >> i * 8) & 0x1f);
68}
69
Masahiro Yamadad421af22017-01-28 06:53:47 +090070static void dump_loop(const struct uniphier_ddrmphy_param *param,
71 void (*callback)(void __iomem *))
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090072{
Masahiro Yamadad421af22017-01-28 06:53:47 +090073 void __iomem *phy_base, *dx_base;
74 int phy, dx;
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090075
Masahiro Yamadad421af22017-01-28 06:53:47 +090076 for (phy = 0; phy < param->nr_phy; phy++) {
77 phy_base = ioremap(param->phy[phy].base, SZ_4K);
78 dx_base = phy_base + MPHY_DX_BASE;
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090079
Masahiro Yamadad421af22017-01-28 06:53:47 +090080 for (dx = 0; dx < param->phy[phy].nr_dx; dx++) {
81 printf("PHY%dDX%d:", phy, dx);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090082 (*callback)(dx_base);
Masahiro Yamada7747f792017-01-28 06:53:46 +090083 dx_base += MPHY_DX_STRIDE;
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090084 printf("\n");
85 }
Masahiro Yamadad421af22017-01-28 06:53:47 +090086
87 iounmap(phy_base);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090088 }
89}
90
Masahiro Yamadad421af22017-01-28 06:53:47 +090091static void zq_dump(const struct uniphier_ddrmphy_param *param)
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090092{
Masahiro Yamadad421af22017-01-28 06:53:47 +090093 void __iomem *phy_base, *zq_base;
94 u32 val;
95 int phy, zq, i;
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090096
97 printf("\n--- Impedance Data ---\n");
Masahiro Yamadad421af22017-01-28 06:53:47 +090098 printf(" ZPD ZPU OPD OPU ZDV ODV\n");
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +090099
Masahiro Yamadad421af22017-01-28 06:53:47 +0900100 for (phy = 0; phy < param->nr_phy; phy++) {
101 phy_base = ioremap(param->phy[phy].base, SZ_4K);
102 zq_base = phy_base + MPHY_ZQ_BASE;
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900103
Masahiro Yamadad421af22017-01-28 06:53:47 +0900104 for (zq = 0; zq < param->phy[phy].nr_zq; zq++) {
105 printf("PHY%dZQ%d:", phy, zq);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900106
Masahiro Yamadad421af22017-01-28 06:53:47 +0900107 val = readl(zq_base + MPHY_ZQ_DR);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900108 for (i = 0; i < 4; i++) {
Masahiro Yamadad421af22017-01-28 06:53:47 +0900109 printf(FS PRINTF_FORMAT, val & 0x7f);
110 val >>= 7;
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900111 }
112
Masahiro Yamadad421af22017-01-28 06:53:47 +0900113 val = readl(zq_base + MPHY_ZQ_PR);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900114 for (i = 0; i < 2; i++) {
Masahiro Yamadad421af22017-01-28 06:53:47 +0900115 printf(FS PRINTF_FORMAT, val & 0xf);
116 val >>= 4;
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900117 }
118
Masahiro Yamada7747f792017-01-28 06:53:46 +0900119 zq_base += MPHY_ZQ_STRIDE;
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900120 printf("\n");
121 }
Masahiro Yamadad421af22017-01-28 06:53:47 +0900122
123 iounmap(phy_base);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900124 }
125}
126
127static void __wbdl_dump(void __iomem *dx_base)
128{
Masahiro Yamada7747f792017-01-28 06:53:46 +0900129 print_bdl(dx_base + MPHY_DX_BDLR0, 4);
130 print_bdl(dx_base + MPHY_DX_BDLR1, 4);
131 print_bdl(dx_base + MPHY_DX_BDLR2, 2);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900132
133 printf(FS "(+" PRINTF_FORMAT ")",
Masahiro Yamada7747f792017-01-28 06:53:46 +0900134 readl(dx_base + MPHY_DX_LCDLR1) & 0xff);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900135}
136
Masahiro Yamadad421af22017-01-28 06:53:47 +0900137static void wbdl_dump(const struct uniphier_ddrmphy_param *param)
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900138{
139 printf("\n--- Write Bit Delay Line ---\n");
Masahiro Yamadad421af22017-01-28 06:53:47 +0900140 printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM DQS (WDQD)\n");
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900141
Masahiro Yamadad421af22017-01-28 06:53:47 +0900142 dump_loop(param, &__wbdl_dump);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900143}
144
145static void __rbdl_dump(void __iomem *dx_base)
146{
Masahiro Yamada7747f792017-01-28 06:53:46 +0900147 print_bdl(dx_base + MPHY_DX_BDLR3, 4);
148 print_bdl(dx_base + MPHY_DX_BDLR4, 4);
149 print_bdl(dx_base + MPHY_DX_BDLR5, 1);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900150
151 printf(FS "(+" PRINTF_FORMAT ")",
Masahiro Yamada7747f792017-01-28 06:53:46 +0900152 (readl(dx_base + MPHY_DX_LCDLR1) >> 8) & 0xff);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900153
154 printf(FS "(+" PRINTF_FORMAT ")",
Masahiro Yamada7747f792017-01-28 06:53:46 +0900155 (readl(dx_base + MPHY_DX_LCDLR1) >> 16) & 0xff);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900156}
157
Masahiro Yamadad421af22017-01-28 06:53:47 +0900158static void rbdl_dump(const struct uniphier_ddrmphy_param *param)
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900159{
160 printf("\n--- Read Bit Delay Line ---\n");
Masahiro Yamadad421af22017-01-28 06:53:47 +0900161 printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM (RDQSD) (RDQSND)\n");
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900162
Masahiro Yamadad421af22017-01-28 06:53:47 +0900163 dump_loop(param, &__rbdl_dump);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900164}
165
166static void __wld_dump(void __iomem *dx_base)
167{
168 int rank;
Masahiro Yamada7747f792017-01-28 06:53:46 +0900169 u32 lcdlr0 = readl(dx_base + MPHY_DX_LCDLR0);
170 u32 gtr = readl(dx_base + MPHY_DX_GTR);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900171
172 for (rank = 0; rank < 4; rank++) {
173 u32 wld = (lcdlr0 >> (8 * rank)) & 0xff; /* Delay */
174 u32 wlsl = (gtr >> (12 + 2 * rank)) & 0x3; /* System Latency */
175
176 printf(FS PRINTF_FORMAT "%sT", wld,
177 wlsl == 0 ? "-1" : wlsl == 1 ? "+0" : "+1");
178 }
179}
180
Masahiro Yamadad421af22017-01-28 06:53:47 +0900181static void wld_dump(const struct uniphier_ddrmphy_param *param)
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900182{
183 printf("\n--- Write Leveling Delay ---\n");
Masahiro Yamadad421af22017-01-28 06:53:47 +0900184 printf(" Rank0 Rank1 Rank2 Rank3\n");
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900185
Masahiro Yamadad421af22017-01-28 06:53:47 +0900186 dump_loop(param, &__wld_dump);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900187}
188
189static void __dqsgd_dump(void __iomem *dx_base)
190{
191 int rank;
Masahiro Yamada7747f792017-01-28 06:53:46 +0900192 u32 lcdlr2 = readl(dx_base + MPHY_DX_LCDLR2);
193 u32 gtr = readl(dx_base + MPHY_DX_GTR);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900194
195 for (rank = 0; rank < 4; rank++) {
196 u32 dqsgd = (lcdlr2 >> (8 * rank)) & 0xff; /* Delay */
197 u32 dgsl = (gtr >> (3 * rank)) & 0x7; /* System Latency */
198
199 printf(FS PRINTF_FORMAT "+%dT", dqsgd, dgsl);
200 }
201}
202
Masahiro Yamadad421af22017-01-28 06:53:47 +0900203static void dqsgd_dump(const struct uniphier_ddrmphy_param *param)
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900204{
205 printf("\n--- DQS Gating Delay ---\n");
Masahiro Yamadad421af22017-01-28 06:53:47 +0900206 printf(" Rank0 Rank1 Rank2 Rank3\n");
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900207
Masahiro Yamadad421af22017-01-28 06:53:47 +0900208 dump_loop(param, &__dqsgd_dump);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900209}
210
211static void __mdl_dump(void __iomem *dx_base)
212{
213 int i;
Masahiro Yamada7747f792017-01-28 06:53:46 +0900214 u32 mdl = readl(dx_base + MPHY_DX_MDLR);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900215
216 for (i = 0; i < 3; i++)
217 printf(FS PRINTF_FORMAT, (mdl >> (8 * i)) & 0xff);
218}
219
Masahiro Yamadad421af22017-01-28 06:53:47 +0900220static void mdl_dump(const struct uniphier_ddrmphy_param *param)
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900221{
222 printf("\n--- Master Delay Line ---\n");
Masahiro Yamadad421af22017-01-28 06:53:47 +0900223 printf(" IPRD TPRD MDLD\n");
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900224
Masahiro Yamadad421af22017-01-28 06:53:47 +0900225 dump_loop(param, &__mdl_dump);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900226}
227
228#define REG_DUMP(x) \
Masahiro Yamada7747f792017-01-28 06:53:46 +0900229 { int ofst = MPHY_ ## x; void __iomem *reg = phy_base + ofst; \
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900230 printf("%3d: %-10s: %p : %08x\n", \
Masahiro Yamada7747f792017-01-28 06:53:46 +0900231 ofst >> MPHY_SHIFT, #x, reg, readl(reg)); }
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900232
233#define DX_REG_DUMP(dx, x) \
Masahiro Yamada7747f792017-01-28 06:53:46 +0900234 { int ofst = MPHY_DX_BASE + MPHY_DX_STRIDE * (dx) + \
235 MPHY_DX_## x; \
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900236 void __iomem *reg = phy_base + ofst; \
237 printf("%3d: DX%d%-7s: %p : %08x\n", \
Masahiro Yamada7747f792017-01-28 06:53:46 +0900238 ofst >> MPHY_SHIFT, (dx), #x, reg, readl(reg)); }
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900239
Masahiro Yamadad421af22017-01-28 06:53:47 +0900240static void reg_dump(const struct uniphier_ddrmphy_param *param)
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900241{
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900242 void __iomem *phy_base;
Masahiro Yamadad421af22017-01-28 06:53:47 +0900243 int phy, dx;
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900244
Masahiro Yamadad421af22017-01-28 06:53:47 +0900245 printf("\n--- DDR Multi PHY registers ---\n");
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900246
Masahiro Yamadad421af22017-01-28 06:53:47 +0900247 for (phy = 0; phy < param->nr_phy; phy++) {
248 phy_base = ioremap(param->phy[phy].base, SZ_4K);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900249
Masahiro Yamadad421af22017-01-28 06:53:47 +0900250 printf("== PHY%d (base: %08x) ==\n", phy,
251 ptr_to_uint(phy_base));
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900252 printf(" No: Name : Address : Data\n");
253
254 REG_DUMP(RIDR);
255 REG_DUMP(PIR);
256 REG_DUMP(PGCR0);
257 REG_DUMP(PGCR1);
258 REG_DUMP(PGCR2);
259 REG_DUMP(PGCR3);
260 REG_DUMP(PGSR0);
261 REG_DUMP(PGSR1);
262 REG_DUMP(PLLCR);
263 REG_DUMP(PTR0);
264 REG_DUMP(PTR1);
265 REG_DUMP(PTR2);
266 REG_DUMP(PTR3);
267 REG_DUMP(PTR4);
268 REG_DUMP(ACMDLR);
269 REG_DUMP(ACBDLR0);
270 REG_DUMP(DXCCR);
271 REG_DUMP(DSGCR);
272 REG_DUMP(DCR);
273 REG_DUMP(DTPR0);
274 REG_DUMP(DTPR1);
275 REG_DUMP(DTPR2);
276 REG_DUMP(DTPR3);
277 REG_DUMP(MR0);
278 REG_DUMP(MR1);
279 REG_DUMP(MR2);
280 REG_DUMP(MR3);
281
Masahiro Yamadad421af22017-01-28 06:53:47 +0900282 for (dx = 0; dx < param->phy[phy].nr_dx; dx++) {
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900283 DX_REG_DUMP(dx, GCR0);
284 DX_REG_DUMP(dx, GCR1);
285 DX_REG_DUMP(dx, GCR2);
286 DX_REG_DUMP(dx, GCR3);
287 DX_REG_DUMP(dx, GTR);
288 }
Masahiro Yamadad421af22017-01-28 06:53:47 +0900289
290 iounmap(phy_base);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900291 }
292}
293
Simon Glassed38aef2020-05-10 11:40:03 -0600294static int do_ddrm(struct cmd_tbl *cmdtp, int flag, int argc,
295 char *const argv[])
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900296{
Masahiro Yamadad421af22017-01-28 06:53:47 +0900297 const struct uniphier_ddrmphy_param *param;
298 char *cmd;
299
300 param = uniphier_get_ddrmphy_param();
301 if (!param) {
Masahiro Yamada609cd532017-10-13 19:21:55 +0900302 pr_err("unsupported SoC\n");
Masahiro Yamadad421af22017-01-28 06:53:47 +0900303 return CMD_RET_FAILURE;
304 }
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900305
306 if (argc == 1)
307 cmd = "all";
Masahiro Yamadad421af22017-01-28 06:53:47 +0900308 else
309 cmd = argv[1];
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900310
311 if (!strcmp(cmd, "zq") || !strcmp(cmd, "all"))
Masahiro Yamadad421af22017-01-28 06:53:47 +0900312 zq_dump(param);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900313
314 if (!strcmp(cmd, "wbdl") || !strcmp(cmd, "all"))
Masahiro Yamadad421af22017-01-28 06:53:47 +0900315 wbdl_dump(param);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900316
317 if (!strcmp(cmd, "rbdl") || !strcmp(cmd, "all"))
Masahiro Yamadad421af22017-01-28 06:53:47 +0900318 rbdl_dump(param);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900319
320 if (!strcmp(cmd, "wld") || !strcmp(cmd, "all"))
Masahiro Yamadad421af22017-01-28 06:53:47 +0900321 wld_dump(param);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900322
323 if (!strcmp(cmd, "dqsgd") || !strcmp(cmd, "all"))
Masahiro Yamadad421af22017-01-28 06:53:47 +0900324 dqsgd_dump(param);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900325
326 if (!strcmp(cmd, "mdl") || !strcmp(cmd, "all"))
Masahiro Yamadad421af22017-01-28 06:53:47 +0900327 mdl_dump(param);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900328
329 if (!strcmp(cmd, "reg") || !strcmp(cmd, "all"))
Masahiro Yamadad421af22017-01-28 06:53:47 +0900330 reg_dump(param);
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900331
Masahiro Yamadad421af22017-01-28 06:53:47 +0900332 return CMD_RET_SUCCESS;
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900333}
334
335U_BOOT_CMD(
336 ddrm, 2, 1, do_ddrm,
Masahiro Yamadad421af22017-01-28 06:53:47 +0900337 "UniPhier DDR Multi PHY parameters dumper",
Masahiro Yamada7facf882016-08-21 16:12:36 +0900338 "- dump all of the following\n"
Masahiro Yamadabfffa2c2016-01-09 01:51:15 +0900339 "ddrm zq - dump Impedance Data\n"
340 "ddrm wbdl - dump Write Bit Delay\n"
341 "ddrm rbdl - dump Read Bit Delay\n"
342 "ddrm wld - dump Write Leveling\n"
343 "ddrm dqsgd - dump DQS Gating Delay\n"
344 "ddrm mdl - dump Master Delay Line\n"
345 "ddrm reg - dump registers\n"
346);