blob: a71f704b0c8b0e1f1f0dd15d1ff55b4dfbaa2c4a [file] [log] [blame]
Masahiro Yamada8f899ed2014-12-19 20:20:53 +09001/*
Masahiro Yamadafa1f73f2016-07-19 21:56:13 +09002 * Copyright (C) 2014 Panasonic Corporation
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +09003 * Copyright (C) 2015-2017 Socionext Inc.
Masahiro Yamadafa1f73f2016-07-19 21:56:13 +09004 * Author: Masahiro Yamada <yamada.masahiro@socionext.com>
Masahiro Yamada8f899ed2014-12-19 20:20:53 +09005 *
6 * SPDX-License-Identifier: GPL-2.0+
7 */
8
9#include <common.h>
Masahiro Yamada663a23f2015-05-29 17:30:00 +090010#include <linux/io.h>
Masahiro Yamada820353b2016-03-18 16:41:45 +090011#include <linux/sizes.h>
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090012
Masahiro Yamada820353b2016-03-18 16:41:45 +090013#include "../soc-info.h"
Masahiro Yamadaefdf3402016-01-09 01:51:13 +090014#include "ddrphy-regs.h"
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090015
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 Yamadab5a83932016-10-27 23:47:09 +090025#define ptr_to_uint(p) ((unsigned int)(unsigned long)(p))
26
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090027#define UNIPHIER_MAX_NR_DDRPHY 4
Masahiro Yamada820353b2016-03-18 16:41:45 +090028
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090029struct uniphier_ddrphy_param {
30 unsigned int soc_id;
31 unsigned int nr_phy;
32 struct {
33 resource_size_t base;
34 unsigned int nr_dx;
35 } phy[UNIPHIER_MAX_NR_DDRPHY];
Masahiro Yamada820353b2016-03-18 16:41:45 +090036};
37
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090038static const struct uniphier_ddrphy_param uniphier_ddrphy_param[] = {
39 {
40 .soc_id = UNIPHIER_LD4_ID,
41 .nr_phy = 2,
42 .phy = {
43 { .base = 0x5bc01000, .nr_dx = 2, },
44 { .base = 0x5be01000, .nr_dx = 2, },
45 },
46 },
47 {
48 .soc_id = UNIPHIER_PRO4_ID,
49 .nr_phy = 4,
50 .phy = {
51 { .base = 0x5bc01000, .nr_dx = 2, },
52 { .base = 0x5bc02000, .nr_dx = 2, },
53 { .base = 0x5be01000, .nr_dx = 2, },
54 { .base = 0x5be02000, .nr_dx = 2, },
55 },
56 },
57 {
58 .soc_id = UNIPHIER_SLD8_ID,
59 .nr_phy = 2,
60 .phy = {
61 { .base = 0x5bc01000, .nr_dx = 2, },
62 { .base = 0x5be01000, .nr_dx = 2, },
63 },
64 },
65 {
66 .soc_id = UNIPHIER_LD11_ID,
67 .nr_phy = 1,
68 .phy = {
69 { .base = 0x5bc01000, .nr_dx = 4, },
70 },
71 },
Masahiro Yamada913b3d02016-10-27 23:47:08 +090072};
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090073UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_ddrphy_param, uniphier_ddrphy_param)
Masahiro Yamadab5a83932016-10-27 23:47:09 +090074
Masahiro Yamadab464ff92016-10-27 23:47:07 +090075static void print_bdl(void __iomem *reg, int n)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090076{
Masahiro Yamadab464ff92016-10-27 23:47:07 +090077 u32 val = readl(reg);
78 int i;
79
80 for (i = 0; i < n; i++)
81 printf(FS PRINTF_FORMAT, (val >> i * 6) & 0x3f);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090082}
83
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090084static void dump_loop(const struct uniphier_ddrphy_param *param,
Masahiro Yamadab464ff92016-10-27 23:47:07 +090085 void (*callback)(void __iomem *))
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090086{
Masahiro Yamadab464ff92016-10-27 23:47:07 +090087 void __iomem *phy_base, *dx_base;
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090088 int phy, dx;
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090089
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090090 for (phy = 0; phy < param->nr_phy; phy++) {
91 phy_base = ioremap(param->phy[phy].base, SZ_4K);
Masahiro Yamadab464ff92016-10-27 23:47:07 +090092 dx_base = phy_base + PHY_DX_BASE;
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090093
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +090094 for (dx = 0; dx < param->phy[phy].nr_dx; dx++) {
95 printf("PHY%dDX%d:", phy, dx);
Masahiro Yamadab464ff92016-10-27 23:47:07 +090096 (*callback)(dx_base);
97 dx_base += PHY_DX_STRIDE;
Masahiro Yamada820353b2016-03-18 16:41:45 +090098 printf("\n");
Masahiro Yamada8f899ed2014-12-19 20:20:53 +090099 }
Masahiro Yamada820353b2016-03-18 16:41:45 +0900100
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900101 iounmap(phy_base);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900102 }
103}
104
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900105static void __wbdl_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900106{
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900107 print_bdl(dx_base + PHY_DX_BDLR0, 5);
108 print_bdl(dx_base + PHY_DX_BDLR1, 5);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900109
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900110 printf(FS "(+" PRINTF_FORMAT ")",
111 readl(dx_base + PHY_DX_LCDLR1) & 0xff);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900112}
113
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900114static void wbdl_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900115{
116 printf("\n--- Write Bit Delay Line ---\n");
117 printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM DQS (WDQD)\n");
118
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900119 dump_loop(param, &__wbdl_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900120}
121
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900122static void __rbdl_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900123{
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900124 print_bdl(dx_base + PHY_DX_BDLR3, 5);
125 print_bdl(dx_base + PHY_DX_BDLR4, 4);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900126
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900127 printf(FS "(+" PRINTF_FORMAT ")",
128 (readl(dx_base + PHY_DX_LCDLR1) >> 8) & 0xff);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900129}
130
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900131static void rbdl_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900132{
133 printf("\n--- Read Bit Delay Line ---\n");
134 printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM (RDQSD)\n");
135
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900136 dump_loop(param, &__rbdl_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900137}
138
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900139static void __wld_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900140{
141 int rank;
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900142 u32 lcdlr0 = readl(dx_base + PHY_DX_LCDLR0);
143 u32 gtr = readl(dx_base + PHY_DX_GTR);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900144
145 for (rank = 0; rank < 4; rank++) {
146 u32 wld = (lcdlr0 >> (8 * rank)) & 0xff; /* Delay */
147 u32 wlsl = (gtr >> (12 + 2 * rank)) & 0x3; /* System Latency */
148
149 printf(FS PRINTF_FORMAT "%sT", wld,
150 wlsl == 0 ? "-1" : wlsl == 1 ? "+0" : "+1");
151 }
152}
153
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900154static void wld_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900155{
156 printf("\n--- Write Leveling Delay ---\n");
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900157 printf(" Rank0 Rank1 Rank2 Rank3\n");
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900158
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900159 dump_loop(param, &__wld_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900160}
161
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900162static void __dqsgd_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900163{
164 int rank;
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900165 u32 lcdlr2 = readl(dx_base + PHY_DX_LCDLR2);
166 u32 gtr = readl(dx_base + PHY_DX_GTR);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900167
168 for (rank = 0; rank < 4; rank++) {
169 u32 dqsgd = (lcdlr2 >> (8 * rank)) & 0xff; /* Delay */
170 u32 dgsl = (gtr >> (3 * rank)) & 0x7; /* System Latency */
171
172 printf(FS PRINTF_FORMAT "+%dT", dqsgd, dgsl);
173 }
174}
175
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900176static void dqsgd_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900177{
178 printf("\n--- DQS Gating Delay ---\n");
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900179 printf(" Rank0 Rank1 Rank2 Rank3\n");
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900180
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900181 dump_loop(param, &__dqsgd_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900182}
183
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900184static void __mdl_dump(void __iomem *dx_base)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900185{
186 int i;
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900187 u32 mdl = readl(dx_base + PHY_DX_MDLR);
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900188
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900189 for (i = 0; i < 3; i++)
190 printf(FS PRINTF_FORMAT, (mdl >> (8 * i)) & 0xff);
191}
192
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900193static void mdl_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900194{
195 printf("\n--- Master Delay Line ---\n");
196 printf(" IPRD TPRD MDLD\n");
197
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900198 dump_loop(param, &__mdl_dump);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900199}
200
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900201#define REG_DUMP(x) \
202 { int ofst = PHY_ ## x; void __iomem *reg = phy_base + ofst; \
Masahiro Yamadab5a83932016-10-27 23:47:09 +0900203 printf("%3d: %-10s: %08x : %08x\n", \
204 ofst >> PHY_REG_SHIFT, #x, \
205 ptr_to_uint(reg), readl(reg)); }
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900206
207#define DX_REG_DUMP(dx, x) \
208 { int ofst = PHY_DX_BASE + PHY_DX_STRIDE * (dx) + \
209 PHY_DX_## x; \
210 void __iomem *reg = phy_base + ofst; \
Masahiro Yamadab5a83932016-10-27 23:47:09 +0900211 printf("%3d: DX%d%-7s: %08x : %08x\n", \
212 ofst >> PHY_REG_SHIFT, (dx), #x, \
213 ptr_to_uint(reg), readl(reg)); }
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900214
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900215static void reg_dump(const struct uniphier_ddrphy_param *param)
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900216{
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900217 void __iomem *phy_base;
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900218 int phy, dx;
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900219
220 printf("\n--- DDR PHY registers ---\n");
221
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900222 for (phy = 0; phy < param->nr_phy; phy++) {
223 phy_base = ioremap(param->phy[phy].base, SZ_4K);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900224
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900225 printf("== PHY%d (base: %08x) ==\n",
226 phy, ptr_to_uint(phy_base));
Masahiro Yamada820353b2016-03-18 16:41:45 +0900227 printf(" No: Name : Address : Data\n");
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900228
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900229 REG_DUMP(RIDR);
230 REG_DUMP(PIR);
231 REG_DUMP(PGCR0);
232 REG_DUMP(PGCR1);
233 REG_DUMP(PGSR0);
234 REG_DUMP(PGSR1);
235 REG_DUMP(PLLCR);
236 REG_DUMP(PTR0);
237 REG_DUMP(PTR1);
238 REG_DUMP(PTR2);
239 REG_DUMP(PTR3);
240 REG_DUMP(PTR4);
241 REG_DUMP(ACMDLR);
242 REG_DUMP(ACBDLR);
243 REG_DUMP(DXCCR);
244 REG_DUMP(DSGCR);
245 REG_DUMP(DCR);
246 REG_DUMP(DTPR0);
247 REG_DUMP(DTPR1);
248 REG_DUMP(DTPR2);
249 REG_DUMP(MR0);
250 REG_DUMP(MR1);
251 REG_DUMP(MR2);
252 REG_DUMP(MR3);
253
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900254 for (dx = 0; dx < param->phy[phy].nr_dx; dx++) {
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900255 DX_REG_DUMP(dx, GCR);
256 DX_REG_DUMP(dx, GTR);
257 }
Masahiro Yamada820353b2016-03-18 16:41:45 +0900258
Masahiro Yamadab464ff92016-10-27 23:47:07 +0900259 iounmap(phy_base);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900260 }
261}
262
263static int do_ddr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
264{
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900265 const struct uniphier_ddrphy_param *param;
266 char *cmd;
Masahiro Yamada820353b2016-03-18 16:41:45 +0900267
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900268 param = uniphier_get_ddrphy_param();
269 if (!param) {
Masahiro Yamada820353b2016-03-18 16:41:45 +0900270 printf("unsupported SoC\n");
271 return CMD_RET_FAILURE;
272 }
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900273
274 if (argc == 1)
275 cmd = "all";
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900276 else
277 cmd = argv[1];
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900278
279 if (!strcmp(cmd, "wbdl") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900280 wbdl_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900281
282 if (!strcmp(cmd, "rbdl") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900283 rbdl_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900284
285 if (!strcmp(cmd, "wld") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900286 wld_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900287
288 if (!strcmp(cmd, "dqsgd") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900289 dqsgd_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900290
291 if (!strcmp(cmd, "mdl") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900292 mdl_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900293
294 if (!strcmp(cmd, "reg") || !strcmp(cmd, "all"))
Masahiro Yamada86f0d8c2017-01-28 06:53:45 +0900295 reg_dump(param);
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900296
Masahiro Yamada820353b2016-03-18 16:41:45 +0900297 return CMD_RET_SUCCESS;
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900298}
299
300U_BOOT_CMD(
301 ddr, 2, 1, do_ddr,
302 "UniPhier DDR PHY parameters dumper",
Masahiro Yamada7facf882016-08-21 16:12:36 +0900303 "- dump all of the following\n"
Masahiro Yamada8f899ed2014-12-19 20:20:53 +0900304 "ddr wbdl - dump Write Bit Delay\n"
305 "ddr rbdl - dump Read Bit Delay\n"
306 "ddr wld - dump Write Leveling\n"
307 "ddr dqsgd - dump DQS Gating Delay\n"
308 "ddr mdl - dump Master Delay Line\n"
309 "ddr reg - dump registers\n"
310);