Fixed ordering of MDDRC config registers to unbreak mpc5121ads patch
PATCH 1/1 Fixed ordering of MDDRC config registers to unbreak mpc5121ads patch
--- cpu/mpc512x/fixed_sdram.c | 23 +++++++++++++++-------- 1 files changed, 15 insertions(+), 8 deletions(-)
cpu/mpc512x/fixed_sdram.c +15 -8
@@ -26,13 +26,14 @@#include <asm/mpc512x.h> /* -* MDDRC Config Runtime Settings in order of the 4 MDDRC cfg registers +* MDDRC Config Runtime Settings in MEMORY order of the 4 MDDRC cfg registers */ u32 default_mddrc_config[4 ] = { +CONFIG_SYS_MDDRC_SYS_CFG ,/* sys_config */ CONFIG_SYS_MDDRC_TIME_CFG0 ,/* time_config0 */ CONFIG_SYS_MDDRC_TIME_CFG1 ,/* time_config1 */ CONFIG_SYS_MDDRC_TIME_CFG2 ,/* time_config2 */ -CONFIG_SYS_MDDRC_SYS_CFG ,/* sys_config */ + };u32 default_init_seq[] = {
@@ -79,6 +80,7 @@ long int fixed_sdram(u32 *mddrc_config, u32 *dram_init_seq, int seq_sz)volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR ;u32 msize =CONFIG_SYS_DDR_SIZE *1024 *1024 ;u32 msize_log2 =__ilog2 (msize); +struct ddr512x_t *ddr_cfg_4regs;u32 i;/* take default settings and init sequence if necessary */
@@ -130,18 +132,23 @@ long int fixed_sdram(u32 *mddrc_config, u32 *dram_init_seq, int seq_sz)* put MDDRC in CMD mode and * set the max time between refreshes to 0 during init process */ -out_be32 (&im->mddrc.ddr_sys_config, mddrc_config[3 ] |MDDRC_SYS_CFG_CMD_MASK ); -out_be32 (&im->mddrc.ddr_time_config0, mddrc_config[0 ] &MDDRC_REFRESH_ZERO_MASK ); -out_be32 (&im->mddrc.ddr_time_config1, mddrc_config[1 ]); -out_be32 (&im->mddrc.ddr_time_config2, mddrc_config[2 ]); + +/* using struct's first 4 regs only */ + mddrc_4regs = (struct ddr512x_t *)mddrc_config; +out_be32 (&im->mddrc.ddr_sys_config, mddrc_4regs->ddr_sys_config + |MDDRC_SYS_CFG_CMD_MASK ); +out_be32 (&im->mddrc.ddr_time_config0, mddrc_4regs->ddr_time_config0 + &MDDRC_REFRESH_ZERO_MASK ); +out_be32 (&im->mddrc.ddr_time_config1, mddrc_4regs->ddr_time_config1); +out_be32 (&im->mddrc.ddr_time_config2, mddrc_4regs->ddr_time_config2);/* Initialize DDR with either default or supplied init sequence */ for (i =0 ; i < seq_sz; i++)out_be32 (&im->mddrc.ddr_command, dram_init_seq[i]);/* Start MDDRC */ -out_be32 (&im->mddrc.ddr_time_config0, mddrc_config[0 ]); -out_be32 (&im->mddrc.ddr_sys_config, mddrc_config[3 ]); +out_be32 (&im->mddrc.ddr_time_config0, mddrc_4regs->ddr_time_config0); +out_be32 (&im->mddrc.ddr_sys_config, mddrc_4regs->ddr_sys_config);return msize; }
Signature · 1 line
1.5.2.4
PATCH 1/1 Fixed ordering of MDDRC config registers to unbreak mpc5121ads patch
Dear Martha M Stan,
Quoted 14 lines · In message <[email protected]> you wrote:
Signed-off-by Martha M Stan <[email protected]>--- cpu/mpc512x/fixed_sdram.c | 23 +++++++++++++++-------- 1 files changed, 15 insertions(+), 8 deletions(-)cpu/mpc512x/fixed_sdram.c +0
-1@@ -26,13 +26,14 @@#include <asm/mpc512x.h> /* -* MDDRC Config Runtime Settings in order of the 4 MDDRC cfg registers
cpu/mpc512x/fixed_sdram.c line 37
Quoted 10 lines
cpu/mpc512x/fixed_sdram.c +3
-1+* MDDRC Config Runtime Settings in MEMORY order of the 4 MDDRC cfg registers */ u32 default_mddrc_config[4 ] = { +CONFIG_SYS_MDDRC_SYS_CFG ,/* sys_config */ CONFIG_SYS_MDDRC_TIME_CFG0 ,/* time_config0 */ CONFIG_SYS_MDDRC_TIME_CFG1 ,/* time_config1 */ CONFIG_SYS_MDDRC_TIME_CFG2 ,/* time_config2 */ -CONFIG_SYS_MDDRC_SYS_CFG ,/* sys_config */ + };
This is an array of u32.
cpu/mpc512x/fixed_sdram.c long int fixed_sdram(u32 *mddrc_config, u32 *dram_init_seq, int seq_sz) · line 83
Quoted 6 lines
cpu/mpc512x/fixed_sdram.c +1
-0u32 default_init_seq[] = {@@ -79,6 +80,7 @@ long int fixed_sdram(u32 *mddrc_config, u32 *dram_init_seq, int seq_sz)volatile immap_t *im = (immap_t *)CONFIG_SYS_IMMR ;u32 msize =CONFIG_SYS_DDR_SIZE *1024 *1024 ;u32 msize_log2 =__ilog2 (msize); +struct ddr512x_t *ddr_cfg_4regs;
And this is (a pointer to) a struct with u32 entries.
cpu/mpc512x/fixed_sdram.c long int fixed_sdram(u32 *mddrc_config, u32 *dram_init_seq, int seq_sz) · line 137
Quoted 2 lines
cpu/mpc512x/fixed_sdram.c +2
-0+/* using struct's first 4 regs only */ + mddrc_4regs = (struct ddr512x_t *)mddrc_config;
What gives you the guarantee that the struct and the array use the same padding / alignment?
This is extremely bad style. If you want to use a struct, then please declare one, and refer to indivisual elements through their names. You could also turn default_mddrc_config into s "struct ddr512x_t" and just initialize the first 4 elements, but note that the memory footprint will go up significantly.
NAK for this code.
Best regards,
Wolfgang Denk
Signature · 5 lines
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de You have the capacity to learn from mistakes. You'll learn a lot today.