public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] PPC32: Update pmac_cpufreq driver back to working conditions
@ 2003-07-29 13:16 Benjamin Herrenschmidt
  0 siblings, 0 replies; only message in thread
From: Benjamin Herrenschmidt @ 2003-07-29 13:16 UTC (permalink / raw)
  To: Linus Torvalds; +Cc: linux-kernel mailing list

This patch updates the PowerMac cpufreq driver so that
it builds & works in current 2.6

Please apply,
Ben.

diff -urN linux-2.5/arch/ppc/platforms/pmac_cpufreq.c linuxppc-2.5-benh/arch/ppc/platforms/pmac_cpufreq.c
--- linux-2.5/arch/ppc/platforms/pmac_cpufreq.c	2003-07-29 08:50:25.000000000 -0400
+++ linuxppc-2.5-benh/arch/ppc/platforms/pmac_cpufreq.c	2003-07-23 20:04:23.000000000 -0400
@@ -1,4 +1,16 @@
+/*
+ *  arch/ppc/platforms/pmac_cpufreq.c
+ *
+ *  Copyright (C) 2002 - 2003 Benjamin Herrenschmidt <benh@kernel.crashing.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+ *
+ */
+
 #include <linux/config.h>
+#include <linux/module.h>
 #include <linux/types.h>
 #include <linux/errno.h>
 #include <linux/kernel.h>
@@ -36,6 +48,18 @@
 #define PMAC_CPU_LOW_SPEED	1
 #define PMAC_CPU_HIGH_SPEED	0
 
+/* There are only two frequency states for each processor. Values
+ * are in kHz for the time being.
+ */
+#define CPUFREQ_HIGH                  PMAC_CPU_HIGH_SPEED
+#define CPUFREQ_LOW                   PMAC_CPU_LOW_SPEED
+
+static struct cpufreq_frequency_table pmac_cpu_freqs[] = {
+	{CPUFREQ_HIGH, 		0},
+	{CPUFREQ_LOW,		0},
+	{0,			CPUFREQ_TABLE_END},
+};
+
 static inline void
 wakeup_decrementer(void)
 {
@@ -192,37 +216,21 @@
 static int __pmac
 pmac_cpufreq_verify(struct cpufreq_policy *policy)
 {
-	if (!policy)
-		return -EINVAL;
-		
-	policy->cpu = 0; /* UP only */
-
-	cpufreq_verify_within_limits(policy, low_freq, hi_freq);
-
-	if ((policy->min > low_freq) && 
-	    (policy->max < hi_freq))
-		policy->max = hi_freq;
-
-	return 0;
+	return cpufreq_frequency_table_verify(policy, pmac_cpu_freqs);
 }
 
 static int __pmac
-pmac_cpufreq_setpolicy(struct cpufreq_policy *policy)
+pmac_cpufreq_target(	struct cpufreq_policy *policy,
+			unsigned int target_freq,
+			unsigned int relation)
 {
-	int rc;
-	
-	if (!policy)
+	unsigned int    newstate = 0;
+
+	if (cpufreq_frequency_table_target(policy, pmac_cpu_freqs,
+			target_freq, relation, &newstate))
 		return -EINVAL;
-	if (policy->min > low_freq)
-		rc = do_set_cpu_speed(PMAC_CPU_HIGH_SPEED);
-	else if (policy->max < hi_freq)
-		rc = do_set_cpu_speed(PMAC_CPU_LOW_SPEED);
-	else if (policy->policy == CPUFREQ_POLICY_POWERSAVE)
-		rc = do_set_cpu_speed(PMAC_CPU_LOW_SPEED);
-	else
-		rc = do_set_cpu_speed(PMAC_CPU_HIGH_SPEED);
 
-	return rc;
+	return do_set_cpu_speed(newstate);
 }
 
 unsigned int __pmac
@@ -232,6 +240,27 @@
 	return (i == 0) ? cur_freq : 0;
 }
 
+static int __pmac
+pmac_cpufreq_cpu_init(struct cpufreq_policy *policy)
+{
+	if (policy->cpu != 0)
+		return -ENODEV;
+
+	policy->policy = (cur_freq == low_freq) ? 
+		CPUFREQ_POLICY_POWERSAVE : CPUFREQ_POLICY_PERFORMANCE;
+	policy->cpuinfo.transition_latency	= CPUFREQ_ETERNAL;
+	policy->cur = cur_freq;
+
+	return cpufreq_frequency_table_cpuinfo(policy, &pmac_cpu_freqs[0]);
+}
+
+static struct cpufreq_driver pmac_cpufreq_driver = {
+	.verify 	= pmac_cpufreq_verify,
+	.target 	= pmac_cpufreq_target,
+	.init		= pmac_cpufreq_cpu_init,
+	.name		= "powermac",
+	.owner		= THIS_MODULE,
+};
 
 /* Currently, we support the following machines:
  * 
@@ -244,13 +273,9 @@
 pmac_cpufreq_setup(void)
 {	
 	struct device_node	*cpunode;
-	struct cpufreq_driver   *driver;
 	u32			*value;
 	int			has_freq_ctl = 0;
-	int			rc;
 	
-	memset(&driver, 0, sizeof(driver));
-
 	/* Assume only one CPU */
 	cpunode = find_type_devices("cpu");
 	if (!cpunode)
@@ -318,34 +343,11 @@
 	if (!has_freq_ctl)
 		return -ENODEV;
 	
-	/* initialization of main "cpufreq" code*/
-	driver = kmalloc(sizeof(struct cpufreq_driver) + 
-			 NR_CPUS * sizeof(struct cpufreq_policy), GFP_KERNEL);
-	if (!driver)
-		return -ENOMEM;
-
-	driver->policy = (struct cpufreq_policy *) (driver + 1);
-
-	driver->verify		= &pmac_cpufreq_verify;
-	driver->setpolicy	= &pmac_cpufreq_setpolicy;
-	driver->init		= NULL;
-	driver->exit		= NULL;
-	strlcpy(driver->name, "powermac", sizeof(driver->name));
-
-	driver->policy[0].cpu				= 0;
-	driver->policy[0].cpuinfo.transition_latency	= CPUFREQ_ETERNAL;
-	driver->policy[0].cpuinfo.min_freq		= low_freq;
-	driver->policy[0].min				= low_freq;
-	driver->policy[0].max				= cur_freq;
-	driver->policy[0].cpuinfo.max_freq		= cur_freq;
-	driver->policy[0].policy			= (cur_freq == low_freq) ? 
-	    	CPUFREQ_POLICY_POWERSAVE : CPUFREQ_POLICY_PERFORMANCE;
-
-	rc = cpufreq_register_driver(driver);
-	if (rc)
-		kfree(driver);
-	return rc;
+	pmac_cpu_freqs[CPUFREQ_LOW].frequency = low_freq;
+	pmac_cpu_freqs[CPUFREQ_HIGH].frequency = hi_freq;
+
+	return cpufreq_register_driver(&pmac_cpufreq_driver);
 }
 
-__initcall(pmac_cpufreq_setup);
+module_init(pmac_cpufreq_setup);
 


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2003-07-29 13:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2003-07-29 13:16 [PATCH] PPC32: Update pmac_cpufreq driver back to working conditions Benjamin Herrenschmidt

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox