From nobody Sun Sep 22 01:41:23 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 EB7ECC4167D for ; Thu, 12 May 2022 12:24:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353690AbiELMYw (ORCPT ); Thu, 12 May 2022 08:24:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37792 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233309AbiELMYn (ORCPT ); Thu, 12 May 2022 08:24:43 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CE97124734C for ; Thu, 12 May 2022 05:24:39 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id d5so7024337wrb.6 for ; Thu, 12 May 2022 05:24: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=HfH019+cT0njZgEoB5v4us8H/Co27KMCU86/mPoLRqg=; b=A7TMJCxmk4lkEBYyfuuMZ5/cY5FebO7K8BkFV3Er9WuM1U2jurjR0UE9SnNbacNFlA vXe6CyqK5xafOBbYPM6wWQ3ch4xeaMAQR+4MZ1AB0vkYdOdTq+RngYD+JqfrsP/nzHJl ZVsDSKx0VaAKb696NNVvGQU/J9LIZizmnigESNEON8zuHSJGbf9BxxYIKoNu9a0MX3wn 9flx1OgMgaooNRHbhFXWKg7LX3HfHQRkPAs4sZ6xETG5kI0LAxbFNSDv3ykm5nTfDBGL fZmsHZIdLC/LJCq4aEQ6BMtiHSnhVgB9w9aLAqAI93C+8Uh87Q+bkkek+PBqrGjYh7Uj QioA== 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=HfH019+cT0njZgEoB5v4us8H/Co27KMCU86/mPoLRqg=; b=urPCSiJ3HUGa0tN7wC8IbV/ms6u0EGSCsYf3lHtJeRjWtfFgxOFo5e0f2AY9FoxEDE 1xzS2zTbcOYqMxPbI6447uapeEntKA588KvF45QtpF5WyjmP3wH0XPpSYxV07umqCzgL u9fb85UOldUXRkYHw3BxmjUH1elnvU0wL7VTVEQ5wwzGRHGw3K15Qdc2weUrmTMo9g9k fP609b5+Jw1voUYH5fO4YpM0ufqjY91ndJQRjvzT539+prXwQ6oaIhqlj0rQoqfZy/r7 m6nzL4loTr8b1HxbFCM3bTQR5INOfpFs5jnbHkS50d4C/TXUiCPD/sK2jkFm9xv4TN+M Ltpw== X-Gm-Message-State: AOAM5302PfXti9utmXfcUOGqTkvegclAMABYH7iGVAl9lLtBTy9GVwCY vN/4QRyXd0HQQBXNDADXSZxNyg== X-Google-Smtp-Source: ABdhPJxWFKFcvfIhGck12vzg6QdmKoi3QsdXBypkekPwJfM4MQvTVlUyQyX9WZNJ3Uv1LPsj0I9o/A== X-Received: by 2002:a5d:6183:0:b0:20a:db51:f21a with SMTP id j3-20020a5d6183000000b0020adb51f21amr27404955wru.127.1652358278336; Thu, 12 May 2022 05:24:38 -0700 (PDT) Received: from xps-9300.baylibre (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id z22-20020a7bc156000000b003942a244f30sm3047819wmi.9.2022.05.12.05.24.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 05:24:38 -0700 (PDT) From: Alexandre Bailon To: robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de Cc: rafael@kernel.org, daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, michael.kao@mediatek.com, ben.tseng@mediatek.com, ethan.chang@mediatek.com, frank-w@public-files.de, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, khilman@baylibre.com, Michael Kao Subject: [PATCH v6 1/7] thermal: mediatek: Relocate driver to mediatek folder Date: Thu, 12 May 2022 14:24:27 +0200 Message-Id: <20220512122433.1399802-2-abailon@baylibre.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220512122433.1399802-1-abailon@baylibre.com> References: <20220512122433.1399802-1-abailon@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: Michael Kao Add Mediatek proprietary folder to upstream more thermal zone and cooler drivers. Relocate the original thermal controller driver to it and rename as soc_temp.c to show its purpose more clearly. Signed-off-by: Michael Kao Signed-off-by: Ben Tseng Reviewed-by: Matthias Brugger --- drivers/thermal/Kconfig | 14 ++++------- drivers/thermal/Makefile | 2 +- drivers/thermal/mediatek/Kconfig | 23 +++++++++++++++++++ drivers/thermal/mediatek/Makefile | 1 + .../{mtk_thermal.c =3D> mediatek/soc_temp.c} | 0 5 files changed, 29 insertions(+), 11 deletions(-) create mode 100644 drivers/thermal/mediatek/Kconfig create mode 100644 drivers/thermal/mediatek/Makefile rename drivers/thermal/{mtk_thermal.c =3D> mediatek/soc_temp.c} (100%) diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index e37691e0bf20..8669d7278055 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -410,16 +410,10 @@ config DA9062_THERMAL zone. Compatible with the DA9062 and DA9061 PMICs. =20 -config MTK_THERMAL - tristate "Temperature sensor driver for mediatek SoCs" - depends on ARCH_MEDIATEK || COMPILE_TEST - depends on HAS_IOMEM - depends on NVMEM || NVMEM=3Dn - depends on RESET_CONTROLLER - default y - help - Enable this option if you want to have support for thermal management - controller present in Mediatek SoCs +menu "Mediatek thermal drivers" +depends on ARCH_MEDIATEK || COMPILE_TEST +source "drivers/thermal/mediatek/Kconfig" +endmenu =20 config AMLOGIC_THERMAL tristate "Amlogic Thermal Support" diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index f0c36a1530d5..9ade39bdb525 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -55,7 +55,7 @@ obj-y +=3D st/ obj-$(CONFIG_QCOM_TSENS) +=3D qcom/ obj-y +=3D tegra/ obj-$(CONFIG_HISI_THERMAL) +=3D hisi_thermal.o -obj-$(CONFIG_MTK_THERMAL) +=3D mtk_thermal.o +obj-$(CONFIG_MTK_THERMAL) +=3D mediatek/ obj-$(CONFIG_GENERIC_ADC_THERMAL) +=3D thermal-generic-adc.o obj-$(CONFIG_UNIPHIER_THERMAL) +=3D uniphier_thermal.o obj-$(CONFIG_AMLOGIC_THERMAL) +=3D amlogic_thermal.o diff --git a/drivers/thermal/mediatek/Kconfig b/drivers/thermal/mediatek/Kc= onfig new file mode 100644 index 000000000000..0351e73170b7 --- /dev/null +++ b/drivers/thermal/mediatek/Kconfig @@ -0,0 +1,23 @@ +config MTK_THERMAL + tristate "Mediatek thermal drivers" + depends on THERMAL_OF + help + This is the option for Mediatek thermal software + solutions. Please enable corresponding options to + get temperature information from thermal sensors or + turn on throttle mechaisms for thermal mitigation. + +if MTK_THERMAL + +config MTK_SOC_THERMAL + tristate "Temperature sensor driver for mediatek SoCs" + depends on HAS_IOMEM + depends on NVMEM + depends on RESET_CONTROLLER + help + Enable this option if you want to get SoC temperature + information for Mediatek platforms. This driver + configures thermal controllers to collect temperature + via AUXADC interface. + +endif diff --git a/drivers/thermal/mediatek/Makefile b/drivers/thermal/mediatek/M= akefile new file mode 100644 index 000000000000..f75313ddce5e --- /dev/null +++ b/drivers/thermal/mediatek/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_MTK_SOC_THERMAL) +=3D soc_temp.o diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mediatek/soc_t= emp.c similarity index 100% rename from drivers/thermal/mtk_thermal.c rename to drivers/thermal/mediatek/soc_temp.c --=20 2.35.1 From nobody Sun Sep 22 01:41:23 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 786CBC433F5 for ; Thu, 12 May 2022 12:24:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353699AbiELMY5 (ORCPT ); Thu, 12 May 2022 08:24:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37632 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353664AbiELMYn (ORCPT ); Thu, 12 May 2022 08:24:43 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BE61F248258 for ; Thu, 12 May 2022 05:24:40 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id m2-20020a1ca302000000b003943bc63f98so2886100wme.4 for ; Thu, 12 May 2022 05:24: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=CEL25fIAOxZ58SCupHBAbwosUkv+Gl8sueS42GQV8/0=; b=hmJKYH3GoV5OPRognhaYZ9+ey9NKhNM6sjc6eiy81im7gczC0H9b8FiR7Ynz3TR2aO EtsHN4T+aZLesVCtqXMrOouFUZ0JeTeDAP3e227fx4J9gnYhikxOjKCKJYufyHjNO++H r7gu1qICR7hpGKy2Fx4ERghUJfTGx+zUO+RQQ12CRjki/XcuVH25CzD0uo8ilTc7N0QX S2j9NtLnAZJBji7+i54njL8ORu9Ph55VVxsVX8jHBGqIkBhETEEywKjaWD6j++UpZVaL SnSRYZY/dbyyAE1QccpUR5ph/44KCoclXmeaiIYnLjiEp86PKr8BtlvuhN6R2B5OxqIw 3wWg== 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=CEL25fIAOxZ58SCupHBAbwosUkv+Gl8sueS42GQV8/0=; b=CvGgdDozrz9mZMqX2DGahwsvxeWMUoHdLCrCbNaNZL/hotIkvCHhzSofDu76lzLJe7 AjlWRReB5JNbz+53siH/HPzNFdaY+58g/FvKSgT2y4QK3S/fEVMHIOgIOv44WSvRxPPO WRIB6kL5S72ZtWvLSjHW7hAh38bRaQukaYCq1qhPe4bsRJTzmnPmAQr60Xv5Pq3cYiUJ izKkuUXF9YiYQra9HdNq838rFr1Y90ATvNWHcRTz0/tot8el+NaKTQAaF4divRJxpQyk 6bhM2JZEL0xxNTRoY2ht9c8ifnfVOHLZ1hTK0H9h6AeWBYeOU2aPwfW0X9VfNfH/Si00 shPA== X-Gm-Message-State: AOAM530phkWY6EVwvNoaF+uzJDMzG+nFZk07BT/tNzp71DqlQJtaxxP7 ChQ7cgrkGQTGOO2GuLDLSBsK7w== X-Google-Smtp-Source: ABdhPJy2UcZEE5+c7sRO4tFxsA0JEIP0dOgsO3PQO1bZq+4Emf94ol1GlRDSyhrBYOiYdVC3cajVNA== X-Received: by 2002:a1c:7510:0:b0:394:1961:708 with SMTP id o16-20020a1c7510000000b0039419610708mr9895075wmc.201.1652358279313; Thu, 12 May 2022 05:24:39 -0700 (PDT) Received: from xps-9300.baylibre (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id z22-20020a7bc156000000b003942a244f30sm3047819wmi.9.2022.05.12.05.24.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 05:24:39 -0700 (PDT) From: Alexandre Bailon To: robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de Cc: rafael@kernel.org, daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, michael.kao@mediatek.com, ben.tseng@mediatek.com, ethan.chang@mediatek.com, frank-w@public-files.de, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, khilman@baylibre.com Subject: [PATCH v6 2/7] dt-bindings: thermal: Add binding document for mt6873 thermal controller Date: Thu, 12 May 2022 14:24:28 +0200 Message-Id: <20220512122433.1399802-3-abailon@baylibre.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220512122433.1399802-1-abailon@baylibre.com> References: <20220512122433.1399802-1-abailon@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: Michael Kao This patch adds binding document for mt6873 thermal controller. Signed-off-by: Michael Kao Signed-off-by: Ben Tseng --- .../thermal/mediatek-thermal-lvts.yaml | 81 +++++++++++++++++++ 1 file changed, 81 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/mediatek-ther= mal-lvts.yaml diff --git a/Documentation/devicetree/bindings/thermal/mediatek-thermal-lvt= s.yaml b/Documentation/devicetree/bindings/thermal/mediatek-thermal-lvts.ya= ml new file mode 100644 index 000000000000..69ffe7b14c21 --- /dev/null +++ b/Documentation/devicetree/bindings/thermal/mediatek-thermal-lvts.yaml @@ -0,0 +1,81 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/thermal/mediatek-thermal-lvts.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Mediatek SoC LVTS thermal controller (DTS) binding + +maintainers: + - Yu-Chia Chang + - Ben Tseng + +properties: + compatible: + const: mediatek,mt6873-lvts + + reg: + maxItems: 1 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + clock-names: + items: + - const: lvts_clk + + "#thermal-sensor-cells": + const: 0 + +required: + - "#thermal-sensor-cells" + - compatible + - reg + - interrupts + - clocks + - clock-names + +additionalProperties: false + +examples: + - | + #include + #include + #include + dts: lvts@1100b000 { + compatible =3D "mediatek,mt6873-lvts"; + reg =3D <0x1100b000 0x1000>; + clocks =3D <&infracfg CLK_INFRA_THERM>; + clock-names =3D "lvts_clk"; + #thermal-sensor-cells =3D <0>; + interrupts =3D ; + }; + + thermal-zones { + cpu_thermal: cpu-thermal { + polling-delay-passive =3D <0>; + polling-delay =3D <0>; + + thermal-sensors =3D <&dts>; + trips { + cpu_alert1: cpu-alert1 { + temperature =3D <85000>; + hysteresis =3D <0>; + type =3D "passive"; + }; + + cpu_crit: cpu-crit { + temperature =3D <120000>; + hysteresis =3D <0>; + type =3D "critical"; + }; + }; + + cooling-maps { + }; + }; + }; +... --=20 2.35.1 From nobody Sun Sep 22 01:41:23 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 3F242C433EF for ; Thu, 12 May 2022 12:25:33 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353692AbiELMZa (ORCPT ); Thu, 12 May 2022 08:25:30 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38132 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353674AbiELMYs (ORCPT ); Thu, 12 May 2022 08:24:48 -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 2CD29248246 for ; Thu, 12 May 2022 05:24:42 -0700 (PDT) Received: by mail-wm1-x330.google.com with SMTP id q20so2940574wmq.1 for ; Thu, 12 May 2022 05:24:42 -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=rsViq6jizmC6opILAn3pU9eAx5KBydp7thSv3NyHUdQ=; b=5qt2ayzijdXdLu5yY6RNuVPwG6W7paipTTmrS2XXAMvhu6n/0UTEETcREmLWWAbin3 JTA1fg00zsjCpeEA4EcEb6OwL2aNZAoFJ5Ko7qy9F9UIAvwbfv2++BBLjV8OLe7bHMQo p6mbitNT6mF8hm6DTIO14rphq+z4MT1qFmJSHl4ctQkTm/OVuT66opb5WDKjhknVYei/ AV88TgUNn9Pa19RN46FJO2n7JfABkY3kcaNn7zQ7o8F4TuJvUjjdeAD6YwzzxiBAaKwK e5dcxf/j1KXy30X5lzBpP+cpkjtmwqIJaWssxhYc7E3vkaGJpX41m3gNUc4tefDWxCfx 3zNw== 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=rsViq6jizmC6opILAn3pU9eAx5KBydp7thSv3NyHUdQ=; b=enFmw7sj+tW6AR+tOHDUeIs98IbgLajSDuu4vMRHAAg+0+90XsBE2URgq/yBndu3XQ HG9YaSpMXqnkeQpM6bvepLMnKqVAxuTqBwm0YE0w7VmdHJpiqYl3D5s+p3a9ZCqP5FGh Rg6aexp+yMhQlq/i0iAWbgP8OPBwKJ60vGrr1BBekCnRJ6U9GOgizlDzo+rRsakk8x17 vo0AikkAv+LS4sFhbl4zcVNHgxZ/9nJFxzD9qC5Qoh5ylpcl6zqab93i0BibR9EjjLXh jPAUJQzT4opMjaiRtQcWjxq4Ib7QxK33K3usuSVgU61abIGf42DznJSR9ZcVgmm8h5SH fO9g== X-Gm-Message-State: AOAM531LIA2wS2XyaUmz1Oc1dkuoLi/ezVjO+viwVPBT1a1ZZYoXSnlQ N3hXmyoLLNxNisFJ9PxrKWfyAg== X-Google-Smtp-Source: ABdhPJzkIFmYwTnYbGE64jiFb8a5wzhN2Gwem49FY9GA/jkvNyXsHiUPpYPLSgZzjuRwGUGuDuPReQ== X-Received: by 2002:a05:600c:4f4d:b0:394:6ead:3523 with SMTP id m13-20020a05600c4f4d00b003946ead3523mr9740599wmq.109.1652358280425; Thu, 12 May 2022 05:24:40 -0700 (PDT) Received: from xps-9300.baylibre (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id z22-20020a7bc156000000b003942a244f30sm3047819wmi.9.2022.05.12.05.24.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 05:24:40 -0700 (PDT) From: Alexandre Bailon To: robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de Cc: rafael@kernel.org, daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, michael.kao@mediatek.com, ben.tseng@mediatek.com, ethan.chang@mediatek.com, frank-w@public-files.de, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, khilman@baylibre.com, Alexandre Bailon Subject: [PATCH v6 3/7] thermal: mediatek: Add LVTS drivers for SoC theraml zones Date: Thu, 12 May 2022 14:24:29 +0200 Message-Id: <20220512122433.1399802-4-abailon@baylibre.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220512122433.1399802-1-abailon@baylibre.com> References: <20220512122433.1399802-1-abailon@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: Michael Kao Add a LVTS (Low voltage thermal sensor) driver to report junction temperatures in Mediatek SoC and register the maximum temperature of sensors and each sensor as a thermal zone. Signed-off-by: Yu-Chia Chang Signed-off-by: Michael Kao Signed-off-by: Ben Tseng Signed-off-by: Alexandre Bailon --- drivers/thermal/mediatek/Kconfig | 10 + drivers/thermal/mediatek/Makefile | 1 + drivers/thermal/mediatek/soc_temp.c | 2 +- drivers/thermal/mediatek/soc_temp_lvts.c | 1280 ++++++++++++++++++++++ drivers/thermal/mediatek/soc_temp_lvts.h | 312 ++++++ 5 files changed, 1604 insertions(+), 1 deletion(-) create mode 100644 drivers/thermal/mediatek/soc_temp_lvts.c create mode 100644 drivers/thermal/mediatek/soc_temp_lvts.h diff --git a/drivers/thermal/mediatek/Kconfig b/drivers/thermal/mediatek/Kc= onfig index 0351e73170b7..d716d0372e1e 100644 --- a/drivers/thermal/mediatek/Kconfig +++ b/drivers/thermal/mediatek/Kconfig @@ -20,4 +20,14 @@ config MTK_SOC_THERMAL configures thermal controllers to collect temperature via AUXADC interface. =20 +config MTK_SOC_THERMAL_LVTS + tristate "LVTS (Low voltage thermal sensor) driver for Mediatek So= Cs" + depends on HAS_IOMEM + depends on NVMEM + depends on RESET_TI_SYSCON + help + Enable this option if you want to get SoC temperature + information for Mediatek platforms. This driver + configures LVTS thermal controllers to collect temperatures + via Analog Serial Interface(ASIF). endif diff --git a/drivers/thermal/mediatek/Makefile b/drivers/thermal/mediatek/M= akefile index f75313ddce5e..16ce166e5916 100644 --- a/drivers/thermal/mediatek/Makefile +++ b/drivers/thermal/mediatek/Makefile @@ -1 +1,2 @@ obj-$(CONFIG_MTK_SOC_THERMAL) +=3D soc_temp.o +obj-$(CONFIG_MTK_SOC_THERMAL_LVTS) +=3D soc_temp_lvts.o diff --git a/drivers/thermal/mediatek/soc_temp.c b/drivers/thermal/mediatek= /soc_temp.c index 79d592f3f60d..4ed78bbadd62 100644 --- a/drivers/thermal/mediatek/soc_temp.c +++ b/drivers/thermal/mediatek/soc_temp.c @@ -23,7 +23,7 @@ #include #include =20 -#include "thermal_hwmon.h" +#include "../thermal_hwmon.h" =20 /* AUXADC Registers */ #define AUXADC_CON1_SET_V 0x008 diff --git a/drivers/thermal/mediatek/soc_temp_lvts.c b/drivers/thermal/med= iatek/soc_temp_lvts.c new file mode 100644 index 000000000000..145ddd5fe409 --- /dev/null +++ b/drivers/thermal/mediatek/soc_temp_lvts.c @@ -0,0 +1,1280 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2020 MediaTek Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "soc_temp_lvts.h" + +/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + * Definition or macro function + *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + */ +#define STOP_COUNTING_V4 (DEVICE_WRITE | RG_TSFM_CTRL_0 << 8 | 0x00) +#define SET_RG_TSFM_LPDLY_V4 (DEVICE_WRITE | RG_TSFM_CTRL_4 << 8 | 0xA6) +#define SET_COUNTING_WINDOW_20US1_V4 (DEVICE_WRITE | RG_TSFM_CTRL_2 << 8 |= 0x00) +#define SET_COUNTING_WINDOW_20US2_V4 (DEVICE_WRITE | RG_TSFM_CTRL_1 << 8 |= 0x20) +#define TSV2F_CHOP_CKSEL_AND_TSV2F_EN_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_2 <= < 8 | 0x84) +#define TSBG_DEM_CKSEL_X_TSBG_CHOP_EN_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_4 <= < 8 | 0x7C) +#define SET_TS_RSV_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_1 << 8 | 0x8D) +#define SET_TS_EN_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_0 << 8 | 0xF4) +#define TOGGLE_RG_TSV2F_VCO_RST1_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_0 << 8 |= 0xFC) +#define TOGGLE_RG_TSV2F_VCO_RST2_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_0 << 8 |= 0xF4) + +#define SET_LVTS_AUTO_RCK_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_6 << 8 | 0x01) +#define SELECT_SENSOR_RCK_V4(id) (DEVICE_WRITE | RG_TSV2F_CTRL_5 << 8 | (i= d)) +#define SET_DEVICE_SINGLE_MODE_V4 (DEVICE_WRITE | RG_TSFM_CTRL_3 << 8 | 0x= 78) +#define KICK_OFF_RCK_COUNTING_V4 (DEVICE_WRITE | RG_TSFM_CTRL_0 << 8 | 0x0= 2) +#define SET_SENSOR_NO_RCK_V4 (DEVICE_WRITE | RG_TSV2F_CTRL_5 << 8 | 0x10) +#define SET_DEVICE_LOW_POWER_SINGLE_MODE_V4 (DEVICE_WRITE | RG_TSFM_CTRL_3= << 8 | 0xB8) + +#define ENABLE_FEATURE(feature) (lvts_data->feature_bitmap |=3D (feature)) +#define DISABLE_FEATURE(feature) (lvts_data->feature_bitmap &=3D (~(featur= e))) +#define IS_ENABLE(feature) (lvts_data->feature_bitmap & (feature)) + +#define DISABLE_THERMAL_HW_REBOOT (-274000) + +#define CLOCK_26MHZ_CYCLE_NS (38) +#define BUS_ACCESS_US (2) + +#define FEATURE_DEVICE_AUTO_RCK (BIT(0)) +#define FEATURE_CK26M_ACTIVE (BIT(1)) +#define CK26M_ACTIVE (((lvts_data->feature_bitmap & FEATURE_CK26M_ACTIVE= ) \ + ? 1 : 0) << 30) +#define GET_BASE_ADDR(tc_id) \ + (lvts_data->domain[lvts_data->tc[tc_id].domain_index].base \ + + lvts_data->tc[tc_id].addr_offset) + +#define SET_TC_SPEED_IN_US(pu, gd, fd, sd) \ + { \ + .period_unit =3D (((pu) * 1000) / (256 * CLOCK_26MHZ_CYCLE_NS)), \ + .group_interval_delay =3D ((gd) / (pu)), \ + .filter_interval_delay =3D ((fd) / (pu)), \ + .sensor_interval_delay =3D ((sd) / (pu)), \ + } + +#define GET_CAL_DATA_BITMASK(index, h, l) \ + (((index) < lvts_data->num_efuse_addr) \ + ? ((lvts_data->efuse[(index)] & GENMASK(h, l)) >> l) \ + : 0) + +#define GET_CAL_DATA_BIT(index, bit) \ + (((index) < lvts_data->num_efuse_addr) \ + ? ((lvts_data->efuse[index] & BIT(bit)) >> (bit)) \ + : 0) + +#define GET_TC_SENSOR_NUM(tc_id) \ + (lvts_data->tc[tc_id].num_sensor) + +#define ONE_SAMPLE (lvts_data->counting_window_us + 2 * BUS_ACCESS_US) + +#define NUM_OF_SAMPLE(tc_id) \ + ((lvts_data->tc[tc_id].hw_filter < LVTS_FILTER_2) ? 1 : \ + ((lvts_data->tc[tc_id].hw_filter > LVTS_FILTER_16_OF_18) ? 1 : \ + ((lvts_data->tc[tc_id].hw_filter =3D=3D LVTS_FILTER_16_OF_18) ? 18 :\ + ((lvts_data->tc[tc_id].hw_filter =3D=3D LVTS_FILTER_8_OF_10) ? 10 : \ + (lvts_data->tc[tc_id].hw_filter * 2))))) + +#define PERIOD_UNIT_US(tc_id) \ + ((lvts_data->tc[tc_id].tc_speed.period_unit * 256 * \ + CLOCK_26MHZ_CYCLE_NS) / 1000) +#define FILTER_INT_US(tc_id) \ + (lvts_data->tc[tc_id].tc_speed.filter_interval_delay \ + * PERIOD_UNIT_US(tc_id)) +#define SENSOR_INT_US(tc_id) \ + (lvts_data->tc[tc_id].tc_speed.sensor_interval_delay \ + * PERIOD_UNIT_US(tc_id)) +#define GROUP_INT_US(tc_id) \ + (lvts_data->tc[tc_id].tc_speed.group_interval_delay \ + * PERIOD_UNIT_US(tc_id)) + +#define SENSOR_LATENCY_US(tc_id) \ + ((NUM_OF_SAMPLE(tc_id) - 1) * FILTER_INT_US(tc_id) \ + + NUM_OF_SAMPLE(tc_id) * ONE_SAMPLE) + +#define GROUP_LATENCY_US(tc_id) \ + (GET_TC_SENSOR_NUM(tc_id) * SENSOR_LATENCY_US(tc_id) \ + + (GET_TC_SENSOR_NUM(tc_id) - 1) * SENSOR_INT_US(tc_id) \ + + GROUP_INT_US(tc_id)) + +/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + * LVTS local common code + *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + */ +static int lvts_raw_to_temp(struct formula_coeff *co, unsigned int msr_raw) +{ + /* This function returns degree mC */ + + int temp; + + temp =3D (co->a * ((unsigned long long)msr_raw)) >> 14; + temp =3D temp + co->golden_temp * 500 + co->b; + + return temp; +} + +static unsigned int lvts_temp_to_raw(struct formula_coeff *co, int temp) +{ + unsigned int msr_raw; + + msr_raw =3D div_s64((s64)((co->golden_temp * 500 + co->b - temp)) << 14, + (-1 * co->a)); + + return msr_raw; +} + +static int soc_temp_lvts_read_temp(void *data, int *temperature) +{ + struct soc_temp_tz *lvts_tz =3D (struct soc_temp_tz *)data; + struct lvts_data *lvts_data =3D lvts_tz->lvts_data; + unsigned int msr_raw; + + msr_raw =3D readl(lvts_data->reg[lvts_tz->id]) & MRS_RAW_MASK; + if (msr_raw =3D=3D 0) + return -EINVAL; + + *temperature =3D lvts_raw_to_temp(&lvts_data->coeff, msr_raw); + + return 0; +} + +static const struct thermal_zone_of_device_ops soc_temp_lvts_ops =3D { + .get_temp =3D soc_temp_lvts_read_temp, +}; + +static void lvts_write_device(struct lvts_data *lvts_data, unsigned int da= ta, + int tc_id) +{ + void __iomem *base; + + base =3D GET_BASE_ADDR(tc_id); + + writel(data, LVTS_CONFIG_0 + base); + + usleep_range(5, 15); +} + +static unsigned int lvts_read_device(struct lvts_data *lvts_data, + unsigned int reg_idx, int tc_id) +{ + struct device *dev =3D lvts_data->dev; + void __iomem *base; + unsigned int data; + int ret; + + base =3D GET_BASE_ADDR(tc_id); + writel(READ_DEVICE_REG(reg_idx), LVTS_CONFIG_0 + base); + + ret =3D readl_poll_timeout(LVTS_CONFIG_0 + base, data, + !(data & DEVICE_ACCESS_STARTUS), + 2, 200); + if (ret) + dev_err(dev, + "Error: LVTS %d DEVICE_ACCESS_START didn't ready\n", tc_id); + + data =3D readl(LVTSRDATA0_0 + base); + + return data; +} + +static void wait_all_tc_sensing_point_idle(struct lvts_data *lvts_data) +{ + struct device *dev =3D lvts_data->dev; + unsigned int mask, error_code, is_error; + void __iomem *base; + int i, cnt, ret; + + mask =3D BIT(10) | BIT(7) | BIT(0); + + for (cnt =3D 0; cnt < 2; cnt++) { + is_error =3D 0; + for (i =3D 0; i < lvts_data->num_tc; i++) { + base =3D GET_BASE_ADDR(i); + ret =3D readl_poll_timeout(LVTSMSRCTL1_0 + base, error_code, + !(error_code & mask), 2, 200); + /* + * Error code + * 000: IDLE + * 001: Write transaction + * 010: Waiting for read after Write + * 011: Disable Continue fetching on Device + * 100: Read transaction + * 101: Set Device special Register for Voltage threshold + * 111: Set TSMCU number for Fetch + */ + error_code =3D ((error_code & BIT(10)) >> 8) + + ((error_code & BIT(7)) >> 6) + + (error_code & BIT(0)); + + if (ret) + dev_err(dev, + "Error LVTS %d sensing points aren't idle, error_code %d\n", + i, error_code); + + if (error_code !=3D 0) + is_error =3D 1; + } + + if (is_error =3D=3D 0) + break; + } +} + +static void lvts_reset(struct lvts_data *lvts_data) +{ + int i; + + for (i =3D 0; i < lvts_data->num_domain; i++) { + if (lvts_data->domain[i].reset) + reset_control_assert(lvts_data->domain[i].reset); + + if (lvts_data->domain[i].reset) + reset_control_deassert(lvts_data->domain[i].reset); + } +} + +static void device_identification(struct lvts_data *lvts_data) +{ + struct device *dev =3D lvts_data->dev; + unsigned int i, data; + void __iomem *base; + + for (i =3D 0; i < lvts_data->num_tc; i++) { + base =3D GET_BASE_ADDR(i); + + writel(ENABLE_LVTS_CTRL_CLK, LVTSCLKEN_0 + base); + + lvts_write_device(lvts_data, RESET_ALL_DEVICES, i); + + lvts_write_device(lvts_data, READ_BACK_DEVICE_ID, i); + + /* Check LVTS device ID */ + data =3D (readl(LVTS_ID_0 + base) & GENMASK(7, 0)); + if (data !=3D (0x81 + i)) + dev_err(dev, "LVTS_TC_%d, Device ID should be 0x%x, but 0x%x\n", + i, (0x81 + i), data); + } +} + +static void disable_all_sensing_points(struct lvts_data *lvts_data) +{ + unsigned int i; + void __iomem *base; + + for (i =3D 0; i < lvts_data->num_tc; i++) { + base =3D GET_BASE_ADDR(i); + writel(DISABLE_SENSING_POINT, LVTSMONCTL0_0 + base); + } +} + +static void enable_all_sensing_points(struct lvts_data *lvts_data) +{ + struct device *dev =3D lvts_data->dev; + struct tc_settings *tc =3D lvts_data->tc; + unsigned int i, num; + void __iomem *base; + + for (i =3D 0; i < lvts_data->num_tc; i++) { + base =3D GET_BASE_ADDR(i); + num =3D tc[i].num_sensor; + + if (num > ALL_SENSING_POINTS) { + dev_err(dev, + "%s, LVTS%d, illegal number of sensors: %d\n", + __func__, i, tc[i].num_sensor); + continue; + } + + writel(ENABLE_SENSING_POINT(num), LVTSMONCTL0_0 + base); + } +} + +static void set_polling_speed(struct lvts_data *lvts_data, int tc_id) +{ + struct device *dev =3D lvts_data->dev; + struct tc_settings *tc =3D lvts_data->tc; + unsigned int lvts_mon_ctl_1, lvts_mon_ctl_2; + void __iomem *base; + + base =3D GET_BASE_ADDR(tc_id); + + lvts_mon_ctl_1 =3D ((tc[tc_id].tc_speed.group_interval_delay << 20) & GEN= MASK(29, 20)) | + (tc[tc_id].tc_speed.period_unit & GENMASK(9, 0)); + lvts_mon_ctl_2 =3D ((tc[tc_id].tc_speed.filter_interval_delay << 16) & GE= NMASK(25, 16)) | + (tc[tc_id].tc_speed.sensor_interval_delay & GENMASK(9, 0)); + /* + * Clock source of LVTS thermal controller is 26MHz. + * Period unit is a base for all interval delays + * All interval delays must multiply it to convert a setting to time. + * Filter interval delay is a delay between two samples of the same sensor + * Sensor interval delay is a delay between two samples of differnet sens= ors + * Group interval delay is a delay between different rounds. + * For example: + * If Period unit =3D C, filter delay =3D 1, sensor delay =3D 2, grou= p delay =3D 1, + * and two sensors, TS1 and TS2, are in a LVTS thermal controller + * and then + * Period unit =3D C * 1/26M * 256 =3D 12 * 38.46ns * 256 =3D 118.149= us + * Filter interval delay =3D 1 * Period unit =3D 118.149us + * Sensor interval delay =3D 2 * Period unit =3D 236.298us + * Group interval delay =3D 1 * Period unit =3D 118.149us + * + * TS1 TS1 ... TS1 TS2 TS2 ... TS2 TS1... + * <--> Filter interval delay + * <--> Sensor interval delay + * <--> Group interval delay + */ + writel(lvts_mon_ctl_1, LVTSMONCTL1_0 + base); + writel(lvts_mon_ctl_2, LVTSMONCTL2_0 + base); + + dev_info(dev, "%s %d, LVTSMONCTL1_0=3D 0x%x,LVTSMONCTL2_0=3D 0x%x\n", + __func__, tc_id, readl(LVTSMONCTL1_0 + base), + readl(LVTSMONCTL2_0 + base)); +} + +static void set_hw_filter(struct lvts_data *lvts_data, int tc_id) +{ + struct device *dev =3D lvts_data->dev; + struct tc_settings *tc =3D lvts_data->tc; + unsigned int option; + void __iomem *base; + + base =3D GET_BASE_ADDR(tc_id); + option =3D tc[tc_id].hw_filter & 0x7; + /* hw filter + * 000: Get one sample + * 001: Get 2 samples and average them + * 010: Get 4 samples, drop max and min, then average the rest of 2 sampl= es + * 011: Get 6 samples, drop max and min, then average the rest of 4 sampl= es + * 100: Get 10 samples, drop max and min, then average the rest of 8 samp= les + * 101: Get 18 samples, drop max and min, then average the rest of 16 sam= ples + */ + option =3D (option << 9) | (option << 6) | (option << 3) | option; + + writel(option, LVTSMSRCTL0_0 + base); + dev_info(dev, "%s %d, LVTSMSRCTL0_0=3D 0x%x\n", + __func__, tc_id, readl(LVTSMSRCTL0_0 + base)); +} + +static int get_dominator_index(struct lvts_data *lvts_data, int tc_id) +{ + struct device *dev =3D lvts_data->dev; + struct tc_settings *tc =3D lvts_data->tc; + int d_index; + + if (tc[tc_id].dominator_sensing_point =3D=3D ALL_SENSING_POINTS) { + d_index =3D ALL_SENSING_POINTS; + } else if (tc[tc_id].dominator_sensing_point < + tc[tc_id].num_sensor){ + d_index =3D tc[tc_id].dominator_sensing_point; + } else { + dev_err(dev, + "Error: LVTS%d, dominator_sensing_point=3D %d should smaller than num_s= ensor=3D %d\n", + tc_id, tc[tc_id].dominator_sensing_point, + tc[tc_id].num_sensor); + + dev_err(dev, "Use the sensing point 0 as the dominated sensor\n"); + d_index =3D SENSING_POINT0; + } + + return d_index; +} + +static void disable_hw_reboot_interrupt(struct lvts_data *lvts_data, int t= c_id) +{ + unsigned int temp; + void __iomem *base; + + base =3D GET_BASE_ADDR(tc_id); + + /* LVTS thermal controller has two interrupts for thermal HW reboot + * One is for AP SW and the other is for RGU + * The interrupt of AP SW can turn off by a bit of a register, but + * the other for RGU cannot. + * To prevent rebooting device accidentally, we are going to add + * a huge offset to LVTS and make LVTS always report extremely low + * temperature. + */ + + /* After adding the huge offset 0x3FFF, LVTS alawys adds the + * offset to MSR_RAW. + * When MSR_RAW is larger, SW will convert lower temperature/ + */ + temp =3D readl(LVTSPROTCTL_0 + base); + writel(temp | 0x3FFF, LVTSPROTCTL_0 + base); + + /* Disable the interrupt of AP SW */ + temp =3D readl(LVTSMONINT_0 + base); + writel(temp & ~(STAGE3_INT_EN), LVTSMONINT_0 + base); +} + +static void enable_hw_reboot_interrupt(struct lvts_data *lvts_data, int tc= _id) +{ + unsigned int temp; + void __iomem *base; + + base =3D GET_BASE_ADDR(tc_id); + + /* Enable the interrupt of AP SW */ + temp =3D readl(LVTSMONINT_0 + base); + writel(temp | STAGE3_INT_EN, LVTSMONINT_0 + base); + /* Clear the offset */ + temp =3D readl(LVTSPROTCTL_0 + base); + writel(temp & ~PROTOFFSET, LVTSPROTCTL_0 + base); +} + +static void set_tc_hw_reboot_threshold(struct lvts_data *lvts_data, + int trip_point, int tc_id) +{ + struct device *dev =3D lvts_data->dev; + unsigned int msr_raw, temp, config, d_index; + void __iomem *base; + + base =3D GET_BASE_ADDR(tc_id); + d_index =3D get_dominator_index(lvts_data, tc_id); + + dev_info(dev, "%s: LVTS%d, the dominator sensing point=3D %d\n", + __func__, tc_id, d_index); + + disable_hw_reboot_interrupt(lvts_data, tc_id); + + temp =3D readl(LVTSPROTCTL_0 + base); + if (d_index =3D=3D ALL_SENSING_POINTS) { + /* Maximum of 4 sensing points */ + config =3D (0x1 << 16); + writel(config | temp, LVTSPROTCTL_0 + base); + } else { + /* Select protection sensor */ + config =3D ((d_index << 2) + 0x2) << 16; + writel(config | temp, LVTSPROTCTL_0 + base); + } + + msr_raw =3D lvts_temp_to_raw(&lvts_data->coeff, trip_point); + writel(msr_raw, LVTSPROTTC_0 + base); + + enable_hw_reboot_interrupt(lvts_data, tc_id); +} + +static void set_all_tc_hw_reboot(struct lvts_data *lvts_data) +{ + struct tc_settings *tc =3D lvts_data->tc; + int i, trip_point; + + for (i =3D 0; i < lvts_data->num_tc; i++) { + trip_point =3D tc[i].hw_reboot_trip_point; + + if (tc[i].num_sensor =3D=3D 0) + continue; + + if (trip_point =3D=3D DISABLE_THERMAL_HW_REBOOT) + continue; + + set_tc_hw_reboot_threshold(lvts_data, trip_point, i); + } +} + +static int lvts_init(struct lvts_data *lvts_data) +{ + struct platform_ops *ops =3D &lvts_data->ops; + struct device *dev =3D lvts_data->dev; + int ret; + + ret =3D clk_prepare_enable(lvts_data->clk); + if (ret) { + dev_err(dev, + "Error: Failed to enable lvts controller clock: %d\n", + ret); + return ret; + } + + lvts_reset(lvts_data); + + device_identification(lvts_data); + if (ops->device_enable_and_init) + ops->device_enable_and_init(lvts_data); + + if (IS_ENABLE(FEATURE_DEVICE_AUTO_RCK)) { + if (ops->device_enable_auto_rck) + ops->device_enable_auto_rck(lvts_data); + } else { + if (ops->device_read_count_rc_n) + ops->device_read_count_rc_n(lvts_data); + } + + if (ops->set_cal_data) + ops->set_cal_data(lvts_data); + + disable_all_sensing_points(lvts_data); + wait_all_tc_sensing_point_idle(lvts_data); + if (ops->init_controller) + ops->init_controller(lvts_data); + enable_all_sensing_points(lvts_data); + + set_all_tc_hw_reboot(lvts_data); + + return 0; +} + +static int prepare_calibration_data(struct lvts_data *lvts_data) +{ + struct device *dev =3D lvts_data->dev; + struct sensor_cal_data *cal_data =3D &lvts_data->cal_data; + struct platform_ops *ops =3D &lvts_data->ops; + int i, offset, size; + char buffer[512]; + + cal_data->count_r =3D devm_kcalloc(dev, lvts_data->num_sensor, + sizeof(*cal_data->count_r), GFP_KERNEL); + if (!cal_data->count_r) + return -ENOMEM; + + cal_data->count_rc =3D devm_kcalloc(dev, lvts_data->num_sensor, + sizeof(*cal_data->count_rc), GFP_KERNEL); + if (!cal_data->count_rc) + return -ENOMEM; + + if (ops->efuse_to_cal_data) + ops->efuse_to_cal_data(lvts_data); + + cal_data->use_fake_efuse =3D 1; + if (cal_data->golden_temp !=3D 0) { + cal_data->use_fake_efuse =3D 0; + } else { + for (i =3D 0; i < lvts_data->num_sensor; i++) { + if (cal_data->count_r[i] !=3D 0 || + cal_data->count_rc[i] !=3D 0) { + cal_data->use_fake_efuse =3D 0; + break; + } + } + } + + if (cal_data->use_fake_efuse) { + /* It means all efuse data are equal to 0 */ + dev_err(dev, + "[lvts_cal] This sample is not calibrated, fake !!\n"); + + cal_data->golden_temp =3D cal_data->default_golden_temp; + for (i =3D 0; i < lvts_data->num_sensor; i++) { + cal_data->count_r[i] =3D cal_data->default_count_r; + cal_data->count_rc[i] =3D cal_data->default_count_rc; + } + } + + lvts_data->coeff.golden_temp =3D cal_data->golden_temp; + + dev_info(dev, "[lvts_cal] golden_temp =3D %d\n", cal_data->golden_temp); + + size =3D sizeof(buffer); + offset =3D snprintf(buffer, size, "[lvts_cal] num:g_count:g_count_rc "); + for (i =3D 0; i < lvts_data->num_sensor; i++) + offset +=3D snprintf(buffer + offset, size - offset, "%d:%d:%d ", + i, cal_data->count_r[i], cal_data->count_rc[i]); + + buffer[offset] =3D '\0'; + dev_info(dev, "%s\n", buffer); + + return 0; +} + +static int get_calibration_data(struct lvts_data *lvts_data) +{ + struct device *dev =3D lvts_data->dev; + char cell_name[8]; + struct nvmem_cell *cell; + u32 *buf; + size_t len; + int i, j, index =3D 0, ret; + + lvts_data->efuse =3D devm_kcalloc(dev, lvts_data->num_efuse_addr, + sizeof(*lvts_data->efuse), GFP_KERNEL); + if (!lvts_data->efuse) + return -ENOMEM; + + for (i =3D 0; i < lvts_data->num_efuse_block; i++) { + snprintf(cell_name, sizeof(cell_name), "e_data%d", i + 1); + cell =3D nvmem_cell_get(dev, cell_name); + if (IS_ERR(cell)) { + dev_err(dev, "Error: Failed to get nvmem cell %s\n", cell_name); + return PTR_ERR(cell); + } + + buf =3D (u32 *)nvmem_cell_read(cell, &len); + nvmem_cell_put(cell); + + if (IS_ERR(buf)) + return PTR_ERR(buf); + + for (j =3D 0; j < (len / sizeof(u32)); j++) { + if (index >=3D lvts_data->num_efuse_addr) { + dev_err(dev, "Array efuse is going to overflow"); + kfree(buf); + return -EINVAL; + } + + lvts_data->efuse[index] =3D buf[j]; + index++; + } + + kfree(buf); + } + + ret =3D prepare_calibration_data(lvts_data); + + return ret; +} + +static int lvts_init_tc_regs(struct device *dev, struct lvts_data *lvts_da= ta) +{ + struct tc_settings *tc =3D lvts_data->tc; + unsigned int i, j, s_index; + void __iomem *base; + + lvts_data->reg =3D devm_kcalloc(dev, lvts_data->num_sensor, + sizeof(*lvts_data->reg), GFP_KERNEL); + if (!lvts_data->reg) + return -ENOMEM; + + for (i =3D 0; i < lvts_data->num_tc; i++) { + base =3D GET_BASE_ADDR(i); + for (j =3D 0; j < tc[i].num_sensor; j++) { + s_index =3D tc[i].sensor_map[j]; + lvts_data->reg[s_index] =3D LVTSMSR0_0 + base + 0x4 * j; + } + } + + return 0; +} + +static int of_update_lvts_data(struct lvts_data *lvts_data, + struct platform_device *pdev) +{ + struct device *dev =3D lvts_data->dev; + struct power_domain *domain; + struct resource *res; + unsigned int i; + int ret; + + lvts_data->clk =3D devm_clk_get(dev, "lvts_clk"); + if (IS_ERR(lvts_data->clk)) + return PTR_ERR(lvts_data->clk); + + domain =3D devm_kcalloc(dev, lvts_data->num_domain, sizeof(*domain), GFP_= KERNEL); + if (!domain) + return -ENOMEM; + + for (i =3D 0; i < lvts_data->num_domain; i++) { + /* Get base address */ + res =3D platform_get_resource(pdev, IORESOURCE_MEM, i); + if (!res) { + dev_err(dev, "No IO resource, index %d\n", i); + return -ENXIO; + } + + domain[i].base =3D devm_ioremap_resource(dev, res); + if (IS_ERR(domain[i].base)) { + dev_err(dev, "Failed to remap io, index %d\n", i); + return PTR_ERR(domain[i].base); + } + + /* Get interrupt number */ + res =3D platform_get_resource(pdev, IORESOURCE_IRQ, i); + if (!res) { + dev_err(dev, "No irq resource, index %d\n", i); + return -EINVAL; + } + domain[i].irq_num =3D res->start; + + /* Get reset control */ + domain[i].reset =3D devm_reset_control_get_by_index(dev, i); + if (IS_ERR(domain[i].reset)) { + dev_err(dev, "Failed to get, index %d\n", i); + return PTR_ERR(domain[i].reset); + } + } + + lvts_data->domain =3D domain; + + ret =3D lvts_init_tc_regs(dev, lvts_data); + if (ret) + return ret; + + ret =3D get_calibration_data(lvts_data); + if (ret) + return ret; + + return 0; +} + +static void lvts_device_close(struct lvts_data *lvts_data) +{ + unsigned int i; + void __iomem *base; + + for (i =3D 0; i < lvts_data->num_tc; i++) { + base =3D GET_BASE_ADDR(i); + lvts_write_device(lvts_data, RESET_ALL_DEVICES, i); + writel(DISABLE_LVTS_CTRL_CLK, LVTSCLKEN_0 + base); + } +} + +static void lvts_close(struct lvts_data *lvts_data) +{ + disable_all_sensing_points(lvts_data); + wait_all_tc_sensing_point_idle(lvts_data); + lvts_device_close(lvts_data); + clk_disable_unprepare(lvts_data->clk); +} + +static void tc_irq_handler(struct lvts_data *lvts_data, int tc_id) +{ + struct device *dev =3D lvts_data->dev; + unsigned int ret =3D 0; + void __iomem *base; + + base =3D GET_BASE_ADDR(tc_id); + + ret =3D readl(LVTSMONINTSTS_0 + base); + /* Write back to clear interrupt status */ + writel(ret, LVTSMONINTSTS_0 + base); + + dev_info(dev, "[Thermal IRQ] LVTS thermal controller %d, LVTSMONINTSTS=3D= 0x%08x\n", + tc_id, ret); + + if (ret & THERMAL_PROTECTION_STAGE_3) + dev_info(dev, + "[Thermal IRQ]: Thermal protection stage 3 interrupt triggered\n"); +} + +static irqreturn_t irq_handler(int irq, void *dev_id) +{ + struct lvts_data *lvts_data =3D (struct lvts_data *)dev_id; + struct device *dev =3D lvts_data->dev; + struct tc_settings *tc =3D lvts_data->tc; + unsigned int i, *irq_bitmap; + void __iomem *base; + + irq_bitmap =3D kcalloc(lvts_data->num_domain, sizeof(*irq_bitmap), GFP_AT= OMIC); + + if (!irq_bitmap) + return IRQ_NONE; + + for (i =3D 0; i < lvts_data->num_domain; i++) { + base =3D lvts_data->domain[i].base; + irq_bitmap[i] =3D readl(THERMINTST + base); + dev_info(dev, "%s : THERMINTST =3D 0x%x\n", __func__, irq_bitmap[i]); + } + + for (i =3D 0; i < lvts_data->num_tc; i++) { + if ((irq_bitmap[tc[i].domain_index] & tc[i].irq_bit) =3D=3D 0) + tc_irq_handler(lvts_data, i); + } + + kfree(irq_bitmap); + + return IRQ_HANDLED; +} + +static int lvts_register_irq_handler(struct lvts_data *lvts_data) +{ + struct device *dev =3D lvts_data->dev; + unsigned int i; + int ret; + + for (i =3D 0; i < lvts_data->num_domain; i++) { + ret =3D devm_request_irq(dev, lvts_data->domain[i].irq_num, irq_handler, + IRQF_TRIGGER_HIGH, "mtk_lvts", lvts_data); + + if (ret) { + dev_err(dev, "Failed to register LVTS IRQ, ret %d, domain %d irq_num %d= \n", + ret, i, lvts_data->domain[i].irq_num); + lvts_close(lvts_data); + return ret; + } + } + + return 0; +} + +static int lvts_register_thermal_zones(struct lvts_data *lvts_data) +{ + struct device *dev =3D lvts_data->dev; + struct thermal_zone *tzdev; + struct soc_temp_tz *lvts_tz; + int i, ret; + + for (i =3D 0; i < lvts_data->num_sensor; i++) { + lvts_tz =3D devm_kzalloc(dev, sizeof(*lvts_tz), GFP_KERNEL); + if (!lvts_tz) { + lvts_close(lvts_data); + return -ENOMEM; + } + + lvts_tz->id =3D i; + lvts_tz->lvts_data =3D lvts_data; + + tzdev =3D devm_thermal_zone_of_sensor_register(dev, lvts_tz->id, + lvts_tz, &soc_temp_lvts_ops); + + if (IS_ERR(tzdev)) { + if (lvts_tz->id !=3D 0) + return 0; + + ret =3D PTR_ERR(tzdev); + dev_err(dev, "Error: Failed to register lvts tz %d, ret =3D %d\n", + lvts_tz->id, ret); + lvts_close(lvts_data); + return ret; + } + } + + return 0; +} + +static int lvts_probe(struct platform_device *pdev) +{ + struct device *dev =3D &pdev->dev; + struct lvts_data *lvts_data; + int ret; + + lvts_data =3D (struct lvts_data *)of_device_get_match_data(dev); + + if (!lvts_data) { + dev_err(dev, "Error: Failed to get lvts platform data\n"); + return -ENODATA; + } + + lvts_data->dev =3D &pdev->dev; + + ret =3D of_update_lvts_data(lvts_data, pdev); + if (ret) + return ret; + + platform_set_drvdata(pdev, lvts_data); + + ret =3D lvts_init(lvts_data); + if (ret) + return ret; + + ret =3D lvts_register_irq_handler(lvts_data); + if (ret) + return ret; + + ret =3D lvts_register_thermal_zones(lvts_data); + if (ret) + return ret; + + return 0; +} + +static int lvts_remove(struct platform_device *pdev) +{ + struct lvts_data *lvts_data; + + lvts_data =3D (struct lvts_data *)platform_get_drvdata(pdev); + + lvts_close(lvts_data); + + return 0; +} + +static int lvts_suspend(struct platform_device *pdev, pm_message_t state) +{ + struct lvts_data *lvts_data; + + lvts_data =3D (struct lvts_data *)platform_get_drvdata(pdev); + + lvts_close(lvts_data); + + return 0; +} + +static int lvts_resume(struct platform_device *pdev) +{ + int ret; + struct lvts_data *lvts_data; + + lvts_data =3D (struct lvts_data *)platform_get_drvdata(pdev); + + ret =3D lvts_init(lvts_data); + if (ret) + return ret; + + return 0; +} + +/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + * LVTS v4 common code + *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + */ +static void device_enable_and_init_v4(struct lvts_data *lvts_data) +{ + unsigned int i; + + for (i =3D 0; i < lvts_data->num_tc; i++) { + lvts_write_device(lvts_data, STOP_COUNTING_V4, i); + lvts_write_device(lvts_data, SET_RG_TSFM_LPDLY_V4, i); + lvts_write_device(lvts_data, SET_COUNTING_WINDOW_20US1_V4, i); + lvts_write_device(lvts_data, SET_COUNTING_WINDOW_20US2_V4, i); + lvts_write_device(lvts_data, TSV2F_CHOP_CKSEL_AND_TSV2F_EN_V4, i); + lvts_write_device(lvts_data, TSBG_DEM_CKSEL_X_TSBG_CHOP_EN_V4, i); + lvts_write_device(lvts_data, SET_TS_RSV_V4, i); + lvts_write_device(lvts_data, SET_TS_EN_V4, i); + lvts_write_device(lvts_data, TOGGLE_RG_TSV2F_VCO_RST1_V4, i); + lvts_write_device(lvts_data, TOGGLE_RG_TSV2F_VCO_RST2_V4, i); + } + + lvts_data->counting_window_us =3D 20; +} + +static void device_enable_auto_rck_v4(struct lvts_data *lvts_data) +{ + unsigned int i; + + for (i =3D 0; i < lvts_data->num_tc; i++) + lvts_write_device(lvts_data, SET_LVTS_AUTO_RCK_V4, i); +} + +static int device_read_count_rc_n_v4(struct lvts_data *lvts_data) +{ + /* Resistor-Capacitor Calibration */ + /* count_RC_N: count RC now */ + struct device *dev =3D lvts_data->dev; + struct tc_settings *tc =3D lvts_data->tc; + struct sensor_cal_data *cal_data =3D &lvts_data->cal_data; + unsigned int offset, size, s_index, data; + void __iomem *base; + int ret, i, j; + char buffer[512]; + + cal_data->count_rc_now =3D devm_kcalloc(dev, lvts_data->num_sensor, + sizeof(*cal_data->count_rc_now), GFP_KERNEL); + if (!cal_data->count_rc_now) + return -ENOMEM; + + for (i =3D 0; i < lvts_data->num_tc; i++) { + base =3D GET_BASE_ADDR(i); + for (j =3D 0; j < tc[i].num_sensor; j++) { + s_index =3D tc[i].sensor_map[j]; + + lvts_write_device(lvts_data, SELECT_SENSOR_RCK_V4(j), i); + lvts_write_device(lvts_data, SET_DEVICE_SINGLE_MODE_V4, i); + usleep_range(10, 20); + + lvts_write_device(lvts_data, KICK_OFF_RCK_COUNTING_V4, i); + usleep_range(30, 40); + + ret =3D readl_poll_timeout(LVTS_CONFIG_0 + base, data, + !(data & DEVICE_SENSING_STATUS), 2, 200); + if (ret) + dev_err(dev, + "Error: LVTS %d DEVICE_SENSING_STATUS didn't ready\n", i); + + data =3D lvts_read_device(lvts_data, 0x00, i); + + cal_data->count_rc_now[s_index] =3D (data & GENMASK(23, 0)); + } + + /* Recover Setting for Normal Access on + * temperature fetch + */ + lvts_write_device(lvts_data, SET_SENSOR_NO_RCK_V4, i); + lvts_write_device(lvts_data, SET_DEVICE_LOW_POWER_SINGLE_MODE_V4, i); + } + + size =3D sizeof(buffer); + offset =3D snprintf(buffer, size, "[COUNT_RC_NOW] "); + for (i =3D 0; i < lvts_data->num_sensor; i++) + offset +=3D snprintf(buffer + offset, size - offset, "%d:%d ", + i, cal_data->count_rc_now[i]); + + buffer[offset] =3D '\0'; + dev_info(dev, "%s\n", buffer); + + return 0; +} + +static void set_calibration_data_v4(struct lvts_data *lvts_data) +{ + struct tc_settings *tc =3D lvts_data->tc; + struct sensor_cal_data *cal_data =3D &lvts_data->cal_data; + unsigned int i, j, s_index, e_data; + void __iomem *base; + + for (i =3D 0; i < lvts_data->num_tc; i++) { + base =3D GET_BASE_ADDR(i); + + for (j =3D 0; j < tc[i].num_sensor; j++) { + s_index =3D tc[i].sensor_map[j]; + if (IS_ENABLE(FEATURE_DEVICE_AUTO_RCK)) + e_data =3D cal_data->count_r[s_index]; + else + e_data =3D (((unsigned long long) + cal_data->count_rc_now[s_index]) * + cal_data->count_r[s_index]) >> 14; + + writel(e_data, LVTSEDATA00_0 + base + 0x4 * j); + } + } +} + +static void init_controller_v4(struct lvts_data *lvts_data) +{ + struct device *dev =3D lvts_data->dev; + unsigned int i; + void __iomem *base; + + for (i =3D 0; i < lvts_data->num_tc; i++) { + base =3D GET_BASE_ADDR(i); + + lvts_write_device(lvts_data, SET_DEVICE_LOW_POWER_SINGLE_MODE_V4, i); + + writel(SET_SENSOR_INDEX, LVTSTSSEL_0 + base); + writel(SET_CALC_SCALE_RULES, LVTSCALSCALE_0 + base); + + set_polling_speed(lvts_data, i); + set_hw_filter(lvts_data, i); + + dev_info(dev, "lvts%d: read all %d sensors in %d us, one in %d us\n", + i, GET_TC_SENSOR_NUM(i), GROUP_LATENCY_US(i), SENSOR_LATENCY_US(i)); + } +} + +/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + * LVTS MT6873 + *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + */ + +#define MT6873_NUM_LVTS (ARRAY_SIZE(mt6873_tc_settings)) + +enum mt6873_lvts_domain { + MT6873_AP_DOMAIN, + MT6873_MCU_DOMAIN, + MT6873_NUM_DOMAIN +}; + +enum mt6873_lvts_sensor_enum { + MT6873_TS1_0, + MT6873_TS1_1, + MT6873_TS2_0, + MT6873_TS2_1, + MT6873_TS3_0, + MT6873_TS3_1, + MT6873_TS3_2, + MT6873_TS3_3, + MT6873_TS4_0, + MT6873_TS4_1, + MT6873_TS5_0, + MT6873_TS5_1, + MT6873_TS6_0, + MT6873_TS6_1, + MT6873_TS7_0, + MT6873_TS7_1, + MT6873_TS7_2, + MT6873_NUM_TS +}; + +static void mt6873_efuse_to_cal_data(struct lvts_data *lvts_data) +{ + struct sensor_cal_data *cal_data =3D &lvts_data->cal_data; + + cal_data->golden_temp =3D GET_CAL_DATA_BITMASK(0, 31, 24); + cal_data->count_r[MT6873_TS1_0] =3D GET_CAL_DATA_BITMASK(1, 23, 0); + cal_data->count_r[MT6873_TS1_1] =3D GET_CAL_DATA_BITMASK(2, 23, 0); + cal_data->count_r[MT6873_TS2_0] =3D GET_CAL_DATA_BITMASK(3, 23, 0); + cal_data->count_r[MT6873_TS2_1] =3D GET_CAL_DATA_BITMASK(4, 23, 0); + cal_data->count_r[MT6873_TS3_0] =3D GET_CAL_DATA_BITMASK(5, 23, 0); + cal_data->count_r[MT6873_TS3_1] =3D GET_CAL_DATA_BITMASK(6, 23, 0); + cal_data->count_r[MT6873_TS3_2] =3D GET_CAL_DATA_BITMASK(7, 23, 0); + cal_data->count_r[MT6873_TS3_3] =3D GET_CAL_DATA_BITMASK(8, 23, 0); + cal_data->count_r[MT6873_TS4_0] =3D GET_CAL_DATA_BITMASK(9, 23, 0); + cal_data->count_r[MT6873_TS4_1] =3D GET_CAL_DATA_BITMASK(10, 23, 0); + cal_data->count_r[MT6873_TS5_0] =3D GET_CAL_DATA_BITMASK(11, 23, 0); + cal_data->count_r[MT6873_TS5_1] =3D GET_CAL_DATA_BITMASK(12, 23, 0); + cal_data->count_r[MT6873_TS6_0] =3D GET_CAL_DATA_BITMASK(13, 23, 0); + cal_data->count_r[MT6873_TS6_1] =3D GET_CAL_DATA_BITMASK(14, 23, 0); + cal_data->count_r[MT6873_TS7_0] =3D GET_CAL_DATA_BITMASK(15, 23, 0); + cal_data->count_r[MT6873_TS7_1] =3D GET_CAL_DATA_BITMASK(16, 23, 0); + cal_data->count_r[MT6873_TS7_2] =3D GET_CAL_DATA_BITMASK(17, 23, 0); + + cal_data->count_rc[MT6873_TS1_0] =3D GET_CAL_DATA_BITMASK(21, 23, 0); + + cal_data->count_rc[MT6873_TS2_0] =3D (GET_CAL_DATA_BITMASK(1, 31, 24) << = 16) + + (GET_CAL_DATA_BITMASK(2, 31, 24) << 8) + + GET_CAL_DATA_BITMASK(3, 31, 24); + + cal_data->count_rc[MT6873_TS3_0] =3D (GET_CAL_DATA_BITMASK(4, 31, 24) << = 16) + + (GET_CAL_DATA_BITMASK(5, 31, 24) << 8) + + GET_CAL_DATA_BITMASK(6, 31, 24); + + cal_data->count_rc[MT6873_TS4_0] =3D (GET_CAL_DATA_BITMASK(7, 31, 24) << = 16) + + (GET_CAL_DATA_BITMASK(8, 31, 24) << 8) + + GET_CAL_DATA_BITMASK(9, 31, 24); + + cal_data->count_rc[MT6873_TS5_0] =3D (GET_CAL_DATA_BITMASK(10, 31, 24) <<= 16) + + (GET_CAL_DATA_BITMASK(11, 31, 24) << 8) + + GET_CAL_DATA_BITMASK(12, 31, 24); + + cal_data->count_rc[MT6873_TS6_0] =3D (GET_CAL_DATA_BITMASK(13, 31, 24) <<= 16) + + (GET_CAL_DATA_BITMASK(14, 31, 24) << 8) + + GET_CAL_DATA_BITMASK(15, 31, 24); + + cal_data->count_rc[MT6873_TS7_0] =3D (GET_CAL_DATA_BITMASK(16, 31, 24) <<= 16) + + (GET_CAL_DATA_BITMASK(17, 31, 24) << 8) + + GET_CAL_DATA_BITMASK(18, 31, 24); +} + +static struct tc_settings mt6873_tc_settings[] =3D { + [0] =3D { + .domain_index =3D MT6873_MCU_DOMAIN, + .addr_offset =3D 0x0, + .num_sensor =3D 2, + .sensor_map =3D {MT6873_TS1_0, MT6873_TS1_1}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT1, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(3), + }, + [1] =3D { + .domain_index =3D MT6873_MCU_DOMAIN, + .addr_offset =3D 0x100, + .num_sensor =3D 2, + .sensor_map =3D {MT6873_TS2_0, MT6873_TS2_1}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT0, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(4), + }, + [2] =3D { + .domain_index =3D MT6873_MCU_DOMAIN, + .addr_offset =3D 0x200, + .num_sensor =3D 4, + .sensor_map =3D {MT6873_TS3_0, MT6873_TS3_1, MT6873_TS3_2, MT6873_TS3_3}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT0, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(5), + }, + [3] =3D { + .domain_index =3D MT6873_AP_DOMAIN, + .addr_offset =3D 0x0, + .num_sensor =3D 2, + .sensor_map =3D {MT6873_TS4_0, MT6873_TS4_1}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT0, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(3), + }, + [4] =3D { + .domain_index =3D MT6873_AP_DOMAIN, + .addr_offset =3D 0x100, + .num_sensor =3D 2, + .sensor_map =3D {MT6873_TS5_0, MT6873_TS5_1}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT1, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(4), + }, + [5] =3D { + .domain_index =3D MT6873_AP_DOMAIN, + .addr_offset =3D 0x200, + .num_sensor =3D 2, + .sensor_map =3D {MT6873_TS6_0, MT6873_TS6_1}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT1, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(5), + }, + [6] =3D { + .domain_index =3D MT6873_AP_DOMAIN, + .addr_offset =3D 0x300, + .num_sensor =3D 3, + .sensor_map =3D {MT6873_TS7_0, MT6873_TS7_1, MT6873_TS7_2}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT2, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(6), + } +}; + +static struct lvts_data mt6873_lvts_data =3D { + .num_domain =3D MT6873_NUM_DOMAIN, + .num_tc =3D MT6873_NUM_LVTS, + .tc =3D mt6873_tc_settings, + .num_sensor =3D MT6873_NUM_TS, + .ops =3D { + .efuse_to_cal_data =3D mt6873_efuse_to_cal_data, + .device_enable_and_init =3D device_enable_and_init_v4, + .device_enable_auto_rck =3D device_enable_auto_rck_v4, + .device_read_count_rc_n =3D device_read_count_rc_n_v4, + .set_cal_data =3D set_calibration_data_v4, + .init_controller =3D init_controller_v4, + }, + .feature_bitmap =3D FEATURE_DEVICE_AUTO_RCK, + .num_efuse_addr =3D 22, + .num_efuse_block =3D 1, + .cal_data =3D { + .default_golden_temp =3D 50, + .default_count_r =3D 35000, + .default_count_rc =3D 2750, + }, + .coeff =3D { + .a =3D -250460, + .b =3D 250460, + }, +}; + +/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + * Support chips + *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + */ +static const struct of_device_id lvts_of_match[] =3D { + { + .compatible =3D "mediatek,mt6873-lvts", + .data =3D (void *)&mt6873_lvts_data, + }, + { + }, +}; +MODULE_DEVICE_TABLE(of, lvts_of_match); +/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D*/ +static struct platform_driver soc_temp_lvts =3D { + .probe =3D lvts_probe, + .remove =3D lvts_remove, + .suspend =3D lvts_suspend, + .resume =3D lvts_resume, + .driver =3D { + .name =3D "mtk-soc-temp-lvts", + .of_match_table =3D lvts_of_match, + }, +}; + +module_platform_driver(soc_temp_lvts); +MODULE_AUTHOR("Yu-Chia Chang "); +MODULE_AUTHOR("Michael Kao "); +MODULE_DESCRIPTION("Mediatek soc temperature driver"); +MODULE_LICENSE("GPL v2"); diff --git a/drivers/thermal/mediatek/soc_temp_lvts.h b/drivers/thermal/med= iatek/soc_temp_lvts.h new file mode 100644 index 000000000000..77c64145aa17 --- /dev/null +++ b/drivers/thermal/mediatek/soc_temp_lvts.h @@ -0,0 +1,312 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2020 MediaTek Inc. + */ + +#ifndef __MTK_SOC_TEMP_LVTS_H__ +#define __MTK_SOC_TEMP_LVTS_H__ + +/* LVTS HW filter settings + * 000: Get one sample + * 001: Get 2 samples and average them + * 010: Get 4 samples, drop max and min, then average the rest of 2 samples + * 011: Get 6 samples, drop max and min, then average the rest of 4 samples + * 100: Get 10 samples, drop max and min, then average the rest of 8 sampl= es + * 101: Get 18 samples, drop max and min, then average the rest of 16 samp= les + */ +enum lvts_hw_filter { + LVTS_FILTER_1, + LVTS_FILTER_2, + LVTS_FILTER_2_OF_4, + LVTS_FILTER_4_OF_6, + LVTS_FILTER_8_OF_10, + LVTS_FILTER_16_OF_18 +}; + +enum lvts_sensing_point { + SENSING_POINT0, + SENSING_POINT1, + SENSING_POINT2, + SENSING_POINT3, + ALL_SENSING_POINTS +}; + +/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + * Data structure + *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + */ +struct lvts_data; + +struct speed_settings { + unsigned int period_unit; + unsigned int group_interval_delay; + unsigned int filter_interval_delay; + unsigned int sensor_interval_delay; +}; + +struct tc_settings { + unsigned int domain_index; + unsigned int addr_offset; + unsigned int num_sensor; + unsigned int sensor_map[ALL_SENSING_POINTS]; /* In sensor ID */ + struct speed_settings tc_speed; + /* HW filter setting + * 000: Get one sample + * 001: Get 2 samples and average them + * 010: Get 4 samples, drop max and min, then average the rest of 2 sampl= es + * 011: Get 6 samples, drop max and min, then average the rest of 4 sampl= es + * 100: Get 10 samples, drop max and min, then average the rest of 8 samp= les + * 101: Get 18 samples, drop max and min, then average the rest of 16 sam= ples + */ + unsigned int hw_filter; + /* Dominator_sensing point is used to select a sensing point + * and reference its temperature to trigger Thermal HW Reboot + * When it is ALL_SENSING_POINTS, it will select all sensing points + */ + int dominator_sensing_point; + int hw_reboot_trip_point; /* -274000: Disable HW reboot */ + unsigned int irq_bit; +}; + +struct formula_coeff { + int a; + int b; + unsigned int golden_temp; +}; + +struct sensor_cal_data { + int use_fake_efuse; /* 1: Use fake efuse, 0: Use real efuse */ + unsigned int golden_temp; + unsigned int *count_r; + unsigned int *count_rc; + unsigned int *count_rc_now; + + unsigned int default_golden_temp; + unsigned int default_count_r; + unsigned int default_count_rc; +}; + +struct platform_ops { + void (*efuse_to_cal_data)(struct lvts_data *lvts_data); + void (*device_enable_and_init)(struct lvts_data *lvts_data); + void (*device_enable_auto_rck)(struct lvts_data *lvts_data); + int (*device_read_count_rc_n)(struct lvts_data *lvts_data); + void (*set_cal_data)(struct lvts_data *lvts_data); + void (*init_controller)(struct lvts_data *lvts_data); +}; + +struct power_domain { + void __iomem *base; /* LVTS base addresses */ + unsigned int irq_num; /* LVTS interrupt numbers */ + struct reset_control *reset; +}; + +struct sensor_data { + void __iomem *base; /* Sensor base address */ + int offset; /* Sensor offset */ +}; + +struct lvts_data { + struct device *dev; + struct clk *clk; + unsigned int num_domain; + struct power_domain *domain; + + int num_tc; /* Number of LVTS thermal controllers */ + struct tc_settings *tc; + int counting_window_us; /* LVTS device counting window */ + + int num_sensor; /* Number of sensors in this platform */ + void __iomem **reg; + + struct platform_ops ops; + int feature_bitmap; /* Show what features are enabled */ + + unsigned int num_efuse_addr; + unsigned int *efuse; + unsigned int num_efuse_block; /* Number of contiguous efuse indexes */ + struct sensor_cal_data cal_data; + struct formula_coeff coeff; +}; + +struct soc_temp_tz { + unsigned int id; /* if id is 0, get max temperature of all sensors */ + struct lvts_data *lvts_data; +}; + +struct match_entry { + char chip[32]; + struct lvts_data *lvts_data; +}; + +struct lvts_match_data { + unsigned int hw_version; + struct match_entry *table; + void (*set_up_common_callbacks)(struct lvts_data *lvts_data); + struct list_head node; +}; + +struct lvts_id { + unsigned int hw_version; + char chip[32]; +}; + +/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + * LVTS device register + *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + */ +#define RG_TSFM_DATA_0 0x00 +#define RG_TSFM_DATA_1 0x01 +#define RG_TSFM_DATA_2 0x02 +#define RG_TSFM_CTRL_0 0x03 +#define RG_TSFM_CTRL_1 0x04 +#define RG_TSFM_CTRL_2 0x05 +#define RG_TSFM_CTRL_3 0x06 +#define RG_TSFM_CTRL_4 0x07 +#define RG_TSV2F_CTRL_0 0x08 +#define RG_TSV2F_CTRL_1 0x09 +#define RG_TSV2F_CTRL_2 0x0A +#define RG_TSV2F_CTRL_3 0x0B +#define RG_TSV2F_CTRL_4 0x0C +#define RG_TSV2F_CTRL_5 0x0D +#define RG_TSV2F_CTRL_6 0x0E +#define RG_TEMP_DATA_0 0x10 +#define RG_TEMP_DATA_1 0x11 +#define RG_TEMP_DATA_2 0x12 +#define RG_TEMP_DATA_3 0x13 +#define RG_RC_DATA_0 0x14 +#define RG_RC_DATA_1 0x15 +#define RG_RC_DATA_2 0x16 +#define RG_RC_DATA_3 0x17 +#define RG_DIV_DATA_0 0x18 +#define RG_DIV_DATA_1 0x19 +#define RG_DIV_DATA_2 0x1A +#define RG_DIV_DATA_3 0x1B +#define RG_TST_DATA_0 0x70 +#define RG_TST_DATA_1 0x71 +#define RG_TST_DATA_2 0x72 +#define RG_TST_CTRL 0x73 +#define RG_DBG_FQMTR 0xF0 +#define RG_DBG_LPSEQ 0xF1 +#define RG_DBG_STATE 0xF2 +#define RG_DBG_CHKSUM 0xF3 +#define RG_DID_LVTS 0xFC +#define RG_DID_REV 0xFD +#define RG_TSFM_RST 0xFF +/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + * LVTS controller register + *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + */ +#define LVTSMONCTL0_0 0x000 +#define LVTS_SINGLE_SENSE BIT(9) +#define ENABLE_SENSING_POINT(num) (LVTS_SINGLE_SENSE | GENMASK(((num) - 1)= , 0)) +#define DISABLE_SENSING_POINT (LVTS_SINGLE_SENSE | 0x0) +#define LVTSMONCTL1_0 0x004 +#define LVTSMONCTL2_0 0x008 +#define LVTSMONINT_0 0x00C +#define STAGE3_INT_EN BIT(31) +#define LVTSMONINTSTS_0 0x010 +#define LVTSMONIDET0_0 0x014 +#define LVTSMONIDET1_0 0x018 +#define LVTSMONIDET2_0 0x01C +#define LVTSMONIDET3_0 0x020 +#define LVTSH2NTHRE_0 0x024 +#define LVTSHTHRE_0 0x028 +#define LVTSCTHRE_0 0x02C +#define LVTSOFFSETH_0 0x030 +#define LVTSOFFSETL_0 0x034 +#define LVTSMSRCTL0_0 0x038 +#define LVTSMSRCTL1_0 0x03C +#define LVTSTSSEL_0 0x040 +#define SET_SENSOR_INDEX 0x13121110 +#define LVTSDEVICETO_0 0x044 +#define LVTSCALSCALE_0 0x048 +#define SET_CALC_SCALE_RULES 0x00000300 +#define LVTS_ID_0 0x04C +#define LVTS_CONFIG_0 0x050 + +#define BROADCAST_ID_UPDATE BIT(26) +#define DEVICE_SENSING_STATUS BIT(25) +#define DEVICE_ACCESS_STARTUS BIT(24) +#define WRITE_ACCESS BIT(16) +#define DEVICE_WRITE (BIT(31) | CK26M_ACTIVE | DEVICE_ACCESS_STARTUS \ + | BIT(17) | WRITE_ACCESS) +#define DEVICE_READ (BIT(31) | CK26M_ACTIVE | DEVICE_ACCESS_STARTUS \ + | 1 << 17) +#define RESET_ALL_DEVICES (DEVICE_WRITE | RG_TSFM_RST << 8 | 0xFF) +#define READ_BACK_DEVICE_ID (BIT(31) | CK26M_ACTIVE | BROADCAST_ID_UPDATE \ + | DEVICE_ACCESS_STARTUS | BIT(17) \ + | RG_DID_LVTS << 8) +#define READ_DEVICE_REG(reg_idx) (DEVICE_READ | (reg_idx) << 8 | 0x00) +#define LVTSEDATA00_0 0x054 +#define LVTSEDATA01_0 0x058 +#define LVTSEDATA02_0 0x05C +#define LVTSEDATA03_0 0x060 +#define LVTSMSR0_0 0x090 +#define MRS_RAW_MASK GENMASK(15, 0) +#define MRS_RAW_VALID_BIT BIT(16) +#define LVTSMSR1_0 0x094 +#define LVTSMSR2_0 0x098 +#define LVTSMSR3_0 0x09C +#define LVTSIMMD0_0 0x0A0 +#define LVTSIMMD1_0 0x0A4 +#define LVTSIMMD2_0 0x0A8 +#define LVTSIMMD3_0 0x0AC +#define LVTSRDATA0_0 0x0B0 +#define LVTSRDATA1_0 0x0B4 +#define LVTSRDATA2_0 0x0B8 +#define LVTSRDATA3_0 0x0BC +#define LVTSPROTCTL_0 0x0C0 +#define PROTOFFSET GENMASK(15, 0) +#define LVTSPROTTA_0 0x0C4 +#define LVTSPROTTB_0 0x0C8 +#define LVTSPROTTC_0 0x0CC +#define LVTSCLKEN_0 0x0E4 +#define ENABLE_LVTS_CTRL_CLK (1) +#define DISABLE_LVTS_CTRL_CLK (0) +#define LVTSDBGSEL_0 0x0E8 +#define LVTSDBGSIG_0 0x0EC +#define LVTSSPARE0_0 0x0F0 +#define LVTSSPARE1_0 0x0F4 +#define LVTSSPARE2_0 0x0F8 +#define LVTSSPARE3_0 0x0FC + +#define THERMINTST 0xF04 +/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + * LVTS register mask + *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + */ +#define THERMAL_COLD_INTERRUPT_0 0x00000001 +#define THERMAL_HOT_INTERRUPT_0 0x00000002 +#define THERMAL_LOW_OFFSET_INTERRUPT_0 0x00000004 +#define THERMAL_HIGH_OFFSET_INTERRUPT_0 0x00000008 +#define THERMAL_HOT2NORMAL_INTERRUPT_0 0x00000010 +#define THERMAL_COLD_INTERRUPT_1 0x00000020 +#define THERMAL_HOT_INTERRUPT_1 0x00000040 +#define THERMAL_LOW_OFFSET_INTERRUPT_1 0x00000080 +#define THERMAL_HIGH_OFFSET_INTERRUPT_1 0x00000100 +#define THERMAL_HOT2NORMAL_INTERRUPT_1 0x00000200 +#define THERMAL_COLD_INTERRUPT_2 0x00000400 +#define THERMAL_HOT_INTERRUPT_2 0x00000800 +#define THERMAL_LOW_OFFSET_INTERRUPT_2 0x00001000 +#define THERMAL_HIGH_OFFSET_INTERRUPT_2 0x00002000 +#define THERMAL_HOT2NORMAL_INTERRUPT_2 0x00004000 +#define THERMAL_AHB_TIMEOUT_INTERRUPT 0x00008000 +#define THERMAL_DEVICE_TIMEOUT_INTERRUPT 0x00008000 +#define THERMAL_IMMEDIATE_INTERRUPT_0 0x00010000 +#define THERMAL_IMMEDIATE_INTERRUPT_1 0x00020000 +#define THERMAL_IMMEDIATE_INTERRUPT_2 0x00040000 +#define THERMAL_FILTER_INTERRUPT_0 0x00080000 +#define THERMAL_FILTER_INTERRUPT_1 0x00100000 +#define THERMAL_FILTER_INTERRUPT_2 0x00200000 +#define THERMAL_COLD_INTERRUPT_3 0x00400000 +#define THERMAL_HOT_INTERRUPT_3 0x00800000 +#define THERMAL_LOW_OFFSET_INTERRUPT_3 0x01000000 +#define THERMAL_HIGH_OFFSET_INTERRUPT_3 0x02000000 +#define THERMAL_HOT2NORMAL_INTERRUPT_3 0x04000000 +#define THERMAL_IMMEDIATE_INTERRUPT_3 0x08000000 +#define THERMAL_FILTER_INTERRUPT_3 0x10000000 +#define THERMAL_PROTECTION_STAGE_1 0x20000000 +#define THERMAL_PROTECTION_STAGE_2 0x40000000 +#define THERMAL_PROTECTION_STAGE_3 0x80000000 +#endif /* __MTK_SOC_TEMP_LVTS_H__ */ --=20 2.35.1 From nobody Sun Sep 22 01:41:23 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 EC4F8C433EF for ; Thu, 12 May 2022 12:25:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353704AbiELMZB (ORCPT ); Thu, 12 May 2022 08:25:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38138 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353676AbiELMYs (ORCPT ); Thu, 12 May 2022 08:24:48 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 06C5B248E29 for ; Thu, 12 May 2022 05:24:42 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id a14-20020a7bc1ce000000b00393fb52a386so5037052wmj.1 for ; Thu, 12 May 2022 05:24:42 -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=S/vo83decuajkRrKEOpC1GzPZTUXB5e+eKL6t2IioWU=; b=qrZVmCr4+Kam5J5VAbk3WUFfCf19Xux9cw0bcqcO04gU3ydSFxVkqFQf+wrCt3IH8n q/IU6+KUbiEQe0Omod83VJY4kdbiut8tJZOZ1NGloiTo4jbupWjISwtFa6nAlWQZPv1j /paqUE5V13OzgyVhBWVHCPVJm5OHtbCsU7Y9OtFPtkXxA5h1WdyDtdHevW49DI6SHUvf d8Dnz5cVV8Kvb4EykZBVWMcK6c/3igHe3lBxdFrBDF78G3hyh3fh6N6jbDrMYHz3AZlb wnzIj0YDS8eu05D0a6PYEgIeIQDvkT08/d7Jkw6JqVAp93r7AeiTYICwOe5HT8n7Q0S9 K6OA== 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=S/vo83decuajkRrKEOpC1GzPZTUXB5e+eKL6t2IioWU=; b=NcHV5rClsouPs8Hd/2FJM//e+IllAWGsDH3QvwhGMm8FWyFwvEqEFo0+19NAXv5U4U eWrjaXC2or+pdgaecElQfaQjsXUngMxlXfZa/WfdBqeYTKp8viZlhj9P2C7ghg6688vq WCaz958TcjJPw+TDU6szKtBCAp5tVjbx2yYdxRg3LKMg/UFZM2PURH86kJsoX5EEAu6L GBqUQGuoGPzCQpn6LLM6wgYa9zA/cB46MucFnCcTKB9wmzt3FpgHvwRtEkYHbaMQGaHf xgs10C+Y9cHqouZfpvpL/KjFCQ7gQTn1SM+UtyH9aKGyW/oIHUu7PqB2RbQ1iMn3Geh4 VQig== X-Gm-Message-State: AOAM532MGu8vSuigvaJd3k3BsisykdrfAwMrson1ReT2y/mvGPSmxmxv V907oubEBdpJWFhAvpMogAZeRQ== X-Google-Smtp-Source: ABdhPJyriTjj+xEsQg0Rd8dZU3OKFWfF/Q7++pVpnNRF2car0YMBp3BYa8rH7qnU6+ejyHZQ7w1hOw== X-Received: by 2002:a05:600c:1e89:b0:394:9587:cbe0 with SMTP id be9-20020a05600c1e8900b003949587cbe0mr9917994wmb.89.1652358281444; Thu, 12 May 2022 05:24:41 -0700 (PDT) Received: from xps-9300.baylibre (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id z22-20020a7bc156000000b003942a244f30sm3047819wmi.9.2022.05.12.05.24.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 05:24:41 -0700 (PDT) From: Alexandre Bailon To: robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de Cc: rafael@kernel.org, daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, michael.kao@mediatek.com, ben.tseng@mediatek.com, ethan.chang@mediatek.com, frank-w@public-files.de, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, khilman@baylibre.com, Alexandre Bailon Subject: [PATCH v6 4/7] dt-bindings: thermal: Add binding document for mt8195 thermal controller Date: Thu, 12 May 2022 14:24:30 +0200 Message-Id: <20220512122433.1399802-5-abailon@baylibre.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220512122433.1399802-1-abailon@baylibre.com> References: <20220512122433.1399802-1-abailon@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" This patch adds binding document for mt8195 thermal controller. Signed-off-by: Alexandre Bailon --- .../devicetree/bindings/thermal/mediatek-thermal-lvts.yaml | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/Documentation/devicetree/bindings/thermal/mediatek-thermal-lvt= s.yaml b/Documentation/devicetree/bindings/thermal/mediatek-thermal-lvts.ya= ml index 69ffe7b14c21..2e1ae00d4fd1 100644 --- a/Documentation/devicetree/bindings/thermal/mediatek-thermal-lvts.yaml +++ b/Documentation/devicetree/bindings/thermal/mediatek-thermal-lvts.yaml @@ -12,7 +12,11 @@ maintainers: =20 properties: compatible: - const: mediatek,mt6873-lvts + oneOf: + - items: + - enum: + - mediatek,mt6873-lvts + - mediatek,mt8195-lvts =20 reg: maxItems: 1 --=20 2.35.1 From nobody Sun Sep 22 01:41:23 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 0682AC433F5 for ; Thu, 12 May 2022 12:25:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353713AbiELMZR (ORCPT ); Thu, 12 May 2022 08:25:17 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38206 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353665AbiELMYs (ORCPT ); Thu, 12 May 2022 08:24:48 -0400 Received: from mail-wr1-x430.google.com (mail-wr1-x430.google.com [IPv6:2a00:1450:4864:20::430]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E3D7124735D for ; Thu, 12 May 2022 05:24:43 -0700 (PDT) Received: by mail-wr1-x430.google.com with SMTP id d5so7024557wrb.6 for ; Thu, 12 May 2022 05:24:43 -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=tQMVyVqHgBWr9jrth3XGcb0oJTmc+ZSSOROdsenztjQ=; b=EI5SK+x2NOPcWAR0ZjAzXIc1jlEF/SB9Fbehmu8SsfBBkbmbBQIAsRnBRasB3L8DRd VIUWoiiTfSO1te4Tld0MYxOBuvqZV6klL8d3U5ttww/hvKZerH8ajUGxx2vvCmWMSFwh VMjwUIFKiurnw/aYrxIu8qrKoP9No2+SO4ROvXduNwE+gpLKnSnl59TibGRy0zNimL+g XTwtsw+cNX9VRZzaOIKaU5ZZId3crQh8ucJachBS1cHxEQKjpprnfI9irH5YbWSOna8F Sp5gro8X/z7WH0/h0bns/01hZf96UHpF/toQEbELjQNBq8TlOBuxhkkB+x8GtO1hcADO Rbww== 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=tQMVyVqHgBWr9jrth3XGcb0oJTmc+ZSSOROdsenztjQ=; b=pq9q78psDF1HAYTA+XdJ9xOv87CymhRk6bZXxfHU22cZPFRoLXqy+DE+z/XxajNEAZ J2CjJLoWrGorOm15H9e4NPshzAHNTBmXda4vc17njPRRY+zSGXRtJzstvxVuccW7zN2P ScaSOEoSADwFdm3VCbCVvct1bn3coLO/Kaw2z2gq1HJNSdAu319Y7EbpCQWNUhKedFa4 wv7tbG2HkevPZFKQhk/8NjZ+pXC0spgbFbXii8suBot6Ux2pK7XWmbOrGHdvXTDkApHm Ummi8MwfogmwxTkaNrgXmWPH6C792On9xTaR7cCZYwzTfbFGv12Iu9KWQDH0elaqcaOw QtPQ== X-Gm-Message-State: AOAM530iHAxHt2pt/6yfl1wtIT0TvVJcS9CAo3WJJtH5skmBagGr8MzC WaTetS5npKNQo90tYkHoJjUk1w== X-Google-Smtp-Source: ABdhPJwoYdXx8akupLRzTqMljKIUVeJymrNlpE7RVAeYS77j644kQJr6ac3Xa8fscPzbbEsY7SxgMg== X-Received: by 2002:a5d:6843:0:b0:20a:def2:5545 with SMTP id o3-20020a5d6843000000b0020adef25545mr27456759wrw.89.1652358282399; Thu, 12 May 2022 05:24:42 -0700 (PDT) Received: from xps-9300.baylibre (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id z22-20020a7bc156000000b003942a244f30sm3047819wmi.9.2022.05.12.05.24.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 05:24:42 -0700 (PDT) From: Alexandre Bailon To: robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de Cc: rafael@kernel.org, daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, michael.kao@mediatek.com, ben.tseng@mediatek.com, ethan.chang@mediatek.com, frank-w@public-files.de, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, khilman@baylibre.com, Alexandre Bailon Subject: [PATCH v6 5/7] thermal: mediatek: Add thermal zone settings for mt8195 Date: Thu, 12 May 2022 14:24:31 +0200 Message-Id: <20220512122433.1399802-6-abailon@baylibre.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220512122433.1399802-1-abailon@baylibre.com> References: <20220512122433.1399802-1-abailon@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: Michael Kao Add thermal zone settings for mt8195 Signed-off-by: Michael Kao Signed-off-by: Ben Tseng Signed-off-by: Alexandre Bailon --- drivers/thermal/mediatek/soc_temp_lvts.c | 206 +++++++++++++++++++++-- 1 file changed, 192 insertions(+), 14 deletions(-) diff --git a/drivers/thermal/mediatek/soc_temp_lvts.c b/drivers/thermal/med= iatek/soc_temp_lvts.c index 145ddd5fe409..1c83c4f9aa64 100644 --- a/drivers/thermal/mediatek/soc_temp_lvts.c +++ b/drivers/thermal/mediatek/soc_temp_lvts.c @@ -53,6 +53,7 @@ =20 #define CLOCK_26MHZ_CYCLE_NS (38) #define BUS_ACCESS_US (2) +#define GOLDEN_TEMP_MAX (62) =20 #define FEATURE_DEVICE_AUTO_RCK (BIT(0)) #define FEATURE_CK26M_ACTIVE (BIT(1)) @@ -549,21 +550,10 @@ static int prepare_calibration_data(struct lvts_data = *lvts_data) if (!cal_data->count_rc) return -ENOMEM; =20 - if (ops->efuse_to_cal_data) + if (ops->efuse_to_cal_data && !cal_data->use_fake_efuse) ops->efuse_to_cal_data(lvts_data); - - cal_data->use_fake_efuse =3D 1; - if (cal_data->golden_temp !=3D 0) { - cal_data->use_fake_efuse =3D 0; - } else { - for (i =3D 0; i < lvts_data->num_sensor; i++) { - if (cal_data->count_r[i] !=3D 0 || - cal_data->count_rc[i] !=3D 0) { - cal_data->use_fake_efuse =3D 0; - break; - } - } - } + if (cal_data->golden_temp =3D=3D 0 || cal_data->golden_temp > GOLDEN_TEMP= _MAX) + cal_data->use_fake_efuse =3D 1; =20 if (cal_data->use_fake_efuse) { /* It means all efuse data are equal to 0 */ @@ -1247,6 +1237,190 @@ static struct lvts_data mt6873_lvts_data =3D { }, }; =20 +/*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + * LVTS MT8195 + *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D + */ + +#define MT8195_NUM_LVTS (ARRAY_SIZE(mt8195_tc_settings)) + +enum mt8195_lvts_domain { + MT8195_AP_DOMAIN, + MT8195_MCU_DOMAIN, + MT8195_NUM_DOMAIN +}; + +enum mt8195_lvts_sensor_enum { + MT8195_TS1_0, + MT8195_TS1_1, + MT8195_TS2_0, + MT8195_TS2_1, + MT8195_TS3_0, + MT8195_TS3_1, + MT8195_TS3_2, + MT8195_TS3_3, + MT8195_TS4_0, + MT8195_TS4_1, + MT8195_TS5_0, + MT8195_TS5_1, + MT8195_TS6_0, + MT8195_TS6_1, + MT8195_TS6_2, + MT8195_TS7_0, + MT8195_TS7_1, + MT8195_NUM_TS +}; + +static void mt8195_efuse_to_cal_data(struct lvts_data *lvts_data) +{ + struct sensor_cal_data *cal_data =3D &lvts_data->cal_data; + + cal_data->golden_temp =3D GET_CAL_DATA_BITMASK(0, 31, 24); + cal_data->count_r[MT8195_TS1_0] =3D GET_CAL_DATA_BITMASK(1, 23, 0); + cal_data->count_r[MT8195_TS1_1] =3D (GET_CAL_DATA_BITMASK(2, 15, 0) << 8)= + + GET_CAL_DATA_BITMASK(1, 31, 24); + cal_data->count_r[MT8195_TS2_0] =3D GET_CAL_DATA_BITMASK(3, 31, 8); + cal_data->count_r[MT8195_TS2_1] =3D GET_CAL_DATA_BITMASK(4, 23, 0); + cal_data->count_r[MT8195_TS3_0] =3D (GET_CAL_DATA_BITMASK(6, 7, 0) << 16)= + + GET_CAL_DATA_BITMASK(5, 31, 16); + cal_data->count_r[MT8195_TS3_1] =3D GET_CAL_DATA_BITMASK(6, 31, 8); + cal_data->count_r[MT8195_TS3_2] =3D GET_CAL_DATA_BITMASK(7, 23, 0); + cal_data->count_r[MT8195_TS3_3] =3D (GET_CAL_DATA_BITMASK(8, 15, 0) << 8)= + + GET_CAL_DATA_BITMASK(7, 31, 24); + cal_data->count_r[MT8195_TS4_0] =3D GET_CAL_DATA_BITMASK(9, 31, 8); + cal_data->count_r[MT8195_TS4_1] =3D GET_CAL_DATA_BITMASK(10, 23, 0); + cal_data->count_r[MT8195_TS5_0] =3D (GET_CAL_DATA_BITMASK(12, 7, 0) << 16= ) + + GET_CAL_DATA_BITMASK(11, 31, 16); + cal_data->count_r[MT8195_TS5_1] =3D GET_CAL_DATA_BITMASK(12, 31, 8); + cal_data->count_r[MT8195_TS6_0] =3D (GET_CAL_DATA_BITMASK(14, 15, 0) << 8= ) + + GET_CAL_DATA_BITMASK(13, 31, 24); + cal_data->count_r[MT8195_TS6_1] =3D (GET_CAL_DATA_BITMASK(15, 7, 0) << 16= ) + + GET_CAL_DATA_BITMASK(14, 31, 16); + cal_data->count_r[MT8195_TS6_2] =3D GET_CAL_DATA_BITMASK(15, 31, 8); + cal_data->count_r[MT8195_TS7_0] =3D (GET_CAL_DATA_BITMASK(17, 15, 0) << 8= ) + + GET_CAL_DATA_BITMASK(16, 31, 24); + cal_data->count_r[MT8195_TS7_1] =3D (GET_CAL_DATA_BITMASK(18, 7, 0) << 16= ) + + GET_CAL_DATA_BITMASK(17, 31, 16); + cal_data->count_rc[MT8195_TS1_0] =3D (GET_CAL_DATA_BITMASK(3, 7, 0) << 16= ) + + GET_CAL_DATA_BITMASK(2, 31, 16); + cal_data->count_rc[MT8195_TS2_0] =3D (GET_CAL_DATA_BITMASK(5, 15, 0) << 8= ) + + GET_CAL_DATA_BITMASK(4, 31, 24); + cal_data->count_rc[MT8195_TS3_0] =3D (GET_CAL_DATA_BITMASK(9, 7, 0) << 16= ) + + GET_CAL_DATA_BITMASK(8, 31, 16); + cal_data->count_rc[MT8195_TS4_0] =3D (GET_CAL_DATA_BITMASK(11, 15, 0) << = 8) + + GET_CAL_DATA_BITMASK(10, 31, 24); + cal_data->count_rc[MT8195_TS5_0] =3D GET_CAL_DATA_BITMASK(13, 23, 0); + cal_data->count_rc[MT8195_TS6_0] =3D GET_CAL_DATA_BITMASK(16, 23, 0); + cal_data->count_rc[MT8195_TS7_0] =3D GET_CAL_DATA_BITMASK(18, 31, 8); +} + +static struct tc_settings mt8195_tc_settings[] =3D { + [0] =3D { + .domain_index =3D MT8195_MCU_DOMAIN, + .addr_offset =3D 0x0, + .num_sensor =3D 2, + .sensor_map =3D {MT8195_TS1_0, MT8195_TS1_1}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT1, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(3), + }, + [1] =3D { + .domain_index =3D MT8195_MCU_DOMAIN, + .addr_offset =3D 0x100, + .num_sensor =3D 2, + .sensor_map =3D {MT8195_TS2_0, MT8195_TS2_1}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT0, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(4), + }, + [2] =3D { + .domain_index =3D MT8195_MCU_DOMAIN, + .addr_offset =3D 0x200, + .num_sensor =3D 4, + .sensor_map =3D {MT8195_TS3_0, MT8195_TS3_1, MT8195_TS3_2, MT8195_TS3_3}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT0, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(5), + }, + [3] =3D { + .domain_index =3D MT8195_AP_DOMAIN, + .addr_offset =3D 0x0, + .num_sensor =3D 2, + .sensor_map =3D {MT8195_TS4_0, MT8195_TS4_1}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT0, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(3), + }, + [4] =3D { + .domain_index =3D MT8195_AP_DOMAIN, + .addr_offset =3D 0x100, + .num_sensor =3D 2, + .sensor_map =3D {MT8195_TS5_0, MT8195_TS5_1}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT1, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(4), + }, + [5] =3D { + .domain_index =3D MT8195_AP_DOMAIN, + .addr_offset =3D 0x200, + .num_sensor =3D 3, + .sensor_map =3D {MT8195_TS6_0, MT8195_TS6_1, MT8195_TS6_2}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT1, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(5), + }, + [6] =3D { + .domain_index =3D MT8195_AP_DOMAIN, + .addr_offset =3D 0x300, + .num_sensor =3D 2, + .sensor_map =3D {MT8195_TS7_0, MT8195_TS7_1}, + .tc_speed =3D SET_TC_SPEED_IN_US(118, 118, 118, 118), + .hw_filter =3D LVTS_FILTER_2_OF_4, + .dominator_sensing_point =3D SENSING_POINT0, + .hw_reboot_trip_point =3D 117000, + .irq_bit =3D BIT(6), + } +}; + +static struct lvts_data mt8195_lvts_data =3D { + .num_domain =3D MT8195_NUM_DOMAIN, + .num_tc =3D MT8195_NUM_LVTS, + .tc =3D mt8195_tc_settings, + .num_sensor =3D MT8195_NUM_TS, + .ops =3D { + .efuse_to_cal_data =3D mt8195_efuse_to_cal_data, + .device_enable_and_init =3D device_enable_and_init_v4, + .device_enable_auto_rck =3D device_enable_auto_rck_v4, + .device_read_count_rc_n =3D device_read_count_rc_n_v4, + .set_cal_data =3D set_calibration_data_v4, + .init_controller =3D init_controller_v4, + }, + .feature_bitmap =3D FEATURE_DEVICE_AUTO_RCK, + .num_efuse_addr =3D 22, + .num_efuse_block =3D 2, + .cal_data =3D { + .default_golden_temp =3D 50, + .default_count_r =3D 35000, + .default_count_rc =3D 2750, + }, + .coeff =3D { + .a =3D -250460, + .b =3D 250460, + }, +}; + /*=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D *=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D * Support chips @@ -1257,6 +1431,10 @@ static const struct of_device_id lvts_of_match[] =3D= { .compatible =3D "mediatek,mt6873-lvts", .data =3D (void *)&mt6873_lvts_data, }, + { + .compatible =3D "mediatek,mt8195-lvts", + .data =3D (void *)&mt8195_lvts_data, + }, { }, }; --=20 2.35.1 From nobody Sun Sep 22 01:41:23 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 EE575C433F5 for ; Thu, 12 May 2022 12:25:08 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353681AbiELMZG (ORCPT ); Thu, 12 May 2022 08:25:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38202 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353680AbiELMYs (ORCPT ); Thu, 12 May 2022 08:24:48 -0400 Received: from mail-wr1-x42c.google.com (mail-wr1-x42c.google.com [IPv6:2a00:1450:4864:20::42c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E710624734C for ; Thu, 12 May 2022 05:24:44 -0700 (PDT) Received: by mail-wr1-x42c.google.com with SMTP id q23so7031712wra.1 for ; Thu, 12 May 2022 05:24:44 -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=befZQ9FS23fWMFZgR26WPFKtinCTSI/vcnKTdqrsD2I=; b=3BHa3XT/PM1d1Fqi4xdlw28bRsyHbtLMKPZ3xkV1jdTvwnDc4q2bNcQ7kJkdQqg2PG ooi6aQOfiOzLrON7fQvWJQHbOEFE1bXmTqDtJfD2uhBwfqsTPcwh23AVpQ2qO0zH/O3/ AV4mGC+ARmcDMVCotPPZkyyvkqbjDeVluw7uOg6vG95WukWDTm76nWqLWuiqvPFZCkSK a/+8/aQicU0gw32smoTPprxZLzqH5r8x5vGutquYVlUh38sRJ2K9G4S+UnfSijBUP0Ey 8dlgbR/MCauaFiOLg5bBREaJz3FqgsXlqhf7Ew1Ghva9ZT6WTCSbrrZ1/N/dJBtXbpZL 8+CQ== 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=befZQ9FS23fWMFZgR26WPFKtinCTSI/vcnKTdqrsD2I=; b=DbKr/XncwSRoPMd/wdo7+ECRL0+yOB2R1Wvz93BrxEgNjAozdX/hmKwZk+/rSmY+NT xKZDpXI86xujqRxtpfe2qpdeuq2ZMWeL6IxA8nqa4BB2+pcu6dVscNUdtsG5EL5bbm2a 29FEpCXYeWu19W3jvrCDTXIXSn8VIWMvLUysJ5DJUEdtLYRHiiqc2vIOEq9oiIABo97A FUjV1ui9CpFNAYmLKLpeWSAMD/CxuL2edsr52s6ym7ZMJY8GFnmXUT1gHYX2y7X/KO5N mEdv8YWKPKnpsu7p4wVoPUQode6FbREOIoBXDsIX4k8B8nzIT/NMmh67KseEstbLhm3h IEfw== X-Gm-Message-State: AOAM530uy1wCIV4/7V7gWa7PuQdB+g5wvpV+gabJFA5TtBaaIpajbcY+ ant6ZJY9g5K4i7oWYqkRiB9/hw== X-Google-Smtp-Source: ABdhPJzl2RnwuKtjp0w2JW5qr0wn4jOfQ9nztXnOxQtRwboK1PADSs7vYj8oT4mnuqSVmq7o/fDkmA== X-Received: by 2002:a5d:47ca:0:b0:20c:72c9:d3be with SMTP id o10-20020a5d47ca000000b0020c72c9d3bemr26671903wrc.114.1652358283467; Thu, 12 May 2022 05:24:43 -0700 (PDT) Received: from xps-9300.baylibre (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id z22-20020a7bc156000000b003942a244f30sm3047819wmi.9.2022.05.12.05.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 05:24:43 -0700 (PDT) From: Alexandre Bailon To: robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de Cc: rafael@kernel.org, daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, michael.kao@mediatek.com, ben.tseng@mediatek.com, ethan.chang@mediatek.com, frank-w@public-files.de, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, khilman@baylibre.com, Alexandre Bailon Subject: [PATCH v6 6/7] arm64: dts: mt8195: Add efuse node to mt8195 Date: Thu, 12 May 2022 14:24:32 +0200 Message-Id: <20220512122433.1399802-7-abailon@baylibre.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220512122433.1399802-1-abailon@baylibre.com> References: <20220512122433.1399802-1-abailon@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" This adds the efuse node. This will be required by the thermal driver to get the calibration data. Signed-off-by: Alexandre Bailon --- arch/arm64/boot/dts/mediatek/mt8195.dtsi | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/arch/arm64/boot/dts/mediatek/mt8195.dtsi b/arch/arm64/boot/dts= /mediatek/mt8195.dtsi index 416d37e07324..12887fb4d0d1 100644 --- a/arch/arm64/boot/dts/mediatek/mt8195.dtsi +++ b/arch/arm64/boot/dts/mediatek/mt8195.dtsi @@ -13,6 +13,7 @@ #include #include #include +#include =20 / { compatible =3D "mediatek,mt8195"; @@ -1248,6 +1249,23 @@ nor_flash: spi@1132c000 { status =3D "disabled"; }; =20 + efuse: efuse@11c10000 { + compatible =3D "mediatek,efuse"; + reg =3D <0 0x11c10000 0 0x1000>; + #address-cells =3D <1>; + #size-cells =3D <1>; + + lvts_e_data1: data1 { + reg =3D <0x1bc 0x14>; + }; + lvts_e_data2: data1-1 { + reg =3D <0x1d0 0x38>; + }; + svs_calibration: calib@580 { + reg =3D <0x580 0x64>; + }; + }; + u3phy2: t-phy@11c40000 { compatible =3D "mediatek,mt8195-tphy", "mediatek,generic-tphy-v3"; #address-cells =3D <1>; --=20 2.35.1 From nobody Sun Sep 22 01:41:23 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 4F2C3C433F5 for ; Thu, 12 May 2022 12:25:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1353766AbiELMZW (ORCPT ); Thu, 12 May 2022 08:25:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:38204 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1353682AbiELMYt (ORCPT ); Thu, 12 May 2022 08:24:49 -0400 Received: from mail-wm1-x331.google.com (mail-wm1-x331.google.com [IPv6:2a00:1450:4864:20::331]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F00FE247374 for ; Thu, 12 May 2022 05:24:45 -0700 (PDT) Received: by mail-wm1-x331.google.com with SMTP id 125-20020a1c1983000000b003941f354c62so2911928wmz.0 for ; Thu, 12 May 2022 05:24:45 -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=O/dkIwzTHk+5gsotg7nLbrQsDZjzi6VTdK6DCeSc+w8=; b=QriHUDKYodKrRPdxpYYgtJTXUTjl6lU+iPjloHZmUjl6pz0T8QXq4FytbPxG5TJGWW SIR6jIVEMBAdtCoHsg9ZBHYt6Fmt76/9P2zA1nFKnL/uSuHVQrl2w4mMEupUJyKHsBNa rtkoisnbWKZ8J5IotNBpXoseTd6d9z7v+TL0JtYf9ARG9ApeW8ypCGCc//Kr+q/mzJiE D8nTwJ+ZSunczyXzcyX+2Jwstqa2kSug0pZrza8UvXqsS2qR9TPdlBrw1+9uqA1W7CvI 7ZOt+8WS4I1B2yOcHuxg40VI2Q25dDYeQjnveExd7cXE8Vi5pNx3CYHsBZtVuDGtmXLY QYJQ== 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=O/dkIwzTHk+5gsotg7nLbrQsDZjzi6VTdK6DCeSc+w8=; b=YEr5bEjMDZGJKyk8u2/aQNGL5q7WoU48px5PlmBNlW3gmd/jzC3A38DgIx2fs6y5SF 7y8WG152EhmBBJdH8cA2MeAm9jJoO7faNh9ZpCL/hWrPNFhKJz3blIyyulGTqKz579Xh /eERmmUGK7U5vGchkjAnqNE7Ry7/Ap9xtG5TtjKQ8fnAVMC7LYUdI7NXieEgKx9wKl1F 2oS/WUBCnY4ROaZym7XrVh4p2Y5ahXhmKmeXKhzyLR1OEybc5fBFsXhSFWLglCQ47RZn bMQCQWpAT+7xcyoXg2eu7+wwRC4BeUiEio+rFSmzrZtaaHA3R1aL+AJ75SFoN1iUmz4E gPGw== X-Gm-Message-State: AOAM530oOoI+g3OuJTfD1wg4B5O+Gof1BdRDyK5efX2toLdQPlcltu04 /Tg7UqvwvWSLLfjnRQVsmlgKcQ== X-Google-Smtp-Source: ABdhPJz7xhNH2VS8qz0wUUIsoo72WfBxVT3Sy5iAc/peGlJ6NUtqhpFPZLhhTH9iUNPRol++6IwYDw== X-Received: by 2002:a7b:ce02:0:b0:381:2007:f75c with SMTP id m2-20020a7bce02000000b003812007f75cmr10138584wmc.6.1652358284482; Thu, 12 May 2022 05:24:44 -0700 (PDT) Received: from xps-9300.baylibre (laubervilliers-658-1-213-31.w90-63.abo.wanadoo.fr. [90.63.244.31]) by smtp.gmail.com with ESMTPSA id z22-20020a7bc156000000b003942a244f30sm3047819wmi.9.2022.05.12.05.24.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 12 May 2022 05:24:44 -0700 (PDT) From: Alexandre Bailon To: robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de Cc: rafael@kernel.org, daniel.lezcano@linaro.org, amitk@kernel.org, rui.zhang@intel.com, michael.kao@mediatek.com, ben.tseng@mediatek.com, ethan.chang@mediatek.com, frank-w@public-files.de, linux-pm@vger.kernel.org, devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, khilman@baylibre.com, Tinghan Shen , Alexandre Bailon Subject: [PATCH v6 7/7] arm64: dts: mt8195: Add thermal zone Date: Thu, 12 May 2022 14:24:33 +0200 Message-Id: <20220512122433.1399802-8-abailon@baylibre.com> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220512122433.1399802-1-abailon@baylibre.com> References: <20220512122433.1399802-1-abailon@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: Tinghan Shen This adds the thermal zone for the mt8195. Signed-off-by: Tinghan Shen Signed-off-by: Ben Tseng Signed-off-by: Alexandre Bailon --- arch/arm64/boot/dts/mediatek/mt8195.dtsi | 103 +++++++++++++++++++++++ 1 file changed, 103 insertions(+) diff --git a/arch/arm64/boot/dts/mediatek/mt8195.dtsi b/arch/arm64/boot/dts= /mediatek/mt8195.dtsi index 12887fb4d0d1..d6e5b595a89f 100644 --- a/arch/arm64/boot/dts/mediatek/mt8195.dtsi +++ b/arch/arm64/boot/dts/mediatek/mt8195.dtsi @@ -823,6 +823,21 @@ spi0: spi@1100a000 { status =3D "disabled"; }; =20 + lvts: lvts@1100b000 { + compatible =3D "mediatek,mt8195-lvts"; + #thermal-sensor-cells =3D <1>; + reg =3D <0 0x1100b000 0 0x1000>, + <0 0x11278000 0 0x1000>; + interrupts =3D , + ; + clocks =3D <&infracfg_ao CLK_INFRA_AO_THERM>; + clock-names =3D "lvts_clk"; + resets =3D <&infracfg_rst 1>, + <&infracfg_rst 2>; + nvmem-cells =3D <&lvts_e_data1 &lvts_e_data2>; + nvmem-cell-names =3D "e_data1","e_data2"; + }; + spi1: spi@11010000 { compatible =3D "mediatek,mt8195-spi", "mediatek,mt6765-spi"; @@ -1627,4 +1642,92 @@ vencsys_core1: clock-controller@1b000000 { #clock-cells =3D <1>; }; }; + + thermal_zones: thermal-zones { + cpu_big1 { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 0>; + }; + cpu_big2 { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 1>; + }; + cpu_big3 { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 2>; + }; + cpu_big4 { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 3>; + }; + cpu_little1{ + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 4>; + }; + cpu_little2 { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 5>; + }; + cpu_little3 { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 6>; + }; + cpu_little4 { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 7>; + }; + vpu1 { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 8>; + }; + vpu2 { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 9>; + }; + gpu1 { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 10>; + }; + gpu2 { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 11>; + }; + vdec { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 12>; + }; + img { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 13>; + }; + infra { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 14>; + }; + cam1 { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 15>; + }; + cam2 { + polling-delay =3D <0>; /* milliseconds */ + polling-delay-passive =3D <0>; /* milliseconds */ + thermal-sensors =3D <&lvts 16>; + }; + }; }; --=20 2.35.1