2014-12-19 11:20:53 +00:00
|
|
|
/*
|
2016-07-19 12:56:13 +00:00
|
|
|
* Copyright (C) 2014 Panasonic Corporation
|
2017-01-27 21:53:45 +00:00
|
|
|
* Copyright (C) 2015-2017 Socionext Inc.
|
2016-07-19 12:56:13 +00:00
|
|
|
* Author: Masahiro Yamada <yamada.masahiro@socionext.com>
|
2014-12-19 11:20:53 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
2015-05-29 08:30:00 +00:00
|
|
|
#include <linux/io.h>
|
2016-03-18 07:41:45 +00:00
|
|
|
#include <linux/sizes.h>
|
2016-01-08 16:51:13 +00:00
|
|
|
|
2016-03-18 07:41:45 +00:00
|
|
|
#include "../soc-info.h"
|
2016-01-08 16:51:13 +00:00
|
|
|
#include "ddrphy-regs.h"
|
2014-12-19 11:20:53 +00:00
|
|
|
|
|
|
|
/* Select either decimal or hexadecimal */
|
|
|
|
#if 1
|
|
|
|
#define PRINTF_FORMAT "%2d"
|
|
|
|
#else
|
|
|
|
#define PRINTF_FORMAT "%02x"
|
|
|
|
#endif
|
|
|
|
/* field separator */
|
|
|
|
#define FS " "
|
|
|
|
|
2016-10-27 14:47:09 +00:00
|
|
|
#define ptr_to_uint(p) ((unsigned int)(unsigned long)(p))
|
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
#define UNIPHIER_MAX_NR_DDRPHY 4
|
2016-03-18 07:41:45 +00:00
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
struct uniphier_ddrphy_param {
|
|
|
|
unsigned int soc_id;
|
|
|
|
unsigned int nr_phy;
|
|
|
|
struct {
|
|
|
|
resource_size_t base;
|
|
|
|
unsigned int nr_dx;
|
|
|
|
} phy[UNIPHIER_MAX_NR_DDRPHY];
|
2016-10-27 14:47:08 +00:00
|
|
|
};
|
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
static const struct uniphier_ddrphy_param uniphier_ddrphy_param[] = {
|
|
|
|
{
|
|
|
|
.soc_id = UNIPHIER_LD4_ID,
|
|
|
|
.nr_phy = 2,
|
|
|
|
.phy = {
|
|
|
|
{ .base = 0x5bc01000, .nr_dx = 2, },
|
|
|
|
{ .base = 0x5be01000, .nr_dx = 2, },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.soc_id = UNIPHIER_PRO4_ID,
|
|
|
|
.nr_phy = 4,
|
|
|
|
.phy = {
|
|
|
|
{ .base = 0x5bc01000, .nr_dx = 2, },
|
|
|
|
{ .base = 0x5bc02000, .nr_dx = 2, },
|
|
|
|
{ .base = 0x5be01000, .nr_dx = 2, },
|
|
|
|
{ .base = 0x5be02000, .nr_dx = 2, },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.soc_id = UNIPHIER_SLD8_ID,
|
|
|
|
.nr_phy = 2,
|
|
|
|
.phy = {
|
|
|
|
{ .base = 0x5bc01000, .nr_dx = 2, },
|
|
|
|
{ .base = 0x5be01000, .nr_dx = 2, },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
{
|
|
|
|
.soc_id = UNIPHIER_LD11_ID,
|
|
|
|
.nr_phy = 1,
|
|
|
|
.phy = {
|
|
|
|
{ .base = 0x5bc01000, .nr_dx = 4, },
|
|
|
|
},
|
|
|
|
},
|
2016-10-27 14:47:09 +00:00
|
|
|
};
|
2017-01-27 21:53:45 +00:00
|
|
|
UNIPHIER_DEFINE_SOCDATA_FUNC(uniphier_get_ddrphy_param, uniphier_ddrphy_param)
|
2016-10-27 14:47:09 +00:00
|
|
|
|
2016-10-27 14:47:07 +00:00
|
|
|
static void print_bdl(void __iomem *reg, int n)
|
2014-12-19 11:20:53 +00:00
|
|
|
{
|
2016-10-27 14:47:07 +00:00
|
|
|
u32 val = readl(reg);
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < n; i++)
|
|
|
|
printf(FS PRINTF_FORMAT, (val >> i * 6) & 0x3f);
|
2014-12-19 11:20:53 +00:00
|
|
|
}
|
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
static void dump_loop(const struct uniphier_ddrphy_param *param,
|
2016-10-27 14:47:07 +00:00
|
|
|
void (*callback)(void __iomem *))
|
2014-12-19 11:20:53 +00:00
|
|
|
{
|
2016-10-27 14:47:07 +00:00
|
|
|
void __iomem *phy_base, *dx_base;
|
2017-01-27 21:53:45 +00:00
|
|
|
int phy, dx;
|
2014-12-19 11:20:53 +00:00
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
for (phy = 0; phy < param->nr_phy; phy++) {
|
|
|
|
phy_base = ioremap(param->phy[phy].base, SZ_4K);
|
2016-10-27 14:47:07 +00:00
|
|
|
dx_base = phy_base + PHY_DX_BASE;
|
2014-12-19 11:20:53 +00:00
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
for (dx = 0; dx < param->phy[phy].nr_dx; dx++) {
|
|
|
|
printf("PHY%dDX%d:", phy, dx);
|
2016-10-27 14:47:07 +00:00
|
|
|
(*callback)(dx_base);
|
|
|
|
dx_base += PHY_DX_STRIDE;
|
2016-03-18 07:41:45 +00:00
|
|
|
printf("\n");
|
2014-12-19 11:20:53 +00:00
|
|
|
}
|
2016-03-18 07:41:45 +00:00
|
|
|
|
2016-10-27 14:47:07 +00:00
|
|
|
iounmap(phy_base);
|
2014-12-19 11:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-10-27 14:47:07 +00:00
|
|
|
static void __wbdl_dump(void __iomem *dx_base)
|
2014-12-19 11:20:53 +00:00
|
|
|
{
|
2016-10-27 14:47:07 +00:00
|
|
|
print_bdl(dx_base + PHY_DX_BDLR0, 5);
|
|
|
|
print_bdl(dx_base + PHY_DX_BDLR1, 5);
|
2014-12-19 11:20:53 +00:00
|
|
|
|
2016-10-27 14:47:07 +00:00
|
|
|
printf(FS "(+" PRINTF_FORMAT ")",
|
|
|
|
readl(dx_base + PHY_DX_LCDLR1) & 0xff);
|
2014-12-19 11:20:53 +00:00
|
|
|
}
|
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
static void wbdl_dump(const struct uniphier_ddrphy_param *param)
|
2014-12-19 11:20:53 +00:00
|
|
|
{
|
|
|
|
printf("\n--- Write Bit Delay Line ---\n");
|
|
|
|
printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM DQS (WDQD)\n");
|
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
dump_loop(param, &__wbdl_dump);
|
2014-12-19 11:20:53 +00:00
|
|
|
}
|
|
|
|
|
2016-10-27 14:47:07 +00:00
|
|
|
static void __rbdl_dump(void __iomem *dx_base)
|
2014-12-19 11:20:53 +00:00
|
|
|
{
|
2016-10-27 14:47:07 +00:00
|
|
|
print_bdl(dx_base + PHY_DX_BDLR3, 5);
|
|
|
|
print_bdl(dx_base + PHY_DX_BDLR4, 4);
|
2014-12-19 11:20:53 +00:00
|
|
|
|
2016-10-27 14:47:07 +00:00
|
|
|
printf(FS "(+" PRINTF_FORMAT ")",
|
|
|
|
(readl(dx_base + PHY_DX_LCDLR1) >> 8) & 0xff);
|
2014-12-19 11:20:53 +00:00
|
|
|
}
|
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
static void rbdl_dump(const struct uniphier_ddrphy_param *param)
|
2014-12-19 11:20:53 +00:00
|
|
|
{
|
|
|
|
printf("\n--- Read Bit Delay Line ---\n");
|
|
|
|
printf(" DQ0 DQ1 DQ2 DQ3 DQ4 DQ5 DQ6 DQ7 DM (RDQSD)\n");
|
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
dump_loop(param, &__rbdl_dump);
|
2014-12-19 11:20:53 +00:00
|
|
|
}
|
|
|
|
|
2016-10-27 14:47:07 +00:00
|
|
|
static void __wld_dump(void __iomem *dx_base)
|
2014-12-19 11:20:53 +00:00
|
|
|
{
|
|
|
|
int rank;
|
2016-10-27 14:47:07 +00:00
|
|
|
u32 lcdlr0 = readl(dx_base + PHY_DX_LCDLR0);
|
|
|
|
u32 gtr = readl(dx_base + PHY_DX_GTR);
|
2014-12-19 11:20:53 +00:00
|
|
|
|
|
|
|
for (rank = 0; rank < 4; rank++) {
|
|
|
|
u32 wld = (lcdlr0 >> (8 * rank)) & 0xff; /* Delay */
|
|
|
|
u32 wlsl = (gtr >> (12 + 2 * rank)) & 0x3; /* System Latency */
|
|
|
|
|
|
|
|
printf(FS PRINTF_FORMAT "%sT", wld,
|
|
|
|
wlsl == 0 ? "-1" : wlsl == 1 ? "+0" : "+1");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
static void wld_dump(const struct uniphier_ddrphy_param *param)
|
2014-12-19 11:20:53 +00:00
|
|
|
{
|
|
|
|
printf("\n--- Write Leveling Delay ---\n");
|
2017-01-27 21:53:45 +00:00
|
|
|
printf(" Rank0 Rank1 Rank2 Rank3\n");
|
2014-12-19 11:20:53 +00:00
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
dump_loop(param, &__wld_dump);
|
2014-12-19 11:20:53 +00:00
|
|
|
}
|
|
|
|
|
2016-10-27 14:47:07 +00:00
|
|
|
static void __dqsgd_dump(void __iomem *dx_base)
|
2014-12-19 11:20:53 +00:00
|
|
|
{
|
|
|
|
int rank;
|
2016-10-27 14:47:07 +00:00
|
|
|
u32 lcdlr2 = readl(dx_base + PHY_DX_LCDLR2);
|
|
|
|
u32 gtr = readl(dx_base + PHY_DX_GTR);
|
2014-12-19 11:20:53 +00:00
|
|
|
|
|
|
|
for (rank = 0; rank < 4; rank++) {
|
|
|
|
u32 dqsgd = (lcdlr2 >> (8 * rank)) & 0xff; /* Delay */
|
|
|
|
u32 dgsl = (gtr >> (3 * rank)) & 0x7; /* System Latency */
|
|
|
|
|
|
|
|
printf(FS PRINTF_FORMAT "+%dT", dqsgd, dgsl);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
static void dqsgd_dump(const struct uniphier_ddrphy_param *param)
|
2014-12-19 11:20:53 +00:00
|
|
|
{
|
|
|
|
printf("\n--- DQS Gating Delay ---\n");
|
2017-01-27 21:53:45 +00:00
|
|
|
printf(" Rank0 Rank1 Rank2 Rank3\n");
|
2014-12-19 11:20:53 +00:00
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
dump_loop(param, &__dqsgd_dump);
|
2014-12-19 11:20:53 +00:00
|
|
|
}
|
|
|
|
|
2016-10-27 14:47:07 +00:00
|
|
|
static void __mdl_dump(void __iomem *dx_base)
|
2014-12-19 11:20:53 +00:00
|
|
|
{
|
|
|
|
int i;
|
2016-10-27 14:47:07 +00:00
|
|
|
u32 mdl = readl(dx_base + PHY_DX_MDLR);
|
2017-01-27 21:53:45 +00:00
|
|
|
|
2014-12-19 11:20:53 +00:00
|
|
|
for (i = 0; i < 3; i++)
|
|
|
|
printf(FS PRINTF_FORMAT, (mdl >> (8 * i)) & 0xff);
|
|
|
|
}
|
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
static void mdl_dump(const struct uniphier_ddrphy_param *param)
|
2014-12-19 11:20:53 +00:00
|
|
|
{
|
|
|
|
printf("\n--- Master Delay Line ---\n");
|
|
|
|
printf(" IPRD TPRD MDLD\n");
|
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
dump_loop(param, &__mdl_dump);
|
2014-12-19 11:20:53 +00:00
|
|
|
}
|
|
|
|
|
2016-10-27 14:47:07 +00:00
|
|
|
#define REG_DUMP(x) \
|
|
|
|
{ int ofst = PHY_ ## x; void __iomem *reg = phy_base + ofst; \
|
2016-10-27 14:47:09 +00:00
|
|
|
printf("%3d: %-10s: %08x : %08x\n", \
|
|
|
|
ofst >> PHY_REG_SHIFT, #x, \
|
|
|
|
ptr_to_uint(reg), readl(reg)); }
|
2016-10-27 14:47:07 +00:00
|
|
|
|
|
|
|
#define DX_REG_DUMP(dx, x) \
|
|
|
|
{ int ofst = PHY_DX_BASE + PHY_DX_STRIDE * (dx) + \
|
|
|
|
PHY_DX_## x; \
|
|
|
|
void __iomem *reg = phy_base + ofst; \
|
2016-10-27 14:47:09 +00:00
|
|
|
printf("%3d: DX%d%-7s: %08x : %08x\n", \
|
|
|
|
ofst >> PHY_REG_SHIFT, (dx), #x, \
|
|
|
|
ptr_to_uint(reg), readl(reg)); }
|
2014-12-19 11:20:53 +00:00
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
static void reg_dump(const struct uniphier_ddrphy_param *param)
|
2014-12-19 11:20:53 +00:00
|
|
|
{
|
2016-10-27 14:47:07 +00:00
|
|
|
void __iomem *phy_base;
|
2017-01-27 21:53:45 +00:00
|
|
|
int phy, dx;
|
2014-12-19 11:20:53 +00:00
|
|
|
|
|
|
|
printf("\n--- DDR PHY registers ---\n");
|
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
for (phy = 0; phy < param->nr_phy; phy++) {
|
|
|
|
phy_base = ioremap(param->phy[phy].base, SZ_4K);
|
2016-03-18 07:41:45 +00:00
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
printf("== PHY%d (base: %08x) ==\n",
|
|
|
|
phy, ptr_to_uint(phy_base));
|
2016-03-18 07:41:45 +00:00
|
|
|
printf(" No: Name : Address : Data\n");
|
|
|
|
|
2016-10-27 14:47:07 +00:00
|
|
|
REG_DUMP(RIDR);
|
|
|
|
REG_DUMP(PIR);
|
|
|
|
REG_DUMP(PGCR0);
|
|
|
|
REG_DUMP(PGCR1);
|
|
|
|
REG_DUMP(PGSR0);
|
|
|
|
REG_DUMP(PGSR1);
|
|
|
|
REG_DUMP(PLLCR);
|
|
|
|
REG_DUMP(PTR0);
|
|
|
|
REG_DUMP(PTR1);
|
|
|
|
REG_DUMP(PTR2);
|
|
|
|
REG_DUMP(PTR3);
|
|
|
|
REG_DUMP(PTR4);
|
|
|
|
REG_DUMP(ACMDLR);
|
|
|
|
REG_DUMP(ACBDLR);
|
|
|
|
REG_DUMP(DXCCR);
|
|
|
|
REG_DUMP(DSGCR);
|
|
|
|
REG_DUMP(DCR);
|
|
|
|
REG_DUMP(DTPR0);
|
|
|
|
REG_DUMP(DTPR1);
|
|
|
|
REG_DUMP(DTPR2);
|
|
|
|
REG_DUMP(MR0);
|
|
|
|
REG_DUMP(MR1);
|
|
|
|
REG_DUMP(MR2);
|
|
|
|
REG_DUMP(MR3);
|
|
|
|
|
2017-01-27 21:53:45 +00:00
|
|
|
for (dx = 0; dx < param->phy[phy].nr_dx; dx++) {
|
2016-10-27 14:47:07 +00:00
|
|
|
DX_REG_DUMP(dx, GCR);
|
|
|
|
DX_REG_DUMP(dx, GTR);
|
|
|
|
}
|
|
|
|
|
|
|
|
iounmap(phy_base);
|
2014-12-19 11:20:53 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
static int do_ddr(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[])
|
|
|
|
{
|
2017-01-27 21:53:45 +00:00
|
|
|
const struct uniphier_ddrphy_param *param;
|
|
|
|
char *cmd;
|
|
|
|
|
|
|
|
param = uniphier_get_ddrphy_param();
|
|
|
|
if (!param) {
|
2016-03-18 07:41:45 +00:00
|
|
|
printf("unsupported SoC\n");
|
|
|
|
return CMD_RET_FAILURE;
|
|
|
|
}
|
2014-12-19 11:20:53 +00:00
|
|
|
|
|
|
|
if (argc == 1)
|
|
|
|
cmd = "all";
|
2017-01-27 21:53:45 +00:00
|
|
|
else
|
|
|
|
cmd = argv[1];
|
2014-12-19 11:20:53 +00:00
|
|
|
|
|
|
|
if (!strcmp(cmd, "wbdl") || !strcmp(cmd, "all"))
|
2017-01-27 21:53:45 +00:00
|
|
|
wbdl_dump(param);
|
2014-12-19 11:20:53 +00:00
|
|
|
|
|
|
|
if (!strcmp(cmd, "rbdl") || !strcmp(cmd, "all"))
|
2017-01-27 21:53:45 +00:00
|
|
|
rbdl_dump(param);
|
2014-12-19 11:20:53 +00:00
|
|
|
|
|
|
|
if (!strcmp(cmd, "wld") || !strcmp(cmd, "all"))
|
2017-01-27 21:53:45 +00:00
|
|
|
wld_dump(param);
|
2014-12-19 11:20:53 +00:00
|
|
|
|
|
|
|
if (!strcmp(cmd, "dqsgd") || !strcmp(cmd, "all"))
|
2017-01-27 21:53:45 +00:00
|
|
|
dqsgd_dump(param);
|
2014-12-19 11:20:53 +00:00
|
|
|
|
|
|
|
if (!strcmp(cmd, "mdl") || !strcmp(cmd, "all"))
|
2017-01-27 21:53:45 +00:00
|
|
|
mdl_dump(param);
|
2014-12-19 11:20:53 +00:00
|
|
|
|
|
|
|
if (!strcmp(cmd, "reg") || !strcmp(cmd, "all"))
|
2017-01-27 21:53:45 +00:00
|
|
|
reg_dump(param);
|
2014-12-19 11:20:53 +00:00
|
|
|
|
2016-03-18 07:41:45 +00:00
|
|
|
return CMD_RET_SUCCESS;
|
2014-12-19 11:20:53 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
U_BOOT_CMD(
|
|
|
|
ddr, 2, 1, do_ddr,
|
|
|
|
"UniPhier DDR PHY parameters dumper",
|
2016-08-21 07:12:36 +00:00
|
|
|
"- dump all of the following\n"
|
2014-12-19 11:20:53 +00:00
|
|
|
"ddr wbdl - dump Write Bit Delay\n"
|
|
|
|
"ddr rbdl - dump Read Bit Delay\n"
|
|
|
|
"ddr wld - dump Write Leveling\n"
|
|
|
|
"ddr dqsgd - dump DQS Gating Delay\n"
|
|
|
|
"ddr mdl - dump Master Delay Line\n"
|
|
|
|
"ddr reg - dump registers\n"
|
|
|
|
);
|