Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

k10temp patch

8 views
Skip to first unread message

cbxbiker61

unread,
Aug 19, 2008, 1:25:17 AM8/19/08
to
Just in case it's useful to others I'm posting a patch for k10
temperature monitoring against 2.6.26.2. It'll probaby apply to any
recent version since it's pretty non-obtrusive.

diff -Naupr linux-2.6.26.2/drivers/hwmon/Kconfig linux-2.6.26.2-k10temp/
drivers/hwmon/Kconfig
--- linux-2.6.26.2/drivers/hwmon/Kconfig 2008-08-06
10:19:01.000000000 -0600
+++ linux-2.6.26.2-k10temp/drivers/hwmon/Kconfig 2008-08-18
22:50:04.155586212 -0600
@@ -165,6 +165,18 @@ config SENSORS_K8TEMP
This driver can also be built as a module. If so, the module
will be called k8temp.

+config SENSORS_K10TEMP
+ tristate "AMD Phenom temperature sensor"
+ depends on X86 && PCI && EXPERIMENTAL
+ help
+ If you say yes here you get support for the temperature
+ sensor(s) inside your CPU. Supported is whole AMD K10
+ microarchitecture. Please note that you will need at least
+ lm-sensors 2.10.1 for proper userspace support.
+
+ This driver can also be built as a module. If so, the module
+ will be called k10temp.
+
config SENSORS_AMS
tristate "Apple Motion Sensor driver"
depends on PPC_PMAC && !PPC64 && INPUT && ((ADB_PMU && I2C = y)
|| (ADB_PMU && !I2C) || I2C) && EXPERIMENTAL
diff -Naupr linux-2.6.26.2/drivers/hwmon/Makefile linux-2.6.26.2-k10temp/
drivers/hwmon/Makefile
--- linux-2.6.26.2/drivers/hwmon/Makefile 2008-08-06
10:19:01.000000000 -0600
+++ linux-2.6.26.2-k10temp/drivers/hwmon/Makefile 2008-08-18
22:50:26.118591131 -0600
@@ -45,6 +45,7 @@ obj-$(CONFIG_SENSORS_IBMAEM) += ibmaem.o
obj-$(CONFIG_SENSORS_IBMPEX) += ibmpex.o
obj-$(CONFIG_SENSORS_IT87) += it87.o
obj-$(CONFIG_SENSORS_K8TEMP) += k8temp.o
+obj-$(CONFIG_SENSORS_K10TEMP) += k10temp.o
obj-$(CONFIG_SENSORS_LM63) += lm63.o
obj-$(CONFIG_SENSORS_LM70) += lm70.o
obj-$(CONFIG_SENSORS_LM75) += lm75.o
diff -Naupr linux-2.6.26.2/drivers/hwmon/k10temp.c linux-2.6.26.2-k10temp/
drivers/hwmon/k10temp.c
--- linux-2.6.26.2/drivers/hwmon/k10temp.c 1969-12-31
17:00:00.000000000 -0700
+++ linux-2.6.26.2-k10temp/drivers/hwmon/k10temp.c 2008-08-18
22:35:56.898587937 -0600
@@ -0,0 +1,191 @@
+/*
+ * k10temp.c - Linux kernel module for hardware monitoring
+ *
+ * Copyright (C) 2008 Rudolf Marek <r.m...@assembler.cz>
+ *
+ * Inspired from the k8temp driver.
+ *
+ * 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; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * 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.
+ */
+
+#include <linux/module.h>
+#include <linux/delay.h>
+#include <linux/init.h>
+#include <linux/slab.h>
+#include <linux/jiffies.h>
+#include <linux/pci.h>
+#include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
+#include <linux/err.h>
+#include <linux/mutex.h>
+
+/* 1000 / 8 = 125 no mask because we shift from bit 31 */
+#define TEMP_FROM_REG(val) (((val) >> 21) * 125)
+#define REG_TEMP 0xa4
+
+struct k10temp_data {
+ struct device *hwmon_dev;
+ struct mutex update_lock;
+ const char *name;
+ char valid; /* zero until following fields are valid
*/
+ unsigned long last_updated; /* in jiffies */
+
+ /* registers values */
+ u32 temp; /* raw value */
+};
+
+static struct k10temp_data *k10temp_update_device(struct device *dev)
+{
+ struct k10temp_data *data = dev_get_drvdata(dev);
+ struct pci_dev *pdev = to_pci_dev(dev);
+ u8 tmp;
+
+ mutex_lock(&data->update_lock);
+
+ if (!data->valid
+ || time_after(jiffies, data->last_updated + HZ)) {
+
+
+ pci_read_config_dword(pdev, REG_TEMP, &data->temp);
+
+ data->last_updated = jiffies;
+ data->valid = 1;
+ }
+
+ mutex_unlock(&data->update_lock);
+ return data;
+}
+
+/*
+ * Sysfs stuff
+ */
+
+static ssize_t show_name(struct device *dev, struct device_attribute
+ *devattr, char *buf)
+{
+ struct k10temp_data *data = dev_get_drvdata(dev);
+
+ return sprintf(buf, "%s\n", data->name);
+}
+
+
+static ssize_t show_temp(struct device *dev,
+ struct device_attribute *devattr, char *buf)
+{
+ struct sensor_device_attribute_2 *attr =
+ to_sensor_dev_attr_2(devattr);
+ int core = attr->nr;
+ int place = attr->index;
+ struct k10temp_data *data = k10temp_update_device(dev);
+
+ return sprintf(buf, "%d\n",
+ TEMP_FROM_REG(data->temp));
+}
+
+/* core, place */
+
+static SENSOR_DEVICE_ATTR_2(temp1_input, S_IRUGO, show_temp, NULL, 0, 0);
+static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
+
+static struct pci_device_id k10temp_ids[] = {
+ { PCI_DEVICE(PCI_VENDOR_ID_AMD, 0x1203) },
+ { 0 },
+};
+
+MODULE_DEVICE_TABLE(pci, k10temp_ids);
+
+static int __devinit k10temp_probe(struct pci_dev *pdev,
+ const struct pci_device_id *id)
+{
+ int err;
+ u8 scfg;
+ u32 temp;
+ struct k10temp_data *data;
+
+ if (!(data = kzalloc(sizeof(struct k10temp_data), GFP_KERNEL))) {
+ err = -ENOMEM;
+ goto exit;
+ }
+
+ data->name = "k10temp";
+ mutex_init(&data->update_lock);
+ dev_set_drvdata(&pdev->dev, data);
+
+ /* Register sysfs hooks */
+ err = device_create_file(&pdev->dev,
+ &sensor_dev_attr_temp1_input.dev_attr);
+ if (err)
+ goto exit_remove;
+
+ err = device_create_file(&pdev->dev, &dev_attr_name);
+ if (err)
+ goto exit_remove;
+
+ data->hwmon_dev = hwmon_device_register(&pdev->dev);
+
+ if (IS_ERR(data->hwmon_dev)) {
+ err = PTR_ERR(data->hwmon_dev);
+ goto exit_remove;
+ }
+
+ return 0;
+
+exit_remove:
+ device_remove_file(&pdev->dev,
+ &sensor_dev_attr_temp1_input.dev_attr);
+ device_remove_file(&pdev->dev, &dev_attr_name);
+exit_free:
+ dev_set_drvdata(&pdev->dev, NULL);
+ kfree(data);
+exit:
+ return err;
+}
+
+static void __devexit k10temp_remove(struct pci_dev *pdev)
+{
+ struct k10temp_data *data = dev_get_drvdata(&pdev->dev);
+
+ hwmon_device_unregister(data->hwmon_dev);
+ device_remove_file(&pdev->dev,
+ &sensor_dev_attr_temp1_input.dev_attr);
+ device_remove_file(&pdev->dev, &dev_attr_name);
+ dev_set_drvdata(&pdev->dev, NULL);
+ kfree(data);
+}
+
+static struct pci_driver k10temp_driver = {
+ .name = "k10temp",
+ .id_table = k10temp_ids,
+ .probe = k10temp_probe,
+ .remove = __devexit_p(k10temp_remove),
+};
+
+static int __init k10temp_init(void)
+{
+ return pci_register_driver(&k10temp_driver);
+}
+
+static void __exit k10temp_exit(void)
+{
+ pci_unregister_driver(&k10temp_driver);
+}
+
+MODULE_AUTHOR("Rudolf Marek <r.m...@assembler.cz>");
+MODULE_DESCRIPTION("AMD K10 core temperature monitor");
+MODULE_LICENSE("GPL");
+
+module_init(k10temp_init)
+module_exit(k10temp_exit)

0 new messages