]> asedeno.scripts.mit.edu Git - linux.git/blobdiff - drivers/thermal/mtk_thermal.c
Merge branch 'work.mount' of git://git.kernel.org/pub/scm/linux/kernel/git/viro/vfs
[linux.git] / drivers / thermal / mtk_thermal.c
index 7737f14846f9e77b0515093d33d13a19c96bf13a..1e61c09153c9abf0d02eb43d4ff21ba925da9415 100644 (file)
@@ -3,6 +3,7 @@
  * Author: Hanyi Wu <hanyi.wu@mediatek.com>
  *         Sascha Hauer <s.hauer@pengutronix.de>
  *         Dawei Chien <dawei.chien@mediatek.com>
+ *         Louis Yu <louis.yu@mediatek.com>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License version 2 as
 
 /*
  * Layout of the fuses providing the calibration data
- * These macros could be used for both MT8173 and MT2701.
- * MT8173 has five sensors and need five VTS calibration data,
- * and MT2701 has three sensors and need three VTS calibration data.
+ * These macros could be used for MT8173, MT2701, and MT2712.
+ * MT8173 has 5 sensors and needs 5 VTS calibration data.
+ * MT2701 has 3 sensors and needs 3 VTS calibration data.
+ * MT2712 has 4 sensors and needs 4 VTS calibration data.
  */
 #define MT8173_CALIB_BUF0_VALID                BIT(0)
 #define MT8173_CALIB_BUF1_ADC_GE(x)    (((x) >> 22) & 0x3ff)
 #define MT8173_CALIB_BUF2_VTS_TSABB(x) (((x) >> 14) & 0x1ff)
 #define MT8173_CALIB_BUF0_DEGC_CALI(x) (((x) >> 1) & 0x3f)
 #define MT8173_CALIB_BUF0_O_SLOPE(x)   (((x) >> 26) & 0x3f)
+#define MT8173_CALIB_BUF0_O_SLOPE_SIGN(x)      (((x) >> 7) & 0x1)
+#define MT8173_CALIB_BUF1_ID(x)        (((x) >> 9) & 0x1)
 
 /* MT2701 thermal sensors */
 #define MT2701_TS1     0
 /* The total number of temperature sensors in the MT2701 */
 #define MT2701_NUM_SENSORS     3
 
-#define THERMAL_NAME    "mtk-thermal"
-
 /* The number of sensing points per bank */
 #define MT2701_NUM_SENSORS_PER_ZONE    3
 
+/* MT2712 thermal sensors */
+#define MT2712_TS1     0
+#define MT2712_TS2     1
+#define MT2712_TS3     2
+#define MT2712_TS4     3
+
+/* AUXADC channel 11 is used for the temperature sensors */
+#define MT2712_TEMP_AUXADC_CHANNEL     11
+
+/* The total number of temperature sensors in the MT2712 */
+#define MT2712_NUM_SENSORS     4
+
+/* The number of sensing points per bank */
+#define MT2712_NUM_SENSORS_PER_ZONE    4
+
+#define THERMAL_NAME    "mtk-thermal"
+
 struct mtk_thermal;
 
 struct thermal_bank_cfg {
@@ -215,6 +234,21 @@ static const int mt2701_adcpnp[MT2701_NUM_SENSORS_PER_ZONE] = {
 
 static const int mt2701_mux_values[MT2701_NUM_SENSORS] = { 0, 1, 16 };
 
+/* MT2712 thermal sensor data */
+static const int mt2712_bank_data[MT2712_NUM_SENSORS] = {
+       MT2712_TS1, MT2712_TS2, MT2712_TS3, MT2712_TS4
+};
+
+static const int mt2712_msr[MT2712_NUM_SENSORS_PER_ZONE] = {
+       TEMP_MSR0, TEMP_MSR1, TEMP_MSR2, TEMP_MSR3
+};
+
+static const int mt2712_adcpnp[MT2712_NUM_SENSORS_PER_ZONE] = {
+       TEMP_ADCPNP0, TEMP_ADCPNP1, TEMP_ADCPNP2, TEMP_ADCPNP3
+};
+
+static const int mt2712_mux_values[MT2712_NUM_SENSORS] = { 0, 1, 2, 3 };
+
 /**
  * The MT8173 thermal controller has four banks. Each bank can read up to
  * four temperature sensors simultaneously. The MT8173 has a total of 5
@@ -277,6 +311,31 @@ static const struct mtk_thermal_data mt2701_thermal_data = {
        .sensor_mux_values = mt2701_mux_values,
 };
 
+/**
+ * The MT2712 thermal controller has one bank, which can read up to
+ * four temperature sensors simultaneously. The MT2712 has a total of 4
+ * temperature sensors.
+ *
+ * The thermal core only gets the maximum temperature of this one bank,
+ * so the bank concept wouldn't be necessary here. However, the SVS (Smart
+ * Voltage Scaling) unit makes its decisions based on the same bank
+ * data.
+ */
+static const struct mtk_thermal_data mt2712_thermal_data = {
+       .auxadc_channel = MT2712_TEMP_AUXADC_CHANNEL,
+       .num_banks = 1,
+       .num_sensors = MT2712_NUM_SENSORS,
+       .bank_data = {
+               {
+                       .num_sensors = 4,
+                       .sensors = mt2712_bank_data,
+               },
+       },
+       .msr = mt2712_msr,
+       .adcpnp = mt2712_adcpnp,
+       .sensor_mux_values = mt2712_mux_values,
+};
+
 /**
  * raw_to_mcelsius - convert a raw ADC value to mcelsius
  * @mt:                The thermal controller
@@ -552,7 +611,11 @@ static int mtk_thermal_get_calibration_data(struct device *dev,
                mt->vts[MT8173_TS4] = MT8173_CALIB_BUF2_VTS_TS4(buf[2]);
                mt->vts[MT8173_TSABB] = MT8173_CALIB_BUF2_VTS_TSABB(buf[2]);
                mt->degc_cali = MT8173_CALIB_BUF0_DEGC_CALI(buf[0]);
-               mt->o_slope = MT8173_CALIB_BUF0_O_SLOPE(buf[0]);
+               if (MT8173_CALIB_BUF1_ID(buf[1]) &
+                   MT8173_CALIB_BUF0_O_SLOPE_SIGN(buf[0]))
+                       mt->o_slope = -MT8173_CALIB_BUF0_O_SLOPE(buf[0]);
+               else
+                       mt->o_slope = MT8173_CALIB_BUF0_O_SLOPE(buf[0]);
        } else {
                dev_info(dev, "Device not calibrated, using default calibration values\n");
        }
@@ -571,6 +634,10 @@ static const struct of_device_id mtk_thermal_of_match[] = {
        {
                .compatible = "mediatek,mt2701-thermal",
                .data = (void *)&mt2701_thermal_data,
+       },
+       {
+               .compatible = "mediatek,mt2712-thermal",
+               .data = (void *)&mt2712_thermal_data,
        }, {
        },
 };
@@ -645,16 +712,16 @@ static int mtk_thermal_probe(struct platform_device *pdev)
                return -EINVAL;
        }
 
+       ret = device_reset(&pdev->dev);
+       if (ret)
+               return ret;
+
        ret = clk_prepare_enable(mt->clk_auxadc);
        if (ret) {
                dev_err(&pdev->dev, "Can't enable auxadc clk: %d\n", ret);
                return ret;
        }
 
-       ret = device_reset(&pdev->dev);
-       if (ret)
-               goto err_disable_clk_auxadc;
-
        ret = clk_prepare_enable(mt->clk_peri_therm);
        if (ret) {
                dev_err(&pdev->dev, "Can't enable peri clk: %d\n", ret);
@@ -705,6 +772,7 @@ static struct platform_driver mtk_thermal_driver = {
 
 module_platform_driver(mtk_thermal_driver);
 
+MODULE_AUTHOR("Louis Yu <louis.yu@mediatek.com>");
 MODULE_AUTHOR("Dawei Chien <dawei.chien@mediatek.com>");
 MODULE_AUTHOR("Sascha Hauer <s.hauer@pengutronix.de>");
 MODULE_AUTHOR("Hanyi Wu <hanyi.wu@mediatek.com>");