Skip to contentSkip to conversation

gpio: 74x164: use dev_read_* APIs for live-tree compatibility

PATCH Superseded Chanhong Jung 3 participants 4 messages Apr 21 – Apr 30 GPIO

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 gpio: 74x164: use dev_read_* APIs for live-tree compatibility

With CONFIG_OF_LIVE=y, dev_of_offset(dev) does not return a valid flat-FDT offset, so fdtdec_get_int(gd->fdt_blob, offset, ...) inside gen_74x164_probe() fails to locate the "registers-number" property and always falls back to the default value of 1. This results in a 4-chip 74HC595 daisy chain being exposed as only 8 GPIOs instead of 32, and any consumer referencing offsets >= 8 fails to bind with -ENOENT ("GPIO ... not found" / Error -22).

The "registers-default" property is ignored for the same reason, so any configured power-on output pattern is silently discarded.

Replace the flat-FDT helpers with dev_read_u32_default() and dev_read_u8_array_ptr(), which correctly walk both live and flat trees. This matches how other DM GPIO drivers (e.g. pca953x_gpio.c) read their per-device properties.

Tested on stm32mp153d-ssonic (CONFIG_OF_LIVE=y) with a 4-chip 74HC595
chain: all 32 GPIOs are now exposed, and 16 consumer LED nodes at offsets 0..31 bind successfully.

Fixes 9300f711baac ("dm: gpio: introduce 74x164 driver")
---
 drivers/gpio/74x164_gpio.c | 13 ++++++-------
 1 file changed, 6 insertions(+), 7 deletions(-)
drivers/gpio/74x164_gpio.c +6 -7
index 331428ccdb9..e394d1ce379 100644
@@ -10,7 +10,6 @@
 
 #include <errno.h>
 #include <dm.h>
-#include <fdtdec.h>
 #include <malloc.h>
 #include <asm/global_data.h>
 #include <asm/gpio.h>
@@ -127,10 +126,9 @@ static int gen_74x164_probe(struct udevice *dev)
 {
 	struct gen_74x164_priv *priv = dev_get_priv(dev);
 	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+	const u8 *defaults;
 	char *str, name[32];
 	int ret;
-	const void *fdt = gd->fdt_blob;
-	int node = dev_of_offset(dev);
 
 	snprintf(name, sizeof(name), "%s_", dev->name);
 	str = strdup(name);
@@ -141,16 +139,17 @@ static int gen_74x164_probe(struct udevice *dev)
 	 * See Linux kernel:
 	 * Documentation/devicetree/bindings/gpio/gpio-74x164.txt
 	 */
-	priv->nregs = fdtdec_get_int(fdt, node, "registers-number", 1);
+	priv->nregs = dev_read_u32_default(dev, "registers-number", 1);
 	priv->buffer = calloc(priv->nregs, sizeof(u8));
 	if (!priv->buffer) {
 		ret = -ENOMEM;
 		goto free_str;
 	}
 
-	ret = fdtdec_get_byte_array(fdt, node, "registers-default",
-				    priv->buffer, priv->nregs);
-	if (ret)
+	defaults = dev_read_u8_array_ptr(dev, "registers-default", priv->nregs);
+	if (defaults)
+		memcpy(priv->buffer, defaults, priv->nregs);
+	else
 		dev_dbg(dev, "No registers-default property\n");
 
 	ret = gpio_request_by_name(dev, "oe-gpios", 0, &priv->oe,
Signature · 1 line
2.34.1
Reviewed-by on v1 1/1
#1 lore raw

Hi Chanhong,

Quoted 27 lines · Chanhong Jung

gpio: 74x164: use dev_read_* APIs for live-tree compatibility

With CONFIG_OF_LIVE=y, dev_of_offset(dev) does not return a valid flat-FDT offset, so fdtdec_get_int(gd->fdt_blob, offset, ...) inside gen_74x164_probe() fails to locate the 'registers-number' property and always falls back to the default value of 1. This results in a 4-chip 74HC595 daisy chain being exposed as only 8 GPIOs instead of 32, and any consumer referencing offsets >= 8 fails to bind with -ENOENT ("GPIO ... not found" / Error -22).

The 'registers-default' property is ignored for the same reason, so any configured power-on output pattern is silently discarded.

Replace the flat-FDT helpers with dev_read_u32_default() and dev_read_u8_array_ptr(), which correctly walk both live and flat trees. This matches how other DM GPIO drivers (e.g. pca953x_gpio.c) read their per-device properties.

Tested on stm32mp153d-ssonic (CONFIG_OF_LIVE=y) with a 4-chip 74HC595
chain: all 32 GPIOs are now exposed, and 16 consumer LED nodes at [...]

drivers/gpio/74x164_gpio.c | 13 ++++++-------

 1 file changed, 6 insertions(+), 7 deletions(-)

drivers/gpio/74x164_gpio.c line 10

Quoted 1 line
drivers/gpio/74x164_gpio.c +0 -1
@@ -10,7 +10,6 @@
-#include <fdtdec.h>

It looks like gd->fdt_blob is no longer used, so please can you also remove DECLARE_GLOBAL_DATA_PTR and the <asm/global_data.h> include?

Regards,
Simon

#2 lore raw

PATCH v2 1/1 gpio: 74x164: use dev_read_* APIs for live-tree compatibility

In reply to Chanhong Jung

With CONFIG_OF_LIVE=y, dev_of_offset(dev) does not return a valid flat-FDT offset, so fdtdec_get_int(gd->fdt_blob, offset, ...) inside gen_74x164_probe() fails to locate the "registers-number" property and always falls back to the default value of 1. This results in a 4-chip 74HC595 daisy chain being exposed as only 8 GPIOs instead of 32, and any consumer referencing offsets >= 8 fails to bind with -ENOENT ("GPIO ... not found" / Error -22).

The "registers-default" property is ignored for the same reason, so any configured power-on output pattern is silently discarded.

Replace the flat-FDT helpers with dev_read_u32_default() and dev_read_u8_array_ptr(), which correctly walk both live and flat trees. This matches how other DM GPIO drivers (e.g. pca953x_gpio.c) read their per-device properties.

With gd->fdt_blob no longer referenced, also drop the now-unused DECLARE_GLOBAL_DATA_PTR and <asm/global_data.h> include.

Tested on stm32mp153d-ssonic (CONFIG_OF_LIVE=y) with a 4-chip 74HC595
chain: all 32 GPIOs are now exposed, and 16 consumer LED nodes at offsets 0..31 bind successfully.

Fixes 9300f711baac ("dm: gpio: introduce 74x164 driver")
---
 drivers/gpio/74x164_gpio.c | 17 ++++++-----------
 1 file changed, 6 insertions(+), 11 deletions(-)
drivers/gpio/74x164_gpio.c +6 -11
index 331428ccd..de2926894 100644
@@ -10,17 +10,13 @@
 
 #include <errno.h>
 #include <dm.h>
-#include <fdtdec.h>
 #include <malloc.h>
-#include <asm/global_data.h>
 #include <asm/gpio.h>
 #include <asm/io.h>
 #include <dm/device_compat.h>
 #include <dt-bindings/gpio/gpio.h>
 #include <spi.h>
 
-DECLARE_GLOBAL_DATA_PTR;
-
 /*
  * struct gen_74x164_chip - Data for 74Hx164
  *
@@ -127,11 +123,9 @@ static int gen_74x164_probe(struct udevice *dev)
 {
 	struct gen_74x164_priv *priv = dev_get_priv(dev);
 	struct gpio_dev_priv *uc_priv = dev_get_uclass_priv(dev);
+	const u8 *defaults;
 	char *str, name[32];
 	int ret;
-	const void *fdt = gd->fdt_blob;
-	int node = dev_of_offset(dev);
-
 	snprintf(name, sizeof(name), "%s_", dev->name);
 	str = strdup(name);
 	if (!str)
@@ -141,16 +135,17 @@ static int gen_74x164_probe(struct udevice *dev)
 	 * See Linux kernel:
 	 * Documentation/devicetree/bindings/gpio/gpio-74x164.txt
 	 */
-	priv->nregs = fdtdec_get_int(fdt, node, "registers-number", 1);
+	priv->nregs = dev_read_u32_default(dev, "registers-number", 1);
 	priv->buffer = calloc(priv->nregs, sizeof(u8));
 	if (!priv->buffer) {
 		ret = -ENOMEM;
 		goto free_str;
 	}
 
-	ret = fdtdec_get_byte_array(fdt, node, "registers-default",
-				    priv->buffer, priv->nregs);
-	if (ret)
+	defaults = dev_read_u8_array_ptr(dev, "registers-default", priv->nregs);
+	if (defaults)
+		memcpy(priv->buffer, defaults, priv->nregs);
+	else
 		dev_dbg(dev, "No registers-default property\n");
 
 	ret = gpio_request_by_name(dev, "oe-gpios", 0, &priv->oe,
Signature · 1 line
2.34.1
#3 lore raw
Quoted 9 lines · Chanhong Jung

With CONFIG_OF_LIVE=y, dev_of_offset(dev) does not return a valid flat-FDT offset, so fdtdec_get_int(gd->fdt_blob, offset, ...) inside gen_74x164_probe() fails to locate the "registers-number" property and always falls back to the default value of 1. This results in a 4-chip 74HC595 daisy chain being exposed as only 8 GPIOs instead of 32, and any consumer referencing offsets >= 8 fails to bind with -ENOENT ("GPIO ... not found" / Error -22).

[...]

Applied to u-boot/master, thanks!

[1/1] gpio: 74x164: use dev_read_* APIs for live-tree compatibility

      commit: b52670d37bc855f6c8da63eb51bf84bce4dad90b
Signature · 1 line
Tom