All of lore.kernel.org
 help / color / mirror / Atom feed
From: Eddie James <eajames@linux.ibm.com>
To: linux-iio@vger.kernel.org
Cc: linux-kernel@vger.kernel.org, joel@jms.id.au, lars@metafoo.de,
	knaack.h@gmx.de, jic23@kernel.org,
	Christopher Bostic <cbostic@linux.vnet.ibm.com>,
	Eddie James <eajames@linux.ibm.com>
Subject: [PATCH v4 2/3] iio: dps310: Temperature measurement errata
Date: Mon, 20 May 2019 21:13:33 -0500	[thread overview]
Message-ID: <1558404814-26078-3-git-send-email-eajames@linux.ibm.com> (raw)
In-Reply-To: <1558404814-26078-1-git-send-email-eajames@linux.ibm.com>

From: Christopher Bostic <cbostic@linux.vnet.ibm.com>

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@linux.vnet.ibm.com>
Signed-off-by: Joel Stanley <joel@jms.id.au>
Signed-off-by: Eddie James <eajames@linux.ibm.com>
Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com>
---
 drivers/iio/pressure/dps310.c | 52 +++++++++++++++++++++++++++++++++++++++++--
 1 file changed, 50 insertions(+), 2 deletions(-)

diff --git a/drivers/iio/pressure/dps310.c b/drivers/iio/pressure/dps310.c
index 9acfccb..a093e3a 100644
--- a/drivers/iio/pressure/dps310.c
+++ b/drivers/iio/pressure/dps310.c
@@ -53,7 +53,6 @@
 #define DPS310_RESET		0x0c
 #define  DPS310_RESET_MAGIC	0x09
 #define DPS310_COEF_BASE	0x10
-#define DPS310_COEF_SRC		0x28
 
 /* Make sure sleep time is <= 20ms for usleep_range */
 #define DPS310_POLL_SLEEP_US(t)		min(20000, (t) / 8)
@@ -234,6 +233,10 @@ static bool dps310_is_writeable_reg(struct device *dev, unsigned int reg)
 	case DPS310_MEAS_CFG:
 	case DPS310_CFG_REG:
 	case DPS310_RESET:
+	/* No documentation available on the registers below */
+	case 0x0e:
+	case 0x0f:
+	case 0x62:
 		return true;
 	default:
 		return false;
@@ -250,6 +253,7 @@ static bool dps310_is_volatile_reg(struct device *dev, unsigned int reg)
 	case DPS310_TMP_B1:
 	case DPS310_TMP_B2:
 	case DPS310_MEAS_CFG:
+	case 0x32:	/* No documentation available on this register */
 		return true;
 	default:
 		return false;
@@ -360,7 +364,7 @@ static void dps310_reset(void *action_data)
 	.writeable_reg = dps310_is_writeable_reg,
 	.volatile_reg = dps310_is_volatile_reg,
 	.cache_type = REGCACHE_RBTREE,
-	.max_register = DPS310_COEF_SRC,
+	.max_register = 0x62, /* No documentation available on this register */
 };
 
 static const struct iio_info dps310_info = {
@@ -368,6 +372,46 @@ static void dps310_reset(void *action_data)
 	.write_raw = dps310_write_raw,
 };
 
+/*
+ * Some verions of chip will read temperatures in the ~60C range when
+ * its actually ~20C. This is the manufacturer recommended workaround
+ * to correct the issue. The registers used below are undocumented.
+ */
+static int dps310_temp_workaround(struct dps310_data *data)
+{
+	int rc;
+	int reg;
+
+	rc = regmap_read(data->regmap, 0x32, &reg);
+	if (rc < 0)
+		return rc;
+
+	/*
+	 * If bit 1 is set then the device is okay, and the workaround does not
+	 * need to be applied
+	 */
+	if (reg & BIT(1))
+		return 0;
+
+	rc = regmap_write(data->regmap, 0x0e, 0xA5);
+	if (rc < 0)
+		return rc;
+
+	rc = regmap_write(data->regmap, 0x0f, 0x96);
+	if (rc < 0)
+		return rc;
+
+	rc = regmap_write(data->regmap, 0x62, 0x02);
+	if (rc < 0)
+		return rc;
+
+	rc = regmap_write(data->regmap, 0x0e, 0x00);
+	if (rc < 0)
+		return rc;
+
+	return regmap_write(data->regmap, 0x0f, 0x00);
+}
+
 static int dps310_probe(struct i2c_client *client,
 			const struct i2c_device_id *id)
 {
@@ -439,6 +483,10 @@ static int dps310_probe(struct i2c_client *client,
 	if (rc < 0)
 		return rc;
 
+	rc = dps310_temp_workaround(data);
+	if (rc < 0)
+		return rc;
+
 	rc = devm_iio_device_register(&client->dev, iio);
 	if (rc)
 		return rc;
-- 
1.8.3.1


  parent reply	other threads:[~2019-05-21  2:13 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-05-21  2:13 [PATCH v4 0/3] iio: Add driver for Infineon DPS310 Eddie James
2019-05-21  2:13 ` [PATCH v4 1/3] " Eddie James
2019-05-26 17:34   ` Jonathan Cameron
2019-05-21  2:13 ` Eddie James [this message]
2019-05-26 17:34   ` [PATCH v4 2/3] iio: dps310: Temperature measurement errata Jonathan Cameron
2019-05-21  2:13 ` [PATCH v4 3/3] iio: dps310: Add pressure sensing capability Eddie James
2019-05-26 17:35   ` Jonathan Cameron

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1558404814-26078-3-git-send-email-eajames@linux.ibm.com \
    --to=eajames@linux.ibm.com \
    --cc=cbostic@linux.vnet.ibm.com \
    --cc=jic23@kernel.org \
    --cc=joel@jms.id.au \
    --cc=knaack.h@gmx.de \
    --cc=lars@metafoo.de \
    --cc=linux-iio@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.