Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cpufreq: powerpc: macintosh: Switch to QoS requests for freq limits

The cpufreq core now takes the min/max frequency constraints via QoS
requests and the CPUFREQ_ADJUST notifier shall get removed later on.

Switch over to using the QoS request for maximum frequency constraint
for windfarm_cpufreq_clamp driver.

Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org>
[ rjw: Subject ]
Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>

authored by

Viresh Kumar and committed by
Rafael J. Wysocki
dce2e3a8 5130802d

+50 -27
+50 -27
drivers/macintosh/windfarm_cpufreq_clamp.c
··· 3 3 #include <linux/errno.h> 4 4 #include <linux/kernel.h> 5 5 #include <linux/delay.h> 6 + #include <linux/pm_qos.h> 6 7 #include <linux/slab.h> 7 8 #include <linux/init.h> 8 9 #include <linux/wait.h> 10 + #include <linux/cpu.h> 9 11 #include <linux/cpufreq.h> 10 12 11 13 #include <asm/prom.h> ··· 18 16 19 17 static int clamped; 20 18 static struct wf_control *clamp_control; 21 - 22 - static int clamp_notifier_call(struct notifier_block *self, 23 - unsigned long event, void *data) 24 - { 25 - struct cpufreq_policy *p = data; 26 - unsigned long max_freq; 27 - 28 - if (event != CPUFREQ_ADJUST) 29 - return 0; 30 - 31 - max_freq = clamped ? (p->cpuinfo.min_freq) : (p->cpuinfo.max_freq); 32 - cpufreq_verify_within_limits(p, 0, max_freq); 33 - 34 - return 0; 35 - } 36 - 37 - static struct notifier_block clamp_notifier = { 38 - .notifier_call = clamp_notifier_call, 39 - }; 19 + static struct dev_pm_qos_request qos_req; 20 + static unsigned int min_freq, max_freq; 40 21 41 22 static int clamp_set(struct wf_control *ct, s32 value) 42 23 { 43 - if (value) 24 + unsigned int freq; 25 + 26 + if (value) { 27 + freq = min_freq; 44 28 printk(KERN_INFO "windfarm: Clamping CPU frequency to " 45 29 "minimum !\n"); 46 - else 30 + } else { 31 + freq = max_freq; 47 32 printk(KERN_INFO "windfarm: CPU frequency unclamped !\n"); 33 + } 48 34 clamped = value; 49 - cpufreq_update_policy(0); 50 - return 0; 35 + 36 + return dev_pm_qos_update_request(&qos_req, freq); 51 37 } 52 38 53 39 static int clamp_get(struct wf_control *ct, s32 *value) ··· 64 74 65 75 static int __init wf_cpufreq_clamp_init(void) 66 76 { 77 + struct cpufreq_policy *policy; 67 78 struct wf_control *clamp; 79 + struct device *dev; 80 + int ret; 81 + 82 + policy = cpufreq_cpu_get(0); 83 + if (!policy) { 84 + pr_warn("%s: cpufreq policy not found cpu0\n", __func__); 85 + return -EPROBE_DEFER; 86 + } 87 + 88 + min_freq = policy->cpuinfo.min_freq; 89 + max_freq = policy->cpuinfo.max_freq; 90 + cpufreq_cpu_put(policy); 91 + 92 + dev = get_cpu_device(0); 93 + if (unlikely(!dev)) { 94 + pr_warn("%s: No cpu device for cpu0\n", __func__); 95 + return -ENODEV; 96 + } 68 97 69 98 clamp = kmalloc(sizeof(struct wf_control), GFP_KERNEL); 70 99 if (clamp == NULL) 71 100 return -ENOMEM; 72 - cpufreq_register_notifier(&clamp_notifier, CPUFREQ_POLICY_NOTIFIER); 101 + 102 + ret = dev_pm_qos_add_request(dev, &qos_req, DEV_PM_QOS_MAX_FREQUENCY, 103 + max_freq); 104 + if (ret < 0) { 105 + pr_err("%s: Failed to add freq constraint (%d)\n", __func__, 106 + ret); 107 + goto free; 108 + } 109 + 73 110 clamp->ops = &clamp_ops; 74 111 clamp->name = "cpufreq-clamp"; 75 - if (wf_register_control(clamp)) 112 + ret = wf_register_control(clamp); 113 + if (ret) 76 114 goto fail; 77 115 clamp_control = clamp; 78 116 return 0; 79 117 fail: 118 + dev_pm_qos_remove_request(&qos_req); 119 + 120 + free: 80 121 kfree(clamp); 81 - return -ENODEV; 122 + return ret; 82 123 } 83 124 84 125 static void __exit wf_cpufreq_clamp_exit(void) 85 126 { 86 - if (clamp_control) 127 + if (clamp_control) { 87 128 wf_unregister_control(clamp_control); 129 + dev_pm_qos_remove_request(&qos_req); 130 + } 88 131 } 89 132 90 133