From nobody Sat Sep 21 17:13:59 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 29EF9ECAAD3 for ; Thu, 1 Sep 2022 13:41:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232973AbiIANlp (ORCPT ); Thu, 1 Sep 2022 09:41:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43630 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232561AbiIANlW (ORCPT ); Thu, 1 Sep 2022 09:41:22 -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 A2F612DAB5 for ; Thu, 1 Sep 2022 06:40:08 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id n17so22413796wrm.4 for ; Thu, 01 Sep 2022 06:40:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=KCPcoUB7YiwSSscJBnh3JUInbmnv/uLJ/66Lvn6Y6Yk=; b=DWof82jkuxZ3n6qKS1EJKURTcSwcpmtxTYMAj/vYMQobBAxY2dZV1YyE7wyJpx2g2E 2LKkmPmH9KHkSJ+JUqRatHWEGRzoCsS89jQe5VGzGWBHD4UPkFPrdnI154eRSDMPDSMP 4F9Q0rmuAkQyRzb2LsOFyCXFa7JDTVvy6wEnlKGxMfrz1TiArI1xgnjCCix7ognj6S+y l/B14A4qUpHABLSuQ8hILmqGLFcQeWlUT+kqx1bxS+qIyg3ANii4YB40pSAezoOLLqs6 TYWYGehFj+25Tgv99GVaRebUxsWdI/W2TfKTuA+TFQPgvNuDqnt3j411E7ow6099AUnt Blkg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=KCPcoUB7YiwSSscJBnh3JUInbmnv/uLJ/66Lvn6Y6Yk=; b=6V4WAJAQoHoqz8Pp+eDa9M1yR7JSm2tjinoq30VaZIx8O3UUDhcOTiGLml2I7os2Ay jMFmxVjxIgNwz7f0zIMVGYZCDlIfdUh1/W+bwGFw/cTpd4TaDzHaRe7Qcu9rp1KZN3ov vVeQg9KhJRicfu/IaUrVEVnSny8oWtDM1e67nNlxEnMnzrpRHqrQuimw7YGX8UcFB87X QqlxidLZyBegdYjznkX5Ohguh4eirAtkGBLHM+VyznABUfLXvdf1/o/qgY3CwgY7L2AE xqDvyA63OORXlUNbj8Pa7VEYgmS3naY1tq9ak2NHGZZtfRbo9Pyb07F+ZUkElRVOGgo+ 45KQ== X-Gm-Message-State: ACgBeo2pFt9mhzbbiU7Lcys3jYK5/2cIdTy0j9vjkH7hbuFjE494RxEA +0Us2XBDdSGIPpNYAcrJaGrQCQ== X-Google-Smtp-Source: AA6agR55XF5dbEcnTiR/UclqwGBi/5TuoAKQ/vTJ0Bk12CiomfceiUFfMs0rxZEZ/oAupen1Fx/ltg== X-Received: by 2002:a05:6000:1374:b0:226:93af:9c26 with SMTP id q20-20020a056000137400b0022693af9c26mr13887160wrz.188.1662039602954; Thu, 01 Sep 2022 06:40:02 -0700 (PDT) Received: from localhost.localdomain (210.145.15.109.rev.sfr.net. [109.15.145.210]) by smtp.googlemail.com with ESMTPSA id e3-20020adfe383000000b0021ef34124ebsm15399016wrm.11.2022.09.01.06.40.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 06:40:02 -0700 (PDT) From: Amjad Ouled-Ameur To: matthias.bgg@gmail.com Cc: Fabien Parent , rafael@kernel.org, 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 , AngeloGioacchino Del Regno Subject: [PATCH v3 1/4] dt-bindings: thermal: mediatek: add binding documentation for MT8365 SoC Date: Thu, 1 Sep 2022 15:39:47 +0200 Message-Id: <20220901133950.115122-2-aouledameur@baylibre.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220901133950.115122-1-aouledameur@baylibre.com> References: <20220901133950.115122-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 Signed-off-by: Amjad Ouled-Ameur Reviewed-by: Matthias Brugger Reviewed-by: AngeloGioacchino Del Regno Acked-by: Rob Herring --- 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.3 From nobody Sat Sep 21 17:13:59 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 B1837C0502C for ; Thu, 1 Sep 2022 13:41:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231351AbiIANlx (ORCPT ); Thu, 1 Sep 2022 09:41:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45944 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233394AbiIANlZ (ORCPT ); Thu, 1 Sep 2022 09:41:25 -0400 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C3B54FF1 for ; Thu, 1 Sep 2022 06:40:08 -0700 (PDT) Received: by mail-wr1-x42f.google.com with SMTP id u18so9747324wrq.10 for ; Thu, 01 Sep 2022 06:40:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=stpnIznClyFbSSAZ9XIBAQVJVqGJPgWnuEIsfvw/Kgw=; b=SgocxATs9nG+dO5eC5Ry/p9RAchwAh7Dpb52+4CBAMfh5whV5zASWzF3gBuq1hnzwp M+7JtEjt88ret/I+CXbQ/8eC7JhJZZYpUMr9LIXHTG//b8nmupFzHkcA4LJTWam7pZbN QBEVv+DsJY1rMjqi9UwKNxes6DzYt2FsHkrUVjyhamtSGhaNqs25BKDjTXNKk09vaU3e 5Yey/AIv9z1PeDrbwbxvkjhbGh/JUK1k7rdBskyuIVcMMC9wZb8GxUwSHKfubs+QiSld cv+od58WOfHDtJuJll+69LK2+7eNURITPegLYKastnotHmlVwhKrU1nx5L/e+r0bg/SB S5Yg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=stpnIznClyFbSSAZ9XIBAQVJVqGJPgWnuEIsfvw/Kgw=; b=YmWqmK6L9zZOwwO/nK/nibfd02T6UtDP5Llv2v+v/xx83ZiJXgvlZD+PH8665y7Fy7 caRrmES+J9ybWCquplERsH6duhX6pQye6FsnuDb3oYHvGIO58TLP9Bf2/6jeO6+0u06m jS9uyTU79djmd9Nj5g/3k42I1LDjR8SJevjMlO4ZBoOKlcj/PTH5pHCFqqT6AwM62z55 lH1Npc4PNEhghmt3/CzX50wpO1RXY4n7R93DNqAL+ztqn0nUEelTqEdmMc8l7ZHnb7O8 ta2efOyTm0lmwDuw+Yfxlq9xofX20xviMCjQ5QrL9Zc/iX9o+q2itXZhz9CMvlDKdx26 +VHg== X-Gm-Message-State: ACgBeo3gDX88s2cNzUFlJJIAq8QbpGviKLJmw4yUbG/I7fmXxXZ1zSQq Z+XIg4vSGf5sc9vnEW0Sn2uWGg== X-Google-Smtp-Source: AA6agR63Bzb51JkQHDsQML106QA1SRbThkvFgEfcZxG1oTuPekWXu06XLjwe2W8lGlgpYHROZLAeqg== X-Received: by 2002:adf:a702:0:b0:226:e205:fa56 with SMTP id c2-20020adfa702000000b00226e205fa56mr7815687wrd.637.1662039604363; Thu, 01 Sep 2022 06:40:04 -0700 (PDT) Received: from localhost.localdomain (210.145.15.109.rev.sfr.net. [109.15.145.210]) by smtp.googlemail.com with ESMTPSA id e3-20020adfe383000000b0021ef34124ebsm15399016wrm.11.2022.09.01.06.40.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 06:40:03 -0700 (PDT) From: Amjad Ouled-Ameur To: matthias.bgg@gmail.com Cc: Markus Schneider-Pargmann , 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 v3 2/4] thermal: mediatek: control buffer enablement tweaks Date: Thu, 1 Sep 2022 15:39:48 +0200 Message-Id: <20220901133950.115122-3-aouledameur@baylibre.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220901133950.115122-1-aouledameur@baylibre.com> References: <20220901133950.115122-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 Signed-off-by: Amjad Ouled-Ameur --- Changes in V3: - Use GENMASK() and BIT() instead of hardcoded data. - Use u32 instead of int for "tmp" var in mtk_thermal_turn_on_buffer()=20 drivers/thermal/mtk_thermal.c | 25 ++++++++++++++++++------- 1 file changed, 18 insertions(+), 7 deletions(-) diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c index ede94eadddda..b5b4401249e8 100644 --- a/drivers/thermal/mtk_thermal.c +++ b/drivers/thermal/mtk_thermal.c @@ -271,6 +271,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 { @@ -514,6 +517,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 GENMASK(31, 6) | BIT(3), + .apmixed_buffer_ctl_set =3D BIT(0), }; =20 /* @@ -963,14 +969,18 @@ static const struct of_device_id mtk_thermal_of_match= [] =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; + u32 tmp; + + if (!mt->conf->apmixed_buffer_ctl_reg) + return; =20 - tmp =3D readl(apmixed_base + APMIXED_SYS_TS_CON1); - tmp &=3D ~(0x37); - tmp |=3D 0x1; - writel(tmp, apmixed_base + APMIXED_SYS_TS_CON1); + 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 @@ -1070,8 +1080,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.3 From nobody Sat Sep 21 17:13:59 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 3FECCC0502C for ; Thu, 1 Sep 2022 13:42:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S233504AbiIANl6 (ORCPT ); Thu, 1 Sep 2022 09:41:58 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233526AbiIANl0 (ORCPT ); Thu, 1 Sep 2022 09:41:26 -0400 Received: from mail-wm1-x330.google.com (mail-wm1-x330.google.com [IPv6:2a00:1450:4864:20::330]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 69E6D3340F for ; Thu, 1 Sep 2022 06:40:10 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id s23so9035187wmj.4 for ; Thu, 01 Sep 2022 06:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=kRMJ3ksjINGY0UaLIqoNPySZcUwLDGDbrGm3yr11xVU=; b=tz+pOh49g5LIfkNvQbRDQDWPtLCnf17entoYbKL2+nw505LBggzs4C2YZWAniqFRJ0 ymUdwd6If+/GI8Kwh3M2omHhrr7q+xKNz63pNZDKSRSC2iNOXXDrEJ5iNbI6oAIVwHRR F+wg+ytmLvqw2YfecGX3ZMnp4XJASQocTk898weiGezzx27Iggz+q8ywVjqeCkdOiUDj fvx30jQ1ko/3oAD9uo2o84ByRyAzcNVB/xPzKVQqFTvu9mjGWhUMscBCjyARSp+LjGCd GEaFjKMsUerfLweAFGJoGOzMQR2d9ezpQsQV19u4uKaH+mUyeZ+cNOC3JEMAGS8WSw3g JXoQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=kRMJ3ksjINGY0UaLIqoNPySZcUwLDGDbrGm3yr11xVU=; b=qB2cScNBRpkn92ntxZIc6NHOE5wwLRLv5cR8bm4HIdtigXq9jYvvvGm1wiGvz3r2J6 +enQu6/2ccfRq1pcP1ngFXYXDSRRHKlEj9PWowRbOJGo6aVmTl5XwBB5yBrCOmqFiVZd 6FsTMPfyslsQP7tWMvx1LXQk3iOd7sUOb0r9925MbEBbIeimLyGBwt8ly4Z94mRG5A5T OR/YkP1gWLzX0eDofSC8BZdRgUxaz2qnAr56tjn4lPstDTMZB4+3hEC2wYuwmV9UnvIE eTQBGx6/pcl3Ep3qM6S1Eool5dZGXojhJt8PmGsvPZ6YLYfgw4AEAB5cxOvY+FmGyWEF mrBA== X-Gm-Message-State: ACgBeo2f/YZNvlDMeFkflSYl15EyNgIseUas24P5yKWTbMatJSNQT6kM qhBb+27U5HJ867GomBm2vm3gvw== X-Google-Smtp-Source: AA6agR6GWWF+sfc4LxWEoQJKYgcYGId/NBi31aLSlC09CFU8xSKkyprOMClEdNyaTK8Hd5Ld+3GGnw== X-Received: by 2002:a05:600c:4e94:b0:3a5:b7e5:9e64 with SMTP id f20-20020a05600c4e9400b003a5b7e59e64mr5287371wmq.26.1662039605545; Thu, 01 Sep 2022 06:40:05 -0700 (PDT) Received: from localhost.localdomain (210.145.15.109.rev.sfr.net. [109.15.145.210]) by smtp.googlemail.com with ESMTPSA id e3-20020adfe383000000b0021ef34124ebsm15399016wrm.11.2022.09.01.06.40.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 06:40:05 -0700 (PDT) From: Amjad Ouled-Ameur To: matthias.bgg@gmail.com Cc: Fabien Parent , rafael@kernel.org, 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 v3 3/4] thermal: mediatek: add support for MT8365 SoC Date: Thu, 1 Sep 2022 15:39:49 +0200 Message-Id: <20220901133950.115122-4-aouledameur@baylibre.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220901133950.115122-1-aouledameur@baylibre.com> References: <20220901133950.115122-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 Signed-off-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 b5b4401249e8..088c388da241 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 { @@ -389,6 +401,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 @@ -463,6 +493,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 @@ -964,6 +1028,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.3 From nobody Sat Sep 21 17:13:59 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 69138C0502C for ; Thu, 1 Sep 2022 13:41:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234065AbiIANls (ORCPT ); Thu, 1 Sep 2022 09:41:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43660 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233128AbiIANlW (ORCPT ); Thu, 1 Sep 2022 09:41:22 -0400 Received: from mail-wm1-x32a.google.com (mail-wm1-x32a.google.com [IPv6:2a00:1450:4864:20::32a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 8C486357ED for ; Thu, 1 Sep 2022 06:40:10 -0700 (PDT) Received: by mail-wm1-x32a.google.com with SMTP id k17so9046570wmr.2 for ; Thu, 01 Sep 2022 06:40:09 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=baylibre-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=PXZk2g+XOqGMjXGT66nViEOp7155I8tzUe2hmezbk9c=; b=17fsFK3ztgm/SVq5u0ayzndJktrteVKsCKcEqAK3Qn//5L3IkRaOUCawLwShBDJFtl euAItBnkxj6Kr+gObW2PdMQJyW+JNckoeeEdJcOyJ8odVyjv9qwSo+Aa+Agrw1D7uadm NjFL4ytCQsfAsiYRX2ZCnWbkqyjhSvU2ArcGakqT0/pe/tzKAGY5ANhWjbKSskm01+SV e08NiN7JfQwTyq8kqygPzg04A3j1sVIHbYcg2+MQmLJ0G2Z5+pbYD3vww9tiFNQdTwNx Wb/b6iHsoxdWnVPAvK6uJ58Bt5C5ENxo+MtunbH7ABwWaEcZ0kMUtDms8wCLcCUx5Vlk EiCg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; 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; bh=PXZk2g+XOqGMjXGT66nViEOp7155I8tzUe2hmezbk9c=; b=dRoYAwDx4hHPldPCf7GF5G9QWzjMm/U737mN3oN7eU/46WnBCnuvPrzm479PNsMNwa hBgU0ZSU1hPX8h09lmMCCS9PhZqET78Qre7NcrYrdkNMUSDKEB5r8XF4NoEfdLR9Cp36 4INR5C6nY72V958pVuLkWRbFdQGOHXgozlfQ5zsYWNuxt/Uobf89sOMkNap9l4UvWeSt cBVFOIrkc5B4fh/CrZunx0MHE+/U6oaG7DKOYLVKsUvnVGvq1QfXC9KeHxsJY1jE4OiK ep8RDbQiWiacQLXz233gGtKRhJ/KiGbgbF4OBupQuCauY4xzIzn+yZoi/TwUSixLF/Sx ceTQ== X-Gm-Message-State: ACgBeo1/2lfsP3iKuSFXdsWtoLq3RsVdP4SgAi8F8wc6zphQOzyZ3chc TJdMCwsOnBeZOx7meiMfcXEdxA== X-Google-Smtp-Source: AA6agR42cS6iV9udNENWfEp+1c99N36znNphQvHct12z9G9cTwZBqzId0Md8KfkxH6g9DJOJUI8Dcw== X-Received: by 2002:a05:600c:4148:b0:3a5:4f94:577b with SMTP id h8-20020a05600c414800b003a54f94577bmr5357868wmm.167.1662039606770; Thu, 01 Sep 2022 06:40:06 -0700 (PDT) Received: from localhost.localdomain (210.145.15.109.rev.sfr.net. [109.15.145.210]) by smtp.googlemail.com with ESMTPSA id e3-20020adfe383000000b0021ef34124ebsm15399016wrm.11.2022.09.01.06.40.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 01 Sep 2022 06:40:06 -0700 (PDT) From: Amjad Ouled-Ameur To: matthias.bgg@gmail.com Cc: Amjad Ouled-Ameur , 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, Michael Kao , Hsin-Yi Wang Subject: [PATCH v3 4/4] thermal: mediatek: add another get_temp ops for thermal sensors Date: Thu, 1 Sep 2022 15:39:50 +0200 Message-Id: <20220901133950.115122-5-aouledameur@baylibre.com> X-Mailer: git-send-email 2.37.3 In-Reply-To: <20220901133950.115122-1-aouledameur@baylibre.com> References: <20220901133950.115122-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: Michael Kao Signed-off-by: Hsin-Yi Wang Signed-off-by: Amjad Ouled-Ameur --- Changes in V3: - Use proper types. - Use devm_kmalloc() instead of kmalloc(). - Fix tabs and spaces. 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 088c388da241..5901787c57f5 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 int _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 devm_kmalloc(&pdev->dev, 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.3