From nobody Thu Dec 18 22:04:23 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 3528D26980B for ; Thu, 13 Feb 2025 21:04:10 +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=1739480652; cv=none; b=aX50oSCEc3YmhmtcZl6n6GSKGibxCUCiN8sa+0n3Qk4H7Mf2JmNSJiEwvvoVBeCCFPgCBHS97GtNnC4Zp46zf5FDiYnWC7p/uPR4ULdh/TulgsC7Y0cu6kSXOED6uEOcnps242b97W7A5DH7Mbx/0CUxecGgMeKXWDsd07vPRyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1739480652; c=relaxed/simple; bh=RI03jic5DoODF2Ud42i4jxiHLYF7EG5DlqIewOfwoWw=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References: MIME-Version; b=Y/VM+D8MC4bWPhwbZXiiq8BlbzuT2IjDGu8qKxtP4m/ZHToENdj+dgwEqKlZMQHVkbYuYF+jhyufqXB0kJ/uy1tOiyYn86sWYix8L0ywksZtg5Bf/50Gqz9fP/J3yFAENrNrtFKfOa8bZha4TiC4zdgyLXOKCiTQ59/WC8Dc+Nk= 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=lW7IN9Kb; 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="lW7IN9Kb" Received: from pps.filterd (m0279863.ppops.net [127.0.0.1]) by mx0a-0031df01.pphosted.com (8.18.1.2/8.18.1.2) with ESMTP id 51DHKES3008247 for ; Thu, 13 Feb 2025 21:04:10 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=tV/aMqmQdVU PKtTU3soSpl6m/OCQWaKUT3FDY13LKkk=; b=lW7IN9KbMvAaTR/bZmjL1Ps+E8I GcFl+5ZTGs+bt8XGbqgpqkOin11Ool5Y1peixFaj/vPrwPMm4wtu3rfHybBkDtrV +Y9Av67o6YFftgrUdQNisTBmyCz97OEQSDzcT7CrIQtqS3OEDrVlwrcYX39sF8H7 SLGj0Xm0QSNuYiJ6ys8zvKb3UKUzPJ3r0FiTW91l6RWGDqb45y3B0kwDy1p2NElK heZcm/IploBa13LiZeTgsBJMWqgbCx/gSVX+8zj2ryeMDwGn+FMbp8y9Mj7GYjlo t3MqMk6QzoGaXKG332orBvr6VGsx7hrWghb92wpTrN8RRiZ0+7GAaK2WIgA== 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 44qewhc4vv-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128 verify=NOT) for ; Thu, 13 Feb 2025 21:04:10 +0000 (GMT) Received: by mail-pl1-f200.google.com with SMTP id d9443c01a7336-21f6cb3097bso38451205ad.3 for ; Thu, 13 Feb 2025 13:04:10 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1739480649; x=1740085449; 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=tV/aMqmQdVUPKtTU3soSpl6m/OCQWaKUT3FDY13LKkk=; b=OlFakzj4CxbGmfL3c1orCTNgnYsQvNNLBFWy9veXxrriGU64ki1qsMAn66gBBJw0d+ 1bxzYsdQXjJ9j0r2rGdSypx26cD/tQ4ItMi2sbKtc1eFrGF8+w+YpJsc3xTCjjzrvhJ8 UvcA2qy+cFYW4AiYCxRL5gWvC3p99Mtq7lPTpI9b2xHE/HLyfnuHFnKidD5zh5R3PG1A Bmm9ifD6MEFKmgil0k+Y6oBG/6PjBNK6VJqqyIIh8/EaEyQwvG237P6c2+zkWw4oieWh RDbkOuFsOu6d0rvVBlxKrM5IjgyM1tkpcVqGNXjLj5GiKAkhQ/t/IT/Ze7fy1rm98CGL V+jQ== X-Forwarded-Encrypted: i=1; AJvYcCXqWpxXLwIER81cc78cfkKzP4d68Hhjcp8GFV/2jkUUYxu9JbipULHf2diFRlPLlD+gsy7Hu8VTOHrgvm8=@vger.kernel.org X-Gm-Message-State: AOJu0Yyr7YjGMJjvuPq18ImivF4j172uw46XJVxa5nZvtHbb1bCyIiEH JSBPjMW83LBKot2+GLGPJIw1y1VVIUvjwVRkbxe7CNYHq7mHezk5q/S2V+2adeqDYCQ5jeH04e0 VKWB8+dURAA5okDRoDz8HgC5UUVw+MTI2hSwMxc0CFW5gSKSvvxiEDdchZYiWxmY= X-Gm-Gg: ASbGncs5fsNdYIm0RfbxAxYaARnAIZJJYtmxK+A4LQgYqbX9AgOslUzTLEIMo/M3YEr YVr/A8tEwGRqi95N78K3WhbW7lcAxWgWNfpBYQpT43fafk8C/UAWR445AtuW14cw0H9rwFcbxgR gyKfpQRNKSNU0ArII3wQtXzrqZcYnUCRNUHCQndTFJAmEvNgXh7B4LZicYfdHeHhZjT5S//nAte yPzvhbbuMWOBw/oKUL4mt/X1488PwEeL5pSpcn0BJecS8wV6lMtJj4q4ZCydBXCG9U2NI0oW/18 ct9rKpuw+mk5+7T+FSR2Ug69bxdHwXlzVZpxF+KhBy19SJHY4wq+rjCNMCa559WQTeN0 X-Received: by 2002:a17:902:ecc4:b0:216:2474:3c9f with SMTP id d9443c01a7336-220bbdf188dmr130667345ad.52.1739480649116; Thu, 13 Feb 2025 13:04:09 -0800 (PST) X-Google-Smtp-Source: AGHT+IH9zLko3u11MbZvHhmrlovw6VTGrXYSekGUZQPeHBW0JNIWw3OrQm1fOmrQL2az7eFMnokhsQ== X-Received: by 2002:a17:902:ecc4:b0:216:2474:3c9f with SMTP id d9443c01a7336-220bbdf188dmr130666475ad.52.1739480648273; Thu, 13 Feb 2025 13:04:08 -0800 (PST) Received: from hu-amelende-lv.qualcomm.com (Global_NAT1.qualcomm.com. [129.46.96.20]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-220dacfc769sm14339375ad.201.2025.02.13.13.04.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Feb 2025 13:04:07 -0800 (PST) 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, linux-arm-msm@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 3/4] thermal: qcom-spmi-temp-alarm: add support for GEN2 rev 2 PMIC peripherals Date: Thu, 13 Feb 2025 13:04:02 -0800 Message-Id: <20250213210403.3396392-4-anjelique.melendez@oss.qualcomm.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20250213210403.3396392-1-anjelique.melendez@oss.qualcomm.com> References: <20250213210403.3396392-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-ORIG-GUID: SC_b-p7vkETEDNEyMfaoPm38X-5M8gUW X-Proofpoint-GUID: SC_b-p7vkETEDNEyMfaoPm38X-5M8gUW X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.293,Aquarius:18.0.1057,Hydra:6.0.680,FMLib:17.12.68.34 definitions=2025-02-13_08,2025-02-13_01,2024-11-22_01 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 mlxscore=0 spamscore=0 impostorscore=0 mlxlogscore=999 phishscore=0 clxscore=1015 adultscore=0 lowpriorityscore=0 malwarescore=0 bulkscore=0 suspectscore=0 priorityscore=1501 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.19.0-2501170000 definitions=main-2502130148 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, 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 af71d4238340..a10f368f2039 100644 --- a/drivers/thermal/qcom/qcom-spmi-temp-alarm.c +++ b/drivers/thermal/qcom/qcom-spmi-temp-alarm.c @@ -25,6 +25,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 @@ -64,6 +69,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 @@ -72,6 +96,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); }; @@ -87,6 +112,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; @@ -304,6 +330,52 @@ 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, in= t trip, int temp) +{ + int ret, temp_cfg; + u8 reg; + + if (trip < 0 || 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; @@ -328,6 +400,58 @@ static int qpnp_tm_configure_trip_temp(struct qpnp_tm_= chip *chip) return qpnp_tm_update_critical_trip_temp(chip, crit_temp); } =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; + + 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++; + + 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_init(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, @@ -349,6 +473,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, + .setup =3D qpnp_tm_gen2_rev2_init, + .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. Setup threshold control and @@ -484,6 +615,8 @@ static int qpnp_tm_probe(struct platform_device *pdev) =20 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 2) + chip->data =3D &spmi_temp_alarm_gen2_rev2_data; else if (subtype =3D=3D QPNP_TM_SUBTYPE_GEN2 && dig_major >=3D 1) chip->data =3D &spmi_temp_alarm_gen2_rev1_data; else if (subtype =3D=3D QPNP_TM_SUBTYPE_GEN2) @@ -491,6 +624,9 @@ static int qpnp_tm_probe(struct platform_device *pdev) else return -ENODEV; =20 + 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 --=20 2.34.1