From nobody Sat Sep 21 19:57:26 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EC17ECCA487 for ; Wed, 20 Jul 2022 18:19:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238645AbiGTSTq (ORCPT ); Wed, 20 Jul 2022 14:19:46 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39570 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231140AbiGTSTk (ORCPT ); Wed, 20 Jul 2022 14:19:40 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E13066E8A0 for ; Wed, 20 Jul 2022 11:19:36 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id d8so7314597wrp.6 for ; Wed, 20 Jul 2022 11:19:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZaKDRIi1mwiob1WvFjjM3OHDQMYuXFWnH3kW9ZW5SAg=; b=PsYMIxchceuMbJ1CYX1Lrbh35TmnoRKSEf1vIjaTvY/UZvH3gBMGBuouo7S69kLVgm nSNPnSdFJWxJkJxc9dI9j4SMPOljPPgIyvOHlFHurFBpVhbP/jxmO58faQftUEr3lR4m LqkenqpuNZhMsXjBngfX4hGQN96QLqmCyufF4rN7VV8bn+98z49tnqB3Xd0dDMVvDNBz wf600N0N1bL/1Kq5XZeQ0nlnP6OEEb2BMg9uq3rJDKqqF+kDSWya2YpU+xvSvjrD7YV5 WjwHWdE3T0pPMx+lfoosC2NrEAkSaAHhVhOrje7/m2eO9/AUEfQ78yACHHQyshF926tl QG0g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ZaKDRIi1mwiob1WvFjjM3OHDQMYuXFWnH3kW9ZW5SAg=; b=DkniQ7Zpi89KF+tnwkgt5RzltjO/0s3XpnTuxu8i7tmzD1beIe2ma51rg9higVOBWw s6YP8OfA+dreFOCPfpk/nMULp55yAD8DvxBhJaBfcc3awK5+McyFGEidPkdYBXcTvAgY 2Osrua8Ut1JNy+/0pB3trl0YaqxDcK9gvkSgMs5IVbPXooo24R7thHRjvYKMyKcKIWve uvKVQWqknkqxOK2gEO8BHBJCfuT1+ssRjE0UPAgDgn2iHfU3DqIHpjBhEyFbYnVFa5wM 2M17Rj7APOIpZXN29+KxffETbawjoQBzImfBw2ZYzIUifhp48eYVokJxI3V210qbEkzX /6OQ== X-Gm-Message-State: AJIora8FvYMcFqQzMLFTkwEct95wluTX8pG072bSgKKASrc7ETdK5Iej QNTSzM+IsCnfMbq+ppEUYyP8uw== X-Google-Smtp-Source: AGRyM1vjGU1aqaq3plo8ZMZ8Ne3fvGE9Cpnovf6zPJ/qO2LpFTeedX0ODd747EfnXKB+paAVbEXf8Q== X-Received: by 2002:a5d:4b51:0:b0:21e:504a:b597 with SMTP id w17-20020a5d4b51000000b0021e504ab597mr1221393wrs.175.1658341175489; Wed, 20 Jul 2022 11:19:35 -0700 (PDT) Received: from amjad-ThinkPad-T490.home (2a01cb040613180084408ac44a1fa242.ipv6.abo.wanadoo.fr. [2a01:cb04:613:1800:8440:8ac4:4a1f:a242]) by smtp.googlemail.com with ESMTPSA id z17-20020a05600c0a1100b003a31d200a7dsm3400093wmp.9.2022.07.20.11.19.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 11:19:34 -0700 (PDT) From: Amjad Ouled-Ameur To: matthias.bgg@gmail.com Cc: rafael@kernel.org, fparent@baylibre.com, amitk@kernel.org, daniel.lezcano@linaro.org, devicetree@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-pm@vger.kernel.org, robh+dt@kernel.org, rui.zhang@intel.com, Amjad Ouled-Ameur Subject: [PATCH v2 1/4] dt-bindings: thermal: mediatek: add binding documentation for MT8365 SoC Date: Wed, 20 Jul 2022 20:18:51 +0200 Message-Id: <20220720181854.547881-2-aouledameur@baylibre.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220720181854.547881-1-aouledameur@baylibre.com> References: <20220720181854.547881-1-aouledameur@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Fabien Parent Add the binding documentation for the thermal support on MT8365 SoC. Signed-off-by: Fabien Parent Acked-by: Amjad Ouled-Ameur Reviewed-by: AngeloGioacchino Del Regno Reviewed-by: Matthias Brugger --- Documentation/devicetree/bindings/thermal/mediatek-thermal.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt= b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt index 5c7e7bdd029a..ba4ebffeade4 100644 --- a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt +++ b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt @@ -14,6 +14,7 @@ Required properties: - "mediatek,mt2712-thermal" : For MT2712 family of SoCs - "mediatek,mt7622-thermal" : For MT7622 SoC - "mediatek,mt8183-thermal" : For MT8183 family of SoCs + - "mediatek,mt8365-thermal" : For MT8365 family of SoCs - "mediatek,mt8516-thermal", "mediatek,mt2701-thermal : For MT8516 famil= y of SoCs - reg: Address range of the thermal controller - interrupts: IRQ for the thermal controller --=20 2.37.1 From nobody Sat Sep 21 19:57:26 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EECD1C433EF for ; Wed, 20 Jul 2022 18:19:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239036AbiGTSTr (ORCPT ); Wed, 20 Jul 2022 14:19:47 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39584 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231182AbiGTSTk (ORCPT ); Wed, 20 Jul 2022 14:19:40 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91CD96EEA9 for ; Wed, 20 Jul 2022 11:19:38 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id d16so27261050wrv.10 for ; Wed, 20 Jul 2022 11:19:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=M1i/0wxRYmvrq6IC7mxhkb2dRV6n4m0qx9SiTZ66LUU=; b=wvCG72+dVbH7vC+FUiUiUlZLxbALX+w2Lr0IOikvpCsLmFn/hOeBIaU1YlrucX7yL0 eERwlr2Ukp2ApNoHVB1QEbN8/S97JCgyHnd1G5ui1uHtcXt4utmSF8MqT9F6XOqlkOau BVOSKeeOoac70OVEa5AzbQQTN3HkwsEfSn9yUksbY25M800xZcNukN9m6l5Bgg5t3hKI gA5GkJVNEw6ZgAi8e7HqFyotAqPQ8nqnjukf+O3sZJH9sY/uP2491T06zRvdODu1SYyW BiWDw1S84c++vZO2E/yFCJwhoM5h8V0HJq203Dvbdpvvamr1dtjJGUwDtkjs61gAA9sP 17/A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=M1i/0wxRYmvrq6IC7mxhkb2dRV6n4m0qx9SiTZ66LUU=; b=RiL0Fj4elgb5PCIUy8WdD2beQnZzB449x0Caoke4Eztq9bHqrd7BuNbV2duL8wKrvl SQvqtcZ1Imue2ZMfVfePE3NM+v9IszecC9hSzwepz3xxYA/pDmVTyGUrSGOoJwADC5cI hY5+lgiwqiLkh1Ij4eG+pJd0zpSrAnu1V21Qr6Q7hDpLCKFnbfvH8JZzaL7zABRM6++5 RdvUMUtjwqnyrqktDc8HRk53AUZZAi7UjUbWNO5/yCqUwvGTwRNr4u3IqSUtNo1V+xMA 7awUIs22rPoxqrwkWOlCc497w9+4Y4CuRS6BoTn4fsgWb/xR5MMV0R0lHASlz5qgmTGo 8dwg== X-Gm-Message-State: AJIora8Z1FGJVtuxNPwhB4b1abkVsZxAWbhR3TsQlsQNJMsBKu7L7uZR 3LlvpWZkzo4GfyFzXeiPMF8vVA== X-Google-Smtp-Source: AGRyM1tJ4ApcHLOkGHWBDanLWrqSKlCjxj6zPXkPYwhUuUsm0V8vXlTq1CWrLAzMq0bV+3Xvi5jBXw== X-Received: by 2002:a05:6000:1545:b0:21d:8f3e:a0bd with SMTP id 5-20020a056000154500b0021d8f3ea0bdmr32428629wry.697.1658341176950; Wed, 20 Jul 2022 11:19:36 -0700 (PDT) Received: from amjad-ThinkPad-T490.home (2a01cb040613180084408ac44a1fa242.ipv6.abo.wanadoo.fr. [2a01:cb04:613:1800:8440:8ac4:4a1f:a242]) by smtp.googlemail.com with ESMTPSA id z17-20020a05600c0a1100b003a31d200a7dsm3400093wmp.9.2022.07.20.11.19.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 11:19:35 -0700 (PDT) From: Amjad Ouled-Ameur To: matthias.bgg@gmail.com Cc: rafael@kernel.org, fparent@baylibre.com, amitk@kernel.org, daniel.lezcano@linaro.org, devicetree@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-pm@vger.kernel.org, robh+dt@kernel.org, rui.zhang@intel.com, Amjad Ouled-Ameur Subject: [PATCH v2 2/4] thermal: mediatek: add support for MT8365 SoC Date: Wed, 20 Jul 2022 20:18:52 +0200 Message-Id: <20220720181854.547881-3-aouledameur@baylibre.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220720181854.547881-1-aouledameur@baylibre.com> References: <20220720181854.547881-1-aouledameur@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Fabien Parent MT8365 is similar to the other SoCs supported by the driver. It has only one bank and 3 actual sensors that can be multiplexed. There is another one sensor that does not have usable data. Signed-off-by: Fabien Parent Reviewed-by: Amjad Ouled-Ameur Tested-by: Amjad Ouled-Ameur --- drivers/thermal/mtk_thermal.c | 68 +++++++++++++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c index ede94eadddda..216eb0d61c5b 100644 --- a/drivers/thermal/mtk_thermal.c +++ b/drivers/thermal/mtk_thermal.c @@ -31,6 +31,7 @@ #define AUXADC_CON2_V 0x010 #define AUXADC_DATA(channel) (0x14 + (channel) * 4) =20 +#define APMIXED_SYS_TS_CON0 0x600 #define APMIXED_SYS_TS_CON1 0x604 =20 /* Thermal Controller Registers */ @@ -245,6 +246,17 @@ enum mtk_thermal_version { /* The calibration coefficient of sensor */ #define MT8183_CALIBRATION 153 =20 +/* MT8365 */ +#define MT8365_TEMP_AUXADC_CHANNEL 11 +#define MT8365_CALIBRATION 164 +#define MT8365_NUM_CONTROLLER 1 +#define MT8365_NUM_BANKS 1 +#define MT8365_NUM_SENSORS 3 +#define MT8365_NUM_SENSORS_PER_ZONE 3 +#define MT8365_TS1 0 +#define MT8365_TS2 1 +#define MT8365_TS3 2 + struct mtk_thermal; =20 struct thermal_bank_cfg { @@ -386,6 +398,24 @@ static const int mt7622_mux_values[MT7622_NUM_SENSORS]= =3D { 0, }; static const int mt7622_vts_index[MT7622_NUM_SENSORS] =3D { VTS1 }; static const int mt7622_tc_offset[MT7622_NUM_CONTROLLER] =3D { 0x0, }; =20 +/* MT8365 thermal sensor data */ +static const int mt8365_bank_data[MT8365_NUM_SENSORS] =3D { + MT8365_TS1, MT8365_TS2, MT8365_TS3 +}; + +static const int mt8365_msr[MT8365_NUM_SENSORS_PER_ZONE] =3D { + TEMP_MSR0, TEMP_MSR1, TEMP_MSR2 +}; + +static const int mt8365_adcpnp[MT8365_NUM_SENSORS_PER_ZONE] =3D { + TEMP_ADCPNP0, TEMP_ADCPNP1, TEMP_ADCPNP2 +}; + +static const int mt8365_mux_values[MT8365_NUM_SENSORS] =3D { 0, 1, 2 }; +static const int mt8365_tc_offset[MT8365_NUM_CONTROLLER] =3D { 0 }; + +static const int mt8365_vts_index[MT8365_NUM_SENSORS] =3D { VTS1, VTS2, VT= S3 }; + /* * The MT8173 thermal controller has four banks. Each bank can read up to * four temperature sensors simultaneously. The MT8173 has a total of 5 @@ -460,6 +490,40 @@ static const struct mtk_thermal_data mt2701_thermal_da= ta =3D { .version =3D MTK_THERMAL_V1, }; =20 +/* + * The MT8365 thermal controller has one bank, which can read up to + * four temperature sensors simultaneously. The MT8365 has a total of 3 + * temperature sensors. + * + * The thermal core only gets the maximum temperature of this one bank, + * so the bank concept wouldn't be necessary here. However, the SVS (Smart + * Voltage Scaling) unit makes its decisions based on the same bank + * data. + */ +static const struct mtk_thermal_data mt8365_thermal_data =3D { + .auxadc_channel =3D MT8365_TEMP_AUXADC_CHANNEL, + .num_banks =3D MT8365_NUM_BANKS, + .num_sensors =3D MT8365_NUM_SENSORS, + .vts_index =3D mt8365_vts_index, + .cali_val =3D MT8365_CALIBRATION, + .num_controller =3D MT8365_NUM_CONTROLLER, + .controller_offset =3D mt8365_tc_offset, + .need_switch_bank =3D false, + .bank_data =3D { + { + .num_sensors =3D MT8365_NUM_SENSORS, + .sensors =3D mt8365_bank_data + }, + }, + .msr =3D mt8365_msr, + .adcpnp =3D mt8365_adcpnp, + .sensor_mux_values =3D mt8365_mux_values, + .version =3D MTK_THERMAL_V1, + .apmixed_buffer_ctl_reg =3D APMIXED_SYS_TS_CON0, + .apmixed_buffer_ctl_mask =3D (u32) ~GENMASK(29, 28), + .apmixed_buffer_ctl_set =3D 0, +}; + /* * The MT2712 thermal controller has one bank, which can read up to * four temperature sensors simultaneously. The MT2712 has a total of 4 @@ -958,6 +1022,10 @@ static const struct of_device_id mtk_thermal_of_match= [] =3D { { .compatible =3D "mediatek,mt8183-thermal", .data =3D (void *)&mt8183_thermal_data, + }, + { + .compatible =3D "mediatek,mt8365-thermal", + .data =3D (void *)&mt8365_thermal_data, }, { }, }; --=20 2.37.1 From nobody Sat Sep 21 19:57:26 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 921D1C43334 for ; Wed, 20 Jul 2022 18:19:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239939AbiGTSTx (ORCPT ); Wed, 20 Jul 2022 14:19:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39614 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229953AbiGTSTl (ORCPT ); Wed, 20 Jul 2022 14:19:41 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4D68D6F7E2 for ; Wed, 20 Jul 2022 11:19:39 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id b26so27295170wrc.2 for ; Wed, 20 Jul 2022 11:19:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=u7ClOaY29q/UhKGleJgriKV9seCgrAHzD4o55sbVqbE=; b=U25zxMuTlfG9FKoGJ8D0VJx2M73CYydlvOMHsJis/rV0YVmrC6mR0xG6wVsf0jVtsh LGYhX+2OZHZGLcWAYcBwN/kxj5pEKVfWT5CI5VYGAljVYrY+Tc6MtBikiOmQJ2WG1ElO ORuSxTh7fBcVgNVov8LDetdZJ0eiSyVtZZy/l1UjoMgZsBV8SEaNK5YFxMt6TSF63ODI ZSH8Q+t/5HwvjV+sbwr7RV8a1wYelm/dKcbV6mwjwG45OHZsG1YqVIniZL7nYRd1elvv rEW6Wxoz3UwFc07F5QgYKPyJCr2UYU/mr7bNC/sdKOddwNjIN8nGLWnMAxzpqeAOqmvF 6cAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=u7ClOaY29q/UhKGleJgriKV9seCgrAHzD4o55sbVqbE=; b=4TZClkZg3BAw/cJ4XdLvqYgdTVj7Q+pHb0lINWEPK3Dt8QtczYriL7I1ctRlHaNkug 38SRrKW7jaPYQIvep6+/QsVrNQIlqZExfYLLg2CU+WYPB6EAWWEbeP2ZEaLSaoyMY0oS /R3YNuLctRz6nxlzyCWT3HCWAfJNny2cnTxy3uePnJt8PPWWZyehMzvxhjyIvCwzgUll slKf2eSMxTnfZ97et4Fll8QcuJ5Fa7+4ssQtWvzlBhIKXgG2rKg6knJSCQ90D5gTWLdW tqnmHV5+TrZUFwTzRZzAwDEVHP4LfkrVUjakwrdFv/ZnWtjPankHGd7tbI52vS7sH897 iaNg== X-Gm-Message-State: AJIora9IA0y8P0wLAEDJ61NhktcLwkGwr3XSsRG3lYmAAbdlIwyOdywb b7w932wQlQr2FBMxFhBlCg4Xuw== X-Google-Smtp-Source: AGRyM1vfj2pobuNQH2wthtGApjgEuP8BunLn/EqZqFLAOjATur0M5PpTlWR4RkCynwXU5aGpbpkUkw== X-Received: by 2002:adf:ee4b:0:b0:21e:4ecf:b150 with SMTP id w11-20020adfee4b000000b0021e4ecfb150mr2128791wro.290.1658341177830; Wed, 20 Jul 2022 11:19:37 -0700 (PDT) Received: from amjad-ThinkPad-T490.home (2a01cb040613180084408ac44a1fa242.ipv6.abo.wanadoo.fr. [2a01:cb04:613:1800:8440:8ac4:4a1f:a242]) by smtp.googlemail.com with ESMTPSA id z17-20020a05600c0a1100b003a31d200a7dsm3400093wmp.9.2022.07.20.11.19.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 11:19:37 -0700 (PDT) From: Amjad Ouled-Ameur To: matthias.bgg@gmail.com Cc: rafael@kernel.org, fparent@baylibre.com, amitk@kernel.org, daniel.lezcano@linaro.org, devicetree@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-pm@vger.kernel.org, robh+dt@kernel.org, rui.zhang@intel.com, Markus Schneider-Pargmann , Amjad Ouled-Ameur Subject: [PATCH v2 3/4] thermal: mediatek: control buffer enablement tweaks Date: Wed, 20 Jul 2022 20:18:53 +0200 Message-Id: <20220720181854.547881-4-aouledameur@baylibre.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220720181854.547881-1-aouledameur@baylibre.com> References: <20220720181854.547881-1-aouledameur@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Markus Schneider-Pargmann Add logic in order to be able to turn on the control buffer on MT8365. This change now allows to have control buffer support for MTK_THERMAL_V1, and it allows to define the register offset, and mask used to enable it. Signed-off-by: Markus Schneider-Pargmann Signed-off-by: Fabien Parent Reviewed-by: Amjad Ouled-Ameur Tested-by: Amjad Ouled-Ameur --- drivers/thermal/mtk_thermal.c | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c index 216eb0d61c5b..1dc276f8c4f1 100644 --- a/drivers/thermal/mtk_thermal.c +++ b/drivers/thermal/mtk_thermal.c @@ -283,6 +283,9 @@ struct mtk_thermal_data { bool need_switch_bank; struct thermal_bank_cfg bank_data[MAX_NUM_ZONES]; enum mtk_thermal_version version; + u32 apmixed_buffer_ctl_reg; + u32 apmixed_buffer_ctl_mask; + u32 apmixed_buffer_ctl_set; }; =20 struct mtk_thermal { @@ -578,6 +581,9 @@ static const struct mtk_thermal_data mt7622_thermal_dat= a =3D { .adcpnp =3D mt7622_adcpnp, .sensor_mux_values =3D mt7622_mux_values, .version =3D MTK_THERMAL_V2, + .apmixed_buffer_ctl_reg =3D APMIXED_SYS_TS_CON1, + .apmixed_buffer_ctl_mask =3D ~0x37, + .apmixed_buffer_ctl_set =3D 0x1, }; =20 /* @@ -1031,14 +1037,18 @@ static const struct of_device_id mtk_thermal_of_mat= ch[] =3D { }; MODULE_DEVICE_TABLE(of, mtk_thermal_of_match); =20 -static void mtk_thermal_turn_on_buffer(void __iomem *apmixed_base) +static void mtk_thermal_turn_on_buffer(struct mtk_thermal *mt, + void __iomem *apmixed_base) { int tmp; =20 - tmp =3D readl(apmixed_base + APMIXED_SYS_TS_CON1); - tmp &=3D ~(0x37); - tmp |=3D 0x1; - writel(tmp, apmixed_base + APMIXED_SYS_TS_CON1); + if (!mt->conf->apmixed_buffer_ctl_reg) + return; + + tmp =3D readl(apmixed_base + mt->conf->apmixed_buffer_ctl_reg); + tmp &=3D mt->conf->apmixed_buffer_ctl_mask; + tmp |=3D mt->conf->apmixed_buffer_ctl_set; + writel(tmp, apmixed_base + mt->conf->apmixed_buffer_ctl_reg); udelay(200); } =20 @@ -1138,8 +1148,9 @@ static int mtk_thermal_probe(struct platform_device *= pdev) goto err_disable_clk_auxadc; } =20 + mtk_thermal_turn_on_buffer(mt, apmixed_base); + if (mt->conf->version =3D=3D MTK_THERMAL_V2) { - mtk_thermal_turn_on_buffer(apmixed_base); mtk_thermal_release_periodic_ts(mt, auxadc_base); } =20 --=20 2.37.1 From nobody Sat Sep 21 19:57:26 2024 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id A15A0CCA485 for ; Wed, 20 Jul 2022 18:19:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239526AbiGTSTt (ORCPT ); Wed, 20 Jul 2022 14:19:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233833AbiGTSTm (ORCPT ); Wed, 20 Jul 2022 14:19:42 -0400 Received: from mail-wm1-x336.google.com (mail-wm1-x336.google.com [IPv6:2a00:1450:4864:20::336]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCC8868DDE for ; Wed, 20 Jul 2022 11:19:40 -0700 (PDT) Received: by mail-wm1-x336.google.com with SMTP id j29-20020a05600c1c1d00b003a2fdafdefbso1792850wms.2 for ; Wed, 20 Jul 2022 11:19:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=/6t1tJznirgBuuhOslr+HrbK0FgxfxpNokiZkLl87qc=; b=jIbnUzr1HAn9joeLX2mrLV6691ELQKqEy3owuhkejKOCKt1cASKXXjB9wMEUyO/jrT s5tUtyzbn1t8G+kZJlIz/Cm67eUcjlh2SfDztzDnH4anMCmyswzuGwbtcoS4ncqRGF2p VoIe1ei2yB23cyB0YfUNuRmPsckQTAWU3G9X8cE3hJmIKjd1U5KyJWwdCwLwdsqizYma sr3KF6IDMPBE6gDy6iX8BTEcU6tJgdBJ+goHrNSSkiuIsJZ+cC0W7d/DwtWQsu/ud2et wOuoUgoaFTHv+6xS/TSJEfF4GvTFskkxX3jdr+EZ7ilhR0NVjqIRQO7vJ7CvmBaDRXeb RxNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=/6t1tJznirgBuuhOslr+HrbK0FgxfxpNokiZkLl87qc=; b=0rwa3F/g9WPy1+7GYDhAGQmrGDhUcV2wqY29xS1LpH10dKs5799wVQ1nPgP5SeefaG sUAMVhkB1VZtFHmceq3e24VCPbX21r7QAfhrx5v4v53kiyFQw9AqT0DeIJLRMJ5XnTlz xkPKu3mC8bGcTj+x1XRQ7oceBacIzdEB1mkeN11Fr/b3xgZaoDtGB4yux6orTjA8Y12B vvS6A9Fgn4/rYIRwuHl69Tkk6Rj9NRvufdwKj3Af7hbMGTRY7/ZCzXVEZExdsWlBmsbr zDYu4LgjuQEC5jtl0f0D51QCPhg4v++Kn8Qlhuv+zyJcw2U/1LImTAPhKKb4q7T4CvfC 5hYQ== X-Gm-Message-State: AJIora+rv+vD8D68Xc4PpkAUxUw69k07zGseYr8OmYyg+8iojVpts7WX /paxsrxiKHtL6V5lztnQ2EH7OA== X-Google-Smtp-Source: AGRyM1uGKhBM5kBeoQFZ7rJFvEZczSvd1eckDYJ1dkCuDSNjsIsqpCTaawcB/4Ev9F6PK/fbasFdmQ== X-Received: by 2002:a05:600c:1d8a:b0:3a3:1104:88ad with SMTP id p10-20020a05600c1d8a00b003a3110488admr4894543wms.179.1658341179153; Wed, 20 Jul 2022 11:19:39 -0700 (PDT) Received: from amjad-ThinkPad-T490.home (2a01cb040613180084408ac44a1fa242.ipv6.abo.wanadoo.fr. [2a01:cb04:613:1800:8440:8ac4:4a1f:a242]) by smtp.googlemail.com with ESMTPSA id z17-20020a05600c0a1100b003a31d200a7dsm3400093wmp.9.2022.07.20.11.19.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 20 Jul 2022 11:19:38 -0700 (PDT) From: Amjad Ouled-Ameur To: matthias.bgg@gmail.com Cc: rafael@kernel.org, fparent@baylibre.com, amitk@kernel.org, daniel.lezcano@linaro.org, devicetree@vger.kernel.org, krzysztof.kozlowski+dt@linaro.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org, linux-pm@vger.kernel.org, robh+dt@kernel.org, rui.zhang@intel.com, Amjad Ouled-Ameur , default avatarMichael Kao , default avatarHsin-Yi Wang Subject: [PATCH v2 4/4] thermal: mediatek: add another get_temp ops for thermal sensors Date: Wed, 20 Jul 2022 20:18:54 +0200 Message-Id: <20220720181854.547881-5-aouledameur@baylibre.com> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220720181854.547881-1-aouledameur@baylibre.com> References: <20220720181854.547881-1-aouledameur@baylibre.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" Provide thermal zone to read thermal sensor in the SoC. We can read all the thermal sensors value in the SoC by the node /sys/class/thermal/ In mtk_thermal_bank_temperature, return -EAGAIN instead of -EACCESS on the first read of sensor that often are bogus values. This can avoid following warning on boot: thermal thermal_zone6: failed to read out thermal zone (-13) Signed-off-by: default avatarMichael Kao Signed-off-by: default avatarHsin-Yi Wang Signed-off-by: Amjad Ouled-Ameur Tested-by: Amjad Ouled-Ameur --- drivers/thermal/mtk_thermal.c | 100 ++++++++++++++++++++++++++-------- 1 file changed, 76 insertions(+), 24 deletions(-) diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c index 1dc276f8c4f1..79b14ce1a08d 100644 --- a/drivers/thermal/mtk_thermal.c +++ b/drivers/thermal/mtk_thermal.c @@ -259,6 +259,11 @@ enum mtk_thermal_version { =20 struct mtk_thermal; =20 +struct mtk_thermal_zone { + struct mtk_thermal *mt; + int id; +}; + struct thermal_bank_cfg { unsigned int num_sensors; const int *sensors; @@ -709,6 +714,32 @@ static void mtk_thermal_put_bank(struct mtk_thermal_ba= nk *bank) mutex_unlock(&mt->lock); } =20 +static u32 _get_sensor_temp(struct mtk_thermal *mt, int id) +{ + u32 raw; + int temp; + + const struct mtk_thermal_data *conf =3D mt->conf; + + raw =3D readl(mt->thermal_base + conf->msr[id]); + + if (mt->conf->version =3D=3D MTK_THERMAL_V1) + temp =3D raw_to_mcelsius_v1(mt, id, raw); + else + temp =3D raw_to_mcelsius_v2(mt, id, raw); + + /* + * The first read of a sensor often contains very high bogus + * temperature value. Filter these out so that the system does + * not immediately shut down. + */ + + if (temp > 200000) + return -EAGAIN; + else + return temp; +} + /** * mtk_thermal_bank_temperature - get the temperature of a bank * @bank: The bank @@ -721,26 +752,9 @@ static int mtk_thermal_bank_temperature(struct mtk_the= rmal_bank *bank) struct mtk_thermal *mt =3D bank->mt; const struct mtk_thermal_data *conf =3D mt->conf; int i, temp =3D INT_MIN, max =3D INT_MIN; - u32 raw; =20 for (i =3D 0; i < conf->bank_data[bank->id].num_sensors; i++) { - raw =3D readl(mt->thermal_base + conf->msr[i]); - - if (mt->conf->version =3D=3D MTK_THERMAL_V1) { - temp =3D raw_to_mcelsius_v1( - mt, conf->bank_data[bank->id].sensors[i], raw); - } else { - temp =3D raw_to_mcelsius_v2( - mt, conf->bank_data[bank->id].sensors[i], raw); - } - - /* - * The first read of a sensor often contains very high bogus - * temperature value. Filter these out so that the system does - * not immediately shut down. - */ - if (temp > 200000) - temp =3D 0; + temp =3D _get_sensor_temp(mt, i); =20 if (temp > max) max =3D temp; @@ -751,7 +765,8 @@ static int mtk_thermal_bank_temperature(struct mtk_ther= mal_bank *bank) =20 static int mtk_read_temp(void *data, int *temperature) { - struct mtk_thermal *mt =3D data; + struct mtk_thermal_zone *tz =3D data; + struct mtk_thermal *mt =3D tz->mt; int i; int tempmax =3D INT_MIN; =20 @@ -770,10 +785,28 @@ static int mtk_read_temp(void *data, int *temperature) return 0; } =20 +static int mtk_read_sensor_temp(void *data, int *temperature) +{ + struct mtk_thermal_zone *tz =3D data; + struct mtk_thermal *mt =3D tz->mt; + int id =3D tz->id - 1; + + if (id < 0) + return -EACCES; + + *temperature =3D _get_sensor_temp(mt, id); + + return 0; +} + static const struct thermal_zone_of_device_ops mtk_thermal_ops =3D { .get_temp =3D mtk_read_temp, }; =20 +static const struct thermal_zone_of_device_ops mtk_thermal_sensor_ops =3D { + .get_temp =3D mtk_read_sensor_temp, +}; + static void mtk_thermal_init_bank(struct mtk_thermal *mt, int num, u32 apmixed_phys_base, u32 auxadc_phys_base, int ctrl_id) @@ -1072,6 +1105,7 @@ static int mtk_thermal_probe(struct platform_device *= pdev) u64 auxadc_phys_base, apmixed_phys_base; struct thermal_zone_device *tzdev; void __iomem *apmixed_base, *auxadc_base; + struct mtk_thermal_zone *tz; =20 mt =3D devm_kzalloc(&pdev->dev, sizeof(*mt), GFP_KERNEL); if (!mt) @@ -1161,11 +1195,29 @@ static int mtk_thermal_probe(struct platform_device= *pdev) =20 platform_set_drvdata(pdev, mt); =20 - tzdev =3D devm_thermal_zone_of_sensor_register(&pdev->dev, 0, mt, - &mtk_thermal_ops); - if (IS_ERR(tzdev)) { - ret =3D PTR_ERR(tzdev); - goto err_disable_clk_peri_therm; + for (i =3D 0; i < mt->conf->num_sensors + 1; i++) { + tz =3D kmalloc(sizeof(*tz), GFP_KERNEL); + if (!tz) + return -ENOMEM; + + tz->mt =3D mt; + tz->id =3D i; + + tzdev =3D devm_thermal_zone_of_sensor_register(&pdev->dev, i, tz, (i =3D= =3D 0) ? + &mtk_thermal_ops : + &mtk_thermal_sensor_ops); + + if (IS_ERR(tzdev)) { + if (PTR_ERR(tzdev) =3D=3D -ENODEV) { + dev_warn(&pdev->dev, + "sensor %d not registered in thermal zone in dt\n", i); + continue; + } + if (PTR_ERR(tzdev) =3D=3D -EACCES) { + ret =3D PTR_ERR(tzdev); + goto err_disable_clk_peri_therm; + } + } } =20 ret =3D devm_thermal_add_hwmon_sysfs(tzdev); --=20 2.37.1