diff options
author | NeilBrown <neilb@suse.de> | 2013-05-17 17:13:39 +1000 |
---|---|---|
committer | NeilBrown <neilb@suse.de> | 2013-05-17 17:15:08 +1000 |
commit | 0db8fc0bec3eca1ab90de492665146940e6f5bd9 (patch) | |
tree | 7e14a971d35bae39e01a0f4b5900742d3ce402cb /drivers/misc | |
parent | c967bed3774ac27535215abb66afa5a552e36295 (diff) | |
download | kernel_goldelico_gta04-0db8fc0bec3eca1ab90de492665146940e6f5bd9.tar.gz kernel_goldelico_gta04-0db8fc0bec3eca1ab90de492665146940e6f5bd9.tar.bz2 kernel_goldelico_gta04-0db8fc0bec3eca1ab90de492665146940e6f5bd9.zip |
BMP085 - Stop returning bogus values
Protect sections of the code that access the bmp085 data structure so
variables aren't read and written at the same time and increase the
temperature timeout. The datasheet says the timeout should be 5, but 8
is needed to make it work correctly. Without these changes, the module
returns bogus values like temperatures of 80C when the sensor is 25C and
pressure jumps from 750 to 1100hpa randomly.
Signed-off-by: Ben Deering <ben_deering@swissmail.org>
Signed-off-by: NeilBrown <neilb@suse.de>
Diffstat (limited to 'drivers/misc')
-rw-r--r-- | drivers/misc/bmp085.c | 6 |
1 files changed, 5 insertions, 1 deletions
diff --git a/drivers/misc/bmp085.c b/drivers/misc/bmp085.c index 229f4ca4be3..634bc716bb1 100644 --- a/drivers/misc/bmp085.c +++ b/drivers/misc/bmp085.c @@ -66,7 +66,7 @@ #define BMP085_CONVERSION_REGISTER_MSB 0xF6 #define BMP085_CONVERSION_REGISTER_LSB 0xF7 #define BMP085_CONVERSION_REGISTER_XLSB 0xF8 -#define BMP085_TEMP_CONVERSION_TIME 5 +#define BMP085_TEMP_CONVERSION_TIME 8 struct bmp085_calibration_data { s16 AC1, AC2, AC3; @@ -206,12 +206,14 @@ static s32 bmp085_get_temperature(struct bmp085_data *data, int *temperature) if (status < 0) goto exit; + mutex_lock(&data->lock); x1 = ((data->raw_temperature - cali->AC6) * cali->AC5) >> 15; x2 = (cali->MC << 11) / (x1 + cali->MD); data->b6 = x1 + x2 - 4000; /* if NULL just update b6. Used for pressure only measurements */ if (temperature != NULL) *temperature = (x1+x2+8) >> 4; + mutex_unlock(&data->lock); exit: return status; @@ -245,6 +247,7 @@ static s32 bmp085_get_pressure(struct bmp085_data *data, int *pressure) if (status < 0) return status; + mutex_lock(&data->lock); x1 = (data->b6 * data->b6) >> 12; x1 *= cali->B2; x1 >>= 11; @@ -272,6 +275,7 @@ static s32 bmp085_get_pressure(struct bmp085_data *data, int *pressure) x2 = (-7357 * p) >> 16; p += (x1 + x2 + 3791) >> 4; + mutex_unlock(&data->lock); *pressure = p; return 0; |