From patchwork Tue May 18 23:43:08 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 12265789 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 4C721C433ED for ; Tue, 18 May 2021 23:43:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2DD0461364 for ; Tue, 18 May 2021 23:43:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237053AbhERXog (ORCPT ); Tue, 18 May 2021 19:44:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39352 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235992AbhERXof (ORCPT ); Tue, 18 May 2021 19:44:35 -0400 Received: from mail-ej1-x62d.google.com (mail-ej1-x62d.google.com [IPv6:2a00:1450:4864:20::62d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B78E4C06175F; Tue, 18 May 2021 16:43:16 -0700 (PDT) Received: by mail-ej1-x62d.google.com with SMTP id et19so10136779ejc.4; Tue, 18 May 2021 16:43:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=U5mKTMQmxEVFJG8UOfkeKjZ+h743hA9emYKF3Ch8SzM=; b=XIpq0m+V4Kvo9Ej7/M6YyR98UcXaTrp/mTf8JNnAN+EGZwNNulqKY6fo8XLO66l0VP gvTJLz1KmoKzjAEk9TXjtlGrCV4HMiomWhFsWZJIdg/yqAEzyeWw8bSV6bEeV6Ph1hCb sf4WrA6g4Sbl+2QyxosI80l9oPiW8r4IM3P4F30fv77JLXWTJlbU+eqGhdcszuxD+mb3 s16ni4x2KSH6JYogXmm+SEcvOY9zZLxQ1H3r+xohtR9pmQ9tPi8XkapXWid2ThJ/w99F yQTBZwXCDmsEkzsdnn5Ak6UgRd4n0yNdvu5sUNfmRNN42mSZNru4+31217jsn1dqTBt/ VWGQ== 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:mime-version:content-transfer-encoding; bh=U5mKTMQmxEVFJG8UOfkeKjZ+h743hA9emYKF3Ch8SzM=; b=rX2Fvp/IMPCPrBTd2xIGT6NV5bSsFnWTBWo0wBt0UvndNJ64p8q56Ygs4IpPD00wJW 2YeRl9zCQV6gwF5cI0aqLG/CICznWsfeZDFt6Oxt28n1HUPlGWpXTmVa0M6tv2pV+9uh y/DfEpY5iPkLL8tJg27aYahloSOe42kbtUDTtTCuKH+8OR/O671sMHi8/cPHaK5+LbMq ziKrGixm9vhXG4k3op5XCvXPp52JciEpXVMigiPq+MxrMdnzF97ouoMVia7mPaWXMdXN l8tvHEDEB6pnSUb7/OliSWHjLbNRE1DupnF6fRbn4qJhlOmeyT8hz2k79NL5vEahhWit y8Cw== X-Gm-Message-State: AOAM532Th2Twf3U9XHhbDfK5lidKHpy7vFSoUK24Wz5NFb6CVSjZXsWb uzaKBJTfxhF63rsens+zcIk= X-Google-Smtp-Source: ABdhPJwLjEeb02TK5+29ocCxmFtlOrcQuMOqbIE3NW9M9jU2buYnEUOgFH8TjPLadgSpKXAnA2QzDQ== X-Received: by 2002:a17:906:f283:: with SMTP id gu3mr8545634ejb.91.1621381395319; Tue, 18 May 2021 16:43:15 -0700 (PDT) Received: from Ansuel-xps.localdomain (93-35-189-2.ip56.fastwebnet.it. [93.35.189.2]) by smtp.googlemail.com with ESMTPSA id bm13sm11220567ejb.75.2021.05.18.16.43.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 16:43:14 -0700 (PDT) From: Ansuel Smith To: Thara Gopinath Cc: Ansuel Smith , Amit Kucheria , Andy Gross , Bjorn Andersson , Zhang Rui , Daniel Lezcano , linux-pm@vger.kernel.org, linux-arm-msm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/3] drivers: thermal: tsens: fix wrong check for tzd in irq handlers Date: Wed, 19 May 2021 01:43:08 +0200 Message-Id: <20210518234309.29014-3-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210518234309.29014-1-ansuelsmth@gmail.com> References: <20210518234309.29014-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org Some device can have some thermal sensor disabled from the factory. The current 2 irq handler functions check all the sensor by default and the check if the sensor was actually registered is wrong. The tzd is actually never set if the registration fail hence the IS_ERR check is wrong. Signed-off-by: Ansuel Smith --- drivers/thermal/qcom/tsens.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index 4c7ebd1d3f9c..b1162e566a70 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -417,7 +417,7 @@ static irqreturn_t tsens_critical_irq_thread(int irq, void *data) const struct tsens_sensor *s = &priv->sensor[i]; u32 hw_id = s->hw_id; - if (IS_ERR(s->tzd)) + if (!s->tzd) continue; if (!tsens_threshold_violated(priv, hw_id, &d)) continue; @@ -467,7 +467,7 @@ static irqreturn_t tsens_irq_thread(int irq, void *data) const struct tsens_sensor *s = &priv->sensor[i]; u32 hw_id = s->hw_id; - if (IS_ERR(s->tzd)) + if (!s->tzd) continue; if (!tsens_threshold_violated(priv, hw_id, &d)) continue; From patchwork Tue May 18 23:43:06 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 12265787 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id EB2A6C433ED for ; Tue, 18 May 2021 23:43:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id CC2DC6112F for ; Tue, 18 May 2021 23:43:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235382AbhERXod (ORCPT ); Tue, 18 May 2021 19:44:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39342 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230114AbhERXod (ORCPT ); Tue, 18 May 2021 19:44:33 -0400 Received: from mail-ej1-x636.google.com (mail-ej1-x636.google.com [IPv6:2a00:1450:4864:20::636]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 34CD4C061573; Tue, 18 May 2021 16:43:14 -0700 (PDT) Received: by mail-ej1-x636.google.com with SMTP id lg14so17197251ejb.9; Tue, 18 May 2021 16:43:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=x6BN/PyTHg0vWjClj6KF7Z9rFUMiX9eq6dsc19wtdr4=; b=n6wyx8OsDzlIlED4O93DtiZhz6eERcfdK3k6vpm3EXg5zXa+1oUGm01Phbrrpzs5E5 qQ3tdtBZEEq8WSlUxVi2s6/MX6K+dRSVOMGlPGRcbCYXmOZ98RF7KLngTJLuRvkRM2bZ DXUJtqfYPDb7zHt8Kyxccd5hrAG/hjvmfISMkpLyhd7prJ5RoLlvljk37X/Sa3VoK94d 9zpcJJs5+jU7YZfoLm7PPZLZt1ZjlfzqMnOl2EFg+vb9QDqLxZdp570J0cascxregwnP ArFOogQv4PVTn1HGagK12A7ksXTgk1dCRcYDClJtElglk+t436DyUbYSrRI0dyEWIq8g eMcw== 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:mime-version :content-transfer-encoding; bh=x6BN/PyTHg0vWjClj6KF7Z9rFUMiX9eq6dsc19wtdr4=; b=OS+eSAbOyDTWXeTOziUkrVex3I0qXPQPajvq9JP8RlqutYtb8ZAt4OTLx3e9WJXClt xdVFnZ6XK65AqrEz5Zf1fyZsu3GcnbV9sagM22QUTzC9cZKescUF55oYkcCxV3+6DmYm H6ZdwF84QdiHO7WslXQl+2w3dxFDi3SF6y2Y90hObEAXmMAqwj4CQLYvC3EGFrIw8UFn E9c5SnNWr4Ueykpj71l6cUPVa96EE8YfvwzAVvuQPcMA+X0EsdXSyU2PtT5e4/u2AvJ6 jBvKnSV2kzqNO/w1KbWqw9Q7tW7FUoycAg0qiBOU7OKFhpdbscDOVoRtg6mYYH8kNDW6 uLJQ== X-Gm-Message-State: AOAM532Sz6+r/efZcgrBOG1LppOWk6Oc0mLZ3II6jAtx+RHSyPGXim6F +SX8y8TuNVnwrQ2HMegID30= X-Google-Smtp-Source: ABdhPJyx4g0eF9jK3jR9GNaW4zcqF2TMglN8q9DN3A6CTzKP9unCmlTL3ltDAQYjzDHsTxzjwkO/DQ== X-Received: by 2002:a17:906:640c:: with SMTP id d12mr8429650ejm.70.1621381392638; Tue, 18 May 2021 16:43:12 -0700 (PDT) Received: from Ansuel-xps.localdomain (93-35-189-2.ip56.fastwebnet.it. [93.35.189.2]) by smtp.googlemail.com with ESMTPSA id bm13sm11220567ejb.75.2021.05.18.16.43.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 16:43:12 -0700 (PDT) From: Ansuel Smith To: Thara Gopinath Cc: Ansuel Smith , Andy Gross , Bjorn Andersson , Amit Kucheria , Zhang Rui , Daniel Lezcano , linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/3] drivers: thermal: tsens: add timeout to get_tem_tsens_valid Date: Wed, 19 May 2021 01:43:06 +0200 Message-Id: <20210518234309.29014-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org The function can loop and lock the system if for whatever reason the bit for the target sensor is NEVER valid. This is the case if a sensor is disabled by the factory and the valid bit is never reported as actually valid. Add a timeout check and exit if a timeout occurs. As this is a very rare condition, handle the timeout only if the first read fails. Signed-off-by: Ansuel Smith --- drivers/thermal/qcom/tsens.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index b1162e566a70..38afde1a599f 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -599,6 +599,7 @@ int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp) int hw_id = s->hw_id; u32 temp_idx = LAST_TEMP_0 + hw_id; u32 valid_idx = VALID_0 + hw_id; + unsigned long timeout; u32 valid; int ret; @@ -607,13 +608,21 @@ int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp) ret = regmap_field_read(priv->rf[valid_idx], &valid); if (ret) return ret; - while (!valid) { - /* Valid bit is 0 for 6 AHB clock cycles. - * At 19.2MHz, 1 AHB clock is ~60ns. - * We should enter this loop very, very rarely. - */ - ndelay(400); - ret = regmap_field_read(priv->rf[valid_idx], &valid); + + if (!valid) { + timeout = jiffies + msecs_to_jiffies(20); + + do { + /* Valid bit is 0 for 6 AHB clock cycles. + * At 19.2MHz, 1 AHB clock is ~60ns. + * We should enter this loop very, very rarely. + */ + ndelay(400); + ret = regmap_field_read(priv->rf[valid_idx], &valid); + if (valid || ret) + break; + } while (!(ret = time_after_eq(jiffies, timeout))); + if (ret) return ret; } From patchwork Tue May 18 23:43:07 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 12265791 X-Patchwork-Delegate: daniel.lezcano@linaro.org Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 6ED4BC43461 for ; Tue, 18 May 2021 23:43:20 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 4217861074 for ; Tue, 18 May 2021 23:43:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237146AbhERXog (ORCPT ); Tue, 18 May 2021 19:44:36 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39344 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230114AbhERXof (ORCPT ); Tue, 18 May 2021 19:44:35 -0400 Received: from mail-ed1-x530.google.com (mail-ed1-x530.google.com [IPv6:2a00:1450:4864:20::530]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 757CBC061573; Tue, 18 May 2021 16:43:15 -0700 (PDT) Received: by mail-ed1-x530.google.com with SMTP id di13so13209018edb.2; Tue, 18 May 2021 16:43:15 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VjYQwQ9/5/A/9HOipl1Xc8ES3BnP3H1XNLdUqpXzYhQ=; b=Z/AjHducSqpAGLVll4DWyqU1Hi227yYS+V5kmV2OGSvlOgN6q21SCjM3jWWqONZ5F1 ipWptuA88u6fwyRu9zqxcm9sNQ1ysfRHG/LCIAmf1aNpkiMUOKfFLrhPbhpCY0DMMZOj bWCzW8m+u6Z/QuLb7HHa2vJkPvUPzn+Rd/ExBheI8Yb32cjiXzTx990AXjWMsaVcmmXG vbCipruJkhCHz4ZwMWGmvoMfsFPzgwbzb7RUl/Ap+HuXqk2UwdBfUFrR8nrIrfQk+y1K mj/W/8MpBDvtidNEw0jeV7KludCT3sSaKL75u1pBDSy5/9p6PqL86c7GO1r2lSTjl9xg noiA== 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:mime-version:content-transfer-encoding; bh=VjYQwQ9/5/A/9HOipl1Xc8ES3BnP3H1XNLdUqpXzYhQ=; b=l4FKW+h9qB3bbxyDjpM4xlmZ5wDXS/2nJc8EBoEel7bh72K77J1Zv89sRAMcOzhu5S x21JoEDTkixSolO5SKQIKr5Qjb6O0c+bAjxA9rg0u+baQqttVCbIZOkapeTSmwFCMTsI j+WlXpQmr2kTiz1J/LTMnKUG/9bzUwZRyAZpW/oQqju9uGJ5RF7npJGcXk6Ie55thQge jPsN/yyeExZcsajZVccse7ldLN6qEzPbVHB7ERjkd6tE9VSEmrngYRRHlpYqQ9UvRVDR yUz7mWJ+/zBOHD4TPsdN31mcECjowpFE/SzrV4SiJC7Pma6JGyQ1VrzQHk2AdHlZAE0S LOlQ== X-Gm-Message-State: AOAM530oz2KQLbIt7VOqzyLxi3BGpTAOLqjVT9c56FenpQBQ3YKOpYAG odum9RaqVxYvopqEdZkkzhoPRtClhuo1zg== X-Google-Smtp-Source: ABdhPJwPVflDMFCOx01/mAVK5h1ssxwhSJiWGQsqrk8qcW7ZtII2zSzFY+Vcbxyt3RxYLxipUchZpw== X-Received: by 2002:a05:6402:19a:: with SMTP id r26mr9772425edv.44.1621381394077; Tue, 18 May 2021 16:43:14 -0700 (PDT) Received: from Ansuel-xps.localdomain (93-35-189-2.ip56.fastwebnet.it. [93.35.189.2]) by smtp.googlemail.com with ESMTPSA id bm13sm11220567ejb.75.2021.05.18.16.43.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 18 May 2021 16:43:13 -0700 (PDT) From: Ansuel Smith To: Thara Gopinath Cc: Robert Marko , Ansuel Smith , Andy Gross , Bjorn Andersson , Amit Kucheria , Zhang Rui , Daniel Lezcano , linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/3] drivers: thermal: tsens: check if crit_int is supported in read_irq_state Date: Wed, 19 May 2021 01:43:07 +0200 Message-Id: <20210518234309.29014-2-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210518234309.29014-1-ansuelsmth@gmail.com> References: <20210518234309.29014-1-ansuelsmth@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org From: Robert Marko Check if crit_int is supported by the current tsens feat and read crit field only if needed or the kernel panic for reading unreadable memory. Signed-off-by: Robert Marko Signed-off-by: Ansuel Smith --- drivers/thermal/qcom/tsens.c | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index 38afde1a599f..27777a05f755 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -325,16 +325,22 @@ static int tsens_read_irq_state(struct tsens_priv *priv, u32 hw_id, ret = regmap_field_read(priv->rf[LOW_INT_MASK_0 + hw_id], &d->low_irq_mask); if (ret) return ret; - ret = regmap_field_read(priv->rf[CRIT_INT_CLEAR_0 + hw_id], - &d->crit_irq_clear); - if (ret) - return ret; - ret = regmap_field_read(priv->rf[CRIT_INT_MASK_0 + hw_id], - &d->crit_irq_mask); - if (ret) - return ret; + if (priv->feat->crit_int) { + ret = regmap_field_read(priv->rf[CRIT_INT_CLEAR_0 + hw_id], + &d->crit_irq_clear); + if (ret) + return ret; + ret = regmap_field_read(priv->rf[CRIT_INT_MASK_0 + hw_id], + &d->crit_irq_mask); + if (ret) + return ret; - d->crit_thresh = tsens_hw_to_mC(s, CRIT_THRESH_0 + hw_id); + d->crit_thresh = tsens_hw_to_mC(s, CRIT_THRESH_0 + hw_id); + } else { + d->crit_irq_clear = 0; + d->crit_irq_mask = 0; + d->crit_thresh = 0; + } } else { /* No mask register on older TSENS */ d->up_irq_mask = 0;