blob: 97c8ee4614b7d408eca9116d3f76704e31b34978 [file] [log] [blame]
Thomas Gleixnerde6cc652019-05-27 08:55:02 +02001// SPDX-License-Identifier: GPL-2.0-or-later
Christian Krafft74889e42007-07-20 21:39:22 +02002/*
3 * pmi backend for the cbe_cpufreq driver
4 *
5 * (C) Copyright IBM Deutschland Entwicklung GmbH 2005-2007
6 *
7 * Author: Christian Krafft <krafft@de.ibm.com>
Christian Krafft74889e42007-07-20 21:39:22 +02008 */
9
10#include <linux/kernel.h>
11#include <linux/types.h>
12#include <linux/timer.h>
Paul Gortmakerdbbe9722016-03-27 18:08:17 -040013#include <linux/init.h>
Jon Loeligerd8caf742007-11-13 11:10:58 -060014#include <linux/of_platform.h>
15
Christian Krafft74889e42007-07-20 21:39:22 +020016#include <asm/processor.h>
17#include <asm/prom.h>
18#include <asm/pmi.h>
Benjamin Herrenschmidteef686a02007-10-04 15:40:42 +100019#include <asm/cell-regs.h>
Christian Krafft74889e42007-07-20 21:39:22 +020020
21#ifdef DEBUG
22#include <asm/time.h>
23#endif
24
Viresh Kumar6eb1c372013-03-25 11:20:23 +053025#include "ppc_cbe_cpufreq.h"
Christian Krafft74889e42007-07-20 21:39:22 +020026
27static u8 pmi_slow_mode_limit[MAX_CBE];
28
29bool cbe_cpufreq_has_pmi = false;
30EXPORT_SYMBOL_GPL(cbe_cpufreq_has_pmi);
31
32/*
33 * hardware specific functions
34 */
35
36int cbe_cpufreq_set_pmode_pmi(int cpu, unsigned int pmode)
37{
38 int ret;
39 pmi_message_t pmi_msg;
40#ifdef DEBUG
41 long time;
42#endif
43 pmi_msg.type = PMI_TYPE_FREQ_CHANGE;
44 pmi_msg.data1 = cbe_cpu_to_node(cpu);
45 pmi_msg.data2 = pmode;
46
47#ifdef DEBUG
48 time = jiffies;
49#endif
50 pmi_send_message(pmi_msg);
51
52#ifdef DEBUG
53 time = jiffies - time;
54 time = jiffies_to_msecs(time);
55 pr_debug("had to wait %lu ms for a transition using " \
56 "PMI\n", time);
57#endif
58 ret = pmi_msg.data2;
59 pr_debug("PMI returned slow mode %d\n", ret);
60
61 return ret;
62}
63EXPORT_SYMBOL_GPL(cbe_cpufreq_set_pmode_pmi);
64
65
66static void cbe_cpufreq_handle_pmi(pmi_message_t pmi_msg)
67{
68 u8 node, slow_mode;
69
70 BUG_ON(pmi_msg.type != PMI_TYPE_FREQ_CHANGE);
71
72 node = pmi_msg.data1;
73 slow_mode = pmi_msg.data2;
74
75 pmi_slow_mode_limit[node] = slow_mode;
76
77 pr_debug("cbe_handle_pmi: node: %d max_freq: %d\n", node, slow_mode);
78}
79
80static int pmi_notifier(struct notifier_block *nb,
81 unsigned long event, void *data)
82{
83 struct cpufreq_policy *policy = data;
Viresh Kumarf8bfc112016-06-03 10:58:47 +053084 struct cpufreq_frequency_table *cbe_freqs = policy->freq_table;
Christian Krafft74889e42007-07-20 21:39:22 +020085 u8 node;
86
Viresh Kumar6bfb7c72015-08-03 08:36:14 +053087 /* Should this really be called for CPUFREQ_ADJUST and CPUFREQ_NOTIFY
88 * policy events?)
Thomas Renningera1531ac2008-07-29 22:32:58 -070089 */
Christian Krafft74889e42007-07-20 21:39:22 +020090 node = cbe_cpu_to_node(policy->cpu);
91
92 pr_debug("got notified, event=%lu, node=%u\n", event, node);
93
94 if (pmi_slow_mode_limit[node] != 0) {
95 pr_debug("limiting node %d to slow mode %d\n",
96 node, pmi_slow_mode_limit[node]);
97
98 cpufreq_verify_within_limits(policy, 0,
99
100 cbe_freqs[pmi_slow_mode_limit[node]].frequency);
101 }
102
103 return 0;
104}
105
106static struct notifier_block pmi_notifier_block = {
107 .notifier_call = pmi_notifier,
108};
109
110static struct pmi_handler cbe_pmi_handler = {
111 .type = PMI_TYPE_FREQ_CHANGE,
112 .handle_pmi_message = cbe_cpufreq_handle_pmi,
113};
114
115
116
117static int __init cbe_cpufreq_pmi_init(void)
118{
119 cbe_cpufreq_has_pmi = pmi_register_handler(&cbe_pmi_handler) == 0;
120
121 if (!cbe_cpufreq_has_pmi)
122 return -ENODEV;
123
124 cpufreq_register_notifier(&pmi_notifier_block, CPUFREQ_POLICY_NOTIFIER);
125
126 return 0;
127}
Paul Gortmakerdbbe9722016-03-27 18:08:17 -0400128device_initcall(cbe_cpufreq_pmi_init);