Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

thermal/drivers/qoriq: Only enable supported sensors

There are MAX 16 sensors, but not all of them supported. Such as
i.MX8MQ, there are only 3 sensors. Enabling all 16 sensors will
touch reserved bits from i.MX8MQ reference mannual, and TMU will stuck,
temperature will not update anymore.

Fixes: 45038e03d633 ("thermal: qoriq: Enable all sensors before registering them")
Signed-off-by: Peng Fan <peng.fan@nxp.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20230516083746.63436-3-peng.fan@oss.nxp.com

authored by

Peng Fan and committed by
Daniel Lezcano
9301575d 5474e98b

+19 -11
+19 -11
drivers/thermal/qoriq_thermal.c
··· 31 31 #define TMR_DISABLE 0x0 32 32 #define TMR_ME 0x80000000 33 33 #define TMR_ALPF 0x0c000000 34 - #define TMR_MSITE_ALL GENMASK(15, 0) 35 34 36 35 #define REGS_TMTMIR 0x008 /* Temperature measurement interval Register */ 37 36 #define TMTMIR_DEFAULT 0x0000000f ··· 104 105 * within sensor range. TEMP is an 9 bit value representing 105 106 * temperature in KelVin. 106 107 */ 108 + 109 + regmap_read(qdata->regmap, REGS_TMR, &val); 110 + if (!(val & TMR_ME)) 111 + return -EAGAIN; 112 + 107 113 if (regmap_read_poll_timeout(qdata->regmap, 108 114 REGS_TRITSR(qsensor->id), 109 115 val, ··· 132 128 static int qoriq_tmu_register_tmu_zone(struct device *dev, 133 129 struct qoriq_tmu_data *qdata) 134 130 { 135 - int id; 136 - 137 - if (qdata->ver == TMU_VER1) { 138 - regmap_write(qdata->regmap, REGS_TMR, 139 - TMR_MSITE_ALL | TMR_ME | TMR_ALPF); 140 - } else { 141 - regmap_write(qdata->regmap, REGS_V2_TMSR, TMR_MSITE_ALL); 142 - regmap_write(qdata->regmap, REGS_TMR, TMR_ME | TMR_ALPF_V2); 143 - } 131 + int id, sites = 0; 144 132 145 133 for (id = 0; id < SITES_MAX; id++) { 146 134 struct thermal_zone_device *tzd; ··· 149 153 if (ret == -ENODEV) 150 154 continue; 151 155 152 - regmap_write(qdata->regmap, REGS_TMR, TMR_DISABLE); 153 156 return ret; 154 157 } 158 + 159 + if (qdata->ver == TMU_VER1) 160 + sites |= 0x1 << (15 - id); 161 + else 162 + sites |= 0x1 << id; 155 163 156 164 if (devm_thermal_add_hwmon_sysfs(dev, tzd)) 157 165 dev_warn(dev, 158 166 "Failed to add hwmon sysfs attributes\n"); 167 + } 159 168 169 + if (sites) { 170 + if (qdata->ver == TMU_VER1) { 171 + regmap_write(qdata->regmap, REGS_TMR, TMR_ME | TMR_ALPF | sites); 172 + } else { 173 + regmap_write(qdata->regmap, REGS_V2_TMSR, sites); 174 + regmap_write(qdata->regmap, REGS_TMR, TMR_ME | TMR_ALPF_V2); 175 + } 160 176 } 161 177 162 178 return 0;