Linux 2.6.17.7
[linux/fpc-iii.git] / drivers / macintosh / windfarm_cpufreq_clamp.c
blob81337cd16e80d1fc80f87ee17fb82aa88a03d00f
1 #include <linux/config.h>
2 #include <linux/types.h>
3 #include <linux/errno.h>
4 #include <linux/kernel.h>
5 #include <linux/delay.h>
6 #include <linux/slab.h>
7 #include <linux/init.h>
8 #include <linux/wait.h>
9 #include <linux/cpufreq.h>
11 #include <asm/prom.h>
13 #include "windfarm.h"
15 #define VERSION "0.3"
17 static int clamped;
18 static struct wf_control *clamp_control;
20 static int clamp_notifier_call(struct notifier_block *self,
21 unsigned long event, void *data)
23 struct cpufreq_policy *p = data;
24 unsigned long max_freq;
26 if (event != CPUFREQ_ADJUST)
27 return 0;
29 max_freq = clamped ? (p->cpuinfo.min_freq) : (p->cpuinfo.max_freq);
30 cpufreq_verify_within_limits(p, 0, max_freq);
32 return 0;
35 static struct notifier_block clamp_notifier = {
36 .notifier_call = clamp_notifier_call,
39 static int clamp_set(struct wf_control *ct, s32 value)
41 if (value)
42 printk(KERN_INFO "windfarm: Clamping CPU frequency to "
43 "minimum !\n");
44 else
45 printk(KERN_INFO "windfarm: CPU frequency unclamped !\n");
46 clamped = value;
47 cpufreq_update_policy(0);
48 return 0;
51 static int clamp_get(struct wf_control *ct, s32 *value)
53 *value = clamped;
54 return 0;
57 static s32 clamp_min(struct wf_control *ct)
59 return 0;
62 static s32 clamp_max(struct wf_control *ct)
64 return 1;
67 static struct wf_control_ops clamp_ops = {
68 .set_value = clamp_set,
69 .get_value = clamp_get,
70 .get_min = clamp_min,
71 .get_max = clamp_max,
72 .owner = THIS_MODULE,
75 static int __init wf_cpufreq_clamp_init(void)
77 struct wf_control *clamp;
79 /* Don't register on old machines that use therm_pm72 for now */
80 if (machine_is_compatible("PowerMac7,2") ||
81 machine_is_compatible("PowerMac7,3") ||
82 machine_is_compatible("RackMac3,1"))
83 return -ENODEV;
85 clamp = kmalloc(sizeof(struct wf_control), GFP_KERNEL);
86 if (clamp == NULL)
87 return -ENOMEM;
88 cpufreq_register_notifier(&clamp_notifier, CPUFREQ_POLICY_NOTIFIER);
89 clamp->ops = &clamp_ops;
90 clamp->name = "cpufreq-clamp";
91 if (wf_register_control(clamp))
92 goto fail;
93 clamp_control = clamp;
94 return 0;
95 fail:
96 kfree(clamp);
97 return -ENODEV;
100 static void __exit wf_cpufreq_clamp_exit(void)
102 if (clamp_control)
103 wf_unregister_control(clamp_control);
107 module_init(wf_cpufreq_clamp_init);
108 module_exit(wf_cpufreq_clamp_exit);
110 MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
111 MODULE_DESCRIPTION("CPU frequency clamp for PowerMacs thermal control");
112 MODULE_LICENSE("GPL");