Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753158AbdDHR3r (ORCPT ); Sat, 8 Apr 2017 13:29:47 -0400 Received: from saturn.retrosnub.co.uk ([178.18.118.26]:38581 "EHLO saturn.retrosnub.co.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752066AbdDHR2G (ORCPT ); Sat, 8 Apr 2017 13:28:06 -0400 Subject: Re: [PATCH v4 2/2] iio: stm32 trigger: Add counter enable modes To: Benjamin Gaignard , linux-kernel@vger.kernel.org, linux-iio@vger.kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, vilhelm.gray@gmail.com, mwelling@ieee.org References: <1491292072-8535-1-git-send-email-benjamin.gaignard@st.com> <1491292072-8535-3-git-send-email-benjamin.gaignard@st.com> Cc: fabrice.gasnier@st.com, linaro-kernel@lists.linaro.org, Benjamin Gaignard From: Jonathan Cameron Message-ID: Date: Sat, 8 Apr 2017 18:28:04 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <1491292072-8535-3-git-send-email-benjamin.gaignard@st.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 4212 Lines: 142 On 04/04/17 08:47, Benjamin Gaignard wrote: > Device counting could be controlled by the level or the edges of > a trigger. > in_count0_enable_mode attibute allow to set the control mode. > > Signed-off-by: Benjamin Gaignard Applied to the togreg branch of iio.git and pushed out as testing for the autobuilders to play with it. Thanks, Jonathan > --- > version 4: > - reword triggered description > > .../ABI/testing/sysfs-bus-iio-timer-stm32 | 25 ++++++++ > drivers/iio/trigger/stm32-timer-trigger.c | 70 ++++++++++++++++++++++ > 2 files changed, 95 insertions(+) > > diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 > index a55ad44..230020e 100644 > --- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 > +++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 > @@ -65,3 +65,28 @@ Description: > quadrature: > Encoder A and B inputs are mixed to get direction > and count with a scale of 0.25. > + > +What: /sys/bus/iio/devices/iio:deviceX/in_count_enable_mode_available > +KernelVersion: 4.12 > +Contact: benjamin.gaignard@st.com > +Description: > + Reading returns the list possible enable modes. > + > +What: /sys/bus/iio/devices/iio:deviceX/in_count0_enable_mode > +KernelVersion: 4.12 > +Contact: benjamin.gaignard@st.com > +Description: > + Configure the device counter enable modes, in all case > + counting direction is set by in_count0_count_direction > + attribute and the counter is clocked by the internal clock. > + always: > + Counter is always ON. > + > + gated: > + Counting is enabled when connected trigger signal > + level is high else counting is disabled. > + > + triggered: > + Counting is enabled on rising edge of the connected > + trigger, and remains enabled for the duration of this > + selected mode. > diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c > index 7db904c..0f1a2cf 100644 > --- a/drivers/iio/trigger/stm32-timer-trigger.c > +++ b/drivers/iio/trigger/stm32-timer-trigger.c > @@ -353,6 +353,74 @@ static int stm32_counter_write_raw(struct iio_dev *indio_dev, > .write_raw = stm32_counter_write_raw > }; > > +static const char *const stm32_enable_modes[] = { > + "always", > + "gated", > + "triggered", > +}; > + > +static int stm32_enable_mode2sms(int mode) > +{ > + switch (mode) { > + case 0: > + return 0; > + case 1: > + return 5; > + case 2: > + return 6; > + } > + > + return -EINVAL; > +} > + > +static int stm32_set_enable_mode(struct iio_dev *indio_dev, > + const struct iio_chan_spec *chan, > + unsigned int mode) > +{ > + struct stm32_timer_trigger *priv = iio_priv(indio_dev); > + int sms = stm32_enable_mode2sms(mode); > + > + if (sms < 0) > + return sms; > + > + regmap_update_bits(priv->regmap, TIM_SMCR, TIM_SMCR_SMS, sms); > + > + return 0; > +} > + > +static int stm32_sms2enable_mode(int mode) > +{ > + switch (mode) { > + case 0: > + return 0; > + case 5: > + return 1; > + case 6: > + return 2; > + } > + > + return -EINVAL; > +} > + > +static int stm32_get_enable_mode(struct iio_dev *indio_dev, > + const struct iio_chan_spec *chan) > +{ > + struct stm32_timer_trigger *priv = iio_priv(indio_dev); > + u32 smcr; > + > + regmap_read(priv->regmap, TIM_SMCR, &smcr); > + smcr &= TIM_SMCR_SMS; > + > + return stm32_sms2enable_mode(smcr); > +} > + > +static const struct iio_enum stm32_enable_mode_enum = { > + .items = stm32_enable_modes, > + .num_items = ARRAY_SIZE(stm32_enable_modes), > + .set = stm32_set_enable_mode, > + .get = stm32_get_enable_mode > +}; > + > static const char *const stm32_quadrature_modes[] = { > "channel_A", > "channel_B", > @@ -466,6 +534,8 @@ static ssize_t stm32_count_set_preset(struct iio_dev *indio_dev, > IIO_ENUM_AVAILABLE("count_direction", &stm32_count_direction_enum), > IIO_ENUM("quadrature_mode", IIO_SEPARATE, &stm32_quadrature_mode_enum), > IIO_ENUM_AVAILABLE("quadrature_mode", &stm32_quadrature_mode_enum), > + IIO_ENUM("enable_mode", IIO_SEPARATE, &stm32_enable_mode_enum), > + IIO_ENUM_AVAILABLE("enable_mode", &stm32_enable_mode_enum), > {} > }; > >