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>
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)
29 max_freq = clamped ? (p->cpuinfo.min_freq) : (p->cpuinfo.max_freq);
30 cpufreq_verify_within_limits(p, 0, max_freq);
35 static struct notifier_block clamp_notifier = {
36 .notifier_call = clamp_notifier_call,
39 static int clamp_set(struct wf_control *ct, s32 value)
42 printk(KERN_INFO "windfarm: Clamping CPU frequency to "
45 printk(KERN_INFO "windfarm: CPU frequency unclamped !\n");
47 cpufreq_update_policy(0);
51 static int clamp_get(struct wf_control *ct, s32 *value)
57 static s32 clamp_min(struct wf_control *ct)
62 static s32 clamp_max(struct wf_control *ct)
67 static struct wf_control_ops clamp_ops = {
68 .set_value = clamp_set,
69 .get_value = clamp_get,
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"))
85 clamp = kmalloc(sizeof(struct wf_control), GFP_KERNEL);
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))
93 clamp_control = clamp;
100 static void __exit wf_cpufreq_clamp_exit(void)
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");