linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] i2c-designware: add optional regulator support
@ 2012-03-19 12:46 Mika Westerberg
       [not found] ` <1332161180-32502-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
  0 siblings, 1 reply; 6+ messages in thread
From: Mika Westerberg @ 2012-03-19 12:46 UTC (permalink / raw)
  To: linux-i2c-u79uwXL29TY76Z2rM5mHXA
  Cc: khali-PUYAD+kWke1g9hUCZPvPmw, ben-linux-elnMNo+KYs3YtjvyW6yDsg,
	w.sang-bIcnvbaLZ9MEGnE8C9+IrQ, Mika Westerberg, Jani Nikula,
	Kirill A. Shutemov, Dirk Brandewie

It is possible that some of the i2c busses are supplied by a separate
regulator which needs to be enabled before we can access the bus. Thus add
support for an optional regulator.

We also implement enabling/disabling the regulator on system and runtime PM
hooks.

Signed-off-by: Mika Westerberg <mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Signed-off-by: Jani Nikula <jani.nikula-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
Signed-off-by: Kirill A. Shutemov <kirill.shutemov-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
Cc: Dirk Brandewie <dirk.brandewie-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
---
 drivers/i2c/busses/i2c-designware-pcidrv.c |   19 +++++++++++++++++++
 1 files changed, 19 insertions(+), 0 deletions(-)

diff --git a/drivers/i2c/busses/i2c-designware-pcidrv.c b/drivers/i2c/busses/i2c-designware-pcidrv.c
index 37f4211..26bcdf3 100644
--- a/drivers/i2c/busses/i2c-designware-pcidrv.c
+++ b/drivers/i2c/busses/i2c-designware-pcidrv.c
@@ -39,6 +39,7 @@
 #include <linux/slab.h>
 #include <linux/pci.h>
 #include <linux/pm_runtime.h>
+#include <linux/regulator/consumer.h>
 #include "i2c-designware-core.h"
 
 #define DRIVER_NAME "i2c-designware-pci"
@@ -62,6 +63,7 @@ struct dw_pci_controller {
 	u32 tx_fifo_depth;
 	u32 rx_fifo_depth;
 	u32 clk_khz;
+	struct regulator *regulator;
 };
 
 #define INTEL_MID_STD_CFG  (DW_IC_CON_MASTER |			\
@@ -144,6 +146,8 @@ static int i2c_dw_pci_suspend(struct device *dev)
 	struct dw_i2c_dev *i2c = pci_get_drvdata(pdev);
 	int err;
 
+	if (i2c->controller->regulator)
+		regulator_disable(i2c->controller->regulator);
 
 	i2c_dw_disable(i2c);
 
@@ -169,6 +173,9 @@ static int i2c_dw_pci_resume(struct device *dev)
 	int err;
 	u32 enabled;
 
+	if (i2c->controller->regulator)
+		regulator_enable(i2c->controller->regulator);
+
 	enabled = i2c_dw_is_enabled(i2c);
 	if (enabled)
 		return 0;
@@ -281,6 +288,12 @@ const struct pci_device_id *id)
 
 	pci_set_drvdata(pdev, dev);
 
+	controller->regulator = regulator_get(&pdev->dev, "v-i2c");
+	if (IS_ERR(controller->regulator))
+		controller->regulator = NULL;
+	else
+		regulator_enable(controller->regulator);
+
 	dev->tx_fifo_depth = controller->tx_fifo_depth;
 	dev->rx_fifo_depth = controller->rx_fifo_depth;
 	r = i2c_dw_init(dev);
@@ -332,11 +345,17 @@ exit:
 static void __devexit i2c_dw_pci_remove(struct pci_dev *pdev)
 {
 	struct dw_i2c_dev *dev = pci_get_drvdata(pdev);
+	struct regulator *regulator = dev->controller->regulator;
 
 	i2c_dw_disable(dev);
 	pm_runtime_forbid(&pdev->dev);
 	pm_runtime_get_noresume(&pdev->dev);
 
+	if (regulator) {
+		regulator_disable(regulator);
+		regulator_put(regulator);
+	}
+
 	pci_set_drvdata(pdev, NULL);
 	i2c_del_adapter(&dev->adapter);
 	put_device(&pdev->dev);
-- 
1.7.9.1

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

end of thread, other threads:[~2012-03-20 15:16 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2012-03-19 12:46 [PATCH] i2c-designware: add optional regulator support Mika Westerberg
     [not found] ` <1332161180-32502-1-git-send-email-mika.westerberg-VuQAYsv1563Yd54FQh9/CA@public.gmane.org>
2012-03-19 14:28   ` Mark Brown
     [not found]     ` <20120319142807.GA9334-GFdadSzt00ze9xe1eoZjHA@public.gmane.org>
2012-03-19 15:41       ` Mika Westerberg
     [not found]         ` <20120319154130.GX32276-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2012-03-19 16:24           ` Mark Brown
     [not found]             ` <20120319162434.GC5132-yzvPICuk2AATkU/dhu1WVueM+bqZidxxQQ4Iyu8u01E@public.gmane.org>
2012-03-20  8:46               ` Mika Westerberg
     [not found]                 ` <20120320084619.GZ32276-ral2JQCrhuEAvxtiuMwx3w@public.gmane.org>
2012-03-20 15:16                   ` Mark Brown

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