From patchwork Fri Mar 24 14:00:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 95942 Delivered-To: patch@linaro.org Received: by 10.140.89.233 with SMTP id v96csp60074qgd; Fri, 24 Mar 2017 07:02:41 -0700 (PDT) X-Received: by 10.84.215.23 with SMTP id k23mr10840398pli.58.1490364161476; Fri, 24 Mar 2017 07:02:41 -0700 (PDT) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id i1si2991983pgn.203.2017.03.24.07.02.41; Fri, 24 Mar 2017 07:02:41 -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 S934925AbdCXOCU (ORCPT + 18 others); Fri, 24 Mar 2017 10:02:20 -0400 Received: from mail-wr0-f176.google.com ([209.85.128.176]:36690 "EHLO mail-wr0-f176.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756927AbdCXOBy (ORCPT ); Fri, 24 Mar 2017 10:01:54 -0400 Received: by mail-wr0-f176.google.com with SMTP id u108so2333460wrb.3 for ; Fri, 24 Mar 2017 07:01:53 -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=l7f7yCzamgwICo0PC1Ct93LWHv6+rO911xdA2T6g1Y8=; b=TRgL1BUiD9wMYc2yCsyF5sy00I+fooxfPYzXjy+jLz8Wt01uPFtfutpLRFoxLc9qJ2 OAJvZosFbkGXql6rNxyM/UNZpwkpZXgUmFILPef17UkgabQ9u/cZhcPsAO0ZPRzVUkUQ g/slhv2lE41Av9qbLGc3rClZRDVgc/PTJWwno= 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=l7f7yCzamgwICo0PC1Ct93LWHv6+rO911xdA2T6g1Y8=; b=dL30DbAjUAfhQZ1Ci8WrM9ZZ8kqPE3e3sSyiKu20Uq9jmJV0oFpAPKfs/rl+zqaEME /wKWED/RUM9UIjoQYZxolTflXFo9vTHKRPd6C5ipp0QOqeOn+xmp4AJ+vifcWwPIznn2 IoWlO27zrqsuZ269/LuXdmrOVSwTby9cu9BNTE7T7+NCW/vmEqrkZd5E1dzvB7lIkNHW vnH9w6r4Jhk7Emq7IhJW+jdOiYefepqwcdFelnof3dsbdc0e8KlY/D55tkhrd1kk1N70 bqT3VG2MkwCIrJHO/8tGJnHgGqScK79Vryhl7t2m5WpI/35Z/IWq4iZYeSm1bm9k3eXZ I4Bw== X-Gm-Message-State: AFeK/H0EwTahvVt/+YvlaImmbNaK1tyQgjwUoMD/9C0adEDVAWhguzOwoeNNKL1nfnY6iYou X-Received: by 10.223.164.85 with SMTP id e21mr7957456wra.58.1490364107256; Fri, 24 Mar 2017 07:01:47 -0700 (PDT) Received: from lmenx321.st.com. ([80.214.123.217]) by smtp.gmail.com with ESMTPSA id o22sm3026896wro.13.2017.03.24.07.01.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Mar 2017 07:01:46 -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 Cc: fabrice.gasnier@st.com, linaro-kernel@lists.linaro.org, benjamin.gaignard@linaro.org, Benjamin Gaignard Subject: [PATCH v2 2/2] iio: stm32 trigger: Add counter enable modes Date: Fri, 24 Mar 2017 15:00:43 +0100 Message-Id: <1490364043-16339-3-git-send-email-benjamin.gaignard@st.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1490364043-16339-1-git-send-email-benjamin.gaignard@st.com> References: <1490364043-16339-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 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 --- .../ABI/testing/sysfs-bus-iio-timer-stm32 | 23 +++++++ drivers/iio/trigger/stm32-timer-trigger.c | 70 ++++++++++++++++++++++ 2 files changed, 93 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 fbdee4f..1886f2c 100644 --- a/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 +++ b/Documentation/ABI/testing/sysfs-bus-iio-timer-stm32 @@ -59,3 +59,26 @@ 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 start on rising edge of the connected trigger. diff --git a/drivers/iio/trigger/stm32-timer-trigger.c b/drivers/iio/trigger/stm32-timer-trigger.c index 48d2bf9..8a87810 100644 --- a/drivers/iio/trigger/stm32-timer-trigger.c +++ b/drivers/iio/trigger/stm32-timer-trigger.c @@ -353,6 +353,74 @@ static int stm32_trigger_write_raw(struct iio_dev *indio_dev, .write_raw = stm32_trigger_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), {} };