lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1436991152-824-1-git-send-email-tduszyns@gmail.com>
Date:	Wed, 15 Jul 2015 22:12:32 +0200
From:	Tomasz Duszynski <tduszyns@...il.com>
To:	jic23@...nel.org
Cc:	knaack.h@....de, lars@...afoo.de, pmeerw@...erw.net,
	tduszyns@...il.com, linux-iio@...r.kernel.org,
	linux-kernel@...r.kernel.org
Subject: [PATCH] iio: pressure: ms5611: add support for MS5803 temperature and pressure sensor

MS5803 is factory calibrated temperature and pressure sensor capable
of providing precise 24bit measurements. Sensor supports  both I2C and SPI
and uses the same command protocol as MS5611/MS5607.

Signed-off-by: Tomasz Duszynski <tduszyns@...il.com>
---
 drivers/iio/pressure/Kconfig       |  2 +-
 drivers/iio/pressure/ms5611.h      |  1 +
 drivers/iio/pressure/ms5611_core.c | 43 ++++++++++++++++++++++++++++++++++++++
 drivers/iio/pressure/ms5611_i2c.c  |  1 +
 drivers/iio/pressure/ms5611_spi.c  |  1 +
 5 files changed, 47 insertions(+), 1 deletion(-)

diff --git a/drivers/iio/pressure/Kconfig b/drivers/iio/pressure/Kconfig
index 4745179..5f339b7 100644
--- a/drivers/iio/pressure/Kconfig
+++ b/drivers/iio/pressure/Kconfig
@@ -56,7 +56,7 @@ config MS5611
 	tristate "Measurement Specialties MS5611 pressure sensor driver"
 	help
 	  Say Y here to build support for the Measurement Specialties
-	  MS5611, MS5607 pressure and temperature sensors.
+	  MS5611, MS5607, MS5803 pressure and temperature sensors.
 
 	  To compile this driver as a module, choose M here: the module will
 	  be called ms5611_core.
diff --git a/drivers/iio/pressure/ms5611.h b/drivers/iio/pressure/ms5611.h
index 23b93c7..07500b6 100644
--- a/drivers/iio/pressure/ms5611.h
+++ b/drivers/iio/pressure/ms5611.h
@@ -30,6 +30,7 @@
 enum {
 	MS5611,
 	MS5607,
+	MS5803
 };
 
 struct ms5611_chip_info {
diff --git a/drivers/iio/pressure/ms5611_core.c b/drivers/iio/pressure/ms5611_core.c
index 2f3d9b4..173d7bf 100644
--- a/drivers/iio/pressure/ms5611_core.c
+++ b/drivers/iio/pressure/ms5611_core.c
@@ -10,6 +10,7 @@
  * Data sheet:
  *  http://www.meas-spec.com/downloads/MS5611-01BA03.pdf
  *  http://www.meas-spec.com/downloads/MS5607-02BA03.pdf
+ *  http://www.meas-spec.com/downloads/MS5803-01BA.pdf
  *
  */
 
@@ -157,6 +158,45 @@ static int ms5607_temp_and_pressure_compensate(struct ms5611_chip_info *chip_inf
 	return 0;
 }
 
+static int ms5803_temp_and_pressure_compensate(struct ms5611_chip_info *chip_info,
+					       s32 *temp, s32 *pressure)
+{
+	s32 t = *temp, p = *pressure;
+	s64 off, sens, dt, off2, sens2, t2;
+
+	dt = t - (chip_info->prom[5] << 8);
+	off = ((s64)chip_info->prom[2] << 16) + ((chip_info->prom[4] * dt) >> 7);
+	sens = ((s64)chip_info->prom[1] << 15) + ((chip_info->prom[3] * dt) >> 8);
+
+	t = 2000 + ((chip_info->prom[6] * dt) >> 23);
+	if (t < 2000) {
+		s64 tmp = (t - 2000) * (t - 2000);
+
+		t2 = (dt * dt) >> 31;
+		off2 = 3 * tmp;
+		sens2 = (7 * tmp) >> 3;
+
+		if (t < -1500)
+			sens2 += 2 * (t + 1500) * (t + 1500);
+	} else {
+		t2 = 0;
+		off2 = 0;
+		sens2 = 0;
+
+		if (t >= 4500)
+			sens2 -= ((t - 4500) * (t - 4500)) >> 3;
+	}
+
+	t -= t2;
+	off -= off2;
+	sens -= sens2;
+
+	*temp = t;
+	*pressure = (((p * sens) >> 21) - off) >> 15;
+
+	return 0;
+}
+
 static int ms5611_reset(struct iio_dev *indio_dev)
 {
 	int ret;
@@ -212,6 +252,9 @@ static struct ms5611_chip_info chip_info_tbl[] = {
 	},
 	[MS5607] = {
 		.temp_and_pressure_compensate = ms5607_temp_and_pressure_compensate,
+	},
+	[MS5803] = {
+		.temp_and_pressure_compensate = ms5803_temp_and_pressure_compensate,
 	}
 };
 
diff --git a/drivers/iio/pressure/ms5611_i2c.c b/drivers/iio/pressure/ms5611_i2c.c
index 245797d..7125055 100644
--- a/drivers/iio/pressure/ms5611_i2c.c
+++ b/drivers/iio/pressure/ms5611_i2c.c
@@ -110,6 +110,7 @@ static int ms5611_i2c_probe(struct i2c_client *client,
 static const struct i2c_device_id ms5611_id[] = {
 	{ "ms5611", MS5611 },
 	{ "ms5607", MS5607 },
+	{ "ms5803", MS5803 },
 	{ }
 };
 MODULE_DEVICE_TABLE(i2c, ms5611_id);
diff --git a/drivers/iio/pressure/ms5611_spi.c b/drivers/iio/pressure/ms5611_spi.c
index 08ee6e8..59a60ed 100644
--- a/drivers/iio/pressure/ms5611_spi.c
+++ b/drivers/iio/pressure/ms5611_spi.c
@@ -110,6 +110,7 @@ static int ms5611_spi_probe(struct spi_device *spi)
 static const struct spi_device_id ms5611_id[] = {
 	{ "ms5611", MS5611 },
 	{ "ms5607", MS5607 },
+	{ "ms5803", MS5803 },
 	{ }
 };
 MODULE_DEVICE_TABLE(spi, ms5611_id);
-- 
2.4.5

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ