mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Mark Brown <broonie@kernel.org>
To: Steve Twiss <stwiss.opensource@diasemi.com>
Cc: Liam Girdwood <lgirdwood@gmail.com>,
	David Dajun Chen <david.chen@diasemi.com>,
	Guennadi Liakhovetski <g.liakhovetski@gmx.de>,
	LKML <linux-kernel@vger.kernel.org>
Subject: Re: [RFC V1] COMMIT 1: DA9210 driver files
Date: Fri, 21 Jun 2013 16:15:23 +0100	[thread overview]
Message-ID: <20130621151523.GA27646@sirena.org.uk> (raw)
In-Reply-To: <201306201454.r5KEsAAS010978@swsrvapps-01.diasemi.com>

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

On Thu, Jun 20, 2013 at 02:42:03PM +0100, Steve Twiss wrote:

> @@ -293,6 +293,13 @@ config REGULATOR_LP8788
>  	help
>  	  This driver supports LP8788 voltage regulator chip.
>  
> +config REGULATOR_DA9210
> +	bool "Dialog Semiconductor DA9210 Regulator"
> +	depends on I2C=y
> +	select REGMAP_I2C
> +	help
> +	  Support for the Dialog Semiconductor DA9210 chip.
> +
>  config REGULATOR_PCF50633

This file ought to be kept sorted though it seems that's not been
happening, and I'm not seeing any reason why this can't be a tristate.

> +#define DRIVER_NAME	"da9210"

Why?

> +struct da9210 {
> +	struct i2c_client *i2c;
> +	struct device *dev;
> +	struct mutex io_mutex;

Why do you need an I/O lock?

> +static int da9210_enable(struct regulator_dev *rdev);
> +static int da9210_set_voltage(struct regulator_dev *rdev, int min_uV,
> +			      int max_uV, unsigned *selector);
> +static int da9210_get_voltage(struct regulator_dev *rdev);
> +static int da9210_set_current_limit(struct regulator_dev *rdev, int min_uA,
> +				    int max_uA);
> +static int da9210_get_current_limit(struct regulator_dev *rdev);
> +
> +static struct regulator_ops da9210_buck_ops = {
> +	.enable = da9210_enable,
> +	.disable = regulator_disable_regmap,
> +	.is_enabled = regulator_is_enabled_regmap,
> +	.set_voltage = da9210_set_voltage,
> +	.get_voltage = da9210_get_voltage,
> +	.list_voltage = regulator_list_voltage_linear,
> +	.set_current_limit = da9210_set_current_limit,
> +	.get_current_limit = da9210_get_current_limit,
> +};

Drivers are normally written to avoid forward declarations like this.

> +static struct regulator_consumer_supply __initdata def_da9210_consumers[] = {
> +	REGULATOR_SUPPLY("DA9210", NULL),
> +};
> +
> +static struct regulator_init_data __initdata default_da9210_constraints = {
> +	.constraints = {

This is not at all sensible, there's a good solid reason why regulator
drivers don't generally do this...  please review the machine interface
and its purpose.

> +static int da9210_set_voltage(struct regulator_dev *rdev, int min_uV,
> +			      int max_uV, unsigned *selector)
> +{
> +	struct da9210 *chip = rdev_get_drvdata(rdev);
> +	int val;
> +	int ret;
> +
> +	val = regulator_map_voltage_linear(rdev, min_uV, max_uV);
> +	if (val < 0)
> +		return -EINVAL;
> +
> +	ret = regmap_update_bits(chip->regmap, DA9210_REG_VBUCK_A,
> +				 DA9210_VBUCK_MASK, val);
> +	return ret;
> +}

Why not just use set_voltage_sel()?

> +static int da9210_get_voltage_sel(struct regulator_dev *rdev)
> +{
> +	struct da9210 *chip = rdev_get_drvdata(rdev);
> +	unsigned int data;
> +	int sel;
> +	int ret;
> +
> +	ret = regmap_read(chip->regmap, DA9210_REG_VBUCK_A, &data);
> +	if (ret < 0)
> +		return ret;
> +
> +	sel = (data & DA9210_VBUCK_MASK) >> DA9210_VBUCK_SHIFT;
> +	sel -= DA9210_VBUCK_BIAS;
> +	if (sel < 0)
> +		sel = 0;
> +	if (sel >= chip->info->n_steps)
> +		sel = chip->info->n_steps - 1;

This looks like poor error handling, if the value is out of range isn't
there an error state?

> +static int da9210_get_voltage(struct regulator_dev *rdev)
> +{
> +	struct da9210 *chip = rdev_get_drvdata(rdev);
> +	int sel = da9210_get_voltage_sel(rdev);
> +
> +	if (sel < 0)
> +		return sel;
> +
> +	return (chip->info->step_uV * sel) + chip->info->min_uV;
> +}

Why are you open coding core functionalit?

> +static int da9210_enable(struct regulator_dev *rdev)
> +{
> +	return regulator_enable_regmap(rdev);
> +}

This is pointless, just use the generic function directly.

> +
> +	dev_info(chip->dev, "Device DA9210 detected.\n");

This is just noise.

> +static const struct i2c_device_id da9210_i2c_id[] = {
> +	{DRIVER_NAME, 0},
> +	{},

Just use the string.

> +static struct i2c_driver da9210_regulator_driver = {
> +	.driver = {
> +		.name = DRIVER_NAME,

Similarly here.

> +		.owner = THIS_MODULE,
> +		},

Indentation.

> +static int __init da9210_regulator_init(void)
> +{
> +	int ret;
> +
> +	ret = i2c_add_driver(&da9210_regulator_driver);
> +	if (0 != ret)
> +		pr_err("Failed to register da9210 I2C driver\n");
> +
> +	return ret;
> +}
> +
> +subsys_initcall(da9210_regulator_init);

Just use module_platform_driver() now we have probe deferral.

> +/*
> + * Registers bits
> + */
> +/* DA9210_REG_PAGE_CON (addr=0x00) */
> +#define	DA9210_PEG_PAGE_SHIFT			0
> +#define	DA9210_REG_PAGE_MASK			0x0F
> +/* On I2C registers 0x00 - 0xFF */
> +#define	DA9210_REG_PAGE0			0
> +/* On I2C registers 0x100 - 0x1FF */
> +#define	DA9210_REG_PAGE2			2
> +#define	DA9210_PAGE_WRITE_MODE			0x00
> +#define	DA9210_REPEAT_WRITE_MODE		0x40
> +#define	DA9210_PAGE_REVERT			0x80

This looks liike you should be using a regmap range.

[-- Attachment #2: Digital signature --]
[-- Type: application/pgp-signature, Size: 836 bytes --]

  parent reply	other threads:[~2013-06-21 15:15 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-06-20 13:42 Steve Twiss
2013-06-21  9:58 ` Guennadi Liakhovetski
2013-06-24  9:17   ` Opensource [Steve Twiss]
2013-06-26  7:55     ` Guennadi Liakhovetski
2013-06-28 10:32       ` Opensource [Steve Twiss]
2013-06-28 11:12         ` Mark Brown
2013-06-28 13:22           ` Opensource [Steve Twiss]
2013-06-21 15:15 ` Mark Brown [this message]
2013-06-24  9:18   ` Opensource [Steve Twiss]

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=20130621151523.GA27646@sirena.org.uk \
    --to=broonie@kernel.org \
    --cc=david.chen@diasemi.com \
    --cc=g.liakhovetski@gmx.de \
    --cc=lgirdwood@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stwiss.opensource@diasemi.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

all inboxes | Powered by JetHome®