Skip to contentSkip to conversation

dt-bindings: memory: allwinner: add sunxi DRAM type constants

PATCH New James Hilliard 1 participant 2 messages Mar 14

Subsystems (5)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/2 dt-bindings: memory: allwinner: add sunxi DRAM type constants

Add constants for the Allwinner DRAM type values used by the H616 DRAM profile binding. This allows U-Boot DRAM profile nodes to describe allwinner,dram-type numerically instead of using string literals.

---
 include/dt-bindings/memory/sunxi-dram.h | 11 +++++++++++
 1 file changed, 11 insertions(+)
 create mode 100644 include/dt-bindings/memory/sunxi-dram.h
include/dt-bindings/memory/sunxi-dram.h new file +11 -0
new file mode 100644
index 00000000000..c0a3201123a
@@ -0,0 +1,11 @@
+/* SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause */
+
+#ifndef _DT_BINDINGS_MEMORY_SUNXI_DRAM_H
+#define _DT_BINDINGS_MEMORY_SUNXI_DRAM_H
+
+#define SUNXI_DRAM_TYPE_DDR3		3
+#define SUNXI_DRAM_TYPE_DDR4		4
+#define SUNXI_DRAM_TYPE_LPDDR3		7
+#define SUNXI_DRAM_TYPE_LPDDR4		8
+
+#endif
Signature · 1 line
2.43.0
#1 lore raw

PATCH v2 2/2 sunxi: h616: support DRAM profiles selected by GPIO straps

Some H616 boards use different DRAM types across hardware revisions and select the matching boot0 parameters from strap GPIOs. Add an H616 DRAM profile source choice so SPL can either keep using the existing fixed Kconfig profile or read a profile ID from the U-Boot device tree at boot.

When GPIO-based selection is enabled, SPL decodes the profile ID from the allwinner,dram-coding-gpios property in /dram-profiles and loads the matching profile from that node. Profiles can either describe the DRAM parameters directly or reference a shared parameter block through the allwinner,dram-params phandle, which avoids duplicating identical tables for multiple hardware revisions.

Refactor the H616 timing code around per-type backends so the common controller flow stays in one place while type-specific PHY init data, mode register programming, and timing setup live in the corresponding backend files. Fixed-profile builds still link only the selected backend, while GPIO-selected builds can dispatch at runtime based on the loaded profile.

Keep the fixed-profile Kconfig flow as the default and hide its prompts when GPIO-based profile selection is enabled.

---
 .../include/asm/arch-sunxi/dram_sun50i_h616.h |  42 +-
 arch/arm/mach-sunxi/Kconfig                   |  49 +-
 arch/arm/mach-sunxi/dram_sun50i_h616.c        | 698 +++++++++---------
 arch/arm/mach-sunxi/dram_timings/Makefile     |   4 +
 arch/arm/mach-sunxi/dram_timings/h616.c       |  37 +
 .../mach-sunxi/dram_timings/h616_ddr3_1333.c  | 149 +++-
 .../arm/mach-sunxi/dram_timings/h616_lpddr3.c | 129 +++-
 .../dram_timings/h616_lpddr4_2133.c           | 120 ++-
 8 files changed, 839 insertions(+), 389 deletions(-)
 create mode 100644 arch/arm/mach-sunxi/dram_timings/h616.c
arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h +39 -3
index a8fdda124a0..793809bba40 100644
@@ -168,13 +168,49 @@ struct dram_config {
 	u8 bus_full_width;
 };
 
-static inline int ns_to_t(int nanoseconds)
+#define H616_PHY_INIT_LEN	27
+
+struct h616_dram_phy_cfg {
+	u32 training_reg14;
+	u32 training_reg1c;
+	u32 write_leveling_reg0c;
+	u32 write_leveling_reg10;
+	u32 dx_dri_hi;
+	u32 dx_odt_lo;
+	u32 dx_odt_hi;
+	u32 tpr6_val;
+	u32 phy_mode;
+	bool clear_phy_ctl_0x4_80;
+	bool set_lpddr4_dx_odt_mode;
+	bool clear_read_training_regs;
+};
+
+struct h616_dram_backend {
+	u32 mstr_flags;
+	u32 odtcfg;
+	bool set_com_ctl_0x50;
+	const u8 *(*get_phy_init)(void);
+	void (*set_timing_params)(const struct dram_para *para);
+	void (*get_phy_cfg)(const struct dram_para *para,
+			    struct h616_dram_phy_cfg *phy_cfg);
+	void (*program_mode_registers)(const struct dram_para *para,
+				       struct sunxi_mctl_ctl_reg *mctl_ctl);
+	void (*ca_bit_delay_compensation)(const struct dram_para *para,
+					  const struct dram_config *config,
+					  u32 val);
+};
+
+static inline int h616_ns_to_t(const struct dram_para *para, int nanoseconds)
 {
-	const unsigned int ctrl_freq = CONFIG_DRAM_CLK / 2;
+	const unsigned int ctrl_freq = para->clk / 2;
 
 	return DIV_ROUND_UP(ctrl_freq * nanoseconds, 1000);
 }
 
-void mctl_set_timing_params(const struct dram_para *para);
+extern const struct h616_dram_backend h616_ddr3_backend;
+extern const struct h616_dram_backend h616_lpddr3_backend;
+extern const struct h616_dram_backend h616_lpddr4_backend;
+
+const struct h616_dram_backend *h616_get_dram_backend(const struct dram_para *para);
 
 #endif /* _SUNXI_DRAM_SUN50I_H616_H */
arch/arm/mach-sunxi/Kconfig +45 -4

85 lines not on this page · raw message

arch/arm/mach-sunxi/dram_sun50i_h616.c +364 -334

895 lines not on this page · raw message

arch/arm/mach-sunxi/dram_timings/Makefile +4 -0
index 5de9fd5aab4..6843b9d323e 100644
@@ -3,6 +3,10 @@ obj-$(CONFIG_SUNXI_DRAM_LPDDR3_STOCK)	+= lpddr3_stock.o
 obj-$(CONFIG_SUNXI_DRAM_DDR2_V3S)	+= ddr2_v3s.o
 obj-$(CONFIG_SUNXI_DRAM_H6_LPDDR3)	+= h6_lpddr3.o
 obj-$(CONFIG_SUNXI_DRAM_H6_DDR3_1333)	+= h6_ddr3_1333.o
+obj-$(CONFIG_DRAM_SUN50I_H616)		+= h616.o
+obj-$(CONFIG_SUNXI_DRAM_H616_GPIO_SELECT)	+= h616_ddr3_1333.o
+obj-$(CONFIG_SUNXI_DRAM_H616_GPIO_SELECT)	+= h616_lpddr3.o
+obj-$(CONFIG_SUNXI_DRAM_H616_GPIO_SELECT)	+= h616_lpddr4_2133.o
 obj-$(CONFIG_SUNXI_DRAM_H616_DDR3_1333)	+= h616_ddr3_1333.o
 obj-$(CONFIG_SUNXI_DRAM_H616_LPDDR3)	+= h616_lpddr3.o
 obj-$(CONFIG_SUNXI_DRAM_H616_LPDDR4)	+= h616_lpddr4_2133.o
arch/arm/mach-sunxi/dram_timings/h616.c new file +37 -0
new file mode 100644
index 00000000000..10d7858a71d
@@ -0,0 +1,37 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * sun50i H616 DRAM backend dispatcher
+ *
+ * Select the appropriate H616 DRAM backend at compile time for fixed-profile
+ * builds and at runtime when GPIO profile selection is enabled.
+ */
+
+#include <asm/arch/dram.h>
+#include <vsprintf.h>
+
+const struct h616_dram_backend *h616_get_dram_backend(const struct dram_para *para)
+{
+	if (IS_ENABLED(CONFIG_SUNXI_DRAM_H616_GPIO_SELECT)) {
+		switch (para->type) {
+		case SUNXI_DRAM_TYPE_DDR3:
+			return &h616_ddr3_backend;
+		case SUNXI_DRAM_TYPE_LPDDR3:
+			return &h616_lpddr3_backend;
+		case SUNXI_DRAM_TYPE_LPDDR4:
+			return &h616_lpddr4_backend;
+		case SUNXI_DRAM_TYPE_DDR4:
+		default:
+			panic("Unsupported H616 DRAM type: %u\n", para->type);
+		}
+	}
+
+	if (IS_ENABLED(CONFIG_SUNXI_DRAM_H616_DDR3_1333))
+		return &h616_ddr3_backend;
+	if (IS_ENABLED(CONFIG_SUNXI_DRAM_H616_LPDDR3))
+		return &h616_lpddr3_backend;
+	if (IS_ENABLED(CONFIG_SUNXI_DRAM_H616_LPDDR4))
+		return &h616_lpddr4_backend;
+
+	panic("No H616 DRAM backend selected\n");
+	return NULL;
+}
arch/arm/mach-sunxi/dram_timings/h616_ddr3_1333.c +133 -16

169 lines not on this page · raw message

arch/arm/mach-sunxi/dram_timings/h616_lpddr3.c +113 -16

149 lines not on this page · raw message

arch/arm/mach-sunxi/dram_timings/h616_lpddr4_2133.c +104 -16

145 lines not on this page · raw message

Signature · 1 line
2.43.0