From patchwork Tue Feb 27 16:09:28 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Priyansh Jain X-Patchwork-Id: 207302 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a05:7300:a81b:b0:108:e6aa:91d0 with SMTP id bq27csp2798840dyb; Tue, 27 Feb 2024 08:11:01 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCVwRJjBwBovlal1EjflO9MiVdSTJYxDiraBnPxmZbTILXHqy1y3tnrMtp75a8a8J8SsDa8FNMpIj3f8uyV0qn1azfEPNQ== X-Google-Smtp-Source: AGHT+IEaF6bO2+rdaQlaVTrQqWowTT/LBblnXxCP6Nnp6k4EwIKCD9QQhBTUuyNWKEwrCtKijP/7 X-Received: by 2002:a0c:cb93:0:b0:68f:20b0:5b22 with SMTP id p19-20020a0ccb93000000b0068f20b05b22mr2069972qvk.11.1709050261548; Tue, 27 Feb 2024 08:11:01 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709050261; cv=pass; d=google.com; s=arc-20160816; b=ez6WPShGKVE+2VTGasQF7oz2iCJBFywRyU9zQkKjpeT9eKiUdiw/bIygIiicjBwlfO PwZgExEIDgIgawwiS3J4KnzazwzTsUmOFL4IQSD7pOCQDdMIJdJFHV5/qZSqnAhMBNjH 3QHCacjgyyDD2PkpKwk6uOfewNFWHXS8P8vR9AWkC1l7s5gwqLhSn8MLm5pFjrIH914p qvWHsJMWe+460bbJd3UPC2t/CmGXvfAlzPnF1okz/X5U27qduyyqEKl3K5X5hHTIZKlV zEmoNgPuVmcF8TRkIv2pv5XW5Sr0/d0ePS4vVkPjSIl8uiSA6JtRXUM4iKca++GwG6Ar +EyQ== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :message-id:date:subject:cc:to:from:dkim-signature; bh=W5cStkw2N0yXySR6E2ojMZNdsHwBF2F9TtvVX4tdNoI=; fh=b3N19Ts0yX5N7kGZGf7E4BsKcauuJMh4OkPmxtWBB8c=; b=yrvP6pBgDP/GLO49YPu9MGzdsiqyOOQYljSiXFYNRvxNeFu3X19fUWxIW4Ff51cTls ZQw8gfm6jA9GduYhJ+2krcWmCRuSwjR7Qvc+wQaf8GWlgIgQUE3OalA8PahnrYd8gMnt qaxMZYnczJBnLhvLn7HL+KQOrDdeCjHUDwZJN48GVEAHKTP/EeKTxwhHD8KsKpSzdr2k SlMH3LShWgpI5FGWx6EnifHWVb9uB0xLhBRiVgsYXtgx3tX9CPJYAOPVDe8CIPJZJB3/ tuHLbwZTESTOWs4KWq4RouV+7Avs3/XeS4nvu6sJn5mn9zv7TExI0wBAZLzdGmv9LfpC TsPQ==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Kiy+ndZe; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-83570-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83570-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from ny.mirrors.kernel.org (ny.mirrors.kernel.org. [147.75.199.223]) by mx.google.com with ESMTPS id gf2-20020a056214250200b0068fac70696csi7978523qvb.4.2024.02.27.08.11.01 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 27 Feb 2024 08:11:01 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-83570-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) client-ip=147.75.199.223; Authentication-Results: mx.google.com; dkim=pass header.i=@quicinc.com header.s=qcppdkim1 header.b=Kiy+ndZe; arc=pass (i=1 spf=pass spfdomain=quicinc.com dkim=pass dkdomain=quicinc.com dmarc=pass fromdomain=quicinc.com); spf=pass (google.com: domain of linux-kernel+bounces-83570-ouuuleilei=gmail.com@vger.kernel.org designates 147.75.199.223 as permitted sender) smtp.mailfrom="linux-kernel+bounces-83570-ouuuleilei=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=quicinc.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ny.mirrors.kernel.org (Postfix) with ESMTPS id 8DFB41C23856 for ; Tue, 27 Feb 2024 16:10:21 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id EEE1C148314; Tue, 27 Feb 2024 16:10:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b="Kiy+ndZe" Received: from mx0a-0031df01.pphosted.com (mx0a-0031df01.pphosted.com [205.220.168.131]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id AC9EC146E8D; Tue, 27 Feb 2024 16:10:01 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.168.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709050203; cv=none; b=SFa1e78FdgUXLSWVBwRBT0srbCv0BH+pbr1KnmMAUzJNH2UzCflOhvwsqiZXONHgpeRPdd+MiN62zn72566nBaxUIsNDNAULNfAoxdtRX0KdGebZIu4D34jPVU2Q+hXY2t45F6vtkBBAp+WDf+s+mI3bMe+41qJ2LfL9H5zzuNU= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709050203; c=relaxed/simple; bh=s43zmuKBRFXWcfjaRTyVKFsDV6KAbShwjjA1KIWLInU=; h=From:To:CC:Subject:Date:Message-ID:MIME-Version:Content-Type; b=V/UNjV6hjBr1LdrgBP+urKRJdXbglaAy/QCcXz5wDM66MD1VmNDviKqIeFuoPY6i3v7OHYpTbj1Chqak6aT+HOmOZf70M/Tl813duPWuPMVcrKv2YEa+CJMNeFOB2nGzBH+2QRYz6JLD+pnZvrCWuYEqUHdpvErIBXC4zegUvI0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com; spf=pass smtp.mailfrom=quicinc.com; dkim=pass (2048-bit key) header.d=quicinc.com header.i=@quicinc.com header.b=Kiy+ndZe; arc=none smtp.client-ip=205.220.168.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=quicinc.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=quicinc.com Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.17.1.24/8.17.1.24) with ESMTP id 41REcbd3032078; Tue, 27 Feb 2024 16:09:53 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=quicinc.com; h= from:to:cc:subject:date:message-id:mime-version:content-type; s= qcppdkim1; bh=W5cStkw2N0yXySR6E2ojMZNdsHwBF2F9TtvVX4tdNoI=; b=Ki y+ndZewDiCfentwLV5U5trwW42iIV3jfTpzHv6x0MTJ5Pab5aPbvTnNGSwYCCxQM P+dOGoI3PG0iYeeODEhL5K07cptyJQAY8+M/rUifyB1xW2EKzteAPbD2KRX5C18y qZtEVTH1eWOcyNlAnb09T//SyPMvwpPxudDlVipJJ4MKvVD8z80cVPgQjoO2mFYG +hbs548pHcytOBdCROFdU3Ripv6YDd4h3rGluNmBWMmZyX5gnUIPJMYRSzLMf8Dv q3mw+6Hni4chMGoPuv/VzfCtb9HvM0rrzfo7YXWfqaYOemZR+2gITcFU1PpFGaeT QvgDs60VfBz8K788/aQQ== Received: from nalasppmta03.qualcomm.com (Global_NAT1.qualcomm.com [129.46.96.20]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 3wh85qsjtv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Feb 2024 16:09:53 +0000 (GMT) Received: from nalasex01b.na.qualcomm.com (nalasex01b.na.qualcomm.com [10.47.209.197]) by NALASPPMTA03.qualcomm.com (8.17.1.5/8.17.1.5) with ESMTPS id 41RG9p0L017287 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=NOT); Tue, 27 Feb 2024 16:09:51 GMT Received: from hu-priyjain-hyd.qualcomm.com (10.80.80.8) by nalasex01b.na.qualcomm.com (10.47.209.197) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1118.40; Tue, 27 Feb 2024 08:09:48 -0800 From: Priyansh Jain To: Amit Kucheria , Thara Gopinath , Bjorn Andersson , "Konrad Dybcio" , "Rafael J . Wysocki" , Daniel Lezcano , Zhang Rui , Lukasz Luba , , , CC: , Subject: [PATCH v3] thermal/drivers/tsens: Add suspend to RAM support for tsens Date: Tue, 27 Feb 2024 21:39:28 +0530 Message-ID: <20240227160928.2671-1-quic_priyjain@quicinc.com> X-Mailer: git-send-email 2.17.1 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-ClientProxiedBy: nasanex01a.na.qualcomm.com (10.52.223.231) To nalasex01b.na.qualcomm.com (10.47.209.197) X-QCInternal: smtphost X-Proofpoint-Virus-Version: vendor=nai engine=6200 definitions=5800 signatures=585085 X-Proofpoint-ORIG-GUID: ZuJQTu5RyW5vI437EFPTCjqewwfDqb3K X-Proofpoint-GUID: ZuJQTu5RyW5vI437EFPTCjqewwfDqb3K X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.272,Aquarius:18.0.1011,Hydra:6.0.619,FMLib:17.11.176.26 definitions=2024-02-27_01,2024-02-27_01,2023-05-22_02 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 phishscore=0 malwarescore=0 clxscore=1015 mlxlogscore=956 lowpriorityscore=0 spamscore=0 suspectscore=0 bulkscore=0 mlxscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2402120000 definitions=main-2402270124 X-getmail-retrieved-from-mailbox: INBOX X-GMAIL-THRID: 1788786518017638429 X-GMAIL-MSGID: 1792069087216800872 As part of suspend to RAM, tsens hardware will be turned off. While resume callback, re-initialize tsens hardware. Signed-off-by: Priyansh Jain --- V2 -> V3: Remove suspend callback & interrupt enablement part from resume callback. V1 -> V2: Update commit text to explain the necessity of this patch drivers/thermal/qcom/tsens-v2.c | 1 + drivers/thermal/qcom/tsens.c | 40 +++++++++++++++++++++++++++++++++ drivers/thermal/qcom/tsens.h | 6 +++++ 3 files changed, 47 insertions(+) diff --git a/drivers/thermal/qcom/tsens-v2.c b/drivers/thermal/qcom/tsens-v2.c index 29a61d2d6ca3..0cb7301eca6e 100644 --- a/drivers/thermal/qcom/tsens-v2.c +++ b/drivers/thermal/qcom/tsens-v2.c @@ -107,6 +107,7 @@ static const struct reg_field tsens_v2_regfields[MAX_REGFIELDS] = { static const struct tsens_ops ops_generic_v2 = { .init = init_common, .get_temp = get_temp_tsens_valid, + .resume = tsens_resume_common, }; struct tsens_plat_data data_tsens_v2 = { diff --git a/drivers/thermal/qcom/tsens.c b/drivers/thermal/qcom/tsens.c index 6d7c16ccb44d..396c1cd71351 100644 --- a/drivers/thermal/qcom/tsens.c +++ b/drivers/thermal/qcom/tsens.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include "../thermal_hwmon.h" #include "tsens.h" @@ -1193,6 +1194,45 @@ static int tsens_register_irq(struct tsens_priv *priv, char *irqname, return ret; } +#ifdef CONFIG_SUSPEND +static int tsens_reinit(struct tsens_priv *priv) +{ + unsigned long flags; + + spin_lock_irqsave(&priv->ul_lock, flags); + + /* in VER_0 TSENS need to be explicitly enabled */ + if (tsens_version(priv) == VER_0) + regmap_field_write(priv->rf[TSENS_EN], 1); + + /* + * Re-enable the watchdog, unmask the bark. + * Disable cycle completion monitoring + */ + if (priv->feat->has_watchdog) { + regmap_field_write(priv->rf[WDOG_BARK_MASK], 0); + regmap_field_write(priv->rf[CC_MON_MASK], 1); + } + + /* Re-enable interrupts */ + if (tsens_version(priv) >= VER_0_1) + tsens_enable_irq(priv); + + spin_unlock_irqrestore(&priv->ul_lock, flags); + + return 0; +} + +int tsens_resume_common(struct tsens_priv *priv) +{ + if (pm_suspend_target_state == PM_SUSPEND_MEM) + tsens_reinit(priv); + + return 0; +} + +#endif /* !CONFIG_SUSPEND */ + static int tsens_register(struct tsens_priv *priv) { int i, ret; diff --git a/drivers/thermal/qcom/tsens.h b/drivers/thermal/qcom/tsens.h index cb637fa289ca..7a147d9d8544 100644 --- a/drivers/thermal/qcom/tsens.h +++ b/drivers/thermal/qcom/tsens.h @@ -635,6 +635,12 @@ int init_common(struct tsens_priv *priv); int get_temp_tsens_valid(const struct tsens_sensor *s, int *temp); int get_temp_common(const struct tsens_sensor *s, int *temp); +#ifdef CONFIG_SUSPEND +int tsens_resume_common(struct tsens_priv *priv); +#else +#define tsens_resume_common NULL +#endif + /* TSENS target */ extern struct tsens_plat_data data_8960;