From patchwork Wed Nov 30 13:19:39 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 27790 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp921034wrr; Wed, 30 Nov 2022 05:22:53 -0800 (PST) X-Google-Smtp-Source: AA0mqf5i2CEM9yViUTdHP5dN9v4yHaI0eMW05OjNvzLDtZs6xNtoTjhNKAEi3++I9mOrBdh6Hd9p X-Received: by 2002:a65:6e8d:0:b0:477:ee28:b8d9 with SMTP id bm13-20020a656e8d000000b00477ee28b8d9mr21280100pgb.396.1669814572825; Wed, 30 Nov 2022 05:22:52 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669814572; cv=none; d=google.com; s=arc-20160816; b=RZH0F939bT0sNVQ/L2v1Tb8y43SiRgrulvov1X/SOHETsGY+BIgojLLIzUljPQI6th awWfWK0xDeQXsCQQ7MQj6IM/ZMsNFw/vmZP9vsOmSEtfSasnXnkP64CyeVhCvIDV5Zsg VNV18bZygqEyhti+tqBI09H7Y7D8khw1qWeyM27/RdwsBV4njIbElDyE2XJsD0GFYTFa cwCaH0fJKBfbcW1rtsqdmTJ7vQRwNjnNaXxihoZZzTi6spY4K2wWYr/qFAK9sof3rpXE TZT/1SlXGq98J2CC5rI5QFU2976/FJXcoex6/9TYoH836QzGzS9H0O3W4yNBr+o63WWE fXsw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date; bh=DFHT8QXxYUZr+XrKJX3b6Dcw8IemN6+tDUwpbICW5kA=; b=xG96oAhNkWwYsgXYOB6/RF0QOm0V5N3429e19C/jvRpeo+G8AjdPQGxEmeOTyNNEOz yevmfX30+k+pHDetWSku8Csma3nXYECbUmIvqCeIduP33POWc+bMPlQVe8DM3V6cSh54 +Fuh8zVGDy3ardlU/GbEAqTGPwEOZAOVL8N7ygk8w0nMIChV9xpmZZbMiYACu9FTF3oF hrcnmUJZP8WpDcP2uFJIIPzZErWXwRi0iJSXh2LnOMs0/roJ19poznD/XqOfduiZFrbM OGe2Oy7z9QWEH5O2NVY5JSQ+np5y3lr5OJ8HfG9yc2WwZSc2bP7XF/BbBVner36N5FDX I5VA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id r15-20020a63ec4f000000b00478599980f4si1241876pgj.93.2022.11.30.05.22.39; Wed, 30 Nov 2022 05:22:52 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233421AbiK3NT5 (ORCPT + 99 others); Wed, 30 Nov 2022 08:19:57 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229971AbiK3NT4 (ORCPT ); Wed, 30 Nov 2022 08:19:56 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F84327920; Wed, 30 Nov 2022 05:19:53 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.94.2) (envelope-from ) id 1p0N05-0006BA-NZ; Wed, 30 Nov 2022 14:19:45 +0100 Date: Wed, 30 Nov 2022 13:19:39 +0000 From: Daniel Golle To: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Zhang Rui , Matthias Brugger , Rob Herring Cc: Steven Liu , Henry Yen Subject: [PATCH v2 1/2] thermal: mediatek: add support for MT7986 and MT7981 Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750927485634957588?= X-GMAIL-MSGID: =?utf-8?q?1750927485634957588?= Add support for V3 generation thermal found in MT7986 and MT7981 SoCs. Brings code to assign values from efuse as well as new function to convert raw temperature to millidegree celsius, as found in MediaTek's SDK sources (but cleaned up and de-duplicated) [1]: https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/+/baf36c7eef477aae1f8f2653b6c29e2caf48475b Signed-off-by: Daniel Golle Reviewed-by: Henry Yen --- Changes since v1: Drop use of adc_oe field in efuse, Henry Yen confirmed its use has been dropped intentionally in MTK SDK as well. drivers/thermal/mtk_thermal.c | 122 +++++++++++++++++++++++++++++++++- 1 file changed, 119 insertions(+), 3 deletions(-) diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c index 8440692e3890..6a69419f8960 100644 --- a/drivers/thermal/mtk_thermal.c +++ b/drivers/thermal/mtk_thermal.c @@ -150,6 +150,21 @@ #define CALIB_BUF1_VALID_V2(x) (((x) >> 4) & 0x1) #define CALIB_BUF1_O_SLOPE_SIGN_V2(x) (((x) >> 3) & 0x1) +/* + * Layout of the fuses providing the calibration data + * These macros can be used for MT7981 and MT7986. + */ +#define CALIB_BUF0_ADC_GE_V3(x) (((x) >> 0) & 0x3ff) +#define CALIB_BUF0_ADC_OE_V3(x) (((x) >> 10) & 0x3ff) +#define CALIB_BUF0_DEGC_CALI_V3(x) (((x) >> 20) & 0x3f) +#define CALIB_BUF0_O_SLOPE_V3(x) (((x) >> 26) & 0x3f) +#define CALIB_BUF1_VTS_TS1_V3(x) (((x) >> 0) & 0x1ff) +#define CALIB_BUF1_VTS_TS2_V3(x) (((x) >> 21) & 0x1ff) +#define CALIB_BUF1_VTS_TSABB_V3(x) (((x) >> 9) & 0x1ff) +#define CALIB_BUF1_VALID_V3(x) (((x) >> 18) & 0x1) +#define CALIB_BUF1_O_SLOPE_SIGN_V3(x) (((x) >> 19) & 0x1) +#define CALIB_BUF1_ID_V3(x) (((x) >> 20) & 0x1) + enum { VTS1, VTS2, @@ -163,6 +178,7 @@ enum { enum mtk_thermal_version { MTK_THERMAL_V1 = 1, MTK_THERMAL_V2, + MTK_THERMAL_V3, }; /* MT2701 thermal sensors */ @@ -245,6 +261,27 @@ enum mtk_thermal_version { /* The calibration coefficient of sensor */ #define MT8183_CALIBRATION 153 +/* AUXADC channel 11 is used for the temperature sensors */ +#define MT7986_TEMP_AUXADC_CHANNEL 11 + +/* The total number of temperature sensors in the MT7986 */ +#define MT7986_NUM_SENSORS 1 + +/* The number of banks in the MT7986 */ +#define MT7986_NUM_ZONES 1 + +/* The number of sensing points per bank */ +#define MT7986_NUM_SENSORS_PER_ZONE 1 + +/* MT7986 thermal sensors */ +#define MT7986_TS1 0 + +/* The number of controller in the MT7986 */ +#define MT7986_NUM_CONTROLLER 1 + +/* The calibration coefficient of sensor */ +#define MT7986_CALIBRATION 165 + struct mtk_thermal; struct thermal_bank_cfg { @@ -386,6 +423,14 @@ static const int mt7622_mux_values[MT7622_NUM_SENSORS] = { 0, }; static const int mt7622_vts_index[MT7622_NUM_SENSORS] = { VTS1 }; static const int mt7622_tc_offset[MT7622_NUM_CONTROLLER] = { 0x0, }; +/* MT7986 thermal sensor data */ +static const int mt7986_bank_data[MT7986_NUM_SENSORS] = { MT7986_TS1, }; +static const int mt7986_msr[MT7986_NUM_SENSORS_PER_ZONE] = { TEMP_MSR0, }; +static const int mt7986_adcpnp[MT7986_NUM_SENSORS_PER_ZONE] = { TEMP_ADCPNP0, }; +static const int mt7986_mux_values[MT7986_NUM_SENSORS] = { 0, }; +static const int mt7986_vts_index[MT7986_NUM_SENSORS] = { VTS1 }; +static const int mt7986_tc_offset[MT7986_NUM_CONTROLLER] = { 0x0, }; + /* * The MT8173 thermal controller has four banks. Each bank can read up to * four temperature sensors simultaneously. The MT8173 has a total of 5 @@ -549,6 +594,30 @@ static const struct mtk_thermal_data mt8183_thermal_data = { .version = MTK_THERMAL_V1, }; +/* + * MT7986 uses AUXADC Channel 11 for raw data access. + */ +static const struct mtk_thermal_data mt7986_thermal_data = { + .auxadc_channel = MT7986_TEMP_AUXADC_CHANNEL, + .num_banks = MT7986_NUM_ZONES, + .num_sensors = MT7986_NUM_SENSORS, + .vts_index = mt7986_vts_index, + .cali_val = MT7986_CALIBRATION, + .num_controller = MT7986_NUM_CONTROLLER, + .controller_offset = mt7986_tc_offset, + .need_switch_bank = true, + .bank_data = { + { + .num_sensors = 1, + .sensors = mt7986_bank_data, + }, + }, + .msr = mt7986_msr, + .adcpnp = mt7986_adcpnp, + .sensor_mux_values = mt7986_mux_values, + .version = MTK_THERMAL_V3, +}; + /** * raw_to_mcelsius - convert a raw ADC value to mcelsius * @mt: The thermal controller @@ -603,6 +672,22 @@ static int raw_to_mcelsius_v2(struct mtk_thermal *mt, int sensno, s32 raw) return (format_2 - tmp) * 100; } +static int raw_to_mcelsius_v3(struct mtk_thermal *mt, int sensno, s32 raw) +{ + s32 tmp; + + if (raw == 0) + return 0; + + raw &= 0xfff; + tmp = 100000 * 15 / 16 * 10000; + tmp /= 4096 - 512 + mt->adc_ge; + tmp /= 1490; + tmp *= raw - mt->vts[sensno] - 2900; + + return mt->degc_cali * 500 - tmp; +} + /** * mtk_thermal_get_bank - get bank * @bank: The bank @@ -659,9 +744,12 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank) if (mt->conf->version == MTK_THERMAL_V1) { temp = raw_to_mcelsius_v1( mt, conf->bank_data[bank->id].sensors[i], raw); - } else { + } else if (mt->conf->version == MTK_THERMAL_V2) { temp = raw_to_mcelsius_v2( mt, conf->bank_data[bank->id].sensors[i], raw); + } else { + temp = raw_to_mcelsius_v3( + mt, conf->bank_data[bank->id].sensors[i], raw); } /* @@ -887,6 +975,26 @@ static int mtk_thermal_extract_efuse_v2(struct mtk_thermal *mt, u32 *buf) return 0; } +static int mtk_thermal_extract_efuse_v3(struct mtk_thermal *mt, u32 *buf) +{ + if (!CALIB_BUF1_VALID_V3(buf[1])) + return -EINVAL; + + mt->adc_oe = CALIB_BUF0_ADC_OE_V3(buf[0]); + mt->adc_ge = CALIB_BUF0_ADC_GE_V3(buf[0]); + mt->degc_cali = CALIB_BUF0_DEGC_CALI_V3(buf[0]); + mt->o_slope = CALIB_BUF0_O_SLOPE_V3(buf[0]); + mt->vts[VTS1] = CALIB_BUF1_VTS_TS1_V3(buf[1]); + mt->vts[VTS2] = CALIB_BUF1_VTS_TS2_V3(buf[1]); + mt->vts[VTSABB] = CALIB_BUF1_VTS_TSABB_V3(buf[1]); + mt->o_slope_sign = CALIB_BUF1_O_SLOPE_SIGN_V3(buf[1]); + + if (CALIB_BUF1_ID_V3(buf[1]) == 0) + mt->o_slope = 0; + + return 0; +} + static int mtk_thermal_get_calibration_data(struct device *dev, struct mtk_thermal *mt) { @@ -897,6 +1005,7 @@ static int mtk_thermal_get_calibration_data(struct device *dev, /* Start with default values */ mt->adc_ge = 512; + mt->adc_oe = 512; for (i = 0; i < mt->conf->num_sensors; i++) mt->vts[i] = 260; mt->degc_cali = 40; @@ -924,8 +1033,10 @@ static int mtk_thermal_get_calibration_data(struct device *dev, if (mt->conf->version == MTK_THERMAL_V1) ret = mtk_thermal_extract_efuse_v1(mt, buf); - else + else if (mt->conf->version == MTK_THERMAL_V2) ret = mtk_thermal_extract_efuse_v2(mt, buf); + else + ret = mtk_thermal_extract_efuse_v3(mt, buf); if (ret) { dev_info(dev, "Device not calibrated, using default calibration values\n"); @@ -955,6 +1066,10 @@ static const struct of_device_id mtk_thermal_of_match[] = { .compatible = "mediatek,mt7622-thermal", .data = (void *)&mt7622_thermal_data, }, + { + .compatible = "mediatek,mt7986-thermal", + .data = (void *)&mt7986_thermal_data, + }, { .compatible = "mediatek,mt8183-thermal", .data = (void *)&mt8183_thermal_data, @@ -1070,7 +1185,8 @@ static int mtk_thermal_probe(struct platform_device *pdev) goto err_disable_clk_auxadc; } - if (mt->conf->version == MTK_THERMAL_V2) { + if (mt->conf->version == MTK_THERMAL_V2 || + mt->conf->version == MTK_THERMAL_V3) { mtk_thermal_turn_on_buffer(apmixed_base); mtk_thermal_release_periodic_ts(mt, auxadc_base); } From patchwork Wed Nov 30 13:20:38 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 27791 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp921067wrr; Wed, 30 Nov 2022 05:22:56 -0800 (PST) X-Google-Smtp-Source: AA0mqf55ryvl03Nn6xU5acnyUfzgPFMK5lOct3VBzaGYJODD61YoePfKumNGacGYT/ttU7iJ1X1F X-Received: by 2002:a17:902:b942:b0:187:1b89:52da with SMTP id h2-20020a170902b94200b001871b8952damr45782206pls.172.1669814576531; Wed, 30 Nov 2022 05:22:56 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669814576; cv=none; d=google.com; s=arc-20160816; b=m6BJ5p5fh2cnr/MaX4MkuzqL9X4rWL5Cag8Mtk68n6g4dORrgQ4FXmNMOBdfzGIy25 JcG3DgNHTOghZsJphsypO1lgvqAkX0FUEhqxM3Xx16uYuctRT/7pUVA+AtHx9LHLf8Ig 4lwBCvq0kt4icGFmKkiVdRL8pHLKOduonjE04+u4q+gyEB4veYyiyxg0JXNOy0uL8ktx gkawauLYa6W1nawE/hPx2BJn63JADcUvxfr1yrTvdksG7A8dznn5RribSbCi90SC1mZe FxsbOpuXYN8kfgi8Q/sd25cil/FHSjlRUe0D6itgHZpExFVNHrVwmpjJ6JJFrO5mj81k w6Zw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-disposition:mime-version:message-id :subject:cc:to:from:date; bh=Ya6fKg+ST44CcgdMM2x2liWbss4d27nVXgG0v0fjkmY=; b=abyYWNukiJXH/Hm4nztGrvktvdSgkzuDnHmxiKLZgqGXFk3RHokMe1uDP1/VLt4Fax PBFCo+5i3/AiN5wgOiyoWaA9eYuhsHP10/YCjKEsZZHUYysl1JCO6CEVBrXMzthQmSBk w8yDuPVZymq/eA5HQikJ2FP2yZYDffk/GpTMS9HNCTrE+g5dwbBk1Xesd+M31XZtYS47 QLUVuNk6IZ5hQmSCQ4b4T/eX1bePYUswXWaaJXJLXX4qGwG2jKy9QoRjU/lNJKxib1bm d3kMQtrUJMG95GmGndVKZc5CTFCYTbUoGnH48usyPNeEUC8MsrOycqIBt99aqDSodBJU 2GFQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id 82-20020a630055000000b004785d1cf6c4si1304396pga.380.2022.11.30.05.22.43; Wed, 30 Nov 2022 05:22:56 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234392AbiK3NUu (ORCPT + 99 others); Wed, 30 Nov 2022 08:20:50 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57468 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229971AbiK3NUr (ORCPT ); Wed, 30 Nov 2022 08:20:47 -0500 Received: from fudo.makrotopia.org (fudo.makrotopia.org [IPv6:2a07:2ec0:3002::71]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E0BB627920; Wed, 30 Nov 2022 05:20:46 -0800 (PST) Received: from local by fudo.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.94.2) (envelope-from ) id 1p0N12-0006Bf-9f; Wed, 30 Nov 2022 14:20:44 +0100 Date: Wed, 30 Nov 2022 13:20:38 +0000 From: Daniel Golle To: linux-pm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org, devicetree@vger.kernel.org, "Rafael J. Wysocki" , Daniel Lezcano , Amit Kucheria , Krzysztof Kozlowski , Zhang Rui , Matthias Brugger , Rob Herring Cc: Steven Liu , Henry Yen Subject: [PATCH v2 2/2] dt-bindings: thermal: mediatek: add compatible string for MT7986 and MT7981 SoC Message-ID: MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_NONE, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1750927489211045963?= X-GMAIL-MSGID: =?utf-8?q?1750927489211045963?= Document compatible string 'mediatek,mt7986-thermal' for V3 thermal unit found in MT7986 SoCs. 'mediatek,mt7981-thermal' is also added as it is identical with the thermal unit of MT7986. Signed-off-by: Daniel Golle Acked-by: Krzysztof Kozlowski --- Changes since v1: Properly document both supported SoCs Documentation/devicetree/bindings/thermal/mediatek-thermal.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt index 5c7e7bdd029a..38b32bb447e3 100644 --- a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt +++ b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt @@ -13,6 +13,8 @@ Required properties: - "mediatek,mt2701-thermal" : For MT2701 family of SoCs - "mediatek,mt2712-thermal" : For MT2712 family of SoCs - "mediatek,mt7622-thermal" : For MT7622 SoC + - "mediatek,mt7981-thermal", "mediatek,mt7986-thermal" : For MT7981 SoC + - "mediatek,mt7986-thermal" : For MT7986 SoC - "mediatek,mt8183-thermal" : For MT8183 family of SoCs - "mediatek,mt8516-thermal", "mediatek,mt2701-thermal : For MT8516 family of SoCs - reg: Address range of the thermal controller