Skip to contentSkip to conversation

IIO: DPS310 fixes

PATCH In review Christopher Bostic 2 participants 7 messages Jul 24, 2017 – Jul 25, 2017

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

cover IIO: DPS310 fixes

* Add manufacturer's recommended workaround for known temperature reading error
* Return previous measured value if current reading isn't finshed

Christopher Bostic (2):
drivers/iio: dps310 Temperature measurement fix. drivers/iio: dps310 Use previous value if new reading not available
yet

 drivers/iio/pressure/dps310.c | 53 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 50 insertions(+), 3 deletions(-)
Signature · 1 line
1.8.2.2
#1 lore raw

PATCH 1/2 drivers/iio: dps310 Temperature measurement fix.

Add a manufacturer's suggested workaround to deal with early revisions of chip that don't indicate correct temperature. Readings can be in the ~60C range when they should be in the ~20's.

---
 drivers/iio/pressure/dps310.c | 49 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)
drivers/iio/pressure/dps310.c +48 -1
index 1b54ae0..f351c26 100644
@@ -56,7 +56,12 @@
 #define  DPS310_FIFO_EN		BIT(5)
 #define  DPS310_SPI_EN		BIT(6)
 #define DPS310_RESET		0x0c
+#define DPS310_TEMP_FIX_E	0x0e
+#define DPS310_TEMP_FIX_F	0x0f
 #define  DPS310_RESET_MAGIC	(BIT(0) | BIT(3))
+#define DPS310_TEMP_FIX_32	0x32
+#define  DPS310_TEMP_ERR_FIXED	BIT(1)
+#define DPS310_TEMP_FIX_62	0x62
 #define DPS310_COEF_BASE	0x10
 
 #define DPS310_PRS_BASE		DPS310_PRS_B0
@@ -219,6 +224,9 @@ static bool dps310_is_writeable_reg(struct device *dev, unsigned int reg)
 	case DPS310_MEAS_CFG:
 	case DPS310_CFG_REG:
 	case DPS310_RESET:
+	case DPS310_TEMP_FIX_E:
+	case DPS310_TEMP_FIX_F:
+	case DPS310_TEMP_FIX_62:
 		return true;
 	default:
 		return false;
@@ -308,7 +316,7 @@ static int dps310_read_raw(struct iio_dev *iio,
 	.writeable_reg = dps310_is_writeable_reg,
 	.volatile_reg = dps310_is_volatile_reg,
 	.cache_type = REGCACHE_RBTREE,
-	.max_register = 0x29,
+	.max_register = 0x62,
 };
 
 static const struct iio_info dps310_info = {
@@ -317,6 +325,41 @@ static int dps310_read_raw(struct iio_dev *iio,
 	.write_raw = dps310_write_raw,
 };
 
+/*
+ * Some verions of chip will read temperatures in the ~60C range when
+ * its acutally ~20C. This is the manufacturer recommended workaround
+ * to correct the issue.
+ */
+static int dps310_temp_workaround(struct dps310_data *data)
+{
+	int r, reg;
+
+	r = regmap_read(data->regmap, DPS310_TEMP_FIX_32, &reg);
+	if (r < 0)
+		return r;
+
+	if (!(reg & DPS310_TEMP_ERR_FIXED)) {
+		r = regmap_write(data->regmap, DPS310_TEMP_FIX_E, 0xA5);
+		if (r < 0)
+			return r;
+
+		r = regmap_write(data->regmap, DPS310_TEMP_FIX_F, 0x96);
+		if (r < 0)
+			return r;
+
+		r = regmap_write(data->regmap, DPS310_TEMP_FIX_62, 0x02);
+		if (r < 0)
+			return r;
+
+		r = regmap_write(data->regmap, DPS310_TEMP_FIX_E, 0x00);
+		if (r < 0)
+			return r;
+
+		r = regmap_write(data->regmap, DPS310_TEMP_FIX_F, 0x00);
+	}
+	return r;
+}
+
 static int dps310_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
@@ -379,6 +422,10 @@ static int dps310_probe(struct i2c_client *client,
 	if (r < 0)
 		return r;
 
+	r = dps310_temp_workaround(data);
+	if (r < 0)
+		return r;
+
 	r = devm_iio_device_register(&client->dev, iio);
 	if (r)
 		return r;
Signature · 1 line
1.8.2.2
#2 lore raw

Re: [PATCH linux dev-4.10 1/2] drivers/iio: dps310 Temperature measurement fix.

Quoted 5 lines · Christopher Bostic

Add a manufacturer's suggested workaround to deal with early revisions of chip that don't indicate correct temperature. Readings can be in the ~60C range when they should be in the ~20's.

Looks okay Chris. Has there been an errata issued for the device so I can check what we're doing here?

I don't think there's much value in the #defines without meaningful labels, so I removed them when applying the patch.

Cheers,

Joel

Quoted 96 lines
---
 drivers/iio/pressure/dps310.c | 49 ++++++++++++++++++++++++++++++++++++++++++-
 1 file changed, 48 insertions(+), 1 deletion(-)
drivers/iio/pressure/dps310.c +48 -2
index 1b54ae0..f351c26 100644
@@ -56,7 +56,12 @@
 #define  DPS310_FIFO_EN                BIT(5)
 #define  DPS310_SPI_EN         BIT(6)
 #define DPS310_RESET           0x0c
+#define DPS310_TEMP_FIX_E      0x0e
+#define DPS310_TEMP_FIX_F      0x0f
 #define  DPS310_RESET_MAGIC    (BIT(0) | BIT(3))
+#define DPS310_TEMP_FIX_32     0x32
+#define  DPS310_TEMP_ERR_FIXED BIT(1)
+#define DPS310_TEMP_FIX_62     0x62
 #define DPS310_COEF_BASE       0x10
 
 #define DPS310_PRS_BASE                DPS310_PRS_B0
@@ -219,6 +224,9 @@ static bool dps310_is_writeable_reg(struct device *dev, unsigned int reg)
        case DPS310_MEAS_CFG:
        case DPS310_CFG_REG:
        case DPS310_RESET:
+       case DPS310_TEMP_FIX_E:
+       case DPS310_TEMP_FIX_F:
+       case DPS310_TEMP_FIX_62:
                return true;
        default:
                return false;
@@ -308,7 +316,7 @@ static int dps310_read_raw(struct iio_dev *iio,
        .writeable_reg = dps310_is_writeable_reg,
        .volatile_reg = dps310_is_volatile_reg,
        .cache_type = REGCACHE_RBTREE,
-       .max_register = 0x29,
+       .max_register = 0x62,
 };
 
 static const struct iio_info dps310_info = {
@@ -317,6 +325,41 @@ static int dps310_read_raw(struct iio_dev *iio,
        .write_raw = dps310_write_raw,
 };
 
+/*
+ * Some verions of chip will read temperatures in the ~60C range when
+ * its acutally ~20C. This is the manufacturer recommended workaround
+ * to correct the issue.
+ */
+static int dps310_temp_workaround(struct dps310_data *data)
+{
+       int r, reg;
+
+       r = regmap_read(data->regmap, DPS310_TEMP_FIX_32, &reg);
+       if (r < 0)
+               return r;
+
+       if (!(reg & DPS310_TEMP_ERR_FIXED)) {
+               r = regmap_write(data->regmap, DPS310_TEMP_FIX_E, 0xA5);
+               if (r < 0)
+                       return r;
+
+               r = regmap_write(data->regmap, DPS310_TEMP_FIX_F, 0x96);
+               if (r < 0)
+                       return r;
+
+               r = regmap_write(data->regmap, DPS310_TEMP_FIX_62, 0x02);
+               if (r < 0)
+                       return r;
+
+               r = regmap_write(data->regmap, DPS310_TEMP_FIX_E, 0x00);
+               if (r < 0)
+                       return r;
+
+               r = regmap_write(data->regmap, DPS310_TEMP_FIX_F, 0x00);
+       }
+       return r;
+}
+
 static int dps310_probe(struct i2c_client *client,
                        const struct i2c_device_id *id)
 {
@@ -379,6 +422,10 @@ static int dps310_probe(struct i2c_client *client,
        if (r < 0)
                return r;
 
+       r = dps310_temp_workaround(data);
+       if (r < 0)
+               return r;
+
        r = devm_iio_device_register(&client->dev, iio);
        if (r)
                return r;
--

1.8.2.2

#3 lore raw

Re: [PATCH linux dev-4.10 1/2] drivers/iio: dps310 Temperature measurement fix.

Quoted 9 lines · Joel Stanley
Quoted 5 lines · Christopher Bostic

Add a manufacturer's suggested workaround to deal with early revisions of chip that don't indicate correct temperature. Readings can be in the ~60C range when they should be in the ~20's.

Looks okay Chris. Has there been an errata issued for the device so I can check what we're doing here?

I wasn't able to find any official documentation from the manufacturer on this. This is based on existing FSP workarounds for this device.

Thanks,
Chris

Quoted 104 lines

I don't think there's much value in the #defines without meaningful labels, so I removed them when applying the patch.

Cheers,

Joel

Quoted 96 lines
---
  drivers/iio/pressure/dps310.c | 49 ++++++++++++++++++++++++++++++++++++++++++-
  1 file changed, 48 insertions(+), 1 deletion(-)
drivers/iio/pressure/dps310.c +48 -2
index 1b54ae0..f351c26 100644
@@ -56,7 +56,12 @@
  #define  DPS310_FIFO_EN                BIT(5)
  #define  DPS310_SPI_EN         BIT(6)
  #define DPS310_RESET           0x0c
+#define DPS310_TEMP_FIX_E      0x0e
+#define DPS310_TEMP_FIX_F      0x0f
  #define  DPS310_RESET_MAGIC    (BIT(0) | BIT(3))
+#define DPS310_TEMP_FIX_32     0x32
+#define  DPS310_TEMP_ERR_FIXED BIT(1)
+#define DPS310_TEMP_FIX_62     0x62
  #define DPS310_COEF_BASE       0x10
 
  #define DPS310_PRS_BASE                DPS310_PRS_B0
@@ -219,6 +224,9 @@ static bool dps310_is_writeable_reg(struct device *dev, unsigned int reg)
         case DPS310_MEAS_CFG:
         case DPS310_CFG_REG:
         case DPS310_RESET:
+       case DPS310_TEMP_FIX_E:
+       case DPS310_TEMP_FIX_F:
+       case DPS310_TEMP_FIX_62:
                 return true;
         default:
                 return false;
@@ -308,7 +316,7 @@ static int dps310_read_raw(struct iio_dev *iio,
         .writeable_reg = dps310_is_writeable_reg,
         .volatile_reg = dps310_is_volatile_reg,
         .cache_type = REGCACHE_RBTREE,
-       .max_register = 0x29,
+       .max_register = 0x62,
  };
 
  static const struct iio_info dps310_info = {
@@ -317,6 +325,41 @@ static int dps310_read_raw(struct iio_dev *iio,
         .write_raw = dps310_write_raw,
  };
 
+/*
+ * Some verions of chip will read temperatures in the ~60C range when
+ * its acutally ~20C. This is the manufacturer recommended workaround
+ * to correct the issue.
+ */
+static int dps310_temp_workaround(struct dps310_data *data)
+{
+       int r, reg;
+
+       r = regmap_read(data->regmap, DPS310_TEMP_FIX_32, &reg);
+       if (r < 0)
+               return r;
+
+       if (!(reg & DPS310_TEMP_ERR_FIXED)) {
+               r = regmap_write(data->regmap, DPS310_TEMP_FIX_E, 0xA5);
+               if (r < 0)
+                       return r;
+
+               r = regmap_write(data->regmap, DPS310_TEMP_FIX_F, 0x96);
+               if (r < 0)
+                       return r;
+
+               r = regmap_write(data->regmap, DPS310_TEMP_FIX_62, 0x02);
+               if (r < 0)
+                       return r;
+
+               r = regmap_write(data->regmap, DPS310_TEMP_FIX_E, 0x00);
+               if (r < 0)
+                       return r;
+
+               r = regmap_write(data->regmap, DPS310_TEMP_FIX_F, 0x00);
+       }
+       return r;
+}
+
  static int dps310_probe(struct i2c_client *client,
                         const struct i2c_device_id *id)
  {
@@ -379,6 +422,10 @@ static int dps310_probe(struct i2c_client *client,
         if (r < 0)
                 return r;
 
+       r = dps310_temp_workaround(data);
+       if (r < 0)
+               return r;
+
         r = devm_iio_device_register(&client->dev, iio);
         if (r)
                 return r;
--

1.8.2.2

#4 lore raw

PATCH 2/2 drivers/iio: dps310 Use previous value if new reading not available yet

In reply to Christopher Bostic

In cases where temperature is queried before the latest value is finished reading then use the previously measured value instead of returning error.

---
 drivers/iio/pressure/dps310.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/pressure/dps310.c +2 -2
index f351c26..c7ee99e 100644
@@ -202,8 +202,8 @@ static int dps310_read_temp(struct dps310_data *data)
 	if (r < 0)
 		return r;
 	if (!(ready & DPS310_TMP_RDY)) {
-		dev_dbg(dev, "temperature not ready\n");
-		return -EAGAIN;
+		dev_dbg(dev, "temperature not ready, use last temp value\n");
+		return 0;
 	}
 
 	r = regmap_bulk_read(regmap, DPS310_TMP_BASE, val, 3);
Signature · 1 line
1.8.2.2
#5 lore raw

Re: [PATCH linux dev-4.10 2/2] drivers/iio: dps310 Use previous value if new reading not available yet

Quoted 13 lines · Christopher Bostic

In cases where temperature is queried before the latest value is finished reading then use the previously measured value instead of returning error.

---
 drivers/iio/pressure/dps310.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/pressure/dps310.c +0 -0
index f351c26..c7ee99e 100644

drivers/iio/pressure/dps310.c static int dps310_read_temp(struct dps310_data *data) · line 206

Quoted 7 lines
drivers/iio/pressure/dps310.c +2 -2
@@ -202,8 +202,8 @@ static int dps310_read_temp(struct dps310_data *data)
        if (r < 0)
                return r;
        if (!(ready & DPS310_TMP_RDY)) {
-               dev_dbg(dev, "temperature not ready\n");
-               return -EAGAIN;
+               dev_dbg(dev, "temperature not ready, use last temp value\n");
+               return 0;

We can't hide these errors in the kernel driver. The user of this API will have no way of knowing if it actually has a new value, or if the value is days old. In the extreme case, the driver may nave never received a value from the hardware, but we will happily report zero.

If you want to go down the path of using old values, there's a defined iio API for doing triggered readings that put data into a timestamped buffer of values. This could be used by userspace when it needs a reading, regardless of it's age. I've not used this before so it would require further investigation to decide if it's useful.

Alternatively, if the userspace application doesn't care about the latest value then it could cache the previously read value and use that.

Cheers,

Joel

#6 lore raw

Re: [PATCH linux dev-4.10 2/2] drivers/iio: dps310 Use previous value if new reading not available yet

Quoted 27 lines · Joel Stanley
Quoted 13 lines · Christopher Bostic

In cases where temperature is queried before the latest value is finished reading then use the previously measured value instead of returning error.

---
  drivers/iio/pressure/dps310.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)
drivers/iio/pressure/dps310.c +0 -0
index f351c26..c7ee99e 100644

drivers/iio/pressure/dps310.c static int dps310_read_temp(struct dps310_data *data) · line 206

Quoted 7 lines
drivers/iio/pressure/dps310.c +2 -2
@@ -202,8 +202,8 @@ static int dps310_read_temp(struct dps310_data *data)
         if (r < 0)
                 return r;
         if (!(ready & DPS310_TMP_RDY)) {
-               dev_dbg(dev, "temperature not ready\n");
-               return -EAGAIN;
+               dev_dbg(dev, "temperature not ready, use last temp value\n");
+               return 0;

We can't hide these errors in the kernel driver. The user of this API will have no way of knowing if it actually has a new value, or if the value is days old. In the extreme case, the driver may nave never received a value from the hardware, but we will happily report zero.

Quoted 5 lines

If you want to go down the path of using old values, there's a defined iio API for doing triggered readings that put data into a timestamped buffer of values. This could be used by userspace when it needs a reading, regardless of it's age. I've not used this before so it would require further investigation to decide if it's useful.

I had thought there was consensus in the Sunday night (Central US time) meeting on using the old value in case where a new measurement wasn't ready. I see your point that we'd not know if the last measurement was days old. Maybe we can take some time in Tuesday night's meeting to discuss further.

Thanks,
Chris

Quoted 9 lines

Alternatively, if the userspace application doesn't care about the latest value then it could cache the previously read value and use that.

Cheers,

Joel