[PATCH] dm: core: add function uclass_probe_all() to probe all devices

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

[PATCH] dm: core: add function uclass_probe_all() to probe all devices

Vabhav Sharma (OSS)
From: Vabhav Sharma <[hidden email]>

Support a common method to probe all devices associated with uclass.

This includes data structures and code for finding the first device and
looping for remaining devices associated with uclasses (groups of devices
with the same purpose, e.g. all SERIAL ports will be in the same uclass).

An example is SBSA compliant PL011 UART IP, where firmware does the serial
port initialization and prepare uart device to let the kernel use it for
sending and reveiving the characters.SERIAL uclass will use this function
to initialize PL011 UART ports.

The feature is enabled with CONFIG_DM.

Signed-off-by: Vabhav Sharma <[hidden email]>
--
  Related discussion https://patchwork.ozlabs.org/project/uboot/patch/1601400
[hidden email]/
---
 drivers/core/uclass.c | 17 +++++++++++++++++
 include/dm/uclass.h   | 12 ++++++++++++
 2 files changed, 29 insertions(+)

diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
index c3f1b73..0725e8e 100644
--- a/drivers/core/uclass.c
+++ b/drivers/core/uclass.c
@@ -792,6 +792,23 @@ int uclass_pre_remove_device(struct udevice *dev)
 }
 #endif
 
+int uclass_probe_all(enum uclass_id id)
+{
+ struct udevice *dev;
+ int ret;
+
+ ret = uclass_first_device(id, &dev);
+ if (ret || !dev)
+ return ret;
+ if (dev) {
+ /* Scanning uclass to probe all devices */
+ for (; dev; uclass_next_device(&dev))
+ ;
+ }
+
+ return 0;
+}
+
 UCLASS_DRIVER(nop) = {
  .id = UCLASS_NOP,
  .name = "nop",
diff --git a/include/dm/uclass.h b/include/dm/uclass.h
index 67ff746..0fce83f 100644
--- a/include/dm/uclass.h
+++ b/include/dm/uclass.h
@@ -380,6 +380,18 @@ int uclass_first_device_drvdata(enum uclass_id id, ulong driver_data,
 int uclass_resolve_seq(struct udevice *dev);
 
 /**
+ * uclass_probe_all() - Probe all devices based on an uclass ID
+ *
+ * Every uclass is identified by an ID, a number from 0 to n-1 where n is
+ * the number of uclasses. This function probe all devices asocciated with
+ * a uclass by looking its ID.
+ *
+ * @id: uclass ID to look up
+ * @return 0 if OK, other -ve on error
+ */
+int uclass_probe_all(enum uclass_id id);
+
+/**
  * uclass_id_foreach_dev() - Helper function to iteration through devices
  *
  * This creates a for() loop which works through the available devices in
--
2.7.4

Reply | Threaded
Open this post in threaded view
|

Re: [PATCH] dm: core: add function uclass_probe_all() to probe all devices

Stefan Roese
On 19.10.20 11:37, Vabhav Sharma wrote:

> From: Vabhav Sharma <[hidden email]>
>
> Support a common method to probe all devices associated with uclass.
>
> This includes data structures and code for finding the first device and
> looping for remaining devices associated with uclasses (groups of devices
> with the same purpose, e.g. all SERIAL ports will be in the same uclass).
>
> An example is SBSA compliant PL011 UART IP, where firmware does the serial
> port initialization and prepare uart device to let the kernel use it for
> sending and reveiving the characters.SERIAL uclass will use this function
> to initialize PL011 UART ports.
>
> The feature is enabled with CONFIG_DM.
>
> Signed-off-by: Vabhav Sharma <[hidden email]>
> --
>    Related discussion https://patchwork.ozlabs.org/project/uboot/patch/1601400
> [hidden email]/
> ---
>   drivers/core/uclass.c | 17 +++++++++++++++++
>   include/dm/uclass.h   | 12 ++++++++++++
>   2 files changed, 29 insertions(+)
>
> diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c
> index c3f1b73..0725e8e 100644
> --- a/drivers/core/uclass.c
> +++ b/drivers/core/uclass.c
> @@ -792,6 +792,23 @@ int uclass_pre_remove_device(struct udevice *dev)
>   }
>   #endif
>  
> +int uclass_probe_all(enum uclass_id id)
> +{
> + struct udevice *dev;
> + int ret;
> +
> + ret = uclass_first_device(id, &dev);
> + if (ret || !dev)
> + return ret;
> + if (dev) {
> + /* Scanning uclass to probe all devices */
> + for (; dev; uclass_next_device(&dev))
> + ;
> + }
> +
> + return 0;
> +}
> +
>   UCLASS_DRIVER(nop) = {
>   .id = UCLASS_NOP,
>   .name = "nop",
> diff --git a/include/dm/uclass.h b/include/dm/uclass.h
> index 67ff746..0fce83f 100644
> --- a/include/dm/uclass.h
> +++ b/include/dm/uclass.h
> @@ -380,6 +380,18 @@ int uclass_first_device_drvdata(enum uclass_id id, ulong driver_data,
>   int uclass_resolve_seq(struct udevice *dev);
>  
>   /**
> + * uclass_probe_all() - Probe all devices based on an uclass ID
> + *
> + * Every uclass is identified by an ID, a number from 0 to n-1 where n is
> + * the number of uclasses. This function probe all devices asocciated with
> + * a uclass by looking its ID.
> + *
> + * @id: uclass ID to look up
> + * @return 0 if OK, other -ve on error
> + */
> +int uclass_probe_all(enum uclass_id id);
> +
> +/**
>    * uclass_id_foreach_dev() - Helper function to iteration through devices
>    *
>    * This creates a for() loop which works through the available devices in
>

Ahh, here is the function. You should better move both patches into one
patchset, so that the dependency can be seen. Especially while applying.

Other that that:

Reviewed-by: Stefan Roese <[hidden email]>

Thanks,
Stefan
Reply | Threaded
Open this post in threaded view
|

RE: [PATCH] dm: core: add function uclass_probe_all() to probe all devices

Vabhav Sharma (OSS)


> -----Original Message-----
> From: Stefan Roese <[hidden email]>
> Sent: Monday, October 19, 2020 3:40 PM
> To: Vabhav Sharma (OSS) <[hidden email]>; u-
> [hidden email]; [hidden email]
> Cc: Varun Sethi <[hidden email]>; [hidden email]; Vabhav
> Sharma <[hidden email]>
> Subject: Re: [PATCH] dm: core: add function uclass_probe_all() to probe all
> devices
>
> On 19.10.20 11:37, Vabhav Sharma wrote:
> > From: Vabhav Sharma <[hidden email]>
> >
> > Support a common method to probe all devices associated with uclass.
> >
> > This includes data structures and code for finding the first device
> > and looping for remaining devices associated with uclasses (groups of
> > devices with the same purpose, e.g. all SERIAL ports will be in the same
> uclass).
> >
> > An example is SBSA compliant PL011 UART IP, where firmware does the
> > serial port initialization and prepare uart device to let the kernel
> > use it for sending and reveiving the characters.SERIAL uclass will use
> > this function to initialize PL011 UART ports.
> >
> > The feature is enabled with CONFIG_DM.
> >
> > Signed-off-by: Vabhav Sharma <[hidden email]>
> > --
> >    Related discussion
> > https://patchwork.ozlabs.org/project/uboot/patch/1601400
> > [hidden email]/
> > ---
> >   drivers/core/uclass.c | 17 +++++++++++++++++
> >   include/dm/uclass.h   | 12 ++++++++++++
> >   2 files changed, 29 insertions(+)
> >
> > diff --git a/drivers/core/uclass.c b/drivers/core/uclass.c index
> > c3f1b73..0725e8e 100644
> > --- a/drivers/core/uclass.c
> > +++ b/drivers/core/uclass.c
> > @@ -792,6 +792,23 @@ int uclass_pre_remove_device(struct udevice *dev)
> >   }
> >   #endif
> >
> > +int uclass_probe_all(enum uclass_id id) {
> > + struct udevice *dev;
> > + int ret;
> > +
> > + ret = uclass_first_device(id, &dev);
> > + if (ret || !dev)
> > + return ret;
> > + if (dev) {
> > + /* Scanning uclass to probe all devices */
> > + for (; dev; uclass_next_device(&dev))
> > + ;
> > + }
> > +
> > + return 0;
> > +}
> > +
> >   UCLASS_DRIVER(nop) = {
> >   .id = UCLASS_NOP,
> >   .name = "nop",
> > diff --git a/include/dm/uclass.h b/include/dm/uclass.h index
> > 67ff746..0fce83f 100644
> > --- a/include/dm/uclass.h
> > +++ b/include/dm/uclass.h
> > @@ -380,6 +380,18 @@ int uclass_first_device_drvdata(enum uclass_id id,
> ulong driver_data,
> >   int uclass_resolve_seq(struct udevice *dev);
> >
> >   /**
> > + * uclass_probe_all() - Probe all devices based on an uclass ID
> > + *
> > + * Every uclass is identified by an ID, a number from 0 to n-1 where
> > +n is
> > + * the number of uclasses. This function probe all devices asocciated
> > +with
> > + * a uclass by looking its ID.
> > + *
> > + * @id: uclass ID to look up
> > + * @return 0 if OK, other -ve on error  */ int uclass_probe_all(enum
> > +uclass_id id);
> > +
> > +/**
> >    * uclass_id_foreach_dev() - Helper function to iteration through devices
> >    *
> >    * This creates a for() loop which works through the available
> > devices in
> >
>
> Ahh, here is the function. You should better move both patches into one
> patchset, so that the dependency can be seen. Especially while applying.
Sure.
>
> Other that that:
>
> Reviewed-by: Stefan Roese <[hidden email]>
>
> Thanks,
> Stefan