Re: Aw: Re: Driver load order

2022-05-19 Thread Sascha Hauer
On Thu, May 19, 2022 at 02:50:13PM +0200, Ahmad Fatoum wrote:
> On 19.05.22 14:43, Frank Wunderlich wrote:
> > @ahmad: thanks for your driver. Take a quick look into it...
> > 
> > it seems nearly complete, is there anything not working or was the only
> > problem the missing regmap-handling added in part1?
> 
> IIRC, Linux just has regmap_i2c_init which does the correct thing for all
> callers. While in barebox this doesn't work and I had to add a smbus specific
> regmap_init. We can always consolidate this later though, so feel free to
> add whatever you find missing, test it and send it out for upstream
> inclusion. You have my Signed-off-by.
> 
> > My current approach is only register the regulators without doing a real
> > pmic init. IO-Domain driver only needs to read out regulator voltage, i'm
> > not sure if it's enough to get the value from the DT or if it needs to be
> > really measured (to depend on complete probe/init of the pmic).
> > 
> > but the problem is that iodomain is probed before the pmic due to 
> > deep-probing
> > if i understand Sascha the right way. So i need a way to defer the iodomain 
> > driver
> > probe till rk808 is ready.
> 
> The right way with deep probe enabled is to just use regulator functions
> normally and on first access, barebox will take care to probe the regulator
> if not done yet. I am not sure if all this works as expected yet, but Sascha
> already offered to help with that.

I gave it a test with your rk808 driver. It just works \o/

regulator_get() triggers probing of the rk808 regulator driver and
returns a valid regulator.

Sascha

-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Re: Aw: Re: Driver load order

2022-05-19 Thread Ahmad Fatoum
On 19.05.22 14:43, Frank Wunderlich wrote:
> @ahmad: thanks for your driver. Take a quick look into it...
> 
> it seems nearly complete, is there anything not working or was the only
> problem the missing regmap-handling added in part1?

IIRC, Linux just has regmap_i2c_init which does the correct thing for all
callers. While in barebox this doesn't work and I had to add a smbus specific
regmap_init. We can always consolidate this later though, so feel free to
add whatever you find missing, test it and send it out for upstream
inclusion. You have my Signed-off-by.

> My current approach is only register the regulators without doing a real
> pmic init. IO-Domain driver only needs to read out regulator voltage, i'm
> not sure if it's enough to get the value from the DT or if it needs to be
> really measured (to depend on complete probe/init of the pmic).
> 
> but the problem is that iodomain is probed before the pmic due to deep-probing
> if i understand Sascha the right way. So i need a way to defer the iodomain 
> driver
> probe till rk808 is ready.

The right way with deep probe enabled is to just use regulator functions
normally and on first access, barebox will take care to probe the regulator
if not done yet. I am not sure if all this works as expected yet, but Sascha
already offered to help with that.

Cheers,
Ahmad

> 
> regards Frank
> 
> ___
> barebox mailing list
> barebox@lists.infradead.org
> http://lists.infradead.org/mailman/listinfo/barebox
> 


-- 
Pengutronix e.K.   | |
Steuerwalder Str. 21   | http://www.pengutronix.de/  |
31137 Hildesheim, Germany  | Phone: +49-5121-206917-0|
Amtsgericht Hildesheim, HRA 2686   | Fax:   +49-5121-206917- |

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox


Aw: Re: Driver load order

2022-05-19 Thread Frank Wunderlich
Hi,
> Gesendet: Donnerstag, 19. Mai 2022 um 13:54 Uhr
> Von: "Sascha Hauer" 
> An: "Frank Wunderlich" 
> Cc: barebox@lists.infradead.org
> Betreff: Re: Driver load order
>
> Hi Frank,
>
> On Thu, May 19, 2022 at 12:59:35PM +0200, Frank Wunderlich wrote:
> > Hi,
> >
> > I try to create a basic driver for rk808 pmic/iodomains. I've noticed
> > that first the iodomain driver is probed and then the rk808 on,but i
> > need it reversed as rk808 registers regulators linked in iodomain via
> > devicetree.
> >
> > How can i defer iodomain probing till rk808 is ready (regulators
> > available defined as phandles in iodomain dt node)? Currently i get
> > always ENODEV (property does not exist or regulator is not ready
> > yet)
>
> Your board has deep probe enabled. The idea with deep probe is that the
> devices for a specific device node are registered on demand instead of
> any particular order. Basically this means that once you do a
> regulator_get() the regulator will be registered automatically for you
> without having to mess with the probe order.

regulator_get returns Null in my case. So imho i need to register
the regulators from the rk808, right?

currently i probe the rk808 and do a double child-loop (first subnodes,
second subnode "regulators"). Then i have the regulator node itself and
i can do something like this:

struct regulator_dev *rd;
ret=of_regulator_register(rd,regchild);

including the loops to have the context:

struct device_node *child,*regchild;
for_each_child_of_node(dev->device_node, child) {
if (!strcmp(child->name,"regulators"))
{
dev_info(dev, "DEBUG %s:%d regulators 
found\n",__FUNCTION__,__LINE__);
for_each_child_of_node(child, regchild) {
struct regulator_dev *rd;
ret=of_regulator_register(rd,regchild);
}
}
}


> That said I'm not sure if that works properly with regulators yet. For
> deep probe to work there must be a device registered for the device node
> representing the regulator. Currently this is not the case, there will
> only be a device for the "rockchip,rk808" device node, but not for the
> regulator child nodes.

as an idea i would do something like this in the iodomain-drivers probe:

if (!pmic_probed())
   return -EPROBE_DEFER

but how can i check the pmic is probed? to delay the probing of the
iodomain driver. I check if the linked phandles are there and
not registered...here i get -ENODEV (-19), but if the proeprty does
not exist i get Null from of_regulator_get(). Basicly i can defer the
probe there (kernel and my current code do a continue here), but i
think it's better to do it before looping over the properties of iodomain.

> I haven't found a suitable test setup to have a deeper look. If you
> could bring your rk808 driver up to a point where it actually registers
> the regulators then I could add the missing pieces in the regulator core
> for you.
>
> Sascha

@ahmad: thanks for your driver. Take a quick look into it...

it seems nearly complete, is there anything not working or was the only
problem the missing regmap-handling added in part1?

My current approach is only register the regulators without doing a real
pmic init. IO-Domain driver only needs to read out regulator voltage, i'm
not sure if it's enough to get the value from the DT or if it needs to be
really measured (to depend on complete probe/init of the pmic).

but the problem is that iodomain is probed before the pmic due to deep-probing
if i understand Sascha the right way. So i need a way to defer the iodomain 
driver
probe till rk808 is ready.

regards Frank

___
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox