diff mbox

[U-Boot,5/7] powerpc/mpc83xx: Migrate from spd_sdram to unified DDR driver

Message ID 1312923045-2612-5-git-send-email-yorksun@freescale.com
State Accepted
Commit d29d17d7badcf90a31e5d6d1d9a82838ea039a42
Headers show

Commit Message

York Sun Aug. 9, 2011, 8:50 p.m. UTC
Unified DDR driver is maintained for better performance, robustness and bug
fixes. Upgrading to use unified DDR driver for MPC83xx takes advantage of
overall improvement. It requires changes for board files to customize
platform-dependent parameters.

To utilize the unified DDR driver, a board needs to define CONFIG_FSL_DDRx
in the header file. No more boards will be accepted without such definition.

Note: the workaround for erratum DDR6 for the very old MPC834x Rev 1.0/1.1
and MPC8360 Rev 1.1/1.2 parts is not migrated to unified driver.

Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
Signed-off-by: York Sun <yorksun@freescale.com>
---
 Makefile                                 |    1 +
 arch/powerpc/cpu/mpc83xx/Makefile        |   20 +++++-
 arch/powerpc/cpu/mpc83xx/ecc.c           |   18 ++++--
 arch/powerpc/cpu/mpc83xx/law.c           |   61 ++++++++++++++++
 arch/powerpc/cpu/mpc83xx/speed.c         |    9 +++
 arch/powerpc/cpu/mpc85xx/ddr-gen2.c      |    8 ++-
 arch/powerpc/cpu/mpc8xxx/ddr/ctrl_regs.c |    4 +-
 arch/powerpc/cpu/mpc8xxx/ddr/util.c      |    9 ++-
 arch/powerpc/include/asm/config.h        |    5 +-
 arch/powerpc/include/asm/immap_83xx.h    |  117 +++++++++++++++++++++++++++++-
 common/Makefile                          |    8 ++-
 include/common.h                         |    4 +-
 12 files changed, 245 insertions(+), 19 deletions(-)
 create mode 100644 arch/powerpc/cpu/mpc83xx/law.c

Comments

Wolfgang Denk Aug. 24, 2011, 10:36 p.m. UTC | #1
Dear York Sun,

In message <1312923045-2612-5-git-send-email-yorksun@freescale.com> you wrote:
> Unified DDR driver is maintained for better performance, robustness and bug
> fixes. Upgrading to use unified DDR driver for MPC83xx takes advantage of
> overall improvement. It requires changes for board files to customize
> platform-dependent parameters.
> 
> To utilize the unified DDR driver, a board needs to define CONFIG_FSL_DDRx
> in the header file. No more boards will be accepted without such definition.
> 
> Note: the workaround for erratum DDR6 for the very old MPC834x Rev 1.0/1.1
> and MPC8360 Rev 1.1/1.2 parts is not migrated to unified driver.
> 
> Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
> Signed-off-by: York Sun <yorksun@freescale.com>

Checkpatch says:

WARNING: do not add new typedefs
#408: FILE: arch/powerpc/include/asm/immap_83xx.h:289:
+typedef struct ccsr_ddr {

Please fix.

Best regards,

Wolfgang Denk
York Sun Aug. 25, 2011, 8:57 p.m. UTC | #2
Wolfgang,

On Thu, 2011-08-25 at 00:36 +0200, Wolfgang Denk wrote:
> Dear York Sun,
> 
> In message <1312923045-2612-5-git-send-email-yorksun@freescale.com> you wrote:
> > Unified DDR driver is maintained for better performance, robustness and bug
> > fixes. Upgrading to use unified DDR driver for MPC83xx takes advantage of
> > overall improvement. It requires changes for board files to customize
> > platform-dependent parameters.
> > 
> > To utilize the unified DDR driver, a board needs to define CONFIG_FSL_DDRx
> > in the header file. No more boards will be accepted without such definition.
> > 
> > Note: the workaround for erratum DDR6 for the very old MPC834x Rev 1.0/1.1
> > and MPC8360 Rev 1.1/1.2 parts is not migrated to unified driver.
> > 
> > Signed-off-by: Kim Phillips <kim.phillips@freescale.com>
> > Signed-off-by: York Sun <yorksun@freescale.com>
> 
> Checkpatch says:
> 
> WARNING: do not add new typedefs
> #408: FILE: arch/powerpc/include/asm/immap_83xx.h:289:
> +typedef struct ccsr_ddr {
> 
> Please fix.
> 

I can fix the new tyepdef. But this one isn't. It has been used for a
long time by 85xx. I am trying to unified the code. It is inevitable to
define the same typedef for 83xx.

Regards,

York
Wolfgang Denk Aug. 25, 2011, 9:20 p.m. UTC | #3
Dear York Sun,

In message <1314305821.29220.21.camel@oslab-l1> you wrote:
> 
> > WARNING: do not add new typedefs
> > #408: FILE: arch/powerpc/include/asm/immap_83xx.h:289:
> > +typedef struct ccsr_ddr {
> > 
> > Please fix.
> 
> I can fix the new tyepdef. But this one isn't. It has been used for a
> long time by 85xx. I am trying to unified the code. It is inevitable to
> define the same typedef for 83xx.

Is it?  I don't think so.  You can, for example, fix the 85xx code as
well...

Best regards,

Wolfgang Denk
York Sun Aug. 25, 2011, 9:25 p.m. UTC | #4
On Thu, 2011-08-25 at 23:20 +0200, Wolfgang Denk wrote:
> Dear York Sun,
> 
> In message <1314305821.29220.21.camel@oslab-l1> you wrote:
> > 
> > > WARNING: do not add new typedefs
> > > #408: FILE: arch/powerpc/include/asm/immap_83xx.h:289:
> > > +typedef struct ccsr_ddr {
> > > 
> > > Please fix.
> > 
> > I can fix the new tyepdef. But this one isn't. It has been used for a
> > long time by 85xx. I am trying to unified the code. It is inevitable to
> > define the same typedef for 83xx.
> 
> Is it?  I don't think so.  You can, for example, fix the 85xx code as
> well...

Fixing all existing reference to ccs_ddr is a lot of work, comparing
with defining it for 83xx. There are many other typedefs in the very
same files. Would we fix all of them? I don't think so. The bottom of
line is ccsr_ddr is not a new typedef.

York
Wolfgang Denk Aug. 25, 2011, 9:30 p.m. UTC | #5
Dear York Sun,

In message <1314307500.29220.24.camel@oslab-l1> you wrote:
>
> Fixing all existing reference to ccs_ddr is a lot of work, comparing
> with defining it for 83xx. There are many other typedefs in the very
> same files. Would we fix all of them? I don't think so. The bottom of

well, if you could fix all of these while you are at it that would be
just great :-)

> line is ccsr_ddr is not a new typedef.

But you are adding it new to this file.

Best regards,

Wolfgang Denk
York Sun Aug. 25, 2011, 9:36 p.m. UTC | #6
Wolfgang,

On Thu, 2011-08-25 at 23:30 +0200, Wolfgang Denk wrote:
> Dear York Sun,
> 
> In message <1314307500.29220.24.camel@oslab-l1> you wrote:
> >
> > Fixing all existing reference to ccs_ddr is a lot of work, comparing
> > with defining it for 83xx. There are many other typedefs in the very
> > same files. Would we fix all of them? I don't think so. The bottom of
> 
> well, if you could fix all of these while you are at it that would be
> just great :-)

There are nearly 400 typedefs for powerpc and 52 for immap_85xx.h, not
mentioned when they are used by .c files. Too many to fix.

> 
> > line is ccsr_ddr is not a new typedef.
> 
> But you are adding it new to this file.

I am introducing it to this file as it is already being used somewhere
else. If you are trying to enforce this new policy, please start with
brand new files/typedefs, as you pointed out in my another patch. I will
be happy to fix that.

York
Wolfgang Denk Aug. 25, 2011, 10:31 p.m. UTC | #7
Dear York Sun,

In message <1314308192.29220.29.camel@oslab-l1> you wrote:
> 
> I am introducing it to this file as it is already being used somewhere
> else. If you are trying to enforce this new policy, please start with
> brand new files/typedefs, as you pointed out in my another patch. I will
> be happy to fix that.

It is in no way a new policy that U-Boot uses the Linux CodingStyle as
model.  We've been doing this for years.  It's just that checkpatch
allows for more regular and more strict tests for violations.

Best regards,

Wolfgang Denk
York Sun Aug. 26, 2011, 5 p.m. UTC | #8
Wolfgang,

On Fri, 2011-08-26 at 00:31 +0200, Wolfgang Denk wrote:
> Dear York Sun,
> 
> In message <1314308192.29220.29.camel@oslab-l1> you wrote:
> > 
> > I am introducing it to this file as it is already being used somewhere
> > else. If you are trying to enforce this new policy, please start with
> > brand new files/typedefs, as you pointed out in my another patch. I will
> > be happy to fix that.
> 
> It is in no way a new policy that U-Boot uses the Linux CodingStyle as
> model.  We've been doing this for years.  It's just that checkpatch
> allows for more regular and more strict tests for violations.
> 

I am going to follow the style and not to add new typedefs. For the
existing typedef, I will keep using them. In this case, it is an
existing typedef, just for another platform. Fixing it alone will cause
more troubles.

York
Wolfgang Denk Aug. 26, 2011, 6:12 p.m. UTC | #9
Dear York Sun,

In message <1314378058.20734.25.camel@oslab-l1> you wrote:
> 
> I am going to follow the style and not to add new typedefs. For the
> existing typedef, I will keep using them. In this case, it is an
> existing typedef, just for another platform. Fixing it alone will cause
> more troubles.

I understand why you would prefer such an interpretation...  But the
fact is, you are adding new code that contains typedef's (and it does
not matter at all if other code in other places does the same or not).


Please don't misunderstand me - I can accept if you prefer not to fix
this problem now, but rather address it later, in a separate patch.
But it is technically wrong to claim you were not adding new
typedef's.   Checkpatch complains not without reason.

Best regards,

Wolfgang Denk
York Sun Aug. 26, 2011, 6:15 p.m. UTC | #10
On Fri, 2011-08-26 at 20:12 +0200, Wolfgang Denk wrote:
> Dear York Sun,
> 
> In message <1314378058.20734.25.camel@oslab-l1> you wrote:
> > 
> > I am going to follow the style and not to add new typedefs. For the
> > existing typedef, I will keep using them. In this case, it is an
> > existing typedef, just for another platform. Fixing it alone will cause
> > more troubles.
> 
> I understand why you would prefer such an interpretation...  But the
> fact is, you are adding new code that contains typedef's (and it does
> not matter at all if other code in other places does the same or not).
> 
> 
> Please don't misunderstand me - I can accept if you prefer not to fix
> this problem now, but rather address it later, in a separate patch.
> But it is technically wrong to claim you were not adding new
> typedef's.   Checkpatch complains not without reason.
> 

OK. I do prefer not to fix it now if you can accept it. Are you implying
we should fix all the existing typedefs? That will be a lot of cleanup.

York
diff mbox

Patch

diff --git a/Makefile b/Makefile
index 689fddb..16f015e 100644
--- a/Makefile
+++ b/Makefile
@@ -252,6 +252,7 @@  LIBS += drivers/power/libpower.o
 LIBS += drivers/spi/libspi.o
 ifeq ($(CPU),mpc83xx)
 LIBS += drivers/qe/libqe.o
+LIBS += arch/powerpc/cpu/mpc8xxx/ddr/libddr.o
 LIBS += arch/powerpc/cpu/mpc8xxx/lib8xxx.o
 endif
 ifeq ($(CPU),mpc85xx)
diff --git a/arch/powerpc/cpu/mpc83xx/Makefile b/arch/powerpc/cpu/mpc83xx/Makefile
index 3979b6f..b353036 100644
--- a/arch/powerpc/cpu/mpc83xx/Makefile
+++ b/arch/powerpc/cpu/mpc83xx/Makefile
@@ -34,7 +34,6 @@  COBJS-y += cpu.o
 COBJS-y += cpu_init.o
 COBJS-y += speed.o
 COBJS-y += interrupts.o
-COBJS-y += spd_sdram.o
 COBJS-y += ecc.o
 COBJS-$(CONFIG_QE) += qe_io.o
 COBJS-$(CONFIG_FSL_SERDES) += serdes.o
@@ -42,6 +41,13 @@  COBJS-$(CONFIG_PCI) += pci.o
 COBJS-$(CONFIG_PCIE) += pcie.o
 COBJS-$(CONFIG_OF_LIBFDT) += fdt.o
 
+ifdef CONFIG_FSL_DDR2
+COBJS-$(CONFIG_MPC8349) += ddr-gen2.o
+else
+COBJS-y += spd_sdram.o
+endif
+COBJS-$(CONFIG_FSL_DDR2) += law.o
+
 COBJS	:= $(COBJS-y)
 SRCS	:= $(START:.o=.S) $(SOBJS:.o=.S) $(COBJS:.o=.c)
 OBJS	:= $(addprefix $(obj),$(SOBJS) $(COBJS))
@@ -52,6 +58,18 @@  all:	$(obj).depend $(START) $(LIB)
 $(LIB):	$(OBJS)
 	$(call cmd_link_o_target, $(OBJS))
 
+$(obj)ddr-gen1.c:
+	@rm -f $(obj)ddr-gen1.c
+	ln -sf $(SRCTREE)/arch/powerpc/cpu/mpc85xx/ddr-gen1.c $(obj)ddr-gen1.c
+
+$(obj)ddr-gen2.c:
+	@rm -f $(obj)ddr-gen2.c
+	ln -sf $(SRCTREE)/arch/powerpc/cpu/mpc85xx/ddr-gen2.c $(obj)ddr-gen2.c
+
+$(obj)ddr-gen3.c:
+	@rm -f $(obj)ddr-gen3.c
+	ln -sf $(SRCTREE)/arch/powerpc/cpu/mpc85xx/ddr-gen3.c $(obj)ddr-gen3.c
+
 #########################################################################
 
 # defines $(obj).depend target
diff --git a/arch/powerpc/cpu/mpc83xx/ecc.c b/arch/powerpc/cpu/mpc83xx/ecc.c
index f8eab96..717365c 100644
--- a/arch/powerpc/cpu/mpc83xx/ecc.c
+++ b/arch/powerpc/cpu/mpc83xx/ecc.c
@@ -1,5 +1,5 @@ 
 /*
- * Copyright (C) 2007 Freescale Semiconductor, Inc.
+ * Copyright (C) 2007-2011 Freescale Semiconductor, Inc.
  *
  * Dave Liu <daveliu@freescale.com>
  * based on the contribution of Marian Balakowicz <m8@semihalf.com>
@@ -20,8 +20,12 @@ 
 #if defined(CONFIG_DDR_ECC) && defined(CONFIG_DDR_ECC_CMD)
 void ecc_print_status(void)
 {
-	volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
-	volatile ddr83xx_t *ddr = &immap->ddr;
+	immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
+#ifdef CONFIG_FSL_DDR2
+	ccsr_ddr_t *ddr = &immap->ddr;
+#else
+	ddr83xx_t *ddr = &immap->ddr;
+#endif
 
 	printf("\nECC mode: %s\n\n",
 	       (ddr->sdram_cfg & SDRAM_CFG_ECC_EN) ? "ON" : "OFF");
@@ -100,8 +104,12 @@  void ecc_print_status(void)
 
 int do_ecc(cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 {
-	volatile immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
-	volatile ddr83xx_t *ddr = &immap->ddr;
+	immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
+#ifdef CONFIG_FSL_DDR2
+	ccsr_ddr_t *ddr = &immap->ddr;
+#else
+	ddr83xx_t *ddr = &immap->ddr;
+#endif
 	volatile u32 val;
 	u64 *addr;
 	u32 count;
diff --git a/arch/powerpc/cpu/mpc83xx/law.c b/arch/powerpc/cpu/mpc83xx/law.c
new file mode 100644
index 0000000..66c88b6
--- /dev/null
+++ b/arch/powerpc/cpu/mpc83xx/law.c
@@ -0,0 +1,61 @@ 
+/*
+ * Copyright 2011 Freescale Semiconductor, Inc.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * Version 2 as published by the Free Software Foundation.
+ */
+
+#include <common.h>
+#include <asm/fsl_law.h>
+#include <asm/mmu.h>
+
+int set_ddr_laws(u64 start, u64 sz, enum law_trgt_if id)
+{
+	immap_t *immap = (immap_t *)CONFIG_SYS_IMMR;
+	law83xx_t *ecm = &immap->sysconf.ddrlaw[0];
+	u64 start_align, law_sz;
+	int law_sz_enc;
+
+	if (start == 0)
+		start_align = 1ull << (LAW_SIZE_2G + 1);
+	else
+		start_align = 1ull << (ffs64(start) - 1);
+	law_sz = min(start_align, sz);
+	law_sz_enc = __ilog2_u64(law_sz) - 1;
+
+	/*
+	 * Set up LAWBAR for all of DDR.
+	 */
+	ecm->bar = start & 0xfffff000;
+	ecm->ar  = (LAWAR_EN | (id << 20) | (LAWAR_SIZE & law_sz_enc));
+	debug("DDR:bar=0x%08x\n", ecm->bar);
+	debug("DDR:ar=0x%08x\n", ecm->ar);
+
+	/* recalculate size based on what was actually covered by the law */
+	law_sz = 1ull << __ilog2_u64(law_sz);
+
+	/* do we still have anything to map */
+	sz = sz - law_sz;
+	if (sz) {
+		start += law_sz;
+
+		start_align = 1ull << (ffs64(start) - 1);
+		law_sz = min(start_align, sz);
+		law_sz_enc = __ilog2_u64(law_sz) - 1;
+		ecm = &immap->sysconf.ddrlaw[1];
+		ecm->bar = start & 0xfffff000;
+		ecm->ar  = (LAWAR_EN | (id << 20) | (LAWAR_SIZE & law_sz_enc));
+		debug("DDR:bar=0x%08x\n", ecm->bar);
+		debug("DDR:ar=0x%08x\n", ecm->ar);
+	} else {
+		return 0;
+	}
+
+	/* do we still have anything to map */
+	sz = sz - law_sz;
+	if (sz)
+		return 1;
+
+	return 0;
+}
diff --git a/arch/powerpc/cpu/mpc83xx/speed.c b/arch/powerpc/cpu/mpc83xx/speed.c
index 5e616dd..82d2ae5 100644
--- a/arch/powerpc/cpu/mpc83xx/speed.c
+++ b/arch/powerpc/cpu/mpc83xx/speed.c
@@ -504,6 +504,15 @@  ulong get_bus_freq(ulong dummy)
 	return gd->csb_clk;
 }
 
+/********************************************
+ * get_ddr_freq
+ * return ddr bus freq in Hz
+ *********************************************/
+ulong get_ddr_freq(ulong dummy)
+{
+	return gd->mem_clk;
+}
+
 int do_clocks (cmd_tbl_t * cmdtp, int flag, int argc, char * const argv[])
 {
 	char buf[32];
diff --git a/arch/powerpc/cpu/mpc85xx/ddr-gen2.c b/arch/powerpc/cpu/mpc85xx/ddr-gen2.c
index 655f99c..10f3685 100644
--- a/arch/powerpc/cpu/mpc85xx/ddr-gen2.c
+++ b/arch/powerpc/cpu/mpc85xx/ddr-gen2.c
@@ -1,5 +1,5 @@ 
 /*
- * Copyright 2008 Freescale Semiconductor, Inc.
+ * Copyright 2008-2011 Freescale Semiconductor, Inc.
  *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
@@ -18,7 +18,11 @@  void fsl_ddr_set_memctl_regs(const fsl_ddr_cfg_regs_t *regs,
 			     unsigned int ctrl_num)
 {
 	unsigned int i;
-	volatile ccsr_ddr_t *ddr = (void *)CONFIG_SYS_MPC85xx_DDR_ADDR;
+#ifdef CONFIG_MPC83xx
+	ccsr_ddr_t *ddr = (void *)CONFIG_SYS_MPC83xx_DDR_ADDR;
+#else
+	ccsr_ddr_t *ddr = (void *)CONFIG_SYS_MPC85xx_DDR_ADDR;
+#endif
 
 	if (ctrl_num) {
 		printf("%s unexpected ctrl_num = %u\n", __FUNCTION__, ctrl_num);
diff --git a/arch/powerpc/cpu/mpc8xxx/ddr/ctrl_regs.c b/arch/powerpc/cpu/mpc8xxx/ddr/ctrl_regs.c
index eb8d8e3..391eb25 100644
--- a/arch/powerpc/cpu/mpc8xxx/ddr/ctrl_regs.c
+++ b/arch/powerpc/cpu/mpc8xxx/ddr/ctrl_regs.c
@@ -18,7 +18,9 @@ 
 
 #include "ddr.h"
 
-#ifdef CONFIG_MPC85xx
+#ifdef CONFIG_MPC83xx
+	#define _DDR_ADDR CONFIG_SYS_MPC83xx_DDR_ADDR
+#elif defined(CONFIG_MPC85xx)
 	#define _DDR_ADDR CONFIG_SYS_MPC85xx_DDR_ADDR
 #elif defined(CONFIG_MPC86xx)
 	#define _DDR_ADDR CONFIG_SYS_MPC86xx_DDR_ADDR
diff --git a/arch/powerpc/cpu/mpc8xxx/ddr/util.c b/arch/powerpc/cpu/mpc8xxx/ddr/util.c
index c644131..eb6a17a 100644
--- a/arch/powerpc/cpu/mpc8xxx/ddr/util.c
+++ b/arch/powerpc/cpu/mpc8xxx/ddr/util.c
@@ -129,10 +129,13 @@  fsl_ddr_set_lawbar(const common_timing_params_t *memctl_common_params,
 
 void board_add_ram_info(int use_default)
 {
-#if defined(CONFIG_MPC85xx)
-	volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
+#if defined(CONFIG_MPC83xx)
+	immap_t *immap = (immap_t *) CONFIG_SYS_IMMR;
+	ccsr_ddr_t *ddr = (void *)&immap->ddr;
+#elif defined(CONFIG_MPC85xx)
+	ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC85xx_DDR_ADDR);
 #elif defined(CONFIG_MPC86xx)
-	volatile ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC86xx_DDR_ADDR);
+	ccsr_ddr_t *ddr = (void *)(CONFIG_SYS_MPC86xx_DDR_ADDR);
 #endif
 #if (CONFIG_NUM_DDR_CONTROLLERS > 1)
 	uint32_t cs0_config = in_be32(&ddr->cs0_config);
diff --git a/arch/powerpc/include/asm/config.h b/arch/powerpc/include/asm/config.h
index c5e5c9c..d138636 100644
--- a/arch/powerpc/include/asm/config.h
+++ b/arch/powerpc/include/asm/config.h
@@ -42,7 +42,10 @@ 
 #define CONFIG_SYS_BOOT_GET_KBD
 
 #ifndef CONFIG_MAX_MEM_MAPPED
-#if defined(CONFIG_4xx) || defined(CONFIG_E500) || defined(CONFIG_MPC86xx)
+#if	defined(CONFIG_4xx)		|| \
+	defined(CONFIG_E500)		|| \
+	defined(CONFIG_MPC86xx)		|| \
+	defined(CONFIG_E300)
 #define CONFIG_MAX_MEM_MAPPED	((phys_size_t)2 << 30)
 #else
 #define CONFIG_MAX_MEM_MAPPED	(256 << 20)
diff --git a/arch/powerpc/include/asm/immap_83xx.h b/arch/powerpc/include/asm/immap_83xx.h
index cc0293a..8d4c9cb 100644
--- a/arch/powerpc/include/asm/immap_83xx.h
+++ b/arch/powerpc/include/asm/immap_83xx.h
@@ -1,5 +1,5 @@ 
 /*
- * Copyright 2004-2009 Freescale Semiconductor, Inc.
+ * Copyright 2004-2011 Freescale Semiconductor, Inc.
  *
  * MPC83xx Internal Memory Map
  *
@@ -285,6 +285,105 @@  typedef struct qesba83xx {
 /*
  * DDR Memory Controller Memory Map
  */
+#if defined(CONFIG_FSL_DDR2) || defined(CONFIG_FSL_DDR3)
+typedef struct ccsr_ddr {
+	u32	cs0_bnds;		/* Chip Select 0 Memory Bounds */
+	u8	res1[4];
+	u32	cs1_bnds;		/* Chip Select 1 Memory Bounds */
+	u8	res2[4];
+	u32	cs2_bnds;		/* Chip Select 2 Memory Bounds */
+	u8	res3[4];
+	u32	cs3_bnds;		/* Chip Select 3 Memory Bounds */
+	u8	res4[100];
+	u32	cs0_config;		/* Chip Select Configuration */
+	u32	cs1_config;		/* Chip Select Configuration */
+	u32	cs2_config;		/* Chip Select Configuration */
+	u32	cs3_config;		/* Chip Select Configuration */
+	u8	res4a[48];
+	u32	cs0_config_2;		/* Chip Select Configuration 2 */
+	u32	cs1_config_2;		/* Chip Select Configuration 2 */
+	u32	cs2_config_2;		/* Chip Select Configuration 2 */
+	u32	cs3_config_2;		/* Chip Select Configuration 2 */
+	u8	res5[48];
+	u32	timing_cfg_3;		/* SDRAM Timing Configuration 3 */
+	u32	timing_cfg_0;		/* SDRAM Timing Configuration 0 */
+	u32	timing_cfg_1;		/* SDRAM Timing Configuration 1 */
+	u32	timing_cfg_2;		/* SDRAM Timing Configuration 2 */
+	u32	sdram_cfg;		/* SDRAM Control Configuration */
+	u32	sdram_cfg_2;		/* SDRAM Control Configuration 2 */
+	u32	sdram_mode;		/* SDRAM Mode Configuration */
+	u32	sdram_mode_2;		/* SDRAM Mode Configuration 2 */
+	u32	sdram_md_cntl;		/* SDRAM Mode Control */
+	u32	sdram_interval;		/* SDRAM Interval Configuration */
+	u32	sdram_data_init;	/* SDRAM Data initialization */
+	u8	res6[4];
+	u32	sdram_clk_cntl;		/* SDRAM Clock Control */
+	u8	res7[20];
+	u32	init_addr;		/* training init addr */
+	u32	init_ext_addr;		/* training init extended addr */
+	u8	res8_1[16];
+	u32	timing_cfg_4;		/* SDRAM Timing Configuration 4 */
+	u32	timing_cfg_5;		/* SDRAM Timing Configuration 5 */
+	u8	reg8_1a[8];
+	u32	ddr_zq_cntl;		/* ZQ calibration control*/
+	u32	ddr_wrlvl_cntl;		/* write leveling control*/
+	u8	reg8_1aa[4];
+	u32	ddr_sr_cntr;		/* self refresh counter */
+	u32	ddr_sdram_rcw_1;	/* Control Words 1 */
+	u32	ddr_sdram_rcw_2;	/* Control Words 2 */
+	u8	reg_1ab[8];
+	u32	ddr_wrlvl_cntl_2;	/* write leveling control 2 */
+	u32	ddr_wrlvl_cntl_3;	/* write leveling control 3 */
+	u8	res8_1b[104];
+	u32	sdram_mode_3;		/* SDRAM Mode Configuration 3 */
+	u32	sdram_mode_4;		/* SDRAM Mode Configuration 4 */
+	u32	sdram_mode_5;		/* SDRAM Mode Configuration 5 */
+	u32	sdram_mode_6;		/* SDRAM Mode Configuration 6 */
+	u32	sdram_mode_7;		/* SDRAM Mode Configuration 7 */
+	u32	sdram_mode_8;		/* SDRAM Mode Configuration 8 */
+	u8	res8_1ba[0x908];
+	u32	ddr_dsr1;		/* Debug Status 1 */
+	u32	ddr_dsr2;		/* Debug Status 2 */
+	u32	ddr_cdr1;		/* Control Driver 1 */
+	u32	ddr_cdr2;		/* Control Driver 2 */
+	u8	res8_1c[200];
+	u32	ip_rev1;		/* IP Block Revision 1 */
+	u32	ip_rev2;		/* IP Block Revision 2 */
+	u32	eor;			/* Enhanced Optimization Register */
+	u8	res8_2[252];
+	u32	mtcr;			/* Memory Test Control Register */
+	u8	res8_3[28];
+	u32	mtp1;			/* Memory Test Pattern 1 */
+	u32	mtp2;			/* Memory Test Pattern 2 */
+	u32	mtp3;			/* Memory Test Pattern 3 */
+	u32	mtp4;			/* Memory Test Pattern 4 */
+	u32	mtp5;			/* Memory Test Pattern 5 */
+	u32	mtp6;			/* Memory Test Pattern 6 */
+	u32	mtp7;			/* Memory Test Pattern 7 */
+	u32	mtp8;			/* Memory Test Pattern 8 */
+	u32	mtp9;			/* Memory Test Pattern 9 */
+	u32	mtp10;			/* Memory Test Pattern 10 */
+	u8	res8_4[184];
+	u32	data_err_inject_hi;	/* Data Path Err Injection Mask High */
+	u32	data_err_inject_lo;	/* Data Path Err Injection Mask Low */
+	u32	ecc_err_inject;		/* Data Path Err Injection Mask ECC */
+	u8	res9[20];
+	u32	capture_data_hi;	/* Data Path Read Capture High */
+	u32	capture_data_lo;	/* Data Path Read Capture Low */
+	u32	capture_ecc;		/* Data Path Read Capture ECC */
+	u8	res10[20];
+	u32	err_detect;		/* Error Detect */
+	u32	err_disable;		/* Error Disable */
+	u32	err_int_en;
+	u32	capture_attributes;	/* Error Attrs Capture */
+	u32	capture_address;	/* Error Addr Capture */
+	u32	capture_ext_address;	/* Error Extended Addr Capture */
+	u32	err_sbe;		/* Single-Bit ECC Error Management */
+	u8	res11[164];
+	u32	debug[32];		/* debug_1 to debug_32 */
+	u8	res12[128];
+} ccsr_ddr_t;
+#else
 typedef struct ddr_cs_bnds {
 	u32 csbnds;
 	u8 res0[4];
@@ -334,6 +433,7 @@  typedef struct ddr83xx {
 	u32 debug_reg;
 	u8 res9[0xFC];
 } ddr83xx_t;
+#endif
 
 /*
  * DUART
@@ -641,7 +741,11 @@  typedef struct immap {
 	u8			dll_ddr[0x100];
 	u8			dll_lbc[0x100];
 	u8			res1[0xE00];
-	ddr83xx_t		ddr;		/* DDR Memory Controller Memory */
+#if defined(CONFIG_FSL_DDR2) || defined(CONFIG_FSL_DDR3)
+	ccsr_ddr_t		ddr;	/* DDR Memory Controller Memory */
+#else
+	ddr83xx_t		ddr;	/* DDR Memory Controller Memory */
+#endif
 	fsl_i2c_t		i2c[2];		/* I2C Controllers */
 	u8			res2[0x1300];
 	duart83xx_t		duart[2];	/* DUART */
@@ -869,10 +973,15 @@  typedef struct immap {
 } immap_t;
 #endif
 
+#define CONFIG_SYS_MPC83xx_DDR_OFFSET	(0x2000)
+#define CONFIG_SYS_MPC83xx_DDR_ADDR \
+			(CONFIG_SYS_IMMR + CONFIG_SYS_MPC83xx_DDR_OFFSET)
 #define CONFIG_SYS_MPC83xx_DMA_OFFSET	(0x8000)
-#define CONFIG_SYS_MPC83xx_DMA_ADDR	(CONFIG_SYS_IMMR + CONFIG_SYS_MPC83xx_DMA_OFFSET)
+#define CONFIG_SYS_MPC83xx_DMA_ADDR \
+			(CONFIG_SYS_IMMR + CONFIG_SYS_MPC83xx_DMA_OFFSET)
 #define CONFIG_SYS_MPC83xx_ESDHC_OFFSET	(0x2e000)
-#define CONFIG_SYS_MPC83xx_ESDHC_ADDR	(CONFIG_SYS_IMMR + CONFIG_SYS_MPC83xx_ESDHC_OFFSET)
+#define CONFIG_SYS_MPC83xx_ESDHC_ADDR \
+			(CONFIG_SYS_IMMR + CONFIG_SYS_MPC83xx_ESDHC_OFFSET)
 
 #ifndef CONFIG_SYS_MPC83xx_USB_OFFSET
 #define CONFIG_SYS_MPC83xx_USB_OFFSET  0x23000
diff --git a/common/Makefile b/common/Makefile
index 224b7cc..8452d5d 100644
--- a/common/Makefile
+++ b/common/Makefile
@@ -162,7 +162,13 @@  COBJS-$(CONFIG_CMD_XIMG) += cmd_ximg.o
 COBJS-$(CONFIG_YAFFS2) += cmd_yaffs2.o
 
 # others
-COBJS-$(CONFIG_DDR_SPD) += ddr_spd.o
+ifdef CONFIG_DDR_SPD
+SPD := y
+endif
+ifdef CONFIG_SPD_EEPROM
+SPD := y
+endif
+COBJS-$(SPD) += ddr_spd.o
 COBJS-$(CONFIG_HWCONFIG) += hwconfig.o
 COBJS-$(CONFIG_CONSOLE_MUX) += iomux.o
 COBJS-y += flash.o
diff --git a/include/common.h b/include/common.h
index 1e21b7a..c22068a 100644
--- a/include/common.h
+++ b/include/common.h
@@ -537,10 +537,12 @@  ulong get_PERCLK3(void);
 ulong	get_bus_freq  (ulong);
 int get_serial_clock(void);
 
+#if defined(CONFIG_MPC83xx) || defined(CONFIG_MPC85xx)
+ulong get_ddr_freq(ulong);
+#endif
 #if defined(CONFIG_MPC85xx)
 typedef MPC85xx_SYS_INFO sys_info_t;
 void	get_sys_info  ( sys_info_t * );
-ulong	get_ddr_freq  (ulong);
 #endif
 #if defined(CONFIG_MPC86xx)
 typedef MPC86xx_SYS_INFO sys_info_t;