Skip to contentSkip to conversation

Exynos5: spl: Reduce spl size

PATCH Superseded Akshay Saraswat 3 participants 7 messages Mar 5, 2013 Arm/actions semi architecture

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore
#0 lore raw

v2 cover Exynos5: spl: Reduce spl size

This patch set tries to gain some space in spl by restructuring and reorganising some code in two different clock init's for two different times of execution.

Compiler arm-2011.09:
With patches u-boot-spl.bin size - 3900 bytes. Without patches u-boot-spl.bin size - 4924 bytes.

Compiler arm-2009q3:
With patches u-boot-spl.bin size - 4412 bytes. Without patches u-boot-spl.bin size - 5692 bytes.

Changes since v1:
- Patch1: Rebased on ToT.
- Patch2: Rebased on ToT.

Akshay Saraswat (2):
Exynos5: spl: Reorganize mem_timing struct to gain space in spl
Exynos5: spl: Reduce clock init in spl

 board/samsung/smdk5250/Makefile         |   3 +-
 board/samsung/smdk5250/clock_init.c     | 506 +-------------------------------
 board/samsung/smdk5250/clock_init.h     |  57 ++--
 board/samsung/smdk5250/dmc_common.c     |  40 +--
 board/samsung/smdk5250/dmc_init_ddr3.c  | 116 ++++----
 board/samsung/smdk5250/lowlevel_init.S  |   4 +-
 board/samsung/smdk5250/setup.h          |  16 +-
 board/samsung/smdk5250/smdk5250.c       |   4 +
 board/samsung/smdk5250/spl_clock_init.c | 469 +++++++++++++++++++++++++++++
 9 files changed, 625 insertions(+), 590 deletions(-)
 create mode 100644 board/samsung/smdk5250/spl_clock_init.c
Signature · 1 line
1.8.0
#1 lore raw

PATCH v2 1/2 Exynos5: spl: Reorganize mem_timing struct to gain space in spl

Distributes struct mem_timings into new different structures to gain space in spl by removing necessity of maintaining two big and almost similar mem_timings instances.

---
Changes since v1:
- None.

 board/samsung/smdk5250/clock_init.c    | 177 ++++++++++++---------------------
 board/samsung/smdk5250/clock_init.h    |  55 ++++++----
 board/samsung/smdk5250/dmc_common.c    |  40 ++++----
 board/samsung/smdk5250/dmc_init_ddr3.c | 116 +++++++++++----------
 board/samsung/smdk5250/setup.h         |  15 ++-
 5 files changed, 193 insertions(+), 210 deletions(-)
board/samsung/smdk5250/clock_init.c +64 -113
index c009ae5..30cbdcf 100644
@@ -127,14 +127,17 @@ struct arm_clk_ratios arm_clk_ratios[] = {
 		.arm_ratio = 0x0,
 	}
 };
-struct mem_timings mem_timings[] = {
-	{
-		.mem_manuf = MEM_MANUF_ELPIDA,
-		.mem_type = DDR_MODE_DDR3,
-		.frequency_mhz = 800,
+
+struct spl_clock_div spl_clock_div = {
 		.mpll_mdiv = 0xc8,
 		.mpll_pdiv = 0x3,
 		.mpll_sdiv = 0x0,
+		.bpll_mdiv = 0x64,
+		.bpll_pdiv = 0x3,
+		.bpll_sdiv = 0x0,
+};
+
+struct non_spl_clock_div non_spl_clock_div = {
 		.cpll_mdiv = 0xde,
 		.cpll_pdiv = 0x4,
 		.cpll_sdiv = 0x2,
@@ -147,14 +150,10 @@ struct mem_timings mem_timings[] = {
 		.vpll_mdiv = 0x96,
 		.vpll_pdiv = 0x3,
 		.vpll_sdiv = 0x2,
+};
 
-		.bpll_mdiv = 0x64,
-		.bpll_pdiv = 0x3,
-		.bpll_sdiv = 0x0,
+struct mem_timings mem_timings = {
 		.pclk_cdrex_ratio = 0x5,
-		.direct_cmd_msr = {
-			0x00020018, 0x00030000, 0x00010042, 0x00000d70
-		},
 		.timing_ref = 0x000000bb,
 		.timing_row = 0x8c36650e,
 		.timing_data = 0x3630580b,
@@ -163,8 +162,6 @@ struct mem_timings mem_timings[] = {
 		.phy1_dqs = 0x08080808,
 		.phy0_dq = 0x08080808,
 		.phy1_dq = 0x08080808,
-		.phy0_tFS = 0x4,
-		.phy1_tFS = 0x4,
 		.phy0_pulld_dqs = 0xf,
 		.phy1_pulld_dqs = 0xf,
 
@@ -186,10 +183,6 @@ struct mem_timings mem_timings[] = {
 
 		.rd_fetch = 0x3,
 
-		.zq_mode_dds = 0x7,
-		.zq_mode_term = 0x1,
-		.zq_mode_noterm = 0,
-
 		/*
 		* Dynamic Clock: Always Running
 		* Memory Burst length: 8
@@ -229,114 +222,49 @@ struct mem_timings mem_timings[] = {
 		.chips_per_channel = 2,
 		.chips_to_configure = 1,
 		.send_zq_init = 1,
+};
+
+struct mem_params mem_params[] = {
+	{
+		.mem_manuf = MEM_MANUF_ELPIDA,
+		.mem_type = DDR_MODE_DDR3,
+		.frequency_mhz = 800,
+
+		.direct_cmd_msr = {
+			0x00020018, 0x00030000, 0x00010042, 0x00000d70
+		},
+
+		.phy0_tFS = 0x4,
+		.phy1_tFS = 0x4,
+
+		.zq_mode_dds = 0x7,
+		.zq_mode_term = 0x1,
+		.zq_mode_noterm = 0,
+
 		.impedance = IMP_OUTPUT_DRV_30_OHM,
 		.gate_leveling_enable = 0,
 	}, {
 		.mem_manuf = MEM_MANUF_SAMSUNG,
 		.mem_type = DDR_MODE_DDR3,
 		.frequency_mhz = 800,
-		.mpll_mdiv = 0xc8,
-		.mpll_pdiv = 0x3,
-		.mpll_sdiv = 0x0,
-		.cpll_mdiv = 0xde,
-		.cpll_pdiv = 0x4,
-		.cpll_sdiv = 0x2,
-		.gpll_mdiv = 0x215,
-		.gpll_pdiv = 0xc,
-		.gpll_sdiv = 0x1,
-		.epll_mdiv = 0x60,
-		.epll_pdiv = 0x3,
-		.epll_sdiv = 0x3,
-		.vpll_mdiv = 0x96,
-		.vpll_pdiv = 0x3,
-		.vpll_sdiv = 0x2,
 
-		.bpll_mdiv = 0x64,
-		.bpll_pdiv = 0x3,
-		.bpll_sdiv = 0x0,
-		.pclk_cdrex_ratio = 0x5,
 		.direct_cmd_msr = {
 			0x00020018, 0x00030000, 0x00010000, 0x00000d70
 		},
-		.timing_ref = 0x000000bb,
-		.timing_row = 0x8c36650e,
-		.timing_data = 0x3630580b,
-		.timing_power = 0x41000a44,
-		.phy0_dqs = 0x08080808,
-		.phy1_dqs = 0x08080808,
-		.phy0_dq = 0x08080808,
-		.phy1_dq = 0x08080808,
+
 		.phy0_tFS = 0x8,
 		.phy1_tFS = 0x8,
-		.phy0_pulld_dqs = 0xf,
-		.phy1_pulld_dqs = 0xf,
-
-		.lpddr3_ctrl_phy_reset = 0x1,
-		.ctrl_start_point = 0x10,
-		.ctrl_inc = 0x10,
-		.ctrl_start = 0x1,
-		.ctrl_dll_on = 0x1,
-		.ctrl_ref = 0x8,
-
-		.ctrl_force = 0x1a,
-		.ctrl_rdlat = 0x0b,
-		.ctrl_bstlen = 0x08,
-
-		.fp_resync = 0x8,
-		.iv_size = 0x7,
-		.dfi_init_start = 1,
-		.aref_en = 1,
-
-		.rd_fetch = 0x3,
 
 		.zq_mode_dds = 0x5,
 		.zq_mode_term = 0x1,
 		.zq_mode_noterm = 1,
 
-		/*
-		* Dynamic Clock: Always Running
-		* Memory Burst length: 8
-		* Number of chips: 1
-		* Memory Bus width: 32 bit
-		* Memory Type: DDR3
-		* Additional Latancy for PLL: 0 Cycle
-		*/
-		.memcontrol = DMC_MEMCONTROL_CLK_STOP_DISABLE |
-			DMC_MEMCONTROL_DPWRDN_DISABLE |
-			DMC_MEMCONTROL_DPWRDN_ACTIVE_PRECHARGE |
-			DMC_MEMCONTROL_TP_DISABLE |
-			DMC_MEMCONTROL_DSREF_ENABLE |
-			DMC_MEMCONTROL_ADD_LAT_PALL_CYCLE(0) |
-			DMC_MEMCONTROL_MEM_TYPE_DDR3 |
-			DMC_MEMCONTROL_MEM_WIDTH_32BIT |
-			DMC_MEMCONTROL_NUM_CHIP_1 |
-			DMC_MEMCONTROL_BL_8 |
-			DMC_MEMCONTROL_PZQ_DISABLE |
-			DMC_MEMCONTROL_MRR_BYTE_7_0,
-		.memconfig = DMC_MEMCONFIGx_CHIP_MAP_INTERLEAVED |
-			DMC_MEMCONFIGx_CHIP_COL_10 |
-			DMC_MEMCONFIGx_CHIP_ROW_15 |
-			DMC_MEMCONFIGx_CHIP_BANK_8,
-		.membaseconfig0 = DMC_MEMBASECONFIG_VAL(0x40),
-		.membaseconfig1 = DMC_MEMBASECONFIG_VAL(0x80),
-		.prechconfig_tp_cnt = 0xff,
-		.dpwrdn_cyc = 0xff,
-		.dsref_cyc = 0xffff,
-		.concontrol = DMC_CONCONTROL_DFI_INIT_START_DISABLE |
-			DMC_CONCONTROL_TIMEOUT_LEVEL0 |
-			DMC_CONCONTROL_RD_FETCH_DISABLE |
-			DMC_CONCONTROL_EMPTY_DISABLE |
-			DMC_CONCONTROL_AREF_EN_DISABLE |
-			DMC_CONCONTROL_IO_PD_CON_DISABLE,
-		.dmc_channels = 2,
-		.chips_per_channel = 2,
-		.chips_to_configure = 1,
-		.send_zq_init = 1,
 		.impedance = IMP_OUTPUT_DRV_40_OHM,
 		.gate_leveling_enable = 1,
 	}
 };
 
+
 /**
  * Get the required memory type and speed (SPL version).
  *
@@ -388,9 +316,24 @@ struct arm_clk_ratios *get_arm_ratios(void)
 	return NULL;
 }
 
+struct spl_clock_div *clock_get_spl_div(void)
+{
+	return &spl_clock_div;
+}
+
+struct non_spl_clock_div *clock_get_non_spl_div(void)
+{
+	return &non_spl_clock_div;
+}
+
 struct mem_timings *clock_get_mem_timings(void)
 {
-	struct mem_timings *mem;
+	return &mem_timings;
+}
+
+struct mem_params *clock_get_mem_params(void)
+{
+	struct mem_params *mem;
 	enum ddr_mode mem_type;
 	enum mem_manuf mem_manuf;
 	unsigned frequency_mhz, arm_freq;
@@ -398,7 +341,7 @@ struct mem_timings *clock_get_mem_timings(void)
 
 	if (!clock_get_mem_selection(&mem_type, &frequency_mhz,
 						&arm_freq, &mem_manuf)) {
-		for (i = 0, mem = mem_timings; i < ARRAY_SIZE(mem_timings);
+		for (i = 0, mem = mem_params; i < ARRAY_SIZE(mem_params);
 				i++, mem++) {
 			if (mem->mem_type == mem_type &&
 					mem->frequency_mhz == frequency_mhz &&
@@ -417,12 +360,14 @@ struct mem_timings *clock_get_mem_timings(void)
 void system_clock_init()
 {
 	struct exynos5_clock *clk = (struct exynos5_clock *)EXYNOS5_CLOCK_BASE;
-	struct mem_timings *mem;
 	struct arm_clk_ratios *arm_clk_ratio;
+	struct spl_clock_div *s_clk_div;
+	struct non_spl_clock_div *ns_clk_div;
 	u32 val, tmp;
 
-	mem = clock_get_mem_timings();
 	arm_clk_ratio = get_arm_ratios();
+	s_clk_div = clock_get_spl_div();
+	ns_clk_div = clock_get_non_spl_div();
 
 	clrbits_le32(&clk->src_cpu, MUX_APLL_SEL_MASK);
 	do {
@@ -499,28 +444,32 @@ void system_clock_init()
 
 	/* Set MPLL */
 	writel(MPLL_CON1_VAL, &clk->mpll_con1);
-	val = set_pll(mem->mpll_mdiv, mem->mpll_pdiv, mem->mpll_sdiv);
+	val = set_pll(s_clk_div->mpll_mdiv,
+				s_clk_div->mpll_pdiv, s_clk_div->mpll_sdiv);
 	writel(val, &clk->mpll_con0);
 	while (readl(&clk->mpll_con0) & MPLL_CON0_LOCKED)
 		;
 
 	/* Set BPLL */
 	writel(BPLL_CON1_VAL, &clk->bpll_con1);
-	val = set_pll(mem->bpll_mdiv, mem->bpll_pdiv, mem->bpll_sdiv);
+	val = set_pll(s_clk_div->bpll_mdiv,
+				s_clk_div->bpll_pdiv, s_clk_div->bpll_sdiv);
 	writel(val, &clk->bpll_con0);
 	while (readl(&clk->bpll_con0) & BPLL_CON0_LOCKED)
 		;
 
 	/* Set CPLL */
 	writel(CPLL_CON1_VAL, &clk->cpll_con1);
-	val = set_pll(mem->cpll_mdiv, mem->cpll_pdiv, mem->cpll_sdiv);
+	val = set_pll(ns_clk_div->cpll_mdiv,
+				ns_clk_div->cpll_pdiv, ns_clk_div->cpll_sdiv);
 	writel(val, &clk->cpll_con0);
 	while (readl(&clk->cpll_con0) & CPLL_CON0_LOCKED)
 		;
 
 	/* Set GPLL */
 	writel(GPLL_CON1_VAL, &clk->gpll_con1);
-	val = set_pll(mem->gpll_mdiv, mem->gpll_pdiv, mem->gpll_sdiv);
+	val = set_pll(ns_clk_div->gpll_mdiv,
+				ns_clk_div->gpll_pdiv, ns_clk_div->gpll_sdiv);
 	writel(val, &clk->gpll_con0);
 	while (readl(&clk->gpll_con0) & GPLL_CON0_LOCKED)
 		;
@@ -528,7 +477,8 @@ void system_clock_init()
 	/* Set EPLL */
 	writel(EPLL_CON2_VAL, &clk->epll_con2);
 	writel(EPLL_CON1_VAL, &clk->epll_con1);
-	val = set_pll(mem->epll_mdiv, mem->epll_pdiv, mem->epll_sdiv);
+	val = set_pll(ns_clk_div->epll_mdiv,
+				ns_clk_div->epll_pdiv, ns_clk_div->epll_sdiv);
 	writel(val, &clk->epll_con0);
 	while (readl(&clk->epll_con0) & EPLL_CON0_LOCKED)
 		;
@@ -536,7 +486,8 @@ void system_clock_init()
 	/* Set VPLL */
 	writel(VPLL_CON2_VAL, &clk->vpll_con2);
 	writel(VPLL_CON1_VAL, &clk->vpll_con1);
-	val = set_pll(mem->vpll_mdiv, mem->vpll_pdiv, mem->vpll_sdiv);
+	val = set_pll(ns_clk_div->vpll_mdiv,
+				ns_clk_div->vpll_pdiv, ns_clk_div->vpll_sdiv);
 	writel(val, &clk->vpll_con0);
 	while (readl(&clk->vpll_con0) & VPLL_CON0_LOCKED)
 		;
board/samsung/smdk5250/clock_init.h +36 -19

98 lines not on this page · raw message

board/samsung/smdk5250/dmc_common.c +22 -18
index 109602a..1166cb7 100644
@@ -30,7 +30,7 @@
 
 #define ZQ_INIT_TIMEOUT	10000
 
-int dmc_config_zq(struct mem_timings *mem,
+int dmc_config_zq(struct mem_params *mparams,
 		  struct exynos5_phy_control *phy0_ctrl,
 		  struct exynos5_phy_control *phy1_ctrl)
 {
@@ -43,14 +43,14 @@ int dmc_config_zq(struct mem_timings *mem,
 	 * long calibration for manual calibration
 	 */
 	val = PHY_CON16_RESET_VAL;
-	val |= mem->zq_mode_dds << PHY_CON16_ZQ_MODE_DDS_SHIFT;
-	val |= mem->zq_mode_term << PHY_CON16_ZQ_MODE_TERM_SHIFT;
+	val |= mparams->zq_mode_dds << PHY_CON16_ZQ_MODE_DDS_SHIFT;
+	val |= mparams->zq_mode_term << PHY_CON16_ZQ_MODE_TERM_SHIFT;
 	val |= ZQ_CLK_DIV_EN;
 	writel(val, &phy0_ctrl->phy_con16);
 	writel(val, &phy1_ctrl->phy_con16);
 
 	/* Disable termination */
-	if (mem->zq_mode_noterm)
+	if (mparams->zq_mode_noterm)
 		val |= PHY_CON16_ZQ_MODE_NOTERM_MASK;
 	writel(val, &phy0_ctrl->phy_con16);
 	writel(val, &phy1_ctrl->phy_con16);
@@ -108,15 +108,17 @@ void update_reset_dll(struct exynos5_dmc *dmc, enum ddr_mode mode)
 	writel(val, &dmc->phycontrol0);
 }
 
-void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc)
+void dmc_config_mrs(struct mem_timings *mtimings,
+			struct mem_params *mparams,
+			struct exynos5_dmc *dmc)
 {
 	int channel, chip;
 
-	for (channel = 0; channel < mem->dmc_channels; channel++) {
+	for (channel = 0; channel < mtimings->dmc_channels; channel++) {
 		unsigned long mask;
 
 		mask = channel << DIRECT_CMD_CHANNEL_SHIFT;
-		for (chip = 0; chip < mem->chips_to_configure; chip++) {
+		for (chip = 0; chip < mtimings->chips_to_configure; chip++) {
 			int i;
 
 			mask |= chip << DIRECT_CMD_CHIP_SHIFT;
@@ -133,12 +135,12 @@ void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc)
 
 			/* Sending EMRS/MRS commands */
 			for (i = 0; i < MEM_TIMINGS_MSR_COUNT; i++) {
-				writel(mem->direct_cmd_msr[i] | mask,
+				writel(mparams->direct_cmd_msr[i] | mask,
 				       &dmc->directcmd);
 				sdelay(0x10000);
 			}
 
-			if (mem->send_zq_init) {
+			if (mtimings->send_zq_init) {
 				/* Sending ZQINIT command */
 				writel(DIRECT_CMD_ZQINIT | mask,
 				       &dmc->directcmd);
@@ -149,15 +151,15 @@ void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc)
 	}
 }
 
-void dmc_config_prech(struct mem_timings *mem, struct exynos5_dmc *dmc)
+void dmc_config_prech(struct mem_timings *mtimings, struct exynos5_dmc *dmc)
 {
 	int channel, chip;
 
-	for (channel = 0; channel < mem->dmc_channels; channel++) {
+	for (channel = 0; channel < mtimings->dmc_channels; channel++) {
 		unsigned long mask;
 
 		mask = channel << DIRECT_CMD_CHANNEL_SHIFT;
-		for (chip = 0; chip < mem->chips_per_channel; chip++) {
+		for (chip = 0; chip < mtimings->chips_per_channel; chip++) {
 			mask |= chip << DIRECT_CMD_CHIP_SHIFT;
 
 			/* PALL (all banks precharge) CMD */
@@ -167,10 +169,10 @@ void dmc_config_prech(struct mem_timings *mem, struct exynos5_dmc *dmc)
 	}
 }
 
-void dmc_config_memory(struct mem_timings *mem, struct exynos5_dmc *dmc)
+void dmc_config_memory(struct mem_timings *mtimings, struct exynos5_dmc *dmc)
 {
-	writel(mem->memconfig, &dmc->memconfig0);
-	writel(mem->memconfig, &dmc->memconfig1);
+	writel(mtimings->memconfig, &dmc->memconfig0);
+	writel(mtimings->memconfig, &dmc->memconfig1);
 	writel(DMC_MEMBASECONFIG0_VAL, &dmc->membaseconfig0);
 	writel(DMC_MEMBASECONFIG1_VAL, &dmc->membaseconfig1);
 }
@@ -178,14 +180,16 @@ void dmc_config_memory(struct mem_timings *mem, struct exynos5_dmc *dmc)
 void mem_ctrl_init()
 {
 	struct spl_machine_param *param = spl_get_machine_params();
-	struct mem_timings *mem;
+	struct mem_timings *mtimings;
+	struct mem_params *mparams;
 	int ret;
 
-	mem = clock_get_mem_timings();
+	mtimings = clock_get_mem_timings();
+	mparams = clock_get_mem_params();
 
 	/* If there are any other memory variant, add their init call below */
 	if (param->mem_type == DDR_MODE_DDR3) {
-		ret = ddr3_mem_ctrl_init(mem, param->mem_iv_size);
+		ret = ddr3_mem_ctrl_init(mtimings, mparams, param->mem_iv_size);
 		if (ret) {
 			/* will hang if failed to init memory control */
 			while (1)
board/samsung/smdk5250/dmc_init_ddr3.c +61 -55

198 lines not on this page · raw message

board/samsung/smdk5250/setup.h +10 -5
index a159601..b30d7d0 100644
@@ -521,6 +521,7 @@
 #define PHY_CON42_CTRL_RDLAT_SHIFT	0
 
 struct mem_timings;
+struct mem_params;
 
 /* Errors that we can encourter in low-level setup */
 enum {
@@ -539,7 +540,9 @@ enum {
  *			accesses; may vary across boards.
  * @return 0 if ok, SETUP_ERR_... if there is a problem
  */
-int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long mem_iv_size);
+int ddr3_mem_ctrl_init(struct mem_timings *mtimings,
+			struct mem_params *mparams,
+			unsigned long mem_iv_size);
 
 /*
  * Configure ZQ I/O interface
@@ -549,7 +552,7 @@ int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long mem_iv_size);
  * @param phy1_ctrl	Pointer to struct containing PHY1 control reg
  * @return 0 if ok, -1 on error
  */
-int dmc_config_zq(struct mem_timings *mem,
+int dmc_config_zq(struct mem_params *mparams,
 		  struct exynos5_phy_control *phy0_ctrl,
 		  struct exynos5_phy_control *phy1_ctrl);
 
@@ -559,7 +562,9 @@ int dmc_config_zq(struct mem_timings *mem,
  * @param mem		Memory timings for this memory type.
  * @param dmc		Pointer to struct of DMC registers
  */
-void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc);
+void dmc_config_mrs(struct mem_timings *mtimings,
+			struct mem_params *mparams,
+			struct exynos5_dmc *dmc);
 
 /*
  * Send PALL Direct commands
@@ -567,7 +572,7 @@ void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc);
  * @param mem		Memory timings for this memory type.
  * @param dmc		Pointer to struct of DMC registers
  */
-void dmc_config_prech(struct mem_timings *mem, struct exynos5_dmc *dmc);
+void dmc_config_prech(struct mem_timings *mtimings, struct exynos5_dmc *dmc);
 
 /*
  * Configure the memconfig and membaseconfig registers
@@ -575,7 +580,7 @@ void dmc_config_prech(struct mem_timings *mem, struct exynos5_dmc *dmc);
  * @param mem		Memory timings for this memory type.
  * @param exynos5_dmc	Pointer to struct of DMC registers
  */
-void dmc_config_memory(struct mem_timings *mem, struct exynos5_dmc *dmc);
+void dmc_config_memory(struct mem_timings *mtimings, struct exynos5_dmc *dmc);
 
 /*
  * Reset the DLL. This function is common between DDR3 and LPDDR2.
Signature · 1 line
1.8.0
#2 lore raw

PATCH v2 1/2 Exynos5: spl: Reorganize mem_timing struct to gain space in spl

Hi Akshay,

Quoted 7 lines · Akshay Saraswat

Distributes struct mem_timings into new different structures to gain space in spl by removing necessity of maintaining two big and almost similar mem_timings instances.

---

Now board boots fine with this patch applied.

Quoted 872 lines

Changes since v1:
- None.

 board/samsung/smdk5250/clock_init.c    | 177
++++++++++++---------------------
 board/samsung/smdk5250/clock_init.h    |  55 ++++++----
 board/samsung/smdk5250/dmc_common.c    |  40 ++++----
 board/samsung/smdk5250/dmc_init_ddr3.c | 116 +++++++++++----------
 board/samsung/smdk5250/setup.h         |  15 ++-
 5 files changed, 193 insertions(+), 210 deletions(-)
board/samsung/smdk5250/clock_init.c +48 -105
index c009ae5..30cbdcf 100644
@@ -127,14 +127,17 @@ struct arm_clk_ratios arm_clk_ratios[] = {
                .arm_ratio = 0x0,
        }
 };
-struct mem_timings mem_timings[] = {
-       {
-               .mem_manuf = MEM_MANUF_ELPIDA,
-               .mem_type = DDR_MODE_DDR3,
-               .frequency_mhz = 800,
+
+struct spl_clock_div spl_clock_div = {
                .mpll_mdiv = 0xc8,
                .mpll_pdiv = 0x3,
                .mpll_sdiv = 0x0,
+               .bpll_mdiv = 0x64,
+               .bpll_pdiv = 0x3,
+               .bpll_sdiv = 0x0,
+};
+
+struct non_spl_clock_div non_spl_clock_div = {
                .cpll_mdiv = 0xde,
                .cpll_pdiv = 0x4,
                .cpll_sdiv = 0x2,
@@ -147,14 +150,10 @@ struct mem_timings mem_timings[] = {
                .vpll_mdiv = 0x96,
                .vpll_pdiv = 0x3,
                .vpll_sdiv = 0x2,
+};
 
-               .bpll_mdiv = 0x64,
-               .bpll_pdiv = 0x3,
-               .bpll_sdiv = 0x0,
+struct mem_timings mem_timings = {
                .pclk_cdrex_ratio = 0x5,
-               .direct_cmd_msr = {
-                       0x00020018, 0x00030000, 0x00010042, 0x00000d70
-               },
                .timing_ref = 0x000000bb,
                .timing_row = 0x8c36650e,
                .timing_data = 0x3630580b,
@@ -163,8 +162,6 @@ struct mem_timings mem_timings[] = {
                .phy1_dqs = 0x08080808,
                .phy0_dq = 0x08080808,
                .phy1_dq = 0x08080808,
-               .phy0_tFS = 0x4,
-               .phy1_tFS = 0x4,
                .phy0_pulld_dqs = 0xf,
                .phy1_pulld_dqs = 0xf,
 
@@ -186,10 +183,6 @@ struct mem_timings mem_timings[] = {
 
                .rd_fetch = 0x3,
 
-               .zq_mode_dds = 0x7,
-               .zq_mode_term = 0x1,
-               .zq_mode_noterm = 0,
-
                /*
                * Dynamic Clock: Always Running
                * Memory Burst length: 8
@@ -229,114 +222,49 @@ struct mem_timings mem_timings[] = {
                .chips_per_channel = 2,
                .chips_to_configure = 1,
                .send_zq_init = 1,
+};
+
+struct mem_params mem_params[] = {
+       {
+               .mem_manuf = MEM_MANUF_ELPIDA,
+               .mem_type = DDR_MODE_DDR3,
+               .frequency_mhz = 800,
+
+               .direct_cmd_msr = {
+                       0x00020018, 0x00030000, 0x00010042, 0x00000d70
+               },
+
+               .phy0_tFS = 0x4,
+               .phy1_tFS = 0x4,
+
+               .zq_mode_dds = 0x7,
+               .zq_mode_term = 0x1,
+               .zq_mode_noterm = 0,
+
                .impedance = IMP_OUTPUT_DRV_30_OHM,
                .gate_leveling_enable = 0,
        }, {
                .mem_manuf = MEM_MANUF_SAMSUNG,
                .mem_type = DDR_MODE_DDR3,
                .frequency_mhz = 800,
-               .mpll_mdiv = 0xc8,
-               .mpll_pdiv = 0x3,
-               .mpll_sdiv = 0x0,
-               .cpll_mdiv = 0xde,
-               .cpll_pdiv = 0x4,
-               .cpll_sdiv = 0x2,
-               .gpll_mdiv = 0x215,
-               .gpll_pdiv = 0xc,
-               .gpll_sdiv = 0x1,
-               .epll_mdiv = 0x60,
-               .epll_pdiv = 0x3,
-               .epll_sdiv = 0x3,
-               .vpll_mdiv = 0x96,
-               .vpll_pdiv = 0x3,
-               .vpll_sdiv = 0x2,
 
-               .bpll_mdiv = 0x64,
-               .bpll_pdiv = 0x3,
-               .bpll_sdiv = 0x0,
-               .pclk_cdrex_ratio = 0x5,
                .direct_cmd_msr = {
                        0x00020018, 0x00030000, 0x00010000, 0x00000d70
                },
-               .timing_ref = 0x000000bb,
-               .timing_row = 0x8c36650e,
-               .timing_data = 0x3630580b,
-               .timing_power = 0x41000a44,
-               .phy0_dqs = 0x08080808,
-               .phy1_dqs = 0x08080808,
-               .phy0_dq = 0x08080808,
-               .phy1_dq = 0x08080808,
+
                .phy0_tFS = 0x8,
                .phy1_tFS = 0x8,
-               .phy0_pulld_dqs = 0xf,
-               .phy1_pulld_dqs = 0xf,
-
-               .lpddr3_ctrl_phy_reset = 0x1,
-               .ctrl_start_point = 0x10,
-               .ctrl_inc = 0x10,
-               .ctrl_start = 0x1,
-               .ctrl_dll_on = 0x1,
-               .ctrl_ref = 0x8,
-
-               .ctrl_force = 0x1a,
-               .ctrl_rdlat = 0x0b,
-               .ctrl_bstlen = 0x08,
-
-               .fp_resync = 0x8,
-               .iv_size = 0x7,
-               .dfi_init_start = 1,
-               .aref_en = 1,
-
-               .rd_fetch = 0x3,
 
                .zq_mode_dds = 0x5,
                .zq_mode_term = 0x1,
                .zq_mode_noterm = 1,
 
-               /*
-               * Dynamic Clock: Always Running
-               * Memory Burst length: 8
-               * Number of chips: 1
-               * Memory Bus width: 32 bit
-               * Memory Type: DDR3
-               * Additional Latancy for PLL: 0 Cycle
-               */
-               .memcontrol = DMC_MEMCONTROL_CLK_STOP_DISABLE |
-                       DMC_MEMCONTROL_DPWRDN_DISABLE |
-                       DMC_MEMCONTROL_DPWRDN_ACTIVE_PRECHARGE |
-                       DMC_MEMCONTROL_TP_DISABLE |
-                       DMC_MEMCONTROL_DSREF_ENABLE |
-                       DMC_MEMCONTROL_ADD_LAT_PALL_CYCLE(0) |
-                       DMC_MEMCONTROL_MEM_TYPE_DDR3 |
-                       DMC_MEMCONTROL_MEM_WIDTH_32BIT |
-                       DMC_MEMCONTROL_NUM_CHIP_1 |
-                       DMC_MEMCONTROL_BL_8 |
-                       DMC_MEMCONTROL_PZQ_DISABLE |
-                       DMC_MEMCONTROL_MRR_BYTE_7_0,
-               .memconfig = DMC_MEMCONFIGx_CHIP_MAP_INTERLEAVED |
-                       DMC_MEMCONFIGx_CHIP_COL_10 |
-                       DMC_MEMCONFIGx_CHIP_ROW_15 |
-                       DMC_MEMCONFIGx_CHIP_BANK_8,
-               .membaseconfig0 = DMC_MEMBASECONFIG_VAL(0x40),
-               .membaseconfig1 = DMC_MEMBASECONFIG_VAL(0x80),
-               .prechconfig_tp_cnt = 0xff,
-               .dpwrdn_cyc = 0xff,
-               .dsref_cyc = 0xffff,
-               .concontrol = DMC_CONCONTROL_DFI_INIT_START_DISABLE |
-                       DMC_CONCONTROL_TIMEOUT_LEVEL0 |
-                       DMC_CONCONTROL_RD_FETCH_DISABLE |
-                       DMC_CONCONTROL_EMPTY_DISABLE |
-                       DMC_CONCONTROL_AREF_EN_DISABLE |
-                       DMC_CONCONTROL_IO_PD_CON_DISABLE,
-               .dmc_channels = 2,
-               .chips_per_channel = 2,
-               .chips_to_configure = 1,
-               .send_zq_init = 1,
                .impedance = IMP_OUTPUT_DRV_40_OHM,
                .gate_leveling_enable = 1,
        }
 };
 
+
 /**
  * Get the required memory type and speed (SPL version).
  *
@@ -388,9 +316,24 @@ struct arm_clk_ratios *get_arm_ratios(void)
        return NULL;
 }
 
+struct spl_clock_div *clock_get_spl_div(void)
+{
+       return &spl_clock_div;
+}
+
+struct non_spl_clock_div *clock_get_non_spl_div(void)
+{
+       return &non_spl_clock_div;
+}
+
 struct mem_timings *clock_get_mem_timings(void)
 {
-       struct mem_timings *mem;
+       return &mem_timings;
+}
+
+struct mem_params *clock_get_mem_params(void)
+{
+       struct mem_params *mem;
        enum ddr_mode mem_type;
        enum mem_manuf mem_manuf;
        unsigned frequency_mhz, arm_freq;
@@ -398,7 +341,7 @@ struct mem_timings *clock_get_mem_timings(void)
 
        if (!clock_get_mem_selection(&mem_type, &frequency_mhz,
                                                &arm_freq, &mem_manuf)) {
-               for (i = 0, mem = mem_timings; i < ARRAY_SIZE(mem_timings);
+               for (i = 0, mem = mem_params; i < ARRAY_SIZE(mem_params);
                                i++, mem++) {
                        if (mem->mem_type == mem_type &&
                                        mem->frequency_mhz ==

frequency_mhz &&

board/samsung/smdk5250/clock_init.c +4 -2
@@ -417,12 +360,14 @@ struct mem_timings *clock_get_mem_timings(void)
 void system_clock_init()
 {
        struct exynos5_clock *clk = (struct exynos5_clock
 *)EXYNOS5_CLOCK_BASE;
-       struct mem_timings *mem;
        struct arm_clk_ratios *arm_clk_ratio;
+       struct spl_clock_div *s_clk_div;
+       struct non_spl_clock_div *ns_clk_div;
        u32 val, tmp;
 
-       mem = clock_get_mem_timings();
        arm_clk_ratio = get_arm_ratios();
+       s_clk_div = clock_get_spl_div();
+       ns_clk_div = clock_get_non_spl_div();
 
        clrbits_le32(&clk->src_cpu, MUX_APLL_SEL_MASK);
        do {
board/samsung/smdk5250/clock_init.c +8 -4
@@ -499,28 +444,32 @@ void system_clock_init()
 
        /* Set MPLL */
        writel(MPLL_CON1_VAL, &clk->mpll_con1);
-       val = set_pll(mem->mpll_mdiv, mem->mpll_pdiv, mem->mpll_sdiv);
+       val = set_pll(s_clk_div->mpll_mdiv,
+                               s_clk_div->mpll_pdiv,
 s_clk_div->mpll_sdiv);
        writel(val, &clk->mpll_con0);
        while (readl(&clk->mpll_con0) & MPLL_CON0_LOCKED)
                ;
 
        /* Set BPLL */
        writel(BPLL_CON1_VAL, &clk->bpll_con1);
-       val = set_pll(mem->bpll_mdiv, mem->bpll_pdiv, mem->bpll_sdiv);
+       val = set_pll(s_clk_div->bpll_mdiv,
+                               s_clk_div->bpll_pdiv,
 s_clk_div->bpll_sdiv);
        writel(val, &clk->bpll_con0);
        while (readl(&clk->bpll_con0) & BPLL_CON0_LOCKED)
                ;
 
        /* Set CPLL */
        writel(CPLL_CON1_VAL, &clk->cpll_con1);
-       val = set_pll(mem->cpll_mdiv, mem->cpll_pdiv, mem->cpll_sdiv);
+       val = set_pll(ns_clk_div->cpll_mdiv,
+                               ns_clk_div->cpll_pdiv,
 ns_clk_div->cpll_sdiv);
        writel(val, &clk->cpll_con0);
        while (readl(&clk->cpll_con0) & CPLL_CON0_LOCKED)
                ;
 
        /* Set GPLL */
        writel(GPLL_CON1_VAL, &clk->gpll_con1);
-       val = set_pll(mem->gpll_mdiv, mem->gpll_pdiv, mem->gpll_sdiv);
+       val = set_pll(ns_clk_div->gpll_mdiv,
+                               ns_clk_div->gpll_pdiv,
ns_clk_div->gpll_sdiv);
        writel(val, &clk->gpll_con0);
        while (readl(&clk->gpll_con0) & GPLL_CON0_LOCKED)
                ;
board/samsung/smdk5250/clock_init.c +2 -1
@@ -528,7 +477,8 @@ void system_clock_init()
        /* Set EPLL */
        writel(EPLL_CON2_VAL, &clk->epll_con2);
        writel(EPLL_CON1_VAL, &clk->epll_con1);
-       val = set_pll(mem->epll_mdiv, mem->epll_pdiv, mem->epll_sdiv);
+       val = set_pll(ns_clk_div->epll_mdiv,
+                               ns_clk_div->epll_pdiv,
 ns_clk_div->epll_sdiv);
        writel(val, &clk->epll_con0);
        while (readl(&clk->epll_con0) & EPLL_CON0_LOCKED)
                ;
board/samsung/smdk5250/clock_init.c +2 -1
@@ -536,7 +486,8 @@ void system_clock_init()
        /* Set VPLL */
        writel(VPLL_CON2_VAL, &clk->vpll_con2);
        writel(VPLL_CON1_VAL, &clk->vpll_con1);
-       val = set_pll(mem->vpll_mdiv, mem->vpll_pdiv, mem->vpll_sdiv);
+       val = set_pll(ns_clk_div->vpll_mdiv,
+                               ns_clk_div->vpll_pdiv,
 ns_clk_div->vpll_sdiv);
        writel(val, &clk->vpll_con0);
        while (readl(&clk->vpll_con0) & VPLL_CON0_LOCKED)
                ;
board/samsung/smdk5250/clock_init.h +34 -19
index f751bcb..12b5c55 100644
@@ -47,19 +47,16 @@ struct arm_clk_ratios {
        unsigned arm_ratio;
 };
 
-/* These are the memory timings for a particular memory type and speed */
-struct mem_timings {
-       enum mem_manuf mem_manuf;       /* Memory manufacturer */
-       enum ddr_mode mem_type;         /* Memory type */
-       unsigned frequency_mhz;         /* Frequency of memory in MHz */
-
-       /* Here follow the timing parameters for the selected memory */
-       unsigned apll_mdiv;
-       unsigned apll_pdiv;
-       unsigned apll_sdiv;
+struct spl_clock_div {
        unsigned mpll_mdiv;
        unsigned mpll_pdiv;
        unsigned mpll_sdiv;
+       unsigned bpll_mdiv;
+       unsigned bpll_pdiv;
+       unsigned bpll_sdiv;
+};
+
+struct non_spl_clock_div {
        unsigned cpll_mdiv;
        unsigned cpll_pdiv;
        unsigned cpll_sdiv;
@@ -72,9 +69,11 @@ struct mem_timings {
        unsigned vpll_mdiv;
        unsigned vpll_pdiv;
        unsigned vpll_sdiv;
-       unsigned bpll_mdiv;
-       unsigned bpll_pdiv;
-       unsigned bpll_sdiv;
+};
+
+/* These are the memory timings for a particular memory type and speed */
+struct mem_timings {
+       /* Here follow the timing parameters for the selected memory */
        unsigned pclk_cdrex_ratio;
        unsigned direct_cmd_msr[MEM_TIMINGS_MSR_COUNT];
 
@@ -88,8 +87,6 @@ struct mem_timings {
        unsigned phy1_dqs;
        unsigned phy0_dq;
        unsigned phy1_dq;
-       unsigned phy0_tFS;
-       unsigned phy1_tFS;
        unsigned phy0_pulld_dqs;
        unsigned phy1_pulld_dqs;
 
@@ -111,10 +108,6 @@ struct mem_timings {
 
        unsigned rd_fetch;
 
-       unsigned zq_mode_dds;
-       unsigned zq_mode_term;
-       unsigned zq_mode_noterm;        /* 1 to allow termination disable
 */
-
        unsigned memcontrol;
        unsigned memconfig;
@@ -129,10 +122,32 @@ struct mem_timings {
        uint8_t chips_per_channel;      /* number of chips per channel */
        uint8_t chips_to_configure;     /* number of chips to configure */
        uint8_t send_zq_init;           /* 1 to send this command */
+};
+
+/* These are the memory timings for a particular memory type and speed */
+struct mem_params {
+       /* Here follow the memory parameters which differ with vendors */
+       enum mem_manuf mem_manuf;       /* Memory manufacturer */
+       enum ddr_mode mem_type;         /* Memory type */
+       unsigned frequency_mhz;         /* Frequency of memory in MHz */
+
+       unsigned direct_cmd_msr[MEM_TIMINGS_MSR_COUNT];
+
+       unsigned phy0_tFS;
+       unsigned phy1_tFS;
+
+       unsigned zq_mode_dds;
+       unsigned zq_mode_term;
+       unsigned zq_mode_noterm;        /* 1 to allow termination disable
 */
+
        unsigned impedance;             /* drive strength impedeance */
        uint8_t gate_leveling_enable;   /* check gate leveling is enabled
 */
 };
 
+struct spl_clock_div *clock_get_spl_div(void);
+
+struct non_spl_clock_div *clock_get_non_spl_div(void);
+
 /**

* Get the correct memory timings for our selected memory type and speed. *

board/samsung/smdk5250/clock_init.h +2 -0
@@ -142,6 +157,8 @@ struct mem_timings {
  */
 struct mem_timings *clock_get_mem_timings(void);
 
+struct mem_params *clock_get_mem_params(void);
+
 /*
  * Initialize clock for the device
  */
board/samsung/smdk5250/dmc_common.c +9 -7
index 109602a..1166cb7 100644
@@ -30,7 +30,7 @@
 
 #define ZQ_INIT_TIMEOUT        10000
 
-int dmc_config_zq(struct mem_timings *mem,
+int dmc_config_zq(struct mem_params *mparams,
                  struct exynos5_phy_control *phy0_ctrl,
                  struct exynos5_phy_control *phy1_ctrl)
 {
@@ -43,14 +43,14 @@ int dmc_config_zq(struct mem_timings *mem,
         * long calibration for manual calibration
         */
        val = PHY_CON16_RESET_VAL;
-       val |= mem->zq_mode_dds << PHY_CON16_ZQ_MODE_DDS_SHIFT;
-       val |= mem->zq_mode_term << PHY_CON16_ZQ_MODE_TERM_SHIFT;
+       val |= mparams->zq_mode_dds << PHY_CON16_ZQ_MODE_DDS_SHIFT;
+       val |= mparams->zq_mode_term << PHY_CON16_ZQ_MODE_TERM_SHIFT;
        val |= ZQ_CLK_DIV_EN;
        writel(val, &phy0_ctrl->phy_con16);
        writel(val, &phy1_ctrl->phy_con16);
 
        /* Disable termination */
-       if (mem->zq_mode_noterm)
+       if (mparams->zq_mode_noterm)
                val |= PHY_CON16_ZQ_MODE_NOTERM_MASK;
        writel(val, &phy0_ctrl->phy_con16);
        writel(val, &phy1_ctrl->phy_con16);
@@ -108,15 +108,17 @@ void update_reset_dll(struct exynos5_dmc *dmc, enum
 ddr_mode mode)
        writel(val, &dmc->phycontrol0);
 }
 
-void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc)
+void dmc_config_mrs(struct mem_timings *mtimings,
+                       struct mem_params *mparams,
+                       struct exynos5_dmc *dmc)
 {
        int channel, chip;
 
-       for (channel = 0; channel < mem->dmc_channels; channel++) {
+       for (channel = 0; channel < mtimings->dmc_channels; channel++) {
                unsigned long mask;
 
                mask = channel << DIRECT_CMD_CHANNEL_SHIFT;
-               for (chip = 0; chip < mem->chips_to_configure; chip++) {
+               for (chip = 0; chip < mtimings->chips_to_configure;
 chip++) {
                        int i;
                        mask |= chip << DIRECT_CMD_CHIP_SHIFT;
board/samsung/smdk5250/dmc_common.c +2 -2
@@ -133,12 +135,12 @@ void dmc_config_mrs(struct mem_timings *mem, struct
 exynos5_dmc *dmc)
 
                        /* Sending EMRS/MRS commands */
                        for (i = 0; i < MEM_TIMINGS_MSR_COUNT; i++) {
-                               writel(mem->direct_cmd_msr[i] | mask,
+                               writel(mparams->direct_cmd_msr[i] | mask,
                                       &dmc->directcmd);
                                sdelay(0x10000);
                        }
 
-                       if (mem->send_zq_init) {
+                       if (mtimings->send_zq_init) {
                                /* Sending ZQINIT command */
                                writel(DIRECT_CMD_ZQINIT | mask,
                                       &dmc->directcmd);
board/samsung/smdk5250/dmc_common.c +3 -3
@@ -149,15 +151,15 @@ void dmc_config_mrs(struct mem_timings *mem, struct
 exynos5_dmc *dmc)
        }
 }
 
-void dmc_config_prech(struct mem_timings *mem, struct exynos5_dmc *dmc)
+void dmc_config_prech(struct mem_timings *mtimings, struct exynos5_dmc
 *dmc)
 {
        int channel, chip;
 
-       for (channel = 0; channel < mem->dmc_channels; channel++) {
+       for (channel = 0; channel < mtimings->dmc_channels; channel++) {
                unsigned long mask;
 
                mask = channel << DIRECT_CMD_CHANNEL_SHIFT;
-               for (chip = 0; chip < mem->chips_per_channel; chip++) {
+               for (chip = 0; chip < mtimings->chips_per_channel; chip++)
 {
                        mask |= chip << DIRECT_CMD_CHIP_SHIFT;

                        /* PALL (all banks precharge) CMD */
board/samsung/smdk5250/dmc_common.c +3 -3
@@ -167,10 +169,10 @@ void dmc_config_prech(struct mem_timings *mem,
 struct exynos5_dmc *dmc)
        }
 }
 
-void dmc_config_memory(struct mem_timings *mem, struct exynos5_dmc *dmc)
+void dmc_config_memory(struct mem_timings *mtimings, struct exynos5_dmc
 *dmc)
 {
-       writel(mem->memconfig, &dmc->memconfig0);
-       writel(mem->memconfig, &dmc->memconfig1);
+       writel(mtimings->memconfig, &dmc->memconfig0);
+       writel(mtimings->memconfig, &dmc->memconfig1);
        writel(DMC_MEMBASECONFIG0_VAL, &dmc->membaseconfig0);
        writel(DMC_MEMBASECONFIG1_VAL, &dmc->membaseconfig1);

}

board/samsung/smdk5250/dmc_common.c +4 -2
@@ -178,14 +180,16 @@ void dmc_config_memory(struct mem_timings *mem,
 struct exynos5_dmc *dmc)
 void mem_ctrl_init()
 {
        struct spl_machine_param *param = spl_get_machine_params();
-       struct mem_timings *mem;
+       struct mem_timings *mtimings;
+       struct mem_params *mparams;
        int ret;
 
-       mem = clock_get_mem_timings();
+       mtimings = clock_get_mem_timings();
+       mparams = clock_get_mem_params();
 
        /* If there are any other memory variant, add their init call

below */

        if (param->mem_type == DDR_MODE_DDR3) {
board/samsung/smdk5250/dmc_common.c +1 -1
-               ret = ddr3_mem_ctrl_init(mem, param->mem_iv_size);
+               ret = ddr3_mem_ctrl_init(mtimings, mparams,
param->mem_iv_size);
                if (ret) {
                        /* will hang if failed to init memory control */
                        while (1)
board/samsung/smdk5250/dmc_init_ddr3.c +22 -22
index e050790..7f4cb3c 100644
@@ -40,7 +40,9 @@ static void reset_phy_ctrl(void)
        writel(DDR3PHY_CTRL_PHY_RESET, &clk->lpddr3phy_ctrl);
 }
 
-int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long mem_iv_size)
+int ddr3_mem_ctrl_init(struct mem_timings *mtimings,
+                       struct mem_params *mparams,
+                       unsigned long mem_iv_size)
 {
        unsigned int val;
        struct exynos5_phy_control *phy0_ctrl, *phy1_ctrl;
@@ -54,93 +56,95 @@ int ddr3_mem_ctrl_init(struct mem_timings *mem,
 unsigned long mem_iv_size)
        reset_phy_ctrl();
 
        /* Set Impedance Output Driver */
-       val = (mem->impedance << CA_CK_DRVR_DS_OFFSET) |
-               (mem->impedance << CA_CKE_DRVR_DS_OFFSET) |
-               (mem->impedance << CA_CS_DRVR_DS_OFFSET) |
-               (mem->impedance << CA_ADR_DRVR_DS_OFFSET);
+       val = (mparams->impedance << CA_CK_DRVR_DS_OFFSET) |
+               (mparams->impedance << CA_CKE_DRVR_DS_OFFSET) |
+               (mparams->impedance << CA_CS_DRVR_DS_OFFSET) |
+               (mparams->impedance << CA_ADR_DRVR_DS_OFFSET);
        writel(val, &phy0_ctrl->phy_con39);
        writel(val, &phy1_ctrl->phy_con39);
 
        /* Set Read Latency and Burst Length for PHY0 and PHY1 */
-       val = (mem->ctrl_bstlen << PHY_CON42_CTRL_BSTLEN_SHIFT) |
-               (mem->ctrl_rdlat << PHY_CON42_CTRL_RDLAT_SHIFT);
+       val = (mtimings->ctrl_bstlen << PHY_CON42_CTRL_BSTLEN_SHIFT) |
+               (mtimings->ctrl_rdlat << PHY_CON42_CTRL_RDLAT_SHIFT);
        writel(val, &phy0_ctrl->phy_con42);
        writel(val, &phy1_ctrl->phy_con42);
 
        /* ZQ Calibration */
-       if (dmc_config_zq(mem, phy0_ctrl, phy1_ctrl))
+       if (dmc_config_zq(mparams, phy0_ctrl, phy1_ctrl))
                return SETUP_ERR_ZQ_CALIBRATION_FAILURE;
 
        /* DQ Signal */
-       writel(mem->phy0_pulld_dqs, &phy0_ctrl->phy_con14);
-       writel(mem->phy1_pulld_dqs, &phy1_ctrl->phy_con14);
+       writel(mtimings->phy0_pulld_dqs, &phy0_ctrl->phy_con14);
+       writel(mtimings->phy1_pulld_dqs, &phy1_ctrl->phy_con14);
 
-       writel(mem->concontrol | (mem->rd_fetch <<
 CONCONTROL_RD_FETCH_SHIFT)
-               | (mem->dfi_init_start << CONCONTROL_DFI_INIT_START_SHIFT),
+       writel(mtimings->concontrol
+               | (mtimings->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)
+               | (mtimings->dfi_init_start <<
 CONCONTROL_DFI_INIT_START_SHIFT),
                &dmc->concontrol);
 
        update_reset_dll(dmc, DDR_MODE_DDR3);
 
        /* DQS Signal */
-       writel(mem->phy0_dqs, &phy0_ctrl->phy_con4);
-       writel(mem->phy1_dqs, &phy1_ctrl->phy_con4);
+       writel(mtimings->phy0_dqs, &phy0_ctrl->phy_con4);
+       writel(mtimings->phy1_dqs, &phy1_ctrl->phy_con4);
 
-       writel(mem->phy0_dq, &phy0_ctrl->phy_con6);
-       writel(mem->phy1_dq, &phy1_ctrl->phy_con6);
+       writel(mtimings->phy0_dq, &phy0_ctrl->phy_con6);
+       writel(mtimings->phy1_dq, &phy1_ctrl->phy_con6);
 
-       writel(mem->phy0_tFS, &phy0_ctrl->phy_con10);
-       writel(mem->phy1_tFS, &phy1_ctrl->phy_con10);
+       writel(mparams->phy0_tFS, &phy0_ctrl->phy_con10);
+       writel(mparams->phy1_tFS, &phy1_ctrl->phy_con10);
 
-       val = (mem->ctrl_start_point << PHY_CON12_CTRL_START_POINT_SHIFT) |
-               (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
-               (mem->ctrl_dll_on << PHY_CON12_CTRL_DLL_ON_SHIFT) |
-               (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
+       val = (mtimings->ctrl_start_point <<

PHY_CON12_CTRL_START_POINT_SHIFT) |

board/samsung/smdk5250/dmc_init_ddr3.c +5 -3
+               (mtimings->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
+               (mtimings->ctrl_dll_on << PHY_CON12_CTRL_DLL_ON_SHIFT) |
+               (mtimings->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
        writel(val, &phy0_ctrl->phy_con12);
        writel(val, &phy1_ctrl->phy_con12);
 
        /* Start DLL locking */
-       writel(val | (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
+       writel(val | (mtimings->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
                &phy0_ctrl->phy_con12);
-       writel(val | (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
+       writel(val | (mtimings->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
                &phy1_ctrl->phy_con12);
 
        update_reset_dll(dmc, DDR_MODE_DDR3);
 
-       writel(mem->concontrol | (mem->rd_fetch <<

CONCONTROL_RD_FETCH_SHIFT),

board/samsung/smdk5250/dmc_init_ddr3.c +20 -20
+       writel(mtimings->concontrol
+               | (mtimings->rd_fetch << CONCONTROL_RD_FETCH_SHIFT),
                &dmc->concontrol);
 
        /* Memory Channel Inteleaving Size */
-       writel(mem->iv_size, &dmc->ivcontrol);
+       writel(mtimings->iv_size, &dmc->ivcontrol);
 
-       writel(mem->memconfig, &dmc->memconfig0);
-       writel(mem->memconfig, &dmc->memconfig1);
-       writel(mem->membaseconfig0, &dmc->membaseconfig0);
-       writel(mem->membaseconfig1, &dmc->membaseconfig1);
+       writel(mtimings->memconfig, &dmc->memconfig0);
+       writel(mtimings->memconfig, &dmc->memconfig1);
+       writel(mtimings->membaseconfig0, &dmc->membaseconfig0);
+       writel(mtimings->membaseconfig1, &dmc->membaseconfig1);
 
        /* Precharge Configuration */
-       writel(mem->prechconfig_tp_cnt << PRECHCONFIG_TP_CNT_SHIFT,
+       writel(mtimings->prechconfig_tp_cnt << PRECHCONFIG_TP_CNT_SHIFT,
                &dmc->prechconfig);
 
        /* Power Down mode Configuration */
-       writel(mem->dpwrdn_cyc << PWRDNCONFIG_DPWRDN_CYC_SHIFT |
-               mem->dsref_cyc << PWRDNCONFIG_DSREF_CYC_SHIFT,
+       writel(mtimings->dpwrdn_cyc << PWRDNCONFIG_DPWRDN_CYC_SHIFT |
+               mtimings->dsref_cyc << PWRDNCONFIG_DSREF_CYC_SHIFT,
                &dmc->pwrdnconfig);
 
        /* TimingRow, TimingData, TimingPower and Timingaref
         * values as per Memory AC parameters
         */
-       writel(mem->timing_ref, &dmc->timingref);
-       writel(mem->timing_row, &dmc->timingrow);
-       writel(mem->timing_data, &dmc->timingdata);
-       writel(mem->timing_power, &dmc->timingpower);
+       writel(mtimings->timing_ref, &dmc->timingref);
+       writel(mtimings->timing_row, &dmc->timingrow);
+       writel(mtimings->timing_data, &dmc->timingdata);
+       writel(mtimings->timing_power, &dmc->timingpower);
 
        /* Send PALL command */
-       dmc_config_prech(mem, dmc);
+       dmc_config_prech(mtimings, dmc);
 
        /* Send NOP, MRS and ZQINIT commands */
-       dmc_config_mrs(mem, dmc);
+       dmc_config_mrs(mtimings, mparams, dmc);
 
-       if (mem->gate_leveling_enable) {
+       if (mparams->gate_leveling_enable) {
                val = PHY_CON0_RESET_VAL;
                val |= P0_CMD_EN;
                writel(val, &phy0_ctrl->phy_con0);
@@ -157,12 +161,12 @@ int ddr3_mem_ctrl_init(struct mem_timings *mem,
 unsigned long mem_iv_size)
                writel(val, &phy0_ctrl->phy_con0);
                writel(val, &phy1_ctrl->phy_con0);
 
-               val = (mem->ctrl_start_point <<
+               val = (mtimings->ctrl_start_point <<
                                PHY_CON12_CTRL_START_POINT_SHIFT) |
-                       (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
-                       (mem->ctrl_force << PHY_CON12_CTRL_FORCE_SHIFT) |
-                       (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT) |
-                       (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
+                       (mtimings->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
+                       (mtimings->ctrl_force <<

PHY_CON12_CTRL_FORCE_SHIFT) |
+ (mtimings->ctrl_start <<
PHY_CON12_CTRL_START_SHIFT) |

board/samsung/smdk5250/dmc_init_ddr3.c +4 -6
+                       (mtimings->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
                writel(val, &phy0_ctrl->phy_con12);
                writel(val, &phy1_ctrl->phy_con12);
@@ -203,13 +207,13 @@ int ddr3_mem_ctrl_init(struct mem_timings *mem,
 unsigned long mem_iv_size)
                writel(0, &phy0_ctrl->phy_con14);
                writel(0, &phy1_ctrl->phy_con14);
 
-               val = (mem->ctrl_start_point <<
+               val = (mtimings->ctrl_start_point <<
                                PHY_CON12_CTRL_START_POINT_SHIFT) |
-                       (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
-                       (mem->ctrl_force << PHY_CON12_CTRL_FORCE_SHIFT) |
-                       (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT) |
-                       (mem->ctrl_dll_on << PHY_CON12_CTRL_DLL_ON_SHIFT) |
-                       (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
+                       (mtimings->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
+                       (mtimings->ctrl_force <<

PHY_CON12_CTRL_FORCE_SHIFT) |
+ (mtimings->ctrl_start <<
PHY_CON12_CTRL_START_SHIFT) |
+ (mtimings->ctrl_dll_on <<
PHY_CON12_CTRL_DLL_ON_SHIFT) |

board/samsung/smdk5250/dmc_init_ddr3.c +3 -4
+                       (mtimings->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
                writel(val, &phy0_ctrl->phy_con12);
                writel(val, &phy1_ctrl->phy_con12);
@@ -217,12 +221,14 @@ int ddr3_mem_ctrl_init(struct mem_timings *mem,
 unsigned long mem_iv_size)
        }
 
        /* Send PALL command */
-       dmc_config_prech(mem, dmc);
+       dmc_config_prech(mtimings, dmc);
 
-       writel(mem->memcontrol, &dmc->memcontrol);
+       writel(mtimings->memcontrol, &dmc->memcontrol);
 
        /* Set DMC Concontrol and enable auto-refresh counter */
-       writel(mem->concontrol | (mem->rd_fetch <<
 CONCONTROL_RD_FETCH_SHIFT)
-               | (mem->aref_en << CONCONTROL_AREF_EN_SHIFT),

&dmc->concontrol);

board/samsung/smdk5250/dmc_init_ddr3.c +4 -0
+       writel(mtimings->concontrol
+               | (mtimings->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)
+               | (mtimings->aref_en << CONCONTROL_AREF_EN_SHIFT),
+               &dmc->concontrol);
        return 0;
 }
board/samsung/smdk5250/setup.h +4 -1
index a159601..b30d7d0 100644
@@ -521,6 +521,7 @@
 #define PHY_CON42_CTRL_RDLAT_SHIFT     0
 
 struct mem_timings;
+struct mem_params;
 
 /* Errors that we can encourter in low-level setup */
 enum {
@@ -539,7 +540,9 @@ enum {
  *                     accesses; may vary across boards.
  * @return 0 if ok, SETUP_ERR_... if there is a problem
  */
-int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long
 mem_iv_size);
+int ddr3_mem_ctrl_init(struct mem_timings *mtimings,
+                       struct mem_params *mparams,
+                       unsigned long mem_iv_size);
 
 /*

* Configure ZQ I/O interface

board/samsung/smdk5250/setup.h +5 -3
@@ -549,7 +552,7 @@ int ddr3_mem_ctrl_init(struct mem_timings *mem,
 unsigned long mem_iv_size);
  * @param phy1_ctrl    Pointer to struct containing PHY1 control reg
  * @return 0 if ok, -1 on error
  */
-int dmc_config_zq(struct mem_timings *mem,
+int dmc_config_zq(struct mem_params *mparams,
                  struct exynos5_phy_control *phy0_ctrl,
                  struct exynos5_phy_control *phy1_ctrl);
@@ -559,7 +562,9 @@ int dmc_config_zq(struct mem_timings *mem,
  * @param mem          Memory timings for this memory type.
  * @param dmc          Pointer to struct of DMC registers
  */
-void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc);
+void dmc_config_mrs(struct mem_timings *mtimings,
+                       struct mem_params *mparams,
+                       struct exynos5_dmc *dmc);
 
 /*
  * Send PALL Direct commands
@@ -567,7 +572,7 @@ void dmc_config_mrs(struct mem_timings *mem, struct
 exynos5_dmc *dmc);
  * @param mem          Memory timings for this memory type.
  * @param dmc          Pointer to struct of DMC registers
  */
-void dmc_config_prech(struct mem_timings *mem, struct exynos5_dmc *dmc);
+void dmc_config_prech(struct mem_timings *mtimings, struct exynos5_dmc
 *dmc);
 

/*
* Configure the memconfig and membaseconfig registers

board/samsung/smdk5250/setup.h +1 -1
@@ -575,7 +580,7 @@ void dmc_config_prech(struct mem_timings *mem, struct
 exynos5_dmc *dmc);
  * @param mem          Memory timings for this memory type.
  * @param exynos5_dmc  Pointer to struct of DMC registers
  */
-void dmc_config_memory(struct mem_timings *mem, struct exynos5_dmc *dmc);
+void dmc_config_memory(struct mem_timings *mtimings, struct exynos5_dmc
 *dmc);
 

/*
* Reset the DLL. This function is common between DDR3 and LPDDR2.
--
1.8.0

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#3 lore raw

PATCH v2 1/2 Exynos5: spl: Reorganize mem_timing struct to gain space in spl

In reply to Akshay Saraswat

Hi Akshay,

Quoted 30 lines · Akshay Saraswat

Distributes struct mem_timings into new different structures to gain space in spl by removing necessity of maintaining two big and almost similar mem_timings instances.

---
Changes since v1:
- None.

 board/samsung/smdk5250/clock_init.c    | 177 ++++++++++++---------------------
 board/samsung/smdk5250/clock_init.h    |  55 ++++++----
 board/samsung/smdk5250/dmc_common.c    |  40 ++++----
 board/samsung/smdk5250/dmc_init_ddr3.c | 116 +++++++++++----------
 board/samsung/smdk5250/setup.h         |  15 ++-
 5 files changed, 193 insertions(+), 210 deletions(-)
board/samsung/smdk5250/clock_init.c +1 -5
index c009ae5..30cbdcf 100644
@@ -127,14 +127,17 @@ struct arm_clk_ratios arm_clk_ratios[] = {
                .arm_ratio = 0x0,
        }
 };
-struct mem_timings mem_timings[] = {
-       {
-               .mem_manuf = MEM_MANUF_ELPIDA,
-               .mem_type = DDR_MODE_DDR3,
-               .frequency_mhz = 800,
+

board/samsung/smdk5250/clock_init.c struct arm_clk_ratios arm_clk_ratios[] = { · line 140

Quoted 10 lines
board/samsung/smdk5250/clock_init.c +7 -0
+struct spl_clock_div spl_clock_div = {
                .mpll_mdiv = 0xc8,
                .mpll_pdiv = 0x3,
                .mpll_sdiv = 0x0,
+               .bpll_mdiv = 0x64,
+               .bpll_pdiv = 0x3,
+               .bpll_sdiv = 0x0,
+};
+
+struct non_spl_clock_div non_spl_clock_div = {

Perhaps just clock_div, instead of non_spl_clock_div.

Quoted 352 lines
board/samsung/smdk5250/clock_init.c +56 -108
                .cpll_mdiv = 0xde,
                .cpll_pdiv = 0x4,
                .cpll_sdiv = 0x2,
@@ -147,14 +150,10 @@ struct mem_timings mem_timings[] = {
                .vpll_mdiv = 0x96,
                .vpll_pdiv = 0x3,
                .vpll_sdiv = 0x2,
+};
 
-               .bpll_mdiv = 0x64,
-               .bpll_pdiv = 0x3,
-               .bpll_sdiv = 0x0,
+struct mem_timings mem_timings = {
                .pclk_cdrex_ratio = 0x5,
-               .direct_cmd_msr = {
-                       0x00020018, 0x00030000, 0x00010042, 0x00000d70
-               },
                .timing_ref = 0x000000bb,
                .timing_row = 0x8c36650e,
                .timing_data = 0x3630580b,
@@ -163,8 +162,6 @@ struct mem_timings mem_timings[] = {
                .phy1_dqs = 0x08080808,
                .phy0_dq = 0x08080808,
                .phy1_dq = 0x08080808,
-               .phy0_tFS = 0x4,
-               .phy1_tFS = 0x4,
                .phy0_pulld_dqs = 0xf,
                .phy1_pulld_dqs = 0xf,
 
@@ -186,10 +183,6 @@ struct mem_timings mem_timings[] = {
 
                .rd_fetch = 0x3,
 
-               .zq_mode_dds = 0x7,
-               .zq_mode_term = 0x1,
-               .zq_mode_noterm = 0,
-
                /*
                * Dynamic Clock: Always Running
                * Memory Burst length: 8
@@ -229,114 +222,49 @@ struct mem_timings mem_timings[] = {
                .chips_per_channel = 2,
                .chips_to_configure = 1,
                .send_zq_init = 1,
+};
+
+struct mem_params mem_params[] = {
+       {
+               .mem_manuf = MEM_MANUF_ELPIDA,
+               .mem_type = DDR_MODE_DDR3,
+               .frequency_mhz = 800,
+
+               .direct_cmd_msr = {
+                       0x00020018, 0x00030000, 0x00010042, 0x00000d70
+               },
+
+               .phy0_tFS = 0x4,
+               .phy1_tFS = 0x4,
+
+               .zq_mode_dds = 0x7,
+               .zq_mode_term = 0x1,
+               .zq_mode_noterm = 0,
+
                .impedance = IMP_OUTPUT_DRV_30_OHM,
                .gate_leveling_enable = 0,
        }, {
                .mem_manuf = MEM_MANUF_SAMSUNG,
                .mem_type = DDR_MODE_DDR3,
                .frequency_mhz = 800,
-               .mpll_mdiv = 0xc8,
-               .mpll_pdiv = 0x3,
-               .mpll_sdiv = 0x0,
-               .cpll_mdiv = 0xde,
-               .cpll_pdiv = 0x4,
-               .cpll_sdiv = 0x2,
-               .gpll_mdiv = 0x215,
-               .gpll_pdiv = 0xc,
-               .gpll_sdiv = 0x1,
-               .epll_mdiv = 0x60,
-               .epll_pdiv = 0x3,
-               .epll_sdiv = 0x3,
-               .vpll_mdiv = 0x96,
-               .vpll_pdiv = 0x3,
-               .vpll_sdiv = 0x2,
 
-               .bpll_mdiv = 0x64,
-               .bpll_pdiv = 0x3,
-               .bpll_sdiv = 0x0,
-               .pclk_cdrex_ratio = 0x5,
                .direct_cmd_msr = {
                        0x00020018, 0x00030000, 0x00010000, 0x00000d70
                },
-               .timing_ref = 0x000000bb,
-               .timing_row = 0x8c36650e,
-               .timing_data = 0x3630580b,
-               .timing_power = 0x41000a44,
-               .phy0_dqs = 0x08080808,
-               .phy1_dqs = 0x08080808,
-               .phy0_dq = 0x08080808,
-               .phy1_dq = 0x08080808,
+
                .phy0_tFS = 0x8,
                .phy1_tFS = 0x8,
-               .phy0_pulld_dqs = 0xf,
-               .phy1_pulld_dqs = 0xf,
-
-               .lpddr3_ctrl_phy_reset = 0x1,
-               .ctrl_start_point = 0x10,
-               .ctrl_inc = 0x10,
-               .ctrl_start = 0x1,
-               .ctrl_dll_on = 0x1,
-               .ctrl_ref = 0x8,
-
-               .ctrl_force = 0x1a,
-               .ctrl_rdlat = 0x0b,
-               .ctrl_bstlen = 0x08,
-
-               .fp_resync = 0x8,
-               .iv_size = 0x7,
-               .dfi_init_start = 1,
-               .aref_en = 1,
-
-               .rd_fetch = 0x3,
 
                .zq_mode_dds = 0x5,
                .zq_mode_term = 0x1,
                .zq_mode_noterm = 1,
 
-               /*
-               * Dynamic Clock: Always Running
-               * Memory Burst length: 8
-               * Number of chips: 1
-               * Memory Bus width: 32 bit
-               * Memory Type: DDR3
-               * Additional Latancy for PLL: 0 Cycle
-               */
-               .memcontrol = DMC_MEMCONTROL_CLK_STOP_DISABLE |
-                       DMC_MEMCONTROL_DPWRDN_DISABLE |
-                       DMC_MEMCONTROL_DPWRDN_ACTIVE_PRECHARGE |
-                       DMC_MEMCONTROL_TP_DISABLE |
-                       DMC_MEMCONTROL_DSREF_ENABLE |
-                       DMC_MEMCONTROL_ADD_LAT_PALL_CYCLE(0) |
-                       DMC_MEMCONTROL_MEM_TYPE_DDR3 |
-                       DMC_MEMCONTROL_MEM_WIDTH_32BIT |
-                       DMC_MEMCONTROL_NUM_CHIP_1 |
-                       DMC_MEMCONTROL_BL_8 |
-                       DMC_MEMCONTROL_PZQ_DISABLE |
-                       DMC_MEMCONTROL_MRR_BYTE_7_0,
-               .memconfig = DMC_MEMCONFIGx_CHIP_MAP_INTERLEAVED |
-                       DMC_MEMCONFIGx_CHIP_COL_10 |
-                       DMC_MEMCONFIGx_CHIP_ROW_15 |
-                       DMC_MEMCONFIGx_CHIP_BANK_8,
-               .membaseconfig0 = DMC_MEMBASECONFIG_VAL(0x40),
-               .membaseconfig1 = DMC_MEMBASECONFIG_VAL(0x80),
-               .prechconfig_tp_cnt = 0xff,
-               .dpwrdn_cyc = 0xff,
-               .dsref_cyc = 0xffff,
-               .concontrol = DMC_CONCONTROL_DFI_INIT_START_DISABLE |
-                       DMC_CONCONTROL_TIMEOUT_LEVEL0 |
-                       DMC_CONCONTROL_RD_FETCH_DISABLE |
-                       DMC_CONCONTROL_EMPTY_DISABLE |
-                       DMC_CONCONTROL_AREF_EN_DISABLE |
-                       DMC_CONCONTROL_IO_PD_CON_DISABLE,
-               .dmc_channels = 2,
-               .chips_per_channel = 2,
-               .chips_to_configure = 1,
-               .send_zq_init = 1,
                .impedance = IMP_OUTPUT_DRV_40_OHM,
                .gate_leveling_enable = 1,
        }
 };
 
+
 /**
  * Get the required memory type and speed (SPL version).
  *
@@ -388,9 +316,24 @@ struct arm_clk_ratios *get_arm_ratios(void)
        return NULL;
 }
 
+struct spl_clock_div *clock_get_spl_div(void)
+{
+       return &spl_clock_div;
+}
+
+struct non_spl_clock_div *clock_get_non_spl_div(void)
+{
+       return &non_spl_clock_div;
+}
+
 struct mem_timings *clock_get_mem_timings(void)
 {
-       struct mem_timings *mem;
+       return &mem_timings;
+}
+
+struct mem_params *clock_get_mem_params(void)
+{
+       struct mem_params *mem;
        enum ddr_mode mem_type;
        enum mem_manuf mem_manuf;
        unsigned frequency_mhz, arm_freq;
@@ -398,7 +341,7 @@ struct mem_timings *clock_get_mem_timings(void)
 
        if (!clock_get_mem_selection(&mem_type, &frequency_mhz,
                                                &arm_freq, &mem_manuf)) {
-               for (i = 0, mem = mem_timings; i < ARRAY_SIZE(mem_timings);
+               for (i = 0, mem = mem_params; i < ARRAY_SIZE(mem_params);
                                i++, mem++) {
                        if (mem->mem_type == mem_type &&
                                        mem->frequency_mhz == frequency_mhz &&
@@ -417,12 +360,14 @@ struct mem_timings *clock_get_mem_timings(void)
 void system_clock_init()
 {
        struct exynos5_clock *clk = (struct exynos5_clock *)EXYNOS5_CLOCK_BASE;
-       struct mem_timings *mem;
        struct arm_clk_ratios *arm_clk_ratio;
+       struct spl_clock_div *s_clk_div;
+       struct non_spl_clock_div *ns_clk_div;
        u32 val, tmp;
 
-       mem = clock_get_mem_timings();
        arm_clk_ratio = get_arm_ratios();
+       s_clk_div = clock_get_spl_div();
+       ns_clk_div = clock_get_non_spl_div();
 
        clrbits_le32(&clk->src_cpu, MUX_APLL_SEL_MASK);
        do {
@@ -499,28 +444,32 @@ void system_clock_init()
 
        /* Set MPLL */
        writel(MPLL_CON1_VAL, &clk->mpll_con1);
-       val = set_pll(mem->mpll_mdiv, mem->mpll_pdiv, mem->mpll_sdiv);
+       val = set_pll(s_clk_div->mpll_mdiv,
+                               s_clk_div->mpll_pdiv, s_clk_div->mpll_sdiv);
        writel(val, &clk->mpll_con0);
        while (readl(&clk->mpll_con0) & MPLL_CON0_LOCKED)
                ;
 
        /* Set BPLL */
        writel(BPLL_CON1_VAL, &clk->bpll_con1);
-       val = set_pll(mem->bpll_mdiv, mem->bpll_pdiv, mem->bpll_sdiv);
+       val = set_pll(s_clk_div->bpll_mdiv,
+                               s_clk_div->bpll_pdiv, s_clk_div->bpll_sdiv);
        writel(val, &clk->bpll_con0);
        while (readl(&clk->bpll_con0) & BPLL_CON0_LOCKED)
                ;
 
        /* Set CPLL */
        writel(CPLL_CON1_VAL, &clk->cpll_con1);
-       val = set_pll(mem->cpll_mdiv, mem->cpll_pdiv, mem->cpll_sdiv);
+       val = set_pll(ns_clk_div->cpll_mdiv,
+                               ns_clk_div->cpll_pdiv, ns_clk_div->cpll_sdiv);
        writel(val, &clk->cpll_con0);
        while (readl(&clk->cpll_con0) & CPLL_CON0_LOCKED)
                ;
 
        /* Set GPLL */
        writel(GPLL_CON1_VAL, &clk->gpll_con1);
-       val = set_pll(mem->gpll_mdiv, mem->gpll_pdiv, mem->gpll_sdiv);
+       val = set_pll(ns_clk_div->gpll_mdiv,
+                               ns_clk_div->gpll_pdiv, ns_clk_div->gpll_sdiv);
        writel(val, &clk->gpll_con0);
        while (readl(&clk->gpll_con0) & GPLL_CON0_LOCKED)
                ;
@@ -528,7 +477,8 @@ void system_clock_init()
        /* Set EPLL */
        writel(EPLL_CON2_VAL, &clk->epll_con2);
        writel(EPLL_CON1_VAL, &clk->epll_con1);
-       val = set_pll(mem->epll_mdiv, mem->epll_pdiv, mem->epll_sdiv);
+       val = set_pll(ns_clk_div->epll_mdiv,
+                               ns_clk_div->epll_pdiv, ns_clk_div->epll_sdiv);
        writel(val, &clk->epll_con0);
        while (readl(&clk->epll_con0) & EPLL_CON0_LOCKED)
                ;
@@ -536,7 +486,8 @@ void system_clock_init()
        /* Set VPLL */
        writel(VPLL_CON2_VAL, &clk->vpll_con2);
        writel(VPLL_CON1_VAL, &clk->vpll_con1);
-       val = set_pll(mem->vpll_mdiv, mem->vpll_pdiv, mem->vpll_sdiv);
+       val = set_pll(ns_clk_div->vpll_mdiv,
+                               ns_clk_div->vpll_pdiv, ns_clk_div->vpll_sdiv);
        writel(val, &clk->vpll_con0);
        while (readl(&clk->vpll_con0) & VPLL_CON0_LOCKED)
                ;
board/samsung/smdk5250/clock_init.h +12 -19
index f751bcb..12b5c55 100644
@@ -47,19 +47,16 @@ struct arm_clk_ratios {
        unsigned arm_ratio;
 };
 
-/* These are the memory timings for a particular memory type and speed */
-struct mem_timings {
-       enum mem_manuf mem_manuf;       /* Memory manufacturer */
-       enum ddr_mode mem_type;         /* Memory type */
-       unsigned frequency_mhz;         /* Frequency of memory in MHz */
-
-       /* Here follow the timing parameters for the selected memory */
-       unsigned apll_mdiv;
-       unsigned apll_pdiv;
-       unsigned apll_sdiv;
+struct spl_clock_div {
        unsigned mpll_mdiv;
        unsigned mpll_pdiv;
        unsigned mpll_sdiv;
+       unsigned bpll_mdiv;
+       unsigned bpll_pdiv;
+       unsigned bpll_sdiv;
+};
+
+struct non_spl_clock_div {
        unsigned cpll_mdiv;
        unsigned cpll_pdiv;
        unsigned cpll_sdiv;
@@ -72,9 +69,11 @@ struct mem_timings {
        unsigned vpll_mdiv;
        unsigned vpll_pdiv;
        unsigned vpll_sdiv;
-       unsigned bpll_mdiv;
-       unsigned bpll_pdiv;
-       unsigned bpll_sdiv;
+};
+
+/* These are the memory timings for a particular memory type and speed */
+struct mem_timings {
+       /* Here follow the timing parameters for the selected memory */
        unsigned pclk_cdrex_ratio;
        unsigned direct_cmd_msr[MEM_TIMINGS_MSR_COUNT];
 
@@ -88,8 +87,6 @@ struct mem_timings {
        unsigned phy1_dqs;
        unsigned phy0_dq;
        unsigned phy1_dq;
-       unsigned phy0_tFS;
-       unsigned phy1_tFS;
        unsigned phy0_pulld_dqs;
        unsigned phy1_pulld_dqs;
 
@@ -111,10 +108,6 @@ struct mem_timings {
 
        unsigned rd_fetch;
 
-       unsigned zq_mode_dds;
-       unsigned zq_mode_term;
-       unsigned zq_mode_noterm;        /* 1 to allow termination disable */
-
        unsigned memcontrol;
        unsigned memconfig;
 

board/samsung/smdk5250/clock_init.h struct mem_timings { · line 127

Quoted 6 lines
board/samsung/smdk5250/clock_init.h +3 -0
@@ -129,10 +122,32 @@ struct mem_timings {
        uint8_t chips_per_channel;      /* number of chips per channel */
        uint8_t chips_to_configure;     /* number of chips to configure */
        uint8_t send_zq_init;           /* 1 to send this command */
+};
+
+/* These are the memory timings for a particular memory type and speed */

This is the same comment as for struct mem_timings. What exactly is the difference?

Quoted 424 lines
board/samsung/smdk5250/clock_init.h +21 -0
+struct mem_params {
+       /* Here follow the memory parameters which differ with vendors */
+       enum mem_manuf mem_manuf;       /* Memory manufacturer */
+       enum ddr_mode mem_type;         /* Memory type */
+       unsigned frequency_mhz;         /* Frequency of memory in MHz */
+
+       unsigned direct_cmd_msr[MEM_TIMINGS_MSR_COUNT];
+
+       unsigned phy0_tFS;
+       unsigned phy1_tFS;
+
+       unsigned zq_mode_dds;
+       unsigned zq_mode_term;
+       unsigned zq_mode_noterm;        /* 1 to allow termination disable */
+
        unsigned impedance;             /* drive strength impedeance */
        uint8_t gate_leveling_enable;   /* check gate leveling is enabled */
 };
 
+struct spl_clock_div *clock_get_spl_div(void);
+
+struct non_spl_clock_div *clock_get_non_spl_div(void);
+
 /**
  * Get the correct memory timings for our selected memory type and speed.
  *
@@ -142,6 +157,8 @@ struct mem_timings {
  */
 struct mem_timings *clock_get_mem_timings(void);
 
+struct mem_params *clock_get_mem_params(void);
+
 /*
  * Initialize clock for the device
  */
board/samsung/smdk5250/dmc_common.c +22 -18
index 109602a..1166cb7 100644
@@ -30,7 +30,7 @@
 
 #define ZQ_INIT_TIMEOUT        10000
 
-int dmc_config_zq(struct mem_timings *mem,
+int dmc_config_zq(struct mem_params *mparams,
                  struct exynos5_phy_control *phy0_ctrl,
                  struct exynos5_phy_control *phy1_ctrl)
 {
@@ -43,14 +43,14 @@ int dmc_config_zq(struct mem_timings *mem,
         * long calibration for manual calibration
         */
        val = PHY_CON16_RESET_VAL;
-       val |= mem->zq_mode_dds << PHY_CON16_ZQ_MODE_DDS_SHIFT;
-       val |= mem->zq_mode_term << PHY_CON16_ZQ_MODE_TERM_SHIFT;
+       val |= mparams->zq_mode_dds << PHY_CON16_ZQ_MODE_DDS_SHIFT;
+       val |= mparams->zq_mode_term << PHY_CON16_ZQ_MODE_TERM_SHIFT;
        val |= ZQ_CLK_DIV_EN;
        writel(val, &phy0_ctrl->phy_con16);
        writel(val, &phy1_ctrl->phy_con16);
 
        /* Disable termination */
-       if (mem->zq_mode_noterm)
+       if (mparams->zq_mode_noterm)
                val |= PHY_CON16_ZQ_MODE_NOTERM_MASK;
        writel(val, &phy0_ctrl->phy_con16);
        writel(val, &phy1_ctrl->phy_con16);
@@ -108,15 +108,17 @@ void update_reset_dll(struct exynos5_dmc *dmc, enum ddr_mode mode)
        writel(val, &dmc->phycontrol0);
 }
 
-void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc)
+void dmc_config_mrs(struct mem_timings *mtimings,
+                       struct mem_params *mparams,
+                       struct exynos5_dmc *dmc)
 {
        int channel, chip;
 
-       for (channel = 0; channel < mem->dmc_channels; channel++) {
+       for (channel = 0; channel < mtimings->dmc_channels; channel++) {
                unsigned long mask;
 
                mask = channel << DIRECT_CMD_CHANNEL_SHIFT;
-               for (chip = 0; chip < mem->chips_to_configure; chip++) {
+               for (chip = 0; chip < mtimings->chips_to_configure; chip++) {
                        int i;
 
                        mask |= chip << DIRECT_CMD_CHIP_SHIFT;
@@ -133,12 +135,12 @@ void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc)
 
                        /* Sending EMRS/MRS commands */
                        for (i = 0; i < MEM_TIMINGS_MSR_COUNT; i++) {
-                               writel(mem->direct_cmd_msr[i] | mask,
+                               writel(mparams->direct_cmd_msr[i] | mask,
                                       &dmc->directcmd);
                                sdelay(0x10000);
                        }
 
-                       if (mem->send_zq_init) {
+                       if (mtimings->send_zq_init) {
                                /* Sending ZQINIT command */
                                writel(DIRECT_CMD_ZQINIT | mask,
                                       &dmc->directcmd);
@@ -149,15 +151,15 @@ void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc)
        }
 }
 
-void dmc_config_prech(struct mem_timings *mem, struct exynos5_dmc *dmc)
+void dmc_config_prech(struct mem_timings *mtimings, struct exynos5_dmc *dmc)
 {
        int channel, chip;
 
-       for (channel = 0; channel < mem->dmc_channels; channel++) {
+       for (channel = 0; channel < mtimings->dmc_channels; channel++) {
                unsigned long mask;
 
                mask = channel << DIRECT_CMD_CHANNEL_SHIFT;
-               for (chip = 0; chip < mem->chips_per_channel; chip++) {
+               for (chip = 0; chip < mtimings->chips_per_channel; chip++) {
                        mask |= chip << DIRECT_CMD_CHIP_SHIFT;
 
                        /* PALL (all banks precharge) CMD */
@@ -167,10 +169,10 @@ void dmc_config_prech(struct mem_timings *mem, struct exynos5_dmc *dmc)
        }
 }
 
-void dmc_config_memory(struct mem_timings *mem, struct exynos5_dmc *dmc)
+void dmc_config_memory(struct mem_timings *mtimings, struct exynos5_dmc *dmc)
 {
-       writel(mem->memconfig, &dmc->memconfig0);
-       writel(mem->memconfig, &dmc->memconfig1);
+       writel(mtimings->memconfig, &dmc->memconfig0);
+       writel(mtimings->memconfig, &dmc->memconfig1);
        writel(DMC_MEMBASECONFIG0_VAL, &dmc->membaseconfig0);
        writel(DMC_MEMBASECONFIG1_VAL, &dmc->membaseconfig1);
 }
@@ -178,14 +180,16 @@ void dmc_config_memory(struct mem_timings *mem, struct exynos5_dmc *dmc)
 void mem_ctrl_init()
 {
        struct spl_machine_param *param = spl_get_machine_params();
-       struct mem_timings *mem;
+       struct mem_timings *mtimings;
+       struct mem_params *mparams;
        int ret;
 
-       mem = clock_get_mem_timings();
+       mtimings = clock_get_mem_timings();
+       mparams = clock_get_mem_params();
 
        /* If there are any other memory variant, add their init call below */
        if (param->mem_type == DDR_MODE_DDR3) {
-               ret = ddr3_mem_ctrl_init(mem, param->mem_iv_size);
+               ret = ddr3_mem_ctrl_init(mtimings, mparams, param->mem_iv_size);
                if (ret) {
                        /* will hang if failed to init memory control */
                        while (1)
board/samsung/smdk5250/dmc_init_ddr3.c +61 -55
index e050790..7f4cb3c 100644
@@ -40,7 +40,9 @@ static void reset_phy_ctrl(void)
        writel(DDR3PHY_CTRL_PHY_RESET, &clk->lpddr3phy_ctrl);
 }
 
-int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long mem_iv_size)
+int ddr3_mem_ctrl_init(struct mem_timings *mtimings,
+                       struct mem_params *mparams,
+                       unsigned long mem_iv_size)
 {
        unsigned int val;
        struct exynos5_phy_control *phy0_ctrl, *phy1_ctrl;
@@ -54,93 +56,95 @@ int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long mem_iv_size)
        reset_phy_ctrl();
 
        /* Set Impedance Output Driver */
-       val = (mem->impedance << CA_CK_DRVR_DS_OFFSET) |
-               (mem->impedance << CA_CKE_DRVR_DS_OFFSET) |
-               (mem->impedance << CA_CS_DRVR_DS_OFFSET) |
-               (mem->impedance << CA_ADR_DRVR_DS_OFFSET);
+       val = (mparams->impedance << CA_CK_DRVR_DS_OFFSET) |
+               (mparams->impedance << CA_CKE_DRVR_DS_OFFSET) |
+               (mparams->impedance << CA_CS_DRVR_DS_OFFSET) |
+               (mparams->impedance << CA_ADR_DRVR_DS_OFFSET);
        writel(val, &phy0_ctrl->phy_con39);
        writel(val, &phy1_ctrl->phy_con39);
 
        /* Set Read Latency and Burst Length for PHY0 and PHY1 */
-       val = (mem->ctrl_bstlen << PHY_CON42_CTRL_BSTLEN_SHIFT) |
-               (mem->ctrl_rdlat << PHY_CON42_CTRL_RDLAT_SHIFT);
+       val = (mtimings->ctrl_bstlen << PHY_CON42_CTRL_BSTLEN_SHIFT) |
+               (mtimings->ctrl_rdlat << PHY_CON42_CTRL_RDLAT_SHIFT);
        writel(val, &phy0_ctrl->phy_con42);
        writel(val, &phy1_ctrl->phy_con42);
 
        /* ZQ Calibration */
-       if (dmc_config_zq(mem, phy0_ctrl, phy1_ctrl))
+       if (dmc_config_zq(mparams, phy0_ctrl, phy1_ctrl))
                return SETUP_ERR_ZQ_CALIBRATION_FAILURE;
 
        /* DQ Signal */
-       writel(mem->phy0_pulld_dqs, &phy0_ctrl->phy_con14);
-       writel(mem->phy1_pulld_dqs, &phy1_ctrl->phy_con14);
+       writel(mtimings->phy0_pulld_dqs, &phy0_ctrl->phy_con14);
+       writel(mtimings->phy1_pulld_dqs, &phy1_ctrl->phy_con14);
 
-       writel(mem->concontrol | (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)
-               | (mem->dfi_init_start << CONCONTROL_DFI_INIT_START_SHIFT),
+       writel(mtimings->concontrol
+               | (mtimings->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)
+               | (mtimings->dfi_init_start << CONCONTROL_DFI_INIT_START_SHIFT),
                &dmc->concontrol);
 
        update_reset_dll(dmc, DDR_MODE_DDR3);
 
        /* DQS Signal */
-       writel(mem->phy0_dqs, &phy0_ctrl->phy_con4);
-       writel(mem->phy1_dqs, &phy1_ctrl->phy_con4);
+       writel(mtimings->phy0_dqs, &phy0_ctrl->phy_con4);
+       writel(mtimings->phy1_dqs, &phy1_ctrl->phy_con4);
 
-       writel(mem->phy0_dq, &phy0_ctrl->phy_con6);
-       writel(mem->phy1_dq, &phy1_ctrl->phy_con6);
+       writel(mtimings->phy0_dq, &phy0_ctrl->phy_con6);
+       writel(mtimings->phy1_dq, &phy1_ctrl->phy_con6);
 
-       writel(mem->phy0_tFS, &phy0_ctrl->phy_con10);
-       writel(mem->phy1_tFS, &phy1_ctrl->phy_con10);
+       writel(mparams->phy0_tFS, &phy0_ctrl->phy_con10);
+       writel(mparams->phy1_tFS, &phy1_ctrl->phy_con10);
 
-       val = (mem->ctrl_start_point << PHY_CON12_CTRL_START_POINT_SHIFT) |
-               (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
-               (mem->ctrl_dll_on << PHY_CON12_CTRL_DLL_ON_SHIFT) |
-               (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
+       val = (mtimings->ctrl_start_point << PHY_CON12_CTRL_START_POINT_SHIFT) |
+               (mtimings->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
+               (mtimings->ctrl_dll_on << PHY_CON12_CTRL_DLL_ON_SHIFT) |
+               (mtimings->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
        writel(val, &phy0_ctrl->phy_con12);
        writel(val, &phy1_ctrl->phy_con12);
 
        /* Start DLL locking */
-       writel(val | (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
+       writel(val | (mtimings->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
                &phy0_ctrl->phy_con12);
-       writel(val | (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
+       writel(val | (mtimings->ctrl_start << PHY_CON12_CTRL_START_SHIFT),
                &phy1_ctrl->phy_con12);
 
        update_reset_dll(dmc, DDR_MODE_DDR3);
 
-       writel(mem->concontrol | (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT),
+       writel(mtimings->concontrol
+               | (mtimings->rd_fetch << CONCONTROL_RD_FETCH_SHIFT),
                &dmc->concontrol);
 
        /* Memory Channel Inteleaving Size */
-       writel(mem->iv_size, &dmc->ivcontrol);
+       writel(mtimings->iv_size, &dmc->ivcontrol);
 
-       writel(mem->memconfig, &dmc->memconfig0);
-       writel(mem->memconfig, &dmc->memconfig1);
-       writel(mem->membaseconfig0, &dmc->membaseconfig0);
-       writel(mem->membaseconfig1, &dmc->membaseconfig1);
+       writel(mtimings->memconfig, &dmc->memconfig0);
+       writel(mtimings->memconfig, &dmc->memconfig1);
+       writel(mtimings->membaseconfig0, &dmc->membaseconfig0);
+       writel(mtimings->membaseconfig1, &dmc->membaseconfig1);
 
        /* Precharge Configuration */
-       writel(mem->prechconfig_tp_cnt << PRECHCONFIG_TP_CNT_SHIFT,
+       writel(mtimings->prechconfig_tp_cnt << PRECHCONFIG_TP_CNT_SHIFT,
                &dmc->prechconfig);
 
        /* Power Down mode Configuration */
-       writel(mem->dpwrdn_cyc << PWRDNCONFIG_DPWRDN_CYC_SHIFT |
-               mem->dsref_cyc << PWRDNCONFIG_DSREF_CYC_SHIFT,
+       writel(mtimings->dpwrdn_cyc << PWRDNCONFIG_DPWRDN_CYC_SHIFT |
+               mtimings->dsref_cyc << PWRDNCONFIG_DSREF_CYC_SHIFT,
                &dmc->pwrdnconfig);
 
        /* TimingRow, TimingData, TimingPower and Timingaref
         * values as per Memory AC parameters
         */
-       writel(mem->timing_ref, &dmc->timingref);
-       writel(mem->timing_row, &dmc->timingrow);
-       writel(mem->timing_data, &dmc->timingdata);
-       writel(mem->timing_power, &dmc->timingpower);
+       writel(mtimings->timing_ref, &dmc->timingref);
+       writel(mtimings->timing_row, &dmc->timingrow);
+       writel(mtimings->timing_data, &dmc->timingdata);
+       writel(mtimings->timing_power, &dmc->timingpower);
 
        /* Send PALL command */
-       dmc_config_prech(mem, dmc);
+       dmc_config_prech(mtimings, dmc);
 
        /* Send NOP, MRS and ZQINIT commands */
-       dmc_config_mrs(mem, dmc);
+       dmc_config_mrs(mtimings, mparams, dmc);
 
-       if (mem->gate_leveling_enable) {
+       if (mparams->gate_leveling_enable) {
                val = PHY_CON0_RESET_VAL;
                val |= P0_CMD_EN;
                writel(val, &phy0_ctrl->phy_con0);
@@ -157,12 +161,12 @@ int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long mem_iv_size)
                writel(val, &phy0_ctrl->phy_con0);
                writel(val, &phy1_ctrl->phy_con0);
 
-               val = (mem->ctrl_start_point <<
+               val = (mtimings->ctrl_start_point <<
                                PHY_CON12_CTRL_START_POINT_SHIFT) |
-                       (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
-                       (mem->ctrl_force << PHY_CON12_CTRL_FORCE_SHIFT) |
-                       (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT) |
-                       (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
+                       (mtimings->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
+                       (mtimings->ctrl_force << PHY_CON12_CTRL_FORCE_SHIFT) |
+                       (mtimings->ctrl_start << PHY_CON12_CTRL_START_SHIFT) |
+                       (mtimings->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
                writel(val, &phy0_ctrl->phy_con12);
                writel(val, &phy1_ctrl->phy_con12);
 
@@ -203,13 +207,13 @@ int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long mem_iv_size)
                writel(0, &phy0_ctrl->phy_con14);
                writel(0, &phy1_ctrl->phy_con14);
 
-               val = (mem->ctrl_start_point <<
+               val = (mtimings->ctrl_start_point <<
                                PHY_CON12_CTRL_START_POINT_SHIFT) |
-                       (mem->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
-                       (mem->ctrl_force << PHY_CON12_CTRL_FORCE_SHIFT) |
-                       (mem->ctrl_start << PHY_CON12_CTRL_START_SHIFT) |
-                       (mem->ctrl_dll_on << PHY_CON12_CTRL_DLL_ON_SHIFT) |
-                       (mem->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
+                       (mtimings->ctrl_inc << PHY_CON12_CTRL_INC_SHIFT) |
+                       (mtimings->ctrl_force << PHY_CON12_CTRL_FORCE_SHIFT) |
+                       (mtimings->ctrl_start << PHY_CON12_CTRL_START_SHIFT) |
+                       (mtimings->ctrl_dll_on << PHY_CON12_CTRL_DLL_ON_SHIFT) |
+                       (mtimings->ctrl_ref << PHY_CON12_CTRL_REF_SHIFT);
                writel(val, &phy0_ctrl->phy_con12);
                writel(val, &phy1_ctrl->phy_con12);
 
@@ -217,12 +221,14 @@ int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long mem_iv_size)
        }
 
        /* Send PALL command */
-       dmc_config_prech(mem, dmc);
+       dmc_config_prech(mtimings, dmc);
 
-       writel(mem->memcontrol, &dmc->memcontrol);
+       writel(mtimings->memcontrol, &dmc->memcontrol);
 
        /* Set DMC Concontrol and enable auto-refresh counter */
-       writel(mem->concontrol | (mem->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)
-               | (mem->aref_en << CONCONTROL_AREF_EN_SHIFT), &dmc->concontrol);
+       writel(mtimings->concontrol
+               | (mtimings->rd_fetch << CONCONTROL_RD_FETCH_SHIFT)
+               | (mtimings->aref_en << CONCONTROL_AREF_EN_SHIFT),
+               &dmc->concontrol);
        return 0;
 }
board/samsung/smdk5250/setup.h +10 -6
index a159601..b30d7d0 100644
@@ -521,6 +521,7 @@
 #define PHY_CON42_CTRL_RDLAT_SHIFT     0
 
 struct mem_timings;
+struct mem_params;
 
 /* Errors that we can encourter in low-level setup */
 enum {
@@ -539,7 +540,9 @@ enum {
  *                     accesses; may vary across boards.
  * @return 0 if ok, SETUP_ERR_... if there is a problem
  */
-int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long mem_iv_size);
+int ddr3_mem_ctrl_init(struct mem_timings *mtimings,
+                       struct mem_params *mparams,
+                       unsigned long mem_iv_size);
 
 /*
  * Configure ZQ I/O interface
@@ -549,7 +552,7 @@ int ddr3_mem_ctrl_init(struct mem_timings *mem, unsigned long mem_iv_size);
  * @param phy1_ctrl    Pointer to struct containing PHY1 control reg
  * @return 0 if ok, -1 on error
  */
-int dmc_config_zq(struct mem_timings *mem,
+int dmc_config_zq(struct mem_params *mparams,
                  struct exynos5_phy_control *phy0_ctrl,
                  struct exynos5_phy_control *phy1_ctrl);
 
@@ -559,7 +562,9 @@ int dmc_config_zq(struct mem_timings *mem,
  * @param mem          Memory timings for this memory type.
  * @param dmc          Pointer to struct of DMC registers
  */
-void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc);
+void dmc_config_mrs(struct mem_timings *mtimings,
+                       struct mem_params *mparams,
+                       struct exynos5_dmc *dmc);
 
 /*
  * Send PALL Direct commands
@@ -567,7 +572,7 @@ void dmc_config_mrs(struct mem_timings *mem, struct exynos5_dmc *dmc);
  * @param mem          Memory timings for this memory type.
  * @param dmc          Pointer to struct of DMC registers
  */
-void dmc_config_prech(struct mem_timings *mem, struct exynos5_dmc *dmc);
+void dmc_config_prech(struct mem_timings *mtimings, struct exynos5_dmc *dmc);
 
 /*
  * Configure the memconfig and membaseconfig registers
@@ -575,7 +580,7 @@ void dmc_config_prech(struct mem_timings *mem, struct exynos5_dmc *dmc);
  * @param mem          Memory timings for this memory type.
  * @param exynos5_dmc  Pointer to struct of DMC registers
  */
-void dmc_config_memory(struct mem_timings *mem, struct exynos5_dmc *dmc);
+void dmc_config_memory(struct mem_timings *mtimings, struct exynos5_dmc *dmc);
 
 /*
  * Reset the DLL. This function is common between DDR3 and LPDDR2.
--
Quoted 2 lines

1.8.0

Regards,
Simon

#4 lore raw

PATCH v2 2/2 Exynos5: spl: Reduce clock init in spl

In reply to Akshay Saraswat

This patch subtracts a part of clock init from spl and executes it after relocation. spl_clock_init executes in spl and system_clock_init executes after relocation in u-boot. This is done to gain some space by removing initially not necessary code.

---
Changes since v1:
- Rebased on ToT.

 board/samsung/smdk5250/Makefile         |   3 +-
 board/samsung/smdk5250/clock_init.c     | 429 +----------------------------
 board/samsung/smdk5250/clock_init.h     |   2 +
 board/samsung/smdk5250/lowlevel_init.S  |   4 +-
 board/samsung/smdk5250/setup.h          |   1 +
 board/samsung/smdk5250/smdk5250.c       |   4 +
 board/samsung/smdk5250/spl_clock_init.c | 469 ++++++++++++++++++++++++++++++++
 7 files changed, 482 insertions(+), 430 deletions(-)
 create mode 100644 board/samsung/smdk5250/spl_clock_init.c
board/samsung/smdk5250/Makefile +2 -1
index 47c6a5a..3ceb7e2 100644
@@ -26,12 +26,13 @@ LIB	= $(obj)lib$(BOARD).o
 
 SOBJS	:= lowlevel_init.o
 
-COBJS	:= clock_init.o
+COBJS	:= spl_clock_init.o
 COBJS	+= dmc_common.o dmc_init_ddr3.o
 COBJS	+= tzpc_init.o
 COBJS	+= smdk5250_spl.o
 
 ifndef CONFIG_SPL_BUILD
+COBJS	+= clock_init.o
 COBJS	+= smdk5250.o
 endif
 
board/samsung/smdk5250/clock_init.c +2 -427

483 lines not on this page · raw message

board/samsung/smdk5250/clock_init.h +2 -0
index 12b5c55..03580d8 100644
@@ -162,5 +162,7 @@ struct mem_params *clock_get_mem_params(void);
 /*
  * Initialize clock for the device
  */
+void spl_clock_init(void);
+
 void system_clock_init(void);
 #endif
board/samsung/smdk5250/lowlevel_init.S +2 -2
index bc6cb6f..1e69c02 100644
@@ -69,7 +69,7 @@ lowlevel_init:
 	beq	1f			/* r0 == r1 then skip sdram init */
 
 	/* init system clock */
-	bl	system_clock_init
+	bl	spl_clock_init
 
 	/* Memory initialize */
 	bl	mem_ctrl_init
@@ -79,7 +79,7 @@ lowlevel_init:
 	ldmia	r13!, {ip,pc}
 
 wakeup_reset:
-	bl	system_clock_init
+	bl	spl_clock_init
 	bl	mem_ctrl_init
 	bl	tzpc_init
 
board/samsung/smdk5250/setup.h +1 -0
index b30d7d0..074219f 100644
@@ -595,5 +595,6 @@ void update_reset_dll(struct exynos5_dmc *, enum ddr_mode);
 void sdelay(unsigned long);
 void mem_ctrl_init(void);
 void system_clock_init(void);
+void spl_clock_init(void);
 void tzpc_init(void);
 #endif
board/samsung/smdk5250/smdk5250.c +4 -0
index ffc5ee5..b6e611c 100644
@@ -29,6 +29,7 @@
 #include <netdev.h>
 #include <spi.h>
 #include <asm/arch/cpu.h>
+#include <asm/arch/dmc.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/mmc.h>
 #include <asm/arch/pinmux.h>
@@ -37,6 +38,7 @@
 #include <asm/arch/dp_info.h>
 #include <power/pmic.h>
 #include <power/max77686_pmic.h>
+#include "clock_init.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -378,6 +380,8 @@ static int board_uart_init(void)
 int board_early_init_f(void)
 {
 	int err;
+
+	system_clock_init();
 	err = board_uart_init();
 	if (err) {
 		debug("UART init failed\n");
board/samsung/smdk5250/spl_clock_init.c new file +469 -0

469 lines not on this page · raw message

Signature · 1 line
1.8.0
#5 lore raw

PATCH v2 2/2 Exynos5: spl: Reduce clock init in spl

Hi Akshay

Quoted 9 lines · Akshay Saraswat

This patch subtracts a part of clock init from spl and executes it after relocation. spl_clock_init executes in spl and system_clock_init executes after relocation in u-boot. This is done to gain some space by removing initially not necessary code.

---

Now board boots fine with this patch applied.

Quoted 1,105 lines

Changes since v1:
- Rebased on ToT.

 board/samsung/smdk5250/Makefile         |   3 +-
 board/samsung/smdk5250/clock_init.c     | 429
+----------------------------
 board/samsung/smdk5250/clock_init.h     |   2 +
 board/samsung/smdk5250/lowlevel_init.S  |   4 +-
 board/samsung/smdk5250/setup.h          |   1 +
 board/samsung/smdk5250/smdk5250.c       |   4 +
 board/samsung/smdk5250/spl_clock_init.c | 469
++++++++++++++++++++++++++++++++
 7 files changed, 482 insertions(+), 430 deletions(-)
 create mode 100644 board/samsung/smdk5250/spl_clock_init.c
board/samsung/smdk5250/Makefile +2 -1
index 47c6a5a..3ceb7e2 100644
@@ -26,12 +26,13 @@ LIB = $(obj)lib$(BOARD).o
 
 SOBJS  := lowlevel_init.o
 
-COBJS  := clock_init.o
+COBJS  := spl_clock_init.o
 COBJS  += dmc_common.o dmc_init_ddr3.o
 COBJS  += tzpc_init.o
 COBJS  += smdk5250_spl.o
 
 ifndef CONFIG_SPL_BUILD
+COBJS  += clock_init.o
 COBJS  += smdk5250.o
 endif
 
board/samsung/smdk5250/clock_init.c +0 -291
index 30cbdcf..fe3cd8a 100644
@@ -34,109 +34,6 @@
 
 DECLARE_GLOBAL_DATA_PTR;
 
-struct arm_clk_ratios arm_clk_ratios[] = {
-       {
-               .arm_freq_mhz = 600,
-
-               .apll_mdiv = 0xc8,
-               .apll_pdiv = 0x4,
-               .apll_sdiv = 0x1,
-
-               .arm2_ratio = 0x0,
-               .apll_ratio = 0x1,
-               .pclk_dbg_ratio = 0x1,
-               .atb_ratio = 0x2,
-               .periph_ratio = 0x7,
-               .acp_ratio = 0x7,
-               .cpud_ratio = 0x1,
-               .arm_ratio = 0x0,
-       }, {
-               .arm_freq_mhz = 800,
-
-               .apll_mdiv = 0x64,
-               .apll_pdiv = 0x3,
-               .apll_sdiv = 0x0,
-
-               .arm2_ratio = 0x0,
-               .apll_ratio = 0x1,
-               .pclk_dbg_ratio = 0x1,
-               .atb_ratio = 0x3,
-               .periph_ratio = 0x7,
-               .acp_ratio = 0x7,
-               .cpud_ratio = 0x2,
-               .arm_ratio = 0x0,
-       }, {
-               .arm_freq_mhz = 1000,
-
-               .apll_mdiv = 0x7d,
-               .apll_pdiv = 0x3,
-               .apll_sdiv = 0x0,
-
-               .arm2_ratio = 0x0,
-               .apll_ratio = 0x1,
-               .pclk_dbg_ratio = 0x1,
-               .atb_ratio = 0x4,
-               .periph_ratio = 0x7,
-               .acp_ratio = 0x7,
-               .cpud_ratio = 0x2,
-               .arm_ratio = 0x0,
-       }, {
-               .arm_freq_mhz = 1200,
-
-               .apll_mdiv = 0x96,
-               .apll_pdiv = 0x3,
-               .apll_sdiv = 0x0,
-
-               .arm2_ratio = 0x0,
-               .apll_ratio = 0x3,
-               .pclk_dbg_ratio = 0x1,
-               .atb_ratio = 0x5,
-               .periph_ratio = 0x7,
-               .acp_ratio = 0x7,
-               .cpud_ratio = 0x3,
-               .arm_ratio = 0x0,
-       }, {
-               .arm_freq_mhz = 1400,
-
-               .apll_mdiv = 0xaf,
-               .apll_pdiv = 0x3,
-               .apll_sdiv = 0x0,
-
-               .arm2_ratio = 0x0,
-               .apll_ratio = 0x3,
-               .pclk_dbg_ratio = 0x1,
-               .atb_ratio = 0x6,
-               .periph_ratio = 0x7,
-               .acp_ratio = 0x7,
-               .cpud_ratio = 0x3,
-               .arm_ratio = 0x0,
-       }, {
-               .arm_freq_mhz = 1700,
-
-               .apll_mdiv = 0x1a9,
-               .apll_pdiv = 0x6,
-               .apll_sdiv = 0x0,
-
-               .arm2_ratio = 0x0,
-               .apll_ratio = 0x3,
-               .pclk_dbg_ratio = 0x1,
-               .atb_ratio = 0x6,
-               .periph_ratio = 0x7,
-               .acp_ratio = 0x7,
-               .cpud_ratio = 0x3,
-               .arm_ratio = 0x0,
-       }
-};
-
-struct spl_clock_div spl_clock_div = {
-               .mpll_mdiv = 0xc8,
-               .mpll_pdiv = 0x3,
-               .mpll_sdiv = 0x0,
-               .bpll_mdiv = 0x64,
-               .bpll_pdiv = 0x3,
-               .bpll_sdiv = 0x0,
-};
-
 struct non_spl_clock_div non_spl_clock_div = {
                .cpll_mdiv = 0xde,
                .cpll_pdiv = 0x4,
@@ -152,255 +49,20 @@ struct non_spl_clock_div non_spl_clock_div = {
                .vpll_sdiv = 0x2,
 };
 
-struct mem_timings mem_timings = {
-               .pclk_cdrex_ratio = 0x5,
-               .timing_ref = 0x000000bb,
-               .timing_row = 0x8c36650e,
-               .timing_data = 0x3630580b,
-               .timing_power = 0x41000a44,
-               .phy0_dqs = 0x08080808,
-               .phy1_dqs = 0x08080808,
-               .phy0_dq = 0x08080808,
-               .phy1_dq = 0x08080808,
-               .phy0_pulld_dqs = 0xf,
-               .phy1_pulld_dqs = 0xf,
-
-               .lpddr3_ctrl_phy_reset = 0x1,
-               .ctrl_start_point = 0x10,
-               .ctrl_inc = 0x10,
-               .ctrl_start = 0x1,
-               .ctrl_dll_on = 0x1,
-               .ctrl_ref = 0x8,
-
-               .ctrl_force = 0x1a,
-               .ctrl_rdlat = 0x0b,
-               .ctrl_bstlen = 0x08,
-
-               .fp_resync = 0x8,
-               .iv_size = 0x7,
-               .dfi_init_start = 1,
-               .aref_en = 1,
-
-               .rd_fetch = 0x3,
-
-               /*
-               * Dynamic Clock: Always Running
-               * Memory Burst length: 8
-               * Number of chips: 1
-               * Memory Bus width: 32 bit
-               * Memory Type: DDR3
-               * Additional Latancy for PLL: 0 Cycle
-               */
-               .memcontrol = DMC_MEMCONTROL_CLK_STOP_DISABLE |
-                       DMC_MEMCONTROL_DPWRDN_DISABLE |
-                       DMC_MEMCONTROL_DPWRDN_ACTIVE_PRECHARGE |
-                       DMC_MEMCONTROL_TP_DISABLE |
-                       DMC_MEMCONTROL_DSREF_ENABLE |
-                       DMC_MEMCONTROL_ADD_LAT_PALL_CYCLE(0) |
-                       DMC_MEMCONTROL_MEM_TYPE_DDR3 |
-                       DMC_MEMCONTROL_MEM_WIDTH_32BIT |
-                       DMC_MEMCONTROL_NUM_CHIP_1 |
-                       DMC_MEMCONTROL_BL_8 |
-                       DMC_MEMCONTROL_PZQ_DISABLE |
-                       DMC_MEMCONTROL_MRR_BYTE_7_0,
-               .memconfig = DMC_MEMCONFIGx_CHIP_MAP_INTERLEAVED |
-                       DMC_MEMCONFIGx_CHIP_COL_10 |
-                       DMC_MEMCONFIGx_CHIP_ROW_15 |
-                       DMC_MEMCONFIGx_CHIP_BANK_8,
-               .membaseconfig0 = DMC_MEMBASECONFIG_VAL(0x40),
-               .membaseconfig1 = DMC_MEMBASECONFIG_VAL(0x80),
-               .prechconfig_tp_cnt = 0xff,
-               .dpwrdn_cyc = 0xff,
-               .dsref_cyc = 0xffff,
-               .concontrol = DMC_CONCONTROL_DFI_INIT_START_DISABLE |
-                       DMC_CONCONTROL_TIMEOUT_LEVEL0 |
-                       DMC_CONCONTROL_RD_FETCH_DISABLE |
-                       DMC_CONCONTROL_EMPTY_DISABLE |
-                       DMC_CONCONTROL_AREF_EN_DISABLE |
-                       DMC_CONCONTROL_IO_PD_CON_DISABLE,
-               .dmc_channels = 2,
-               .chips_per_channel = 2,
-               .chips_to_configure = 1,
-               .send_zq_init = 1,
-};
-
-struct mem_params mem_params[] = {
-       {
-               .mem_manuf = MEM_MANUF_ELPIDA,
-               .mem_type = DDR_MODE_DDR3,
-               .frequency_mhz = 800,
-
-               .direct_cmd_msr = {
-                       0x00020018, 0x00030000, 0x00010042, 0x00000d70
-               },
-
-               .phy0_tFS = 0x4,
-               .phy1_tFS = 0x4,
-
-               .zq_mode_dds = 0x7,
-               .zq_mode_term = 0x1,
-               .zq_mode_noterm = 0,
-
-               .impedance = IMP_OUTPUT_DRV_30_OHM,
-               .gate_leveling_enable = 0,
-       }, {
-               .mem_manuf = MEM_MANUF_SAMSUNG,
-               .mem_type = DDR_MODE_DDR3,
-               .frequency_mhz = 800,
-
-               .direct_cmd_msr = {
-                       0x00020018, 0x00030000, 0x00010000, 0x00000d70
-               },
-
-               .phy0_tFS = 0x8,
-               .phy1_tFS = 0x8,
-
-               .zq_mode_dds = 0x5,
-               .zq_mode_term = 0x1,
-               .zq_mode_noterm = 1,
-
-               .impedance = IMP_OUTPUT_DRV_40_OHM,
-               .gate_leveling_enable = 1,
-       }
-};
-
-
-/**
- * Get the required memory type and speed (SPL version).
- *
- * In SPL we have no device tree, so we use the machine parameters
- *
- * @param mem_type     Returns memory type
- * @param frequency_mhz        Returns memory speed in MHz
- * @param arm_freq     Returns ARM clock speed in MHz
- * @param mem_manuf    Return Memory Manufacturer name
- * @return 0 if all ok
- */
-static int clock_get_mem_selection(enum ddr_mode *mem_type,
-               unsigned *frequency_mhz, unsigned *arm_freq,
-               enum mem_manuf *mem_manuf)
-{
-       struct spl_machine_param *params;
-
-       params = spl_get_machine_params();
-       *mem_type = params->mem_type;
-       *frequency_mhz = params->frequency_mhz;
-       *arm_freq = params->arm_freq_mhz;
-       *mem_manuf = params->mem_manuf;
-
-       return 0;
-}
-
-/* Get the ratios for setting ARM clock */
-struct arm_clk_ratios *get_arm_ratios(void)
-{
-       struct arm_clk_ratios *arm_ratio;
-       enum ddr_mode mem_type;
-       enum mem_manuf mem_manuf;
-       unsigned frequency_mhz, arm_freq;
-       int i;
-
-       if (clock_get_mem_selection(&mem_type, &frequency_mhz,
-                                       &arm_freq, &mem_manuf))
-               ;
-       for (i = 0, arm_ratio = arm_clk_ratios; i <
 ARRAY_SIZE(arm_clk_ratios);
-               i++, arm_ratio++) {
-               if (arm_ratio->arm_freq_mhz == arm_freq)
-                       return arm_ratio;
-       }
-
-       /* will hang if failed to find clock ratio */
-       while (1)
-               ;
-
-       return NULL;
-}
-
-struct spl_clock_div *clock_get_spl_div(void)
-{
-       return &spl_clock_div;
-}
-
 struct non_spl_clock_div *clock_get_non_spl_div(void)
 {
        return &non_spl_clock_div;
 }
 
-struct mem_timings *clock_get_mem_timings(void)
-{
-       return &mem_timings;
-}
-
-struct mem_params *clock_get_mem_params(void)
-{
-       struct mem_params *mem;
-       enum ddr_mode mem_type;
-       enum mem_manuf mem_manuf;
-       unsigned frequency_mhz, arm_freq;
-       int i;
-
-       if (!clock_get_mem_selection(&mem_type, &frequency_mhz,
-                                               &arm_freq, &mem_manuf)) {
-               for (i = 0, mem = mem_params; i < ARRAY_SIZE(mem_params);
-                               i++, mem++) {
-                       if (mem->mem_type == mem_type &&
-                                       mem->frequency_mhz ==

frequency_mhz &&

board/samsung/smdk5250/clock_init.c +0 -12
-                                       mem->mem_manuf == mem_manuf)
-                               return mem;
-               }
-       }
-
-       /* will hang if failed to find memory timings */
-       while (1)
-               ;
-
-       return NULL;
-}
-
 void system_clock_init()
 {
        struct exynos5_clock *clk = (struct exynos5_clock

*)EXYNOS5_CLOCK_BASE;

board/samsung/smdk5250/clock_init.c +1 -85
-       struct arm_clk_ratios *arm_clk_ratio;
-       struct spl_clock_div *s_clk_div;
        struct non_spl_clock_div *ns_clk_div;
-       u32 val, tmp;
+       u32 val;
 
-       arm_clk_ratio = get_arm_ratios();
-       s_clk_div = clock_get_spl_div();
        ns_clk_div = clock_get_non_spl_div();
 
-       clrbits_le32(&clk->src_cpu, MUX_APLL_SEL_MASK);
-       do {
-               val = readl(&clk->mux_stat_cpu);
-       } while ((val | MUX_APLL_SEL_MASK) != val);
-
-       clrbits_le32(&clk->src_core1, MUX_MPLL_SEL_MASK);
-       do {
-               val = readl(&clk->mux_stat_core1);
-       } while ((val | MUX_MPLL_SEL_MASK) != val);
-
-       clrbits_le32(&clk->src_core1, MUX_CPLL_SEL_MASK);
-       clrbits_le32(&clk->src_core1, MUX_EPLL_SEL_MASK);
-       clrbits_le32(&clk->src_core1, MUX_VPLL_SEL_MASK);
-       clrbits_le32(&clk->src_core1, MUX_GPLL_SEL_MASK);
-       tmp = MUX_CPLL_SEL_MASK | MUX_EPLL_SEL_MASK | MUX_VPLL_SEL_MASK
-               | MUX_GPLL_SEL_MASK;
-       do {
-               val = readl(&clk->mux_stat_top2);
-       } while ((val | tmp) != val);
-
-       clrbits_le32(&clk->src_cdrex, MUX_BPLL_SEL_MASK);
-       do {
-               val = readl(&clk->mux_stat_cdrex);
-       } while ((val | MUX_BPLL_SEL_MASK) != val);
-
        /* PLL locktime */
-       writel(APLL_LOCK_VAL, &clk->apll_lock);
-
-       writel(MPLL_LOCK_VAL, &clk->mpll_lock);
-
-       writel(BPLL_LOCK_VAL, &clk->bpll_lock);
-
        writel(CPLL_LOCK_VAL, &clk->cpll_lock);
 
        writel(GPLL_LOCK_VAL, &clk->gpll_lock);
@@ -409,55 +71,6 @@ void system_clock_init()
 
        writel(VPLL_LOCK_VAL, &clk->vpll_lock);
 
-       writel(CLK_REG_DISABLE, &clk->pll_div2_sel);
-
-       writel(MUX_HPM_SEL_MASK, &clk->src_cpu);
-       do {
-               val = readl(&clk->mux_stat_cpu);
-       } while ((val | HPM_SEL_SCLK_MPLL) != val);
-
-       val = arm_clk_ratio->arm2_ratio << 28
-               | arm_clk_ratio->apll_ratio << 24
-               | arm_clk_ratio->pclk_dbg_ratio << 20
-               | arm_clk_ratio->atb_ratio << 16
-               | arm_clk_ratio->periph_ratio << 12
-               | arm_clk_ratio->acp_ratio << 8
-               | arm_clk_ratio->cpud_ratio << 4
-               | arm_clk_ratio->arm_ratio;
-       writel(val, &clk->div_cpu0);
-       do {
-               val = readl(&clk->div_stat_cpu0);
-       } while (0 != val);
-
-       writel(CLK_DIV_CPU1_VAL, &clk->div_cpu1);
-       do {
-               val = readl(&clk->div_stat_cpu1);
-       } while (0 != val);
-
-       /* Set APLL */
-       writel(APLL_CON1_VAL, &clk->apll_con1);
-       val = set_pll(arm_clk_ratio->apll_mdiv, arm_clk_ratio->apll_pdiv,
-                       arm_clk_ratio->apll_sdiv);
-       writel(val, &clk->apll_con0);
-       while (readl(&clk->apll_con0) & APLL_CON0_LOCKED)
-               ;
-
-       /* Set MPLL */
-       writel(MPLL_CON1_VAL, &clk->mpll_con1);
-       val = set_pll(s_clk_div->mpll_mdiv,
-                               s_clk_div->mpll_pdiv,
 s_clk_div->mpll_sdiv);
-       writel(val, &clk->mpll_con0);
-       while (readl(&clk->mpll_con0) & MPLL_CON0_LOCKED)
-               ;
-
-       /* Set BPLL */
-       writel(BPLL_CON1_VAL, &clk->bpll_con1);
-       val = set_pll(s_clk_div->bpll_mdiv,
-                               s_clk_div->bpll_pdiv,
 s_clk_div->bpll_sdiv);
-       writel(val, &clk->bpll_con0);
-       while (readl(&clk->bpll_con0) & BPLL_CON0_LOCKED)
-               ;
-
        /* Set CPLL */
        writel(CPLL_CON1_VAL, &clk->cpll_con1);
        val = set_pll(ns_clk_div->cpll_mdiv,
board/samsung/smdk5250/clock_init.c +1 -9
@@ -488,19 +101,11 @@ void system_clock_init()
        writel(VPLL_CON1_VAL, &clk->vpll_con1);
        val = set_pll(ns_clk_div->vpll_mdiv,
                                ns_clk_div->vpll_pdiv,
 ns_clk_div->vpll_sdiv);
+
        writel(val, &clk->vpll_con0);
        while (readl(&clk->vpll_con0) & VPLL_CON0_LOCKED)
                ;
 
-       writel(CLK_SRC_CORE0_VAL, &clk->src_core0);
-       writel(CLK_DIV_CORE0_VAL, &clk->div_core0);
-       while (readl(&clk->div_stat_core0) != 0)
-               ;
-
-       writel(CLK_DIV_CORE1_VAL, &clk->div_core1);
-       while (readl(&clk->div_stat_core1) != 0)
-               ;
-
        writel(CLK_DIV_SYSRGT_VAL, &clk->div_sysrgt);
        while (readl(&clk->div_stat_sysrgt) != 0)
                ;
board/samsung/smdk5250/clock_init.c +0 -23
@@ -549,29 +154,10 @@ void system_clock_init()
        while (readl(&clk->div_stat_r1x))
                ;
 
-       writel(CLK_REG_DISABLE, &clk->src_cdrex);
-
-       writel(CLK_DIV_CDREX_VAL, &clk->div_cdrex);
-       while (readl(&clk->div_stat_cdrex))
-               ;
-
-       val = readl(&clk->src_cpu);
-       val |= CLK_SRC_CPU_VAL;
-       writel(val, &clk->src_cpu);
-
        val = readl(&clk->src_top2);
        val |= CLK_SRC_TOP2_VAL;
        writel(val, &clk->src_top2);
 
-       val = readl(&clk->src_core1);
-       val |= CLK_SRC_CORE1_VAL;
-       writel(val, &clk->src_core1);
-
-       writel(CLK_SRC_FSYS0_VAL, &clk->src_fsys);
-       writel(CLK_DIV_FSYS0_VAL, &clk->div_fsys0);
-       while (readl(&clk->div_stat_fsys0))
-               ;
-
        writel(CLK_REG_DISABLE, &clk->clkout_cmu_cpu);
        writel(CLK_REG_DISABLE, &clk->clkout_cmu_core);
        writel(CLK_REG_DISABLE, &clk->clkout_cmu_acp);
@@ -604,14 +190,3 @@ void system_clock_init()
                | MMC3_RATIO_VAL << MMC3_RATIO_OFFSET;
        writel(val, &clk->div_fsys2);
 }
-
-void clock_init_dp_clock(void)
-{
-       struct exynos5_clock *clk = (struct exynos5_clock

*)EXYNOS5_CLOCK_BASE;

board/samsung/smdk5250/clock_init.c +0 -7
-
-       /* DP clock enable */
-       setbits_le32(&clk->gate_ip_disp1, CLK_GATE_DP1_ALLOW);
-
-       /* We run DP at 267 Mhz */
-       setbits_le32(&clk->div_disp1_0, CLK_DIV_DISP1_0_FIMD1);
-}
board/samsung/smdk5250/clock_init.h +2 -0
index 12b5c55..03580d8 100644
@@ -162,5 +162,7 @@ struct mem_params *clock_get_mem_params(void);
 /*
  * Initialize clock for the device
  */
+void spl_clock_init(void);
+
 void system_clock_init(void);
 #endif
board/samsung/smdk5250/lowlevel_init.S +2 -2
index bc6cb6f..1e69c02 100644
@@ -69,7 +69,7 @@ lowlevel_init:
        beq     1f                      /* r0 == r1 then skip sdram init */
 
        /* init system clock */
-       bl      system_clock_init
+       bl      spl_clock_init
 
        /* Memory initialize */
        bl      mem_ctrl_init
@@ -79,7 +79,7 @@ lowlevel_init:
        ldmia   r13!, {ip,pc}
 
 wakeup_reset:
-       bl      system_clock_init
+       bl      spl_clock_init
        bl      mem_ctrl_init
        bl      tzpc_init
 
board/samsung/smdk5250/setup.h +1 -0
index b30d7d0..074219f 100644
@@ -595,5 +595,6 @@ void update_reset_dll(struct exynos5_dmc *, enum
 ddr_mode);
 void sdelay(unsigned long);
 void mem_ctrl_init(void);
 void system_clock_init(void);
+void spl_clock_init(void);
 void tzpc_init(void);

#endif

board/samsung/smdk5250/smdk5250.c +4 -0
index ffc5ee5..b6e611c 100644
@@ -29,6 +29,7 @@
 #include <netdev.h>
 #include <spi.h>
 #include <asm/arch/cpu.h>
+#include <asm/arch/dmc.h>
 #include <asm/arch/gpio.h>
 #include <asm/arch/mmc.h>
 #include <asm/arch/pinmux.h>
@@ -37,6 +38,7 @@
 #include <asm/arch/dp_info.h>
 #include <power/pmic.h>
 #include <power/max77686_pmic.h>
+#include "clock_init.h"
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -378,6 +380,8 @@ static int board_uart_init(void)
 int board_early_init_f(void)
 {
        int err;
+
+       system_clock_init();
        err = board_uart_init();
        if (err) {
                debug("UART init failed\n");
board/samsung/smdk5250/spl_clock_init.c new file +291 -0
new file mode 100644
index 0000000..cd6146e
@@ -0,0 +1,469 @@
+/*
+ * Clock setup for SMDK5250 board based on EXYNOS5
+ *
+ * Copyright (C) 2012 Samsung Electronics
+ *
+ * See file CREDITS for list of people who contributed to this
+ * project.
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License as
+ * published by the Free Software Foundation; either version 2 of
+ * the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+ * MA 02111-1307 USA
+ */
+
+#include <common.h>
+#include <config.h>
+#include <asm/io.h>
+#include <asm/arch/clk.h>
+#include <asm/arch/clock.h>
+#include <asm/arch/spl.h>
+
+#include "clock_init.h"
+#include "setup.h"
+
+DECLARE_GLOBAL_DATA_PTR;
+
+struct arm_clk_ratios arm_clk_ratios[] = {
+       {
+               .arm_freq_mhz = 600,
+
+               .apll_mdiv = 0xc8,
+               .apll_pdiv = 0x4,
+               .apll_sdiv = 0x1,
+
+               .arm2_ratio = 0x0,
+               .apll_ratio = 0x1,
+               .pclk_dbg_ratio = 0x1,
+               .atb_ratio = 0x2,
+               .periph_ratio = 0x7,
+               .acp_ratio = 0x7,
+               .cpud_ratio = 0x1,
+               .arm_ratio = 0x0,
+       }, {
+               .arm_freq_mhz = 800,
+
+               .apll_mdiv = 0x64,
+               .apll_pdiv = 0x3,
+               .apll_sdiv = 0x0,
+
+               .arm2_ratio = 0x0,
+               .apll_ratio = 0x1,
+               .pclk_dbg_ratio = 0x1,
+               .atb_ratio = 0x3,
+               .periph_ratio = 0x7,
+               .acp_ratio = 0x7,
+               .cpud_ratio = 0x2,
+               .arm_ratio = 0x0,
+       }, {
+               .arm_freq_mhz = 1000,
+
+               .apll_mdiv = 0x7d,
+               .apll_pdiv = 0x3,
+               .apll_sdiv = 0x0,
+
+               .arm2_ratio = 0x0,
+               .apll_ratio = 0x1,
+               .pclk_dbg_ratio = 0x1,
+               .atb_ratio = 0x4,
+               .periph_ratio = 0x7,
+               .acp_ratio = 0x7,
+               .cpud_ratio = 0x2,
+               .arm_ratio = 0x0,
+       }, {
+               .arm_freq_mhz = 1200,
+
+               .apll_mdiv = 0x96,
+               .apll_pdiv = 0x3,
+               .apll_sdiv = 0x0,
+
+               .arm2_ratio = 0x0,
+               .apll_ratio = 0x3,
+               .pclk_dbg_ratio = 0x1,
+               .atb_ratio = 0x5,
+               .periph_ratio = 0x7,
+               .acp_ratio = 0x7,
+               .cpud_ratio = 0x3,
+               .arm_ratio = 0x0,
+       }, {
+               .arm_freq_mhz = 1400,
+
+               .apll_mdiv = 0xaf,
+               .apll_pdiv = 0x3,
+               .apll_sdiv = 0x0,
+
+               .arm2_ratio = 0x0,
+               .apll_ratio = 0x3,
+               .pclk_dbg_ratio = 0x1,
+               .atb_ratio = 0x6,
+               .periph_ratio = 0x7,
+               .acp_ratio = 0x7,
+               .cpud_ratio = 0x3,
+               .arm_ratio = 0x0,
+       }, {
+               .arm_freq_mhz = 1700,
+
+               .apll_mdiv = 0x1a9,
+               .apll_pdiv = 0x6,
+               .apll_sdiv = 0x0,
+
+               .arm2_ratio = 0x0,
+               .apll_ratio = 0x3,
+               .pclk_dbg_ratio = 0x1,
+               .atb_ratio = 0x6,
+               .periph_ratio = 0x7,
+               .acp_ratio = 0x7,
+               .cpud_ratio = 0x3,
+               .arm_ratio = 0x0,
+       }
+};
+
+struct spl_clock_div spl_clock_div = {
+               .mpll_mdiv = 0xc8,
+               .mpll_pdiv = 0x3,
+               .mpll_sdiv = 0x0,
+               .bpll_mdiv = 0x64,
+               .bpll_pdiv = 0x3,
+               .bpll_sdiv = 0x0,
+};
+
+struct mem_timings mem_timings = {
+               .pclk_cdrex_ratio = 0x5,
+               .timing_ref = 0x000000bb,
+               .timing_row = 0x8c36650e,
+               .timing_data = 0x3630580b,
+               .timing_power = 0x41000a44,
+               .phy0_dqs = 0x08080808,
+               .phy1_dqs = 0x08080808,
+               .phy0_dq = 0x08080808,
+               .phy1_dq = 0x08080808,
+               .phy0_pulld_dqs = 0xf,
+               .phy1_pulld_dqs = 0xf,
+
+               .lpddr3_ctrl_phy_reset = 0x1,
+               .ctrl_start_point = 0x10,
+               .ctrl_inc = 0x10,
+               .ctrl_start = 0x1,
+               .ctrl_dll_on = 0x1,
+               .ctrl_ref = 0x8,
+
+               .ctrl_force = 0x1a,
+               .ctrl_rdlat = 0x0b,
+               .ctrl_bstlen = 0x08,
+
+               .fp_resync = 0x8,
+               .iv_size = 0x7,
+               .dfi_init_start = 1,
+               .aref_en = 1,
+
+               .rd_fetch = 0x3,
+
+               /*
+               * Dynamic Clock: Always Running
+               * Memory Burst length: 8
+               * Number of chips: 1
+               * Memory Bus width: 32 bit
+               * Memory Type: DDR3
+               * Additional Latancy for PLL: 0 Cycle
+               */
+               .memcontrol = DMC_MEMCONTROL_CLK_STOP_DISABLE |
+                       DMC_MEMCONTROL_DPWRDN_DISABLE |
+                       DMC_MEMCONTROL_DPWRDN_ACTIVE_PRECHARGE |
+                       DMC_MEMCONTROL_TP_DISABLE |
+                       DMC_MEMCONTROL_DSREF_ENABLE |
+                       DMC_MEMCONTROL_ADD_LAT_PALL_CYCLE(0) |
+                       DMC_MEMCONTROL_MEM_TYPE_DDR3 |
+                       DMC_MEMCONTROL_MEM_WIDTH_32BIT |
+                       DMC_MEMCONTROL_NUM_CHIP_1 |
+                       DMC_MEMCONTROL_BL_8 |
+                       DMC_MEMCONTROL_PZQ_DISABLE |
+                       DMC_MEMCONTROL_MRR_BYTE_7_0,
+               .memconfig = DMC_MEMCONFIGx_CHIP_MAP_INTERLEAVED |
+                       DMC_MEMCONFIGx_CHIP_COL_10 |
+                       DMC_MEMCONFIGx_CHIP_ROW_15 |
+                       DMC_MEMCONFIGx_CHIP_BANK_8,
+               .membaseconfig0 = DMC_MEMBASECONFIG_VAL(0x40),
+               .membaseconfig1 = DMC_MEMBASECONFIG_VAL(0x80),
+               .prechconfig_tp_cnt = 0xff,
+               .dpwrdn_cyc = 0xff,
+               .dsref_cyc = 0xffff,
+               .concontrol = DMC_CONCONTROL_DFI_INIT_START_DISABLE |
+                       DMC_CONCONTROL_TIMEOUT_LEVEL0 |
+                       DMC_CONCONTROL_RD_FETCH_DISABLE |
+                       DMC_CONCONTROL_EMPTY_DISABLE |
+                       DMC_CONCONTROL_AREF_EN_DISABLE |
+                       DMC_CONCONTROL_IO_PD_CON_DISABLE,
+               .dmc_channels = 2,
+               .chips_per_channel = 2,
+               .chips_to_configure = 1,
+               .send_zq_init = 1,
+};
+
+struct mem_params mem_params[] = {
+       {
+               .mem_manuf = MEM_MANUF_ELPIDA,
+               .mem_type = DDR_MODE_DDR3,
+               .frequency_mhz = 800,
+
+               .direct_cmd_msr = {
+                       0x00020018, 0x00030000, 0x00010042, 0x00000d70
+               },
+
+               .phy0_tFS = 0x4,
+               .phy1_tFS = 0x4,
+
+               .zq_mode_dds = 0x7,
+               .zq_mode_term = 0x1,
+               .zq_mode_noterm = 0,
+
+               .impedance = IMP_OUTPUT_DRV_30_OHM,
+               .gate_leveling_enable = 0,
+       }, {
+               .mem_manuf = MEM_MANUF_SAMSUNG,
+               .mem_type = DDR_MODE_DDR3,
+               .frequency_mhz = 800,
+
+               .direct_cmd_msr = {
+                       0x00020018, 0x00030000, 0x00010000, 0x00000d70
+               },
+
+               .phy0_tFS = 0x8,
+               .phy1_tFS = 0x8,
+
+               .zq_mode_dds = 0x5,
+               .zq_mode_term = 0x1,
+               .zq_mode_noterm = 1,
+
+               .impedance = IMP_OUTPUT_DRV_40_OHM,
+               .gate_leveling_enable = 1,
+       }
+};
+
+
+/**
+ * Get the required memory type and speed (SPL version).
+ *
+ * In SPL we have no device tree, so we use the machine parameters
+ *
+ * @param mem_type     Returns memory type
+ * @param frequency_mhz        Returns memory speed in MHz
+ * @param arm_freq     Returns ARM clock speed in MHz
+ * @param mem_manuf    Return Memory Manufacturer name
+ * @return 0 if all ok
+ */
+static int clock_get_mem_selection(enum ddr_mode *mem_type,
+               unsigned *frequency_mhz, unsigned *arm_freq,
+               enum mem_manuf *mem_manuf)
+{
+       struct spl_machine_param *params;
+
+       params = spl_get_machine_params();
+       *mem_type = params->mem_type;
+       *frequency_mhz = params->frequency_mhz;
+       *arm_freq = params->arm_freq_mhz;
+       *mem_manuf = params->mem_manuf;
+
+       return 0;
+}
+
+/* Get the ratios for setting ARM clock */
+struct arm_clk_ratios *get_arm_ratios(void)
+{
+       struct arm_clk_ratios *arm_ratio;
+       enum ddr_mode mem_type;
+       enum mem_manuf mem_manuf;
+       unsigned frequency_mhz, arm_freq;
+       int i;
+
+       if (clock_get_mem_selection(&mem_type, &frequency_mhz,
+                                       &arm_freq, &mem_manuf))
+               ;
+       for (i = 0, arm_ratio = arm_clk_ratios; i <

ARRAY_SIZE(arm_clk_ratios);

board/samsung/smdk5250/spl_clock_init.c new file +36 -0
+               i++, arm_ratio++) {
+               if (arm_ratio->arm_freq_mhz == arm_freq)
+                       return arm_ratio;
+       }
+
+       /* will hang if failed to find clock ratio */
+       while (1)
+               ;
+
+       return NULL;
+}
+
+struct spl_clock_div *clock_get_spl_div(void)
+{
+       return &spl_clock_div;
+}
+
+struct mem_timings *clock_get_mem_timings(void)
+{
+       return &mem_timings;
+}
+
+struct mem_params *clock_get_mem_params(void)
+{
+       struct mem_params *mem;
+       enum ddr_mode mem_type;
+       enum mem_manuf mem_manuf;
+       unsigned frequency_mhz, arm_freq;
+       int i;
+
+       if (!clock_get_mem_selection(&mem_type, &frequency_mhz,
+                                               &arm_freq, &mem_manuf)) {
+               for (i = 0, mem = mem_params; i < ARRAY_SIZE(mem_params);
+                               i++, mem++) {
+                       if (mem->mem_type == mem_type &&
+                                       mem->frequency_mhz ==

frequency_mhz &&

board/samsung/smdk5250/spl_clock_init.c new file +15 -0
+                                       mem->mem_manuf == mem_manuf)
+                               return mem;
+               }
+       }
+
+       /* will hang if failed to find memory timings */
+       while (1)
+               ;
+
+       return NULL;
+}
+
+void spl_clock_init()
+{
+       struct exynos5_clock *clk = (struct exynos5_clock

*)EXYNOS5_CLOCK_BASE;

board/samsung/smdk5250/spl_clock_init.c new file +76 -0
+       struct arm_clk_ratios *arm_clk_ratio;
+       struct spl_clock_div *s_clk_div;
+       u32 val, tmp;
+
+       arm_clk_ratio = get_arm_ratios();
+       s_clk_div = clock_get_spl_div();
+
+       clrbits_le32(&clk->src_cpu, MUX_APLL_SEL_MASK);
+       do {
+               val = readl(&clk->mux_stat_cpu);
+       } while ((val | MUX_APLL_SEL_MASK) != val);
+
+       clrbits_le32(&clk->src_core1, MUX_MPLL_SEL_MASK);
+       do {
+               val = readl(&clk->mux_stat_core1);
+       } while ((val | MUX_MPLL_SEL_MASK) != val);
+
+       clrbits_le32(&clk->src_core1, MUX_CPLL_SEL_MASK);
+       clrbits_le32(&clk->src_core1, MUX_EPLL_SEL_MASK);
+       clrbits_le32(&clk->src_core1, MUX_VPLL_SEL_MASK);
+       clrbits_le32(&clk->src_core1, MUX_GPLL_SEL_MASK);
+       tmp = MUX_CPLL_SEL_MASK | MUX_EPLL_SEL_MASK | MUX_VPLL_SEL_MASK
+               | MUX_GPLL_SEL_MASK;
+       do {
+               val = readl(&clk->mux_stat_top2);
+       } while ((val | tmp) != val);
+
+       clrbits_le32(&clk->src_cdrex, MUX_BPLL_SEL_MASK);
+       do {
+               val = readl(&clk->mux_stat_cdrex);
+       } while ((val | MUX_BPLL_SEL_MASK) != val);
+
+       /* PLL locktime */
+       writel(APLL_LOCK_VAL, &clk->apll_lock);
+
+       writel(MPLL_LOCK_VAL, &clk->mpll_lock);
+
+       writel(BPLL_LOCK_VAL, &clk->bpll_lock);
+
+       writel(CLK_REG_DISABLE, &clk->pll_div2_sel);
+
+       writel(MUX_HPM_SEL_MASK, &clk->src_cpu);
+       do {
+               val = readl(&clk->mux_stat_cpu);
+       } while ((val | HPM_SEL_SCLK_MPLL) != val);
+
+       val = arm_clk_ratio->arm2_ratio << 28
+               | arm_clk_ratio->apll_ratio << 24
+               | arm_clk_ratio->pclk_dbg_ratio << 20
+               | arm_clk_ratio->atb_ratio << 16
+               | arm_clk_ratio->periph_ratio << 12
+               | arm_clk_ratio->acp_ratio << 8
+               | arm_clk_ratio->cpud_ratio << 4
+               | arm_clk_ratio->arm_ratio;
+       writel(val, &clk->div_cpu0);
+       do {
+               val = readl(&clk->div_stat_cpu0);
+       } while (0 != val);
+
+       writel(CLK_DIV_CPU1_VAL, &clk->div_cpu1);
+       do {
+               val = readl(&clk->div_stat_cpu1);
+       } while (0 != val);
+
+       /* Set APLL */
+       writel(APLL_CON1_VAL, &clk->apll_con1);
+       val = set_pll(arm_clk_ratio->apll_mdiv, arm_clk_ratio->apll_pdiv,
+                       arm_clk_ratio->apll_sdiv);
+       writel(val, &clk->apll_con0);
+       while (readl(&clk->apll_con0) & APLL_CON0_LOCKED)
+               ;
+
+       /* Set MPLL */
+       writel(MPLL_CON1_VAL, &clk->mpll_con1);
+       val = set_pll(s_clk_div->mpll_mdiv,
+                               s_clk_div->mpll_pdiv,

s_clk_div->mpll_sdiv);

board/samsung/smdk5250/spl_clock_init.c new file +8 -0
+       writel(val, &clk->mpll_con0);
+       while (readl(&clk->mpll_con0) & MPLL_CON0_LOCKED)
+               ;
+
+       /* Set BPLL */
+       writel(BPLL_CON1_VAL, &clk->bpll_con1);
+       val = set_pll(s_clk_div->bpll_mdiv,
+                               s_clk_div->bpll_pdiv,

s_clk_div->bpll_sdiv);

board/samsung/smdk5250/spl_clock_init.c new file +36 -0
+       writel(val, &clk->bpll_con0);
+       while (readl(&clk->bpll_con0) & BPLL_CON0_LOCKED)
+               ;
+
+       writel(CLK_SRC_CORE0_VAL, &clk->src_core0);
+       writel(CLK_DIV_CORE0_VAL, &clk->div_core0);
+       while (readl(&clk->div_stat_core0) != 0)
+               ;
+
+       writel(CLK_DIV_CORE1_VAL, &clk->div_core1);
+       while (readl(&clk->div_stat_core1) != 0)
+               ;
+
+       writel(CLK_REG_DISABLE, &clk->src_cdrex);
+
+       writel(CLK_DIV_CDREX_VAL, &clk->div_cdrex);
+       while (readl(&clk->div_stat_cdrex))
+               ;
+
+       val = readl(&clk->src_cpu);
+       val |= CLK_SRC_CPU_VAL;
+       writel(val, &clk->src_cpu);
+
+       val = readl(&clk->src_core1);
+       val |= CLK_SRC_CORE1_VAL;
+       writel(val, &clk->src_core1);
+
+       writel(CLK_SRC_FSYS0_VAL, &clk->src_fsys);
+       writel(CLK_DIV_FSYS0_VAL, &clk->div_fsys0);
+       while (readl(&clk->div_stat_fsys0))
+               ;
+}
+
+void clock_init_dp_clock(void)
+{
+       struct exynos5_clock *clk = (struct exynos5_clock

*)EXYNOS5_CLOCK_BASE;

board/samsung/smdk5250/spl_clock_init.c new file +7 -1
+
+       /* DP clock enable */
+       setbits_le32(&clk->gate_ip_disp1, CLK_GATE_DP1_ALLOW);
+
+       /* We run DP at 267 Mhz */
+       setbits_le32(&clk->div_disp1_0, CLK_DIV_DISP1_0_FIMD1);
+}
--

1.8.0

_______________________________________________
U-Boot mailing list
U-Boot at lists.denx.de
http://lists.denx.de/mailman/listinfo/u-boot

#6 lore raw

PATCH v2 2/2 Exynos5: spl: Reduce clock init in spl

In reply to Akshay Saraswat

Hi Akshay,

Quoted 8 lines · Akshay Saraswat

This patch subtracts a part of clock init from spl and executes it after relocation. spl_clock_init executes in spl and system_clock_init executes after relocation in u-boot. This is done to gain some space by removing initially not necessary code.

---

Looks good - just one question below.

Quoted 18 lines

Changes since v1:
- Rebased on ToT.

 board/samsung/smdk5250/Makefile         |   3 +-
 board/samsung/smdk5250/clock_init.c     | 429 +----------------------------
 board/samsung/smdk5250/clock_init.h     |   2 +
 board/samsung/smdk5250/lowlevel_init.S  |   4 +-
 board/samsung/smdk5250/setup.h          |   1 +
 board/samsung/smdk5250/smdk5250.c       |   4 +
 board/samsung/smdk5250/spl_clock_init.c | 469 ++++++++++++++++++++++++++++++++
 7 files changed, 482 insertions(+), 430 deletions(-)
 create mode 100644 board/samsung/smdk5250/spl_clock_init.c
board/samsung/smdk5250/Makefile +0 -0
index 47c6a5a..3ceb7e2 100644

board/samsung/smdk5250/Makefile LIB = $(obj)lib$(BOARD).o · line 29

Quoted 5 lines
board/samsung/smdk5250/Makefile +1 -1
@@ -26,12 +26,13 @@ LIB = $(obj)lib$(BOARD).o
 
 SOBJS  := lowlevel_init.o
 
-COBJS  := clock_init.o
+COBJS  := spl_clock_init.o

Shouldn't this only be included in the SPL build?

board/samsung/smdk5250/Makefile LIB = $(obj)lib$(BOARD).o · line 38

Quoted 9 lines
board/samsung/smdk5250/Makefile +1 -0
 COBJS  += dmc_common.o dmc_init_ddr3.o
 COBJS  += tzpc_init.o
 COBJS  += smdk5250_spl.o
 
 ifndef CONFIG_SPL_BUILD
+COBJS  += clock_init.o
 COBJS  += smdk5250.o
 endif
 

...

Regards,
Simon