From patchwork Thu Aug 4 13:09:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balsam CHIHI X-Patchwork-Id: 12936373 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id C6EC3C25B08 for ; Thu, 4 Aug 2022 13:10:26 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=qQK3oz9qbEyhSdrl3bVOwNcv3E2dhXu4IVGnclR+410=; b=i2MrXzPy8hgMCRHadyeAQYr7d9 BUW424sXlDZYTtCSKry2jgoWBwYR2zTzKHLc5u8754Tr3feap+zNydRiDiHP7ryGsFPgS1ZAcTO6b n92rVLBjniC4EGQ9wORGvRDGp0iPs8tp7KAH8jOSU71umyAo7PgtxAC0pI0Z4kE9NE3clhZKQHJnx WJN5SccYCo8BidDLOzXu+aS883jusW5Du0bSyn2FcOu+/Pm0oIlfieny2xWfqxMP5L/lIMijmD7pA ttRWlQrokQ6Q3E65yL8t/WV0OPfwCPa1QEWnIm0Jgx0TJHD7SojONeRsEsAydqCfo+pFeDsYQc28n sNHL2Qaw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJacF-006AkH-Ix; Thu, 04 Aug 2022 13:10:19 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJabw-006AWi-Fe for linux-mediatek@lists.infradead.org; Thu, 04 Aug 2022 13:10:04 +0000 Received: by mail-wm1-x329.google.com with SMTP id h34-20020a05600c49a200b003a5165eae0fso150796wmp.4 for ; Thu, 04 Aug 2022 06:09:59 -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=qQK3oz9qbEyhSdrl3bVOwNcv3E2dhXu4IVGnclR+410=; b=vr2V+/907iDdlnruy3oQToaR/XfzjPvf1I8r6njjhSb5We2JXBTFSpXjdhgdhuNfIQ N6tVvfvbwormefx89zs9dso8FCwkmNIrVtuB7VcJE6msdYBZU77/6XDdKGeMSR24Ojfy b68X2iJtRHY0/FXzxwb7gVrvSm8ZGqAstptPsUlBWVnKCyufHMMDHVYFqfnRyc3CiNa6 yNleYhuM22fRPZf+6wl8eCBgKF+TOF7sLztPbBzwmMoYU1BjTLALh2RAIrl5ylhBiasi RHaK1gwfDFm3QBWJDHVlAi72fFMinOga3boV8oOh8/AaLcZ0X/2+S4dQH5Voj5HM652n jwiw== 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=qQK3oz9qbEyhSdrl3bVOwNcv3E2dhXu4IVGnclR+410=; b=TkU1s0nRYGcUJv2ZZi5C21qfcT9Q/CHZgDbjLHwN8cc3rL4ebCLrwLAnNyY85TksUw VfOiw6sDiKUrNZ3B6RjraqxCUf3mwbjR+a/cBBE4MTMzHehNiFGJY3E3kmJ+RD9Hfxa2 Gfd0bZepciKVPx5v847ZbLmkFvD3AUlk5v6tjn1sdceRGZTgjKdPvqUFpG4DeRXv5OUF 90y9SHMECekTMlm7X528fGkF6qQY0akN5Pfbg50+PU/G/T5EvHb7Z78kJu2491cXlUNC rzzOJz/6BRsgnWAFiUhkiLyYwhOvYx11A0y2X6hZoGntmFVwQt2pUvkQymNyC0oP/KuB wEpQ== X-Gm-Message-State: ACgBeo1acgvnEPFoLRFpnJw+ScjUR9C4RquJ1AbX0YTevgP/IYoLX0oe DJGmhg6FyFsw9SROOhwHsW643Q== X-Google-Smtp-Source: AA6agR6o7r2+kCKEC0XaLuFu+G6WZijNXigrC6QeFtwmE/pCSyLppgMu1drtiApXCtiavm4n36GGGQ== X-Received: by 2002:a05:600c:503:b0:3a3:29ec:cd0 with SMTP id i3-20020a05600c050300b003a329ec0cd0mr6067777wmc.63.1659618597960; Thu, 04 Aug 2022 06:09:57 -0700 (PDT) Received: from Balsam-ThinkPad-T480.. (235.163.185.81.rev.sfr.net. [81.185.163.235]) by smtp.gmail.com with ESMTPSA id o15-20020adfcf0f000000b0021d6a520ce9sm1156817wrj.47.2022.08.04.06.09.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 06:09:57 -0700 (PDT) From: bchihi@baylibre.com To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amitk@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, mka@chromium.org, robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, james.lo@mediatek.com, fan.chen@mediatek.com, louis.yu@mediatek.com, rex-bc.chen@mediatek.com, abailon@baylibre.com Subject: [PATCH v8.1, 1/7] thermal: mediatek: Relocate driver to mediatek folder Date: Thu, 4 Aug 2022 15:09:06 +0200 Message-Id: <20220804130912.676043-2-bchihi@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220804130912.676043-1-bchihi@baylibre.com> References: <20220804130912.676043-1-bchihi@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220804_061000_547757_A9C57592 X-CRM114-Status: GOOD ( 17.07 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org 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 it as "mtxxxx_thermal.c" to show its purpose more clearly. Signed-off-by: Michael Kao Signed-off-by: Ben Tseng Signed-off-by: Balsam CHIHI --- drivers/thermal/Kconfig | 14 ++++------- drivers/thermal/Makefile | 2 +- drivers/thermal/mediatek/Kconfig | 23 +++++++++++++++++++ drivers/thermal/mediatek/Makefile | 1 + .../mtxxxx_thermal.c} | 2 +- 5 files changed, 30 insertions(+), 12 deletions(-) create mode 100644 drivers/thermal/mediatek/Kconfig create mode 100644 drivers/thermal/mediatek/Makefile rename drivers/thermal/{mtk_thermal.c => mediatek/mtxxxx_thermal.c} (99%) diff --git a/drivers/thermal/Kconfig b/drivers/thermal/Kconfig index 0e5cc948373c..ecba8d6e313b 100644 --- a/drivers/thermal/Kconfig +++ b/drivers/thermal/Kconfig @@ -412,16 +412,10 @@ config DA9062_THERMAL zone. Compatible with the DA9062 and DA9061 PMICs. -config MTK_THERMAL - tristate "Temperature sensor driver for mediatek SoCs" - depends on ARCH_MEDIATEK || COMPILE_TEST - depends on HAS_IOMEM - depends on NVMEM || NVMEM=n - 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 config AMLOGIC_THERMAL tristate "Amlogic Thermal Support" diff --git a/drivers/thermal/Makefile b/drivers/thermal/Makefile index def8e1a0399c..f7daeb8056c4 100644 --- a/drivers/thermal/Makefile +++ b/drivers/thermal/Makefile @@ -55,7 +55,7 @@ obj-y += st/ obj-$(CONFIG_QCOM_TSENS) += qcom/ obj-y += tegra/ obj-$(CONFIG_HISI_THERMAL) += hisi_thermal.o -obj-$(CONFIG_MTK_THERMAL) += mtk_thermal.o +obj-y += mediatek/ obj-$(CONFIG_GENERIC_ADC_THERMAL) += thermal-generic-adc.o obj-$(CONFIG_UNIPHIER_THERMAL) += uniphier_thermal.o obj-$(CONFIG_AMLOGIC_THERMAL) += amlogic_thermal.o diff --git a/drivers/thermal/mediatek/Kconfig b/drivers/thermal/mediatek/Kconfig new file mode 100644 index 000000000000..592c849b9fed --- /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/Makefile new file mode 100644 index 000000000000..c2b9a166fbef --- /dev/null +++ b/drivers/thermal/mediatek/Makefile @@ -0,0 +1 @@ +obj-$(CONFIG_MTK_SOC_THERMAL) += mtxxxx_thermal.o diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mediatek/mtxxxx_thermal.c similarity index 99% rename from drivers/thermal/mtk_thermal.c rename to drivers/thermal/mediatek/mtxxxx_thermal.c index ede94eadddda..60924f8f98e9 100644 --- a/drivers/thermal/mtk_thermal.c +++ b/drivers/thermal/mediatek/mtxxxx_thermal.c @@ -23,7 +23,7 @@ #include #include -#include "thermal_hwmon.h" +#include "../thermal_hwmon.h" /* AUXADC Registers */ #define AUXADC_CON1_SET_V 0x008 From patchwork Thu Aug 4 13:09:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balsam CHIHI X-Patchwork-Id: 12936374 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 71880C19F2A for ; Thu, 4 Aug 2022 13:10:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ETAlUNaMGQpo/uPrl7ABLWcA/ucKMRK4Sq2xTm6LKJ0=; b=Rq6TbHbCtezQON9FU1hQAKVaB5 AHnvKrh7Ly5WbojnsVtVfbKi51ovHkMvL7gEithU8o/9zOhKipGMFhz4yxUJlC/+6xJ25p5bnE/XG InX5C2CECNsUTBNcDGSz6hEGjqtKsjNd5zYOqPdBVzVyxD6jSmckvuXFiG20qDNY49mP6nc80TxTf ryUcF7jlNwT5xnTHzZc/GWNmWU58U8/MKbWtjXDP7ILH4WX9QYEoYDQGWkK1b/4u3UFNm/16cCmUE O6QL7CPEzSXTmlfrauXQps+6hn1fwmN2vOS775xW2GMzBzdN8De7bRk8YB1fMkXu0i7WSSuznvDJh lXkd/+uw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJacR-006Arr-2F; Thu, 04 Aug 2022 13:10:31 +0000 Received: from mail-wr1-x435.google.com ([2a00:1450:4864:20::435]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJabx-006AXm-FB for linux-mediatek@lists.infradead.org; Thu, 04 Aug 2022 13:10:04 +0000 Received: by mail-wr1-x435.google.com with SMTP id bk11so15353405wrb.10 for ; Thu, 04 Aug 2022 06:10:00 -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=ETAlUNaMGQpo/uPrl7ABLWcA/ucKMRK4Sq2xTm6LKJ0=; b=N9mg1GGa3pwtI8qwXcnAzLD7CEsS9/tz7e5TGqSzK+TYejyMwE84o1o+htg5e0jfGa QBxFGjvIgNUvt/vOt6d4dG1yGNG746FMXZYKqBhUuq5PFkIFiggS94FEW1HWzmVSL8YN VKycWa1BpZmcTDDw4DTb41yyiuExfFx0brq5izSecgSnDkBwXDN4z3C96SkMOGS+Z9RS vV1BuNEXObvWZfnqJg5XFPrcLT4tqCeoZqZefNM2mu6diG5F6R3ejU/Tv95FZt0X2xbK eQyAN+SfZXUDilGmsLqOIHelMmqfzs8Be/E1VYoBKl+x4Sy1OeomZT+hVK27z58IHnsv PsvQ== 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=ETAlUNaMGQpo/uPrl7ABLWcA/ucKMRK4Sq2xTm6LKJ0=; b=ApxsCDNnIGACxuM32qVbQFoKkCqsw+Og4KuUvN+Rufd/kNSRp876+qk+f7+oBcNbO7 Yuo0+z6vndqnTTQCDt0V3fMk6riplCDSFCTS6IvUrasNVNvMWcIb20+cHBR+ajTxvY1x o9hyuQUZ0CrPsv+OProqLbXq6k6Di5hgYLZNReQ54kBhwZvyX14H4I9LoWQTf2/rRxbm /xe+RLL0qs0jWOeZHGw9SwUQ9Ba9sbc/tRZ9gSVQy1vhjBqI/xZoRUNn2/j9BawmLaIA dZ14vjXiH6tPx8H70vBo/QJjbzU5FfvM1RO3doYfLEK+F43frhB+7mXNuTkRUqb+s9wt NiOQ== X-Gm-Message-State: ACgBeo1QZRXVYQs41ZfYl0SayUwdydttc/K/IPlHoIKGRpqvCJUIWoU/ 7ssMaX0X20928zC9YPVF0Uvipg== X-Google-Smtp-Source: AA6agR4NM2DuUJ9ZgcrlN+3wkc0Rf579Msjd8f9h/Jqtrma62QpnqPtRFG6GD9EJr9FuCtRnPy1P/Q== X-Received: by 2002:a5d:6f1c:0:b0:21f:121e:1190 with SMTP id ay28-20020a5d6f1c000000b0021f121e1190mr1341352wrb.589.1659618599667; Thu, 04 Aug 2022 06:09:59 -0700 (PDT) Received: from Balsam-ThinkPad-T480.. (235.163.185.81.rev.sfr.net. [81.185.163.235]) by smtp.gmail.com with ESMTPSA id o15-20020adfcf0f000000b0021d6a520ce9sm1156817wrj.47.2022.08.04.06.09.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 06:09:59 -0700 (PDT) From: bchihi@baylibre.com To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amitk@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, mka@chromium.org, robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, james.lo@mediatek.com, fan.chen@mediatek.com, louis.yu@mediatek.com, rex-bc.chen@mediatek.com, abailon@baylibre.com Subject: [PATCH v8.1, 2/7] dt-bindings: thermal: Add binding document for LVTS thermal controllers Date: Thu, 4 Aug 2022 15:09:07 +0200 Message-Id: <20220804130912.676043-3-bchihi@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220804130912.676043-1-bchihi@baylibre.com> References: <20220804130912.676043-1-bchihi@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220804_061001_534163_D25B6E9B X-CRM114-Status: GOOD ( 11.67 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Alexandre Bailon This patch adds dt-binding documents for mt8192 and mt8195 thermal controllers. Signed-off-by: Alexandre Bailon Signed-off-by: Balsam CHIHI --- .../thermal/mediatek,lvts-thermal.yaml | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 Documentation/devicetree/bindings/thermal/mediatek,lvts-thermal.yaml diff --git a/Documentation/devicetree/bindings/thermal/mediatek,lvts-thermal.yaml b/Documentation/devicetree/bindings/thermal/mediatek,lvts-thermal.yaml new file mode 100644 index 000000000000..53c44a73f3a4 --- /dev/null +++ b/Documentation/devicetree/bindings/thermal/mediatek,lvts-thermal.yaml @@ -0,0 +1,77 @@ +# SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/thermal/mediatek,lvts-thermal.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: MediaTek SoC LVTS thermal controller + +maintainers: + - Yu-Chia Chang + - Ben Tseng + +properties: + compatible: + enum: + - mediatek,mt8192-lvts-ap + - mediatek,mt8192-lvts-mcu + - mediatek,mt8195-lvts-ap + - mediatek,mt8195-lvts-mcu + + "#thermal-sensor-cells": + const: 1 + + reg: + maxItems: 2 + + interrupts: + maxItems: 1 + + clocks: + maxItems: 1 + + resets: + items: + - description: SW reset HW AP/MCU domain to clean temporary data on HW initialization/resume. + + nvmem-cells: + items: + - description: LVTS calibration data 1 for thermal sensors + - description: LVTS calibration data 2 for thermal sensors + + nvmem-cell-names: + items: + - const: lvts_calib_data1 + - const: lvts_calib_data2 + +required: + - compatible + - '#thermal-sensor-cells' + - reg + - interrupts + - clocks + - resets + - nvmem-cells + - nvmem-cell-names + +additionalProperties: false + +examples: + - | + #include + #include + #include + #include + + lvtsmcu: thermal-sensor@11278000 { + compatible = "mediatek,mt8195-lvts-mcu"; + #thermal-sensor-cells = <1>; + reg = <0 0x11278000 0 0x400>; + interrupts = ; + clocks = <&infracfg_ao CLK_INFRA_AO_THERM>; + resets = <&infracfg_ao MT8195_INFRA_RST4_THERM_CTRL_MCU_SWRST>; + nvmem-cells = <&lvts_efuse_data1 &lvts_efuse_data2>; + nvmem-cell-names = "lvts_calib_data1", "lvts_calib_data2"; + }; + +... From patchwork Thu Aug 4 13:09:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balsam CHIHI X-Patchwork-Id: 12936375 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 8AD52C19F2A for ; Thu, 4 Aug 2022 13:11:17 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=ts9wGXUYExk6gtCsSPDiHLEprUWAxTPstjlSxz/66wI=; b=nAdSF7AK/FI2wiGBajY5NmCcxM UiUbbDrzsmdYYb3xHND8NRDnDMo9Xr8SpVwXABFLEy02TDLy9x833OJOrYnmRG3IC5y+s8mQhF8Pl FIrsCzml61fpQ9AGD39qN+3HsJJ/eHIWIKABn+Ga7s0BAnQgfxDQkWshFUlip+yPHkcX8gW3fPDO6 eSaICjf8pl1PfDDJCwciiseN2T81ce0vR53vNfinQ1kFCIEkI6z/u1m+xd8i0kWt7bHMNIn86vNPG JLIGAiPaaVQ5PMtrP2SDB93TPKDnWR+AWgc70Duc7aeyUCPKNtfA9n0D4HH3shpctFwkJKmyHtbBZ XcDCd9sA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJad3-006BFx-1K; Thu, 04 Aug 2022 13:11:09 +0000 Received: from mail-wr1-x431.google.com ([2a00:1450:4864:20::431]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJabz-006AZa-Hw for linux-mediatek@lists.infradead.org; Thu, 04 Aug 2022 13:10:07 +0000 Received: by mail-wr1-x431.google.com with SMTP id j1so16847739wrw.1 for ; Thu, 04 Aug 2022 06:10:02 -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=ts9wGXUYExk6gtCsSPDiHLEprUWAxTPstjlSxz/66wI=; b=bMwcYGHsBIEMrbYzlqomUHZufeEAWm8D1KStc+1SHQNZmazstd2ArhFBuu/ztF9QHj H3kz2IfvpwimKU818GmMAmRDWXueM8lHfGBtN229jA0npnntym3dU8IPoUYQ0OUaPDIv mVVe0jJJcyN69Bwh+Sttsael1VYjQz04wd2lsfayRx+JLK5hbMcYlpE0DR6yI4xN3OZj Pkc/MRvr3Xcyj31H3scdaxgzPpEUZUMrQcmKrt8OOD8kIgwsmD8seSjCea6FPTQxdZBs d3YquQOuxz/SyCOgKlC8WNv+6YltIlnRVg/qmXLQZTYXGBbwVS0K64jNV8ggb5OJzw0G elAQ== 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=ts9wGXUYExk6gtCsSPDiHLEprUWAxTPstjlSxz/66wI=; b=aFKFMulH5ZWS86f6KpmuRR7H6qOQwbTDMRy/aDbB8aA4QyxVbLL8XyoImHpIUDQWeN PazKThQN6MgITqiZxXZ3x760/upuDb8Evu5J0Z6Tt/ZbImHuWRP3CnvIHZ0flUhwUZ2i Rj5Pe25zvq2C2ysf5f1DE9Evyz9DSd4BK7+OM2B5nh4vD00CuYKAxk44WwF+LQkgUNDq 3YvjNQKbqBkDEvuUVj9in4Za3SLvph9lMC1dvdPOBhHIAZUvOrcypYYB1q5qxrRdF6g5 zzmIlnDFZlX4LfGw8vH74/v4tx54UK5VlGJhUfbOTGm5D6khrHMKQ1Ast194jmaFyeFY BPUA== X-Gm-Message-State: ACgBeo3NiK1/QQPCIl+4JOtMUU4DQeABBrkDMsSIWO3OObg0LOe8y9bk rAyKx5KQkTm8J4qiScObGtC6hw== X-Google-Smtp-Source: AA6agR4hBf9nrcJv9jI+ROSaWAYZZoaanOEqB2H5H2YmKYmGpgitvUOLLcF93mI+x3J0h5O+UNCjhQ== X-Received: by 2002:adf:d090:0:b0:220:7188:ac8b with SMTP id y16-20020adfd090000000b002207188ac8bmr1413517wrh.389.1659618601454; Thu, 04 Aug 2022 06:10:01 -0700 (PDT) Received: from Balsam-ThinkPad-T480.. (235.163.185.81.rev.sfr.net. [81.185.163.235]) by smtp.gmail.com with ESMTPSA id o15-20020adfcf0f000000b0021d6a520ce9sm1156817wrj.47.2022.08.04.06.09.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 06:10:00 -0700 (PDT) From: bchihi@baylibre.com To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amitk@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, mka@chromium.org, robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, james.lo@mediatek.com, fan.chen@mediatek.com, louis.yu@mediatek.com, rex-bc.chen@mediatek.com, abailon@baylibre.com Subject: [PATCH v8.1, 3/7] arm64: dts: mt8192: Add thermal zone Date: Thu, 4 Aug 2022 15:09:08 +0200 Message-Id: <20220804130912.676043-4-bchihi@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220804130912.676043-1-bchihi@baylibre.com> References: <20220804130912.676043-1-bchihi@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220804_061003_625888_2FDCEE33 X-CRM114-Status: GOOD ( 10.83 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Balsam CHIHI This adds the thermal zone for the mt8192. Signed-off-by: Balsam CHIHI --- arch/arm64/boot/dts/mediatek/mt8192.dtsi | 113 ++++++++++++++++++++++- 1 file changed, 112 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/mediatek/mt8192.dtsi b/arch/arm64/boot/dts/mediatek/mt8192.dtsi index cbae5a5ee4a0..3320b5c14ee3 100644 --- a/arch/arm64/boot/dts/mediatek/mt8192.dtsi +++ b/arch/arm64/boot/dts/mediatek/mt8192.dtsi @@ -1,6 +1,6 @@ // SPDX-License-Identifier: (GPL-2.0 OR MIT) /* - * Copyright (C) 2020 MediaTek Inc. + * Copyright (C) 2022 MediaTek Inc. * Author: Seiya Wang */ @@ -12,6 +12,7 @@ #include #include #include +#include / { compatible = "mediatek,mt8192"; @@ -599,6 +600,28 @@ spi0: spi@1100a000 { status = "disabled"; }; + lvts_ap: thermal-sensor@1100b000 { + compatible = "mediatek,mt8192-lvts-ap"; + #thermal-sensor-cells = <1>; + reg = <0 0x1100b000 0 0x1000>; + interrupts = ; + clocks = <&infracfg CLK_INFRA_THERM>; + resets = <&infracfg MT8192_INFRA_RST0_THERM_CTRL_SWRST>; + nvmem-cells = <&lvts_e_data1>; + nvmem-cell-names = "lvts_calib_data1"; + }; + + lvts_mcu: thermal-sensor@11278000 { + compatible = "mediatek,mt8192-lvts-mcu"; + #thermal-sensor-cells = <1>; + reg = <0 0x11278000 0 0x1000>; + interrupts = ; + clocks = <&infracfg CLK_INFRA_THERM>; + resets = <&infracfg MT8192_INFRA_RST4_THERM_CTRL_MCU_SWRST>; + nvmem-cells = <&lvts_e_data1>; + nvmem-cell-names = "lvts_calib_data1"; + }; + spi1: spi@11010000 { compatible = "mediatek,mt8192-spi", "mediatek,mt6765-spi"; @@ -1457,4 +1480,92 @@ larb2: larb@1f002000 { power-domains = <&spm MT8192_POWER_DOMAIN_MDP>; }; }; + + thermal_zones: thermal-zones { + cpu-big1-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 0>; + }; + cpu-big2-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 1>; + }; + cpu-big3-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 2>; + }; + cpu-big4-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 3>; + }; + cpu-little1-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 4>; + }; + cpu-little2-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 5>; + }; + cpu-little3-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 6>; + }; + cpu-little4-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 7>; + }; + vpu1-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 0>; + }; + vpu2-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 1>; + }; + gpu1-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 2>; + }; + gpu2-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 3>; + }; + vdec-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 4>; + }; + img-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 5>; + }; + infra-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 6>; + }; + cam1-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 7>; + }; + cam2-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 8>; + }; + }; }; From patchwork Thu Aug 4 13:09:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balsam CHIHI X-Patchwork-Id: 12936390 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 030A1C19F2D for ; Thu, 4 Aug 2022 13:11:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=RTUSIjIW6j59eiU8cZedNsdzrm+5uRCGFx6bcWXiwvI=; b=s3ScqnWPzOgGSxKCsQb2VoS1ID nXHePaxqPW9qEhrdP1N2ftZOiayJIkcnilTpsCKqfCcXJt+TU1AhTDPUrAd4aW89zBISttIxNW3Du Lcfx3tL/E+iSirk1DVBnf+sX13Hbxha7NzfLT8+V4SgOgRP9AP2B6TNvVGFY2MBsnQzDnSHP/ZU/5 sU05TmaH1o4IHWh4BrUI+bHU944qmvtjbHCQ19lgCakYAYEYRjlctd38RoPMyEMj0JiuVCyi9H9EC mE+p+FEojiZwrqoXbhq6DWBqoZKdeZ9xvwEwR3US+bX6ZbcSXbrQuA+H3wro6vWvrKAVaYRBhsXRS e5ooYzwA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJadh-006Bk2-W3; Thu, 04 Aug 2022 13:11:50 +0000 Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJac1-006AbU-4z for linux-mediatek@lists.infradead.org; Thu, 04 Aug 2022 13:10:11 +0000 Received: by mail-wm1-x332.google.com with SMTP id j4-20020a05600c1c0400b003a4f287418bso2319019wms.5 for ; Thu, 04 Aug 2022 06:10:04 -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=RTUSIjIW6j59eiU8cZedNsdzrm+5uRCGFx6bcWXiwvI=; b=p1SWDNLS+RbHTq8rbmAZLHsgjccbo+EPnho8XhZafHLu/Z+WsLSlQC9YGQqa0B8dP/ DL1dc/yNQBVm/RJq7boCjjwYJKzVRDJbTS3Nem2jO+25pVtBxyV3mRyaui4kamV4CcEV /bmv514ITcqspDNfr+RMsQ9Ij+ejCh+uT2Xr1JDldULforBsjDF+rF7eqnpkAFCTfvmF 5cEhzvr3OF/TVqxx1SceadPHbJO5w46Oj3SmC8ca6357wlJmUc/h/unGUy3n2Eim/tcG 4+Rgd5fxJhJnAyi1lENMeFr/odohUkrsDTn1gysg2CfkpNH0a1seOpor8Bg4PL4qtx1D ELKg== 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=RTUSIjIW6j59eiU8cZedNsdzrm+5uRCGFx6bcWXiwvI=; b=L3RqPWMDhuRTfvqw3U/Oe3F0wjsz9+2Lxv3Uzu8YZlZlYzV5NVna0XVgsLG3Boaymz GjA3iYK3/oejsrNkjBe6Yo/GVgizJC0oncg+lxZhxREpaSssEZvzF90OfxTJBe3IUHDL YifNoWbL4O4lh0N13fuVHzE8IgwZb70iX2l8jeoUrcXLgdi0mOKj/MA6H9VmVGsSZ12s SXbuWWqZTMUPUNfd8sEN6Rs0hHXEi/mgvkCNA8NfZJBX9acbusM6hlMmyqDoPDlAAucE oTr6ktxUENLd9WWzNx312g4VrjvJcuYI+U7gG9JAlEVFkYQtkwD0X/qVzwFZ3AIGo8BU D+9w== X-Gm-Message-State: ACgBeo3SB8gBN0CcbWdZU+rxaOu6pQ9QrKdkeOumNrk+FxfzWQhe7VD8 /9IUyzNQNm4sFfbrqZoufr/A5w== X-Google-Smtp-Source: AA6agR6ma/4LM4KuakQMbRWXXqGDVL4hd4F0vCeAEf7F/HIpwnOi7ByPUIGISa9yk3PIl0af6RRRJA== X-Received: by 2002:a1c:f217:0:b0:3a4:bfd4:21b4 with SMTP id s23-20020a1cf217000000b003a4bfd421b4mr1409029wmc.96.1659618603508; Thu, 04 Aug 2022 06:10:03 -0700 (PDT) Received: from Balsam-ThinkPad-T480.. (235.163.185.81.rev.sfr.net. [81.185.163.235]) by smtp.gmail.com with ESMTPSA id o15-20020adfcf0f000000b0021d6a520ce9sm1156817wrj.47.2022.08.04.06.10.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 06:10:03 -0700 (PDT) From: bchihi@baylibre.com To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amitk@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, mka@chromium.org, robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, james.lo@mediatek.com, fan.chen@mediatek.com, louis.yu@mediatek.com, rex-bc.chen@mediatek.com, abailon@baylibre.com Subject: [PATCH v8.1, 4/7] thermal: mediatek: Add LVTS driver for mt8192 thermal zones Date: Thu, 4 Aug 2022 15:09:09 +0200 Message-Id: <20220804130912.676043-5-bchihi@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220804130912.676043-1-bchihi@baylibre.com> References: <20220804130912.676043-1-bchihi@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220804_061005_496629_A422B943 X-CRM114-Status: GOOD ( 28.46 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Michael Kao Add a LVTS V4 (Low Voltage Thermal Sensor) driver to report junction temperatures in MediaTek SoC mt8192 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 Signed-off-by: Balsam CHIHI --- drivers/thermal/mediatek/Kconfig | 24 + drivers/thermal/mediatek/Makefile | 2 + drivers/thermal/mediatek/lvts_thermal.c | 855 ++++++++++++++++++++++++ drivers/thermal/mediatek/lvts_thermal.h | 376 +++++++++++ drivers/thermal/mediatek/lvts_v4.c | 241 +++++++ 5 files changed, 1498 insertions(+) create mode 100644 drivers/thermal/mediatek/lvts_thermal.c create mode 100644 drivers/thermal/mediatek/lvts_thermal.h create mode 100644 drivers/thermal/mediatek/lvts_v4.c diff --git a/drivers/thermal/mediatek/Kconfig b/drivers/thermal/mediatek/Kconfig index 592c849b9fed..afef43a0e7ca 100644 --- a/drivers/thermal/mediatek/Kconfig +++ b/drivers/thermal/mediatek/Kconfig @@ -20,4 +20,28 @@ config MTK_SOC_THERMAL configures thermal controllers to collect temperature via AUXADC interface. +config MTK_LVTS_THERMAL + tristate "LVTS (Low Voltage Thermal 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 + LVTS (Low Voltage Thermal Sensor) thermal controllers to + collect temperatures via ASIF (Analog Serial Interface). + +if MTK_LVTS_THERMAL + +config MTK_LVTS_V4 + tristate "LVTS V4 Thermal 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 LVTS V4. + +endif + endif diff --git a/drivers/thermal/mediatek/Makefile b/drivers/thermal/mediatek/Makefile index c2b9a166fbef..80a14be07053 100644 --- a/drivers/thermal/mediatek/Makefile +++ b/drivers/thermal/mediatek/Makefile @@ -1 +1,3 @@ obj-$(CONFIG_MTK_SOC_THERMAL) += mtxxxx_thermal.o +obj-$(CONFIG_MTK_LVTS_THERMAL) += lvts_thermal.o +obj-$(CONFIG_MTK_LVTS_V4) += lvts_v4.o diff --git a/drivers/thermal/mediatek/lvts_thermal.c b/drivers/thermal/mediatek/lvts_thermal.c new file mode 100644 index 000000000000..77297a91b9fa --- /dev/null +++ b/drivers/thermal/mediatek/lvts_thermal.c @@ -0,0 +1,855 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022 MediaTek Inc. + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include "lvts_thermal.h" + +static int lvts_raw_to_temp(struct lvts_formula_coeff *co, unsigned int msr_raw) +{ + /* This function returns degree mC */ + + int temp; + + temp = (co->a * ((unsigned long long)msr_raw)) >> 14; + temp = temp + co->golden_temp * 500 + co->b; + + return temp; +} + +static unsigned int lvts_temp_to_raw(struct lvts_formula_coeff *co, int temp) +{ + unsigned int msr_raw; + + msr_raw = 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 = (struct soc_temp_tz *)data; + struct lvts_data *lvts_data = lvts_tz->lvts_data; + struct device *dev = lvts_data->dev; + unsigned int msr_raw; + + msr_raw = readl(lvts_data->reg[lvts_tz->id]) & MRS_RAW_MASK; + if (msr_raw == 0) { + /* Prevents a false critical temperature trap */ + *temperature = 0; + dev_dbg(dev, "LVTS not yet ready\n"); + + } else + *temperature = lvts_raw_to_temp(&lvts_data->coeff, msr_raw); + + return 0; +} + +static const struct thermal_zone_of_device_ops soc_temp_lvts_ops = { + .get_temp = soc_temp_lvts_read_temp, +}; + +static void lvts_write_device(struct lvts_data *lvts_data, unsigned int data, int tc_id) +{ + void __iomem *base = GET_BASE_ADDR(lvts_data, tc_id); + + writel(DEVICE_WRITE | data, LVTS_CONFIG_0 + base); + usleep_range(20, 30); +} + +static unsigned int lvts_read_device(struct lvts_data *lvts_data, unsigned int reg_idx, int tc_id) +{ + void __iomem *base = GET_BASE_ADDR(lvts_data, tc_id); + struct device *dev = lvts_data->dev; + unsigned int data; + int ret; + + writel(READ_DEVICE_REG(reg_idx), LVTS_CONFIG_0 + base); + usleep_range(20, 30); + ret = readl_poll_timeout(LVTS_CONFIG_0 + base, data, !(data & DEVICE_ACCESS_STARTUS), 2, 200); + if (ret) + dev_err(dev, "LVTS_TC_%d DEVICE_ACCESS_START is not ready\n", tc_id); + + data = readl(LVTSRDATA0_0 + base); + + return data; +} + +static const char * const lvts_error_table[] = { + "Idle", + "Write transaction", + "Waiting for read after write", + "Disable continue fetching on device", + "Read transaction", + "Set device special register for voltage threshold", + "Set TSMCU number for fetch" +}; + +static void wait_all_tc_sensing_point_idle(struct lvts_data *lvts_data) +{ + void __iomem *base; + struct device *dev = lvts_data->dev; + unsigned int error_code, is_error; + int i, cnt, ret; + + for (cnt = 0; cnt < 2; cnt++) { + is_error = 0; + + for (i = 0; i < lvts_data->num_tc; i++) { + base = GET_BASE_ADDR(lvts_data, i); + ret = readl_poll_timeout(LVTSMSRCTL1_0 + base, error_code, + !(error_code & ALL_TC_SENSING_POINT_STATUS), 2, 200); + error_code = ((error_code & TC_SENSING_POINT_10) >> 8) + + ((error_code & TC_SENSING_POINT_7) >> 6) + (error_code & TC_SENSING_POINT_0); + if (ret) + dev_err(dev, "LVTS_TC_%d Error Code : %s\n", i, lvts_error_table[error_code]); + + if (error_code != 0) + is_error = 1; + } + + if (is_error == 0) + break; + } +} + +static void lvts_reset(struct lvts_data *lvts_data) +{ + if (lvts_data->reset) + reset_control_assert(lvts_data->reset); + + if (lvts_data->reset) + reset_control_deassert(lvts_data->reset); +} + +static void device_identification(struct lvts_data *lvts_data) +{ + void __iomem *base; + struct device *dev = lvts_data->dev; + unsigned int i, data; + + for (i = 0; i < lvts_data->num_tc; i++) { + base = GET_BASE_ADDR(lvts_data, i); + writel(ENABLE_LVTS_CTRL_CLK, LVTSCLKEN_0 + base); + lvts_write_device(lvts_data, RESET_ALL_DEVICES, i); + writel(READ_BACK_DEVICE_ID, LVTS_CONFIG_0 + base); + usleep_range(20, 30); + /* Check LVTS device ID */ + data = (readl(LVTS_ID_0 + base) & DEVICE_REG_DATA); + if (data != (lvts_data->tc->dev_id + i)) + dev_err(dev, "LVTS_TC_%d, Device ID should be 0x%x, but 0x%x\n", + i, (lvts_data->tc->dev_id + i), data); + } +} + +static void disable_all_sensing_points(struct lvts_data *lvts_data) +{ + void __iomem *base; + unsigned int i; + + for (i = 0; i < lvts_data->num_tc; i++) { + base = GET_BASE_ADDR(lvts_data, i); + writel(DISABLE_SENSING_POINT, LVTSMONCTL0_0 + base); + } +} + +static void enable_all_sensing_points(struct lvts_data *lvts_data) +{ + void __iomem *base; + struct device *dev = lvts_data->dev; + const struct lvts_tc_settings *tc = lvts_data->tc; + unsigned int i, num; + + for (i = 0; i < lvts_data->num_tc; i++) { + base = GET_BASE_ADDR(lvts_data, i); + num = tc[i].num_sensor; + if (num > ALL_SENSING_POINTS) { + dev_err(dev, "LVTS_TC_%d, illegal number of sensors: %d\n", 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) +{ + void __iomem *base = GET_BASE_ADDR(lvts_data, tc_id); + struct device *dev = lvts_data->dev; + const struct lvts_tc_settings *tc = lvts_data->tc; + unsigned int lvts_mon_ctl_1, lvts_mon_ctl_2; + + lvts_mon_ctl_1 = ((tc[tc_id].tc_speed->group_interval_delay << 20) & GROUP_INTERVAL_DELAY_MASK) | + (tc[tc_id].tc_speed->period_unit & PERIOD_UNIT_MASK); + lvts_mon_ctl_2 = ((tc[tc_id].tc_speed->filter_interval_delay << 16) & FILTER_INTERVAL_DELAY_MASK) | + (tc[tc_id].tc_speed->sensor_interval_delay & SENSOR_INTERVAL_DELAY_MASK); + /* + * 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 sensors + * Group interval delay is a delay between different rounds. + * For example: + * If Period unit = C, filter delay = 1, sensor delay = 2, group delay = 1, + * and two sensors, TS1 and TS2, are in a LVTS thermal controller + * and then + * Period unit = C * 1/26M * 256 = 12 * 38.46ns * 256 = 118.149us + * Filter interval delay = 1 * Period unit = 118.149us + * Sensor interval delay = 2 * Period unit = 236.298us + * Group interval delay = 1 * Period unit = 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_dbg(dev, "lvts_tc_%d, LVTSMONCTL1_0= 0x%x, LVTSMONCTL2_0= 0x%x\n", + tc_id, readl(LVTSMONCTL1_0 + base), readl(LVTSMONCTL2_0 + base)); +} + +static void set_hw_filter(struct lvts_data *lvts_data, int tc_id) +{ + void __iomem *base = GET_BASE_ADDR(lvts_data, tc_id); + struct device *dev = lvts_data->dev; + const struct lvts_tc_settings *tc = lvts_data->tc; + unsigned int option = 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 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 samples + * 101: Get 18 samples, drop max and min, then average the rest of 16 samples + */ + option = (option << 9) | (option << 6) | (option << 3) | option; + writel(option, LVTSMSRCTL0_0 + base); + dev_dbg(dev, "lvts_tc_%d, LVTSMSRCTL0_0= 0x%x\n", tc_id, readl(LVTSMSRCTL0_0 + base)); +} + +static int get_dominator_index(struct lvts_data *lvts_data, int tc_id) +{ + struct device *dev = lvts_data->dev; + const struct lvts_tc_settings *tc = lvts_data->tc; + int d_index; + + if (tc[tc_id].dominator_sensing_point == ALL_SENSING_POINTS) { + d_index = ALL_SENSING_POINTS; + } else if (tc[tc_id].dominator_sensing_point < tc[tc_id].num_sensor) { + d_index = tc[tc_id].dominator_sensing_point; + } else { + dev_err(dev, "LVTS_TC_%d: dominator sensing point = %d. \ + It should be smaller than num_sensor %d\n", + tc_id, tc[tc_id].dominator_sensing_point, tc[tc_id].num_sensor); + dev_err(dev, "Using the sensing point 0 as the dominated sensor\n"); + d_index = SENSING_POINT0; + } + + return d_index; +} + +static void disable_hw_reboot_interrupt(struct lvts_data *lvts_data, int tc_id) +{ + void __iomem *base = GET_BASE_ADDR(lvts_data, tc_id); + unsigned int temp; + + /* + * 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 be turned 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 0x3FFF to LVTS and make it always report extremely low temperature. + * LVTS always adds the offset 0x3FFF to MSR_RAW. + * When MSR_RAW is larger, SW will convert lower temperature. + */ + temp = readl(LVTSPROTCTL_0 + base); + writel(temp | 0x3FFF, LVTSPROTCTL_0 + base); + + /* Disable the interrupt of AP SW */ + temp = 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) +{ + void __iomem *base = GET_BASE_ADDR(lvts_data, tc_id); + unsigned int temp; + + /* Enable the interrupt of AP SW */ + temp = readl(LVTSMONINT_0 + base); + writel(temp | STAGE3_INT_EN, LVTSMONINT_0 + base); + + /* Clear the offset */ + temp = 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) +{ + void __iomem *base = GET_BASE_ADDR(lvts_data, tc_id); + struct device *dev = lvts_data->dev; + unsigned int msr_raw, temp, config, d_index; + + d_index = get_dominator_index(lvts_data, tc_id); + + dev_dbg(dev, "lvts_tc_%d: dominator sensing point = %d\n", tc_id, d_index); + + disable_hw_reboot_interrupt(lvts_data, tc_id); + temp = readl(LVTSPROTCTL_0 + base); + if (d_index == ALL_SENSING_POINTS) { + /* Maximum of 4 sensing points */ + config = (0x1 << 16); + writel(config | temp, LVTSPROTCTL_0 + base); + + } else { + /* Select protection sensor */ + config = ((d_index << 2) + 0x2) << 16; + writel(config | temp, LVTSPROTCTL_0 + base); + } + + msr_raw = 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) +{ + const struct lvts_tc_settings *tc = lvts_data->tc; + int i, trip_point; + + for (i = 0; i < lvts_data->num_tc; i++) { + trip_point = tc[i].hw_reboot_trip_point; + + if (tc[i].num_sensor == 0) + continue; + + if (trip_point == THERMAL_TEMP_INVALID) + continue; + + set_tc_hw_reboot_threshold(lvts_data, trip_point, i); + } +} + +static int lvts_init(struct lvts_data *lvts_data) +{ + struct platform_ops *ops = &lvts_data->ops; + struct device *dev = lvts_data->dev; + int ret; + + ret = clk_prepare_enable(lvts_data->clk); + if (ret) { + dev_err(dev, "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 (HAS_FEATURE(lvts_data, FEATURE_DEVICE_AUTO_RCK) && (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 = lvts_data->dev; + struct lvts_sensor_cal_data *cal_data = &lvts_data->cal_data; + struct platform_ops *ops = &lvts_data->ops; + int i, offset; + char buffer[512]; + + cal_data->count_r = 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 = 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 && !cal_data->use_fake_efuse) + ops->efuse_to_cal_data(lvts_data); + if (cal_data->golden_temp == 0 || cal_data->golden_temp > GOLDEN_TEMP_MAX) + cal_data->use_fake_efuse = 1; + + if (cal_data->use_fake_efuse) { + /* It means all efuse data are equal to 0 */ + dev_err(dev, "This sample is not calibrated, fake !!\n"); + cal_data->golden_temp = cal_data->default_golden_temp; + for (i = 0; i < lvts_data->num_sensor; i++) { + cal_data->count_r[i] = cal_data->default_count_r; + cal_data->count_rc[i] = cal_data->default_count_rc; + } + } + + lvts_data->coeff.golden_temp = cal_data->golden_temp; + dev_dbg(dev, "golden_temp = %d\n", cal_data->golden_temp); + offset = snprintf(buffer, sizeof(buffer), "[lvts_cal] num:g_count:g_count_rc "); + for (i = 0; i < lvts_data->num_sensor; i++) + offset += snprintf(buffer + offset, sizeof(buffer) - offset, "%d:%d:%d ", + i, cal_data->count_r[i], cal_data->count_rc[i]); + + return 0; +} + +static int get_calibration_data(struct lvts_data *lvts_data) +{ + struct device *dev = lvts_data->dev; + char cell_name[32]; + struct nvmem_cell *cell; + u32 *buf; + size_t len; + int i, j, index = 0, ret; + + lvts_data->efuse = devm_kcalloc(dev, lvts_data->num_efuse_addr, + sizeof(*lvts_data->efuse), GFP_KERNEL); + if (!lvts_data->efuse) + return -ENOMEM; + + for (i = 0; i < lvts_data->num_efuse_block; i++) { + snprintf(cell_name, sizeof(cell_name), "lvts_calib_data%d", i + 1); + cell = nvmem_cell_get(dev, cell_name); + if (IS_ERR(cell)) { + dev_err(dev, "Failed to get nvmem cell %s\n", cell_name); + + return PTR_ERR(cell); + } + + buf = (u32 *)nvmem_cell_read(cell, &len); + nvmem_cell_put(cell); + if (IS_ERR(buf)) + return PTR_ERR(buf); + + for (j = 0; j < (len / sizeof(u32)); j++) { + if (index >= lvts_data->num_efuse_addr) { + dev_err(dev, "Array efuse is going to overflow"); + kfree(buf); + + return -EINVAL; + } + + lvts_data->efuse[index] = buf[j]; + index++; + } + + kfree(buf); + } + + ret = prepare_calibration_data(lvts_data); + + return ret; +} + +static int lvts_init_tc_regs(struct device *dev, struct lvts_data *lvts_data) +{ + void __iomem *base; + const struct lvts_tc_settings *tc = lvts_data->tc; + unsigned int i, j, s_index; + + lvts_data->reg = devm_kcalloc(dev, lvts_data->num_sensor, + sizeof(*lvts_data->reg), GFP_KERNEL); + if (!lvts_data->reg) + return -ENOMEM; + + for (i = 0; i < lvts_data->num_tc; i++) { + base = GET_BASE_ADDR(lvts_data, i); + for (j = 0; j < tc[i].num_sensor; j++) { + s_index = tc[i].sensor_map[j]; + lvts_data->reg[s_index] = 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 = lvts_data->dev; + struct resource *res; + int ret; + + lvts_data->clk = devm_clk_get(dev, NULL); + if (IS_ERR(lvts_data->clk)) + return PTR_ERR(lvts_data->clk); + + /* Get base address */ + res = platform_get_mem_or_io(pdev, 0); + if (!res) { + dev_err(dev, "No IO resource\n"); + + return -ENXIO; + } + + lvts_data->base = devm_ioremap_resource(dev, res); + if (IS_ERR(lvts_data->base)) { + dev_err(dev, "Failed to remap io\n"); + + return PTR_ERR(lvts_data->base); + } + + /* Get interrupt number */ + ret = platform_get_irq(pdev, 0); + if (ret < 0) { + dev_err(dev, "No irq resource\n"); + + return ret; + } + + lvts_data->irq_num = ret; + /* Get reset control */ + lvts_data->reset = devm_reset_control_get_by_index(dev, 0); + if (IS_ERR(lvts_data->reset)) { + dev_err(dev, "Failed to get reset control\n"); + + return PTR_ERR(lvts_data->reset); + } + + ret = lvts_init_tc_regs(dev, lvts_data); + if (ret) + return ret; + + ret = get_calibration_data(lvts_data); + if (ret) + return ret; + + return 0; +} + +static void lvts_device_close(struct lvts_data *lvts_data) +{ + void __iomem *base; + unsigned int i; + + for (i = 0; i < lvts_data->num_tc; i++) { + base = GET_BASE_ADDR(lvts_data, 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) +{ + void __iomem *base = GET_BASE_ADDR(lvts_data, tc_id); + const struct device *dev = lvts_data->dev; + unsigned int ret = readl(LVTSMONINTSTS_0 + base); + + /* Write back to clear interrupt status */ + writel(ret, LVTSMONINTSTS_0 + base); + dev_dbg(dev, "LVTS thermal controller %d, LVTSMONINTSTS=0x%08x\n", tc_id, ret); + if (ret & THERMAL_PROTECTION_STAGE_3) + dev_dbg(dev, "Thermal protection stage 3 interrupt triggered\n"); +} + +static irqreturn_t irq_handler(int irq, void *dev_id) +{ + void __iomem *base; + struct lvts_data *lvts_data = (struct lvts_data *)dev_id; + struct device *dev = lvts_data->dev; + const struct lvts_tc_settings *tc = lvts_data->tc; + unsigned int i, irq_bitmap; + + base = lvts_data->base; + irq_bitmap = readl(THERMINTST + base); + dev_dbg(dev, "THERMINTST = 0x%x\n", irq_bitmap); + for (i = 0; i < lvts_data->num_tc; i++) { + if (tc[i].irq_bit == 0) + tc_irq_handler(lvts_data, i); + } + + return IRQ_HANDLED; +} + +static int lvts_register_irq_handler(struct lvts_data *lvts_data) +{ + struct device *dev = lvts_data->dev; + int ret; + + ret = devm_request_irq(dev, lvts_data->irq_num, irq_handler, IRQF_TRIGGER_NONE, + "mtk_lvts", lvts_data); + if (ret) { + dev_err(dev, "Failed to register LVTS IRQ, ret %d, irq_num %d\n", + ret, lvts_data->irq_num); + lvts_close(lvts_data); + + return ret; + } + + return 0; +} + +static int lvts_register_thermal_zones(struct lvts_data *lvts_data) +{ + struct device *dev = lvts_data->dev; + struct thermal_zone_device *tzdev; + struct soc_temp_tz *lvts_tz; + int i, ret; + + for (i = 0; i < lvts_data->num_sensor; i++) { + lvts_tz = devm_kzalloc(dev, sizeof(*lvts_tz), GFP_KERNEL); + if (!lvts_tz) { + lvts_close(lvts_data); + + return -ENOMEM; + } + + lvts_tz->id = i; + lvts_tz->lvts_data = lvts_data; + tzdev = devm_thermal_zone_of_sensor_register(dev, lvts_tz->id, lvts_tz, &soc_temp_lvts_ops); + if (IS_ERR(tzdev)) { + if (lvts_tz->id != 0) + return 0; + + ret = PTR_ERR(tzdev); + dev_err(dev, "Failed to register lvts tz %d, ret = %d\n", lvts_tz->id, ret); + lvts_close(lvts_data); + + return ret; + } + } + + return 0; +} + +void lvts_device_enable_and_init(struct lvts_data *lvts_data) +{ + unsigned int i; + + for (i = 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 = 20; +} +EXPORT_SYMBOL_GPL(lvts_device_enable_and_init); + +void lvts_device_enable_auto_rck_v4(struct lvts_data *lvts_data) +{ + unsigned int i; + + for (i = 0; i < lvts_data->num_tc; i++) + lvts_write_device(lvts_data, SET_LVTS_AUTO_RCK_V4, i); +} +EXPORT_SYMBOL_GPL(lvts_device_enable_auto_rck_v4); + +int lvts_device_read_count_rc_n_v4(struct lvts_data *lvts_data) +{ + void __iomem *base; + struct device *dev = lvts_data->dev; + const struct lvts_tc_settings *tc = lvts_data->tc; + struct lvts_sensor_cal_data *cal_data = &lvts_data->cal_data; + unsigned int offset, s_index, data; + int ret, i, j; + char buffer[128]; + + cal_data->count_rc_now = 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 = 0; i < lvts_data->num_tc; i++) { + base = GET_BASE_ADDR(lvts_data, i); + for (j = 0; j < tc[i].num_sensor; j++) { + s_index = 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); + lvts_write_device(lvts_data, KICK_OFF_RCK_COUNTING_V4, i); + ret = readl_poll_timeout(LVTS_CONFIG_0 + base, data, + !(data & DEVICE_SENSING_STATUS), 2, 200); + if (ret) + dev_err(dev, "LVTS_TC_%d DEVICE_SENSING_STATUS didn't ready\n", i); + + data = lvts_read_device(lvts_data, 0x00, i); + cal_data->count_rc_now[s_index] = (data & COUNT_RC_NOW_MASK); + } + + /* 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); + } + + offset = snprintf(buffer, sizeof(buffer), "[COUNT_RC_NOW] "); + for (i = 0; i < lvts_data->num_sensor; i++) + offset += snprintf(buffer + offset, sizeof(buffer) - offset, "%d:%d ", i, + cal_data->count_rc_now[i]); + + return 0; +} +EXPORT_SYMBOL_GPL(lvts_device_read_count_rc_n_v4); + +void lvts_set_calibration_data_v4(struct lvts_data *lvts_data) +{ + void __iomem *base; + const struct lvts_tc_settings *tc = lvts_data->tc; + struct lvts_sensor_cal_data *cal_data = &lvts_data->cal_data; + unsigned int i, j, s_index; + u32 lvts_calib_data; + + for (i = 0; i < lvts_data->num_tc; i++) { + base = GET_BASE_ADDR(lvts_data, i); + for (j = 0; j < tc[i].num_sensor; j++) { + s_index = tc[i].sensor_map[j]; + if (HAS_FEATURE(lvts_data, FEATURE_DEVICE_AUTO_RCK)) + lvts_calib_data = cal_data->count_r[s_index]; + + else + lvts_calib_data = (((u32)cal_data->count_rc_now[s_index]) * + cal_data->count_r[s_index]) >> 14; + + writel(lvts_calib_data, LVTSEDATA00_0 + base + 0x4 * j); + } + } +} +EXPORT_SYMBOL_GPL(lvts_set_calibration_data_v4); + +void lvts_init_controller_v4(struct lvts_data *lvts_data) +{ + void __iomem *base; + struct device *dev = lvts_data->dev; + unsigned int i; + + for (i = 0; i < lvts_data->num_tc; i++) { + base = GET_BASE_ADDR(lvts_data, 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_dbg(dev, "lvts_tc_%d: read all %d sensors in %d us, one in %d us\n", + i, GET_TC_SENSOR_NUM(lvts_data, i), GROUP_LATENCY_US(i), SENSOR_LATENCY_US(i)); + } +} +EXPORT_SYMBOL_GPL(lvts_init_controller_v4); + +int lvts_probe(struct platform_device *pdev) +{ + struct device *dev = &pdev->dev; + struct lvts_data *lvts_data; + int ret; + + lvts_data = (struct lvts_data *)of_device_get_match_data(dev); + if (!lvts_data) { + dev_err(dev, "Failed to get lvts platform data\n"); + + return -ENODATA; + } + + lvts_data->dev = &pdev->dev; + ret = of_update_lvts_data(lvts_data, pdev); + if (ret) + return ret; + + platform_set_drvdata(pdev, lvts_data); + ret = lvts_init(lvts_data); + if (ret) + return ret; + + ret = lvts_register_irq_handler(lvts_data); + if (ret) + return ret; + + ret = lvts_register_thermal_zones(lvts_data); + if (ret) + return ret; + + return 0; +} + +int lvts_remove(struct platform_device *pdev) +{ + struct lvts_data *lvts_data; + + lvts_data = (struct lvts_data *)platform_get_drvdata(pdev); + lvts_close(lvts_data); + + return 0; +} + +int lvts_suspend(struct platform_device *pdev, pm_message_t state) +{ + struct lvts_data *lvts_data; + + lvts_data = (struct lvts_data *)platform_get_drvdata(pdev); + lvts_close(lvts_data); + + return 0; +} + +int lvts_resume(struct platform_device *pdev) +{ + struct lvts_data *lvts_data; + int ret; + + lvts_data = (struct lvts_data *)platform_get_drvdata(pdev); + ret = lvts_init(lvts_data); + if (ret) + return ret; + + return 0; +} + +MODULE_AUTHOR("Yu-Chia Chang "); +MODULE_AUTHOR("Michael Kao "); +MODULE_DESCRIPTION("MediaTek LVTS Thermal Driver"); +MODULE_LICENSE("GPL"); diff --git a/drivers/thermal/mediatek/lvts_thermal.h b/drivers/thermal/mediatek/lvts_thermal.h new file mode 100644 index 000000000000..9095f9cd232b --- /dev/null +++ b/drivers/thermal/mediatek/lvts_thermal.h @@ -0,0 +1,376 @@ +/* SPDX-License-Identifier: GPL-2.0-only */ +/* + * Copyright (c) 2022 MediaTek Inc. + */ + +#ifndef __MTK_SOC_TEMP_LVTS_H__ +#define __MTK_SOC_TEMP_LVTS_H__ + +#define PERIOD_UNIT 12 +#define GROUP_INTERVAL_DELAY 1 +#define FILTER_INTERVAL_DELAY 1 +#define SENSOR_INTERVAL_DELAY 1 + +#define HW_REBOOT_TRIP_POINT 117000 + +#define FEATURE_DEVICE_AUTO_RCK BIT(0) +#define NUM_EFUSE_ADDR 22 +#define NUM_EFUSE_BLOCK_MT8192 1 +#define DEFAULT_GOLDEN_TEMP 50 +#define DEFAULT_CUONT_R 35000 +#define DEFAULT_CUONT_RC 2750 +#define COEFF_A -250460 +#define COEFF_B 250460 + +#define CLOCK_26MHZ_CYCLE_NS 38 +#define BUS_ACCESS_US 2 +#define GOLDEN_TEMP_MAX 62 + +#define TC_SENSING_POINT_0 BIT(0) +#define TC_SENSING_POINT_7 BIT(7) +#define TC_SENSING_POINT_10 BIT(10) +#define ALL_TC_SENSING_POINT_STATUS (BIT(10) | BIT(7) | BIT(0)) +#define COUNT_RC_NOW_MASK GENMASK(23, 0) +#define PERIOD_UNIT_MASK GENMASK(9, 0) +#define GROUP_INTERVAL_DELAY_MASK GENMASK(29, 20) +#define FILTER_INTERVAL_DELAY_MASK GENMASK(25, 16) +#define SENSOR_INTERVAL_DELAY_MASK GENMASK(9, 0) + +/* LVTS device register */ +#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 + +/* LVTS controller register */ +#define LVTSMONCTL0_0 0x000 +#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 SCK_ONLY BIT(31) +#define BROADCAST_ID_UPDATE BIT(26) +#define DEVICE_SENSING_STATUS BIT(25) +#define DEVICE_ACCESS_STARTUS BIT(24) +#define READ_32BIT_ACCESS BIT(17) +#define WRITE_ACCESS BIT(16) +#define LVTS_SINGLE_SENSE BIT(9) +#define FEATURE_CK26M_ACTIVE BIT(1) +#define DEVICE_REG_DATA GENMASK(7, 0) + +#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 + +/* LVTS register mask */ +#define THERMAL_COLD_INTERRUPT_0 BIT(0) +#define THERMAL_HOT_INTERRUPT_0 BIT(1) +#define THERMAL_LOW_OFFSET_INTERRUPT_0 BIT(2) +#define THERMAL_HIGH_OFFSET_INTERRUPT_0 BIT(3) +#define THERMAL_HOT2NORMAL_INTERRUPT_0 BIT(4) +#define THERMAL_COLD_INTERRUPT_1 BIT(5) +#define THERMAL_HOT_INTERRUPT_1 BIT(6) +#define THERMAL_LOW_OFFSET_INTERRUPT_1 BIT(7) +#define THERMAL_HIGH_OFFSET_INTERRUPT_1 BIT(8) +#define THERMAL_HOT2NORMAL_INTERRUPT_1 BIT(9) +#define THERMAL_COLD_INTERRUPT_2 BIT(10) +#define THERMAL_HOT_INTERRUPT_2 BIT(11) +#define THERMAL_LOW_OFFSET_INTERRUPT_2 BIT(12) +#define THERMAL_HIGH_OFFSET_INTERRUPT_2 BIT(13) +#define THERMAL_HOT2NORMAL_INTERRUPT_2 BIT(14) +#define THERMAL_AHB_TIMEOUT_INTERRUPT BIT(15) +#define THERMAL_DEVICE_TIMEOUT_INTERRUPT BIT(15) +#define THERMAL_IMMEDIATE_INTERRUPT_0 BIT(16) +#define THERMAL_IMMEDIATE_INTERRUPT_1 BIT(17) +#define THERMAL_IMMEDIATE_INTERRUPT_2 BIT(18) +#define THERMAL_FILTER_INTERRUPT_0 BIT(19) +#define THERMAL_FILTER_INTERRUPT_1 BIT(20) +#define THERMAL_FILTER_INTERRUPT_2 BIT(21) +#define THERMAL_COLD_INTERRUPT_3 BIT(22) +#define THERMAL_HOT_INTERRUPT_3 BIT(23) +#define THERMAL_LOW_OFFSET_INTERRUPT_3 BIT(24) +#define THERMAL_HIGH_OFFSET_INTERRUPT_3 BIT(25) +#define THERMAL_HOT2NORMAL_INTERRUPT_3 BIT(26) +#define THERMAL_IMMEDIATE_INTERRUPT_3 BIT(27) +#define THERMAL_FILTER_INTERRUPT_3 BIT(28) +#define THERMAL_PROTECTION_STAGE_1 BIT(29) +#define THERMAL_PROTECTION_STAGE_2 BIT(30) +#define THERMAL_PROTECTION_STAGE_3 BIT(31) + +#define CFG_REGISTER(reg, value) (reg << 8 | value) + +#define STOP_COUNTING_V4 CFG_REGISTER(RG_TSFM_CTRL_0, 0x00) +#define SET_RG_TSFM_LPDLY_V4 CFG_REGISTER(RG_TSFM_CTRL_4, 0xA6) +#define SET_COUNTING_WINDOW_20US1_V4 CFG_REGISTER(RG_TSFM_CTRL_2, 0x00) +#define SET_COUNTING_WINDOW_20US2_V4 CFG_REGISTER(RG_TSFM_CTRL_1, 0x20) +#define TSV2F_CHOP_CKSEL_AND_TSV2F_EN_V4 CFG_REGISTER(RG_TSV2F_CTRL_2, 0x84) +#define TSBG_DEM_CKSEL_X_TSBG_CHOP_EN_V4 CFG_REGISTER(RG_TSV2F_CTRL_4, 0x7C) +#define SET_TS_RSV_V4 CFG_REGISTER(RG_TSV2F_CTRL_1, 0x8D) +#define SET_TS_EN_V4 CFG_REGISTER(RG_TSV2F_CTRL_0, 0xF4) +#define TOGGLE_RG_TSV2F_VCO_RST1_V4 CFG_REGISTER(RG_TSV2F_CTRL_0, 0xFC) +#define TOGGLE_RG_TSV2F_VCO_RST2_V4 CFG_REGISTER(RG_TSV2F_CTRL_0, 0xF4) + +#define SET_LVTS_AUTO_RCK_V4 CFG_REGISTER(RG_TSV2F_CTRL_6, 0x01) +#define SELECT_SENSOR_RCK_V4(id) CFG_REGISTER(RG_TSV2F_CTRL_5, (id)) +#define SET_DEVICE_SINGLE_MODE_V4 CFG_REGISTER(RG_TSFM_CTRL_3, 0x78) +#define KICK_OFF_RCK_COUNTING_V4 CFG_REGISTER(RG_TSFM_CTRL_0, 0x02) +#define SET_SENSOR_NO_RCK_V4 CFG_REGISTER(RG_TSV2F_CTRL_5, 0x10) +#define SET_DEVICE_LOW_POWER_SINGLE_MODE_V4 CFG_REGISTER(RG_TSFM_CTRL_3, 0xB8) + +#define HAS_FEATURE(lvts_data, feature) (lvts_data->feature_bitmap & (feature)) +#define GET_BASE_ADDR(lvts_data, tc_id) (lvts_data->base + lvts_data->tc[tc_id].addr_offset) +#define GET_CAL_DATA_BITMASK(index, lvts_data, h, l) (((index) < lvts_data->num_efuse_addr) ? \ + ((lvts_data->efuse[(index)] & GENMASK(h, l)) >> l) : 0) + +#define GET_TC_SENSOR_NUM(lvts_data, 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 == LVTS_FILTER_16_OF_18) ? \ + 18 : ((lvts_data->tc[tc_id].hw_filter == 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(lvts_data, tc_id) * \ + SENSOR_LATENCY_US(tc_id) + (GET_TC_SENSOR_NUM(lvts_data, tc_id) - 1) * \ + SENSOR_INT_US(tc_id) + GROUP_INT_US(tc_id)) + +#define CK26M_ACTIVE(lvts_data) (((lvts_data->feature_bitmap & FEATURE_CK26M_ACTIVE) ? 1 : 0) << 30) +#define DEVICE_ACCESS (SCK_ONLY | DEVICE_ACCESS_STARTUS | READ_32BIT_ACCESS) +#define DEVICE_READ (CK26M_ACTIVE(lvts_data) | DEVICE_ACCESS) +#define DEVICE_WRITE (CK26M_ACTIVE(lvts_data) | DEVICE_ACCESS | WRITE_ACCESS) +#define RESET_ALL_DEVICES (DEVICE_WRITE | RG_TSFM_RST << 8 | 0xFF) +#define READ_DEVICE_REG(reg_id) (DEVICE_READ | (reg_id) << 8 | 0x00) +#define READ_BACK_DEVICE_ID (CK26M_ACTIVE(lvts_data) | DEVICE_ACCESS | BROADCAST_ID_UPDATE | \ + RG_DID_LVTS << 8) + +/* + * 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 samples + * 101: Get 18 samples, drop max and min, then average the rest of 16 samples + */ +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 +}; + +struct lvts_data; + +/** + * struct lvts_speed_settings - A structure to hold the data related to polling rate + * @period_unit: Period unit is a base for all interval delays + * @group_interval_delay: Delay between different rounds + * @filter_interval_delay: Delay between two samples of the same sensor + * @sensor_interval_delay: Delay between two samples of differnet sensors + * + * Calculation is achieved with the following equations: + * For the period unit: (period_us * 1000) / (256 * clock_26mhz_cycle_ns) + * For the interval delays: delay / period_us + */ +struct lvts_speed_settings { + unsigned int period_unit; + unsigned int group_interval_delay; + unsigned int filter_interval_delay; + unsigned int sensor_interval_delay; +}; + +struct lvts_tc_settings { + unsigned int dev_id; + unsigned int addr_offset; + unsigned int num_sensor; + unsigned int sensor_map[ALL_SENSING_POINTS]; /* In sensor ID */ + struct lvts_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 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 samples + * 101: Get 18 samples, drop max and min, then average the rest of 16 samples + */ + 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 lvts_formula_coeff { + int a; + int b; + unsigned int golden_temp; +}; + +struct lvts_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 lvts_data { + struct device *dev; + struct clk *clk; + void __iomem *base; /* LVTS base addresses */ + unsigned int irq_num; /* LVTS interrupt numbers */ + struct reset_control *reset; + int num_tc; /* Number of LVTS thermal controllers */ + const struct lvts_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 lvts_sensor_cal_data cal_data; + struct lvts_formula_coeff coeff; +}; + +struct soc_temp_tz { + unsigned int id; + struct lvts_data *lvts_data; +}; + +extern void lvts_device_enable_and_init(struct lvts_data *lvts_data); +extern void lvts_device_enable_auto_rck_v4(struct lvts_data *lvts_data); +extern int lvts_device_read_count_rc_n_v4(struct lvts_data *lvts_data); +extern void lvts_set_calibration_data_v4(struct lvts_data *lvts_data); +extern void lvts_init_controller_v4(struct lvts_data *lvts_data); + +extern int lvts_probe(struct platform_device *pdev); +extern int lvts_remove(struct platform_device *pdev); +extern int lvts_suspend(struct platform_device *pdev, pm_message_t state); +extern int lvts_resume(struct platform_device *pdev); + +#endif /* __MTK_SOC_TEMP_LVTS_H__ */ diff --git a/drivers/thermal/mediatek/lvts_v4.c b/drivers/thermal/mediatek/lvts_v4.c new file mode 100644 index 000000000000..6477d386c9e1 --- /dev/null +++ b/drivers/thermal/mediatek/lvts_v4.c @@ -0,0 +1,241 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * Copyright (c) 2022 MediaTek Inc. + */ + +#include +#include +#include "lvts_thermal.h" + +enum mt8192_lvts_mcu_sensor_enum { + MT8192_TS1_0, + MT8192_TS1_1, + MT8192_TS2_0, + MT8192_TS2_1, + MT8192_TS3_0, + MT8192_TS3_1, + MT8192_TS3_2, + MT8192_TS3_3, + MT8192_NUM_TS_MCU +}; + +enum mt8192_lvts_ap_sensor_enum { + MT8192_TS4_0, + MT8192_TS4_1, + MT8192_TS5_0, + MT8192_TS5_1, + MT8192_TS6_0, + MT8192_TS6_1, + MT8192_TS7_0, + MT8192_TS7_1, + MT8192_TS7_2, + MT8192_NUM_TS_AP +}; + +static void mt8192_mcu_efuse_to_cal_data(struct lvts_data *lvts_data) +{ + const unsigned int mt8192_ts[] = { MT8192_TS2_0, MT8192_TS3_0 }; + struct lvts_sensor_cal_data *cal_data = &lvts_data->cal_data; + unsigned int i, j; + + cal_data->golden_temp = GET_CAL_DATA_BITMASK(0, lvts_data, 31, 24); + + for (i = 0; i < MT8192_NUM_TS_MCU; i++) + cal_data->count_r[i] = GET_CAL_DATA_BITMASK(i + 1, lvts_data, 23, 0); + + cal_data->count_rc[MT8192_TS1_0] = GET_CAL_DATA_BITMASK(21, lvts_data, 23, 0); + + for (i = 0; i < (ARRAY_SIZE(mt8192_ts)); i++) { + for (j = 1; j <= 18; j++) { + cal_data->count_rc[mt8192_ts[i]] = (GET_CAL_DATA_BITMASK(j, lvts_data, 31, 24) << 16) + + (GET_CAL_DATA_BITMASK(j, lvts_data, 31, 24) << 8) + + GET_CAL_DATA_BITMASK(j, lvts_data, 31, 24); + } + } +} + +static void mt8192_ap_efuse_to_cal_data(struct lvts_data *lvts_data) +{ + const unsigned int mt8192_ts[] = { MT8192_TS4_0, MT8192_TS5_0, MT8192_TS6_0, MT8192_TS7_0 }; + struct lvts_sensor_cal_data *cal_data = &lvts_data->cal_data; + unsigned int i, j; + + cal_data->golden_temp = GET_CAL_DATA_BITMASK(0, lvts_data, 31, 24); + + for (i = 0; i < MT8192_NUM_TS_AP; i++) + cal_data->count_r[i] = GET_CAL_DATA_BITMASK(i + 1, lvts_data, 23, 0); + + for (i = 0; i < (ARRAY_SIZE(mt8192_ts)); i++) { + for (j = 1; j <= 18; j++) { + cal_data->count_rc[mt8192_ts[i]] = (GET_CAL_DATA_BITMASK(j, lvts_data, 31, 24) << 16) + + (GET_CAL_DATA_BITMASK(j, lvts_data, 31, 24) << 8) + + GET_CAL_DATA_BITMASK(j, lvts_data, 31, 24); + } + } +} + +static struct lvts_speed_settings tc_speed_mt8192 = { + .period_unit = PERIOD_UNIT, + .group_interval_delay = GROUP_INTERVAL_DELAY, + .filter_interval_delay = FILTER_INTERVAL_DELAY, + .sensor_interval_delay = SENSOR_INTERVAL_DELAY, +}; + +static const struct lvts_tc_settings mt8192_tc_mcu_settings[] = { + [0] = { + .dev_id = 0x81, + .addr_offset = 0x0, + .num_sensor = 2, + .sensor_map = { MT8192_TS1_0, MT8192_TS1_1 }, + .tc_speed = &tc_speed_mt8192, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT1, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(3), + }, + [1] = { + .dev_id = 0x82, + .addr_offset = 0x100, + .num_sensor = 2, + .sensor_map = { MT8192_TS2_0, MT8192_TS2_1 }, + .tc_speed = &tc_speed_mt8192, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT0, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(4), + }, + [2] = { + .dev_id = 0x83, + .addr_offset = 0x200, + .num_sensor = 4, + .sensor_map = { MT8192_TS3_0, MT8192_TS3_1, MT8192_TS3_2, MT8192_TS3_3 }, + .tc_speed = &tc_speed_mt8192, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT0, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(5), + } +}; + +static const struct lvts_tc_settings mt8192_tc_ap_settings[] = { + [0] = { + .dev_id = 0x84, + .addr_offset = 0x0, + .num_sensor = 2, + .sensor_map = { MT8192_TS4_0, MT8192_TS4_1 }, + .tc_speed = &tc_speed_mt8192, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT0, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(3), + }, + [1] = { + .dev_id = 0x85, + .addr_offset = 0x100, + .num_sensor = 2, + .sensor_map = { MT8192_TS5_0, MT8192_TS5_1 }, + .tc_speed = &tc_speed_mt8192, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT1, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(4), + }, + [2] = { + .dev_id = 0x86, + .addr_offset = 0x200, + .num_sensor = 2, + .sensor_map = { MT8192_TS6_0, MT8192_TS6_1 }, + .tc_speed = &tc_speed_mt8192, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT1, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(5), + }, + [3] = { + .dev_id = 0x87, + .addr_offset = 0x300, + .num_sensor = 3, + .sensor_map = { MT8192_TS7_0, MT8192_TS7_1, MT8192_TS7_2 }, + .tc_speed = &tc_speed_mt8192, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT2, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(6), + } +}; + +static const struct lvts_data mt8192_lvts_mcu_data = { + .num_tc = (ARRAY_SIZE(mt8192_tc_mcu_settings)), + .tc = mt8192_tc_mcu_settings, + .num_sensor = MT8192_NUM_TS_MCU, + .ops = { + .efuse_to_cal_data = mt8192_mcu_efuse_to_cal_data, + .device_enable_and_init = lvts_device_enable_and_init, + .device_enable_auto_rck = lvts_device_enable_auto_rck_v4, + .device_read_count_rc_n = lvts_device_read_count_rc_n_v4, + .set_cal_data = lvts_set_calibration_data_v4, + .init_controller = lvts_init_controller_v4, + }, + .feature_bitmap = FEATURE_DEVICE_AUTO_RCK, + .num_efuse_addr = NUM_EFUSE_ADDR, + .num_efuse_block = NUM_EFUSE_BLOCK_MT8192, + .cal_data = { + .default_golden_temp = DEFAULT_GOLDEN_TEMP, + .default_count_r = DEFAULT_CUONT_R, + .default_count_rc = DEFAULT_CUONT_RC, + }, + .coeff = { + .a = COEFF_A, + .b = COEFF_B, + }, +}; + +static const struct lvts_data mt8192_lvts_ap_data = { + .num_tc = (ARRAY_SIZE(mt8192_tc_ap_settings)), + .tc = mt8192_tc_ap_settings, + .num_sensor = MT8192_NUM_TS_AP, + .ops = { + .efuse_to_cal_data = mt8192_ap_efuse_to_cal_data, + .device_enable_and_init = lvts_device_enable_and_init, + .device_enable_auto_rck = lvts_device_enable_auto_rck_v4, + .device_read_count_rc_n = lvts_device_read_count_rc_n_v4, + .set_cal_data = lvts_set_calibration_data_v4, + .init_controller = lvts_init_controller_v4, + }, + .feature_bitmap = FEATURE_DEVICE_AUTO_RCK, + .num_efuse_addr = NUM_EFUSE_ADDR, + .num_efuse_block = NUM_EFUSE_BLOCK_MT8192, + .cal_data = { + .default_golden_temp = DEFAULT_GOLDEN_TEMP, + .default_count_r = DEFAULT_CUONT_R, + .default_count_rc = DEFAULT_CUONT_RC, + }, + .coeff = { + .a = COEFF_A, + .b = COEFF_B, + }, +}; + +static const struct of_device_id lvts_of_match[] = { + { .compatible = "mediatek,mt8192-lvts-mcu", .data = &mt8192_lvts_mcu_data, }, + { .compatible = "mediatek,mt8192-lvts-ap", .data = &mt8192_lvts_ap_data, }, + {}, +}; +MODULE_DEVICE_TABLE(of, lvts_of_match); + +static struct platform_driver soc_temp_lvts = { + .probe = lvts_probe, + .remove = lvts_remove, + .suspend = lvts_suspend, + .resume = lvts_resume, + .driver = { + .name = "mtk-lvts-v4", + .of_match_table = lvts_of_match, + }, +}; +module_platform_driver(soc_temp_lvts); + +MODULE_AUTHOR("Yu-Chia Chang "); +MODULE_AUTHOR("Michael Kao "); +MODULE_DESCRIPTION("MediaTek LVTS V4 Thermal Driver"); +MODULE_LICENSE("GPL"); From patchwork Thu Aug 4 13:09:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balsam CHIHI X-Patchwork-Id: 12936376 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 67E7EC19F2D for ; Thu, 4 Aug 2022 13:11:18 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=WNYml0pJZwTGwtJKLLK7VkX/NLD3rdkLagQmwO0aon0=; b=x5raxNShuPSQnb7xNT0eC5oO7C Ezl/dMyyE5JAtyp+4PuBwy7fKy5bZqOb8kbJ7CDBP3bBbfPkbBsH8eTudJZCSvsV23fpVVG7owkHt T2dZ0Y9R/GOlZVSpDnHIl1f7riqS7wyE3pNDxIllrmwueNiLRp1Zfhc1oChsToiey8IStBUAUismL KND4e9f9wSZi2zGhhtuiMeR7HJv1hvqWfEj3M+mP93PflkKISikC9p1buch+UpzP/feENgluAy8pw OtPAH/XS+LXs041eo2QwbiaPCFCknAYBNby834JLrUUeXEyZSrrENNImT+Kb8yiutlvQ8A3xwiPuT 6LVab8xg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJad5-006BH6-3I; Thu, 04 Aug 2022 13:11:11 +0000 Received: from mail-wr1-x433.google.com ([2a00:1450:4864:20::433]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJac1-006AXk-UK for linux-mediatek@lists.infradead.org; Thu, 04 Aug 2022 13:10:07 +0000 Received: by mail-wr1-x433.google.com with SMTP id j15so17129459wrr.2 for ; Thu, 04 Aug 2022 06:10:05 -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=WNYml0pJZwTGwtJKLLK7VkX/NLD3rdkLagQmwO0aon0=; b=ZIF8770Ihf88JsnID2E4OKI0p+G1KqCThV1B61k6ZnS8dsLIOYFWyCkB7bDfs7agFr d0wl7p9RVQBrWZNoxLdVC2hu2PCA9l0ZYwEDNXpC8RlnTcJ87X/Owzk6sQ4MCvd9WyWR 1MuXn+M5hdTC9n6LvkQ33zzNgRbfwSqFW4ZK4nqYWDhkeg1VCLHk6odj7c4kLWKxG2eg 4qdrFDyQbKjanHaWKGYQ5WuWEGMR+Pan0cQPTsTT2Q4dRqMxCxyWtWZ/sPAaEegUKBOA CCcutBRhbY4YNhFVm9AwHvlxP0QBOKRffr9nlfwiomPmmuSXw1iMyW6s4PsoDtUihjbP O6jg== 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=WNYml0pJZwTGwtJKLLK7VkX/NLD3rdkLagQmwO0aon0=; b=lAgbzEToQE6N4eZSEagM0XxGlzRMMNk9EezZqfDuG55IOtWatXSn+Ht3/cw/77LqDt VxOTSlMlZotfsr6r89qxm1c5xBHQL4BcMSUqYUPdZbPI6aA5QgLd2ViGF/wT5xlOErwM RJdM6+KOYhycL+m4NWrcBpeoWsJnnC8T8sqvPLg62XlHzKQ+HGguFouSgIm6jCG/35LU l1Vo3z9QZEDZEQcCbANuVx4/mkAALP2Ps2UHQsnbpP/MeG0jNEWx7jjOAlMUH+4+qz56 S9878QuHQUyLHuw76fg4RZB2rruESs3rYFmHn2MZlFAT7MNrlLalzX+m9GJGZjTTqNd4 tPIg== X-Gm-Message-State: ACgBeo2AtaELC6KRv0hmTIQe+4uviRKQqqPX9oD+77KMdFvCYpGFh2vs ur84dW0zG0JMhFTEKYkNAcw7eQ== X-Google-Smtp-Source: AA6agR4i2eds1JM8hnk2a0haj7V4iukZavQOGw33veGLMXvkiAhhA/wBiCQmQspA8M6Bxt5N1Bt3zQ== X-Received: by 2002:adf:ef8b:0:b0:220:8235:124 with SMTP id d11-20020adfef8b000000b0022082350124mr1378639wro.628.1659618605481; Thu, 04 Aug 2022 06:10:05 -0700 (PDT) Received: from Balsam-ThinkPad-T480.. (235.163.185.81.rev.sfr.net. [81.185.163.235]) by smtp.gmail.com with ESMTPSA id o15-20020adfcf0f000000b0021d6a520ce9sm1156817wrj.47.2022.08.04.06.10.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 06:10:05 -0700 (PDT) From: bchihi@baylibre.com To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amitk@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, mka@chromium.org, robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, james.lo@mediatek.com, fan.chen@mediatek.com, louis.yu@mediatek.com, rex-bc.chen@mediatek.com, abailon@baylibre.com Subject: [PATCH v8.1, 5/7] arm64: dts: mt8195: Add efuse node to mt8195 Date: Thu, 4 Aug 2022 15:09:10 +0200 Message-Id: <20220804130912.676043-6-bchihi@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220804130912.676043-1-bchihi@baylibre.com> References: <20220804130912.676043-1-bchihi@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220804_061006_004548_DCDEF0D4 X-CRM114-Status: GOOD ( 10.56 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Alexandre Bailon This adds the efuse node. This will be required by the thermal driver to get the calibration data. Signed-off-by: Alexandre Bailon Signed-off-by: Balsam CHIHI --- arch/arm64/boot/dts/mediatek/mt8195.dtsi | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/arch/arm64/boot/dts/mediatek/mt8195.dtsi b/arch/arm64/boot/dts/mediatek/mt8195.dtsi index 73a0e2103b83..cbd0401968a2 100644 --- a/arch/arm64/boot/dts/mediatek/mt8195.dtsi +++ b/arch/arm64/boot/dts/mediatek/mt8195.dtsi @@ -1,6 +1,6 @@ // SPDX-License-Identifier: (GPL-2.0 OR MIT) /* - * Copyright (c) 2021 MediaTek Inc. + * Copyright (c) 2022 MediaTek Inc. * Author: Seiya Wang */ @@ -733,6 +733,18 @@ u2_intr_p3: usb2-intr-p3@189,2 { reg = <0x189 0x2>; bits = <7 5>; }; + + lvts_efuse_data1: lvts1-calib@1bc { + reg = <0x1bc 0x14>; + }; + + lvts_efuse_data2: lvts2-calib@1d0 { + reg = <0x1d0 0x38>; + }; + + svs_calibration: calib@580 { + reg = <0x580 0x64>; + }; }; u3phy2: t-phy@11c40000 { From patchwork Thu Aug 4 13:09:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balsam CHIHI X-Patchwork-Id: 12936392 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 27415C19F2D for ; Thu, 4 Aug 2022 13:12:25 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=nxQpFa1KVHgBC+y7kPg5BLU20sJM1ezbCwHBaU9ajtw=; b=ecKFTioGKrVDvXHPcYcoE/KwnQ eNOB9GvCxQFd1xvuWoHb3pAav4p9AGSye4B6/K2QL43JE0PB+lZd5SLpbbzE6pTmtVTO3mJmXW7HW v0Uq6smQxcguIDHQX/BZBA+B6DBGRxYq2D2W6b+4s3U3v5aZlaMFiyqqMf+H5kicvuTLUQ+nRd7PQ Aatowrm4eMkEKvWxlN7C1YMWj4ACm2jchsoXHTCPxvHFzNa85mcb20moHpy7Ba+O+WSR63VDJK0XH +bjirDupcmUSPXzmhnQzK6lhxuEgzLkc6wHPoD9grntoFpvRSNdCdid2/Etn909odf+PWn1apeF6/ POX1wdqg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJae8-006C2M-Ph; Thu, 04 Aug 2022 13:12:16 +0000 Received: from mail-wm1-x329.google.com ([2a00:1450:4864:20::329]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJac4-006Ae9-Nr for linux-mediatek@lists.infradead.org; Thu, 04 Aug 2022 13:10:15 +0000 Received: by mail-wm1-x329.google.com with SMTP id j4-20020a05600c1c0400b003a4f287418bso2319082wms.5 for ; Thu, 04 Aug 2022 06:10:08 -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=nxQpFa1KVHgBC+y7kPg5BLU20sJM1ezbCwHBaU9ajtw=; b=OmS/UkX0R637Z4VOJjpcKnP3ZDUAMHkDGbSIg/Aw2kDIDwqY2jkjmSErujW6MF16kI Z26rAKBKkCCrFgXiKHN5qW63UzSl7/IymfTimFdGViikviaxZ5EJ9PMMfZA5LjKYFv8K FMX5JT1q0KuWRiPStZOL1LSG/s9QAcGpif5DlyRn1KP+ABPO2/LnrA+xTlbkcEC2aNlq JSfTg49e1qxzJt9KP50OsUJ/hYRk//CCB1zt3F4ZYm8vOyetiDUM5IjphPb53TSvCP5V mU2tmROZpKoz8jkRzJ99d80GxGXHR6MyTMyXTQoQtM8eqEmZcMslhBSc9X7ErlhNOio6 o8dg== 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=nxQpFa1KVHgBC+y7kPg5BLU20sJM1ezbCwHBaU9ajtw=; b=S/f0SfYYW4n2f1uy8JPnz9jDB/n2PUZefmN251pnajHobSqt0m41SOgN6NlUnqU9W0 xT3qMXvTuw+ThtrmKOg5ACEtVMVf+NlbdgaOyjfk4ZqXDRqyFy0DaP4TIUriPE8x5M7m NjjECYOo93pywKAGwQihJcG7oqE83VfYrTzG2kxBTUhYNhNc8XOwstS0DYn3ZU/lSZKw DdBm+XYHWP2XpzYVXD0pAoVzGgdoTevEawiuDIMbN3U4QgM06fTuJbf2nRvKC4xpUygh Umv2f+qqxRhfYCg47cM13I/eBj2flPcT5YvyYQkRSU1RFobpQtA+LqUgdLuUVEIlpmcm KWew== X-Gm-Message-State: ACgBeo3v6oaAbJx2Uggj1XPA34Pjn/D+QisBByg9XJqBaTfyeP/QY8dw 2hqBgW7/1d4mWadjAM3gydFUlg== X-Google-Smtp-Source: AA6agR56YaWcFKth3loWOPC2qQQk2cH3Ku2XADJ0DMwX+fzZCwDmAQChaI3g7lAVv/mFv9ObqjloyA== X-Received: by 2002:a05:600c:34d6:b0:3a3:31cc:e150 with SMTP id d22-20020a05600c34d600b003a331cce150mr6198544wmq.94.1659618607450; Thu, 04 Aug 2022 06:10:07 -0700 (PDT) Received: from Balsam-ThinkPad-T480.. (235.163.185.81.rev.sfr.net. [81.185.163.235]) by smtp.gmail.com with ESMTPSA id o15-20020adfcf0f000000b0021d6a520ce9sm1156817wrj.47.2022.08.04.06.10.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 06:10:06 -0700 (PDT) From: bchihi@baylibre.com To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amitk@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, mka@chromium.org, robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, james.lo@mediatek.com, fan.chen@mediatek.com, louis.yu@mediatek.com, rex-bc.chen@mediatek.com, abailon@baylibre.com Subject: [PATCH v8.1, 6/7] arm64: dts: mt8195: Add thermal zone Date: Thu, 4 Aug 2022 15:09:11 +0200 Message-Id: <20220804130912.676043-7-bchihi@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220804130912.676043-1-bchihi@baylibre.com> References: <20220804130912.676043-1-bchihi@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220804_061008_812996_6C833AB3 X-CRM114-Status: UNSURE ( 9.54 ) X-CRM114-Notice: Please train this message. X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org 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 Signed-off-by: Balsam CHIHI --- arch/arm64/boot/dts/mediatek/mt8195.dtsi | 111 +++++++++++++++++++++++ 1 file changed, 111 insertions(+) diff --git a/arch/arm64/boot/dts/mediatek/mt8195.dtsi b/arch/arm64/boot/dts/mediatek/mt8195.dtsi index cbd0401968a2..5890e688eebe 100644 --- a/arch/arm64/boot/dts/mediatek/mt8195.dtsi +++ b/arch/arm64/boot/dts/mediatek/mt8195.dtsi @@ -10,6 +10,7 @@ #include #include #include +#include / { compatible = "mediatek,mt8195"; @@ -452,6 +453,28 @@ spi0: spi@1100a000 { status = "disabled"; }; + lvts_ap: thermal-sensor@1100b000 { + compatible = "mediatek,mt8195-lvts-ap"; + #thermal-sensor-cells = <1>; + reg = <0 0x1100b000 0 0x1000>; + interrupts = ; + clocks = <&infracfg_ao CLK_INFRA_AO_THERM>; + resets = <&infracfg_ao MT8195_INFRA_RST0_THERM_CTRL_SWRST>; + nvmem-cells = <&lvts_efuse_data1 &lvts_efuse_data2>; + nvmem-cell-names = "lvts_calib_data1", "lvts_calib_data2"; + }; + + lvts_mcu: thermal-sensor@11278000 { + compatible = "mediatek,mt8195-lvts-mcu"; + #thermal-sensor-cells = <1>; + reg = <0 0x11278000 0 0x1000>; + interrupts = ; + clocks = <&infracfg_ao CLK_INFRA_AO_THERM>; + resets = <&infracfg_ao MT8195_INFRA_RST4_THERM_CTRL_MCU_SWRST>; + nvmem-cells = <&lvts_efuse_data1 &lvts_efuse_data2>; + nvmem-cell-names = "lvts_calib_data1", "lvts_calib_data2"; + }; + spi1: spi@11010000 { compatible = "mediatek,mt8195-spi", "mediatek,mt6765-spi"; @@ -1106,4 +1129,92 @@ vencsys_core1: clock-controller@1b000000 { #clock-cells = <1>; }; }; + + thermal_zones: thermal-zones { + cpu-big1-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 0>; + }; + cpu-big2-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 1>; + }; + cpu-big3-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 2>; + }; + cpu-big4-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 3>; + }; + cpu-little1-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 4>; + }; + cpu-little2-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 5>; + }; + cpu-little3-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 6>; + }; + cpu-little4-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_mcu 7>; + }; + vpu1-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 0>; + }; + vpu2-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 1>; + }; + gpu1-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 2>; + }; + gpu2-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 3>; + }; + vdec-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 4>; + }; + img-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 5>; + }; + infra-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 6>; + }; + cam1-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 7>; + }; + cam2-thermal { + polling-delay = <0>; + polling-delay-passive = <0>; + thermal-sensors = <&lvts_ap 8>; + }; + }; }; From patchwork Thu Aug 4 13:09:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Balsam CHIHI X-Patchwork-Id: 12936391 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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 66428C19F2A for ; Thu, 4 Aug 2022 13:12:24 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:List-Subscribe:List-Help :List-Post:List-Archive:List-Unsubscribe:List-Id:Content-Transfer-Encoding: MIME-Version:References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=cla0lM4BldOpdb6hEqlLWVngdnoWs3axmUG8txIxp54=; b=wACTzcE/OB8fL6/rzvgRtfKSmZ 4WCoUVxvxbhE1y5qdcGu8CF0ghB0oqVchznZVgfmx/GhTkibqcCYO6wn4PpodjsEvf2WPvaZW2doh nvn0m1GD4WDFxSKTZSoenGDgN+fV95LpHAkK7spHn98YtHzIQOu7J37v17Eva/WfB8CFKsYzkQYsf IBPMNLsWPEBIkq8f58dCEPS8Hl/gqflNvymvr0Ow0UxcYKkXJgT27s/Oe90ViSrrEjXgJb3I+CRMq ljJI+5RrsDtkVUsF+x1/52jnus1/yY1ms5s5ez+EJ9dn3fPXOUiM1jnCRocyapg7kTYg876MGPcCI KlFpRlxw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJae7-006C1e-QQ; Thu, 04 Aug 2022 13:12:15 +0000 Received: from mail-wm1-x32c.google.com ([2a00:1450:4864:20::32c]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1oJac6-006Afr-Iz for linux-mediatek@lists.infradead.org; Thu, 04 Aug 2022 13:10:14 +0000 Received: by mail-wm1-x32c.google.com with SMTP id v131-20020a1cac89000000b003a4bb3f786bso2480547wme.0 for ; Thu, 04 Aug 2022 06:10:10 -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=cla0lM4BldOpdb6hEqlLWVngdnoWs3axmUG8txIxp54=; b=IJrM87wbpGCvXj70KwixdInKdcktY/525oInwlXZaqH3/HWmLnQHPLGgV+IzGKCQLD qaD0iwZSqgD09TxvOOWc3+rvefb0CTTt6K0PGyuhVFHolhiaIFpR00ot+3GsmOjrlElz V2o1Pi8oxEDLoiCoDc5z31p+P2foC+McHOht/KSu3FHsuV/idbm47AWTqHW0Tf/zJi7m t+yBUQfVe7YlI/5q6UsvrzgV9shJKZ/GA0R+dfw3mnhCDlNDHA2wnb1x7tP5w6N+IRDQ Yc0gXiSxBA24lnN4Pt9ygruZrDJMZ0gxwD0zvBg9PvZ96yZxfA7nDCEWh8EownBGPOIk Lq9g== 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=cla0lM4BldOpdb6hEqlLWVngdnoWs3axmUG8txIxp54=; b=lj/gBUk6+S1VxW05xY/JCtQJNhn8aP6AEjkdfEZJzr4ctQBeUzw1NnfqZZR5/mTHq3 E6abNGDLWo20JwRLcwXGSueh9iaEACZz/DvsQkmubMbyGqRUF7mHe2jpUErmlSHQzfno w5nnC7S9s3JEfN1aMYBR5sARTXxbg8lVKawcolW6kSeR4eCggKweKkccGEw+FDxBYXdE wysQVm5/mBug694vRSxw0+jNcB060Kj5/C//q4n/YjfkTodRqRXAHwbtQYWUGaNxxoLw nFM0Vdt33d8Z46zt59EFJE0soFr20SHO/uQI8jgt91nnzoCaPOzpQkzHFb2hfAL1MxyZ uQpg== X-Gm-Message-State: ACgBeo3k4s9VktQ9XRquVkvHi9xL2zl38JsXI0oU19asVktuulIUc/Xm Kho9CvNs7nmDBZ7ExmOCuvrqag== X-Google-Smtp-Source: AA6agR4FHom/Hb5zs4LT+11P8Qnc2UjkasWQfOka/HpKPxrvCMFaQXG6iQpiiTxD44HRyTYVlSeb9Q== X-Received: by 2002:a05:600c:3556:b0:3a3:2a9c:f26 with SMTP id i22-20020a05600c355600b003a32a9c0f26mr6193299wmq.58.1659618609259; Thu, 04 Aug 2022 06:10:09 -0700 (PDT) Received: from Balsam-ThinkPad-T480.. (235.163.185.81.rev.sfr.net. [81.185.163.235]) by smtp.gmail.com with ESMTPSA id o15-20020adfcf0f000000b0021d6a520ce9sm1156817wrj.47.2022.08.04.06.10.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 04 Aug 2022 06:10:08 -0700 (PDT) From: bchihi@baylibre.com To: rafael@kernel.org, rui.zhang@intel.com, daniel.lezcano@linaro.org, amitk@kernel.org Cc: linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, khilman@baylibre.com, mka@chromium.org, robh+dt@kernel.org, krzk+dt@kernel.org, matthias.bgg@gmail.com, p.zabel@pengutronix.de, devicetree@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, james.lo@mediatek.com, fan.chen@mediatek.com, louis.yu@mediatek.com, rex-bc.chen@mediatek.com, abailon@baylibre.com Subject: [PATCH v8.1, 7/7] thermal: mediatek: Add thermal zone settings for mt8195 Date: Thu, 4 Aug 2022 15:09:12 +0200 Message-Id: <20220804130912.676043-8-bchihi@baylibre.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220804130912.676043-1-bchihi@baylibre.com> References: <20220804130912.676043-1-bchihi@baylibre.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20220804_061010_691754_73F1A242 X-CRM114-Status: GOOD ( 12.54 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+linux-mediatek=archiver.kernel.org@lists.infradead.org From: Michael Kao Add thermal zone settings for mt8195 Signed-off-by: Michael Kao Signed-off-by: Ben Tseng Signed-off-by: Alexandre Bailon Signed-off-by: Balsam CHIHI --- drivers/thermal/mediatek/lvts_thermal.h | 1 + drivers/thermal/mediatek/lvts_v4.c | 223 ++++++++++++++++++++++++ 2 files changed, 224 insertions(+) diff --git a/drivers/thermal/mediatek/lvts_thermal.h b/drivers/thermal/mediatek/lvts_thermal.h index 9095f9cd232b..4db2c135661e 100644 --- a/drivers/thermal/mediatek/lvts_thermal.h +++ b/drivers/thermal/mediatek/lvts_thermal.h @@ -16,6 +16,7 @@ #define FEATURE_DEVICE_AUTO_RCK BIT(0) #define NUM_EFUSE_ADDR 22 #define NUM_EFUSE_BLOCK_MT8192 1 +#define NUM_EFUSE_BLOCK_MT8195 2 #define DEFAULT_GOLDEN_TEMP 50 #define DEFAULT_CUONT_R 35000 #define DEFAULT_CUONT_RC 2750 diff --git a/drivers/thermal/mediatek/lvts_v4.c b/drivers/thermal/mediatek/lvts_v4.c index 6477d386c9e1..e216b66625db 100644 --- a/drivers/thermal/mediatek/lvts_v4.c +++ b/drivers/thermal/mediatek/lvts_v4.c @@ -32,6 +32,31 @@ enum mt8192_lvts_ap_sensor_enum { MT8192_NUM_TS_AP }; +enum mt8195_lvts_mcu_sensor_enum { + MT8195_TS1_0, // cpu_big1 + MT8195_TS1_1, // cpu_big2 + MT8195_TS2_0, // cpu_big3 + MT8195_TS2_1, // cpu_big4 + MT8195_TS3_0, // cpu_little1 + MT8195_TS3_1, // cpu_little2 + MT8195_TS3_2, // cpu_little3 + MT8195_TS3_3, // cpu_little4 + MT8195_NUM_TS_MCU +}; + +enum mt8195_lvts_ap_sensor_enum { + MT8195_TS4_0, // vpu1 + MT8195_TS4_1, // vpu2 + MT8195_TS5_0, // gpu1 + MT8195_TS5_1, // gpu2 + MT8195_TS6_0, // vdec + MT8195_TS6_1, // img + MT8195_TS6_2, // infra + MT8195_TS7_0, // cam1 + MT8195_TS7_1, // cam2 + MT8195_NUM_TS_AP +}; + static void mt8192_mcu_efuse_to_cal_data(struct lvts_data *lvts_data) { const unsigned int mt8192_ts[] = { MT8192_TS2_0, MT8192_TS3_0 }; @@ -74,6 +99,60 @@ static void mt8192_ap_efuse_to_cal_data(struct lvts_data *lvts_data) } } +static void mt8195_mcu_efuse_to_cal_data(struct lvts_data *lvts_data) +{ + struct lvts_sensor_cal_data *cal_data = &lvts_data->cal_data; + + cal_data->golden_temp = GET_CAL_DATA_BITMASK(0, lvts_data, 31, 24); + + cal_data->count_r[MT8195_TS1_0] = GET_CAL_DATA_BITMASK(1, lvts_data, 23, 0); + cal_data->count_r[MT8195_TS1_1] = (GET_CAL_DATA_BITMASK(2, lvts_data, 15, 0) << 8) + + GET_CAL_DATA_BITMASK(1, lvts_data, 31, 24); + cal_data->count_r[MT8195_TS2_0] = GET_CAL_DATA_BITMASK(3, lvts_data, 31, 8); + cal_data->count_r[MT8195_TS2_1] = GET_CAL_DATA_BITMASK(4, lvts_data, 23, 0); + cal_data->count_r[MT8195_TS3_0] = (GET_CAL_DATA_BITMASK(6, lvts_data, 7, 0) << 16) + + GET_CAL_DATA_BITMASK(5, lvts_data, 31, 16); + cal_data->count_r[MT8195_TS3_1] = GET_CAL_DATA_BITMASK(6, lvts_data, 31, 8); + cal_data->count_r[MT8195_TS3_2] = GET_CAL_DATA_BITMASK(7, lvts_data, 23, 0); + cal_data->count_r[MT8195_TS3_3] = (GET_CAL_DATA_BITMASK(8, lvts_data, 15, 0) << 8) + + GET_CAL_DATA_BITMASK(7, lvts_data, 31, 24); + + cal_data->count_rc[MT8195_TS1_0] = (GET_CAL_DATA_BITMASK(3, lvts_data, 7, 0) << 16) + + GET_CAL_DATA_BITMASK(2, lvts_data, 31, 16); + cal_data->count_rc[MT8195_TS2_0] = (GET_CAL_DATA_BITMASK(5, lvts_data, 15, 0) << 8) + + GET_CAL_DATA_BITMASK(4, lvts_data, 31, 24); + cal_data->count_rc[MT8195_TS3_0] = (GET_CAL_DATA_BITMASK(9, lvts_data, 7, 0) << 16) + + GET_CAL_DATA_BITMASK(8, lvts_data, 31, 16); +} + +static void mt8195_ap_efuse_to_cal_data(struct lvts_data *lvts_data) +{ + struct lvts_sensor_cal_data *cal_data = &lvts_data->cal_data; + + cal_data->golden_temp = GET_CAL_DATA_BITMASK(0, lvts_data, 31, 24); + + cal_data->count_r[MT8195_TS4_0] = GET_CAL_DATA_BITMASK(9, lvts_data, 31, 8); + cal_data->count_r[MT8195_TS4_1] = GET_CAL_DATA_BITMASK(10, lvts_data, 23, 0); + cal_data->count_r[MT8195_TS5_0] = (GET_CAL_DATA_BITMASK(12, lvts_data, 7, 0) << 16) + + GET_CAL_DATA_BITMASK(11, lvts_data, 31, 16); + cal_data->count_r[MT8195_TS5_1] = GET_CAL_DATA_BITMASK(12, lvts_data, 31, 8); + cal_data->count_r[MT8195_TS6_0] = (GET_CAL_DATA_BITMASK(14, lvts_data, 15, 0) << 8) + + GET_CAL_DATA_BITMASK(13, lvts_data, 31, 24); + cal_data->count_r[MT8195_TS6_1] = (GET_CAL_DATA_BITMASK(15, lvts_data, 7, 0) << 16) + + GET_CAL_DATA_BITMASK(14, lvts_data, 31, 16); + cal_data->count_r[MT8195_TS6_2] = GET_CAL_DATA_BITMASK(15, lvts_data, 31, 8); + cal_data->count_r[MT8195_TS7_0] = (GET_CAL_DATA_BITMASK(17, lvts_data, 15, 0) << 8) + + GET_CAL_DATA_BITMASK(16, lvts_data, 31, 24); + cal_data->count_r[MT8195_TS7_1] = (GET_CAL_DATA_BITMASK(18, lvts_data, 7, 0) << 16) + + GET_CAL_DATA_BITMASK(17, lvts_data, 31, 16); + + cal_data->count_rc[MT8195_TS4_0] = (GET_CAL_DATA_BITMASK(11, lvts_data, 15, 0) << 8) + + GET_CAL_DATA_BITMASK(10, lvts_data, 31, 24); + cal_data->count_rc[MT8195_TS5_0] = GET_CAL_DATA_BITMASK(13, lvts_data, 23, 0); + cal_data->count_rc[MT8195_TS6_0] = GET_CAL_DATA_BITMASK(16, lvts_data, 23, 0); + cal_data->count_rc[MT8195_TS7_0] = GET_CAL_DATA_BITMASK(18, lvts_data, 31, 8); +} + static struct lvts_speed_settings tc_speed_mt8192 = { .period_unit = PERIOD_UNIT, .group_interval_delay = GROUP_INTERVAL_DELAY, @@ -81,6 +160,13 @@ static struct lvts_speed_settings tc_speed_mt8192 = { .sensor_interval_delay = SENSOR_INTERVAL_DELAY, }; +static struct lvts_speed_settings tc_speed_mt8195 = { + .period_unit = PERIOD_UNIT, + .group_interval_delay = GROUP_INTERVAL_DELAY, + .filter_interval_delay = FILTER_INTERVAL_DELAY, + .sensor_interval_delay = SENSOR_INTERVAL_DELAY, +}; + static const struct lvts_tc_settings mt8192_tc_mcu_settings[] = { [0] = { .dev_id = 0x81, @@ -164,6 +250,89 @@ static const struct lvts_tc_settings mt8192_tc_ap_settings[] = { } }; +static const struct lvts_tc_settings mt8195_tc_mcu_settings[] = { + [0] = { + .dev_id = 0x81, + .addr_offset = 0x0, + .num_sensor = 2, + .sensor_map = { MT8195_TS1_0, MT8195_TS1_1 }, + .tc_speed = &tc_speed_mt8195, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT1, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(3), + }, + [1] = { + .dev_id = 0x82, + .addr_offset = 0x100, + .num_sensor = 2, + .sensor_map = { MT8195_TS2_0, MT8195_TS2_1 }, + .tc_speed = &tc_speed_mt8195, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT0, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(4), + }, + [2] = { + .dev_id = 0x83, + .addr_offset = 0x200, + .num_sensor = 4, + .sensor_map = { MT8195_TS3_0, MT8195_TS3_1, MT8195_TS3_2, MT8195_TS3_3 }, + .tc_speed = &tc_speed_mt8195, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT0, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(5), + } +}; + +static const struct lvts_tc_settings mt8195_tc_ap_settings[] = { + [0] = { + .dev_id = 0x84, + .addr_offset = 0x0, + .num_sensor = 2, + .sensor_map = { MT8195_TS4_0, MT8195_TS4_1 }, + .tc_speed = &tc_speed_mt8195, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT0, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(3), + }, + [1] = { + .dev_id = 0x85, + .addr_offset = 0x100, + .num_sensor = 2, + .sensor_map = { MT8195_TS5_0, MT8195_TS5_1 }, + .tc_speed = &tc_speed_mt8195, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT1, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(4), + }, + [2] = { + .dev_id = 0x86, + .addr_offset = 0x200, + .num_sensor = 3, + .sensor_map = { MT8195_TS6_0, MT8195_TS6_1, MT8195_TS6_2 }, + .tc_speed = &tc_speed_mt8195, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT1, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(5), + }, + [3] = { + .dev_id = 0x87, + .addr_offset = 0x300, + .num_sensor = 2, + .sensor_map = { MT8195_TS7_0, MT8195_TS7_1 }, + .tc_speed = &tc_speed_mt8195, + .hw_filter = LVTS_FILTER_2_OF_4, + .dominator_sensing_point = SENSING_POINT0, + .hw_reboot_trip_point = HW_REBOOT_TRIP_POINT, + .irq_bit = BIT(6), + } +}; + static const struct lvts_data mt8192_lvts_mcu_data = { .num_tc = (ARRAY_SIZE(mt8192_tc_mcu_settings)), .tc = mt8192_tc_mcu_settings, @@ -216,9 +385,63 @@ static const struct lvts_data mt8192_lvts_ap_data = { }, }; +static const struct lvts_data mt8195_lvts_mcu_data = { + .num_tc = (ARRAY_SIZE(mt8195_tc_mcu_settings)), + .tc = mt8195_tc_mcu_settings, + .num_sensor = MT8195_NUM_TS_MCU, + .ops = { + .efuse_to_cal_data = mt8195_mcu_efuse_to_cal_data, + .device_enable_and_init = lvts_device_enable_and_init, + .device_enable_auto_rck = lvts_device_enable_auto_rck_v4, + .device_read_count_rc_n = lvts_device_read_count_rc_n_v4, + .set_cal_data = lvts_set_calibration_data_v4, + .init_controller = lvts_init_controller_v4, + }, + .feature_bitmap = FEATURE_DEVICE_AUTO_RCK, + .num_efuse_addr = NUM_EFUSE_ADDR, + .num_efuse_block = NUM_EFUSE_BLOCK_MT8195, + .cal_data = { + .default_golden_temp = DEFAULT_GOLDEN_TEMP, + .default_count_r = DEFAULT_CUONT_R, + .default_count_rc = DEFAULT_CUONT_RC, + }, + .coeff = { + .a = COEFF_A, + .b = COEFF_B, + }, +}; + +static const struct lvts_data mt8195_lvts_ap_data = { + .num_tc = (ARRAY_SIZE(mt8195_tc_ap_settings)), + .tc = mt8195_tc_ap_settings, + .num_sensor = MT8195_NUM_TS_AP, + .ops = { + .efuse_to_cal_data = mt8195_ap_efuse_to_cal_data, + .device_enable_and_init = lvts_device_enable_and_init, + .device_enable_auto_rck = lvts_device_enable_auto_rck_v4, + .device_read_count_rc_n = lvts_device_read_count_rc_n_v4, + .set_cal_data = lvts_set_calibration_data_v4, + .init_controller = lvts_init_controller_v4, + }, + .feature_bitmap = FEATURE_DEVICE_AUTO_RCK, + .num_efuse_addr = NUM_EFUSE_ADDR, + .num_efuse_block = NUM_EFUSE_BLOCK_MT8195, + .cal_data = { + .default_golden_temp = DEFAULT_GOLDEN_TEMP, + .default_count_r = DEFAULT_CUONT_R, + .default_count_rc = DEFAULT_CUONT_RC, + }, + .coeff = { + .a = COEFF_A, + .b = COEFF_B, + }, +}; + static const struct of_device_id lvts_of_match[] = { { .compatible = "mediatek,mt8192-lvts-mcu", .data = &mt8192_lvts_mcu_data, }, { .compatible = "mediatek,mt8192-lvts-ap", .data = &mt8192_lvts_ap_data, }, + { .compatible = "mediatek,mt8195-lvts-mcu", .data = &mt8195_lvts_mcu_data, }, + { .compatible = "mediatek,mt8195-lvts-ap", .data = &mt8195_lvts_ap_data, }, {}, }; MODULE_DEVICE_TABLE(of, lvts_of_match);