]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blobdiff - drivers/iio/adc/max9611.c
iio: adc: max9611: Fix too short conversion time delay
[mirror_ubuntu-bionic-kernel.git] / drivers / iio / adc / max9611.c
index 0538ff8c4ac1d2f1e242898daf644d3b69345c4d..9f1a5ef0b444c2b61eac95cccfe5fcd7a1f7c570 100644 (file)
 #define MAX9611_TEMP_MAX_POS           0x7f80
 #define MAX9611_TEMP_MAX_NEG           0xff80
 #define MAX9611_TEMP_MIN_NEG           0xd980
-#define MAX9611_TEMP_MASK              GENMASK(7, 15)
+#define MAX9611_TEMP_MASK              GENMASK(15, 7)
 #define MAX9611_TEMP_SHIFT             0x07
 #define MAX9611_TEMP_RAW(_r)           ((_r) >> MAX9611_TEMP_SHIFT)
 #define MAX9611_TEMP_SCALE_NUM         1000000
 #define MAX9611_TEMP_SCALE_DIV         2083
 
+/*
+ * Conversion time is 2 ms (typically) at Ta=25 degreeC
+ * No maximum value is known, so play it safe.
+ */
+#define MAX9611_CONV_TIME_US_RANGE     3000, 3300
+
 struct max9611_dev {
        struct device *dev;
        struct i2c_client *i2c_client;
@@ -239,11 +245,9 @@ static int max9611_read_single(struct max9611_dev *max9611,
                return ret;
        }
 
-       /*
-        * need a delay here to make register configuration
-        * stabilize. 1 msec at least, from empirical testing.
-        */
-       usleep_range(1000, 2000);
+       /* need a delay here to make register configuration stabilize. */
+
+       usleep_range(MAX9611_CONV_TIME_US_RANGE);
 
        ret = i2c_smbus_read_word_swapped(max9611->i2c_client, reg_addr);
        if (ret < 0) {
@@ -289,7 +293,7 @@ static int max9611_read_csa_voltage(struct max9611_dev *max9611,
                        return ret;
 
                if (*adc_raw > 0) {
-                       *csa_gain = gain_selectors[i];
+                       *csa_gain = (enum max9611_csa_gain)gain_selectors[i];
                        return 0;
                }
        }
@@ -483,7 +487,7 @@ static int max9611_init(struct max9611_dev *max9611)
        if (ret)
                return ret;
 
-       regval = ret & MAX9611_TEMP_MASK;
+       regval &= MAX9611_TEMP_MASK;
 
        if ((regval > MAX9611_TEMP_MAX_POS &&
             regval < MAX9611_TEMP_MIN_NEG) ||
@@ -510,7 +514,7 @@ static int max9611_init(struct max9611_dev *max9611)
                        MAX9611_REG_CTRL2, 0);
                return ret;
        }
-       usleep_range(1000, 2000);
+       usleep_range(MAX9611_CONV_TIME_US_RANGE);
 
        return 0;
 }