48 #include <linux/module.h>
49 #include <linux/device.h>
51 #include <linux/slab.h>
56 #define BMP085_CHIP_ID 0x55
57 #define BMP085_CALIBRATION_DATA_START 0xAA
58 #define BMP085_CALIBRATION_DATA_LENGTH 11
59 #define BMP085_CHIP_ID_REG 0xD0
60 #define BMP085_CTRL_REG 0xF4
61 #define BMP085_TEMP_MEASUREMENT 0x2E
62 #define BMP085_PRESSURE_MEASUREMENT 0x34
63 #define BMP085_CONVERSION_REGISTER_MSB 0xF6
64 #define BMP085_CONVERSION_REGISTER_LSB 0xF7
65 #define BMP085_CONVERSION_REGISTER_XLSB 0xF8
66 #define BMP085_TEMP_CONVERSION_TIME 5
123 "Error while requesting temperature measurement.\n");
132 "Error while reading temperature measurement result\n");
155 "Error while requesting pressure measurement.\n");
167 "Error while reading pressure measurement results\n");
189 status = bmp085_update_raw_temperature(data);
194 x2 = (cali->
MC << 11) / (x1 + cali->
MD);
195 data->
b6 = x1 + x2 - 4000;
197 if (temperature !=
NULL)
198 *temperature = (x1+x2+8) >> 4;
212 static s32 bmp085_get_pressure(
struct bmp085_data *data,
int *pressure)
223 status = bmp085_get_temperature(data,
NULL);
228 status = bmp085_update_raw_pressure(data);
232 x1 = (data->
b6 * data->
b6) >> 12;
236 x2 = cali->
AC2 * data->
b6;
244 x1 = (cali->
AC3 * data->
b6) >> 13;
245 x2 = (cali->
B1 * ((data->
b6 * data->
b6) >> 12)) >> 16;
246 x3 = (x1 + x2 + 2) >> 2;
247 b4 = (cali->
AC4 * (
u32)(x3 + 32768)) >> 15;
251 p = ((b7 < 0x80000000) ? ((b7 << 1) / b4) : ((b7 / b4) * 2));
255 x1 = (x1 * 3038) >> 16;
256 x2 = (-7357 *
p) >> 16;
257 p += (x1 + x2 + 3791) >> 4;
271 static void bmp085_set_oversampling(
struct bmp085_data *data,
272 unsigned char oversampling)
274 if (oversampling > 3)
282 static unsigned char bmp085_get_oversampling(
struct bmp085_data *data)
293 unsigned long oversampling;
294 int err = kstrtoul(buf, 10, &oversampling);
298 bmp085_set_oversampling(data, oversampling);
311 return sprintf(buf,
"%u\n", bmp085_get_oversampling(data));
314 show_oversampling, set_oversampling);
324 status = bmp085_get_temperature(data, &temperature);
328 return sprintf(buf,
"%d\n", temperature);
340 status = bmp085_get_pressure(data, &pressure);
344 return sprintf(buf,
"%d\n", pressure);
349 static struct attribute *bmp085_attributes[] = {
350 &dev_attr_temp0_input.attr,
351 &dev_attr_pressure0_input.attr,
352 &dev_attr_oversampling.attr,
357 .attrs = bmp085_attributes,
386 if (!of_property_read_u32(np,
"chip-id", &prop))
389 if (!of_property_read_u32(np,
"temp-measurement-period", &prop))
392 if (!of_property_read_u32(np,
"default-oversampling", &prop))
397 static int bmp085_init_client(
struct bmp085_data *data)
399 int status = bmp085_read_calibration_data(data);
410 bmp085_get_of_properties(data);
439 err = bmp085_init_client(data);