[PATCH linux dev-4.10 1/2] drivers/iio: dps310 Temperature measurement fix.
Christopher Bostic
cbostic at linux.vnet.ibm.com
Tue Jul 25 07:25:08 AEST 2017
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.
Signed-off-by: Christopher Bostic <cbostic at linux.vnet.ibm.com>
---
drivers/iio/pressure/dps310.c | 49 ++++++++++++++++++++++++++++++++++++++++++-
1 file changed, 48 insertions(+), 1 deletion(-)
diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 1b54ae0..f351c26 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -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, ®);
+ 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
More information about the openbmc
mailing list