linux-arm-kernel.lists.infradead.org archive mirror
 help / color / mirror / Atom feed
From: jic23@kernel.org (Jonathan Cameron)
To: linux-arm-kernel@lists.infradead.org
Subject: [PATCH v2 3/7] iio: adc: stm32: add trigger polarity extended attribute
Date: Sat, 28 Jan 2017 18:39:41 +0000	[thread overview]
Message-ID: <c5be8b19-651e-d5e3-0ccd-af0ae36bc1cb@kernel.org> (raw)
In-Reply-To: <1485440915-30119-4-git-send-email-fabrice.gasnier@st.com>

On 26/01/17 14:28, 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>
Applied though as discussed we might want some ability to add
a default for external triggers via dt.

Can be added later.

Pushed out as testing for the autobuilders to play with it.

Thanks,

Jonathan
> ---
> Changes in v2:
> - Rename and document new trigger_polarity custom attribute
> ---
>  Documentation/ABI/testing/sysfs-bus-iio-adc-stm32 | 18 +++++++++
>  drivers/iio/adc/stm32-adc.c                       | 46 ++++++++++++++++++++++-
>  2 files changed, 63 insertions(+), 1 deletion(-)
>  create mode 100644 Documentation/ABI/testing/sysfs-bus-iio-adc-stm32
> 
> diff --git a/Documentation/ABI/testing/sysfs-bus-iio-adc-stm32 b/Documentation/ABI/testing/sysfs-bus-iio-adc-stm32
> new file mode 100644
> index 0000000..efe4c85
> --- /dev/null
> +++ b/Documentation/ABI/testing/sysfs-bus-iio-adc-stm32
> @@ -0,0 +1,18 @@
> +What:		/sys/bus/iio/devices/triggerX/trigger_polarity
> +KernelVersion:	4.11
> +Contact:	fabrice.gasnier at 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.
> +
> +What:		/sys/bus/iio/devices/triggerX/trigger_polarity_available
> +KernelVersion:	4.11
> +Contact:	fabrice.gasnier at st.com
> +Description:
> +		List all available trigger_polarity settings.
> diff --git a/drivers/iio/adc/stm32-adc.c b/drivers/iio/adc/stm32-adc.c
> index 87d984b..9a38f9a 100644
> --- a/drivers/iio/adc/stm32-adc.c
> +++ b/drivers/iio/adc/stm32-adc.c
> @@ -135,6 +135,7 @@ struct stm32_adc_regs {
>   * @lock:		spinlock
>   * @bufi:		data buffer index
>   * @num_conv:		expected number of scan conversions
> + * @trigger_polarity:	external trigger polarity (e.g. exten)
>   */
>  struct stm32_adc {
>  	struct stm32_adc_common	*common;
> @@ -146,6 +147,7 @@ struct stm32_adc {
>  	spinlock_t		lock;		/* interrupt lock */
>  	unsigned int		bufi;
>  	unsigned int		num_conv;
> +	u32			trigger_polarity;
>  };
>  
>  /**
> @@ -410,7 +412,7 @@ static int stm32_adc_set_trig(struct iio_dev *indio_dev,
>  
>  		/* set trigger source and polarity (default to rising edge) */
>  		extsel = ret;
> -		exten = STM32_EXTEN_HWTRIG_RISING_EDGE;
> +		exten = adc->trigger_polarity + STM32_EXTEN_HWTRIG_RISING_EDGE;
>  	}
>  
>  	spin_lock_irqsave(&adc->lock, flags);
> @@ -424,6 +426,36 @@ 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->trigger_polarity = 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->trigger_polarity;
> +}
> +
> +static const char * const stm32_trig_pol_items[] = {
> +	"rising-edge", "falling-edge", "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
> @@ -682,6 +714,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_polarity", IIO_SHARED_BY_ALL, &stm32_adc_trig_pol),
> +	{
> +		.name = "trigger_polarity_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,
> @@ -697,6 +740,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-28 18:39 UTC|newest]

Thread overview: 16+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-01-26 14:28 [PATCH v2 0/7] Add support for triggered buffer mode to STM32 ADC Fabrice Gasnier
2017-01-26 14:28 ` [PATCH v2 1/7] iio: adc: stm32: add support for triggered buffer mode Fabrice Gasnier
2017-01-28 18:36   ` Jonathan Cameron
2017-01-26 14:28 ` [PATCH v2 2/7] iio: adc: stm32: Enable use of stm32 timer triggers Fabrice Gasnier
2017-01-28 18:37   ` Jonathan Cameron
2017-01-26 14:28 ` [PATCH v2 3/7] iio: adc: stm32: add trigger polarity extended attribute Fabrice Gasnier
2017-01-28 18:39   ` Jonathan Cameron [this message]
2017-01-26 14:28 ` [PATCH v2 4/7] Documentation: dt: iio: stm32-adc: optional dma support Fabrice Gasnier
2017-01-28 18:39   ` Jonathan Cameron
2017-01-26 14:28 ` [PATCH v2 5/7] iio: adc: stm32: add " Fabrice Gasnier
2017-01-28 18:40   ` Jonathan Cameron
2017-01-28 18:41   ` Jonathan Cameron
2017-01-30  8:57     ` Fabrice Gasnier
2017-01-26 14:28 ` [PATCH v2 6/7] ARM: dts: stm32: Enable dma by default on stm32f4 adc Fabrice Gasnier
2017-01-26 14:28 ` [PATCH v2 7/7] ARM: dts: stm32: Enable pwm1 and pwm3 on stm32f429i-eval Fabrice Gasnier
2017-04-03 14:53 ` [PATCH v2 0/7] Add support for triggered buffer mode to STM32 ADC Alexandre Torgue

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=c5be8b19-651e-d5e3-0ccd-af0ae36bc1cb@kernel.org \
    --to=jic23@kernel.org \
    --cc=linux-arm-kernel@lists.infradead.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).