public inbox for u-boot@lists.denx.de
 help / color / mirror / Atom feed
From: Tim Harvey <tharvey@gateworks.com>
To: u-boot@lists.denx.de
Subject: [U-Boot] [PATCH 14/14] imx: ventana: fix usage of dt paths with leading 0s (Linux 4.15+)
Date: Mon,  4 Feb 2019 13:11:00 -0800	[thread overview]
Message-ID: <20190204211100.11004-15-tharvey@gateworks.com> (raw)
In-Reply-To: <20190204211100.11004-1-tharvey@gateworks.com>

device-tree paths should never be used that reference node addresses
making an assumption about leading zeros. They should not be there per
the device-tree specification however they have been there until Linux
4.15 when they were removed via kernel commit
8dccafaa281aa1d240a58bbcdff338aec114a021.

This fixes various issues which will occur when using Linux 4.15+
that are being fixed up on a per model per PCB revision basis such as:
 - enabling MMC UHS-I on board revisions that support it
 - enabling PWM based on hwconfig
 - fixing PCIe reset on GW552x
 - removing cpu external watchdog reset on boards that do not support it
 - populate PCI dt nodes based on PCI scan in order to fix GW16082
   interrupt mapping and inject MAC address for PCI based GbE

Signed-off-by: Tim Harvey <tharvey@gateworks.com>
---
 board/gateworks/gw_ventana/gw_ventana.c | 90 +++++++++++--------------
 1 file changed, 41 insertions(+), 49 deletions(-)

diff --git a/board/gateworks/gw_ventana/gw_ventana.c b/board/gateworks/gw_ventana/gw_ventana.c
index 0b2258e87a..c63fb41e1b 100644
--- a/board/gateworks/gw_ventana/gw_ventana.c
+++ b/board/gateworks/gw_ventana/gw_ventana.c
@@ -879,34 +879,12 @@ static int ft_sethdmiinfmt(void *blob, char *mode)
 	return 0;
 }
 
-/* enable a property of a node if the node is found */
-static inline void ft_enable_path(void *blob, const char *path)
-{
-	int i = fdt_path_offset(blob, path);
-	if (i >= 0) {
-		debug("enabling %s\n", path);
-		fdt_status_okay(blob, i);
-	}
-}
-
-/* remove a property of a node if the node is found */
-static inline void ft_delprop_path(void *blob, const char *path,
-				   const char *name)
-{
-	int i = fdt_path_offset(blob, path);
-	if (i) {
-		debug("removing %s/%s\n", path, name);
-		fdt_delprop(blob, i, name);
-	}
-}
-
 #if defined(CONFIG_CMD_PCI)
 #define PCI_ID(x) ( \
 	(PCI_BUS(x->devfn)<<16)| \
 	(PCI_DEV(x->devfn)<<11)| \
 	(PCI_FUNC(x->devfn)<<8) \
 	)
-#define PCIE_PATH	"/soc/pcie at 0x01000000"
 int fdt_add_pci_node(void *blob, int par, struct pci_dev *dev)
 {
 	uint32_t reg[5];
@@ -939,7 +917,7 @@ int fdt_add_pci_path(void *blob, struct pci_dev *dev)
 	int k, np;
 
 	/* build list of parents */
-	np = fdt_path_offset(blob, PCIE_PATH);
+	np = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
 	if (np < 0)
 		return np;
 
@@ -976,7 +954,7 @@ int fdt_fixup_gw16082(void *blob, int np, struct pci_dev *dev)
 	int i;
 
 	/* build irq-map based on host controllers map */
-	host = fdt_path_offset(blob, PCIE_PATH);
+	host = fdt_node_offset_by_compatible(blob, -1, "fsl,imx6q-pcie");
 	if (host < 0) {
 		printf("   %s failed: missing host\n", __func__);
 		return host;
@@ -1118,10 +1096,14 @@ void ft_board_pci_fixup(void *blob, bd_t *bd)
 }
 #endif /* if defined(CONFIG_CMD_PCI) */
 
-void ft_board_wdog_fixup(void *blob, const char *path)
+void ft_board_wdog_fixup(void *blob, phys_addr_t addr)
 {
-	ft_delprop_path(blob, path, "ext-reset-output");
-	ft_delprop_path(blob, path, "fsl,ext-reset-output");
+	int off = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt", addr);
+
+	if (off) {
+		fdt_delprop(blob, off, "ext-reset-output");
+		fdt_delprop(blob, off, "fsl,ext-reset-output");
+	}
 }
 
 /*
@@ -1133,10 +1115,11 @@ void ft_board_wdog_fixup(void *blob, const char *path)
  *  - board (full model from EEPROM)
  *  - peripherals removed from DTB if not loaded on board (per EEPROM config)
  */
-#define UART1_PATH	"/soc/aips-bus at 02100000/serial at 021ec000"
-#define WDOG1_PATH	"/soc/aips-bus at 02000000/wdog at 020bc000"
-#define WDOG2_PATH	"/soc/aips-bus at 02000000/wdog at 020c0000"
-#define GPIO3_PATH	"/soc/aips-bus at 02000000/gpio@020a4000"
+#define WDOG1_ADDR	0x20bc000
+#define WDOG2_ADDR	0x20c0000
+#define GPIO3_ADDR	0x20a4000
+#define USDHC3_ADDR	0x2198000
+#define PWM0_ADDR	0x2080000
 int ft_board_setup(void *blob, bd_t *bd)
 {
 	struct ventana_board_info *info = &ventana_info;
@@ -1199,14 +1182,15 @@ int ft_board_setup(void *blob, bd_t *bd)
 		 * errata causing wdog timer to be unreliable.
 		 */
 		if (rev >= 'A' && rev < 'C') {
-			i = fdt_path_offset(blob, WDOG1_PATH);
+			i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-wdt",
+							  WDOG1_ADDR);
 			if (i)
 				fdt_status_disabled(blob, i);
 		}
 
 		/* GW51xx-E adds WDOG1_B external reset */
 		if (rev < 'E')
-			ft_board_wdog_fixup(blob, WDOG1_PATH);
+			ft_board_wdog_fixup(blob, WDOG1_ADDR);
 		break;
 
 	case GW52xx:
@@ -1222,7 +1206,8 @@ int ft_board_setup(void *blob, bd_t *bd)
 							   "reset-gpio", NULL);
 
 			if (range) {
-				i = fdt_path_offset(blob, GPIO3_PATH);
+				i = fdt_node_offset_by_compat_reg(blob,
+					"fsl,imx6q-gpio", GPIO3_ADDR);
 				if (i)
 					handle = fdt_get_phandle(blob, i);
 				if (handle) {
@@ -1237,18 +1222,19 @@ int ft_board_setup(void *blob, bd_t *bd)
 				gpio_cfg[board_type].usd_vsel = 0;
 
 			/* GW522x-B adds WDOG1_B external reset */
-			ft_board_wdog_fixup(blob, WDOG1_PATH);
+			if (rev < 'B')
+				ft_board_wdog_fixup(blob, WDOG1_ADDR);
 		}
 
 		/* GW520x-E adds WDOG1_B external reset */
 		else if (info->model[4] == '0' && rev < 'E')
-			ft_board_wdog_fixup(blob, WDOG1_PATH);
+			ft_board_wdog_fixup(blob, WDOG1_ADDR);
 		break;
 
 	case GW53xx:
 		/* GW53xx-E adds WDOG1_B external reset */
 		if (rev < 'E')
-			ft_board_wdog_fixup(blob, WDOG1_PATH);
+			ft_board_wdog_fixup(blob, WDOG1_ADDR);
 		break;
 
 	case GW54xx:
@@ -1256,13 +1242,12 @@ int ft_board_setup(void *blob, bd_t *bd)
 		 * disable serial2 node for GW54xx for compatibility with older
 		 * 3.10.x kernel that improperly had this node enabled in the DT
 		 */
-		i = fdt_path_offset(blob, UART1_PATH);
-		if (i)
-			fdt_del_node(blob, i);
+		fdt_set_status_by_alias(blob, "serial2", FDT_STATUS_DISABLED,
+					0);
 
 		/* GW54xx-E adds WDOG2_B external reset */
 		if (rev < 'E')
-			ft_board_wdog_fixup(blob, WDOG2_PATH);
+			ft_board_wdog_fixup(blob, WDOG2_ADDR);
 		break;
 
 	case GW551x:
@@ -1311,13 +1296,13 @@ int ft_board_setup(void *blob, bd_t *bd)
 
 		/* GW551x-C adds WDOG1_B external reset */
 		if (rev < 'C')
-			ft_board_wdog_fixup(blob, WDOG1_PATH);
+			ft_board_wdog_fixup(blob, WDOG1_ADDR);
 		break;
 	case GW5901:
 	case GW5902:
 		/* GW5901/GW5901 revB adds WDOG1_B as an external reset */
 		if (rev < 'B')
-			ft_board_wdog_fixup(blob, WDOG1_PATH);
+			ft_board_wdog_fixup(blob, WDOG1_ADDR);
 		break;
 	}
 
@@ -1331,20 +1316,27 @@ int ft_board_setup(void *blob, bd_t *bd)
 			continue;
 		if (hwconfig_subarg_cmp(arg, "mode", "pwm") && cfg->pwm_param)
 		{
-			char path[48];
-			sprintf(path, "/soc/aips-bus at 02000000/pwm@%08x",
-				0x02080000 + (0x4000 * (cfg->pwm_param - 1)));
+			phys_addr_t addr;
+			int off;
+
 			printf("   Enabling pwm%d for DIO%d\n",
 			       cfg->pwm_param, i);
-			ft_enable_path(blob, path);
+			addr = PWM0_ADDR + (0x4000 * (cfg->pwm_param - 1));
+			off = fdt_node_offset_by_compat_reg(blob,
+							    "fsl,imx6q-pwm",
+							    addr);
+			if (off)
+				fdt_status_okay(blob, off);
 		}
 	}
 
 	/* remove no-1-8-v if UHS-I support is present */
 	if (gpio_cfg[board_type].usd_vsel) {
 		debug("Enabling UHS-I support\n");
-		ft_delprop_path(blob, "/soc/aips-bus at 02100000/usdhc at 02198000",
-				"no-1-8-v");
+		i = fdt_node_offset_by_compat_reg(blob, "fsl,imx6q-usdhc",
+						  USDHC3_ADDR);
+		if (i)
+			fdt_delprop(blob, i, "no-1-8-v");
 	}
 
 #if defined(CONFIG_CMD_PCI)
-- 
2.17.1

  parent reply	other threads:[~2019-02-04 21:11 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-02-04 21:10 [U-Boot] [PATCH 00/14] Gateworks Ventana updates Tim Harvey
2019-02-04 21:10 ` [U-Boot] [PATCH 01/14] imx: ventana: mv88e61xx change LED configuration Tim Harvey
2019-02-16 10:26   ` [U-Boot] [U-Boot, " sbabic at denx.de
2019-02-04 21:10 ` [U-Boot] [PATCH 02/14] imx: ventana: do not iomux UART1 Tim Harvey
2019-02-16 10:35   ` [U-Boot] [U-Boot,02/14] " sbabic at denx.de
2019-02-04 21:10 ` [U-Boot] [PATCH 03/14] imx: ventana: remove setup of I2C3 from SPL Tim Harvey
2019-02-16 10:35   ` [U-Boot] [U-Boot, " sbabic at denx.de
2019-02-04 21:10 ` [U-Boot] [PATCH 04/14] imx: ventana: add support for GW5905 Tim Harvey
2019-02-16 10:35   ` [U-Boot] [U-Boot,04/14] " sbabic at denx.de
2019-02-04 21:10 ` [U-Boot] [PATCH 05/14] imx: ventana: add support for Z101WX01 LVDS display Tim Harvey
2019-02-16 10:26   ` [U-Boot] [U-Boot, " sbabic at denx.de
2019-02-04 21:10 ` [U-Boot] [PATCH 06/14] imx: ventana: skip nand init for nandless boards Tim Harvey
2019-02-16 10:26   ` [U-Boot] [U-Boot, " sbabic at denx.de
2019-02-04 21:10 ` [U-Boot] [PATCH 07/14] imx: ventana: add i2c detect for all LVDS displays Tim Harvey
2019-02-16 10:26   ` [U-Boot] [U-Boot, " sbabic at denx.de
2019-02-04 21:10 ` [U-Boot] [PATCH 08/14] imx: ventana: add support for GW5906 Tim Harvey
2019-02-16 10:26   ` [U-Boot] [U-Boot,08/14] " sbabic at denx.de
2019-02-04 21:10 ` [U-Boot] [PATCH 09/14] imx: ventana: add support for GW5907 Tim Harvey
2019-02-16 10:45   ` [U-Boot] [U-Boot,09/14] " sbabic at denx.de
2019-02-04 21:10 ` [U-Boot] [PATCH 10/14] imx: ventana: add support for GW5908 Tim Harvey
2019-02-16 10:26   ` [U-Boot] [U-Boot,10/14] " sbabic at denx.de
2019-02-04 21:10 ` [U-Boot] [PATCH 11/14] imx: ventana: add support for GW5909 Tim Harvey
2019-02-16 10:35   ` [U-Boot] [U-Boot,11/14] " sbabic at denx.de
2019-02-04 21:10 ` [U-Boot] [PATCH 12/14] imx: ventana: add support for GW5901/GW5902 Tim Harvey
2019-02-16 10:35   ` [U-Boot] [U-Boot, " sbabic at denx.de
2019-02-04 21:10 ` [U-Boot] [PATCH 13/14] imx: ventana: gw5904/gw5909: disable RS485 Tim Harvey
2019-02-16 10:35   ` [U-Boot] [U-Boot, " sbabic at denx.de
2019-02-04 21:11 ` Tim Harvey [this message]
2019-02-16 10:26   ` [U-Boot] [U-Boot, 14/14] imx: ventana: fix usage of dt paths with leading 0s (Linux 4.15+) sbabic at denx.de

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190204211100.11004-15-tharvey@gateworks.com \
    --to=tharvey@gateworks.com \
    --cc=u-boot@lists.denx.de \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox