Skip to contentSkip to conversation

pinctrl: imx: Convert to use livetree API for fdt access

PATCH In review Tim Harvey 3 participants 7 messages Oct 23, 2024 – Oct 28, 2024

Subsystems (6)
lore
Share & tools
lore

Tim Harvey

author
#0 lore raw

PATCH 1/4 pinctrl: imx: Convert to use livetree API for fdt access

Convert to using livetree API functions.

Without this if livetree is enabled (OF_LIVE) the imx8mq-pinctrl driver will (silently) fail to probe causing issues with multiple devices.

---
 drivers/pinctrl/nxp/pinctrl-imx.c | 25 ++++++++++++-------------
 1 file changed, 12 insertions(+), 13 deletions(-)
drivers/pinctrl/nxp/pinctrl-imx.c +12 -13
index ff466c491041..b1960c56b512 100644
@@ -22,7 +22,7 @@ static int imx_pinctrl_set_state(struct udevice *dev, struct udevice *config)
 {
 	struct imx_pinctrl_priv *priv = dev_get_priv(dev);
 	struct imx_pinctrl_soc_info *info = priv->info;
-	int node = dev_of_offset(config);
+	ofnode node = dev_ofnode(config);
 	const struct fdt_property *prop;
 	u32 *pin_data;
 	int npins, size, pin_size;
@@ -40,7 +40,7 @@ static int imx_pinctrl_set_state(struct udevice *dev, struct udevice *config)
 	else
 		pin_size = FSL_PIN_SIZE;
 
-	prop = fdt_getprop(gd->fdt_blob, node, "fsl,pins", &size);
+	prop = ofnode_get_property(node, "fsl,pins", &size);
 	if (!prop) {
 		dev_err(dev, "No fsl,pins property in node %s\n", config->name);
 		return -EINVAL;
@@ -56,8 +56,8 @@ static int imx_pinctrl_set_state(struct udevice *dev, struct udevice *config)
 	if (!pin_data)
 		return -ENOMEM;
 
-	if (fdtdec_get_int_array(gd->fdt_blob, node, "fsl,pins",
-				 pin_data, size >> 2)) {
+	if (ofnode_read_u32_array(node, "fsl,pins",
+				  pin_data, size >> 2)) {
 		dev_err(dev, "Error reading pin data.\n");
 		devm_kfree(dev, pin_data);
 		return -EINVAL;
@@ -202,10 +202,11 @@ int imx_pinctrl_probe(struct udevice *dev,
 		      struct imx_pinctrl_soc_info *info)
 {
 	struct imx_pinctrl_priv *priv = dev_get_priv(dev);
-	int node = dev_of_offset(dev), ret;
-	struct fdtdec_phandle_args arg;
+	struct ofnode_phandle_args arg;
+	ofnode node = dev_ofnode(dev);
 	fdt_addr_t addr;
 	fdt_size_t size;
+	int ret;
 
 	if (!info) {
 		dev_err(dev, "wrong pinctrl info\n");
@@ -218,7 +219,7 @@ int imx_pinctrl_probe(struct udevice *dev,
 	if (info->flags & IMX8_USE_SCU)
 		return 0;
 
-	addr = devfdt_get_addr_size_index(dev, 0, &size);
+	addr = ofnode_get_addr_size_index(dev_ofnode(dev), 0, &size);
 	if (addr == FDT_ADDR_T_NONE)
 		return -EINVAL;
 
@@ -227,22 +228,20 @@ int imx_pinctrl_probe(struct udevice *dev,
 		return -ENOMEM;
 	priv->info = info;
 
-	info->mux_mask = fdtdec_get_int(gd->fdt_blob, node, "fsl,mux_mask", 0);
+	info->mux_mask = ofnode_read_u32(node, "fsl,mux_mask", 0);
 	/*
 	 * Refer to linux documentation for details:
 	 * Documentation/devicetree/bindings/pinctrl/fsl,imx7d-pinctrl.txt
 	 */
-	if (fdtdec_get_bool(gd->fdt_blob, node, "fsl,input-sel")) {
-		ret = fdtdec_parse_phandle_with_args(gd->fdt_blob,
-						     node, "fsl,input-sel",
+	if (ofnode_read_bool(node, "fsl,input-sel")) {
+		ret = ofnode_parse_phandle_with_args(node, "fsl,input-sel",
 						     NULL, 0, 0, &arg);
 		if (ret) {
 			dev_err(dev, "iomuxc fsl,input-sel property not found\n");
 			return -EINVAL;
 		}
 
-		addr = fdtdec_get_addr_size(gd->fdt_blob, arg.node, "reg",
-					    &size);
+		addr = ofnode_get_addr_size(arg.node, "reg", &size);
 		if (addr == FDT_ADDR_T_NONE)
 			return -EINVAL;
 
Signature · 1 line
2.25.1
author
#1 lore raw

PATCH 2/4 imx: power-domain: Convert to use livetree API for fdt access

Convert to using livetree API functions.

Without this if livetree is enabled (OF_LIVE) the imx8m-power-domain driver will (silently) fail to probe its children leaving you with no power domain support causing issues with certain devices.

---
 drivers/power/domain/imx8m-power-domain.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
drivers/power/domain/imx8m-power-domain.c +7 -11
index 8b6870c86463..c22fbe60675e 100644
@@ -456,25 +456,22 @@ static int imx8m_power_domain_of_xlate(struct power_domain *power_domain,
 
 static int imx8m_power_domain_bind(struct udevice *dev)
 {
-	int offset;
+	ofnode subnode;
 	const char *name;
 	int ret = 0;
 
-	offset = dev_of_offset(dev);
-	for (offset = fdt_first_subnode(gd->fdt_blob, offset); offset > 0;
-	     offset = fdt_next_subnode(gd->fdt_blob, offset)) {
+	ofnode_for_each_subnode(subnode, dev_ofnode(dev)) {
 		/* Bind the subnode to this driver */
-		name = fdt_get_name(gd->fdt_blob, offset, NULL);
+		name = ofnode_get_name(subnode);
 
 		/* Descend into 'pgc' subnode */
 		if (!strstr(name, "power-domain")) {
-			offset = fdt_first_subnode(gd->fdt_blob, offset);
-			name = fdt_get_name(gd->fdt_blob, offset, NULL);
+			subnode = ofnode_first_subnode(subnode);
+			name = ofnode_get_name(subnode);
 		}
-
 		ret = device_bind_with_driver_data(dev, dev->driver, name,
 						   dev->driver_data,
-						   offset_to_ofnode(offset),
+						   subnode,
 						   NULL);
 
 		if (ret == -ENODEV)
@@ -514,8 +511,7 @@ static int imx8m_power_domain_of_to_plat(struct udevice *dev)
 	struct imx_pgc_domain_data *domain_data =
 		(struct imx_pgc_domain_data *)dev_get_driver_data(dev);
 
-	pdata->resource_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
-					    "reg", -1);
+	pdata->resource_id = ofnode_read_u32_default(dev_ofnode(dev), "reg", -1);
 	pdata->domain = &domain_data->domains[pdata->resource_id];
 	pdata->regs = domain_data->pgc_regs;
 	pdata->base = dev_read_addr_ptr(dev->parent);
Signature · 1 line
2.25.1
Reviewed-by on v1 2/4
#2 lore raw

RE: [PATCH 2/4] imx: power-domain: Convert to use livetree API for fdt access

Quoted 10 lines

-----Original Message-----
From: Tim Harvey <[email protected]>
Sent: Thursday, October 24, 2024 5:29 AM
To: Heiko Schocher <[email protected]>; Tom Rini <[email protected]>; Peng Fan <[email protected]>; Jaehoon Chung <[email protected]>; [email protected]
Cc: [email protected]; Tim Harvey <[email protected]>
Subject: [PATCH 2/4] imx: power-domain: Convert to use livetree API for fdt access

Quoted 7 lines

Convert to using livetree API functions.

Without this if livetree is enabled (OF_LIVE) the imx8m-power-domain driver will (silently) fail to probe its children leaving you with no power domain support causing issues with certain devices.

Best Regards,
Jaehoon Chung

Quoted 53 lines
---
 drivers/power/domain/imx8m-power-domain.c | 18 +++++++-----------
 1 file changed, 7 insertions(+), 11 deletions(-)
drivers/power/domain/imx8m-power-domain.c +7 -12
index 8b6870c86463..c22fbe60675e 100644
@@ -456,25 +456,22 @@ static int imx8m_power_domain_of_xlate(struct power_domain *power_domain,
 
 static int imx8m_power_domain_bind(struct udevice *dev)
 {
-	int offset;
+	ofnode subnode;
 	const char *name;
 	int ret = 0;
 
-	offset = dev_of_offset(dev);
-	for (offset = fdt_first_subnode(gd->fdt_blob, offset); offset > 0;
-	     offset = fdt_next_subnode(gd->fdt_blob, offset)) {
+	ofnode_for_each_subnode(subnode, dev_ofnode(dev)) {
 		/* Bind the subnode to this driver */
-		name = fdt_get_name(gd->fdt_blob, offset, NULL);
+		name = ofnode_get_name(subnode);
 
 		/* Descend into 'pgc' subnode */
 		if (!strstr(name, "power-domain")) {
-			offset = fdt_first_subnode(gd->fdt_blob, offset);
-			name = fdt_get_name(gd->fdt_blob, offset, NULL);
+			subnode = ofnode_first_subnode(subnode);
+			name = ofnode_get_name(subnode);
 		}
-
 		ret = device_bind_with_driver_data(dev, dev->driver, name,
 						   dev->driver_data,
-						   offset_to_ofnode(offset),
+						   subnode,
 						   NULL);
 
 		if (ret == -ENODEV)
@@ -514,8 +511,7 @@ static int imx8m_power_domain_of_to_plat(struct udevice *dev)
 	struct imx_pgc_domain_data *domain_data =
 		(struct imx_pgc_domain_data *)dev_get_driver_data(dev);
 
-	pdata->resource_id = fdtdec_get_int(gd->fdt_blob, dev_of_offset(dev),
-					    "reg", -1);
+	pdata->resource_id = ofnode_read_u32_default(dev_ofnode(dev), "reg", -1);
 	pdata->domain = &domain_data->domains[pdata->resource_id];
 	pdata->regs = domain_data->pgc_regs;
 	pdata->base = dev_read_addr_ptr(dev->parent);
--

2.25.1

author
#3 lore raw

PATCH 3/4 i2c: mxc_i2c: Convert to use livetree API for fdt access

In reply to Tim Harvey

Convert to using livetree API functions.

Without this if livetree is enabled (OF_LIVE) the mxc-i2c driver will fail to support scl-gpios and sda-gpios for i2c bus recovery.

---
 drivers/i2c/mxc_i2c.c | 16 ++++++----------
 1 file changed, 6 insertions(+), 10 deletions(-)
drivers/i2c/mxc_i2c.c +6 -10
index 2f3cb5908c91..2dfc1c4eab5d 100644
@@ -29,7 +29,6 @@
 #include <watchdog.h>
 #include <dm.h>
 #include <dm/pinctrl.h>
-#include <fdtdec.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -867,8 +866,7 @@ static int mxc_i2c_set_bus_speed(struct udevice *bus, unsigned int speed)
 static int mxc_i2c_probe(struct udevice *bus)
 {
 	struct mxc_i2c_bus *i2c_bus = dev_get_priv(bus);
-	const void *fdt = gd->fdt_blob;
-	int node = dev_of_offset(bus);
+	ofnode node = dev_ofnode(bus);
 	fdt_addr_t addr;
 	int ret, ret2;
 
@@ -912,17 +910,15 @@ static int mxc_i2c_probe(struct udevice *bus)
 	 * See Documentation/devicetree/bindings/i2c/i2c-imx.txt
 	 * Use gpio to force bus idle when necessary.
 	 */
-	ret = fdt_stringlist_search(fdt, node, "pinctrl-names", "gpio");
+	ret = ofnode_stringlist_search(node, "pinctrl-names", "gpio");
 	if (ret < 0) {
 		debug("i2c bus %d at 0x%2lx, no gpio pinctrl state.\n",
 		      dev_seq(bus), i2c_bus->base);
 	} else {
-		ret = gpio_request_by_name_nodev(offset_to_ofnode(node),
-				"scl-gpios", 0, &i2c_bus->scl_gpio,
-				GPIOD_IS_OUT);
-		ret2 = gpio_request_by_name_nodev(offset_to_ofnode(node),
-				"sda-gpios", 0, &i2c_bus->sda_gpio,
-				GPIOD_IS_OUT);
+		ret = gpio_request_by_name(bus, "scl-gpios", 0, &i2c_bus->scl_gpio,
+					   GPIOD_IS_OUT);
+		ret2 = gpio_request_by_name(bus, "sda-gpios", 0, &i2c_bus->sda_gpio,
+					    GPIOD_IS_OUT);
 		if (!dm_gpio_is_valid(&i2c_bus->sda_gpio) ||
 		    !dm_gpio_is_valid(&i2c_bus->scl_gpio) ||
 		    ret || ret2) {
Signature · 1 line
2.25.1
Reviewed-by on v1 3/4
#4 lore raw

Re: [PATCH 3/4] i2c: mxc_i2c: Convert to use livetree API for fdt access

Hello Tim,

Quoted 10 lines · Tim Harvey

Convert to using livetree API functions.

Without this if livetree is enabled (OF_LIVE) the mxc-i2c driver will fail to support scl-gpios and sda-gpios for i2c bus recovery.

---
  drivers/i2c/mxc_i2c.c | 16 ++++++----------
  1 file changed, 6 insertions(+), 10 deletions(-)

Thanks!

bye,
Heiko

Signature · 3 lines
DENX Software Engineering GmbH,      Managing Director: Erika Unter
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: +49-8142-66989-52   Fax: +49-8142-66989-80   Email: [email protected]
author
#5 lore raw

PATCH 4/4 mmc: fsl_esdhc: Convert to use livetree API for fdt access

In reply to Tim Harvey

Convert to using livetree API functions.

Without this if livetree is enabled (OF_LIVE) the fsl_esdhc_imx driver will fail to read vendor-specific properties from the dt.

---
 drivers/mmc/fsl_esdhc_imx.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/mmc/fsl_esdhc_imx.c +7 -8
index fb410104c1fc..d7a45ef0ad0d 100644
@@ -1398,8 +1398,7 @@ static int fsl_esdhc_of_to_plat(struct udevice *dev)
 	struct udevice *vqmmc_dev;
 	int ret;
 
-	const void *fdt = gd->fdt_blob;
-	int node = dev_of_offset(dev);
+	ofnode node = dev_ofnode(dev);
 	fdt_addr_t addr;
 	unsigned int val;
 
@@ -1413,15 +1412,15 @@ static int fsl_esdhc_of_to_plat(struct udevice *dev)
 	priv->dev = dev;
 	priv->mode = -1;
 
-	val = fdtdec_get_int(fdt, node, "fsl,tuning-step", 1);
+	val = ofnode_read_u32_default(node, "fsl,tuning-step", 1);
 	priv->tuning_step = val;
-	val = fdtdec_get_int(fdt, node, "fsl,tuning-start-tap",
-			     ESDHC_TUNING_START_TAP_DEFAULT);
+	val = ofnode_read_u32_default(node, "fsl,tuning-start-tap",
+				      ESDHC_TUNING_START_TAP_DEFAULT);
 	priv->tuning_start_tap = val;
-	val = fdtdec_get_int(fdt, node, "fsl,strobe-dll-delay-target",
-			     ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_DEFAULT);
+	val = ofnode_read_u32_default(node, "fsl,strobe-dll-delay-target",
+				      ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_DEFAULT);
 	priv->strobe_dll_delay_target = val;
-	val = fdtdec_get_int(fdt, node, "fsl,signal-voltage-switch-extra-delay-ms", 0);
+	val = ofnode_read_u32_default(node, "fsl,signal-voltage-switch-extra-delay-ms", 0);
 	priv->signal_voltage_switch_extra_delay_ms = val;
 
 	if (dev_read_bool(dev, "broken-cd"))
Signature · 1 line
2.25.1
Reviewed-by on v1 4/4
#6 lore raw

RE: [PATCH 4/4] mmc: fsl_esdhc: Convert to use livetree API for fdt access

Quoted 10 lines

-----Original Message-----
From: Tim Harvey <[email protected]>
Sent: Thursday, October 24, 2024 5:29 AM
To: Heiko Schocher <[email protected]>; Tom Rini <[email protected]>; Peng Fan <[email protected]>; Jaehoon Chung <[email protected]>; [email protected]
Cc: [email protected]; Tim Harvey <[email protected]>
Subject: [PATCH 4/4] mmc: fsl_esdhc: Convert to use livetree API for fdt access

Quoted 6 lines

Convert to using livetree API functions.

Without this if livetree is enabled (OF_LIVE) the fsl_esdhc_imx driver will fail to read vendor-specific properties from the dt.

Best Regards,
Jaehoon Chung

Quoted 43 lines
---
 drivers/mmc/fsl_esdhc_imx.c | 15 +++++++--------
 1 file changed, 7 insertions(+), 8 deletions(-)
drivers/mmc/fsl_esdhc_imx.c +7 -9
index fb410104c1fc..d7a45ef0ad0d 100644
@@ -1398,8 +1398,7 @@ static int fsl_esdhc_of_to_plat(struct udevice *dev)
 	struct udevice *vqmmc_dev;
 	int ret;
 
-	const void *fdt = gd->fdt_blob;
-	int node = dev_of_offset(dev);
+	ofnode node = dev_ofnode(dev);
 	fdt_addr_t addr;
 	unsigned int val;
 
@@ -1413,15 +1412,15 @@ static int fsl_esdhc_of_to_plat(struct udevice *dev)
 	priv->dev = dev;
 	priv->mode = -1;
 
-	val = fdtdec_get_int(fdt, node, "fsl,tuning-step", 1);
+	val = ofnode_read_u32_default(node, "fsl,tuning-step", 1);
 	priv->tuning_step = val;
-	val = fdtdec_get_int(fdt, node, "fsl,tuning-start-tap",
-			     ESDHC_TUNING_START_TAP_DEFAULT);
+	val = ofnode_read_u32_default(node, "fsl,tuning-start-tap",
+				      ESDHC_TUNING_START_TAP_DEFAULT);
 	priv->tuning_start_tap = val;
-	val = fdtdec_get_int(fdt, node, "fsl,strobe-dll-delay-target",
-			     ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_DEFAULT);
+	val = ofnode_read_u32_default(node, "fsl,strobe-dll-delay-target",
+				      ESDHC_STROBE_DLL_CTRL_SLV_DLY_TARGET_DEFAULT);
 	priv->strobe_dll_delay_target = val;
-	val = fdtdec_get_int(fdt, node, "fsl,signal-voltage-switch-extra-delay-ms", 0);
+	val = ofnode_read_u32_default(node, "fsl,signal-voltage-switch-extra-delay-ms", 0);
 	priv->signal_voltage_switch_extra_delay_ms = val;
 
 	if (dev_read_bool(dev, "broken-cd"))
--

2.25.1