linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23@kernel.org>
To: Gregory CLEMENT <gregory.clement@bootlin.com>
Cc: Hartmut Knaack <knaack.h@gmx.de>,
	Lars-Peter Clausen <lars@metafoo.de>,
	Peter Meerwald-Stadler <pmeerw@pmeerw.net>,
	linux-iio@vger.kernel.org, Vladimir Zapolskiy <vz@mleia.com>,
	Sylvain Lemieux <slemieux.tyco@gmail.com>,
	Rob Herring <robh+dt@kernel.org>,
	devicetree@vger.kernel.org,
	Thomas Petazzoni <thomas.petazzoni@bootlin.com>,
	linux-arm-kernel@lists.infradead.org
Subject: Re: [PATCH v2 3/4] iio: adc: lpc32xx: Add scale feature
Date: Sat, 16 Mar 2019 17:26:34 +0000	[thread overview]
Message-ID: <20190316172634.4bb51753@archlinux> (raw)
In-Reply-To: <20190315095231.17001-4-gregory.clement@bootlin.com>

On Fri, 15 Mar 2019 10:52:30 +0100
Gregory CLEMENT <gregory.clement@bootlin.com> wrote:

> Until now this driver only exposed the raw value of the channels. With
> this patch, the scale value is also exposed.
> 
> It depends of a regulator supply, and unlike most of the other driver, do
> not having this regulator won't prevent to use the driver. The reason for
> it is to allow to continue to use this driver with an old device tree. If
> there is no regulator supply then the scale won't be exposed.
> 
> Signed-off-by: Gregory CLEMENT <gregory.clement@bootlin.com>

I made a minor tweak to downgrade the message if the regulator isn't
specified.

Applied to the togreg branch of iio.git and pushed out as testing
for the autobuilders to play with it.

Thanks,

Jonathan

> ---
>  drivers/iio/adc/lpc32xx_adc.c | 44 ++++++++++++++++++++++++++++++-----
>  1 file changed, 38 insertions(+), 6 deletions(-)
> 
> diff --git a/drivers/iio/adc/lpc32xx_adc.c b/drivers/iio/adc/lpc32xx_adc.c
> index f391c1e10136..5d1c76e3aad8 100644
> --- a/drivers/iio/adc/lpc32xx_adc.c
> +++ b/drivers/iio/adc/lpc32xx_adc.c
> @@ -14,6 +14,7 @@
>  #include <linux/io.h>
>  #include <linux/module.h>
>  #include <linux/platform_device.h>
> +#include <linux/regulator/consumer.h>
>  
>  /*
>   * LPC32XX registers definitions
> @@ -45,6 +46,7 @@ struct lpc32xx_adc_state {
>  	void __iomem *adc_base;
>  	struct clk *clk;
>  	struct completion completion;
> +	struct regulator *vref;
>  
>  	u32 value;
>  };
> @@ -57,7 +59,9 @@ static int lpc32xx_read_raw(struct iio_dev *indio_dev,
>  {
>  	struct lpc32xx_adc_state *st = iio_priv(indio_dev);
>  	int ret;
> -	if (mask == IIO_CHAN_INFO_RAW) {
> +
> +	switch (mask) {
> +	case IIO_CHAN_INFO_RAW:
>  		mutex_lock(&indio_dev->mlock);
>  		ret = clk_prepare_enable(st->clk);
>  		if (ret) {
> @@ -77,22 +81,36 @@ static int lpc32xx_read_raw(struct iio_dev *indio_dev,
>  		mutex_unlock(&indio_dev->mlock);
>  
>  		return IIO_VAL_INT;
> -	}
>  
> -	return -EINVAL;
> +	case IIO_CHAN_INFO_SCALE:
> +		*val = regulator_get_voltage(st->vref) / 1000;
> +		*val2 =  10;
> +
> +		return IIO_VAL_FRACTIONAL_LOG2;
> +	default:
> +		return -EINVAL;
> +	}
>  }
>  
>  static const struct iio_info lpc32xx_adc_iio_info = {
>  	.read_raw = &lpc32xx_read_raw,
>  };
>  
> -#define LPC32XX_ADC_CHANNEL(_index) {			\
> +#define LPC32XX_ADC_CHANNEL_BASE(_index)		\
>  	.type = IIO_VOLTAGE,				\
>  	.indexed = 1,					\
>  	.channel = _index,				\
>  	.info_mask_separate = BIT(IIO_CHAN_INFO_RAW),	\
>  	.address = LPC32XXAD_IN * _index,		\
> -	.scan_index = _index,				\
> +	.scan_index = _index,
> +
> +#define LPC32XX_ADC_CHANNEL(_index) {		\
> +	LPC32XX_ADC_CHANNEL_BASE(_index)	\
> +}
> +
> +#define LPC32XX_ADC_SCALE_CHANNEL(_index) {			\
> +	LPC32XX_ADC_CHANNEL_BASE(_index)			\
> +	.info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE)	\
>  }
>  
>  static const struct iio_chan_spec lpc32xx_adc_iio_channels[] = {
> @@ -101,6 +119,12 @@ static const struct iio_chan_spec lpc32xx_adc_iio_channels[] = {
>  	LPC32XX_ADC_CHANNEL(2),
>  };
>  
> +static const struct iio_chan_spec lpc32xx_adc_iio_scale_channels[] = {
> +	LPC32XX_ADC_SCALE_CHANNEL(0),
> +	LPC32XX_ADC_SCALE_CHANNEL(1),
> +	LPC32XX_ADC_SCALE_CHANNEL(2),
> +};
> +
>  static irqreturn_t lpc32xx_adc_isr(int irq, void *dev_id)
>  {
>  	struct lpc32xx_adc_state *st = dev_id;
> @@ -159,6 +183,15 @@ static int lpc32xx_adc_probe(struct platform_device *pdev)
>  		return retval;
>  	}
>  
> +	st->vref = devm_regulator_get(&pdev->dev, "vref");
> +	if (IS_ERR(st->vref)) {
> +		iodev->channels = lpc32xx_adc_iio_channels;
> +		dev_err(&pdev->dev,
> +			"Missing vref regulator: No scaling available\n");
It isn't an error, so downgraded to dev_info.

> +	} else {
> +		iodev->channels = lpc32xx_adc_iio_scale_channels;
> +	}
> +
>  	platform_set_drvdata(pdev, iodev);
>  
>  	init_completion(&st->completion);
> @@ -167,7 +200,6 @@ static int lpc32xx_adc_probe(struct platform_device *pdev)
>  	iodev->dev.parent = &pdev->dev;
>  	iodev->info = &lpc32xx_adc_iio_info;
>  	iodev->modes = INDIO_DIRECT_MODE;
> -	iodev->channels = lpc32xx_adc_iio_channels;
>  	iodev->num_channels = ARRAY_SIZE(lpc32xx_adc_iio_channels);
>  
>  	retval = devm_iio_device_register(&pdev->dev, iodev);


  reply	other threads:[~2019-03-16 17:26 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-03-15  9:52 [PATCH v2 0/4] Adding scale support to the lpc32xx ADC driver Gregory CLEMENT
2019-03-15  9:52 ` [PATCH v2 1/4] iio: adc: lpc32xx: Sort headers Gregory CLEMENT
2019-03-16 17:17   ` Jonathan Cameron
2019-03-15  9:52 ` [PATCH v2 2/4] iio: adc: lpc32xx: Cleanup headers Gregory CLEMENT
2019-03-16 17:23   ` Jonathan Cameron
2019-03-15  9:52 ` [PATCH v2 3/4] iio: adc: lpc32xx: Add scale feature Gregory CLEMENT
2019-03-16 17:26   ` Jonathan Cameron [this message]
2019-03-15  9:52 ` [PATCH v2 4/4] dt-bindings: iio: adc: lpc32xx-adc: Document vref-supply Gregory CLEMENT
2019-03-16 17:27   ` Jonathan Cameron
2019-03-16 17:16 ` [PATCH v2 0/4] Adding scale support to the lpc32xx ADC driver Jonathan Cameron

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=20190316172634.4bb51753@archlinux \
    --to=jic23@kernel.org \
    --cc=devicetree@vger.kernel.org \
    --cc=gregory.clement@bootlin.com \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.org \
    --cc=slemieux.tyco@gmail.com \
    --cc=thomas.petazzoni@bootlin.com \
    --cc=vz@mleia.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).