linux-i2c.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Kevin Hilman <khilman@deeprootsystems.com>
To: linux-i2c@vger.kernel.org
Cc: Chaithrika U S <chaithrika@ti.com>,
	"Jean Delvare (PC drivers, core)" <khali@linux-fr.org>,
	"Ben Dooks (embedded platforms)" <ben-linux@fluff.org>,
	Kevin Hilman <khilman@deeprootsystems.com>,
	Philby John <pjohn@in.mvista.com>,
	"Srinivasan, Nageswari" <nageswari@ti.com>,
	linux-kernel@vger.kernel.org
Subject: [PATCH 5/6] i2c: davinci: Add cpufreq support
Date: Tue,  6 Apr 2010 10:42:17 -0700	[thread overview]
Message-ID: <1270575738-22388-6-git-send-email-khilman@deeprootsystems.com> (raw)
In-Reply-To: <1270575738-22388-1-git-send-email-khilman@deeprootsystems.com>

From: Chaithrika U S <chaithrika@ti.com>

Add cpufreq support for DaVinci I2C driver.
Tested on DA850/OMAP-L138 EVM.

Signed-off-by: Chaithrika U S <chaithrika@ti.com>
Acked-by: Kevin Hilman <khilman@deeprootsystems.com>
---
 drivers/i2c/busses/i2c-davinci.c |   63 ++++++++++++++++++++++++++++++++++++++
 1 files changed, 63 insertions(+), 0 deletions(-)

diff --git a/drivers/i2c/busses/i2c-davinci.c b/drivers/i2c/busses/i2c-davinci.c
index dfec296..fd7a155 100644
--- a/drivers/i2c/busses/i2c-davinci.c
+++ b/drivers/i2c/busses/i2c-davinci.c
@@ -35,6 +35,7 @@
 #include <linux/interrupt.h>
 #include <linux/platform_device.h>
 #include <linux/io.h>
+#include <linux/cpufreq.h>
 
 #include <mach/hardware.h>
 #include <mach/i2c.h>
@@ -106,6 +107,10 @@ struct davinci_i2c_dev {
 	int			stop;
 	u8			terminate;
 	struct i2c_adapter	adapter;
+#ifdef CONFIG_CPU_FREQ
+	struct completion	xfr_complete;
+	struct notifier_block	freq_transition;
+#endif
 };
 
 /* default platform data to use if not supplied in the platform_device */
@@ -390,6 +395,11 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
 		if (ret < 0)
 			return ret;
 	}
+
+#ifdef CONFIG_CPU_FREQ
+	complete(&dev->xfr_complete);
+#endif
+
 	return num;
 }
 
@@ -522,6 +532,48 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
 	return count ? IRQ_HANDLED : IRQ_NONE;
 }
 
+#ifdef CONFIG_CPU_FREQ
+static int i2c_davinci_cpufreq_transition(struct notifier_block *nb,
+				     unsigned long val, void *data)
+{
+	struct davinci_i2c_dev *dev;
+
+	dev = container_of(nb, struct davinci_i2c_dev, freq_transition);
+	if (val == CPUFREQ_PRECHANGE) {
+		wait_for_completion(&dev->xfr_complete);
+		davinci_i2c_reset_ctrl(dev, 0);
+	} else if (val == CPUFREQ_POSTCHANGE) {
+		i2c_davinci_calc_clk_dividers(dev);
+		davinci_i2c_reset_ctrl(dev, 1);
+	}
+
+	return 0;
+}
+
+static inline int i2c_davinci_cpufreq_register(struct davinci_i2c_dev *dev)
+{
+	dev->freq_transition.notifier_call = i2c_davinci_cpufreq_transition;
+
+	return cpufreq_register_notifier(&dev->freq_transition,
+					 CPUFREQ_TRANSITION_NOTIFIER);
+}
+
+static inline void i2c_davinci_cpufreq_deregister(struct davinci_i2c_dev *dev)
+{
+	cpufreq_unregister_notifier(&dev->freq_transition,
+				    CPUFREQ_TRANSITION_NOTIFIER);
+}
+#else
+static inline int i2c_davinci_cpufreq_register(struct davinci_i2c_dev *dev)
+{
+	return 0;
+}
+
+static inline void i2c_davinci_cpufreq_deregister(struct davinci_i2c_dev *dev)
+{
+}
+#endif
+
 static struct i2c_algorithm i2c_davinci_algo = {
 	.master_xfer	= i2c_davinci_xfer,
 	.functionality	= i2c_davinci_func,
@@ -561,6 +613,9 @@ static int davinci_i2c_probe(struct platform_device *pdev)
 	}
 
 	init_completion(&dev->cmd_complete);
+#ifdef CONFIG_CPU_FREQ
+	init_completion(&dev->xfr_complete);
+#endif
 	dev->dev = get_device(&pdev->dev);
 	dev->irq = irq->start;
 	platform_set_drvdata(pdev, dev);
@@ -586,6 +641,12 @@ static int davinci_i2c_probe(struct platform_device *pdev)
 		goto err_unuse_clocks;
 	}
 
+	r = i2c_davinci_cpufreq_register(dev);
+	if (r) {
+		dev_err(&pdev->dev, "failed to register cpufreq\n");
+		goto err_free_irq;
+	}
+
 	adap = &dev->adapter;
 	i2c_set_adapdata(adap, dev);
 	adap->owner = THIS_MODULE;
@@ -627,6 +688,8 @@ static int davinci_i2c_remove(struct platform_device *pdev)
 	struct davinci_i2c_dev *dev = platform_get_drvdata(pdev);
 	struct resource *mem;
 
+	i2c_davinci_cpufreq_deregister(dev);
+
 	platform_set_drvdata(pdev, NULL);
 	i2c_del_adapter(&dev->adapter);
 	put_device(&pdev->dev);
-- 
1.7.0.2

  parent reply	other threads:[~2010-04-06 17:42 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2010-04-06 17:42 [PATCH 0/6] i2c: davinci updates for 2.6.35 Kevin Hilman
     [not found] ` <1270575738-22388-1-git-send-email-khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-04-06 17:42   ` [PATCH 1/6] i2c: davinci: Fix smbus Oops with AIC33 usage Kevin Hilman
     [not found]     ` <1270575738-22388-2-git-send-email-khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-04-20  0:05       ` Ben Dooks
2010-04-06 17:42   ` [PATCH 2/6] i2c: davinci: misc. cleanups: remove MOD_REG_BIT and IO_ADDRESS usage Kevin Hilman
2010-04-06 17:42   ` [PATCH 3/6] i2c: davinci: Add helper functions for power management Kevin Hilman
2010-04-06 17:42   ` [PATCH 4/6] i2c: davinci: Add suspend/resume support Kevin Hilman
2010-04-06 17:42   ` [PATCH 6/6] i2c: davinci: bus recovery procedure to clear the bus Kevin Hilman
2010-04-20  0:06   ` [PATCH 0/6] i2c: davinci updates for 2.6.35 Ben Dooks
     [not found]     ` <20100420000621.GK32401-elnMNo+KYs3pIgCt6eIbzw@public.gmane.org>
2010-04-20 13:55       ` Kevin Hilman
2010-06-21 20:16       ` Kevin Hilman
     [not found]         ` <AANLkTikJ6XDywcBA5O0mC85jQEIWxZ9NOALIQOjcGCDJ-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-08-10 15:56           ` Kevin Hilman
     [not found]             ` <AANLkTinNXxzCoH+b3=xA92sW8GCqqO4iY+_yVwBFLMqG-JsoAwUIsXosN+BqQ9rBEUg@public.gmane.org>
2010-08-10 23:44               ` Ben Dooks
2010-04-06 17:42 ` Kevin Hilman [this message]
  -- strict thread matches above, loose matches on Subject: below --
2010-01-26 23:41 [PATCH 0/6] davinci i2c updates for 2.6.34 Kevin Hilman
     [not found] ` <1264549293-25556-1-git-send-email-khilman-1D3HCaltpLuhEniVeURVKkEOCMrvLtNR@public.gmane.org>
2010-01-26 23:41   ` [PATCH 5/6] i2c: davinci: Add cpufreq support Kevin Hilman

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=1270575738-22388-6-git-send-email-khilman@deeprootsystems.com \
    --to=khilman@deeprootsystems.com \
    --cc=ben-linux@fluff.org \
    --cc=chaithrika@ti.com \
    --cc=khali@linux-fr.org \
    --cc=linux-i2c@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=nageswari@ti.com \
    --cc=pjohn@in.mvista.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).