From patchwork Thu Apr 27 13:29:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 98287 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp98660qgf; Thu, 27 Apr 2017 06:29:50 -0700 (PDT) X-Received: by 10.98.76.26 with SMTP id z26mr6095261pfa.14.1493299790390; Thu, 27 Apr 2017 06:29:50 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i63si2654172pfa.404.2017.04.27.06.29.50; Thu, 27 Apr 2017 06:29:50 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1034261AbdD0N3r (ORCPT + 25 others); Thu, 27 Apr 2017 09:29:47 -0400 Received: from mail-wm0-f54.google.com ([74.125.82.54]:33190 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939233AbdD0N3a (ORCPT ); Thu, 27 Apr 2017 09:29:30 -0400 Received: by mail-wm0-f54.google.com with SMTP id i137so5402021wmf.0 for ; Thu, 27 Apr 2017 06:29:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=90A6+vwRwYJc+ruD+36KG+7FrQX8m7U7VOvwDbbgAGw=; b=Fff+qwl83eJ7XCF3T9DgVUbTOgfW07Vxdhf723ksdz+OfjzvYKLgg4egL2xz3Olvp5 XlBcdN1KB3tHIwr+C/U12/Y/hgP+kAHG0pc2f0+t9UUn0LN4hVtx76JvgsqJ0nIdSmuN 4kbaDjfcYPQO0KGbjhux/shbAjab5PYOUPyG0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=90A6+vwRwYJc+ruD+36KG+7FrQX8m7U7VOvwDbbgAGw=; b=iUyzjCzFgoG0OvPVw7AWSGLAbElnnHQCFMLPi/s6oMc9o/cX6j4BuFF372p2f7Z/L6 7Gb4XEzf79FXhGntdQ3zSlzrATuVXyHyGNilLfS0UAZznNEqlS4Du7qdxBjHPhhUlxg7 LiTHwWOZINIZXRucZQWfPw+8zolINPSn3dCNQ1EQ8GOEzzyTXvhxL9EpYdgBzboQTrLG zgMF63l8KY+EVHrOYpv0fHuEb3LLcU+j+TLsHyqzShMCiSqOSmLpvTMvmiCql3IFui0w kc1D6j8PeMjzAfhfWTshHVbS54cecQlntbVBnn1p55aI7EAzJE9hpeio9EoL3hq101yl MG3Q== X-Gm-Message-State: AN3rC/55+EUpSsOq0Vp+WZn6BqlO6xTkpESSKvm6pHhC/4wBM15iVTLl CxrjiZIRFRXYS7lf X-Received: by 10.28.178.17 with SMTP id b17mr2144448wmf.23.1493299768701; Thu, 27 Apr 2017 06:29:28 -0700 (PDT) Received: from lmenx321.st.com. ([80.215.5.151]) by smtp.gmail.com with ESMTPSA id w126sm9182345wmb.25.2017.04.27.06.29.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Apr 2017 06:29:28 -0700 (PDT) From: Benjamin Gaignard X-Google-Original-From: Benjamin Gaignard To: linux-kernel@vger.kernel.org, jic23@kernel.org, linux-iio@vger.kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, vilhelm.gray@gmail.com, mwelling@ieee.org Cc: fabrice.gasnier@st.com, linaro-kernel@lists.linaro.org, benjamin.gaignard@linaro.org, Benjamin Gaignard Subject: [PATCH 1/2] iio: add hardware triggered operating mode Date: Thu, 27 Apr 2017 15:29:15 +0200 Message-Id: <1493299756-18157-2-git-send-email-benjamin.gaignard@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493299756-18157-1-git-send-email-benjamin.gaignard@st.com> References: <1493299756-18157-1-git-send-email-benjamin.gaignard@st.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Devices, like stm32 timer, could be triggered by hardware events which are not buffer or software events. However it could be necessary to validate the triggers like it is done for buffer or event triggered modes. This patch add a new INDIO_HARDWARE_TRIGGERED operating mode for this kind of devices and allow this mode to register trigger consumer. Signed-off-by: Benjamin Gaignard --- drivers/iio/industrialio-core.c | 4 ++-- include/linux/iio/iio.h | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) -- 1.9.1 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c index d18ded4..7872219 100644 --- a/drivers/iio/industrialio-core.c +++ b/drivers/iio/industrialio-core.c @@ -1429,7 +1429,7 @@ static void iio_device_unregister_sysfs(struct iio_dev *indio_dev) static void iio_dev_release(struct device *device) { struct iio_dev *indio_dev = dev_to_iio_dev(device); - if (indio_dev->modes & (INDIO_BUFFER_TRIGGERED | INDIO_EVENT_TRIGGERED)) + if (indio_dev->modes & INDIO_ALL_TRIGGERED_MODES) iio_device_unregister_trigger_consumer(indio_dev); iio_device_unregister_eventset(indio_dev); iio_device_unregister_sysfs(indio_dev); @@ -1711,7 +1711,7 @@ int iio_device_register(struct iio_dev *indio_dev) "Failed to register event set\n"); goto error_free_sysfs; } - if (indio_dev->modes & (INDIO_BUFFER_TRIGGERED | INDIO_EVENT_TRIGGERED)) + if (indio_dev->modes & INDIO_ALL_TRIGGERED_MODES) iio_device_register_trigger_consumer(indio_dev); if ((indio_dev->modes & INDIO_ALL_BUFFER_MODES) && diff --git a/include/linux/iio/iio.h b/include/linux/iio/iio.h index 3f5ea2e..d68bec2 100644 --- a/include/linux/iio/iio.h +++ b/include/linux/iio/iio.h @@ -352,10 +352,16 @@ static inline bool iio_channel_has_available(const struct iio_chan_spec *chan, #define INDIO_BUFFER_SOFTWARE 0x04 #define INDIO_BUFFER_HARDWARE 0x08 #define INDIO_EVENT_TRIGGERED 0x10 +#define INDIO_HARDWARE_TRIGGERED 0x20 #define INDIO_ALL_BUFFER_MODES \ (INDIO_BUFFER_TRIGGERED | INDIO_BUFFER_HARDWARE | INDIO_BUFFER_SOFTWARE) +#define INDIO_ALL_TRIGGERED_MODES \ + (INDIO_BUFFER_TRIGGERED \ + | INDIO_EVENT_TRIGGERED \ + | INDIO_HARDWARE_TRIGGERED) + #define INDIO_MAX_RAW_ELEMENTS 4 struct iio_trigger; /* forward declaration */ From patchwork Thu Apr 27 13:29:16 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 98288 Delivered-To: patch@linaro.org Received: by 10.140.109.52 with SMTP id k49csp98768qgf; Thu, 27 Apr 2017 06:30:05 -0700 (PDT) X-Received: by 10.98.141.16 with SMTP id z16mr6172588pfd.91.1493299805620; Thu, 27 Apr 2017 06:30:05 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 31si2539046ply.314.2017.04.27.06.30.05; Thu, 27 Apr 2017 06:30:05 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1162441AbdD0N34 (ORCPT + 25 others); Thu, 27 Apr 2017 09:29:56 -0400 Received: from mail-wm0-f50.google.com ([74.125.82.50]:36739 "EHLO mail-wm0-f50.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S939238AbdD0N3c (ORCPT ); Thu, 27 Apr 2017 09:29:32 -0400 Received: by mail-wm0-f50.google.com with SMTP id u65so16844611wmu.1 for ; Thu, 27 Apr 2017 06:29:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=X39tKK5S16oF88gL+zdhDFdIXziCftzDPjENCG9x3Hs=; b=FCTE6JxBsJ/3StzbK+tjUhtQCxOKfAEQBhFVZYW4sz8P8Etczb62dZOK48nSRAzSMn /6dxza3YndbGFzLKqVKhL+ya30mTKAWNWBcvLWksMHe54LszfVCk77UXJE53G9r03m62 CmV4MQFPN7NNJZ+piGzB0ON/hAQGgHnH+ZQEs= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=X39tKK5S16oF88gL+zdhDFdIXziCftzDPjENCG9x3Hs=; b=STIbe2a2Ws8TvmKASodTGe1Ik8FVPI3T2idVOypWVtUVH7Xh4sFGj5h7q794HvLYpD RQOLsxnVhLa3zGSht4Kw5RxSaSMaOOnk5euQ/QBlUzdp/WbwohXrZyGpXfPMPUQnpdAc flsEzt3lcDfTzKBWKKj4FHaKf7PcX0zevKFi3/T5c8nYXfkWDoFrsyfA2FS8bJT6TRpJ C3N8yOj6r0FgLZWTBvaAcAE9YrbrfQiGq/NFgBfxk2W8a4GjpbQtMinNbjqtUXzIdiRj Pu0sR1ZWkfZs+v21KyRA5GXNoZ34Kgqnif9ZVp0TwwVTKkOHaW2iGOcwCukXOvx+JCgX 7rcA== X-Gm-Message-State: AN3rC/71F3RTb3LThn0aM+L/TpX9svwP+coUoaQNXvLHQxT5IqPdKJL/ 2xCzjuBAWjT3ua0Z X-Received: by 10.28.95.85 with SMTP id t82mr2359598wmb.3.1493299770416; Thu, 27 Apr 2017 06:29:30 -0700 (PDT) Received: from lmenx321.st.com. ([80.215.5.151]) by smtp.gmail.com with ESMTPSA id w126sm9182345wmb.25.2017.04.27.06.29.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 27 Apr 2017 06:29:29 -0700 (PDT) From: Benjamin Gaignard X-Google-Original-From: Benjamin Gaignard To: linux-kernel@vger.kernel.org, jic23@kernel.org, linux-iio@vger.kernel.org, knaack.h@gmx.de, lars@metafoo.de, pmeerw@pmeerw.net, vilhelm.gray@gmail.com, mwelling@ieee.org Cc: fabrice.gasnier@st.com, linaro-kernel@lists.linaro.org, benjamin.gaignard@linaro.org, Benjamin Gaignard Subject: [PATCH 2/2] iio: make stm32 trigger driver use INDIO_HARDWARE_TRIGGERED mode Date: Thu, 27 Apr 2017 15:29:16 +0200 Message-Id: <1493299756-18157-3-git-send-email-benjamin.gaignard@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1493299756-18157-1-git-send-email-benjamin.gaignard@st.com> References: <1493299756-18157-1-git-send-email-benjamin.gaignard@st.com> Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Add validate function to be use to use the correct trigger. Add an attribute to configure device mode like for quadrature and enable modes Signed-off-by: Benjamin Gaignard --- .../ABI/testing/sysfs-bus-iio-timer-stm32 | 15 ++++++ drivers/iio/trigger/stm32-timer-trigger.c | 61 ++++++++++++++++++++++ 2 files changed, 76 insertions(+) -- 1.9.1 diff --git a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 index 230020e..cccdf57 100644 --- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 +++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 @@ -90,3 +90,18 @@ Description: Counting is enabled on rising edge of the connected trigger, and remains enabled for the duration of this selected mode. + +What: /sys/bus/iio/devices/iio:deviceX/in_count_trigger_mode_available +KernelVersion: 4.13 +Contact: benjamin.gaignard@st.com +Description: + Reading returns the list possible trigger modes. + +What: /sys/bus/iio/devices/iio:deviceX/in_count0_trigger_mode +KernelVersion: 4.13 +Contact: benjamin.gaignard@st.com +Description: + Configure the device counter trigger mode + counting direction is set by in_count0_count_direction + attribute and the counter is clocked by the connected trigger + rising edges. diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c index 0f1a2cf..7c6e90e 100644 --- a/drivers/iio/trigger/stm32-timer-trigger.c +++ b/drivers/iio/trigger/stm32-timer-trigger.c @@ -347,12 +347,70 @@ static int stm32_counter_write_raw(struct iio_dev *indio_dev, return -EINVAL; } +static int stm32_counter_validate_trigger(struct iio_dev *indio_dev, + struct iio_trigger *trig) +{ + struct stm32_timer_trigger *priv = iio_priv(indio_dev); + const char * const *cur = priv->valids; + unsigned int i = 0; + + if (!is_stm32_timer_trigger(trig)) + return -EINVAL; + + while (cur && *cur) { + if (!strncmp(trig->name, *cur, strlen(trig->name))) { + regmap_update_bits(priv->regmap, + TIM_SMCR, TIM_SMCR_TS, + i << TIM_SMCR_TS_SHIFT); + return 0; + } + cur++; + i++; + } + + return -EINVAL; +} + static const struct iio_info stm32_trigger_info = { .driver_module = THIS_MODULE, + .validate_trigger = stm32_counter_validate_trigger, .read_raw = stm32_counter_read_raw, .write_raw = stm32_counter_write_raw }; +static const char *const stm32_trigger_modes[] = { + "trigger", +}; + +static int stm32_set_trigger_mode(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + unsigned int mode) +{ + struct stm32_timer_trigger *priv = iio_priv(indio_dev); + + regmap_update_bits(priv->regmap, TIM_SMCR, TIM_SMCR_SMS, TIM_SMCR_SMS); + + return 0; +} + +static int stm32_get_trigger_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); + + return smcr == TIM_SMCR_SMS ? 0 : -EINVAL; +} + +static const struct iio_enum stm32_trigger_mode_enum = { + .items = stm32_trigger_modes, + .num_items = ARRAY_SIZE(stm32_trigger_modes), + .set = stm32_set_trigger_mode, + .get = stm32_get_trigger_mode +}; + static const char *const stm32_enable_modes[] = { "always", "gated", @@ -536,6 +594,8 @@ static ssize_t stm32_count_set_preset(struct iio_dev *indio_dev, 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), + IIO_ENUM("trigger_mode", IIO_SEPARATE, &stm32_trigger_mode_enum), + IIO_ENUM_AVAILABLE("trigger_mode", &stm32_trigger_mode_enum), {} }; @@ -560,6 +620,7 @@ static struct stm32_timer_trigger *stm32_setup_counter_device(struct device *dev indio_dev->name = dev_name(dev); indio_dev->dev.parent = dev; indio_dev->info = &stm32_trigger_info; + indio_dev->modes = INDIO_HARDWARE_TRIGGERED; indio_dev->num_channels = 1; indio_dev->channels = &stm32_trigger_channel; indio_dev->dev.of_node = dev->of_node;