Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enable ECC using device tree #15

Open
wants to merge 3 commits into
base: aspeed-master-v2019.04
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions arch/arm/dts/ast2600-rainier.dts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@

&sdrammc {
clock-frequency = <400000000>;
aspeed,ecc-enabled;
};

&wdt2 {
Expand Down
19 changes: 0 additions & 19 deletions drivers/ram/aspeed/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -127,23 +127,4 @@ config ASPEED_DDR4_WR_DATA_EYE_TRAINING_RESULT_OFFSET
are not sure what is the best value in your system.
endif

config ASPEED_ECC
bool "aspeed SDRAM error correcting code"
depends on DM && OF_CONTROL && ARCH_ASPEED
default n
help
enable SDRAM ECC function

if ASPEED_ECC
config ASPEED_ECC_SIZE
int "ECC size: 0=driver auto-caluated"
depends on ASPEED_ECC
default 0
help
SDRAM size with the error correcting code enabled. The unit is
in Megabytes. Noted that only the 8/9 of the configured size
can be used by the system. The remaining 1/9 will be used by
the ECC engine. If the size is set to 0, the sdram driver will
calculate the SDRAM size and set the whole range be ECC enabled.
endif
endif
23 changes: 13 additions & 10 deletions drivers/ram/aspeed/sdram_ast2500.c
Original file line number Diff line number Diff line change
Expand Up @@ -278,17 +278,16 @@ static void ast2500_sdrammc_calc_size(struct dram_info *info)
<< SDRAM_CONF_CAP_SHIFT));
}

#ifdef CONFIG_ASPEED_ECC
static void ast2500_sdrammc_ecc_enable(struct dram_info *info)
static void ast2500_sdrammc_ecc_enable(struct dram_info *info, u32 conf_size_mb)
{
struct ast2500_sdrammc_regs *regs = info->regs;
size_t conf_size;
u32 reg;

conf_size = CONFIG_ASPEED_ECC_SIZE * SDRAM_SIZE_1MB;
conf_size = conf_size_mb * SDRAM_SIZE_1MB;
if (conf_size > info->info.size) {
printf("warning: ECC configured %dMB but actual size is %dMB\n",
CONFIG_ASPEED_ECC_SIZE,
conf_size_mb,
info->info.size / SDRAM_SIZE_1MB);
conf_size = info->info.size;
} else if (conf_size == 0) {
Expand All @@ -313,10 +312,10 @@ static void ast2500_sdrammc_ecc_enable(struct dram_info *info)
writel(0x400, &regs->ecc_test_ctrl);
printf("ECC enable, ");
}
#endif

static int ast2500_sdrammc_init_ddr4(struct dram_info *info)
static int ast2500_sdrammc_init_ddr4(struct udevice *dev)
{
struct dram_info *info = dev_get_priv(dev);
int i;
const u32 power_control = SDRAM_PCR_CKE_EN
| (1 << SDRAM_PCR_CKE_DELAY_SHIFT)
Expand Down Expand Up @@ -370,9 +369,13 @@ static int ast2500_sdrammc_init_ddr4(struct dram_info *info)

writel(SDRAM_MISC_DDR4_TREFRESH, &info->regs->misc_control);

#ifdef CONFIG_ASPEED_ECC
ast2500_sdrammc_ecc_enable(info);
#endif
if (dev_read_bool(dev, "aspeed,ecc-enabled")) {
u32 ecc_size;

ecc_size = dev_read_u32_default(dev, "aspeed,ecc-size-mb", 0);
ast2500_sdrammc_ecc_enable(info, ecc_size);
}

/* Enable all requests except video & display */
writel(SDRAM_REQ_USB20_EHCI1
| SDRAM_REQ_USB20_EHCI2
Expand Down Expand Up @@ -477,7 +480,7 @@ static int ast2500_sdrammc_probe(struct udevice *dev)

ast2500_sdrammc_init_phy(priv->phy);
if (readl(&priv->scu->hwstrap) & SCU_HWSTRAP_DDR4) {
ast2500_sdrammc_init_ddr4(priv);
ast2500_sdrammc_init_ddr4(dev);
} else {
debug("Unsupported DRAM3\n");
return -EINVAL;
Expand Down
19 changes: 11 additions & 8 deletions drivers/ram/aspeed/sdram_ast2600.c
Original file line number Diff line number Diff line change
Expand Up @@ -862,17 +862,17 @@ static void ast2600_sdrammc_update_size(struct dram_info *info)

info->info.size = hw_size;
}
#ifdef CONFIG_ASPEED_ECC
static void ast2600_sdrammc_ecc_enable(struct dram_info *info)

static void ast2600_sdrammc_ecc_enable(struct dram_info *info, u32 conf_size_mb)
{
struct ast2600_sdrammc_regs *regs = info->regs;
size_t conf_size;
u32 reg;

conf_size = CONFIG_ASPEED_ECC_SIZE * SDRAM_SIZE_1MB;
conf_size = conf_size_mb * SDRAM_SIZE_1MB;
if (conf_size > info->info.size) {
printf("warning: ECC configured %dMB but actual size is %dMB\n",
CONFIG_ASPEED_ECC_SIZE,
conf_size_mb,
info->info.size / SDRAM_SIZE_1MB);
conf_size = info->info.size;
} else if (conf_size == 0) {
Expand All @@ -893,7 +893,6 @@ static void ast2600_sdrammc_ecc_enable(struct dram_info *info)
writel(BIT(31), &regs->intr_ctrl);
writel(0, &regs->intr_ctrl);
}
#endif

static int ast2600_sdrammc_probe(struct udevice *dev)
{
Expand Down Expand Up @@ -986,9 +985,13 @@ static int ast2600_sdrammc_probe(struct udevice *dev)
}
#endif

#ifdef CONFIG_ASPEED_ECC
ast2600_sdrammc_ecc_enable(priv);
#endif
if (dev_read_bool(dev, "aspeed,ecc-enabled")) {
u32 ecc_size;

ecc_size = dev_read_u32_default(dev, "aspeed,ecc-size-mb", 0);
ast2600_sdrammc_ecc_enable(priv, ecc_size);
}

setbits_le32(priv->scu + AST_SCU_HANDSHAKE, SCU_HANDSHAKE_MASK);
clrbits_le32(&regs->intr_ctrl, MCR50_RESET_ALL_INTR);
ast2600_sdrammc_lock(priv);
Expand Down