Re: [PATCH 2/2] regulator: pf8x00: add support of nxp pf8x00 regulator

From: Mark Brown
Date: Mon Dec 07 2020 - 09:09:06 EST


On Sun, Dec 06, 2020 at 01:26:29AM +0100, Adrien Grassein wrote:

> +/* sw1 to sw6 voltages, from 0.4V to 1.49375V with 0.006250V increments */
> +#define SWV(i) (6250 * i + 400000)
> +
> +static const int pf8x00_sw1_to_6_voltages[] = {
> + SWV(0), SWV(1), SWV(2), SWV(3), SWV(4), SWV(5), SWV(6), SWV(7),

There are helpers for linear mappings, please use them directly rather
than open coding - this is clearer and much more efficient at runtime.

> +static const struct i2c_device_id pf8x_device_id[] = {
> + {.name = "pf8x00",},
> + { }
> +};
> +MODULE_DEVICE_TABLE(i2c, pf8x_device_id);

There should be separate IDs for the individual parts as with the OF
compatible.

> +static int pf8x00_regulator_set_voltage_time_sel(struct regulator_dev *rdev,
> + unsigned int old_sel, unsigned int new_sel)
> +{
> + struct pf8x_chip *pf = rdev_get_drvdata(rdev);
> + struct pf8x_regulator *rdesc = container_of(rdev->desc, struct pf8x_regulator, desc);
> + const unsigned int *volt_table = rdev->desc->volt_table;
> + int old_v = volt_table[old_sel];
> + int new_v = volt_table[new_sel];
> + int change = (new_v - old_v);
> + unsigned int index;
> + unsigned int slew;
> +
> + index = (rdesc->fast_slew & 1) ? 2 : 0;

Please write normal conditional statements to make things easier to
read.

> + if ((desc->id != REG_SW1) && quad_phase) {
> + dev_err(pf->dev, "ignoring, only sw1 can use quad-phase\n");
> + quad_phase = 0;
> + }
> + if ((desc->id != REG_SW1) && (desc->id != REG_SW4)
> + && (desc->id != REG_SW5) && dual_phase) {
> + dev_err(pf->dev, "ignoring, only sw1/sw4/sw5 can use dual-phase\n");
> + dual_phase = 0;
> + }

This wasn't in the binding document...

> +static int pf8x_parse_regulators_dt(struct pf8x_chip *pf)
> +{
> + struct device *dev = pf->dev;
> + struct device_node *np, *parent;
> + int ret;
> +
> + np = of_node_get(dev->of_node);
> + if (!np)
> + return -EINVAL;
> +
> + parent = of_get_child_by_name(np, "regulators");
> + if (!parent) {
> + dev_err(dev, "regulators node not found\n");
> + return -EINVAL;
> + }
> +
> + ret = of_regulator_match(dev, parent, pf8x00_matches,
> + ARRAY_SIZE(pf8x00_matches));

Don't open code binding parsing, just specify the relevant names in the
regulator decriptors, register them and and let the core parse things
for you.

> + if (ilim <= 3) {
> + mask |= 3 << 3;
> + val |= ilim << 3;
> + }
> + if (fast_slew <= 1) {
> + mask |= 1 << 5;
> + val |= fast_slew << 5;
> + }

More blank lines between blocks please.

> +static int pf8x_suspend(struct device *dev)
> +{
> + return 0;
> +}
> +
> +static int pf8x_resume(struct device *dev)
> +{
> + return 0;
> +}

Remove empty functions.

> +static int __init pf8x_init(void)
> +{
> + return i2c_add_driver(&pf8x_driver);
> +}
> +subsys_initcall(pf8x_init);

You should be able to use module_i2c_driver() here.

Attachment: signature.asc
Description: PGP signature