Skip to contentSkip to conversation

sunxi: h616: prepare for runtime DRAM backend selection

PATCH New James Hilliard 1 participant 1 message Mar 15

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

PATCH v3 1/1 sunxi: h616: prepare for runtime DRAM backend selection

Move the H616 PHY init tables into the per-DRAM-type timing files and expose helpers to select the timing and PHY initialisation data from the current DRAM parameters.

Also make ns_to_t() use dram_para->clk instead of CONFIG_DRAM_CLK so a future caller can select the backend at runtime.

Keep the existing fixed-profile Kconfig selection and linkage unchanged by doing the dispatch in inline helpers, so current H616 boards still build with only their selected backend linked in.

---
 .../include/asm/arch-sunxi/dram_sun50i_h616.h | 39 ++++++++++++--
 arch/arm/mach-sunxi/dram_sun50i_h616.c        | 42 +--------------
 .../mach-sunxi/dram_timings/h616_ddr3_1333.c  | 54 +++++++++++++------
 .../arm/mach-sunxi/dram_timings/h616_lpddr3.c | 54 +++++++++++++------
 .../dram_timings/h616_lpddr4_2133.c           | 54 +++++++++++++------
 5 files changed, 152 insertions(+), 91 deletions(-)
arch/arm/include/asm/arch-sunxi/dram_sun50i_h616.h +36 -3
index a8fdda124a0..6dab3b4832b 100644
@@ -168,13 +168,46 @@ struct dram_config {
 	u8 bus_full_width;
 };
 
-static inline int ns_to_t(int nanoseconds)
+#define H616_PHY_INIT_LEN	27
+
+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);
 }
 
-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 +2 -40

60 lines not on this page · raw message

arch/arm/mach-sunxi/dram_timings/h616_ddr3_1333.c +38 -16

71 lines not on this page · raw message

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

71 lines not on this page · raw message

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

75 lines not on this page · raw message

Signature · 1 line
2.43.0