Re: [PATCH v2 4/5] regulator: Support the LTM8054 voltage regulator

From: Andy Shevchenko

Date: Wed Oct 22 2025 - 10:44:19 EST


On Thu, Sep 25, 2025 at 02:37:36PM +0200, Romain Gantois wrote:
> Add a stub driver for the Linear Technology LTM8054 Buck-Boost voltage
> regulator. This version only supports enabling/disabling the regulator via
> a GPIO, and reporting the output voltage level from the resistor divider
> values given in the device tree.

...

It's a bit an interesting grouping of headers...

> +#include <asm/div64.h>

...starting with leading asm/*.

> +#include <linux/array_size.h>
> +
> +#include <linux/device.h>
> +#include <linux/device/devres.h>
> +#include <linux/device/driver.h>
> +
> +#include <linux/dev_printk.h>
> +#include <linux/err.h>
> +#include <linux/errno.h>
> +#include <linux/gpio/consumer.h>
> +#include <linux/module.h>
> +#include <linux/of.h>
> +#include <linux/platform_device.h>
> +#include <linux/property.h>

I would expect above to be (but not limited to)

#include <linux/array_size.h>
#include <linux/device.h>
#include <linux/device/devres.h>
#include <linux/device/driver.h>
#include <linux/dev_printk.h>
#include <linux/err.h>

#include <linux/errno.h>

#include <linux/gpio/consumer.h>
#include <linux/math64.h>
#include <linux/module.h>
#include <linux/of.h>
#include <linux/platform_device.h>
#include <linux/property.h>

Also missing
types.h

> +#include <linux/regulator/consumer.h>
> +#include <linux/regulator/driver.h>
> +#include <linux/regulator/of_regulator.h>

...

> +static int ltm8054_of_parse(struct device *dev, struct ltm8054_priv *priv,
> + struct regulator_config *config)
> +{
> + struct device_node *np = dev->of_node;

No need, see below how.

> + u32 r[2];
> + int ret;

> + config->of_node = np;

Better to move it...

> +
> + ret = device_property_read_u32_array(dev, "lltc,fb-voltage-divider", r, ARRAY_SIZE(r));
> + if (ret)
> + return ret;
> +
> + priv->rdesc.fixed_uV = ltm8054_scale(LTM8054_FB_uV, r[0], r[1]);
> + priv->rdesc.min_uV = priv->rdesc.fixed_uV;
> + priv->rdesc.n_voltages = 1;

...here and reuse.

> + config->init_data = of_get_regulator_init_data(dev,
> + np,
> + &priv->rdesc);

config->of_node = dev_of_node(dev);
config->init_data = of_get_regulator_init_data(dev,
config->of_node,
&priv->rdesc);

> + if (!config->init_data)
> + return -EINVAL;
> +
> + config->ena_gpiod = devm_gpiod_get_optional(dev, "enable", GPIOD_OUT_LOW);
> + if (IS_ERR(config->ena_gpiod))
> + return PTR_ERR(config->ena_gpiod);
> +
> + return 0;
> +}

> +static int ltm8054_probe(struct platform_device *pdev)
> +{
> + struct regulator_config config = { };
> + struct device *dev = &pdev->dev;
> + struct regulator_dev *rdev;
> + struct ltm8054_priv *priv;
> + int ret;
> +
> + priv = devm_kzalloc(dev, sizeof(*priv), GFP_KERNEL);
> + if (!priv)
> + return -ENOMEM;
> +
> + priv->rdesc.name = "ltm8054-regulator",
> + priv->rdesc.ops = &ltm8054_regulator_ops,
> + priv->rdesc.type = REGULATOR_VOLTAGE,
> + priv->rdesc.owner = THIS_MODULE,

The commas should be replaced by semicolons.

> + config.dev = dev;
> + config.driver_data = priv;
> +
> + ret = ltm8054_of_parse(dev, priv, &config);
> + if (ret)
> + return dev_err_probe(dev, ret, "failed to parse device tree\n");
> +
> + rdev = devm_regulator_register(dev, &priv->rdesc, &config);
> + if (IS_ERR(rdev))
> + return dev_err_probe(dev, PTR_ERR(rdev), "failed to register regulator\n");
> +
> + return 0;
> +}

--
With Best Regards,
Andy Shevchenko