From patchwork Thu Mar 20 20:24:04 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anjelique Melendez X-Patchwork-Id: 14024533 X-Patchwork-Delegate: daniel.lezcano@linaro.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 E16FE229B28 for ; Thu, 20 Mar 2025 20:24:15 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742502258; cv=none; b=MWFn6qHTBt9nnFkR0uB5nbs9EbEoctaWvG6c60QUoPQrVmYORIsQnAVXJblj4iVb+CBjGhLGlfyPvJ4hBJmY7dGi8IsHvO9Ttj+kN+9PnS0TTg/jp7Qiu3/+zu3Fbm6QEwQqeexWnHll+/J8GkZrvaiXqDqBOl70Hrk4YjBuxLg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742502258; c=relaxed/simple; bh=Hm34EcCZY7Nya6IWrGgD3q/+JNM1BPaGd40TDCxo+LM=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gQvsu1fTU3pTUBNNzTPn+JsEsx+rT7FONrn37C3d4BM1eR80dJP2xan/75y1deOWBD2El4u2XporXFyC3M4OwjRqXMNv02mWWkJw1eg7E8zitG9w2F99AyHEPQfsWE27PsVTG7M2aWVJMSZaJkNVP0MtiaJaQ5TMlm4s1zuHcf4= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=CdGX+dfu; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="CdGX+dfu" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52KEIJnH005901 for ; Thu, 20 Mar 2025 20:24:14 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=/E2f4sNa5dJ 1J/+u/sCAiw4E4qFHfywaLempWlQrqbI=; b=CdGX+dfu1or4up/kVTceuigYPa+ PjYTNf1Iodo3P87R2IF7TigyISDQMViNKvOtS3swqAEjAiimVvZk02OPArmZ6aFS 5yV55tekQfWD3mH47JfH6LZ4UC3YPIO3gLShgXzKHjofMbgxPxhBPSMKS9caxOvF yhtU4hj2JnSQq9STT+bqSW6ejDehg4GbyTL54We8YX6k9hxyX+KstjXLmoI5gsUD o/IePWHHD5fBf6FOJhuckrPxcJDeXDcE74C/r7XH2orqIsMGjPGNJi/Ju3eLNXfL giTqTNm3oWnB8/gyGgbGt6H0reE6/LMtCdYkVjo2PiGw4H7PfIs9PegD9FA== Received: from mail-pj1-f70.google.com (mail-pj1-f70.google.com [209.85.216.70]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 45etmc2xau-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 20 Mar 2025 20:24:14 +0000 (GMT) Received: by mail-pj1-f70.google.com with SMTP id 98e67ed59e1d1-2ff7aecba07so1739366a91.2 for ; Thu, 20 Mar 2025 13:24:14 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742502253; x=1743107053; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=/E2f4sNa5dJ1J/+u/sCAiw4E4qFHfywaLempWlQrqbI=; b=iiw3GvWOo9N6I9hXSrhyXXca+pSBPNfzPld0+/xZ3PgMdX020POQmBczF61Tqx/JGF UHCfyt4YX93OyzvFw2Cmxh/NJwlHCsrd39xUkByorTuAR0/dUnsUheaqthUbABvQ2PN+ bUR1ATJWmZiIYJI/zROe6s4ym3EOT3mmQig4bv3lLDz0bQ8AeSA94Z576yf23lYpKk/i jVAbfZcVTZKf73qBKLqF1gYxREG1eVeNRBRxhuL9rkBAZUEvwErFHuRLNq84ArCO+ZgW z6WTYgeiZnt3vKpiQbJX4bUcZtJDQAblIYY74esowqaxVbximagqJGgUsLszoUu3nxxY 7Bjg== X-Forwarded-Encrypted: i=1; AJvYcCWzrPe78BQaZkFSm3itpEdaGVJC/oKPJ7O9fUUsn68b1MXHx0wlFgAnpFNYueGjI2veUjZpG4VRmw==@vger.kernel.org X-Gm-Message-State: AOJu0YxfxGaAT6WHHfuihNKlirUEV1b8ZnfBPzD5mke3FKnDIKZKyOTk eXGZNqzm0yIC/mkU169sbfPYmjmtLfSBQFLokw/UVcFLRsbzd1IcKYbngk0DyEVMe22Ka24/btE SKyn4izDlDkmGmu7v0lOwN7YkjfgyeBQM+HNHK8GsZ5Qe+7uhPV1z0A1NMQ== X-Gm-Gg: ASbGncvzcPanvFxvER8K7CBbrguENtapfLmwDlcPaZ9PG0V9Pul0a5j91+bS2XLEU/k KnZv2eXykn62FffXQl3dwUqIHJ1GcJXg8NwfZEKzOA8ClOHObz3oOVaG+Gyb1hLzRZd8O1erw41 uL5hVsro4+gOjQG4H2X+zHzMgNSZqYlibJ+XZTBXOCpQVNLJYt5/QJnCw6aScCLJ2lTFlcPxHyu yVvyFwzDaEkQ+3Hm0MXZaNEZTel2f5ahdUC5YniLUt3iiHCk95WEWW1JtPcQJEr+PkUjPy0BiCK p/O2kgLmWB/+4r4WpaZXBWHCyVZVJ79Kp1PkfT89X4IT8Goq3tNo8RKlyGYOTsIU69c1otDXhEu 4Etw= X-Received: by 2002:a05:6a00:2d88:b0:736:a7e3:d4ab with SMTP id d2e1a72fcca58-739059457b8mr1274944b3a.5.1742502252889; Thu, 20 Mar 2025 13:24:12 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEcujCC6dIUgoBwEfsAlF9R5NoEtjy+9Vi+GLQJ5dHhBKP3SMyOMLn0UaHxXsQSLcRFSA/W8w== X-Received: by 2002:a05:6a00:2d88:b0:736:a7e3:d4ab with SMTP id d2e1a72fcca58-739059457b8mr1274889b3a.5.1742502252290; Thu, 20 Mar 2025 13:24:12 -0700 (PDT) Received: from hu-amelende-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7390600b9b1sm249308b3a.76.2025.03.20.13.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 13:24:10 -0700 (PDT) From: Anjelique Melendez To: amitk@kernel.org, thara.gopinath@gmail.com, rafael@kernel.org, daniel.lezcano@linaro.org Cc: rui.zhang@intel.com, lukasz.luba@arm.com, david.collins@oss.qualcomm.com, srinivas.kandagatla@linaro.org, stefan.schmidt@linaro.org, quic_tsoni@quicinc.com, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.baryshkov@linaro.org Subject: [PATCH v3 1/5 RESEND] thermal: qcom-spmi-temp-alarm: enable stage 2 shutdown when required Date: Thu, 20 Mar 2025 13:24:04 -0700 Message-Id: <20250320202408.3940777-2-anjelique.melendez@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250320202408.3940777-1-anjelique.melendez@oss.qualcomm.com> References: <20250320202408.3940777-1-anjelique.melendez@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: 1KNn9pxMIVSiiu7gyv_kK_BumhmZHear X-Proofpoint-GUID: 1KNn9pxMIVSiiu7gyv_kK_BumhmZHear X-Authority-Analysis: v=2.4 cv=aMLwqa9m c=1 sm=1 tr=0 ts=67dc796e cx=c_pps a=0uOsjrqzRL749jD1oC5vDA==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=Vs1iUdzkB0EA:10 a=EUspDBNiAAAA:8 a=q_MlTjK-hrb8HEj9cREA:9 a=RVmHIydaz68A:10 a=mQ_c8vxmzFEMiUWkPHU9:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-20_07,2025-03-20_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 spamscore=0 clxscore=1015 phishscore=0 mlxscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 adultscore=0 lowpriorityscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503200131 From: David Collins Certain TEMP_ALARM GEN2 PMIC peripherals need over-temperature stage 2 automatic PMIC partial shutdown to be enabled in order to avoid repeated faults in the event of reaching over-temperature stage 3. Modify the stage 2 shutdown control logic to ensure that stage 2 shutdown is enabled on all affected PMICs. Read the digital major and minor revision registers to identify these PMICs. Signed-off-by: David Collins Signed-off-by: Anjelique Melendez --- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 32 +++++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c index c2d59cbfaea9..b2077ff9fe73 100644 --- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c +++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c @@ -1,6 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2011-2015, 2017, 2020, The Linux Foundation. All rights reserved. + * Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -16,6 +17,7 @@ #include "../thermal_hwmon.h" +#define QPNP_TM_REG_DIG_MINOR 0x00 #define QPNP_TM_REG_DIG_MAJOR 0x01 #define QPNP_TM_REG_TYPE 0x04 #define QPNP_TM_REG_SUBTYPE 0x05 @@ -71,6 +73,7 @@ struct qpnp_tm_chip { struct device *dev; struct thermal_zone_device *tz_dev; unsigned int subtype; + unsigned int dig_revision; long temp; unsigned int thresh; unsigned int stage; @@ -78,6 +81,7 @@ struct qpnp_tm_chip { /* protects .thresh, .stage and chip registers */ struct mutex lock; bool initialized; + bool require_s2_shutdown; struct iio_channel *adc; const long (*temp_map)[THRESH_COUNT][STAGE_COUNT]; @@ -255,7 +259,7 @@ static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip, skip: reg |= chip->thresh; - if (disable_s2_shutdown) + if (disable_s2_shutdown && !chip->require_s2_shutdown) reg |= SHUTDOWN_CTRL1_OVERRIDE_S2; return qpnp_tm_write(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, reg); @@ -350,7 +354,7 @@ static int qpnp_tm_probe(struct platform_device *pdev) { struct qpnp_tm_chip *chip; struct device_node *node; - u8 type, subtype, dig_major; + u8 type, subtype, dig_major, dig_minor; u32 res; int ret, irq; @@ -403,6 +407,30 @@ static int qpnp_tm_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, ret, "could not read dig_major\n"); + ret = qpnp_tm_read(chip, QPNP_TM_REG_DIG_MINOR, &dig_minor); + if (ret < 0) { + dev_err(&pdev->dev, "could not read dig_minor\n"); + return ret; + } + + chip->dig_revision = (dig_major << 8) | dig_minor; + + if (chip->subtype == QPNP_TM_SUBTYPE_GEN2) { + /* + * Check if stage 2 automatic partial shutdown must remain + * enabled to avoid potential repeated faults upon reaching + * over-temperature stage 3. + */ + switch (chip->dig_revision) { + case 0x0001: + case 0x0002: + case 0x0100: + case 0x0101: + chip->require_s2_shutdown = true; + break; + } + } + if (type != QPNP_TM_TYPE || (subtype != QPNP_TM_SUBTYPE_GEN1 && subtype != QPNP_TM_SUBTYPE_GEN2)) { dev_err(&pdev->dev, "invalid type 0x%02x or subtype 0x%02x\n", From patchwork Thu Mar 20 20:24:05 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anjelique Melendez X-Patchwork-Id: 14024534 X-Patchwork-Delegate: daniel.lezcano@linaro.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 E419E22A4FA for ; Thu, 20 Mar 2025 20:24:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742502260; cv=none; b=YdbppgcL0KvqrtPazaDcTxSV7C70E9bYbYcsjj35p+EnyY/BwABGB3i12tbZE3XC5i6Naq5GlKGw7Oa3ueBu5f6JbOfxDBmGDNQMjpr9oXA9PWVen9UIoHfHdChTosOlENg7BYrdvKPEiMKVZqgKq8yLRAhnVkXuPDCv4cyqIDQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742502260; c=relaxed/simple; bh=TERzkLtrEdxdj4VDCvTpsUge5vjFH8TR9OIZ4SAHj0M=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=gXW9YBFiW/m8N1C9uV8P4wYsBZlLczumZzyJXc2KpvKTi9xdT5J1gAUjLMNLpKsFTytcWi5mnyri49F0xvkPcg0GWoKNCxuF6gmcuioJT2dZ4idwHlso/1QZFHzBxKlT52HHnmY7G6s01oRczPRKDTaP6FsTnCSXGRS+e/EfWfo= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=PEMV49ZQ; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="PEMV49ZQ" Received: from pps.filterd (m0279873.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52KEajUQ004912 for ; Thu, 20 Mar 2025 20:24:16 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=oFHi6HPiiob VnYa1RpPQaEiVA5GMEQ/6EX2Jo7SAl8M=; b=PEMV49ZQGBnfuexIE7Sh/xLHhbI cfjqolQsUwy9IdY7Q9QhIrzWIjcUSxn84aMf2sa/lgSR5MI9RnP3mJAkGWVGhsXE qRkSBplCdBexPyWhxmHKj4qzqX5/VjVCkF0DIIWKPOXRUSJ4ex4k8iVXpGAj45ts NlFA85UMKnPojp3qjPO+hJe+15kWWI3bLnBCceduhnkqW59nAZTkqBylUfwniJhk PDIj9qe3ZwrTM76iGz//y6tglAhG205neVu0xbo0aGC4a1lvDQ5KATWAnTg81ES4 r39w1x/rcMUdUL8NKg8E8patSkkMXoWARF6gPX2Xl676dSLXTr2XezG1dew== Received: from mail-pj1-f71.google.com (mail-pj1-f71.google.com [209.85.216.71]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 45gcd1an2s-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 20 Mar 2025 20:24:16 +0000 (GMT) Received: by mail-pj1-f71.google.com with SMTP id 98e67ed59e1d1-2ff798e8c93so1732247a91.2 for ; Thu, 20 Mar 2025 13:24:16 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742502255; x=1743107055; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=oFHi6HPiiobVnYa1RpPQaEiVA5GMEQ/6EX2Jo7SAl8M=; b=PUSel4ab7cEJP0FeGmx8okd2MFNK79Aj6oO2gPQ6fFNd4YnxjvlAwPqa2q4J/WyvKQ L4/37J2MEp3TqXfUPo0BDQS3488oPYUe0dAFGw1w8jiI6pbQ+xrAw7OuQidbUG8gWlcR MzHeYkev75bStqvxDleW+daHmqeOWYBvNKh6iVs8Pk8pGUeHktRc1UmvLqcXY7oubVhw CxmgPIVEDVr4deQkpdPH4X/0i/B/uxtfA3K+QsTHPJqv6ffu5LCKVkcQOabhAWuc70Bl 5YhogvZLuh3J1dvEVAm6CbD+0g/82RyyBG4i95ze1ps3S9ZoBOljE6URw7z6m1xIOFyc jk8g== X-Forwarded-Encrypted: i=1; AJvYcCVt9l3en5BqCuxa4fvMS82nlwN7LeEr5RTFHYE/tIafV6OB1lvGRUxpTqbepZWbz4LLJsUTTKQDGg==@vger.kernel.org X-Gm-Message-State: AOJu0YwG4EadSP0pDco9MuIGXqZAIJDYlRhx8Fhk3nX9h3HNJfG8tbwp q9/bicCyz5+v89lc9Wyqkq4m/znzizapN7/LNoKa+v6aZhE3/ljkHmdw0RgJtcFrclk7shCrLbY VYi2xTJetQ/FqvJPdTInu82JrT1vJ1XuvE6G/c00TvP7u1Lzfhgn8Bu0o99iJVWPBCA== X-Gm-Gg: ASbGncsOmyk8nGZcMUiUfRUk9nJBlonm8Wvk7SL4TOeYFNbI+FgfoCagoOhSGWQwUXs Dznsw/PtOHUnhuv+M6noYG290AuWJ8Mf1QD9qD2fZNiBgY1sLObo1pnlBXV5w2qsqgi0md+cHtf gmBMtCxmfaLFrFXBqK3J02WTi0ETcFyYkggW1wvQujO5CtimLNXGqEjiPBqBgwqxXV6uHwKjqud 2x5XXeIFWjABP++cHVBxTesehohiwQPGoP6u58N6iQgPkJhSTllvliOrxvB6yxt8UMZkQCYzyVl 7rPc8GfoJGhHBS5YoyQ3y/bYbeE2DXSuQBnXlP/7tEBPLUO30gdjJw2VSnpos+ArfNcHVWFKAoE asYU= X-Received: by 2002:a05:6a21:4cc7:b0:1f5:59e5:8ad2 with SMTP id adf61e73a8af0-1fe42f77d23mr1285368637.24.1742502254767; Thu, 20 Mar 2025 13:24:14 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHhV95qI9oD2ZQTx71pqMEjUhaaI2n8WNnUi/DUAHAKOP5r1/rpGHlkwIv9ebewSlncY8Drqg== X-Received: by 2002:a05:6a21:4cc7:b0:1f5:59e5:8ad2 with SMTP id adf61e73a8af0-1fe42f77d23mr1285327637.24.1742502254330; Thu, 20 Mar 2025 13:24:14 -0700 (PDT) Received: from hu-amelende-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7390600b9b1sm249308b3a.76.2025.03.20.13.24.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 13:24:13 -0700 (PDT) From: Anjelique Melendez To: amitk@kernel.org, thara.gopinath@gmail.com, rafael@kernel.org, daniel.lezcano@linaro.org Cc: rui.zhang@intel.com, lukasz.luba@arm.com, david.collins@oss.qualcomm.com, srinivas.kandagatla@linaro.org, stefan.schmidt@linaro.org, quic_tsoni@quicinc.com, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.baryshkov@linaro.org Subject: [PATCH v3 2/5 RESEND] thermal: qcom-spmi-temp-alarm: Add temp alarm data struct based on HW subtype Date: Thu, 20 Mar 2025 13:24:05 -0700 Message-Id: <20250320202408.3940777-3-anjelique.melendez@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250320202408.3940777-1-anjelique.melendez@oss.qualcomm.com> References: <20250320202408.3940777-1-anjelique.melendez@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Authority-Analysis: v=2.4 cv=bfFrUPPB c=1 sm=1 tr=0 ts=67dc7970 cx=c_pps a=UNFcQwm+pnOIJct1K4W+Mw==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=Vs1iUdzkB0EA:10 a=EUspDBNiAAAA:8 a=KKAkSRfTAAAA:8 a=KV_uBXLwT3x28NnhTW4A:9 a=RVmHIydaz68A:10 a=uKXjsCUrEbL0IQVhDsJ9:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-GUID: hp6iuMlqhbHIXxbSwUjl1Lyb0i_oM5Yd X-Proofpoint-ORIG-GUID: hp6iuMlqhbHIXxbSwUjl1Lyb0i_oM5Yd X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-20_07,2025-03-20_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 impostorscore=0 clxscore=1015 suspectscore=0 malwarescore=0 bulkscore=0 mlxlogscore=999 priorityscore=1501 lowpriorityscore=0 mlxscore=0 adultscore=0 phishscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503200131 Currently multiple if/else statements are used in functions to decipher between SPMI temp alarm Gen 1, Gen 2 and Gen 2 Rev 1 functionality. Instead refactor the driver so that SPMI temp alarm chips will have reference to a spmi_temp_alarm_data struct which defines data and function callbacks based on the HW subtype. Signed-off-by: Anjelique Melendez Reviewed-by: Dmitry Baryshkov --- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 107 +++++++++++++------- 1 file changed, 70 insertions(+), 37 deletions(-) diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c index b2077ff9fe73..1cc9369ca9e1 100644 --- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c +++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c @@ -4,6 +4,7 @@ * Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. */ +#include #include #include #include @@ -31,7 +32,6 @@ #define STATUS_GEN1_STAGE_MASK GENMASK(1, 0) #define STATUS_GEN2_STATE_MASK GENMASK(6, 4) -#define STATUS_GEN2_STATE_SHIFT 4 #define SHUTDOWN_CTRL1_OVERRIDE_S2 BIT(6) #define SHUTDOWN_CTRL1_THRESHOLD_MASK GENMASK(1, 0) @@ -68,10 +68,18 @@ static const long temp_map_gen2_v1[THRESH_COUNT][STAGE_COUNT] = { /* Temperature in Milli Celsius reported during stage 0 if no ADC is present */ #define DEFAULT_TEMP 37000 +struct qpnp_tm_chip; + +struct spmi_temp_alarm_data { + const long (*temp_map)[THRESH_COUNT][STAGE_COUNT]; + int (*get_temp_stage)(struct qpnp_tm_chip *chip); +}; + struct qpnp_tm_chip { struct regmap *map; struct device *dev; struct thermal_zone_device *tz_dev; + const struct spmi_temp_alarm_data *data; unsigned int subtype; unsigned int dig_revision; long temp; @@ -82,9 +90,9 @@ struct qpnp_tm_chip { struct mutex lock; bool initialized; bool require_s2_shutdown; + long temp_thresh_map[STAGE_COUNT]; struct iio_channel *adc; - const long (*temp_map)[THRESH_COUNT][STAGE_COUNT]; }; /* This array maps from GEN2 alarm state to GEN1 alarm stage */ @@ -118,20 +126,19 @@ static int qpnp_tm_write(struct qpnp_tm_chip *chip, u16 addr, u8 data) */ static long qpnp_tm_decode_temp(struct qpnp_tm_chip *chip, unsigned int stage) { - if (!chip->temp_map || chip->thresh >= THRESH_COUNT || stage == 0 || - stage > STAGE_COUNT) + if (stage == 0 || stage > STAGE_COUNT) return 0; - return (*chip->temp_map)[chip->thresh][stage - 1]; + return chip->temp_thresh_map[stage - 1]; } /** - * qpnp_tm_get_temp_stage() - return over-temperature stage + * qpnp_tm_gen1_get_temp_stage() - return over-temperature stage * @chip: Pointer to the qpnp_tm chip * - * Return: stage (GEN1) or state (GEN2) on success, or errno on failure. + * Return: stage on success, or errno on failure. */ -static int qpnp_tm_get_temp_stage(struct qpnp_tm_chip *chip) +static int qpnp_tm_gen1_get_temp_stage(struct qpnp_tm_chip *chip) { int ret; u8 reg = 0; @@ -140,12 +147,27 @@ static int qpnp_tm_get_temp_stage(struct qpnp_tm_chip *chip) if (ret < 0) return ret; - if (chip->subtype == QPNP_TM_SUBTYPE_GEN1) - ret = reg & STATUS_GEN1_STAGE_MASK; - else - ret = (reg & STATUS_GEN2_STATE_MASK) >> STATUS_GEN2_STATE_SHIFT; + return FIELD_GET(STATUS_GEN1_STAGE_MASK, reg); +} - return ret; +/** + * qpnp_tm_gen2_get_temp_stage() - return over-temperature stage + * @chip: Pointer to the qpnp_tm chip + * + * Return: stage on success, or errno on failure. + */ +static int qpnp_tm_gen2_get_temp_stage(struct qpnp_tm_chip *chip) +{ + u8 reg = 0; + int ret; + + ret = qpnp_tm_read(chip, QPNP_TM_REG_STATUS, ®); + if (ret < 0) + return ret; + + ret = FIELD_GET(STATUS_GEN2_STATE_MASK, reg); + + return alarm_state_map[ret]; } /* @@ -154,23 +176,16 @@ static int qpnp_tm_get_temp_stage(struct qpnp_tm_chip *chip) */ static int qpnp_tm_update_temp_no_adc(struct qpnp_tm_chip *chip) { - unsigned int stage, stage_new, stage_old; + unsigned int stage_new, stage_old; int ret; WARN_ON(!mutex_is_locked(&chip->lock)); - ret = qpnp_tm_get_temp_stage(chip); + ret = chip->data->get_temp_stage(chip); if (ret < 0) return ret; - stage = ret; - - if (chip->subtype == QPNP_TM_SUBTYPE_GEN1) { - stage_new = stage; - stage_old = chip->stage; - } else { - stage_new = alarm_state_map[stage]; - stage_old = alarm_state_map[chip->stage]; - } + stage_new = ret; + stage_old = chip->stage; if (stage_new > stage_old) { /* increasing stage, use lower bound */ @@ -182,7 +197,7 @@ static int qpnp_tm_update_temp_no_adc(struct qpnp_tm_chip *chip) - TEMP_STAGE_HYSTERESIS; } - chip->stage = stage; + chip->stage = stage_new; return 0; } @@ -222,8 +237,8 @@ static int qpnp_tm_get_temp(struct thermal_zone_device *tz, int *temp) static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip, int temp) { - long stage2_threshold_min = (*chip->temp_map)[THRESH_MIN][1]; - long stage2_threshold_max = (*chip->temp_map)[THRESH_MAX][1]; + long stage2_threshold_min = (*chip->data->temp_map)[THRESH_MIN][1]; + long stage2_threshold_max = (*chip->data->temp_map)[THRESH_MAX][1]; bool disable_s2_shutdown = false; u8 reg; @@ -258,6 +273,8 @@ static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip, } skip: + memcpy(chip->temp_thresh_map, chip->data->temp_map[chip->thresh], + sizeof(chip->temp_thresh_map)); reg |= chip->thresh; if (disable_s2_shutdown && !chip->require_s2_shutdown) reg |= SHUTDOWN_CTRL1_OVERRIDE_S2; @@ -295,6 +312,21 @@ static irqreturn_t qpnp_tm_isr(int irq, void *data) return IRQ_HANDLED; } +static const struct spmi_temp_alarm_data spmi_temp_alarm_data = { + .temp_map = &temp_map_gen1, + .get_temp_stage = qpnp_tm_gen1_get_temp_stage, +}; + +static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_data = { + .temp_map = &temp_map_gen1, + .get_temp_stage = qpnp_tm_gen2_get_temp_stage, +}; + +static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_rev1_data = { + .temp_map = &temp_map_gen2_v1, + .get_temp_stage = qpnp_tm_gen2_get_temp_stage, +}; + /* * This function initializes the internal temp value based on only the * current thermal stage and threshold. Setup threshold control and @@ -302,7 +334,6 @@ static irqreturn_t qpnp_tm_isr(int irq, void *data) */ static int qpnp_tm_init(struct qpnp_tm_chip *chip) { - unsigned int stage; int ret; u8 reg = 0; int crit_temp; @@ -316,16 +347,13 @@ static int qpnp_tm_init(struct qpnp_tm_chip *chip) chip->thresh = reg & SHUTDOWN_CTRL1_THRESHOLD_MASK; chip->temp = DEFAULT_TEMP; - ret = qpnp_tm_get_temp_stage(chip); + ret = chip->data->get_temp_stage(chip); if (ret < 0) goto out; chip->stage = ret; - stage = chip->subtype == QPNP_TM_SUBTYPE_GEN1 - ? chip->stage : alarm_state_map[chip->stage]; - - if (stage) - chip->temp = qpnp_tm_decode_temp(chip, stage); + if (chip->stage) + chip->temp = qpnp_tm_decode_temp(chip, chip->stage); mutex_unlock(&chip->lock); @@ -439,10 +467,15 @@ static int qpnp_tm_probe(struct platform_device *pdev) } chip->subtype = subtype; - if (subtype == QPNP_TM_SUBTYPE_GEN2 && dig_major >= 1) - chip->temp_map = &temp_map_gen2_v1; + + if (subtype == QPNP_TM_SUBTYPE_GEN1) + chip->data = &spmi_temp_alarm_data; + else if (subtype == QPNP_TM_SUBTYPE_GEN2 && dig_major >= 1) + chip->data = &spmi_temp_alarm_gen2_rev1_data; + else if (subtype == QPNP_TM_SUBTYPE_GEN2) + chip->data = &spmi_temp_alarm_gen2_data; else - chip->temp_map = &temp_map_gen1; + return -ENODEV; /* * Register the sensor before initializing the hardware to be able to From patchwork Thu Mar 20 20:24:06 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anjelique Melendez X-Patchwork-Id: 14024535 X-Patchwork-Delegate: daniel.lezcano@linaro.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 EA9AC22A1EF for ; Thu, 20 Mar 2025 20:24:19 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742502261; cv=none; b=ME8xU3iAdBNXM8P0f3WyqsIovDg5Ap7G1cdWD59UOk2E5Zhgu4e8fa6mJ3WTgap+jsijI9RS7vFbcapp5paWg1VodSvihobcQdfx0JvjaP2ulPxJUcVks2apKfSyHbDMmQo56Am1EQ6VqEdRIGqOPd7B65z/36IzVU6JPoOJLsI= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742502261; c=relaxed/simple; bh=DNXVnMOqwb8fWB/J/SIbMZJRwIg2Q5PHwQoBAEHkhoQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=WdDvnwZPN8lfO/WwP/dSdP/Zg5D8HYxyqBmKYUGfBSmkRRnrJaP3mkKhULhVrhIlMJ8XfZJsz+nwI2oMBAvz1oxNu5o4FH3NU6xlnuLglNXUpG7wJLpWFOJhYUzyspjEvLlMy1n9GTNUHIGsOKhhhGPil79o4uq1QrXYzA/oLVk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=IkrbXpeu; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="IkrbXpeu" Received: from pps.filterd (m0279870.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52KE3qcZ005861 for ; Thu, 20 Mar 2025 20:24:19 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=egiacthqZDG pHiFeoWLEDtn1W1SQg/ufELhmV7ySKG4=; b=IkrbXpeuBHQF59MdyRW5Wu4gFjw ii3aId66w7asE94pdj9xS8aBwVe6fCog5kkfMiD/3wiDqzf5e9xAYmebj+xvfT6R wGh48RgphuSzfSUL/XjKumaesGV0Ewf3cSgTSb22MQWygZNkwlmpLncguAPlbgW+ XSrMJEJBmu/r2qj9UMeLD8/i4xC59C1t7IlE9GRo13zZNRhASp/uwO0doOOSy5QC 8PsWXXBmRtCdjEErUFPgAszw3QHZtrCPb5Io4f3/suKiB5kjVXN9ntqaQpvIiyXe QZcKFdid0bCVJkSHmwTMRL7aHun1qQLnLjAvmE07k/fVkvV5f1MyeoyeNkQ== Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 45etmc2xb3-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 20 Mar 2025 20:24:18 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-224192ff68bso15177275ad.1 for ; Thu, 20 Mar 2025 13:24:18 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742502257; x=1743107057; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=egiacthqZDGpHiFeoWLEDtn1W1SQg/ufELhmV7ySKG4=; b=cAzG25flkFQkig3yr2SZGA32wC2txzMfKaGIPJxDDB/NAlTDqNpjZNXPyk+Ha5Q7hD x5u0DOYSGxMtsKUOc7uaJF9d8LYsaANqGw2rJ7YLZSZeDcL4W81w7hPcdQ93/nClRa3l Uex9UUD6L7cZmOVUpYWIoVX+FqyVj8G7bwrY9csBKNyGa2rOGddTxrtz2DZJGIDkLgZz L0BtcGgq0tZMQcA61CFEOgBgfsKM6TB0OgdsgtdzUQ077OTXGO0pEAEFAHn06uNZ/yLb LmrEJjsxwD6GO9YtnNseHrg2nIeNejASS+QTLT3cMS3jPApMKI4kehGy78r3P/qa5WJM fq6A== X-Forwarded-Encrypted: i=1; AJvYcCVN4Z4CsfqMoaev7pyVhJwKhc/u8YQARtrtnqaWJR+CcjsNGJnN6uWTHvdpQRAagZzbuTu2ihh/GQ==@vger.kernel.org X-Gm-Message-State: AOJu0YwWl4bRyv6L7uqq64UUwirIfRvFmTswXfcY+bvMHTy/8V/fk1BE BdmGhLxsJ7HDd2+64aZc8eobLI+MFL+sEvXT2we6JwyIn9C3WIwMzWT+8EEtvjvs1u7w8GaijvD PBRsdLxc8P4k2ya0spo33BvbsskVn3S92D5/7kxm1x+/pFJx34g4IdBOjRw== X-Gm-Gg: ASbGncuUfQzNy84vPXFMn50MbSFLAJKjUf0uTFYlOcAcdv7E6/xb8hOFWlLl795D066 8oIiPtIcKuLF0tDaQOhg+nqIuNVwzDCjeb1l0cSjwHWZcWV2c6sSPpedCEZ54fyzgIZJBeSeZWm qvO48xVQ1J12+JWHU9Do42YDjBMfU1wBEzAQVkac11w1JWJ2M3q/FQ11+mryLinsf8jkXcb/FWP XaPkIg8Wb6b9AHrBTovjjTqC/UdsETYFRxj7ACz0qkKBq2b1qwIr/4klr/uVbyrT0vJIFc857ck CSJSd2NdCvvLd8yj77yaAP5KnJsZpHeGcR/XDZ8ESnNNeJf2lEns7TxT2Drtu/+jfQ1UfkiFeSe +ZU4= X-Received: by 2002:a05:6a00:928f:b0:736:34ff:be7 with SMTP id d2e1a72fcca58-73905a2762cmr1410689b3a.15.1742502256408; Thu, 20 Mar 2025 13:24:16 -0700 (PDT) X-Google-Smtp-Source: AGHT+IH0JgEhdNyGDOq+wE1L4PhVpZdw5furaqQDaL73WBTBB6Ug6C2GuXYFgOxKakNTxeXNINsJsA== X-Received: by 2002:a05:6a00:928f:b0:736:34ff:be7 with SMTP id d2e1a72fcca58-73905a2762cmr1410638b3a.15.1742502255805; Thu, 20 Mar 2025 13:24:15 -0700 (PDT) Received: from hu-amelende-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7390600b9b1sm249308b3a.76.2025.03.20.13.24.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 13:24:15 -0700 (PDT) From: Anjelique Melendez To: amitk@kernel.org, thara.gopinath@gmail.com, rafael@kernel.org, daniel.lezcano@linaro.org Cc: rui.zhang@intel.com, lukasz.luba@arm.com, david.collins@oss.qualcomm.com, srinivas.kandagatla@linaro.org, stefan.schmidt@linaro.org, quic_tsoni@quicinc.com, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.baryshkov@linaro.org Subject: [PATCH v3 3/5 RESEND] thermal: qcom-spmi-temp-alarm: Prepare to support additional Temp Alarm subtypes Date: Thu, 20 Mar 2025 13:24:06 -0700 Message-Id: <20250320202408.3940777-4-anjelique.melendez@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250320202408.3940777-1-anjelique.melendez@oss.qualcomm.com> References: <20250320202408.3940777-1-anjelique.melendez@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: O2LgmGeZB65j3iPSgNyMH9GkreKbU6PQ X-Proofpoint-GUID: O2LgmGeZB65j3iPSgNyMH9GkreKbU6PQ X-Authority-Analysis: v=2.4 cv=aMLwqa9m c=1 sm=1 tr=0 ts=67dc7972 cx=c_pps a=IZJwPbhc+fLeJZngyXXI0A==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=Vs1iUdzkB0EA:10 a=EUspDBNiAAAA:8 a=7un5503AD7E7R8fKnWkA:9 a=RVmHIydaz68A:10 a=uG9DUKGECoFWVXl0Dc02:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-20_07,2025-03-20_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 impostorscore=0 priorityscore=1501 spamscore=0 clxscore=1015 phishscore=0 mlxscore=0 suspectscore=0 malwarescore=0 mlxlogscore=999 bulkscore=0 adultscore=0 lowpriorityscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503200131 In preparation to support newer temp alarm subtypes, add the "ops" and "configure_trip_temps" references to spmi_temp_alarm_data. This will allow for each Temp Alarm subtype to define its own thermal_zone_device_ops and properly configure thermal trip temperature. Signed-off-by: Anjelique Melendez --- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 38 ++++++++++++++------- 1 file changed, 26 insertions(+), 12 deletions(-) diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c index 1cc9369ca9e1..514772e94a28 100644 --- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c +++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c @@ -1,7 +1,7 @@ // SPDX-License-Identifier: GPL-2.0-only /* * Copyright (c) 2011-2015, 2017, 2020, The Linux Foundation. All rights reserved. - * Copyright (c) 2024, Qualcomm Innovation Center, Inc. All rights reserved. + * Copyright (c) 2024-2025, Qualcomm Innovation Center, Inc. All rights reserved. */ #include @@ -71,8 +71,10 @@ static const long temp_map_gen2_v1[THRESH_COUNT][STAGE_COUNT] = { struct qpnp_tm_chip; struct spmi_temp_alarm_data { + const struct thermal_zone_device_ops *ops; const long (*temp_map)[THRESH_COUNT][STAGE_COUNT]; int (*get_temp_stage)(struct qpnp_tm_chip *chip); + int (*configure_trip_temps)(struct qpnp_tm_chip *chip); }; struct qpnp_tm_chip { @@ -312,18 +314,39 @@ static irqreturn_t qpnp_tm_isr(int irq, void *data) return IRQ_HANDLED; } +static int qpnp_tm_configure_trip_temp(struct qpnp_tm_chip *chip) +{ + int crit_temp, ret; + + mutex_unlock(&chip->lock); + + ret = thermal_zone_get_crit_temp(chip->tz_dev, &crit_temp); + if (ret) + crit_temp = THERMAL_TEMP_INVALID; + + mutex_lock(&chip->lock); + + return qpnp_tm_update_critical_trip_temp(chip, crit_temp); +} + static const struct spmi_temp_alarm_data spmi_temp_alarm_data = { + .ops = &qpnp_tm_sensor_ops, .temp_map = &temp_map_gen1, + .configure_trip_temps = qpnp_tm_configure_trip_temp, .get_temp_stage = qpnp_tm_gen1_get_temp_stage, }; static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_data = { + .ops = &qpnp_tm_sensor_ops, .temp_map = &temp_map_gen1, + .configure_trip_temps = qpnp_tm_configure_trip_temp, .get_temp_stage = qpnp_tm_gen2_get_temp_stage, }; static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_rev1_data = { + .ops = &qpnp_tm_sensor_ops, .temp_map = &temp_map_gen2_v1, + .configure_trip_temps = qpnp_tm_configure_trip_temp, .get_temp_stage = qpnp_tm_gen2_get_temp_stage, }; @@ -336,7 +359,6 @@ static int qpnp_tm_init(struct qpnp_tm_chip *chip) { int ret; u8 reg = 0; - int crit_temp; mutex_lock(&chip->lock); @@ -355,15 +377,7 @@ static int qpnp_tm_init(struct qpnp_tm_chip *chip) if (chip->stage) chip->temp = qpnp_tm_decode_temp(chip, chip->stage); - mutex_unlock(&chip->lock); - - ret = thermal_zone_get_crit_temp(chip->tz_dev, &crit_temp); - if (ret) - crit_temp = THERMAL_TEMP_INVALID; - - mutex_lock(&chip->lock); - - ret = qpnp_tm_update_critical_trip_temp(chip, crit_temp); + ret = chip->data->configure_trip_temps(chip); if (ret < 0) goto out; @@ -483,7 +497,7 @@ static int qpnp_tm_probe(struct platform_device *pdev) * before the hardware initialization is completed. */ chip->tz_dev = devm_thermal_of_zone_register( - &pdev->dev, 0, chip, &qpnp_tm_sensor_ops); + &pdev->dev, 0, chip, chip->data->ops); if (IS_ERR(chip->tz_dev)) return dev_err_probe(&pdev->dev, PTR_ERR(chip->tz_dev), "failed to register sensor\n"); From patchwork Thu Mar 20 20:24:07 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anjelique Melendez X-Patchwork-Id: 14024536 X-Patchwork-Delegate: daniel.lezcano@linaro.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 BE0BA22A7F4 for ; Thu, 20 Mar 2025 20:24:20 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742502262; cv=none; b=q63G6wpGEWnKBVbnrTVVUiryZ8YEgNTNHlfjnSP/zwchnK5mNhvB9vLLT2ekPLjVWhYH9eeq1kouc2diKy90DNZbutVEG+3Mq268KDUJ3B3QJlIg4NaxG3cvF1wcoxxOZjCDvUOmKq96MMZmSVyBxfvIGVrZOVOUPj7x/h3s4PY= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742502262; c=relaxed/simple; bh=TXVz2/T0OBMtfqAXnLHMdu8+NX9jjpGzRajAY7ANRI8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=pI0gEHFUgJBqrFd02LsWprDAaimEtoMss6b2w4qzpiNSo92Wopv2EWYVF4+unP7GfhD+UXmn1XDpg5NSPuKV33B4hROYf9we20pr+wcZRcpeQBrg1gQ/H9eqv4mFbK6OI+aG2NUqm4j1mOJ1pT3zuyAzLvF+0rlrNf1PEECD+Fc= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=jvT9iuEc; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="jvT9iuEc" Received: from pps.filterd (m0279872.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52KDhidA022766 for ; Thu, 20 Mar 2025 20:24:20 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=LIlSavennvF SuEJSQHTgSgc2W+NpJOFIMTRCL7znOuc=; b=jvT9iuEcZpzfsvINc4vjXNqvq1t KWTlwJtMO9zyBzBNrG99T02xv+dkCjn0Mn/mH/ddlTN9vWBdXa3a2bFDgyMjP/EV 7pGQMEr0qcBuzU31Yp6u3+XfdT8i1KIYeiYta4i9iMnTCacF9Q3M7gl4DzxFfPrU CmUpNl4eer1A+94cgwajLIymuE/FYYAnpyvyLOnA9t5exylAfgObqS+htZivSXe9 wxWHfkkvQekh36+4XQdfltEJ4dmEb1fNfZIyCfgxCUTmniW8L7Mwor1/kJu3pZnc NuDqAFXehE3/kduyfOp/qqCMZeCTs2uEBsHYOV9ThluR+z3ZEEQdTuMP+ew== Received: from mail-pl1-f199.google.com (mail-pl1-f199.google.com [209.85.214.199]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 45fdmwynph-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 20 Mar 2025 20:24:19 +0000 (GMT) Received: by mail-pl1-f199.google.com with SMTP id d9443c01a7336-2265a09dbfcso30675535ad.0 for ; Thu, 20 Mar 2025 13:24:19 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742502258; x=1743107058; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=LIlSavennvFSuEJSQHTgSgc2W+NpJOFIMTRCL7znOuc=; b=dgC3iBrhjShUci1xRF20M2WPFs1vpZBkReRlIvGKXWWtrtwl9vH3goD7FIWKwC0TnK 9nbcgIYuDxapxcOoLSu86wKjhc3GHbqz5itkl+q0XkRO4B61NnLBon0rxnOmkl8yHCdo nKXwPsVKbM77gzJkzG4NZSv3DNXbUILRlC+wP4y9fdyUuxRoBuSkXwlwMDD5SdYcVUQl 7aT25+0HAdKF78IHR1O0YxUVUZ1mR3doiB0EuAspoieY9Ls0ySYmOFoVwGBAaDcv3U5T BqnXJKMkbT8RGthgV3bcwwEZ0qF2KdWU9i49Qemawtc7oajZMvJLfC1aIpDHreOdzHZE auIQ== X-Forwarded-Encrypted: i=1; AJvYcCUeAX4FTnnga95uBTLNBrgPTaDGJ9luleIpG7OkBxJmHHgD5sENHVN2m1gVi2k2ibaw2mRE1fXAwQ==@vger.kernel.org X-Gm-Message-State: AOJu0Yy44gxySHg5Wpzml7W5+9aBh2b7s6KvEJZ1ZCHMAEBf0lMrF42a kLtvcTDFkzcS6WmnWRwPfFIcvqOQhw+ohsTYPkIsTkXO8PqmEyjEk/6VfJBQqt13JZ9iZnrnafR atGaqjYD+cIEx/OpNcbkN+sZBd4PjhqhaptCbFO0TdbqBgZkH5DdLEXltsw== X-Gm-Gg: ASbGncsQggDc7ldUkcdYRAbPXj3f5q6g/rSBTVuGF+LDTlRxIHUwGYCiatLX4z/SY5/ dU76rr2sUd4YPBySajQrUIRGHpGVcVWa1JSnOonyoLMS5rq7HLWYFwGNbsqpDetpk0uvx3iIcG/ TZcDyJ0lj/iS6gjujzewjN2q0H+EhXvpphzAj3yopV801Egl5eKoq4UKA+4vfTaJwr/h216T1NR bJBchhSlUZw5qRI0flBlR8N1GIXXtu+Rh+lz/47ay5WThy/6216a415uM9LrV9OIY/WtwBcJ5+B ml11AVh9M3kyPORLy4I2BigVt7Fef+uodmfo+MWx531YXImzYamJZkM3hvYW57y+sfh+TD0WfBO Uh2E= X-Received: by 2002:a05:6a00:170b:b0:737:6e1f:29da with SMTP id d2e1a72fcca58-73905a3599dmr1226246b3a.21.1742502258230; Thu, 20 Mar 2025 13:24:18 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHgE0enSGH32lM0/bmbQoILyWmukGtAIJ78rW2WC9ZP+ZuRQNv75+CTGAlMDQjKvLzb755TNg== X-Received: by 2002:a05:6a00:170b:b0:737:6e1f:29da with SMTP id d2e1a72fcca58-73905a3599dmr1226182b3a.21.1742502257634; Thu, 20 Mar 2025 13:24:17 -0700 (PDT) Received: from hu-amelende-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7390600b9b1sm249308b3a.76.2025.03.20.13.24.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 13:24:16 -0700 (PDT) From: Anjelique Melendez To: amitk@kernel.org, thara.gopinath@gmail.com, rafael@kernel.org, daniel.lezcano@linaro.org Cc: rui.zhang@intel.com, lukasz.luba@arm.com, david.collins@oss.qualcomm.com, srinivas.kandagatla@linaro.org, stefan.schmidt@linaro.org, quic_tsoni@quicinc.com, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.baryshkov@linaro.org Subject: [PATCH v3 4/5 RESEND] thermal: qcom-spmi-temp-alarm: add support for GEN2 rev 2 PMIC peripherals Date: Thu, 20 Mar 2025 13:24:07 -0700 Message-Id: <20250320202408.3940777-5-anjelique.melendez@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250320202408.3940777-1-anjelique.melendez@oss.qualcomm.com> References: <20250320202408.3940777-1-anjelique.melendez@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: TEQHE54QGXrF23QrNjsyg3sveAGjH73B X-Authority-Analysis: v=2.4 cv=ReKQC0tv c=1 sm=1 tr=0 ts=67dc7973 cx=c_pps a=JL+w9abYAAE89/QcEU+0QA==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=Vs1iUdzkB0EA:10 a=EUspDBNiAAAA:8 a=4OMqYXV_ruVW7JoEK48A:9 a=324X-CrmTo6CU4MGRt3R:22 X-Proofpoint-GUID: TEQHE54QGXrF23QrNjsyg3sveAGjH73B X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-20_07,2025-03-20_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 spamscore=0 bulkscore=0 phishscore=0 suspectscore=0 impostorscore=0 clxscore=1015 mlxscore=0 malwarescore=0 mlxlogscore=999 priorityscore=1501 adultscore=0 lowpriorityscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503200131 Add support for TEMP_ALARM GEN2 PMIC peripherals with digital major revision 2. This revision utilizes individual temp DAC registers to set the threshold temperature for over-temperature stages 1, 2, and 3 instead of a single register to specify a set of thresholds. Signed-off-by: David Collins Signed-off-by: Anjelique Melendez --- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 136 ++++++++++++++++++++ 1 file changed, 136 insertions(+) diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c index 514772e94a28..efd2b6534127 100644 --- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c +++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c @@ -26,6 +26,11 @@ #define QPNP_TM_REG_SHUTDOWN_CTRL1 0x40 #define QPNP_TM_REG_ALARM_CTRL 0x46 +/* TEMP_DAC_STGx registers are only present for TEMP_GEN2 v2.0 */ +#define QPNP_TM_REG_TEMP_DAC_STG1 0x47 +#define QPNP_TM_REG_TEMP_DAC_STG2 0x48 +#define QPNP_TM_REG_TEMP_DAC_STG3 0x49 + #define QPNP_TM_TYPE 0x09 #define QPNP_TM_SUBTYPE_GEN1 0x08 #define QPNP_TM_SUBTYPE_GEN2 0x09 @@ -65,6 +70,25 @@ static const long temp_map_gen2_v1[THRESH_COUNT][STAGE_COUNT] = { #define TEMP_STAGE_HYSTERESIS 2000 +/* + * For TEMP_GEN2 v2.0, TEMP_DAC_STG1/2/3 registers are used to set the threshold + * for each stage independently. + * TEMP_DAC_STG* = 0 --> 80 C + * Each 8 step increase in TEMP_DAC_STG* value corresponds to 5 C (5000 mC). + */ +#define TEMP_DAC_MIN 80000 +#define TEMP_DAC_SCALE_NUM 8 +#define TEMP_DAC_SCALE_DEN 5000 + +#define TEMP_DAC_TEMP_TO_REG(temp) \ + (((temp) - TEMP_DAC_MIN) * TEMP_DAC_SCALE_NUM / TEMP_DAC_SCALE_DEN) +#define TEMP_DAC_REG_TO_TEMP(reg) \ + (TEMP_DAC_MIN + (reg) * TEMP_DAC_SCALE_DEN / TEMP_DAC_SCALE_NUM) + +static const long temp_dac_max[STAGE_COUNT] = { + 119375, 159375, 159375 +}; + /* Temperature in Milli Celsius reported during stage 0 if no ADC is present */ #define DEFAULT_TEMP 37000 @@ -73,6 +97,7 @@ struct qpnp_tm_chip; struct spmi_temp_alarm_data { const struct thermal_zone_device_ops *ops; const long (*temp_map)[THRESH_COUNT][STAGE_COUNT]; + int (*setup)(struct qpnp_tm_chip *chip); int (*get_temp_stage)(struct qpnp_tm_chip *chip); int (*configure_trip_temps)(struct qpnp_tm_chip *chip); }; @@ -88,6 +113,7 @@ struct qpnp_tm_chip { unsigned int thresh; unsigned int stage; unsigned int base; + unsigned int ntrips; /* protects .thresh, .stage and chip registers */ struct mutex lock; bool initialized; @@ -305,6 +331,52 @@ static const struct thermal_zone_device_ops qpnp_tm_sensor_ops = { .set_trip_temp = qpnp_tm_set_trip_temp, }; +static int qpnp_tm_gen2_rev2_set_temp_thresh(struct qpnp_tm_chip *chip, int trip, int temp) +{ + int ret, temp_cfg; + u8 reg; + + if (trip < 0 || trip >= STAGE_COUNT) { + dev_err(chip->dev, "invalid TEMP_DAC trip = %d\n", trip); + return -EINVAL; + } else if (temp < TEMP_DAC_MIN || temp > temp_dac_max[trip]) { + dev_err(chip->dev, "invalid TEMP_DAC temp = %d\n", temp); + return -EINVAL; + } + + reg = TEMP_DAC_TEMP_TO_REG(temp); + temp_cfg = TEMP_DAC_REG_TO_TEMP(reg); + + ret = qpnp_tm_write(chip, QPNP_TM_REG_TEMP_DAC_STG1 + trip, reg); + if (ret < 0) { + dev_err(chip->dev, "TEMP_DAC_STG write failed, ret=%d\n", ret); + return ret; + } + + chip->temp_thresh_map[trip] = temp_cfg; + + return 0; +} + +static int qpnp_tm_gen2_rev2_set_trip_temp(struct thermal_zone_device *tz, + const struct thermal_trip *trip, int temp) +{ + unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv); + struct qpnp_tm_chip *chip = thermal_zone_device_priv(tz); + int ret; + + mutex_lock(&chip->lock); + ret = qpnp_tm_gen2_rev2_set_temp_thresh(chip, trip_index, temp); + mutex_unlock(&chip->lock); + + return ret; +} + +static const struct thermal_zone_device_ops qpnp_tm_gen2_rev2_sensor_ops = { + .get_temp = qpnp_tm_get_temp, + .set_trip_temp = qpnp_tm_gen2_rev2_set_trip_temp, +}; + static irqreturn_t qpnp_tm_isr(int irq, void *data) { struct qpnp_tm_chip *chip = data; @@ -329,6 +401,58 @@ static int qpnp_tm_configure_trip_temp(struct qpnp_tm_chip *chip) return qpnp_tm_update_critical_trip_temp(chip, crit_temp); } +/* Configure TEMP_DAC registers based on DT thermal_zone trips */ +static int qpnp_tm_gen2_rev2_configure_trip_temps_cb(struct thermal_trip *trip, void *data) +{ + struct qpnp_tm_chip *chip = data; + int ret; + + trip->priv = THERMAL_INT_TO_TRIP_PRIV(chip->ntrips); + ret = qpnp_tm_gen2_rev2_set_temp_thresh(chip, chip->ntrips, trip->temperature); + chip->ntrips++; + + return ret; +} + +static int qpnp_tm_gen2_rev2_configure_trip_temps(struct qpnp_tm_chip *chip) +{ + int ret, i; + + ret = thermal_zone_for_each_trip(chip->tz_dev, + qpnp_tm_gen2_rev2_configure_trip_temps_cb, chip); + if (ret < 0) + return ret; + + /* Verify that trips are strictly increasing. */ + for (i = 1; i < STAGE_COUNT; i++) { + if (chip->temp_thresh_map[i] <= chip->temp_thresh_map[i - 1]) { + dev_err(chip->dev, "Threshold %d=%ld <= threshold %d=%ld\n", + i, chip->temp_thresh_map[i], i - 1, + chip->temp_thresh_map[i - 1]); + return -EINVAL; + } + } + + return 0; +} + +/* Read the hardware default TEMP_DAC stage threshold temperatures */ +static int qpnp_tm_gen2_rev2_setup(struct qpnp_tm_chip *chip) +{ + int ret, i; + u8 reg = 0; + + for (i = 0; i < STAGE_COUNT; i++) { + ret = qpnp_tm_read(chip, QPNP_TM_REG_TEMP_DAC_STG1 + i, ®); + if (ret < 0) + return ret; + + chip->temp_thresh_map[i] = TEMP_DAC_REG_TO_TEMP(reg); + } + + return 0; +} + static const struct spmi_temp_alarm_data spmi_temp_alarm_data = { .ops = &qpnp_tm_sensor_ops, .temp_map = &temp_map_gen1, @@ -350,6 +474,13 @@ static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_rev1_data = { .get_temp_stage = qpnp_tm_gen2_get_temp_stage, }; +static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_rev2_data = { + .ops = &qpnp_tm_gen2_rev2_sensor_ops, + .setup = qpnp_tm_gen2_rev2_setup, + .configure_trip_temps = qpnp_tm_gen2_rev2_configure_trip_temps, + .get_temp_stage = qpnp_tm_gen2_get_temp_stage, +}; + /* * This function initializes the internal temp value based on only the * current thermal stage and threshold. Setup threshold control and @@ -484,6 +615,8 @@ static int qpnp_tm_probe(struct platform_device *pdev) if (subtype == QPNP_TM_SUBTYPE_GEN1) chip->data = &spmi_temp_alarm_data; + else if (subtype == QPNP_TM_SUBTYPE_GEN2 && dig_major >= 2) + chip->data = &spmi_temp_alarm_gen2_rev2_data; else if (subtype == QPNP_TM_SUBTYPE_GEN2 && dig_major >= 1) chip->data = &spmi_temp_alarm_gen2_rev1_data; else if (subtype == QPNP_TM_SUBTYPE_GEN2) @@ -491,6 +624,9 @@ static int qpnp_tm_probe(struct platform_device *pdev) else return -ENODEV; + if (chip->data->setup) + chip->data->setup(chip); + /* * Register the sensor before initializing the hardware to be able to * read the trip points. get_temp() returns the default temperature From patchwork Thu Mar 20 20:24:08 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anjelique Melendez X-Patchwork-Id: 14024537 X-Patchwork-Delegate: daniel.lezcano@linaro.org Received: from mx0b-0031df01.pphosted.com (mx0b-0031df01.pphosted.com [205.220.180.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 E778822AE6B for ; Thu, 20 Mar 2025 20:24:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=205.220.180.131 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742502264; cv=none; b=k5uQozMNInQKso0UZZb7L2bUJcQXf2z4YNwlwYA4sFTbSGZaAFngukSCc3IiLRVw+yHcZAwayU29SnlA7F4J3lscmXmLBMXhOKHgdZmix+VudOj4WBTifSIUnBz13YfUdBQuRJRmI6Kyp8XwFZr+ovdwhSYQmBvhUBxzVqH/Mvk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1742502264; c=relaxed/simple; bh=H7KSE1RYrshvUFGJnP3ejIrBqUM1jbXJhYU6mYIyRu8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=UCMs5I8NMzMDF8+/vsoGw9QjBTX2lpkgK3LvH07BrRjD6m1Ru7GNQfhNvfXSH25FuUVzpzFo7h5EAqnms0j5qPcb+PLhwr1K+IrYRxqzT4cEoLs7qBRvhcf5weVS03+3tjUzg0/m4W1GZY/MXZlbwS1DtcN3sktSJg8/6IXNWaE= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com; spf=pass smtp.mailfrom=oss.qualcomm.com; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b=WHDbyOin; arc=none smtp.client-ip=205.220.180.131 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=oss.qualcomm.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=qualcomm.com header.i=@qualcomm.com header.b="WHDbyOin" Received: from pps.filterd (m0279868.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 52KESAnw010963 for ; Thu, 20 Mar 2025 20:24:21 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=qualcomm.com; h= cc:content-transfer-encoding:date:from:in-reply-to:message-id :mime-version:references:subject:to; s=qcppdkim1; bh=uSqnCviNEbU NoXfwtDyicmV9Arq/nNUqt1uGmYnbL+A=; b=WHDbyOiniykYbGVwSn84UcNhkkG T34xxDv38XdC9eXB1JJbHovlpiHXIAo1X4ABpO9Cebln3EzKJztFB6fEbqSVMcNU eobuK/nHRYGW+/sDuMeN73ubeqlV+9yrG+B5m0Ysk7pxaxzI8w4sildGF8mzIZAs CR2MlpPEpSre0lg+M+I7j473N7lDoz7pNHqQckG9ypk7JOjW9uczIQGXkfFpK1wf IFQ/fqWrRVjpfvDpN63JdGOlSz7k/tVCfYlMiChLorjOEIncIW9JxEYV6sEgHA2F Zgz1Nl/9hGpRZfzLaskIxF9i2nRusTeiIWDDudQevB35/wRyfRy4x7Mu7Ig== Received: from mail-pl1-f200.google.com (mail-pl1-f200.google.com [209.85.214.200]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 45fd1dqm5u-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 20 Mar 2025 20:24:21 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-225429696a9so26078255ad.1 for ; Thu, 20 Mar 2025 13:24:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1742502260; x=1743107060; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=uSqnCviNEbUNoXfwtDyicmV9Arq/nNUqt1uGmYnbL+A=; b=vCPVoDwL5TQfylUCHHNQVX7vaZD+BkjTIvneze1m5I7k7GWlSo2mpPy5tLb5i7W5em Ew8cMHM4C/pqE8LBXxOOrJE1xlAC8b8SkoL44PZD3gU47Y+6Y5/YVsD+77daoscf0Gwf jK0eEPeLDMuo3+a3alHbhEMIZMWc/eIJUdwieVLE5XqKTgKMlnKkF7tnyD2nKDDNMZ7A bBmWADnqy/fIHA2yBCzcWNIWPl6JKAtZLxdoo0xc+HjVdAtVswYf0y9H0wdxOjhbkCkt gwAhFHCu4HqJQdtnOgTU0eVuiVOXKGe+UqKRgzRyCOrcViL8lDzerXwKQjRmBog8Jrze 1dgw== X-Forwarded-Encrypted: i=1; AJvYcCWQ7dI6sjMsE3Ph7eHzOxvoPO4/dDH7cW7MX8WBQwmISsY+vrYYbeg5HmPFU5Veex3NX4zepeoDGw==@vger.kernel.org X-Gm-Message-State: AOJu0YzGtccAtKnyXij/s1qMw7mCB//Tx9PUIgeEvlWCbyM+AJW1/70c VOQIwBVD81ikZijto7H9DSXxPaXPdocW0k6YbMaAI1ACQKCD6cK2rM7fE6WkC2lhcNc/kCitmO1 OUQMc+pXVih8F1XcCukYfFpVBj7DjnFAvmPu2Z2koUdthC35QUSY+1kLBuw== X-Gm-Gg: ASbGncvSza1+lv86+E8Q3qK2dRoyGRX0YF2rDenEbZS0OSJWvrZc9BW/+EI1SdIlZhb pdAh+fF63WYMIFqIoyuGVeDmMTm98eBr1LYeCHmS32HeJIdJS0JC11+ThXcw5LFdRwnR020yX6F XbE73zfqKBXFNNtfafkcjHjdOcHSqSdu0lrPI2f7uyq5F4Bo2uIEkw7UHEOIVw3rf21dHRkBbHs jza5IhC8fBY+3i1qnW8GuhmUMHnW/vjF3CmFBqk3mD+lvztS2286PWmNY1H45X3VFHqd2o2+HPM upFB1CQxJgqGvYOvYO0Zo0aAW7MTxNxjUl0KUHTyjX9da1yaRxcdrxA82cBeA8FFA8TWdfKn/v4 ipk4= X-Received: by 2002:a05:6a00:240a:b0:735:d89c:4b8e with SMTP id d2e1a72fcca58-7390593b951mr1123648b3a.5.1742502260202; Thu, 20 Mar 2025 13:24:20 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGOYjKbzZttKS9290h39CP47Mhl5hJ/EmNXmP8vThXaSY14c36zQGyLwBI4ub7Dt+C7OW2xmw== X-Received: by 2002:a05:6a00:240a:b0:735:d89c:4b8e with SMTP id d2e1a72fcca58-7390593b951mr1123604b3a.5.1742502259556; Thu, 20 Mar 2025 13:24:19 -0700 (PDT) Received: from hu-amelende-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-7390600b9b1sm249308b3a.76.2025.03.20.13.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 20 Mar 2025 13:24:18 -0700 (PDT) From: Anjelique Melendez To: amitk@kernel.org, thara.gopinath@gmail.com, rafael@kernel.org, daniel.lezcano@linaro.org Cc: rui.zhang@intel.com, lukasz.luba@arm.com, david.collins@oss.qualcomm.com, srinivas.kandagatla@linaro.org, stefan.schmidt@linaro.org, quic_tsoni@quicinc.com, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.baryshkov@linaro.org Subject: [PATCH v3 5/5 RESEND] thermal: qcom-spmi-temp-alarm: add support for LITE PMIC peripherals Date: Thu, 20 Mar 2025 13:24:08 -0700 Message-Id: <20250320202408.3940777-6-anjelique.melendez@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250320202408.3940777-1-anjelique.melendez@oss.qualcomm.com> References: <20250320202408.3940777-1-anjelique.melendez@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-pm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Proofpoint-ORIG-GUID: r0--z48Ha86xkqpm9QXNdTt0ktuoViip X-Proofpoint-GUID: r0--z48Ha86xkqpm9QXNdTt0ktuoViip X-Authority-Analysis: v=2.4 cv=T52MT+KQ c=1 sm=1 tr=0 ts=67dc7975 cx=c_pps a=IZJwPbhc+fLeJZngyXXI0A==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=Vs1iUdzkB0EA:10 a=EUspDBNiAAAA:8 a=47G9NL9pyX4x7Wg37RYA:9 a=uG9DUKGECoFWVXl0Dc02:22 X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1093,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-03-20_07,2025-03-20_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 adultscore=0 impostorscore=0 priorityscore=1501 bulkscore=0 mlxscore=0 clxscore=1015 mlxlogscore=999 lowpriorityscore=0 phishscore=0 spamscore=0 malwarescore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2502280000 definitions=main-2503200131 Add support for TEMP_ALARM LITE PMIC peripherals. This subtype utilizes a pair of registers to configure a warning interrupt threshold temperature and an automatic hardware shutdown threshold temperature. Signed-off-by: David Collins Signed-off-by: Anjelique Melendez --- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 204 +++++++++++++++++++- 1 file changed, 203 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c index efd2b6534127..2547a69dbd07 100644 --- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c +++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c @@ -23,6 +23,7 @@ #define QPNP_TM_REG_TYPE 0x04 #define QPNP_TM_REG_SUBTYPE 0x05 #define QPNP_TM_REG_STATUS 0x08 +#define QPNP_TM_REG_IRQ_STATUS 0x10 #define QPNP_TM_REG_SHUTDOWN_CTRL1 0x40 #define QPNP_TM_REG_ALARM_CTRL 0x46 @@ -30,14 +31,20 @@ #define QPNP_TM_REG_TEMP_DAC_STG1 0x47 #define QPNP_TM_REG_TEMP_DAC_STG2 0x48 #define QPNP_TM_REG_TEMP_DAC_STG3 0x49 +#define QPNP_TM_REG_LITE_TEMP_CFG1 0x50 +#define QPNP_TM_REG_LITE_TEMP_CFG2 0x51 #define QPNP_TM_TYPE 0x09 #define QPNP_TM_SUBTYPE_GEN1 0x08 #define QPNP_TM_SUBTYPE_GEN2 0x09 +#define QPNP_TM_SUBTYPE_LITE 0xC0 #define STATUS_GEN1_STAGE_MASK GENMASK(1, 0) #define STATUS_GEN2_STATE_MASK GENMASK(6, 4) +/* IRQ status only needed for TEMP_ALARM_LITE */ +#define IRQ_STATUS_MASK BIT(0) + #define SHUTDOWN_CTRL1_OVERRIDE_S2 BIT(6) #define SHUTDOWN_CTRL1_THRESHOLD_MASK GENMASK(1, 0) @@ -45,6 +52,8 @@ #define ALARM_CTRL_FORCE_ENABLE BIT(7) +#define LITE_TEMP_CFG_THRESHOLD_MASK GENMASK(3, 2) + #define THRESH_COUNT 4 #define STAGE_COUNT 3 @@ -89,6 +98,19 @@ static const long temp_dac_max[STAGE_COUNT] = { 119375, 159375, 159375 }; +/* + * TEMP_ALARM_LITE has two stages: warning and shutdown with independently + * configured threshold temperatures. + */ + +static const long temp_lite_warning_map[THRESH_COUNT] = { + 115000, 125000, 135000, 145000 +}; + +static const long temp_lite_shutdown_map[THRESH_COUNT] = { + 135000, 145000, 160000, 175000 +}; + /* Temperature in Milli Celsius reported during stage 0 if no ADC is present */ #define DEFAULT_TEMP 37000 @@ -198,6 +220,24 @@ static int qpnp_tm_gen2_get_temp_stage(struct qpnp_tm_chip *chip) return alarm_state_map[ret]; } +/** + * qpnp_tm_lite_get_temp_stage() - return over-temperature stage + * @chip: Pointer to the qpnp_tm chip + * + * Return: alarm interrupt state on success, or errno on failure. + */ +static int qpnp_tm_lite_get_temp_stage(struct qpnp_tm_chip *chip) +{ + u8 reg = 0; + int ret; + + ret = qpnp_tm_read(chip, QPNP_TM_REG_IRQ_STATUS, ®); + if (ret < 0) + return ret; + + return reg & IRQ_STATUS_MASK; +} + /* * This function updates the internal temp value based on the * current thermal stage and threshold as well as the previous stage @@ -377,6 +417,96 @@ static const struct thermal_zone_device_ops qpnp_tm_gen2_rev2_sensor_ops = { .set_trip_temp = qpnp_tm_gen2_rev2_set_trip_temp, }; +static int qpnp_tm_lite_set_temp_thresh(struct qpnp_tm_chip *chip, int trip, int temp) +{ + int ret, temp_cfg, i; + const long *temp_map; + u16 addr; + u8 reg, thresh; + + if (trip < 0 || trip >= STAGE_COUNT) { + dev_err(chip->dev, "invalid TEMP_LITE trip = %d\n", trip); + return -EINVAL; + } + + switch (trip) { + case 0: + temp_map = temp_lite_warning_map; + addr = QPNP_TM_REG_LITE_TEMP_CFG1; + break; + case 1: + /* + * The second trip point is purely in software to facilitate + * a controlled shutdown after the warning threshold is crossed + * but before the automatic hardware shutdown threshold is + * crossed. + */ + return 0; + case 2: + temp_map = temp_lite_shutdown_map; + addr = QPNP_TM_REG_LITE_TEMP_CFG2; + break; + default: + return 0; + } + + if (temp < temp_map[THRESH_MIN] || temp > temp_map[THRESH_MAX]) { + dev_err(chip->dev, "invalid TEMP_LITE temp = %d\n", temp); + return -EINVAL; + } + + thresh = 0; + temp_cfg = temp_map[thresh]; + for (i = THRESH_MAX; i >= THRESH_MIN; i--) { + if (temp >= temp_map[i]) { + thresh = i; + temp_cfg = temp_map[i]; + break; + } + } + + if (temp_cfg == chip->temp_thresh_map[trip]) + return 0; + + ret = qpnp_tm_read(chip, addr, ®); + if (ret < 0) { + dev_err(chip->dev, "LITE_TEMP_CFG read failed, ret=%d\n", ret); + return ret; + } + + reg &= ~LITE_TEMP_CFG_THRESHOLD_MASK; + reg |= FIELD_PREP(LITE_TEMP_CFG_THRESHOLD_MASK, thresh); + + ret = qpnp_tm_write(chip, addr, reg); + if (ret < 0) { + dev_err(chip->dev, "LITE_TEMP_CFG write failed, ret=%d\n", ret); + return ret; + } + + chip->temp_thresh_map[trip] = temp_cfg; + + return 0; +} + +static int qpnp_tm_lite_set_trip_temp(struct thermal_zone_device *tz, + const struct thermal_trip *trip, int temp) +{ + unsigned int trip_index = THERMAL_TRIP_PRIV_TO_INT(trip->priv); + struct qpnp_tm_chip *chip = thermal_zone_device_priv(tz); + int ret; + + mutex_lock(&chip->lock); + ret = qpnp_tm_lite_set_temp_thresh(chip, trip_index, temp); + mutex_unlock(&chip->lock); + + return ret; +} + +static const struct thermal_zone_device_ops qpnp_tm_lite_sensor_ops = { + .get_temp = qpnp_tm_get_temp, + .set_trip_temp = qpnp_tm_lite_set_trip_temp, +}; + static irqreturn_t qpnp_tm_isr(int irq, void *data) { struct qpnp_tm_chip *chip = data; @@ -453,6 +583,68 @@ static int qpnp_tm_gen2_rev2_setup(struct qpnp_tm_chip *chip) return 0; } +/* Configure TEMP_LITE registers based on DT thermal_zone trips */ +static int qpnp_tm_lite_configure_trip_temps_cb(struct thermal_trip *trip, void *data) +{ + struct qpnp_tm_chip *chip = data; + int ret; + + trip->priv = THERMAL_INT_TO_TRIP_PRIV(chip->ntrips); + ret = qpnp_tm_lite_set_temp_thresh(chip, chip->ntrips, trip->temperature); + chip->ntrips++; + + return ret; +} + +static int qpnp_tm_lite_configure_trip_temps(struct qpnp_tm_chip *chip) +{ + int ret; + + ret = thermal_zone_for_each_trip(chip->tz_dev, qpnp_tm_lite_configure_trip_temps_cb, chip); + if (ret < 0) + return ret; + + /* Verify that trips are strictly increasing. */ + if (chip->temp_thresh_map[2] <= chip->temp_thresh_map[0]) { + dev_err(chip->dev, "Threshold 2=%ld <= threshold 0=%ld\n", + chip->temp_thresh_map[2], chip->temp_thresh_map[0]); + return -EINVAL; + } + + return 0; +} + +/* Read the hardware default TEMP_LITE stage threshold temperatures */ +static int qpnp_tm_lite_setup(struct qpnp_tm_chip *chip) +{ + int ret, thresh; + u8 reg = 0; + + /* + * Store the warning trip temp in temp_thresh_map[0] and the shutdown trip + * temp in temp_thresh_map[2]. The second trip point is purely in software + * to facilitate a controlled shutdown after the warning threshold is + * crossed but before the automatic hardware shutdown threshold is + * crossed. Thus, there is no register to read for the second trip + * point. + */ + ret = qpnp_tm_read(chip, QPNP_TM_REG_LITE_TEMP_CFG1, ®); + if (ret < 0) + return ret; + + thresh = FIELD_GET(LITE_TEMP_CFG_THRESHOLD_MASK, reg); + chip->temp_thresh_map[0] = temp_lite_warning_map[thresh]; + + ret = qpnp_tm_read(chip, QPNP_TM_REG_LITE_TEMP_CFG2, ®); + if (ret < 0) + return ret; + + thresh = FIELD_GET(LITE_TEMP_CFG_THRESHOLD_MASK, reg); + chip->temp_thresh_map[2] = temp_lite_shutdown_map[thresh]; + + return 0; +} + static const struct spmi_temp_alarm_data spmi_temp_alarm_data = { .ops = &qpnp_tm_sensor_ops, .temp_map = &temp_map_gen1, @@ -481,6 +673,13 @@ static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_rev2_data = { .get_temp_stage = qpnp_tm_gen2_get_temp_stage, }; +static const struct spmi_temp_alarm_data spmi_temp_alarm_lite_data = { + .ops = &qpnp_tm_lite_sensor_ops, + .setup = qpnp_tm_lite_setup, + .configure_trip_temps = qpnp_tm_lite_configure_trip_temps, + .get_temp_stage = qpnp_tm_lite_get_temp_stage, +}; + /* * This function initializes the internal temp value based on only the * current thermal stage and threshold. Setup threshold control and @@ -605,7 +804,8 @@ static int qpnp_tm_probe(struct platform_device *pdev) } if (type != QPNP_TM_TYPE || (subtype != QPNP_TM_SUBTYPE_GEN1 - && subtype != QPNP_TM_SUBTYPE_GEN2)) { + && subtype != QPNP_TM_SUBTYPE_GEN2 + && subtype != QPNP_TM_SUBTYPE_LITE)) { dev_err(&pdev->dev, "invalid type 0x%02x or subtype 0x%02x\n", type, subtype); return -ENODEV; @@ -621,6 +821,8 @@ static int qpnp_tm_probe(struct platform_device *pdev) chip->data = &spmi_temp_alarm_gen2_rev1_data; else if (subtype == QPNP_TM_SUBTYPE_GEN2) chip->data = &spmi_temp_alarm_gen2_data; + else if (subtype == QPNP_TM_SUBTYPE_LITE) + chip->data = &spmi_temp_alarm_lite_data; else return -ENODEV;