Message ID | 20190806103844.25277-4-j-keerthy@ti.com |
---|---|
State | Changes Requested |
Delegated to: | Tom Rini |
Headers | show |
Series | net: ti: icssg: Add prueth support | expand |
On Tue, Aug 06, 2019 at 04:08:33PM +0530, Keerthy wrote: > Introduce misc_init_by_ofnode to probe a misc device > using its ofnode. > > Signed-off-by: Keerthy <j-keerthy@ti.com> > --- > drivers/misc/misc-uclass.c | 25 +++++++++++++++++++++++++ > include/misc.h | 9 +++++++++ > 2 files changed, 34 insertions(+) > > diff --git a/drivers/misc/misc-uclass.c b/drivers/misc/misc-uclass.c > index 55381edc98..835d3f7118 100644 > --- a/drivers/misc/misc-uclass.c > +++ b/drivers/misc/misc-uclass.c > @@ -5,6 +5,8 @@ > > #include <common.h> > #include <dm.h> > +#include <dm/device-internal.h> > +#include <dm/uclass-internal.h> > #include <errno.h> > #include <misc.h> > > @@ -65,6 +67,29 @@ int misc_set_enabled(struct udevice *dev, bool val) > return ops->set_enabled(dev, val); > } > > +int misc_init_by_ofnode(ofnode node) > +{ > + struct udevice *dev = NULL; > + int ret; > + long temp1, temp2; > + > + temp1 = ofnode_to_offset(node); > + > + for (ret = uclass_find_first_device(UCLASS_MISC, &dev); dev; > + ret = uclass_find_next_device(&dev)) { > + temp2 = ofnode_to_offset(dev_ofnode(dev)); > + if (temp1 == temp2) { > + ret = device_probe(dev); > + if (ret) > + debug("%s: Failed to initialize - %d\n", Doesn't that put a 'minus' in front of an already negative number? Might look more confusing than it needs to be. I've often seen the formatting specifier for errors be like "...(%d)...". > + dev->name, ret); > + return ret; > + } > + } > + > + return -ENODEV; > +} > + > UCLASS_DRIVER(misc) = { > .id = UCLASS_MISC, > .name = "misc", > diff --git a/include/misc.h b/include/misc.h > index 12d1325ee2..79263ed480 100644 > --- a/include/misc.h > +++ b/include/misc.h > @@ -76,6 +76,15 @@ int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, > */ > int misc_set_enabled(struct udevice *dev, bool val); > > +/** > + * misc_init_by_ofnode() - Probe a misc device by using ofnode. > + * @node: ofnode of the misc device. > + * > + * A misc device is probed using ofnode. > + * > + * Return: -ve on error, 0 on success > + */ > +int misc_init_by_ofnode(ofnode node); Missing blank line here. -- Andreas Dannenberg Texas Instruments Inc > /* > * struct misc_ops - Driver model Misc operations > * > -- > 2.17.1 > > _______________________________________________ > U-Boot mailing list > U-Boot@lists.denx.de > https://lists.denx.de/listinfo/u-boot
Hi Keerthy, On Tue, 6 Aug 2019 at 04:38, Keerthy <j-keerthy@ti.com> wrote: > > Introduce misc_init_by_ofnode to probe a misc device > using its ofnode. What is the purpose of this? All patches should have a motivation. > > Signed-off-by: Keerthy <j-keerthy@ti.com> > --- > drivers/misc/misc-uclass.c | 25 +++++++++++++++++++++++++ > include/misc.h | 9 +++++++++ > 2 files changed, 34 insertions(+) > > diff --git a/drivers/misc/misc-uclass.c b/drivers/misc/misc-uclass.c > index 55381edc98..835d3f7118 100644 > --- a/drivers/misc/misc-uclass.c > +++ b/drivers/misc/misc-uclass.c > @@ -5,6 +5,8 @@ > > #include <common.h> > #include <dm.h> > +#include <dm/device-internal.h> > +#include <dm/uclass-internal.h> > #include <errno.h> > #include <misc.h> > > @@ -65,6 +67,29 @@ int misc_set_enabled(struct udevice *dev, bool val) > return ops->set_enabled(dev, val); > } > > +int misc_init_by_ofnode(ofnode node) > +{ > + struct udevice *dev = NULL; > + int ret; > + long temp1, temp2; > + > + temp1 = ofnode_to_offset(node); Why convert to offset? Can you just compare the node? > + > + for (ret = uclass_find_first_device(UCLASS_MISC, &dev); dev; > + ret = uclass_find_next_device(&dev)) { uclass_foreach_dev(dev, UCLASS_MISC) { > + temp2 = ofnode_to_offset(dev_ofnode(dev)); Again hopefully you can avoid this conversion. It won't work with livetree. > + if (temp1 == temp2) { > + ret = device_probe(dev); Hmm can you use uclass_foreach_dev_probe() above instead? > + if (ret) > + debug("%s: Failed to initialize - %d\n", > + dev->name, ret); > + return ret; > + } > + } > + > + return -ENODEV; > +} > + > UCLASS_DRIVER(misc) = { > .id = UCLASS_MISC, > .name = "misc", > diff --git a/include/misc.h b/include/misc.h > index 12d1325ee2..79263ed480 100644 > --- a/include/misc.h > +++ b/include/misc.h > @@ -76,6 +76,15 @@ int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, > */ > int misc_set_enabled(struct udevice *dev, bool val); > > +/** > + * misc_init_by_ofnode() - Probe a misc device by using ofnode. > + * @node: ofnode of the misc device. > + * > + * A misc device is probed using ofnode. > + * > + * Return: -ve on error, 0 on success > + */ > +int misc_init_by_ofnode(ofnode node); > /* > * struct misc_ops - Driver model Misc operations > * > -- > 2.17.1 >
On 13/08/19 3:04 PM, Simon Glass wrote: > Hi Keerthy, > > On Tue, 6 Aug 2019 at 04:38, Keerthy <j-keerthy@ti.com> wrote: >> >> Introduce misc_init_by_ofnode to probe a misc device >> using its ofnode. > > What is the purpose of this? All patches should have a motivation. Okay. I will add more details in the commit log. In my case pruss which is the pru subsystem which is a misc device needs to be probed before pru device which is an rproc class device. I will try to figure out a cleaner way if it exists. > >> >> Signed-off-by: Keerthy <j-keerthy@ti.com> >> --- >> drivers/misc/misc-uclass.c | 25 +++++++++++++++++++++++++ >> include/misc.h | 9 +++++++++ >> 2 files changed, 34 insertions(+) >> >> diff --git a/drivers/misc/misc-uclass.c b/drivers/misc/misc-uclass.c >> index 55381edc98..835d3f7118 100644 >> --- a/drivers/misc/misc-uclass.c >> +++ b/drivers/misc/misc-uclass.c >> @@ -5,6 +5,8 @@ >> >> #include <common.h> >> #include <dm.h> >> +#include <dm/device-internal.h> >> +#include <dm/uclass-internal.h> >> #include <errno.h> >> #include <misc.h> >> >> @@ -65,6 +67,29 @@ int misc_set_enabled(struct udevice *dev, bool val) >> return ops->set_enabled(dev, val); >> } >> >> +int misc_init_by_ofnode(ofnode node) >> +{ >> + struct udevice *dev = NULL; >> + int ret; >> + long temp1, temp2; >> + >> + temp1 = ofnode_to_offset(node); > > Why convert to offset? Can you just compare the node? Yes okay. > >> + >> + for (ret = uclass_find_first_device(UCLASS_MISC, &dev); dev; >> + ret = uclass_find_next_device(&dev)) { > > uclass_foreach_dev(dev, UCLASS_MISC) { okay > >> + temp2 = ofnode_to_offset(dev_ofnode(dev)); > > Again hopefully you can avoid this conversion. It won't work with livetree. okay > >> + if (temp1 == temp2) { >> + ret = device_probe(dev); > > Hmm can you use uclass_foreach_dev_probe() above instead? okay. I will try to figure out a cleaner way for my case. Thanks for the review. > > >> + if (ret) >> + debug("%s: Failed to initialize - %d\n", >> + dev->name, ret); >> + return ret; >> + } >> + } >> + >> + return -ENODEV; >> +} >> + >> UCLASS_DRIVER(misc) = { >> .id = UCLASS_MISC, >> .name = "misc", >> diff --git a/include/misc.h b/include/misc.h >> index 12d1325ee2..79263ed480 100644 >> --- a/include/misc.h >> +++ b/include/misc.h >> @@ -76,6 +76,15 @@ int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, >> */ >> int misc_set_enabled(struct udevice *dev, bool val); >> >> +/** >> + * misc_init_by_ofnode() - Probe a misc device by using ofnode. >> + * @node: ofnode of the misc device. >> + * >> + * A misc device is probed using ofnode. >> + * >> + * Return: -ve on error, 0 on success >> + */ >> +int misc_init_by_ofnode(ofnode node); >> /* >> * struct misc_ops - Driver model Misc operations >> * >> -- >> 2.17.1 >>
diff --git a/drivers/misc/misc-uclass.c b/drivers/misc/misc-uclass.c index 55381edc98..835d3f7118 100644 --- a/drivers/misc/misc-uclass.c +++ b/drivers/misc/misc-uclass.c @@ -5,6 +5,8 @@ #include <common.h> #include <dm.h> +#include <dm/device-internal.h> +#include <dm/uclass-internal.h> #include <errno.h> #include <misc.h> @@ -65,6 +67,29 @@ int misc_set_enabled(struct udevice *dev, bool val) return ops->set_enabled(dev, val); } +int misc_init_by_ofnode(ofnode node) +{ + struct udevice *dev = NULL; + int ret; + long temp1, temp2; + + temp1 = ofnode_to_offset(node); + + for (ret = uclass_find_first_device(UCLASS_MISC, &dev); dev; + ret = uclass_find_next_device(&dev)) { + temp2 = ofnode_to_offset(dev_ofnode(dev)); + if (temp1 == temp2) { + ret = device_probe(dev); + if (ret) + debug("%s: Failed to initialize - %d\n", + dev->name, ret); + return ret; + } + } + + return -ENODEV; +} + UCLASS_DRIVER(misc) = { .id = UCLASS_MISC, .name = "misc", diff --git a/include/misc.h b/include/misc.h index 12d1325ee2..79263ed480 100644 --- a/include/misc.h +++ b/include/misc.h @@ -76,6 +76,15 @@ int misc_call(struct udevice *dev, int msgid, void *tx_msg, int tx_size, */ int misc_set_enabled(struct udevice *dev, bool val); +/** + * misc_init_by_ofnode() - Probe a misc device by using ofnode. + * @node: ofnode of the misc device. + * + * A misc device is probed using ofnode. + * + * Return: -ve on error, 0 on success + */ +int misc_init_by_ofnode(ofnode node); /* * struct misc_ops - Driver model Misc operations *
Introduce misc_init_by_ofnode to probe a misc device using its ofnode. Signed-off-by: Keerthy <j-keerthy@ti.com> --- drivers/misc/misc-uclass.c | 25 +++++++++++++++++++++++++ include/misc.h | 9 +++++++++ 2 files changed, 34 insertions(+)