linux-iio.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Fabrice Gasnier <fabrice.gasnier@st.com>
To: Jonathan Cameron <jic23@kernel.org>, <linux@armlinux.org.uk>,
	<robh+dt@kernel.org>, <linux-arm-kernel@lists.infradead.org>,
	<devicetree@vger.kernel.org>, <linux-kernel@vger.kernel.org>
Cc: <linux-iio@vger.kernel.org>, <mark.rutland@arm.com>,
	<mcoquelin.stm32@gmail.com>, <alexandre.torgue@st.com>,
	<lars@metafoo.de>, <knaack.h@gmx.de>, <pmeerw@pmeerw.net>,
	<benjamin.gaignard@linaro.org>, <benjamin.gaignard@st.com>
Subject: Re: [PATCH 3/7] iio: adc: stm32: add trigger polarity extended attribute
Date: Tue, 24 Jan 2017 15:41:24 +0100	[thread overview]
Message-ID: <e78b51ed-5257-b60d-74a7-962fa0f92699@st.com> (raw)
In-Reply-To: <17e5b8ba-0ef3-34eb-aa30-a899f87616f7@kernel.org>


On 01/22/2017 01:58 PM, Jonathan Cameron wrote:
> On 19/01/17 13:34, Fabrice Gasnier wrote:
>> Define extended attribute so that user may choose rising, falling or both
>> edges for external trigger sources.
>> Default to rising edge in case it isn't set.
>>
>> Signed-off-by: Fabrice Gasnier <fabrice.gasnier@st.com>
> Creates a custom attibute.  Documentation please!
> /Documentation/ABI/testing/sysfs-bus-iio-stm32 or similar.

Ok, I'll add something like:
Documentation/ABI/testing/sysfs-bus-iio-adc-stm32:

+What:		/sys/bus/iio/devices/triggerX/trigger_polarity
+KernelVersion:	4.11
+Contact:	fabrice.gasnier@st.com
+Description:
+		The STM32 ADC can be configured to use external trigger sources
+		(e.g. timers, pwm or exti gpio). Then, it can be tuned to start
+		conversions on external trigger by either:
+		- "rising-edge"
+		- "falling-edge"
+		- "both-edges".
+		Reading returns current trigger polarity.
+		Writing value before enabling conversions sets trigger polarity.

Best Regards,
Thanks,
Fabrice
>
> The approach seems reasonable, but easier to discuss when it's
> formally described.
>
> I'd also not care about characters saved and go with
> trigger_polarity rather than the short form (unless this you have
> a good reason for it!)
>
> Jonathan
>> ---
>>  drivers/iio/adc/stm32-adc.c | 51 ++++++++++++++++++++++++++++++++++++++++++++-
>>  1 file changed, 50 insertions(+), 1 deletion(-)
>>
>> diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
>> index 30708bc..9753c39 100644
>> --- a/drivers/iio/adc/stm32-adc.c
>> +++ b/drivers/iio/adc/stm32-adc.c
>> @@ -164,6 +164,7 @@ struct stm32_adc_trig_info {
>>   * @lock:		spinlock
>>   * @bufi:		data buffer index
>>   * @num_conv:		expected number of scan conversions
>> + * @exten:		external trigger config (enable/polarity)
>>   */
>>  struct stm32_adc {
>>  	struct stm32_adc_common	*common;
>> @@ -175,6 +176,7 @@ struct stm32_adc {
>>  	spinlock_t		lock;		/* interrupt lock */
>>  	int			bufi;
>>  	int			num_conv;
>> +	enum stm32_adc_exten	exten;
>>  };
>>
>>  /**
>> @@ -449,7 +451,9 @@ static int stm32_adc_set_trig(struct iio_dev *indio_dev,
>>
>>  		/* set trigger source, default to rising edge */
>>  		extsel = ret;
>> -		exten = STM32_EXTEN_HWTRIG_RISING_EDGE;
>> +		if (adc->exten == STM32_EXTEN_SWTRIG)
>> +			adc->exten = STM32_EXTEN_HWTRIG_RISING_EDGE;
>> +		exten = adc->exten;
>>  	}
>>
>>  	spin_lock_irqsave(&adc->lock, flags);
>> @@ -463,6 +467,39 @@ static int stm32_adc_set_trig(struct iio_dev *indio_dev,
>>  	return 0;
>>  }
>>
>> +static int stm32_adc_set_trig_pol(struct iio_dev *indio_dev,
>> +				  const struct iio_chan_spec *chan,
>> +				  unsigned int type)
>> +{
>> +	struct stm32_adc *adc = iio_priv(indio_dev);
>> +
>> +	adc->exten = type;
>> +
>> +	return 0;
>> +}
>> +
>> +static int stm32_adc_get_trig_pol(struct iio_dev *indio_dev,
>> +				  const struct iio_chan_spec *chan)
>> +{
>> +	struct stm32_adc *adc = iio_priv(indio_dev);
>> +
>> +	return adc->exten;
>> +}
>> +
>> +static const char * const stm32_trig_pol_items[] = {
>> +	[STM32_EXTEN_SWTRIG] = "swtrig",
>> +	[STM32_EXTEN_HWTRIG_RISING_EDGE] = "rising-edge",
>> +	[STM32_EXTEN_HWTRIG_FALLING_EDGE] = "falling-edge",
>> +	[STM32_EXTEN_HWTRIG_BOTH_EDGES] = "both-edges",
>> +};
>> +
>> +const struct iio_enum stm32_adc_trig_pol = {
>> +	.items = stm32_trig_pol_items,
>> +	.num_items = ARRAY_SIZE(stm32_trig_pol_items),
>> +	.get = stm32_adc_get_trig_pol,
>> +	.set = stm32_adc_set_trig_pol,
>> +};
>> +
>>  /**
>>   * stm32_adc_single_conv() - Performs a single conversion
>>   * @indio_dev: IIO device
>> @@ -745,6 +782,17 @@ static irqreturn_t stm32_adc_trigger_handler(int irq, void *p)
>>  	return IRQ_HANDLED;
>>  }
>>
>> +static const struct iio_chan_spec_ext_info stm32_adc_ext_info[] = {
>> +	IIO_ENUM("trigger_pol", IIO_SHARED_BY_ALL, &stm32_adc_trig_pol),
>> +	{
>> +		.name = "trigger_pol_available",
>> +		.shared = IIO_SHARED_BY_ALL,
>> +		.read = iio_enum_available_read,
>> +		.private = (uintptr_t)&stm32_adc_trig_pol,
>> +	},
>> +	{},
>> +};
>> +
>>  static void stm32_adc_chan_init_one(struct iio_dev *indio_dev,
>>  				    struct iio_chan_spec *chan,
>>  				    const struct stm32_adc_chan_spec *channel,
>> @@ -760,6 +808,7 @@ static void stm32_adc_chan_init_one(struct iio_dev *indio_dev,
>>  	chan->scan_type.sign = 'u';
>>  	chan->scan_type.realbits = 12;
>>  	chan->scan_type.storagebits = 16;
>> +	chan->ext_info = stm32_adc_ext_info;
>>  }
>>
>>  static int stm32_adc_chan_of_init(struct iio_dev *indio_dev)
>>
>

  reply	other threads:[~2017-01-24 14:42 UTC|newest]

Thread overview: 25+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-19 13:34 [PATCH 0/7] Add support for triggered buffer mode to STM32 ADC Fabrice Gasnier
2017-01-19 13:34 ` [PATCH 1/7] iio: adc: stm32: add support for triggered buffer mode Fabrice Gasnier
2017-01-22 12:53   ` Jonathan Cameron
2017-01-24 14:35     ` Fabrice Gasnier
2017-01-28 14:02       ` Jonathan Cameron
2017-01-19 13:34 ` [PATCH 2/7] iio: adc: stm32: Enable use of stm32 timer triggers Fabrice Gasnier
2017-01-19 23:31   ` kbuild test robot
2017-01-21 12:55     ` Jonathan Cameron
2017-01-22 12:55   ` Jonathan Cameron
2017-01-24 14:37     ` Fabrice Gasnier
2017-01-28 12:46       ` Jonathan Cameron
2017-01-19 13:34 ` [PATCH 3/7] iio: adc: stm32: add trigger polarity extended attribute Fabrice Gasnier
2017-01-22 12:58   ` Jonathan Cameron
2017-01-24 14:41     ` Fabrice Gasnier [this message]
2017-01-19 13:34 ` [PATCH 4/7] Documentation: dt: iio: stm32-adc: optional dma support Fabrice Gasnier
2017-01-21 20:54   ` Rob Herring
2017-01-19 13:34 ` [PATCH 5/7] iio: adc: stm32: add " Fabrice Gasnier
2017-01-22 13:14   ` Jonathan Cameron
2017-01-24 14:43     ` Fabrice Gasnier
2017-01-24 18:25       ` Jonathan Cameron
2017-01-19 13:34 ` [PATCH 6/7] ARM: dts: stm32: Enable dma by default on stm32f4 adc Fabrice Gasnier
2017-01-19 13:34 ` [PATCH 7/7] ARM: dts: stm32: Enable pwm1 and pwm3 for stm32f469-eval Fabrice Gasnier
2017-01-20  0:09   ` kbuild test robot
2017-01-20 10:19   ` Alexandre Torgue
2017-01-20 10:36     ` Fabrice Gasnier

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=e78b51ed-5257-b60d-74a7-962fa0f92699@st.com \
    --to=fabrice.gasnier@st.com \
    --cc=alexandre.torgue@st.com \
    --cc=benjamin.gaignard@linaro.org \
    --cc=benjamin.gaignard@st.com \
    --cc=devicetree@vger.kernel.org \
    --cc=jic23@kernel.org \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux@armlinux.org.uk \
    --cc=mark.rutland@arm.com \
    --cc=mcoquelin.stm32@gmail.com \
    --cc=pmeerw@pmeerw.net \
    --cc=robh+dt@kernel.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).