From nobody Tue Oct 7 08:58:28 2025 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 6A4F829ACED for ; Thu, 10 Jul 2025 22:46:00 +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=1752187562; cv=none; b=mEdFmg/2omyUfpuokZKJg/9un9649251ZJB/XteffmVPFvrc4SZh5CLOgM0iS8ZHxos/B9aJtLiA5I7/XtCOHhzzs2NuZcYUjwk5uVIjvQuJ5b1VW38sy9y2mRWF8p7WfiK9tcJiMkC60zu5Ke8eFtGYW2oSZ45uhvGkezOj+2w= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752187562; c=relaxed/simple; bh=/G3yjvmAIVn8+g+OKZB3AzxtfHQGlX8eD13Fl1ZcDVc=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=JwqDUAWEQPwyC7ojjjH17SQ9Wh35+3o5IzHW32/ONTRySkVbXN6ft8nFoMLqaQQh1e2V5zBbTaLiopj1bLSzLPx+5wRSjFZppXgd5kkmCqXWGK24dmzUPjCtGGVQzDfuY4zsCQZM5ooIj8CXwRYF2J/jzaimMd2PckxoWfG2O0k= 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=K3pkjYIp; arc=none smtp.client-ip=205.220.168.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="K3pkjYIp" Received: from pps.filterd (m0279864.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 56AJRYBS031478 for ; Thu, 10 Jul 2025 22:45:59 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=2+Bx4W9mabN GnGAOk9vdoVwnLh7nIUmtj3EmkWbgNNA=; b=K3pkjYIp8d8+u3U3e5+oWQz9k2R WuffzfWkg/YGs7d8nMG3sen+wNdeOFZbN+t6M5WIK3SvrXN87ACzusn5YOyftgUQ hbWfhCiqKiELxgQ8uvtiiNJNS6eWy0w5m3v7YxInF66r31RFiKQt/7iJ0O2d3JYr KCz1RE51UpO7/276rrHBDnPel2p61UpWnad5Q2F10NXWPi4Z89NO0U7wMnBYJRMU K1h1AMzRHRbX88JQOx5U6PyiumCVFvCFVfdaLtqMqZKLW0/unYucI1ZNQ6cZ0HaY Y2Kql93yF67mfBJDj9W9ss/GpLfj5x+JfLETi+6yafhdtC+F4e8FA2Ipvbw== 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 47tkf30fhu-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 10 Jul 2025 22:45:59 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2349fe994a9so12957735ad.1 for ; Thu, 10 Jul 2025 15:45:59 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752187559; x=1752792359; 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=2+Bx4W9mabNGnGAOk9vdoVwnLh7nIUmtj3EmkWbgNNA=; b=ULv4JDOcfJP7i1zmG0PHWV0J9QvvUT9si2Yi7z49YiJRhDf7MJL1RkTvaS9UCYEyFC MA0WRF7ksfH3Xd0lVHe40hMH3iY88EHWuDaPk0U2i3+gr03I077RP+1A+f9j+JYvCiaG K7zS70Mo/6WUswX49Prj13bfP0gtvTiIGeYAPV5m+yIvmlINtdYVqwtexCmY/EjVhmJ4 r+BQJtaa5INdsN6zsGWaWyUtIYOC4MVLcE1nkCnEm8OPw6gqKQX29f0UNfRrbS4VgAwA 47VnpnOzMXIAe/gcLaZCypntoWd2vzmxefUQUsXjmy4d8DPGFr2vFrfYK5xa+o53WZmE UWXQ== X-Forwarded-Encrypted: i=1; AJvYcCXVvY4O7SyZqlBKx8VqGK51lkYQxOZco61pgNd1rQJDwjen9wPVzM07D3GtzOIkONK4PMUtcpBsRV9mTR0=@vger.kernel.org X-Gm-Message-State: AOJu0YwVFgEOCpW/Ndu42FLdaCqUOppWEfULcv2LO5eQXfTbtjs+lzdo DBinzJ7VR6AWFethhfFcyAXfDxy+EXIdl8DWLOtHQqp+vFD5QBKzPNJXcbB2LQnHzmDnlM82oLF xJl34VLQLsLsQmd4yg2k9Q8twyAoll6n9m6uo9gqBFDMFp3h3O3GoXARp42vxN4bG9wM= X-Gm-Gg: ASbGncuj5/RgN83XjOX8xqJKswTnmmneqot8AepIirZZY6XRUTtp2oNEqAOYUABejWh SZpU45xZD4fJCXLJcxNuIx+FCLTLZHtFBnj23sUc+5TzYdZTYWN2votqnT+o3mxCAgWc9xUBilS Nustojh7XYD0/jMsUh32ZxrOuSUMSAWkq1dGYbvJDtm89aVqpyBWdDULshpZ1Tbetua2/5N/ZDt 9qxNEwqadMaVhofexJMdrxgLgpf8XG2GYD4JHtm6CsxOSmVb/aST1/vwgSS99ZZ+xdAq2YYXruS quAw2+wQBBBzwpQuGAfTO31ypJ3ZIhgtDPqgX7wcLEjUCYofjgngK+5yuldFU38B1GW70ssnQEC j7WHaZiTkXqKbNFgthqx4gRonjMU= X-Received: by 2002:a17:903:b8e:b0:237:ec18:ead7 with SMTP id d9443c01a7336-23dee27d2f0mr12009245ad.24.1752187558561; Thu, 10 Jul 2025 15:45:58 -0700 (PDT) X-Google-Smtp-Source: AGHT+IE+kL17WYIoYYBJY3WzQsljLuG5yOgF0j4V2/C1bfca3Lxbq/ar9/HqaY2SNZCXXYtPSrSpiA== X-Received: by 2002:a17:903:b8e:b0:237:ec18:ead7 with SMTP id d9443c01a7336-23dee27d2f0mr12008945ad.24.1752187558101; Thu, 10 Jul 2025 15:45:58 -0700 (PDT) Received: from hu-amelende-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23de4341d51sm30479615ad.189.2025.07.10.15.45.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jul 2025 15:45:57 -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, stefan.schmidt@linaro.org, quic_tsoni@quicinc.com, konrad.dybcio@oss.qualcomm.com, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.baryshkov@linaro.org, dmitry.baryshkov@oss.qualcomm.com Subject: [PATCH v6 1/5] thermal: qcom-spmi-temp-alarm: enable stage 2 shutdown when required Date: Thu, 10 Jul 2025 15:45:51 -0700 Message-Id: <20250710224555.3047790-2-anjelique.melendez@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250710224555.3047790-1-anjelique.melendez@oss.qualcomm.com> References: <20250710224555.3047790-1-anjelique.melendez@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzEwMDE5MSBTYWx0ZWRfXzrmpsll4NuF1 NwkeipieOVzYCv7BlFkgt63alv3IC+8opzRMW3gfP+TpXbV0G17VfdxKMTPycFrT7nFkEgOGMFk Qnp+fhl0ToGpwtfESf2jaMT87jDsPEfrjC0HVtPqH+J59tZSglojq3lzc6akv5K9AbH/ZD8jqlZ FuMyYVvhQfnM6MGICItxpvxNZoC1QgfE0I7xyj94WXHZLtN3y3wG1VI+B+OemJqPWFJ9MV9awbT RNcSVRZYpHxtaJmLyXYNJDXhySBablwt0xL5D8T9/q1GpRbCti6xuwfJJGHjJsgiEViNtosV5Au YPd2+0IrOjOi4Y9MbOu5Xng/vo4eEhuGLvVBPxLlMPEns/p4DcOTb3TUZj2pbwD5YPv4m+DN7O3 73LWohqS19b0ymjMHN1fRuqm8sa+AYqmfL/6iDZb+s8B2pRgGntvBGFiO+2haZDBoov5ccsw X-Proofpoint-GUID: R18P7Vd8B95mTiFtN8_UPZVMFZCxPBEE X-Authority-Analysis: v=2.4 cv=Xuf6OUF9 c=1 sm=1 tr=0 ts=687042a7 cx=c_pps a=IZJwPbhc+fLeJZngyXXI0A==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=Wb1JkmetP80A:10 a=EUspDBNiAAAA:8 a=2ebS6B6wQDVqfW-kuUgA:9 a=uG9DUKGECoFWVXl0Dc02:22 X-Proofpoint-ORIG-GUID: R18P7Vd8B95mTiFtN8_UPZVMFZCxPBEE X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-10_05,2025-07-09_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 suspectscore=0 bulkscore=0 spamscore=0 lowpriorityscore=0 impostorscore=0 clxscore=1015 priorityscore=1501 malwarescore=0 adultscore=0 mlxscore=0 phishscore=0 mlxlogscore=999 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2505280000 definitions=main-2507100191 Content-Type: text/plain; charset="utf-8" From: David Collins Certain TEMP_ALARM GEN2 PMIC peripherals need over-temperature stage 2 automatic PMIC partial shutdown. This will ensure that in the event of reaching the hotter stage 3 over-temperature threshold, repeated faults will be avoided during the automatic PMIC hardware full shutdown. 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 | 43 ++++++++++++++++----- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/= qcom/qcom-spmi-temp-alarm.c index a81e7d6e865f..4b91cc13ce34 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 r= eserved. + * Copyright (c) Qualcomm Technologies, Inc. and/or its subsidiaries. */ =20 #include @@ -16,6 +17,7 @@ =20 #include "../thermal_hwmon.h" =20 +#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 @@ -31,7 +33,7 @@ #define STATUS_GEN2_STATE_MASK GENMASK(6, 4) #define STATUS_GEN2_STATE_SHIFT 4 =20 -#define SHUTDOWN_CTRL1_OVERRIDE_S2 BIT(6) +#define SHUTDOWN_CTRL1_OVERRIDE_STAGE2 BIT(6) #define SHUTDOWN_CTRL1_THRESHOLD_MASK GENMASK(1, 0) =20 #define SHUTDOWN_CTRL1_RATE_25HZ BIT(3) @@ -78,6 +80,7 @@ struct qpnp_tm_chip { /* protects .thresh, .stage and chip registers */ struct mutex lock; bool initialized; + bool require_stage2_shutdown; =20 struct iio_channel *adc; const long (*temp_map)[THRESH_COUNT][STAGE_COUNT]; @@ -220,13 +223,13 @@ static int qpnp_tm_update_critical_trip_temp(struct q= pnp_tm_chip *chip, { long stage2_threshold_min =3D (*chip->temp_map)[THRESH_MIN][1]; long stage2_threshold_max =3D (*chip->temp_map)[THRESH_MAX][1]; - bool disable_s2_shutdown =3D false; + bool disable_stage2_shutdown =3D false; u8 reg; =20 WARN_ON(!mutex_is_locked(&chip->lock)); =20 /* - * Default: S2 and S3 shutdown enabled, thresholds at + * Default: Stage 2 and Stage 3 shutdown enabled, thresholds at * lowest threshold set, monitoring at 25Hz */ reg =3D SHUTDOWN_CTRL1_RATE_25HZ; @@ -241,12 +244,12 @@ static int qpnp_tm_update_critical_trip_temp(struct q= pnp_tm_chip *chip, chip->thresh =3D THRESH_MAX - ((stage2_threshold_max - temp) / TEMP_THRESH_STEP); - disable_s2_shutdown =3D true; + disable_stage2_shutdown =3D true; } else { chip->thresh =3D THRESH_MAX; =20 if (chip->adc) - disable_s2_shutdown =3D true; + disable_stage2_shutdown =3D true; else dev_warn(chip->dev, "No ADC is configured and critical temperature %d mC is above the max= imum stage 2 threshold of %ld mC! Configuring stage 2 shutdown at %ld mC.\n= ", @@ -255,8 +258,8 @@ static int qpnp_tm_update_critical_trip_temp(struct qpn= p_tm_chip *chip, =20 skip: reg |=3D chip->thresh; - if (disable_s2_shutdown) - reg |=3D SHUTDOWN_CTRL1_OVERRIDE_S2; + if (disable_stage2_shutdown && !chip->require_stage2_shutdown) + reg |=3D SHUTDOWN_CTRL1_OVERRIDE_STAGE2; =20 return qpnp_tm_write(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, reg); } @@ -350,8 +353,8 @@ static int qpnp_tm_probe(struct platform_device *pdev) { struct qpnp_tm_chip *chip; struct device_node *node; - u8 type, subtype, dig_major; - u32 res; + u8 type, subtype, dig_major, dig_minor; + u32 res, dig_revision; int ret, irq; =20 node =3D pdev->dev.of_node; @@ -402,6 +405,11 @@ static int qpnp_tm_probe(struct platform_device *pdev) return dev_err_probe(&pdev->dev, ret, "could not read dig_major\n"); =20 + ret =3D qpnp_tm_read(chip, QPNP_TM_REG_DIG_MINOR, &dig_minor); + if (ret < 0) + return dev_err_probe(&pdev->dev, ret, + "could not read dig_minor\n"); + if (type !=3D QPNP_TM_TYPE || (subtype !=3D QPNP_TM_SUBTYPE_GEN1 && subtype !=3D QPNP_TM_SUBTYPE_GEN2)) { dev_err(&pdev->dev, "invalid type 0x%02x or subtype 0x%02x\n", @@ -415,6 +423,23 @@ static int qpnp_tm_probe(struct platform_device *pdev) else chip->temp_map =3D &temp_map_gen1; =20 + if (chip->subtype =3D=3D QPNP_TM_SUBTYPE_GEN2) { + dig_revision =3D (dig_major << 8) | dig_minor; + /* + * Check if stage 2 automatic partial shutdown must remain + * enabled to avoid potential repeated faults upon reaching + * over-temperature stage 3. + */ + switch (dig_revision) { + case 0x0001: + case 0x0002: + case 0x0100: + case 0x0101: + chip->require_stage2_shutdown =3D true; + break; + } + } + /* * Register the sensor before initializing the hardware to be able to * read the trip points. get_temp() returns the default temperature --=20 2.34.1 From nobody Tue Oct 7 08:58:28 2025 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 BE9FD29AB16 for ; Thu, 10 Jul 2025 22:46:02 +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=1752187564; cv=none; b=Jnqo3fTQpEUoZLfip4pKD1Pu6Fa6xOpsdE9qrFpetEUIVOPZ6reF0tlMlrt+z9WNi+8GaRILVnRbIkz3OxnBQvfqmBpaERyNjbjqesm3KNYjmn02AKEnUl52kjGP8TwWhSTXamtfay4U7SUJdZvfK3qv9C0FqK8MJDptaeL2tq0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752187564; c=relaxed/simple; bh=+Eoq5QK+Z4TcLAmXwts6HQBk6+27HKQ9YgXVeCWlpr0=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=L3rANeY3Z+oNUSFNz+bbh1+QYAfRXxFWtAIxjaiqpGzs8MRBVZyhmgMjPDADvhKm6eJ0imDfTJ0QL74YCXYo22HVbje+JCQKdvcWKpREoJsSv7h2ZyyicMUgQSSRsdqs0B0YBss0iO/gPIchXQc+qyX4eSB/NOUB0ah561ui3+0= 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=dGiiBLMy; 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="dGiiBLMy" 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 56AJRZZ2015055 for ; Thu, 10 Jul 2025 22:46:01 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=ZP+qUw1MC4b uspzImbL7NoA9rFA4HkK9harDxg/RzyE=; b=dGiiBLMysYQEf75s1YHzUlBcoZ0 Ahx9uSNit08dpuYoGtX2B5fTHUpH5mdGScGfIkYP9VFfzndIEWvfPofJvXDIX/3U 2ezlkr0j+DFpIoeyhZYmmmc5ZPxpxInjq3ClEamHGIj2dcd8CscY6OXO4NVn+SAH KH+htdXSUQ6PEdUVm8C1tWBw8a0zRcVpUFqbC2ZYgeE4eqV0ZjipcskfDDhcZ9DZ vL7gxMBO004FWSai4Mr/58TXQATtWCVixI125hKaBZe+asWhswJAi2ikEz4d44g4 5bnpen+sO93p3STozS0QRfJsddHcviCloXzNaPsRZB2TRyvH+lvJUpJab/w== Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 47pucna2t1-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 10 Jul 2025 22:46:01 +0000 (GMT) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-235f77f86f6so14153985ad.2 for ; Thu, 10 Jul 2025 15:46:01 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752187560; x=1752792360; 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=ZP+qUw1MC4buspzImbL7NoA9rFA4HkK9harDxg/RzyE=; b=Oz0ZHX15eaWlWomQVNvcgunxnWdAksycLCcapwVepvbUwdpJmf/20mN9ABkcwFmbP+ y31vj1l16/QoMGG0FWJiiMDAWonLkElP7i4tDt1PPeyXZ8TvzsWIxwsSatUHD05+UL4K LmEozrpIc8Lb0WWJDeAf21vS0lBh33aIkQZZQTDix0nnbYh+QU0jD5sFjASAnbaXcDw3 cOadaaL0AZRoXUlUAQNg/XIY1fIketXYWn24XIsomgu5jtiTjkK2e920h1CFxZqIyDF6 QU+XpoSsMYAO1TV/yiiJt1fXTz4DN4WXqB6+XSw0WGtepVWfIrZAs0pldeNeuLW5waRJ tKQA== X-Forwarded-Encrypted: i=1; AJvYcCXbmRj0blbIASHXCP6b7jz6++fUfj04qer6WBvCO++vDrva7rUQ6TZy6JMFyHjW1mKXTOW4CXJe5mz31nk=@vger.kernel.org X-Gm-Message-State: AOJu0YyK+2/cZhyH2PusD8miH7fam1tR2FNLokxegG1xDehlWqDHCdiu I0DU7PuLmxuDSHAGTuLVP6h/3FIlZvPbK0EZgChAuKGQzubcWWmCYRVrDJPK46SIhrRXYdPo0Oi rOINmij0JoOn6/dwO3xqNpHnMAFCsa5V4qFpSPtwIL8LMhNQ3jdGLaSHUQxjhmJt2JZw= X-Gm-Gg: ASbGncu63IoDEOEZxLbQ0siiwL7uZuRwA/FNjwL9Qv5pxQ95i5WWn6DWRG9hfSFWaNP AOvDgHwVWB6qFFTcxoKY+aoSyIyS82h5FycYQIQ/SIVIHuwCOkFwFcIgom5Vy3FB2tExdsz2A9F VI7ifdv00f5gni/S29VCddItFU4E6x4IRMFFO1JBd26SP6ITgpwmP7As40ZSxpG9QffMMIAy9H7 eyXbu62ELtPNNab0ekc4p0F2xKAyx2IE5W6+2+WupYSrFWlzoIJw0eX4BrcMKymRIaEMXLKf6A9 a7BgFa4G3NvVVxiCK6eEtbptqkmbJReojOa6EKwG0vv4ttvesUoeT3nXmTzmTzOdNjVGKGTEy+d Zz6kPS9n6+OmCNSug5GKzgP+hXfM= X-Received: by 2002:a17:903:1a0b:b0:23d:ed96:e2b6 with SMTP id d9443c01a7336-23dee2a09c6mr11931745ad.44.1752187559957; Thu, 10 Jul 2025 15:45:59 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHkENv3EZgXL2V0Tg8YXKutWmikxrgBnK5ws65xd+qPdGWLFXphAye7Sp98D4bIpTFjAkWfGg== X-Received: by 2002:a17:903:1a0b:b0:23d:ed96:e2b6 with SMTP id d9443c01a7336-23dee2a09c6mr11931395ad.44.1752187559492; Thu, 10 Jul 2025 15:45:59 -0700 (PDT) Received: from hu-amelende-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23de4341d51sm30479615ad.189.2025.07.10.15.45.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jul 2025 15:45:58 -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, stefan.schmidt@linaro.org, quic_tsoni@quicinc.com, konrad.dybcio@oss.qualcomm.com, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.baryshkov@linaro.org, dmitry.baryshkov@oss.qualcomm.com Subject: [PATCH v6 2/5] thermal: qcom-spmi-temp-alarm: Add temp alarm data struct based on HW subtype Date: Thu, 10 Jul 2025 15:45:52 -0700 Message-Id: <20250710224555.3047790-3-anjelique.melendez@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250710224555.3047790-1-anjelique.melendez@oss.qualcomm.com> References: <20250710224555.3047790-1-anjelique.melendez@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=GdQXnRXL c=1 sm=1 tr=0 ts=687042a9 cx=c_pps a=cmESyDAEBpBGqyK7t0alAg==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=Wb1JkmetP80A:10 a=EUspDBNiAAAA:8 a=KKAkSRfTAAAA:8 a=3gcoFgraK96GEOzUlygA:9 a=1OuFwYUASf3TG4hYMiVC:22 a=cvBusfyB2V15izCimMoJ:22 X-Proofpoint-GUID: ycs4vAJWYFru_Zj63w2yciT9eYKzRlFB X-Proofpoint-ORIG-GUID: ycs4vAJWYFru_Zj63w2yciT9eYKzRlFB X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzEwMDE5MSBTYWx0ZWRfX+10I9bWOdVMF ZMFOK9fQRGYtoPPXZffatuZ6gmejNT17j8zzBY9/cpAhzKoZHNQfSuWVQWQOQFZypYyBRXATam4 6PoK7ad/RGNIiJgTXfRMRwpUEdI6msO90BKAf/tyWX/HtcA25c1iHcNAr4jYgODUVzYXDfIEXa0 xtnhDe3qfrkCFxCiY9qXL5LmLV48A+GrcWG178RCaHFYf2KHZ11WOwQ6P/RXyY3LPy0y4HKhyuT 9qc2HvYH0DhL9Av7rHO2h4fpKYfwJaVx5kacFZpwOfMz/trSn6C4l6xYXLn1pIWAfhsjplCqB6l lDH+IoA8UracdXbIkTMfckh8KRUrKC1mPsBbYQ5xkvk+aQeOtl9Or0jVJA5ea0DFHFGhP2RKMcS sfJrTPlSqXTy41+TCrS7W7CX1UEVMGPng8L7BS844d9nFhula+HuqIhkUxkVl+TusccB2Utq X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-10_05,2025-07-09_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 adultscore=0 bulkscore=0 clxscore=1015 spamscore=0 suspectscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 malwarescore=0 mlxscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2505280000 definitions=main-2507100191 Content-Type: text/plain; charset="utf-8" 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 | 135 +++++++++++++------- 1 file changed, 88 insertions(+), 47 deletions(-) diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/= qcom/qcom-spmi-temp-alarm.c index 4b91cc13ce34..607838162c7d 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) Qualcomm Technologies, Inc. and/or its subsidiaries. */ =20 +#include #include #include #include @@ -31,7 +32,6 @@ =20 #define STATUS_GEN1_STAGE_MASK GENMASK(1, 0) #define STATUS_GEN2_STATE_MASK GENMASK(6, 4) -#define STATUS_GEN2_STATE_SHIFT 4 =20 #define SHUTDOWN_CTRL1_OVERRIDE_STAGE2 BIT(6) #define SHUTDOWN_CTRL1_THRESHOLD_MASK GENMASK(1, 0) @@ -43,6 +43,12 @@ #define THRESH_COUNT 4 #define STAGE_COUNT 3 =20 +enum overtemp_stage { + STAGE1 =3D 0, + STAGE2, + STAGE3, +}; + /* Over-temperature trip point values in mC */ static const long temp_map_gen1[THRESH_COUNT][STAGE_COUNT] =3D { { 105000, 125000, 145000 }, @@ -68,22 +74,29 @@ static const long temp_map_gen2_v1[THRESH_COUNT][STAGE_= COUNT] =3D { /* Temperature in Milli Celsius reported during stage 0 if no ADC is prese= nt */ #define DEFAULT_TEMP 37000 =20 +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; long temp; - unsigned int thresh; unsigned int stage; unsigned int base; /* protects .thresh, .stage and chip registers */ struct mutex lock; bool initialized; bool require_stage2_shutdown; + long temp_thresh_map[STAGE_COUNT]; =20 struct iio_channel *adc; - const long (*temp_map)[THRESH_COUNT][STAGE_COUNT]; }; =20 /* This array maps from GEN2 alarm state to GEN1 alarm stage */ @@ -117,34 +130,48 @@ static int qpnp_tm_write(struct qpnp_tm_chip *chip, u= 16 addr, u8 data) */ static long qpnp_tm_decode_temp(struct qpnp_tm_chip *chip, unsigned int st= age) { - if (!chip->temp_map || chip->thresh >=3D THRESH_COUNT || stage =3D=3D 0 || - stage > STAGE_COUNT) + if (stage =3D=3D 0 || stage > STAGE_COUNT) return 0; =20 - return (*chip->temp_map)[chip->thresh][stage - 1]; + return chip->temp_thresh_map[stage - 1]; } =20 /** - * 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 =3D 0; + u8 reg; =20 ret =3D qpnp_tm_read(chip, QPNP_TM_REG_STATUS, ®); if (ret < 0) return ret; =20 - if (chip->subtype =3D=3D QPNP_TM_SUBTYPE_GEN1) - ret =3D reg & STATUS_GEN1_STAGE_MASK; - else - ret =3D (reg & STATUS_GEN2_STATE_MASK) >> STATUS_GEN2_STATE_SHIFT; + return FIELD_GET(STATUS_GEN1_STAGE_MASK, reg); +} =20 - 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) +{ + int ret; + u8 reg; + + ret =3D qpnp_tm_read(chip, QPNP_TM_REG_STATUS, ®); + if (ret < 0) + return ret; + + ret =3D FIELD_GET(STATUS_GEN2_STATE_MASK, reg); + + return alarm_state_map[ret]; } =20 /* @@ -153,23 +180,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; =20 WARN_ON(!mutex_is_locked(&chip->lock)); =20 - ret =3D qpnp_tm_get_temp_stage(chip); + ret =3D chip->data->get_temp_stage(chip); if (ret < 0) return ret; - stage =3D ret; - - if (chip->subtype =3D=3D QPNP_TM_SUBTYPE_GEN1) { - stage_new =3D stage; - stage_old =3D chip->stage; - } else { - stage_new =3D alarm_state_map[stage]; - stage_old =3D alarm_state_map[chip->stage]; - } + stage_new =3D ret; + stage_old =3D chip->stage; =20 if (stage_new > stage_old) { /* increasing stage, use lower bound */ @@ -181,7 +201,7 @@ static int qpnp_tm_update_temp_no_adc(struct qpnp_tm_ch= ip *chip) - TEMP_STAGE_HYSTERESIS; } =20 - chip->stage =3D stage; + chip->stage =3D stage_new; =20 return 0; } @@ -221,10 +241,10 @@ static int qpnp_tm_get_temp(struct thermal_zone_devic= e *tz, int *temp) static int qpnp_tm_update_critical_trip_temp(struct qpnp_tm_chip *chip, int temp) { - long stage2_threshold_min =3D (*chip->temp_map)[THRESH_MIN][1]; - long stage2_threshold_max =3D (*chip->temp_map)[THRESH_MAX][1]; + long stage2_threshold_min =3D (*chip->data->temp_map)[THRESH_MIN][STAGE2]; + long stage2_threshold_max =3D (*chip->data->temp_map)[THRESH_MAX][STAGE2]; bool disable_stage2_shutdown =3D false; - u8 reg; + u8 reg, threshold; =20 WARN_ON(!mutex_is_locked(&chip->lock)); =20 @@ -236,17 +256,17 @@ static int qpnp_tm_update_critical_trip_temp(struct q= pnp_tm_chip *chip, =20 if (temp =3D=3D THERMAL_TEMP_INVALID || temp < stage2_threshold_min) { - chip->thresh =3D THRESH_MIN; + threshold =3D THRESH_MIN; goto skip; } =20 if (temp <=3D stage2_threshold_max) { - chip->thresh =3D THRESH_MAX - + threshold =3D THRESH_MAX - ((stage2_threshold_max - temp) / TEMP_THRESH_STEP); disable_stage2_shutdown =3D true; } else { - chip->thresh =3D THRESH_MAX; + threshold =3D THRESH_MAX; =20 if (chip->adc) disable_stage2_shutdown =3D true; @@ -257,7 +277,9 @@ static int qpnp_tm_update_critical_trip_temp(struct qpn= p_tm_chip *chip, } =20 skip: - reg |=3D chip->thresh; + memcpy(chip->temp_thresh_map, chip->data->temp_map[threshold], + sizeof(chip->temp_thresh_map)); + reg |=3D threshold; if (disable_stage2_shutdown && !chip->require_stage2_shutdown) reg |=3D SHUTDOWN_CTRL1_OVERRIDE_STAGE2; =20 @@ -294,6 +316,21 @@ static irqreturn_t qpnp_tm_isr(int irq, void *data) return IRQ_HANDLED; } =20 +static const struct spmi_temp_alarm_data spmi_temp_alarm_data =3D { + .temp_map =3D &temp_map_gen1, + .get_temp_stage =3D qpnp_tm_gen1_get_temp_stage, +}; + +static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_data =3D { + .temp_map =3D &temp_map_gen1, + .get_temp_stage =3D qpnp_tm_gen2_get_temp_stage, +}; + +static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_rev1_data = =3D { + .temp_map =3D &temp_map_gen2_v1, + .get_temp_stage =3D 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 @@ -301,10 +338,10 @@ 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 =3D 0; int crit_temp; + u8 threshold; + int ret; + u8 reg; =20 mutex_lock(&chip->lock); =20 @@ -312,19 +349,19 @@ static int qpnp_tm_init(struct qpnp_tm_chip *chip) if (ret < 0) goto out; =20 - chip->thresh =3D reg & SHUTDOWN_CTRL1_THRESHOLD_MASK; + threshold =3D reg & SHUTDOWN_CTRL1_THRESHOLD_MASK; + memcpy(chip->temp_thresh_map, chip->data->temp_map[threshold], + sizeof(chip->temp_thresh_map)); + chip->temp =3D DEFAULT_TEMP; =20 - ret =3D qpnp_tm_get_temp_stage(chip); + ret =3D chip->data->get_temp_stage(chip); if (ret < 0) goto out; chip->stage =3D ret; =20 - stage =3D chip->subtype =3D=3D QPNP_TM_SUBTYPE_GEN1 - ? chip->stage : alarm_state_map[chip->stage]; - - if (stage) - chip->temp =3D qpnp_tm_decode_temp(chip, stage); + if (chip->stage) + chip->temp =3D qpnp_tm_decode_temp(chip, chip->stage); =20 mutex_unlock(&chip->lock); =20 @@ -418,10 +455,14 @@ static int qpnp_tm_probe(struct platform_device *pdev) } =20 chip->subtype =3D subtype; - if (subtype =3D=3D QPNP_TM_SUBTYPE_GEN2 && dig_major >=3D 1) - chip->temp_map =3D &temp_map_gen2_v1; + if (subtype =3D=3D QPNP_TM_SUBTYPE_GEN1) + chip->data =3D &spmi_temp_alarm_data; + else if (subtype =3D=3D QPNP_TM_SUBTYPE_GEN2 && dig_major =3D=3D 0) + chip->data =3D &spmi_temp_alarm_gen2_data; + else if (subtype =3D=3D QPNP_TM_SUBTYPE_GEN2 && dig_major >=3D 1) + chip->data =3D &spmi_temp_alarm_gen2_rev1_data; else - chip->temp_map =3D &temp_map_gen1; + return -ENODEV; =20 if (chip->subtype =3D=3D QPNP_TM_SUBTYPE_GEN2) { dig_revision =3D (dig_major << 8) | dig_minor; --=20 2.34.1 From nobody Tue Oct 7 08:58:28 2025 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 512472BF015 for ; Thu, 10 Jul 2025 22:46:03 +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=1752187564; cv=none; b=F0ZL72OH/sLoR7tDgKvHiENWxv9mqpIH2eTo/FBLxSrc1QCcYReCDQisHTcFTC3URqJT4qoZwNtsPbOCbQWdevYQHdjrdBe0p4nNeiGeSCSePhhnY6hWldOoRAmnQ1Zl9LJPc6Rs/HfBdeeUFDdT7HnCQx+CJihTZJmwBBfmlNA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752187564; c=relaxed/simple; bh=lPBv04A+toV8WZOdRHfbvwf4kD8BRLqfW18tqoQF3iY=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=ViwEUPKDI0MKYyLFXaq/Hi/7biRL+VzhaOxuexofcgF4ZWUYhbhNGr0TmpfYpchxDFMbDlpIvSQGGdkgtQicfqiRB5whgvtPbJuwyFyR/7P0eBvHEb8tCzLDvHunpjt0MkJqRNuMah/lhWdVv1ZdIJLda1lPm0E/9IvdTqvmWuk= 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=ARYWwwME; arc=none smtp.client-ip=205.220.168.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="ARYWwwME" Received: from pps.filterd (m0279866.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 56AJQrkr032490 for ; Thu, 10 Jul 2025 22:46:02 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=DB4i8v/AasE lbiDrSbyFxUSNsJIeniLxoLg5G/ldTFo=; b=ARYWwwMEGdc57S9AnI05VQtDY3m 2jkEke/lAjRH0szbS7lZYyzskCnS8rN1zW6Pz4P/BHGwxnuS7ieUYS/n0iw4Gl08 /T0F+hjh3OzhQTJQ+RV+CXi7/zkreIkRyE3AfKfCY8vuqeJfGhhVCRUGx7RtBaV7 xmdc/JgKJmf1AwIYMndcJaWhHGaZL0D0uVgUSQe9he2uoCyJwm30LC+mPS2BBVsu BYVdYN6WG483/D4G1XpsfwZOdPbbNtGVD7hYjwTxtGNOE+65d57QB/syYeIiuVak LsSzWIRNLc5wv/x2Lu1r/xk0qX9cMU/KQHFjqh6tyBYznr5eUJeo+6Y54LQ== Received: from mail-pl1-f197.google.com (mail-pl1-f197.google.com [209.85.214.197]) by mx0a-0031df01.pphosted.com (PPS) with ESMTPS id 47r9b17hvp-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 10 Jul 2025 22:46:02 +0000 (GMT) Received: by mail-pl1-f197.google.com with SMTP id d9443c01a7336-23692793178so13227525ad.0 for ; Thu, 10 Jul 2025 15:46:02 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752187561; x=1752792361; 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=DB4i8v/AasElbiDrSbyFxUSNsJIeniLxoLg5G/ldTFo=; b=DftUw4D3vqyKQV+n2YXHjLe+1ltBWm+ZKOf09hkll7YJNnDKN2PwoJCmIGYuHzDcIb XZuXtAKJqsB8VRygdiktibSH4hJjrbMCqsesYKJzUSk45X/cVm4u3pWEQdPoGIfLpYWS Gha4z0tWu094oN7nR+W+ZRRagqY5Gc28QSWOaayKoNQsfrjhC0Fq9NvamP8i2TrRkg9s gxUAAT5ScsNu6g5kpKKhnMbiDVjfdpw9XfH1mYP/GR7zM+xaO1beeFYa7jkdL8rx8l2C QyQzYCnng5rx5b9pNdbT0wA4lAh15zv+64Pps0iisLfZm51RVmbzT2izx6TC+rIEYIKT s3Lw== X-Forwarded-Encrypted: i=1; AJvYcCVwljqt/6qv3/zt6hfVz2W9rLxhqKYEN8qjBGuSQU9aJa9XQcew9uPNW3h05BYv9dOqc/TQDGep0/Qx4zY=@vger.kernel.org X-Gm-Message-State: AOJu0YxTLfDtlUzFjjny3W9PMu09++5Nlp4Sxeo5f2ZPc8Dc5ilMAKq6 BOcocw+hSFUsqkdP7C5mGfBABRVBc1v45LcIrXHg4riuAvvE7YWFdxp2vHBek1+GcVshymn127o 0l/LrIv6oMK9CutJQ31S+lvAnf7NejQ9vFy6LAC2dtXLzSkaqeDmL6HVNKHZUv8AnME4= X-Gm-Gg: ASbGncviOOl0zTcGxoIboLQm0wK1TZWFBRhp1Ehpr79YP3Dp04fIrQdKLkFNH3BB9g/ IaFR0nko5MVS5dLOM24DkBBEfNymT7ZirO/zblQAM1Qk7ukoNx06qwmk6p1eHEEA3c3J1+sUu8N nGcv3rlclPjOe1SnRmFP+puNyTBf7nZNVEU1dEdjjFsFig1BOsPLE+jzUv8jsNfGCSvWJLIViAG TmB4guTP4zj+D9HK/wlywwRwBCC3Ya7BmQt6CqRPKcOCWgOsuj2n2ewlWSdRlIhZutzfY9WELms UyYHGuK2sIxTCYOBI1nSZaKgYcSRB/E4Hxa0OzfZWoz+EkHOUuwX8wJZFbFqW0mmfZsHUVcQ3Z6 nQN9pf6+GOp4ko9y+kOH96XwSeP0= X-Received: by 2002:a17:902:d586:b0:234:909b:3da9 with SMTP id d9443c01a7336-23dede860e5mr13179515ad.27.1752187561321; Thu, 10 Jul 2025 15:46:01 -0700 (PDT) X-Google-Smtp-Source: AGHT+IFWGsHHH3QEMr3onM8+s+jPWCUGCCRaJbbIUFVY5SnFyVHssHV5KFq/OmOLdd94659u73tp7w== X-Received: by 2002:a17:902:d586:b0:234:909b:3da9 with SMTP id d9443c01a7336-23dede860e5mr13179315ad.27.1752187560911; Thu, 10 Jul 2025 15:46:00 -0700 (PDT) Received: from hu-amelende-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23de4341d51sm30479615ad.189.2025.07.10.15.45.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jul 2025 15:46:00 -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, stefan.schmidt@linaro.org, quic_tsoni@quicinc.com, konrad.dybcio@oss.qualcomm.com, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.baryshkov@linaro.org, dmitry.baryshkov@oss.qualcomm.com Subject: [PATCH v6 3/5] thermal: qcom-spmi-temp-alarm: Prepare to support additional Temp Alarm subtypes Date: Thu, 10 Jul 2025 15:45:53 -0700 Message-Id: <20250710224555.3047790-4-anjelique.melendez@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250710224555.3047790-1-anjelique.melendez@oss.qualcomm.com> References: <20250710224555.3047790-1-anjelique.melendez@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=dYuA3WXe c=1 sm=1 tr=0 ts=687042aa cx=c_pps a=cmESyDAEBpBGqyK7t0alAg==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=Wb1JkmetP80A:10 a=EUspDBNiAAAA:8 a=EDJ0a-WMmjN7NLPDzUkA:9 a=1OuFwYUASf3TG4hYMiVC:22 X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzEwMDE5MSBTYWx0ZWRfX6xnbzCc3qubA 8C6irDRIn1TxqbSEC9uncEl1kGl+bmkKJE/obof2bro1lsx3RuiYqDfcUonxmzVuTED2xqtHSvC 5MAk8Dg8Hu+IeP79iNqPNpmLWZtu4VKvxlK/CV+wKKGnKF/FgQp4Eh8qpTowzcjPHZbXEW/PSZf H5cfDmrVnQWbvNfphikjFxgrNE6eVZIcc3TPSZ0qmBkdZkQ9Gpm5xrKRSc+EOLmsYlj5JprvWQw qcAckLoieMbizInWCWeeK/6o0CXGNso6Mq0qUsmsfV540zhNqasMBTmK6C1XAIfOI+dK7QwCWMO YP7grqzEbnyd8YvMlrCV819g0ci55oiLOuKKgp1qkSSPUi+cLYOkjx2XBb0zgsXIE+zFs5OIUpX r59edhynLlFR8jDoYx6HTqwUWQGKNXdlwtSiG16KoLYUa6ZopmLUt+BK3n+S7esGfTyXxlhL X-Proofpoint-GUID: PkcYwzzLDeftFq391nzBck8z6WhMoY_G X-Proofpoint-ORIG-GUID: PkcYwzzLDeftFq391nzBck8z6WhMoY_G X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-10_05,2025-07-09_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 phishscore=0 suspectscore=0 clxscore=1015 impostorscore=0 lowpriorityscore=0 priorityscore=1501 spamscore=0 adultscore=0 mlxlogscore=999 malwarescore=0 mlxscore=0 bulkscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2505280000 definitions=main-2507100191 Content-Type: text/plain; charset="utf-8" In preparation to support newer temp alarm subtypes, add the "ops", "sync_thresholds" 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 initialize and configure thermal trip temperature. Signed-off-by: Anjelique Melendez Acked-by: Konrad Dybcio --- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 92 ++++++++++++++------- 1 file changed, 64 insertions(+), 28 deletions(-) diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/= qcom/qcom-spmi-temp-alarm.c index 607838162c7d..c8e4db585d2b 100644 --- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c +++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c @@ -77,8 +77,11 @@ static const long temp_map_gen2_v1[THRESH_COUNT][STAGE_C= OUNT] =3D { struct qpnp_tm_chip; =20 struct spmi_temp_alarm_data { + const struct thermal_zone_device_ops *ops; const long (*temp_map)[THRESH_COUNT][STAGE_COUNT]; + int (*sync_thresholds)(struct qpnp_tm_chip *chip); int (*get_temp_stage)(struct qpnp_tm_chip *chip); + int (*configure_trip_temps)(struct qpnp_tm_chip *chip); }; =20 struct qpnp_tm_chip { @@ -316,64 +319,95 @@ static irqreturn_t qpnp_tm_isr(int irq, void *data) return IRQ_HANDLED; } =20 +/* Read the hardware default stage threshold temperatures */ +static int qpnp_tm_sync_thresholds(struct qpnp_tm_chip *chip) +{ + u8 reg, threshold; + int ret; + + ret =3D qpnp_tm_read(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, ®); + if (ret < 0) + return ret; + + threshold =3D reg & SHUTDOWN_CTRL1_THRESHOLD_MASK; + memcpy(chip->temp_thresh_map, chip->data->temp_map[threshold], + sizeof(chip->temp_thresh_map)); + + return ret; +} + +static int qpnp_tm_configure_trip_temp(struct qpnp_tm_chip *chip) +{ + int crit_temp, ret; + + ret =3D thermal_zone_get_crit_temp(chip->tz_dev, &crit_temp); + if (ret) + crit_temp =3D THERMAL_TEMP_INVALID; + + mutex_lock(&chip->lock); + ret =3D qpnp_tm_update_critical_trip_temp(chip, crit_temp); + mutex_unlock(&chip->lock); + + return ret; +} + static const struct spmi_temp_alarm_data spmi_temp_alarm_data =3D { + .ops =3D &qpnp_tm_sensor_ops, .temp_map =3D &temp_map_gen1, + .sync_thresholds =3D qpnp_tm_sync_thresholds, + .configure_trip_temps =3D qpnp_tm_configure_trip_temp, .get_temp_stage =3D qpnp_tm_gen1_get_temp_stage, }; =20 static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_data =3D { + .ops =3D &qpnp_tm_sensor_ops, .temp_map =3D &temp_map_gen1, + .sync_thresholds =3D qpnp_tm_sync_thresholds, + .configure_trip_temps =3D qpnp_tm_configure_trip_temp, .get_temp_stage =3D qpnp_tm_gen2_get_temp_stage, }; =20 static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_rev1_data = =3D { + .ops =3D &qpnp_tm_sensor_ops, .temp_map =3D &temp_map_gen2_v1, + .sync_thresholds =3D qpnp_tm_sync_thresholds, + .configure_trip_temps =3D qpnp_tm_configure_trip_temp, .get_temp_stage =3D qpnp_tm_gen2_get_temp_stage, }; =20 /* * This function initializes the internal temp value based on only the - * current thermal stage and threshold. Setup threshold control and - * disable shutdown override. + * current thermal stage and threshold. */ -static int qpnp_tm_init(struct qpnp_tm_chip *chip) +static int qpnp_tm_threshold_init(struct qpnp_tm_chip *chip) { - int crit_temp; - u8 threshold; int ret; - u8 reg; =20 - mutex_lock(&chip->lock); - - ret =3D qpnp_tm_read(chip, QPNP_TM_REG_SHUTDOWN_CTRL1, ®); + ret =3D chip->data->sync_thresholds(chip); if (ret < 0) - goto out; - - threshold =3D reg & SHUTDOWN_CTRL1_THRESHOLD_MASK; - memcpy(chip->temp_thresh_map, chip->data->temp_map[threshold], - sizeof(chip->temp_thresh_map)); - - chip->temp =3D DEFAULT_TEMP; + return ret; =20 ret =3D chip->data->get_temp_stage(chip); if (ret < 0) - goto out; + return ret; chip->stage =3D ret; + chip->temp =3D DEFAULT_TEMP; =20 if (chip->stage) chip->temp =3D qpnp_tm_decode_temp(chip, chip->stage); =20 - mutex_unlock(&chip->lock); - - ret =3D thermal_zone_get_crit_temp(chip->tz_dev, &crit_temp); - if (ret) - crit_temp =3D THERMAL_TEMP_INVALID; + return ret; +} =20 - mutex_lock(&chip->lock); +/* This function initializes threshold control and disables shutdown overr= ide. */ +static int qpnp_tm_init(struct qpnp_tm_chip *chip) +{ + int ret; + u8 reg; =20 - ret =3D qpnp_tm_update_critical_trip_temp(chip, crit_temp); + ret =3D chip->data->configure_trip_temps(chip); if (ret < 0) - goto out; + return ret; =20 /* Enable the thermal alarm PMIC module in always-on mode. */ reg =3D ALARM_CTRL_FORCE_ENABLE; @@ -381,8 +415,6 @@ static int qpnp_tm_init(struct qpnp_tm_chip *chip) =20 chip->initialized =3D true; =20 -out: - mutex_unlock(&chip->lock); return ret; } =20 @@ -481,13 +513,17 @@ static int qpnp_tm_probe(struct platform_device *pdev) } } =20 + ret =3D qpnp_tm_threshold_init(chip); + if (ret < 0) + return dev_err_probe(&pdev->dev, ret, "threshold init failed\n"); + /* * Register the sensor before initializing the hardware to be able to * read the trip points. get_temp() returns the default temperature * before the hardware initialization is completed. */ chip->tz_dev =3D 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"); --=20 2.34.1 From nobody Tue Oct 7 08:58:28 2025 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 67CEC2C15B5 for ; Thu, 10 Jul 2025 22:46:05 +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=1752187567; cv=none; b=Ibh/++8YDMVU05AFv7/M6UKRk7+9I06cGN4h1fxGpY8ZntmpkSocf/76ijS5Iu5UoRZZ6X0vXtlRY3nsS3VXK/+dLT5ed9fIRgnNrzwDa65ncaxr+zso7/F40tWn2apZyr2jRSrE7u1Ld996p4H8BFpXjixXwAvxKphzuJUzfu8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752187567; c=relaxed/simple; bh=LTrWIBmHuSPigCg/BnSdxHQ/CMxK6ECk7MJSl7YiYcQ=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=V9VCQ/JZWBMuGU1cI+jQTRNmdcXzNqWJmlFkdboa4nMMb2W/ykGCzRk/ep9+QGKNtcLHFLfbff5ZJO98cWMHzfy4w0gzXswCuy2+34PhDGq2t4XiF5f0DsGumQYmUq6e8Gk/EpM/Jvo9vhhOJ+aICaxEN17Mfm38hfie7fZu2tE= 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=YrAC/bR3; 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="YrAC/bR3" 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 56AJQtUY013120 for ; Thu, 10 Jul 2025 22:46:04 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=4BowjyUNDu5 UOuLJtzw9IisX6hUip4xF24PhAzp2Jeg=; b=YrAC/bR3AveJv27MHtzyVWE+WpP g22Isi6oVltMh1S6Nb45dFol8LjGva7pVlSHKRuOug5hXPPOwT091/SANgI+54R+ htIyLb8RAph+r1PInMHaXA7F5rB1w6D1AfBGWWrZ8FLLYh6Cn8KnC7QO7JHe8NoL e5StvCziDdv5ZfgtWvulISik3wHT0EBAQe5ie2JCB19uQkS9jhG75triXg7AhWLG SddPO7Od7dPpqvNHRijdGadX6IKWLUS2aMSgIiTNcetow3Rviqae1Vvb00oSlYMl UAoV1SPTxS4c0UByt82ciCmLqjfY+NxoyNj6dAk2HpHtoZSi+lO872p8UDw== 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 47pucna2ta-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 10 Jul 2025 22:46:04 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-235dd77d11fso15035285ad.0 for ; Thu, 10 Jul 2025 15:46:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752187563; x=1752792363; 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=4BowjyUNDu5UOuLJtzw9IisX6hUip4xF24PhAzp2Jeg=; b=marERJPipPBoDRhwnngrA2ldzNs/cigmit3o55eX89JtutcNNpIuS+woqX21p1gil5 QHX5pW0zX+c0tPX9Q+Hf6M9xJhSc4p60XUq5kitRuK/sKQJyHm4daHNAHqVkyN+bpVz1 mkMtJI7VEszJeRjMdnpTbwm1qn0KS4Oyxg+p1XfjuWAA+xrN6u+Evyr+TibR33u1zvhM IY6f0ciLEDUPVq4roA3gUI172qHnUddXqBz7jguCf/KyOucoQN9q4BG8P1OKiYUtKfgu F31iw6yla2OLqNqNXcCx/SjXJ3tre+xGDQzq5UE2isqfDtiQffvwm284O7bjmNq0VsUb xpwA== X-Forwarded-Encrypted: i=1; AJvYcCVyu4oBwxeHyvzu5RRJP4D8SgKayNJIq7r6STZHLMcQDuP+HZv4WvrM8Qm61VoK3EXqUZalcp+9TPeNpNc=@vger.kernel.org X-Gm-Message-State: AOJu0YxFc6C04tpA1wg+gDWh09rOXNaAmhCZdxe2mY+HKAwLK89g97tG uaDdkMjh9TB/OtQwVD9rFR/xxLgVVCShjBzM5GdCpgzsUPPs++4U7+Gf55tEG9GOQ7lCR1eIq7Z y+98ToUoTzeRo2H3OOG1FsxyHfxRZmCHHvJLLVyr80Iq3WahDVUpJNWM7bGsnsFEaUIE= X-Gm-Gg: ASbGncsmrAItq0OdEtnzcuRmby1LX8Igda8nYnfRYj+T0nX+0LM/Sez5mR8T0ix+umZ Oygq3SAlc4InAmnsCHV3GghVHk0Ac9LPRjD/EP2K3pkbxEbMFuY86VVYJ1GvT2cKDPerccQAHFH RR2VQg6u0j6vwtvYyIe14YPMDU3lh5J6O3Tsq2D17ASoRGIGSmj4YeXIWO+6h7+TzMzEbjLFG2/ pRyUVRu8/UoM1ZJGwVWSezBW4Gq2NmcE6nxThgDZF4LpAm0K7fBc3m/FuENudND1nTjh4ubbqvj vrhT44pWC2rVqOy0A2K1ifZh3Y0jb4hODtwuUYFHSqimcDRwccD9qQNeER2K+BNpKfCCYNon3Pm ItwNeVQhLgOYw0cdhPaaBgGXa58U= X-Received: by 2002:a17:903:944:b0:237:f7f8:7453 with SMTP id d9443c01a7336-23dee0dff73mr13953215ad.51.1752187562681; Thu, 10 Jul 2025 15:46:02 -0700 (PDT) X-Google-Smtp-Source: AGHT+IEsToXwVRifnNntKFg0y25mkyPcXWWREZRxNC6sUDzHSHUhCziAj4udao5hth8gDYMUngSZyw== X-Received: by 2002:a17:903:944:b0:237:f7f8:7453 with SMTP id d9443c01a7336-23dee0dff73mr13952835ad.51.1752187562271; Thu, 10 Jul 2025 15:46:02 -0700 (PDT) Received: from hu-amelende-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23de4341d51sm30479615ad.189.2025.07.10.15.46.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jul 2025 15:46:01 -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, stefan.schmidt@linaro.org, quic_tsoni@quicinc.com, konrad.dybcio@oss.qualcomm.com, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.baryshkov@linaro.org, dmitry.baryshkov@oss.qualcomm.com Subject: [PATCH v6 4/5] thermal: qcom-spmi-temp-alarm: add support for GEN2 rev 2 PMIC peripherals Date: Thu, 10 Jul 2025 15:45:54 -0700 Message-Id: <20250710224555.3047790-5-anjelique.melendez@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250710224555.3047790-1-anjelique.melendez@oss.qualcomm.com> References: <20250710224555.3047790-1-anjelique.melendez@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=GdQXnRXL c=1 sm=1 tr=0 ts=687042ac cx=c_pps a=IZJwPbhc+fLeJZngyXXI0A==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=Wb1JkmetP80A:10 a=EUspDBNiAAAA:8 a=N9IR0GguogMVy2wE49AA:9 a=uG9DUKGECoFWVXl0Dc02:22 X-Proofpoint-GUID: BbT0_QTnf5-vjTXoamp-NDr6oEngyQch X-Proofpoint-ORIG-GUID: BbT0_QTnf5-vjTXoamp-NDr6oEngyQch X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzEwMDE5MSBTYWx0ZWRfX5iagU03w1KFh nU/k3r9zadsKIqDtxe4m4x7vCT0yIp7JZN1w2vOLX3xNawmmMl/PHTJdz37HR3ROCEjVuAF+Iwj YjvLeU5l5lWMjhEC1jGosJQexUEoL5QdPR+xlUedOQqOmPK56PB4pPGMBr10FY6GNp86r9V3G76 T01ntfkKDpk3QBDWxnocj5XnBASEImo+SWCTeeoPpnbcTJwL2JuwfAulEsXGxHtJJoNtd6I+kks uPE6J2HRvFkucptve+G/SJJ9i+l3OBomE6uKQZ+aIXE7lsgL1mN8ygrFAe0xUo9NeQVAkcQ23r3 ZftpqU1F/9M32oO+JFN0CfP2muzy01qFoFDZ53uCDl39uGGO7aceTaIP0dY7zxbNAzn7dn9P/gH 1hKd2omCQiznWOdfHupAIu4RHCPKJq4YEyoelOatWKzsD1WOWcowGx9/n5ckG/mbWbIrkvHA X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-10_05,2025-07-09_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 lowpriorityscore=0 phishscore=0 adultscore=0 bulkscore=0 clxscore=1015 spamscore=0 suspectscore=0 mlxlogscore=999 priorityscore=1501 impostorscore=0 malwarescore=0 mlxscore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2505280000 definitions=main-2507100191 Content-Type: text/plain; charset="utf-8" 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 (warning), 2 (system shutdown), and 3 (emergency shutdown) instead of a single register to specify a set of thresholds. Co-developed-by: David Collins Signed-off-by: David Collins Signed-off-by: Anjelique Melendez --- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 138 +++++++++++++++++++- 1 file changed, 137 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/= qcom/qcom-spmi-temp-alarm.c index c8e4db585d2b..9fbfd192017d 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 =20 +/* 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 @@ -71,6 +76,25 @@ static const long temp_map_gen2_v1[THRESH_COUNT][STAGE_C= OUNT] =3D { =20 #define TEMP_STAGE_HYSTERESIS 2000 =20 +/* + * For TEMP_GEN2 v2.0, TEMP_DAC_STG1/2/3 registers are used to set the thr= eshold + * for each stage independently. + * TEMP_DAC_STG* =3D 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] =3D { + 119375, 159375, 159375 +}; + /* Temperature in Milli Celsius reported during stage 0 if no ADC is prese= nt */ #define DEFAULT_TEMP 37000 =20 @@ -93,6 +117,7 @@ struct qpnp_tm_chip { long temp; unsigned int stage; unsigned int base; + unsigned int ntrips; /* protects .thresh, .stage and chip registers */ struct mutex lock; bool initialized; @@ -310,6 +335,54 @@ static const struct thermal_zone_device_ops qpnp_tm_se= nsor_ops =3D { .set_trip_temp =3D qpnp_tm_set_trip_temp, }; =20 +static int qpnp_tm_gen2_rev2_set_temp_thresh(struct qpnp_tm_chip *chip, un= signed int trip, int temp) +{ + int ret, temp_cfg; + u8 reg; + + WARN_ON(!mutex_is_locked(&chip->lock)); + + if (trip >=3D STAGE_COUNT) { + dev_err(chip->dev, "invalid TEMP_DAC trip =3D %d\n", trip); + return -EINVAL; + } else if (temp < TEMP_DAC_MIN || temp > temp_dac_max[trip]) { + dev_err(chip->dev, "invalid TEMP_DAC temp =3D %d\n", temp); + return -EINVAL; + } + + reg =3D TEMP_DAC_TEMP_TO_REG(temp); + temp_cfg =3D TEMP_DAC_REG_TO_TEMP(reg); + + ret =3D 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=3D%d\n", ret); + return ret; + } + + chip->temp_thresh_map[trip] =3D 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 =3D THERMAL_TRIP_PRIV_TO_INT(trip->priv); + struct qpnp_tm_chip *chip =3D thermal_zone_device_priv(tz); + int ret; + + mutex_lock(&chip->lock); + ret =3D 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 = =3D { + .get_temp =3D qpnp_tm_get_temp, + .set_trip_temp =3D qpnp_tm_gen2_rev2_set_trip_temp, +}; + static irqreturn_t qpnp_tm_isr(int irq, void *data) { struct qpnp_tm_chip *chip =3D data; @@ -351,6 +424,60 @@ static int qpnp_tm_configure_trip_temp(struct qpnp_tm_= chip *chip) return ret; } =20 +/* 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 =3D data; + int ret; + + mutex_lock(&chip->lock); + trip->priv =3D THERMAL_INT_TO_TRIP_PRIV(chip->ntrips); + ret =3D qpnp_tm_gen2_rev2_set_temp_thresh(chip, chip->ntrips, trip->tempe= rature); + chip->ntrips++; + mutex_unlock(&chip->lock); + + return ret; +} + +static int qpnp_tm_gen2_rev2_configure_trip_temps(struct qpnp_tm_chip *chi= p) +{ + int ret, i; + + ret =3D 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 =3D 1; i < STAGE_COUNT; i++) { + if (chip->temp_thresh_map[i] <=3D chip->temp_thresh_map[i - 1]) { + dev_err(chip->dev, "Threshold %d=3D%ld <=3D threshold %d=3D%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_sync_thresholds(struct qpnp_tm_chip *chip) +{ + int ret, i; + u8 reg =3D 0; + + for (i =3D 0; i < STAGE_COUNT; i++) { + ret =3D qpnp_tm_read(chip, QPNP_TM_REG_TEMP_DAC_STG1 + i, ®); + if (ret < 0) + return ret; + + chip->temp_thresh_map[i] =3D TEMP_DAC_REG_TO_TEMP(reg); + } + + return 0; +} + static const struct spmi_temp_alarm_data spmi_temp_alarm_data =3D { .ops =3D &qpnp_tm_sensor_ops, .temp_map =3D &temp_map_gen1, @@ -375,6 +502,13 @@ static const struct spmi_temp_alarm_data spmi_temp_ala= rm_gen2_rev1_data =3D { .get_temp_stage =3D qpnp_tm_gen2_get_temp_stage, }; =20 +static const struct spmi_temp_alarm_data spmi_temp_alarm_gen2_rev2_data = =3D { + .ops =3D &qpnp_tm_gen2_rev2_sensor_ops, + .sync_thresholds =3D qpnp_tm_gen2_rev2_sync_thresholds, + .configure_trip_temps =3D qpnp_tm_gen2_rev2_configure_trip_temps, + .get_temp_stage =3D qpnp_tm_gen2_get_temp_stage, +}; + /* * This function initializes the internal temp value based on only the * current thermal stage and threshold. @@ -491,8 +625,10 @@ static int qpnp_tm_probe(struct platform_device *pdev) chip->data =3D &spmi_temp_alarm_data; else if (subtype =3D=3D QPNP_TM_SUBTYPE_GEN2 && dig_major =3D=3D 0) chip->data =3D &spmi_temp_alarm_gen2_data; - else if (subtype =3D=3D QPNP_TM_SUBTYPE_GEN2 && dig_major >=3D 1) + else if (subtype =3D=3D QPNP_TM_SUBTYPE_GEN2 && dig_major =3D=3D 1) chip->data =3D &spmi_temp_alarm_gen2_rev1_data; + else if (subtype =3D=3D QPNP_TM_SUBTYPE_GEN2 && dig_major >=3D 2) + chip->data =3D &spmi_temp_alarm_gen2_rev2_data; else return -ENODEV; =20 --=20 2.34.1 From nobody Tue Oct 7 08:58:28 2025 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 0690C2D12E2 for ; Thu, 10 Jul 2025 22:46:06 +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=1752187568; cv=none; b=Uq0Ts5PN/ruV1+W3yAaAKmDB8BDvmFKzL0d20XPAZX0ura/ACDDp20+4wohbBxK9Sc/pJziWGg12WeEUbYOMnUvYG6Os+3bKCUiW1JqaLHCgHnwthLvzTkWM2feosjJkUZHTmkyY00ns2QHEJ7ORBDxE5+z6A/WnyZaEaJdi1Go= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1752187568; c=relaxed/simple; bh=1I6+4fLFYxIRchnimpbcx/xAezT0weK9I3m33+3twO8=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Wz1BP3KKs9jFJfm9l1sRJl2vwycQPaHifc0/o6BPjJ9sHNwvhddL3hzPOk+dyJHGc7ECtKcB2IF8glbmlMrVpdTIik7kXVhoC8kPhTn9QrEDNqTULfdgGSYasPlGVDd7nSgyIaSbcIZ7Qy9r81yvQTygRpA1P7r/S4dwQGJv/CM= 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=gmTp5H4p; 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="gmTp5H4p" Received: from pps.filterd (m0279871.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 56AJR2vA023696 for ; Thu, 10 Jul 2025 22:46:06 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=qTV57CQ8ymJ mYXnc5Iu4DmQhuHr9c68sQy8sTbtSQKA=; b=gmTp5H4pyJl2bQGN0MmDSdMwfn3 yX7cXfISaAD49TwkCNf+Q+1wd+/j+OpmwWykqo10Fv3CncvoT09CanLZ0XhGMgRO Fg2Ya3CZIJwdD94lJkzFd/viSjUyQb+Xe0eNoDqyUfgyvCBQGOSatWXK8x0IPm51 qSB1Y6LYpdgfxS2f7aWY5wO7gbQtmmTkr3Qlq9WcYUQp88o70NNmDoNIkFPFnGAF WvbCy/rckNCsAsI9den2DW9CXWqg8G/l9PLnbKv7B/YTDrrPBYGLf1cQiMvnz2+c UNxonW/1TMo66gKNsePCIGBQp52EaeS1Z06pkGKMD6t5/hy2tGwrWdgItsA== 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 47smafpgej-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 10 Jul 2025 22:46:05 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-2382607509fso8413365ad.3 for ; Thu, 10 Jul 2025 15:46:05 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1752187564; x=1752792364; 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=qTV57CQ8ymJmYXnc5Iu4DmQhuHr9c68sQy8sTbtSQKA=; b=quhIjHbMxHGW+NXgi+GeGzt1f9x0pmoiKThwYq594Po61CyP7L1LKkFXEuGKrEVPFR EVb0sleAcRPP7gjNs3cXoo6EYFC29B8mP5JNNgWSsjtzLxDEacDPs5K57wQLtwP+3U+8 jnvdxUMkRn4jivnyGRhWAvIVKXrjbx7D3cAfs1B/sUdkXhXynn2w8D0uVwxNgWDRA0JO HGt69iVI+wtQnIJ3lDraH2MRvnwlxO4XeGtpvkSioIgchGLEFcHpObOwOGyjhym+0/qx qnYZAtEyN9btrqUQG+THFjV4V88orxKIBDWfZkzvM+oq2TlBDvS9nS9jlqjpU88B6Cku KS9Q== X-Forwarded-Encrypted: i=1; AJvYcCWKiZwZviCUDuW2wNMa+Hm8iuv8i9f1qDdiNegVjhwjbg7HzOnTFcuaPWaV8LrY/yW6n7D0xVATg4rtOJo=@vger.kernel.org X-Gm-Message-State: AOJu0Yzk8z5auyoI0YayRSOt31du6XUF/8v7vtWA67BvlzXym6hbdLzT CpsFrVLs8siOrmUpCyby+PF6qf4u4yrIKZnqOrjjMwL5aG/g2VkaKhcGjFiPVxtz5uAmJsQm1Ow h7bfA3bXquTefRCpYXYdgygzgrKINzyqnyWtrOqUV48e1KCrKYFNU0i97s+TPtgJcaFE= X-Gm-Gg: ASbGnctrp+7dzIuoOQ7cZvFjyIP8gYx1P1957FBk4S0Ww+NedK2NNw+ynKyg6W7FYVm OLTZBNIpBqvGnMsGUobtec+kvFgctXPMoXxeDYEFf5b9VKKHsau6ZHxfvIByF2+nPfZbfXTrazc Idtv816yWUgifGLzVXTCZI4dvcytNqP7hGph9cnmMI8mzUsva+8ClQu2mxjkneqJZi6OBMda3+F 7k1rKIfqVzdmVSKnVetX2bX8xc9+dyQdf2iXfz+ihrIJQJop2FDHA+iPSpJFqzzk2ljJ4/+bUcY f7tmCAFD3JrbpOoZAyvsa43cIiveYJso3NTX7ewf28LCZbYL2bid4TkOH6SpVEpo5CzoYVAZH2W Cn8MbIa1MY7kN+Y1CiKvLF7FAbX0= X-Received: by 2002:a17:903:98c:b0:22e:421b:49b1 with SMTP id d9443c01a7336-23dede94a67mr12179095ad.48.1752187564129; Thu, 10 Jul 2025 15:46:04 -0700 (PDT) X-Google-Smtp-Source: AGHT+IGkdL3WJ6xRqtGtImhgF2AwOwFBRgfjiJyMt52F5VPsKm3YbKQk5xFMvR1NzIW+jCLp+JXxFQ== X-Received: by 2002:a17:903:98c:b0:22e:421b:49b1 with SMTP id d9443c01a7336-23dede94a67mr12178805ad.48.1752187563716; Thu, 10 Jul 2025 15:46:03 -0700 (PDT) Received: from hu-amelende-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-23de4341d51sm30479615ad.189.2025.07.10.15.46.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Jul 2025 15:46:03 -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, stefan.schmidt@linaro.org, quic_tsoni@quicinc.com, konrad.dybcio@oss.qualcomm.com, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, dmitry.baryshkov@linaro.org, dmitry.baryshkov@oss.qualcomm.com Subject: [PATCH v6 5/5] thermal: qcom-spmi-temp-alarm: add support for LITE PMIC peripherals Date: Thu, 10 Jul 2025 15:45:55 -0700 Message-Id: <20250710224555.3047790-6-anjelique.melendez@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250710224555.3047790-1-anjelique.melendez@oss.qualcomm.com> References: <20250710224555.3047790-1-anjelique.melendez@oss.qualcomm.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Authority-Analysis: v=2.4 cv=ZJ/XmW7b c=1 sm=1 tr=0 ts=687042ad cx=c_pps a=IZJwPbhc+fLeJZngyXXI0A==:117 a=ouPCqIW2jiPt+lZRy3xVPw==:17 a=Wb1JkmetP80A:10 a=EUspDBNiAAAA:8 a=mWY56GqtIC0XaCpv56YA:9 a=uG9DUKGECoFWVXl0Dc02:22 X-Proofpoint-ORIG-GUID: Ra832_FG8Z34i4GN2X6ecsJgNq4ug7D- X-Proofpoint-GUID: Ra832_FG8Z34i4GN2X6ecsJgNq4ug7D- X-Proofpoint-Spam-Details-Enc: AW1haW4tMjUwNzEwMDE5MSBTYWx0ZWRfX4xKOn2PXFWKO OFyFnmpLnSony2l6isX1DrPT7wzYjBJygfbbjwPWZHCCA6GOmZxNYKYOR/NGnllnZ1DBTg+bgXs Ad/HbNNCXP6RejuWV+OfN/+nrv199P4lvxvAYFuyoSeAMRKBvGDinvNvMgeNdi1H4FAoIeG2jj+ ezNVB8bEKZ+D4+z18xfGEQJc1/1AJktYu05Wl2B9BrFULy82uo9DioL1tPVnRpnqgceTuNgoFDb BnfW+6B46SXQCpYX1z9txokvMkOkoXw++PIW/OKNXSxUk0VRRGrv9jTK243CABJmaVg20h3joOk aJbPxWufpbnM3PIw6YtHIqH5geHHH6vN+d4UDr9y+Pxhj9J8C572Ny8+zVq83Eb8uE7AWGh7mAb aPQu9x4j8IKNsiAHkB2nm6WjJhHFpD5Cdzsfm8DGDdek0wNVEDQO/Dhd/B4NjvC6SKvIhqJr X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1099,Hydra:6.1.7,FMLib:17.12.80.40 definitions=2025-07-10_05,2025-07-09_01,2025-03-28_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxlogscore=999 impostorscore=0 spamscore=0 adultscore=0 clxscore=1015 bulkscore=0 phishscore=0 priorityscore=1501 mlxscore=0 lowpriorityscore=0 suspectscore=0 malwarescore=0 classifier=spam authscore=0 authtc=n/a authcc= route=outbound adjust=0 reason=mlx scancount=1 engine=8.19.0-2505280000 definitions=main-2507100191 Content-Type: text/plain; charset="utf-8" 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. Co-developed-by: David Collins Signed-off-by: David Collins Signed-off-by: Anjelique Melendez Reviewed-by: Dmitry Baryshkov --- drivers/thermal/qcom/qcom-spmi-temp-alarm.c | 208 +++++++++++++++++++- 1 file changed, 207 insertions(+), 1 deletion(-) diff --git a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c b/drivers/thermal/= qcom/qcom-spmi-temp-alarm.c index 9fbfd192017d..f39ca0ddd17b 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 =20 @@ -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 =20 #define QPNP_TM_TYPE 0x09 #define QPNP_TM_SUBTYPE_GEN1 0x08 #define QPNP_TM_SUBTYPE_GEN2 0x09 +#define QPNP_TM_SUBTYPE_LITE 0xC0 =20 #define STATUS_GEN1_STAGE_MASK GENMASK(1, 0) #define STATUS_GEN2_STATE_MASK GENMASK(6, 4) =20 +/* IRQ status only needed for TEMP_ALARM_LITE */ +#define IRQ_STATUS_MASK BIT(0) + #define SHUTDOWN_CTRL1_OVERRIDE_STAGE2 BIT(6) #define SHUTDOWN_CTRL1_THRESHOLD_MASK GENMASK(1, 0) =20 @@ -45,6 +52,8 @@ =20 #define ALARM_CTRL_FORCE_ENABLE BIT(7) =20 +#define LITE_TEMP_CFG_THRESHOLD_MASK GENMASK(3, 2) + #define THRESH_COUNT 4 #define STAGE_COUNT 3 =20 @@ -95,6 +104,19 @@ static const long temp_dac_max[STAGE_COUNT] =3D { 119375, 159375, 159375 }; =20 +/* + * TEMP_ALARM_LITE has two stages: warning and shutdown with independently + * configured threshold temperatures. + */ + +static const long temp_lite_warning_map[THRESH_COUNT] =3D { + 115000, 125000, 135000, 145000 +}; + +static const long temp_lite_shutdown_map[THRESH_COUNT] =3D { + 135000, 145000, 160000, 175000 +}; + /* Temperature in Milli Celsius reported during stage 0 if no ADC is prese= nt */ #define DEFAULT_TEMP 37000 =20 @@ -202,6 +224,24 @@ static int qpnp_tm_gen2_get_temp_stage(struct qpnp_tm_= chip *chip) return alarm_state_map[ret]; } =20 +/** + * 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 =3D 0; + int ret; + + ret =3D qpnp_tm_read(chip, QPNP_TM_REG_IRQ_STATUS, ®); + if (ret < 0) + return ret; + + return FIELD_GET(IRQ_STATUS_MASK, reg); +} + /* * This function updates the internal temp value based on the * current thermal stage and threshold as well as the previous stage @@ -383,6 +423,98 @@ static const struct thermal_zone_device_ops qpnp_tm_ge= n2_rev2_sensor_ops =3D { .set_trip_temp =3D qpnp_tm_gen2_rev2_set_trip_temp, }; =20 +static int qpnp_tm_lite_set_temp_thresh(struct qpnp_tm_chip *chip, unsigne= d int trip, int temp) +{ + int ret, temp_cfg, i; + const long *temp_map; + u8 reg, thresh; + u16 addr; + + WARN_ON(!mutex_is_locked(&chip->lock)); + + if (trip >=3D STAGE_COUNT) { + dev_err(chip->dev, "invalid TEMP_LITE trip =3D %d\n", trip); + return -EINVAL; + } + + switch (trip) { + case 0: + temp_map =3D temp_lite_warning_map; + addr =3D 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 =3D temp_lite_shutdown_map; + addr =3D 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 =3D %d\n", temp); + return -EINVAL; + } + + thresh =3D 0; + temp_cfg =3D temp_map[thresh]; + for (i =3D THRESH_MAX; i >=3D THRESH_MIN; i--) { + if (temp >=3D temp_map[i]) { + thresh =3D i; + temp_cfg =3D temp_map[i]; + break; + } + } + + if (temp_cfg =3D=3D chip->temp_thresh_map[trip]) + return 0; + + ret =3D qpnp_tm_read(chip, addr, ®); + if (ret < 0) { + dev_err(chip->dev, "LITE_TEMP_CFG read failed, ret=3D%d\n", ret); + return ret; + } + + reg &=3D ~LITE_TEMP_CFG_THRESHOLD_MASK; + reg |=3D FIELD_PREP(LITE_TEMP_CFG_THRESHOLD_MASK, thresh); + + ret =3D qpnp_tm_write(chip, addr, reg); + if (ret < 0) { + dev_err(chip->dev, "LITE_TEMP_CFG write failed, ret=3D%d\n", ret); + return ret; + } + + chip->temp_thresh_map[trip] =3D 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 =3D THERMAL_TRIP_PRIV_TO_INT(trip->priv); + struct qpnp_tm_chip *chip =3D thermal_zone_device_priv(tz); + int ret; + + mutex_lock(&chip->lock); + ret =3D 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 =3D { + .get_temp =3D qpnp_tm_get_temp, + .set_trip_temp =3D qpnp_tm_lite_set_trip_temp, +}; + static irqreturn_t qpnp_tm_isr(int irq, void *data) { struct qpnp_tm_chip *chip =3D data; @@ -478,6 +610,70 @@ static int qpnp_tm_gen2_rev2_sync_thresholds(struct qp= np_tm_chip *chip) return 0; } =20 +/* 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 =3D data; + int ret; + + mutex_lock(&chip->lock); + trip->priv =3D THERMAL_INT_TO_TRIP_PRIV(chip->ntrips); + ret =3D qpnp_tm_lite_set_temp_thresh(chip, chip->ntrips, trip->temperatur= e); + chip->ntrips++; + mutex_unlock(&chip->lock); + + return ret; +} + +static int qpnp_tm_lite_configure_trip_temps(struct qpnp_tm_chip *chip) +{ + int ret; + + ret =3D thermal_zone_for_each_trip(chip->tz_dev, qpnp_tm_lite_configure_t= rip_temps_cb, chip); + if (ret < 0) + return ret; + + /* Verify that trips are strictly increasing. */ + if (chip->temp_thresh_map[2] <=3D chip->temp_thresh_map[0]) { + dev_err(chip->dev, "Threshold 2=3D%ld <=3D threshold 0=3D%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_sync_thresholds(struct qpnp_tm_chip *chip) +{ + int ret, thresh; + u8 reg =3D 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 softwa= re + * 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 =3D qpnp_tm_read(chip, QPNP_TM_REG_LITE_TEMP_CFG1, ®); + if (ret < 0) + return ret; + + thresh =3D FIELD_GET(LITE_TEMP_CFG_THRESHOLD_MASK, reg); + chip->temp_thresh_map[0] =3D temp_lite_warning_map[thresh]; + + ret =3D qpnp_tm_read(chip, QPNP_TM_REG_LITE_TEMP_CFG2, ®); + if (ret < 0) + return ret; + + thresh =3D FIELD_GET(LITE_TEMP_CFG_THRESHOLD_MASK, reg); + chip->temp_thresh_map[2] =3D temp_lite_shutdown_map[thresh]; + + return 0; +} + static const struct spmi_temp_alarm_data spmi_temp_alarm_data =3D { .ops =3D &qpnp_tm_sensor_ops, .temp_map =3D &temp_map_gen1, @@ -509,6 +705,13 @@ static const struct spmi_temp_alarm_data spmi_temp_ala= rm_gen2_rev2_data =3D { .get_temp_stage =3D qpnp_tm_gen2_get_temp_stage, }; =20 +static const struct spmi_temp_alarm_data spmi_temp_alarm_lite_data =3D { + .ops =3D &qpnp_tm_lite_sensor_ops, + .sync_thresholds =3D qpnp_tm_lite_sync_thresholds, + .configure_trip_temps =3D qpnp_tm_lite_configure_trip_temps, + .get_temp_stage =3D qpnp_tm_lite_get_temp_stage, +}; + /* * This function initializes the internal temp value based on only the * current thermal stage and threshold. @@ -614,7 +817,8 @@ static int qpnp_tm_probe(struct platform_device *pdev) "could not read dig_minor\n"); =20 if (type !=3D QPNP_TM_TYPE || (subtype !=3D QPNP_TM_SUBTYPE_GEN1 - && subtype !=3D QPNP_TM_SUBTYPE_GEN2)) { + && subtype !=3D QPNP_TM_SUBTYPE_GEN2 + && subtype !=3D QPNP_TM_SUBTYPE_LITE)) { dev_err(&pdev->dev, "invalid type 0x%02x or subtype 0x%02x\n", type, subtype); return -ENODEV; @@ -629,6 +833,8 @@ static int qpnp_tm_probe(struct platform_device *pdev) chip->data =3D &spmi_temp_alarm_gen2_rev1_data; else if (subtype =3D=3D QPNP_TM_SUBTYPE_GEN2 && dig_major >=3D 2) chip->data =3D &spmi_temp_alarm_gen2_rev2_data; + else if (subtype =3D=3D QPNP_TM_SUBTYPE_LITE) + chip->data =3D &spmi_temp_alarm_lite_data; else return -ENODEV; =20 --=20 2.34.1