[U-Boot,v2] board: fsl: lx2160a: implement board_fix_fdt
diff mbox series

Message ID 20190717154553.25482-1-pankaj.bansal@nxp.com
State Changes Requested
Delegated to: Prabhakar Kushwaha
Headers show
Series
  • [U-Boot,v2] board: fsl: lx2160a: implement board_fix_fdt
Related show

Commit Message

Pankaj Bansal July 17, 2019, 10:23 a.m. UTC
In lx2160a rev2 the pcie controller has been changed.
Therefore, we need to change the device tree nodes of pcie controllers
so that new controller can be probed.
It involves changing the "compatible" field as well as registers names'.
we are keeping same device tree for lx2160a rev1 and rev2, therefore we
change the device tree nodes as part of fdt fixups.
These changes would only be applied if the soc revision is not rev1.

Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
---

Notes:
    V2:
    - explained the patch requirements and patch changes.

 board/freescale/lx2160a/lx2160a.c | 67 +++++++++++++++++++++++++++++
 configs/lx2160aqds_tfa_defconfig  |  1 +
 configs/lx2160ardb_tfa_defconfig  |  1 +
 3 files changed, 69 insertions(+)

Comments

Prabhakar Kushwaha Aug. 16, 2019, 11:17 a.m. UTC | #1
Dear Pankaj

> -----Original Message-----
> From: Pankaj Bansal
> Sent: Wednesday, July 17, 2019 3:54 PM
> To: Prabhakar Kushwaha <prabhakar.kushwaha@nxp.com>; Meenakshi
> Aggarwal <meenakshi.aggarwal@nxp.com>
> Cc: Varun Sethi <V.Sethi@nxp.com>; u-boot@lists.denx.de
> Subject: [PATCH v2] board: fsl: lx2160a: implement board_fix_fdt
> 
> In lx2160a rev2 the pcie controller has been changed.
> Therefore, we need to change the device tree nodes of pcie controllers so that
> new controller can be probed.
> It involves changing the "compatible" field as well as registers names'.
> we are keeping same device tree for lx2160a rev1 and rev2, therefore we
> change the device tree nodes as part of fdt fixups.
> These changes would only be applied if the soc revision is not rev1.
> 
> Signed-off-by: Pankaj Bansal <pankaj.bansal@nxp.com>
> ---
> 
> Notes:
>     V2:
>     - explained the patch requirements and patch changes.
> 
>  board/freescale/lx2160a/lx2160a.c | 67 +++++++++++++++++++++++++++++
> configs/lx2160aqds_tfa_defconfig  |  1 +  configs/lx2160ardb_tfa_defconfig  |  1
> +

I am seeing compilation warning with your patch. 
Please fix it


--pk

board/freescale/lx2160a/lx2160a.c: In function 'board_fix_fdt':
board/freescale/lx2160a/lx2160a.c:143:13: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
   reg_names = fdt_getprop(fdt, off, "reg-names", &names_len);

Patch
diff mbox series

diff --git a/board/freescale/lx2160a/lx2160a.c b/board/freescale/lx2160a/lx2160a.c
index addc829e5d..1182c4a1e6 100644
--- a/board/freescale/lx2160a/lx2160a.c
+++ b/board/freescale/lx2160a/lx2160a.c
@@ -20,6 +20,8 @@ 
 #include <efi_loader.h>
 #include <asm/arch/mmu.h>
 #include <hwconfig.h>
+#include <asm/arch/clock.h>
+#include <asm/arch/config.h>
 #include <asm/arch/fsl_serdes.h>
 #include <asm/arch/soc.h>
 #include "../common/qixis.h"
@@ -108,6 +110,71 @@  int board_early_init_f(void)
 	return 0;
 }
 
+#ifdef CONFIG_OF_BOARD_FIXUP
+int board_fix_fdt(void *fdt)
+{
+	char *reg_names, *reg_name;
+	int names_len, old_name_len, new_name_len, remaining_names_len;
+	struct str_map {
+		char *old_str;
+		char *new_str;
+	} reg_names_map[] = {
+		{ "ccsr", "dip" },
+		{ "pf_ctrl", "ctrl" }
+	};
+	int off = -1, i;
+
+	if (IS_SVR_REV(get_svr(), 1, 0))
+		return 0;
+
+	off = fdt_node_offset_by_compatible(fdt, -1, "fsl,lx2160a-pcie");
+	while (off != -FDT_ERR_NOTFOUND) {
+		fdt_setprop(fdt, off, "compatible", "fsl,ls-pcie",
+			    strlen("fsl,ls-pcie") + 1);
+
+		reg_names = fdt_getprop(fdt, off, "reg-names", &names_len);
+		if (!reg_names)
+			continue;
+
+		reg_name = reg_names;
+		remaining_names_len = names_len - (reg_name - reg_names);
+		for (i = 0; (i < ARRAY_SIZE(reg_names_map)) && names_len; i++) {
+			old_name_len = strlen(reg_names_map[i].old_str);
+			new_name_len = strlen(reg_names_map[i].new_str);
+			if (memcmp(reg_name, reg_names_map[i].old_str,
+				   old_name_len) == 0) {
+				/* first only leave required bytes for new_str
+				 * and copy rest of the string after it
+				 */
+				memcpy(reg_name + new_name_len,
+				       reg_name + old_name_len,
+				       remaining_names_len - old_name_len);
+				/* Now copy new_str */
+				memcpy(reg_name, reg_names_map[i].new_str,
+				       new_name_len);
+				names_len -= old_name_len;
+				names_len += new_name_len;
+			}
+
+			reg_name = memchr(reg_name, '\0', remaining_names_len);
+			if (!reg_name)
+				break;
+
+			reg_name += 1;
+
+			remaining_names_len = names_len -
+					      (reg_name - reg_names);
+		}
+
+		fdt_setprop(fdt, off, "reg-names", reg_names, names_len);
+		off = fdt_node_offset_by_compatible(fdt, off,
+						    "fsl,lx2160a-pcie");
+	}
+
+	return 0;
+}
+#endif
+
 #if defined(CONFIG_TARGET_LX2160AQDS)
 void esdhc_dspi_status_fixup(void *blob)
 {
diff --git a/configs/lx2160aqds_tfa_defconfig b/configs/lx2160aqds_tfa_defconfig
index d68b40de3f..0eca208020 100644
--- a/configs/lx2160aqds_tfa_defconfig
+++ b/configs/lx2160aqds_tfa_defconfig
@@ -9,6 +9,7 @@  CONFIG_SEC_FIRMWARE_ARMV8_PSCI=y
 CONFIG_AHCI=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_OF_BOARD_SETUP=y
+CONFIG_OF_BOARD_FIXUP=y
 CONFIG_OF_STDOUT_VIA_ALIAS=y
 CONFIG_BOOTDELAY=10
 CONFIG_USE_BOOTARGS=y
diff --git a/configs/lx2160ardb_tfa_defconfig b/configs/lx2160ardb_tfa_defconfig
index 94f58a832f..dedb6c747e 100644
--- a/configs/lx2160ardb_tfa_defconfig
+++ b/configs/lx2160ardb_tfa_defconfig
@@ -10,6 +10,7 @@  CONFIG_SEC_FIRMWARE_ARMV8_PSCI=y
 CONFIG_AHCI=y
 CONFIG_FIT_VERBOSE=y
 CONFIG_OF_BOARD_SETUP=y
+CONFIG_OF_BOARD_FIXUP=y
 CONFIG_OF_STDOUT_VIA_ALIAS=y
 CONFIG_BOOTDELAY=10
 CONFIG_USE_BOOTARGS=y