drm/connector: make mode_valid take a const struct drm_display_mode
[drm/drm-misc.git] / drivers / cpufreq / ppc_cbe_cpufreq_pmi.c
blob6f0c32592416ded9864ec397dac527de954fc1fc
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * pmi backend for the cbe_cpufreq driver
5 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005-2007
7 * Author: Christian Krafft <krafft@de.ibm.com>
8 */
10 #include <linux/kernel.h>
11 #include <linux/types.h>
12 #include <linux/timer.h>
13 #include <linux/init.h>
14 #include <linux/pm_qos.h>
15 #include <linux/slab.h>
17 #include <asm/processor.h>
18 #include <asm/pmi.h>
19 #include <asm/cell-regs.h>
21 #ifdef DEBUG
22 #include <asm/time.h>
23 #endif
25 #include "ppc_cbe_cpufreq.h"
27 bool cbe_cpufreq_has_pmi = false;
28 EXPORT_SYMBOL_GPL(cbe_cpufreq_has_pmi);
31 * hardware specific functions
34 int cbe_cpufreq_set_pmode_pmi(int cpu, unsigned int pmode)
36 int ret;
37 pmi_message_t pmi_msg;
38 #ifdef DEBUG
39 long time;
40 #endif
41 pmi_msg.type = PMI_TYPE_FREQ_CHANGE;
42 pmi_msg.data1 = cbe_cpu_to_node(cpu);
43 pmi_msg.data2 = pmode;
45 #ifdef DEBUG
46 time = jiffies;
47 #endif
48 pmi_send_message(pmi_msg);
50 #ifdef DEBUG
51 time = jiffies - time;
52 time = jiffies_to_msecs(time);
53 pr_debug("had to wait %lu ms for a transition using " \
54 "PMI\n", time);
55 #endif
56 ret = pmi_msg.data2;
57 pr_debug("PMI returned slow mode %d\n", ret);
59 return ret;
61 EXPORT_SYMBOL_GPL(cbe_cpufreq_set_pmode_pmi);
64 static void cbe_cpufreq_handle_pmi(pmi_message_t pmi_msg)
66 struct cpufreq_policy *policy;
67 struct freq_qos_request *req;
68 u8 node, slow_mode;
69 int cpu, ret;
71 BUG_ON(pmi_msg.type != PMI_TYPE_FREQ_CHANGE);
73 node = pmi_msg.data1;
74 slow_mode = pmi_msg.data2;
76 cpu = cbe_node_to_cpu(node);
78 pr_debug("cbe_handle_pmi: node: %d max_freq: %d\n", node, slow_mode);
80 policy = cpufreq_cpu_get(cpu);
81 if (!policy) {
82 pr_warn("cpufreq policy not found cpu%d\n", cpu);
83 return;
86 req = policy->driver_data;
88 ret = freq_qos_update_request(req,
89 policy->freq_table[slow_mode].frequency);
90 if (ret < 0)
91 pr_warn("Failed to update freq constraint: %d\n", ret);
92 else
93 pr_debug("limiting node %d to slow mode %d\n", node, slow_mode);
95 cpufreq_cpu_put(policy);
98 static struct pmi_handler cbe_pmi_handler = {
99 .type = PMI_TYPE_FREQ_CHANGE,
100 .handle_pmi_message = cbe_cpufreq_handle_pmi,
103 void cbe_cpufreq_pmi_policy_init(struct cpufreq_policy *policy)
105 struct freq_qos_request *req;
106 int ret;
108 if (!cbe_cpufreq_has_pmi)
109 return;
111 req = kzalloc(sizeof(*req), GFP_KERNEL);
112 if (!req)
113 return;
115 ret = freq_qos_add_request(&policy->constraints, req, FREQ_QOS_MAX,
116 policy->freq_table[0].frequency);
117 if (ret < 0) {
118 pr_err("Failed to add freq constraint (%d)\n", ret);
119 kfree(req);
120 return;
123 policy->driver_data = req;
125 EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_policy_init);
127 void cbe_cpufreq_pmi_policy_exit(struct cpufreq_policy *policy)
129 struct freq_qos_request *req = policy->driver_data;
131 if (cbe_cpufreq_has_pmi) {
132 freq_qos_remove_request(req);
133 kfree(req);
136 EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_policy_exit);
138 void cbe_cpufreq_pmi_init(void)
140 if (!pmi_register_handler(&cbe_pmi_handler))
141 cbe_cpufreq_has_pmi = true;
143 EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_init);
145 void cbe_cpufreq_pmi_exit(void)
147 pmi_unregister_handler(&cbe_pmi_handler);
148 cbe_cpufreq_has_pmi = false;
150 EXPORT_SYMBOL_GPL(cbe_cpufreq_pmi_exit);