blob: ca519d1c7e0c6be37d0ef00cbbc30b72a763fcc4 [file] [log] [blame]
Tom Rini10e47792018-05-06 17:58:06 -04001// SPDX-License-Identifier: GPL-2.0+
Masahiro Yamada8f899ed2014-12-19 20:20:53 +09002/*
Masahiro Yamadafa1f73f2016-07-19 21:56:13 +09003 * Copyright (C) 2014 Panasonic Corporation
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +09004 * Copyright (C) 2015-2017 Socionext Inc.
Masahiro Yamadafa1f73f2016-07-19 21:56:13 +09005 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada8f899ed2014-12-19 20:20:53 +09006 */
7
Simon Glassed38aef2020-05-10 11:40:03 -06008#include <command.h>
Masahiro Yamada609cd532017-10-13 19:21:55 +09009#include <stdio.h>
Masahiro Yamada663a23f2015-05-29 17:30:00 +090010#include <linux/io.h>
Masahiro Yamada609cd532017-10-13 19:21:55 +090011#include <linux/printk.h>
Masahiro Yamada820353b2016-03-18 16:41:45 +090012#include <linux/sizes.h>
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090013
Masahiro Yamada820353b2016-03-18 16:41:45 +090014#include "../soc-info.h"
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090015#include "ddrphy-regs.h"
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090016
17/* Select either decimal or hexadecimal */
18#if 1
19#define PRINTF_FORMAT "%2d"
20#else
21#define PRINTF_FORMAT "%02x"
22#endif
23/* field separator */
24#define FS " "
25
Masahiro Yamadab5a83932016-10-27 23:47:09 +090026#define ptr_to_uint(p) ((unsigned int)(unsigned long)(p))
27
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090028#define UNIPHIER_MAX_NR_DDRPHY 4
Masahiro Yamada820353b2016-03-18 16:41:45 +090029
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090030struct uniphier_ddrphy_param {
31 unsigned int soc_id;
32 unsigned int nr_phy;
33 struct {
34 resource_size_t base;
35 unsigned int nr_dx;
36 } phy[UNIPHIER_MAX_NR_DDRPHY];
Masahiro Yamada820353b2016-03-18 16:41:45 +090037};
38
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090039static const struct uniphier_ddrphy_param uniphier_ddrphy_param[] = {
40 {
41 .soc_id = UNIPHIER_LD4_ID,
42 .nr_phy = 2,
43 .phy = {
44 { .base = 0x5bc01000, .nr_dx = 2, },
45 { .base = 0x5be01000, .nr_dx = 2, },
46 },
47 },
48 {
49 .soc_id = UNIPHIER_PRO4_ID,
50 .nr_phy = 4,
51 .phy = {
52 { .base = 0x5bc01000, .nr_dx = 2, },
53 { .base = 0x5bc02000, .nr_dx = 2, },
54 { .base = 0x5be01000, .nr_dx = 2, },
55 { .base = 0x5be02000, .nr_dx = 2, },
56 },
57 },
58 {
59 .soc_id = UNIPHIER_SLD8_ID,
60 .nr_phy = 2,
61 .phy = {
62 { .base = 0x5bc01000, .nr_dx = 2, },
63 { .base = 0x5be01000, .nr_dx = 2, },
64 },
65 },
66 {
67 .soc_id = UNIPHIER_LD11_ID,
68 .nr_phy = 1,
69 .phy = {
70 { .base = 0x5bc01000, .nr_dx = 4, },
71 },
72 },
Masahiro Yamada913b3d02016-10-27 23:47:08 +090073};
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090074UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_ddrphy_param, uniphier_ddrphy_param)
Masahiro Yamadab5a83932016-10-27 23:47:09 +090075
Masahiro Yamadab464ff92016-10-27 23:47:07 +090076static void print_bdl(void __iomem *reg, int n)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090077{
Masahiro Yamadab464ff92016-10-27 23:47:07 +090078 u32 val = readl(reg);
79 int i;
80
81 for (i = 0; i < n; i++)
82 printf(FS PRINTF_FORMAT, (val >> i * 6) & 0x3f);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090083}
84
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090085static void dump_loop(const struct uniphier_ddrphy_param *param,
Masahiro Yamadab464ff92016-10-27 23:47:07 +090086 void (*callback)(void __iomem *))
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090087{
Masahiro Yamadab464ff92016-10-27 23:47:07 +090088 void __iomem *phy_base, *dx_base;
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090089 int phy, dx;
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090090
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090091 for (phy = 0; phy < param->nr_phy; phy++) {
92 phy_base = ioremap(param->phy[phy].base, SZ_4K);
Masahiro Yamadab464ff92016-10-27 23:47:07 +090093 dx_base = phy_base + PHY_DX_BASE;
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090094
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090095 for (dx = 0; dx < param->phy[phy].nr_dx; dx++) {
96 printf("PHY%dDX%d:", phy, dx);
Masahiro Yamadab464ff92016-10-27 23:47:07 +090097 (*callback)(dx_base);
98 dx_base += PHY_DX_STRIDE;
Masahiro Yamada820353b2016-03-18 16:41:45 +090099 printf("\n");
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900100 }
Masahiro Yamada820353b2016-03-18 16:41:45 +0900101
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900102 iounmap(phy_base);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900103 }
104}
105
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900106static void __wbdl_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900107{
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900108 print_bdl(dx_base + PHY_DX_BDLR0, 5);
109 print_bdl(dx_base + PHY_DX_BDLR1, 5);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900110
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900111 printf(FS "(+" PRINTF_FORMAT ")",
112 readl(dx_base + PHY_DX_LCDLR1) & 0xff);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900113}
114
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900115static void wbdl_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900116{
117 printf("\n--- Write Bit Delay Line ---\n");
118 printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM DQS (WDQD)\n");
119
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900120 dump_loop(param, &__wbdl_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900121}
122
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900123static void __rbdl_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900124{
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900125 print_bdl(dx_base + PHY_DX_BDLR3, 5);
126 print_bdl(dx_base + PHY_DX_BDLR4, 4);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900127
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900128 printf(FS "(+" PRINTF_FORMAT ")",
129 (readl(dx_base + PHY_DX_LCDLR1) >> 8) & 0xff);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900130}
131
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900132static void rbdl_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900133{
134 printf("\n--- Read Bit Delay Line ---\n");
135 printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM (RDQSD)\n");
136
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900137 dump_loop(param, &__rbdl_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900138}
139
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900140static void __wld_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900141{
142 int rank;
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900143 u32 lcdlr0 = readl(dx_base + PHY_DX_LCDLR0);
144 u32 gtr = readl(dx_base + PHY_DX_GTR);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900145
146 for (rank = 0; rank < 4; rank++) {
147 u32 wld = (lcdlr0 >> (8 * rank)) & 0xff; /* Delay */
148 u32 wlsl = (gtr >> (12 + 2 * rank)) & 0x3; /* System Latency */
149
150 printf(FS PRINTF_FORMAT "%sT", wld,
151 wlsl == 0 ? "-1" : wlsl == 1 ? "+0" : "+1");
152 }
153}
154
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900155static void wld_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900156{
157 printf("\n--- Write Leveling Delay ---\n");
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900158 printf(" Rank0 Rank1 Rank2 Rank3\n");
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900159
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900160 dump_loop(param, &__wld_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900161}
162
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900163static void __dqsgd_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900164{
165 int rank;
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900166 u32 lcdlr2 = readl(dx_base + PHY_DX_LCDLR2);
167 u32 gtr = readl(dx_base + PHY_DX_GTR);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900168
169 for (rank = 0; rank < 4; rank++) {
170 u32 dqsgd = (lcdlr2 >> (8 * rank)) & 0xff; /* Delay */
171 u32 dgsl = (gtr >> (3 * rank)) & 0x7; /* System Latency */
172
173 printf(FS PRINTF_FORMAT "+%dT", dqsgd, dgsl);
174 }
175}
176
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900177static void dqsgd_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900178{
179 printf("\n--- DQS Gating Delay ---\n");
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900180 printf(" Rank0 Rank1 Rank2 Rank3\n");
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900181
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900182 dump_loop(param, &__dqsgd_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900183}
184
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900185static void __mdl_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900186{
187 int i;
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900188 u32 mdl = readl(dx_base + PHY_DX_MDLR);
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900189
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900190 for (i = 0; i < 3; i++)
191 printf(FS PRINTF_FORMAT, (mdl >> (8 * i)) & 0xff);
192}
193
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900194static void mdl_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900195{
196 printf("\n--- Master Delay Line ---\n");
197 printf(" IPRD TPRD MDLD\n");
198
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900199 dump_loop(param, &__mdl_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900200}
201
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900202#define REG_DUMP(x) \
203 { int ofst = PHY_ ## x; void __iomem *reg = phy_base + ofst; \
Masahiro Yamadab5a83932016-10-27 23:47:09 +0900204 printf("%3d: %-10s: %08x : %08x\n", \
205 ofst >> PHY_REG_SHIFT, #x, \
206 ptr_to_uint(reg), readl(reg)); }
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900207
208#define DX_REG_DUMP(dx, x) \
209 { int ofst = PHY_DX_BASE + PHY_DX_STRIDE * (dx) + \
210 PHY_DX_## x; \
211 void __iomem *reg = phy_base + ofst; \
Masahiro Yamadab5a83932016-10-27 23:47:09 +0900212 printf("%3d: DX%d%-7s: %08x : %08x\n", \
213 ofst >> PHY_REG_SHIFT, (dx), #x, \
214 ptr_to_uint(reg), readl(reg)); }
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900215
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900216static void reg_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900217{
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900218 void __iomem *phy_base;
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900219 int phy, dx;
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900220
221 printf("\n--- DDR PHY registers ---\n");
222
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900223 for (phy = 0; phy < param->nr_phy; phy++) {
224 phy_base = ioremap(param->phy[phy].base, SZ_4K);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900225
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900226 printf("== PHY%d (base: %08x) ==\n",
227 phy, ptr_to_uint(phy_base));
Masahiro Yamada820353b2016-03-18 16:41:45 +0900228 printf(" No: Name : Address : Data\n");
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900229
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900230 REG_DUMP(RIDR);
231 REG_DUMP(PIR);
232 REG_DUMP(PGCR0);
233 REG_DUMP(PGCR1);
234 REG_DUMP(PGSR0);
235 REG_DUMP(PGSR1);
236 REG_DUMP(PLLCR);
237 REG_DUMP(PTR0);
238 REG_DUMP(PTR1);
239 REG_DUMP(PTR2);
240 REG_DUMP(PTR3);
241 REG_DUMP(PTR4);
242 REG_DUMP(ACMDLR);
243 REG_DUMP(ACBDLR);
244 REG_DUMP(DXCCR);
245 REG_DUMP(DSGCR);
246 REG_DUMP(DCR);
247 REG_DUMP(DTPR0);
248 REG_DUMP(DTPR1);
249 REG_DUMP(DTPR2);
250 REG_DUMP(MR0);
251 REG_DUMP(MR1);
252 REG_DUMP(MR2);
253 REG_DUMP(MR3);
254
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900255 for (dx = 0; dx < param->phy[phy].nr_dx; dx++) {
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900256 DX_REG_DUMP(dx, GCR);
257 DX_REG_DUMP(dx, GTR);
258 }
Masahiro Yamada820353b2016-03-18 16:41:45 +0900259
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900260 iounmap(phy_base);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900261 }
262}
263
Simon Glassed38aef2020-05-10 11:40:03 -0600264static int do_ddr(struct cmd_tbl *cmdtp, int flag, int argc,
265 char *const argv[])
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900266{
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900267 const struct uniphier_ddrphy_param *param;
268 char *cmd;
Masahiro Yamada820353b2016-03-18 16:41:45 +0900269
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900270 param = uniphier_get_ddrphy_param();
271 if (!param) {
Masahiro Yamada609cd532017-10-13 19:21:55 +0900272 pr_err("unsupported SoC\n");
Masahiro Yamada820353b2016-03-18 16:41:45 +0900273 return CMD_RET_FAILURE;
274 }
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900275
276 if (argc == 1)
277 cmd = "all";
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900278 else
279 cmd = argv[1];
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900280
281 if (!strcmp(cmd, "wbdl") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900282 wbdl_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900283
284 if (!strcmp(cmd, "rbdl") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900285 rbdl_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900286
287 if (!strcmp(cmd, "wld") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900288 wld_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900289
290 if (!strcmp(cmd, "dqsgd") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900291 dqsgd_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900292
293 if (!strcmp(cmd, "mdl") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900294 mdl_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900295
296 if (!strcmp(cmd, "reg") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900297 reg_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900298
Masahiro Yamada820353b2016-03-18 16:41:45 +0900299 return CMD_RET_SUCCESS;
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900300}
301
302U_BOOT_CMD(
303 ddr, 2, 1, do_ddr,
304 "UniPhier DDR PHY parameters dumper",
Masahiro Yamada7facf882016-08-21 16:12:36 +0900305 "- dump all of the following\n"
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900306 "ddr wbdl - dump Write Bit Delay\n"
307 "ddr rbdl - dump Read Bit Delay\n"
308 "ddr wld - dump Write Leveling\n"
309 "ddr dqsgd - dump DQS Gating Delay\n"
310 "ddr mdl - dump Master Delay Line\n"
311 "ddr reg - dump registers\n"
312);