blob: dde4e31491796f08602cc31dfab1dd4130476316 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * (C) 2001-2004 Dave Jones. <davej@codemonkey.org.uk>
3 * (C) 2002 Padraig Brady. <padraig@antefacto.com>
4 *
5 * Licensed under the terms of the GNU GPL License version 2.
6 * Based upon datasheets & sample CPUs kindly provided by VIA.
7 *
8 * VIA have currently 3 different versions of Longhaul.
9 * Version 1 (Longhaul) uses the BCR2 MSR at 0x1147.
10 * It is present only in Samuel 1 (C5A), Samuel 2 (C5B) stepping 0.
Rafa³ Bilski2b8c0e12007-02-14 22:00:37 +010011 * Version 2 of longhaul is backward compatible with v1, but adds
12 * LONGHAUL MSR for purpose of both frequency and voltage scaling.
13 * Present in Samuel 2 (steppings 1-7 only) (C5B), and Ezra (C5C).
Linus Torvalds1da177e2005-04-16 15:20:36 -070014 * Version 3 of longhaul got renamed to Powersaver and redesigned
Rafa³ Bilski2b8c0e12007-02-14 22:00:37 +010015 * to use only the POWERSAVER MSR at 0x110a.
Linus Torvalds1da177e2005-04-16 15:20:36 -070016 * It is present in Ezra-T (C5M), Nehemiah (C5X) and above.
17 * It's pretty much the same feature wise to longhaul v2, though
18 * there is provision for scaling FSB too, but this doesn't work
19 * too well in practice so we don't even try to use this.
20 *
21 * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous*
22 */
23
24#include <linux/kernel.h>
25#include <linux/module.h>
26#include <linux/moduleparam.h>
27#include <linux/init.h>
28#include <linux/cpufreq.h>
Rafa³ Bilski179da8e2006-08-08 19:12:20 +020029#include <linux/pci.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070030#include <linux/slab.h>
31#include <linux/string.h>
Rafał Bilski73e107d2007-05-28 21:56:19 +020032#include <linux/delay.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070033
34#include <asm/msr.h>
35#include <asm/timex.h>
36#include <asm/io.h>
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +020037#include <asm/acpi.h>
38#include <linux/acpi.h>
39#include <acpi/processor.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070040
41#include "longhaul.h"
42
43#define PFX "longhaul: "
44
45#define TYPE_LONGHAUL_V1 1
46#define TYPE_LONGHAUL_V2 2
47#define TYPE_POWERSAVER 3
48
49#define CPU_SAMUEL 1
50#define CPU_SAMUEL2 2
51#define CPU_EZRA 3
52#define CPU_EZRA_T 4
53#define CPU_NEHEMIAH 5
Rafa³ Bilski980342a2007-01-31 23:42:47 +010054#define CPU_NEHEMIAH_C 6
Linus Torvalds1da177e2005-04-16 15:20:36 -070055
Rafa³ Bilski264166e2006-12-24 14:04:23 +010056/* Flags */
57#define USE_ACPI_C3 (1 << 1)
58#define USE_NORTHBRIDGE (1 << 2)
59
Linus Torvalds1da177e2005-04-16 15:20:36 -070060static int cpu_model;
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +020061static unsigned int numscales=16;
Linus Torvalds1da177e2005-04-16 15:20:36 -070062static unsigned int fsb;
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +020063
Dave Jonesbd5ab262007-02-22 19:11:16 -050064static const struct mV_pos *vrm_mV_table;
65static const unsigned char *mV_vrm_table;
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +020066
67static unsigned int highest_speed, lowest_speed; /* kHz */
Linus Torvalds1da177e2005-04-16 15:20:36 -070068static unsigned int minmult, maxmult;
69static int can_scale_voltage;
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +020070static struct acpi_processor *pr = NULL;
71static struct acpi_processor_cx *cx = NULL;
Rafa³ Bilski264166e2006-12-24 14:04:23 +010072static u8 longhaul_flags;
Rafał Bilski73e107d2007-05-28 21:56:19 +020073static unsigned int longhaul_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -070074
75/* Module parameters */
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +020076static int scale_voltage;
Linus Torvalds1da177e2005-04-16 15:20:36 -070077
78#define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "longhaul", msg)
79
80
Linus Torvalds1da177e2005-04-16 15:20:36 -070081/* Clock ratios multiplied by 10 */
82static int clock_ratio[32];
83static int eblcr_table[32];
Linus Torvalds1da177e2005-04-16 15:20:36 -070084static int longhaul_version;
85static struct cpufreq_frequency_table *longhaul_table;
86
87#ifdef CONFIG_CPU_FREQ_DEBUG
88static char speedbuffer[8];
89
90static char *print_speed(int speed)
91{
Dave Jonese2aa8732006-05-30 17:37:15 -040092 if (speed < 1000) {
93 snprintf(speedbuffer, sizeof(speedbuffer),"%dMHz", speed);
94 return speedbuffer;
95 }
96
97 if (speed%1000 == 0)
98 snprintf(speedbuffer, sizeof(speedbuffer),
99 "%dGHz", speed/1000);
100 else
101 snprintf(speedbuffer, sizeof(speedbuffer),
102 "%d.%dGHz", speed/1000, (speed%1000)/100);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700103
104 return speedbuffer;
105}
106#endif
107
108
109static unsigned int calc_speed(int mult)
110{
111 int khz;
112 khz = (mult/10)*fsb;
113 if (mult%10)
114 khz += fsb/2;
115 khz *= 1000;
116 return khz;
117}
118
119
120static int longhaul_get_cpu_mult(void)
121{
122 unsigned long invalue=0,lo, hi;
123
124 rdmsr (MSR_IA32_EBL_CR_POWERON, lo, hi);
125 invalue = (lo & (1<<22|1<<23|1<<24|1<<25)) >>22;
126 if (longhaul_version==TYPE_LONGHAUL_V2 || longhaul_version==TYPE_POWERSAVER) {
127 if (lo & (1<<27))
128 invalue+=16;
129 }
130 return eblcr_table[invalue];
131}
132
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200133/* For processor with BCR2 MSR */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700134
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200135static void do_longhaul1(unsigned int clock_ratio_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700136{
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200137 union msr_bcr2 bcr2;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700138
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200139 rdmsrl(MSR_VIA_BCR2, bcr2.val);
140 /* Enable software clock multiplier */
141 bcr2.bits.ESOFTBF = 1;
Rafał Bilski73e107d2007-05-28 21:56:19 +0200142 bcr2.bits.CLOCKMUL = clock_ratio_index & 0xff;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700143
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200144 /* Sync to timer tick */
Zachary Amsden4bb0d3e2005-09-03 15:56:36 -0700145 safe_halt();
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200146 /* Change frequency on next halt or sleep */
147 wrmsrl(MSR_VIA_BCR2, bcr2.val);
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200148 /* Invoke transition */
149 ACPI_FLUSH_CPU_CACHE();
150 halt();
Linus Torvalds1da177e2005-04-16 15:20:36 -0700151
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200152 /* Disable software clock multiplier */
Dave Jones3be6a482005-05-31 19:03:51 -0700153 local_irq_disable();
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200154 rdmsrl(MSR_VIA_BCR2, bcr2.val);
155 bcr2.bits.ESOFTBF = 0;
156 wrmsrl(MSR_VIA_BCR2, bcr2.val);
157}
Dave Jones3be6a482005-05-31 19:03:51 -0700158
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200159/* For processor with Longhaul MSR */
Dave Jones11746312005-05-31 19:03:51 -0700160
Rafał Bilski73e107d2007-05-28 21:56:19 +0200161static void do_powersaver(int cx_address, unsigned int clock_ratio_index,
162 unsigned int dir)
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200163{
164 union msr_longhaul longhaul;
165 u32 t;
Dave Jones3be6a482005-05-31 19:03:51 -0700166
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200167 rdmsrl(MSR_VIA_LONGHAUL, longhaul.val);
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100168 /* Setup new frequency */
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200169 longhaul.bits.RevisionKey = longhaul.bits.RevisionID;
170 longhaul.bits.SoftBusRatio = clock_ratio_index & 0xf;
171 longhaul.bits.SoftBusRatio4 = (clock_ratio_index & 0x10) >> 4;
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100172 /* Setup new voltage */
173 if (can_scale_voltage)
Rafał Bilski73e107d2007-05-28 21:56:19 +0200174 longhaul.bits.SoftVID = (clock_ratio_index >> 8) & 0x1f;
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200175 /* Sync to timer tick */
176 safe_halt();
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100177 /* Raise voltage if necessary */
Rafał Bilski73e107d2007-05-28 21:56:19 +0200178 if (can_scale_voltage && dir) {
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100179 longhaul.bits.EnableSoftVID = 1;
180 wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
181 /* Change voltage */
182 if (!cx_address) {
183 ACPI_FLUSH_CPU_CACHE();
184 halt();
185 } else {
186 ACPI_FLUSH_CPU_CACHE();
187 /* Invoke C3 */
188 inb(cx_address);
189 /* Dummy op - must do something useless after P_LVL3
190 * read */
Dave Jonesbd0561c2007-02-10 20:36:29 -0500191 t = inl(acpi_gbl_FADT.xpm_timer_block.address);
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100192 }
193 longhaul.bits.EnableSoftVID = 0;
194 wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100195 }
196
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200197 /* Change frequency on next halt or sleep */
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100198 longhaul.bits.EnableSoftBusRatio = 1;
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200199 wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
Rafa³ Bilski264166e2006-12-24 14:04:23 +0100200 if (!cx_address) {
rafalbilski@interia.pl7f1be892006-09-24 20:28:13 +0200201 ACPI_FLUSH_CPU_CACHE();
rafalbilski@interia.pl7f1be892006-09-24 20:28:13 +0200202 halt();
203 } else {
204 ACPI_FLUSH_CPU_CACHE();
205 /* Invoke C3 */
206 inb(cx_address);
207 /* Dummy op - must do something useless after P_LVL3 read */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300208 t = inl(acpi_gbl_FADT.xpm_timer_block.address);
rafalbilski@interia.pl7f1be892006-09-24 20:28:13 +0200209 }
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200210 /* Disable bus ratio bit */
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200211 longhaul.bits.EnableSoftBusRatio = 0;
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200212 wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100213
214 /* Reduce voltage if necessary */
Rafał Bilski73e107d2007-05-28 21:56:19 +0200215 if (can_scale_voltage && !dir) {
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100216 longhaul.bits.EnableSoftVID = 1;
217 wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
218 /* Change voltage */
219 if (!cx_address) {
220 ACPI_FLUSH_CPU_CACHE();
221 halt();
222 } else {
223 ACPI_FLUSH_CPU_CACHE();
224 /* Invoke C3 */
225 inb(cx_address);
226 /* Dummy op - must do something useless after P_LVL3
227 * read */
Dave Jonesbd0561c2007-02-10 20:36:29 -0500228 t = inl(acpi_gbl_FADT.xpm_timer_block.address);
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100229 }
230 longhaul.bits.EnableSoftVID = 0;
231 wrmsrl(MSR_VIA_LONGHAUL, longhaul.val);
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100232 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700233}
234
235/**
236 * longhaul_set_cpu_frequency()
237 * @clock_ratio_index : bitpattern of the new multiplier.
238 *
239 * Sets a new clock ratio.
240 */
241
Rafał Bilski73e107d2007-05-28 21:56:19 +0200242static void longhaul_setstate(unsigned int table_index)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700243{
Rafał Bilski73e107d2007-05-28 21:56:19 +0200244 unsigned int clock_ratio_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700245 int speed, mult;
246 struct cpufreq_freqs freqs;
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200247 unsigned long flags;
248 unsigned int pic1_mask, pic2_mask;
Rafał Bilski489dc5c2007-05-17 22:39:02 +0200249 u32 bm_status = 0;
250 u32 bm_timeout = 100000;
Rafał Bilski73e107d2007-05-28 21:56:19 +0200251 unsigned int dir = 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700252
Rafał Bilski73e107d2007-05-28 21:56:19 +0200253 clock_ratio_index = longhaul_table[table_index].index;
254 /* Safety precautions */
255 mult = clock_ratio[clock_ratio_index & 0x1f];
Linus Torvalds1da177e2005-04-16 15:20:36 -0700256 if (mult == -1)
257 return;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700258 speed = calc_speed(mult);
259 if ((speed > highest_speed) || (speed < lowest_speed))
260 return;
Rafał Bilski73e107d2007-05-28 21:56:19 +0200261 /* Voltage transition before frequency transition? */
262 if (can_scale_voltage && longhaul_index < table_index)
263 dir = 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700264
265 freqs.old = calc_speed(longhaul_get_cpu_mult());
266 freqs.new = speed;
267 freqs.cpu = 0; /* longhaul.c is UP only driver */
268
269 cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE);
270
271 dprintk ("Setting to FSB:%dMHz Mult:%d.%dx (%s)\n",
272 fsb, mult/10, mult%10, print_speed(speed/1000));
273
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200274 preempt_disable();
275 local_irq_save(flags);
276
277 pic2_mask = inb(0xA1);
278 pic1_mask = inb(0x21); /* works on C3. save mask. */
279 outb(0xFF,0xA1); /* Overkill */
280 outb(0xFE,0x21); /* TMR0 only */
281
Rafał Bilski489dc5c2007-05-17 22:39:02 +0200282 /* Wait while PCI bus is busy. */
283 if (longhaul_flags & USE_NORTHBRIDGE
284 || ((pr != NULL) && pr->flags.bm_control)) {
285 acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS, &bm_status);
286 while (bm_status && bm_timeout) {
287 acpi_set_register(ACPI_BITREG_BUS_MASTER_STATUS, 1);
288 bm_timeout--;
289 acpi_get_register(ACPI_BITREG_BUS_MASTER_STATUS,
290 &bm_status);
291 }
292 }
293
Rafa³ Bilski264166e2006-12-24 14:04:23 +0100294 if (longhaul_flags & USE_NORTHBRIDGE) {
295 /* Disable AGP and PCI arbiters */
296 outb(3, 0x22);
297 } else if ((pr != NULL) && pr->flags.bm_control) {
Rafał Bilski73e107d2007-05-28 21:56:19 +0200298 /* Disable bus master arbitration */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300299 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1);
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200300 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700301 switch (longhaul_version) {
302
303 /*
304 * Longhaul v1. (Samuel[C5A] and Samuel2 stepping 0[C5B])
305 * Software controlled multipliers only.
Linus Torvalds1da177e2005-04-16 15:20:36 -0700306 */
307 case TYPE_LONGHAUL_V1:
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200308 do_longhaul1(clock_ratio_index);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700309 break;
310
311 /*
Rafa³ Bilski2b8c0e12007-02-14 22:00:37 +0100312 * Longhaul v2 appears in Samuel2 Steppings 1->7 [C5B] and Ezra [C5C]
313 *
Linus Torvalds1da177e2005-04-16 15:20:36 -0700314 * Longhaul v3 (aka Powersaver). (Ezra-T [C5M] & Nehemiah [C5N])
Linus Torvalds1da177e2005-04-16 15:20:36 -0700315 * Nehemiah can do FSB scaling too, but this has never been proven
316 * to work in practice.
317 */
Rafa³ Bilski2b8c0e12007-02-14 22:00:37 +0100318 case TYPE_LONGHAUL_V2:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700319 case TYPE_POWERSAVER:
Rafa³ Bilski264166e2006-12-24 14:04:23 +0100320 if (longhaul_flags & USE_ACPI_C3) {
321 /* Don't allow wakeup */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300322 acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0);
Rafał Bilski73e107d2007-05-28 21:56:19 +0200323 do_powersaver(cx->address, clock_ratio_index, dir);
Rafa³ Bilski264166e2006-12-24 14:04:23 +0100324 } else {
Rafał Bilski73e107d2007-05-28 21:56:19 +0200325 do_powersaver(0, clock_ratio_index, dir);
Rafa³ Bilski264166e2006-12-24 14:04:23 +0100326 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700327 break;
328 }
329
Rafa³ Bilski264166e2006-12-24 14:04:23 +0100330 if (longhaul_flags & USE_NORTHBRIDGE) {
331 /* Enable arbiters */
332 outb(0, 0x22);
333 } else if ((pr != NULL) && pr->flags.bm_control) {
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200334 /* Enable bus master arbitration */
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300335 acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0);
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200336 }
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200337 outb(pic2_mask,0xA1); /* restore mask */
338 outb(pic1_mask,0x21);
339
340 local_irq_restore(flags);
341 preempt_enable();
342
Rafa³ Bilski2b8c0e12007-02-14 22:00:37 +0100343 freqs.new = calc_speed(longhaul_get_cpu_mult());
Linus Torvalds1da177e2005-04-16 15:20:36 -0700344 cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE);
Rafał Bilski489dc5c2007-05-17 22:39:02 +0200345
346 if (!bm_timeout)
347 printk(KERN_INFO PFX "Warning: Timeout while waiting for "
348 "idle PCI bus.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700349}
350
351/*
352 * Centaur decided to make life a little more tricky.
353 * Only longhaul v1 is allowed to read EBLCR BSEL[0:1].
354 * Samuel2 and above have to try and guess what the FSB is.
355 * We do this by assuming we booted at maximum multiplier, and interpolate
356 * between that value multiplied by possible FSBs and cpu_mhz which
357 * was calculated at boot time. Really ugly, but no other way to do this.
358 */
359
360#define ROUNDING 0xf
361
Rafa³ Bilski24ebead2007-01-01 23:49:34 +0100362static int guess_fsb(int mult)
Linus Torvalds1da177e2005-04-16 15:20:36 -0700363{
Rafa³ Bilski46ef9552007-02-04 15:58:46 +0100364 int speed = cpu_khz / 1000;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700365 int i;
Rafa³ Bilski46ef9552007-02-04 15:58:46 +0100366 int speeds[] = { 666, 1000, 1333, 2000 };
367 int f_max, f_min;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700368
Rafa³ Bilski46ef9552007-02-04 15:58:46 +0100369 for (i = 0; i < 4; i++) {
370 f_max = ((speeds[i] * mult) + 50) / 100;
371 f_max += (ROUNDING / 2);
372 f_min = f_max - ROUNDING;
373 if ((speed <= f_max) && (speed >= f_min))
374 return speeds[i] / 10;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700375 }
376 return 0;
377}
378
379
380static int __init longhaul_get_ranges(void)
381{
Rafał Bilski73e107d2007-05-28 21:56:19 +0200382 unsigned int i, j, k = 0;
383 unsigned int ratio;
Rafa³ Bilski980342a2007-01-31 23:42:47 +0100384 int mult;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700385
Rafa³ Bilski980342a2007-01-31 23:42:47 +0100386 /* Get current frequency */
387 mult = longhaul_get_cpu_mult();
388 if (mult == -1) {
389 printk(KERN_INFO PFX "Invalid (reserved) multiplier!\n");
390 return -EINVAL;
391 }
392 fsb = guess_fsb(mult);
393 if (fsb == 0) {
394 printk(KERN_INFO PFX "Invalid (reserved) FSB!\n");
395 return -EINVAL;
396 }
397 /* Get max multiplier - as we always did.
398 * Longhaul MSR is usefull only when voltage scaling is enabled.
399 * C3 is booting at max anyway. */
400 maxmult = mult;
401 /* Get min multiplier */
Rafa³ Bilski9addf3b2007-02-07 22:53:29 +0100402 switch (cpu_model) {
403 case CPU_NEHEMIAH:
404 minmult = 50;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700405 break;
Rafa³ Bilski9addf3b2007-02-07 22:53:29 +0100406 case CPU_NEHEMIAH_C:
407 minmult = 40;
408 break;
409 default:
410 minmult = 30;
Rafa³ Bilski980342a2007-01-31 23:42:47 +0100411 break;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700412 }
413
414 dprintk ("MinMult:%d.%dx MaxMult:%d.%dx\n",
415 minmult/10, minmult%10, maxmult/10, maxmult%10);
416
Linus Torvalds1da177e2005-04-16 15:20:36 -0700417 highest_speed = calc_speed(maxmult);
418 lowest_speed = calc_speed(minmult);
419 dprintk ("FSB:%dMHz Lowest speed: %s Highest speed:%s\n", fsb,
Alexey Starikovskiycee324b2007-02-02 19:48:22 +0300420 print_speed(lowest_speed/1000),
Linus Torvalds1da177e2005-04-16 15:20:36 -0700421 print_speed(highest_speed/1000));
422
423 if (lowest_speed == highest_speed) {
424 printk (KERN_INFO PFX "highestspeed == lowest, aborting.\n");
425 return -EINVAL;
426 }
427 if (lowest_speed > highest_speed) {
428 printk (KERN_INFO PFX "nonsense! lowest (%d > %d) !\n",
429 lowest_speed, highest_speed);
430 return -EINVAL;
431 }
432
433 longhaul_table = kmalloc((numscales + 1) * sizeof(struct cpufreq_frequency_table), GFP_KERNEL);
434 if(!longhaul_table)
435 return -ENOMEM;
436
Rafał Bilski73e107d2007-05-28 21:56:19 +0200437 for (j = 0; j < numscales; j++) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700438 ratio = clock_ratio[j];
439 if (ratio == -1)
440 continue;
441 if (ratio > maxmult || ratio < minmult)
442 continue;
443 longhaul_table[k].frequency = calc_speed(ratio);
444 longhaul_table[k].index = j;
445 k++;
446 }
Rafał Bilski73e107d2007-05-28 21:56:19 +0200447 if (k <= 1) {
448 kfree(longhaul_table);
449 return -ENODEV;
450 }
451 /* Sort */
452 for (j = 0; j < k - 1; j++) {
453 unsigned int min_f, min_i;
454 min_f = longhaul_table[j].frequency;
455 min_i = j;
456 for (i = j + 1; i < k; i++) {
457 if (longhaul_table[i].frequency < min_f) {
458 min_f = longhaul_table[i].frequency;
459 min_i = i;
460 }
461 }
462 if (min_i != j) {
463 unsigned int temp;
464 temp = longhaul_table[j].frequency;
465 longhaul_table[j].frequency = longhaul_table[min_i].frequency;
466 longhaul_table[min_i].frequency = temp;
467 temp = longhaul_table[j].index;
468 longhaul_table[j].index = longhaul_table[min_i].index;
469 longhaul_table[min_i].index = temp;
470 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700471 }
472
Rafał Bilski73e107d2007-05-28 21:56:19 +0200473 longhaul_table[k].frequency = CPUFREQ_TABLE_END;
474
475 /* Find index we are running on */
476 for (j = 0; j < k; j++) {
477 if (clock_ratio[longhaul_table[j].index & 0x1f] == mult) {
478 longhaul_index = j;
479 break;
480 }
481 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700482 return 0;
483}
484
485
486static void __init longhaul_setup_voltagescaling(void)
487{
488 union msr_longhaul longhaul;
Rafał Bilski73e107d2007-05-28 21:56:19 +0200489 struct mV_pos minvid, maxvid, vid;
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200490 unsigned int j, speed, pos, kHz_step, numvscales;
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100491 int min_vid_speed;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700492
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200493 rdmsrl(MSR_VIA_LONGHAUL, longhaul.val);
494 if (!(longhaul.bits.RevisionID & 1)) {
495 printk(KERN_INFO PFX "Voltage scaling not supported by CPU.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700496 return;
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200497 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700498
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200499 if (!longhaul.bits.VRMRev) {
Rafał Bilski73e107d2007-05-28 21:56:19 +0200500 printk(KERN_INFO PFX "VRM 8.5\n");
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200501 vrm_mV_table = &vrm85_mV[0];
502 mV_vrm_table = &mV_vrm85[0];
503 } else {
Rafał Bilski73e107d2007-05-28 21:56:19 +0200504 printk(KERN_INFO PFX "Mobile VRM\n");
Rafa³ Bilski2b8c0e12007-02-14 22:00:37 +0100505 if (cpu_model < CPU_NEHEMIAH)
506 return;
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200507 vrm_mV_table = &mobilevrm_mV[0];
508 mV_vrm_table = &mV_mobilevrm[0];
509 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700510
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200511 minvid = vrm_mV_table[longhaul.bits.MinimumVID];
512 maxvid = vrm_mV_table[longhaul.bits.MaximumVID];
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200513
514 if (minvid.mV == 0 || maxvid.mV == 0 || minvid.mV > maxvid.mV) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700515 printk (KERN_INFO PFX "Bogus values Min:%d.%03d Max:%d.%03d. "
516 "Voltage scaling disabled.\n",
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200517 minvid.mV/1000, minvid.mV%1000, maxvid.mV/1000, maxvid.mV%1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700518 return;
519 }
520
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200521 if (minvid.mV == maxvid.mV) {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700522 printk (KERN_INFO PFX "Claims to support voltage scaling but min & max are "
523 "both %d.%03d. Voltage scaling disabled\n",
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200524 maxvid.mV/1000, maxvid.mV%1000);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700525 return;
526 }
527
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100528 /* How many voltage steps */
529 numvscales = maxvid.pos - minvid.pos + 1;
530 printk(KERN_INFO PFX
531 "Max VID=%d.%03d "
532 "Min VID=%d.%03d, "
533 "%d possible voltage scales\n",
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200534 maxvid.mV/1000, maxvid.mV%1000,
535 minvid.mV/1000, minvid.mV%1000,
536 numvscales);
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100537
538 /* Calculate max frequency at min voltage */
539 j = longhaul.bits.MinMHzBR;
540 if (longhaul.bits.MinMHzBR4)
541 j += 16;
542 min_vid_speed = eblcr_table[j];
543 if (min_vid_speed == -1)
544 return;
545 switch (longhaul.bits.MinMHzFSB) {
546 case 0:
547 min_vid_speed *= 13333;
548 break;
549 case 1:
550 min_vid_speed *= 10000;
551 break;
552 case 3:
553 min_vid_speed *= 6666;
554 break;
555 default:
556 return;
557 break;
558 }
559 if (min_vid_speed >= highest_speed)
560 return;
561 /* Calculate kHz for one voltage step */
562 kHz_step = (highest_speed - min_vid_speed) / numvscales;
563
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200564 j = 0;
565 while (longhaul_table[j].frequency != CPUFREQ_TABLE_END) {
566 speed = longhaul_table[j].frequency;
Rafa³ Bilski348f31e2007-02-08 18:56:04 +0100567 if (speed > min_vid_speed)
568 pos = (speed - min_vid_speed) / kHz_step + minvid.pos;
569 else
570 pos = minvid.pos;
Rafał Bilski73e107d2007-05-28 21:56:19 +0200571 longhaul_table[j].index |= mV_vrm_table[pos] << 8;
572 vid = vrm_mV_table[mV_vrm_table[pos]];
573 printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n", speed, j, vid.mV);
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200574 j++;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700575 }
576
Linus Torvalds1da177e2005-04-16 15:20:36 -0700577 can_scale_voltage = 1;
Rafał Bilski73e107d2007-05-28 21:56:19 +0200578 printk(KERN_INFO PFX "Voltage scaling enabled.\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700579}
580
581
582static int longhaul_verify(struct cpufreq_policy *policy)
583{
584 return cpufreq_frequency_table_verify(policy, longhaul_table);
585}
586
587
588static int longhaul_target(struct cpufreq_policy *policy,
589 unsigned int target_freq, unsigned int relation)
590{
591 unsigned int table_index = 0;
Rafał Bilski73e107d2007-05-28 21:56:19 +0200592 unsigned int i;
593 unsigned int dir = 0;
594 u8 vid, current_vid;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700595
596 if (cpufreq_frequency_table_target(policy, longhaul_table, target_freq, relation, &table_index))
597 return -EINVAL;
598
Rafał Bilski73e107d2007-05-28 21:56:19 +0200599 /* Don't set same frequency again */
600 if (longhaul_index == table_index)
601 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700602
Rafał Bilski73e107d2007-05-28 21:56:19 +0200603 if (!can_scale_voltage)
604 longhaul_setstate(table_index);
605 else {
606 /* On test system voltage transitions exceeding single
607 * step up or down were turning motherboard off. Both
608 * "ondemand" and "userspace" are unsafe. C7 is doing
609 * this in hardware, C3 is old and we need to do this
610 * in software. */
611 i = longhaul_index;
612 current_vid = (longhaul_table[longhaul_index].index >> 8) & 0x1f;
613 if (table_index > longhaul_index)
614 dir = 1;
615 while (i != table_index) {
616 vid = (longhaul_table[i].index >> 8) & 0x1f;
617 if (vid != current_vid) {
618 longhaul_setstate(i);
619 current_vid = vid;
620 msleep(200);
621 }
622 if (dir)
623 i++;
624 else
625 i--;
626 }
627 longhaul_setstate(table_index);
628 }
629 longhaul_index = table_index;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700630 return 0;
631}
632
633
634static unsigned int longhaul_get(unsigned int cpu)
635{
636 if (cpu)
637 return 0;
638 return calc_speed(longhaul_get_cpu_mult());
639}
640
Adrian Bunkc4a96c12006-07-09 19:53:08 +0200641static acpi_status longhaul_walk_callback(acpi_handle obj_handle,
642 u32 nesting_level,
643 void *context, void **return_value)
Rafa³ Bilskidadb49d2006-07-03 07:19:05 +0200644{
645 struct acpi_device *d;
646
647 if ( acpi_bus_get_device(obj_handle, &d) ) {
648 return 0;
649 }
650 *return_value = (void *)acpi_driver_data(d);
651 return 1;
652}
Linus Torvalds1da177e2005-04-16 15:20:36 -0700653
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200654/* VIA don't support PM2 reg, but have something similar */
655static int enable_arbiter_disable(void)
656{
657 struct pci_dev *dev;
Rafał Bilski73e107d2007-05-28 21:56:19 +0200658 int status = 1;
rafalbilski@interia.pl7f1be892006-09-24 20:28:13 +0200659 int reg;
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200660 u8 pci_cmd;
661
662 /* Find PLE133 host bridge */
rafalbilski@interia.pl7f1be892006-09-24 20:28:13 +0200663 reg = 0x78;
Rafał Bilskifb48e152007-03-02 20:12:27 +0100664 dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8601_0,
665 NULL);
rafalbilski@interia.pl7f1be892006-09-24 20:28:13 +0200666 /* Find CLE266 host bridge */
667 if (dev == NULL) {
rafalbilski@interia.pl7f1be892006-09-24 20:28:13 +0200668 reg = 0x76;
Rafał Bilskifb48e152007-03-02 20:12:27 +0100669 dev = pci_get_device(PCI_VENDOR_ID_VIA,
670 PCI_DEVICE_ID_VIA_862X_0, NULL);
Rafa³ Bilskidb2fb9d2006-11-30 03:47:41 +0100671 /* Find CN400 V-Link host bridge */
672 if (dev == NULL)
Rafał Bilskifb48e152007-03-02 20:12:27 +0100673 dev = pci_get_device(PCI_VENDOR_ID_VIA, 0x7259, NULL);
rafalbilski@interia.pl7f1be892006-09-24 20:28:13 +0200674 }
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200675 if (dev != NULL) {
676 /* Enable access to port 0x22 */
rafalbilski@interia.pl7f1be892006-09-24 20:28:13 +0200677 pci_read_config_byte(dev, reg, &pci_cmd);
Rafa³ Bilski786f46b2007-02-04 18:43:12 +0100678 if (!(pci_cmd & 1<<7)) {
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200679 pci_cmd |= 1<<7;
rafalbilski@interia.pl7f1be892006-09-24 20:28:13 +0200680 pci_write_config_byte(dev, reg, pci_cmd);
Rafa³ Bilski786f46b2007-02-04 18:43:12 +0100681 pci_read_config_byte(dev, reg, &pci_cmd);
682 if (!(pci_cmd & 1<<7)) {
683 printk(KERN_ERR PFX
684 "Can't enable access to port 0x22.\n");
Rafał Bilskifb48e152007-03-02 20:12:27 +0100685 status = 0;
Rafa³ Bilski786f46b2007-02-04 18:43:12 +0100686 }
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200687 }
Rafał Bilskifb48e152007-03-02 20:12:27 +0100688 pci_dev_put(dev);
689 return status;
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200690 }
691 return 0;
692}
693
Rafał Bilski7d5edcc2007-05-17 22:33:46 +0200694static int longhaul_setup_southbridge(void)
Rafa³ Bilski786f46b2007-02-04 18:43:12 +0100695{
696 struct pci_dev *dev;
697 u8 pci_cmd;
698
699 /* Find VT8235 southbridge */
Rafał Bilskifb48e152007-03-02 20:12:27 +0100700 dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, NULL);
Rafał Bilski920dd0f2007-05-17 22:35:29 +0200701 if (dev == NULL)
702 /* Find VT8237 southbridge */
703 dev = pci_get_device(PCI_VENDOR_ID_VIA,
704 PCI_DEVICE_ID_VIA_8237, NULL);
Rafa³ Bilski786f46b2007-02-04 18:43:12 +0100705 if (dev != NULL) {
706 /* Set transition time to max */
707 pci_read_config_byte(dev, 0xec, &pci_cmd);
708 pci_cmd &= ~(1 << 2);
709 pci_write_config_byte(dev, 0xec, pci_cmd);
710 pci_read_config_byte(dev, 0xe4, &pci_cmd);
711 pci_cmd &= ~(1 << 7);
712 pci_write_config_byte(dev, 0xe4, pci_cmd);
713 pci_read_config_byte(dev, 0xe5, &pci_cmd);
714 pci_cmd |= 1 << 7;
715 pci_write_config_byte(dev, 0xe5, pci_cmd);
Rafał Bilskifb48e152007-03-02 20:12:27 +0100716 pci_dev_put(dev);
Rafa³ Bilski786f46b2007-02-04 18:43:12 +0100717 return 1;
718 }
719 return 0;
720}
721
Linus Torvalds1da177e2005-04-16 15:20:36 -0700722static int __init longhaul_cpu_init(struct cpufreq_policy *policy)
723{
724 struct cpuinfo_x86 *c = cpu_data;
725 char *cpuname=NULL;
726 int ret;
Rafa³ Bilski2b8c0e12007-02-14 22:00:37 +0100727 u32 lo, hi;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700728
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200729 /* Check what we have on this motherboard */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700730 switch (c->x86_model) {
731 case 6:
732 cpu_model = CPU_SAMUEL;
733 cpuname = "C3 'Samuel' [C5A]";
734 longhaul_version = TYPE_LONGHAUL_V1;
735 memcpy (clock_ratio, samuel1_clock_ratio, sizeof(samuel1_clock_ratio));
736 memcpy (eblcr_table, samuel1_eblcr, sizeof(samuel1_eblcr));
737 break;
738
739 case 7:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700740 switch (c->x86_mask) {
741 case 0:
Rafa³ Bilski2b8c0e12007-02-14 22:00:37 +0100742 longhaul_version = TYPE_LONGHAUL_V1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700743 cpu_model = CPU_SAMUEL2;
744 cpuname = "C3 'Samuel 2' [C5B]";
Rafa³ Bilski2b8c0e12007-02-14 22:00:37 +0100745 /* Note, this is not a typo, early Samuel2's had
746 * Samuel1 ratios. */
747 memcpy(clock_ratio, samuel1_clock_ratio,
748 sizeof(samuel1_clock_ratio));
749 memcpy(eblcr_table, samuel2_eblcr,
750 sizeof(samuel2_eblcr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700751 break;
752 case 1 ... 15:
Rafal Bilski07844252007-04-22 12:26:04 +0200753 longhaul_version = TYPE_LONGHAUL_V1;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700754 if (c->x86_mask < 8) {
755 cpu_model = CPU_SAMUEL2;
756 cpuname = "C3 'Samuel 2' [C5B]";
757 } else {
758 cpu_model = CPU_EZRA;
759 cpuname = "C3 'Ezra' [C5C]";
760 }
Rafa³ Bilski2b8c0e12007-02-14 22:00:37 +0100761 memcpy(clock_ratio, ezra_clock_ratio,
762 sizeof(ezra_clock_ratio));
763 memcpy(eblcr_table, ezra_eblcr,
764 sizeof(ezra_eblcr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700765 break;
766 }
767 break;
768
769 case 8:
770 cpu_model = CPU_EZRA_T;
771 cpuname = "C3 'Ezra-T' [C5M]";
772 longhaul_version = TYPE_POWERSAVER;
773 numscales=32;
774 memcpy (clock_ratio, ezrat_clock_ratio, sizeof(ezrat_clock_ratio));
775 memcpy (eblcr_table, ezrat_eblcr, sizeof(ezrat_eblcr));
776 break;
777
778 case 9:
Linus Torvalds1da177e2005-04-16 15:20:36 -0700779 longhaul_version = TYPE_POWERSAVER;
Rafa³ Bilski0d44b2b2007-01-31 23:50:49 +0100780 numscales = 32;
781 memcpy(clock_ratio,
782 nehemiah_clock_ratio,
783 sizeof(nehemiah_clock_ratio));
784 memcpy(eblcr_table, nehemiah_eblcr, sizeof(nehemiah_eblcr));
Linus Torvalds1da177e2005-04-16 15:20:36 -0700785 switch (c->x86_mask) {
786 case 0 ... 1:
Rafa³ Bilski980342a2007-01-31 23:42:47 +0100787 cpu_model = CPU_NEHEMIAH;
Rafa³ Bilskie57501c2007-02-08 23:12:02 +0100788 cpuname = "C3 'Nehemiah A' [C5XLOE]";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700789 break;
790 case 2 ... 4:
Rafa³ Bilski980342a2007-01-31 23:42:47 +0100791 cpu_model = CPU_NEHEMIAH;
Rafa³ Bilskie57501c2007-02-08 23:12:02 +0100792 cpuname = "C3 'Nehemiah B' [C5XLOH]";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700793 break;
794 case 5 ... 15:
Rafa³ Bilski980342a2007-01-31 23:42:47 +0100795 cpu_model = CPU_NEHEMIAH_C;
Rafa³ Bilskie57501c2007-02-08 23:12:02 +0100796 cpuname = "C3 'Nehemiah C' [C5P]";
Linus Torvalds1da177e2005-04-16 15:20:36 -0700797 break;
798 }
799 break;
800
801 default:
802 cpuname = "Unknown";
803 break;
804 }
Rafa³ Bilski2b8c0e12007-02-14 22:00:37 +0100805 /* Check Longhaul ver. 2 */
806 if (longhaul_version == TYPE_LONGHAUL_V2) {
807 rdmsr(MSR_VIA_LONGHAUL, lo, hi);
808 if (lo == 0 && hi == 0)
809 /* Looks like MSR isn't present */
810 longhaul_version = TYPE_LONGHAUL_V1;
811 }
Linus Torvalds1da177e2005-04-16 15:20:36 -0700812
813 printk (KERN_INFO PFX "VIA %s CPU detected. ", cpuname);
814 switch (longhaul_version) {
815 case TYPE_LONGHAUL_V1:
816 case TYPE_LONGHAUL_V2:
817 printk ("Longhaul v%d supported.\n", longhaul_version);
818 break;
819 case TYPE_POWERSAVER:
820 printk ("Powersaver supported.\n");
821 break;
822 };
823
Rafa³ Bilski786f46b2007-02-04 18:43:12 +0100824 /* Doesn't hurt */
Rafał Bilski7d5edcc2007-05-17 22:33:46 +0200825 longhaul_setup_southbridge();
Rafa³ Bilski786f46b2007-02-04 18:43:12 +0100826
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200827 /* Find ACPI data for processor */
Rafa³ Bilski786f46b2007-02-04 18:43:12 +0100828 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
829 ACPI_UINT32_MAX, &longhaul_walk_callback,
830 NULL, (void *)&pr);
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200831
Rafa³ Bilski264166e2006-12-24 14:04:23 +0100832 /* Check ACPI support for C3 state */
Dave Jones7ab77e02007-04-20 15:58:00 -0400833 if (pr != NULL && longhaul_version == TYPE_POWERSAVER) {
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200834 cx = &pr->power.states[ACPI_STATE_C3];
Rafał Bilski7d5edcc2007-05-17 22:33:46 +0200835 if (cx->address > 0 && cx->latency <= 1000)
Rafa³ Bilski264166e2006-12-24 14:04:23 +0100836 longhaul_flags |= USE_ACPI_C3;
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200837 }
Rafa³ Bilski264166e2006-12-24 14:04:23 +0100838 /* Check if northbridge is friendly */
Rafał Bilski7d5edcc2007-05-17 22:33:46 +0200839 if (enable_arbiter_disable())
Rafa³ Bilski264166e2006-12-24 14:04:23 +0100840 longhaul_flags |= USE_NORTHBRIDGE;
Rafał Bilski7d5edcc2007-05-17 22:33:46 +0200841
Rafa³ Bilski264166e2006-12-24 14:04:23 +0100842 /* Check ACPI support for bus master arbiter disable */
Rafał Bilski7d5edcc2007-05-17 22:33:46 +0200843 if (!(longhaul_flags & USE_ACPI_C3
844 || longhaul_flags & USE_NORTHBRIDGE)
845 && ((pr == NULL) || !(pr->flags.bm_control))) {
Rafa³ Bilski264166e2006-12-24 14:04:23 +0100846 printk(KERN_ERR PFX
847 "No ACPI support. Unsupported northbridge.\n");
848 return -ENODEV;
849 }
850
Rafa³ Bilski786f46b2007-02-04 18:43:12 +0100851 if (longhaul_flags & USE_NORTHBRIDGE)
Rafał Bilski7d5edcc2007-05-17 22:33:46 +0200852 printk(KERN_INFO PFX "Using northbridge support.\n");
853 if (longhaul_flags & USE_ACPI_C3)
854 printk(KERN_INFO PFX "Using ACPI support.\n");
Rafa³ Bilski179da8e2006-08-08 19:12:20 +0200855
Linus Torvalds1da177e2005-04-16 15:20:36 -0700856 ret = longhaul_get_ranges();
857 if (ret != 0)
858 return ret;
859
Rafa³ Bilski786f46b2007-02-04 18:43:12 +0100860 if ((longhaul_version != TYPE_LONGHAUL_V1) && (scale_voltage != 0))
Linus Torvalds1da177e2005-04-16 15:20:36 -0700861 longhaul_setup_voltagescaling();
862
863 policy->governor = CPUFREQ_DEFAULT_GOVERNOR;
Dave Jones6778bae2005-05-31 19:03:51 -0700864 policy->cpuinfo.transition_latency = 200000; /* nsec */
Linus Torvalds1da177e2005-04-16 15:20:36 -0700865 policy->cur = calc_speed(longhaul_get_cpu_mult());
866
867 ret = cpufreq_frequency_table_cpuinfo(policy, longhaul_table);
868 if (ret)
869 return ret;
870
871 cpufreq_frequency_table_get_attr(longhaul_table, policy->cpu);
872
873 return 0;
874}
875
876static int __devexit longhaul_cpu_exit(struct cpufreq_policy *policy)
877{
878 cpufreq_frequency_table_put_attr(policy->cpu);
879 return 0;
880}
881
882static struct freq_attr* longhaul_attr[] = {
883 &cpufreq_freq_attr_scaling_available_freqs,
884 NULL,
885};
886
Linus Torvalds221dee22007-02-26 14:55:48 -0800887static struct cpufreq_driver longhaul_driver = {
Linus Torvalds1da177e2005-04-16 15:20:36 -0700888 .verify = longhaul_verify,
889 .target = longhaul_target,
890 .get = longhaul_get,
891 .init = longhaul_cpu_init,
892 .exit = __devexit_p(longhaul_cpu_exit),
893 .name = "longhaul",
894 .owner = THIS_MODULE,
895 .attr = longhaul_attr,
896};
897
898
899static int __init longhaul_init(void)
900{
901 struct cpuinfo_x86 *c = cpu_data;
902
903 if (c->x86_vendor != X86_VENDOR_CENTAUR || c->x86 != 6)
904 return -ENODEV;
905
Rafa³ Bilski48b7bde2006-07-04 17:50:57 +0200906#ifdef CONFIG_SMP
907 if (num_online_cpus() > 1) {
Rafa³ Bilski48b7bde2006-07-04 17:50:57 +0200908 printk(KERN_ERR PFX "More than 1 CPU detected, longhaul disabled.\n");
Dave Jones1cfe2012006-12-28 22:30:16 -0500909 return -ENODEV;
Rafa³ Bilski48b7bde2006-07-04 17:50:57 +0200910 }
911#endif
912#ifdef CONFIG_X86_IO_APIC
913 if (cpu_has_apic) {
914 printk(KERN_ERR PFX "APIC detected. Longhaul is currently broken in this configuration.\n");
915 return -ENODEV;
916 }
917#endif
Linus Torvalds1da177e2005-04-16 15:20:36 -0700918 switch (c->x86_model) {
919 case 6 ... 9:
920 return cpufreq_register_driver(&longhaul_driver);
Dave Jones8ec98222006-12-17 19:07:35 -0500921 case 10:
922 printk(KERN_ERR PFX "Use acpi-cpufreq driver for VIA C7\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700923 default:
Dave Jones928ee512006-12-17 19:09:59 -0500924 ;;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700925 }
926
927 return -ENODEV;
928}
929
930
931static void __exit longhaul_exit(void)
932{
Dave Jones8eebf1a2006-05-30 17:40:16 -0400933 int i;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700934
935 for (i=0; i < numscales; i++) {
936 if (clock_ratio[i] == maxmult) {
937 longhaul_setstate(i);
938 break;
939 }
940 }
941
942 cpufreq_unregister_driver(&longhaul_driver);
943 kfree(longhaul_table);
944}
945
Rafa³ Bilskidb44aaf2006-08-16 01:07:33 +0200946module_param (scale_voltage, int, 0644);
947MODULE_PARM_DESC(scale_voltage, "Scale voltage of processor");
Linus Torvalds1da177e2005-04-16 15:20:36 -0700948
949MODULE_AUTHOR ("Dave Jones <davej@codemonkey.org.uk>");
950MODULE_DESCRIPTION ("Longhaul driver for VIA Cyrix processors.");
951MODULE_LICENSE ("GPL");
952
Rafa³ Bilski0d6daba2006-07-07 08:48:26 +0200953late_initcall(longhaul_init);
Linus Torvalds1da177e2005-04-16 15:20:36 -0700954module_exit(longhaul_exit);