1 #include <linux/types.h>
2 #include <linux/errno.h>
3 #include <linux/kernel.h>
4 #include <linux/delay.h>
5 #include <linux/slab.h>
6 #include <linux/init.h>
7 #include <linux/wait.h>
8 #include <linux/cpufreq.h>
17 static struct wf_control
*clamp_control
;
19 static int clamp_notifier_call(struct notifier_block
*self
,
20 unsigned long event
, void *data
)
22 struct cpufreq_policy
*p
= data
;
23 unsigned long max_freq
;
25 if (event
!= CPUFREQ_ADJUST
)
28 max_freq
= clamped
? (p
->cpuinfo
.min_freq
) : (p
->cpuinfo
.max_freq
);
29 cpufreq_verify_within_limits(p
, 0, max_freq
);
34 static struct notifier_block clamp_notifier
= {
35 .notifier_call
= clamp_notifier_call
,
38 static int clamp_set(struct wf_control
*ct
, s32 value
)
41 printk(KERN_INFO
"windfarm: Clamping CPU frequency to "
44 printk(KERN_INFO
"windfarm: CPU frequency unclamped !\n");
46 cpufreq_update_policy(0);
50 static int clamp_get(struct wf_control
*ct
, s32
*value
)
56 static s32
clamp_min(struct wf_control
*ct
)
61 static s32
clamp_max(struct wf_control
*ct
)
66 static const struct wf_control_ops clamp_ops
= {
67 .set_value
= clamp_set
,
68 .get_value
= clamp_get
,
74 static int __init
wf_cpufreq_clamp_init(void)
76 struct wf_control
*clamp
;
78 clamp
= kmalloc(sizeof(struct wf_control
), GFP_KERNEL
);
81 cpufreq_register_notifier(&clamp_notifier
, CPUFREQ_POLICY_NOTIFIER
);
82 clamp
->ops
= &clamp_ops
;
83 clamp
->name
= "cpufreq-clamp";
84 if (wf_register_control(clamp
))
86 clamp_control
= clamp
;
93 static void __exit
wf_cpufreq_clamp_exit(void)
96 wf_unregister_control(clamp_control
);
100 module_init(wf_cpufreq_clamp_init
);
101 module_exit(wf_cpufreq_clamp_exit
);
103 MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
104 MODULE_DESCRIPTION("CPU frequency clamp for PowerMacs thermal control");
105 MODULE_LICENSE("GPL");