]> git.hungrycats.org Git - linux/commitdiff
[ARM PATCH] 1890/2: Consolidate CPUFREQ handling in SOC PCMCIA driver
authorIan Campbell <icampbell@com.rmk.(none)>
Thu, 3 Jun 2004 22:13:07 +0000 (23:13 +0100)
committerRussell King <rmk@flint.arm.linux.org.uk>
Thu, 3 Jun 2004 22:13:07 +0000 (23:13 +0100)
Patch from Ian Campbell

Rediffed against latest BK. Compiles on Assabet and my PXA255

platform. Tested on my 255 platform.

drivers/pcmcia/pxa2xx_base.c
drivers/pcmcia/sa11xx_base.c
drivers/pcmcia/soc_common.c
drivers/pcmcia/soc_common.h

index ef574afa0263fdf8fed39cb2e2ede14b8f48da63..491d11bc8fe6ea6d190abad1aab5f141fe469a4d 100644 (file)
@@ -22,7 +22,6 @@
 #include <linux/cpufreq.h>
 #include <linux/ioport.h>
 #include <linux/kernel.h>
-#include <linux/notifier.h>
 #include <linux/spinlock.h>
 
 #include <asm/hardware.h>
@@ -133,6 +132,39 @@ static int pxa2xx_pcmcia_set_timing(struct soc_pcmcia_socket *skt)
        return pxa2xx_pcmcia_set_mcxx(skt, clk);
 }
 
+#ifdef CONFIG_CPU_FREQ
+
+static int
+pxa2xx_pcmcia_frequency_change(struct soc_pcmcia_socket *skt,
+                              unsigned long val,
+                              struct cpufreq_freqs *freqs)
+{
+#warning "it's not clear if this is right since the core CPU (N) clock has no effect on the memory (L) clock"
+       switch (val) {
+       case CPUFREQ_PRECHANGE:
+               if (freqs->new > freqs->old) {
+                       debug(skt, 2, "new frequency %u.%uMHz > %u.%uMHz, "
+                              "pre-updating\n",
+                              freqs->new / 1000, (freqs->new / 100) % 10,
+                              freqs->old / 1000, (freqs->old / 100) % 10);
+                       pxa2xx_pcmcia_set_mcxx(skt, freqs->new);
+               }
+               break;
+
+       case CPUFREQ_POSTCHANGE:
+               if (freqs->new < freqs->old) {
+                       debug(skt, 2, "new frequency %u.%uMHz < %u.%uMHz, "
+                              "post-updating\n",
+                              freqs->new / 1000, (freqs->new / 100) % 10,
+                              freqs->old / 1000, (freqs->old / 100) % 10);
+                       pxa2xx_pcmcia_set_mcxx(skt, freqs->new);
+               }
+               break;
+       }
+       return 0;
+}
+#endif
+
 int pxa2xx_drv_pcmcia_probe(struct device *dev)
 {
        int ret;
@@ -181,6 +213,9 @@ int pxa2xx_drv_pcmcia_probe(struct device *dev)
 
        /* Provide our PXA2xx specific timing routines. */
        ops->set_timing  = pxa2xx_pcmcia_set_timing;
+#ifdef CONFIG_CPU_FREQ
+       ops->frequency_change = pxa2xx_pcmcia_frequency_change;
+#endif
 
        ret = soc_common_drv_pcmcia_probe(dev, ops, first, nr);
 
@@ -227,101 +262,13 @@ static struct device_driver pxa2xx_pcmcia_driver = {
        .bus            = &platform_bus_type,
 };
 
-#ifdef CONFIG_CPU_FREQ
-
-/*
- * When pxa2xx_pcmcia_notifier() decides that a MC{IO,MEM,ATT} adjustment (due
- * to a core clock frequency change) is needed, this routine establishes
- * new values consistent with the clock speed `clock'.
- */
-static void pxa2xx_pcmcia_update_mcxx(unsigned int clock)
-{
-       struct soc_pcmcia_socket *skt;
-
-       down(&soc_sockets_lock);
-       list_for_each_entry(skt, &soc_sockets, node) {
-               pxa2xx_pcmcia_set_mcxx(skt, clock);
-       }
-       up(&soc_sockets_lock);
-}
-
-/*
- * When changing the processor L clock frequency, it is necessary
- * to adjust the MCXX timings accordingly. We've recorded the timings
- * requested by Card Services, so this is just a matter of finding
- * out what our current speed is, and then recomputing the new MCXX
- * values.
- *
- * Returns: 0 on success, -1 on error
- */
-static int
-pxa2xx_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data)
-{
-       struct cpufreq_freqs *freqs = data;
-
-#warning "it's not clear if this is right since the core CPU (N) clock has no effect on the memory (L) clock"
-       switch (val) {
-               case CPUFREQ_PRECHANGE:
-                       if (freqs->new > freqs->old) {
-                               debug( 2, "new frequency %u.%uMHz > %u.%uMHz, "
-                                               "pre-updating\n",
-                                               freqs->new / 1000, (freqs->new / 100) % 10,
-                                               freqs->old / 1000, (freqs->old / 100) % 10);
-                               pxa2xx_pcmcia_update_mcxx(freqs->new);
-                       }
-                       break;
-
-               case CPUFREQ_POSTCHANGE:
-                       if (freqs->new < freqs->old) {
-                               debug( 2, "new frequency %u.%uMHz < %u.%uMHz, "
-                                               "post-updating\n",
-                                               freqs->new / 1000, (freqs->new / 100) % 10,
-                                               freqs->old / 1000, (freqs->old / 100) % 10);
-                               pxa2xx_pcmcia_update_mcxx(freqs->new);
-                       }
-                       break;
-       }
-
-       return 0;
-}
-
-static struct notifier_block pxa2xx_pcmcia_notifier_block = {
-       .notifier_call  = pxa2xx_pcmcia_notifier
-};
-
-static int __init pxa2xx_pcmcia_cpufreq_init(void)
-{
-       int ret;
-
-       ret = cpufreq_register_notifier(&pxa2xx_pcmcia_notifier_block,
-                                       CPUFREQ_TRANSITION_NOTIFIER);
-       if (ret < 0)
-               printk(KERN_ERR "Unable to register CPU frequency change "
-                               "notifier for PCMCIA (%d)\n", ret);
-       return ret;
-}
-
-static void __exit pxa2xx_pcmcia_cpufreq_exit(void)
-{
-       cpufreq_unregister_notifier(&pxa2xx_pcmcia_notifier_block, CPUFREQ_TRANSITION_NOTIFIER);
-}
-
-#else
-#define pxa2xx_pcmcia_cpufreq_init()
-#define pxa2xx_pcmcia_cpufreq_exit()
-#endif
-
 static int __init pxa2xx_pcmcia_init(void)
 {
-       int ret = driver_register(&pxa2xx_pcmcia_driver);
-       if (ret == 0)
-               pxa2xx_pcmcia_cpufreq_init();
-       return ret;
+       return driver_register(&pxa2xx_pcmcia_driver);
 }
 
 static void __exit pxa2xx_pcmcia_exit(void)
 {
-       pxa2xx_pcmcia_cpufreq_exit();
        driver_unregister(&pxa2xx_pcmcia_driver);
 }
 
index fb634ab5def4feb4b04d03116ec3840c8923a30b..db04ffb6f68c564cca51f335c81b92686229364e 100644 (file)
@@ -36,7 +36,6 @@
 #include <linux/cpufreq.h>
 #include <linux/ioport.h>
 #include <linux/kernel.h>
-#include <linux/notifier.h>
 #include <linux/spinlock.h>
 
 #include <asm/hardware.h>
@@ -111,6 +110,32 @@ sa1100_pcmcia_set_mecr(struct soc_pcmcia_socket *skt, unsigned int cpu_clock)
        return 0;
 }
 
+#ifdef CONFIG_CPU_FREQ
+static int
+sa1100_pcmcia_frequency_change(struct soc_pcmcia_socket *skt,
+                              unsigned long val,
+                              struct cpufreq_freqs *freqs)
+{
+       switch (val) {
+       case CPUFREQ_PRECHANGE:
+               if (freqs->new > freqs->old)
+                       sa1100_pcmcia_set_mecr(skt, freqs->new);
+               break;
+
+       case CPUFREQ_POSTCHANGE:
+               if (freqs->new < freqs->old)
+                       sa1100_pcmcia_set_mecr(skt, freqs->new);
+               break;
+       case CPUFREQ_RESUMECHANGE:
+               sa1100_pcmcia_set_mecr(skt, freqs->new);
+               break;
+       }
+
+       return 0;
+}
+
+#endif
+
 static int
 sa1100_pcmcia_set_timing(struct soc_pcmcia_socket *skt)
 {
@@ -152,90 +177,23 @@ int sa11xx_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops,
        /* Provide our SA11x0 specific timing routines. */
        ops->set_timing  = sa1100_pcmcia_set_timing;
        ops->show_timing = sa1100_pcmcia_show_timing;
+#ifdef CONFIG_CPU_FREQ
+       ops->frequency_change = sa1100_pcmcia_frequency_change;
+#endif
 
        return soc_common_drv_pcmcia_probe(dev, ops, first, nr);
 }
 EXPORT_SYMBOL(sa11xx_drv_pcmcia_probe);
 
-#ifdef CONFIG_CPU_FREQ
-
-/* sa1100_pcmcia_update_mecr()
- * ^^^^^^^^^^^^^^^^^^^^^^^^^^^
- * When sa1100_pcmcia_notifier() decides that a MECR adjustment (due
- * to a core clock frequency change) is needed, this routine establishes
- * new BS_xx values consistent with the clock speed `clock'.
- */
-static void sa1100_pcmcia_update_mecr(unsigned int clock)
-{
-       struct soc_pcmcia_socket *skt;
-
-       down(&soc_pcmcia_sockets_lock);
-       list_for_each_entry(skt, &soc_pcmcia_sockets, node)
-               sa1100_pcmcia_set_mecr(skt, clock);
-       up(&soc_pcmcia_sockets_lock);
-}
-
-/* sa1100_pcmcia_notifier()
- * ^^^^^^^^^^^^^^^^^^^^^^^^
- * When changing the processor core clock frequency, it is necessary
- * to adjust the MECR timings accordingly. We've recorded the timings
- * requested by Card Services, so this is just a matter of finding
- * out what our current speed is, and then recomputing the new MECR
- * values.
- *
- * Returns: 0 on success, -1 on error
- */
-static int
-sa1100_pcmcia_notifier(struct notifier_block *nb, unsigned long val,
-                      void *data)
-{
-       struct cpufreq_freqs *freqs = data;
-
-       switch (val) {
-       case CPUFREQ_PRECHANGE:
-               if (freqs->new > freqs->old)
-                       sa1100_pcmcia_update_mecr(freqs->new);
-               break;
-
-       case CPUFREQ_POSTCHANGE:
-               if (freqs->new < freqs->old)
-                       sa1100_pcmcia_update_mecr(freqs->new);
-               break;
-       case CPUFREQ_RESUMECHANGE:
-               sa1100_pcmcia_update_mecr(freqs->new);
-               break;
-       }
-
-       return 0;
-}
-
-static struct notifier_block sa1100_pcmcia_notifier_block = {
-       .notifier_call  = sa1100_pcmcia_notifier
-};
-
 static int __init sa11xx_pcmcia_init(void)
 {
-       int ret;
-
-       printk(KERN_INFO "SA11xx PCMCIA\n");
-
-       ret = cpufreq_register_notifier(&sa1100_pcmcia_notifier_block,
-                                       CPUFREQ_TRANSITION_NOTIFIER);
-       if (ret < 0)
-               printk(KERN_ERR "Unable to register CPU frequency change "
-                       "notifier (%d)\n", ret);
-
-       return ret;
+       return 0;
 }
 module_init(sa11xx_pcmcia_init);
 
-static void __exit sa11xx_pcmcia_exit(void)
-{
-       cpufreq_unregister_notifier(&sa1100_pcmcia_notifier_block, CPUFREQ_TRANSITION_NOTIFIER);
-}
+static void __exit sa11xx_pcmcia_exit(void) {}
 
 module_exit(sa11xx_pcmcia_exit);
-#endif
 
 MODULE_AUTHOR("John Dorsey <john+@cs.cmu.edu>");
 MODULE_DESCRIPTION("Linux PCMCIA Card Services: SA-11xx core socket driver");
index ff8b52124f66f8fb9b05ab5f2f9cdc6da0f1e2e4..6d393e739fc0f0576d4d5dc4dbcc963026794b25 100644 (file)
@@ -31,6 +31,7 @@
 ======================================================================*/
 
 
+#include <linux/config.h>
 #include <linux/module.h>
 #include <linux/moduleparam.h>
 #include <linux/init.h>
@@ -39,6 +40,7 @@
 #include <linux/mm.h>
 #include <linux/interrupt.h>
 #include <linux/spinlock.h>
+#include <linux/cpufreq.h>
 
 #include <asm/hardware.h>
 #include <asm/io.h>
@@ -614,6 +616,49 @@ struct skt_dev_info {
 #define SKT_DEV_INFO_SIZE(n) \
        (sizeof(struct skt_dev_info) + (n)*sizeof(struct soc_pcmcia_socket))
 
+#ifdef CONFIG_CPU_FREQ
+static int
+soc_pcmcia_notifier(struct notifier_block *nb, unsigned long val, void *data)
+{
+       struct soc_pcmcia_socket *skt;
+       struct cpufreq_freqs *freqs = data;
+       int ret = 0;
+
+       down(&soc_pcmcia_sockets_lock);
+       list_for_each_entry(skt, &soc_pcmcia_sockets, node)
+               if ( skt->ops->frequency_change )
+                       ret += skt->ops->frequency_change(skt, val, freqs);
+       up(&soc_pcmcia_sockets_lock);
+
+       return ret;
+}
+
+static struct notifier_block soc_pcmcia_notifier_block = {
+       .notifier_call  = soc_pcmcia_notifier
+};
+
+static int soc_pcmcia_cpufreq_register(void)
+{
+       int ret;
+
+       ret = cpufreq_register_notifier(&soc_pcmcia_notifier_block,
+                                       CPUFREQ_TRANSITION_NOTIFIER);
+       if (ret < 0)
+               printk(KERN_ERR "Unable to register CPU frequency change "
+                               "notifier for PCMCIA (%d)\n", ret);
+       return ret;
+}
+
+static void soc_pcmcia_cpufreq_unregister(void)
+{
+       cpufreq_unregister_notifier(&soc_pcmcia_notifier_block, CPUFREQ_TRANSITION_NOTIFIER);
+}
+
+#else
+#define soc_pcmcia_cpufreq_register()
+#define soc_pcmcia_cpufreq_unregister()
+#endif
+
 int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops, int first, int nr)
 {
        struct skt_dev_info *sinfo;
@@ -692,6 +737,9 @@ int soc_common_drv_pcmcia_probe(struct device *dev, struct pcmcia_low_level *ops
                        goto out_err_5;
                }
 
+               if ( list_empty(&soc_pcmcia_sockets) )
+                       soc_pcmcia_cpufreq_register();
+
                list_add(&skt->node, &soc_pcmcia_sockets);
 
                /*
@@ -789,6 +837,9 @@ int soc_common_drv_pcmcia_remove(struct device *dev)
                release_resource(&skt->res_io);
                release_resource(&skt->res_skt);
        }
+       if ( list_empty(&soc_pcmcia_sockets) )
+               soc_pcmcia_cpufreq_unregister();
+
        up(&soc_pcmcia_sockets_lock);
 
        kfree(sinfo);
index 60e30197bd3fb49097a34fe8f71bc9ee408dcb9b..f77923ceda7ac6937a3b9ab4086428482a26995e 100644 (file)
@@ -10,6 +10,7 @@
 #define _ASM_ARCH_PCMCIA
 
 /* include the world */
+#include <linux/cpufreq.h>
 #include <pcmcia/version.h>
 #include <pcmcia/cs_types.h>
 #include <pcmcia/cs.h>
@@ -103,6 +104,13 @@ struct pcmcia_low_level {
        unsigned int (*get_timing)(struct soc_pcmcia_socket *, unsigned int, unsigned int);
        int (*set_timing)(struct soc_pcmcia_socket *);
        int (*show_timing)(struct soc_pcmcia_socket *, char *);
+
+#ifdef CONFIG_CPU_FREQ
+       /*
+        * CPUFREQ support.
+        */
+       int (*frequency_change)(struct soc_pcmcia_socket *, unsigned long, struct cpufreq_freqs *);
+#endif
 };