Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/egtvedt...
[firefly-linux-kernel-4.4.55.git] / drivers / hwmon / dme1737.c
index e9a610bfd0cc894db71e7203e11d783a34157c46..d9c592713919886a0300cc1b29929e6c20c5e32a 100644 (file)
@@ -77,12 +77,14 @@ enum chips { dme1737, sch5027, sch311x, sch5127 };
  * in4   +12V
  * in5   VTR   (+3.3V stby)
  * in6   Vbat
+ * in7   Vtrip (sch5127 only)
  *
  * --------------------------------------------------------------------- */
 
-/* Voltages (in) numbered 0-6 (ix) */
-#define        DME1737_REG_IN(ix)              ((ix) < 5 ? 0x20 + (ix) \
-                                                 : 0x94 + (ix))
+/* Voltages (in) numbered 0-7 (ix) */
+#define        DME1737_REG_IN(ix)              ((ix) < 5 ? 0x20 + (ix) : \
+                                        (ix) < 7 ? 0x94 + (ix) : \
+                                                   0x1f)
 #define        DME1737_REG_IN_MIN(ix)          ((ix) < 5 ? 0x44 + (ix) * 2 \
                                                  : 0x91 + (ix) * 2)
 #define        DME1737_REG_IN_MAX(ix)          ((ix) < 5 ? 0x45 + (ix) * 2 \
@@ -101,10 +103,11 @@ enum chips { dme1737, sch5027, sch311x, sch5127 };
  *    IN_TEMP_LSB(1) = [temp3, temp1]
  *    IN_TEMP_LSB(2) = [in4, temp2]
  *    IN_TEMP_LSB(3) = [in3, in0]
- *    IN_TEMP_LSB(4) = [in2, in1] */
+ *    IN_TEMP_LSB(4) = [in2, in1]
+ *    IN_TEMP_LSB(5) = [res, in7] */
 #define DME1737_REG_IN_TEMP_LSB(ix)    (0x84 + (ix))
-static const u8 DME1737_REG_IN_LSB[] = {3, 4, 4, 3, 2, 0, 0};
-static const u8 DME1737_REG_IN_LSB_SHL[] = {4, 4, 0, 0, 0, 0, 4};
+static const u8 DME1737_REG_IN_LSB[] = {3, 4, 4, 3, 2, 0, 0, 5};
+static const u8 DME1737_REG_IN_LSB_SHL[] = {4, 4, 0, 0, 0, 0, 4, 4};
 static const u8 DME1737_REG_TEMP_LSB[] = {1, 2, 1};
 static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0};
 
@@ -145,7 +148,7 @@ static const u8 DME1737_REG_TEMP_LSB_SHL[] = {4, 4, 0};
 #define DME1737_REG_ALARM1             0x41
 #define DME1737_REG_ALARM2             0x42
 #define DME1737_REG_ALARM3             0x83
-static const u8 DME1737_BIT_ALARM_IN[] = {0, 1, 2, 3, 8, 16, 17};
+static const u8 DME1737_BIT_ALARM_IN[] = {0, 1, 2, 3, 8, 16, 17, 18};
 static const u8 DME1737_BIT_ALARM_TEMP[] = {4, 5, 6};
 static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23};
 
@@ -190,6 +193,7 @@ static const u8 DME1737_BIT_ALARM_FAN[] = {10, 11, 12, 13, 22, 23};
 #define HAS_PWM_MIN            (1 << 4)                /* bit 4 */
 #define HAS_FAN(ix)            (1 << ((ix) + 5))       /* bits 5-10 */
 #define HAS_PWM(ix)            (1 << ((ix) + 11))      /* bits 11-16 */
+#define HAS_IN7                        (1 << 17)               /* bit 17 */
 
 /* ---------------------------------------------------------------------
  * Data structures and manipulation thereof
@@ -213,9 +217,9 @@ struct dme1737_data {
        u32 has_features;
 
        /* Register values */
-       u16 in[7];
-       u8  in_min[7];
-       u8  in_max[7];
+       u16 in[8];
+       u8  in_min[8];
+       u8  in_max[8];
        s16 temp[3];
        s8  temp_min[3];
        s8  temp_max[3];
@@ -247,7 +251,7 @@ static const int IN_NOMINAL_SCH311x[] = {2500, 1500, 3300, 5000, 12000, 3300,
 static const int IN_NOMINAL_SCH5027[] = {5000, 2250, 3300, 1125, 1125, 3300,
                                         3300};
 static const int IN_NOMINAL_SCH5127[] = {2500, 2250, 3300, 1125, 1125, 3300,
-                                        3300};
+                                        3300, 1500};
 #define IN_NOMINAL(type)       ((type) == sch311x ? IN_NOMINAL_SCH311x : \
                                 (type) == sch5027 ? IN_NOMINAL_SCH5027 : \
                                 (type) == sch5127 ? IN_NOMINAL_SCH5127 : \
@@ -580,7 +584,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
 {
        struct dme1737_data *data = dev_get_drvdata(dev);
        int ix;
-       u8 lsb[5];
+       u8 lsb[6];
 
        mutex_lock(&data->update_lock);
 
@@ -603,6 +607,9 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
                        /* Voltage inputs are stored as 16 bit values even
                         * though they have only 12 bits resolution. This is
                         * to make it consistent with the temp inputs. */
+                       if (ix == 7 && !(data->has_features & HAS_IN7)) {
+                               continue;
+                       }
                        data->in[ix] = dme1737_read(data,
                                        DME1737_REG_IN(ix)) << 8;
                        data->in_min[ix] = dme1737_read(data,
@@ -635,10 +642,16 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
                 * which the registers are read (MSB first, then LSB) is
                 * important! */
                for (ix = 0; ix < ARRAY_SIZE(lsb); ix++) {
+                       if (ix == 5 && !(data->has_features & HAS_IN7)) {
+                               continue;
+                       }
                        lsb[ix] = dme1737_read(data,
                                        DME1737_REG_IN_TEMP_LSB(ix));
                }
                for (ix = 0; ix < ARRAY_SIZE(data->in); ix++) {
+                       if (ix == 7 && !(data->has_features & HAS_IN7)) {
+                               continue;
+                       }
                        data->in[ix] |= (lsb[DME1737_REG_IN_LSB[ix]] <<
                                        DME1737_REG_IN_LSB_SHL[ix]) & 0xf0;
                }
@@ -762,7 +775,7 @@ static struct dme1737_data *dme1737_update_device(struct device *dev)
 
 /* ---------------------------------------------------------------------
  * Voltage sysfs attributes
- * ix = [0-5]
+ * ix = [0-7]
  * --------------------------------------------------------------------- */
 
 #define SYS_IN_INPUT   0
@@ -1439,7 +1452,7 @@ static ssize_t show_name(struct device *dev, struct device_attribute *attr,
  * Sysfs device attribute defines and structs
  * --------------------------------------------------------------------- */
 
-/* Voltages 0-6 */
+/* Voltages 0-7 */
 
 #define SENSOR_DEVICE_ATTR_IN(ix) \
 static SENSOR_DEVICE_ATTR_2(in##ix##_input, S_IRUGO, \
@@ -1458,6 +1471,7 @@ SENSOR_DEVICE_ATTR_IN(3);
 SENSOR_DEVICE_ATTR_IN(4);
 SENSOR_DEVICE_ATTR_IN(5);
 SENSOR_DEVICE_ATTR_IN(6);
+SENSOR_DEVICE_ATTR_IN(7);
 
 /* Temperatures 1-3 */
 
@@ -1576,7 +1590,7 @@ static DEVICE_ATTR(name, S_IRUGO, show_name, NULL);   /* for ISA devices */
  * created unconditionally. The attributes that need modification of their
  * permissions are created read-only and write permissions are added or removed
  * on the fly when required */
-static struct attribute *dme1737_attr[] ={
+static struct attribute *dme1737_attr[] = {
        /* Voltages */
        &sensor_dev_attr_in0_input.dev_attr.attr,
        &sensor_dev_attr_in0_min.dev_attr.attr,
@@ -1681,7 +1695,7 @@ static const struct attribute_group dme1737_zone3_group = {
 };
 
 
-/* The following struct holds temp zone hysteresis  related attributes, which
+/* The following struct holds temp zone hysteresis related attributes, which
  * are not available in all chips. The following chips support them:
  * DME1737, SCH311x */
 static struct attribute *dme1737_zone_hyst_attr[] = {
@@ -1695,6 +1709,21 @@ static const struct attribute_group dme1737_zone_hyst_group = {
        .attrs = dme1737_zone_hyst_attr,
 };
 
+/* The following struct holds voltage in7 related attributes, which
+ * are not available in all chips. The following chips support them:
+ * SCH5127 */
+static struct attribute *dme1737_in7_attr[] = {
+       &sensor_dev_attr_in7_input.dev_attr.attr,
+       &sensor_dev_attr_in7_min.dev_attr.attr,
+       &sensor_dev_attr_in7_max.dev_attr.attr,
+       &sensor_dev_attr_in7_alarm.dev_attr.attr,
+       NULL
+};
+
+static const struct attribute_group dme1737_in7_group = {
+       .attrs = dme1737_in7_attr,
+};
+
 /* The following structs hold the PWM attributes, some of which are optional.
  * Their creation depends on the chip configuration which is determined during
  * module load. */
@@ -1986,6 +2015,9 @@ static void dme1737_remove_files(struct device *dev)
        if (data->has_features & HAS_ZONE_HYST) {
                sysfs_remove_group(&dev->kobj, &dme1737_zone_hyst_group);
        }
+       if (data->has_features & HAS_IN7) {
+               sysfs_remove_group(&dev->kobj, &dme1737_in7_group);
+       }
        sysfs_remove_group(&dev->kobj, &dme1737_group);
 
        if (!data->client) {
@@ -1999,43 +2031,58 @@ static int dme1737_create_files(struct device *dev)
        int err, ix;
 
        /* Create a name attribute for ISA devices */
-       if (!data->client &&
-           (err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr))) {
-               goto exit;
+       if (!data->client) {
+               err = sysfs_create_file(&dev->kobj, &dev_attr_name.attr);
+               if (err) {
+                       goto exit;
+               }
        }
 
        /* Create standard sysfs attributes */
-       if ((err = sysfs_create_group(&dev->kobj, &dme1737_group))) {
+       err = sysfs_create_group(&dev->kobj, &dme1737_group);
+       if (err) {
                goto exit_remove;
        }
 
        /* Create chip-dependent sysfs attributes */
-       if ((data->has_features & HAS_TEMP_OFFSET) &&
-           (err = sysfs_create_group(&dev->kobj,
-                                     &dme1737_temp_offset_group))) {
-               goto exit_remove;
+       if (data->has_features & HAS_TEMP_OFFSET) {
+               err = sysfs_create_group(&dev->kobj,
+                                        &dme1737_temp_offset_group);
+               if (err) {
+                       goto exit_remove;
+               }
        }
-       if ((data->has_features & HAS_VID) &&
-           (err = sysfs_create_group(&dev->kobj,
-                                     &dme1737_vid_group))) {
-               goto exit_remove;
+       if (data->has_features & HAS_VID) {
+               err = sysfs_create_group(&dev->kobj, &dme1737_vid_group);
+               if (err) {
+                       goto exit_remove;
+               }
        }
-       if ((data->has_features & HAS_ZONE3) &&
-           (err = sysfs_create_group(&dev->kobj,
-                                     &dme1737_zone3_group))) {
-               goto exit_remove;
+       if (data->has_features & HAS_ZONE3) {
+               err = sysfs_create_group(&dev->kobj, &dme1737_zone3_group);
+               if (err) {
+                       goto exit_remove;
+               }
        }
-       if ((data->has_features & HAS_ZONE_HYST) &&
-           (err = sysfs_create_group(&dev->kobj,
-                                     &dme1737_zone_hyst_group))) {
-               goto exit_remove;
+       if (data->has_features & HAS_ZONE_HYST) {
+               err = sysfs_create_group(&dev->kobj, &dme1737_zone_hyst_group);
+               if (err) {
+                       goto exit_remove;
+               }
+       }
+       if (data->has_features & HAS_IN7) {
+               err = sysfs_create_group(&dev->kobj, &dme1737_in7_group);
+               if (err) {
+                       goto exit_remove;
+               }
        }
 
        /* Create fan sysfs attributes */
        for (ix = 0; ix < ARRAY_SIZE(dme1737_fan_group); ix++) {
                if (data->has_features & HAS_FAN(ix)) {
-                       if ((err = sysfs_create_group(&dev->kobj,
-                                               &dme1737_fan_group[ix]))) {
+                       err = sysfs_create_group(&dev->kobj,
+                                                &dme1737_fan_group[ix]);
+                       if (err) {
                                goto exit_remove;
                        }
                }
@@ -2044,14 +2091,17 @@ static int dme1737_create_files(struct device *dev)
        /* Create PWM sysfs attributes */
        for (ix = 0; ix < ARRAY_SIZE(dme1737_pwm_group); ix++) {
                if (data->has_features & HAS_PWM(ix)) {
-                       if ((err = sysfs_create_group(&dev->kobj,
-                                               &dme1737_pwm_group[ix]))) {
+                       err = sysfs_create_group(&dev->kobj,
+                                                &dme1737_pwm_group[ix]);
+                       if (err) {
                                goto exit_remove;
                        }
-                       if ((data->has_features & HAS_PWM_MIN) && ix < 3 &&
-                           (err = sysfs_create_file(&dev->kobj,
-                                       dme1737_auto_pwm_min_attr[ix]))) {
-                               goto exit_remove;
+                       if ((data->has_features & HAS_PWM_MIN) && (ix < 3)) {
+                               err = sysfs_create_file(&dev->kobj,
+                                               dme1737_auto_pwm_min_attr[ix]);
+                               if (err) {
+                                       goto exit_remove;
+                               }
                        }
                }
        }
@@ -2188,7 +2238,7 @@ static int dme1737_init_device(struct device *dev)
                data->has_features |= HAS_ZONE3;
                break;
        case sch5127:
-               data->has_features |= HAS_FAN(2) | HAS_PWM(2);
+               data->has_features |= HAS_FAN(2) | HAS_PWM(2) | HAS_IN7;
                break;
        default:
                break;
@@ -2281,8 +2331,9 @@ static int dme1737_i2c_get_features(int sio_cip, struct dme1737_data *data)
        dme1737_sio_outb(sio_cip, 0x07, 0x0a);
 
        /* Get the base address of the runtime registers */
-       if (!(addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
-                     dme1737_sio_inb(sio_cip, 0x61))) {
+       addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
+               dme1737_sio_inb(sio_cip, 0x61);
+       if (!addr) {
                err = -ENODEV;
                goto exit;
        }
@@ -2363,13 +2414,15 @@ static int dme1737_i2c_probe(struct i2c_client *client,
        mutex_init(&data->update_lock);
 
        /* Initialize the DME1737 chip */
-       if ((err = dme1737_init_device(dev))) {
+       err = dme1737_init_device(dev);
+       if (err) {
                dev_err(dev, "Failed to initialize device.\n");
                goto exit_kfree;
        }
 
        /* Create sysfs files */
-       if ((err = dme1737_create_files(dev))) {
+       err = dme1737_create_files(dev);
+       if (err) {
                dev_err(dev, "Failed to create sysfs files.\n");
                goto exit_kfree;
        }
@@ -2446,8 +2499,9 @@ static int __init dme1737_isa_detect(int sio_cip, unsigned short *addr)
        dme1737_sio_outb(sio_cip, 0x07, 0x0a);
 
        /* Get the base address of the runtime registers */
-       if (!(base_addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
-                          dme1737_sio_inb(sio_cip, 0x61))) {
+       base_addr = (dme1737_sio_inb(sio_cip, 0x60) << 8) |
+                    dme1737_sio_inb(sio_cip, 0x61);
+       if (!base_addr) {
                pr_err("Base address not set\n");
                err = -ENODEV;
                goto exit;
@@ -2476,18 +2530,21 @@ static int __init dme1737_isa_device_add(unsigned short addr)
        if (err)
                goto exit;
 
-       if (!(pdev = platform_device_alloc("dme1737", addr))) {
+       pdev = platform_device_alloc("dme1737", addr);
+       if (!pdev) {
                pr_err("Failed to allocate device\n");
                err = -ENOMEM;
                goto exit;
        }
 
-       if ((err = platform_device_add_resources(pdev, &res, 1))) {
+       err = platform_device_add_resources(pdev, &res, 1);
+       if (err) {
                pr_err("Failed to add device resource (err = %d)\n", err);
                goto exit_device_put;
        }
 
-       if ((err = platform_device_add(pdev))) {
+       err = platform_device_add(pdev);
+       if (err) {
                pr_err("Failed to add device (err = %d)\n", err);
                goto exit_device_put;
        }
@@ -2514,11 +2571,12 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
                dev_err(dev, "Failed to request region 0x%04x-0x%04x.\n",
                        (unsigned short)res->start,
                        (unsigned short)res->start + DME1737_EXTENT - 1);
-                err = -EBUSY;
-                goto exit;
-        }
+               err = -EBUSY;
+               goto exit;
+       }
 
-       if (!(data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL))) {
+       data = kzalloc(sizeof(struct dme1737_data), GFP_KERNEL);
+       if (!data) {
                err = -ENOMEM;
                goto exit_release_region;
        }
@@ -2565,13 +2623,15 @@ static int __devinit dme1737_isa_probe(struct platform_device *pdev)
                 data->type == sch5127 ? "SCH5127" : "SCH311x", data->addr);
 
        /* Initialize the chip */
-       if ((err = dme1737_init_device(dev))) {
+       err = dme1737_init_device(dev);
+       if (err) {
                dev_err(dev, "Failed to initialize device.\n");
                goto exit_kfree;
        }
 
        /* Create sysfs files */
-       if ((err = dme1737_create_files(dev))) {
+       err = dme1737_create_files(dev);
+       if (err) {
                dev_err(dev, "Failed to create sysfs files.\n");
                goto exit_kfree;
        }
@@ -2628,7 +2688,8 @@ static int __init dme1737_init(void)
        int err;
        unsigned short addr;
 
-       if ((err = i2c_add_driver(&dme1737_i2c_driver))) {
+       err = i2c_add_driver(&dme1737_i2c_driver);
+       if (err) {
                goto exit;
        }
 
@@ -2641,12 +2702,14 @@ static int __init dme1737_init(void)
                return 0;
        }
 
-       if ((err = platform_driver_register(&dme1737_isa_driver))) {
+       err = platform_driver_register(&dme1737_isa_driver);
+       if (err) {
                goto exit_del_i2c_driver;
        }
 
        /* Sets global pdev as a side effect */
-       if ((err = dme1737_isa_device_add(addr))) {
+       err = dme1737_isa_device_add(addr);
+       if (err) {
                goto exit_del_isa_driver;
        }