Harald's C7 temp driver
I've been messing (clumsily, since I am learning C while doing this... please be patient with me :) with Harald's via_cputemp.ko driver and have noticed that while I do not get readings using his driver as is, some printk's added into his code show that there is a reading being obtained.
Here is some sample output:
acpitz-virtual-0
Adapter: Virtual device
temp1: +57.0°C (crit = +105.0°C)
c7temp-isa-0000
Adapter: ISA adapter in0: +0.84 V temp1: +0.0°C
via_cputemp-isa-0000
Adapter: ISA adapter
Core 0: +0.1°C
root@justin-mininote:/lib/modules/2.6.31-rc6justin/kernel/drivers/hwmon# dmesg | tail [28068.954298] TEMP: 53 [28075.767438] show_temp: 3 [28075.767451] CPU: 0, MSR: 1169, eax: 35, edx: 0, err: 3 [28075.767459] TEMP: 53 [28096.575734] show_temp: 3 [28096.575746] CPU: 0, MSR: 1169, eax: 37, edx: 0, err: 3 [28096.575753] TEMP: 55 [28156.787908] show_temp: 3 [28156.787920] CPU: 0, MSR: 1169, eax: 38, edx: 0, err: 3 [28156.787928] TEMP: 56
As you can see, the dmesg log shows a CPU temp that tracks with but does not exactly duplicate the ACPI temp. To me, this means that I am probably getting good data.
The function in question is show_temp on lines 69-86 in the attached code. If someone can help me understand how the string buffer 'buf' with the temperature reading is supposed to be passed on to userland code, I'd appreciate it.
Once again, please be patient as I am NOT a programmer, just a guy with a C7 cpu who want to get lm-sensors working.
Thanks.
/*
* via_cputemp.c - Driver for VIA CPU core temperature monitoring
* Copyright (C) 2009 VIA Technologies, Inc.
*
* based on existing coretemp.c, which is
*
* Copyright (C) 2007 Rudolf Marek <r.marek at assembler.cz>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
* 02110-1301 USA.
*
* Original work by Harald Welte, modified by Justin Chudgar <[email protected]> */
#include <linux/module.h>
#include <linux/kernel.h>
#include <linux/delay.h>
#include <linux/init.h>
#include <linux/slab.h>
#include <linux/jiffies.h>
#include <linux/hwmon.h>
#include <linux/sysfs.h>
#include <linux/hwmon-sysfs.h>
#include <linux/err.h>
#include <linux/mutex.h>
#include <linux/list.h>
#include <linux/platform_device.h>
#include <linux/cpu.h>
#include <asm/msr.h>
#include <asm/processor.h>
#define DRVNAME "via_cputemp"
enum { SHOW_TEMP, SHOW_LABEL, SHOW_NAME } SHOW;
struct via_cputemp_data {
struct device *hwmon_dev;
const char *name;
u32 id;
u32 msr;
};static ssize_t show_name(struct device *dev, struct device_attribute *devattr, char *buf)
{
int ret;
struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
struct via_cputemp_data *data = dev_get_drvdata(dev);
if (attr->index == SHOW_NAME) {
ret = sprintf(buf, "%s\n", data->name);
}
else { /* show label */
ret = sprintf(buf, "Core %d\n", data->id);
}
return ret;
}static ssize_t show_temp(struct device *dev, struct device_attribute *devattr, char *buf)
{
struct via_cputemp_data *data = dev_get_drvdata(dev);
u32 eax, edx;
int err;
err = rdmsr_safe_on_cpu(data->id, data->msr, &eax, &edx);
if (err)
return -EAGAIN;
err = sprintf(buf, "%d\n", eax & 0xffffff);
printk(KERN_ALERT "show_temp: %d", err);
printk(KERN_ALERT "CPU: %8x, MSR: %8x, eax: %8x, edx: %8x, err: %8x", data->id, data->msr, eax, edx, err);
printk(KERN_ALERT "TEMP: %d", eax & 0xffffff);
return err;
}static SENSOR_DEVICE_ATTR(temp1_input, S_IRUGO, show_temp, NULL, SHOW_TEMP); 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);
static struct attribute *via_cputemp_attributes[] = {
&sensor_dev_attr_name.dev_attr.attr, &sensor_dev_attr_temp1_label.dev_attr.attr, &sensor_dev_attr_temp1_input.dev_attr.attr, NULL
};
static const struct attribute_group via_cputemp_group = {
.attrs = via_cputemp_attributes,
};
static int __devinit via_cputemp_probe(struct platform_device *pdev)
{
struct via_cputemp_data *data;
struct cpuinfo_x86 *c = &cpu_data(pdev->id);
int err;
u32 eax, edx;
if (!(data = kzalloc(sizeof(struct via_cputemp_data), GFP_KERNEL))) {
err = -ENOMEM;
dev_err(&pdev->dev, "Out of memory\n");
goto exit;
}
data->id = pdev->id;
data->name = "via_cputemp";
switch (c->x86_model) {
case 0xA:
printk(KERN_ALERT "We are using a VIA C7 model A CPU.");
data->msr = 0x1169;
break;
case 0xB:
printk(KERN_ALERT "We are using a VIA C7 model B CPU.");
data->msr = 0x1169;
break;
case 0xC:
printk(KERN_ALERT "We are using a VIA C7 model C CPU.");
data->msr = 0x1169;
break;
case 0xD:
printk(KERN_ALERT "We are using a VIA C7 model D CPU.");
data->msr = 0x1169; // MSR 0x1167 is the user Therm Threshold Temp
break;
case 0xF:
printk(KERN_ALERT "We are using a VIA Nano CPU.");
data->msr = 0x1423;
break;
default:
printk(KERN_ALERT "We are using an unidentified CPU.");
err = -ENODEV;
goto exit_free;
}
/* test if we can access the TEMPERATURE MSR */
err = rdmsr_safe_on_cpu(data->id, data->msr, &eax, &edx);
printk(KERN_ALERT "Read MSR from CPU %d, MSR %x, %x, %x: ", data->id, data->msr, &eax, &edx);
if (err) {
dev_err(&pdev->dev, "Unable to access TEMP MSR, giving up\n");
goto exit_free;
}
platform_set_drvdata(pdev, data);
if ((err = sysfs_create_group(&pdev->dev.kobj, &via_cputemp_group)))
goto exit_free;
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;
}
return 0;
exit_class:
sysfs_remove_group(&pdev->dev.kobj, &via_cputemp_group);
exit_free:
kfree(data);
exit:
return err;
}static int __devexit via_cputemp_remove(struct platform_device *pdev)
{
struct via_cputemp_data *data = platform_get_drvdata(pdev);
hwmon_device_unregister(data->hwmon_dev);
sysfs_remove_group(&pdev->dev.kobj, &via_cputemp_group);
platform_set_drvdata(pdev, NULL);
kfree(data);
return 0;
}static struct platform_driver via_cputemp_driver = {
.driver = {
.owner = THIS_MODULE,
.name = DRVNAME,
},
.probe = via_cputemp_probe,
.remove = __devexit_p(via_cputemp_remove),
};
struct pdev_entry {
struct list_head list;
struct platform_device *pdev;
unsigned int cpu;
};static LIST_HEAD(pdev_list);
static DEFINE_MUTEX(pdev_list_mutex);
static int __cpuinit via_cputemp_device_add(unsigned int cpu)
{
int err;
struct platform_device *pdev;
struct pdev_entry *pdev_entry;
pdev = platform_device_alloc(DRVNAME, cpu);
if (!pdev) {
err = -ENOMEM;
printk(KERN_ERR DRVNAME ": Device allocation failed\n");
goto exit;
}
pdev_entry = kzalloc(sizeof(struct pdev_entry), GFP_KERNEL);
if (!pdev_entry) {
err = -ENOMEM;
goto exit_device_put;
}
err = platform_device_add(pdev);
if (err) {
printk(KERN_ERR DRVNAME ": Device addition failed (%d)\n", err);
goto exit_device_free;
}
pdev_entry->pdev = pdev;
pdev_entry->cpu = cpu;
mutex_lock(&pdev_list_mutex);
list_add_tail(&pdev_entry->list, &pdev_list);
mutex_unlock(&pdev_list_mutex);
return 0;
exit_device_free:
kfree(pdev_entry);
exit_device_put:
platform_device_put(pdev);
exit:
return err;
}#ifdef CONFIG_HOTPLUG_CPU
static void via_cputemp_device_remove(unsigned int cpu)
{
struct pdev_entry *p, *n;
mutex_lock(&pdev_list_mutex);
list_for_each_entry_safe(p, n, &pdev_list, list) {
if (p->cpu == cpu) {
platform_device_unregister(p->pdev);
list_del(&p->list);
kfree(p);
}
}
mutex_unlock(&pdev_list_mutex);
}static int __cpuinit via_cputemp_cpu_callback(struct notifier_block *nfb, unsigned long action, void *hcpu)
{
unsigned int cpu = (unsigned long) hcpu;
switch (action) {
case CPU_ONLINE:
case CPU_DOWN_FAILED:
via_cputemp_device_add(cpu);
break;
case CPU_DOWN_PREPARE:
via_cputemp_device_remove(cpu);
break;
}
return NOTIFY_OK;
}static struct notifier_block via_cputemp_cpu_notifier __refdata = {
.notifier_call = via_cputemp_cpu_callback,
};
#endif /* !CONFIG_HOTPLUG_CPU */
static int __init via_cputemp_init(void)
{
int i, err = -ENODEV;
struct pdev_entry *p, *n;
printk(KERN_ALERT "Initilizing module: %s", DRVNAME);
if (cpu_data(0).x86_vendor != X86_VENDOR_CENTAUR) {
printk(KERN_ALERT "Not a VIA CPU\n");
goto exit;
}
err = platform_driver_register(&via_cputemp_driver);
if (err)
goto exit;
for_each_online_cpu(i) {
struct cpuinfo_x86 *c = &cpu_data(i);
printk(KERN_ALERT "c->x86: %d", c->x86);
if (c->x86 != 6) { continue; }
if (c->x86_model < 0x0a) { continue; }
if (c->x86_model > 0x0f) {
printk(KERN_WARNING DRVNAME ": Unknown CPU model %x\n", c->x86_model);
continue;
}
err = via_cputemp_device_add(i);
if (err)
goto exit_devices_unreg;
}
if (list_empty(&pdev_list)) {
err = -ENODEV;
goto exit_driver_unreg;
}
#ifdef CONFIG_HOTPLUG_CPU
register_hotcpu_notifier(&via_cputemp_cpu_notifier);
#endif
return 0;
exit_devices_unreg:
mutex_lock(&pdev_list_mutex);
list_for_each_entry_safe(p, n, &pdev_list, list) {
platform_device_unregister(p->pdev);
list_del(&p->list);
kfree(p);
}
mutex_unlock(&pdev_list_mutex);
exit_driver_unreg:
platform_driver_unregister(&via_cputemp_driver);
exit:
return err;
}static void __exit via_cputemp_exit(void)
{
struct pdev_entry *p, *n;
printk(KERN_ALERT "Exiting module: %s", DRVNAME);
#ifdef CONFIG_HOTPLUG_CPU
unregister_hotcpu_notifier(&via_cputemp_cpu_notifier);
#endif
mutex_lock(&pdev_list_mutex);
list_for_each_entry_safe(p, n, &pdev_list, list) {
platform_device_unregister(p->pdev);
list_del(&p->list);
kfree(p);
}
mutex_unlock(&pdev_list_mutex);
platform_driver_unregister(&via_cputemp_driver);
}MODULE_AUTHOR("Harald Welte <HaraldWelte at viatech.com>"); MODULE_DESCRIPTION("VIA CPU temperature monitor"); MODULE_LICENSE("GPL");
module_init(via_cputemp_init)module_exit(via_cputemp_exit)
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
Thanks, Lu! That worked as advertised.
With the addition of '* 1000', sensors is reporting seemingly accurate data.
Now, what remains is merging Harald's temperature algorithm with Juerg's voltage algorithm. I was planning on creating a module called via_c7temp with the working parts of both Harald's and Juerg's work. However, I do not know if that is the appropriate thing to do.
Since this was initially Juerg's baby, (and since Juerg is much better at this than I ;) ) would you like to handle it? Or direct me in making the needed changes?
Signature · 4 lines
Justin Chudgar Information Technology Consultant 5040 Saddlehorn Rd, Weed, CA 96084 530-938-9692 (Home Office)
Quoted 29 lines · you
Dear Justin,
Harald had a updated version of
via_cputemp,=============
drivers/hwmon/via-cputemp.c +2
-2@@ -37,7 +37,7 @@#include <asm/msr.h> #include <asm/processor.h> -#define DRVNAME "via-cputemp" +#define DRVNAME "via_cputemp"typedef enum {SHOW_TEMP ,SHOW_LABEL ,SHOW_NAME }SHOW ;@@ -81,7 +81,7 @@ static ssize_t show_temp(struct device *dev,if (err)return -EAGAIN ; - err =sprintf (buf,"%d\n" , eax &0xffffff ); + err =sprintf (buf,"%d\n" , (eax &0xffffff ) *1000 );return err; }=============
Quoted 55 lines
Had you try it?
Just a remind.2009/8/22 Justin Chudgar <[email protected]>:
Quoted 51 lines
I've been messing (clumsily, since I am learning C while doing this... please be patient with me :) with Harald's via_cputemp.ko driver and have noticed that while I do not get readings using his driver as is, some printk's added into his code show that there is a reading being obtained.
Here is some sample output:
acpitz-virtual-0
Adapter: Virtual device
temp1: +57.0°C (crit = +105.0°C)c7temp-isa-0000
Adapter: ISA adapter
in0: +0.84 V
temp1: +0.0°Cvia_cputemp-isa-0000
Adapter: ISA adapter
Core 0: +0.1°Croot@justin-mininote:/lib/modules/2.6.31-rc6justin/kernel/drivers/hwmon# dmesg | tail
[28068.954298] TEMP: 53 [28075.767438] show_temp: 3 [28075.767451] CPU: 0, MSR: 1169, eax: 35, edx: 0, err: 3 [28075.767459] TEMP: 53 [28096.575734] show_temp: 3 [28096.575746] CPU: 0, MSR: 1169, eax: 37, edx: 0, err: 3 [28096.575753] TEMP: 55 [28156.787908] show_temp: 3 [28156.787920] CPU: 0, MSR: 1169, eax: 38, edx: 0, err: 3 [28156.787928] TEMP: 56As you can see, the dmesg log shows a CPU temp that tracks with but does not exactly duplicate the ACPI temp. To me, this means that I am probably getting good data.
The function in question is
show_tempon lines 69-86 in the attached code. If someone can help me understand how the string buffer 'buf' with the temperature reading is supposed to be passed on to userland code, I'd appreciate it.Once again, please be patient as I am NOT a programmer, just a guy with a C7 cpu who want to get lm-sensors working.
Thanks.
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors
_______________________________________________
lm-sensors mailing list
[email protected]
http://lists.lm-sensors.org/mailman/listinfo/lm-sensors