drivers/ddr/altera: Add the DDR controller driver for SoCFPGA
Subsystems (2)
v2 cover drivers/ddr/altera: Add the DDR controller driver for SoCFPGA
From: Dinh Nguyen <[email protected]>
Hi,
This is V2 of patch series that adds the DDR controller driver for Altera's SoCFPGA platform.
V2:
- Clean up to address comments from Pavel
Thanks,
Dinh Nguyen (3):
driver/ddr/altera: Add DDR driver for Altera's SDRAM controller driver/ddr/altera/: Add the sdram calibration portion
arm: socfpga: enable the Altera SDRAM controller driver
Makefile | 1 + arch/arm/include/asm/arch-socfpga/sdram.h | 306 ++ arch/arm/include/asm/arch-socfpga/sdram_config.h | 100 + drivers/ddr/altera/Makefile | 12 + drivers/ddr/altera/sdram.c | 799 +++++ drivers/ddr/altera/sequencer.c | 3907 ++++++++++++++++++++++ drivers/ddr/altera/sequencer.h | 328 ++ drivers/ddr/altera/sequencer_auto.h | 128 + drivers/ddr/altera/sequencer_auto_ac_init.c | 85 + drivers/ddr/altera/sequencer_auto_inst_init.c | 270 ++ drivers/ddr/altera/sequencer_defines.h | 121 + include/configs/socfpga_common.h | 5 + scripts/Makefile.spl | 1 + 13 files changed, 6063 insertions(+) create mode 100644 arch/arm/include/asm/arch-socfpga/sdram.h create mode 100644 arch/arm/include/asm/arch-socfpga/sdram_config.h create mode 100644 drivers/ddr/altera/Makefile create mode 100644 drivers/ddr/altera/sdram.c create mode 100644 drivers/ddr/altera/sequencer.c create mode 100644 drivers/ddr/altera/sequencer.h create mode 100644 drivers/ddr/altera/sequencer_auto.h create mode 100644 drivers/ddr/altera/sequencer_auto_ac_init.c create mode 100644 drivers/ddr/altera/sequencer_auto_inst_init.c create mode 100644 drivers/ddr/altera/sequencer_defines.h
Signature · 1 line
2.2.1
PATCH v2 1/3 driver/ddr/altera: Add DDR driver for Altera's SDRAM controller
From: Dinh Nguyen <[email protected]>
This patch enables the SDRAM controller that is used on Altera's SoCFPGA family. This patch configures the SDRAM controller based on a configuration file that is generated from the Quartus tool, sdram_config.h.
---
v2: clean up with comments from Pavel
--- Makefile | 1 + arch/arm/include/asm/arch-socfpga/sdram.h | 306 +++++++++ arch/arm/include/asm/arch-socfpga/sdram_config.h | 100 +++ drivers/ddr/altera/sdram.c | 799 +++++++++++++++++++++++ scripts/Makefile.spl | 1 + 5 files changed, 1207 insertions(+) create mode 100644 arch/arm/include/asm/arch-socfpga/sdram.h create mode 100644 arch/arm/include/asm/arch-socfpga/sdram_config.h create mode 100644 drivers/ddr/altera/sdram.c
Makefile +1 -0
@@ -649,6 +649,7 @@ libs-y += drivers/power/ \ libs-y += drivers/spi/ libs-$(CONFIG_FMAN_ENET) += drivers/net/fm/ libs-$(CONFIG_SYS_FSL_DDR) += drivers/ddr/fsl/ +libs-$(CONFIG_ALTERA_SDRAM) += drivers/ddr/altera/ libs-y += drivers/serial/ libs-y += drivers/usb/dwc3/ libs-y += drivers/usb/eth/
arch/arm/include/asm/arch-socfpga/sdram.h new file +306 -0
306 lines not on this page · raw message
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +100 -0
100 lines not on this page · raw message
drivers/ddr/altera/sdram.c new file +799 -0
799 lines not on this page · raw message
scripts/Makefile.spl +1 -0
@@ -60,6 +60,7 @@ libs-$(CONFIG_SPL_GPIO_SUPPORT) += drivers/gpio/ libs-$(CONFIG_SPL_MMC_SUPPORT) += drivers/mmc/ libs-$(CONFIG_SPL_MPC8XXX_INIT_DDR_SUPPORT) += drivers/ddr/fsl/ libs-$(CONFIG_SYS_MVEBU_DDR) += drivers/ddr/mvebu/ +libs-$(CONFIG_ALTERA_SDRAM) += drivers/ddr/altera/ libs-$(CONFIG_SPL_SERIAL_SUPPORT) += drivers/serial/ libs-$(CONFIG_SPL_SPI_FLASH_SUPPORT) += drivers/mtd/spi/ libs-$(CONFIG_SPL_SPI_SUPPORT) += drivers/spi/
Signature · 1 line
2.2.1
PATCH v2 2/3 driver/ddr/altera/: Add the sdram calibration portion
In reply to dinguyen at opensource.altera.comFrom: Dinh Nguyen <[email protected]>
This patch adds the DDR calibration portion of the Altera SDRAM driver.
--- drivers/ddr/altera/Makefile | 12 + drivers/ddr/altera/sequencer.c | 3907 +++++++++++++++++++++++++ drivers/ddr/altera/sequencer.h | 328 +++ drivers/ddr/altera/sequencer_auto.h | 128 + drivers/ddr/altera/sequencer_auto_ac_init.c | 85 + drivers/ddr/altera/sequencer_auto_inst_init.c | 270 ++ drivers/ddr/altera/sequencer_defines.h | 121 + 7 files changed, 4851 insertions(+) create mode 100644 drivers/ddr/altera/Makefile create mode 100644 drivers/ddr/altera/sequencer.c create mode 100644 drivers/ddr/altera/sequencer.h create mode 100644 drivers/ddr/altera/sequencer_auto.h create mode 100644 drivers/ddr/altera/sequencer_auto_ac_init.c create mode 100644 drivers/ddr/altera/sequencer_auto_inst_init.c create mode 100644 drivers/ddr/altera/sequencer_defines.h
drivers/ddr/altera/Makefile new file +12 -0
@@ -0,0 +1,12 @@ +# +# (C) Copyright 2000-2003 +# Wolfgang Denk, DENX Software Engineering, wd at denx.de. +# +# (C) Copyright 2010, Thomas Chou <[email protected]> +# Copyright (C) 2014 Altera Corporation <www.altera.com> +# +# SPDX-License-Identifier: GPL-2.0+ +# + +obj-$(CONFIG_ALTERA_SDRAM) += sdram.o sequencer.o sequencer_auto_ac_init.o \ + sequencer_auto_inst_init.o
drivers/ddr/altera/sequencer.c new file +3907 -0
2,988 lines not on this page · raw message
drivers/ddr/altera/sequencer.h new file +328 -0
328 lines not on this page · raw message
drivers/ddr/altera/sequencer_auto.h new file +128 -0
128 lines not on this page · raw message
drivers/ddr/altera/sequencer_auto_ac_init.c new file +85 -0
85 lines not on this page · raw message
drivers/ddr/altera/sequencer_auto_inst_init.c new file +270 -0
270 lines not on this page · raw message
drivers/ddr/altera/sequencer_defines.h new file +121 -0
121 lines not on this page · raw message
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.2.1
Part of the diff is not shown here. View the raw message.
PATCH v2 3/3 arm: socfpga: enable the Altera SDRAM controller driver
In reply to dinguyen at opensource.altera.comFrom: Dinh Nguyen <[email protected]>
Enable the Altera SDRAM driver for the SoCFPGA platform.
--- include/configs/socfpga_common.h | 5 +++++ 1 file changed, 5 insertions(+)
include/configs/socfpga_common.h +5 -0
@@ -77,6 +77,11 @@#define CONFIG_SYS_PL310_BASE SOCFPGA_MPUL2_ADDRESS/* +* SDRAM controller +*/ +#define CONFIG_ALTERA_SDRAM + +/* * EPCS/EPCQx1 Serial Flash Controller */ #ifdef CONFIG_ALTERA_SPI
Signature · 1 line
2.2.1
PATCH v2 1/3 driver/ddr/altera: Add DDR driver for Altera's SDRAM controller
In reply to dinguyen at opensource.altera.comQuoted 7 lines · dinguyen at opensource.altera.com
From: Dinh Nguyen <[email protected]>
This patch enables the SDRAM controller that is used on Altera's SoCFPGA family. This patch configures the SDRAM controller based on a configuration file that is generated from the Quartus tool,
sdram_config.h.Signed-off-by Dinh Nguyen <[email protected]>
There's room for improvement, but the quality looks already OKish. If there's no opposition, I'd like to pick this one patch. I still have to check the others.
Best regards,
Marek Vasut
PATCH v2 2/3 driver/ddr/altera/: Add the sdram calibration portion
In reply to dinguyen at opensource.altera.comQuoted 5 lines · dinguyen at opensource.altera.com
From: Dinh Nguyen <[email protected]>
This patch adds the DDR calibration portion of the Altera SDRAM driver.
Signed-off-by Dinh Nguyen <[email protected]>
[...]
Quoted 19 lines
+/************************************************************************* ***** +
**************************************************************************
**** + ** NOTE: Special Rules for Globale Variables
** + **
** + ** All global variables that are explicitly initialized
(including ** + ** explicitly initialized to zero), are only
initialized once, during ** + ** configuration time, and not again
on reset. This means that they ** + ** preserve their current
contents across resets, which is needed for some ** + ** special cases
involving communication with external modules. In ** + **
addition, this avoids paying the price to have the memory initialized, ** + ** even for zeroed data, provided it is explicitly set to zero in the code, ** + ** and doesn't rely on implicit initialization.** +**************************************************************************
**** +
**************************************************************************
****/ +
drivers/ddr/altera/sequencer.c line 56
Quoted 6 lines
drivers/ddr/altera/sequencer.c new file +6
-0+/* +* Temporary workaround to place the initial stack pointer at a safe +* offset from end +*/ +asm(".global __alt_stack_pointer" ); +asm("__alt_stack_pointer = " __stringify(STACK_POINTER));
This is really scary. The idea here is to have some kind of a storage which is preserved over warm reboots, right ? Tom, Simon, Albert, don't we have some kind of a generic abstration for this kind of stuff ?
Quoted 22 lines
drivers/ddr/altera/sequencer.c new file +13
-0+/* Just to make the debugging code more uniform */ +#ifndef RW_MGR_MEM_NUMBER_OF_CS_PER_DIMM +#define RW_MGR_MEM_NUMBER_OF_CS_PER_DIMM 0 +#endif + +#define SDR_WRITE 1 +#define SDR_READ 0 + +#define DELTA_D 1 +#define MGR_SELECT_MASK 0xf8000 + +/* +* In order to reduce ROM size, most of the selectable calibration steps are + * decided at compile time based on the user's calibration mode selection, + * as captured by the
STATIC_CALIB_STEPSselection below.
+ *
+ * However, to support simulation-time selection of fast simulation mode, where + * we skip everything except the bare minimum, we need a few of the steps to + * be dynamic. In those cases, we either use theDYNAMIC_CALIB_STEPSfor the + * check, which is based on the rtl-supplied value, or we dynamically compute + * the value to use based on the dynamically-chosen calibration mode + */
Review
Quoted 2 lines
(quoted diff) +2
-0+ +#define BTFLD_FMT "%u"
Nit: Maybe you should just massage this BTFLD_FMT into the code and drop the macro.
drivers/ddr/altera/sequencer.c line 94
Quoted 12 lines
drivers/ddr/altera/sequencer.c new file +5
-0+/* For HPS running on actual hardware */ + +#define DLEVEL 0 +/* +* space around comma is required for varargs macro to remove comma if args + * is empty
+ */drivers/ddr/altera/sequencer.c new file +5
-0+#define BFM_GBL_SET (field, value) +#define BFM_GBL_GET (field) ((long unsigned int)0) +#define BFM_STAGE (stage) +#define BFM_INC_VFIFO +#define COV (label)
Are the macros above needed ?
Quoted 9 lines
drivers/ddr/altera/sequencer.c new file +9
-0+#define STATIC_IN_RTL_SIM 0 + +#define STATIC_SKIP_DELAY_LOOPS 0 + +#define STATIC_CALIB_STEPS (STATIC_IN_RTL_SIM | CALIB_SKIP_FULL_TEST | \ + STATIC_SKIP_DELAY_LOOPS) + +/* calibration steps requested by the rtl */ +uint16_t dyn_calib_steps;
[...]
drivers/ddr/altera/sequencer.c line 567
Quoted 6 lines
drivers/ddr/altera/sequencer.c new file +6
-0+static inline void scc_mgr_set_dm_in_delay (uint32_t write_group, +uint32_t dm,uint32_t delay) +{ +/* Load the setting in the SCC manager */ +sdr_ops ((u32 *)SCC_MGR_IO_IN_DELAY , + (RW_MGR_MEM_DQ_PER_WRITE_DQS +1 + dm) <<2 , delay,SDR_WRITE );
Won't it be better to convert this entire sdr_ops() to something like ...
addr = get_reg_address(...args...);writel(...value..., addr);
? I think that'd make this code a bit more readable. What do you think ?
Quoted 2 lines
(quoted diff) +2
-0+} +
[...]
Quoted 15 lines
drivers/ddr/altera/sequencer.c new file +15
-0+/* find a good dqs enable to use */ +static uint32_t rw_mgr_mem_calibrate_vfifo_find_dqs_en_phase (uint32_t grp) +{ +uint32_t i, d, v, p; +uint32_t max_working_cnt; +uint32_t fail_cnt; +uint32_t bit_chk; +uint32_t dtaps_per_ptap; +uint32_t found_begin, found_end; +uint32_t work_bgn, work_mid, work_end, tmp_delay; +uint32_t test_status; +uint32_t found_passing_read, found_failing_read, initial_failing_dtap; + +debug ("%s:%d %u\n" , __func__, __LINE__, grp); +BFM_STAGE ("find_dqs_en_phase" );
drivers/ddr/altera/sequencer.c line 1462
Quoted 10 lines
drivers/ddr/altera/sequencer.c new file +10
-0+ +reg_file_set_sub_stage (CAL_SUBSTAGE_VFIFO_CENTER ); + +scc_mgr_set_dqs_en_delay_all_ranks (grp,0 ); +scc_mgr_set_dqs_en_phase_all_ranks (grp,0 ); + + fail_cnt =0 ; + +/* ************************************************************** */ +/* * Step 0 : Determine number of delay taps for each phase tap * */
You might want to split the steps in this function into separate functions, since this functions is really extremely long. Would thats work please?
Quoted 8 lines
drivers/ddr/altera/sequencer.c new file +8
-0+ dtaps_per_ptap =0 ; + tmp_delay =0 ; +while (tmp_delay <IO_DELAY_PER_OPA_TAP ) { + dtaps_per_ptap++; + tmp_delay +=IO_DELAY_PER_DQS_EN_DCHAIN_TAP ; + } + dtaps_per_ptap--; + tmp_delay =0 ;
[...]
Quoted 5 lines
(quoted diff) +0
-0
b/drivers/ddr/altera/sequencer.hnew file mode 100644 index 0000000..29f61a8drivers/ddr/altera/sequencer.h new file +0
-0
[...]
drivers/ddr/altera/sequencer.h line 90
Quoted 10 lines
drivers/ddr/altera/sequencer.h new file +10
-0+/* MarkW: how should these base addresses be done for A-V? */ +#define BASE_PTR_MGR (0x00040000) +#define BASE_SCC_MGR (0x00058000) +#define BASE_REG_FILE (0x00070000) +#define BASE_TIMER (0x00078000) +#define BASE_PHY_MGR (0x00088000) +#define BASE_RW_MGR (0x00090000) +#define BASE_DATA_MGR (0x00098000) +#define BASE_MMR (0x000C0000) +#define BASE_TRK_MGR (0x000D0000)
No need for those () around value .
drivers/ddr/altera/sequencer.h line 99
Quoted 8 lines
drivers/ddr/altera/sequencer.h new file +8
-0+#define SCC_MGR_GROUP_COUNTER (BASE_SCC_MGR + 0x0000) +#define SCC_MGR_DQS_IN_DELAY (BASE_SCC_MGR + 0x0100) +#define SCC_MGR_DQS_EN_PHASE (BASE_SCC_MGR + 0x0200) +#define SCC_MGR_DQS_EN_DELAY (BASE_SCC_MGR + 0x0300) +#define SCC_MGR_DQDQS_OUT_PHASE (BASE_SCC_MGR + 0x0400) +#define SCC_MGR_OCT_OUT1_DELAY (BASE_SCC_MGR + 0x0500) +#define SCC_MGR_IO_OUT1_DELAY (BASE_SCC_MGR + 0x0700) +#define SCC_MGR_IO_IN_DELAY (BASE_SCC_MGR + 0x0900)
Here it _IS_ needed though ;)
[...]
drivers/ddr/altera/sequencer_auto_ac_init.c line 7
Quoted 13 lines
(quoted diff) +0
-0
b/drivers/ddr/altera/sequencer_auto_ac_init.cnew file mode 100644 index 0000000..358a0cadrivers/ddr/altera/sequencer_auto_ac_init.c new file +7
-0@@ -0,0 +1,85 @@ +/* +* Copyright Altera Corporation (C) 2012-2015 +* +* SPDX-License-Identifier: BSD-3-Clause +*/ + +const unsigned long ac_rom_init_size =36 ;
You can use ARRAY_SIZE() on the array below if that's really needed. No need to explicitly hardcode values :)
drivers/ddr/altera/sequencer_auto_ac_init.c line 8
Quoted 1 line
drivers/ddr/altera/sequencer_auto_ac_init.c new file +1
-0+const unsigned long ac_rom_init[36 ] = {
The compiler will compute the size of the array automatically.
Quoted 9 lines
drivers/ddr/altera/sequencer_auto_ac_init.c new file +9
-0+#ifdef CONFIG_SOCFPGA_ARRIA5 +/* The if..else... is not required if generated by tools */ +0x20700000 , +0x20780000 , +0x10080831 , +0x10080930 , +0x10090004 , +0x100a0008 , + 0x100b0000,
[...]
Quoted 6 lines
(quoted diff) +0
-0
b/drivers/ddr/altera/sequencer_auto_inst_init.cnew file mode 100644 index 0000000..9983c40
drivers/ddr/altera/sequencer_auto_inst_init.c line 10
Quoted 10 lines
drivers/ddr/altera/sequencer_auto_inst_init.c new file +10
-0@@ -0,0 +1,270 @@ +/* +* Copyright Altera Corporation (C) 2012-2015 +* +* SPDX-License-Identifier: BSD-3-Clause +*/ + +#ifdef CONFIG_SOCFPGA_ARRIA5 +/* The if..else... is not required if generated by tools */ +const alt_u32 inst_rom_init_size =126 ; +const alt_u32 inst_rom_init[126] = {
DTTO here.
[...]