Skip to content

Commit a321ced

Browse files
Carsten Emdetorvalds
authored andcommitted
drivers/hwmon/coretemp.c: get TjMax value from MSR
The MSR IA32_TEMPERATURE_TARGET contains the TjMax value in the newer Intel processors. Signed-off-by: Huaxu Wan <huaxu.wan@linux.intel.com> Signed-off-by: Carsten Emde <C.Emde@osadl.org> Cc: Jean Delvare <khali@linux-fr.org> Cc: Valdis Kletnieks <valdis.kletnieks@vt.edu> Cc: Henrique de Moraes Holschuh <hmh@hmh.eng.br> Cc: Yong Wang <yong.y.wang@linux.intel.com> Cc: Rudolf Marek <r.marek@assembler.cz> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
1 parent 5db47b0 commit a321ced

File tree

2 files changed

+59
-4
lines changed

2 files changed

+59
-4
lines changed

arch/x86/include/asm/msr-index.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,8 @@
236236

237237
#define MSR_IA32_MISC_ENABLE 0x000001a0
238238

239+
#define MSR_IA32_TEMPERATURE_TARGET 0x000001a2
240+
239241
/* MISC_ENABLE bits: architectural */
240242
#define MSR_IA32_MISC_ENABLE_FAST_STRING (1ULL << 0)
241243
#define MSR_IA32_MISC_ENABLE_TCC (1ULL << 1)

drivers/hwmon/coretemp.c

Lines changed: 57 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -241,6 +241,55 @@ static int __devinit adjust_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *
241241
return tjmax;
242242
}
243243

244+
static int __devinit get_tjmax(struct cpuinfo_x86 *c, u32 id,
245+
struct device *dev)
246+
{
247+
/* The 100C is default for both mobile and non mobile CPUs */
248+
int err;
249+
u32 eax, edx;
250+
u32 val;
251+
252+
/* A new feature of current Intel(R) processors, the
253+
IA32_TEMPERATURE_TARGET contains the TjMax value */
254+
err = rdmsr_safe_on_cpu(id, MSR_IA32_TEMPERATURE_TARGET, &eax, &edx);
255+
if (err) {
256+
dev_warn(dev, "Unable to read TjMax from CPU.\n");
257+
} else {
258+
val = (eax >> 16) & 0xff;
259+
/*
260+
* If the TjMax is not plausible, an assumption
261+
* will be used
262+
*/
263+
if ((val > 80) && (val < 120)) {
264+
dev_info(dev, "TjMax is %d C.\n", val);
265+
return val * 1000;
266+
}
267+
}
268+
269+
/*
270+
* An assumption is made for early CPUs and unreadable MSR.
271+
* NOTE: the given value may not be correct.
272+
*/
273+
274+
switch (c->x86_model) {
275+
case 0xe:
276+
case 0xf:
277+
case 0x16:
278+
case 0x1a:
279+
dev_warn(dev, "TjMax is assumed as 100 C!\n");
280+
return 100000;
281+
break;
282+
case 0x17:
283+
case 0x1c: /* Atom CPUs */
284+
return adjust_tjmax(c, id, dev);
285+
break;
286+
default:
287+
dev_warn(dev, "CPU (model=0x%x) is not supported yet,"
288+
" using default TjMax of 100C.\n", c->x86_model);
289+
return 100000;
290+
}
291+
}
292+
244293
static int __devinit coretemp_probe(struct platform_device *pdev)
245294
{
246295
struct coretemp_data *data;
@@ -283,14 +332,18 @@ static int __devinit coretemp_probe(struct platform_device *pdev)
283332
}
284333
}
285334

286-
data->tjmax = adjust_tjmax(c, data->id, &pdev->dev);
335+
data->tjmax = get_tjmax(c, data->id, &pdev->dev);
287336
platform_set_drvdata(pdev, data);
288337

289-
/* read the still undocumented IA32_TEMPERATURE_TARGET it exists
290-
on older CPUs but not in this register, Atoms don't have it either */
338+
/*
339+
* read the still undocumented IA32_TEMPERATURE_TARGET. It exists
340+
* on older CPUs but not in this register,
341+
* Atoms don't have it either.
342+
*/
291343

292344
if ((c->x86_model > 0xe) && (c->x86_model != 0x1c)) {
293-
err = rdmsr_safe_on_cpu(data->id, 0x1a2, &eax, &edx);
345+
err = rdmsr_safe_on_cpu(data->id, MSR_IA32_TEMPERATURE_TARGET,
346+
&eax, &edx);
294347
if (err) {
295348
dev_warn(&pdev->dev, "Unable to read"
296349
" IA32_TEMPERATURE_TARGET MSR\n");

0 commit comments

Comments
 (0)