Merge master.kernel.org:/home/rmk/linux-2.6-arm
[linux-2.6-block.git] / drivers / hwmon / f71882fg.c
index a833797e96d3d13facc23360cc9bf8502972d4dc..609cafff86bc2ce23c364831f959c2dbcd310baf 100644 (file)
@@ -28,6 +28,7 @@
 #include <linux/err.h>
 #include <linux/mutex.h>
 #include <linux/io.h>
+#include <linux/acpi.h>
 
 #define DRVNAME "f71882fg"
 
@@ -448,6 +449,28 @@ static struct sensor_device_attribute_2 f71862fg_fan_attr[] = {
                      0, 1),
        SENSOR_ATTR_2(pwm2_auto_point2_temp_hyst, S_IRUGO,
                      show_pwm_auto_point_temp_hyst, NULL, 3, 1),
+
+       SENSOR_ATTR_2(pwm3, S_IRUGO|S_IWUSR, show_pwm, store_pwm, 0, 2),
+       SENSOR_ATTR_2(pwm3_enable, S_IRUGO|S_IWUSR, show_pwm_enable,
+                     store_pwm_enable, 0, 2),
+       SENSOR_ATTR_2(pwm3_auto_point1_pwm, S_IRUGO|S_IWUSR,
+                     show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
+                     1, 2),
+       SENSOR_ATTR_2(pwm3_auto_point2_pwm, S_IRUGO|S_IWUSR,
+                     show_pwm_auto_point_pwm, store_pwm_auto_point_pwm,
+                     4, 2),
+       SENSOR_ATTR_2(pwm3_auto_point1_temp, S_IRUGO|S_IWUSR,
+                     show_pwm_auto_point_temp, store_pwm_auto_point_temp,
+                     0, 2),
+       SENSOR_ATTR_2(pwm3_auto_point2_temp, S_IRUGO|S_IWUSR,
+                     show_pwm_auto_point_temp, store_pwm_auto_point_temp,
+                     3, 2),
+       SENSOR_ATTR_2(pwm3_auto_point1_temp_hyst, S_IRUGO|S_IWUSR,
+                     show_pwm_auto_point_temp_hyst,
+                     store_pwm_auto_point_temp_hyst,
+                     0, 2),
+       SENSOR_ATTR_2(pwm3_auto_point2_temp_hyst, S_IRUGO,
+                     show_pwm_auto_point_temp_hyst, NULL, 3, 2),
 };
 
 /* Fan / PWM attr for the f71882fg */
@@ -788,12 +811,12 @@ static inline void superio_exit(int base)
        outb(SIO_LOCK_KEY, base);
 }
 
-static inline u16 fan_from_reg(u16 reg)
+static inline int fan_from_reg(u16 reg)
 {
        return reg ? (1500000 / reg) : 0;
 }
 
-static inline u16 fan_to_reg(u16 fan)
+static inline u16 fan_to_reg(int fan)
 {
        return fan ? (1500000 / fan) : 0;
 }
@@ -1593,8 +1616,9 @@ static ssize_t show_pwm_auto_point_channel(struct device *dev,
        int result;
        struct f71882fg_data *data = f71882fg_update_device(dev);
        int nr = to_sensor_dev_attr_2(devattr)->index;
+       int temp_start = (data->type == f8000) ? 0 : 1;
 
-       result = 1 << ((data->pwm_auto_point_mapping[nr] & 3) - 1);
+       result = 1 << ((data->pwm_auto_point_mapping[nr] & 3) - temp_start);
 
        return sprintf(buf, "%d\n", result);
 }
@@ -1605,20 +1629,23 @@ static ssize_t store_pwm_auto_point_channel(struct device *dev,
 {
        struct f71882fg_data *data = dev_get_drvdata(dev);
        int nr = to_sensor_dev_attr_2(devattr)->index;
+       int temp_start = (data->type == f8000) ? 0 : 1;
        long val = simple_strtol(buf, NULL, 10);
+
        switch (val) {
        case 1:
-               val = 1;
+               val = 0;
                break;
        case 2:
-               val = 2;
+               val = 1;
                break;
        case 4:
-               val = 3;
+               val = 2;
                break;
        default:
                return -EINVAL;
        }
+       val += temp_start;
        mutex_lock(&data->update_lock);
        data->pwm_auto_point_mapping[nr] =
                f71882fg_read8(data, F71882FG_REG_POINT_MAPPING(nr));
@@ -1685,7 +1712,7 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
 {
        struct f71882fg_data *data;
        struct f71882fg_sio_data *sio_data = pdev->dev.platform_data;
-       int err;
+       int err, i, nr_fans = (sio_data->type == f71882fg) ? 4 : 3;
        u8 start_reg;
 
        data = kzalloc(sizeof(struct f71882fg_data), GFP_KERNEL);
@@ -1709,14 +1736,14 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
                goto exit_free;
        }
 
+       data->pwm_enable = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
        /* If it is a 71862 and the fan / pwm part is enabled sanity check
           the pwm settings */
        if (data->type == f71862fg && (start_reg & 0x02)) {
-               u8 reg = f71882fg_read8(data, F71882FG_REG_PWM_ENABLE);
-               if ((reg & 0x15) != 0x15) {
+               if ((data->pwm_enable & 0x15) != 0x15) {
                        dev_err(&pdev->dev,
                                "Invalid (reserved) pwm settings: 0x%02x\n",
-                               (unsigned int)reg);
+                               (unsigned int)data->pwm_enable);
                        err = -ENODEV;
                        goto exit_free;
                }
@@ -1776,6 +1803,11 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
                }
                if (err)
                        goto exit_unregister_sysfs;
+
+               for (i = 0; i < nr_fans; i++)
+                       dev_info(&pdev->dev, "Fan: %d is in %s mode\n", i + 1,
+                                (data->pwm_enable & (1 << 2 * i)) ?
+                                "duty-cycle" : "RPM");
        }
 
        data->hwmon_dev = hwmon_device_register(&pdev->dev);
@@ -1898,6 +1930,10 @@ static int __init f71882fg_device_add(unsigned short address,
                return -ENOMEM;
 
        res.name = f71882fg_pdev->name;
+       err = acpi_check_resource_conflict(&res);
+       if (err)
+               return err;
+
        err = platform_device_add_resources(f71882fg_pdev, &res, 1);
        if (err) {
                printk(KERN_ERR DRVNAME ": Device resource addition failed\n");