All of lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [RFC PATCH v2 10/18] ddr: socfpga: gen5: fetch handoff information from 'of_to_platdata'
Date: Tue, 15 Oct 2019 22:10:23 +0200	[thread overview]
Message-ID: <20191015201032.20156-11-simon.k.r.goldschmidt@gmail.com> (raw)
In-Reply-To: <20191015201032.20156-1-simon.k.r.goldschmidt@gmail.com>

In preparation to move handoff data from 'qts' files to devicetree, fetch
SDRAM config in 'of_to_platdata' DM callback. That way, this callback
can be changed to fetch the data from devicetree.

Signed-off-by: Simon Goldschmidt <simon.k.r.goldschmidt@gmail.com>
---

Changes in v2: None

 drivers/ddr/altera/sdram_gen5.c | 45 +++++++++++++++++++++++++--------
 drivers/ddr/altera/sequencer.c  | 35 +++++++++++++++----------
 drivers/ddr/altera/sequencer.h  |  9 ++++++-
 3 files changed, 64 insertions(+), 25 deletions(-)

diff --git a/drivers/ddr/altera/sdram_gen5.c b/drivers/ddr/altera/sdram_gen5.c
index 8c8ea19eb9..91d9f6c0fc 100644
--- a/drivers/ddr/altera/sdram_gen5.c
+++ b/drivers/ddr/altera/sdram_gen5.c
@@ -25,6 +25,15 @@ struct altera_gen5_sdram_priv {
 
 struct altera_gen5_sdram_platdata {
 	struct socfpga_sdr *sdr;
+	/* Handoff config follows */
+	const struct socfpga_sdram_config *cfg;
+	const struct socfpga_sdram_rw_mgr_config *rwcfg;
+	const struct socfpga_sdram_io_config *iocfg;
+	const struct socfpga_sdram_misc_config *misccf;
+	const u32 *inst_rom_init;
+	unsigned int inst_rom_init_len;
+	const u32 *ac_rom_init;
+	unsigned int ac_rom_init_len;
 };
 
 struct sdram_prot_rule {
@@ -43,7 +52,9 @@ struct sdram_prot_rule {
 static struct socfpga_system_manager *sysmgr_regs =
 	(struct socfpga_system_manager *)SOCFPGA_SYSMGR_ADDRESS;
 
-static unsigned long sdram_calculate_size(struct socfpga_sdr_ctrl *sdr_ctrl);
+static unsigned long sdram_calculate_size(
+	struct socfpga_sdr_ctrl *sdr_ctrl,
+	const struct socfpga_sdram_config *cfg);
 
 /**
  * get_errata_rows() - Up the number of DRAM rows to cover entire address space
@@ -446,10 +457,10 @@ static void sdr_load_regs(struct socfpga_sdr_ctrl *sdr_ctrl,
  *
  * Initialize the SDRAM MMR.
  */
-int sdram_mmr_init_full(struct socfpga_sdr_ctrl *sdr_ctrl,
-			unsigned int sdr_phy_reg)
+static int sdram_mmr_init_full(struct socfpga_sdr_ctrl *sdr_ctrl,
+			       unsigned int sdr_phy_reg,
+			       const struct socfpga_sdram_config *cfg)
 {
-	const struct socfpga_sdram_config *cfg = socfpga_get_sdram_config();
 	const unsigned int rows =
 		(cfg->dram_addrw & SDR_CTRLGRP_DRAMADDRW_ROWBITS_MASK) >>
 			SDR_CTRLGRP_DRAMADDRW_ROWBITS_LSB;
@@ -481,7 +492,7 @@ int sdram_mmr_init_full(struct socfpga_sdr_ctrl *sdr_ctrl,
 			1 << SDR_CTRLGRP_STATICCFG_APPLYCFG_LSB);
 
 	sdram_set_protection_config(sdr_ctrl, 0,
-				    sdram_calculate_size(sdr_ctrl) - 1);
+				    sdram_calculate_size(sdr_ctrl, cfg) - 1);
 
 	sdram_dump_protection_config(sdr_ctrl);
 
@@ -494,11 +505,12 @@ int sdram_mmr_init_full(struct socfpga_sdr_ctrl *sdr_ctrl,
  * Calculate SDRAM device size based on SDRAM controller parameters.
  * Size is specified in bytes.
  */
-static unsigned long sdram_calculate_size(struct socfpga_sdr_ctrl *sdr_ctrl)
+static unsigned long sdram_calculate_size(
+	struct socfpga_sdr_ctrl *sdr_ctrl,
+	const struct socfpga_sdram_config *cfg)
 {
 	unsigned long temp;
 	unsigned long row, bank, col, cs, width;
-	const struct socfpga_sdram_config *cfg = socfpga_get_sdram_config();
 	const unsigned int csbits =
 		((cfg->dram_addrw & SDR_CTRLGRP_DRAMADDRW_CSBITS_MASK) >>
 			SDR_CTRLGRP_DRAMADDRW_CSBITS_LSB) + 1;
@@ -565,6 +577,16 @@ static int altera_gen5_sdram_ofdata_to_platdata(struct udevice *dev)
 	if (!plat->sdr)
 		return -ENODEV;
 
+	/* Get handoff config */
+	plat->cfg = socfpga_get_sdram_config();
+	plat->rwcfg = socfpga_get_sdram_rwmgr_config();
+	plat->iocfg = socfpga_get_sdram_io_config();
+	plat->misccf = socfpga_get_sdram_misc_config();
+
+	socfpga_get_seq_inst_init(&plat->inst_rom_init,
+				  &plat->inst_rom_init_len);
+	socfpga_get_seq_ac_init(&plat->ac_rom_init, &plat->ac_rom_init_len);
+
 	return 0;
 }
 
@@ -584,19 +606,22 @@ static int altera_gen5_sdram_probe(struct udevice *dev)
 	}
 	reset_deassert_bulk(&resets);
 
-	if (sdram_mmr_init_full(sdr_ctrl, 0xffffffff) != 0) {
+	if (sdram_mmr_init_full(sdr_ctrl, 0xffffffff, plat->cfg) != 0) {
 		puts("SDRAM init failed.\n");
 		goto failed;
 	}
 
 	debug("SDRAM: Calibrating PHY\n");
 	/* SDRAM calibration */
-	if (sdram_calibration_full(plat->sdr) == 0) {
+	if (sdram_calibration_full(plat->sdr, plat->rwcfg, plat->iocfg,
+				   plat->misccf, plat->inst_rom_init,
+				   plat->inst_rom_init_len, plat->ac_rom_init,
+				   plat->ac_rom_init_len) == 0) {
 		puts("SDRAM calibration failed.\n");
 		goto failed;
 	}
 
-	sdram_size = sdram_calculate_size(sdr_ctrl);
+	sdram_size = sdram_calculate_size(sdr_ctrl, plat->cfg);
 	debug("SDRAM: %ld MiB\n", sdram_size >> 20);
 
 	/* Sanity check ensure correct SDRAM size specified */
diff --git a/drivers/ddr/altera/sequencer.c b/drivers/ddr/altera/sequencer.c
index 6c632227c2..1e03cf3cf6 100644
--- a/drivers/ddr/altera/sequencer.c
+++ b/drivers/ddr/altera/sequencer.c
@@ -3655,21 +3655,20 @@ static void debug_mem_calibrate(struct socfpga_sdrseq *seq, int pass)
  *
  * Initialize ROM data.
  */
-static void hc_initialize_rom_data(void)
+static void hc_initialize_rom_data(const u32 *inst_rom_init,
+				   unsigned int inst_rom_init_len,
+				   const u32 *ac_rom_init,
+				   unsigned int ac_rom_init_len)
 {
-	unsigned int nelem = 0;
-	const u32 *rom_init;
 	u32 i, addr;
 
-	socfpga_get_seq_inst_init(&rom_init, &nelem);
 	addr = SDR_PHYGRP_RWMGRGRP_ADDRESS | RW_MGR_INST_ROM_WRITE_OFFSET;
-	for (i = 0; i < nelem; i++)
-		writel(rom_init[i], addr + (i << 2));
+	for (i = 0; i < inst_rom_init_len; i++)
+		writel(inst_rom_init[i], addr + (i << 2));
 
-	socfpga_get_seq_ac_init(&rom_init, &nelem);
 	addr = SDR_PHYGRP_RWMGRGRP_ADDRESS | RW_MGR_AC_ROM_WRITE_OFFSET;
-	for (i = 0; i < nelem; i++)
-		writel(rom_init[i], addr + (i << 2));
+	for (i = 0; i < ac_rom_init_len; i++)
+		writel(ac_rom_init[i], addr + (i << 2));
 }
 
 /**
@@ -3788,7 +3787,14 @@ static void initialize_tracking(struct socfpga_sdrseq *seq)
 	       &sdr_reg_file->trk_rfsh);
 }
 
-int sdram_calibration_full(struct socfpga_sdr *sdr)
+int sdram_calibration_full(struct socfpga_sdr *sdr,
+			   const struct socfpga_sdram_rw_mgr_config *rwcfg,
+			   const struct socfpga_sdram_io_config *iocfg,
+			   const struct socfpga_sdram_misc_config *misccfg,
+			   const u32 *inst_rom_init,
+			   unsigned int inst_rom_init_len,
+			   const u32 *ac_rom_init,
+			   unsigned int ac_rom_init_len)
 {
 	u32 pass;
 	struct socfpga_sdrseq seq;
@@ -3802,9 +3808,9 @@ int sdram_calibration_full(struct socfpga_sdr *sdr)
 
 	memset(&seq, 0, sizeof(seq));
 
-	seq.rwcfg = socfpga_get_sdram_rwmgr_config();
-	seq.iocfg = socfpga_get_sdram_io_config();
-	seq.misccfg = socfpga_get_sdram_misc_config();
+	seq.rwcfg = rwcfg;
+	seq.iocfg = iocfg;
+	seq.misccfg = misccfg;
 
 	/* Set the calibration enabled by default */
 	seq.gbl.phy_debug_mode_flags |= PHY_DEBUG_ENABLE_CAL_RPT;
@@ -3856,7 +3862,8 @@ int sdram_calibration_full(struct socfpga_sdr *sdr)
 	debug_cond(DLEVEL >= 1, "dqs_in_reserve=%u dqs_out_reserve=%u\n",
 		   seq.iocfg->dqs_in_reserve, seq.iocfg->dqs_out_reserve);
 
-	hc_initialize_rom_data();
+	hc_initialize_rom_data(inst_rom_init, inst_rom_init_len,
+			       ac_rom_init, ac_rom_init_len);
 
 	/* update info for sims */
 	reg_file_set_stage(CAL_STAGE_NIL);
diff --git a/drivers/ddr/altera/sequencer.h b/drivers/ddr/altera/sequencer.h
index 4a03c3fdf9..84057d4b4f 100644
--- a/drivers/ddr/altera/sequencer.h
+++ b/drivers/ddr/altera/sequencer.h
@@ -278,6 +278,13 @@ struct socfpga_sdrseq {
 	struct param_type param;
 };
 
-int sdram_calibration_full(struct socfpga_sdr *sdr);
+int sdram_calibration_full(struct socfpga_sdr *sdr,
+			   const struct socfpga_sdram_rw_mgr_config *rwcfg,
+			   const struct socfpga_sdram_io_config *iocfg,
+			   const struct socfpga_sdram_misc_config *misccfg,
+			   const u32 *inst_rom_init,
+			   unsigned int inst_rom_init_len,
+			   const u32 *ac_rom_init,
+			   unsigned int ac_rom_init_len);
 
 #endif /* _SEQUENCER_H_ */
-- 
2.20.1

  parent reply	other threads:[~2019-10-15 20:10 UTC|newest]

Thread overview: 28+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-10-15 20:10 [U-Boot] [RFC PATCH v2 00/18] arm: socfpga: gen5: move to DM Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 01/18] ddr: socfpga: gen5: constify altera_gen5_sdram_ops Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 02/18] dts: arm: socfpga: add label for clkmgr Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 03/18] arm: socfpga: gen5: increase SPL_SYS_MALLOC_F_LEN Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 04/18] timer: dw-apb: add reset handling Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 05/18] arm: socfpga: gen5: move initial reset handling to reset driver Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 06/18] arm: dts: socfpga: add settings for gen5 clk driver Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 07/18] arm: dts: socfpga: make clock nodes available in SPL Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 08/18] socfpga: gen5: add new tool to create handoff dtsi files Simon Goldschmidt
2019-10-22 17:10   ` Dalon L Westergreen
2019-10-22 17:13     ` Simon Goldschmidt
2019-10-23 16:03       ` Dalon L Westergreen
2019-10-23 19:22         ` Simon Goldschmidt
2019-10-24 14:25           ` Dalon L Westergreen
2019-10-24 14:29             ` Simon Goldschmidt
2019-10-24 17:29               ` Dalon L Westergreen
2019-10-24 18:00                 ` Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 09/18] sdram: socfpga: gen5: make config structs dts compatible Simon Goldschmidt
2019-10-15 20:10 ` Simon Goldschmidt [this message]
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 11/18] ddr: socfpga: gen5: read handoff information from devicetree Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 12/18] arm: socfpga: gen5: add readonly clk driver Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 13/18] arm: socfpga: gen5: enable DM CLK Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 14/18] arm: socfpga: gen5: move clock initialization to CLK driver Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 15/18] arm: socfpga: gen5: load CLK config from devicetree Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 16/18] spi: cadence_qspi: support DM_CLK Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 17/18] arm: socfpga: gen5: parse qspi clock from devictree Simon Goldschmidt
2019-10-15 20:10 ` [U-Boot] [RFC PATCH v2 18/18] socfpga: gen5: move CLK and SDRAM to DM Simon Goldschmidt
2019-10-23 20:36 ` [U-Boot] [RFC PATCH v2 00/18] arm: socfpga: gen5: move " Simon Goldschmidt

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20191015201032.20156-11-simon.k.r.goldschmidt@gmail.com \
    --to=simon.k.r.goldschmidt@gmail.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.