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