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

Configure Feed

Select the types of activity you want to include in your feed.

Merge branch 'hwmon-for-linus' of git://github.com/groeck/linux

* 'hwmon-for-linus' of git://github.com/groeck/linux:
hwmon: (coretemp) remove struct platform_data * parameter from create_core_data()
hwmon: (coretemp) constify static data
hwmon: (coretemp) don't use kernel assigned CPU number as platform device ID
hwmon: (ds620) Fix handling of negative temperatures
hwmon: (w83791d) rename prototype parameter from 'register' to 'reg'
hwmon: (coretemp) Don't use threshold registers for tempX_max
hwmon: (coretemp) Let the user force TjMax
hwmon: (coretemp) Drop duplicate function get_pkg_tjmax

+47 -166
+4 -10
Documentation/hwmon/coretemp
··· 35 35 All Sysfs entries are named with their core_id (represented here by 'X'). 36 36 tempX_input - Core temperature (in millidegrees Celsius). 37 37 tempX_max - All cooling devices should be turned on (on Core2). 38 - Initialized with IA32_THERM_INTERRUPT. When the CPU 39 - temperature reaches this temperature, an interrupt is 40 - generated and tempX_max_alarm is set. 41 - tempX_max_hyst - If the CPU temperature falls below than temperature, 42 - an interrupt is generated and tempX_max_alarm is reset. 43 - tempX_max_alarm - Set if the temperature reaches or exceeds tempX_max. 44 - Reset if the temperature drops to or below tempX_max_hyst. 45 38 tempX_crit - Maximum junction temperature (in millidegrees Celsius). 46 39 tempX_crit_alarm - Set when Out-of-spec bit is set, never clears. 47 40 Correct CPU operation is no longer guaranteed. ··· 42 49 number. For Package temp, this will be "Physical id Y", 43 50 where Y is the package number. 44 51 45 - The TjMax temperature is set to 85 degrees C if undocumented model specific 46 - register (UMSR) 0xee has bit 30 set. If not the TjMax is 100 degrees C as 47 - (sometimes) documented in processor datasheet. 52 + On CPU models which support it, TjMax is read from a model-specific register. 53 + On other models, it is set to an arbitrary value based on weak heuristics. 54 + If these heuristics don't work for you, you can pass the correct TjMax value 55 + as a module parameter (tjmax). 48 56 49 57 Appendix A. Known TjMax lists (TBD): 50 58 Some information comes from ark.intel.com
+40 -153
drivers/hwmon/coretemp.c
··· 36 36 #include <linux/cpu.h> 37 37 #include <linux/pci.h> 38 38 #include <linux/smp.h> 39 + #include <linux/moduleparam.h> 39 40 #include <asm/msr.h> 40 41 #include <asm/processor.h> 41 42 42 43 #define DRVNAME "coretemp" 43 44 45 + /* 46 + * force_tjmax only matters when TjMax can't be read from the CPU itself. 47 + * When set, it replaces the driver's suboptimal heuristic. 48 + */ 49 + static int force_tjmax; 50 + module_param_named(tjmax, force_tjmax, int, 0444); 51 + MODULE_PARM_DESC(tjmax, "TjMax value in degrees Celsius"); 52 + 44 53 #define BASE_SYSFS_ATTR_NO 2 /* Sysfs Base attr no for coretemp */ 45 54 #define NUM_REAL_CORES 16 /* Number of Real cores per cpu */ 46 55 #define CORETEMP_NAME_LENGTH 17 /* String Length of attrs */ 47 56 #define MAX_CORE_ATTRS 4 /* Maximum no of basic attrs */ 48 - #define MAX_THRESH_ATTRS 3 /* Maximum no of Threshold attrs */ 49 - #define TOTAL_ATTRS (MAX_CORE_ATTRS + MAX_THRESH_ATTRS) 57 + #define TOTAL_ATTRS (MAX_CORE_ATTRS + 1) 50 58 #define MAX_CORE_DATA (NUM_REAL_CORES + BASE_SYSFS_ATTR_NO) 51 59 52 60 #ifdef CONFIG_SMP ··· 77 69 * This value is passed as "id" field to rdmsr/wrmsr functions. 78 70 * @status_reg: One of IA32_THERM_STATUS or IA32_PACKAGE_THERM_STATUS, 79 71 * from where the temperature values should be read. 80 - * @intrpt_reg: One of IA32_THERM_INTERRUPT or IA32_PACKAGE_THERM_INTERRUPT, 81 - * from where the thresholds are read. 82 72 * @attr_size: Total number of pre-core attrs displayed in the sysfs. 83 73 * @is_pkg_data: If this is 1, the temp_data holds pkgtemp data. 84 74 * Otherwise, temp_data holds coretemp data. ··· 85 79 struct temp_data { 86 80 int temp; 87 81 int ttarget; 88 - int tmin; 89 82 int tjmax; 90 83 unsigned long last_updated; 91 84 unsigned int cpu; 92 85 u32 cpu_core_id; 93 86 u32 status_reg; 94 - u32 intrpt_reg; 95 87 int attr_size; 96 88 bool is_pkg_data; 97 89 bool valid; ··· 147 143 return sprintf(buf, "%d\n", (eax >> 5) & 1); 148 144 } 149 145 150 - static ssize_t show_max_alarm(struct device *dev, 151 - struct device_attribute *devattr, char *buf) 152 - { 153 - u32 eax, edx; 154 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 155 - struct platform_data *pdata = dev_get_drvdata(dev); 156 - struct temp_data *tdata = pdata->core_data[attr->index]; 157 - 158 - rdmsr_on_cpu(tdata->cpu, tdata->status_reg, &eax, &edx); 159 - 160 - return sprintf(buf, "%d\n", !!(eax & THERM_STATUS_THRESHOLD1)); 161 - } 162 - 163 146 static ssize_t show_tjmax(struct device *dev, 164 147 struct device_attribute *devattr, char *buf) 165 148 { ··· 163 172 struct platform_data *pdata = dev_get_drvdata(dev); 164 173 165 174 return sprintf(buf, "%d\n", pdata->core_data[attr->index]->ttarget); 166 - } 167 - 168 - static ssize_t store_ttarget(struct device *dev, 169 - struct device_attribute *devattr, 170 - const char *buf, size_t count) 171 - { 172 - struct platform_data *pdata = dev_get_drvdata(dev); 173 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 174 - struct temp_data *tdata = pdata->core_data[attr->index]; 175 - u32 eax, edx; 176 - unsigned long val; 177 - int diff; 178 - 179 - if (strict_strtoul(buf, 10, &val)) 180 - return -EINVAL; 181 - 182 - /* 183 - * THERM_MASK_THRESHOLD1 is 7 bits wide. Values are entered in terms 184 - * of milli degree celsius. Hence don't accept val > (127 * 1000) 185 - */ 186 - if (val > tdata->tjmax || val > 127000) 187 - return -EINVAL; 188 - 189 - diff = (tdata->tjmax - val) / 1000; 190 - 191 - mutex_lock(&tdata->update_lock); 192 - rdmsr_on_cpu(tdata->cpu, tdata->intrpt_reg, &eax, &edx); 193 - eax = (eax & ~THERM_MASK_THRESHOLD1) | 194 - (diff << THERM_SHIFT_THRESHOLD1); 195 - wrmsr_on_cpu(tdata->cpu, tdata->intrpt_reg, eax, edx); 196 - tdata->ttarget = val; 197 - mutex_unlock(&tdata->update_lock); 198 - 199 - return count; 200 - } 201 - 202 - static ssize_t show_tmin(struct device *dev, 203 - struct device_attribute *devattr, char *buf) 204 - { 205 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 206 - struct platform_data *pdata = dev_get_drvdata(dev); 207 - 208 - return sprintf(buf, "%d\n", pdata->core_data[attr->index]->tmin); 209 - } 210 - 211 - static ssize_t store_tmin(struct device *dev, 212 - struct device_attribute *devattr, 213 - const char *buf, size_t count) 214 - { 215 - struct platform_data *pdata = dev_get_drvdata(dev); 216 - struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr); 217 - struct temp_data *tdata = pdata->core_data[attr->index]; 218 - u32 eax, edx; 219 - unsigned long val; 220 - int diff; 221 - 222 - if (strict_strtoul(buf, 10, &val)) 223 - return -EINVAL; 224 - 225 - /* 226 - * THERM_MASK_THRESHOLD0 is 7 bits wide. Values are entered in terms 227 - * of milli degree celsius. Hence don't accept val > (127 * 1000) 228 - */ 229 - if (val > tdata->tjmax || val > 127000) 230 - return -EINVAL; 231 - 232 - diff = (tdata->tjmax - val) / 1000; 233 - 234 - mutex_lock(&tdata->update_lock); 235 - rdmsr_on_cpu(tdata->cpu, tdata->intrpt_reg, &eax, &edx); 236 - eax = (eax & ~THERM_MASK_THRESHOLD0) | 237 - (diff << THERM_SHIFT_THRESHOLD0); 238 - wrmsr_on_cpu(tdata->cpu, tdata->intrpt_reg, eax, edx); 239 - tdata->tmin = val; 240 - mutex_unlock(&tdata->update_lock); 241 - 242 - return count; 243 175 } 244 176 245 177 static ssize_t show_temp(struct device *dev, ··· 288 374 289 375 static int get_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *dev) 290 376 { 291 - /* The 100C is default for both mobile and non mobile CPUs */ 292 377 int err; 293 378 u32 eax, edx; 294 379 u32 val; ··· 298 385 */ 299 386 err = rdmsr_safe_on_cpu(id, MSR_IA32_TEMPERATURE_TARGET, &eax, &edx); 300 387 if (err) { 301 - dev_warn(dev, "Unable to read TjMax from CPU.\n"); 388 + if (c->x86_model > 0xe && c->x86_model != 0x1c) 389 + dev_warn(dev, "Unable to read TjMax from CPU %u\n", id); 302 390 } else { 303 391 val = (eax >> 16) & 0xff; 304 392 /* ··· 307 393 * will be used 308 394 */ 309 395 if (val) { 310 - dev_info(dev, "TjMax is %d C.\n", val); 396 + dev_dbg(dev, "TjMax is %d degrees C\n", val); 311 397 return val * 1000; 312 398 } 399 + } 400 + 401 + if (force_tjmax) { 402 + dev_notice(dev, "TjMax forced to %d degrees C by user\n", 403 + force_tjmax); 404 + return force_tjmax * 1000; 313 405 } 314 406 315 407 /* ··· 334 414 rdmsr(MSR_IA32_UCODE_REV, eax, *(u32 *)edx); 335 415 } 336 416 337 - static int get_pkg_tjmax(unsigned int cpu, struct device *dev) 338 - { 339 - int err; 340 - u32 eax, edx, val; 341 - 342 - err = rdmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, &eax, &edx); 343 - if (!err) { 344 - val = (eax >> 16) & 0xff; 345 - if (val) 346 - return val * 1000; 347 - } 348 - dev_warn(dev, "Unable to read Pkg-TjMax from CPU:%u\n", cpu); 349 - return 100000; /* Default TjMax: 100 degree celsius */ 350 - } 351 - 352 417 static int create_name_attr(struct platform_data *pdata, struct device *dev) 353 418 { 354 419 sysfs_attr_init(&pdata->name_attr.attr); ··· 347 442 int attr_no) 348 443 { 349 444 int err, i; 350 - static ssize_t (*rd_ptr[TOTAL_ATTRS]) (struct device *dev, 445 + static ssize_t (*const rd_ptr[TOTAL_ATTRS]) (struct device *dev, 351 446 struct device_attribute *devattr, char *buf) = { 352 447 show_label, show_crit_alarm, show_temp, show_tjmax, 353 - show_max_alarm, show_ttarget, show_tmin }; 354 - static ssize_t (*rw_ptr[TOTAL_ATTRS]) (struct device *dev, 355 - struct device_attribute *devattr, const char *buf, 356 - size_t count) = { NULL, NULL, NULL, NULL, NULL, 357 - store_ttarget, store_tmin }; 358 - static const char *names[TOTAL_ATTRS] = { 448 + show_ttarget }; 449 + static const char *const names[TOTAL_ATTRS] = { 359 450 "temp%d_label", "temp%d_crit_alarm", 360 451 "temp%d_input", "temp%d_crit", 361 - "temp%d_max_alarm", "temp%d_max", 362 - "temp%d_max_hyst" }; 452 + "temp%d_max" }; 363 453 364 454 for (i = 0; i < tdata->attr_size; i++) { 365 455 snprintf(tdata->attr_name[i], CORETEMP_NAME_LENGTH, names[i], ··· 362 462 sysfs_attr_init(&tdata->sd_attrs[i].dev_attr.attr); 363 463 tdata->sd_attrs[i].dev_attr.attr.name = tdata->attr_name[i]; 364 464 tdata->sd_attrs[i].dev_attr.attr.mode = S_IRUGO; 365 - if (rw_ptr[i]) { 366 - tdata->sd_attrs[i].dev_attr.attr.mode |= S_IWUSR; 367 - tdata->sd_attrs[i].dev_attr.store = rw_ptr[i]; 368 - } 369 465 tdata->sd_attrs[i].dev_attr.show = rd_ptr[i]; 370 466 tdata->sd_attrs[i].index = attr_no; 371 467 err = device_create_file(dev, &tdata->sd_attrs[i].dev_attr); ··· 434 538 435 539 tdata->status_reg = pkg_flag ? MSR_IA32_PACKAGE_THERM_STATUS : 436 540 MSR_IA32_THERM_STATUS; 437 - tdata->intrpt_reg = pkg_flag ? MSR_IA32_PACKAGE_THERM_INTERRUPT : 438 - MSR_IA32_THERM_INTERRUPT; 439 541 tdata->is_pkg_data = pkg_flag; 440 542 tdata->cpu = cpu; 441 543 tdata->cpu_core_id = TO_CORE_ID(cpu); ··· 442 548 return tdata; 443 549 } 444 550 445 - static int create_core_data(struct platform_data *pdata, 446 - struct platform_device *pdev, 551 + static int create_core_data(struct platform_device *pdev, 447 552 unsigned int cpu, int pkg_flag) 448 553 { 449 554 struct temp_data *tdata; 555 + struct platform_data *pdata = platform_get_drvdata(pdev); 450 556 struct cpuinfo_x86 *c = &cpu_data(cpu); 451 557 u32 eax, edx; 452 558 int err, attr_no; ··· 482 588 goto exit_free; 483 589 484 590 /* We can access status register. Get Critical Temperature */ 485 - if (pkg_flag) 486 - tdata->tjmax = get_pkg_tjmax(pdev->id, &pdev->dev); 487 - else 488 - tdata->tjmax = get_tjmax(c, cpu, &pdev->dev); 591 + tdata->tjmax = get_tjmax(c, cpu, &pdev->dev); 489 592 490 593 /* 491 - * Test if we can access the intrpt register. If so, increase the 492 - * 'size' enough to have ttarget/tmin/max_alarm interfaces. 493 - * Initialize ttarget with bits 16:22 of MSR_IA32_THERM_INTERRUPT 594 + * Read the still undocumented bits 8:15 of IA32_TEMPERATURE_TARGET. 595 + * The target temperature is available on older CPUs but not in this 596 + * register. Atoms don't have the register at all. 494 597 */ 495 - err = rdmsr_safe_on_cpu(cpu, tdata->intrpt_reg, &eax, &edx); 496 - if (!err) { 497 - tdata->attr_size += MAX_THRESH_ATTRS; 498 - tdata->tmin = tdata->tjmax - 499 - ((eax & THERM_MASK_THRESHOLD0) >> 500 - THERM_SHIFT_THRESHOLD0) * 1000; 501 - tdata->ttarget = tdata->tjmax - 502 - ((eax & THERM_MASK_THRESHOLD1) >> 503 - THERM_SHIFT_THRESHOLD1) * 1000; 598 + if (c->x86_model > 0xe && c->x86_model != 0x1c) { 599 + err = rdmsr_safe_on_cpu(cpu, MSR_IA32_TEMPERATURE_TARGET, 600 + &eax, &edx); 601 + if (!err) { 602 + tdata->ttarget 603 + = tdata->tjmax - ((eax >> 8) & 0xff) * 1000; 604 + tdata->attr_size++; 605 + } 504 606 } 505 607 506 608 pdata->core_data[attr_no] = tdata; ··· 514 624 515 625 static void coretemp_add_core(unsigned int cpu, int pkg_flag) 516 626 { 517 - struct platform_data *pdata; 518 627 struct platform_device *pdev = coretemp_get_pdev(cpu); 519 628 int err; 520 629 521 630 if (!pdev) 522 631 return; 523 632 524 - pdata = platform_get_drvdata(pdev); 525 - 526 - err = create_core_data(pdata, pdev, cpu, pkg_flag); 633 + err = create_core_data(pdev, cpu, pkg_flag); 527 634 if (err) 528 635 dev_err(&pdev->dev, "Adding Core %u failed\n", cpu); 529 636 } ··· 558 671 if (err) 559 672 goto exit_free; 560 673 561 - pdata->phys_proc_id = TO_PHYS_ID(pdev->id); 674 + pdata->phys_proc_id = pdev->id; 562 675 platform_set_drvdata(pdev, pdata); 563 676 564 677 pdata->hwmon_dev = hwmon_device_register(&pdev->dev); ··· 610 723 611 724 mutex_lock(&pdev_list_mutex); 612 725 613 - pdev = platform_device_alloc(DRVNAME, cpu); 726 + pdev = platform_device_alloc(DRVNAME, TO_PHYS_ID(cpu)); 614 727 if (!pdev) { 615 728 err = -ENOMEM; 616 729 pr_err("Device allocation failed\n");
+1 -1
drivers/hwmon/ds620.c
··· 72 72 char valid; /* !=0 if following fields are valid */ 73 73 unsigned long last_updated; /* In jiffies */ 74 74 75 - u16 temp[3]; /* Register values, word */ 75 + s16 temp[3]; /* Register values, word */ 76 76 }; 77 77 78 78 /*
+2 -2
drivers/hwmon/w83791d.c
··· 329 329 struct i2c_board_info *info); 330 330 static int w83791d_remove(struct i2c_client *client); 331 331 332 - static int w83791d_read(struct i2c_client *client, u8 register); 333 - static int w83791d_write(struct i2c_client *client, u8 register, u8 value); 332 + static int w83791d_read(struct i2c_client *client, u8 reg); 333 + static int w83791d_write(struct i2c_client *client, u8 reg, u8 value); 334 334 static struct w83791d_data *w83791d_update_device(struct device *dev); 335 335 336 336 #ifdef DEBUG