libata-sff: separate out BMDMA qc_issue
[safe/jmp/linux-2.6] / drivers / hwmon / pc87360.c
index 08fcb5a..4a64b85 100644 (file)
@@ -1,7 +1,7 @@
 /*
  *  pc87360.c - Part of lm_sensors, Linux kernel modules
  *              for hardware monitoring
- *  Copyright (C) 2004 Jean Delvare <khali@linux-fr.org>
+ *  Copyright (C) 2004, 2007 Jean Delvare <khali@linux-fr.org>
  *
  *  Copied from smsc47m1.c:
  *  Copyright (C) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com>
 #include <linux/init.h>
 #include <linux/slab.h>
 #include <linux/jiffies.h>
-#include <linux/i2c.h>
-#include <linux/i2c-isa.h>
+#include <linux/platform_device.h>
 #include <linux/hwmon.h>
+#include <linux/hwmon-sysfs.h>
 #include <linux/hwmon-vid.h>
 #include <linux/err.h>
-#include <asm/io.h>
+#include <linux/mutex.h>
+#include <linux/acpi.h>
+#include <linux/io.h>
 
 static u8 devid;
-static unsigned short address;
+static struct platform_device *pdev;
 static unsigned short extra_isa[3];
 static u8 confreg[4];
 
-enum chips { any_chip, pc87360, pc87363, pc87364, pc87365, pc87366 };
-
 static int init = 1;
 module_param(init, int, 0);
 MODULE_PARM_DESC(init,
@@ -60,6 +60,10 @@ MODULE_PARM_DESC(init,
  " 2: Forcibly enable all voltage and temperature channels, except in9\n"
  " 3: Forcibly enable all voltage and temperature channels, including in9");
 
+static unsigned short force_id;
+module_param(force_id, ushort, 0);
+MODULE_PARM_DESC(force_id, "Override the detected device ID");
+
 /*
  * Super-I/O registers and operations
  */
@@ -72,7 +76,8 @@ MODULE_PARM_DESC(init,
 #define FSCM   0x09    /* Logical device: fans */
 #define VLM    0x0d    /* Logical device: voltages */
 #define TMS    0x0e    /* Logical device: temperatures */
-static const u8 logdev[3] = { FSCM, VLM, TMS };
+#define LDNI_MAX 3
+static const u8 logdev[LDNI_MAX] = { FSCM, VLM, TMS };
 
 #define LD_FAN         0
 #define LD_IN          1
@@ -176,14 +181,14 @@ static inline u8 PWM_TO_REG(int val, int inv)
                                         ((val) + 500) / 1000)
 
 /*
- * Client data (each client gets its own)
+ * Device data
  */
 
 struct pc87360_data {
-       struct i2c_client client;
-       struct class_device *class_dev;
-       struct semaphore lock;
-       struct semaphore update_lock;
+       const char *name;
+       struct device *hwmon_dev;
+       struct mutex lock;
+       struct mutex update_lock;
        char valid;             /* !=0 if following fields are valid */
        unsigned long last_updated;     /* In jiffies */
 
@@ -220,290 +225,332 @@ struct pc87360_data {
  * Functions declaration
  */
 
-static int pc87360_detect(struct i2c_adapter *adapter);
-static int pc87360_detach_client(struct i2c_client *client);
+static int pc87360_probe(struct platform_device *pdev);
+static int __devexit pc87360_remove(struct platform_device *pdev);
 
 static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
                              u8 reg);
 static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank,
                                u8 reg, u8 value);
-static void pc87360_init_client(struct i2c_client *client, int use_thermistors);
+static void pc87360_init_device(struct platform_device *pdev,
+                               int use_thermistors);
 static struct pc87360_data *pc87360_update_device(struct device *dev);
 
 /*
- * Driver data (common to all clients)
+ * Driver data
  */
 
-static struct i2c_driver pc87360_driver = {
-       .owner          = THIS_MODULE,
-       .name           = "pc87360",
-       .attach_adapter = pc87360_detect,
-       .detach_client  = pc87360_detach_client,
+static struct platform_driver pc87360_driver = {
+       .driver = {
+               .owner  = THIS_MODULE,
+               .name   = "pc87360",
+       },
+       .probe          = pc87360_probe,
+       .remove         = __devexit_p(pc87360_remove),
 };
 
 /*
  * Sysfs stuff
  */
 
-static ssize_t set_fan_min(struct device *dev, const char *buf,
-       size_t count, int nr)
+static ssize_t show_fan_input(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[attr->index],
+                      FAN_DIV_FROM_REG(data->fan_status[attr->index])));
+}
+static ssize_t show_fan_min(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[attr->index],
+                      FAN_DIV_FROM_REG(data->fan_status[attr->index])));
+}
+static ssize_t show_fan_div(struct device *dev, struct device_attribute *devattr, char *buf)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct pc87360_data *data = i2c_get_clientdata(client);
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n",
+                      FAN_DIV_FROM_REG(data->fan_status[attr->index]));
+}
+static ssize_t show_fan_status(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n",
+                      FAN_STATUS_FROM_REG(data->fan_status[attr->index]));
+}
+static ssize_t set_fan_min(struct device *dev, struct device_attribute *devattr, const char *buf,
+       size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = dev_get_drvdata(dev);
        long fan_min = simple_strtol(buf, NULL, 10);
 
-       down(&data->update_lock);
-       fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[nr]));
+       mutex_lock(&data->update_lock);
+       fan_min = FAN_TO_REG(fan_min, FAN_DIV_FROM_REG(data->fan_status[attr->index]));
 
        /* If it wouldn't fit, change clock divisor */
        while (fan_min > 255
-           && (data->fan_status[nr] & 0x60) != 0x60) {
+           && (data->fan_status[attr->index] & 0x60) != 0x60) {
                fan_min >>= 1;
-               data->fan[nr] >>= 1;
-               data->fan_status[nr] += 0x20;
+               data->fan[attr->index] >>= 1;
+               data->fan_status[attr->index] += 0x20;
        }
-       data->fan_min[nr] = fan_min > 255 ? 255 : fan_min;
-       pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_MIN(nr),
-                           data->fan_min[nr]);
+       data->fan_min[attr->index] = fan_min > 255 ? 255 : fan_min;
+       pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_MIN(attr->index),
+                           data->fan_min[attr->index]);
 
        /* Write new divider, preserve alarm bits */
-       pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(nr),
-                           data->fan_status[nr] & 0xF9);
-       up(&data->update_lock);
+       pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_FAN_STATUS(attr->index),
+                           data->fan_status[attr->index] & 0xF9);
+       mutex_unlock(&data->update_lock);
+
+       return count;
+}
+
+static struct sensor_device_attribute fan_input[] = {
+       SENSOR_ATTR(fan1_input, S_IRUGO, show_fan_input, NULL, 0),
+       SENSOR_ATTR(fan2_input, S_IRUGO, show_fan_input, NULL, 1),
+       SENSOR_ATTR(fan3_input, S_IRUGO, show_fan_input, NULL, 2),
+};
+static struct sensor_device_attribute fan_status[] = {
+       SENSOR_ATTR(fan1_status, S_IRUGO, show_fan_status, NULL, 0),
+       SENSOR_ATTR(fan2_status, S_IRUGO, show_fan_status, NULL, 1),
+       SENSOR_ATTR(fan3_status, S_IRUGO, show_fan_status, NULL, 2),
+};
+static struct sensor_device_attribute fan_div[] = {
+       SENSOR_ATTR(fan1_div, S_IRUGO, show_fan_div, NULL, 0),
+       SENSOR_ATTR(fan2_div, S_IRUGO, show_fan_div, NULL, 1),
+       SENSOR_ATTR(fan3_div, S_IRUGO, show_fan_div, NULL, 2),
+};
+static struct sensor_device_attribute fan_min[] = {
+       SENSOR_ATTR(fan1_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 0),
+       SENSOR_ATTR(fan2_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 1),
+       SENSOR_ATTR(fan3_min, S_IWUSR | S_IRUGO, show_fan_min, set_fan_min, 2),
+};
+
+#define FAN_UNIT_ATTRS(X)      \
+       &fan_input[X].dev_attr.attr,    \
+       &fan_status[X].dev_attr.attr,   \
+       &fan_div[X].dev_attr.attr,      \
+       &fan_min[X].dev_attr.attr
 
+static ssize_t show_pwm(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n",
+                      PWM_FROM_REG(data->pwm[attr->index],
+                                   FAN_CONFIG_INVERT(data->fan_conf,
+                                                     attr->index)));
+}
+static ssize_t set_pwm(struct device *dev, struct device_attribute *devattr, const char *buf,
+       size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = dev_get_drvdata(dev);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->pwm[attr->index] = PWM_TO_REG(val,
+                             FAN_CONFIG_INVERT(data->fan_conf, attr->index));
+       pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(attr->index),
+                           data->pwm[attr->index]);
+       mutex_unlock(&data->update_lock);
        return count;
 }
 
-#define show_and_set_fan(offset) \
-static ssize_t show_fan##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan[offset-1], \
-                      FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \
-} \
-static ssize_t show_fan##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", FAN_FROM_REG(data->fan_min[offset-1], \
-                      FAN_DIV_FROM_REG(data->fan_status[offset-1]))); \
-} \
-static ssize_t show_fan##offset##_div(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", \
-                      FAN_DIV_FROM_REG(data->fan_status[offset-1])); \
-} \
-static ssize_t show_fan##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", \
-                      FAN_STATUS_FROM_REG(data->fan_status[offset-1])); \
-} \
-static ssize_t set_fan##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       return set_fan_min(dev, buf, count, offset-1); \
-} \
-static DEVICE_ATTR(fan##offset##_input, S_IRUGO, \
-       show_fan##offset##_input, NULL); \
-static DEVICE_ATTR(fan##offset##_min, S_IWUSR | S_IRUGO, \
-       show_fan##offset##_min, set_fan##offset##_min); \
-static DEVICE_ATTR(fan##offset##_div, S_IRUGO, \
-       show_fan##offset##_div, NULL); \
-static DEVICE_ATTR(fan##offset##_status, S_IRUGO, \
-       show_fan##offset##_status, NULL);
-show_and_set_fan(1)
-show_and_set_fan(2)
-show_and_set_fan(3)
-
-#define show_and_set_pwm(offset) \
-static ssize_t show_pwm##offset(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", \
-                      PWM_FROM_REG(data->pwm[offset-1], \
-                                   FAN_CONFIG_INVERT(data->fan_conf, \
-                                                     offset-1))); \
-} \
-static ssize_t set_pwm##offset(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct pc87360_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       down(&data->update_lock); \
-       data->pwm[offset-1] = PWM_TO_REG(val, \
-                             FAN_CONFIG_INVERT(data->fan_conf, offset-1)); \
-       pc87360_write_value(data, LD_FAN, NO_BANK, PC87360_REG_PWM(offset-1), \
-                           data->pwm[offset-1]); \
-       up(&data->update_lock); \
-       return count; \
-} \
-static DEVICE_ATTR(pwm##offset, S_IWUSR | S_IRUGO, \
-       show_pwm##offset, set_pwm##offset);
-show_and_set_pwm(1)
-show_and_set_pwm(2)
-show_and_set_pwm(3)
-
-#define show_and_set_in(offset) \
-static ssize_t show_in##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset], \
-                      data->in_vref)); \
-} \
-static ssize_t show_in##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset], \
-                      data->in_vref)); \
-} \
-static ssize_t show_in##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset], \
-                      data->in_vref)); \
-} \
-static ssize_t show_in##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", data->in_status[offset]); \
-} \
-static ssize_t set_in##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct pc87360_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       down(&data->update_lock); \
-       data->in_min[offset] = IN_TO_REG(val, data->in_vref); \
-       pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MIN, \
-                           data->in_min[offset]); \
-       up(&data->update_lock); \
-       return count; \
-} \
-static ssize_t set_in##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct pc87360_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       down(&data->update_lock); \
-       data->in_max[offset] = IN_TO_REG(val, \
-                              data->in_vref); \
-       pc87360_write_value(data, LD_IN, offset, PC87365_REG_IN_MAX, \
-                           data->in_max[offset]); \
-       up(&data->update_lock); \
-       return count; \
-} \
-static DEVICE_ATTR(in##offset##_input, S_IRUGO, \
-       show_in##offset##_input, NULL); \
-static DEVICE_ATTR(in##offset##_min, S_IWUSR | S_IRUGO, \
-       show_in##offset##_min, set_in##offset##_min); \
-static DEVICE_ATTR(in##offset##_max, S_IWUSR | S_IRUGO, \
-       show_in##offset##_max, set_in##offset##_max); \
-static DEVICE_ATTR(in##offset##_status, S_IRUGO, \
-       show_in##offset##_status, NULL);
-show_and_set_in(0)
-show_and_set_in(1)
-show_and_set_in(2)
-show_and_set_in(3)
-show_and_set_in(4)
-show_and_set_in(5)
-show_and_set_in(6)
-show_and_set_in(7)
-show_and_set_in(8)
-show_and_set_in(9)
-show_and_set_in(10)
-
-#define show_and_set_therm(offset) \
-static ssize_t show_temp##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", IN_FROM_REG(data->in[offset+7], \
-                      data->in_vref)); \
-} \
-static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[offset+7], \
-                      data->in_vref)); \
-} \
-static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[offset+7], \
-                      data->in_vref)); \
-} \
-static ssize_t show_temp##offset##_crit(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[offset-4], \
-                      data->in_vref)); \
-} \
-static ssize_t show_temp##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%u\n", data->in_status[offset+7]); \
-} \
-static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct pc87360_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       down(&data->update_lock); \
-       data->in_min[offset+7] = IN_TO_REG(val, data->in_vref); \
-       pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MIN, \
-                           data->in_min[offset+7]); \
-       up(&data->update_lock); \
-       return count; \
-} \
-static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct pc87360_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       down(&data->update_lock); \
-       data->in_max[offset+7] = IN_TO_REG(val, data->in_vref); \
-       pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_MAX, \
-                           data->in_max[offset+7]); \
-       up(&data->update_lock); \
-       return count; \
-} \
-static ssize_t set_temp##offset##_crit(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct pc87360_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       down(&data->update_lock); \
-       data->in_crit[offset-4] = IN_TO_REG(val, data->in_vref); \
-       pc87360_write_value(data, LD_IN, offset+7, PC87365_REG_TEMP_CRIT, \
-                           data->in_crit[offset-4]); \
-       up(&data->update_lock); \
-       return count; \
-} \
-static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
-       show_temp##offset##_input, NULL); \
-static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
-       show_temp##offset##_min, set_temp##offset##_min); \
-static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
-       show_temp##offset##_max, set_temp##offset##_max); \
-static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \
-       show_temp##offset##_crit, set_temp##offset##_crit); \
-static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \
-       show_temp##offset##_status, NULL);
-show_and_set_therm(4)
-show_and_set_therm(5)
-show_and_set_therm(6)
+static struct sensor_device_attribute pwm[] = {
+       SENSOR_ATTR(pwm1, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 0),
+       SENSOR_ATTR(pwm2, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 1),
+       SENSOR_ATTR(pwm3, S_IWUSR | S_IRUGO, show_pwm, set_pwm, 2),
+};
+
+static struct attribute * pc8736x_fan_attr_array[] = {
+       FAN_UNIT_ATTRS(0),
+       FAN_UNIT_ATTRS(1),
+       FAN_UNIT_ATTRS(2),
+       &pwm[0].dev_attr.attr,
+       &pwm[1].dev_attr.attr,
+       &pwm[2].dev_attr.attr,
+       NULL
+};
+static const struct attribute_group pc8736x_fan_group = {
+       .attrs = pc8736x_fan_attr_array,
+};
+
+static ssize_t show_in_input(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index],
+                      data->in_vref));
+}
+static ssize_t show_in_min(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index],
+                      data->in_vref));
+}
+static ssize_t show_in_max(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index],
+                      data->in_vref));
+}
+static ssize_t show_in_status(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n", data->in_status[attr->index]);
+}
+static ssize_t set_in_min(struct device *dev, struct device_attribute *devattr, const char *buf,
+       size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = dev_get_drvdata(dev);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
+       pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MIN,
+                           data->in_min[attr->index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+static ssize_t set_in_max(struct device *dev, struct device_attribute *devattr, const char *buf,
+       size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = dev_get_drvdata(dev);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->in_max[attr->index] = IN_TO_REG(val,
+                              data->in_vref);
+       pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_IN_MAX,
+                           data->in_max[attr->index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+static struct sensor_device_attribute in_input[] = {
+       SENSOR_ATTR(in0_input, S_IRUGO, show_in_input, NULL, 0),
+       SENSOR_ATTR(in1_input, S_IRUGO, show_in_input, NULL, 1),
+       SENSOR_ATTR(in2_input, S_IRUGO, show_in_input, NULL, 2),
+       SENSOR_ATTR(in3_input, S_IRUGO, show_in_input, NULL, 3),
+       SENSOR_ATTR(in4_input, S_IRUGO, show_in_input, NULL, 4),
+       SENSOR_ATTR(in5_input, S_IRUGO, show_in_input, NULL, 5),
+       SENSOR_ATTR(in6_input, S_IRUGO, show_in_input, NULL, 6),
+       SENSOR_ATTR(in7_input, S_IRUGO, show_in_input, NULL, 7),
+       SENSOR_ATTR(in8_input, S_IRUGO, show_in_input, NULL, 8),
+       SENSOR_ATTR(in9_input, S_IRUGO, show_in_input, NULL, 9),
+       SENSOR_ATTR(in10_input, S_IRUGO, show_in_input, NULL, 10),
+};
+static struct sensor_device_attribute in_status[] = {
+       SENSOR_ATTR(in0_status, S_IRUGO, show_in_status, NULL, 0),
+       SENSOR_ATTR(in1_status, S_IRUGO, show_in_status, NULL, 1),
+       SENSOR_ATTR(in2_status, S_IRUGO, show_in_status, NULL, 2),
+       SENSOR_ATTR(in3_status, S_IRUGO, show_in_status, NULL, 3),
+       SENSOR_ATTR(in4_status, S_IRUGO, show_in_status, NULL, 4),
+       SENSOR_ATTR(in5_status, S_IRUGO, show_in_status, NULL, 5),
+       SENSOR_ATTR(in6_status, S_IRUGO, show_in_status, NULL, 6),
+       SENSOR_ATTR(in7_status, S_IRUGO, show_in_status, NULL, 7),
+       SENSOR_ATTR(in8_status, S_IRUGO, show_in_status, NULL, 8),
+       SENSOR_ATTR(in9_status, S_IRUGO, show_in_status, NULL, 9),
+       SENSOR_ATTR(in10_status, S_IRUGO, show_in_status, NULL, 10),
+};
+static struct sensor_device_attribute in_min[] = {
+       SENSOR_ATTR(in0_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 0),
+       SENSOR_ATTR(in1_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 1),
+       SENSOR_ATTR(in2_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 2),
+       SENSOR_ATTR(in3_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 3),
+       SENSOR_ATTR(in4_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 4),
+       SENSOR_ATTR(in5_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 5),
+       SENSOR_ATTR(in6_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 6),
+       SENSOR_ATTR(in7_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 7),
+       SENSOR_ATTR(in8_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 8),
+       SENSOR_ATTR(in9_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 9),
+       SENSOR_ATTR(in10_min, S_IWUSR | S_IRUGO, show_in_min, set_in_min, 10),
+};
+static struct sensor_device_attribute in_max[] = {
+       SENSOR_ATTR(in0_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 0),
+       SENSOR_ATTR(in1_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 1),
+       SENSOR_ATTR(in2_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 2),
+       SENSOR_ATTR(in3_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 3),
+       SENSOR_ATTR(in4_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 4),
+       SENSOR_ATTR(in5_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 5),
+       SENSOR_ATTR(in6_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 6),
+       SENSOR_ATTR(in7_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 7),
+       SENSOR_ATTR(in8_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 8),
+       SENSOR_ATTR(in9_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 9),
+       SENSOR_ATTR(in10_max, S_IWUSR | S_IRUGO, show_in_max, set_in_max, 10),
+};
+
+/* (temp & vin) channel status register alarm bits (pdf sec.11.5.12) */
+#define CHAN_ALM_MIN   0x02    /* min limit crossed */
+#define CHAN_ALM_MAX   0x04    /* max limit exceeded */
+#define TEMP_ALM_CRIT  0x08    /* temp crit exceeded (temp only) */
+
+/* show_in_min/max_alarm() reads data from the per-channel status
+   register (sec 11.5.12), not the vin event status registers (sec
+   11.5.2) that (legacy) show_in_alarm() resds (via data->in_alarms) */
+
+static ssize_t show_in_min_alarm(struct device *dev,
+                       struct device_attribute *devattr, char *buf)
+{
+       struct pc87360_data *data = pc87360_update_device(dev);
+       unsigned nr = to_sensor_dev_attr(devattr)->index;
+
+       return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MIN));
+}
+static ssize_t show_in_max_alarm(struct device *dev,
+                       struct device_attribute *devattr, char *buf)
+{
+       struct pc87360_data *data = pc87360_update_device(dev);
+       unsigned nr = to_sensor_dev_attr(devattr)->index;
+
+       return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MAX));
+}
+
+static struct sensor_device_attribute in_min_alarm[] = {
+       SENSOR_ATTR(in0_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 0),
+       SENSOR_ATTR(in1_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 1),
+       SENSOR_ATTR(in2_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 2),
+       SENSOR_ATTR(in3_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 3),
+       SENSOR_ATTR(in4_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 4),
+       SENSOR_ATTR(in5_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 5),
+       SENSOR_ATTR(in6_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 6),
+       SENSOR_ATTR(in7_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 7),
+       SENSOR_ATTR(in8_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 8),
+       SENSOR_ATTR(in9_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 9),
+       SENSOR_ATTR(in10_min_alarm, S_IRUGO, show_in_min_alarm, NULL, 10),
+};
+static struct sensor_device_attribute in_max_alarm[] = {
+       SENSOR_ATTR(in0_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 0),
+       SENSOR_ATTR(in1_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 1),
+       SENSOR_ATTR(in2_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 2),
+       SENSOR_ATTR(in3_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 3),
+       SENSOR_ATTR(in4_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 4),
+       SENSOR_ATTR(in5_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 5),
+       SENSOR_ATTR(in6_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 6),
+       SENSOR_ATTR(in7_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 7),
+       SENSOR_ATTR(in8_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 8),
+       SENSOR_ATTR(in9_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 9),
+       SENSOR_ATTR(in10_max_alarm, S_IRUGO, show_in_max_alarm, NULL, 10),
+};
+
+#define VIN_UNIT_ATTRS(X) \
+       &in_input[X].dev_attr.attr,     \
+       &in_status[X].dev_attr.attr,    \
+       &in_min[X].dev_attr.attr,       \
+       &in_max[X].dev_attr.attr,       \
+       &in_min_alarm[X].dev_attr.attr, \
+       &in_max_alarm[X].dev_attr.attr
 
 static ssize_t show_vid(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -514,13 +561,12 @@ static DEVICE_ATTR(cpu0_vid, S_IRUGO, show_vid, NULL);
 
 static ssize_t show_vrm(struct device *dev, struct device_attribute *attr, char *buf)
 {
-       struct pc87360_data *data = pc87360_update_device(dev);
+       struct pc87360_data *data = dev_get_drvdata(dev);
        return sprintf(buf, "%u\n", data->vrm);
 }
 static ssize_t set_vrm(struct device *dev, struct device_attribute *attr, const char *buf, size_t count)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct pc87360_data *data = i2c_get_clientdata(client);
+       struct pc87360_data *data = dev_get_drvdata(dev);
        data->vrm = simple_strtoul(buf, NULL, 10);
        return count;
 }
@@ -533,87 +579,322 @@ static ssize_t show_in_alarms(struct device *dev, struct device_attribute *attr,
 }
 static DEVICE_ATTR(alarms_in, S_IRUGO, show_in_alarms, NULL);
 
-#define show_and_set_temp(offset) \
-static ssize_t show_temp##offset##_input(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[offset-1])); \
-} \
-static ssize_t show_temp##offset##_min(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[offset-1])); \
-} \
-static ssize_t show_temp##offset##_max(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[offset-1])); \
-}\
-static ssize_t show_temp##offset##_crit(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[offset-1])); \
-}\
-static ssize_t show_temp##offset##_status(struct device *dev, struct device_attribute *attr, char *buf) \
-{ \
-       struct pc87360_data *data = pc87360_update_device(dev); \
-       return sprintf(buf, "%d\n", data->temp_status[offset-1]); \
-}\
-static ssize_t set_temp##offset##_min(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct pc87360_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       down(&data->update_lock); \
-       data->temp_min[offset-1] = TEMP_TO_REG(val); \
-       pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MIN, \
-                           data->temp_min[offset-1]); \
-       up(&data->update_lock); \
-       return count; \
-} \
-static ssize_t set_temp##offset##_max(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct pc87360_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       down(&data->update_lock); \
-       data->temp_max[offset-1] = TEMP_TO_REG(val); \
-       pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_MAX, \
-                           data->temp_max[offset-1]); \
-       up(&data->update_lock); \
-       return count; \
-} \
-static ssize_t set_temp##offset##_crit(struct device *dev, struct device_attribute *attr, const char *buf, \
-       size_t count) \
-{ \
-       struct i2c_client *client = to_i2c_client(dev); \
-       struct pc87360_data *data = i2c_get_clientdata(client); \
-       long val = simple_strtol(buf, NULL, 10); \
- \
-       down(&data->update_lock); \
-       data->temp_crit[offset-1] = TEMP_TO_REG(val); \
-       pc87360_write_value(data, LD_TEMP, offset-1, PC87365_REG_TEMP_CRIT, \
-                           data->temp_crit[offset-1]); \
-       up(&data->update_lock); \
-       return count; \
-} \
-static DEVICE_ATTR(temp##offset##_input, S_IRUGO, \
-       show_temp##offset##_input, NULL); \
-static DEVICE_ATTR(temp##offset##_min, S_IWUSR | S_IRUGO, \
-       show_temp##offset##_min, set_temp##offset##_min); \
-static DEVICE_ATTR(temp##offset##_max, S_IWUSR | S_IRUGO, \
-       show_temp##offset##_max, set_temp##offset##_max); \
-static DEVICE_ATTR(temp##offset##_crit, S_IWUSR | S_IRUGO, \
-       show_temp##offset##_crit, set_temp##offset##_crit); \
-static DEVICE_ATTR(temp##offset##_status, S_IRUGO, \
-       show_temp##offset##_status, NULL);
-show_and_set_temp(1)
-show_and_set_temp(2)
-show_and_set_temp(3)
+static struct attribute *pc8736x_vin_attr_array[] = {
+       VIN_UNIT_ATTRS(0),
+       VIN_UNIT_ATTRS(1),
+       VIN_UNIT_ATTRS(2),
+       VIN_UNIT_ATTRS(3),
+       VIN_UNIT_ATTRS(4),
+       VIN_UNIT_ATTRS(5),
+       VIN_UNIT_ATTRS(6),
+       VIN_UNIT_ATTRS(7),
+       VIN_UNIT_ATTRS(8),
+       VIN_UNIT_ATTRS(9),
+       VIN_UNIT_ATTRS(10),
+       &dev_attr_cpu0_vid.attr,
+       &dev_attr_vrm.attr,
+       &dev_attr_alarms_in.attr,
+       NULL
+};
+static const struct attribute_group pc8736x_vin_group = {
+       .attrs = pc8736x_vin_attr_array,
+};
+
+static ssize_t show_therm_input(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n", IN_FROM_REG(data->in[attr->index],
+                      data->in_vref));
+}
+static ssize_t show_therm_min(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_min[attr->index],
+                      data->in_vref));
+}
+static ssize_t show_therm_max(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_max[attr->index],
+                      data->in_vref));
+}
+static ssize_t show_therm_crit(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n", IN_FROM_REG(data->in_crit[attr->index-11],
+                      data->in_vref));
+}
+static ssize_t show_therm_status(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%u\n", data->in_status[attr->index]);
+}
+static ssize_t set_therm_min(struct device *dev, struct device_attribute *devattr, const char *buf,
+       size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = dev_get_drvdata(dev);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->in_min[attr->index] = IN_TO_REG(val, data->in_vref);
+       pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MIN,
+                           data->in_min[attr->index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+static ssize_t set_therm_max(struct device *dev, struct device_attribute *devattr, const char *buf,
+       size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = dev_get_drvdata(dev);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->in_max[attr->index] = IN_TO_REG(val, data->in_vref);
+       pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_MAX,
+                           data->in_max[attr->index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+static ssize_t set_therm_crit(struct device *dev, struct device_attribute *devattr, const char *buf,
+       size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = dev_get_drvdata(dev);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->in_crit[attr->index-11] = IN_TO_REG(val, data->in_vref);
+       pc87360_write_value(data, LD_IN, attr->index, PC87365_REG_TEMP_CRIT,
+                           data->in_crit[attr->index-11]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+/* the +11 term below reflects the fact that VLM units 11,12,13 are
+   used in the chip to measure voltage across the thermistors
+*/
+static struct sensor_device_attribute therm_input[] = {
+       SENSOR_ATTR(temp4_input, S_IRUGO, show_therm_input, NULL, 0+11),
+       SENSOR_ATTR(temp5_input, S_IRUGO, show_therm_input, NULL, 1+11),
+       SENSOR_ATTR(temp6_input, S_IRUGO, show_therm_input, NULL, 2+11),
+};
+static struct sensor_device_attribute therm_status[] = {
+       SENSOR_ATTR(temp4_status, S_IRUGO, show_therm_status, NULL, 0+11),
+       SENSOR_ATTR(temp5_status, S_IRUGO, show_therm_status, NULL, 1+11),
+       SENSOR_ATTR(temp6_status, S_IRUGO, show_therm_status, NULL, 2+11),
+};
+static struct sensor_device_attribute therm_min[] = {
+       SENSOR_ATTR(temp4_min, S_IRUGO | S_IWUSR,
+                   show_therm_min, set_therm_min, 0+11),
+       SENSOR_ATTR(temp5_min, S_IRUGO | S_IWUSR,
+                   show_therm_min, set_therm_min, 1+11),
+       SENSOR_ATTR(temp6_min, S_IRUGO | S_IWUSR,
+                   show_therm_min, set_therm_min, 2+11),
+};
+static struct sensor_device_attribute therm_max[] = {
+       SENSOR_ATTR(temp4_max, S_IRUGO | S_IWUSR,
+                   show_therm_max, set_therm_max, 0+11),
+       SENSOR_ATTR(temp5_max, S_IRUGO | S_IWUSR,
+                   show_therm_max, set_therm_max, 1+11),
+       SENSOR_ATTR(temp6_max, S_IRUGO | S_IWUSR,
+                   show_therm_max, set_therm_max, 2+11),
+};
+static struct sensor_device_attribute therm_crit[] = {
+       SENSOR_ATTR(temp4_crit, S_IRUGO | S_IWUSR,
+                   show_therm_crit, set_therm_crit, 0+11),
+       SENSOR_ATTR(temp5_crit, S_IRUGO | S_IWUSR,
+                   show_therm_crit, set_therm_crit, 1+11),
+       SENSOR_ATTR(temp6_crit, S_IRUGO | S_IWUSR,
+                   show_therm_crit, set_therm_crit, 2+11),
+};
+
+/* show_therm_min/max_alarm() reads data from the per-channel voltage
+   status register (sec 11.5.12) */
+
+static ssize_t show_therm_min_alarm(struct device *dev,
+                               struct device_attribute *devattr, char *buf)
+{
+       struct pc87360_data *data = pc87360_update_device(dev);
+       unsigned nr = to_sensor_dev_attr(devattr)->index;
+
+       return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MIN));
+}
+static ssize_t show_therm_max_alarm(struct device *dev,
+                               struct device_attribute *devattr, char *buf)
+{
+       struct pc87360_data *data = pc87360_update_device(dev);
+       unsigned nr = to_sensor_dev_attr(devattr)->index;
+
+       return sprintf(buf, "%u\n", !!(data->in_status[nr] & CHAN_ALM_MAX));
+}
+static ssize_t show_therm_crit_alarm(struct device *dev,
+                               struct device_attribute *devattr, char *buf)
+{
+       struct pc87360_data *data = pc87360_update_device(dev);
+       unsigned nr = to_sensor_dev_attr(devattr)->index;
+
+       return sprintf(buf, "%u\n", !!(data->in_status[nr] & TEMP_ALM_CRIT));
+}
+
+static struct sensor_device_attribute therm_min_alarm[] = {
+       SENSOR_ATTR(temp4_min_alarm, S_IRUGO,
+                   show_therm_min_alarm, NULL, 0+11),
+       SENSOR_ATTR(temp5_min_alarm, S_IRUGO,
+                   show_therm_min_alarm, NULL, 1+11),
+       SENSOR_ATTR(temp6_min_alarm, S_IRUGO,
+                   show_therm_min_alarm, NULL, 2+11),
+};
+static struct sensor_device_attribute therm_max_alarm[] = {
+       SENSOR_ATTR(temp4_max_alarm, S_IRUGO,
+                   show_therm_max_alarm, NULL, 0+11),
+       SENSOR_ATTR(temp5_max_alarm, S_IRUGO,
+                   show_therm_max_alarm, NULL, 1+11),
+       SENSOR_ATTR(temp6_max_alarm, S_IRUGO,
+                   show_therm_max_alarm, NULL, 2+11),
+};
+static struct sensor_device_attribute therm_crit_alarm[] = {
+       SENSOR_ATTR(temp4_crit_alarm, S_IRUGO,
+                   show_therm_crit_alarm, NULL, 0+11),
+       SENSOR_ATTR(temp5_crit_alarm, S_IRUGO,
+                   show_therm_crit_alarm, NULL, 1+11),
+       SENSOR_ATTR(temp6_crit_alarm, S_IRUGO,
+                   show_therm_crit_alarm, NULL, 2+11),
+};
+
+#define THERM_UNIT_ATTRS(X) \
+       &therm_input[X].dev_attr.attr,  \
+       &therm_status[X].dev_attr.attr, \
+       &therm_min[X].dev_attr.attr,    \
+       &therm_max[X].dev_attr.attr,    \
+       &therm_crit[X].dev_attr.attr,   \
+       &therm_min_alarm[X].dev_attr.attr, \
+       &therm_max_alarm[X].dev_attr.attr, \
+       &therm_crit_alarm[X].dev_attr.attr
+
+static struct attribute * pc8736x_therm_attr_array[] = {
+       THERM_UNIT_ATTRS(0),
+       THERM_UNIT_ATTRS(1),
+       THERM_UNIT_ATTRS(2),
+       NULL
+};
+static const struct attribute_group pc8736x_therm_group = {
+       .attrs = pc8736x_therm_attr_array,
+};
+
+static ssize_t show_temp_input(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp[attr->index]));
+}
+static ssize_t show_temp_min(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_min[attr->index]));
+}
+static ssize_t show_temp_max(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_max[attr->index]));
+}
+static ssize_t show_temp_crit(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%d\n", TEMP_FROM_REG(data->temp_crit[attr->index]));
+}
+static ssize_t show_temp_status(struct device *dev, struct device_attribute *devattr, char *buf)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = pc87360_update_device(dev);
+       return sprintf(buf, "%d\n", data->temp_status[attr->index]);
+}
+static ssize_t set_temp_min(struct device *dev, struct device_attribute *devattr, const char *buf,
+       size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = dev_get_drvdata(dev);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->temp_min[attr->index] = TEMP_TO_REG(val);
+       pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MIN,
+                           data->temp_min[attr->index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+static ssize_t set_temp_max(struct device *dev, struct device_attribute *devattr, const char *buf,
+       size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = dev_get_drvdata(dev);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->temp_max[attr->index] = TEMP_TO_REG(val);
+       pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_MAX,
+                           data->temp_max[attr->index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+static ssize_t set_temp_crit(struct device *dev, struct device_attribute *devattr, const char *buf,
+       size_t count)
+{
+       struct sensor_device_attribute *attr = to_sensor_dev_attr(devattr);
+       struct pc87360_data *data = dev_get_drvdata(dev);
+       long val = simple_strtol(buf, NULL, 10);
+
+       mutex_lock(&data->update_lock);
+       data->temp_crit[attr->index] = TEMP_TO_REG(val);
+       pc87360_write_value(data, LD_TEMP, attr->index, PC87365_REG_TEMP_CRIT,
+                           data->temp_crit[attr->index]);
+       mutex_unlock(&data->update_lock);
+       return count;
+}
+
+static struct sensor_device_attribute temp_input[] = {
+       SENSOR_ATTR(temp1_input, S_IRUGO, show_temp_input, NULL, 0),
+       SENSOR_ATTR(temp2_input, S_IRUGO, show_temp_input, NULL, 1),
+       SENSOR_ATTR(temp3_input, S_IRUGO, show_temp_input, NULL, 2),
+};
+static struct sensor_device_attribute temp_status[] = {
+       SENSOR_ATTR(temp1_status, S_IRUGO, show_temp_status, NULL, 0),
+       SENSOR_ATTR(temp2_status, S_IRUGO, show_temp_status, NULL, 1),
+       SENSOR_ATTR(temp3_status, S_IRUGO, show_temp_status, NULL, 2),
+};
+static struct sensor_device_attribute temp_min[] = {
+       SENSOR_ATTR(temp1_min, S_IRUGO | S_IWUSR,
+                   show_temp_min, set_temp_min, 0),
+       SENSOR_ATTR(temp2_min, S_IRUGO | S_IWUSR,
+                   show_temp_min, set_temp_min, 1),
+       SENSOR_ATTR(temp3_min, S_IRUGO | S_IWUSR,
+                   show_temp_min, set_temp_min, 2),
+};
+static struct sensor_device_attribute temp_max[] = {
+       SENSOR_ATTR(temp1_max, S_IRUGO | S_IWUSR,
+                   show_temp_max, set_temp_max, 0),
+       SENSOR_ATTR(temp2_max, S_IRUGO | S_IWUSR,
+                   show_temp_max, set_temp_max, 1),
+       SENSOR_ATTR(temp3_max, S_IRUGO | S_IWUSR,
+                   show_temp_max, set_temp_max, 2),
+};
+static struct sensor_device_attribute temp_crit[] = {
+       SENSOR_ATTR(temp1_crit, S_IRUGO | S_IWUSR,
+                   show_temp_crit, set_temp_crit, 0),
+       SENSOR_ATTR(temp2_crit, S_IRUGO | S_IWUSR,
+                   show_temp_crit, set_temp_crit, 1),
+       SENSOR_ATTR(temp3_crit, S_IRUGO | S_IWUSR,
+                   show_temp_crit, set_temp_crit, 2),
+};
 
 static ssize_t show_temp_alarms(struct device *dev, struct device_attribute *attr, char *buf)
 {
@@ -622,6 +903,97 @@ static ssize_t show_temp_alarms(struct device *dev, struct device_attribute *att
 }
 static DEVICE_ATTR(alarms_temp, S_IRUGO, show_temp_alarms, NULL);
 
+/* show_temp_min/max_alarm() reads data from the per-channel status
+   register (sec 12.3.7), not the temp event status registers (sec
+   12.3.2) that show_temp_alarm() reads (via data->temp_alarms) */
+
+static ssize_t show_temp_min_alarm(struct device *dev,
+                       struct device_attribute *devattr, char *buf)
+{
+       struct pc87360_data *data = pc87360_update_device(dev);
+       unsigned nr = to_sensor_dev_attr(devattr)->index;
+
+       return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MIN));
+}
+static ssize_t show_temp_max_alarm(struct device *dev,
+                       struct device_attribute *devattr, char *buf)
+{
+       struct pc87360_data *data = pc87360_update_device(dev);
+       unsigned nr = to_sensor_dev_attr(devattr)->index;
+
+       return sprintf(buf, "%u\n", !!(data->temp_status[nr] & CHAN_ALM_MAX));
+}
+static ssize_t show_temp_crit_alarm(struct device *dev,
+                       struct device_attribute *devattr, char *buf)
+{
+       struct pc87360_data *data = pc87360_update_device(dev);
+       unsigned nr = to_sensor_dev_attr(devattr)->index;
+
+       return sprintf(buf, "%u\n", !!(data->temp_status[nr] & TEMP_ALM_CRIT));
+}
+
+static struct sensor_device_attribute temp_min_alarm[] = {
+       SENSOR_ATTR(temp1_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 0),
+       SENSOR_ATTR(temp2_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 1),
+       SENSOR_ATTR(temp3_min_alarm, S_IRUGO, show_temp_min_alarm, NULL, 2),
+};
+static struct sensor_device_attribute temp_max_alarm[] = {
+       SENSOR_ATTR(temp1_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 0),
+       SENSOR_ATTR(temp2_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 1),
+       SENSOR_ATTR(temp3_max_alarm, S_IRUGO, show_temp_max_alarm, NULL, 2),
+};
+static struct sensor_device_attribute temp_crit_alarm[] = {
+       SENSOR_ATTR(temp1_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 0),
+       SENSOR_ATTR(temp2_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 1),
+       SENSOR_ATTR(temp3_crit_alarm, S_IRUGO, show_temp_crit_alarm, NULL, 2),
+};
+
+#define TEMP_FAULT     0x40    /* open diode */
+static ssize_t show_temp_fault(struct device *dev,
+                       struct device_attribute *devattr, char *buf)
+{
+       struct pc87360_data *data = pc87360_update_device(dev);
+       unsigned nr = to_sensor_dev_attr(devattr)->index;
+
+       return sprintf(buf, "%u\n", !!(data->temp_status[nr] & TEMP_FAULT));
+}
+static struct sensor_device_attribute temp_fault[] = {
+       SENSOR_ATTR(temp1_fault, S_IRUGO, show_temp_fault, NULL, 0),
+       SENSOR_ATTR(temp2_fault, S_IRUGO, show_temp_fault, NULL, 1),
+       SENSOR_ATTR(temp3_fault, S_IRUGO, show_temp_fault, NULL, 2),
+};
+
+#define TEMP_UNIT_ATTRS(X) \
+       &temp_input[X].dev_attr.attr,   \
+       &temp_status[X].dev_attr.attr,  \
+       &temp_min[X].dev_attr.attr,     \
+       &temp_max[X].dev_attr.attr,     \
+       &temp_crit[X].dev_attr.attr,    \
+       &temp_min_alarm[X].dev_attr.attr, \
+       &temp_max_alarm[X].dev_attr.attr, \
+       &temp_crit_alarm[X].dev_attr.attr, \
+       &temp_fault[X].dev_attr.attr
+
+static struct attribute * pc8736x_temp_attr_array[] = {
+       TEMP_UNIT_ATTRS(0),
+       TEMP_UNIT_ATTRS(1),
+       TEMP_UNIT_ATTRS(2),
+       /* include the few miscellaneous atts here */
+       &dev_attr_alarms_temp.attr,
+       NULL
+};
+static const struct attribute_group pc8736x_temp_group = {
+       .attrs = pc8736x_temp_attr_array,
+};
+
+static ssize_t show_name(struct device *dev,
+                       struct device_attribute *devattr, char *buf)
+{
+       struct pc87360_data *data = dev_get_drvdata(dev);
+       return sprintf(buf, "%s\n", data->name);
+}
+static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);
+
 /*
  * Device detection, registration and update
  */
@@ -635,7 +1007,7 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
        /* No superio_enter */
 
        /* Identify device */
-       val = superio_inb(sioaddr, DEVID);
+       val = force_id ? force_id : superio_inb(sioaddr, DEVID);
        switch (val) {
        case 0xE1: /* PC87360 */
        case 0xE8: /* PC87363 */
@@ -716,26 +1088,17 @@ static int __init pc87360_find(int sioaddr, u8 *devid, unsigned short *addresses
        return 0;
 }
 
-static int pc87360_detect(struct i2c_adapter *adapter)
+static int __devinit pc87360_probe(struct platform_device *pdev)
 {
        int i;
-       struct i2c_client *new_client;
        struct pc87360_data *data;
        int err = 0;
        const char *name = "pc87360";
        int use_thermistors = 0;
+       struct device *dev = &pdev->dev;
 
-       if (!(data = kmalloc(sizeof(struct pc87360_data), GFP_KERNEL)))
+       if (!(data = kzalloc(sizeof(struct pc87360_data), GFP_KERNEL)))
                return -ENOMEM;
-       memset(data, 0x00, sizeof(struct pc87360_data));
-
-       new_client = &data->client;
-       i2c_set_clientdata(new_client, data);
-       new_client->addr = address;
-       init_MUTEX(&data->lock);
-       new_client->adapter = adapter;
-       new_client->driver = &pc87360_driver;
-       new_client->flags = 0;
 
        data->fannr = 2;
        data->innr = 0;
@@ -763,15 +1126,17 @@ static int pc87360_detect(struct i2c_adapter *adapter)
                break;
        }
 
-       strcpy(new_client->name, name);
+       data->name = name;
        data->valid = 0;
-       init_MUTEX(&data->update_lock);
+       mutex_init(&data->lock);
+       mutex_init(&data->update_lock);
+       platform_set_drvdata(pdev, data);
 
-       for (i = 0; i < 3; i++) {
+       for (i = 0; i < LDNI_MAX; i++) {
                if (((data->address[i] = extra_isa[i]))
                 && !request_region(extra_isa[i], PC87360_EXTENT,
-                                   pc87360_driver.name)) {
-                       dev_err(&new_client->dev, "Region 0x%x-0x%x already "
+                                   pc87360_driver.driver.name)) {
+                       dev_err(dev, "Region 0x%x-0x%x already "
                                "in use!\n", extra_isa[i],
                                extra_isa[i]+PC87360_EXTENT-1);
                        for (i--; i >= 0; i--)
@@ -785,9 +1150,6 @@ static int pc87360_detect(struct i2c_adapter *adapter)
        if (data->fannr)
                data->fan_conf = confreg[0] | (confreg[1] << 8);
 
-       if ((err = i2c_attach_client(new_client)))
-               goto ERROR2;
-
        /* Use the correct reference voltage
           Unless both the VLM and the TMS logical devices agree to
           use an external Vref, the internal one is used. */
@@ -799,11 +1161,11 @@ static int pc87360_detect(struct i2c_adapter *adapter)
                                                PC87365_REG_TEMP_CONFIG);
                }
                data->in_vref = (i&0x02) ? 3025 : 2966;
-               dev_dbg(&new_client->dev, "Using %s reference voltage\n",
+               dev_dbg(dev, "Using %s reference voltage\n",
                        (i&0x02) ? "external" : "internal");
 
                data->vid_conf = confreg[3];
-               data->vrm = 90;
+               data->vrm = vid_which_vrm();
        }
 
        /* Fan clock dividers may be needed before any data is read */
@@ -818,155 +1180,83 @@ static int pc87360_detect(struct i2c_adapter *adapter)
                if (devid == 0xe9 && data->address[1]) /* PC87366 */
                        use_thermistors = confreg[2] & 0x40;
 
-               pc87360_init_client(new_client, use_thermistors);
+               pc87360_init_device(pdev, use_thermistors);
        }
 
-       /* Register sysfs hooks */
-       data->class_dev = hwmon_device_register(&new_client->dev);
-       if (IS_ERR(data->class_dev)) {
-               err = PTR_ERR(data->class_dev);
-               goto ERROR3;
-       }
+       /* Register all-or-nothing sysfs groups */
 
-       if (data->innr) {
-               device_create_file(&new_client->dev, &dev_attr_in0_input);
-               device_create_file(&new_client->dev, &dev_attr_in1_input);
-               device_create_file(&new_client->dev, &dev_attr_in2_input);
-               device_create_file(&new_client->dev, &dev_attr_in3_input);
-               device_create_file(&new_client->dev, &dev_attr_in4_input);
-               device_create_file(&new_client->dev, &dev_attr_in5_input);
-               device_create_file(&new_client->dev, &dev_attr_in6_input);
-               device_create_file(&new_client->dev, &dev_attr_in7_input);
-               device_create_file(&new_client->dev, &dev_attr_in8_input);
-               device_create_file(&new_client->dev, &dev_attr_in9_input);
-               device_create_file(&new_client->dev, &dev_attr_in10_input);
-               device_create_file(&new_client->dev, &dev_attr_in0_min);
-               device_create_file(&new_client->dev, &dev_attr_in1_min);
-               device_create_file(&new_client->dev, &dev_attr_in2_min);
-               device_create_file(&new_client->dev, &dev_attr_in3_min);
-               device_create_file(&new_client->dev, &dev_attr_in4_min);
-               device_create_file(&new_client->dev, &dev_attr_in5_min);
-               device_create_file(&new_client->dev, &dev_attr_in6_min);
-               device_create_file(&new_client->dev, &dev_attr_in7_min);
-               device_create_file(&new_client->dev, &dev_attr_in8_min);
-               device_create_file(&new_client->dev, &dev_attr_in9_min);
-               device_create_file(&new_client->dev, &dev_attr_in10_min);
-               device_create_file(&new_client->dev, &dev_attr_in0_max);
-               device_create_file(&new_client->dev, &dev_attr_in1_max);
-               device_create_file(&new_client->dev, &dev_attr_in2_max);
-               device_create_file(&new_client->dev, &dev_attr_in3_max);
-               device_create_file(&new_client->dev, &dev_attr_in4_max);
-               device_create_file(&new_client->dev, &dev_attr_in5_max);
-               device_create_file(&new_client->dev, &dev_attr_in6_max);
-               device_create_file(&new_client->dev, &dev_attr_in7_max);
-               device_create_file(&new_client->dev, &dev_attr_in8_max);
-               device_create_file(&new_client->dev, &dev_attr_in9_max);
-               device_create_file(&new_client->dev, &dev_attr_in10_max);
-               device_create_file(&new_client->dev, &dev_attr_in0_status);
-               device_create_file(&new_client->dev, &dev_attr_in1_status);
-               device_create_file(&new_client->dev, &dev_attr_in2_status);
-               device_create_file(&new_client->dev, &dev_attr_in3_status);
-               device_create_file(&new_client->dev, &dev_attr_in4_status);
-               device_create_file(&new_client->dev, &dev_attr_in5_status);
-               device_create_file(&new_client->dev, &dev_attr_in6_status);
-               device_create_file(&new_client->dev, &dev_attr_in7_status);
-               device_create_file(&new_client->dev, &dev_attr_in8_status);
-               device_create_file(&new_client->dev, &dev_attr_in9_status);
-               device_create_file(&new_client->dev, &dev_attr_in10_status);
-
-               device_create_file(&new_client->dev, &dev_attr_cpu0_vid);
-               device_create_file(&new_client->dev, &dev_attr_vrm);
-               device_create_file(&new_client->dev, &dev_attr_alarms_in);
-       }
+       if (data->innr &&
+           (err = sysfs_create_group(&dev->kobj,
+                                     &pc8736x_vin_group)))
+               goto ERROR3;
 
-       if (data->tempnr) {
-               device_create_file(&new_client->dev, &dev_attr_temp1_input);
-               device_create_file(&new_client->dev, &dev_attr_temp2_input);
-               device_create_file(&new_client->dev, &dev_attr_temp1_min);
-               device_create_file(&new_client->dev, &dev_attr_temp2_min);
-               device_create_file(&new_client->dev, &dev_attr_temp1_max);
-               device_create_file(&new_client->dev, &dev_attr_temp2_max);
-               device_create_file(&new_client->dev, &dev_attr_temp1_crit);
-               device_create_file(&new_client->dev, &dev_attr_temp2_crit);
-               device_create_file(&new_client->dev, &dev_attr_temp1_status);
-               device_create_file(&new_client->dev, &dev_attr_temp2_status);
-
-               device_create_file(&new_client->dev, &dev_attr_alarms_temp);
-       }
-       if (data->tempnr == 3) {
-               device_create_file(&new_client->dev, &dev_attr_temp3_input);
-               device_create_file(&new_client->dev, &dev_attr_temp3_min);
-               device_create_file(&new_client->dev, &dev_attr_temp3_max);
-               device_create_file(&new_client->dev, &dev_attr_temp3_crit);
-               device_create_file(&new_client->dev, &dev_attr_temp3_status);
-       }
-       if (data->innr == 14) {
-               device_create_file(&new_client->dev, &dev_attr_temp4_input);
-               device_create_file(&new_client->dev, &dev_attr_temp5_input);
-               device_create_file(&new_client->dev, &dev_attr_temp6_input);
-               device_create_file(&new_client->dev, &dev_attr_temp4_min);
-               device_create_file(&new_client->dev, &dev_attr_temp5_min);
-               device_create_file(&new_client->dev, &dev_attr_temp6_min);
-               device_create_file(&new_client->dev, &dev_attr_temp4_max);
-               device_create_file(&new_client->dev, &dev_attr_temp5_max);
-               device_create_file(&new_client->dev, &dev_attr_temp6_max);
-               device_create_file(&new_client->dev, &dev_attr_temp4_crit);
-               device_create_file(&new_client->dev, &dev_attr_temp5_crit);
-               device_create_file(&new_client->dev, &dev_attr_temp6_crit);
-               device_create_file(&new_client->dev, &dev_attr_temp4_status);
-               device_create_file(&new_client->dev, &dev_attr_temp5_status);
-               device_create_file(&new_client->dev, &dev_attr_temp6_status);
-       }
+       if (data->innr == 14 &&
+           (err = sysfs_create_group(&dev->kobj,
+                                     &pc8736x_therm_group)))
+               goto ERROR3;
 
-       if (data->fannr) {
-               if (FAN_CONFIG_MONITOR(data->fan_conf, 0)) {
-                       device_create_file(&new_client->dev,
-                                          &dev_attr_fan1_input);
-                       device_create_file(&new_client->dev,
-                                          &dev_attr_fan1_min);
-                       device_create_file(&new_client->dev,
-                                          &dev_attr_fan1_div);
-                       device_create_file(&new_client->dev,
-                                          &dev_attr_fan1_status);
-               }
+       /* create device attr-files for varying sysfs groups */
 
-               if (FAN_CONFIG_MONITOR(data->fan_conf, 1)) {
-                       device_create_file(&new_client->dev,
-                                          &dev_attr_fan2_input);
-                       device_create_file(&new_client->dev,
-                                          &dev_attr_fan2_min);
-                       device_create_file(&new_client->dev,
-                                          &dev_attr_fan2_div);
-                       device_create_file(&new_client->dev,
-                                          &dev_attr_fan2_status);
+       if (data->tempnr) {
+               for (i = 0; i < data->tempnr; i++) {
+                       if ((err = device_create_file(dev,
+                                       &temp_input[i].dev_attr))
+                           || (err = device_create_file(dev,
+                                       &temp_min[i].dev_attr))
+                           || (err = device_create_file(dev,
+                                       &temp_max[i].dev_attr))
+                           || (err = device_create_file(dev,
+                                       &temp_crit[i].dev_attr))
+                           || (err = device_create_file(dev,
+                                       &temp_status[i].dev_attr))
+                           || (err = device_create_file(dev,
+                                       &temp_min_alarm[i].dev_attr))
+                           || (err = device_create_file(dev,
+                                       &temp_max_alarm[i].dev_attr))
+                           || (err = device_create_file(dev,
+                                       &temp_crit_alarm[i].dev_attr))
+                           || (err = device_create_file(dev,
+                                       &temp_fault[i].dev_attr)))
+                               goto ERROR3;
                }
-
-               if (FAN_CONFIG_CONTROL(data->fan_conf, 0))
-                       device_create_file(&new_client->dev, &dev_attr_pwm1);
-               if (FAN_CONFIG_CONTROL(data->fan_conf, 1))
-                       device_create_file(&new_client->dev, &dev_attr_pwm2);
+               if ((err = device_create_file(dev, &dev_attr_alarms_temp)))
+                       goto ERROR3;
        }
-       if (data->fannr == 3) {
-               if (FAN_CONFIG_MONITOR(data->fan_conf, 2)) {
-                       device_create_file(&new_client->dev,
-                                          &dev_attr_fan3_input);
-                       device_create_file(&new_client->dev,
-                                          &dev_attr_fan3_min);
-                       device_create_file(&new_client->dev,
-                                          &dev_attr_fan3_div);
-                       device_create_file(&new_client->dev,
-                                          &dev_attr_fan3_status);
-               }
 
-               if (FAN_CONFIG_CONTROL(data->fan_conf, 2))
-                       device_create_file(&new_client->dev, &dev_attr_pwm3);
+       for (i = 0; i < data->fannr; i++) {
+               if (FAN_CONFIG_MONITOR(data->fan_conf, i)
+                   && ((err = device_create_file(dev,
+                                       &fan_input[i].dev_attr))
+                       || (err = device_create_file(dev,
+                                       &fan_min[i].dev_attr))
+                       || (err = device_create_file(dev,
+                                       &fan_div[i].dev_attr))
+                       || (err = device_create_file(dev,
+                                       &fan_status[i].dev_attr))))
+                       goto ERROR3;
+
+               if (FAN_CONFIG_CONTROL(data->fan_conf, i)
+                   && (err = device_create_file(dev, &pwm[i].dev_attr)))
+                       goto ERROR3;
        }
 
+       if ((err = device_create_file(dev, &dev_attr_name)))
+               goto ERROR3;
+
+       data->hwmon_dev = hwmon_device_register(dev);
+       if (IS_ERR(data->hwmon_dev)) {
+               err = PTR_ERR(data->hwmon_dev);
+               goto ERROR3;
+       }
        return 0;
 
 ERROR3:
-       i2c_detach_client(new_client);
-ERROR2:
+       device_remove_file(dev, &dev_attr_name);
+       /* can still remove groups whose members were added individually */
+       sysfs_remove_group(&dev->kobj, &pc8736x_temp_group);
+       sysfs_remove_group(&dev->kobj, &pc8736x_fan_group);
+       sysfs_remove_group(&dev->kobj, &pc8736x_therm_group);
+       sysfs_remove_group(&dev->kobj, &pc8736x_vin_group);
        for (i = 0; i < 3; i++) {
                if (data->address[i]) {
                        release_region(data->address[i], PC87360_EXTENT);
@@ -977,15 +1267,18 @@ ERROR1:
        return err;
 }
 
-static int pc87360_detach_client(struct i2c_client *client)
+static int __devexit pc87360_remove(struct platform_device *pdev)
 {
-       struct pc87360_data *data = i2c_get_clientdata(client);
+       struct pc87360_data *data = platform_get_drvdata(pdev);
        int i;
 
-       hwmon_device_unregister(data->class_dev);
+       hwmon_device_unregister(data->hwmon_dev);
 
-       if ((i = i2c_detach_client(client)))
-               return i;
+       device_remove_file(&pdev->dev, &dev_attr_name);
+       sysfs_remove_group(&pdev->dev.kobj, &pc8736x_temp_group);
+       sysfs_remove_group(&pdev->dev.kobj, &pc8736x_fan_group);
+       sysfs_remove_group(&pdev->dev.kobj, &pc8736x_therm_group);
+       sysfs_remove_group(&pdev->dev.kobj, &pc8736x_vin_group);
 
        for (i = 0; i < 3; i++) {
                if (data->address[i]) {
@@ -1004,11 +1297,11 @@ static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
 {
        int res;
 
-       down(&(data->lock));
+       mutex_lock(&(data->lock));
        if (bank != NO_BANK)
                outb_p(bank, data->address[ldi] + PC87365_REG_BANK);
        res = inb_p(data->address[ldi] + reg);
-       up(&(data->lock));
+       mutex_unlock(&(data->lock));
 
        return res;
 }
@@ -1016,16 +1309,27 @@ static int pc87360_read_value(struct pc87360_data *data, u8 ldi, u8 bank,
 static void pc87360_write_value(struct pc87360_data *data, u8 ldi, u8 bank,
                                u8 reg, u8 value)
 {
-       down(&(data->lock));
+       mutex_lock(&(data->lock));
        if (bank != NO_BANK)
                outb_p(bank, data->address[ldi] + PC87365_REG_BANK);
        outb_p(value, data->address[ldi] + reg);
-       up(&(data->lock));
+       mutex_unlock(&(data->lock));
 }
 
-static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
+/* (temp & vin) channel conversion status register flags (pdf sec.11.5.12) */
+#define CHAN_CNVRTD    0x80    /* new data ready */
+#define CHAN_ENA       0x01    /* enabled channel (temp or vin) */
+#define CHAN_ALM_ENA   0x10    /* propagate to alarms-reg ?? (chk val!) */
+#define CHAN_READY     (CHAN_ENA|CHAN_CNVRTD) /* sample ready mask */
+
+#define TEMP_OTS_OE    0x20    /* OTS Output Enable */
+#define VIN_RW1C_MASK  (CHAN_READY|CHAN_ALM_MAX|CHAN_ALM_MIN)   /* 0x87 */
+#define TEMP_RW1C_MASK (VIN_RW1C_MASK|TEMP_ALM_CRIT|TEMP_FAULT) /* 0xCF */
+
+static void pc87360_init_device(struct platform_device *pdev,
+                               int use_thermistors)
 {
-       struct pc87360_data *data = i2c_get_clientdata(client);
+       struct pc87360_data *data = platform_get_drvdata(pdev);
        int i, nr;
        const u8 init_in[14] = { 2, 2, 2, 2, 2, 2, 2, 1, 1, 3, 1, 2, 2, 2 };
        const u8 init_temp[3] = { 2, 2, 1 };
@@ -1034,7 +1338,7 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
        if (init >= 2 && data->innr) {
                reg = pc87360_read_value(data, LD_IN, NO_BANK,
                                         PC87365_REG_IN_CONVRATE);
-               dev_info(&client->dev, "VLM conversion set to "
+               dev_info(&pdev->dev, "VLM conversion set to "
                         "1s period, 160us delay\n");
                pc87360_write_value(data, LD_IN, NO_BANK,
                                    PC87365_REG_IN_CONVRATE,
@@ -1042,13 +1346,14 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
        }
 
        nr = data->innr < 11 ? data->innr : 11;
-       for (i=0; i<nr; i++) {
+       for (i = 0; i < nr; i++) {
+               reg = pc87360_read_value(data, LD_IN, i,
+                                        PC87365_REG_IN_STATUS);
+               dev_dbg(&pdev->dev, "bios in%d status:0x%02x\n", i, reg);
                if (init >= init_in[i]) {
                        /* Forcibly enable voltage channel */
-                       reg = pc87360_read_value(data, LD_IN, i,
-                                                PC87365_REG_IN_STATUS);
-                       if (!(reg & 0x01)) {
-                               dev_dbg(&client->dev, "Forcibly "
+                       if (!(reg & CHAN_ENA)) {
+                               dev_dbg(&pdev->dev, "Forcibly "
                                        "enabling in%d\n", i);
                                pc87360_write_value(data, LD_IN, i,
                                                    PC87365_REG_IN_STATUS,
@@ -1059,20 +1364,25 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
 
        /* We can't blindly trust the Super-I/O space configuration bit,
           most BIOS won't set it properly */
-       for (i=11; i<data->innr; i++) {
+       dev_dbg(&pdev->dev, "bios thermistors:%d\n", use_thermistors);
+       for (i = 11; i < data->innr; i++) {
                reg = pc87360_read_value(data, LD_IN, i,
                                         PC87365_REG_TEMP_STATUS);
-               use_thermistors = use_thermistors || (reg & 0x01);
+               use_thermistors = use_thermistors || (reg & CHAN_ENA);
+               /* thermistors are temp[4-6], measured on vin[11-14] */
+               dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i-7, reg);
        }
+       dev_dbg(&pdev->dev, "using thermistors:%d\n", use_thermistors);
 
        i = use_thermistors ? 2 : 0;
-       for (; i<data->tempnr; i++) {
+       for (; i < data->tempnr; i++) {
+               reg = pc87360_read_value(data, LD_TEMP, i,
+                                        PC87365_REG_TEMP_STATUS);
+               dev_dbg(&pdev->dev, "bios temp%d_status:0x%02x\n", i+1, reg);
                if (init >= init_temp[i]) {
                        /* Forcibly enable temperature channel */
-                       reg = pc87360_read_value(data, LD_TEMP, i,
-                                                PC87365_REG_TEMP_STATUS);
-                       if (!(reg & 0x01)) {
-                               dev_dbg(&client->dev, "Forcibly "
+                       if (!(reg & CHAN_ENA)) {
+                               dev_dbg(&pdev->dev, "Forcibly "
                                        "enabling temp%d\n", i+1);
                                pc87360_write_value(data, LD_TEMP, i,
                                                    PC87365_REG_TEMP_STATUS,
@@ -1082,14 +1392,14 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
        }
 
        if (use_thermistors) {
-               for (i=11; i<data->innr; i++) {
+               for (i = 11; i < data->innr; i++) {
                        if (init >= init_in[i]) {
                                /* The pin may already be used by thermal
                                   diodes */
                                reg = pc87360_read_value(data, LD_TEMP,
                                      (i-11)/2, PC87365_REG_TEMP_STATUS);
-                               if (reg & 0x01) {
-                                       dev_dbg(&client->dev, "Skipping "
+                               if (reg & CHAN_ENA) {
+                                       dev_dbg(&pdev->dev, "Skipping "
                                                "temp%d, pin already in use "
                                                "by temp%d\n", i-7, (i-11)/2);
                                        continue;
@@ -1098,8 +1408,8 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
                                /* Forcibly enable thermistor channel */
                                reg = pc87360_read_value(data, LD_IN, i,
                                                         PC87365_REG_IN_STATUS);
-                               if (!(reg & 0x01)) {
-                                       dev_dbg(&client->dev, "Forcibly "
+                               if (!(reg & CHAN_ENA)) {
+                                       dev_dbg(&pdev->dev, "Forcibly "
                                                "enabling temp%d\n", i-7);
                                        pc87360_write_value(data, LD_IN, i,
                                                PC87365_REG_TEMP_STATUS,
@@ -1112,8 +1422,9 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
        if (data->innr) {
                reg = pc87360_read_value(data, LD_IN, NO_BANK,
                                         PC87365_REG_IN_CONFIG);
-               if (reg & 0x01) {
-                       dev_dbg(&client->dev, "Forcibly "
+               dev_dbg(&pdev->dev, "bios vin-cfg:0x%02x\n", reg);
+               if (reg & CHAN_ENA) {
+                       dev_dbg(&pdev->dev, "Forcibly "
                                "enabling monitoring (VLM)\n");
                        pc87360_write_value(data, LD_IN, NO_BANK,
                                            PC87365_REG_IN_CONFIG,
@@ -1124,8 +1435,9 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
        if (data->tempnr) {
                reg = pc87360_read_value(data, LD_TEMP, NO_BANK,
                                         PC87365_REG_TEMP_CONFIG);
-               if (reg & 0x01) {
-                       dev_dbg(&client->dev, "Forcibly enabling "
+               dev_dbg(&pdev->dev, "bios temp-cfg:0x%02x\n", reg);
+               if (reg & CHAN_ENA) {
+                       dev_dbg(&pdev->dev, "Forcibly enabling "
                                "monitoring (TMS)\n");
                        pc87360_write_value(data, LD_TEMP, NO_BANK,
                                            PC87365_REG_TEMP_CONFIG,
@@ -1147,9 +1459,9 @@ static void pc87360_init_client(struct i2c_client *client, int use_thermistors)
        }
 }
 
-static void pc87360_autodiv(struct i2c_client *client, int nr)
+static void pc87360_autodiv(struct device *dev, int nr)
 {
-       struct pc87360_data *data = i2c_get_clientdata(client);
+       struct pc87360_data *data = dev_get_drvdata(dev);
        u8 old_min = data->fan_min[nr];
 
        /* Increase clock divider if needed and possible */
@@ -1159,7 +1471,7 @@ static void pc87360_autodiv(struct i2c_client *client, int nr)
                        data->fan_status[nr] += 0x20;
                        data->fan_min[nr] >>= 1;
                        data->fan[nr] >>= 1;
-                       dev_dbg(&client->dev, "Increasing "
+                       dev_dbg(dev, "Increasing "
                                "clock divider to %d for fan %d\n",
                                FAN_DIV_FROM_REG(data->fan_status[nr]), nr+1);
                }
@@ -1171,7 +1483,7 @@ static void pc87360_autodiv(struct i2c_client *client, int nr)
                        data->fan_status[nr] -= 0x20;
                        data->fan_min[nr] <<= 1;
                        data->fan[nr] <<= 1;
-                       dev_dbg(&client->dev, "Decreasing "
+                       dev_dbg(dev, "Decreasing "
                                "clock divider to %d for fan %d\n",
                                FAN_DIV_FROM_REG(data->fan_status[nr]),
                                nr+1);
@@ -1188,14 +1500,13 @@ static void pc87360_autodiv(struct i2c_client *client, int nr)
 
 static struct pc87360_data *pc87360_update_device(struct device *dev)
 {
-       struct i2c_client *client = to_i2c_client(dev);
-       struct pc87360_data *data = i2c_get_clientdata(client);
+       struct pc87360_data *data = dev_get_drvdata(dev);
        u8 i;
 
-       down(&data->update_lock);
+       mutex_lock(&data->update_lock);
 
        if (time_after(jiffies, data->last_updated + HZ * 2) || !data->valid) {
-               dev_dbg(&client->dev, "Data update\n");
+               dev_dbg(dev, "Data update\n");
 
                /* Fans */
                for (i = 0; i < data->fannr; i++) {
@@ -1209,7 +1520,7 @@ static struct pc87360_data *pc87360_update_device(struct device *dev)
                                                   LD_FAN, NO_BANK,
                                                   PC87360_REG_FAN_MIN(i));
                                /* Change clock divider if needed */
-                               pc87360_autodiv(client, i);
+                               pc87360_autodiv(dev, i);
                                /* Clear bits and write new divider */
                                pc87360_write_value(data, LD_FAN, NO_BANK,
                                                    PC87360_REG_FAN_STATUS(i),
@@ -1228,11 +1539,11 @@ static struct pc87360_data *pc87360_update_device(struct device *dev)
                        pc87360_write_value(data, LD_IN, i,
                                            PC87365_REG_IN_STATUS,
                                            data->in_status[i]);
-                       if ((data->in_status[i] & 0x81) == 0x81) {
+                       if ((data->in_status[i] & CHAN_READY) == CHAN_READY) {
                                data->in[i] = pc87360_read_value(data, LD_IN,
                                              i, PC87365_REG_IN);
                        }
-                       if (data->in_status[i] & 0x01) {
+                       if (data->in_status[i] & CHAN_ENA) {
                                data->in_min[i] = pc87360_read_value(data,
                                                  LD_IN, i,
                                                  PC87365_REG_IN_MIN);
@@ -1265,12 +1576,12 @@ static struct pc87360_data *pc87360_update_device(struct device *dev)
                        pc87360_write_value(data, LD_TEMP, i,
                                            PC87365_REG_TEMP_STATUS,
                                            data->temp_status[i]);
-                       if ((data->temp_status[i] & 0x81) == 0x81) {
+                       if ((data->temp_status[i] & CHAN_READY) == CHAN_READY) {
                                data->temp[i] = pc87360_read_value(data,
                                                LD_TEMP, i,
                                                PC87365_REG_TEMP);
                        }
-                       if (data->temp_status[i] & 0x01) {
+                       if (data->temp_status[i] & CHAN_ENA) {
                                data->temp_min[i] = pc87360_read_value(data,
                                                    LD_TEMP, i,
                                                    PC87365_REG_TEMP_MIN);
@@ -1292,14 +1603,63 @@ static struct pc87360_data *pc87360_update_device(struct device *dev)
                data->valid = 1;
        }
 
-       up(&data->update_lock);
+       mutex_unlock(&data->update_lock);
 
        return data;
 }
 
+static int __init pc87360_device_add(unsigned short address)
+{
+       struct resource res = {
+               .name   = "pc87360",
+               .flags  = IORESOURCE_IO,
+       };
+       int err, i;
+
+       pdev = platform_device_alloc("pc87360", address);
+       if (!pdev) {
+               err = -ENOMEM;
+               printk(KERN_ERR "pc87360: Device allocation failed\n");
+               goto exit;
+       }
+
+       for (i = 0; i < 3; i++) {
+               if (!extra_isa[i])
+                       continue;
+               res.start = extra_isa[i];
+               res.end = extra_isa[i] + PC87360_EXTENT - 1;
+
+               err = acpi_check_resource_conflict(&res);
+               if (err)
+                       goto exit_device_put;
+
+               err = platform_device_add_resources(pdev, &res, 1);
+               if (err) {
+                       printk(KERN_ERR "pc87360: Device resource[%d] "
+                              "addition failed (%d)\n", i, err);
+                       goto exit_device_put;
+               }
+       }
+
+       err = platform_device_add(pdev);
+       if (err) {
+               printk(KERN_ERR "pc87360: Device addition failed (%d)\n",
+                      err);
+               goto exit_device_put;
+       }
+
+       return 0;
+
+exit_device_put:
+       platform_device_put(pdev);
+exit:
+       return err;
+}
+
 static int __init pc87360_init(void)
 {
-       int i;
+       int err, i;
+       unsigned short address = 0;
 
        if (pc87360_find(0x2e, &devid, extra_isa)
         && pc87360_find(0x4e, &devid, extra_isa)) {
@@ -1322,12 +1682,27 @@ static int __init pc87360_init(void)
                return -ENODEV;
        }
 
-       return i2c_isa_add_driver(&pc87360_driver);
+       err = platform_driver_register(&pc87360_driver);
+       if (err)
+               goto exit;
+
+       /* Sets global pdev as a side effect */
+       err = pc87360_device_add(address);
+       if (err)
+               goto exit_driver;
+
+       return 0;
+
+ exit_driver:
+       platform_driver_unregister(&pc87360_driver);
+ exit:
+       return err;
 }
 
 static void __exit pc87360_exit(void)
 {
-       i2c_isa_del_driver(&pc87360_driver);
+       platform_device_unregister(pdev);
+       platform_driver_unregister(&pc87360_driver);
 }