linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Mark Brown <broonie@opensource.wolfsonmicro.com>
To: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>
Cc: linux-kernel@vger.kernel.org, linaro-dev@lists.linaro.org,
	patches@linaro.org, eric.miao@linaro.org,
	Nancy Chen <Nancy.Chen@freescale.com>, Liam Girdwood <lrg@ti.com>
Subject: Re: [PATCHv2] Regulator: Add Anatop regulator driver
Date: Thu, 22 Dec 2011 11:33:38 +0000	[thread overview]
Message-ID: <20111222113337.GL4546@opensource.wolfsonmicro.com> (raw)
In-Reply-To: <1324458211-1612-1-git-send-email-paul.liu@linaro.org>

On Wed, Dec 21, 2011 at 05:03:31PM +0800, Ying-Chun Liu (PaulLiu) wrote:
> From: "Ying-Chun Liu (PaulLiu)" <paul.liu@linaro.org>
> 
> Anatop regulator driver is used by i.MX6 SoC. The regulator provides
> controlling the voltage of PU, CORE, SOC, and some devices. This patch
> adds the Anatop regulator driver.

It's still not at all clear to me what an "Anatop" regulator is or why
everything is being done as platform data.

> +config REGULATOR_ANATOP
> +	tristate "ANATOP LDO regulators"
> +	depends on SOC_IMX6
> +	default y if SOC_IMX6

This isn't great, it might be on your reference design but people are
going to change that.

> +#include <linux/platform_device.h>
> +#include <linux/regulator/machine.h>

Why does your regulator driver need this?  That suggests a layering
violation.

> +static int anatop_set_voltage(struct regulator_dev *reg, int min_uV,
> +				  int max_uV, unsigned *selector)
> +{
> +	struct anatop_regulator *anatop_reg = rdev_get_drvdata(reg);
> +	u32 val, rega;
> +	int uv;
> +
> +	uv = max_uV;

This looks wrong, you should be aiming to get as close as possible to
the minimum not the maximum.

> +	if (anatop_reg->rdata->control_reg) {
> +		val = anatop_reg->rdata->min_bit_val +
> +			(uv - reg->constraints->min_uV) / 25000;

You're not checking that the resulting voltage matches the constraints
or updating selector.

> +	} else {
> +		pr_debug("Regulator not supported.\n");

Why are you logging an error as a debug message?  You should also use
dev_ logging.

> +static int anatop_get_voltage(struct regulator_dev *reg)
> +{

Implement this as get_voltage_sel()

> +static int anatop_enable(struct regulator_dev *reg)
> +{
> +	return 0;
> +}
> +
> +static int anatop_disable(struct regulator_dev *reg)
> +{
> +	return 0;
> +}
> +
> +static int anatop_is_enabled(struct regulator_dev *reg)
> +{
> +	return 1;
> +}

The regulator clearly doesn't have enable or disable support at all, it
shouldn't have these operations.

> +static struct regulator_ops anatop_rops = {
> +	.set_voltage	= anatop_set_voltage,
> +	.get_voltage	= anatop_get_voltage,

You should implement list_voltage() as well.

> +static struct regulator_desc anatop_reg_desc[] = {
> +	{
> +		.name = "vddpu",
> +		.id = ANATOP_VDDPU,
> +		.ops = &anatop_rops,
> +		.irq = 0,

No need to set zero fields.  It's also *very* odd to see a table
explicitly listing regulators by name in a driver that doesn't know
which registers it's working with.

> +int anatop_regulator_probe(struct platform_device *pdev)
> +{
> +	struct regulator_desc *rdesc;
> +	struct regulator_dev *rdev;
> +	struct anatop_regulator *sreg;
> +	struct regulator_init_data *initdata;
> +
> +	sreg = platform_get_drvdata(pdev);
> +	initdata = pdev->dev.platform_data;
> +	sreg->cur_current = 0;
> +	sreg->next_current = 0;
> +	sreg->cur_voltage = 0;

You're trying to read the driver data but you haven't set any.  This is
going to crash.

> +	init_waitqueue_head(&sreg->wait_q);

This waitqueue appears to never be referenced.

> +	if (pdev->id > ANATOP_SUPPLY_NUM) {
> +		rdesc = kzalloc(sizeof(struct regulator_desc), GFP_KERNEL);

devm_kzalloc() and check the return value.

> +		memcpy(rdesc, &anatop_reg_desc[ANATOP_SUPPLY_NUM],
> +			sizeof(struct regulator_desc));
> +		rdesc->name = kstrdup(sreg->rdata->name, GFP_KERNEL);

This looks really confused, you've got some regulators embedded into the
driver and some with things passed in as platform data.  Either approach
should be fine but mixing both complicates things needlessly.

> +	} else
> +		rdesc = &anatop_reg_desc[pdev->id];

Use braces on both sides of the if.

> +	pr_debug("probing regulator %s %s %d\n",
> +			sreg->rdata->name,
> +			rdesc->name,
> +			pdev->id);

A lot of this logging looks like it's just replicating logging from the
core.

> +	/* register regulator */
> +	rdev = regulator_register(rdesc, &pdev->dev,
> +				  initdata, sreg);

The driver isn't doing anything to for example map the register bank
it's using.

> +int anatop_register_regulator(
> +		struct anatop_regulator *reg_data, int reg,
> +			      struct regulator_init_data *initdata)
> +{

Eew, no.  Just register the platform device normally.

> +	int mode;
> +	int cur_voltage;
> +	int cur_current;
> +	int next_current;

These appear to be unused and are rather obscure.

> +struct anatop_regulator_data {
> +	char name[80];

const char *.

> +	char *parent_name;

What's this?

  reply	other threads:[~2011-12-22 11:33 UTC|newest]

Thread overview: 37+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-12-07 13:53 [PATCH] Regulator: Add Anatop regulator driver Ying-Chun Liu (PaulLiu)
2011-12-07 13:53 ` Ying-Chun Liu (PaulLiu)
2011-12-07 15:54   ` Mark Brown
2011-12-07 16:30     ` Ying-Chun Liu (PaulLiu)
2011-12-21  9:03   ` [PATCHv2] " Ying-Chun Liu (PaulLiu)
2011-12-22 11:33     ` Mark Brown [this message]
2011-12-24 12:37       ` Mark Brown
2011-12-27 10:06       ` Ying-Chun Liu (PaulLiu)
2011-12-27 10:40         ` Mark Brown
2011-12-27 10:16     ` [PATCH v3] " Ying-Chun Liu (PaulLiu)
2011-12-27 10:52       ` Mark Brown
2011-12-27 11:38       ` Shawn Guo
2012-02-08 20:51       ` [PATCH v4 1/2] mfd: Add anatop mfd driver Ying-Chun Liu (PaulLiu)
2012-02-08 20:51         ` [PATCH v4 2/2] Regulator: Add Anatop regulator driver Ying-Chun Liu (PaulLiu)
2012-02-09 11:24           ` Mark Brown
2012-02-11  6:36           ` Shawn Guo
2012-02-11 13:17             ` Mark Brown
2012-02-11  6:05         ` [PATCH v4 1/2] mfd: Add anatop mfd driver Shawn Guo
2012-02-21 11:17         ` Samuel Ortiz
2012-03-01  9:19           ` Ying-Chun Liu (PaulLiu)
2012-03-01  9:10         ` [PATCH v5 " Ying-Chun Liu (PaulLiu)
2012-03-01  9:10           ` [PATCH v5 2/2] Regulator: Add Anatop regulator driver Ying-Chun Liu (PaulLiu)
2012-03-01 11:17             ` Mark Brown
2012-03-01 11:30           ` [PATCH v5 1/2] mfd: Add anatop mfd driver Mark Brown
2012-03-02  7:00           ` [PATCH v6 " Ying-Chun Liu (PaulLiu)
2012-03-02  7:00             ` [PATCH v6 2/2] Regulator: Add Anatop regulator driver Ying-Chun Liu (PaulLiu)
2012-03-04  6:51               ` Shawn Guo
2012-03-04 13:29                 ` Mark Brown
2012-03-02  7:07             ` [PATCH v6 1/2] mfd: Add anatop mfd driver Venu Byravarasu
2012-03-02  7:51               ` Ying-Chun Liu (PaulLiu)
2012-03-02  8:02                 ` Venu Byravarasu
2012-03-02 14:00             ` Peter Korsgaard
2012-03-03 17:39             ` [PATCH v7 " Ying-Chun Liu (PaulLiu)
2012-03-03 17:58               ` Mark Brown
2012-03-04  5:25               ` Shawn Guo
2012-03-04  5:42               ` Shawn Guo
2012-03-04  5:55               ` Shawn Guo

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=20111222113337.GL4546@opensource.wolfsonmicro.com \
    --to=broonie@opensource.wolfsonmicro.com \
    --cc=Nancy.Chen@freescale.com \
    --cc=eric.miao@linaro.org \
    --cc=linaro-dev@lists.linaro.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=lrg@ti.com \
    --cc=patches@linaro.org \
    --cc=paul.liu@linaro.org \
    /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).