Commit 9a16711c authored by Chaithrika U S's avatar Chaithrika U S Committed by Kevin Hilman

i2c: davinci: Add cpufreq support

Add cpufreq support for DaVinci I2C driver.
Tested on DA850/OMAP-L138 EVM.
Signed-off-by: default avatarChaithrika U S <chaithrika@ti.com>
Acked-by: default avatarKevin Hilman <khilman@deeprootsystems.com>
parent 8e960127
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/io.h> #include <linux/io.h>
#include <linux/slab.h> #include <linux/slab.h>
#include <linux/cpufreq.h>
#include <mach/hardware.h> #include <mach/hardware.h>
#include <mach/i2c.h> #include <mach/i2c.h>
...@@ -107,6 +108,10 @@ struct davinci_i2c_dev { ...@@ -107,6 +108,10 @@ struct davinci_i2c_dev {
int stop; int stop;
u8 terminate; u8 terminate;
struct i2c_adapter adapter; 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 */ /* default platform data to use if not supplied in the platform_device */
...@@ -391,6 +396,11 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num) ...@@ -391,6 +396,11 @@ i2c_davinci_xfer(struct i2c_adapter *adap, struct i2c_msg msgs[], int num)
if (ret < 0) if (ret < 0)
return ret; return ret;
} }
#ifdef CONFIG_CPU_FREQ
complete(&dev->xfr_complete);
#endif
return num; return num;
} }
...@@ -523,6 +533,48 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id) ...@@ -523,6 +533,48 @@ static irqreturn_t i2c_davinci_isr(int this_irq, void *dev_id)
return count ? IRQ_HANDLED : IRQ_NONE; 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 = { static struct i2c_algorithm i2c_davinci_algo = {
.master_xfer = i2c_davinci_xfer, .master_xfer = i2c_davinci_xfer,
.functionality = i2c_davinci_func, .functionality = i2c_davinci_func,
...@@ -562,6 +614,9 @@ static int davinci_i2c_probe(struct platform_device *pdev) ...@@ -562,6 +614,9 @@ static int davinci_i2c_probe(struct platform_device *pdev)
} }
init_completion(&dev->cmd_complete); init_completion(&dev->cmd_complete);
#ifdef CONFIG_CPU_FREQ
init_completion(&dev->xfr_complete);
#endif
dev->dev = get_device(&pdev->dev); dev->dev = get_device(&pdev->dev);
dev->irq = irq->start; dev->irq = irq->start;
platform_set_drvdata(pdev, dev); platform_set_drvdata(pdev, dev);
...@@ -587,6 +642,12 @@ static int davinci_i2c_probe(struct platform_device *pdev) ...@@ -587,6 +642,12 @@ static int davinci_i2c_probe(struct platform_device *pdev)
goto err_unuse_clocks; 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; adap = &dev->adapter;
i2c_set_adapdata(adap, dev); i2c_set_adapdata(adap, dev);
adap->owner = THIS_MODULE; adap->owner = THIS_MODULE;
...@@ -628,6 +689,8 @@ static int davinci_i2c_remove(struct platform_device *pdev) ...@@ -628,6 +689,8 @@ static int davinci_i2c_remove(struct platform_device *pdev)
struct davinci_i2c_dev *dev = platform_get_drvdata(pdev); struct davinci_i2c_dev *dev = platform_get_drvdata(pdev);
struct resource *mem; struct resource *mem;
i2c_davinci_cpufreq_deregister(dev);
platform_set_drvdata(pdev, NULL); platform_set_drvdata(pdev, NULL);
i2c_del_adapter(&dev->adapter); i2c_del_adapter(&dev->adapter);
put_device(&pdev->dev); put_device(&pdev->dev);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment