From patchwork Mon Feb 18 14:03:14 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Havelange X-Patchwork-Id: 10818121 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 227B01399 for ; Mon, 18 Feb 2019 14:25:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 11C592A06E for ; Mon, 18 Feb 2019 14:25:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 037A72ADD8; Mon, 18 Feb 2019 14:25:03 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 840E42ADC7 for ; Mon, 18 Feb 2019 14:25:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389154AbfBROZB (ORCPT ); Mon, 18 Feb 2019 09:25:01 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:43470 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389746AbfBRODu (ORCPT ); Mon, 18 Feb 2019 09:03:50 -0500 Received: by mail-ed1-f66.google.com with SMTP id m35so9950449ede.10 for ; Mon, 18 Feb 2019 06:03:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=essensium-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id; bh=C7LfhrPnx4nAAVgxwo9NlyGkJiC6uZjQ0aP5k7jZulQ=; b=IsB2vKUQ0fFFZ3Si03pp+C3YnEwIGfiap8SKOQSLsqp4xuu3XfOVwg7fS4wRCKDkQE OLbC93ZPgfinbdENjBY13fGRfsVOXYmWZMIvCSNjAjwJ/sXxaUa5ojgt9KK1UuKQYO8h J79qQcugI6ovrMgtNAZEgOiapw8Y/bCxMzOhI3luA6lQt1ihP1n13m1SxJ1g3sNASLa8 nsBt5b9wjpatlE8nuWNvOSCk+Yk6MQptaJ6/19HWYHgNZOYJDLjOAzmo2BDsVnCRx2nR y0XD07OFkIXEAJU15ujUJyhmbdp7FEDw9YapXo1H/XWzsEPNetMGdGgJmzijzH0lqEKK igpQ== 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; bh=C7LfhrPnx4nAAVgxwo9NlyGkJiC6uZjQ0aP5k7jZulQ=; b=N2+trZ3Uj+M0ZA6HgWHnH5upN8Nv5R5cwPpYRUPXwU0U6u1XKTMsp5NfUyekRyK7cp 0JsUh8v7uXz47nl9m7rX3eu0SSqGmz+GWd3SNF0PmqRbOq5UJilbd302XOgBqk04SjN3 9VrOb/jsd1ZklJV60ve0PCkvzUwJEp94DwkQvvvZtR7nhLlDZmLQlfL740Hoe1Tfksil 1bU5sbhhJsdZJgVmOA5WJIaG4SfrI6uLk75/bJJ8mUgnwl5j9FnLcZrnv4Ck0RPk0ACo Qb7kEUykJkIudJvzIT69SpzdevdXZavyrW+eZBMJ8JAwHE3Qi+/zqci9Ba59mgEZEHkD 23Nw== X-Gm-Message-State: AHQUAubIPE9EH7LVWWzMJKz2q5d0AgK3HwzHCOMsyP2g8k4udYhOleT+ kWlOwXtW1nFlU36dOc6NQu0y8g== X-Google-Smtp-Source: AHgI3Ia0x1ktlXNUOXQ9qmej4UWt8bjITH2AKcym466NvP3q2IEYPeYewvhp2d01vHGZ6OHrFmkucQ== X-Received: by 2002:a17:906:381:: with SMTP id b1mr16659937eja.67.1550498627933; Mon, 18 Feb 2019 06:03:47 -0800 (PST) Received: from localhost.localdomain (ip-188-118-3-185.reverse.destiny.be. [188.118.3.185]) by smtp.gmail.com with ESMTPSA id w48sm1421606eda.88.2019.02.18.06.03.46 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 06:03:47 -0800 (PST) From: Patrick Havelange To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Mark Rutland , Shawn Guo , Li Yang , Daniel Lezcano , Thomas Gleixner , Thierry Reding , Esben Haabendal , William Breathitt Gray , Linus Walleij , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Patrick Havelange Subject: [PATCH 1/8] include/fsl: add common FlexTimer #defines in a separate header. Date: Mon, 18 Feb 2019 15:03:14 +0100 Message-Id: <20190218140321.19166-1-patrick.havelange@essensium.com> X-Mailer: git-send-email 2.17.1 Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Patrick Havelange Reviewed-by: Esben Haabendal --- include/linux/fsl/ftm.h | 88 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) create mode 100644 include/linux/fsl/ftm.h diff --git a/include/linux/fsl/ftm.h b/include/linux/fsl/ftm.h new file mode 100644 index 000000000000..d59011acf66c --- /dev/null +++ b/include/linux/fsl/ftm.h @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0 +#ifndef __FSL_FTM_H__ +#define __FSL_FTM_H__ + +#define FTM_SC 0x0 /* Status And Control */ +#define FTM_CNT 0x4 /* Counter */ +#define FTM_MOD 0x8 /* Modulo */ + +#define FTM_CNTIN 0x4C /* Counter Initial Value */ +#define FTM_STATUS 0x50 /* Capture And Compare Status */ +#define FTM_MODE 0x54 /* Features Mode Selection */ +#define FTM_SYNC 0x58 /* Synchronization */ +#define FTM_OUTINIT 0x5C /* Initial State For Channels Output */ +#define FTM_OUTMASK 0x60 /* Output Mask */ +#define FTM_COMBINE 0x64 /* Function For Linked Channels */ +#define FTM_DEADTIME 0x68 /* Deadtime Insertion Control */ +#define FTM_EXTTRIG 0x6C /* FTM External Trigger */ +#define FTM_POL 0x70 /* Channels Polarity */ +#define FTM_FMS 0x74 /* Fault Mode Status */ +#define FTM_FILTER 0x78 /* Input Capture Filter Control */ +#define FTM_FLTCTRL 0x7C /* Fault Control */ +#define FTM_QDCTRL 0x80 /* Quadrature Decoder Control And Status */ +#define FTM_CONF 0x84 /* Configuration */ +#define FTM_FLTPOL 0x88 /* FTM Fault Input Polarity */ +#define FTM_SYNCONF 0x8C /* Synchronization Configuration */ +#define FTM_INVCTRL 0x90 /* FTM Inverting Control */ +#define FTM_SWOCTRL 0x94 /* FTM Software Output Control */ +#define FTM_PWMLOAD 0x98 /* FTM PWM Load */ + +#define FTM_SC_CLK_MASK_SHIFT 3 +#define FTM_SC_CLK_MASK (3 << FTM_SC_CLK_MASK_SHIFT) +#define FTM_SC_TOF 0x80 +#define FTM_SC_TOIE 0x40 +#define FTM_SC_CPWMS 0x20 +#define FTM_SC_CLKS 0x18 +#define FTM_SC_PS_1 0x0 +#define FTM_SC_PS_2 0x1 +#define FTM_SC_PS_4 0x2 +#define FTM_SC_PS_8 0x3 +#define FTM_SC_PS_16 0x4 +#define FTM_SC_PS_32 0x5 +#define FTM_SC_PS_64 0x6 +#define FTM_SC_PS_128 0x7 +#define FTM_SC_PS_MASK 0x7 + +#define FTM_MODE_FAULTIE 0x80 +#define FTM_MODE_FAULTM 0x60 +#define FTM_MODE_CAPTEST 0x10 +#define FTM_MODE_PWMSYNC 0x8 +#define FTM_MODE_WPDIS 0x4 +#define FTM_MODE_INIT 0x2 +#define FTM_MODE_FTMEN 0x1 + +/* NXP Errata: The PHAFLTREN and PHBFLTREN bits are tide to zero internally + * and these bits cannot be set. Flextimer cannot use Filter in + * Quadrature Decoder Mode. + * https://community.nxp.com/thread/467648#comment-1010319 + */ +#define FTM_QDCTRL_PHAFLTREN 0x80 +#define FTM_QDCTRL_PHBFLTREN 0x40 +#define FTM_QDCTRL_PHAPOL 0x20 +#define FTM_QDCTRL_PHBPOL 0x10 +#define FTM_QDCTRL_QUADMODE 0x8 +#define FTM_QDCTRL_QUADDIR 0x4 +#define FTM_QDCTRL_TOFDIR 0x2 +#define FTM_QDCTRL_QUADEN 0x1 + +#define FTM_FMS_FAULTF 0x80 +#define FTM_FMS_WPEN 0x40 +#define FTM_FMS_FAULTIN 0x10 +#define FTM_FMS_FAULTF3 0x8 +#define FTM_FMS_FAULTF2 0x4 +#define FTM_FMS_FAULTF1 0x2 +#define FTM_FMS_FAULTF0 0x1 + +#define FTM_CSC_BASE 0xC +#define FTM_CSC_MSB 0x20 +#define FTM_CSC_MSA 0x10 +#define FTM_CSC_ELSB 0x8 +#define FTM_CSC_ELSA 0x4 +#define FTM_CSC(_channel) (FTM_CSC_BASE + ((_channel) * 8)) + +#define FTM_CV_BASE 0x10 +#define FTM_CV(_channel) (FTM_CV_BASE + ((_channel) * 8)) + +#define FTM_PS_MAX 7 + +#endif From patchwork Mon Feb 18 14:03:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Havelange X-Patchwork-Id: 10818119 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 9093B1575 for ; Mon, 18 Feb 2019 14:25:02 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7C3D129FA1 for ; Mon, 18 Feb 2019 14:25:02 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6B04F2A06E; Mon, 18 Feb 2019 14:25:02 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B9752A049 for ; Mon, 18 Feb 2019 14:25:02 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389766AbfBROZB (ORCPT ); Mon, 18 Feb 2019 09:25:01 -0500 Received: from mail-ed1-f68.google.com ([209.85.208.68]:32769 "EHLO mail-ed1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389154AbfBRODu (ORCPT ); Mon, 18 Feb 2019 09:03:50 -0500 Received: by mail-ed1-f68.google.com with SMTP id a2so13947236edi.0 for ; Mon, 18 Feb 2019 06:03:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=essensium-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=yRbFDaxWpy1WZcEaSiXFGy4r6+XphTOi/wCgftAJFLc=; b=r986BO1Bzxok2V8E1eD37WYjzK2SBEteAVMs6PJ+GyfPBhlMmSQusvvsx60zQIua0j HEtFc2Cbjy57gwxNqqBkJTEfiend4iuH9mrGHHfaPOHdhozsGK7yXfjWIX5pNCwVJfzf Hi7DRrqfs8UCedwzmElcbeS4l2np34oQ+BmVxFRzAKISQbXvMikWdJV9/RWIbEHMnp8t B7CuoCwlSNrRceunX/D+BNQP/vorwExi5Q3k3KPWa29v4DiDhCkN4xsC777AFI8ZwwZc VzHmLw2/DQxlDztf1WTkxkdvMn9z8ND9aIuIVSjPg6LbZqJVTe885POnip9mNLyZWwYu I2Dw== 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=yRbFDaxWpy1WZcEaSiXFGy4r6+XphTOi/wCgftAJFLc=; b=aj00xY6K50sjnld2+ynjcQiurOJxZ60lAAJr/tK77KnKsA/AVjG6d5Rb//u0cAoCHe VTR7cW/bQxNkf4rc0hd6ysog7l0w78WqaIaDwIdbHR63NF22EGl4CqNeJzARahzAP3tD nfBz8K8h7nhQ6Ho+sfGkz+EnaeXjvKUoT+Rf+xsZIWEXKiPMLvtdppQHTdsDubbXEZfG G0KORL/F5eJz9X8xSPSGQ3rMPD+4IZ/XvtY7i5uVH1BjE3GA06z/Yq902COYIUW5xYey zXPUyIKul/7NKC0a2WzewXroGyYkp1K6gwtEjszTn8T6sQ4zYizHXNGsE2XgCQRF/qBa 9sbQ== X-Gm-Message-State: AHQUAubAk5ENGoeSmSk2yqYim+tVZVxlfsq+++W17Rop/OK6n/uqc9QY v/OMTW8OnosRrb76+4NyDftoqg== X-Google-Smtp-Source: AHgI3IYj7ckxoDKJl3E4bX/rvyXEihO7cEuEYlmgZecPBrtn60bN0Tp19Cvro+2kMS5QDOx/dl2T5Q== X-Received: by 2002:a50:b527:: with SMTP id y36mr19649567edd.83.1550498629140; Mon, 18 Feb 2019 06:03:49 -0800 (PST) Received: from localhost.localdomain (ip-188-118-3-185.reverse.destiny.be. [188.118.3.185]) by smtp.gmail.com with ESMTPSA id w48sm1421606eda.88.2019.02.18.06.03.47 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 06:03:48 -0800 (PST) From: Patrick Havelange To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Mark Rutland , Shawn Guo , Li Yang , Daniel Lezcano , Thomas Gleixner , Thierry Reding , Esben Haabendal , William Breathitt Gray , Linus Walleij , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Patrick Havelange Subject: [PATCH 2/8] drivers/pwm: pwm-fsl-ftm: use common header for FlexTimer #defines Date: Mon, 18 Feb 2019 15:03:15 +0100 Message-Id: <20190218140321.19166-2-patrick.havelange@essensium.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190218140321.19166-1-patrick.havelange@essensium.com> References: <20190218140321.19166-1-patrick.havelange@essensium.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This also fixes the wrong value for the previously defined FTM_MODE_INIT macro (it was not used). Signed-off-by: Patrick Havelange Reviewed-by: Esben Haabendal --- drivers/pwm/pwm-fsl-ftm.c | 44 +-------------------------------------- 1 file changed, 1 insertion(+), 43 deletions(-) diff --git a/drivers/pwm/pwm-fsl-ftm.c b/drivers/pwm/pwm-fsl-ftm.c index 883378d055c6..f21ea1b97116 100644 --- a/drivers/pwm/pwm-fsl-ftm.c +++ b/drivers/pwm/pwm-fsl-ftm.c @@ -22,51 +22,9 @@ #include #include #include +#include -#define FTM_SC 0x00 -#define FTM_SC_CLK_MASK_SHIFT 3 -#define FTM_SC_CLK_MASK (3 << FTM_SC_CLK_MASK_SHIFT) #define FTM_SC_CLK(c) (((c) + 1) << FTM_SC_CLK_MASK_SHIFT) -#define FTM_SC_PS_MASK 0x7 - -#define FTM_CNT 0x04 -#define FTM_MOD 0x08 - -#define FTM_CSC_BASE 0x0C -#define FTM_CSC_MSB BIT(5) -#define FTM_CSC_MSA BIT(4) -#define FTM_CSC_ELSB BIT(3) -#define FTM_CSC_ELSA BIT(2) -#define FTM_CSC(_channel) (FTM_CSC_BASE + ((_channel) * 8)) - -#define FTM_CV_BASE 0x10 -#define FTM_CV(_channel) (FTM_CV_BASE + ((_channel) * 8)) - -#define FTM_CNTIN 0x4C -#define FTM_STATUS 0x50 - -#define FTM_MODE 0x54 -#define FTM_MODE_FTMEN BIT(0) -#define FTM_MODE_INIT BIT(2) -#define FTM_MODE_PWMSYNC BIT(3) - -#define FTM_SYNC 0x58 -#define FTM_OUTINIT 0x5C -#define FTM_OUTMASK 0x60 -#define FTM_COMBINE 0x64 -#define FTM_DEADTIME 0x68 -#define FTM_EXTTRIG 0x6C -#define FTM_POL 0x70 -#define FTM_FMS 0x74 -#define FTM_FILTER 0x78 -#define FTM_FLTCTRL 0x7C -#define FTM_QDCTRL 0x80 -#define FTM_CONF 0x84 -#define FTM_FLTPOL 0x88 -#define FTM_SYNCONF 0x8C -#define FTM_INVCTRL 0x90 -#define FTM_SWOCTRL 0x94 -#define FTM_PWMLOAD 0x98 enum fsl_pwm_clk { FSL_PWM_CLK_SYS, From patchwork Mon Feb 18 14:03:16 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Havelange X-Patchwork-Id: 10818117 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 308F51575 for ; Mon, 18 Feb 2019 14:24:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1D8FC29BE1 for ; Mon, 18 Feb 2019 14:24:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 119752A049; Mon, 18 Feb 2019 14:24:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B340D29BE1 for ; Mon, 18 Feb 2019 14:24:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389726AbfBRODx (ORCPT ); Mon, 18 Feb 2019 09:03:53 -0500 Received: from mail-ed1-f67.google.com ([209.85.208.67]:32771 "EHLO mail-ed1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389759AbfBRODw (ORCPT ); Mon, 18 Feb 2019 09:03:52 -0500 Received: by mail-ed1-f67.google.com with SMTP id a2so13947289edi.0 for ; Mon, 18 Feb 2019 06:03:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=essensium-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=kDOvI7KHRas/e++nV1MAoAVesXibxebovw6lFI3t2LQ=; b=lPdVLPONMX15tVFEdOGTWdO0qWE/4jq/BAze0ALMLuA0nMhYdTscqDSDouBdQJMKI+ 9P9j1Oo5wGvSlAFqwJ5MbsxrTSd68gxajlZug9ZW4tzsNll+n461GjbggeOeqUQpgDm7 W1pyYQRMbpuwsNn1TXoxIgHxqzMBLkEm6z/Mm2OFJDHKy3mdBVweK2p66YcDrrpeiyKy popuvplA8CMeHuToUOieTP7qkuHWUthsRGN5rVdQwprYyfywzPhUboAT3lTaCfKDFUXD GZCmTGPgJsVS9ZBLdp8t6SAGMuf9SNrpjtxDkSgWKiN8DRRDgz3mzZ/37doMnbxznzr/ OTcQ== 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=kDOvI7KHRas/e++nV1MAoAVesXibxebovw6lFI3t2LQ=; b=IDZdy40S+oJq4dhQN/HOxuAz0l5NIfjsHwhJxhJge2LAMD+dVLllavStEOgYXYVOHY tZGfAGpW9rPDZxJH8WKHLhxgc/R++NHru03mfVERiJMbCY+E2WOTwM7navT+llJomslS jfTjvZqTtRW7JyzHlLwm8zZO5bd6OvgHgDRTLAea5TaOTYQzyypdtR9G+ivKkLqiJtS4 rZfKmXDDyeX2y647xKqPxopiPtuduq9IidJNTQuUzBhhMiAU7ZbE45gZzCk4If5j8RSD MP0BC/CviuB6n+L71BJZpouFxvS8Si4qQG737HxBVMkLGrauRh/X3bz2yiZxJIUIT97s 53aQ== X-Gm-Message-State: AHQUAuayCWlfX4VGAvWUQ4Ijkbj23hc4z/MB7vZfxW0q2dhYTa8kA9t9 cmtv6mlYAowEVG0FGwk5NZUFHg== X-Google-Smtp-Source: AHgI3IZ8OLgKjAeX/g4O2478yycvuHIzPgfc0uD5abEOkLT1aY3Iky8/UzyD7nuf/AReqmoOjyDzEw== X-Received: by 2002:a17:906:791:: with SMTP id l17mr13001446ejc.1.1550498630266; Mon, 18 Feb 2019 06:03:50 -0800 (PST) Received: from localhost.localdomain (ip-188-118-3-185.reverse.destiny.be. [188.118.3.185]) by smtp.gmail.com with ESMTPSA id w48sm1421606eda.88.2019.02.18.06.03.49 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 06:03:49 -0800 (PST) From: Patrick Havelange To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Mark Rutland , Shawn Guo , Li Yang , Daniel Lezcano , Thomas Gleixner , Thierry Reding , Esben Haabendal , William Breathitt Gray , Linus Walleij , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Patrick Havelange Subject: [PATCH 3/8] drivers/clocksource: timer-fsl-ftm: use common header for FlexTimer #defines Date: Mon, 18 Feb 2019 15:03:16 +0100 Message-Id: <20190218140321.19166-3-patrick.havelange@essensium.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190218140321.19166-1-patrick.havelange@essensium.com> References: <20190218140321.19166-1-patrick.havelange@essensium.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Signed-off-by: Patrick Havelange Reviewed-by: Esben Haabendal --- drivers/clocksource/timer-fsl-ftm.c | 15 ++------------- 1 file changed, 2 insertions(+), 13 deletions(-) diff --git a/drivers/clocksource/timer-fsl-ftm.c b/drivers/clocksource/timer-fsl-ftm.c index 846d18daf893..e1c34b2f53a5 100644 --- a/drivers/clocksource/timer-fsl-ftm.c +++ b/drivers/clocksource/timer-fsl-ftm.c @@ -19,20 +19,9 @@ #include #include #include +#include -#define FTM_SC 0x00 -#define FTM_SC_CLK_SHIFT 3 -#define FTM_SC_CLK_MASK (0x3 << FTM_SC_CLK_SHIFT) -#define FTM_SC_CLK(c) ((c) << FTM_SC_CLK_SHIFT) -#define FTM_SC_PS_MASK 0x7 -#define FTM_SC_TOIE BIT(6) -#define FTM_SC_TOF BIT(7) - -#define FTM_CNT 0x04 -#define FTM_MOD 0x08 -#define FTM_CNTIN 0x4C - -#define FTM_PS_MAX 7 +#define FTM_SC_CLK(c) ((c) << FTM_SC_CLK_MASK_SHIFT) struct ftm_clock_device { void __iomem *clksrc_base; From patchwork Mon Feb 18 14:03:17 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Havelange X-Patchwork-Id: 10818035 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 77EDD6C2 for ; Mon, 18 Feb 2019 14:03:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 51CC72871E for ; Mon, 18 Feb 2019 14:03:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4556128C2E; Mon, 18 Feb 2019 14:03:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2F8B8288F7 for ; Mon, 18 Feb 2019 14:03:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389749AbfBRODy (ORCPT ); Mon, 18 Feb 2019 09:03:54 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:38349 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389771AbfBRODx (ORCPT ); Mon, 18 Feb 2019 09:03:53 -0500 Received: by mail-ed1-f65.google.com with SMTP id h58so13900665edb.5 for ; Mon, 18 Feb 2019 06:03:52 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=essensium-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=I6Qr3PnJqhUErKNHRtGnpwGVLGbDm4vYaQedao4hHXI=; b=kdHcXhxCjuyfL/RsbUdI7m1L2Yqy6Ch6aOf/JLBNnD5HRcGRSlgFnLV7GDHT0+O/ZH WwhadtXZC4vVGNOZDuBn55xN7S4uRWX++KyhraFKHbfOfDIpV2BF2i1X1ZZmPSUG4VoF AkRhIRakB9igwGHCOjQRaHFAWn158WcLofcO9Bvujyxj6a9Q5/FR2tK/sXcaVtMFDepB mzDtU5X9T6XAokc0oVHVyJYLk6aWrjK7mlq7vIRYN+67ZQfflVjoZTlS3hBnJ8v3vCvY cUmqgkNmUgZCJM9+9LD/mdkYFxEuSclcXauFOzLsjW1gmke/0ca5/PZRLVfeL0qwR77Y 7kDw== 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=I6Qr3PnJqhUErKNHRtGnpwGVLGbDm4vYaQedao4hHXI=; b=a4S8VO/pgx/cbD/2nmCiAEsRU/cdhYTsn1q0WWRmuC6XDwlwphfs7gBD85l8ugsSGe JhJLaGx+2Dfsz+uyzZiMaRIxasHFy3qdNPO5vdyijz8LmHOKJ9Igwrw/LBleN/xMcH59 HAc6z6IxUmB6o/TDm+qnbROdHvE5z9mraKV7TNZl0Y0wUW2liYjiseBhpIP9uMVUNbo5 /VQRHvc17XKBOr49zUm1+mRCkQyw+2CMlFEZifDc/uxiI0ARnHonpppHEb4Gc0HZLxJ5 03LsLXcRXqsuD5DxqPvK80/c0lanjk2CH/pX1yqWHs9qFO1ugfZJpp0IcP0S0ahDI7Od PJkQ== X-Gm-Message-State: AHQUAuZ08VerAVkfF6FYEPC5l7KUOw8WwIlTKqAEBzI1FUI9ZP/wPle9 wOXNvYFFBGEVVKndLtkmdrOTIw== X-Google-Smtp-Source: AHgI3IZi9n1v6BYfISfADbqQLufHezmPHIqiJiJUI3/6IPWV+cI2byGpqq/pa18Sn/cvn8B5knGS2w== X-Received: by 2002:a17:906:ee2:: with SMTP id x2mr16832980eji.202.1550498631380; Mon, 18 Feb 2019 06:03:51 -0800 (PST) Received: from localhost.localdomain (ip-188-118-3-185.reverse.destiny.be. [188.118.3.185]) by smtp.gmail.com with ESMTPSA id w48sm1421606eda.88.2019.02.18.06.03.50 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 06:03:50 -0800 (PST) From: Patrick Havelange To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Mark Rutland , Shawn Guo , Li Yang , Daniel Lezcano , Thomas Gleixner , Thierry Reding , Esben Haabendal , William Breathitt Gray , Linus Walleij , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Patrick Havelange Subject: [PATCH 4/8] dt-bindings: iio/counter: ftm-quaddec Date: Mon, 18 Feb 2019 15:03:17 +0100 Message-Id: <20190218140321.19166-4-patrick.havelange@essensium.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190218140321.19166-1-patrick.havelange@essensium.com> References: <20190218140321.19166-1-patrick.havelange@essensium.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP FlexTimer quadrature decoder driver. Signed-off-by: Patrick Havelange Reviewed-by: Esben Haabendal --- .../bindings/iio/counter/ftm-quaddec.txt | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/counter/ftm-quaddec.txt diff --git a/Documentation/devicetree/bindings/iio/counter/ftm-quaddec.txt b/Documentation/devicetree/bindings/iio/counter/ftm-quaddec.txt new file mode 100644 index 000000000000..4d18cd722074 --- /dev/null +++ b/Documentation/devicetree/bindings/iio/counter/ftm-quaddec.txt @@ -0,0 +1,18 @@ +FlexTimer Quadrature decoder counter + +This driver exposes a simple counter for the quadrature decoder mode. + +Required properties: +- compatible: Must be "fsl,ftm-quaddec". +- reg: Must be set to the memory region of the flextimer. + +Optional property: +- big-endian: Access the device registers in big-endian mode. + +Example: + counter0: counter@29d0000 { + compatible = "fsl,ftm-quaddec"; + reg = <0x0 0x29d0000 0x0 0x10000>; + big-endian; + status = "disabled"; + }; From patchwork Mon Feb 18 14:03:18 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Havelange X-Patchwork-Id: 10818115 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 792771399 for ; Mon, 18 Feb 2019 14:24:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6695329FA1 for ; Mon, 18 Feb 2019 14:24:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5A4032A06E; Mon, 18 Feb 2019 14:24:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A3F8C29FA1 for ; Mon, 18 Feb 2019 14:24:37 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731473AbfBROYg (ORCPT ); Mon, 18 Feb 2019 09:24:36 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:42414 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389782AbfBRODz (ORCPT ); Mon, 18 Feb 2019 09:03:55 -0500 Received: by mail-ed1-f66.google.com with SMTP id j89so4517479edb.9 for ; Mon, 18 Feb 2019 06:03:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=essensium-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=y8ELJQgbv7DeZTb+dT/figIxEA2QKkZyGqslXLAy5pw=; b=1EEQllAKYnQmKGyF7FtBV8s+Yo0LgZ+xETEnQoTbs89uCfBgFIQ0qHbAaUYBZBPsKS fwFn/5j6UMtojlsPU7N8YLaHy18t/D6CuMvAXYNDRIUtQk/eCiX9LSKmj6GwJCC3WR8l mchRPF0/tfIt1ap/CB6BXikspkpVKxs3SSEdLUlDWBBPnYeez50q7QhiUYLNud3XA+Le LByS6/3fi9R3gdcpvfOaFHw0k5Ivdg7qqhSklk5ULNmLTmb/AgDfU2BqomRkWEATbXc/ M15uee4hiqq4EopIi4zU3U84DDY781Duvz2ek9XRndzF0Rj6m6jcRRQcLG84cdIaKg84 w1lw== 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=y8ELJQgbv7DeZTb+dT/figIxEA2QKkZyGqslXLAy5pw=; b=Odmu5XTmolmGppQI0CMoUzIDac61v/Gax2owHcywUg32649UFbPkNUTtyq8ycYZ1K7 GfmuDsaxIgldoWMOlpfDCg6GP+KGzL30mCK4fSpWJq5rTt1wBS8Hg7uq7DAMHpHQRN7T qm4T3gIMboT9i/X8Iy/X1xCfDeEMa5M1Q2UIuFZzNWpr27vEXUm9PV/V8qUAmQzV5CXx mr/J8qm+Ql/TnTbIkFHECGuHr/zrquCtI9rgv4PLZR5y1AIMircmv5wo0B8G5AFo2GbV ZrN1SsPKSf7AwFUBzxuhkXG3NK07eaWRRMf+yhjk9AxDRInsn3pIxY3uslTGUWFvECw5 2Pww== X-Gm-Message-State: AHQUAuZ1FcWxFSNqKIMTLCYHwg3uOzgEXvpwarxGqH4ZI4PGMTJD8gcy PxZ1IIMOn5fU26YJ50S1h8Ai+g== X-Google-Smtp-Source: AHgI3IYrC+euDCA6+19B7LQzEHnG2fbshumRDoikpwE8u2sTiM5Yfqae37ry7AmGJn2cYvKCWgnr7w== X-Received: by 2002:a50:94d6:: with SMTP id t22mr19337308eda.232.1550498632701; Mon, 18 Feb 2019 06:03:52 -0800 (PST) Received: from localhost.localdomain (ip-188-118-3-185.reverse.destiny.be. [188.118.3.185]) by smtp.gmail.com with ESMTPSA id w48sm1421606eda.88.2019.02.18.06.03.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 06:03:52 -0800 (PST) From: Patrick Havelange To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Mark Rutland , Shawn Guo , Li Yang , Daniel Lezcano , Thomas Gleixner , Thierry Reding , Esben Haabendal , William Breathitt Gray , Linus Walleij , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Patrick Havelange Subject: [PATCH 5/8] iio/counter: add FlexTimer Module Quadrature decoder counter driver Date: Mon, 18 Feb 2019 15:03:18 +0100 Message-Id: <20190218140321.19166-5-patrick.havelange@essensium.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190218140321.19166-1-patrick.havelange@essensium.com> References: <20190218140321.19166-1-patrick.havelange@essensium.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This driver exposes the counter for the quadrature decoder of the FlexTimer Module, present in the LS1021A soc. Signed-off-by: Patrick Havelange Reviewed-by: Esben Haabendal --- drivers/iio/counter/Kconfig | 10 + drivers/iio/counter/Makefile | 1 + drivers/iio/counter/ftm-quaddec.c | 294 ++++++++++++++++++++++++++++++ 3 files changed, 305 insertions(+) create mode 100644 drivers/iio/counter/ftm-quaddec.c diff --git a/drivers/iio/counter/Kconfig b/drivers/iio/counter/Kconfig index bf1e559ad7cd..4641cb2e752a 100644 --- a/drivers/iio/counter/Kconfig +++ b/drivers/iio/counter/Kconfig @@ -31,4 +31,14 @@ config STM32_LPTIMER_CNT To compile this driver as a module, choose M here: the module will be called stm32-lptimer-cnt. + +config FTM_QUADDEC + tristate "Flex Timer Module Quadrature decoder driver" + help + Select this option to enable the Flex Timer Quadrature decoder + driver. + + To compile this driver as a module, choose M here: the + module will be called ftm-quaddec. + endmenu diff --git a/drivers/iio/counter/Makefile b/drivers/iio/counter/Makefile index 1b9a896eb488..757c1f4196af 100644 --- a/drivers/iio/counter/Makefile +++ b/drivers/iio/counter/Makefile @@ -6,3 +6,4 @@ obj-$(CONFIG_104_QUAD_8) += 104-quad-8.o obj-$(CONFIG_STM32_LPTIMER_CNT) += stm32-lptimer-cnt.o +obj-$(CONFIG_FTM_QUADDEC) += ftm-quaddec.o diff --git a/drivers/iio/counter/ftm-quaddec.c b/drivers/iio/counter/ftm-quaddec.c new file mode 100644 index 000000000000..ca7e55a9ab3f --- /dev/null +++ b/drivers/iio/counter/ftm-quaddec.c @@ -0,0 +1,294 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Flex Timer Module Quadrature decoder + * + * This module implements a driver for decoding the FTM quadrature + * of ex. a LS1021A + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +struct ftm_quaddec { + struct platform_device *pdev; + void __iomem *ftm_base; + bool big_endian; + struct mutex ftm_quaddec_mutex; +}; + +#define HASFLAGS(flag, bits) ((flag & bits) ? 1 : 0) + +#define DEFAULT_POLL_INTERVAL 100 /* in msec */ + +static void ftm_read(struct ftm_quaddec *ftm, uint32_t offset, uint32_t *data) +{ + if (ftm->big_endian) + *data = ioread32be(ftm->ftm_base + offset); + else + *data = ioread32(ftm->ftm_base + offset); +} + +static void ftm_write(struct ftm_quaddec *ftm, uint32_t offset, uint32_t data) +{ + if (ftm->big_endian) + iowrite32be(data, ftm->ftm_base + offset); + else + iowrite32(data, ftm->ftm_base + offset); +} + +/* take mutex + * call ftm_clear_write_protection + * update settings + * call ftm_set_write_protection + * release mutex + */ +static void ftm_clear_write_protection(struct ftm_quaddec *ftm) +{ + uint32_t flag; + + /* First see if it is enabled */ + ftm_read(ftm, FTM_FMS, &flag); + + if (flag & FTM_FMS_WPEN) { + ftm_read(ftm, FTM_MODE, &flag); + ftm_write(ftm, FTM_MODE, flag | FTM_MODE_WPDIS); + } +} + +static void ftm_set_write_protection(struct ftm_quaddec *ftm) +{ + ftm_write(ftm, FTM_FMS, FTM_FMS_WPEN); +} + +static void ftm_reset_counter(struct ftm_quaddec *ftm) +{ + /* Reset hardware counter to CNTIN */ + ftm_write(ftm, FTM_CNT, 0x0); +} + +static void ftm_quaddec_init(struct ftm_quaddec *ftm) +{ + ftm_clear_write_protection(ftm); + + /* Do not write in the region from the CNTIN register through the + * PWMLOAD register when FTMEN = 0. + */ + ftm_write(ftm, FTM_MODE, FTM_MODE_FTMEN); /* enable FTM */ + ftm_write(ftm, FTM_CNTIN, 0x0000); /* zero init value */ + ftm_write(ftm, FTM_MOD, 0xffff); /* max overflow value */ + ftm_write(ftm, FTM_CNT, 0x0); /* reset counter value */ + ftm_write(ftm, FTM_SC, FTM_SC_PS_1); /* prescale with x1 */ + /* Select quad mode */ + ftm_write(ftm, FTM_QDCTRL, FTM_QDCTRL_QUADEN); + + /* Unused features and reset to default section */ + ftm_write(ftm, FTM_POL, 0x0); /* polarity is active high */ + ftm_write(ftm, FTM_FLTCTRL, 0x0); /* all faults disabled */ + ftm_write(ftm, FTM_SYNCONF, 0x0); /* disable all sync */ + ftm_write(ftm, FTM_SYNC, 0xffff); + + /* Lock the FTM */ + ftm_set_write_protection(ftm); +} + +static int ftm_quaddec_read_raw(struct iio_dev *indio_dev, + struct iio_chan_spec const *chan, + int *val, int *val2, long mask) +{ + struct ftm_quaddec *ftm = iio_priv(indio_dev); + uint32_t counter; + + switch (mask) { + case IIO_CHAN_INFO_RAW: + ftm_read(ftm, FTM_CNT, &counter); + *val = counter; + return IIO_VAL_INT; + default: + return -EINVAL; + } +} + +static ssize_t ftm_write_reset(struct iio_dev *indio_dev, + uintptr_t private, + struct iio_chan_spec const *chan, + const char *buf, size_t len) +{ + struct ftm_quaddec *ftm = iio_priv(indio_dev); + + /* Only "counter reset" is supported for now */ + if (!sysfs_streq(buf, "0")) { + dev_warn(&ftm->pdev->dev, "Reset only accepts '0'\n"); + return -EINVAL; + } + + ftm_reset_counter(ftm); + + return len; +} + +static int ftm_quaddec_get_prescaler(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan) +{ + struct ftm_quaddec *ftm = iio_priv(indio_dev); + uint32_t scflags; + + ftm_read(ftm, FTM_SC, &scflags); + + return scflags & FTM_SC_PS_MASK; +} + +static int ftm_quaddec_set_prescaler(struct iio_dev *indio_dev, + const struct iio_chan_spec *chan, + unsigned int type) +{ + struct ftm_quaddec *ftm = iio_priv(indio_dev); + + uint32_t scflags; + + mutex_lock(&ftm->ftm_quaddec_mutex); + + ftm_read(ftm, FTM_SC, &scflags); + + scflags &= ~FTM_SC_PS_MASK; + type &= FTM_SC_PS_MASK; /*just to be 100% sure*/ + + scflags |= type; + + /* Write */ + ftm_clear_write_protection(ftm); + ftm_write(ftm, FTM_SC, scflags); + ftm_set_write_protection(ftm); + + /* Also resets the counter as it is undefined anyway now */ + ftm_reset_counter(ftm); + + mutex_unlock(&ftm->ftm_quaddec_mutex); + return 0; +} + +static const char * const ftm_quaddec_prescaler[] = { + "1", "2", "4", "8", "16", "32", "64", "128" +}; + +static const struct iio_enum ftm_quaddec_prescaler_en = { + .items = ftm_quaddec_prescaler, + .num_items = ARRAY_SIZE(ftm_quaddec_prescaler), + .get = ftm_quaddec_get_prescaler, + .set = ftm_quaddec_set_prescaler, +}; + +static const struct iio_chan_spec_ext_info ftm_quaddec_ext_info[] = { + { + .name = "reset", + .shared = IIO_SEPARATE, + .write = ftm_write_reset, + }, + IIO_ENUM("prescaler", IIO_SEPARATE, &ftm_quaddec_prescaler_en), + IIO_ENUM_AVAILABLE("prescaler", &ftm_quaddec_prescaler_en), + {} +}; + +static const struct iio_chan_spec ftm_quaddec_channels = { + .type = IIO_COUNT, + .channel = 0, + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .ext_info = ftm_quaddec_ext_info, + .indexed = 1, +}; + +static const struct iio_info ftm_quaddec_iio_info = { + .read_raw = ftm_quaddec_read_raw, +}; + +static int ftm_quaddec_probe(struct platform_device *pdev) +{ + struct iio_dev *indio_dev; + struct ftm_quaddec *ftm; + int ret; + + struct device_node *node = pdev->dev.of_node; + + indio_dev = devm_iio_device_alloc(&pdev->dev, sizeof(*ftm)); + if (!indio_dev) + return -ENOMEM; + + ftm = iio_priv(indio_dev); + + platform_set_drvdata(pdev, ftm); + + ftm->pdev = pdev; + ftm->big_endian = of_property_read_bool(node, "big-endian"); + ftm->ftm_base = of_iomap(node, 0); + if (!ftm->ftm_base) + return -EINVAL; + + indio_dev->name = dev_name(&pdev->dev); + indio_dev->dev.parent = &pdev->dev; + indio_dev->info = &ftm_quaddec_iio_info; + indio_dev->num_channels = 1; + indio_dev->channels = &ftm_quaddec_channels; + + ftm_quaddec_init(ftm); + + mutex_init(&ftm->ftm_quaddec_mutex); + + ret = devm_iio_device_register(&pdev->dev, indio_dev); + if (ret) { + mutex_destroy(&ftm->ftm_quaddec_mutex); + iounmap(ftm->ftm_base); + } + return ret; +} + +static int ftm_quaddec_remove(struct platform_device *pdev) +{ + struct ftm_quaddec *ftm; + struct iio_dev *indio_dev; + + ftm = (struct ftm_quaddec *)platform_get_drvdata(pdev); + indio_dev = iio_priv_to_dev(ftm); + /* This is needed to remove sysfs entries */ + devm_iio_device_unregister(&pdev->dev, indio_dev); + + ftm_write(ftm, FTM_MODE, 0); + + iounmap(ftm->ftm_base); + mutex_destroy(&ftm->ftm_quaddec_mutex); + + return 0; +} + +static const struct of_device_id ftm_quaddec_match[] = { + { .compatible = "fsl,ftm-quaddec" }, + {}, +}; + +static struct platform_driver ftm_quaddec_driver = { + .driver = { + .name = "ftm-quaddec", + .owner = THIS_MODULE, + .of_match_table = ftm_quaddec_match, + }, + .probe = ftm_quaddec_probe, + .remove = ftm_quaddec_remove, +}; + +module_platform_driver(ftm_quaddec_driver); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Kjeld Flarup X-Patchwork-Id: 10818113 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D38151399 for ; Mon, 18 Feb 2019 14:24:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C12B42A049 for ; Mon, 18 Feb 2019 14:24:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id B4EFE2ADC7; Mon, 18 Feb 2019 14:24:35 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6053E2A049 for ; Mon, 18 Feb 2019 14:24:35 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389807AbfBROD4 (ORCPT ); Mon, 18 Feb 2019 09:03:56 -0500 Received: from mail-ed1-f66.google.com ([209.85.208.66]:46022 "EHLO mail-ed1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389789AbfBRODz (ORCPT ); Mon, 18 Feb 2019 09:03:55 -0500 Received: by mail-ed1-f66.google.com with SMTP id d9so13871618edh.12 for ; Mon, 18 Feb 2019 06:03:54 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=essensium-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GTpjAPx1fakrDr6iX7ZaByuauFa8vRSnm2YIwlrmcQE=; b=oGtwGp0cHyc/ThOhI0NGYWLVDSrVX2SWB9ZJ86TRWH4C14DlC7FmlBqmeHKpbD4ucE vy/cFD//qkNVp/7JweqiNyeeg6fDH7HUF9mA0hk3Qp+XvmGXydwbBtQScNcqt99PQqJj fXJiLwhkrLzTHy8oWETYAmZeDKsH/sLeZhett9YfcfNF3hxuBS6vcRFn1IuHqEM0GQrJ scnLF3d9dBAcbYPSfUy/wulNDGyhsraiJpy/A78BMb5aGPAuPBzsm9QQa9gq2UtvAHin 5jYZqBKuzSOiKZeBUYrIuuIng+KsDiIFRHsTEbrGCCOO34hD2CMy1H1kiXUMQDAfUcYo cHTQ== 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=GTpjAPx1fakrDr6iX7ZaByuauFa8vRSnm2YIwlrmcQE=; b=iooHXMqNkYeVofqPFWCBV6jaXVSlOtrXnydABCTrtGyBvftU6YE5r4fEyfNMFqYUKW NnZY85NxRpU0p2PwKr2nl9ou7oatBkZoR+5Hnab9n6ck0cGTbRJirDVbj16ZzvQt/M+X sAQSzkyef8jae0vXTFAAyEeQk/WGqiJde0hjOrZnvRqLAlbgowCpANMYy6KuYSMUakL0 TPd3TxGp/5il+Exl1hrLiE12s7T35CLcwmop47nFAV92qU5zySJWOo5uacSfDeFk8+/5 1C/ntbovzgMtbostkziNqLq8DzhluScbw0ak3v4MqCujWYeGfXtk/vypqgpnHgh1ffSI OPZw== X-Gm-Message-State: AHQUAuakHrX0RdQu/MGIVMvx6Q4g+gc9/UPkX8P5LU5npSFhKCzIwVnG sHEBWh+LHMG8WBtmAhB2xwm4mw== X-Google-Smtp-Source: AHgI3IaGiJP5XG+ub4Q/7liQMN3rjPdmMOiO1kL3JJ7SmjuWWM5ZIcTeHoTOJT8m3tJlRpqM6BKEYA== X-Received: by 2002:a17:906:1552:: with SMTP id c18mr8653338ejd.64.1550498633824; Mon, 18 Feb 2019 06:03:53 -0800 (PST) Received: from localhost.localdomain (ip-188-118-3-185.reverse.destiny.be. [188.118.3.185]) by smtp.gmail.com with ESMTPSA id w48sm1421606eda.88.2019.02.18.06.03.52 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 06:03:53 -0800 (PST) From: Patrick Havelange To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Mark Rutland , Shawn Guo , Li Yang , Daniel Lezcano , Thomas Gleixner , Thierry Reding , Esben Haabendal , William Breathitt Gray , Linus Walleij , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Patrick Havelange Subject: [PATCH 6/8] LS1021A: dtsi: add ftm quad decoder entries Date: Mon, 18 Feb 2019 15:03:19 +0100 Message-Id: <20190218140321.19166-6-patrick.havelange@essensium.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190218140321.19166-1-patrick.havelange@essensium.com> References: <20190218140321.19166-1-patrick.havelange@essensium.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Add the 4 Quadrature counters for this board. Signed-off-by: Patrick Havelange Reviewed-by: Esben Haabendal --- arch/arm/boot/dts/ls1021a.dtsi | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/arch/arm/boot/dts/ls1021a.dtsi b/arch/arm/boot/dts/ls1021a.dtsi index ed0941292172..0168fb62590a 100644 --- a/arch/arm/boot/dts/ls1021a.dtsi +++ b/arch/arm/boot/dts/ls1021a.dtsi @@ -433,6 +433,34 @@ status = "disabled"; }; + counter0: counter@29d0000 { + compatible = "fsl,ftm-quaddec"; + reg = <0x0 0x29d0000 0x0 0x10000>; + big-endian; + status = "disabled"; + }; + + counter1: counter@29e0000 { + compatible = "fsl,ftm-quaddec"; + reg = <0x0 0x29e0000 0x0 0x10000>; + big-endian; + status = "disabled"; + }; + + counter2: counter@29f0000 { + compatible = "fsl,ftm-quaddec"; + reg = <0x0 0x29f0000 0x0 0x10000>; + big-endian; + status = "disabled"; + }; + + counter3: counter@2a00000 { + compatible = "fsl,ftm-quaddec"; + reg = <0x0 0x2a00000 0x0 0x10000>; + big-endian; + status = "disabled"; + }; + gpio0: gpio@2300000 { compatible = "fsl,ls1021a-gpio", "fsl,qoriq-gpio"; reg = <0x0 0x2300000 0x0 0x10000>; From patchwork Mon Feb 18 14:03:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Havelange X-Patchwork-Id: 10818111 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E975B1575 for ; Mon, 18 Feb 2019 14:24:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D763329FA1 for ; Mon, 18 Feb 2019 14:24:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id CB2962A06E; Mon, 18 Feb 2019 14:24:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7412429FA1 for ; Mon, 18 Feb 2019 14:24:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731432AbfBROYd (ORCPT ); Mon, 18 Feb 2019 09:24:33 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:46024 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389802AbfBROD5 (ORCPT ); Mon, 18 Feb 2019 09:03:57 -0500 Received: by mail-ed1-f65.google.com with SMTP id d9so13871692edh.12 for ; Mon, 18 Feb 2019 06:03:55 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=essensium-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=TMKsmtSeB2s1AaZbZadZjj3xF8b5OyVicGrn8cs6Cxc=; b=KJPSI94h/3tr09gSDgWJ5ok7TSJC7JE/SFp+CPCPi5fV/xhzlIP8m+1T5aj3kNAVCS xawDKsAC8POcScc1qfEU3Mx7JR/0TIz2paMShO/Y2zlRdoxPpLXQcVNXOi1BkhNbvT5t k0Dsnts9zdDl5ya7+AE5PYVl1eet6ZUddv22gxrkx+FfPCHE1QFt1rqHB425oMLtX2dH DLj9oeRh/NaIiuETNkVr+lgZUDEJeC/mlCLreb/nV4Sgwr66LdO2XTOmd/gnnQ92GugB s6PgCWxnsmxMFnaVMIB24Cm2z6lH0e8xo+pB9gUvDoZQ5IXH9k28jMdD5ZInypUxMlVn vJpQ== 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=TMKsmtSeB2s1AaZbZadZjj3xF8b5OyVicGrn8cs6Cxc=; b=h6C1DU0T4j5V3UZ4QNDVBunUZl36IxwpbHr0AC2A/E/k2j7PudDj0/BD3tHJgArPMG s2hk1hu4oRohbvwebHcu40hMpNcpGFCD1VpUb+ttAqmokmitjNonC5NFOpVAMVX50TbC vH7PIXNlZFIb0bC7HYHRSLUlbILR8+V8J05ZtlA7cH0GPtZAjSKShNwMC3NLDMph8kNs FTWxeZkfp5+DC6qUUmu30BpdMC/NSJLZRNsjcL0qhKf26lY0u3WQvClflUcT2ZksihtQ MTbHYp96qGst01zKng9YHulH74qSaviOk83+SOn8Pct4qLQoXYBov3E4thcFMa6pyy4S nLxw== X-Gm-Message-State: AHQUAuaQnGeLd9XnbjRj34FSHaBp83/21ZRssk8GnPwjv541yT8ofiDL 1/hmr7PCapAHmWa8foieuepLIA== X-Google-Smtp-Source: AHgI3IZWqJlESiACGZSBuFtcSlgUTXzB5UwYLjy0fJjTMr4Yq/bz8Bc0PoTINj2B3ihTtaQ8an9+iQ== X-Received: by 2002:a50:fc12:: with SMTP id i18mr19300418edr.149.1550498635286; Mon, 18 Feb 2019 06:03:55 -0800 (PST) Received: from localhost.localdomain (ip-188-118-3-185.reverse.destiny.be. [188.118.3.185]) by smtp.gmail.com with ESMTPSA id w48sm1421606eda.88.2019.02.18.06.03.53 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 06:03:54 -0800 (PST) From: Patrick Havelange To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Mark Rutland , Shawn Guo , Li Yang , Daniel Lezcano , Thomas Gleixner , Thierry Reding , Esben Haabendal , William Breathitt Gray , Linus Walleij , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Patrick Havelange Subject: [PATCH 7/8] dt-bindings: iio/counter: ftm-quaddec: add poll-interval parameter Date: Mon, 18 Feb 2019 15:03:20 +0100 Message-Id: <20190218140321.19166-7-patrick.havelange@essensium.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190218140321.19166-1-patrick.havelange@essensium.com> References: <20190218140321.19166-1-patrick.havelange@essensium.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP New optional parameter supported by updated driver. Signed-off-by: Patrick Havelange Reviewed-by: Esben Haabendal Reviewed-by: Rob Herring --- .../devicetree/bindings/iio/counter/ftm-quaddec.txt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/iio/counter/ftm-quaddec.txt b/Documentation/devicetree/bindings/iio/counter/ftm-quaddec.txt index 4d18cd722074..60554e6c4367 100644 --- a/Documentation/devicetree/bindings/iio/counter/ftm-quaddec.txt +++ b/Documentation/devicetree/bindings/iio/counter/ftm-quaddec.txt @@ -6,8 +6,14 @@ Required properties: - compatible: Must be "fsl,ftm-quaddec". - reg: Must be set to the memory region of the flextimer. -Optional property: +Optional properties: - big-endian: Access the device registers in big-endian mode. +- poll-interval Poll interval time in milliseconds for detecting + the under/overflow of the counter. Default value + is 100. + A value of 0 disables polling. This value can also + be set at runtime, but not to less than this initial + value (except 0 for disabling). Example: counter0: counter@29d0000 { From patchwork Mon Feb 18 14:03:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Havelange X-Patchwork-Id: 10818109 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id AD32E1575 for ; Mon, 18 Feb 2019 14:24:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 99A2129FA1 for ; Mon, 18 Feb 2019 14:24:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8D8542A06E; Mon, 18 Feb 2019 14:24:33 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id CFE4F2A049 for ; Mon, 18 Feb 2019 14:24:32 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2389142AbfBROYV (ORCPT ); Mon, 18 Feb 2019 09:24:21 -0500 Received: from mail-ed1-f65.google.com ([209.85.208.65]:42421 "EHLO mail-ed1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S2389815AbfBROD7 (ORCPT ); Mon, 18 Feb 2019 09:03:59 -0500 Received: by mail-ed1-f65.google.com with SMTP id j89so4517658edb.9 for ; Mon, 18 Feb 2019 06:03:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=essensium-com.20150623.gappssmtp.com; s=20150623; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=KlgMi7EUDch9k0ALR7Q1zPGaXCvfUKqLAbFj7Wd2gYI=; b=Xjqf2CUTK3wWht17aEOAfDSRolyYwwEgAB17Hbj0Bz1DyXH86CotYo4nyRklgT/rSD eSN/mf1lcvmMZNhjgf2Dp8QQ+OyaQjqhflJKsAyk5ch7c2anSejIDuxPg351D9OIAC5I XB3aJL8f0SYEaijY2jGLrVizGZKqjfbrSJSe+2kJBlPHaAH7LcdIx+zEfL9v9JDjLy40 /NbM3Rj+BpkJlVDwreItXS2VB22ny0PZcUA8/SWtfN/mEK2Hv2lt+fhuYFIeCy88I+Ue sEi0cl3RD+LfCL9Y8iK6nm2P9yPlSY0h1O6Soci3IDh16V+wUgIMKJ+o9mLZj8yEnKXB A3oA== 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=KlgMi7EUDch9k0ALR7Q1zPGaXCvfUKqLAbFj7Wd2gYI=; b=UC4wiCehRYXzS52E6JJdLHHQR7BJadGq/NU1aQjeMEtndJ3v0dxBuYCtk6g7QLne3v 58p8dyu77mU41PL0Edo67/a03MwmXBOqZJmWcZPS4PsnN9sPI8I5Q9UD+EICnK+5qQwn 9QW3bkIku5CVO6twAgsJ28J/QmOkU5UKWRHdi3c20/njoJWow0AgACnkzj+VB+mwECAq VdSdiRr2ipgjD1d4wscsyVMRn7FS7CIPNax99p1bUiRC3nFx1yHB0QUzUr8kiA+qSuiT I3EliMUjx5h3osg7RqgJmMI2vKv3AqytbFE7ZIta1QeYXq1mFQBb9HPAbXDzxsyYbcMR FohQ== X-Gm-Message-State: AHQUAuYkokIvZxHj9dUh3I/cZrOyOh4izXb2EgYcugBtMzTU5hehnRa5 0E6fBlNDLageky/DZ8XxgAChSw== X-Google-Smtp-Source: AHgI3IY0ceN0vfQ9xmpYZOcoyNSJemRZclaQngynB0UdW0cgs6sy04XzxzixF0mhiQPAsNetmxb/iA== X-Received: by 2002:a17:906:82d1:: with SMTP id a17mr16402415ejy.164.1550498636470; Mon, 18 Feb 2019 06:03:56 -0800 (PST) Received: from localhost.localdomain (ip-188-118-3-185.reverse.destiny.be. [188.118.3.185]) by smtp.gmail.com with ESMTPSA id w48sm1421606eda.88.2019.02.18.06.03.55 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 18 Feb 2019 06:03:55 -0800 (PST) From: Patrick Havelange To: Jonathan Cameron , Hartmut Knaack , Lars-Peter Clausen , Peter Meerwald-Stadler , Rob Herring , Mark Rutland , Shawn Guo , Li Yang , Daniel Lezcano , Thomas Gleixner , Thierry Reding , Esben Haabendal , William Breathitt Gray , Linus Walleij , linux-iio@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-pwm@vger.kernel.org, linuxppc-dev@lists.ozlabs.org Cc: Patrick Havelange Subject: [PATCH 8/8] iio/counter/ftm-quaddec: add handling of under/overflow of the counter. Date: Mon, 18 Feb 2019 15:03:21 +0100 Message-Id: <20190218140321.19166-8-patrick.havelange@essensium.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20190218140321.19166-1-patrick.havelange@essensium.com> References: <20190218140321.19166-1-patrick.havelange@essensium.com> Sender: linux-iio-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-iio@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This is implemented by polling the counter value. A new parameter "poll-interval" can be set in the device tree, or can be changed at runtime. The reason for the polling is to avoid interrupts flooding. If the quadrature input is going up and down around the overflow value (or around 0), the interrupt will be triggering all the time. Thus, polling is an easy way to handle overflow in a consistent way. Polling can still be disabled by setting poll-interval to 0. Signed-off-by: Patrick Havelange Reviewed-by: Esben Haabendal --- drivers/iio/counter/ftm-quaddec.c | 199 +++++++++++++++++++++++++++++- 1 file changed, 193 insertions(+), 6 deletions(-) diff --git a/drivers/iio/counter/ftm-quaddec.c b/drivers/iio/counter/ftm-quaddec.c index ca7e55a9ab3f..3a0395c3ef33 100644 --- a/drivers/iio/counter/ftm-quaddec.c +++ b/drivers/iio/counter/ftm-quaddec.c @@ -25,11 +25,33 @@ struct ftm_quaddec { struct platform_device *pdev; + struct delayed_work delayedcounterwork; void __iomem *ftm_base; bool big_endian; + + /* Offset added to the counter to adjust for overflows of the + * 16 bit HW counter. Only the 16 MSB are set. + */ + uint32_t counteroffset; + + /* Store the counter on each read, this is used to detect + * if the counter readout if we over or underflow + */ + uint8_t lastregion; + + /* Poll-interval, in ms before delayed work must poll counter */ + uint16_t poll_interval; + struct mutex ftm_quaddec_mutex; }; +struct counter_result { + /* 16 MSB are from the counteroffset + * 16 LSB are from the hardware counter + */ + uint32_t value; +}; + #define HASFLAGS(flag, bits) ((flag & bits) ? 1 : 0) #define DEFAULT_POLL_INTERVAL 100 /* in msec */ @@ -74,8 +96,75 @@ static void ftm_set_write_protection(struct ftm_quaddec *ftm) ftm_write(ftm, FTM_FMS, FTM_FMS_WPEN); } +/* must be called with mutex locked */ +static void ftm_work_reschedule(struct ftm_quaddec *ftm) +{ + cancel_delayed_work(&ftm->delayedcounterwork); + if (ftm->poll_interval > 0) + schedule_delayed_work(&ftm->delayedcounterwork, + msecs_to_jiffies(ftm->poll_interval)); +} + +/* Reports the hardware counter added the offset counter. + * + * The quadrature decodes does not use interrupts, because it cannot be + * guaranteed that the counter won't flip between 0xFFFF and 0x0000 at a high + * rate, causing Real Time performance degration. Instead the counter must be + * read frequently enough - the assumption is 150 KHz input can be handled with + * 100 ms read cycles. + */ +static void ftm_work_counter(struct ftm_quaddec *ftm, + struct counter_result *returndata) +{ + /* only 16bits filled in*/ + uint32_t hwcounter; + uint8_t currentregion; + + mutex_lock(&ftm->ftm_quaddec_mutex); + + ftm_read(ftm, FTM_CNT, &hwcounter); + + /* Divide the counter in four regions: + * 0x0000-0x4000-0x8000-0xC000-0xFFFF + * When the hwcounter changes between region 0 and 3 there is an + * over/underflow + */ + currentregion = hwcounter / 0x4000; + + if (ftm->lastregion == 3 && currentregion == 0) + ftm->counteroffset += 0x10000; + + if (ftm->lastregion == 0 && currentregion == 3) + ftm->counteroffset -= 0x10000; + + ftm->lastregion = currentregion; + + if (returndata) + returndata->value = ftm->counteroffset + hwcounter; + + ftm_work_reschedule(ftm); + + mutex_unlock(&ftm->ftm_quaddec_mutex); +} + +/* wrapper around the real function */ +static void ftm_work_counter_delay(struct work_struct *workptr) +{ + struct delayed_work *work; + struct ftm_quaddec *ftm; + + work = container_of(workptr, struct delayed_work, work); + ftm = container_of(work, struct ftm_quaddec, delayedcounterwork); + + ftm_work_counter(ftm, NULL); +} + +/* must be called with mutex locked */ static void ftm_reset_counter(struct ftm_quaddec *ftm) { + ftm->counteroffset = 0; + ftm->lastregion = 0; + /* Reset hardware counter to CNTIN */ ftm_write(ftm, FTM_CNT, 0x0); } @@ -110,18 +199,91 @@ static int ftm_quaddec_read_raw(struct iio_dev *indio_dev, int *val, int *val2, long mask) { struct ftm_quaddec *ftm = iio_priv(indio_dev); - uint32_t counter; + struct counter_result counter; switch (mask) { case IIO_CHAN_INFO_RAW: - ftm_read(ftm, FTM_CNT, &counter); - *val = counter; + case IIO_CHAN_INFO_PROCESSED: + ftm_work_counter(ftm, &counter); + if (mask == IIO_CHAN_INFO_RAW) + counter.value &= 0xffff; + + *val = counter.value; + return IIO_VAL_INT; default: return -EINVAL; } } +static uint32_t ftm_get_default_poll_interval(const struct ftm_quaddec *ftm) +{ + /* Read values from device tree */ + uint32_t val; + const struct device_node *node = ftm->pdev->dev.of_node; + + if (of_property_read_u32(node, "poll-interval", &val)) + val = DEFAULT_POLL_INTERVAL; + + return val; +} + +static ssize_t ftm_read_default_poll_interval(struct iio_dev *indio_dev, + uintptr_t private, + struct iio_chan_spec const *chan, + char *buf) +{ + const struct ftm_quaddec *ftm = iio_priv(indio_dev); + uint32_t val = ftm_get_default_poll_interval(ftm); + + return snprintf(buf, PAGE_SIZE, "%u\n", val); +} + +static ssize_t ftm_read_poll_interval(struct iio_dev *indio_dev, + uintptr_t private, + struct iio_chan_spec const *chan, + char *buf) +{ + struct ftm_quaddec *ftm = iio_priv(indio_dev); + + uint32_t poll_interval = READ_ONCE(ftm->poll_interval); + + return snprintf(buf, PAGE_SIZE, "%u\n", poll_interval); +} + +static ssize_t ftm_write_poll_interval(struct iio_dev *indio_dev, + uintptr_t private, + struct iio_chan_spec const *chan, + const char *buf, size_t len) +{ + struct ftm_quaddec *ftm = iio_priv(indio_dev); + uint32_t newpoll_interval; + uint32_t default_interval; + + if (kstrtouint(buf, 10, &newpoll_interval) != 0) { + dev_err(&ftm->pdev->dev, "poll_interval not a number: '%s'\n", + buf); + return -EINVAL; + } + + /* Don't accept polling times below the default value to protect the + * system. + */ + default_interval = ftm_get_default_poll_interval(ftm); + + if (newpoll_interval < default_interval && newpoll_interval != 0) + newpoll_interval = default_interval; + + mutex_lock(&ftm->ftm_quaddec_mutex); + + WRITE_ONCE(ftm->poll_interval, newpoll_interval); + ftm_work_reschedule(ftm); + + mutex_unlock(&ftm->ftm_quaddec_mutex); + + return len; +} + static ssize_t ftm_write_reset(struct iio_dev *indio_dev, uintptr_t private, struct iio_chan_spec const *chan, @@ -135,8 +297,11 @@ static ssize_t ftm_write_reset(struct iio_dev *indio_dev, return -EINVAL; } + mutex_lock(&ftm->ftm_quaddec_mutex); + ftm_reset_counter(ftm); + mutex_unlock(&ftm->ftm_quaddec_mutex); return len; } @@ -192,6 +357,17 @@ static const struct iio_enum ftm_quaddec_prescaler_en = { }; static const struct iio_chan_spec_ext_info ftm_quaddec_ext_info[] = { + { + .name = "default_poll_interval", + .shared = IIO_SHARED_BY_TYPE, + .read = ftm_read_default_poll_interval, + }, + { + .name = "poll_interval", + .shared = IIO_SHARED_BY_TYPE, + .read = ftm_read_poll_interval, + .write = ftm_write_poll_interval, + }, { .name = "reset", .shared = IIO_SEPARATE, @@ -205,7 +381,8 @@ static const struct iio_chan_spec_ext_info ftm_quaddec_ext_info[] = { static const struct iio_chan_spec ftm_quaddec_channels = { .type = IIO_COUNT, .channel = 0, - .info_mask_separate = BIT(IIO_CHAN_INFO_RAW), + .info_mask_separate = BIT(IIO_CHAN_INFO_RAW) | + BIT(IIO_CHAN_INFO_PROCESSED), .ext_info = ftm_quaddec_ext_info, .indexed = 1, }; @@ -232,10 +409,14 @@ static int ftm_quaddec_probe(struct platform_device *pdev) ftm->pdev = pdev; ftm->big_endian = of_property_read_bool(node, "big-endian"); + ftm->counteroffset = 0; + ftm->lastregion = 0; ftm->ftm_base = of_iomap(node, 0); if (!ftm->ftm_base) return -EINVAL; + ftm->poll_interval = ftm_get_default_poll_interval(ftm); + indio_dev->name = dev_name(&pdev->dev); indio_dev->dev.parent = &pdev->dev; indio_dev->info = &ftm_quaddec_iio_info; @@ -245,9 +426,13 @@ static int ftm_quaddec_probe(struct platform_device *pdev) ftm_quaddec_init(ftm); mutex_init(&ftm->ftm_quaddec_mutex); + INIT_DELAYED_WORK(&ftm->delayedcounterwork, ftm_work_counter_delay); + + ftm_work_reschedule(ftm); ret = devm_iio_device_register(&pdev->dev, indio_dev); if (ret) { + cancel_delayed_work_sync(&ftm->delayedcounterwork); mutex_destroy(&ftm->ftm_quaddec_mutex); iounmap(ftm->ftm_base); } @@ -261,13 +446,15 @@ static int ftm_quaddec_remove(struct platform_device *pdev) ftm = (struct ftm_quaddec *)platform_get_drvdata(pdev); indio_dev = iio_priv_to_dev(ftm); - /* This is needed to remove sysfs entries */ + /* Make sure no concurrent attribute reads happen*/ devm_iio_device_unregister(&pdev->dev, indio_dev); + cancel_delayed_work_sync(&ftm->delayedcounterwork); + ftm_write(ftm, FTM_MODE, 0); - iounmap(ftm->ftm_base); mutex_destroy(&ftm->ftm_quaddec_mutex); + iounmap(ftm->ftm_base); return 0; }