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

thermal: qoriq: Update the settings for TMUv2

For TMU v2, TMSAR registers need to be set properly to get the
accurate temperature values.
Also the temperature read needs to be converted to degree Celsius
since it is in degrees Kelvin.

Signed-off-by: Yuantian Tang <andy.tang@nxp.com>
Signed-off-by: Daniel Lezcano <daniel.lezcano@linaro.org>
Link: https://lore.kernel.org/r/20200526060212.4118-1-andy.tang@nxp.com

authored by

Yuantian Tang and committed by
Daniel Lezcano
47fa116e b03628b7

+24 -2
+24 -2
drivers/thermal/qoriq_thermal.c
··· 11 11 #include <linux/regmap.h> 12 12 #include <linux/sizes.h> 13 13 #include <linux/thermal.h> 14 + #include <linux/units.h> 14 15 15 16 #include "thermal_core.h" 16 17 #include "thermal_hwmon.h" ··· 24 23 #define TMTMIR_DEFAULT 0x0000000f 25 24 #define TIER_DISABLE 0x0 26 25 #define TEUMR0_V2 0x51009c00 26 + #define TMSARA_V2 0xe 27 27 #define TMU_VER1 0x1 28 28 #define TMU_VER2 0x2 29 29 ··· 52 50 * Site Register 53 51 */ 54 52 #define TRITSR_V BIT(31) 53 + #define REGS_V2_TMSAR(n) (0x304 + 16 * (n)) /* TMU monitoring 54 + * site adjustment register 55 + */ 55 56 #define REGS_TTRnCR(n) (0xf10 + 4 * (n)) /* Temperature Range n 56 57 * Control Register 57 58 */ ··· 90 85 /* 91 86 * REGS_TRITSR(id) has the following layout: 92 87 * 88 + * For TMU Rev1: 93 89 * 31 ... 7 6 5 4 3 2 1 0 94 90 * V TEMP 95 91 * 96 92 * Where V bit signifies if the measurement is ready and is 97 93 * within sensor range. TEMP is an 8 bit value representing 98 - * temperature in C. 94 + * temperature in Celsius. 95 + 96 + * For TMU Rev2: 97 + * 31 ... 8 7 6 5 4 3 2 1 0 98 + * V TEMP 99 + * 100 + * Where V bit signifies if the measurement is ready and is 101 + * within sensor range. TEMP is an 9 bit value representing 102 + * temperature in KelVin. 99 103 */ 100 104 if (regmap_read_poll_timeout(qdata->regmap, 101 105 REGS_TRITSR(qsensor->id), ··· 114 100 10 * USEC_PER_MSEC)) 115 101 return -ENODATA; 116 102 117 - *temp = (val & 0xff) * 1000; 103 + if (qdata->ver == TMU_VER1) 104 + *temp = (val & GENMASK(7, 0)) * MILLIDEGREE_PER_DEGREE; 105 + else 106 + *temp = kelvin_to_millicelsius(val & GENMASK(8, 0)); 118 107 119 108 return 0; 120 109 } ··· 209 192 210 193 static void qoriq_tmu_init_device(struct qoriq_tmu_data *data) 211 194 { 195 + int i; 196 + 212 197 /* Disable interrupt, using polling instead */ 213 198 regmap_write(data->regmap, REGS_TIER, TIER_DISABLE); 214 199 ··· 221 202 } else { 222 203 regmap_write(data->regmap, REGS_V2_TMTMIR, TMTMIR_DEFAULT); 223 204 regmap_write(data->regmap, REGS_V2_TEUMR(0), TEUMR0_V2); 205 + for (i = 0; i < SITES_MAX; i++) 206 + regmap_write(data->regmap, REGS_V2_TMSAR(i), TMSARA_V2); 224 207 } 225 208 226 209 /* Disable monitoring */ ··· 233 212 regmap_reg_range(REGS_TMR, REGS_TSCFGR), 234 213 regmap_reg_range(REGS_TTRnCR(0), REGS_TTRnCR(3)), 235 214 regmap_reg_range(REGS_V2_TEUMR(0), REGS_V2_TEUMR(2)), 215 + regmap_reg_range(REGS_V2_TMSAR(0), REGS_V2_TMSAR(15)), 236 216 regmap_reg_range(REGS_IPBRR(0), REGS_IPBRR(1)), 237 217 /* Read only registers below */ 238 218 regmap_reg_range(REGS_TRITSR(0), REGS_TRITSR(15)),