Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 83EF8C6FA91 for ; Thu, 22 Sep 2022 14:29:04 +0000 (UTC) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4DBE984A38; Thu, 22 Sep 2022 16:29:02 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=none (p=none dis=none) header.from=denx.de Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1663856942; bh=LL4lAe4SdyFstk1CLxAVxxKzxHMXWTPBIFv/oX9LWDE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:List-Id: List-Unsubscribe:List-Archive:List-Post:List-Help:List-Subscribe: From; b=BoS0r2DOcpnoV9mQt+Kw0UEWBfBObGpJ6/Wec575f0w52GKqi7TO4/EFv51KyTtAh pzveSOK9j5y3p2bwOhLgsY26P2ehzgTCDzceEnpaPEHsAPsNpl/B2TQEINsiTI4vDq oDOJPiDN8HTXbDe2hsbrGILiRr1ujdmbAl55+E4Yz/AYRnSdLiRTqpFLw8CY466J4x rLXBTEtH8VO9HtoZXKUshLBXRtua9J3RFPd9mQk7BAkW+OYVeQ5UaUC/t2yCtDqldQ wSphTvOJU90jb9kZ2mwCo6lBLmkVcLlN+nf8qfW/DU0Dm4cmiB2jBh5uan2I/bKaJu nudo03NwsB0qA== Received: from [127.0.0.1] (p578adb1c.dip0.t-ipconnect.de [87.138.219.28]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) (Authenticated sender: marex@denx.de) by phobos.denx.de (Postfix) with ESMTPSA id AB4CA8419C; Thu, 22 Sep 2022 16:28:59 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=denx.de; s=phobos-20191101; t=1663856940; bh=LL4lAe4SdyFstk1CLxAVxxKzxHMXWTPBIFv/oX9LWDE=; h=Date:Subject:To:Cc:References:From:In-Reply-To:From; b=yxjsCuVUuQd8ua3fVqXjK63RRCkIDpYUq2bqKlh0yjg5hlboHRPg9BtBMmL7kSXAN ctu2kdBC0+7Knhv6sLKhzmm1oaW/0HN00lv4BnhsC2BWcqaru0hMXIhHvqkW1CHAJg 7OUJ5iXH9eai+BpI2M4bIXZcgqzDjbsyoU5bNK1Jm5bHFCG6PTZ2ylglxfNVJOTKYJ hdiX6SCcNsXAURgjZiKIR5JYVyFm+vTeROL2CU08EORfdfFKczejGNgXjXWV35Q9S8 8V8MfyiwuH6Bhb6ELfA6KVQ0j1XEkKtGGnWHyGIoijbXq8wZgGksBXw8sEzlGFgcnB IKmDVbnUdaFJw== Message-ID: <52f414fd-d557-2fe6-e1a8-dece66b59feb@denx.de> Date: Thu, 22 Sep 2022 16:28:59 +0200 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH] gpio: Get rid of gpio_hog_probe_all() Content-Language: en-US To: Quentin Schulz , u-boot@lists.denx.de Cc: Heinrich Schuchardt , Samuel Holland , Simon Glass References: <20220919194502.106252-1-marex@denx.de> <68efb78c-3a0e-6473-aee8-92ec30064941@theobroma-systems.com> From: Marek Vasut In-Reply-To: <68efb78c-3a0e-6473-aee8-92ec30064941@theobroma-systems.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.6 at phobos.denx.de X-Virus-Status: Clean On 9/22/22 15:59, Quentin Schulz wrote: > Hi Marek, Hi, [...] >> 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); This second part should be handled by the DM, or you need dm-pre-reloc in your GPIO controller in DT. This would fail e.g. in case your GPIO controller has higher depth of hog subnodes, like: gpio-controller { something { gpio-hog { u-boot,dm-pre-reloc; }; }; }; Should really be: gpio-controller { u-boot,dm-pre-reloc; something { u-boot,dm-pre-reloc; gpio-hog { u-boot,dm-pre-reloc; }; }; }; At some point, I had the idea to instead of littering the DT with u-boot,dm-pre-reloc , we could use phandles instead and do something like: / { config { u-boot,dm-pre-reloc = <&node1 &node2 ... &gpio_hog ...>; }; } ... gpio-controller { something { gpio_hog: gpio-hog { }; }; };