[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <ZrtB7NPmnqF5ya2A@smile.fi.intel.com>
Date: Tue, 13 Aug 2024 14:22:20 +0300
From: Andy Shevchenko <andriy.shevchenko@...ux.intel.com>
To: Chen-Yu Tsai <wenst@...omium.org>
Cc: Rob Herring <robh@...nel.org>, Saravana Kannan <saravanak@...gle.com>,
Matthias Brugger <matthias.bgg@...il.com>,
AngeloGioacchino Del Regno <angelogioacchino.delregno@...labora.com>,
Wolfram Sang <wsa@...nel.org>, Benson Leung <bleung@...omium.org>,
Tzung-Bi Shih <tzungbi@...nel.org>, Mark Brown <broonie@...nel.org>,
Liam Girdwood <lgirdwood@...il.com>,
chrome-platform@...ts.linux.dev, devicetree@...r.kernel.org,
linux-arm-kernel@...ts.infradead.org,
linux-mediatek@...ts.infradead.org, linux-kernel@...r.kernel.org,
Douglas Anderson <dianders@...omium.org>,
Johan Hovold <johan@...nel.org>, Jiri Kosina <jikos@...nel.org>,
linux-i2c@...r.kernel.org
Subject: Re: [PATCH v4 2/6] regulator: Add regulator_of_get_optional() for
pure DT regulator lookup
On Thu, Aug 08, 2024 at 05:59:25PM +0800, Chen-Yu Tsai wrote:
> The to-be-introduced I2C component prober needs to enable regulator
> supplies (and toggle GPIO pins) for the various components it intends
> to probe. To support this, a new "pure DT lookup" method for getting
> regulator supplies is needed, since the device normally requesting
> the supply won't get created until after the component is probed to
> be available.
>
> This adds a new regulator_of_get_optional() for this purpose. The
> underlying code that support the existing regulator_get*() functions
> are extended to support this specific case.
...
> /**
> * regulator_dev_lookup - lookup a regulator device.
> * @dev: device for regulator "consumer".
> + * @node: device node for regulator supply lookup.
> + * Falls back to dev->of_node if NULL.
Please, avoid using dereferences in the comments. Use plain language:
"Falls back to the OF node of the @dev, if NULL." or alike.
> * @supply: Supply name or regulator ID.
> */
...
> static struct regulator_dev *regulator_dev_lookup(struct device *dev,
> + struct device_node *node,
This function has no of_ prefix in its name. If you want to make it for all,
please use fwnode instead. Otherwise I would expect a new one with of_ prefix.
(But I really prefer just agnostic, i.e. fwnode, approach!)
> const char *supply)
> {
> + bool pure_dt_lookup = false;
Redundant assignment.
> + pure_dt_lookup = (node && !dev);
>
> + /* Pure DT lookup should use given supply name directly */
> + if (!pure_dt_lookup)
> + regulator_supply_alias(&dev, &supply);
> +
> + if (!node && dev && dev->of_node)
The dev->of_node is redundant and with the above...
> + node = dev->of_node;
...this becomes as simple as
if (!node && dev)
> + /* Pure DT lookup stops here. */
> + if (pure_dt_lookup)
> + return ERR_PTR(-ENODEV);
Looking at this pure_dt_lookup and the above (somehow inverted) case I would
rather use (node && !dev) or (!node && dev) explicitly everywhere.
...
> +struct regulator *_regulator_get(struct device *dev, struct device_node *node,
> + const char *id, enum regulator_get_type get_type)
Again, no of_ prefix and function becomes OF-specific...
--
With Best Regards,
Andy Shevchenko
Powered by blists - more mailing lists