]> git.karo-electronics.de Git - karo-tx-linux.git/blobdiff - drivers/hwmon/sht15.c
hwmon: (sht15) Properly handle the case CONFIG_REGULATOR=n
[karo-tx-linux.git] / drivers / hwmon / sht15.c
index ebe38b680ee38494520c5cf162e50a027ab21799..fbc997ee67d973283c37181cd38dc499159639b0 100644 (file)
@@ -302,13 +302,13 @@ error_ret:
  **/
 static inline int sht15_calc_temp(struct sht15_data *data)
 {
-       int d1 = 0;
+       int d1 = temppoints[0].d1;
        int i;
 
-       for (i = 1; i < ARRAY_SIZE(temppoints) - 1; i++)
+       for (i = ARRAY_SIZE(temppoints) - 1; i > 0; i--)
                /* Find pointer to interpolate */
                if (data->supply_uV > temppoints[i - 1].vdd) {
-                       d1 = (data->supply_uV/1000 - temppoints[i - 1].vdd)
+                       d1 = (data->supply_uV - temppoints[i - 1].vdd)
                                * (temppoints[i].d1 - temppoints[i - 1].d1)
                                / (temppoints[i].vdd - temppoints[i - 1].vdd)
                                + temppoints[i - 1].d1;
@@ -332,12 +332,12 @@ static inline int sht15_calc_humid(struct sht15_data *data)
 
        const int c1 = -4;
        const int c2 = 40500; /* x 10 ^ -6 */
-       const int c3 = 2800; /* x10 ^ -9 */
+       const int c3 = -2800; /* x10 ^ -9 */
 
        RHlinear = c1*1000
                + c2 * data->val_humid/1000
                + (data->val_humid * data->val_humid * c3)/1000000;
-       return (temp - 25000) * (10000 + 800 * data->val_humid)
+       return (temp - 25000) * (10000 + 80 * data->val_humid)
                / 1000000 + RHlinear;
 }
 
@@ -541,7 +541,12 @@ static int __devinit sht15_probe(struct platform_device *pdev)
 /* If a regulator is available, query what the supply voltage actually is!*/
        data->reg = regulator_get(data->dev, "vcc");
        if (!IS_ERR(data->reg)) {
-               data->supply_uV = regulator_get_voltage(data->reg);
+               int voltage;
+
+               voltage = regulator_get_voltage(data->reg);
+               if (voltage)
+                       data->supply_uV = voltage;
+
                regulator_enable(data->reg);
                /* setup a notifier block to update this if another device
                 *  causes the voltage to change */