From patchwork Sat Apr 21 15:12:34 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 10354255 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 3387860231 for ; Sat, 21 Apr 2018 15:20:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E0F172891C for ; Sat, 21 Apr 2018 15:20:48 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DF5D528977; Sat, 21 Apr 2018 15:20:48 +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=-2.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E9EEC2891C for ; Sat, 21 Apr 2018 15:20:41 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=B4aX1udjXGVfQj8JJKUCbzqBhrMOjfoZSVINoltQ46c=; b=dX859BNcK0PvCjGc85E95iTEUJ ya6hay6D/ytZDdIrONC94XxVGQ0dFV49PLz4eQNwjDoG76PW7TUv59V0+eEMhqg1d5xSWr4oO0dJm 0cLtkgo5d1vtky34+Lnpxzxyio/w/soKGi5YphCXv4KIbwyeP3en93Ssrihce+aegGCiP+xLcTotN bJqbB8CGUNB5d5m+woWmF2kFK7rWjoBlr97TlWMhoZ70KMmuo5gcUs7+ngMzeGitbSPxiUT2ao0WW NEf3/ARRNUKNY3RVgGLEY3UlWwW1Mxr4Da9q1y64rWSyaJ/o0rM45I/KMrlLMlKEM3a+W3R5Hxusa SdzGQK4g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f9uJW-0000SW-O5; Sat, 21 Apr 2018 15:20:34 +0000 Received: from mail.bootlin.com ([62.4.15.54]) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1f9uCi-0003cN-IS for linux-arm-kernel@lists.infradead.org; Sat, 21 Apr 2018 15:13:37 +0000 Received: by mail.bootlin.com (Postfix, from userid 110) id 31CA5209A5; Sat, 21 Apr 2018 17:13:14 +0200 (CEST) Received: from localhost.localdomain (unknown [91.224.148.103]) by mail.bootlin.com (Postfix) with ESMTPSA id 30AEB207BE; Sat, 21 Apr 2018 17:13:03 +0200 (CEST) From: Miquel Raynal To: Gregory Clement , Jason Cooper , Andrew Lunn , Sebastian Hesselbarth , Zhang Rui , Eduardo Valentin Subject: [PATCH 06/27] thermal: armada: average over samples to avoid glitches Date: Sat, 21 Apr 2018 17:12:34 +0200 Message-Id: <20180421151255.29929-7-miquel.raynal@bootlin.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20180421151255.29929-1-miquel.raynal@bootlin.com> References: <20180421151255.29929-1-miquel.raynal@bootlin.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180421_081332_903030_AFCF28D1 X-CRM114-Status: GOOD ( 14.73 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, linux-pm@vger.kernel.org, Antoine Tenart , Catalin Marinas , Will Deacon , Maxime Chevallier , Nadav Haklai , David Sniatkiwicz , Rob Herring , Thomas Petazzoni , Miquel Raynal , linux-arm-kernel@lists.infradead.org MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Configure the sample frequency and number of averaged samples. This is needed for two reasons: 1/ To be bootloader independent. 2/ To prepare the introduction of multi-sensors support by preventing inconsistencies when reading temperatures that could be a mean of samples took from different sensors. Signed-off-by: Miquel Raynal --- drivers/thermal/armada_thermal.c | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c index 9291ea3ad2f7..1f9706d96a0d 100644 --- a/drivers/thermal/armada_thermal.c +++ b/drivers/thermal/armada_thermal.c @@ -54,7 +54,12 @@ #define CONTROL0_TSEN_START BIT(0) #define CONTROL0_TSEN_RESET BIT(1) #define CONTROL0_TSEN_ENABLE BIT(2) +#define CONTROL0_TSEN_AVG_BYPASS BIT(6) +#define CONTROL0_TSEN_OSR_SHIFT 24 +#define CONTROL0_TSEN_OSR_MAX 0x3 +#define CONTROL1_TSEN_AVG_SHIFT 0 +#define CONTROL1_TSEN_AVG_MASK 0x7 #define CONTROL1_EXT_TSEN_SW_RESET BIT(7) #define CONTROL1_EXT_TSEN_HW_RESETn BIT(8) @@ -194,6 +199,13 @@ static void armada_ap806_init(struct platform_device *pdev, reg = readl_relaxed(priv->control0); reg &= ~CONTROL0_TSEN_RESET; reg |= CONTROL0_TSEN_START | CONTROL0_TSEN_ENABLE; + + /* Sample every ~2ms */ + reg |= CONTROL0_TSEN_OSR_MAX << CONTROL0_TSEN_OSR_SHIFT; + + /* Enable average (2 samples by default) */ + reg &= ~CONTROL0_TSEN_AVG_BYPASS; + writel(reg, priv->control0); /* Wait the sensors to be valid or the core will warn the user */ @@ -203,7 +215,20 @@ static void armada_ap806_init(struct platform_device *pdev, static void armada_cp110_init(struct platform_device *pdev, struct armada_thermal_priv *priv) { + u32 reg; + armada380_init(pdev, priv); + + /* Sample every ~2ms */ + reg = readl_relaxed(priv->control0); + reg |= CONTROL0_TSEN_OSR_MAX << CONTROL0_TSEN_OSR_SHIFT; + writel(reg, priv->control0); + + /* Average the output value over 2^1 = 2 samples */ + reg = readl_relaxed(priv->control1); + reg &= ~CONTROL1_TSEN_AVG_MASK << CONTROL1_TSEN_AVG_SHIFT; + reg |= 1 << CONTROL1_TSEN_AVG_SHIFT; + writel(reg, priv->control1); } static bool armada_is_valid(struct armada_thermal_priv *priv)