linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Adrien Grassein <adrien.grassein@gmail.com>
Cc: lgirdwood@gmail.com, robh+dt@kernel.org,
	linux-kernel@vger.kernel.org, devicetree@vger.kernel.org,
	troy.kisky@boundarydevices.com, gary.bisson@boundarydevices.com
Subject: Re: [PATCH 2/2] regulator: pf8x00: add support of nxp pf8x00 regulator
Date: Mon, 7 Dec 2020 14:08:10 +0000	[thread overview]
Message-ID: <20201207140810.GF5694@sirena.org.uk> (raw)
In-Reply-To: <20201206002629.12872-2-adrien.grassein@gmail.com>

[-- Attachment #1: Type: text/plain, Size: 2961 bytes --]

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 #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 488 bytes --]

  reply	other threads:[~2020-12-07 14:09 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-12-06  0:26 [PATCH 1/2] dt-bindings: regulator: Add pf8x00 regulator Adrien Grassein
2020-12-06  0:26 ` [PATCH 2/2] regulator: pf8x00: add support of nxp " Adrien Grassein
2020-12-07 14:08   ` Mark Brown [this message]
2020-12-07 20:36   ` kernel test robot
2020-12-07 13:55 ` [PATCH 1/2] dt-bindings: regulator: Add " Mark Brown
2020-12-10 22:24   ` Adrien Grassein
2020-12-11 13:25     ` Mark Brown
2020-12-10  3:35 ` Rob Herring
2020-12-10 22:16 ` [PATCH v2 1/2] dt-bindings: regulator: add pf8x00 PMIC Adrien Grassein
2020-12-10 22:16   ` [PATCH v2 2/2] regulator: pf8x00: add support of nxp pf8x00 regulator Adrien Grassein
2020-12-11 15:28     ` Mark Brown
2020-12-11 14:04   ` [PATCH v2 1/2] dt-bindings: regulator: add pf8x00 PMIC Mark Brown
2020-12-12 22:43     ` Adrien Grassein

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20201207140810.GF5694@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=adrien.grassein@gmail.com \
    --cc=devicetree@vger.kernel.org \
    --cc=gary.bisson@boundarydevices.com \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=robh+dt@kernel.org \
    --cc=troy.kisky@boundarydevices.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).