iio:pressure:ms5611: fix and enhancements
Subsystems (2)
v2 cover iio:pressure:ms5611: fix and enhancements
Changes since v1:
* temperature compensation fix:
* reword commit message
* remove useless parenthesis
* power regulator: reword commit message
* add oversampling rate support
Gregor Boirie (3):
iio:pressure:ms5611: fix ms5607 temp compensation iio:pressure:ms5611: oversampling rate support iio:pressure:ms5611: continuous sampling support
Grégor Boirie (3):
iio:pressure:ms5611: use probed device name
iio:pressure:ms5611: power regulator support
iio:pressure:ms5611: DT bindings documentation
.../devicetree/bindings/iio/pressure/ms5611.txt | 19 ++ drivers/iio/pressure/ms5611.h | 31 ++- drivers/iio/pressure/ms5611_core.c | 252 ++++++++++++++++++--- drivers/iio/pressure/ms5611_i2c.c | 14 +- drivers/iio/pressure/ms5611_spi.c | 23 +- 5 files changed, 284 insertions(+), 55 deletions(-) create mode 100644 Documentation/devicetree/bindings/iio/pressure/ms5611.txt
Signature · 1 line
2.1.4
PATCH v2 1/6 iio:pressure:ms5611: fix ms5607 temp compensation
Computation of sens2 was wrong and is fixed by this patch, sens2 should be:
2 * (t - 2000)^2
See page 8 of ms5607 datasheet here:
http://www.meas-spec.com/product/pressure/MS5607-02BA03.aspx--- drivers/iio/pressure/ms5611_core.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-)
drivers/iio/pressure/ms5611_core.c +6 -6
@@ -136,17 +136,17 @@ static int ms5607_temp_and_pressure_compensate(struct ms5611_chip_info *chip_inf t =2000 + ((chip_info->prom[6 ] * dt) >>23 );if (t <2000 ) { -s64 off2, sens2, t2; +s64 off2, sens2, t2, tmp; t2 = (dt * dt) >>31 ; - off2 = (61 * (t -2000 ) * (t -2000 )) >>4 ; - sens2 = off2 <<1 ; + tmp = (t -2000 ) * (t -2000 ); + off2 = (61 * tmp) >>4 ; + sens2 = tmp <<1 ;if (t <-1500 ) { -s64 tmp = (t +1500 ) * (t +1500 ); - + tmp = (t +1500 ) * (t +1500 ); off2 +=15 * tmp; - sens2 += (8 * tmp); + sens2 +=8 * tmp; } t -= t2;
Signature · 1 line
2.1.4
PATCH v2 2/6 iio:pressure:ms5611: use probed device name
In reply to Gregor BoirieFrom: Grégor Boirie <[email protected]>
Use name of probed device instead of driver's one when registering device.
--- drivers/iio/pressure/ms5611.h | 3 ++- drivers/iio/pressure/ms5611_core.c | 5 +++-- drivers/iio/pressure/ms5611_i2c.c | 2 +- drivers/iio/pressure/ms5611_spi.c | 4 ++-- 4 files changed, 8 insertions(+), 6 deletions(-)
drivers/iio/pressure/ms5611.h +2 -1
@@ -51,7 +51,8 @@ struct ms5611_state { struct ms5611_chip_info *chip_info; }; -int ms5611_probe (struct iio_dev *indio_dev,struct device *dev,int type); +int ms5611_probe (struct iio_dev *indio_dev,struct device *dev, +const char * name,int type);int ms5611_remove (struct iio_dev *indio_dev);#endif /* _MS5611_H */
drivers/iio/pressure/ms5611_core.c +3 -2
@@ -298,7 +298,8 @@ static int ms5611_init(struct iio_dev *indio_dev)return ms5611_read_prom (indio_dev); } -int ms5611_probe (struct iio_dev *indio_dev,struct device *dev,int type) +int ms5611_probe (struct iio_dev *indio_dev,struct device *dev, +const char *name,int type) {int ret;struct ms5611_state *st =iio_priv (indio_dev);
@@ -306,7 +307,7 @@ int ms5611_probe(struct iio_dev *indio_dev, struct device *dev, int type)mutex_init (&st->lock); st->chip_info = &chip_info_tbl[type]; indio_dev->dev.parent = dev; - indio_dev->name = dev->driver->name; + indio_dev->name = name; indio_dev->info = &ms5611_info; indio_dev->channels = ms5611_channels; indio_dev->num_channels =ARRAY_SIZE (ms5611_channels);
drivers/iio/pressure/ms5611_i2c.c +1 -1
@@ -105,7 +105,7 @@ static int ms5611_i2c_probe(struct i2c_client *client, st->read_adc_temp_and_pressure = ms5611_i2c_read_adc_temp_and_pressure; st->client = client; -return ms5611_probe (indio_dev, &client->dev, id->driver_data); +return ms5611_probe (indio_dev, &client->dev, id->name, id->driver_data); }static int ms5611_i2c_remove (struct i2c_client *client)
drivers/iio/pressure/ms5611_spi.c +2 -2
@@ -105,8 +105,8 @@ static int ms5611_spi_probe(struct spi_device *spi) st->read_adc_temp_and_pressure = ms5611_spi_read_adc_temp_and_pressure; st->client = spi; -return ms5611_probe (indio_dev, &spi->dev, -spi_get_device_id (spi)->driver_data); +return ms5611_probe (indio_dev, &spi->dev,spi_get_device_id (spi)->name, +spi_get_device_id (spi)->driver_data); }static int ms5611_spi_remove (struct spi_device *spi)
Signature · 1 line
2.1.4
PATCH v2 3/6 iio:pressure:ms5611: power regulator support
In reply to Gregor BoirieFrom: Grégor Boirie <[email protected]>
Add support for an optional regulator which, if found into device-tree, will power on device at probing time.
The regulator is declared into ms5611 DTS entry as a "vdd-supply" property.
--- drivers/iio/pressure/ms5611_core.c | 13 +++++++++++++ 1 file changed, 13 insertions(+)
drivers/iio/pressure/ms5611_core.c +13 -0
@@ -16,6 +16,7 @@#include <linux/module.h> #include <linux/iio/iio.h> #include <linux/delay.h> +#include <linux/regulator/consumer.h> #include <linux/iio/buffer.h> #include <linux/iio/triggered_buffer.h>
@@ -290,6 +291,18 @@ static const struct iio_info ms5611_info = {static int ms5611_init (struct iio_dev *indio_dev) {int ret; +struct regulator *vdd =devm_regulator_get (indio_dev->dev.parent, +"vdd" ); + +/* Enable attached regulator if any. */ +if (!IS_ERR (vdd)) { + ret =regulator_enable (vdd); +if (ret) { +dev_err (indio_dev->dev.parent, +"failed to enable Vdd supply: %d\n" , ret); +return ret; + } + } ret =ms5611_reset (indio_dev);if (ret <0 )
Signature · 1 line
2.1.4
PATCH v2 4/6 iio:pressure:ms5611: DT bindings documentation
In reply to Gregor BoirieFrom: Grégor Boirie <[email protected]>
--- .../devicetree/bindings/iio/pressure/ms5611.txt | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) create mode 100644 Documentation/devicetree/bindings/iio/pressure/ms5611.txt
Documentation/devicetree/bindings/iio/pressure/ms5611.txt new file +19 -0
@@ -0,0 +1,19 @@ +MEAS ms5611 family pressure sensors + +Pressure sensors from MEAS Switzerland with SPI and I2C bus interfaces. + +Required properties: +- compatible: "ms5611" or "ms5607" +- reg: the I2C or SPI address the device will respond to + +Optional properties: +- vdd-supply: an optional regulator that needs to be on to provide VDD + power to the sensor. + +Example: + +ms5607@77 { + compatible = "ms5607"; + reg = <0x77>; + vdd-supply = <&ldo_3v3_gnss>; +};
Signature · 1 line
2.1.4
PATCH v2 5/6 iio:pressure:ms5611: oversampling rate support
In reply to Gregor BoirieAdd support for setting and retrieving OverSampling Rate independently for each of the temperature and pressure channels. This allows userspace to fine tune hardware sampling process according to the following tradeoffs :
* the higher the OSR, the finer the resolution ;
* the higher the OSR, the lower the noise ;
BUT:
* the higher the OSR, the larger the drift ;
* the higher the OSR, the longer the response time, i.e. less samples per unit of time.
--- drivers/iio/pressure/ms5611.h | 20 ++++--- drivers/iio/pressure/ms5611_core.c | 105 ++++++++++++++++++++++++++++++++++++- drivers/iio/pressure/ms5611_i2c.c | 12 ++--- drivers/iio/pressure/ms5611_spi.c | 19 +++---- 4 files changed, 133 insertions(+), 23 deletions(-)
drivers/iio/pressure/ms5611.h +14 -6
@@ -19,12 +19,6 @@#define MS5611_RESET 0x1e#define MS5611_READ_ADC 0x00#define MS5611_READ_PROM_WORD 0xA0 -#define MS5611_START_TEMP_CONV 0x58 -#define MS5611_START_PRESSURE_CONV 0x48 - -#define MS5611_CONV_TIME_MIN 9040 -#define MS5611_CONV_TIME_MAX 10000 -#define MS5611_PROM_WORDS_NB 8enum {
@@ -39,10 +33,24 @@ struct ms5611_chip_info { s32 *temp, s32 *pressure); }; +/* +* OverSampling Rate descriptor. +* Warning: cmd MUST be kept aligned on a word boundary (see +* m5611_spi_read_adc_temp_and_pressure in ms5611_spi.c). +*/ +struct ms5611_osr { +unsigned long conv_usec; +uint8_t cmd; +unsigned short rate; +}; +struct ms5611_state {void *client;struct mutex lock; +const struct ms5611_osr *pressure_osr; +const struct ms5611_osr *temp_osr; +int (*reset)(struct device *dev);int (*read_prom_word)(struct device *dev,int index,u16 *word); int (*read_adc_temp_and_pressure)(struct device *dev,
drivers/iio/pressure/ms5611_core.c +103 -2
151 lines not on this page · raw message
drivers/iio/pressure/ms5611_i2c.c +6 -6
@@ -62,23 +62,23 @@ static int ms5611_i2c_read_adc_temp_and_pressure(struct device *dev, {int ret;struct ms5611_state *st =iio_priv (dev_to_iio_dev (dev)); +const struct ms5611_osr *osr = st->temp_osr; - ret =i2c_smbus_write_byte (st->client,MS5611_START_TEMP_CONV ); + ret =i2c_smbus_write_byte (st->client, osr->cmd);if (ret <0 )return ret; -usleep_range (MS5611_CONV_TIME_MIN ,MS5611_CONV_TIME_MAX ); - +usleep_range (osr->conv_usec, osr->conv_usec + (osr->conv_usec /10UL )); ret =ms5611_i2c_read_adc (st, temp);if (ret <0 )return ret; - ret =i2c_smbus_write_byte (st->client,MS5611_START_PRESSURE_CONV ); + osr = st->pressure_osr; + ret =i2c_smbus_write_byte (st->client, osr->cmd);if (ret <0 )return ret; -usleep_range (MS5611_CONV_TIME_MIN ,MS5611_CONV_TIME_MAX ); - +usleep_range (osr->conv_usec, osr->conv_usec + (osr->conv_usec /10UL ));return ms5611_i2c_read_adc (st, pressure); }
drivers/iio/pressure/ms5611_spi.c +10 -9
@@ -55,28 +55,29 @@ static int ms5611_spi_read_adc(struct device *dev, s32 *val)static int ms5611_spi_read_adc_temp_and_pressure (struct device *dev,s32 *temp,s32 *pressure) { -u8 cmd;int ret;struct ms5611_state *st =iio_priv (dev_to_iio_dev (dev)); +const struct ms5611_osr *osr = st->temp_osr; - cmd =MS5611_START_TEMP_CONV ; - ret =spi_write_then_read (st->client, &cmd,1 ,NULL ,0 ); +/* +* Warning: &osr->cmd MUST be aligned on a word boundary since used as +* 2nd argument (void*) of spi_write_then_read. +*/ + ret =spi_write_then_read (st->client, &osr->cmd,1 ,NULL ,0 );if (ret <0 )return ret; -usleep_range (MS5611_CONV_TIME_MIN ,MS5611_CONV_TIME_MAX ); - +usleep_range (osr->conv_usec, osr->conv_usec + (osr->conv_usec /10UL )); ret =ms5611_spi_read_adc (dev, temp);if (ret <0 )return ret; - cmd =MS5611_START_PRESSURE_CONV ; - ret =spi_write_then_read (st->client, &cmd,1 ,NULL ,0 ); + osr = st->pressure_osr; + ret =spi_write_then_read (st->client, &osr->cmd,1 ,NULL ,0 );if (ret <0 )return ret; -usleep_range (MS5611_CONV_TIME_MIN ,MS5611_CONV_TIME_MAX ); - +usleep_range (osr->conv_usec, osr->conv_usec + (osr->conv_usec /10UL ));return ms5611_spi_read_adc (dev, pressure); }
Signature · 1 line
2.1.4
PATCH v2 6/6 iio:pressure:ms5611: continuous sampling support
In reply to Gregor BoirieImplement INDIO_BUFFER_SOFTWARE mode to allow continuous sampling without relying upon external trigger.
Sampling is carried out by a kthread which life cycle is bound to samples
buffering: it is created at postenable time and destroyed at predisable time.
--- drivers/iio/pressure/ms5611.h | 8 +++ drivers/iio/pressure/ms5611_core.c | 117 ++++++++++++++++++++++++++++++------- 2 files changed, 105 insertions(+), 20 deletions(-)
drivers/iio/pressure/ms5611.h +8 -0
@@ -44,10 +44,17 @@ struct ms5611_osr {unsigned short rate; }; +/* +* Number of s32 for a complete sample, i.e. s32 (pressure) + s32 (temp) + +* 2 * s32 (timestamp). +*/ +#define MS5611_BUFFER_NR (4U) +struct ms5611_state {void *client;struct mutex lock; +s32 buf[MS5611_BUFFER_NR ];const struct ms5611_osr *pressure_osr;const struct ms5611_osr *temp_osr;
@@ -57,6 +64,7 @@ struct ms5611_state { s32 *temp, s32 *pressure);struct ms5611_chip_info *chip_info; +struct task_struct *task; }; int ms5611_probe(struct iio_dev *indio_dev, struct device *dev,
drivers/iio/pressure/ms5611_core.c +97 -20
173 lines not on this page · raw message
Signature · 1 line
2.1.4