mirror of
https://github.com/openwrt/openwrt.git
synced 2024-12-22 06:57:57 +00:00
228e0e1039
Removed upstreamed: 01. backport-5.15/424-v6.4-0001-mtd-core-provide-unique-name-for-nvmem-device-take-t.patch 02. backport-5.15/424-v6.4-0002-mtd-core-fix-nvmem-error-reporting.patch 03. generic-backport/424-v6.4-0003-mtd-core-fix-error-path-for-nvmem-provider.patch 04. generic-backport/828-v6.4-0001-of-Fix-modalias-string-generation.patch 05. bcm4908/patches-5.15/031-v5.17-0002-arm64-dts-broadcom-bcm4908-add-DT-for-Netgear-RAXE50.patch 06. bcm4908/patches-5.15/033-v6.0-0001-arm64-dts-Add-DTS-files-for-bcmbca-SoC-BCM63158.patchgit 07. bcm4908/patches-5.15/033-v6.0-0002-arm64-dts-Add-DTS-files-for-bcmbca-SoC-BCM4912.patchgita 08. bcm4908/patches-5.15/033-v6.0-0010-arm64-dts-Add-base-DTS-file-for-bcmbca-device-Asus-G.patchgit 09. bcm4908/patches-5.15/034-v6.1-0005-arm64-dts-Move-BCM4908-dts-to-bcmbca-folder.patch 10. bcm4908/patches-5.15/036-v6.4-0002-arm64-dts-broadcom-bcmbca-bcm4908-fix-NAND-interrupt.patch 11. bcm4908/patches-5.15/036-v6.4-0004-arm64-dts-broadcom-bcmbca-bcm4908-fix-procmon-nodena.patch 12. ipq806x/patches-5.15/104-v6.0-06-ARM-dts-qcom-ipq8064-reduce-pci-IO-size-to-64K.patch Manually rebased: bcm27xx/patches-5.15/950-0078-BCM2708-Add-core-Device-Tree-support.patch bcm27xx/patches-5.15/950-0547-ARM-dts-Add-Pi-Zero-2-support.patch bcm4908/patches-5.15/033-v6.0-0001-arm64-dts-Add-DTS-files-for-bcmbca-SoC-BCM63158.patchgit bcm4908/patches-5.15/033-v6.0-0002-arm64-dts-Add-DTS-files-for-bcmbca-SoC-BCM4912.patchgit bcm4908/patches-5.15/030-v5.16-0001-arm64-dts-broadcom-bcm4908-Fix-NAND-node-name.patch bcm4908/patches-5.15/032-v5.18-0002-arm64-dts-broadcom-bcm4908-add-pinctrl-binding.patch bcm4908/patches-5.15/032-v5.18-0003-arm64-dts-broadcom-bcm4908-add-watchdog-block.patch bcm4908/patches-5.15/032-v5.18-0004-arm64-dts-broadcom-bcm4908-add-I2C-block.patch bcm4908/patches-5.15/033-v6.0-0003-ARM64-dts-Add-DTS-files-for-bcmbca-SoC-BCM6858.patchgit bcm4908/patches-5.15/033-v6.0-0008-arm64-dts-broadcom-bcm4908-Fix-timer-node-for-BCM490.patchgit bcm4908/patches-5.15/034-v6.1-0001-arm64-dts-broadcom-bcm4908-add-remaining-LED-pins.patch bcm4908/patches-5.15/034-v6.1-0002-arm64-dts-broadcom-bcm4908-add-LEDs-controller-block.patch bcm4908/patches-5.15/034-v6.1-0003-arm64-dts-broadcom-bcm4908-add-Asus-GT-AC5300-LEDs.patch bcm4908/patches-5.15/034-v6.1-0004-arm64-dts-bcmbca-update-BCM4908-board-dts-files.patch All other patches automatically rebased. Build system: x86_64 Build-tested: bcm2711/RPi4B, ramips/tplink_archer-a6-v3, filogic/xiaomi_redmi-router-ax6000-ubootmod Run-tested: bcm2711/RPi4B, ramips/tplink_archer-a6-v3, filogic/xiaomi_redmi-router-ax6000-ubootmod 01. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.15.111&id=77112d23a671697f0f70695ab901f807e15d2093 02. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.15.111&id=fe07b3b5af01f42b291f5da0da09d047f50b33a6 03. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.15.111&id=273be36e420924237f6c9d43cdad96718c13dd52 04. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.15.111&id=fe8ab85ed4958e58e991bba0aa0a655b552b0273 05. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.15.111&id=6ae67829fa5e9e71f458f69db42f0e216225616a 06. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.15.111&id=1994284cb9226b65ca3a6744ce3320218b584f26 07. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.15.111&id=a46878476c5549a4fde15a31922ce80a50b23492 08. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.15.111&id=112ff0f2530549d50510f116474924f9c4fad590 09. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.15.111&id=7c253e98685e6d884d12e2618ef4d2ad90b4fbd7 10. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.15.111&id=8444b46e163aa9559a0af0381a1d230ec4146eb2 11. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.15.111&id=6d1af517817a760d7af3dee0fc4603645485495c 12. https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git/commit/?h=v5.15.111&id=cc4f0e168a5630ad0491ac5328f1a89f3cf3d04e Signed-off-by: John Audia <therealgraysky@proton.me>
241 lines
7.0 KiB
Diff
241 lines
7.0 KiB
Diff
From aa957c759b1182aee00cc35178667f849f941b42 Mon Sep 17 00:00:00 2001
|
|
From: Daniel Golle <daniel@makrotopia.org>
|
|
Date: Wed, 30 Nov 2022 13:19:39 +0000
|
|
Subject: [PATCH 2/2] thermal: mediatek: add support for MT7986 and MT7981
|
|
|
|
Add support for V3 generation thermal found in MT7986 and MT7981 SoCs.
|
|
Brings code to assign values from efuse as well as new function to
|
|
convert raw temperature to millidegree celsius, as found in MediaTek's
|
|
SDK sources (but cleaned up and de-duplicated)
|
|
|
|
[1]: https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/+/baf36c7eef477aae1f8f2653b6c29e2caf48475b
|
|
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
|
|
---
|
|
drivers/thermal/mtk_thermal.c | 137 ++++++++++++++++++++++++++++++++--
|
|
1 file changed, 132 insertions(+), 5 deletions(-)
|
|
|
|
--- a/drivers/thermal/mtk_thermal.c
|
|
+++ b/drivers/thermal/mtk_thermal.c
|
|
@@ -150,6 +150,20 @@
|
|
#define CALIB_BUF1_VALID_V2(x) (((x) >> 4) & 0x1)
|
|
#define CALIB_BUF1_O_SLOPE_SIGN_V2(x) (((x) >> 3) & 0x1)
|
|
|
|
+/*
|
|
+ * Layout of the fuses providing the calibration data
|
|
+ * These macros can be used for MT7981 and MT7986.
|
|
+ */
|
|
+#define CALIB_BUF0_ADC_GE_V3(x) (((x) >> 0) & 0x3ff)
|
|
+#define CALIB_BUF0_DEGC_CALI_V3(x) (((x) >> 20) & 0x3f)
|
|
+#define CALIB_BUF0_O_SLOPE_V3(x) (((x) >> 26) & 0x3f)
|
|
+#define CALIB_BUF1_VTS_TS1_V3(x) (((x) >> 0) & 0x1ff)
|
|
+#define CALIB_BUF1_VTS_TS2_V3(x) (((x) >> 21) & 0x1ff)
|
|
+#define CALIB_BUF1_VTS_TSABB_V3(x) (((x) >> 9) & 0x1ff)
|
|
+#define CALIB_BUF1_VALID_V3(x) (((x) >> 18) & 0x1)
|
|
+#define CALIB_BUF1_O_SLOPE_SIGN_V3(x) (((x) >> 19) & 0x1)
|
|
+#define CALIB_BUF1_ID_V3(x) (((x) >> 20) & 0x1)
|
|
+
|
|
enum {
|
|
VTS1,
|
|
VTS2,
|
|
@@ -163,6 +177,7 @@ enum {
|
|
enum mtk_thermal_version {
|
|
MTK_THERMAL_V1 = 1,
|
|
MTK_THERMAL_V2,
|
|
+ MTK_THERMAL_V3,
|
|
};
|
|
|
|
/* MT2701 thermal sensors */
|
|
@@ -245,6 +260,27 @@ enum mtk_thermal_version {
|
|
/* The calibration coefficient of sensor */
|
|
#define MT8183_CALIBRATION 153
|
|
|
|
+/* AUXADC channel 11 is used for the temperature sensors */
|
|
+#define MT7986_TEMP_AUXADC_CHANNEL 11
|
|
+
|
|
+/* The total number of temperature sensors in the MT7986 */
|
|
+#define MT7986_NUM_SENSORS 1
|
|
+
|
|
+/* The number of banks in the MT7986 */
|
|
+#define MT7986_NUM_ZONES 1
|
|
+
|
|
+/* The number of sensing points per bank */
|
|
+#define MT7986_NUM_SENSORS_PER_ZONE 1
|
|
+
|
|
+/* MT7986 thermal sensors */
|
|
+#define MT7986_TS1 0
|
|
+
|
|
+/* The number of controller in the MT7986 */
|
|
+#define MT7986_NUM_CONTROLLER 1
|
|
+
|
|
+/* The calibration coefficient of sensor */
|
|
+#define MT7986_CALIBRATION 165
|
|
+
|
|
struct mtk_thermal;
|
|
|
|
struct thermal_bank_cfg {
|
|
@@ -388,6 +424,14 @@ static const int mt7622_mux_values[MT762
|
|
static const int mt7622_vts_index[MT7622_NUM_SENSORS] = { VTS1 };
|
|
static const int mt7622_tc_offset[MT7622_NUM_CONTROLLER] = { 0x0, };
|
|
|
|
+/* MT7986 thermal sensor data */
|
|
+static const int mt7986_bank_data[MT7986_NUM_SENSORS] = { MT7986_TS1, };
|
|
+static const int mt7986_msr[MT7986_NUM_SENSORS_PER_ZONE] = { TEMP_MSR0, };
|
|
+static const int mt7986_adcpnp[MT7986_NUM_SENSORS_PER_ZONE] = { TEMP_ADCPNP0, };
|
|
+static const int mt7986_mux_values[MT7986_NUM_SENSORS] = { 0, };
|
|
+static const int mt7986_vts_index[MT7986_NUM_SENSORS] = { VTS1 };
|
|
+static const int mt7986_tc_offset[MT7986_NUM_CONTROLLER] = { 0x0, };
|
|
+
|
|
/*
|
|
* The MT8173 thermal controller has four banks. Each bank can read up to
|
|
* four temperature sensors simultaneously. The MT8173 has a total of 5
|
|
@@ -551,6 +595,30 @@ static const struct mtk_thermal_data mt8
|
|
.version = MTK_THERMAL_V1,
|
|
};
|
|
|
|
+/*
|
|
+ * MT7986 uses AUXADC Channel 11 for raw data access.
|
|
+ */
|
|
+static const struct mtk_thermal_data mt7986_thermal_data = {
|
|
+ .auxadc_channel = MT7986_TEMP_AUXADC_CHANNEL,
|
|
+ .num_banks = MT7986_NUM_ZONES,
|
|
+ .num_sensors = MT7986_NUM_SENSORS,
|
|
+ .vts_index = mt7986_vts_index,
|
|
+ .cali_val = MT7986_CALIBRATION,
|
|
+ .num_controller = MT7986_NUM_CONTROLLER,
|
|
+ .controller_offset = mt7986_tc_offset,
|
|
+ .need_switch_bank = true,
|
|
+ .bank_data = {
|
|
+ {
|
|
+ .num_sensors = 1,
|
|
+ .sensors = mt7986_bank_data,
|
|
+ },
|
|
+ },
|
|
+ .msr = mt7986_msr,
|
|
+ .adcpnp = mt7986_adcpnp,
|
|
+ .sensor_mux_values = mt7986_mux_values,
|
|
+ .version = MTK_THERMAL_V3,
|
|
+};
|
|
+
|
|
/**
|
|
* raw_to_mcelsius - convert a raw ADC value to mcelsius
|
|
* @mt: The thermal controller
|
|
@@ -605,6 +673,22 @@ static int raw_to_mcelsius_v2(struct mtk
|
|
return (format_2 - tmp) * 100;
|
|
}
|
|
|
|
+static int raw_to_mcelsius_v3(struct mtk_thermal *mt, int sensno, s32 raw)
|
|
+{
|
|
+ s32 tmp;
|
|
+
|
|
+ if (raw == 0)
|
|
+ return 0;
|
|
+
|
|
+ raw &= 0xfff;
|
|
+ tmp = 100000 * 15 / 16 * 10000;
|
|
+ tmp /= 4096 - 512 + mt->adc_ge;
|
|
+ tmp /= 1490;
|
|
+ tmp *= raw - mt->vts[sensno] - 2900;
|
|
+
|
|
+ return mt->degc_cali * 500 - tmp;
|
|
+}
|
|
+
|
|
/**
|
|
* mtk_thermal_get_bank - get bank
|
|
* @bank: The bank
|
|
@@ -885,6 +969,25 @@ static int mtk_thermal_extract_efuse_v2(
|
|
return 0;
|
|
}
|
|
|
|
+static int mtk_thermal_extract_efuse_v3(struct mtk_thermal *mt, u32 *buf)
|
|
+{
|
|
+ if (!CALIB_BUF1_VALID_V3(buf[1]))
|
|
+ return -EINVAL;
|
|
+
|
|
+ mt->adc_ge = CALIB_BUF0_ADC_GE_V3(buf[0]);
|
|
+ mt->degc_cali = CALIB_BUF0_DEGC_CALI_V3(buf[0]);
|
|
+ mt->o_slope = CALIB_BUF0_O_SLOPE_V3(buf[0]);
|
|
+ mt->vts[VTS1] = CALIB_BUF1_VTS_TS1_V3(buf[1]);
|
|
+ mt->vts[VTS2] = CALIB_BUF1_VTS_TS2_V3(buf[1]);
|
|
+ mt->vts[VTSABB] = CALIB_BUF1_VTS_TSABB_V3(buf[1]);
|
|
+ mt->o_slope_sign = CALIB_BUF1_O_SLOPE_SIGN_V3(buf[1]);
|
|
+
|
|
+ if (CALIB_BUF1_ID_V3(buf[1]) == 0)
|
|
+ mt->o_slope = 0;
|
|
+
|
|
+ return 0;
|
|
+}
|
|
+
|
|
static int mtk_thermal_get_calibration_data(struct device *dev,
|
|
struct mtk_thermal *mt)
|
|
{
|
|
@@ -895,6 +998,7 @@ static int mtk_thermal_get_calibration_d
|
|
|
|
/* Start with default values */
|
|
mt->adc_ge = 512;
|
|
+ mt->adc_oe = 512;
|
|
for (i = 0; i < mt->conf->num_sensors; i++)
|
|
mt->vts[i] = 260;
|
|
mt->degc_cali = 40;
|
|
@@ -920,10 +1024,20 @@ static int mtk_thermal_get_calibration_d
|
|
goto out;
|
|
}
|
|
|
|
- if (mt->conf->version == MTK_THERMAL_V1)
|
|
+ switch (mt->conf->version) {
|
|
+ case MTK_THERMAL_V1:
|
|
ret = mtk_thermal_extract_efuse_v1(mt, buf);
|
|
- else
|
|
+ break;
|
|
+ case MTK_THERMAL_V2:
|
|
ret = mtk_thermal_extract_efuse_v2(mt, buf);
|
|
+ break;
|
|
+ case MTK_THERMAL_V3:
|
|
+ ret = mtk_thermal_extract_efuse_v3(mt, buf);
|
|
+ break;
|
|
+ default:
|
|
+ ret = -EINVAL;
|
|
+ break;
|
|
+ }
|
|
|
|
if (ret) {
|
|
dev_info(dev, "Device not calibrated, using default calibration values\n");
|
|
@@ -954,6 +1068,10 @@ static const struct of_device_id mtk_the
|
|
.data = (void *)&mt7622_thermal_data,
|
|
},
|
|
{
|
|
+ .compatible = "mediatek,mt7986-thermal",
|
|
+ .data = (void *)&mt7986_thermal_data,
|
|
+ },
|
|
+ {
|
|
.compatible = "mediatek,mt8183-thermal",
|
|
.data = (void *)&mt8183_thermal_data,
|
|
}, {
|
|
@@ -1078,15 +1196,24 @@ static int mtk_thermal_probe(struct plat
|
|
goto err_disable_clk_auxadc;
|
|
}
|
|
|
|
- if (mt->conf->version == MTK_THERMAL_V2) {
|
|
+ if (mt->conf->version != MTK_THERMAL_V1) {
|
|
mtk_thermal_turn_on_buffer(apmixed_base);
|
|
mtk_thermal_release_periodic_ts(mt, auxadc_base);
|
|
}
|
|
|
|
- if (mt->conf->version == MTK_THERMAL_V1)
|
|
+ switch (mt->conf->version) {
|
|
+ case MTK_THERMAL_V1:
|
|
mt->raw_to_mcelsius = raw_to_mcelsius_v1;
|
|
- else
|
|
+ break;
|
|
+ case MTK_THERMAL_V2:
|
|
mt->raw_to_mcelsius = raw_to_mcelsius_v2;
|
|
+ break;
|
|
+ case MTK_THERMAL_V3:
|
|
+ mt->raw_to_mcelsius = raw_to_mcelsius_v3;
|
|
+ break;
|
|
+ default:
|
|
+ break;
|
|
+ }
|
|
|
|
for (ctrl_id = 0; ctrl_id < mt->conf->num_controller ; ctrl_id++)
|
|
for (i = 0; i < mt->conf->num_banks; i++)
|