Skip to contentSkip to conversation

sunxi: h616: make ns_to_t() use the DRAM clock

PATCH New James Hilliard 1 participant 5 messages Mar 27

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

PATCH v4 1/5 sunxi: h616: make ns_to_t() use the DRAM clock

Pass struct dram_para into ns_to_t() and derive the controller clock from para->clk instead of CONFIG_DRAM_CLK.

This prepares the H616 timing code for selecting the DRAM backend from runtime parameters instead of a fixed build-time clock setting.

---
 .../include/asm/arch-sunxi/dram_sun50i_h616.h |  4 +--
 .../mach-sunxi/dram_timings/h616_ddr3_1333.c  | 30 +++++++++----------
 .../arm/mach-sunxi/dram_timings/h616_lpddr3.c | 30 +++++++++----------
 .../dram_timings/h616_lpddr4_2133.c           | 30 +++++++++----------
 4 files changed, 47 insertions(+), 47 deletions(-)
arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h +2 -2
index a8fdda124a0..c35ef0252cb 100644
@@ -168,9 +168,9 @@ struct dram_config {
 	u8 bus_full_width;
 };
 
-static inline int ns_to_t(int nanoseconds)
+static inline int 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);
 }
arch/arm/mach-sunxi/dram_timings/h616_ddr3_1333.c +15 -15
index 3faf8d5bd97..1f0d0de198c 100644
@@ -20,27 +20,27 @@ void mctl_set_timing_params(const struct dram_para *para)
 			(struct sunxi_mctl_ctl_reg *)SUNXI_DRAM_CTL0_BASE;
 
 	u8 tccd		= 2;			/* JEDEC: 4nCK */
-	u8 tfaw		= ns_to_t(50);		/* JEDEC: 30 ns w/ 1K pages */
-	u8 trrd		= max(ns_to_t(6), 4);	/* JEDEC: max(6 ns, 4nCK) */
-	u8 trcd		= ns_to_t(15);		/* JEDEC: 13.5 ns */
-	u8 trc		= ns_to_t(53);		/* JEDEC: 49.5 ns */
-	u8 txp		= max(ns_to_t(6), 3);	/* JEDEC: max(6 ns, 3nCK) */
-	u8 trtp		= max(ns_to_t(8), 2);	/* JEDEC: max(7.5 ns, 4nCK) */
-	u8 trp		= ns_to_t(15);		/* JEDEC: >= 13.75 ns */
-	u8 tras		= ns_to_t(38);		/* JEDEC >= 36 ns, <= 9*trefi */
-	u16 trefi	= ns_to_t(7800) / 32;	/* JEDEC: 7.8us@Tcase <= 85C */
-	u16 trfc	= ns_to_t(350);		/* JEDEC: 160 ns for 2Gb */
+	u8 tfaw		= ns_to_t(para, 50);	/* JEDEC: 30 ns w/ 1K pages */
+	u8 trrd		= max(ns_to_t(para, 6), 4); /* JEDEC: max(6 ns, 4nCK) */
+	u8 trcd		= ns_to_t(para, 15);	/* JEDEC: 13.5 ns */
+	u8 trc		= ns_to_t(para, 53);	/* JEDEC: 49.5 ns */
+	u8 txp		= max(ns_to_t(para, 6), 3); /* JEDEC: max(6 ns, 3nCK) */
+	u8 trtp		= max(ns_to_t(para, 8), 2); /* JEDEC: max(7.5 ns, 4nCK) */
+	u8 trp		= ns_to_t(para, 15);	/* JEDEC: >= 13.75 ns */
+	u8 tras		= ns_to_t(para, 38);	/* JEDEC >= 36 ns, <= 9*trefi */
+	u16 trefi	= ns_to_t(para, 7800) / 32; /* JEDEC: 7.8us@Tcase <= 85C */
+	u16 trfc	= ns_to_t(para, 350);	/* JEDEC: 160 ns for 2Gb */
 	u16 txsr	= 4;			/* ? */
 
 	u8 tmrw		= 0;			/* ? */
 	u8 tmrd		= 4;			/* JEDEC: 4nCK */
-	u8 tmod		= max(ns_to_t(15), 12);	/* JEDEC: max(15 ns, 12nCK) */
-	u8 tcke		= max(ns_to_t(6), 3);	/* JEDEC: max(5.625 ns, 3nCK) */
-	u8 tcksrx	= max(ns_to_t(10), 4);	/* JEDEC: max(10 ns, 5nCK) */
-	u8 tcksre	= max(ns_to_t(10), 4);	/* JEDEC: max(10 ns, 5nCK) */
+	u8 tmod		= max(ns_to_t(para, 15), 12); /* JEDEC: max(15 ns, 12nCK) */
+	u8 tcke		= max(ns_to_t(para, 6), 3); /* JEDEC: max(5.625 ns, 3nCK) */
+	u8 tcksrx	= max(ns_to_t(para, 10), 4); /* JEDEC: max(10 ns, 5nCK) */
+	u8 tcksre	= max(ns_to_t(para, 10), 4); /* JEDEC: max(10 ns, 5nCK) */
 	u8 tckesr	= tcke + 1;		/* JEDEC: tCKE(min) + 1nCK */
 	u8 trasmax	= (para->clk / 2) / 15;	/* JEDEC: tREFI * 9 */
-	u8 txs		= ns_to_t(360) / 32;	/* JEDEC: max(5nCK,tRFC+10ns) */
+	u8 txs		= ns_to_t(para, 360) / 32; /* JEDEC: max(5nCK,tRFC+10ns) */
 	u8 txsdll	= 16;			/* JEDEC: 512 nCK */
 	u8 txsabort	= 4;			/* ? */
 	u8 txsfast	= 4;			/* ? */
arch/arm/mach-sunxi/dram_timings/h616_lpddr3.c +15 -15
index ce2ffa7a020..e753fd7b4af 100644
@@ -20,27 +20,27 @@ void mctl_set_timing_params(const struct dram_para *para)
 			(struct sunxi_mctl_ctl_reg *)SUNXI_DRAM_CTL0_BASE;
 
 	u8 tccd		= 2;
-	u8 tfaw		= ns_to_t(50);
-	u8 trrd		= max(ns_to_t(6), 4);
-	u8 trcd		= ns_to_t(24);
-	u8 trc		= ns_to_t(70);
-	u8 txp		= max(ns_to_t(8), 3);
-	u8 trtp		= max(ns_to_t(8), 2);
-	u8 trp		= ns_to_t(27);
-	u8 tras		= ns_to_t(41);
-	u16 trefi	= ns_to_t(7800) / 64;
-	u16 trfc	= ns_to_t(210);
+	u8 tfaw		= ns_to_t(para, 50);
+	u8 trrd		= max(ns_to_t(para, 6), 4);
+	u8 trcd		= ns_to_t(para, 24);
+	u8 trc		= ns_to_t(para, 70);
+	u8 txp		= max(ns_to_t(para, 8), 3);
+	u8 trtp		= max(ns_to_t(para, 8), 2);
+	u8 trp		= ns_to_t(para, 27);
+	u8 tras		= ns_to_t(para, 41);
+	u16 trefi	= ns_to_t(para, 7800) / 64;
+	u16 trfc	= ns_to_t(para, 210);
 	u16 txsr	= 88;
 
 	u8 tmrw		= 5;
 	u8 tmrd		= 5;
-	u8 tmod		= max(ns_to_t(15), 12);
-	u8 tcke		= max(ns_to_t(6), 3);
-	u8 tcksrx	= max(ns_to_t(12), 4);
-	u8 tcksre	= max(ns_to_t(12), 4);
+	u8 tmod		= max(ns_to_t(para, 15), 12);
+	u8 tcke		= max(ns_to_t(para, 6), 3);
+	u8 tcksrx	= max(ns_to_t(para, 12), 4);
+	u8 tcksre	= max(ns_to_t(para, 12), 4);
 	u8 tckesr	= tcke + 2;
 	u8 trasmax	= (para->clk / 2) / 16;
-	u8 txs		= ns_to_t(360) / 32;
+	u8 txs		= ns_to_t(para, 360) / 32;
 	u8 txsdll	= 16;
 	u8 txsabort	= 4;
 	u8 txsfast	= 4;
arch/arm/mach-sunxi/dram_timings/h616_lpddr4_2133.c +15 -15
index 6f5c4acbd62..bbe401464eb 100644
@@ -18,24 +18,24 @@ void mctl_set_timing_params(const struct dram_para *para)
 			(struct sunxi_mctl_ctl_reg *)SUNXI_DRAM_CTL0_BASE;
 
 	u8 tccd		= 4;
-	u8 tfaw		= ns_to_t(40);
-	u8 trrd		= max(ns_to_t(10), 2);
-	u8 trcd		= max(ns_to_t(18), 2);
-	u8 trc		= ns_to_t(65);
-	u8 txp		= max(ns_to_t(8), 2);
+	u8 tfaw		= ns_to_t(para, 40);
+	u8 trrd		= max(ns_to_t(para, 10), 2);
+	u8 trcd		= max(ns_to_t(para, 18), 2);
+	u8 trc		= ns_to_t(para, 65);
+	u8 txp		= max(ns_to_t(para, 8), 2);
 	u8 trtp		= 4;
-	u8 trp		= ns_to_t(21);
-	u8 tras		= ns_to_t(42);
-	u16 trefi	= ns_to_t(3904) / 32;
-	u16 trfc	= ns_to_t(280);
-	u16 txsr	= ns_to_t(190);
+	u8 trp		= ns_to_t(para, 21);
+	u8 tras		= ns_to_t(para, 42);
+	u16 trefi	= ns_to_t(para, 3904) / 32;
+	u16 trfc	= ns_to_t(para, 280);
+	u16 txsr	= ns_to_t(para, 190);
 
-	u8 tmrw		= max(ns_to_t(14), 5);
+	u8 tmrw		= max(ns_to_t(para, 14), 5);
 	u8 tmrd		= tmrw;
 	u8 tmod		= 12;
-	u8 tcke		= max(ns_to_t(15), 2);
-	u8 tcksrx	= max(ns_to_t(2), 2);
-	u8 tcksre	= max(ns_to_t(5), 2);
+	u8 tcke		= max(ns_to_t(para, 15), 2);
+	u8 tcksrx	= max(ns_to_t(para, 2), 2);
+	u8 tcksre	= max(ns_to_t(para, 5), 2);
 	u8 tckesr	= tcke;
 	u8 trasmax	= (trefi * 9) / 32;
 	u8 txs		= 4;
@@ -49,7 +49,7 @@ void mctl_set_timing_params(const struct dram_para *para)
 
 	u8 twtp		= 24;
 	u8 twr2rd	= max(trrd, (u8)4) + 14;
-	u8 trd2wr	= (ns_to_t(4) + 17) - ns_to_t(1);
+	u8 trd2wr	= (ns_to_t(para, 4) + 17) - ns_to_t(para, 1);
 
 	/* set DRAM timing */
 	writel((twtp << 24) | (tfaw << 16) | (trasmax << 8) | tras,
Signature · 1 line
2.43.0
#1 lore raw

PATCH v4 2/5 sunxi: h616: move PHY init tables into timing files

Store the compile-time-selected PHY initialisation data alongside each H616 timing implementation instead of in the common H616 DRAM code.

The common code still consumes a single phy_init pointer, so this only moves the DRAM-type-specific data without changing the selection model.

---
 .../include/asm/arch-sunxi/dram_sun50i_h616.h |  3 ++
 arch/arm/mach-sunxi/dram_sun50i_h616.c        | 41 +------------------
 .../mach-sunxi/dram_timings/h616_ddr3_1333.c  | 18 ++++++++
 .../arm/mach-sunxi/dram_timings/h616_lpddr3.c | 18 ++++++++
 .../dram_timings/h616_lpddr4_2133.c           | 18 ++++++++
 5 files changed, 58 insertions(+), 40 deletions(-)
arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h +3 -0
index c35ef0252cb..fa12d5d2685 100644
@@ -168,6 +168,8 @@ struct dram_config {
 	u8 bus_full_width;
 };
 
+#define H616_PHY_INIT_LEN	27
+
 static inline int ns_to_t(const struct dram_para *para, int nanoseconds)
 {
 	const unsigned int ctrl_freq = para->clk / 2;
@@ -175,6 +177,7 @@ static inline int ns_to_t(const struct dram_para *para, int nanoseconds)
 	return DIV_ROUND_UP(ctrl_freq * nanoseconds, 1000);
 }
 
+extern const u8 *phy_init;
 void mctl_set_timing_params(const struct dram_para *para);
 
 #endif /* _SUNXI_DRAM_SUN50I_H616_H */
arch/arm/mach-sunxi/dram_sun50i_h616.c +1 -40

53 lines not on this page · raw message

arch/arm/mach-sunxi/dram_timings/h616_ddr3_1333.c +18 -0
index 1f0d0de198c..f367f604d5f 100644
@@ -14,6 +14,24 @@
 #include <asm/arch/dram.h>
 #include <asm/arch/cpu.h>
 
+static const u8 h616_ddr3_phy_init_default[H616_PHY_INIT_LEN] = {
+	0x07, 0x0b, 0x02, 0x16, 0x0d, 0x0e, 0x14, 0x19,
+	0x0a, 0x15, 0x03, 0x13, 0x04, 0x0c, 0x10, 0x06,
+	0x0f, 0x11, 0x1a, 0x01, 0x12, 0x17, 0x00, 0x08,
+	0x09, 0x05, 0x18
+};
+
+static const u8 h616_ddr3_phy_init_addr_map_1[H616_PHY_INIT_LEN] = {
+	0x08, 0x02, 0x12, 0x05, 0x15, 0x17, 0x18, 0x0b,
+	0x14, 0x07, 0x04, 0x13, 0x0c, 0x00, 0x16, 0x1a,
+	0x0a, 0x11, 0x03, 0x10, 0x0e, 0x01, 0x0d, 0x19,
+	0x06, 0x09, 0x0f
+};
+
+const u8 *phy_init = IS_ENABLED(CONFIG_DRAM_SUNXI_PHY_ADDR_MAP_1) ?
+		     h616_ddr3_phy_init_addr_map_1 :
+		     h616_ddr3_phy_init_default;
+
 void mctl_set_timing_params(const struct dram_para *para)
 {
 	struct sunxi_mctl_ctl_reg * const mctl_ctl =
arch/arm/mach-sunxi/dram_timings/h616_lpddr3.c +18 -0
index e753fd7b4af..7efb1b22a84 100644
@@ -14,6 +14,24 @@
 #include <asm/arch/dram.h>
 #include <asm/arch/cpu.h>
 
+static const u8 h616_lpddr3_phy_init_default[H616_PHY_INIT_LEN] = {
+	0x18, 0x06, 0x00, 0x05, 0x04, 0x03, 0x09, 0x02,
+	0x08, 0x01, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+	0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x07,
+	0x17, 0x19, 0x1a
+};
+
+static const u8 h616_lpddr3_phy_init_addr_map_1[H616_PHY_INIT_LEN] = {
+	0x18, 0x00, 0x04, 0x09, 0x06, 0x05, 0x02, 0x19,
+	0x17, 0x03, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+	0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x07,
+	0x08, 0x01, 0x1a
+};
+
+const u8 *phy_init = IS_ENABLED(CONFIG_DRAM_SUNXI_PHY_ADDR_MAP_1) ?
+		     h616_lpddr3_phy_init_addr_map_1 :
+		     h616_lpddr3_phy_init_default;
+
 void mctl_set_timing_params(const struct dram_para *para)
 {
 	struct sunxi_mctl_ctl_reg * const mctl_ctl =
arch/arm/mach-sunxi/dram_timings/h616_lpddr4_2133.c +18 -0
index bbe401464eb..055d8dd3cad 100644
@@ -12,6 +12,24 @@
 #include <asm/arch/dram.h>
 #include <asm/arch/cpu.h>
 
+static const u8 h616_lpddr4_phy_init_default[H616_PHY_INIT_LEN] = {
+	0x02, 0x00, 0x17, 0x05, 0x04, 0x19, 0x06, 0x07,
+	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+	0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x01,
+	0x18, 0x03, 0x1a
+};
+
+static const u8 h616_lpddr4_phy_init_addr_map_1[H616_PHY_INIT_LEN] = {
+	0x03, 0x00, 0x17, 0x05, 0x02, 0x19, 0x06, 0x07,
+	0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f,
+	0x10, 0x11, 0x12, 0x13, 0x14, 0x15, 0x16, 0x01,
+	0x18, 0x04, 0x1a
+};
+
+const u8 *phy_init = IS_ENABLED(CONFIG_DRAM_SUNXI_PHY_ADDR_MAP_1) ?
+		     h616_lpddr4_phy_init_addr_map_1 :
+		     h616_lpddr4_phy_init_default;
+
 void mctl_set_timing_params(const struct dram_para *para)
 {
 	struct sunxi_mctl_ctl_reg * const mctl_ctl =
Signature · 1 line
2.43.0
#2 lore raw

PATCH v4 3/5 sunxi: h616: split timing and PHY init helpers by DRAM type

In reply to James Hilliard

Give each H616 timing file its own timing entry point and PHY initialisation accessor, then dispatch to them through inline helpers in the H616 header.

This keeps the current fixed-profile build model intact while making the common H616 code consume DRAM-type-specific helpers through a uniform interface.

---
 .../include/asm/arch-sunxi/dram_sun50i_h616.h | 34 +++++++++++++++++--
 arch/arm/mach-sunxi/dram_sun50i_h616.c        |  1 +
 .../mach-sunxi/dram_timings/h616_ddr3_1333.c  | 12 ++++---
 .../arm/mach-sunxi/dram_timings/h616_lpddr3.c | 12 ++++---
 .../dram_timings/h616_lpddr4_2133.c           | 12 ++++---
 5 files changed, 57 insertions(+), 14 deletions(-)
arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h +32 -2
index fa12d5d2685..6dab3b4832b 100644
@@ -177,7 +177,37 @@ static inline int ns_to_t(const struct dram_para *para, int nanoseconds)
 	return DIV_ROUND_UP(ctrl_freq * nanoseconds, 1000);
 }
 
-extern const u8 *phy_init;
-void mctl_set_timing_params(const struct dram_para *para);
+void h616_ddr3_set_timing_params(const struct dram_para *para);
+void h616_lpddr3_set_timing_params(const struct dram_para *para);
+void h616_lpddr4_set_timing_params(const struct dram_para *para);
+
+const u8 *h616_ddr3_get_phy_init(void);
+const u8 *h616_lpddr3_get_phy_init(void);
+const u8 *h616_lpddr4_get_phy_init(void);
+
+static inline void mctl_set_timing_params(const struct dram_para *para)
+{
+#ifdef CONFIG_SUNXI_DRAM_H616_DDR3_1333
+	h616_ddr3_set_timing_params(para);
+#elif defined(CONFIG_SUNXI_DRAM_H616_LPDDR3)
+	h616_lpddr3_set_timing_params(para);
+#elif defined(CONFIG_SUNXI_DRAM_H616_LPDDR4)
+	h616_lpddr4_set_timing_params(para);
+#endif
+}
+
+static inline const u8 *h616_get_phy_init(const struct dram_para *para)
+{
+	(void)para;
+
+#ifdef CONFIG_SUNXI_DRAM_H616_DDR3_1333
+	return h616_ddr3_get_phy_init();
+#elif defined(CONFIG_SUNXI_DRAM_H616_LPDDR3)
+	return h616_lpddr3_get_phy_init();
+#elif defined(CONFIG_SUNXI_DRAM_H616_LPDDR4)
+	return h616_lpddr4_get_phy_init();
+#endif
+	return NULL;
+}
 
 #endif /* _SUNXI_DRAM_SUN50I_H616_H */
arch/arm/mach-sunxi/dram_sun50i_h616.c +1 -0
index 5ee1ca25311..c3e1286fb35 100644
@@ -869,6 +869,7 @@ static bool mctl_phy_init(const struct dram_para *para,
 			(struct sunxi_mctl_com_reg *)SUNXI_DRAM_COM_BASE;
 	struct sunxi_mctl_ctl_reg * const mctl_ctl =
 			(struct sunxi_mctl_ctl_reg *)SUNXI_DRAM_CTL0_BASE;
+	const u8 *phy_init = h616_get_phy_init(para);
 	u32 val, val2, *ptr, mr0, mr2;
 	int i;
 
arch/arm/mach-sunxi/dram_timings/h616_ddr3_1333.c +8 -4
index f367f604d5f..20c90f20cb9 100644
@@ -28,11 +28,15 @@ static const u8 h616_ddr3_phy_init_addr_map_1[H616_PHY_INIT_LEN] = {
 	0x06, 0x09, 0x0f
 };
 
-const u8 *phy_init = IS_ENABLED(CONFIG_DRAM_SUNXI_PHY_ADDR_MAP_1) ?
-		     h616_ddr3_phy_init_addr_map_1 :
-		     h616_ddr3_phy_init_default;
+const u8 *h616_ddr3_get_phy_init(void)
+{
+	if (IS_ENABLED(CONFIG_DRAM_SUNXI_PHY_ADDR_MAP_1))
+		return h616_ddr3_phy_init_addr_map_1;
+
+	return h616_ddr3_phy_init_default;
+}
 
-void mctl_set_timing_params(const struct dram_para *para)
+void h616_ddr3_set_timing_params(const struct dram_para *para)
 {
 	struct sunxi_mctl_ctl_reg * const mctl_ctl =
 			(struct sunxi_mctl_ctl_reg *)SUNXI_DRAM_CTL0_BASE;
arch/arm/mach-sunxi/dram_timings/h616_lpddr3.c +8 -4
index 7efb1b22a84..23b29cc973c 100644
@@ -28,11 +28,15 @@ static const u8 h616_lpddr3_phy_init_addr_map_1[H616_PHY_INIT_LEN] = {
 	0x08, 0x01, 0x1a
 };
 
-const u8 *phy_init = IS_ENABLED(CONFIG_DRAM_SUNXI_PHY_ADDR_MAP_1) ?
-		     h616_lpddr3_phy_init_addr_map_1 :
-		     h616_lpddr3_phy_init_default;
+const u8 *h616_lpddr3_get_phy_init(void)
+{
+	if (IS_ENABLED(CONFIG_DRAM_SUNXI_PHY_ADDR_MAP_1))
+		return h616_lpddr3_phy_init_addr_map_1;
+
+	return h616_lpddr3_phy_init_default;
+}
 
-void mctl_set_timing_params(const struct dram_para *para)
+void h616_lpddr3_set_timing_params(const struct dram_para *para)
 {
 	struct sunxi_mctl_ctl_reg * const mctl_ctl =
 			(struct sunxi_mctl_ctl_reg *)SUNXI_DRAM_CTL0_BASE;
arch/arm/mach-sunxi/dram_timings/h616_lpddr4_2133.c +8 -4
index 055d8dd3cad..c19ae025f75 100644
@@ -26,11 +26,15 @@ static const u8 h616_lpddr4_phy_init_addr_map_1[H616_PHY_INIT_LEN] = {
 	0x18, 0x04, 0x1a
 };
 
-const u8 *phy_init = IS_ENABLED(CONFIG_DRAM_SUNXI_PHY_ADDR_MAP_1) ?
-		     h616_lpddr4_phy_init_addr_map_1 :
-		     h616_lpddr4_phy_init_default;
+const u8 *h616_lpddr4_get_phy_init(void)
+{
+	if (IS_ENABLED(CONFIG_DRAM_SUNXI_PHY_ADDR_MAP_1))
+		return h616_lpddr4_phy_init_addr_map_1;
+
+	return h616_lpddr4_phy_init_default;
+}
 
-void mctl_set_timing_params(const struct dram_para *para)
+void h616_lpddr4_set_timing_params(const struct dram_para *para)
 {
 	struct sunxi_mctl_ctl_reg * const mctl_ctl =
 			(struct sunxi_mctl_ctl_reg *)SUNXI_DRAM_CTL0_BASE;
Signature · 1 line
2.43.0
#3 lore raw

PATCH v4 4/5 dt-bindings: memory: allwinner: add sunxi DRAM type constants

In reply to James Hilliard

Add numeric DRAM type constants for the Allwinner DRAM bindings so H616 DT nodes can describe the dram-type property without using string values.

---
 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
#4 lore raw

PATCH v4 5/5 sunxi: h616: support a default DRAM profile from the device tree

In reply to James Hilliard

Add a second H616 profile source mode which loads the DRAM parameters from /dram-profiles/default in the U-Boot device tree.

In this mode SPL builds all supported H616 timing backends and selects the matching one from the dram-type property at boot. This provides the simplest device-tree-driven parameter flow for boards that need runtime selection later, while keeping the existing fixed-profile path in the main H616 driver.

Add a small device-tree DRAM parameter loader for the default profile and use hidden H616 backend symbols so fixed-profile mode builds one backend while device-tree profile mode builds all of them, without reusing the visible timing choice symbols as build plumbing. Also make SUNXI_DRAM_FIXED_PARAMS a derived hidden symbol so the fixed H616 timing choice and H616 fixed-parameter prompts are hidden automatically when device-tree profiles are enabled.

---
 .../include/asm/arch-sunxi/dram_sun50i_h616.h | 31 ++++++-
 arch/arm/mach-sunxi/Kconfig                   | 78 +++++++++++++---
 arch/arm/mach-sunxi/Makefile                  |  1 +
 arch/arm/mach-sunxi/dram_sun50i_h616.c        | 55 +++++++----
 arch/arm/mach-sunxi/dram_sun50i_h616_dt.c     | 93 +++++++++++++++++++
 arch/arm/mach-sunxi/dram_timings/Makefile     |  6 +-
 6 files changed, 227 insertions(+), 37 deletions(-)
 create mode 100644 arch/arm/mach-sunxi/dram_sun50i_h616_dt.c
arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h +30 -1
index 6dab3b4832b..9593409b465 100644
@@ -170,6 +170,8 @@ struct dram_config {
 
 #define H616_PHY_INIT_LEN	27
 
+void h616_get_dram_para_dt(struct dram_para *para);
+
 static inline int ns_to_t(const struct dram_para *para, int nanoseconds)
 {
 	const unsigned int ctrl_freq = para->clk / 2;
@@ -187,6 +189,22 @@ const u8 *h616_lpddr4_get_phy_init(void);
 
 static inline void mctl_set_timing_params(const struct dram_para *para)
 {
+	if (IS_ENABLED(CONFIG_DRAM_SUN50I_H616_DT_PROFILE)) {
+		switch (para->type) {
+		case SUNXI_DRAM_TYPE_DDR3:
+			h616_ddr3_set_timing_params(para);
+			return;
+		case SUNXI_DRAM_TYPE_LPDDR3:
+			h616_lpddr3_set_timing_params(para);
+			return;
+		case SUNXI_DRAM_TYPE_LPDDR4:
+			h616_lpddr4_set_timing_params(para);
+			return;
+		default:
+			return;
+		}
+	}
+
 #ifdef CONFIG_SUNXI_DRAM_H616_DDR3_1333
 	h616_ddr3_set_timing_params(para);
 #elif defined(CONFIG_SUNXI_DRAM_H616_LPDDR3)
@@ -198,7 +216,18 @@ static inline void mctl_set_timing_params(const struct dram_para *para)
 
 static inline const u8 *h616_get_phy_init(const struct dram_para *para)
 {
-	(void)para;
+	if (IS_ENABLED(CONFIG_DRAM_SUN50I_H616_DT_PROFILE)) {
+		switch (para->type) {
+		case SUNXI_DRAM_TYPE_DDR3:
+			return h616_ddr3_get_phy_init();
+		case SUNXI_DRAM_TYPE_LPDDR3:
+			return h616_lpddr3_get_phy_init();
+		case SUNXI_DRAM_TYPE_LPDDR4:
+			return h616_lpddr4_get_phy_init();
+		default:
+			return NULL;
+		}
+	}
 
 #ifdef CONFIG_SUNXI_DRAM_H616_DDR3_1333
 	return h616_ddr3_get_phy_init();
arch/arm/mach-sunxi/Kconfig +65 -13

151 lines not on this page · raw message

arch/arm/mach-sunxi/Makefile +1 -0
index 9c79b55abf3..862386cf6f0 100644
@@ -44,6 +44,7 @@ obj-$(CONFIG_SUNXI_DRAM_DW)	+= dram_timings/
 obj-$(CONFIG_DRAM_SUN50I_H6)	+= dram_sun50i_h6.o dram_dw_helpers.o
 obj-$(CONFIG_DRAM_SUN50I_H6)	+= dram_timings/
 obj-$(CONFIG_DRAM_SUN50I_H616)	+= dram_sun50i_h616.o dram_dw_helpers.o
+obj-$(CONFIG_DRAM_SUN50I_H616_DT_PROFILE) += dram_sun50i_h616_dt.o
 obj-$(CONFIG_DRAM_SUN50I_H616)	+= dram_timings/
 obj-$(CONFIG_DRAM_SUN50I_A133)	+= dram_sun50i_a133.o
 obj-$(CONFIG_DRAM_SUN50I_A133)	+= dram_timings/
arch/arm/mach-sunxi/dram_sun50i_h616.c +35 -20

68 lines not on this page · raw message

arch/arm/mach-sunxi/dram_sun50i_h616_dt.c new file +93 -0

93 lines not on this page · raw message

arch/arm/mach-sunxi/dram_timings/Makefile +3 -3
index 5de9fd5aab4..165f6123cb4 100644
@@ -3,9 +3,9 @@ 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_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
+obj-$(CONFIG_SUNXI_DRAM_H616_BACKEND_DDR3) += h616_ddr3_1333.o
+obj-$(CONFIG_SUNXI_DRAM_H616_BACKEND_LPDDR3) += h616_lpddr3.o
+obj-$(CONFIG_SUNXI_DRAM_H616_BACKEND_LPDDR4) += h616_lpddr4_2133.o
 obj-$(CONFIG_SUNXI_DRAM_A133_DDR4)	+= a133_ddr4.o
 obj-$(CONFIG_SUNXI_DRAM_A133_LPDDR4)	+= a133_lpddr4.o
 obj-$(CONFIG_SUNXI_DRAM_A523_DDR3)	+= a523_ddr3.o
Signature · 1 line
2.43.0