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>
16 static struct wf_control *clamp_control;
18 static int clamp_notifier_call(struct notifier_block *self,
19 unsigned long event, void *data)
21 struct cpufreq_policy *p = data;
22 unsigned long max_freq;
24 if (event != CPUFREQ_ADJUST)
27 max_freq = clamped ? (p->cpuinfo.min_freq) : (p->cpuinfo.max_freq);
28 cpufreq_verify_within_limits(p, 0, max_freq);
33 static struct notifier_block clamp_notifier = {
34 .notifier_call = clamp_notifier_call,
37 static int clamp_set(struct wf_control *ct, s32 value)
40 printk(KERN_INFO "windfarm: Clamping CPU frequency to "
43 printk(KERN_INFO "windfarm: CPU frequency unclamped !\n");
45 cpufreq_update_policy(0);
49 static int clamp_get(struct wf_control *ct, s32 *value)
55 static s32 clamp_min(struct wf_control *ct)
60 static s32 clamp_max(struct wf_control *ct)
65 static struct wf_control_ops clamp_ops = {
66 .set_value = clamp_set,
67 .get_value = clamp_get,
73 static int __init wf_cpufreq_clamp_init(void)
75 struct wf_control *clamp;
77 clamp = kmalloc(sizeof(struct wf_control), GFP_KERNEL);
80 cpufreq_register_notifier(&clamp_notifier, CPUFREQ_POLICY_NOTIFIER);
81 clamp->ops = &clamp_ops;
82 clamp->name = "cpufreq-clamp";
83 if (wf_register_control(clamp))
85 clamp_control = clamp;
92 static void __exit wf_cpufreq_clamp_exit(void)
95 wf_unregister_control(clamp_control);
99 module_init(wf_cpufreq_clamp_init);
100 module_exit(wf_cpufreq_clamp_exit);
102 MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
103 MODULE_DESCRIPTION("CPU frequency clamp for PowerMacs thermal control");
104 MODULE_LICENSE("GPL");