linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/2] Add EOC handling for bmp085 + DT update
@ 2013-11-30 15:25 Marek Belisko
  2013-11-30 15:26 ` [PATCH v2 1/2] misc: bmp085: Clean up and enable use of interrupt for completion Marek Belisko
  2013-11-30 15:26 ` [PATCH v2 2/2] misc: bmp085: devicetree irq update Marek Belisko
  0 siblings, 2 replies; 3+ messages in thread
From: Marek Belisko @ 2013-11-30 15:25 UTC (permalink / raw)
  To: arnd, gregkh
  Cc: rob.herring, pawel.moll, mark.rutland, swarren, ijc+devicetree,
	rob, devicetree, linux-doc, linux-kernel, neilb, hns,
	Marek Belisko

This series add support for using EOC gpio line of bmp085 to detect when conversion
is finished. First patch add that functionality. Second patch document DT binding.

Changes from v1:
- drop custom platform data and use i2c, spi client irq
- use managed resources irq request
- document DT property
- drop patch 3 (adding platform data isn't necessary)

Marek Belisko (2):
  misc: bmp085: Clean up and enable use of interrupt for completion.
  misc: bmp085: devicetree irq update.

 Documentation/devicetree/bindings/misc/bmp085.txt |  4 +++
 drivers/misc/bmp085-i2c.c                         |  2 +-
 drivers/misc/bmp085-spi.c                         |  2 +-
 drivers/misc/bmp085.c                             | 39 ++++++++++++++++++++---
 drivers/misc/bmp085.h                             |  2 +-
 5 files changed, 41 insertions(+), 8 deletions(-)

-- 
1.8.3.2


^ permalink raw reply	[flat|nested] 3+ messages in thread

* [PATCH v2 1/2] misc: bmp085: Clean up and enable use of interrupt for completion.
  2013-11-30 15:25 [PATCH v2 0/2] Add EOC handling for bmp085 + DT update Marek Belisko
@ 2013-11-30 15:26 ` Marek Belisko
  2013-11-30 15:26 ` [PATCH v2 2/2] misc: bmp085: devicetree irq update Marek Belisko
  1 sibling, 0 replies; 3+ messages in thread
From: Marek Belisko @ 2013-11-30 15:26 UTC (permalink / raw)
  To: arnd, gregkh
  Cc: rob.herring, pawel.moll, mark.rutland, swarren, ijc+devicetree,
	rob, devicetree, linux-doc, linux-kernel, neilb, hns,
	Marek Belisko

- pass IRQ to driver and have it initialize
- finish waiting early if interrupt fires

Signed-off-by: NeilBrown <neilb@suse.de>
Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com>
Signed-off-by: Marek Belisko <marek@goldelico.com>
---
 drivers/misc/bmp085-i2c.c |  2 +-
 drivers/misc/bmp085-spi.c |  2 +-
 drivers/misc/bmp085.c     | 39 ++++++++++++++++++++++++++++++++++-----
 drivers/misc/bmp085.h     |  2 +-
 4 files changed, 37 insertions(+), 8 deletions(-)

diff --git a/drivers/misc/bmp085-i2c.c b/drivers/misc/bmp085-i2c.c
index 3abfcec..a7c1629 100644
--- a/drivers/misc/bmp085-i2c.c
+++ b/drivers/misc/bmp085-i2c.c
@@ -49,7 +49,7 @@ static int bmp085_i2c_probe(struct i2c_client *client,
 		return err;
 	}
 
-	return bmp085_probe(&client->dev, regmap);
+	return bmp085_probe(&client->dev, regmap, client->irq);
 }
 
 static int bmp085_i2c_remove(struct i2c_client *client)
diff --git a/drivers/misc/bmp085-spi.c b/drivers/misc/bmp085-spi.c
index d6a5265..864ecac 100644
--- a/drivers/misc/bmp085-spi.c
+++ b/drivers/misc/bmp085-spi.c
@@ -41,7 +41,7 @@ static int bmp085_spi_probe(struct spi_device *client)
 		return err;
 	}
 
-	return bmp085_probe(&client->dev, regmap);
+	return bmp085_probe(&client->dev, regmap, client->irq);
 }
 
 static int bmp085_spi_remove(struct spi_device *client)
diff --git a/drivers/misc/bmp085.c b/drivers/misc/bmp085.c
index 2704d88..820e53d 100644
--- a/drivers/misc/bmp085.c
+++ b/drivers/misc/bmp085.c
@@ -49,9 +49,11 @@
 #include <linux/device.h>
 #include <linux/init.h>
 #include <linux/slab.h>
-#include <linux/delay.h>
 #include <linux/of.h>
 #include "bmp085.h"
+#include <linux/interrupt.h>
+#include <linux/completion.h>
+#include <linux/gpio.h>
 
 #define BMP085_CHIP_ID			0x55
 #define BMP085_CALIBRATION_DATA_START	0xAA
@@ -84,8 +86,19 @@ struct bmp085_data {
 	unsigned long last_temp_measurement;
 	u8	chip_id;
 	s32	b6; /* calculated temperature correction coefficient */
+	int	irq;
+	struct	completion done;
 };
 
+static irqreturn_t bmp085_eoc_isr(int irq, void *devid)
+{
+	struct bmp085_data *data = devid;
+
+	complete(&data->done);
+
+	return IRQ_HANDLED;
+}
+
 static s32 bmp085_read_calibration_data(struct bmp085_data *data)
 {
 	u16 tmp[BMP085_CALIBRATION_DATA_LENGTH];
@@ -116,6 +129,9 @@ static s32 bmp085_update_raw_temperature(struct bmp085_data *data)
 	s32 status;
 
 	mutex_lock(&data->lock);
+
+	init_completion(&data->done);
+
 	status = regmap_write(data->regmap, BMP085_CTRL_REG,
 			      BMP085_TEMP_MEASUREMENT);
 	if (status < 0) {
@@ -123,7 +139,8 @@ static s32 bmp085_update_raw_temperature(struct bmp085_data *data)
 			"Error while requesting temperature measurement.\n");
 		goto exit;
 	}
-	msleep(BMP085_TEMP_CONVERSION_TIME);
+	wait_for_completion_timeout(&data->done, 1 + msecs_to_jiffies(
+					    BMP085_TEMP_CONVERSION_TIME));
 
 	status = regmap_bulk_read(data->regmap, BMP085_CONVERSION_REGISTER_MSB,
 				 &tmp, sizeof(tmp));
@@ -147,6 +164,9 @@ static s32 bmp085_update_raw_pressure(struct bmp085_data *data)
 	s32 status;
 
 	mutex_lock(&data->lock);
+
+	init_completion(&data->done);
+
 	status = regmap_write(data->regmap, BMP085_CTRL_REG,
 			BMP085_PRESSURE_MEASUREMENT +
 			(data->oversampling_setting << 6));
@@ -157,8 +177,8 @@ static s32 bmp085_update_raw_pressure(struct bmp085_data *data)
 	}
 
 	/* wait for the end of conversion */
-	msleep(2+(3 << data->oversampling_setting));
-
+	wait_for_completion_timeout(&data->done, 1 + msecs_to_jiffies(
+					2+(3 << data->oversampling_setting)));
 	/* copy data into a u32 (4 bytes), but skip the first byte. */
 	status = regmap_bulk_read(data->regmap, BMP085_CONVERSION_REGISTER_MSB,
 				 ((u8 *)&tmp)+1, 3);
@@ -420,7 +440,7 @@ struct regmap_config bmp085_regmap_config = {
 };
 EXPORT_SYMBOL_GPL(bmp085_regmap_config);
 
-int bmp085_probe(struct device *dev, struct regmap *regmap)
+int bmp085_probe(struct device *dev, struct regmap *regmap, int irq)
 {
 	struct bmp085_data *data;
 	int err = 0;
@@ -434,6 +454,15 @@ int bmp085_probe(struct device *dev, struct regmap *regmap)
 	dev_set_drvdata(dev, data);
 	data->dev = dev;
 	data->regmap = regmap;
+	data->irq = irq;
+
+	if (data->irq > 0) {
+		err = devm_request_irq(dev, data->irq, bmp085_eoc_isr,
+					      IRQF_TRIGGER_RISING, "bmp085",
+					      data);
+		if (err < 0)
+			goto exit_free;
+	}
 
 	/* Initialize the BMP085 chip */
 	err = bmp085_init_client(data);
diff --git a/drivers/misc/bmp085.h b/drivers/misc/bmp085.h
index 2b8f615..8b8e3b1 100644
--- a/drivers/misc/bmp085.h
+++ b/drivers/misc/bmp085.h
@@ -26,7 +26,7 @@
 
 extern struct regmap_config bmp085_regmap_config;
 
-int bmp085_probe(struct device *dev, struct regmap *regmap);
+int bmp085_probe(struct device *dev, struct regmap *regmap, int irq);
 int bmp085_remove(struct device *dev);
 int bmp085_detect(struct device *dev);
 
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* [PATCH v2 2/2] misc: bmp085: devicetree irq update.
  2013-11-30 15:25 [PATCH v2 0/2] Add EOC handling for bmp085 + DT update Marek Belisko
  2013-11-30 15:26 ` [PATCH v2 1/2] misc: bmp085: Clean up and enable use of interrupt for completion Marek Belisko
@ 2013-11-30 15:26 ` Marek Belisko
  1 sibling, 0 replies; 3+ messages in thread
From: Marek Belisko @ 2013-11-30 15:26 UTC (permalink / raw)
  To: arnd, gregkh
  Cc: rob.herring, pawel.moll, mark.rutland, swarren, ijc+devicetree,
	rob, devicetree, linux-doc, linux-kernel, neilb, hns,
	Marek Belisko

Document irq handling for bmp085.

Signed-off-by: Marek Belisko <marek@goldelico.com>
---
 Documentation/devicetree/bindings/misc/bmp085.txt | 4 ++++
 1 file changed, 4 insertions(+)

diff --git a/Documentation/devicetree/bindings/misc/bmp085.txt b/Documentation/devicetree/bindings/misc/bmp085.txt
index 91dfda2..d7a6deb 100644
--- a/Documentation/devicetree/bindings/misc/bmp085.txt
+++ b/Documentation/devicetree/bindings/misc/bmp085.txt
@@ -8,6 +8,8 @@ Optional properties:
 - 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.
+- interrupt-parent: should be the phandle for the interrupt controller
+- interrupts: interrupt mapping for IRQ
 
 Example:
 
@@ -17,4 +19,6 @@ pressure@77 {
 	chip-id = <10>;
 	temp-measurement-period = <100>;
 	default-oversampling = <2>;
+	interrupt-parent = <&gpio0>;
+	interrupts = <25 IRQ_TYPE_EDGE_RISING>;
 };
-- 
1.8.3.2


^ permalink raw reply related	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2013-11-30 15:26 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-11-30 15:25 [PATCH v2 0/2] Add EOC handling for bmp085 + DT update Marek Belisko
2013-11-30 15:26 ` [PATCH v2 1/2] misc: bmp085: Clean up and enable use of interrupt for completion Marek Belisko
2013-11-30 15:26 ` [PATCH v2 2/2] misc: bmp085: devicetree irq update Marek Belisko

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).