]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
board: phytec: common: Introduce a method to inject DDR timings deltas
authorWadim Egorov <w.egorov@phytec.de>
Wed, 22 May 2024 07:55:04 +0000 (09:55 +0200)
committerTom Rini <trini@konsulko.com>
Fri, 7 Jun 2024 20:02:26 +0000 (14:02 -0600)
Introduce fdt_apply_ddrss_timings_patch() to allow board code to
override DDR settings in the device tree prior to DDRSS driver probing.

Signed-off-by: Wadim Egorov <w.egorov@phytec.de>
Tested-by: John Ma <jma@phytec.com>
board/phytec/common/Makefile
board/phytec/common/k3/Makefile
board/phytec/common/k3/k3_ddrss_patch.c [new file with mode: 0644]
board/phytec/common/k3/k3_ddrss_patch.h [new file with mode: 0644]
board/phytec/phycore_am62x/MAINTAINERS

index c34fc503059bb2f78492b4f2416265eaadf39e48..988c5742db53711642fa9a01b4aacb7714b3cc32 100644 (file)
@@ -5,10 +5,8 @@
 ifdef CONFIG_SPL_BUILD
 # necessary to create built-in.o
 obj- := __dummy__.o
-else
-obj-$(CONFIG_ARCH_K3) += k3/
 endif
 
 obj-y += phytec_som_detection.o
-obj-$(CONFIG_ARCH_K3) += am6_som_detection.o
+obj-$(CONFIG_ARCH_K3) += am6_som_detection.o k3/
 obj-$(CONFIG_ARCH_IMX8M) += imx8m_som_detection.o
index bcca1a9f846c238cb505728264306bf834debfd9..40e91a43e9962c7da5ab4e0ee90c5732aa295c78 100644 (file)
@@ -1,2 +1,3 @@
 # SPDX-License-Identifier: GPL-2.0+
 obj-y += board.o
+obj-$(CONFIG_K3_DDRSS) += k3_ddrss_patch.o
diff --git a/board/phytec/common/k3/k3_ddrss_patch.c b/board/phytec/common/k3/k3_ddrss_patch.c
new file mode 100644 (file)
index 0000000..39f7be8
--- /dev/null
@@ -0,0 +1,68 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2024 PHYTEC Messtechnik GmbH
+ * Author: Wadim Egorov <w.egorov@phytec.de>
+ */
+
+#include "k3_ddrss_patch.h"
+
+#include <fdt_support.h>
+#include <linux/errno.h>
+
+#ifdef CONFIG_K3_AM64_DDRSS
+#define LPDDR4_INTR_CTL_REG_COUNT (423U)
+#define LPDDR4_INTR_PHY_INDEP_REG_COUNT (345U)
+#endif
+
+static int fdt_setprop_inplace_idx_u32(void *fdt, int nodeoffset,
+                                      const char *name, uint32_t idx, u32 val)
+{
+       val = cpu_to_be32(val);
+       return fdt_setprop_inplace_namelen_partial(fdt, nodeoffset, name,
+                                                  strlen(name),
+                                                  idx * sizeof(val), &val,
+                                                  sizeof(val));
+}
+
+int fdt_apply_ddrss_timings_patch(void *fdt, struct ddrss *ddrss)
+{
+       int i, j;
+       int ret;
+       int mem_offset;
+
+       mem_offset = fdt_path_offset(fdt, "/memorycontroller@f300000");
+       if (mem_offset < 0)
+               return -ENODEV;
+
+       for (i = 0; i < LPDDR4_INTR_CTL_REG_COUNT; i++)
+               for (j = 0; j < ddrss->ctl_regs_num; j++)
+                       if (i == ddrss->ctl_regs[j].off) {
+                               ret = fdt_setprop_inplace_idx_u32(fdt,
+                                               mem_offset, "ti,ctl-data", i,
+                                               ddrss->ctl_regs[j].val);
+                               if (ret)
+                                       return ret;
+                       }
+
+       for (i = 0; i < LPDDR4_INTR_PHY_INDEP_REG_COUNT; i++)
+               for (j = 0; j < ddrss->pi_regs_num; j++)
+                       if (i == ddrss->pi_regs[j].off) {
+                               ret = fdt_setprop_inplace_idx_u32(fdt,
+                                               mem_offset, "ti,pi-data", i,
+                                               ddrss->pi_regs[j].val);
+                               if (ret)
+                                       return ret;
+                       }
+
+       for (i = 0; i < LPDDR4_INTR_PHY_INDEP_REG_COUNT; i++)
+               for (j = 0; j < ddrss->phy_regs_num; j++)
+                       if (i == ddrss->phy_regs[j].off) {
+                               ret = fdt_setprop_inplace_idx_u32(fdt,
+                                               mem_offset, "ti,phy-data", i,
+                                               ddrss->phy_regs[j].val);
+                               if (ret)
+                                       return ret;
+                       }
+
+       return 0;
+}
diff --git a/board/phytec/common/k3/k3_ddrss_patch.h b/board/phytec/common/k3/k3_ddrss_patch.h
new file mode 100644 (file)
index 0000000..0a47c85
--- /dev/null
@@ -0,0 +1,28 @@
+/* SPDX-License-Identifier: GPL-2.0-or-later */
+/*
+ * Copyright (C) 2024 PHYTEC Messtechnik GmbH
+ * Author: Wadim Egorov <w.egorov@phytec.de>
+ */
+
+#ifndef K3_DDRSS_PATCH
+#define K3_DDRSS_PATCH
+
+#include <linux/types.h>
+
+struct ddr_reg {
+       u32 off;
+       u32 val;
+};
+
+struct ddrss {
+       struct ddr_reg *ctl_regs;
+       u32 ctl_regs_num;
+       struct ddr_reg *pi_regs;
+       u32 pi_regs_num;
+       struct ddr_reg *phy_regs;
+       u32 phy_regs_num;
+};
+
+int fdt_apply_ddrss_timings_patch(void *fdt, struct ddrss *ddrss);
+
+#endif /* K3_DDRSS_PATCH */
index 02ac88e58a4320a6a2b160884d26130383cdc07c..42463ad054ef22601b91739d922449c0e2f13f48 100644 (file)
@@ -11,3 +11,4 @@ F:    configs/phycore_am62x_a53_defconfig
 F:     configs/phycore_am62x_r5_defconfig
 F:     include/configs/phycore_am62x.h
 F:     doc/board/phytec/phycore-am62x.rst
+F:     board/phytec/common/k3