Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 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. |
| 11 | * Version 2 of longhaul is the same as v1, but adds voltage scaling. |
| 12 | * Present in Samuel 2 (steppings 1-7 only) (C5B), and Ezra (C5C) |
| 13 | * voltage scaling support has currently been disabled in this driver |
| 14 | * until we have code that gets it right. |
| 15 | * Version 3 of longhaul got renamed to Powersaver and redesigned |
| 16 | * to use the POWERSAVER MSR at 0x110a. |
| 17 | * It is present in Ezra-T (C5M), Nehemiah (C5X) and above. |
| 18 | * It's pretty much the same feature wise to longhaul v2, though |
| 19 | * there is provision for scaling FSB too, but this doesn't work |
| 20 | * too well in practice so we don't even try to use this. |
| 21 | * |
| 22 | * BIG FAT DISCLAIMER: Work in progress code. Possibly *dangerous* |
| 23 | */ |
| 24 | |
| 25 | #include <linux/kernel.h> |
| 26 | #include <linux/module.h> |
| 27 | #include <linux/moduleparam.h> |
| 28 | #include <linux/init.h> |
| 29 | #include <linux/cpufreq.h> |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 30 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 31 | #include <linux/slab.h> |
| 32 | #include <linux/string.h> |
| 33 | |
| 34 | #include <asm/msr.h> |
| 35 | #include <asm/timex.h> |
| 36 | #include <asm/io.h> |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 37 | #include <asm/acpi.h> |
| 38 | #include <linux/acpi.h> |
| 39 | #include <acpi/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 40 | |
| 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³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 54 | #define CPU_NEHEMIAH_C 6 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 55 | |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 56 | /* Flags */ |
| 57 | #define USE_ACPI_C3 (1 << 1) |
| 58 | #define USE_NORTHBRIDGE (1 << 2) |
| 59 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 60 | static int cpu_model; |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 61 | static unsigned int numscales=16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | static unsigned int fsb; |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 63 | |
| 64 | static struct mV_pos *vrm_mV_table; |
| 65 | static unsigned char *mV_vrm_table; |
| 66 | struct f_msr { |
| 67 | unsigned char vrm; |
| 68 | }; |
| 69 | static struct f_msr f_msr_table[32]; |
| 70 | |
| 71 | static unsigned int highest_speed, lowest_speed; /* kHz */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 72 | static unsigned int minmult, maxmult; |
| 73 | static int can_scale_voltage; |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 74 | static struct acpi_processor *pr = NULL; |
| 75 | static struct acpi_processor_cx *cx = NULL; |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 76 | static u8 longhaul_flags; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 77 | |
| 78 | /* Module parameters */ |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 79 | static int scale_voltage; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 80 | |
| 81 | #define dprintk(msg...) cpufreq_debug_printk(CPUFREQ_DEBUG_DRIVER, "longhaul", msg) |
| 82 | |
| 83 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 84 | /* Clock ratios multiplied by 10 */ |
| 85 | static int clock_ratio[32]; |
| 86 | static int eblcr_table[32]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 87 | static int longhaul_version; |
| 88 | static struct cpufreq_frequency_table *longhaul_table; |
| 89 | |
| 90 | #ifdef CONFIG_CPU_FREQ_DEBUG |
| 91 | static char speedbuffer[8]; |
| 92 | |
| 93 | static char *print_speed(int speed) |
| 94 | { |
Dave Jones | e2aa873 | 2006-05-30 17:37:15 -0400 | [diff] [blame] | 95 | if (speed < 1000) { |
| 96 | snprintf(speedbuffer, sizeof(speedbuffer),"%dMHz", speed); |
| 97 | return speedbuffer; |
| 98 | } |
| 99 | |
| 100 | if (speed%1000 == 0) |
| 101 | snprintf(speedbuffer, sizeof(speedbuffer), |
| 102 | "%dGHz", speed/1000); |
| 103 | else |
| 104 | snprintf(speedbuffer, sizeof(speedbuffer), |
| 105 | "%d.%dGHz", speed/1000, (speed%1000)/100); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | return speedbuffer; |
| 108 | } |
| 109 | #endif |
| 110 | |
| 111 | |
| 112 | static unsigned int calc_speed(int mult) |
| 113 | { |
| 114 | int khz; |
| 115 | khz = (mult/10)*fsb; |
| 116 | if (mult%10) |
| 117 | khz += fsb/2; |
| 118 | khz *= 1000; |
| 119 | return khz; |
| 120 | } |
| 121 | |
| 122 | |
| 123 | static int longhaul_get_cpu_mult(void) |
| 124 | { |
| 125 | unsigned long invalue=0,lo, hi; |
| 126 | |
| 127 | rdmsr (MSR_IA32_EBL_CR_POWERON, lo, hi); |
| 128 | invalue = (lo & (1<<22|1<<23|1<<24|1<<25)) >>22; |
| 129 | if (longhaul_version==TYPE_LONGHAUL_V2 || longhaul_version==TYPE_POWERSAVER) { |
| 130 | if (lo & (1<<27)) |
| 131 | invalue+=16; |
| 132 | } |
| 133 | return eblcr_table[invalue]; |
| 134 | } |
| 135 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 136 | /* For processor with BCR2 MSR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 138 | static void do_longhaul1(unsigned int clock_ratio_index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 139 | { |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 140 | union msr_bcr2 bcr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 141 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 142 | rdmsrl(MSR_VIA_BCR2, bcr2.val); |
| 143 | /* Enable software clock multiplier */ |
| 144 | bcr2.bits.ESOFTBF = 1; |
| 145 | bcr2.bits.CLOCKMUL = clock_ratio_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 146 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 147 | /* Sync to timer tick */ |
Zachary Amsden | 4bb0d3e | 2005-09-03 15:56:36 -0700 | [diff] [blame] | 148 | safe_halt(); |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 149 | /* Change frequency on next halt or sleep */ |
| 150 | wrmsrl(MSR_VIA_BCR2, bcr2.val); |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 151 | /* Invoke transition */ |
| 152 | ACPI_FLUSH_CPU_CACHE(); |
| 153 | halt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 154 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 155 | /* Disable software clock multiplier */ |
Dave Jones | 3be6a48 | 2005-05-31 19:03:51 -0700 | [diff] [blame] | 156 | local_irq_disable(); |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 157 | rdmsrl(MSR_VIA_BCR2, bcr2.val); |
| 158 | bcr2.bits.ESOFTBF = 0; |
| 159 | wrmsrl(MSR_VIA_BCR2, bcr2.val); |
| 160 | } |
Dave Jones | 3be6a48 | 2005-05-31 19:03:51 -0700 | [diff] [blame] | 161 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 162 | /* For processor with Longhaul MSR */ |
Dave Jones | 1174631 | 2005-05-31 19:03:51 -0700 | [diff] [blame] | 163 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 164 | static void do_powersaver(int cx_address, unsigned int clock_ratio_index) |
| 165 | { |
| 166 | union msr_longhaul longhaul; |
| 167 | u32 t; |
Dave Jones | 3be6a48 | 2005-05-31 19:03:51 -0700 | [diff] [blame] | 168 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 169 | rdmsrl(MSR_VIA_LONGHAUL, longhaul.val); |
| 170 | longhaul.bits.RevisionKey = longhaul.bits.RevisionID; |
| 171 | longhaul.bits.SoftBusRatio = clock_ratio_index & 0xf; |
| 172 | longhaul.bits.SoftBusRatio4 = (clock_ratio_index & 0x10) >> 4; |
Rafa³ Bilski | eb23c75 | 2006-07-09 21:47:04 +0200 | [diff] [blame] | 173 | longhaul.bits.EnableSoftBusRatio = 1; |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 174 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 175 | if (can_scale_voltage) { |
| 176 | longhaul.bits.SoftVID = f_msr_table[clock_ratio_index].vrm; |
| 177 | longhaul.bits.EnableSoftVID = 1; |
| 178 | } |
| 179 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 180 | /* Sync to timer tick */ |
| 181 | safe_halt(); |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 182 | /* Change frequency on next halt or sleep */ |
| 183 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 184 | if (!cx_address) { |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 185 | ACPI_FLUSH_CPU_CACHE(); |
| 186 | /* Invoke C1 */ |
| 187 | halt(); |
| 188 | } else { |
| 189 | ACPI_FLUSH_CPU_CACHE(); |
| 190 | /* Invoke C3 */ |
| 191 | inb(cx_address); |
| 192 | /* Dummy op - must do something useless after P_LVL3 read */ |
| 193 | t = inl(acpi_fadt.xpm_tmr_blk.address); |
| 194 | } |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 195 | /* Disable bus ratio bit */ |
| 196 | local_irq_disable(); |
| 197 | longhaul.bits.RevisionKey = longhaul.bits.RevisionID; |
| 198 | longhaul.bits.EnableSoftBusRatio = 0; |
| 199 | longhaul.bits.EnableSoftBSEL = 0; |
| 200 | longhaul.bits.EnableSoftVID = 0; |
| 201 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 202 | } |
| 203 | |
| 204 | /** |
| 205 | * longhaul_set_cpu_frequency() |
| 206 | * @clock_ratio_index : bitpattern of the new multiplier. |
| 207 | * |
| 208 | * Sets a new clock ratio. |
| 209 | */ |
| 210 | |
| 211 | static void longhaul_setstate(unsigned int clock_ratio_index) |
| 212 | { |
| 213 | int speed, mult; |
| 214 | struct cpufreq_freqs freqs; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 215 | static unsigned int old_ratio=-1; |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 216 | unsigned long flags; |
| 217 | unsigned int pic1_mask, pic2_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 218 | |
| 219 | if (old_ratio == clock_ratio_index) |
| 220 | return; |
| 221 | old_ratio = clock_ratio_index; |
| 222 | |
| 223 | mult = clock_ratio[clock_ratio_index]; |
| 224 | if (mult == -1) |
| 225 | return; |
| 226 | |
| 227 | speed = calc_speed(mult); |
| 228 | if ((speed > highest_speed) || (speed < lowest_speed)) |
| 229 | return; |
| 230 | |
| 231 | freqs.old = calc_speed(longhaul_get_cpu_mult()); |
| 232 | freqs.new = speed; |
| 233 | freqs.cpu = 0; /* longhaul.c is UP only driver */ |
| 234 | |
| 235 | cpufreq_notify_transition(&freqs, CPUFREQ_PRECHANGE); |
| 236 | |
| 237 | dprintk ("Setting to FSB:%dMHz Mult:%d.%dx (%s)\n", |
| 238 | fsb, mult/10, mult%10, print_speed(speed/1000)); |
| 239 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 240 | preempt_disable(); |
| 241 | local_irq_save(flags); |
| 242 | |
| 243 | pic2_mask = inb(0xA1); |
| 244 | pic1_mask = inb(0x21); /* works on C3. save mask. */ |
| 245 | outb(0xFF,0xA1); /* Overkill */ |
| 246 | outb(0xFE,0x21); /* TMR0 only */ |
| 247 | |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 248 | if (longhaul_flags & USE_NORTHBRIDGE) { |
| 249 | /* Disable AGP and PCI arbiters */ |
| 250 | outb(3, 0x22); |
| 251 | } else if ((pr != NULL) && pr->flags.bm_control) { |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 252 | /* Disable bus master arbitration */ |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 253 | acpi_set_register(ACPI_BITREG_ARB_DISABLE, 1, |
| 254 | ACPI_MTX_DO_NOT_LOCK); |
| 255 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | switch (longhaul_version) { |
| 257 | |
| 258 | /* |
| 259 | * Longhaul v1. (Samuel[C5A] and Samuel2 stepping 0[C5B]) |
| 260 | * Software controlled multipliers only. |
| 261 | * |
| 262 | * *NB* Until we get voltage scaling working v1 & v2 are the same code. |
| 263 | * Longhaul v2 appears in Samuel2 Steppings 1->7 [C5b] and Ezra [C5C] |
| 264 | */ |
| 265 | case TYPE_LONGHAUL_V1: |
| 266 | case TYPE_LONGHAUL_V2: |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 267 | do_longhaul1(clock_ratio_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 268 | break; |
| 269 | |
| 270 | /* |
| 271 | * Longhaul v3 (aka Powersaver). (Ezra-T [C5M] & Nehemiah [C5N]) |
| 272 | * We can scale voltage with this too, but that's currently |
| 273 | * disabled until we come up with a decent 'match freq to voltage' |
| 274 | * algorithm. |
| 275 | * When we add voltage scaling, we will also need to do the |
| 276 | * voltage/freq setting in order depending on the direction |
| 277 | * of scaling (like we do in powernow-k7.c) |
| 278 | * Nehemiah can do FSB scaling too, but this has never been proven |
| 279 | * to work in practice. |
| 280 | */ |
| 281 | case TYPE_POWERSAVER: |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 282 | if (longhaul_flags & USE_ACPI_C3) { |
| 283 | /* Don't allow wakeup */ |
| 284 | acpi_set_register(ACPI_BITREG_BUS_MASTER_RLD, 0, |
| 285 | ACPI_MTX_DO_NOT_LOCK); |
| 286 | do_powersaver(cx->address, clock_ratio_index); |
| 287 | } else { |
| 288 | do_powersaver(0, clock_ratio_index); |
| 289 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 290 | break; |
| 291 | } |
| 292 | |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 293 | if (longhaul_flags & USE_NORTHBRIDGE) { |
| 294 | /* Enable arbiters */ |
| 295 | outb(0, 0x22); |
| 296 | } else if ((pr != NULL) && pr->flags.bm_control) { |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 297 | /* Enable bus master arbitration */ |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 298 | acpi_set_register(ACPI_BITREG_ARB_DISABLE, 0, |
| 299 | ACPI_MTX_DO_NOT_LOCK); |
| 300 | } |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 301 | outb(pic2_mask,0xA1); /* restore mask */ |
| 302 | outb(pic1_mask,0x21); |
| 303 | |
| 304 | local_irq_restore(flags); |
| 305 | preempt_enable(); |
| 306 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 307 | cpufreq_notify_transition(&freqs, CPUFREQ_POSTCHANGE); |
| 308 | } |
| 309 | |
| 310 | /* |
| 311 | * Centaur decided to make life a little more tricky. |
| 312 | * Only longhaul v1 is allowed to read EBLCR BSEL[0:1]. |
| 313 | * Samuel2 and above have to try and guess what the FSB is. |
| 314 | * We do this by assuming we booted at maximum multiplier, and interpolate |
| 315 | * between that value multiplied by possible FSBs and cpu_mhz which |
| 316 | * was calculated at boot time. Really ugly, but no other way to do this. |
| 317 | */ |
| 318 | |
| 319 | #define ROUNDING 0xf |
| 320 | |
Rafa³ Bilski | 24ebead | 2007-01-01 23:49:34 +0100 | [diff] [blame] | 321 | static int guess_fsb(int mult) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 322 | { |
Rafa³ Bilski | 46ef955 | 2007-02-04 15:58:46 +0100 | [diff] [blame^] | 323 | int speed = cpu_khz / 1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 324 | int i; |
Rafa³ Bilski | 46ef955 | 2007-02-04 15:58:46 +0100 | [diff] [blame^] | 325 | int speeds[] = { 666, 1000, 1333, 2000 }; |
| 326 | int f_max, f_min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 327 | |
Rafa³ Bilski | 46ef955 | 2007-02-04 15:58:46 +0100 | [diff] [blame^] | 328 | for (i = 0; i < 4; i++) { |
| 329 | f_max = ((speeds[i] * mult) + 50) / 100; |
| 330 | f_max += (ROUNDING / 2); |
| 331 | f_min = f_max - ROUNDING; |
| 332 | if ((speed <= f_max) && (speed >= f_min)) |
| 333 | return speeds[i] / 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 334 | } |
| 335 | return 0; |
| 336 | } |
| 337 | |
| 338 | |
| 339 | static int __init longhaul_get_ranges(void) |
| 340 | { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 341 | unsigned int j, k = 0; |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 342 | int mult; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 343 | |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 344 | /* Get current frequency */ |
| 345 | mult = longhaul_get_cpu_mult(); |
| 346 | if (mult == -1) { |
| 347 | printk(KERN_INFO PFX "Invalid (reserved) multiplier!\n"); |
| 348 | return -EINVAL; |
| 349 | } |
| 350 | fsb = guess_fsb(mult); |
| 351 | if (fsb == 0) { |
| 352 | printk(KERN_INFO PFX "Invalid (reserved) FSB!\n"); |
| 353 | return -EINVAL; |
| 354 | } |
| 355 | /* Get max multiplier - as we always did. |
| 356 | * Longhaul MSR is usefull only when voltage scaling is enabled. |
| 357 | * C3 is booting at max anyway. */ |
| 358 | maxmult = mult; |
| 359 | /* Get min multiplier */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 360 | switch (longhaul_version) { |
| 361 | case TYPE_LONGHAUL_V1: |
| 362 | case TYPE_LONGHAUL_V2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 363 | minmult = 30; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 364 | break; |
| 365 | |
| 366 | case TYPE_POWERSAVER: |
| 367 | /* Ezra-T */ |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 368 | if (cpu_model == CPU_EZRA_T) |
Rafa³ Bilski | 24ebead | 2007-01-01 23:49:34 +0100 | [diff] [blame] | 369 | minmult = 30; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 370 | /* Nehemiah */ |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 371 | else if (cpu_model == CPU_NEHEMIAH) |
| 372 | minmult = 50; |
| 373 | /* Nehemiah C */ |
| 374 | else if (cpu_model == CPU_NEHEMIAH_C) |
| 375 | minmult = 40; |
| 376 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 377 | } |
| 378 | |
| 379 | dprintk ("MinMult:%d.%dx MaxMult:%d.%dx\n", |
| 380 | minmult/10, minmult%10, maxmult/10, maxmult%10); |
| 381 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 382 | highest_speed = calc_speed(maxmult); |
| 383 | lowest_speed = calc_speed(minmult); |
| 384 | dprintk ("FSB:%dMHz Lowest speed: %s Highest speed:%s\n", fsb, |
| 385 | print_speed(lowest_speed/1000), |
| 386 | print_speed(highest_speed/1000)); |
| 387 | |
| 388 | if (lowest_speed == highest_speed) { |
| 389 | printk (KERN_INFO PFX "highestspeed == lowest, aborting.\n"); |
| 390 | return -EINVAL; |
| 391 | } |
| 392 | if (lowest_speed > highest_speed) { |
| 393 | printk (KERN_INFO PFX "nonsense! lowest (%d > %d) !\n", |
| 394 | lowest_speed, highest_speed); |
| 395 | return -EINVAL; |
| 396 | } |
| 397 | |
| 398 | longhaul_table = kmalloc((numscales + 1) * sizeof(struct cpufreq_frequency_table), GFP_KERNEL); |
| 399 | if(!longhaul_table) |
| 400 | return -ENOMEM; |
| 401 | |
| 402 | for (j=0; j < numscales; j++) { |
| 403 | unsigned int ratio; |
| 404 | ratio = clock_ratio[j]; |
| 405 | if (ratio == -1) |
| 406 | continue; |
| 407 | if (ratio > maxmult || ratio < minmult) |
| 408 | continue; |
| 409 | longhaul_table[k].frequency = calc_speed(ratio); |
| 410 | longhaul_table[k].index = j; |
| 411 | k++; |
| 412 | } |
| 413 | |
| 414 | longhaul_table[k].frequency = CPUFREQ_TABLE_END; |
| 415 | if (!k) { |
| 416 | kfree (longhaul_table); |
| 417 | return -EINVAL; |
| 418 | } |
| 419 | |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | |
| 424 | static void __init longhaul_setup_voltagescaling(void) |
| 425 | { |
| 426 | union msr_longhaul longhaul; |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 427 | struct mV_pos minvid, maxvid; |
| 428 | unsigned int j, speed, pos, kHz_step, numvscales; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 430 | rdmsrl(MSR_VIA_LONGHAUL, longhaul.val); |
| 431 | if (!(longhaul.bits.RevisionID & 1)) { |
| 432 | printk(KERN_INFO PFX "Voltage scaling not supported by CPU.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 433 | return; |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 434 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 435 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 436 | if (!longhaul.bits.VRMRev) { |
| 437 | printk (KERN_INFO PFX "VRM 8.5\n"); |
| 438 | vrm_mV_table = &vrm85_mV[0]; |
| 439 | mV_vrm_table = &mV_vrm85[0]; |
| 440 | } else { |
| 441 | printk (KERN_INFO PFX "Mobile VRM\n"); |
| 442 | vrm_mV_table = &mobilevrm_mV[0]; |
| 443 | mV_vrm_table = &mV_mobilevrm[0]; |
| 444 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 445 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 446 | minvid = vrm_mV_table[longhaul.bits.MinimumVID]; |
| 447 | maxvid = vrm_mV_table[longhaul.bits.MaximumVID]; |
| 448 | numvscales = maxvid.pos - minvid.pos + 1; |
| 449 | kHz_step = (highest_speed - lowest_speed) / numvscales; |
| 450 | |
| 451 | if (minvid.mV == 0 || maxvid.mV == 0 || minvid.mV > maxvid.mV) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | printk (KERN_INFO PFX "Bogus values Min:%d.%03d Max:%d.%03d. " |
| 453 | "Voltage scaling disabled.\n", |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 454 | minvid.mV/1000, minvid.mV%1000, maxvid.mV/1000, maxvid.mV%1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 455 | return; |
| 456 | } |
| 457 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 458 | if (minvid.mV == maxvid.mV) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | printk (KERN_INFO PFX "Claims to support voltage scaling but min & max are " |
| 460 | "both %d.%03d. Voltage scaling disabled\n", |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 461 | maxvid.mV/1000, maxvid.mV%1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | return; |
| 463 | } |
| 464 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 465 | printk(KERN_INFO PFX "Max VID=%d.%03d Min VID=%d.%03d, %d possible voltage scales\n", |
| 466 | maxvid.mV/1000, maxvid.mV%1000, |
| 467 | minvid.mV/1000, minvid.mV%1000, |
| 468 | numvscales); |
| 469 | |
| 470 | j = 0; |
| 471 | while (longhaul_table[j].frequency != CPUFREQ_TABLE_END) { |
| 472 | speed = longhaul_table[j].frequency; |
| 473 | pos = (speed - lowest_speed) / kHz_step + minvid.pos; |
| 474 | f_msr_table[longhaul_table[j].index].vrm = mV_vrm_table[pos]; |
| 475 | j++; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | } |
| 477 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 478 | can_scale_voltage = 1; |
| 479 | } |
| 480 | |
| 481 | |
| 482 | static int longhaul_verify(struct cpufreq_policy *policy) |
| 483 | { |
| 484 | return cpufreq_frequency_table_verify(policy, longhaul_table); |
| 485 | } |
| 486 | |
| 487 | |
| 488 | static int longhaul_target(struct cpufreq_policy *policy, |
| 489 | unsigned int target_freq, unsigned int relation) |
| 490 | { |
| 491 | unsigned int table_index = 0; |
| 492 | unsigned int new_clock_ratio = 0; |
| 493 | |
| 494 | if (cpufreq_frequency_table_target(policy, longhaul_table, target_freq, relation, &table_index)) |
| 495 | return -EINVAL; |
| 496 | |
| 497 | new_clock_ratio = longhaul_table[table_index].index & 0xFF; |
| 498 | |
| 499 | longhaul_setstate(new_clock_ratio); |
| 500 | |
| 501 | return 0; |
| 502 | } |
| 503 | |
| 504 | |
| 505 | static unsigned int longhaul_get(unsigned int cpu) |
| 506 | { |
| 507 | if (cpu) |
| 508 | return 0; |
| 509 | return calc_speed(longhaul_get_cpu_mult()); |
| 510 | } |
| 511 | |
Adrian Bunk | c4a96c1 | 2006-07-09 19:53:08 +0200 | [diff] [blame] | 512 | static acpi_status longhaul_walk_callback(acpi_handle obj_handle, |
| 513 | u32 nesting_level, |
| 514 | void *context, void **return_value) |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 515 | { |
| 516 | struct acpi_device *d; |
| 517 | |
| 518 | if ( acpi_bus_get_device(obj_handle, &d) ) { |
| 519 | return 0; |
| 520 | } |
| 521 | *return_value = (void *)acpi_driver_data(d); |
| 522 | return 1; |
| 523 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 525 | /* VIA don't support PM2 reg, but have something similar */ |
| 526 | static int enable_arbiter_disable(void) |
| 527 | { |
| 528 | struct pci_dev *dev; |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 529 | int reg; |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 530 | u8 pci_cmd; |
| 531 | |
| 532 | /* Find PLE133 host bridge */ |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 533 | reg = 0x78; |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 534 | dev = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8601_0, NULL); |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 535 | /* Find CLE266 host bridge */ |
| 536 | if (dev == NULL) { |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 537 | reg = 0x76; |
Rafa³ Bilski | eed7d41 | 2006-09-27 08:25:27 +0200 | [diff] [blame] | 538 | dev = pci_find_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_862X_0, NULL); |
Rafa³ Bilski | db2fb9d | 2006-11-30 03:47:41 +0100 | [diff] [blame] | 539 | /* Find CN400 V-Link host bridge */ |
| 540 | if (dev == NULL) |
| 541 | dev = pci_find_device(PCI_VENDOR_ID_VIA, 0x7259, NULL); |
| 542 | |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 543 | } |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 544 | if (dev != NULL) { |
| 545 | /* Enable access to port 0x22 */ |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 546 | pci_read_config_byte(dev, reg, &pci_cmd); |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 547 | if ( !(pci_cmd & 1<<7) ) { |
| 548 | pci_cmd |= 1<<7; |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 549 | pci_write_config_byte(dev, reg, pci_cmd); |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 550 | } |
| 551 | return 1; |
| 552 | } |
| 553 | return 0; |
| 554 | } |
| 555 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | static int __init longhaul_cpu_init(struct cpufreq_policy *policy) |
| 557 | { |
| 558 | struct cpuinfo_x86 *c = cpu_data; |
| 559 | char *cpuname=NULL; |
| 560 | int ret; |
| 561 | |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 562 | /* Check what we have on this motherboard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 563 | switch (c->x86_model) { |
| 564 | case 6: |
| 565 | cpu_model = CPU_SAMUEL; |
| 566 | cpuname = "C3 'Samuel' [C5A]"; |
| 567 | longhaul_version = TYPE_LONGHAUL_V1; |
| 568 | memcpy (clock_ratio, samuel1_clock_ratio, sizeof(samuel1_clock_ratio)); |
| 569 | memcpy (eblcr_table, samuel1_eblcr, sizeof(samuel1_eblcr)); |
| 570 | break; |
| 571 | |
| 572 | case 7: |
| 573 | longhaul_version = TYPE_LONGHAUL_V1; |
| 574 | switch (c->x86_mask) { |
| 575 | case 0: |
| 576 | cpu_model = CPU_SAMUEL2; |
| 577 | cpuname = "C3 'Samuel 2' [C5B]"; |
| 578 | /* Note, this is not a typo, early Samuel2's had Samuel1 ratios. */ |
| 579 | memcpy (clock_ratio, samuel1_clock_ratio, sizeof(samuel1_clock_ratio)); |
| 580 | memcpy (eblcr_table, samuel2_eblcr, sizeof(samuel2_eblcr)); |
| 581 | break; |
| 582 | case 1 ... 15: |
| 583 | if (c->x86_mask < 8) { |
| 584 | cpu_model = CPU_SAMUEL2; |
| 585 | cpuname = "C3 'Samuel 2' [C5B]"; |
| 586 | } else { |
| 587 | cpu_model = CPU_EZRA; |
| 588 | cpuname = "C3 'Ezra' [C5C]"; |
| 589 | } |
| 590 | memcpy (clock_ratio, ezra_clock_ratio, sizeof(ezra_clock_ratio)); |
| 591 | memcpy (eblcr_table, ezra_eblcr, sizeof(ezra_eblcr)); |
| 592 | break; |
| 593 | } |
| 594 | break; |
| 595 | |
| 596 | case 8: |
| 597 | cpu_model = CPU_EZRA_T; |
| 598 | cpuname = "C3 'Ezra-T' [C5M]"; |
| 599 | longhaul_version = TYPE_POWERSAVER; |
| 600 | numscales=32; |
| 601 | memcpy (clock_ratio, ezrat_clock_ratio, sizeof(ezrat_clock_ratio)); |
| 602 | memcpy (eblcr_table, ezrat_eblcr, sizeof(ezrat_eblcr)); |
| 603 | break; |
| 604 | |
| 605 | case 9: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 606 | longhaul_version = TYPE_POWERSAVER; |
Rafa³ Bilski | 0d44b2b | 2007-01-31 23:50:49 +0100 | [diff] [blame] | 607 | numscales = 32; |
| 608 | memcpy(clock_ratio, |
| 609 | nehemiah_clock_ratio, |
| 610 | sizeof(nehemiah_clock_ratio)); |
| 611 | memcpy(eblcr_table, nehemiah_eblcr, sizeof(nehemiah_eblcr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 612 | switch (c->x86_mask) { |
| 613 | case 0 ... 1: |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 614 | cpu_model = CPU_NEHEMIAH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | cpuname = "C3 'Nehemiah A' [C5N]"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 616 | break; |
| 617 | case 2 ... 4: |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 618 | cpu_model = CPU_NEHEMIAH; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 619 | cpuname = "C3 'Nehemiah B' [C5N]"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | break; |
| 621 | case 5 ... 15: |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 622 | cpu_model = CPU_NEHEMIAH_C; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 623 | cpuname = "C3 'Nehemiah C' [C5N]"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | break; |
| 625 | } |
| 626 | break; |
| 627 | |
| 628 | default: |
| 629 | cpuname = "Unknown"; |
| 630 | break; |
| 631 | } |
| 632 | |
| 633 | printk (KERN_INFO PFX "VIA %s CPU detected. ", cpuname); |
| 634 | switch (longhaul_version) { |
| 635 | case TYPE_LONGHAUL_V1: |
| 636 | case TYPE_LONGHAUL_V2: |
| 637 | printk ("Longhaul v%d supported.\n", longhaul_version); |
| 638 | break; |
| 639 | case TYPE_POWERSAVER: |
| 640 | printk ("Powersaver supported.\n"); |
| 641 | break; |
| 642 | }; |
| 643 | |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 644 | /* Find ACPI data for processor */ |
| 645 | acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, ACPI_UINT32_MAX, |
| 646 | &longhaul_walk_callback, NULL, (void *)&pr); |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 647 | |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 648 | /* Check ACPI support for C3 state */ |
| 649 | if ((pr != NULL) && (longhaul_version == TYPE_POWERSAVER)) { |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 650 | cx = &pr->power.states[ACPI_STATE_C3]; |
Rafa³ Bilski | 1479672 | 2007-01-19 22:28:22 +0100 | [diff] [blame] | 651 | if (cx->address > 0 && cx->latency <= 1000) { |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 652 | longhaul_flags |= USE_ACPI_C3; |
Rafa³ Bilski | eed7d41 | 2006-09-27 08:25:27 +0200 | [diff] [blame] | 653 | goto print_support_type; |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 654 | } |
| 655 | } |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 656 | /* Check if northbridge is friendly */ |
| 657 | if (enable_arbiter_disable()) { |
| 658 | longhaul_flags |= USE_NORTHBRIDGE; |
| 659 | goto print_support_type; |
Rafa³ Bilski | eed7d41 | 2006-09-27 08:25:27 +0200 | [diff] [blame] | 660 | } |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 661 | |
| 662 | /* No ACPI C3 or we can't use it */ |
| 663 | /* Check ACPI support for bus master arbiter disable */ |
| 664 | if ((pr == NULL) || !(pr->flags.bm_control)) { |
| 665 | printk(KERN_ERR PFX |
| 666 | "No ACPI support. Unsupported northbridge.\n"); |
| 667 | return -ENODEV; |
| 668 | } |
| 669 | |
Rafa³ Bilski | eed7d41 | 2006-09-27 08:25:27 +0200 | [diff] [blame] | 670 | print_support_type: |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 671 | if (!(longhaul_flags & USE_NORTHBRIDGE)) { |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 672 | printk (KERN_INFO PFX "Using ACPI support.\n"); |
| 673 | } else { |
| 674 | printk (KERN_INFO PFX "Using northbridge support.\n"); |
| 675 | } |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 676 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 677 | ret = longhaul_get_ranges(); |
| 678 | if (ret != 0) |
| 679 | return ret; |
| 680 | |
| 681 | if ((longhaul_version==TYPE_LONGHAUL_V2 || longhaul_version==TYPE_POWERSAVER) && |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 682 | (scale_voltage != 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 683 | longhaul_setup_voltagescaling(); |
| 684 | |
| 685 | policy->governor = CPUFREQ_DEFAULT_GOVERNOR; |
Dave Jones | 6778bae | 2005-05-31 19:03:51 -0700 | [diff] [blame] | 686 | policy->cpuinfo.transition_latency = 200000; /* nsec */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 687 | policy->cur = calc_speed(longhaul_get_cpu_mult()); |
| 688 | |
| 689 | ret = cpufreq_frequency_table_cpuinfo(policy, longhaul_table); |
| 690 | if (ret) |
| 691 | return ret; |
| 692 | |
| 693 | cpufreq_frequency_table_get_attr(longhaul_table, policy->cpu); |
| 694 | |
| 695 | return 0; |
| 696 | } |
| 697 | |
| 698 | static int __devexit longhaul_cpu_exit(struct cpufreq_policy *policy) |
| 699 | { |
| 700 | cpufreq_frequency_table_put_attr(policy->cpu); |
| 701 | return 0; |
| 702 | } |
| 703 | |
| 704 | static struct freq_attr* longhaul_attr[] = { |
| 705 | &cpufreq_freq_attr_scaling_available_freqs, |
| 706 | NULL, |
| 707 | }; |
| 708 | |
| 709 | static struct cpufreq_driver longhaul_driver = { |
| 710 | .verify = longhaul_verify, |
| 711 | .target = longhaul_target, |
| 712 | .get = longhaul_get, |
| 713 | .init = longhaul_cpu_init, |
| 714 | .exit = __devexit_p(longhaul_cpu_exit), |
| 715 | .name = "longhaul", |
| 716 | .owner = THIS_MODULE, |
| 717 | .attr = longhaul_attr, |
| 718 | }; |
| 719 | |
| 720 | |
| 721 | static int __init longhaul_init(void) |
| 722 | { |
| 723 | struct cpuinfo_x86 *c = cpu_data; |
| 724 | |
| 725 | if (c->x86_vendor != X86_VENDOR_CENTAUR || c->x86 != 6) |
| 726 | return -ENODEV; |
| 727 | |
Rafa³ Bilski | 48b7bde | 2006-07-04 17:50:57 +0200 | [diff] [blame] | 728 | #ifdef CONFIG_SMP |
| 729 | if (num_online_cpus() > 1) { |
Rafa³ Bilski | 48b7bde | 2006-07-04 17:50:57 +0200 | [diff] [blame] | 730 | printk(KERN_ERR PFX "More than 1 CPU detected, longhaul disabled.\n"); |
Dave Jones | 1cfe201 | 2006-12-28 22:30:16 -0500 | [diff] [blame] | 731 | return -ENODEV; |
Rafa³ Bilski | 48b7bde | 2006-07-04 17:50:57 +0200 | [diff] [blame] | 732 | } |
| 733 | #endif |
| 734 | #ifdef CONFIG_X86_IO_APIC |
| 735 | if (cpu_has_apic) { |
| 736 | printk(KERN_ERR PFX "APIC detected. Longhaul is currently broken in this configuration.\n"); |
| 737 | return -ENODEV; |
| 738 | } |
| 739 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 740 | switch (c->x86_model) { |
| 741 | case 6 ... 9: |
| 742 | return cpufreq_register_driver(&longhaul_driver); |
Dave Jones | 8ec9822 | 2006-12-17 19:07:35 -0500 | [diff] [blame] | 743 | case 10: |
| 744 | printk(KERN_ERR PFX "Use acpi-cpufreq driver for VIA C7\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 745 | default: |
Dave Jones | 928ee51 | 2006-12-17 19:09:59 -0500 | [diff] [blame] | 746 | ;; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 747 | } |
| 748 | |
| 749 | return -ENODEV; |
| 750 | } |
| 751 | |
| 752 | |
| 753 | static void __exit longhaul_exit(void) |
| 754 | { |
Dave Jones | 8eebf1a | 2006-05-30 17:40:16 -0400 | [diff] [blame] | 755 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 756 | |
| 757 | for (i=0; i < numscales; i++) { |
| 758 | if (clock_ratio[i] == maxmult) { |
| 759 | longhaul_setstate(i); |
| 760 | break; |
| 761 | } |
| 762 | } |
| 763 | |
| 764 | cpufreq_unregister_driver(&longhaul_driver); |
| 765 | kfree(longhaul_table); |
| 766 | } |
| 767 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 768 | module_param (scale_voltage, int, 0644); |
| 769 | MODULE_PARM_DESC(scale_voltage, "Scale voltage of processor"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 770 | |
| 771 | MODULE_AUTHOR ("Dave Jones <davej@codemonkey.org.uk>"); |
| 772 | MODULE_DESCRIPTION ("Longhaul driver for VIA Cyrix processors."); |
| 773 | MODULE_LICENSE ("GPL"); |
| 774 | |
Rafa³ Bilski | 0d6daba | 2006-07-07 08:48:26 +0200 | [diff] [blame] | 775 | late_initcall(longhaul_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 776 | module_exit(longhaul_exit); |