X-Git-Url: http://ftp.safe.ca/?a=blobdiff_plain;f=drivers%2Fhwmon%2Fcoretemp.c;h=93c17223b527018271b0febf9b96b4af4d030670;hb=17c1f07ed70afa4f3941745fc3cc173e2a0365fe;hp=0328382df8fae74a3edf1e0560404cd8f6f3f18a;hpb=67f363b1f6a31cf5027a97372f64bcced4f05ba6;p=safe%2Fjmp%2Flinux-2.6 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c index 0328382..93c1722 100644 --- a/drivers/hwmon/coretemp.c +++ b/drivers/hwmon/coretemp.c @@ -38,7 +38,8 @@ #define DRVNAME "coretemp" -typedef enum { SHOW_TEMP, SHOW_TJMAX, SHOW_LABEL, SHOW_NAME } SHOW; +typedef enum { SHOW_TEMP, SHOW_TJMAX, SHOW_TTARGET, SHOW_LABEL, + SHOW_NAME } SHOW; /* * Functions declaration @@ -47,7 +48,7 @@ typedef enum { SHOW_TEMP, SHOW_TJMAX, SHOW_LABEL, SHOW_NAME } SHOW; static struct coretemp_data *coretemp_update_device(struct device *dev); struct coretemp_data { - struct class_device *class_dev; + struct device *hwmon_dev; struct mutex update_lock; const char *name; u32 id; @@ -55,11 +56,10 @@ struct coretemp_data { unsigned long last_updated; /* in jiffies */ int temp; int tjmax; + int ttarget; u8 alarm; }; -static struct coretemp_data *coretemp_update_device(struct device *dev); - /* * Sysfs stuff */ @@ -95,9 +95,10 @@ static ssize_t show_temp(struct device *dev, if (attr->index == SHOW_TEMP) err = data->valid ? sprintf(buf, "%d\n", data->temp) : -EAGAIN; - else + else if (attr->index == SHOW_TJMAX) err = sprintf(buf, "%d\n", data->tjmax); - + else + err = sprintf(buf, "%d\n", data->ttarget); return err; } @@ -105,6 +106,8 @@ static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, SHOW_TEMP); static SENSOR_DEVICE_ATTR(temp1_crit, S_IRUGO, show_temp, NULL, SHOW_TJMAX); +static SENSOR_DEVICE_ATTR(temp1_max, S_IRUGO, show_temp, NULL, + SHOW_TTARGET); static DEVICE_ATTR(temp1_crit_alarm, S_IRUGO, show_alarm, NULL); static SENSOR_DEVICE_ATTR(temp1_label, S_IRUGO, show_name, NULL, SHOW_LABEL); static SENSOR_DEVICE_ATTR(name, S_IRUGO, show_name, NULL, SHOW_NAME); @@ -149,10 +152,60 @@ static struct coretemp_data *coretemp_update_device(struct device *dev) return data; } +static int __devinit adjust_tjmax(struct cpuinfo_x86 *c, u32 id, struct device *dev) +{ + /* The 100C is default for both mobile and non mobile CPUs */ + + int tjmax = 100000; + int ismobile = 1; + int err; + u32 eax, edx; + + /* Early chips have no MSR for TjMax */ + + if ((c->x86_model == 0xf) && (c->x86_mask < 4)) { + ismobile = 0; + } + + if ((c->x86_model > 0xe) && (ismobile)) { + + /* Now we can detect the mobile CPU using Intel provided table + http://softwarecommunity.intel.com/Wiki/Mobility/720.htm + For Core2 cores, check MSR 0x17, bit 28 1 = Mobile CPU + */ + + err = rdmsr_safe_on_cpu(id, 0x17, &eax, &edx); + if (err) { + dev_warn(dev, + "Unable to access MSR 0x17, assuming desktop" + " CPU\n"); + ismobile = 0; + } else if (!(eax & 0x10000000)) { + ismobile = 0; + } + } + + if (ismobile) { + + err = rdmsr_safe_on_cpu(id, 0xee, &eax, &edx); + if (err) { + dev_warn(dev, + "Unable to access MSR 0xEE, for Tjmax, left" + " at default"); + } else if (eax & 0x40000000) { + tjmax = 85000; + } + } else { + dev_warn(dev, "Using relative temperature scale!\n"); + } + + return tjmax; +} + static int __devinit coretemp_probe(struct platform_device *pdev) { struct coretemp_data *data; - struct cpuinfo_x86 *c = &(cpu_data)[pdev->id]; + struct cpuinfo_x86 *c = &cpu_data(pdev->id); int err; u32 eax, edx; @@ -165,8 +218,6 @@ static int __devinit coretemp_probe(struct platform_device *pdev) data->id = pdev->id; data->name = "coretemp"; mutex_init(&data->update_lock); - /* Tjmax default is 100 degrees C */ - data->tjmax = 100000; /* test if we can access the THERM_STATUS MSR */ err = rdmsr_safe_on_cpu(data->id, MSR_IA32_THERM_STATUS, &eax, &edx); @@ -185,6 +236,7 @@ static int __devinit coretemp_probe(struct platform_device *pdev) /* check for microcode update */ rdmsr_on_cpu(data->id, MSR_IA32_UCODE_REV, &eax, &edx); if (edx < 0x39) { + err = -ENODEV; dev_err(&pdev->dev, "Errata AE18 not fixed, update BIOS or " "microcode of the CPU!\n"); @@ -192,44 +244,33 @@ static int __devinit coretemp_probe(struct platform_device *pdev) } } - /* Some processors have Tjmax 85 following magic should detect it - Intel won't disclose the information without signed NDA, but - individuals cannot sign it. Catch(ed) 22. - */ + data->tjmax = adjust_tjmax(c, data->id, &pdev->dev); + platform_set_drvdata(pdev, data); + + /* read the still undocumented IA32_TEMPERATURE_TARGET it exists + on older CPUs but not in this register */ - if (((c->x86_model == 0xf) && (c->x86_mask > 3)) || - (c->x86_model == 0xe)) { - err = rdmsr_safe_on_cpu(data->id, 0xee, &eax, &edx); + if (c->x86_model > 0xe) { + err = rdmsr_safe_on_cpu(data->id, 0x1a2, &eax, &edx); if (err) { - dev_warn(&pdev->dev, - "Unable to access MSR 0xEE, Tjmax left at %d " - "degrees C\n", data->tjmax/1000); - } else if (eax & 0x40000000) { - data->tjmax = 85000; + dev_warn(&pdev->dev, "Unable to read" + " IA32_TEMPERATURE_TARGET MSR\n"); + } else { + data->ttarget = data->tjmax - + (((eax >> 8) & 0xff) * 1000); + err = device_create_file(&pdev->dev, + &sensor_dev_attr_temp1_max.dev_attr); + if (err) + goto exit_free; } } - /* Intel says that above should not work for desktop Core2 processors, - but it seems to work. There is no other way how get the absolute - readings. Warn the user about this. First check if are desktop, - bit 50 of MSR_IA32_PLATFORM_ID should be 0. - */ - - rdmsr_safe_on_cpu(data->id, MSR_IA32_PLATFORM_ID, &eax, &edx); - - if ((c->x86_model == 0xf) && (!(edx & 0x00040000))) { - dev_warn(&pdev->dev, "Using undocumented features, absolute " - "temperature might be wrong!\n"); - } - - platform_set_drvdata(pdev, data); - if ((err = sysfs_create_group(&pdev->dev.kobj, &coretemp_group))) - goto exit_free; + goto exit_dev; - data->class_dev = hwmon_device_register(&pdev->dev); - if (IS_ERR(data->class_dev)) { - err = PTR_ERR(data->class_dev); + data->hwmon_dev = hwmon_device_register(&pdev->dev); + if (IS_ERR(data->hwmon_dev)) { + err = PTR_ERR(data->hwmon_dev); dev_err(&pdev->dev, "Class registration failed (%d)\n", err); goto exit_class; @@ -239,6 +280,8 @@ static int __devinit coretemp_probe(struct platform_device *pdev) exit_class: sysfs_remove_group(&pdev->dev.kobj, &coretemp_group); +exit_dev: + device_remove_file(&pdev->dev, &sensor_dev_attr_temp1_max.dev_attr); exit_free: kfree(data); exit: @@ -249,8 +292,9 @@ static int __devexit coretemp_remove(struct platform_device *pdev) { struct coretemp_data *data = platform_get_drvdata(pdev); - hwmon_device_unregister(data->class_dev); + hwmon_device_unregister(data->hwmon_dev); sysfs_remove_group(&pdev->dev.kobj, &coretemp_group); + device_remove_file(&pdev->dev, &sensor_dev_attr_temp1_max.dev_attr); platform_set_drvdata(pdev, NULL); kfree(data); return 0; @@ -317,7 +361,7 @@ exit: } #ifdef CONFIG_HOTPLUG_CPU -void coretemp_device_remove(unsigned int cpu) +static void coretemp_device_remove(unsigned int cpu) { struct pdev_entry *p, *n; mutex_lock(&pdev_list_mutex); @@ -331,25 +375,24 @@ void coretemp_device_remove(unsigned int cpu) mutex_unlock(&pdev_list_mutex); } -static int coretemp_cpu_callback(struct notifier_block *nfb, +static int __cpuinit coretemp_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu) { unsigned int cpu = (unsigned long) hcpu; switch (action) { case CPU_ONLINE: - case CPU_ONLINE_FROZEN: + case CPU_DOWN_FAILED: coretemp_device_add(cpu); break; - case CPU_DEAD: - case CPU_DEAD_FROZEN: + case CPU_DOWN_PREPARE: coretemp_device_remove(cpu); break; } return NOTIFY_OK; } -static struct notifier_block __cpuinitdata coretemp_cpu_notifier = { +static struct notifier_block coretemp_cpu_notifier __refdata = { .notifier_call = coretemp_cpu_callback, }; #endif /* !CONFIG_HOTPLUG_CPU */ @@ -360,7 +403,7 @@ static int __init coretemp_init(void) struct pdev_entry *p, *n; /* quick check if we run Intel */ - if (cpu_data[0].x86_vendor != X86_VENDOR_INTEL) + if (cpu_data(0).x86_vendor != X86_VENDOR_INTEL) goto exit; err = platform_driver_register(&coretemp_driver); @@ -368,11 +411,13 @@ static int __init coretemp_init(void) goto exit; for_each_online_cpu(i) { - struct cpuinfo_x86 *c = &(cpu_data)[i]; + struct cpuinfo_x86 *c = &cpu_data(i); - /* check if family 6, models e, f */ + /* check if family 6, models 0xe, 0xf, 0x16, 0x17, 0x1A */ if ((c->cpuid_level < 0) || (c->x86 != 0x6) || - !((c->x86_model == 0xe) || (c->x86_model == 0xf))) { + !((c->x86_model == 0xe) || (c->x86_model == 0xf) || + (c->x86_model == 0x16) || (c->x86_model == 0x17) || + (c->x86_model == 0x1A))) { /* supported CPU not found, but report the unknown family 6 CPU */