From: Eric Andersson <eric.andersson@unixphere.com>
To: linux-kernel@vger.kernel.org
Cc: gregkh@linuxfoundation.org, alan@lxorguk.ukuu.org.uk,
arnd@arndb.de, zhengguang.guo@bosch-sensortec.com,
peter.moeller@cn.bosch.com, stefan.nilsson@unixphere.com,
broonie@opensource.wolfsonmicro.com,
Eric Andersson <eric.andersson@unixphere.com>
Subject: [PATCHv3 2/3] misc: bmp085: add device tree properties
Date: Wed, 4 Apr 2012 21:45:58 +0200 [thread overview]
Message-ID: <1333568759-13536-3-git-send-email-eric.andersson@unixphere.com> (raw)
In-Reply-To: <1333568759-13536-1-git-send-email-eric.andersson@unixphere.com>
Reviewed-by: Stefan Nilsson <stefan.nilsson@unixphere.com>
Signed-off-by: Eric Andersson <eric.andersson@unixphere.com>
---
Documentation/devicetree/bindings/misc/bmp085.txt | 20 +++++++++++
drivers/misc/bmp085.c | 37 ++++++++++++++++++++-
2 files changed, 56 insertions(+), 1 deletions(-)
create mode 100644 Documentation/devicetree/bindings/misc/bmp085.txt
diff --git a/Documentation/devicetree/bindings/misc/bmp085.txt b/Documentation/devicetree/bindings/misc/bmp085.txt
new file mode 100644
index 0000000..1672b03
--- /dev/null
+++ b/Documentation/devicetree/bindings/misc/bmp085.txt
@@ -0,0 +1,20 @@
+BMP085/BMP18x digital pressure sensors
+
+Required properties:
+- compatible: bosch-sensortec,bmp085
+
+Optional properties:
+- chip-id: configurable chip id for non-default chip revisions
+- temp-measurement-period: temperature measurement period (milliseconds)
+- default-oversampling: default oversampling value to be used at startup,
+ value range is 0-3 with rising sensitivity.
+
+Example:
+
+pressure@77 {
+ compatible = "bosch-sensortec,bmp085";
+ reg = <0x77>;
+ chip-id = <10>;
+ temp-measurement-period = <10>;
+ default-oversampling = <2>;
+};
diff --git a/drivers/misc/bmp085.c b/drivers/misc/bmp085.c
index 1b20974..bdd369d 100644
--- a/drivers/misc/bmp085.c
+++ b/drivers/misc/bmp085.c
@@ -50,6 +50,7 @@
#include <linux/i2c.h>
#include <linux/slab.h>
#include <linux/delay.h>
+#include <linux/of.h>
#define BMP085_NAME "bmp085"
#define BMP085_I2C_ADDRESS 0x77
@@ -85,6 +86,7 @@ struct bmp085_data {
u32 raw_pressure;
u32 temp_measurement_period;
unsigned long last_temp_measurement;
+ u8 chip_id;
s32 b6; /* calculated temperature correction coefficient */
};
@@ -385,6 +387,27 @@ static int bmp085_detect(struct i2c_client *client, struct i2c_board_info *info)
return 0;
}
+static void __init bmp085_get_of_properties(struct i2c_client *client,
+ struct bmp085_data *data)
+{
+#ifdef CONFIG_OF
+ struct device_node *np = client->dev.of_node;
+ u32 prop;
+
+ if (!np)
+ return;
+
+ if (!of_property_read_u32(np, "chip-id", &prop))
+ data->chip_id = prop & 0xff;
+
+ if (!of_property_read_u32(np, "temp-measurement-period", &prop))
+ data->temp_measurement_period = (prop/100)*HZ;
+
+ if (!of_property_read_u32(np, "default-oversampling", &prop))
+ data->oversampling_setting = prop & 0xff;
+#endif
+}
+
static int bmp085_init_client(struct i2c_client *client)
{
struct bmp085_data *data = i2c_get_clientdata(client);
@@ -393,10 +416,15 @@ static int bmp085_init_client(struct i2c_client *client)
if (status < 0)
return status;
+ /* default settings */
data->client = client;
+ data->chip_id = BMP085_CHIP_ID;
data->last_temp_measurement = 0;
data->temp_measurement_period = 1*HZ;
data->oversampling_setting = 3;
+
+ bmp085_get_of_properties(client, data);
+
mutex_init(&data->lock);
return 0;
@@ -446,6 +474,12 @@ static int __devexit bmp085_remove(struct i2c_client *client)
return 0;
}
+static const struct of_device_id bmp085_of_match[] = {
+ { .compatible = "bosch-sensortec,bmp085", },
+ { },
+};
+MODULE_DEVICE_TABLE(of, bmp085_of_match);
+
static const struct i2c_device_id bmp085_id[] = {
{ BMP085_NAME, 0 },
{ }
@@ -455,7 +489,8 @@ MODULE_DEVICE_TABLE(i2c, bmp085_id);
static struct i2c_driver bmp085_driver = {
.driver = {
.owner = THIS_MODULE,
- .name = BMP085_NAME
+ .name = BMP085_NAME,
+ .of_match_table = bmp085_of_match
},
.id_table = bmp085_id,
.probe = bmp085_probe,
--
1.7.3.4
next prev parent reply other threads:[~2012-04-04 19:45 UTC|newest]
Thread overview: 12+ messages / expand[flat|nested] mbox.gz Atom feed top
2012-04-04 19:45 [PATCHv3 0/3] bmp085: add support for bmp18x chip Eric Andersson
2012-04-04 19:45 ` [PATCHv3 1/3] misc: clean up bmp085 driver Eric Andersson
2012-04-04 19:55 ` Joe Perches
2012-04-05 6:30 ` Eric Andersson
2012-04-04 19:45 ` Eric Andersson [this message]
2012-04-04 19:45 ` [PATCHv3 3/3] misc: add support for bmp18x chips to the " Eric Andersson
2012-04-04 19:55 ` Mark Brown
2012-04-04 20:00 ` Arnd Bergmann
2012-04-04 20:11 ` Mark Brown
2012-04-05 6:53 ` Eric Andersson
2012-04-07 1:37 ` Grant Likely
2012-04-04 19:52 ` [PATCHv3 0/3] bmp085: add support for bmp18x chip Arnd Bergmann
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1333568759-13536-3-git-send-email-eric.andersson@unixphere.com \
--to=eric.andersson@unixphere.com \
--cc=alan@lxorguk.ukuu.org.uk \
--cc=arnd@arndb.de \
--cc=broonie@opensource.wolfsonmicro.com \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=peter.moeller@cn.bosch.com \
--cc=stefan.nilsson@unixphere.com \
--cc=zhengguang.guo@bosch-sensortec.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).