hwmon: driver for Texas Instruments amc6821 chip
[safe/jmp/linux-2.6] / drivers / hwmon / f71882fg.c
index 210ed66..a95fa42 100644 (file)
@@ -48,6 +48,7 @@
 #define SIO_F71858_ID          0x0507  /* Chipset ID */
 #define SIO_F71862_ID          0x0601  /* Chipset ID */
 #define SIO_F71882_ID          0x0541  /* Chipset ID */
+#define SIO_F71889_ID          0x0723  /* Chipset ID */
 #define SIO_F8000_ID           0x0581  /* Chipset ID */
 
 #define REGION_LENGTH          8
@@ -95,12 +96,13 @@ static unsigned short force_id;
 module_param(force_id, ushort, 0);
 MODULE_PARM_DESC(force_id, "Override the detected device ID");
 
-enum chips { f71858fg, f71862fg, f71882fg, f8000 };
+enum chips { f71858fg, f71862fg, f71882fg, f71889fg, f8000 };
 
 static const char *f71882fg_names[] = {
        "f71858fg",
        "f71862fg",
        "f71882fg",
+       "f71889fg",
        "f8000",
 };
 
@@ -155,7 +157,7 @@ struct f71882fg_data {
        u8      pwm_auto_point_hyst[2];
        u8      pwm_auto_point_mapping[4];
        u8      pwm_auto_point_pwm[4][5];
-       u8      pwm_auto_point_temp[4][4];
+       s8      pwm_auto_point_temp[4][4];
 };
 
 /* Sysfs in */
@@ -945,7 +947,7 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
        /* Update once every 60 seconds */
        if ( time_after(jiffies, data->last_limits + 60 * HZ ) ||
                        !data->valid) {
-               if (data->type == f71882fg) {
+               if (data->type == f71882fg || data->type == f71889fg) {
                        data->in1_max =
                                f71882fg_read8(data, F71882FG_REG_IN1_HIGH);
                        data->in_beep =
@@ -967,7 +969,8 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
                                                F71882FG_REG_TEMP_HYST(1));
                }
 
-               if (data->type == f71862fg || data->type == f71882fg) {
+               if (data->type == f71862fg || data->type == f71882fg ||
+                   data->type == f71889fg) {
                        data->fan_beep = f71882fg_read8(data,
                                                F71882FG_REG_FAN_BEEP);
                        data->temp_beep = f71882fg_read8(data,
@@ -977,15 +980,33 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
                        data->temp_type[2] = (reg & 0x04) ? 2 : 4;
                        data->temp_type[3] = (reg & 0x08) ? 2 : 4;
                }
-               reg2 = f71882fg_read8(data, F71882FG_REG_PECI);
-               if ((reg2 & 0x03) == 0x01)
-                       data->temp_type[1] = 6 /* PECI */;
-               else if ((reg2 & 0x03) == 0x02)
-                       data->temp_type[1] = 5 /* AMDSI */;
-               else if (data->type == f71862fg || data->type == f71882fg)
-                       data->temp_type[1] = (reg & 0x02) ? 2 : 4;
-               else
-                       data->temp_type[1] = 2; /* Only supports BJT */
+               /* Determine temp index 1 sensor type */
+               if (data->type == f71889fg) {
+                       reg2 = f71882fg_read8(data, F71882FG_REG_START);
+                       switch ((reg2 & 0x60) >> 5) {
+                       case 0x00: /* BJT / Thermistor */
+                               data->temp_type[1] = (reg & 0x02) ? 2 : 4;
+                               break;
+                       case 0x01: /* AMDSI */
+                               data->temp_type[1] = 5;
+                               break;
+                       case 0x02: /* PECI */
+                       case 0x03: /* Ibex Peak ?? Report as PECI for now */
+                               data->temp_type[1] = 6;
+                               break;
+                       }
+               } else {
+                       reg2 = f71882fg_read8(data, F71882FG_REG_PECI);
+                       if ((reg2 & 0x03) == 0x01)
+                               data->temp_type[1] = 6; /* PECI */
+                       else if ((reg2 & 0x03) == 0x02)
+                               data->temp_type[1] = 5; /* AMDSI */
+                       else if (data->type == f71862fg ||
+                                data->type == f71882fg)
+                               data->temp_type[1] = (reg & 0x02) ? 2 : 4;
+                       else /* f71858fg and f8000 only support BJT */
+                               data->temp_type[1] = 2;
+               }
 
                data->pwm_enable = f71882fg_read8(data,
                                                  F71882FG_REG_PWM_ENABLE);
@@ -1062,7 +1083,7 @@ static struct f71882fg_data *f71882fg_update_device(struct device *dev)
                if (data->type == f8000)
                        data->fan[3] = f71882fg_read16(data,
                                                F71882FG_REG_FAN(3));
-               if (data->type == f71882fg)
+               if (data->type == f71882fg || data->type == f71889fg)
                        data->in_status = f71882fg_read8(data,
                                                F71882FG_REG_IN_STATUS);
                for (nr = 0; nr < nr_ins; nr++)
@@ -1780,7 +1801,11 @@ static ssize_t store_pwm_auto_point_temp(struct device *dev,
        int pwm = to_sensor_dev_attr_2(devattr)->index;
        int point = to_sensor_dev_attr_2(devattr)->nr;
        long val = simple_strtol(buf, NULL, 10) / 1000;
-       val = SENSORS_LIMIT(val, 0, 255);
+
+       if (data->type == f71889fg)
+               val = SENSORS_LIMIT(val, -128, 127);
+       else
+               val = SENSORS_LIMIT(val, 0, 127);
 
        mutex_lock(&data->update_lock);
        f71882fg_write8(data, F71882FG_REG_POINT_TEMP(pwm, point), val);
@@ -1810,6 +1835,15 @@ static int __devinit f71882fg_create_sysfs_files(struct platform_device *pdev,
        return 0;
 }
 
+static void f71882fg_remove_sysfs_files(struct platform_device *pdev,
+       struct sensor_device_attribute_2 *attr, int count)
+{
+       int i;
+
+       for (i = 0; i < count; i++)
+               device_remove_file(&pdev->dev, &attr[i].dev_attr);
+}
+
 static int __devinit f71882fg_probe(struct platform_device *pdev)
 {
        struct f71882fg_data *data;
@@ -1862,6 +1896,7 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
                                        ARRAY_SIZE(f71858fg_in_temp_attr));
                        break;
                case f71882fg:
+               case f71889fg:
                        err = f71882fg_create_sysfs_files(pdev,
                                        fxxxx_in1_alarm_attr,
                                        ARRAY_SIZE(fxxxx_in1_alarm_attr));
@@ -1899,6 +1934,7 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
                        err = (data->pwm_enable & 0x15) != 0x15;
                        break;
                case f71882fg:
+               case f71889fg:
                        err = 0;
                        break;
                case f8000:
@@ -1918,7 +1954,8 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
                if (err)
                        goto exit_unregister_sysfs;
 
-               if (data->type == f71862fg || data->type == f71882fg) {
+               if (data->type == f71862fg || data->type == f71882fg ||
+                   data->type == f71889fg) {
                        err = f71882fg_create_sysfs_files(pdev,
                                        fxxxx_fan_beep_attr, nr_fans);
                        if (err)
@@ -1941,6 +1978,22 @@ static int __devinit f71882fg_probe(struct platform_device *pdev)
                                        f8000_auto_pwm_attr,
                                        ARRAY_SIZE(f8000_auto_pwm_attr));
                        break;
+               case f71889fg:
+                       for (i = 0; i < nr_fans; i++) {
+                               data->pwm_auto_point_mapping[i] =
+                                       f71882fg_read8(data,
+                                               F71882FG_REG_POINT_MAPPING(i));
+                               if (data->pwm_auto_point_mapping[i] & 0x80)
+                                       break;
+                       }
+                       if (i != nr_fans) {
+                               dev_warn(&pdev->dev,
+                                        "Auto pwm controlled by raw digital "
+                                        "data, disabling pwm auto_point "
+                                        "sysfs attributes\n");
+                               break;
+                       }
+                       /* fall through */
                default: /* f71858fg / f71882fg */
                        err = f71882fg_create_sysfs_files(pdev,
                                &fxxxx_auto_pwm_attr[0][0],
@@ -1974,42 +2027,76 @@ exit_free:
 
 static int f71882fg_remove(struct platform_device *pdev)
 {
-       int i, j;
        struct f71882fg_data *data = platform_get_drvdata(pdev);
+       int nr_fans = (data->type == f71882fg) ? 4 : 3;
+       u8 start_reg = f71882fg_read8(data, F71882FG_REG_START);
 
        platform_set_drvdata(pdev, NULL);
        if (data->hwmon_dev)
                hwmon_device_unregister(data->hwmon_dev);
 
-       /* Note we are not looping over all attr arrays we have as the ones
-          below are supersets of the ones skipped. */
        device_remove_file(&pdev->dev, &dev_attr_name);
 
-       for (i = 0; i < ARRAY_SIZE(fxxxx_in_temp_attr); i++)
-               device_remove_file(&pdev->dev,
-                                       &fxxxx_in_temp_attr[i].dev_attr);
-
-       for (i = 0; i < ARRAY_SIZE(fxxxx_in1_alarm_attr); i++)
-               device_remove_file(&pdev->dev,
-                                       &fxxxx_in1_alarm_attr[i].dev_attr);
-
-       for (i = 0; i < ARRAY_SIZE(fxxxx_fan_attr); i++)
-               for (j = 0; j < ARRAY_SIZE(fxxxx_fan_attr[0]); j++)
-                       device_remove_file(&pdev->dev,
-                                          &fxxxx_fan_attr[i][j].dev_attr);
+       if (start_reg & 0x01) {
+               switch (data->type) {
+               case f71858fg:
+                       if (data->temp_config & 0x10)
+                               f71882fg_remove_sysfs_files(pdev,
+                                       f8000_in_temp_attr,
+                                       ARRAY_SIZE(f8000_in_temp_attr));
+                       else
+                               f71882fg_remove_sysfs_files(pdev,
+                                       f71858fg_in_temp_attr,
+                                       ARRAY_SIZE(f71858fg_in_temp_attr));
+                       break;
+               case f71882fg:
+               case f71889fg:
+                       f71882fg_remove_sysfs_files(pdev,
+                                       fxxxx_in1_alarm_attr,
+                                       ARRAY_SIZE(fxxxx_in1_alarm_attr));
+                       /* fall through! */
+               case f71862fg:
+                       f71882fg_remove_sysfs_files(pdev,
+                                       fxxxx_in_temp_attr,
+                                       ARRAY_SIZE(fxxxx_in_temp_attr));
+                       break;
+               case f8000:
+                       f71882fg_remove_sysfs_files(pdev,
+                                       f8000_in_temp_attr,
+                                       ARRAY_SIZE(f8000_in_temp_attr));
+                       break;
+               }
+       }
 
-       for (i = 0; i < ARRAY_SIZE(fxxxx_fan_beep_attr); i++)
-               device_remove_file(&pdev->dev,
-                                  &fxxxx_fan_beep_attr[i].dev_attr);
+       if (start_reg & 0x02) {
+               f71882fg_remove_sysfs_files(pdev, &fxxxx_fan_attr[0][0],
+                               ARRAY_SIZE(fxxxx_fan_attr[0]) * nr_fans);
 
-       for (i = 0; i < ARRAY_SIZE(fxxxx_auto_pwm_attr); i++)
-               for (j = 0; j < ARRAY_SIZE(fxxxx_auto_pwm_attr[0]); j++)
-                       device_remove_file(&pdev->dev,
-                                         &fxxxx_auto_pwm_attr[i][j].dev_attr);
+               if (data->type == f71862fg || data->type == f71882fg ||
+                   data->type == f71889fg)
+                       f71882fg_remove_sysfs_files(pdev,
+                                       fxxxx_fan_beep_attr, nr_fans);
 
-       for (i = 0; i < ARRAY_SIZE(f8000_auto_pwm_attr); i++)
-               device_remove_file(&pdev->dev,
-                                  &f8000_auto_pwm_attr[i].dev_attr);
+               switch (data->type) {
+               case f71862fg:
+                       f71882fg_remove_sysfs_files(pdev,
+                                       f71862fg_auto_pwm_attr,
+                                       ARRAY_SIZE(f71862fg_auto_pwm_attr));
+                       break;
+               case f8000:
+                       f71882fg_remove_sysfs_files(pdev,
+                                       f8000_fan_attr,
+                                       ARRAY_SIZE(f8000_fan_attr));
+                       f71882fg_remove_sysfs_files(pdev,
+                                       f8000_auto_pwm_attr,
+                                       ARRAY_SIZE(f8000_auto_pwm_attr));
+                       break;
+               default: /* f71858fg / f71882fg / f71889fg */
+                       f71882fg_remove_sysfs_files(pdev,
+                               &fxxxx_auto_pwm_attr[0][0],
+                               ARRAY_SIZE(fxxxx_auto_pwm_attr[0]) * nr_fans);
+               }
+       }
 
        kfree(data);
 
@@ -2041,11 +2128,15 @@ static int __init f71882fg_find(int sioaddr, unsigned short *address,
        case SIO_F71882_ID:
                sio_data->type = f71882fg;
                break;
+       case SIO_F71889_ID:
+               sio_data->type = f71889fg;
+               break;
        case SIO_F8000_ID:
                sio_data->type = f8000;
                break;
        default:
-               printk(KERN_INFO DRVNAME ": Unsupported Fintek device\n");
+               printk(KERN_INFO DRVNAME ": Unsupported Fintek device: %04x\n",
+                      (unsigned int)devid);
                goto exit;
        }