aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/misc
diff options
context:
space:
mode:
authorEric Andersson <eric.andersson@unixphere.com>2012-04-09 16:16:16 -0400
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>2012-04-18 17:56:36 -0400
commitc5a86ab6dd6e424c56826421a80b855e24f7caa1 (patch)
tree684ff235e5a6391a7e2f1e37fdb9fb038b92affd /drivers/misc
parente939ca0a63627d6b2205dd945833ee7da4fc181a (diff)
misc: bmp085: add device tree properties
Reviewed-by: Stefan Nilsson <stefan.nilsson@unixphere.com> Signed-off-by: Eric Andersson <eric.andersson@unixphere.com> Reviewed-by: Arnd Bergmann <arnd@arndb.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Diffstat (limited to 'drivers/misc')
-rw-r--r--drivers/misc/bmp085.c37
1 files changed, 36 insertions, 1 deletions
diff --git a/drivers/misc/bmp085.c b/drivers/misc/bmp085.c
index 6f572bc21879..6adde9e1a0d1 100644
--- a/drivers/misc/bmp085.c
+++ b/drivers/misc/bmp085.c
@@ -50,6 +50,7 @@
50#include <linux/i2c.h> 50#include <linux/i2c.h>
51#include <linux/slab.h> 51#include <linux/slab.h>
52#include <linux/delay.h> 52#include <linux/delay.h>
53#include <linux/of.h>
53 54
54#define BMP085_NAME "bmp085" 55#define BMP085_NAME "bmp085"
55#define BMP085_I2C_ADDRESS 0x77 56#define BMP085_I2C_ADDRESS 0x77
@@ -85,6 +86,7 @@ struct bmp085_data {
85 u32 raw_pressure; 86 u32 raw_pressure;
86 u32 temp_measurement_period; 87 u32 temp_measurement_period;
87 unsigned long last_temp_measurement; 88 unsigned long last_temp_measurement;
89 u8 chip_id;
88 s32 b6; /* calculated temperature correction coefficient */ 90 s32 b6; /* calculated temperature correction coefficient */
89}; 91};
90 92
@@ -385,6 +387,27 @@ static int bmp085_detect(struct i2c_client *client, struct i2c_board_info *info)
385 return 0; 387 return 0;
386} 388}
387 389
390static void __init bmp085_get_of_properties(struct i2c_client *client,
391 struct bmp085_data *data)
392{
393#ifdef CONFIG_OF
394 struct device_node *np = client->dev.of_node;
395 u32 prop;
396
397 if (!np)
398 return;
399
400 if (!of_property_read_u32(np, "chip-id", &prop))
401 data->chip_id = prop & 0xff;
402
403 if (!of_property_read_u32(np, "temp-measurement-period", &prop))
404 data->temp_measurement_period = (prop/100)*HZ;
405
406 if (!of_property_read_u32(np, "default-oversampling", &prop))
407 data->oversampling_setting = prop & 0xff;
408#endif
409}
410
388static int bmp085_init_client(struct i2c_client *client) 411static int bmp085_init_client(struct i2c_client *client)
389{ 412{
390 struct bmp085_data *data = i2c_get_clientdata(client); 413 struct bmp085_data *data = i2c_get_clientdata(client);
@@ -393,10 +416,15 @@ static int bmp085_init_client(struct i2c_client *client)
393 if (status < 0) 416 if (status < 0)
394 return status; 417 return status;
395 418
419 /* default settings */
396 data->client = client; 420 data->client = client;
421 data->chip_id = BMP085_CHIP_ID;
397 data->last_temp_measurement = 0; 422 data->last_temp_measurement = 0;
398 data->temp_measurement_period = 1*HZ; 423 data->temp_measurement_period = 1*HZ;
399 data->oversampling_setting = 3; 424 data->oversampling_setting = 3;
425
426 bmp085_get_of_properties(client, data);
427
400 mutex_init(&data->lock); 428 mutex_init(&data->lock);
401 429
402 return 0; 430 return 0;
@@ -446,6 +474,12 @@ static int __devexit bmp085_remove(struct i2c_client *client)
446 return 0; 474 return 0;
447} 475}
448 476
477static const struct of_device_id bmp085_of_match[] = {
478 { .compatible = "bosch,bmp085", },
479 { },
480};
481MODULE_DEVICE_TABLE(of, bmp085_of_match);
482
449static const struct i2c_device_id bmp085_id[] = { 483static const struct i2c_device_id bmp085_id[] = {
450 { BMP085_NAME, 0 }, 484 { BMP085_NAME, 0 },
451 { } 485 { }
@@ -455,7 +489,8 @@ MODULE_DEVICE_TABLE(i2c, bmp085_id);
455static struct i2c_driver bmp085_driver = { 489static struct i2c_driver bmp085_driver = {
456 .driver = { 490 .driver = {
457 .owner = THIS_MODULE, 491 .owner = THIS_MODULE,
458 .name = BMP085_NAME 492 .name = BMP085_NAME,
493 .of_match_table = bmp085_of_match
459 }, 494 },
460 .id_table = bmp085_id, 495 .id_table = bmp085_id,
461 .probe = bmp085_probe, 496 .probe = bmp085_probe,