Root/target/linux/xburst/patches-3.2/0013-MMC-JZ4740-Added-support-for-CPU-frequency-changing.patch

1From b95144c1b702f98c7902c75beb83f323701eb7c5 Mon Sep 17 00:00:00 2001
2From: Maarten ter Huurne <maarten@treewalker.org>
3Date: Sun, 19 Jun 2011 10:57:18 +0200
4Subject: [PATCH 13/28] MMC: JZ4740: Added support for CPU frequency changing.
5
6The MSC device clock is stopped before the frequency change.
7After the change a new divider is computed and the clock is restarted.
8Also the frequency change is postponed if an I/O operation is in progress.
9---
10 drivers/mmc/host/jz4740_mmc.c | 69 +++++++++++++++++++++++++++++++++++++++-
11 1 files changed, 67 insertions(+), 2 deletions(-)
12
13diff --git a/drivers/mmc/host/jz4740_mmc.c b/drivers/mmc/host/jz4740_mmc.c
14index 74218ad..6e40f1b 100644
15--- a/drivers/mmc/host/jz4740_mmc.c
16+++ b/drivers/mmc/host/jz4740_mmc.c
17@@ -23,6 +23,7 @@
18 #include <linux/delay.h>
19 #include <linux/scatterlist.h>
20 #include <linux/clk.h>
21+#include <linux/cpufreq.h>
22 
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);
27 }
28 
29+#ifdef CONFIG_CPU_FREQ
30+
31+static struct jz4740_mmc_host *cpufreq_host;
32+
33+static int jz4740_mmc_cpufreq_transition(struct notifier_block *nb,
34+ unsigned long val, void *data)
35+{
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. */
38+
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;
44+ if (ios->clock)
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);
49+ }
50+ return 0;
51+}
52+
53+static struct notifier_block jz4740_mmc_cpufreq_nb = {
54+ .notifier_call = jz4740_mmc_cpufreq_transition,
55+};
56+
57+static inline int jz4740_mmc_cpufreq_register(struct jz4740_mmc_host *host)
58+{
59+ cpufreq_host = host;
60+ return cpufreq_register_notifier(&jz4740_mmc_cpufreq_nb,
61+ CPUFREQ_TRANSITION_NOTIFIER);
62+}
63+
64+static inline void jz4740_mmc_cpufreq_unregister(void)
65+{
66+ cpufreq_unregister_notifier(&jz4740_mmc_cpufreq_nb,
67+ CPUFREQ_TRANSITION_NOTIFIER);
68+}
69+
70+#else
71+
72+static inline int jz4740_mmc_cpufreq_register(struct jz4740_mmc_host *host)
73+{
74+ return 0;
75+}
76+
77+static inline void jz4740_mmc_cpufreq_unregister(void)
78+{
79+}
80+
81+#endif
82+
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)
87         goto err_free_host;
88     }
89 
90+ ret = jz4740_mmc_cpufreq_register(host);
91+ if (ret) {
92+ dev_err(&pdev->dev,
93+ "Failed to register cpufreq transition notifier\n");
94+ goto err_clk_put;
95+ }
96+
97     host->mem = platform_get_resource(pdev, IORESOURCE_MEM, 0);
98     if (!host->mem) {
99         ret = -ENOENT;
100         dev_err(&pdev->dev, "Failed to get base platform memory\n");
101- goto err_clk_put;
102+ goto err_cpufreq_unreg;
103     }
104 
105     host->mem = request_mem_region(host->mem->start,
106@@ -846,7 +908,7 @@ static int __devinit jz4740_mmc_probe(struct platform_device* pdev)
107     if (!host->mem) {
108         ret = -EBUSY;
109         dev_err(&pdev->dev, "Failed to request base memory region\n");
110- goto err_clk_put;
111+ goto err_cpufreq_unreg;
112     }
113 
114     host->base = ioremap_nocache(host->mem->start, resource_size(host->mem));
115@@ -929,6 +991,8 @@ err_iounmap:
116     iounmap(host->base);
117 err_release_mem_region:
118     release_mem_region(host->mem->start, resource_size(host->mem));
119+err_cpufreq_unreg:
120+ jz4740_mmc_cpufreq_unregister();
121 err_clk_put:
122     clk_put(host->clk);
123 err_free_host:
124@@ -958,6 +1022,7 @@ static int __devexit jz4740_mmc_remove(struct platform_device *pdev)
125     iounmap(host->base);
126     release_mem_region(host->mem->start, resource_size(host->mem));
127 
128+ jz4740_mmc_cpufreq_unregister();
129     clk_put(host->clk);
130 
131     platform_set_drvdata(pdev, NULL);
132--
1331.7.5.4
134
135

Archive Download this file



interactive