[PATCH v4 2/6] regulator: Add regulator_of_get_optional() for pure DT regulator lookup
Andy Shevchenko
andriy.shevchenko at linux.intel.com
Tue Aug 13 04:22:20 PDT 2024
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
More information about the linux-arm-kernel
mailing list