2 * Copyright (C) 2014-2015 Masahiro Yamada <yamada.masahiro@socionext.com>
4 * SPDX-License-Identifier: GPL-2.0+
10 #include "ddrphy-regs.h"
12 /* Select either decimal or hexadecimal */
14 #define PRINTF_FORMAT "%2d"
16 #define PRINTF_FORMAT "%02x"
21 static u32 read_bdl(struct ddrphy_datx8 __iomem *dx, int index)
23 return (readl(&dx->bdlr[index / 5]) >> (index % 5 * 6)) & 0x3f;
26 static void dump_loop(void (*callback)(struct ddrphy_datx8 __iomem *))
29 struct ddrphy __iomem *phy;
31 for (ch = 0; ch < NR_DDRCH; ch++) {
32 for (p = 0; p < NR_DDRPHY_PER_CH; p++) {
33 phy = (struct ddrphy __iomem *)DDRPHY_BASE(ch, p);
35 for (dx = 0; dx < NR_DATX8_PER_DDRPHY; dx++) {
36 printf("CH%dP%dDX%d:", ch, p, dx);
37 (*callback)(&phy->dx[dx]);
44 static void __wbdl_dump(struct ddrphy_datx8 __iomem *dx)
48 for (i = 0; i < 10; i++)
49 printf(FS PRINTF_FORMAT, read_bdl(dx, i));
51 printf(FS "(+" PRINTF_FORMAT ")", readl(&dx->lcdlr[1]) & 0xff);
54 static void wbdl_dump(void)
56 printf("\n--- Write Bit Delay Line ---\n");
57 printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM DQS (WDQD)\n");
59 dump_loop(&__wbdl_dump);
62 static void __rbdl_dump(struct ddrphy_datx8 __iomem *dx)
66 for (i = 15; i < 24; i++)
67 printf(FS PRINTF_FORMAT, read_bdl(dx, i));
69 printf(FS "(+" PRINTF_FORMAT ")", (readl(&dx->lcdlr[1]) >> 8) & 0xff);
72 static void rbdl_dump(void)
74 printf("\n--- Read Bit Delay Line ---\n");
75 printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM (RDQSD)\n");
77 dump_loop(&__rbdl_dump);
80 static void __wld_dump(struct ddrphy_datx8 __iomem *dx)
83 u32 lcdlr0 = readl(&dx->lcdlr[0]);
84 u32 gtr = readl(&dx->gtr);
86 for (rank = 0; rank < 4; rank++) {
87 u32 wld = (lcdlr0 >> (8 * rank)) & 0xff; /* Delay */
88 u32 wlsl = (gtr >> (12 + 2 * rank)) & 0x3; /* System Latency */
90 printf(FS PRINTF_FORMAT "%sT", wld,
91 wlsl == 0 ? "-1" : wlsl == 1 ? "+0" : "+1");
95 static void wld_dump(void)
97 printf("\n--- Write Leveling Delay ---\n");
98 printf(" Rank0 Rank1 Rank2 Rank3\n");
100 dump_loop(&__wld_dump);
103 static void __dqsgd_dump(struct ddrphy_datx8 __iomem *dx)
106 u32 lcdlr2 = readl(&dx->lcdlr[2]);
107 u32 gtr = readl(&dx->gtr);
109 for (rank = 0; rank < 4; rank++) {
110 u32 dqsgd = (lcdlr2 >> (8 * rank)) & 0xff; /* Delay */
111 u32 dgsl = (gtr >> (3 * rank)) & 0x7; /* System Latency */
113 printf(FS PRINTF_FORMAT "+%dT", dqsgd, dgsl);
117 static void dqsgd_dump(void)
119 printf("\n--- DQS Gating Delay ---\n");
120 printf(" Rank0 Rank1 Rank2 Rank3\n");
122 dump_loop(&__dqsgd_dump);
125 static void __mdl_dump(struct ddrphy_datx8 __iomem *dx)
128 u32 mdl = readl(&dx->mdlr);
129 for (i = 0; i < 3; i++)
130 printf(FS PRINTF_FORMAT, (mdl >> (8 * i)) & 0xff);
133 static void mdl_dump(void)
135 printf("\n--- Master Delay Line ---\n");
136 printf(" IPRD TPRD MDLD\n");
138 dump_loop(&__mdl_dump);
141 #define REG_DUMP(x) \
142 { u32 __iomem *p = &phy->x; printf("%3d: %-10s: %p : %08x\n", \
143 p - (u32 *)phy, #x, p, readl(p)); }
145 static void reg_dump(void)
148 struct ddrphy __iomem *phy;
150 printf("\n--- DDR PHY registers ---\n");
152 for (ch = 0; ch < NR_DDRCH; ch++) {
153 for (p = 0; p < NR_DDRPHY_PER_CH; p++) {
154 printf("== Ch%d, PHY%d ==\n", ch, p);
155 printf(" No: Name : Address : Data\n");
157 phy = (struct ddrphy __iomem *)DDRPHY_BASE(ch, p);
191 static int do_ddr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
198 if (!strcmp(cmd, "wbdl") || !strcmp(cmd, "all"))
201 if (!strcmp(cmd, "rbdl") || !strcmp(cmd, "all"))
204 if (!strcmp(cmd, "wld") || !strcmp(cmd, "all"))
207 if (!strcmp(cmd, "dqsgd") || !strcmp(cmd, "all"))
210 if (!strcmp(cmd, "mdl") || !strcmp(cmd, "all"))
213 if (!strcmp(cmd, "reg") || !strcmp(cmd, "all"))
221 "UniPhier DDR PHY parameters dumper",
222 "- dump all of the followings\n"
223 "ddr wbdl - dump Write Bit Delay\n"
224 "ddr rbdl - dump Read Bit Delay\n"
225 "ddr wld - dump Write Leveling\n"
226 "ddr dqsgd - dump DQS Gating Delay\n"
227 "ddr mdl - dump Master Delay Line\n"
228 "ddr reg - dump registers\n"