From patchwork Thu Dec 14 10:30:09 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Miquel Raynal X-Patchwork-Id: 10111777 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 9B783602C2 for ; Thu, 14 Dec 2017 10:30:34 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 836A2212DB for ; Thu, 14 Dec 2017 10:30:34 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7825428A06; Thu, 14 Dec 2017 10:30: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=-6.9 required=2.0 tests=BAYES_00,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 1F6E829A7F for ; Thu, 14 Dec 2017 10:30:34 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751520AbdLNKac (ORCPT ); Thu, 14 Dec 2017 05:30:32 -0500 Received: from mail.free-electrons.com ([62.4.15.54]:57191 "EHLO mail.free-electrons.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751127AbdLNKaZ (ORCPT ); Thu, 14 Dec 2017 05:30:25 -0500 Received: by mail.free-electrons.com (Postfix, from userid 110) id 51BA820986; Thu, 14 Dec 2017 11:30:23 +0100 (CET) Received: from localhost.localdomain (LStLambert-657-1-97-87.w90-63.abo.wanadoo.fr [90.63.216.87]) by mail.free-electrons.com (Postfix) with ESMTPSA id DF03D20758; Thu, 14 Dec 2017 11:30:22 +0100 (CET) From: Miquel Raynal To: Zhang Rui , Eduardo Valentin , Rob Herring , Mark Rutland , Jason Cooper , Andrew Lunn , Gregory Clement , Sebastian Hesselbarth , Catalin Marinas , Will Deacon Cc: linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Thomas Petazzoni , Antoine Tenart , Nadav Haklai , Miquel Raynal , Baruch Siach , David Sniatkiwicz Subject: [PATCH v3 09/11] thermal: armada: Wait sensors validity before exiting the init callback Date: Thu, 14 Dec 2017 11:30:09 +0100 Message-Id: <20171214103011.24713-10-miquel.raynal@free-electrons.com> X-Mailer: git-send-email 2.11.0 In-Reply-To: <20171214103011.24713-1-miquel.raynal@free-electrons.com> References: <20171214103011.24713-1-miquel.raynal@free-electrons.com> Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The thermal core will check for sensors validity right after the initialization callback has returned. As the initialization routine make a reset, the sensors are not ready immediately and the core spawns an error in the dmesg. Avoid this annoying situation by polling on the validity bit before exiting from these routines. This also avoid the use of blind sleeps. Suggested-by: David Sniatkiwicz Signed-off-by: Miquel Raynal --- drivers/thermal/armada_thermal.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/armada_thermal.c b/drivers/thermal/armada_thermal.c index be141ca53e83..1c4122f7377c 100644 --- a/drivers/thermal/armada_thermal.c +++ b/drivers/thermal/armada_thermal.c @@ -23,6 +23,7 @@ #include #include #include +#include /* Thermal Manager Control and Status Register */ #define PMU_TDC0_SW_RST_MASK (0x1 << 1) @@ -59,6 +60,9 @@ #define CONTROL1_EXT_TSEN_SW_RESET BIT(7) #define CONTROL1_EXT_TSEN_HW_RESETn BIT(8) +#define STATUS_POLL_PERIOD_US 1000 +#define STATUS_POLL_TIMEOUT_US 100000 + struct armada_thermal_data; /* Marvell EBU Thermal Sensor Dev Structure */ @@ -154,6 +158,16 @@ static void armada375_init_sensor(struct platform_device *pdev, msleep(50); } +static void armada_wait_sensor_validity(struct armada_thermal_priv *priv) +{ + u32 reg; + + readl_relaxed_poll_timeout(priv->status, reg, + reg & priv->data->is_valid_bit, + STATUS_POLL_PERIOD_US, + STATUS_POLL_TIMEOUT_US); +} + static void armada380_init_sensor(struct platform_device *pdev, struct armada_thermal_priv *priv) { @@ -163,7 +177,6 @@ static void armada380_init_sensor(struct platform_device *pdev, reg |= CONTROL1_EXT_TSEN_HW_RESETn; reg &= ~CONTROL1_EXT_TSEN_SW_RESET; writel(reg, priv->control1); - msleep(10); /* Set Tsen Tc Trim to correct default value (errata #132698) */ if (priv->control0) { @@ -171,8 +184,10 @@ static void armada380_init_sensor(struct platform_device *pdev, reg &= ~CONTROL0_TSEN_TC_TRIM_MASK; reg |= CONTROL0_TSEN_TC_TRIM_VAL; writel(reg, priv->control0); - msleep(10); } + + /* Wait the sensors to be valid or the core will warn the user */ + armada_wait_sensor_validity(priv); } static void armada_ap806_init_sensor(struct platform_device *pdev, @@ -190,7 +205,9 @@ static void armada_ap806_init_sensor(struct platform_device *pdev, reg &= ~CONTROL0_TSEN_RESET; reg |= CONTROL0_TSEN_START | CONTROL0_TSEN_ENABLE; writel(reg, priv->control0); - msleep(10); + + /* Wait the sensors to be valid or the core will warn the user */ + armada_wait_sensor_validity(priv); } static bool armada_is_valid(struct armada_thermal_priv *priv)