1 // SPDX-License-Identifier: GPL-2.0-only
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 const 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 clamp
= kmalloc(sizeof(struct wf_control
), GFP_KERNEL
);
82 cpufreq_register_notifier(&clamp_notifier
, CPUFREQ_POLICY_NOTIFIER
);
83 clamp
->ops
= &clamp_ops
;
84 clamp
->name
= "cpufreq-clamp";
85 if (wf_register_control(clamp
))
87 clamp_control
= clamp
;
94 static void __exit
wf_cpufreq_clamp_exit(void)
97 wf_unregister_control(clamp_control
);
101 module_init(wf_cpufreq_clamp_init
);
102 module_exit(wf_cpufreq_clamp_exit
);
104 MODULE_AUTHOR("Benjamin Herrenschmidt <benh@kernel.crashing.org>");
105 MODULE_DESCRIPTION("CPU frequency clamp for PowerMacs thermal control");
106 MODULE_LICENSE("GPL");