Hi Marek,

On 9/19/22 21:45, Marek Vasut wrote:
The gpio_hog_probe_all() functionality can be perfectly well replaced by
DM_FLAG_PROBE_AFTER_BIND DM flag, which would trigger .probe() callback
of each GPIO hog driver instance after .bind() and thus configure the
hogged GPIO accordingly.

Signed-off-by: Marek Vasut <ma...@denx.de>
---
Cc: Heinrich Schuchardt <xypron.g...@gmx.de>
Cc: Samuel Holland <sam...@sholland.org>
Cc: Simon Glass <s...@chromium.org>
---
  common/board_r.c           |  3 ---
  common/spl/spl.c           |  3 ---
  doc/README.gpio            |  6 ++----
  drivers/gpio/gpio-uclass.c | 25 ++-----------------------
  include/asm-generic/gpio.h |  8 --------
  5 files changed, 4 insertions(+), 41 deletions(-)

diff --git a/common/board_r.c b/common/board_r.c
index 56eb60fa275..c556aa5a073 100644
--- a/common/board_r.c
+++ b/common/board_r.c
@@ -750,9 +750,6 @@ static init_fnc_t init_sequence_r[] = {
        initr_status_led,
  #endif
        /* PPC has a udelay(20) here dating from 2002. Why? */
-#if defined(CONFIG_GPIO_HOG)
-       gpio_hog_probe_all,
-#endif
  #ifdef CONFIG_BOARD_LATE_INIT
        board_late_init,
  #endif
diff --git a/common/spl/spl.c b/common/spl/spl.c
index 29e0898f03d..683e0dfc526 100644
--- a/common/spl/spl.c
+++ b/common/spl/spl.c
@@ -770,9 +770,6 @@ void board_init_r(gd_t *dummy1, ulong dummy2)
                }
        }
- if (CONFIG_IS_ENABLED(GPIO_HOG))
-               gpio_hog_probe_all();
-
  #if CONFIG_IS_ENABLED(BOARD_INIT)
        spl_board_init();
  #endif
diff --git a/doc/README.gpio b/doc/README.gpio
index 548ff37b8cc..d253f654fad 100644
--- a/doc/README.gpio
+++ b/doc/README.gpio
@@ -2,10 +2,8 @@
  GPIO hog (CONFIG_GPIO_HOG)
  --------
-All the GPIO hog are initialized in gpio_hog_probe_all() function called in
-board_r.c just before board_late_init() but you can also acces directly to
-the gpio with gpio_hog_lookup_name().
-
+All the GPIO hog are initialized using DM_FLAG_PROBE_AFTER_BIND DM flag
+after bind().
Example, for the device tree: diff --git a/drivers/gpio/gpio-uclass.c b/drivers/gpio/gpio-uclass.c
index 0ed32b72170..32df0448a7b 100644
--- a/drivers/gpio/gpio-uclass.c
+++ b/drivers/gpio/gpio-uclass.c
@@ -315,34 +315,11 @@ static int gpio_hog_probe(struct udevice *dev)
        return 0;
  }
-int gpio_hog_probe_all(void)
-{
-       struct udevice *dev;
-       int ret;
-       int retval = 0;
-
-       for (uclass_first_device(UCLASS_NOP, &dev);
-            dev;
-            uclass_find_next_device(&dev)) {
-               if (dev->driver == DM_DRIVER_GET(gpio_hog)) {
-                       ret = device_probe(dev);
-                       if (ret) {
-                               printf("Failed to probe device %s err: %d\n",
-                                      dev->name, ret);
-                               retval = ret;
-                       }
-               }
-       }
-
-       return retval;
-}
-
  int gpio_hog_lookup_name(const char *name, struct gpio_desc **desc)
  {
        struct udevice *dev;
*desc = NULL;
-       gpio_hog_probe_all();
        if (!uclass_get_device_by_name(UCLASS_NOP, name, &dev)) {
                struct gpio_hog_priv *priv = dev_get_priv(dev);
@@ -1503,6 +1480,8 @@ static int gpio_post_bind(struct udevice *dev)
                                                                 &child);
                                if (ret)
                                        return ret;
+
+                               dev_or_flags(child, DM_FLAG_PROBE_AFTER_BIND);

I replaced this line with:

+                               /*
+                                * Make sure gpio-hogs are probed after bind
+ * since hogs can be essential to the hardware
+                                * system.
+                                */
+ dev_or_flags(child, DM_FLAG_PROBE_AFTER_BIND);
+
+                               /*
+                                * Since gpio-hog is a U_BOOT_DRIVER and not
+                                * a U_BOOT_CLASS, the DM core does not bind
+ * it and therefore it's up to this driver to
+                                * set the DM_FLAG_PRE_RELOC appropriately.
+                                */
+                               if (ofnode_pre_reloc(node))
+ dev_or_flags(child, DM_FLAG_PRE_RELOC);

and it works fine for me now (no dependency on the core DM patch I sent just a few minutes ago; I assume it's because we revert-recursively probe the parents of such devices?)

Cheers,
Quentin

Reply via email to