2013-11-15 03:12:37 +00:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Atmel Corporation
|
|
|
|
* Bo Shen <voice.shen@atmel.com>
|
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: GPL-2.0+
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <common.h>
|
|
|
|
#include <asm/io.h>
|
|
|
|
#include <asm/arch/atmel_mpddrc.h>
|
|
|
|
|
2015-08-13 13:43:18 +00:00
|
|
|
static inline void atmel_mpddr_op(const struct atmel_mpddr *mpddr,
|
|
|
|
int mode,
|
|
|
|
u32 ram_address)
|
2013-11-15 03:12:37 +00:00
|
|
|
{
|
|
|
|
writel(mode, &mpddr->mr);
|
|
|
|
writel(0, ram_address);
|
|
|
|
}
|
|
|
|
|
2014-10-31 07:30:58 +00:00
|
|
|
static int ddr2_decodtype_is_seq(u32 cr)
|
|
|
|
{
|
2015-03-27 06:23:35 +00:00
|
|
|
#if defined(CONFIG_SAMA5D3) || defined(CONFIG_SAMA5D4) || \
|
2015-03-27 06:23:36 +00:00
|
|
|
defined(CONFIG_AT91SAM9X5) || defined(CONFIG_AT91SAM9N12)
|
2014-10-31 07:30:58 +00:00
|
|
|
if (cr & ATMEL_MPDDRC_CR_DECOD_INTERLEAVED)
|
|
|
|
return 0;
|
|
|
|
#endif
|
|
|
|
return 1;
|
|
|
|
}
|
|
|
|
|
2015-08-13 13:43:18 +00:00
|
|
|
|
|
|
|
int ddr2_init(const unsigned int base,
|
|
|
|
const unsigned int ram_address,
|
2013-11-15 03:12:37 +00:00
|
|
|
const struct atmel_mpddr *mpddr_value)
|
|
|
|
{
|
2015-08-13 13:43:18 +00:00
|
|
|
const struct atmel_mpddr *mpddr = (struct atmel_mpddr *)base;
|
|
|
|
|
2013-11-15 03:12:37 +00:00
|
|
|
u32 ba_off, cr;
|
|
|
|
|
|
|
|
/* Compute bank offset according to NC in configuration register */
|
|
|
|
ba_off = (mpddr_value->cr & ATMEL_MPDDRC_CR_NC_MASK) + 9;
|
2014-10-31 07:30:58 +00:00
|
|
|
if (ddr2_decodtype_is_seq(mpddr_value->cr))
|
2014-10-31 07:30:57 +00:00
|
|
|
ba_off += ((mpddr_value->cr & ATMEL_MPDDRC_CR_NR_MASK) >> 2) + 11;
|
2013-11-15 03:12:37 +00:00
|
|
|
|
|
|
|
ba_off += (mpddr_value->md & ATMEL_MPDDRC_MD_DBW_MASK) ? 1 : 2;
|
|
|
|
|
|
|
|
/* Program the memory device type into the memory device register */
|
|
|
|
writel(mpddr_value->md, &mpddr->md);
|
|
|
|
|
|
|
|
/* Program the configuration register */
|
|
|
|
writel(mpddr_value->cr, &mpddr->cr);
|
|
|
|
|
|
|
|
/* Program the timing register */
|
|
|
|
writel(mpddr_value->tpr0, &mpddr->tpr0);
|
|
|
|
writel(mpddr_value->tpr1, &mpddr->tpr1);
|
|
|
|
writel(mpddr_value->tpr2, &mpddr->tpr2);
|
|
|
|
|
|
|
|
/* Issue a NOP command */
|
2015-08-13 13:43:18 +00:00
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_NOP_CMD, ram_address);
|
2013-11-15 03:12:37 +00:00
|
|
|
|
|
|
|
/* A 200 us is provided to precede any signal toggle */
|
|
|
|
udelay(200);
|
|
|
|
|
|
|
|
/* Issue a NOP command */
|
2015-08-13 13:43:18 +00:00
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_NOP_CMD, ram_address);
|
2013-11-15 03:12:37 +00:00
|
|
|
|
|
|
|
/* Issue an all banks precharge command */
|
2015-08-13 13:43:18 +00:00
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_PRCGALL_CMD, ram_address);
|
2013-11-15 03:12:37 +00:00
|
|
|
|
|
|
|
/* Issue an extended mode register set(EMRS2) to choose operation */
|
2015-08-13 13:43:18 +00:00
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_EXT_LMR_CMD,
|
2013-11-15 03:12:37 +00:00
|
|
|
ram_address + (0x2 << ba_off));
|
|
|
|
|
|
|
|
/* Issue an extended mode register set(EMRS3) to set EMSR to 0 */
|
2015-08-13 13:43:18 +00:00
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_EXT_LMR_CMD,
|
2013-11-15 03:12:37 +00:00
|
|
|
ram_address + (0x3 << ba_off));
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Issue an extended mode register set(EMRS1) to enable DLL and
|
|
|
|
* program D.I.C (output driver impedance control)
|
|
|
|
*/
|
2015-08-13 13:43:18 +00:00
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_EXT_LMR_CMD,
|
2013-11-15 03:12:37 +00:00
|
|
|
ram_address + (0x1 << ba_off));
|
|
|
|
|
|
|
|
/* Enable DLL reset */
|
|
|
|
cr = readl(&mpddr->cr);
|
|
|
|
writel(cr | ATMEL_MPDDRC_CR_DLL_RESET_ENABLED, &mpddr->cr);
|
|
|
|
|
|
|
|
/* A mode register set(MRS) cycle is issued to reset DLL */
|
2015-08-13 13:43:18 +00:00
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_LMR_CMD, ram_address);
|
2013-11-15 03:12:37 +00:00
|
|
|
|
|
|
|
/* Issue an all banks precharge command */
|
2015-08-13 13:43:18 +00:00
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_PRCGALL_CMD, ram_address);
|
2013-11-15 03:12:37 +00:00
|
|
|
|
|
|
|
/* Two auto-refresh (CBR) cycles are provided */
|
2015-08-13 13:43:18 +00:00
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_RFSH_CMD, ram_address);
|
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_RFSH_CMD, ram_address);
|
2013-11-15 03:12:37 +00:00
|
|
|
|
|
|
|
/* Disable DLL reset */
|
|
|
|
cr = readl(&mpddr->cr);
|
|
|
|
writel(cr & (~ATMEL_MPDDRC_CR_DLL_RESET_ENABLED), &mpddr->cr);
|
|
|
|
|
|
|
|
/* A mode register set (MRS) cycle is issued to disable DLL reset */
|
2015-08-13 13:43:18 +00:00
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_LMR_CMD, ram_address);
|
2013-11-15 03:12:37 +00:00
|
|
|
|
|
|
|
/* Set OCD calibration in default state */
|
|
|
|
cr = readl(&mpddr->cr);
|
|
|
|
writel(cr | ATMEL_MPDDRC_CR_OCD_DEFAULT, &mpddr->cr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An extended mode register set (EMRS1) cycle is issued
|
|
|
|
* to OCD default value
|
|
|
|
*/
|
2015-08-13 13:43:18 +00:00
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_EXT_LMR_CMD,
|
2013-11-15 03:12:37 +00:00
|
|
|
ram_address + (0x1 << ba_off));
|
|
|
|
|
|
|
|
/* OCD calibration mode exit */
|
|
|
|
cr = readl(&mpddr->cr);
|
|
|
|
writel(cr & (~ATMEL_MPDDRC_CR_OCD_DEFAULT), &mpddr->cr);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* An extended mode register set (EMRS1) cycle is issued
|
|
|
|
* to enable OCD exit
|
|
|
|
*/
|
2015-08-13 13:43:18 +00:00
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_EXT_LMR_CMD,
|
2013-11-15 03:12:37 +00:00
|
|
|
ram_address + (0x1 << ba_off));
|
|
|
|
|
|
|
|
/* A nornal mode command is provided */
|
2015-08-13 13:43:18 +00:00
|
|
|
atmel_mpddr_op(mpddr, ATMEL_MPDDRC_MR_MODE_NORMAL_CMD, ram_address);
|
2013-11-15 03:12:37 +00:00
|
|
|
|
|
|
|
/* Perform a write access to any DDR2-SDRAM address */
|
|
|
|
writel(0, ram_address);
|
|
|
|
|
|
|
|
/* Write the refresh rate */
|
|
|
|
writel(mpddr_value->rtr, &mpddr->rtr);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|