[U-Boot] [PATCH] Fixed ordering of MDDRC config registers to unbreak mpc5121ads patch

Signed-off-by: Martha M Stan mmarx@silicontkx.com --- cpu/mpc512x/fixed_sdram.c | 23 +++++++++++++++-------- 1 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/cpu/mpc512x/fixed_sdram.c b/cpu/mpc512x/fixed_sdram.c index 673d61e..7617e31 100644 --- a/cpu/mpc512x/fixed_sdram.c +++ b/cpu/mpc512x/fixed_sdram.c @@ -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; }

Dear Martha M Stan,
In message 12538848343158-git-send-email-mmarx@silicontkx.com you wrote:
Signed-off-by: Martha M Stan mmarx@silicontkx.com
cpu/mpc512x/fixed_sdram.c | 23 +++++++++++++++-------- 1 files changed, 15 insertions(+), 8 deletions(-)
diff --git a/cpu/mpc512x/fixed_sdram.c b/cpu/mpc512x/fixed_sdram.c index 673d61e..7617e31 100644 --- a/cpu/mpc512x/fixed_sdram.c +++ b/cpu/mpc512x/fixed_sdram.c @@ -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 */
};
This is an array of u32.
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;
And this is (a pointer to) a struct with u32 entries.
- /* 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
participants (2)
-
Martha M Stan
-
Wolfgang Denk