* [PATCH 1/2] thermal: mediatek: add support for MT7986 and MT7981
@ 2022-10-31 22:15 Daniel Golle
2022-10-31 22:16 ` [PATCH 2/2] dt-bindings: thermal: mediatek: add compatible string for MT7986 SoC Daniel Golle
2022-10-31 23:07 ` [PATCH 1/2] thermal: mediatek: add support for MT7986 and MT7981 Daniel Golle
0 siblings, 2 replies; 11+ messages in thread
From: Daniel Golle @ 2022-10-31 22:15 UTC (permalink / raw)
To: linux-pm, linux-arm-kernel, linux-mediatek, linux-kernel,
Rafael J. Wysocki, Daniel Lezcano, Amit Kucheria, Zhang Rui,
Matthias Brugger
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)
The conversion formula as found in MediaTek's SDK has been refactored
and the adc_oe offset value from the efuse was no longer taken into
account as a result, while the goal was apparently to prevent the
loss of floating point precission along the calculation[1].
Hence I added back the adc_oe offset calibration value as it has also
been present the calculation before the mentioned change.
[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 | 122 +++++++++++++++++++++++++++++++++-
1 file changed, 119 insertions(+), 3 deletions(-)
diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
index 8440692e3890d2..5b60971323a49b 100644
--- a/drivers/thermal/mtk_thermal.c
+++ b/drivers/thermal/mtk_thermal.c
@@ -150,6 +150,21 @@
#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_ADC_OE_V3(x) (((x) >> 10) & 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 +178,7 @@ enum {
enum mtk_thermal_version {
MTK_THERMAL_V1 = 1,
MTK_THERMAL_V2,
+ MTK_THERMAL_V3,
};
/* MT2701 thermal sensors */
@@ -245,6 +261,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 {
@@ -386,6 +423,14 @@ static const int mt7622_mux_values[MT7622_NUM_SENSORS] = { 0, };
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
@@ -549,6 +594,30 @@ static const struct mtk_thermal_data mt8183_thermal_data = {
.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
@@ -603,6 +672,22 @@ static int raw_to_mcelsius_v2(struct mtk_thermal *mt, int sensno, s32 raw)
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 - mt->adc_oe + 512;
+
+ return mt->degc_cali * 500 - tmp;
+}
+
/**
* mtk_thermal_get_bank - get bank
* @bank: The bank
@@ -659,9 +744,12 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
if (mt->conf->version == MTK_THERMAL_V1) {
temp = raw_to_mcelsius_v1(
mt, conf->bank_data[bank->id].sensors[i], raw);
- } else {
+ } else if (mt->conf->version == MTK_THERMAL_V2) {
temp = raw_to_mcelsius_v2(
mt, conf->bank_data[bank->id].sensors[i], raw);
+ } else {
+ temp = raw_to_mcelsius_v3(
+ mt, conf->bank_data[bank->id].sensors[i], raw);
}
/*
@@ -887,6 +975,26 @@ static int mtk_thermal_extract_efuse_v2(struct mtk_thermal *mt, u32 *buf)
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_oe = CALIB_BUF0_ADC_OE_V3(buf[0]);
+ 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)
{
@@ -897,6 +1005,7 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
/* 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;
@@ -924,8 +1033,10 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
if (mt->conf->version == MTK_THERMAL_V1)
ret = mtk_thermal_extract_efuse_v1(mt, buf);
- else
+ else if (mt->conf->version == MTK_THERMAL_V2)
ret = mtk_thermal_extract_efuse_v2(mt, buf);
+ else
+ ret = mtk_thermal_extract_efuse_v3(mt, buf);
if (ret) {
dev_info(dev, "Device not calibrated, using default calibration values\n");
@@ -955,6 +1066,10 @@ static const struct of_device_id mtk_thermal_of_match[] = {
.compatible = "mediatek,mt7622-thermal",
.data = (void *)&mt7622_thermal_data,
},
+ {
+ .compatible = "mediatek,mt7986-thermal",
+ .data = (void *)&mt7986_thermal_data,
+ },
{
.compatible = "mediatek,mt8183-thermal",
.data = (void *)&mt8183_thermal_data,
@@ -1070,7 +1185,8 @@ static int mtk_thermal_probe(struct platform_device *pdev)
goto err_disable_clk_auxadc;
}
- if (mt->conf->version == MTK_THERMAL_V2) {
+ if (mt->conf->version == MTK_THERMAL_V2 ||
+ mt->conf->version == MTK_THERMAL_V3) {
mtk_thermal_turn_on_buffer(apmixed_base);
mtk_thermal_release_periodic_ts(mt, auxadc_base);
}
--
2.38.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/2] dt-bindings: thermal: mediatek: add compatible string for MT7986 SoC
2022-10-31 22:15 [PATCH 1/2] thermal: mediatek: add support for MT7986 and MT7981 Daniel Golle
@ 2022-10-31 22:16 ` Daniel Golle
2022-10-31 23:08 ` Daniel Golle
` (2 more replies)
2022-10-31 23:07 ` [PATCH 1/2] thermal: mediatek: add support for MT7986 and MT7981 Daniel Golle
1 sibling, 3 replies; 11+ messages in thread
From: Daniel Golle @ 2022-10-31 22:16 UTC (permalink / raw)
To: devicetree, linux-pm, linux-arm-kernel, linux-mediatek,
linux-kernel, Rafael J. Wysocki, Daniel Lezcano, Amit Kucheria,
Zhang Rui, Matthias Brugger, Krzysztof Kozlowski
Add compatible string 'mediatek,mt7986-thermal' for V3 thermal unit
found in MT7981 and MT7986 SoCs.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
Documentation/devicetree/bindings/thermal/mediatek-thermal.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
index 5c7e7bdd029abf..efc16ab5b22b5d 100644
--- a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
+++ b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
@@ -13,6 +13,7 @@ Required properties:
- "mediatek,mt2701-thermal" : For MT2701 family of SoCs
- "mediatek,mt2712-thermal" : For MT2712 family of SoCs
- "mediatek,mt7622-thermal" : For MT7622 SoC
+ - "mediatek,mt7986-thermal" : For MT7981 and MT7986 SoC
- "mediatek,mt8183-thermal" : For MT8183 family of SoCs
- "mediatek,mt8516-thermal", "mediatek,mt2701-thermal : For MT8516 family of SoCs
- reg: Address range of the thermal controller
--
2.38.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 1/2] thermal: mediatek: add support for MT7986 and MT7981
2022-10-31 22:15 [PATCH 1/2] thermal: mediatek: add support for MT7986 and MT7981 Daniel Golle
2022-10-31 22:16 ` [PATCH 2/2] dt-bindings: thermal: mediatek: add compatible string for MT7986 SoC Daniel Golle
@ 2022-10-31 23:07 ` Daniel Golle
2022-11-29 11:53 ` Henry Yen (顏修溫)
1 sibling, 1 reply; 11+ messages in thread
From: Daniel Golle @ 2022-10-31 23:07 UTC (permalink / raw)
To: linux-pm, linux-arm-kernel, linux-mediatek, linux-kernel,
Rafael J. Wysocki, Daniel Lezcano, Amit Kucheria, Zhang Rui,
Matthias Brugger
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)
The conversion formula as found in MediaTek's SDK has been refactored
and the adc_oe offset value from the efuse was no longer taken into
account as a result, while the goal was apparently to prevent the
loss of floating point precission along the calculation[1].
Hence I added back the adc_oe offset calibration value as it has also
been present the calculation before the mentioned change.
[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 | 122 +++++++++++++++++++++++++++++++++-
1 file changed, 119 insertions(+), 3 deletions(-)
diff --git a/drivers/thermal/mtk_thermal.c b/drivers/thermal/mtk_thermal.c
index 8440692e3890d2..5b60971323a49b 100644
--- a/drivers/thermal/mtk_thermal.c
+++ b/drivers/thermal/mtk_thermal.c
@@ -150,6 +150,21 @@
#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_ADC_OE_V3(x) (((x) >> 10) & 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 +178,7 @@ enum {
enum mtk_thermal_version {
MTK_THERMAL_V1 = 1,
MTK_THERMAL_V2,
+ MTK_THERMAL_V3,
};
/* MT2701 thermal sensors */
@@ -245,6 +261,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 {
@@ -386,6 +423,14 @@ static const int mt7622_mux_values[MT7622_NUM_SENSORS] = { 0, };
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
@@ -549,6 +594,30 @@ static const struct mtk_thermal_data mt8183_thermal_data = {
.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
@@ -603,6 +672,22 @@ static int raw_to_mcelsius_v2(struct mtk_thermal *mt, int sensno, s32 raw)
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 - mt->adc_oe + 512;
+
+ return mt->degc_cali * 500 - tmp;
+}
+
/**
* mtk_thermal_get_bank - get bank
* @bank: The bank
@@ -659,9 +744,12 @@ static int mtk_thermal_bank_temperature(struct mtk_thermal_bank *bank)
if (mt->conf->version == MTK_THERMAL_V1) {
temp = raw_to_mcelsius_v1(
mt, conf->bank_data[bank->id].sensors[i], raw);
- } else {
+ } else if (mt->conf->version == MTK_THERMAL_V2) {
temp = raw_to_mcelsius_v2(
mt, conf->bank_data[bank->id].sensors[i], raw);
+ } else {
+ temp = raw_to_mcelsius_v3(
+ mt, conf->bank_data[bank->id].sensors[i], raw);
}
/*
@@ -887,6 +975,26 @@ static int mtk_thermal_extract_efuse_v2(struct mtk_thermal *mt, u32 *buf)
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_oe = CALIB_BUF0_ADC_OE_V3(buf[0]);
+ 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)
{
@@ -897,6 +1005,7 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
/* 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;
@@ -924,8 +1033,10 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
if (mt->conf->version == MTK_THERMAL_V1)
ret = mtk_thermal_extract_efuse_v1(mt, buf);
- else
+ else if (mt->conf->version == MTK_THERMAL_V2)
ret = mtk_thermal_extract_efuse_v2(mt, buf);
+ else
+ ret = mtk_thermal_extract_efuse_v3(mt, buf);
if (ret) {
dev_info(dev, "Device not calibrated, using default calibration values\n");
@@ -955,6 +1066,10 @@ static const struct of_device_id mtk_thermal_of_match[] = {
.compatible = "mediatek,mt7622-thermal",
.data = (void *)&mt7622_thermal_data,
},
+ {
+ .compatible = "mediatek,mt7986-thermal",
+ .data = (void *)&mt7986_thermal_data,
+ },
{
.compatible = "mediatek,mt8183-thermal",
.data = (void *)&mt8183_thermal_data,
@@ -1070,7 +1185,8 @@ static int mtk_thermal_probe(struct platform_device *pdev)
goto err_disable_clk_auxadc;
}
- if (mt->conf->version == MTK_THERMAL_V2) {
+ if (mt->conf->version == MTK_THERMAL_V2 ||
+ mt->conf->version == MTK_THERMAL_V3) {
mtk_thermal_turn_on_buffer(apmixed_base);
mtk_thermal_release_periodic_ts(mt, auxadc_base);
}
--
2.38.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 11+ messages in thread
* [PATCH 2/2] dt-bindings: thermal: mediatek: add compatible string for MT7986 SoC
2022-10-31 22:16 ` [PATCH 2/2] dt-bindings: thermal: mediatek: add compatible string for MT7986 SoC Daniel Golle
@ 2022-10-31 23:08 ` Daniel Golle
2022-11-02 18:26 ` Rob Herring
2022-11-02 20:43 ` Krzysztof Kozlowski
2 siblings, 0 replies; 11+ messages in thread
From: Daniel Golle @ 2022-10-31 23:08 UTC (permalink / raw)
To: linux-pm, linux-arm-kernel, linux-mediatek, linux-kernel,
Rafael J. Wysocki, Daniel Lezcano, Amit Kucheria, Zhang Rui,
Matthias Brugger
Add compatible string 'mediatek,mt7986-thermal' for V3 thermal unit
found in MT7981 and MT7986 SoCs.
Signed-off-by: Daniel Golle <daniel@makrotopia.org>
---
Documentation/devicetree/bindings/thermal/mediatek-thermal.txt | 1 +
1 file changed, 1 insertion(+)
diff --git a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
index 5c7e7bdd029abf..efc16ab5b22b5d 100644
--- a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
+++ b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
@@ -13,6 +13,7 @@ Required properties:
- "mediatek,mt2701-thermal" : For MT2701 family of SoCs
- "mediatek,mt2712-thermal" : For MT2712 family of SoCs
- "mediatek,mt7622-thermal" : For MT7622 SoC
+ - "mediatek,mt7986-thermal" : For MT7981 and MT7986 SoC
- "mediatek,mt8183-thermal" : For MT8183 family of SoCs
- "mediatek,mt8516-thermal", "mediatek,mt2701-thermal : For MT8516 family of SoCs
- reg: Address range of the thermal controller
--
2.38.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] dt-bindings: thermal: mediatek: add compatible string for MT7986 SoC
2022-10-31 22:16 ` [PATCH 2/2] dt-bindings: thermal: mediatek: add compatible string for MT7986 SoC Daniel Golle
2022-10-31 23:08 ` Daniel Golle
@ 2022-11-02 18:26 ` Rob Herring
2022-11-02 20:43 ` Krzysztof Kozlowski
2 siblings, 0 replies; 11+ messages in thread
From: Rob Herring @ 2022-11-02 18:26 UTC (permalink / raw)
To: Daniel Golle
Cc: linux-pm, linux-arm-kernel, linux-mediatek, linux-kernel,
Rafael J. Wysocki, Daniel Lezcano, Amit Kucheria, Zhang Rui,
Matthias Brugger
On Mon, Oct 31, 2022 at 6:08 PM Daniel Golle <daniel@makrotopia.org> wrote:
>
> Add compatible string 'mediatek,mt7986-thermal' for V3 thermal unit
> found in MT7981 and MT7986 SoCs.
>
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
> Documentation/devicetree/bindings/thermal/mediatek-thermal.txt | 1 +
> 1 file changed, 1 insertion(+)
Resending as the reply headers got lost...
Acked-by: Rob Herring <robh@kernel.org>
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] dt-bindings: thermal: mediatek: add compatible string for MT7986 SoC
2022-10-31 22:16 ` [PATCH 2/2] dt-bindings: thermal: mediatek: add compatible string for MT7986 SoC Daniel Golle
2022-10-31 23:08 ` Daniel Golle
2022-11-02 18:26 ` Rob Herring
@ 2022-11-02 20:43 ` Krzysztof Kozlowski
2022-11-30 12:09 ` Daniel Golle
2 siblings, 1 reply; 11+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-02 20:43 UTC (permalink / raw)
To: Daniel Golle, devicetree, linux-pm, linux-arm-kernel,
linux-mediatek, linux-kernel, Rafael J. Wysocki, Daniel Lezcano,
Amit Kucheria, Zhang Rui, Matthias Brugger, Krzysztof Kozlowski
On 31/10/2022 18:16, Daniel Golle wrote:
> Add compatible string 'mediatek,mt7986-thermal' for V3 thermal unit
> found in MT7981 and MT7986 SoCs.
>
> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> ---
> Documentation/devicetree/bindings/thermal/mediatek-thermal.txt | 1 +
> 1 file changed, 1 insertion(+)
>
> diff --git a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
> index 5c7e7bdd029abf..efc16ab5b22b5d 100644
> --- a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
> +++ b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
> @@ -13,6 +13,7 @@ Required properties:
> - "mediatek,mt2701-thermal" : For MT2701 family of SoCs
> - "mediatek,mt2712-thermal" : For MT2712 family of SoCs
> - "mediatek,mt7622-thermal" : For MT7622 SoC
> + - "mediatek,mt7986-thermal" : For MT7981 and MT7986 SoC
Then recommended is to have specific compatible followed by fallback (so
7986 followed by 7981)
Best regards,
Krzysztof
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] thermal: mediatek: add support for MT7986 and MT7981
2022-10-31 23:07 ` [PATCH 1/2] thermal: mediatek: add support for MT7986 and MT7981 Daniel Golle
@ 2022-11-29 11:53 ` Henry Yen (顏修溫)
2022-11-29 12:11 ` Daniel Golle
0 siblings, 1 reply; 11+ messages in thread
From: Henry Yen (顏修溫) @ 2022-11-29 11:53 UTC (permalink / raw)
To: linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
rui.zhang@intel.com, linux-pm@vger.kernel.org,
daniel.lezcano@linaro.org, linux-arm-kernel@lists.infradead.org,
amitk@kernel.org, rafael@kernel.org, matthias.bgg@gmail.com,
daniel@makrotopia.org
Cc: Steven Liu (劉人豪),
Henry Yen (顏修溫),
Xing Fang (方兴)
On Mon, 2022-10-31 at 23:07 +0000, Daniel Golle wrote:
> diff --git a/drivers/thermal/mtk_thermal.c
> b/drivers/thermal/mtk_thermal.c
>
> +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 - mt->adc_oe + 512;
Hi Daniel,
Regarding the conversion formula, I would suggest following the
original one, i.e., discarding "adc_oe" parameter as shown in [1].
This equation is derived based on hardware-specific theory, so any
arbitrary change could possibly lead to incorrect temperature output.
Thanks.
[1]
https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/+/baf36c7eef477aae1f8f2653b6c29e2caf48475b%5E%21/#F0
Henry
> +
> + return mt->degc_cali * 500 - tmp;
> +}
> +
> /**
> * mtk_thermal_get_bank - get bank
> * @bank: The bank
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] thermal: mediatek: add support for MT7986 and MT7981
2022-11-29 11:53 ` Henry Yen (顏修溫)
@ 2022-11-29 12:11 ` Daniel Golle
2022-11-30 7:43 ` Henry Yen (顏修溫)
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Golle @ 2022-11-29 12:11 UTC (permalink / raw)
To: Henry Yen (顏修溫)
Cc: linux-mediatek@lists.infradead.org, linux-kernel@vger.kernel.org,
rui.zhang@intel.com, linux-pm@vger.kernel.org,
daniel.lezcano@linaro.org, linux-arm-kernel@lists.infradead.org,
amitk@kernel.org, rafael@kernel.org, matthias.bgg@gmail.com,
Steven Liu (劉人豪),
Xing Fang (方兴)
On Tue, Nov 29, 2022 at 11:53:58AM +0000, Henry Yen (顏修溫) wrote:
> On Mon, 2022-10-31 at 23:07 +0000, Daniel Golle wrote:
> > diff --git a/drivers/thermal/mtk_thermal.c
> > b/drivers/thermal/mtk_thermal.c
> >
> > +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 - mt->adc_oe + 512;
>
> Hi Daniel,
>
> Regarding the conversion formula, I would suggest following the
> original one, i.e., discarding "adc_oe" parameter as shown in [1].
Ok, I see. According to the commit description it looked to me more
like adc_oe has been dropped by accident, it doesn't sound like it
happened on purpose:
"Refactor MT7986 thermal temperature calculation formula to
prevent loss of floating-point accuracy."
Hence it made sense to be to keep the parameter and really only
use the updated formula to not loose precision. Maybe you can inquire
with the original author if dropping adc_oe was intentional, despite
being unmentioned in the commit message.
> This equation is derived based on hardware-specific theory, so any
> arbitrary change could possibly lead to incorrect temperature output.
> Thanks.
On my BPi-R3 board I found the value 512 burned into the efuse, so in
practise the resulting calculated temperature is exactly the same on
this board.
If other MT7986 or MT7981 boards will have arbitrary values stored in
adc_oe field in the efuse because this value isn't even used during
the manufacturer's calibration process, then of course, there is no
choice other than dropping it here as well.
>
> [1]
>
> https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/+/baf36c7eef477aae1f8f2653b6c29e2caf48475b%5E%21/#F0
>
>
> Henry
>
> > +
> > + return mt->degc_cali * 500 - tmp;
> > +}
> > +
> > /**
> > * mtk_thermal_get_bank - get bank
> > * @bank: The bank
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 1/2] thermal: mediatek: add support for MT7986 and MT7981
2022-11-29 12:11 ` Daniel Golle
@ 2022-11-30 7:43 ` Henry Yen (顏修溫)
0 siblings, 0 replies; 11+ messages in thread
From: Henry Yen (顏修溫) @ 2022-11-30 7:43 UTC (permalink / raw)
To: daniel@makrotopia.org
Cc: linux-kernel@vger.kernel.org, linux-mediatek@lists.infradead.org,
rui.zhang@intel.com, Xing Fang (方兴),
linux-pm@vger.kernel.org, daniel.lezcano@linaro.org,
linux-arm-kernel@lists.infradead.org, amitk@kernel.org,
Steven Liu (劉人豪), rafael@kernel.org,
matthias.bgg@gmail.com
On Tue, 2022-11-29 at 12:11 +0000, Daniel Golle wrote:
> On Tue, Nov 29, 2022 at 11:53:58AM +0000, Henry Yen (顏修溫) wrote:
> > On Mon, 2022-10-31 at 23:07 +0000, Daniel Golle wrote:
> > > diff --git a/drivers/thermal/mtk_thermal.c
> > > b/drivers/thermal/mtk_thermal.c
> > >
> > > +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 - mt->adc_oe + 512;
> >
> > Hi Daniel,
> >
> > Regarding the conversion formula, I would suggest following the
> > original one, i.e., discarding "adc_oe" parameter as shown in [1].
>
> Ok, I see. According to the commit description it looked to me more
> like adc_oe has been dropped by accident, it doesn't sound like it
> happened on purpose:
> "Refactor MT7986 thermal temperature calculation formula to
> prevent loss of floating-point accuracy."
>
> Hence it made sense to be to keep the parameter and really only
> use the updated formula to not loose precision. Maybe you can inquire
> with the original author if dropping adc_oe was intentional, despite
> being unmentioned in the commit message.
Actually I'm just the original author who developes MT7986/MT7981
thermal driver and refactors this conversion formula. Getting rid of
"adc_oe" is indeed an intentional change, because back then our
hardware members indicated that this parameter shouldn't have been
used.
Thank you for your carefulness :)
>
> > This equation is derived based on hardware-specific theory, so any
> > arbitrary change could possibly lead to incorrect temperature
> > output.
> > Thanks.
>
> On my BPi-R3 board I found the value 512 burned into the efuse, so in
> practise the resulting calculated temperature is exactly the same on
> this board.
>
> If other MT7986 or MT7981 boards will have arbitrary values stored in
> adc_oe field in the efuse because this value isn't even used during
> the manufacturer's calibration process, then of course, there is no
> choice other than dropping it here as well.
>
The value of "adc_oe" is not necessarily 512. It could possibly vary
from board to board.
- Henry
> >
> > [1]
> >
> >
https://git01.mediatek.com/plugins/gitiles/openwrt/feeds/mtk-openwrt-feeds/+/baf36c7eef477aae1f8f2653b6c29e2caf48475b%5E%21/#F0
> >
> >
> > Henry
> >
> > > +
> > > + return mt->degc_cali * 500 - tmp;
> > > +}
> > > +
> > > /**
> > > * mtk_thermal_get_bank - get bank
> > > * @bank: The bank
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] dt-bindings: thermal: mediatek: add compatible string for MT7986 SoC
2022-11-02 20:43 ` Krzysztof Kozlowski
@ 2022-11-30 12:09 ` Daniel Golle
2022-11-30 12:27 ` Krzysztof Kozlowski
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Golle @ 2022-11-30 12:09 UTC (permalink / raw)
To: Krzysztof Kozlowski
Cc: devicetree, linux-pm, linux-arm-kernel, linux-mediatek,
linux-kernel, Rafael J. Wysocki, Daniel Lezcano, Amit Kucheria,
Zhang Rui, Matthias Brugger, Krzysztof Kozlowski
On Wed, Nov 02, 2022 at 04:43:35PM -0400, Krzysztof Kozlowski wrote:
> On 31/10/2022 18:16, Daniel Golle wrote:
> > Add compatible string 'mediatek,mt7986-thermal' for V3 thermal unit
> > found in MT7981 and MT7986 SoCs.
> >
> > Signed-off-by: Daniel Golle <daniel@makrotopia.org>
> > ---
> > Documentation/devicetree/bindings/thermal/mediatek-thermal.txt | 1 +
> > 1 file changed, 1 insertion(+)
> >
> > diff --git a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
> > index 5c7e7bdd029abf..efc16ab5b22b5d 100644
> > --- a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
> > +++ b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
> > @@ -13,6 +13,7 @@ Required properties:
> > - "mediatek,mt2701-thermal" : For MT2701 family of SoCs
> > - "mediatek,mt2712-thermal" : For MT2712 family of SoCs
> > - "mediatek,mt7622-thermal" : For MT7622 SoC
> > + - "mediatek,mt7986-thermal" : For MT7981 and MT7986 SoC
>
> Then recommended is to have specific compatible followed by fallback (so
> 7986 followed by 7981)
I'm a bit confused about the order you are suggesting. It may seem
counter-intuitive, but MT7986 was released before MT7981, the thermal
units found in both SoCs seems to be exactly identical.
Or are you suggesting to list MT7981 first to maintain alphabetical
order? Because in terms of precedence, MT7986 has been there first, and
hence I'd list 7986 first, followed by 7981, ie. the opposite of the
order you were suggesting.
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [PATCH 2/2] dt-bindings: thermal: mediatek: add compatible string for MT7986 SoC
2022-11-30 12:09 ` Daniel Golle
@ 2022-11-30 12:27 ` Krzysztof Kozlowski
0 siblings, 0 replies; 11+ messages in thread
From: Krzysztof Kozlowski @ 2022-11-30 12:27 UTC (permalink / raw)
To: Daniel Golle
Cc: devicetree, linux-pm, linux-arm-kernel, linux-mediatek,
linux-kernel, Rafael J. Wysocki, Daniel Lezcano, Amit Kucheria,
Zhang Rui, Matthias Brugger, Krzysztof Kozlowski
On 30/11/2022 13:09, Daniel Golle wrote:
> On Wed, Nov 02, 2022 at 04:43:35PM -0400, Krzysztof Kozlowski wrote:
>> On 31/10/2022 18:16, Daniel Golle wrote:
>>> Add compatible string 'mediatek,mt7986-thermal' for V3 thermal unit
>>> found in MT7981 and MT7986 SoCs.
>>>
>>> Signed-off-by: Daniel Golle <daniel@makrotopia.org>
>>> ---
>>> Documentation/devicetree/bindings/thermal/mediatek-thermal.txt | 1 +
>>> 1 file changed, 1 insertion(+)
>>>
>>> diff --git a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
>>> index 5c7e7bdd029abf..efc16ab5b22b5d 100644
>>> --- a/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
>>> +++ b/Documentation/devicetree/bindings/thermal/mediatek-thermal.txt
>>> @@ -13,6 +13,7 @@ Required properties:
>>> - "mediatek,mt2701-thermal" : For MT2701 family of SoCs
>>> - "mediatek,mt2712-thermal" : For MT2712 family of SoCs
>>> - "mediatek,mt7622-thermal" : For MT7622 SoC
>>> + - "mediatek,mt7986-thermal" : For MT7981 and MT7986 SoC
>>
>> Then recommended is to have specific compatible followed by fallback (so
>> 7986 followed by 7981)
>
> I'm a bit confused about the order you are suggesting. It may seem
> counter-intuitive, but MT7986 was released before MT7981, the thermal
> units found in both SoCs seems to be exactly identical.
> Or are you suggesting to list MT7981 first to maintain alphabetical
> order? Because in terms of precedence, MT7986 has been there first, and
> hence I'd list 7986 first, followed by 7981, ie. the opposite of the
> order you were suggesting.
>
I have no clue which came first. Choose whatever is reasonable.
Best regards,
Krzysztof
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2022-11-30 12:28 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-10-31 22:15 [PATCH 1/2] thermal: mediatek: add support for MT7986 and MT7981 Daniel Golle
2022-10-31 22:16 ` [PATCH 2/2] dt-bindings: thermal: mediatek: add compatible string for MT7986 SoC Daniel Golle
2022-10-31 23:08 ` Daniel Golle
2022-11-02 18:26 ` Rob Herring
2022-11-02 20:43 ` Krzysztof Kozlowski
2022-11-30 12:09 ` Daniel Golle
2022-11-30 12:27 ` Krzysztof Kozlowski
2022-10-31 23:07 ` [PATCH 1/2] thermal: mediatek: add support for MT7986 and MT7981 Daniel Golle
2022-11-29 11:53 ` Henry Yen (顏修溫)
2022-11-29 12:11 ` Daniel Golle
2022-11-30 7:43 ` Henry Yen (顏修溫)
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).