Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 1 | /* |
| 2 | * cpufreq driver for the cell processor |
| 3 | * |
| 4 | * (C) Copyright IBM Deutschland Entwicklung GmbH 2005 |
| 5 | * |
| 6 | * Author: Christian Krafft <krafft@de.ibm.com> |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2, or (at your option) |
| 11 | * any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License |
| 19 | * along with this program; if not, write to the Free Software |
| 20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <linux/cpufreq.h> |
| 24 | #include <linux/timer.h> |
| 25 | |
| 26 | #include <asm/hw_irq.h> |
| 27 | #include <asm/io.h> |
Olof Johansson | 4bd4aa1 | 2007-04-28 12:49:03 +1000 | [diff] [blame] | 28 | #include <asm/machdep.h> |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 29 | #include <asm/processor.h> |
| 30 | #include <asm/prom.h> |
| 31 | #include <asm/time.h> |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 32 | #include <asm/pmi.h> |
| 33 | #include <asm/of_platform.h> |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 34 | |
| 35 | #include "cbe_regs.h" |
| 36 | |
| 37 | static DEFINE_MUTEX(cbe_switch_mutex); |
| 38 | |
| 39 | |
| 40 | /* the CBE supports an 8 step frequency scaling */ |
| 41 | static struct cpufreq_frequency_table cbe_freqs[] = { |
| 42 | {1, 0}, |
| 43 | {2, 0}, |
| 44 | {3, 0}, |
| 45 | {4, 0}, |
| 46 | {5, 0}, |
| 47 | {6, 0}, |
| 48 | {8, 0}, |
| 49 | {10, 0}, |
| 50 | {0, CPUFREQ_TABLE_END}, |
| 51 | }; |
| 52 | |
| 53 | /* to write to MIC register */ |
| 54 | static u64 MIC_Slow_Fast_Timer_table[] = { |
| 55 | [0 ... 7] = 0x007fc00000000000ull, |
| 56 | }; |
| 57 | |
| 58 | /* more values for the MIC */ |
| 59 | static u64 MIC_Slow_Next_Timer_table[] = { |
| 60 | 0x0000240000000000ull, |
| 61 | 0x0000268000000000ull, |
| 62 | 0x000029C000000000ull, |
| 63 | 0x00002D0000000000ull, |
| 64 | 0x0000300000000000ull, |
| 65 | 0x0000334000000000ull, |
| 66 | 0x000039C000000000ull, |
| 67 | 0x00003FC000000000ull, |
| 68 | }; |
| 69 | |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 70 | static u8 pmi_slow_mode_limit[MAX_BE]; |
Christian Krafft | 813f907 | 2007-07-20 21:39:18 +0200 | [diff] [blame] | 71 | |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 72 | /* |
| 73 | * hardware specific functions |
| 74 | */ |
| 75 | |
Christian Krafft | 813f907 | 2007-07-20 21:39:18 +0200 | [diff] [blame] | 76 | static bool cbe_cpufreq_has_pmi; |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 77 | |
Christian Krafft | ee5d1b7 | 2007-06-28 21:14:38 +1000 | [diff] [blame] | 78 | #ifdef CONFIG_PPC_PMI |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 79 | static int set_pmode_pmi(int cpu, unsigned int pmode) |
| 80 | { |
| 81 | int ret; |
| 82 | pmi_message_t pmi_msg; |
| 83 | #ifdef DEBUG |
Christian Krafft | a964b9b | 2007-07-20 21:39:19 +0200 | [diff] [blame] | 84 | long time; |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 85 | #endif |
| 86 | |
| 87 | pmi_msg.type = PMI_TYPE_FREQ_CHANGE; |
| 88 | pmi_msg.data1 = cbe_cpu_to_node(cpu); |
| 89 | pmi_msg.data2 = pmode; |
| 90 | |
| 91 | #ifdef DEBUG |
Christian Krafft | a964b9b | 2007-07-20 21:39:19 +0200 | [diff] [blame] | 92 | time = jiffies; |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 93 | #endif |
| 94 | |
Christian Krafft | 813f907 | 2007-07-20 21:39:18 +0200 | [diff] [blame] | 95 | pmi_send_message(pmi_msg); |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 96 | ret = pmi_msg.data2; |
| 97 | |
| 98 | pr_debug("PMI returned slow mode %d\n", ret); |
| 99 | |
| 100 | #ifdef DEBUG |
Christian Krafft | a964b9b | 2007-07-20 21:39:19 +0200 | [diff] [blame] | 101 | time = jiffies - time; /* actual cycles (not cpu cycles!) */ |
| 102 | time = jiffies_to_msecs(time); |
| 103 | pr_debug("had to wait %lu ms for a transition using PMI.\n", time); |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 104 | #endif |
| 105 | return ret; |
| 106 | } |
Christian Krafft | ee5d1b7 | 2007-06-28 21:14:38 +1000 | [diff] [blame] | 107 | #endif |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 108 | |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 109 | static int get_pmode(int cpu) |
| 110 | { |
| 111 | int ret; |
| 112 | struct cbe_pmd_regs __iomem *pmd_regs; |
| 113 | |
| 114 | pmd_regs = cbe_get_cpu_pmd_regs(cpu); |
| 115 | ret = in_be64(&pmd_regs->pmsr) & 0x07; |
| 116 | |
| 117 | return ret; |
| 118 | } |
| 119 | |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 120 | static int set_pmode_reg(int cpu, unsigned int pmode) |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 121 | { |
| 122 | struct cbe_pmd_regs __iomem *pmd_regs; |
| 123 | struct cbe_mic_tm_regs __iomem *mic_tm_regs; |
| 124 | u64 flags; |
| 125 | u64 value; |
Christian Krafft | a964b9b | 2007-07-20 21:39:19 +0200 | [diff] [blame] | 126 | #ifdef DEBUG |
| 127 | long time; |
| 128 | #endif |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 129 | |
| 130 | local_irq_save(flags); |
| 131 | |
| 132 | mic_tm_regs = cbe_get_cpu_mic_tm_regs(cpu); |
| 133 | pmd_regs = cbe_get_cpu_pmd_regs(cpu); |
| 134 | |
Christian Krafft | a964b9b | 2007-07-20 21:39:19 +0200 | [diff] [blame] | 135 | #ifdef DEBUG |
| 136 | time = jiffies; |
| 137 | #endif |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 138 | out_be64(&mic_tm_regs->slow_fast_timer_0, MIC_Slow_Fast_Timer_table[pmode]); |
| 139 | out_be64(&mic_tm_regs->slow_fast_timer_1, MIC_Slow_Fast_Timer_table[pmode]); |
| 140 | |
| 141 | out_be64(&mic_tm_regs->slow_next_timer_0, MIC_Slow_Next_Timer_table[pmode]); |
| 142 | out_be64(&mic_tm_regs->slow_next_timer_1, MIC_Slow_Next_Timer_table[pmode]); |
| 143 | |
| 144 | value = in_be64(&pmd_regs->pmcr); |
| 145 | /* set bits to zero */ |
| 146 | value &= 0xFFFFFFFFFFFFFFF8ull; |
| 147 | /* set bits to next pmode */ |
| 148 | value |= pmode; |
| 149 | |
| 150 | out_be64(&pmd_regs->pmcr, value); |
| 151 | |
Christian Krafft | a964b9b | 2007-07-20 21:39:19 +0200 | [diff] [blame] | 152 | #ifdef DEBUG |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 153 | /* wait until new pmode appears in status register */ |
| 154 | value = in_be64(&pmd_regs->pmsr) & 0x07; |
| 155 | while(value != pmode) { |
| 156 | cpu_relax(); |
| 157 | value = in_be64(&pmd_regs->pmsr) & 0x07; |
| 158 | } |
| 159 | |
Christian Krafft | a964b9b | 2007-07-20 21:39:19 +0200 | [diff] [blame] | 160 | time = jiffies - time; |
| 161 | time = jiffies_to_msecs(time); |
| 162 | pr_debug("had to wait %lu ms for a transition using " \ |
| 163 | "the pervasive unit.\n", time); |
| 164 | #endif |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 165 | local_irq_restore(flags); |
| 166 | |
| 167 | return 0; |
| 168 | } |
| 169 | |
Christian Krafft | 813f907 | 2007-07-20 21:39:18 +0200 | [diff] [blame] | 170 | static int set_pmode(int cpu, unsigned int slow_mode) |
| 171 | { |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 172 | int rc; |
Christian Krafft | ee5d1b7 | 2007-06-28 21:14:38 +1000 | [diff] [blame] | 173 | #ifdef CONFIG_PPC_PMI |
Christian Krafft | 813f907 | 2007-07-20 21:39:18 +0200 | [diff] [blame] | 174 | if (cbe_cpufreq_has_pmi) |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 175 | rc = set_pmode_pmi(cpu, slow_mode); |
| 176 | else |
Christian Krafft | ee5d1b7 | 2007-06-28 21:14:38 +1000 | [diff] [blame] | 177 | #endif |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 178 | rc = set_pmode_reg(cpu, slow_mode); |
| 179 | |
| 180 | pr_debug("register contains slow mode %d\n", get_pmode(cpu)); |
| 181 | |
| 182 | return rc; |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 183 | } |
| 184 | |
Christian Krafft | 813f907 | 2007-07-20 21:39:18 +0200 | [diff] [blame] | 185 | static void cbe_cpufreq_handle_pmi(pmi_message_t pmi_msg) |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 186 | { |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 187 | u8 node; slow_mode; |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 188 | |
Olof Johansson | 4bd4aa1 | 2007-04-28 12:49:03 +1000 | [diff] [blame] | 189 | BUG_ON(pmi_msg.type != PMI_TYPE_FREQ_CHANGE); |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 190 | |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 191 | node = pmi_msg.data1; |
| 192 | slow_mode = pmi_msg.data2; |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 193 | |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 194 | pmi_slow_mode_limit[node] = slow_mode; |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 195 | |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 196 | pr_debug("cbe_handle_pmi: node: %d, max slow_mode=%d\n", slow_mode); |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 197 | } |
| 198 | |
Thomas Renninger | 1552cb9 | 2007-06-05 04:14:40 +1000 | [diff] [blame] | 199 | static int pmi_notifier(struct notifier_block *nb, |
| 200 | unsigned long event, void *data) |
| 201 | { |
| 202 | struct cpufreq_policy *policy = data; |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 203 | u8 node; |
Thomas Renninger | 1552cb9 | 2007-06-05 04:14:40 +1000 | [diff] [blame] | 204 | |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 205 | node = cbe_cpu_to_node(policy->cpu); |
| 206 | |
| 207 | pr_debug("got notified, event=%lu, node=%u\n", event, node); |
| 208 | |
| 209 | if (pmi_slow_mode_limit[node] != 0) { |
| 210 | pr_debug("limiting node %d to slow mode %d\n", |
| 211 | node, pmi_slow_mode_limit[node]); |
| 212 | |
| 213 | cpufreq_verify_within_limits(policy, 0, |
| 214 | cbe_freqs[pmi_slow_mode_limit[node]].frequency); |
| 215 | } |
Thomas Renninger | 1552cb9 | 2007-06-05 04:14:40 +1000 | [diff] [blame] | 216 | |
Thomas Renninger | 1552cb9 | 2007-06-05 04:14:40 +1000 | [diff] [blame] | 217 | return 0; |
| 218 | } |
| 219 | |
| 220 | static struct notifier_block pmi_notifier_block = { |
| 221 | .notifier_call = pmi_notifier, |
| 222 | }; |
| 223 | |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 224 | static struct pmi_handler cbe_pmi_handler = { |
| 225 | .type = PMI_TYPE_FREQ_CHANGE, |
| 226 | .handle_pmi_message = cbe_cpufreq_handle_pmi, |
| 227 | }; |
| 228 | |
| 229 | |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 230 | /* |
| 231 | * cpufreq functions |
| 232 | */ |
| 233 | |
Olof Johansson | 4bd4aa1 | 2007-04-28 12:49:03 +1000 | [diff] [blame] | 234 | static int cbe_cpufreq_cpu_init(struct cpufreq_policy *policy) |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 235 | { |
Stephen Rothwell | 9c1a2ba | 2007-04-03 22:50:59 +1000 | [diff] [blame] | 236 | const u32 *max_freqp; |
| 237 | u32 max_freq; |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 238 | int i, cur_pmode; |
| 239 | struct device_node *cpu; |
| 240 | |
| 241 | cpu = of_get_cpu_node(policy->cpu, NULL); |
| 242 | |
Olof Johansson | 4bd4aa1 | 2007-04-28 12:49:03 +1000 | [diff] [blame] | 243 | if (!cpu) |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 244 | return -ENODEV; |
| 245 | |
| 246 | pr_debug("init cpufreq on CPU %d\n", policy->cpu); |
| 247 | |
Stephen Rothwell | 9c1a2ba | 2007-04-03 22:50:59 +1000 | [diff] [blame] | 248 | max_freqp = of_get_property(cpu, "clock-frequency", NULL); |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 249 | |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 250 | of_node_put(cpu); |
| 251 | |
Stephen Rothwell | 9c1a2ba | 2007-04-03 22:50:59 +1000 | [diff] [blame] | 252 | if (!max_freqp) |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 253 | return -EINVAL; |
| 254 | |
Olof Johansson | 4bd4aa1 | 2007-04-28 12:49:03 +1000 | [diff] [blame] | 255 | /* we need the freq in kHz */ |
Stephen Rothwell | 9c1a2ba | 2007-04-03 22:50:59 +1000 | [diff] [blame] | 256 | max_freq = *max_freqp / 1000; |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 257 | |
Stephen Rothwell | 9c1a2ba | 2007-04-03 22:50:59 +1000 | [diff] [blame] | 258 | pr_debug("max clock-frequency is at %u kHz\n", max_freq); |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 259 | pr_debug("initializing frequency table\n"); |
| 260 | |
Olof Johansson | 4bd4aa1 | 2007-04-28 12:49:03 +1000 | [diff] [blame] | 261 | /* initialize frequency table */ |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 262 | for (i=0; cbe_freqs[i].frequency!=CPUFREQ_TABLE_END; i++) { |
Stephen Rothwell | 9c1a2ba | 2007-04-03 22:50:59 +1000 | [diff] [blame] | 263 | cbe_freqs[i].frequency = max_freq / cbe_freqs[i].index; |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 264 | pr_debug("%d: %d\n", i, cbe_freqs[i].frequency); |
| 265 | } |
| 266 | |
| 267 | policy->governor = CPUFREQ_DEFAULT_GOVERNOR; |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 268 | |
| 269 | /* if DEBUG is enabled set_pmode() measures the latency |
| 270 | * of a transition */ |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 271 | policy->cpuinfo.transition_latency = 25000; |
| 272 | |
| 273 | cur_pmode = get_pmode(policy->cpu); |
| 274 | pr_debug("current pmode is at %d\n",cur_pmode); |
| 275 | |
| 276 | policy->cur = cbe_freqs[cur_pmode].frequency; |
| 277 | |
| 278 | #ifdef CONFIG_SMP |
| 279 | policy->cpus = cpu_sibling_map[policy->cpu]; |
| 280 | #endif |
| 281 | |
Olof Johansson | 4bd4aa1 | 2007-04-28 12:49:03 +1000 | [diff] [blame] | 282 | cpufreq_frequency_table_get_attr(cbe_freqs, policy->cpu); |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 283 | |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 284 | /* this ensures that policy->cpuinfo_min |
| 285 | * and policy->cpuinfo_max are set correctly */ |
Olof Johansson | 4bd4aa1 | 2007-04-28 12:49:03 +1000 | [diff] [blame] | 286 | return cpufreq_frequency_table_cpuinfo(policy, cbe_freqs); |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 287 | } |
| 288 | |
| 289 | static int cbe_cpufreq_cpu_exit(struct cpufreq_policy *policy) |
| 290 | { |
| 291 | cpufreq_frequency_table_put_attr(policy->cpu); |
| 292 | return 0; |
| 293 | } |
| 294 | |
| 295 | static int cbe_cpufreq_verify(struct cpufreq_policy *policy) |
| 296 | { |
| 297 | return cpufreq_frequency_table_verify(policy, cbe_freqs); |
| 298 | } |
| 299 | |
| 300 | |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 301 | static int cbe_cpufreq_target(struct cpufreq_policy *policy, |
| 302 | unsigned int target_freq, |
| 303 | unsigned int relation) |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 304 | { |
| 305 | int rc; |
| 306 | struct cpufreq_freqs freqs; |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 307 | unsigned int cbe_pmode_new; |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 308 | |
| 309 | cpufreq_frequency_table_target(policy, |
| 310 | cbe_freqs, |
| 311 | target_freq, |
| 312 | relation, |
| 313 | &cbe_pmode_new); |
| 314 | |
| 315 | freqs.old = policy->cur; |
| 316 | freqs.new = cbe_freqs[cbe_pmode_new].frequency; |
| 317 | freqs.cpu = policy->cpu; |
| 318 | |
Olof Johansson | 4bd4aa1 | 2007-04-28 12:49:03 +1000 | [diff] [blame] | 319 | mutex_lock(&cbe_switch_mutex); |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 320 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); |
| 321 | |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 322 | pr_debug("setting frequency for cpu %d to %d kHz, " \ |
| 323 | "1/%d of max frequency\n", |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 324 | policy->cpu, |
| 325 | cbe_freqs[cbe_pmode_new].frequency, |
| 326 | cbe_freqs[cbe_pmode_new].index); |
| 327 | |
| 328 | rc = set_pmode(policy->cpu, cbe_pmode_new); |
Christian Krafft | 1e21fd5 | 2007-07-20 21:39:21 +0200 | [diff] [blame^] | 329 | |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 330 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); |
| 331 | mutex_unlock(&cbe_switch_mutex); |
| 332 | |
| 333 | return rc; |
| 334 | } |
| 335 | |
| 336 | static struct cpufreq_driver cbe_cpufreq_driver = { |
| 337 | .verify = cbe_cpufreq_verify, |
| 338 | .target = cbe_cpufreq_target, |
| 339 | .init = cbe_cpufreq_cpu_init, |
| 340 | .exit = cbe_cpufreq_cpu_exit, |
| 341 | .name = "cbe-cpufreq", |
| 342 | .owner = THIS_MODULE, |
| 343 | .flags = CPUFREQ_CONST_LOOPS, |
| 344 | }; |
| 345 | |
| 346 | /* |
| 347 | * module init and destoy |
| 348 | */ |
| 349 | |
| 350 | static int __init cbe_cpufreq_init(void) |
| 351 | { |
Olof Johansson | 4bd4aa1 | 2007-04-28 12:49:03 +1000 | [diff] [blame] | 352 | if (!machine_is(cell)) |
| 353 | return -ENODEV; |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 354 | |
Christian Krafft | 813f907 | 2007-07-20 21:39:18 +0200 | [diff] [blame] | 355 | cbe_cpufreq_has_pmi = pmi_register_handler(&cbe_pmi_handler) == 0; |
Christian Krafft | 5050063 | 2007-04-23 21:35:42 +0200 | [diff] [blame] | 356 | |
Christian Krafft | e5ecc87 | 2007-07-20 21:39:20 +0200 | [diff] [blame] | 357 | if (cbe_cpufreq_has_pmi) |
| 358 | cpufreq_register_notifier(&pmi_notifier_block, CPUFREQ_POLICY_NOTIFIER); |
| 359 | |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 360 | return cpufreq_register_driver(&cbe_cpufreq_driver); |
| 361 | } |
| 362 | |
| 363 | static void __exit cbe_cpufreq_exit(void) |
| 364 | { |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 365 | cpufreq_unregister_driver(&cbe_cpufreq_driver); |
Christian Krafft | 813f907 | 2007-07-20 21:39:18 +0200 | [diff] [blame] | 366 | |
Christian Krafft | e5ecc87 | 2007-07-20 21:39:20 +0200 | [diff] [blame] | 367 | if (cbe_cpufreq_has_pmi) { |
| 368 | cpufreq_unregister_notifier(&pmi_notifier_block, CPUFREQ_POLICY_NOTIFIER); |
Christian Krafft | 813f907 | 2007-07-20 21:39:18 +0200 | [diff] [blame] | 369 | pmi_unregister_handler(&cbe_pmi_handler); |
Christian Krafft | e5ecc87 | 2007-07-20 21:39:20 +0200 | [diff] [blame] | 370 | } |
Christian Krafft | 36ca4ba | 2006-10-24 18:39:45 +0200 | [diff] [blame] | 371 | } |
| 372 | |
| 373 | module_init(cbe_cpufreq_init); |
| 374 | module_exit(cbe_cpufreq_exit); |
| 375 | |
| 376 | MODULE_LICENSE("GPL"); |
| 377 | MODULE_AUTHOR("Christian Krafft <krafft@de.ibm.com>"); |