1 From b95144c1b702f98c7902c75beb83f323701eb7c5 Mon Sep 17 00:00:00 2001
2 From: Maarten ter Huurne <maarten@treewalker.org>
3 Date: Sun, 19 Jun 2011 10:57:18 +0200
4 Subject: [PATCH 13/21] MMC: JZ4740: Added support for CPU frequency changing.
6 The MSC device clock is stopped before the frequency change.
7 After the change a new divider is computed and the clock is restarted.
8 Also the frequency change is postponed if an I/O operation is in progress.
10 drivers/mmc/host/jz4740_mmc.c | 69 +++++++++++++++++++++++++++++++++++++++-
11 1 files changed, 67 insertions(+), 2 deletions(-)
13 diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
14 index 74218ad..6e40f1b 100644
15 --- a/drivers/mmc/host/jz4740_mmc.c
16 +++ b/drivers/mmc/host/jz4740_mmc.c
18 #include <linux/delay.h>
19 #include <linux/scatterlist.h>
20 #include <linux/clk.h>
21 +#include <linux/cpufreq.h>
23 #include <linux/bitops.h>
24 #include <linux/gpio.h>
25 @@ -685,6 +686,60 @@ static void jz4740_mmc_enable_sdio_irq(struct mmc_host *mmc, int enable)
26 jz4740_mmc_set_irq_enabled(host, JZ_MMC_IRQ_SDIO, enable);
29 +#ifdef CONFIG_CPU_FREQ
31 +static struct jz4740_mmc_host *cpufreq_host;
33 +static int jz4740_mmc_cpufreq_transition(struct notifier_block *nb,
34 + unsigned long val, void *data)
36 + /* TODO: We only have to take action when the PLL freq changes:
37 + the main dividers have no influence on the MSC device clock. */
39 + if (val == CPUFREQ_PRECHANGE) {
40 + mmc_claim_host(cpufreq_host->mmc);
41 + clk_disable(cpufreq_host->clk);
42 + } else if (val == CPUFREQ_POSTCHANGE) {
43 + struct mmc_ios *ios = &cpufreq_host->mmc->ios;
45 + jz4740_mmc_set_clock_rate(cpufreq_host, ios->clock);
46 + if (ios->power_mode != MMC_POWER_OFF)
47 + clk_enable(cpufreq_host->clk);
48 + mmc_release_host(cpufreq_host->mmc);
53 +static struct notifier_block jz4740_mmc_cpufreq_nb = {
54 + .notifier_call = jz4740_mmc_cpufreq_transition,
57 +static inline int jz4740_mmc_cpufreq_register(struct jz4740_mmc_host *host)
59 + cpufreq_host = host;
60 + return cpufreq_register_notifier(&jz4740_mmc_cpufreq_nb,
61 + CPUFREQ_TRANSITION_NOTIFIER);
64 +static inline void jz4740_mmc_cpufreq_unregister(void)
66 + cpufreq_unregister_notifier(&jz4740_mmc_cpufreq_nb,
67 + CPUFREQ_TRANSITION_NOTIFIER);
72 +static inline int jz4740_mmc_cpufreq_register(struct jz4740_mmc_host *host)
77 +static inline void jz4740_mmc_cpufreq_unregister(void)
83 static const struct mmc_host_ops jz4740_mmc_ops = {
84 .request = jz4740_mmc_request,
85 .set_ios = jz4740_mmc_set_ios,
86 @@ -834,11 +889,18 @@ static int __devinit jz4740_mmc_probe(struct platform_device* pdev)
90 + ret = jz4740_mmc_cpufreq_register(host);
93 + "Failed to register cpufreq transition notifier\n");
97 host->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
100 dev_err(&pdev->dev, "Failed to get base platform memory\n");
102 + goto err_cpufreq_unreg;
105 host->mem = request_mem_region(host->mem->start,
106 @@ -846,7 +908,7 @@ static int __devinit jz4740_mmc_probe(struct platform_device* pdev)
109 dev_err(&pdev->dev, "Failed to request base memory region\n");
111 + goto err_cpufreq_unreg;
114 host->base = ioremap_nocache(host->mem->start, resource_size(host->mem));
115 @@ -929,6 +991,8 @@ err_iounmap:
117 err_release_mem_region:
118 release_mem_region(host->mem->start, resource_size(host->mem));
120 + jz4740_mmc_cpufreq_unregister();
124 @@ -958,6 +1022,7 @@ static int __devexit jz4740_mmc_remove(struct platform_device *pdev)
126 release_mem_region(host->mem->start, resource_size(host->mem));
128 + jz4740_mmc_cpufreq_unregister();
131 platform_set_drvdata(pdev, NULL);