devicetree.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Jonathan Cameron <jic23-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>
To: Vignesh R <vigneshr-l0cyMroinI0@public.gmane.org>,
	Rob Herring <robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org>,
	Pawel Moll <pawel.moll-5wv7dgnIgG8@public.gmane.org>,
	Mark Rutland <mark.rutland-5wv7dgnIgG8@public.gmane.org>,
	Ian Campbell
	<ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org>,
	Kumar Gala <galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org>
Cc: Hartmut Knaack <knaack.h-Mmb7MZpHnFY@public.gmane.org>,
	Lars-Peter Clausen <lars-Qo5EllUWu/uELgA04lAiVw@public.gmane.org>,
	Peter Meerwald <pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org>,
	Dmitry Torokhov
	<dmitry.torokhov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>,
	Karol Wrona <k.wrona-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org>,
	Jan Kardell <jan.kardell-KSZdJiTw9mzQT0dZR+AlfA@public.gmane.org>,
	devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-kernel-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	linux-iio-u79uwXL29TY76Z2rM5mHXA@public.gmane.org,
	fcooper-l0cyMroinI0@public.gmane.org
Subject: Re: [PATCH 2/2] iio: adc: ti_am335x_adc: make sample delay, open delay, averaging DT parameters
Date: Thu, 09 Apr 2015 15:19:40 +0100	[thread overview]
Message-ID: <55268A7C.1050307@kernel.org> (raw)
In-Reply-To: <1427800357-21680-3-git-send-email-vigneshr-l0cyMroinI0@public.gmane.org>

On 31/03/15 12:12, Vignesh R wrote:
> Add optional DT properties to set open delay, sample delay and number
> of averages per sample for each adc step. Open delay, sample delay
> and averaging are some of the parameters that affect the sampling rate
> and accuracy of the sample. Making these parameters configurable via
> DT will help in balancing speed vs accuracy.
> 
> Signed-off-by: Vignesh R <vigneshr-l0cyMroinI0@public.gmane.org>
All looks fine to me, but I would ideally like a devicetree
ack on this one.

Jonathan
> ---
>  .../bindings/input/touchscreen/ti-tsc-adc.txt      | 24 ++++++++++
>  drivers/iio/adc/ti_am335x_adc.c                    | 54 +++++++++++++++++++---
>  2 files changed, 72 insertions(+), 6 deletions(-)
> 
> diff --git a/Documentation/devicetree/bindings/input/touchscreen/ti-tsc-adc.txt b/Documentation/devicetree/bindings/input/touchscreen/ti-tsc-adc.txt
> index 6c4fb34823d3..8aafbe87f0eb 100644
> --- a/Documentation/devicetree/bindings/input/touchscreen/ti-tsc-adc.txt
> +++ b/Documentation/devicetree/bindings/input/touchscreen/ti-tsc-adc.txt
> @@ -42,6 +42,27 @@ Optional properties:
>  			 hardware knob for adjusting the amount of "settling
>  			 time".
>  
> +- child "adc"
> +	ti,chan-step-opendelay: List of open delays for each channel of
> +				ADC in the order of ti,adc-channels. The
> +				value corresponds to the number of ADC
> +				clock cycles to wait after applying the
> +				step configuration registers and before
> +				sending the start of ADC conversion.
> +				Maximum value is 0x3FFFF.
> +       ti,chan-step-sampledelay: List of sample delays for each channel
> +				  of ADC in the order of ti,adc-channels.
> +				  The value corresponds to the number of
> +				  ADC clock cycles to sample (to hold
> +				  start of conversion high).
> +				  Maximum value is 0xFF.
> +       ti,chan-step-avg: Number of averages to be performed for each
> +			  channel of ADC. If average is 16 then input
> +			  is sampled 16 times and averaged to get more
> +			  accurate value. This increases the time taken
> +			  by ADC to generate a sample. Valid range is 0
> +			  average to 16 averages. Maximum value is 16.
> +
>  Example:
>  	tscadc: tscadc@44e0d000 {
>  		compatible = "ti,am3359-tscadc";
> @@ -55,5 +76,8 @@ Example:
>  
>  		adc {
>  			ti,adc-channels = <4 5 6 7>;
> +			ti,chan-step-opendelay = <0x098 0x3ffff 0x098 0x0>;
> +			ti,chan-step-sampledelay = <0xff 0x0 0xf 0x0>;
> +			ti,chan-step-avg = <16 2 4 8>;
>  		};
>  	}
> diff --git a/drivers/iio/adc/ti_am335x_adc.c b/drivers/iio/adc/ti_am335x_adc.c
> index 2f818405ffbe..5ee597b4a1af 100644
> --- a/drivers/iio/adc/ti_am335x_adc.c
> +++ b/drivers/iio/adc/ti_am335x_adc.c
> @@ -37,6 +37,7 @@ struct tiadc_device {
>  	u8 channel_step[8];
>  	int buffer_en_ch_steps;
>  	u16 data[8];
> +	u32 open_delay[8], sample_delay[8], step_avg[8];
>  };
>  
>  static unsigned int tiadc_readl(struct tiadc_device *adc, unsigned int reg)
> @@ -85,6 +86,7 @@ static u32 get_adc_step_bit(struct tiadc_device *adc_dev, int chan)
>  static void tiadc_step_config(struct iio_dev *indio_dev)
>  {
>  	struct tiadc_device *adc_dev = iio_priv(indio_dev);
> +	struct device *dev = adc_dev->mfd_tscadc->dev;
>  	unsigned int stepconfig;
>  	int i, steps = 0;
>  
> @@ -98,20 +100,47 @@ static void tiadc_step_config(struct iio_dev *indio_dev)
>  	 * needs to be given to ADC to digitalize data.
>  	 */
>  
> -	if (iio_buffer_enabled(indio_dev))
> -		stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1
> -					| STEPCONFIG_MODE_SWCNT;
> -	else
> -		stepconfig = STEPCONFIG_AVG_16 | STEPCONFIG_FIFO1;
>  
>  	for (i = 0; i < adc_dev->channels; i++) {
>  		int chan;
>  
>  		chan = adc_dev->channel_line[i];
> +
> +		if (adc_dev->step_avg[i] > STEPCONFIG_AVG_16) {
> +			dev_warn(dev, "chan %d step_avg truncating to %d\n",
> +				 chan, STEPCONFIG_AVG_16);
> +			adc_dev->step_avg[i] = STEPCONFIG_AVG_16;
> +		}
> +
> +		if (adc_dev->step_avg[i])
> +			stepconfig =
> +			STEPCONFIG_AVG(ffs(adc_dev->step_avg[i]) - 1) |
> +			STEPCONFIG_FIFO1;
> +		else
> +			stepconfig = STEPCONFIG_FIFO1;
> +
> +		if (iio_buffer_enabled(indio_dev))
> +			stepconfig |= STEPCONFIG_MODE_SWCNT;
> +
>  		tiadc_writel(adc_dev, REG_STEPCONFIG(steps),
>  				stepconfig | STEPCONFIG_INP(chan));
> +
> +		if (adc_dev->open_delay[i] > STEPDELAY_OPEN_MASK)alue corresponds to the number of ADC
> +				clock cycles to wait after applying the
> +				step configuration registers and before
> +				sending the start of ADC conversion.
> +				Maximum value is 0x3FFFF.
> +       ti,chan-step-sampledelay: List of sample delays for each channel
> +				  of ADC in the order of ti,adc-channels.
> +				  The value corresponds to the number of
> +				  ADC clock cycles to sample (to hold
> +				  start of conversion high).
> +				  Maximum value is 0xFF.
> +       ti,chan-step-avg: Number of averages to be performed for each
> +			  channel of ADC. If average is 16 then input
> +			  is sampled 16 times and averaged to get more
> +			  accurate value. This increases the time taken
> +			  by ADC to generate a sample. Valid range is 0
> +			  average to 16 averages. Maximum value is 16. {
> +			dev_warn(dev, "chan %d open delay truncating to 0x3FFFF\n",
> +				 chan);
> +			adc_dev->open_delay[i] = STEPDELAY_OPEN_MASK;
> +		}
> +
> +		if (adc_dev->sample_delay[i] > 0xFF) {
> +			dev_warn(dev, "chan %d sample delay truncating to 0xFF\n",
> +				 chan);
> +			adc_dev->sample_delay[i] = 0xFF;
> +		}
> +
>  		tiadc_writel(adc_dev, REG_STEPDELAY(steps),
> -				STEPCONFIG_OPENDLY);
> +				STEPDELAY_OPEN(adc_dev->open_delay[i]) |
> +				STEPDELAY_SAMPLE(adc_dev->sample_delay[i]));
> +
>  		adc_dev->channel_step[i] = steps;
>  		steps++;
>  	}
> @@ -407,9 +436,22 @@ static int tiadc_parse_dt(struct platform_device *pdev,
>  
>  	of_property_for_each_u32(node, "ti,adc-channels", prop, cur, val) {
>  		adc_dev->channel_line[channels] = val;
> +
> +		/* Set Default values for optional DT parameters */
> +		adc_dev->open_delay[channels] = STEPCONFIG_OPENDLY;
> +		adc_dev->sample_delay[channels] = STEPCONFIG_SAMPLEDLY;
> +		adc_dev->step_avg[channels] = 16;
> +
>  		channels++;
>  	}
>  
> +	of_property_read_u32_array(node, "ti,chan-step-avg",
> +				   adc_dev->step_avg, channels);
> +	of_property_read_u32_array(node, "ti,chan-step-opendelay",
> +				   adc_dev->open_delay, channels);
> +	of_property_read_u32_array(node, "ti,chan-step-sampledelay",
> +				   adc_dev->sample_delay, channels);
> +
>  	adc_dev->channels = channels;
>  	return 0;
>  }
> 

  parent reply	other threads:[~2015-04-09 14:19 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2015-03-31 11:12 [PATCH 0/2] iio: ti_am335x_adc: Add optional DT properties for tscadc Vignesh R
2015-03-31 11:12 ` [PATCH 1/2] iio: adc: ti_am335x_adc: refactor DT parsing into a function Vignesh R
     [not found]   ` <1427800357-21680-2-git-send-email-vigneshr-l0cyMroinI0@public.gmane.org>
2015-04-09 14:13     ` Jonathan Cameron
2015-03-31 11:12 ` [PATCH 2/2] iio: adc: ti_am335x_adc: make sample delay, open delay, averaging DT parameters Vignesh R
     [not found]   ` <1427800357-21680-3-git-send-email-vigneshr-l0cyMroinI0@public.gmane.org>
2015-04-09 14:19     ` Jonathan Cameron [this message]
2015-05-13  7:42       ` Vignesh R
     [not found]         ` <5553006B.1050306-l0cyMroinI0@public.gmane.org>
2015-05-13 17:38           ` Jonathan Cameron
  -- strict thread matches above, loose matches on Subject: below --
2014-08-27 12:19 [PATCH 1/2] iio: adc: ti_am335x_adc: refactor DT parsing into a function Vignesh R
2014-08-27 12:19 ` [PATCH 2/2] iio: adc: ti_am335x_adc: make sample delay, open delay, averaging DT parameters Vignesh R
     [not found]   ` <1409141990-29627-2-git-send-email-vigneshr-l0cyMroinI0@public.gmane.org>
2014-08-27 13:56     ` Lee Jones
2014-08-28  5:12       ` Vignesh R
2014-08-28  7:11         ` Lee Jones
2014-08-30  9:34           ` Jonathan Cameron
2014-08-30  9:43   ` Jonathan Cameron
2014-09-01  6:40     ` Vignesh R

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=55268A7C.1050307@kernel.org \
    --to=jic23-dgejt+ai2ygdnm+yrofe0a@public.gmane.org \
    --cc=devicetree-u79uwXL29TY76Z2rM5mHXA@public.gmane.org \
    --cc=dmitry.torokhov-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org \
    --cc=fcooper-l0cyMroinI0@public.gmane.org \
    --cc=galak-sgV2jX0FEOL9JmXXK+q4OQ@public.gmane.org \
    --cc=ijc+devicetree-KcIKpvwj1kUDXYZnReoRVg@public.gmane.org \
    --cc=jan.kardell-KSZdJiTw9mzQT0dZR+AlfA@public.gmane.org \
    --cc=k.wrona-Sze3O3UU22JBDgjK7y7TUQ@public.gmane.org \
    --cc=knaack.h-Mmb7MZpHnFY@public.gmane.org \
    --cc=lars-Qo5EllUWu/uELgA04lAiVw@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=pawel.moll-5wv7dgnIgG8@public.gmane.org \
    --cc=pmeerw-jW+XmwGofnusTnJN9+BGXg@public.gmane.org \
    --cc=robh+dt-DgEjT+Ai2ygdnm+yROfE0A@public.gmane.org \
    --cc=vigneshr-l0cyMroinI0@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).