blob: 476c5b3582308140078adab1d5a68b031a24341e [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
8#include <common.h>
Simon Glassed38aef2020-05-10 11:40:03 -06009#include <command.h>
Masahiro Yamada609cd532017-10-13 19:21:55 +090010#include <stdio.h>
Masahiro Yamada663a23f2015-05-29 17:30:00 +090011#include <linux/io.h>
Masahiro Yamada609cd532017-10-13 19:21:55 +090012#include <linux/printk.h>
Masahiro Yamada820353b2016-03-18 16:41:45 +090013#include <linux/sizes.h>
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090014
Masahiro Yamada820353b2016-03-18 16:41:45 +090015#include "../soc-info.h"
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090016#include "ddrphy-regs.h"
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090017
18/* Select either decimal or hexadecimal */
19#if 1
20#define PRINTF_FORMAT "%2d"
21#else
22#define PRINTF_FORMAT "%02x"
23#endif
24/* field separator */
25#define FS " "
26
Masahiro Yamadab5a83932016-10-27 23:47:09 +090027#define ptr_to_uint(p) ((unsigned int)(unsigned long)(p))
28
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090029#define UNIPHIER_MAX_NR_DDRPHY 4
Masahiro Yamada820353b2016-03-18 16:41:45 +090030
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090031struct uniphier_ddrphy_param {
32 unsigned int soc_id;
33 unsigned int nr_phy;
34 struct {
35 resource_size_t base;
36 unsigned int nr_dx;
37 } phy[UNIPHIER_MAX_NR_DDRPHY];
Masahiro Yamada820353b2016-03-18 16:41:45 +090038};
39
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090040static const struct uniphier_ddrphy_param uniphier_ddrphy_param[] = {
41 {
42 .soc_id = UNIPHIER_LD4_ID,
43 .nr_phy = 2,
44 .phy = {
45 { .base = 0x5bc01000, .nr_dx = 2, },
46 { .base = 0x5be01000, .nr_dx = 2, },
47 },
48 },
49 {
50 .soc_id = UNIPHIER_PRO4_ID,
51 .nr_phy = 4,
52 .phy = {
53 { .base = 0x5bc01000, .nr_dx = 2, },
54 { .base = 0x5bc02000, .nr_dx = 2, },
55 { .base = 0x5be01000, .nr_dx = 2, },
56 { .base = 0x5be02000, .nr_dx = 2, },
57 },
58 },
59 {
60 .soc_id = UNIPHIER_SLD8_ID,
61 .nr_phy = 2,
62 .phy = {
63 { .base = 0x5bc01000, .nr_dx = 2, },
64 { .base = 0x5be01000, .nr_dx = 2, },
65 },
66 },
67 {
68 .soc_id = UNIPHIER_LD11_ID,
69 .nr_phy = 1,
70 .phy = {
71 { .base = 0x5bc01000, .nr_dx = 4, },
72 },
73 },
Masahiro Yamada913b3d02016-10-27 23:47:08 +090074};
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090075UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_ddrphy_param, uniphier_ddrphy_param)
Masahiro Yamadab5a83932016-10-27 23:47:09 +090076
Masahiro Yamadab464ff92016-10-27 23:47:07 +090077static void print_bdl(void __iomem *reg, int n)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090078{
Masahiro Yamadab464ff92016-10-27 23:47:07 +090079 u32 val = readl(reg);
80 int i;
81
82 for (i = 0; i < n; i++)
83 printf(FS PRINTF_FORMAT, (val >> i * 6) & 0x3f);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090084}
85
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090086static void dump_loop(const struct uniphier_ddrphy_param *param,
Masahiro Yamadab464ff92016-10-27 23:47:07 +090087 void (*callback)(void __iomem *))
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090088{
Masahiro Yamadab464ff92016-10-27 23:47:07 +090089 void __iomem *phy_base, *dx_base;
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090090 int phy, dx;
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090091
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090092 for (phy = 0; phy < param->nr_phy; phy++) {
93 phy_base = ioremap(param->phy[phy].base, SZ_4K);
Masahiro Yamadab464ff92016-10-27 23:47:07 +090094 dx_base = phy_base + PHY_DX_BASE;
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090095
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090096 for (dx = 0; dx < param->phy[phy].nr_dx; dx++) {
97 printf("PHY%dDX%d:", phy, dx);
Masahiro Yamadab464ff92016-10-27 23:47:07 +090098 (*callback)(dx_base);
99 dx_base += PHY_DX_STRIDE;
Masahiro Yamada820353b2016-03-18 16:41:45 +0900100 printf("\n");
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900101 }
Masahiro Yamada820353b2016-03-18 16:41:45 +0900102
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900103 iounmap(phy_base);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900104 }
105}
106
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900107static void __wbdl_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900108{
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900109 print_bdl(dx_base + PHY_DX_BDLR0, 5);
110 print_bdl(dx_base + PHY_DX_BDLR1, 5);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900111
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900112 printf(FS "(+" PRINTF_FORMAT ")",
113 readl(dx_base + PHY_DX_LCDLR1) & 0xff);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900114}
115
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900116static void wbdl_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900117{
118 printf("\n--- Write Bit Delay Line ---\n");
119 printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM DQS (WDQD)\n");
120
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900121 dump_loop(param, &__wbdl_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900122}
123
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900124static void __rbdl_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900125{
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900126 print_bdl(dx_base + PHY_DX_BDLR3, 5);
127 print_bdl(dx_base + PHY_DX_BDLR4, 4);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900128
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900129 printf(FS "(+" PRINTF_FORMAT ")",
130 (readl(dx_base + PHY_DX_LCDLR1) >> 8) & 0xff);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900131}
132
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900133static void rbdl_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900134{
135 printf("\n--- Read Bit Delay Line ---\n");
136 printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM (RDQSD)\n");
137
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900138 dump_loop(param, &__rbdl_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900139}
140
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900141static void __wld_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900142{
143 int rank;
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900144 u32 lcdlr0 = readl(dx_base + PHY_DX_LCDLR0);
145 u32 gtr = readl(dx_base + PHY_DX_GTR);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900146
147 for (rank = 0; rank < 4; rank++) {
148 u32 wld = (lcdlr0 >> (8 * rank)) & 0xff; /* Delay */
149 u32 wlsl = (gtr >> (12 + 2 * rank)) & 0x3; /* System Latency */
150
151 printf(FS PRINTF_FORMAT "%sT", wld,
152 wlsl == 0 ? "-1" : wlsl == 1 ? "+0" : "+1");
153 }
154}
155
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900156static void wld_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900157{
158 printf("\n--- Write Leveling Delay ---\n");
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900159 printf(" Rank0 Rank1 Rank2 Rank3\n");
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900160
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900161 dump_loop(param, &__wld_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900162}
163
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900164static void __dqsgd_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900165{
166 int rank;
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900167 u32 lcdlr2 = readl(dx_base + PHY_DX_LCDLR2);
168 u32 gtr = readl(dx_base + PHY_DX_GTR);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900169
170 for (rank = 0; rank < 4; rank++) {
171 u32 dqsgd = (lcdlr2 >> (8 * rank)) & 0xff; /* Delay */
172 u32 dgsl = (gtr >> (3 * rank)) & 0x7; /* System Latency */
173
174 printf(FS PRINTF_FORMAT "+%dT", dqsgd, dgsl);
175 }
176}
177
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900178static void dqsgd_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900179{
180 printf("\n--- DQS Gating Delay ---\n");
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900181 printf(" Rank0 Rank1 Rank2 Rank3\n");
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900182
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900183 dump_loop(param, &__dqsgd_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900184}
185
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900186static void __mdl_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900187{
188 int i;
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900189 u32 mdl = readl(dx_base + PHY_DX_MDLR);
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900190
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900191 for (i = 0; i < 3; i++)
192 printf(FS PRINTF_FORMAT, (mdl >> (8 * i)) & 0xff);
193}
194
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900195static void mdl_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900196{
197 printf("\n--- Master Delay Line ---\n");
198 printf(" IPRD TPRD MDLD\n");
199
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900200 dump_loop(param, &__mdl_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900201}
202
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900203#define REG_DUMP(x) \
204 { int ofst = PHY_ ## x; void __iomem *reg = phy_base + ofst; \
Masahiro Yamadab5a83932016-10-27 23:47:09 +0900205 printf("%3d: %-10s: %08x : %08x\n", \
206 ofst >> PHY_REG_SHIFT, #x, \
207 ptr_to_uint(reg), readl(reg)); }
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900208
209#define DX_REG_DUMP(dx, x) \
210 { int ofst = PHY_DX_BASE + PHY_DX_STRIDE * (dx) + \
211 PHY_DX_## x; \
212 void __iomem *reg = phy_base + ofst; \
Masahiro Yamadab5a83932016-10-27 23:47:09 +0900213 printf("%3d: DX%d%-7s: %08x : %08x\n", \
214 ofst >> PHY_REG_SHIFT, (dx), #x, \
215 ptr_to_uint(reg), readl(reg)); }
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900216
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900217static void reg_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900218{
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900219 void __iomem *phy_base;
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900220 int phy, dx;
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900221
222 printf("\n--- DDR PHY registers ---\n");
223
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900224 for (phy = 0; phy < param->nr_phy; phy++) {
225 phy_base = ioremap(param->phy[phy].base, SZ_4K);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900226
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900227 printf("== PHY%d (base: %08x) ==\n",
228 phy, ptr_to_uint(phy_base));
Masahiro Yamada820353b2016-03-18 16:41:45 +0900229 printf(" No: Name : Address : Data\n");
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900230
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900231 REG_DUMP(RIDR);
232 REG_DUMP(PIR);
233 REG_DUMP(PGCR0);
234 REG_DUMP(PGCR1);
235 REG_DUMP(PGSR0);
236 REG_DUMP(PGSR1);
237 REG_DUMP(PLLCR);
238 REG_DUMP(PTR0);
239 REG_DUMP(PTR1);
240 REG_DUMP(PTR2);
241 REG_DUMP(PTR3);
242 REG_DUMP(PTR4);
243 REG_DUMP(ACMDLR);
244 REG_DUMP(ACBDLR);
245 REG_DUMP(DXCCR);
246 REG_DUMP(DSGCR);
247 REG_DUMP(DCR);
248 REG_DUMP(DTPR0);
249 REG_DUMP(DTPR1);
250 REG_DUMP(DTPR2);
251 REG_DUMP(MR0);
252 REG_DUMP(MR1);
253 REG_DUMP(MR2);
254 REG_DUMP(MR3);
255
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900256 for (dx = 0; dx < param->phy[phy].nr_dx; dx++) {
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900257 DX_REG_DUMP(dx, GCR);
258 DX_REG_DUMP(dx, GTR);
259 }
Masahiro Yamada820353b2016-03-18 16:41:45 +0900260
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900261 iounmap(phy_base);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900262 }
263}
264
Simon Glassed38aef2020-05-10 11:40:03 -0600265static int do_ddr(struct cmd_tbl *cmdtp, int flag, int argc,
266 char *const argv[])
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900267{
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900268 const struct uniphier_ddrphy_param *param;
269 char *cmd;
Masahiro Yamada820353b2016-03-18 16:41:45 +0900270
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900271 param = uniphier_get_ddrphy_param();
272 if (!param) {
Masahiro Yamada609cd532017-10-13 19:21:55 +0900273 pr_err("unsupported SoC\n");
Masahiro Yamada820353b2016-03-18 16:41:45 +0900274 return CMD_RET_FAILURE;
275 }
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900276
277 if (argc == 1)
278 cmd = "all";
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900279 else
280 cmd = argv[1];
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900281
282 if (!strcmp(cmd, "wbdl") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900283 wbdl_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900284
285 if (!strcmp(cmd, "rbdl") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900286 rbdl_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900287
288 if (!strcmp(cmd, "wld") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900289 wld_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900290
291 if (!strcmp(cmd, "dqsgd") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900292 dqsgd_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900293
294 if (!strcmp(cmd, "mdl") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900295 mdl_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900296
297 if (!strcmp(cmd, "reg") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900298 reg_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900299
Masahiro Yamada820353b2016-03-18 16:41:45 +0900300 return CMD_RET_SUCCESS;
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900301}
302
303U_BOOT_CMD(
304 ddr, 2, 1, do_ddr,
305 "UniPhier DDR PHY parameters dumper",
Masahiro Yamada7facf882016-08-21 16:12:36 +0900306 "- dump all of the following\n"
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900307 "ddr wbdl - dump Write Bit Delay\n"
308 "ddr rbdl - dump Read Bit Delay\n"
309 "ddr wld - dump Write Leveling\n"
310 "ddr dqsgd - dump DQS Gating Delay\n"
311 "ddr mdl - dump Master Delay Line\n"
312 "ddr reg - dump registers\n"
313);