Merge tag 'soundwire-6.6-fixes' of git://git.kernel.org/pub/scm/linux/kernel/git...
[platform/kernel/linux-starfive.git] / drivers / thermal / qoriq_thermal.c
index e587563..ccc2eea 100644 (file)
@@ -31,7 +31,6 @@
 #define TMR_DISABLE    0x0
 #define TMR_ME         0x80000000
 #define TMR_ALPF       0x0c000000
-#define TMR_MSITE_ALL  GENMASK(15, 0)
 
 #define REGS_TMTMIR    0x008   /* Temperature measurement interval Register */
 #define TMTMIR_DEFAULT 0x0000000f
@@ -51,6 +50,7 @@
                                            * Site Register
                                            */
 #define TRITSR_V       BIT(31)
+#define TRITSR_TP5     BIT(9)
 #define REGS_V2_TMSAR(n)       (0x304 + 16 * (n))      /* TMU monitoring
                                                * site adjustment register
                                                */
@@ -105,6 +105,11 @@ static int tmu_get_temp(struct thermal_zone_device *tz, int *temp)
         * within sensor range. TEMP is an 9 bit value representing
         * temperature in KelVin.
         */
+
+       regmap_read(qdata->regmap, REGS_TMR, &val);
+       if (!(val & TMR_ME))
+               return -EAGAIN;
+
        if (regmap_read_poll_timeout(qdata->regmap,
                                     REGS_TRITSR(qsensor->id),
                                     val,
@@ -113,10 +118,15 @@ static int tmu_get_temp(struct thermal_zone_device *tz, int *temp)
                                     10 * USEC_PER_MSEC))
                return -ENODATA;
 
-       if (qdata->ver == TMU_VER1)
+       if (qdata->ver == TMU_VER1) {
                *temp = (val & GENMASK(7, 0)) * MILLIDEGREE_PER_DEGREE;
-       else
-               *temp = kelvin_to_millicelsius(val & GENMASK(8, 0));
+       } else {
+               if (val & TRITSR_TP5)
+                       *temp = milli_kelvin_to_millicelsius((val & GENMASK(8, 0)) *
+                                                            MILLIDEGREE_PER_DEGREE + 500);
+               else
+                       *temp = kelvin_to_millicelsius(val & GENMASK(8, 0));
+       }
 
        return 0;
 }
@@ -128,15 +138,7 @@ static const struct thermal_zone_device_ops tmu_tz_ops = {
 static int qoriq_tmu_register_tmu_zone(struct device *dev,
                                       struct qoriq_tmu_data *qdata)
 {
-       int id;
-
-       if (qdata->ver == TMU_VER1) {
-               regmap_write(qdata->regmap, REGS_TMR,
-                            TMR_MSITE_ALL | TMR_ME | TMR_ALPF);
-       } else {
-               regmap_write(qdata->regmap, REGS_V2_TMSR, TMR_MSITE_ALL);
-               regmap_write(qdata->regmap, REGS_TMR, TMR_ME | TMR_ALPF_V2);
-       }
+       int id, sites = 0;
 
        for (id = 0; id < SITES_MAX; id++) {
                struct thermal_zone_device *tzd;
@@ -153,14 +155,24 @@ static int qoriq_tmu_register_tmu_zone(struct device *dev,
                        if (ret == -ENODEV)
                                continue;
 
-                       regmap_write(qdata->regmap, REGS_TMR, TMR_DISABLE);
                        return ret;
                }
 
-               if (devm_thermal_add_hwmon_sysfs(dev, tzd))
-                       dev_warn(dev,
-                                "Failed to add hwmon sysfs attributes\n");
+               if (qdata->ver == TMU_VER1)
+                       sites |= 0x1 << (15 - id);
+               else
+                       sites |= 0x1 << id;
+
+               devm_thermal_add_hwmon_sysfs(dev, tzd);
+       }
 
+       if (sites) {
+               if (qdata->ver == TMU_VER1) {
+                       regmap_write(qdata->regmap, REGS_TMR, TMR_ME | TMR_ALPF | sites);
+               } else {
+                       regmap_write(qdata->regmap, REGS_V2_TMSR, sites);
+                       regmap_write(qdata->regmap, REGS_TMR, TMR_ME | TMR_ALPF_V2);
+               }
        }
 
        return 0;
@@ -208,8 +220,6 @@ static int qoriq_tmu_calibration(struct device *dev,
 
 static void qoriq_tmu_init_device(struct qoriq_tmu_data *data)
 {
-       int i;
-
        /* Disable interrupt, using polling instead */
        regmap_write(data->regmap, REGS_TIER, TIER_DISABLE);
 
@@ -220,8 +230,6 @@ static void qoriq_tmu_init_device(struct qoriq_tmu_data *data)
        } else {
                regmap_write(data->regmap, REGS_V2_TMTMIR, TMTMIR_DEFAULT);
                regmap_write(data->regmap, REGS_V2_TEUMR(0), TEUMR0_V2);
-               for (i = 0; i < SITES_MAX; i++)
-                       regmap_write(data->regmap, REGS_V2_TMSAR(i), TMSARA_V2);
        }
 
        /* Disable monitoring */
@@ -230,7 +238,7 @@ static void qoriq_tmu_init_device(struct qoriq_tmu_data *data)
 
 static const struct regmap_range qoriq_yes_ranges[] = {
        regmap_reg_range(REGS_TMR, REGS_TSCFGR),
-       regmap_reg_range(REGS_TTRnCR(0), REGS_TTRnCR(3)),
+       regmap_reg_range(REGS_TTRnCR(0), REGS_TTRnCR(15)),
        regmap_reg_range(REGS_V2_TEUMR(0), REGS_V2_TEUMR(2)),
        regmap_reg_range(REGS_V2_TMSAR(0), REGS_V2_TMSAR(15)),
        regmap_reg_range(REGS_IPBRR(0), REGS_IPBRR(1)),