devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Fabrice Gasnier <fabrice.gasnier-qxv4g6HH51o@public.gmane.org>,
	linux-I+IVW8TIWO2tmTQ+vhA3Yw@public.gmane.org,
	robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org,
	linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
Cc: linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	mark.rutland-5wv7dgnIgG8@public.gmane.org,
	mcoquelin.stm32-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org,
	alexandre.torgue-qxv4g6HH51o@public.gmane.org,
	lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org,
	knaack.h-Mmb7MZpHnFY@public.gmane.org,
	pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org,
	benjamin.gaignard-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org,
	benjamin.gaignard-qxv4g6HH51o@public.gmane.org,
	linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org
Subject: Re: [PATCH v2 2/2] iio: adc: stm32: add dt option to set resolution
Date: Mon, 3 Apr 2017 20:46:43 +0100	[thread overview]
Message-ID: <e0979bed-603b-c84f-62f2-ee432fc021b4@kernel.org> (raw)
In-Reply-To: <8d440abd-3548-6aab-bba9-3f62fe27e72d-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>

On 02/04/17 09:54, Jonathan Cameron wrote:
> On 31/03/17 13:32, Fabrice Gasnier wrote:
>> stm32 adc supports several resolution. Add 'assigned-resolution-bits'
>> dt optional property to set it. Default to maximum resolution in case
>> it isn't set.
>>
>> Signed-off-by: Fabrice Gasnier <fabrice.gasnier-qxv4g6HH51o@public.gmane.org>
> The code is fine.  Just waiting on review of the binding.
> 
> Give me a poke if I seem to have dropped this in a week or two.
Applied to the togreg branch of iio.git and pushed out as
testing for the autobuilders to play with it.

Thanks,

Jonathan
> 
> Thanks,
> 
> Jonathan
>> ---
>> Changes in v2:
>> - rename property from 'st,adc-res' to 'assigned-resolution-bits', so it
>>   is more common.
>> ---
>>  drivers/iio/adc/stm32-adc.c | 50 ++++++++++++++++++++++++++++++++++++++++++++-
>>  1 file changed, 49 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
>> index 9b49a6ad..c28e7ff 100644
>> --- a/drivers/iio/adc/stm32-adc.c
>> +++ b/drivers/iio/adc/stm32-adc.c
>> @@ -60,6 +60,8 @@
>>  #define STM32F4_EOC			BIT(1)
>>  
>>  /* STM32F4_ADC_CR1 - bit fields */
>> +#define STM32F4_RES_SHIFT		24
>> +#define STM32F4_RES_MASK		GENMASK(25, 24)
>>  #define STM32F4_SCAN			BIT(8)
>>  #define STM32F4_EOCIE			BIT(5)
>>  
>> @@ -141,6 +143,7 @@ struct stm32_adc_regs {
>>   * @lock:		spinlock
>>   * @bufi:		data buffer index
>>   * @num_conv:		expected number of scan conversions
>> + * @res:		data resolution (e.g. RES bitfield value)
>>   * @trigger_polarity:	external trigger polarity (e.g. exten)
>>   * @dma_chan:		dma channel
>>   * @rx_buf:		dma rx buffer cpu address
>> @@ -157,6 +160,7 @@ struct stm32_adc {
>>  	spinlock_t		lock;		/* interrupt lock */
>>  	unsigned int		bufi;
>>  	unsigned int		num_conv;
>> +	u32			res;
>>  	u32			trigger_polarity;
>>  	struct dma_chan		*dma_chan;
>>  	u8			*rx_buf;
>> @@ -196,6 +200,11 @@ struct stm32_adc_chan_spec {
>>  	{ IIO_VOLTAGE, 15, "in15" },
>>  };
>>  
>> +static const unsigned int stm32f4_adc_resolutions[] = {
>> +	/* sorted values so the index matches RES[1:0] in STM32F4_ADC_CR1 */
>> +	12, 10, 8, 6,
>> +};
>> +
>>  /**
>>   * stm32f4_sq - describe regular sequence registers
>>   * - L: sequence len (register & bit field)
>> @@ -302,6 +311,14 @@ static void stm32_adc_conv_irq_disable(struct stm32_adc *adc)
>>  	stm32_adc_clr_bits(adc, STM32F4_ADC_CR1, STM32F4_EOCIE);
>>  }
>>  
>> +static void stm32_adc_set_res(struct stm32_adc *adc)
>> +{
>> +	u32 val = stm32_adc_readl(adc, STM32F4_ADC_CR1);
>> +
>> +	val = (val & ~STM32F4_RES_MASK) | (adc->res << STM32F4_RES_SHIFT);
>> +	stm32_adc_writel(adc, STM32F4_ADC_CR1, val);
>> +}
>> +
>>  /**
>>   * stm32_adc_start_conv() - Start conversions for regular channels.
>>   * @adc: stm32 adc instance
>> @@ -870,11 +887,37 @@ static irqreturn_t stm32_adc_trigger_handler(int irq, void *p)
>>  	{},
>>  };
>>  
>> +static int stm32_adc_of_get_resolution(struct iio_dev *indio_dev)
>> +{
>> +	struct device_node *node = indio_dev->dev.of_node;
>> +	struct stm32_adc *adc = iio_priv(indio_dev);
>> +	unsigned int i;
>> +	u32 res;
>> +
>> +	if (of_property_read_u32(node, "assigned-resolution-bits", &res))
>> +		res = stm32f4_adc_resolutions[0];
>> +
>> +	for (i = 0; i < ARRAY_SIZE(stm32f4_adc_resolutions); i++)
>> +		if (res == stm32f4_adc_resolutions[i])
>> +			break;
>> +	if (i >= ARRAY_SIZE(stm32f4_adc_resolutions)) {
>> +		dev_err(&indio_dev->dev, "Bad resolution: %u bits\n", res);
>> +		return -EINVAL;
>> +	}
>> +
>> +	dev_dbg(&indio_dev->dev, "Using %u bits resolution\n", res);
>> +	adc->res = i;
>> +
>> +	return 0;
>> +}
>> +
>>  static void stm32_adc_chan_init_one(struct iio_dev *indio_dev,
>>  				    struct iio_chan_spec *chan,
>>  				    const struct stm32_adc_chan_spec *channel,
>>  				    int scan_index)
>>  {
>> +	struct stm32_adc *adc = iio_priv(indio_dev);
>> +
>>  	chan->type = channel->type;
>>  	chan->channel = channel->channel;
>>  	chan->datasheet_name = channel->name;
>> @@ -883,7 +926,7 @@ static void stm32_adc_chan_init_one(struct iio_dev *indio_dev,
>>  	chan->info_mask_separate = BIT(IIO_CHAN_INFO_RAW);
>>  	chan->info_mask_shared_by_type = BIT(IIO_CHAN_INFO_SCALE);
>>  	chan->scan_type.sign = 'u';
>> -	chan->scan_type.realbits = 12;
>> +	chan->scan_type.realbits = stm32f4_adc_resolutions[adc->res];
>>  	chan->scan_type.storagebits = 16;
>>  	chan->ext_info = stm32_adc_ext_info;
>>  }
>> @@ -1022,6 +1065,11 @@ static int stm32_adc_probe(struct platform_device *pdev)
>>  		return ret;
>>  	}
>>  
>> +	ret = stm32_adc_of_get_resolution(indio_dev);
>> +	if (ret < 0)
>> +		goto err_clk_disable;
>> +	stm32_adc_set_res(adc);
>> +
>>  	ret = stm32_adc_chan_of_init(indio_dev);
>>  	if (ret < 0)
>>  		goto err_clk_disable;
>>
> 
> --
> To unsubscribe from this list: send the line "unsubscribe linux-iio" in
> the body of a message to majordomo-u79uwXL29TY76Z2rM5mHXA@public.gmane.org
> More majordomo info at  http://vger.kernel.org/majordomo-info.html
> 

      parent reply	other threads:[~2017-04-03 19:46 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-03-31 12:32 [PATCH v2 0/2] iio: allow to set STM32 ADC resolution Fabrice Gasnier
2017-03-31 12:32 ` [PATCH v2 1/2] dt-bindings: iio: stm32-adc: add option to set resolution Fabrice Gasnier
     [not found]   ` <1490963559-32159-2-git-send-email-fabrice.gasnier-qxv4g6HH51o@public.gmane.org>
2017-04-03 16:46     ` Rob Herring
2017-04-03 19:45       ` Jonathan Cameron
2017-03-31 12:32 ` [PATCH v2 2/2] iio: adc: stm32: add dt " Fabrice Gasnier
     [not found]   ` <1490963559-32159-3-git-send-email-fabrice.gasnier-qxv4g6HH51o@public.gmane.org>
2017-04-02  8:54     ` Jonathan Cameron
     [not found]       ` <8d440abd-3548-6aab-bba9-3f62fe27e72d-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
2017-04-03 19:46         ` Jonathan Cameron [this message]

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=e0979bed-603b-c84f-62f2-ee432fc021b4@kernel.org \
    --to=jic23-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=alexandre.torgue-qxv4g6HH51o@public.gmane.org \
    --cc=benjamin.gaignard-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=benjamin.gaignard-qxv4g6HH51o@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=fabrice.gasnier-qxv4g6HH51o@public.gmane.org \
    --cc=knaack.h-Mmb7MZpHnFY@public.gmane.org \
    --cc=lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org \
    --cc=linus.walleij-QSEj5FYQhm4dnm+yROfE0A@public.gmane.org \
    --cc=linux-I+IVW8TIWO2tmTQ+vhA3Yw@public.gmane.org \
    --cc=linux-arm-kernel-IAPFreCvJWM7uuMidbF8XUB+6BGkLq7r@public.gmane.org \
    --cc=linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=mark.rutland-5wv7dgnIgG8@public.gmane.org \
    --cc=mcoquelin.stm32-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.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).