Skip to contentSkip to conversation

drivers/ddr/altera: Add the DDR controller driver for SoCFPGA

PATCH RESEND Superseded dinguyen at opensource.altera.com 2 participants 8 messages Apr 16, 2015 – Apr 25, 2015

Subsystems (2)

v1 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

cover drivers/ddr/altera: Add the DDR controller driver for SoCFPGA

From: Dinh Nguyen <[email protected]>

Hi,

This is a resend of the patch series that adds the DDR controller driver for Altera's SoCFPGA platform. This resend contains a new patch:

arm: socfpga: enable the Altera SDRAM controller driver

This new patch is necessary for the driver to build against u-boot-socfpga/master.

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        |  294 ++
 arch/arm/include/asm/arch-socfpga/sdram_config.h |  100 +
 drivers/ddr/altera/Makefile                      |   12 +
 drivers/ddr/altera/sdram.c                       |  827 +++++
 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, 6079 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
#1 lore raw

PATCH RESEND 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.

---
 Makefile                                         |   1 +
 arch/arm/include/asm/arch-socfpga/sdram.h        | 294 ++++++++
 arch/arm/include/asm/arch-socfpga/sdram_config.h | 100 +++
 drivers/ddr/altera/sdram.c                       | 827 +++++++++++++++++++++++
 scripts/Makefile.spl                             |   1 +
 5 files changed, 1223 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
index 0f7d583..163d530 100644
@@ -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 +294 -0

294 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 +827 -0

827 lines not on this page · raw message

scripts/Makefile.spl +1 -0
index fcacb7f..a04b286 100644
@@ -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
#2 lore raw

PATCH RESEND 1/3 driver/ddr/altera: Add DDR driver for Altera's SDRAM controller

Hi!

arch/arm/include/asm/arch-socfpga/sdram.h line 11

Quoted 6 lines
arch/arm/include/asm/arch-socfpga/sdram.h new file +6 -0
+#ifndef	_SDRAM_H_
+#define	_SDRAM_H_
+
+#ifndef __ASSEMBLY__
+
+/* function declaration */

You can delete this comment.

Quoted 7 lines
arch/arm/include/asm/arch-socfpga/sdram.h new file +7 -0
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_0_THRESHOLDRSTCYCLES_31_0_LSB 0
+#define  \
+SDR_CTRLGRP_MPTHRESHOLDRST_0_THRESHOLDRSTCYCLES_31_0_MASK \
+0xffffffff
+/* Register template: sdr::ctrlgrp::mpthresholdrst::mpthresholdrst_1       */
+#define \

arch/arm/include/asm/arch-socfpga/sdram.h line 248

Quoted 10 lines
arch/arm/include/asm/arch-socfpga/sdram.h new file +10 -0
+SDR_CTRLGRP_MPTHRESHOLDRST_1_THRESHOLDRSTCYCLES_63_32_LSB 0
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_1_THRESHOLDRSTCYCLES_63_32_MASK \
+0xffffffff
+/* Register template: sdr::ctrlgrp::mpthresholdrst::mpthresholdrst_2       */
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_2_THRESHOLDRSTCYCLES_79_64_LSB 0
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_2_THRESHOLDRSTCYCLES_79_64_MASK \
+0x0000ffff

Can we get slightly shorter define names?

Quoted 21 lines
arch/arm/include/asm/arch-socfpga/sdram.h new file +21 -0
+/* Register template: sdr::ctrlgrp::remappriority                          */
+#define SDR_CTRLGRP_REMAPPRIORITY_PRIORITYREMAP_LSB 0
+#define SDR_CTRLGRP_REMAPPRIORITY_PRIORITYREMAP_MASK 0x000000ff
+/* Register template: sdr::ctrlgrp::phyctrl::phyctrl_0                     */
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_SAMPLECOUNT_19_0_LSB 12
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_SAMPLECOUNT_19_0_WIDTH 20
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_SAMPLECOUNT_19_0_SET(x) \
+ (((x) << 12) & 0xfffff000)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_ADDLATSEL_SET(x) \
+ (((x) << 10) & 0x00000c00)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_DQSLOGICDELAYEN_SET(x) \
+ (((x) << 6) & 0x000000c0)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_RESETDELAYEN_SET(x) \
+ (((x) << 8) & 0x00000100)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_LPDDRDIS_SET(x) \
+ (((x) << 9) & 0x00000200)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_DQSDELAYEN_SET(x) \
+ (((x) << 4) & 0x00000030)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_DQDELAYEN_SET(x) \
+ (((x) << 2) & 0x0000000c)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_ACDELAYEN_SET(x) \

arch/arm/include/asm/arch-socfpga/sdram.h line 279

Quoted 10 lines
arch/arm/include/asm/arch-socfpga/sdram.h new file +10 -0
+ (((x) << 0) & 0x00000003)
+/* Register template: sdr::ctrlgrp::phyctrl::phyctrl_1                     */
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_1_LONGIDLESAMPLECOUNT_19_0_WIDTH 20
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_1_LONGIDLESAMPLECOUNT_19_0_SET(x) \
+ (((x) << 12) & 0xfffff000)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_1_SAMPLECOUNT_31_20_SET(x) \
+ (((x) << 0) & 0x00000fff)
+/* Register template: sdr::ctrlgrp::phyctrl::phyctrl_2                     */
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_2_LONGIDLESAMPLECOUNT_31_20_SET(x) \
+ (((x) << 0) & 0x00000fff)

Too long names here, too..

arch/arm/include/asm/arch-socfpga/sdram_config.h line 6

Quoted 9 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +6 -0
@@ -0,0 +1,100 @@
+/*
+ * Copyright Altera Corporation (C) 2012-2015
+ *
+ * SPDX-License-Identifier:    BSD-3-Clause
+ */
+

If this file is autogenerated, you should mention it here.

arch/arm/include/asm/arch-socfpga/sdram_config.h line 23

Quoted 2 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +2 -0
+#ifdef CONFIG_SOCFPGA_ARRIA5
+/* The if..else... is not required if generated by tools */

What does this comment say?

arch/arm/include/asm/arch-socfpga/sdram_config.h line 92

Quoted 9 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +9 -0
+#define CONFIG_HPS_SDR_CTRLCFG_MPPACING_1_THRESHOLD2_3_0	0
+#define CONFIG_HPS_SDR_CTRLCFG_MPPACING_2_THRESHOLD2_35_4	0x41041041
+#define CONFIG_HPS_SDR_CTRLCFG_MPPACING_3_THRESHOLD2_59_36	0x410410
+#define CONFIG_HPS_SDR_CTRLCFG_MPTHRESHOLDRST_0_THRESHOLDRSTCYCLES_31_0 \
+0x01010101
+#define CONFIG_HPS_SDR_CTRLCFG_MPTHRESHOLDRST_1_THRESHOLDRSTCYCLES_63_32 \
+0x01010101
+#define CONFIG_HPS_SDR_CTRLCFG_MPTHRESHOLDRST_2_THRESHOLDRSTCYCLES_79_64 \
+0x0101

Drop "HPS" and "CTRLCFG" from the config names... they should still be unique and you'll not hit 80 column limits with just the name?

arch/arm/include/asm/arch-socfpga/sdram_config.h line 18

Quoted 1 line
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +1 -0
+#define COMPARE_FAIL_ACTION	return 1;

Macros that change control flow are nasty.

arch/arm/include/asm/arch-socfpga/sdram_config.h line 19

Quoted 1 line
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +1 -0
+/* Below function only applicable for SPL */

"Function below"?

Add ifdef so that it is not available for u-boot proper?

arch/arm/include/asm/arch-socfpga/sdram_config.h line 31

Quoted 12 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +12 -0
+typedef struct _sdram_prot_rule {
+	uint64_t	sdram_start;	/* SDRAM start address */
+	uint64_t	sdram_end;	/* SDRAM end address */
+	uint32_t	rule;		/* SDRAM protection rule number: 0-19 */
+	int		valid;		/* Rule valid or not? 1 - valid, 0 not*/
+
+	uint32_t	security;
+	uint32_t	portmask;
+	uint32_t	result;
+	uint32_t	lo_prot_id;
+	uint32_t	hi_prot_id;
+} sdram_prot_rule, *psdram_prot_rule;

Struct typedefs are nasty. Just use "struct sdram_prot_rule"?

arch/arm/include/asm/arch-socfpga/sdram_config.h line 36

Quoted 5 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +5 -0
+static void sdram_get_rule(psdram_prot_rule prule)
+{
+	uint32_t protruleaddr;
+	uint32_t protruleid;
+	uint32_t protruledata;

Remove "protrule" from local variables, as it is clear from context?

arch/arm/include/asm/arch-socfpga/sdram_config.h line 47

Quoted 11 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +11 -0
+static void sdram_set_protection_config(uint64_t sdram_start, uint64_t sdram_end)
+{
+	sdram_prot_rule rule;
+	int rules;
+
+	/* Start with accepting all SDRAM transaction */
+	writel(0x0, &sdr_ctrl->protport_default);
+
+	/* Clear all protection rules for warm boot case */
+
+	rule.sdram_start = 0;

Kill last empty line. And actually... maybe memset?

Quoted 7 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +7 -0
+static void set_sdr_addr_rw(void)
+{
+	int cs = CONFIG_HPS_SDR_CTRLCFG_DRAMADDRW_CSBITS;
+	int width = 8;
+	int rows = CONFIG_HPS_SDR_CTRLCFG_DRAMADDRW_ROWBITS;
+	int banks = CONFIG_HPS_SDR_CTRLCFG_DRAMADDRW_BANKBITS;
+	int cols = CONFIG_HPS_SDR_CTRLCFG_DRAMADDRW_COLBITS;

arch/arm/include/asm/arch-socfpga/sdram_config.h line 64

Quoted 10 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +10 -0
+	unsigned long long workaround_memsize = MEMSIZE_4G;
+
+	debug("Configuring DRAMADDRW\n");
+	clrsetbits_le32(&sdr_ctrl->dram_addrw, SDR_CTRLGRP_DRAMADDRW_COLBITS_MASK,
+			CONFIG_HPS_SDR_CTRLCFG_DRAMADDRW_COLBITS <<
+			SDR_CTRLGRP_DRAMADDRW_COLBITS_LSB);
+	/* SDRAM Failure When Accessing Non-Existent Memory
+	 * Update Preloader to artificially increase the number of rows so
+	 * that the memory thinks it has 4GB of RAM.
+	 */

Comment style, "rows, so"?

arch/arm/include/asm/arch-socfpga/sdram_config.h line 65

Quoted 1 line
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +1 -0
+/* To calculate SDRAM device size based on SDRAM controller parameters.

Drop "To".

arch/arm/include/asm/arch-socfpga/sdram_config.h line 72

Quoted 7 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +7 -0
+ * Size is specified in bytes.
+ *
+ * NOTE!!!!
+ * This function is compiled and linked into the preloader and
+ * Uboot (there may be others). So if this function changes, the Preloader
+ * and UBoot must be updated simultaneously.
+ */

Is that worth big note and four exclamation marks? Compiler should take care of recompilation...

Ok, this starts to look like something that we could actually merge.

Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#3 lore raw

PATCH RESEND 1/3 driver/ddr/altera: Add DDR driver for Altera's SDRAM controller

Hi Pavel,

Quoted 11 lines · Pavel Machek

Hi!

arch/arm/include/asm/arch-socfpga/sdram.h line 11

Quoted 6 lines
arch/arm/include/asm/arch-socfpga/sdram.h new file +6 -0
+#ifndef	_SDRAM_H_
+#define	_SDRAM_H_
+
+#ifndef __ASSEMBLY__
+
+/* function declaration */

You can delete this comment.

Ok...

Quoted 11 lines
Quoted 11 lines
arch/arm/include/asm/arch-socfpga/sdram.h new file +11 -0
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_0_THRESHOLDRSTCYCLES_31_0_LSB 0
+#define  \
+SDR_CTRLGRP_MPTHRESHOLDRST_0_THRESHOLDRSTCYCLES_31_0_MASK \
+0xffffffff
+/* Register template: sdr::ctrlgrp::mpthresholdrst::mpthresholdrst_1       */
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_1_THRESHOLDRSTCYCLES_63_32_LSB 0
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_1_THRESHOLDRSTCYCLES_63_32_MASK \
+0xffffffff
Quoted 8 lines

arch/arm/include/asm/arch-socfpga/sdram.h line 248

Quoted 6 lines
arch/arm/include/asm/arch-socfpga/sdram.h new file +6 -0
+/* Register template: sdr::ctrlgrp::mpthresholdrst::mpthresholdrst_2       */
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_2_THRESHOLDRSTCYCLES_79_64_LSB 0
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_2_THRESHOLDRSTCYCLES_79_64_MASK \
+0x0000ffff

Can we get slightly shorter define names?

I did think about shortening these defines a bit, but came to this reason that I should leave these alone. These defines are generated from the tools AFAICT. I don't think any sane person would try to have defines this long. So I still want to try to save the use case that the driver can still be used with the autogenerated header file from the tools in some form.

Quoted 35 lines
Quoted 22 lines
arch/arm/include/asm/arch-socfpga/sdram.h new file +21 -0
+/* Register template: sdr::ctrlgrp::remappriority                          */
+#define SDR_CTRLGRP_REMAPPRIORITY_PRIORITYREMAP_LSB 0
+#define SDR_CTRLGRP_REMAPPRIORITY_PRIORITYREMAP_MASK 0x000000ff
+/* Register template: sdr::ctrlgrp::phyctrl::phyctrl_0                     */
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_SAMPLECOUNT_19_0_LSB 12
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_SAMPLECOUNT_19_0_WIDTH 20
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_SAMPLECOUNT_19_0_SET(x) \
+ (((x) << 12) & 0xfffff000)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_ADDLATSEL_SET(x) \
+ (((x) << 10) & 0x00000c00)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_DQSLOGICDELAYEN_SET(x) \
+ (((x) << 6) & 0x000000c0)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_RESETDELAYEN_SET(x) \
+ (((x) << 8) & 0x00000100)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_LPDDRDIS_SET(x) \
+ (((x) << 9) & 0x00000200)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_DQSDELAYEN_SET(x) \
+ (((x) << 4) & 0x00000030)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_DQDELAYEN_SET(x) \
+ (((x) << 2) & 0x0000000c)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_0_ACDELAYEN_SET(x) \

arch/arm/include/asm/arch-socfpga/sdram.h line 279

Quoted 10 lines
arch/arm/include/asm/arch-socfpga/sdram.h new file +10 -0
+ (((x) << 0) & 0x00000003)
+/* Register template: sdr::ctrlgrp::phyctrl::phyctrl_1                     */
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_1_LONGIDLESAMPLECOUNT_19_0_WIDTH 20
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_1_LONGIDLESAMPLECOUNT_19_0_SET(x) \
+ (((x) << 12) & 0xfffff000)
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_1_SAMPLECOUNT_31_20_SET(x) \
+ (((x) << 0) & 0x00000fff)
+/* Register template: sdr::ctrlgrp::phyctrl::phyctrl_2                     */
+#define SDR_CTRLGRP_PHYCTRL_PHYCTRL_2_LONGIDLESAMPLECOUNT_31_20_SET(x) \
+ (((x) << 0) & 0x00000fff)

Too long names here, too..

Quoted 12 lines

arch/arm/include/asm/arch-socfpga/sdram_config.h line 6

Quoted 9 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +6 -0
@@ -0,0 +1,100 @@
+/*
+ * Copyright Altera Corporation (C) 2012-2015
+ *
+ * SPDX-License-Identifier:    BSD-3-Clause
+ */
+

If this file is autogenerated, you should mention it here.

Ok...

Quoted 5 lines

arch/arm/include/asm/arch-socfpga/sdram_config.h line 23

Quoted 2 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +2 -0
+#ifdef CONFIG_SOCFPGA_ARRIA5
+/* The if..else... is not required if generated by tools */

What does this comment say?

I have no idea, but will clean up.

Quoted 4 lines
Quoted 4 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +4 -0
+#define CONFIG_HPS_SDR_CTRLCFG_MPPACING_1_THRESHOLD2_3_0	0
+#define CONFIG_HPS_SDR_CTRLCFG_MPPACING_2_THRESHOLD2_35_4	0x41041041
+#define CONFIG_HPS_SDR_CTRLCFG_MPPACING_3_THRESHOLD2_59_36	0x410410
+#define CONFIG_HPS_SDR_CTRLCFG_MPTHRESHOLDRST_0_THRESHOLDRSTCYCLES_31_0 \
Quoted 9 lines

arch/arm/include/asm/arch-socfpga/sdram_config.h line 92

Quoted 5 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +5 -0
+0x01010101
+#define CONFIG_HPS_SDR_CTRLCFG_MPTHRESHOLDRST_1_THRESHOLDRSTCYCLES_63_32 \
+0x01010101
+#define CONFIG_HPS_SDR_CTRLCFG_MPTHRESHOLDRST_2_THRESHOLDRSTCYCLES_79_64 \
+0x0101

Drop "HPS" and "CTRLCFG" from the config names... they should still be unique and you'll not hit 80 column limits with just the name?

Same reasoning as I had for previous comment regarding long define names.

Quoted 4 lines

arch/arm/include/asm/arch-socfpga/sdram_config.h line 18

Quoted 1 line
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +1 -0
+#define COMPARE_FAIL_ACTION	return 1;

Macros that change control flow are nasty.

Will remove...

Quoted 3 lines

arch/arm/include/asm/arch-socfpga/sdram_config.h line 19

Quoted 1 line
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +1 -0
+/* Below function only applicable for SPL */

"Function below"?

Will clean..

Quoted 17 lines

Add ifdef so that it is not available for u-boot proper?

arch/arm/include/asm/arch-socfpga/sdram_config.h line 31

Quoted 12 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +12 -0
+typedef struct _sdram_prot_rule {
+	uint64_t	sdram_start;	/* SDRAM start address */
+	uint64_t	sdram_end;	/* SDRAM end address */
+	uint32_t	rule;		/* SDRAM protection rule number: 0-19 */
+	int		valid;		/* Rule valid or not? 1 - valid, 0 not*/
+
+	uint32_t	security;
+	uint32_t	portmask;
+	uint32_t	result;
+	uint32_t	lo_prot_id;
+	uint32_t	hi_prot_id;
+} sdram_prot_rule, *psdram_prot_rule;

Struct typedefs are nasty. Just use "struct sdram_prot_rule"?

Yeah...will clean up...

Quoted 9 lines

arch/arm/include/asm/arch-socfpga/sdram_config.h line 36

Quoted 6 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +5 -0
+static void sdram_get_rule(psdram_prot_rule prule)
+{
+	uint32_t protruleaddr;
+	uint32_t protruleid;
+	uint32_t protruledata;

Remove "protrule" from local variables, as it is clear from context?

Ok...

Quoted 5 lines
Quoted 5 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +5 -0
+static void sdram_set_protection_config(uint64_t sdram_start, uint64_t sdram_end)
+{
+	sdram_prot_rule rule;
+	int rules;
+
Quoted 8 lines

arch/arm/include/asm/arch-socfpga/sdram_config.h line 47

Quoted 6 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +6 -0
+	/* Start with accepting all SDRAM transaction */
+	writel(0x0, &sdr_ctrl->protport_default);
+
+	/* Clear all protection rules for warm boot case */
+
+	rule.sdram_start = 0;

Kill last empty line. And actually... maybe memset?

Ok...

Quoted 12 lines
Quoted 12 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +11 -0
+static void set_sdr_addr_rw(void)
+{
+	int cs = CONFIG_HPS_SDR_CTRLCFG_DRAMADDRW_CSBITS;
+	int width = 8;
+	int rows = CONFIG_HPS_SDR_CTRLCFG_DRAMADDRW_ROWBITS;
+	int banks = CONFIG_HPS_SDR_CTRLCFG_DRAMADDRW_BANKBITS;
+	int cols = CONFIG_HPS_SDR_CTRLCFG_DRAMADDRW_COLBITS;
+	unsigned long long workaround_memsize = MEMSIZE_4G;
+
+	debug("Configuring DRAMADDRW\n");
+	clrsetbits_le32(&sdr_ctrl->dram_addrw, SDR_CTRLGRP_DRAMADDRW_COLBITS_MASK,
Quoted 9 lines

arch/arm/include/asm/arch-socfpga/sdram_config.h line 64

Quoted 6 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +6 -0
+			CONFIG_HPS_SDR_CTRLCFG_DRAMADDRW_COLBITS <<
+			SDR_CTRLGRP_DRAMADDRW_COLBITS_LSB);
+	/* SDRAM Failure When Accessing Non-Existent Memory
+	 * Update Preloader to artificially increase the number of rows so
+	 * that the memory thinks it has 4GB of RAM.
+	 */

Comment style, "rows, so"?

Will clean up...

Quoted 5 lines

arch/arm/include/asm/arch-socfpga/sdram_config.h line 65

Quoted 2 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +1 -0
+/* To calculate SDRAM device size based on SDRAM controller parameters.

Drop "To".

Ok...

Quoted 10 lines

arch/arm/include/asm/arch-socfpga/sdram_config.h line 72

Quoted 7 lines
arch/arm/include/asm/arch-socfpga/sdram_config.h new file +7 -0
+ * Size is specified in bytes.
+ *
+ * NOTE!!!!
+ * This function is compiled and linked into the preloader and
+ * Uboot (there may be others). So if this function changes, the Preloader
+ * and UBoot must be updated simultaneously.
+ */

Is that worth big note and four exclamation marks? Compiler should take care of recompilation...

Yeah, I'll clean up...

Quoted 2 lines

Ok, this starts to look like something that we could actually merge.

Almost...

thanks,
Dinh

#4 lore raw

PATCH RESEND 1/3 driver/ddr/altera: Add DDR driver for Altera's SDRAM controller

Hi!

Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
arch/arm/include/asm/arch-socfpga/sdram.h new file +11 -0
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_0_THRESHOLDRSTCYCLES_31_0_LSB 0
+#define  \
+SDR_CTRLGRP_MPTHRESHOLDRST_0_THRESHOLDRSTCYCLES_31_0_MASK \
+0xffffffff
+/* Register template: sdr::ctrlgrp::mpthresholdrst::mpthresholdrst_1       */
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_1_THRESHOLDRSTCYCLES_63_32_LSB 0
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_1_THRESHOLDRSTCYCLES_63_32_MASK \
+0xffffffff
Quoted 8 lines

arch/arm/include/asm/arch-socfpga/sdram.h line 248

Quoted 6 lines
arch/arm/include/asm/arch-socfpga/sdram.h new file +6 -0
+/* Register template: sdr::ctrlgrp::mpthresholdrst::mpthresholdrst_2       */
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_2_THRESHOLDRSTCYCLES_79_64_LSB 0
+#define \
+SDR_CTRLGRP_MPTHRESHOLDRST_2_THRESHOLDRSTCYCLES_79_64_MASK \
+0x0000ffff

Can we get slightly shorter define names?

Quoted 6 lines

I did think about shortening these defines a bit, but came to this reason that I should leave these alone. These defines are generated from the tools AFAICT. I don't think any sane person would try to have defines this long. So I still want to try to save the use case that the driver can still be used with the autogenerated header file from the tools in some form.

Ok.

[I'd suggest placing the defines on single lines, ignoring 80 column rule, but then checkpatch would scream, so I guess it is ok as it is.]

Best regards,
Pavel

Signature · 2 lines
(english) http://www.livejournal.com/~pavelmachek
(cesky, pictures) http://atrey.karlin.mff.cuni.cz/~pavel/picture/horses/blog.html
#5 lore raw

PATCH RESEND 2/3 driver/ddr/altera/: Add the sdram calibration portion

In reply to dinguyen at opensource.altera.com

From: 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
new file mode 100644
index 0000000..38fba57
@@ -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.

#6 lore raw

PATCH RESEND 2/3 driver/ddr/altera/: Add the sdram calibration portion

Hi!

drivers/ddr/altera/Makefile line 3

Quoted 5 lines

+++ b/drivers/ddr/altera/Makefile

drivers/ddr/altera/Makefile new file +3 -0
@@ -0,0 +1,12 @@
+#
+# (C) Copyright 2000-2003
+# Wolfgang Denk, DENX Software Engineering, wd at denx.de.

Umm. Looks like nothing of Wolfgang's original code is remaining at this point, you can delete this.

drivers/ddr/altera/sequencer.c line 39

Quoted 4 lines
drivers/ddr/altera/sequencer.c new file +4 -0
+/******************************************************************************
+ ******************************************************************************
+ ** NOTE: Special Rules for Globale Variables                                **
+ **                                                                          **

They are global, not globale.

drivers/ddr/altera/sequencer.c line 47

Quoted 8 lines
drivers/ddr/altera/sequencer.c new file +8 -0
+ ** 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.                             **

Is this true for variables in this .c file, or for all of them?

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));

How is this different from normal variable?

drivers/ddr/altera/sequencer.c line 85

Quoted 3 lines
drivers/ddr/altera/sequencer.c new file +3 -0
+/* For HPS running on actual hardware */
+
+#define DLEVEL 0

DEBUG_LEVEL?

drivers/ddr/altera/sequencer.c line 94

Quoted 9 lines
drivers/ddr/altera/sequencer.c new file +9 -0
+/*
+ * space around comma is required for varargs macro to remove comma if args
+ * is empty
+ */
+#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)

I don't get the comment, or the macros. Can you just remove them?

Thanks,
Pavel

#7 lore raw

PATCH RESEND 3/3 arm: socfpga: enable the Altera SDRAM controller driver

In reply to dinguyen at opensource.altera.com

From: 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
index cae744d..9b52050 100644
@@ -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