Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
Dave Jones | d5e80b4 | 2014-12-19 11:20:43 -0500 | [diff] [blame] | 2 | * (C) 2001-2004 Dave Jones. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 11 | * 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | * Version 3 of longhaul got renamed to Powersaver and redesigned |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 15 | * to use only the POWERSAVER MSR at 0x110a. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 16 | * 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³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 29 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | #include <linux/slab.h> |
| 31 | #include <linux/string.h> |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 32 | #include <linux/delay.h> |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 33 | #include <linux/timex.h> |
| 34 | #include <linux/io.h> |
| 35 | #include <linux/acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 36 | |
| 37 | #include <asm/msr.h> |
Andi Kleen | fa8031a | 2012-01-26 00:09:12 +0100 | [diff] [blame] | 38 | #include <asm/cpu_device_id.h> |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 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; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [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 | |
Dave Jones | bd5ab26 | 2007-02-22 19:11:16 -0500 | [diff] [blame] | 64 | static const struct mV_pos *vrm_mV_table; |
| 65 | static const unsigned char *mV_vrm_table; |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 66 | |
| 67 | static unsigned int highest_speed, lowest_speed; /* kHz */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | static unsigned int minmult, maxmult; |
| 69 | static int can_scale_voltage; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 70 | static struct acpi_processor *pr; |
| 71 | static struct acpi_processor_cx *cx; |
Rafał Bilski | 275bc6b | 2007-06-05 22:08:50 +0200 | [diff] [blame] | 72 | static u32 acpi_regs_addr; |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 73 | static u8 longhaul_flags; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 74 | static unsigned int longhaul_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 75 | |
| 76 | /* Module parameters */ |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 77 | static int scale_voltage; |
Rafał Bilski | 905497c | 2007-07-08 21:51:26 +0200 | [diff] [blame] | 78 | static int disable_acpi_c3; |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 79 | static int revid_errata; |
Rafał Bilski | b5811bc | 2012-12-15 00:45:02 +0100 | [diff] [blame] | 80 | static int enable; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 82 | /* Clock ratios multiplied by 10 */ |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 83 | static int mults[32]; |
| 84 | static int eblcr[32]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 85 | static int longhaul_version; |
| 86 | static struct cpufreq_frequency_table *longhaul_table; |
| 87 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 88 | static char speedbuffer[8]; |
| 89 | |
| 90 | static char *print_speed(int speed) |
| 91 | { |
Dave Jones | e2aa873 | 2006-05-30 17:37:15 -0400 | [diff] [blame] | 92 | if (speed < 1000) { |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 93 | snprintf(speedbuffer, sizeof(speedbuffer), "%dMHz", speed); |
Dave Jones | e2aa873 | 2006-05-30 17:37:15 -0400 | [diff] [blame] | 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 Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 103 | |
| 104 | return speedbuffer; |
| 105 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | |
| 107 | |
| 108 | static unsigned int calc_speed(int mult) |
| 109 | { |
| 110 | int khz; |
| 111 | khz = (mult/10)*fsb; |
| 112 | if (mult%10) |
| 113 | khz += fsb/2; |
| 114 | khz *= 1000; |
| 115 | return khz; |
| 116 | } |
| 117 | |
| 118 | |
| 119 | static int longhaul_get_cpu_mult(void) |
| 120 | { |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 121 | unsigned long invalue = 0, lo, hi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 123 | rdmsr(MSR_IA32_EBL_CR_POWERON, lo, hi); |
| 124 | invalue = (lo & (1<<22|1<<23|1<<24|1<<25))>>22; |
| 125 | if (longhaul_version == TYPE_LONGHAUL_V2 || |
| 126 | longhaul_version == TYPE_POWERSAVER) { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | if (lo & (1<<27)) |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 128 | invalue += 16; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 129 | } |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 130 | return eblcr[invalue]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | } |
| 132 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 133 | /* For processor with BCR2 MSR */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 135 | static void do_longhaul1(unsigned int mults_index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 136 | { |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 137 | union msr_bcr2 bcr2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 138 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 139 | rdmsrl(MSR_VIA_BCR2, bcr2.val); |
| 140 | /* Enable software clock multiplier */ |
| 141 | bcr2.bits.ESOFTBF = 1; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 142 | bcr2.bits.CLOCKMUL = mults_index & 0xff; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 143 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 144 | /* Sync to timer tick */ |
Zachary Amsden | 4bb0d3e | 2005-09-03 15:56:36 -0700 | [diff] [blame] | 145 | safe_halt(); |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 146 | /* Change frequency on next halt or sleep */ |
| 147 | wrmsrl(MSR_VIA_BCR2, bcr2.val); |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 148 | /* Invoke transition */ |
| 149 | ACPI_FLUSH_CPU_CACHE(); |
| 150 | halt(); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 151 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 152 | /* Disable software clock multiplier */ |
Dave Jones | 3be6a48 | 2005-05-31 19:03:51 -0700 | [diff] [blame] | 153 | local_irq_disable(); |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 154 | rdmsrl(MSR_VIA_BCR2, bcr2.val); |
| 155 | bcr2.bits.ESOFTBF = 0; |
| 156 | wrmsrl(MSR_VIA_BCR2, bcr2.val); |
| 157 | } |
Dave Jones | 3be6a48 | 2005-05-31 19:03:51 -0700 | [diff] [blame] | 158 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 159 | /* For processor with Longhaul MSR */ |
Dave Jones | 1174631 | 2005-05-31 19:03:51 -0700 | [diff] [blame] | 160 | |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 161 | static void do_powersaver(int cx_address, unsigned int mults_index, |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 162 | unsigned int dir) |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 163 | { |
| 164 | union msr_longhaul longhaul; |
| 165 | u32 t; |
Dave Jones | 3be6a48 | 2005-05-31 19:03:51 -0700 | [diff] [blame] | 166 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 167 | rdmsrl(MSR_VIA_LONGHAUL, longhaul.val); |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 168 | /* Setup new frequency */ |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 169 | if (!revid_errata) |
| 170 | longhaul.bits.RevisionKey = longhaul.bits.RevisionID; |
| 171 | else |
| 172 | longhaul.bits.RevisionKey = 0; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 173 | longhaul.bits.SoftBusRatio = mults_index & 0xf; |
| 174 | longhaul.bits.SoftBusRatio4 = (mults_index & 0x10) >> 4; |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 175 | /* Setup new voltage */ |
| 176 | if (can_scale_voltage) |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 177 | longhaul.bits.SoftVID = (mults_index >> 8) & 0x1f; |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 178 | /* Sync to timer tick */ |
| 179 | safe_halt(); |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 180 | /* Raise voltage if necessary */ |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 181 | if (can_scale_voltage && dir) { |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 182 | longhaul.bits.EnableSoftVID = 1; |
| 183 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); |
| 184 | /* Change voltage */ |
| 185 | if (!cx_address) { |
| 186 | ACPI_FLUSH_CPU_CACHE(); |
| 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 |
| 193 | * read */ |
Dave Jones | bd0561c | 2007-02-10 20:36:29 -0500 | [diff] [blame] | 194 | t = inl(acpi_gbl_FADT.xpm_timer_block.address); |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 195 | } |
| 196 | longhaul.bits.EnableSoftVID = 0; |
| 197 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 198 | } |
| 199 | |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 200 | /* Change frequency on next halt or sleep */ |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 201 | longhaul.bits.EnableSoftBusRatio = 1; |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 202 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 203 | if (!cx_address) { |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 204 | ACPI_FLUSH_CPU_CACHE(); |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 205 | halt(); |
| 206 | } else { |
| 207 | ACPI_FLUSH_CPU_CACHE(); |
| 208 | /* Invoke C3 */ |
| 209 | inb(cx_address); |
| 210 | /* Dummy op - must do something useless after P_LVL3 read */ |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 211 | t = inl(acpi_gbl_FADT.xpm_timer_block.address); |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 212 | } |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 213 | /* Disable bus ratio bit */ |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 214 | longhaul.bits.EnableSoftBusRatio = 0; |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 215 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 216 | |
| 217 | /* Reduce voltage if necessary */ |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 218 | if (can_scale_voltage && !dir) { |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 219 | longhaul.bits.EnableSoftVID = 1; |
| 220 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); |
| 221 | /* Change voltage */ |
| 222 | if (!cx_address) { |
| 223 | ACPI_FLUSH_CPU_CACHE(); |
| 224 | halt(); |
| 225 | } else { |
| 226 | ACPI_FLUSH_CPU_CACHE(); |
| 227 | /* Invoke C3 */ |
| 228 | inb(cx_address); |
| 229 | /* Dummy op - must do something useless after P_LVL3 |
| 230 | * read */ |
Dave Jones | bd0561c | 2007-02-10 20:36:29 -0500 | [diff] [blame] | 231 | t = inl(acpi_gbl_FADT.xpm_timer_block.address); |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 232 | } |
| 233 | longhaul.bits.EnableSoftVID = 0; |
| 234 | wrmsrl(MSR_VIA_LONGHAUL, longhaul.val); |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 235 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 236 | } |
| 237 | |
| 238 | /** |
| 239 | * longhaul_set_cpu_frequency() |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 240 | * @mults_index : bitpattern of the new multiplier. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 241 | * |
| 242 | * Sets a new clock ratio. |
| 243 | */ |
| 244 | |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 245 | static int longhaul_setstate(struct cpufreq_policy *policy, |
Viresh Kumar | b43a7ff | 2013-03-24 11:56:43 +0530 | [diff] [blame] | 246 | unsigned int table_index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 247 | { |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 248 | unsigned int mults_index; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 249 | int speed, mult; |
| 250 | struct cpufreq_freqs freqs; |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 251 | unsigned long flags; |
| 252 | unsigned int pic1_mask, pic2_mask; |
Rafał Bilski | 689eba7 | 2007-06-07 22:31:24 +0200 | [diff] [blame] | 253 | u16 bm_status = 0; |
Rafał Bilski | 275bc6b | 2007-06-05 22:08:50 +0200 | [diff] [blame] | 254 | u32 bm_timeout = 1000; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 255 | unsigned int dir = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 256 | |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 257 | mults_index = longhaul_table[table_index].driver_data; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 258 | /* Safety precautions */ |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 259 | mult = mults[mults_index & 0x1f]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 260 | if (mult == -1) |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 261 | return -EINVAL; |
| 262 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 263 | speed = calc_speed(mult); |
| 264 | if ((speed > highest_speed) || (speed < lowest_speed)) |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 265 | return -EINVAL; |
| 266 | |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 267 | /* Voltage transition before frequency transition? */ |
| 268 | if (can_scale_voltage && longhaul_index < table_index) |
| 269 | dir = 1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | |
| 271 | freqs.old = calc_speed(longhaul_get_cpu_mult()); |
| 272 | freqs.new = speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 273 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 274 | pr_debug("Setting to FSB:%dMHz Mult:%d.%dx (%s)\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 275 | fsb, mult/10, mult%10, print_speed(speed/1000)); |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 276 | retry_loop: |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 277 | preempt_disable(); |
| 278 | local_irq_save(flags); |
| 279 | |
| 280 | pic2_mask = inb(0xA1); |
| 281 | pic1_mask = inb(0x21); /* works on C3. save mask. */ |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 282 | outb(0xFF, 0xA1); /* Overkill */ |
| 283 | outb(0xFE, 0x21); /* TMR0 only */ |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 284 | |
Rafał Bilski | 489dc5c | 2007-05-17 22:39:02 +0200 | [diff] [blame] | 285 | /* Wait while PCI bus is busy. */ |
Rafał Bilski | 689eba7 | 2007-06-07 22:31:24 +0200 | [diff] [blame] | 286 | if (acpi_regs_addr && (longhaul_flags & USE_NORTHBRIDGE |
| 287 | || ((pr != NULL) && pr->flags.bm_control))) { |
| 288 | bm_status = inw(acpi_regs_addr); |
Rafał Bilski | 275bc6b | 2007-06-05 22:08:50 +0200 | [diff] [blame] | 289 | bm_status &= 1 << 4; |
Rafał Bilski | 489dc5c | 2007-05-17 22:39:02 +0200 | [diff] [blame] | 290 | while (bm_status && bm_timeout) { |
Rafał Bilski | 689eba7 | 2007-06-07 22:31:24 +0200 | [diff] [blame] | 291 | outw(1 << 4, acpi_regs_addr); |
Rafał Bilski | 489dc5c | 2007-05-17 22:39:02 +0200 | [diff] [blame] | 292 | bm_timeout--; |
Rafał Bilski | 689eba7 | 2007-06-07 22:31:24 +0200 | [diff] [blame] | 293 | bm_status = inw(acpi_regs_addr); |
Rafał Bilski | 275bc6b | 2007-06-05 22:08:50 +0200 | [diff] [blame] | 294 | bm_status &= 1 << 4; |
Rafał Bilski | 489dc5c | 2007-05-17 22:39:02 +0200 | [diff] [blame] | 295 | } |
| 296 | } |
| 297 | |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 298 | if (longhaul_flags & USE_NORTHBRIDGE) { |
| 299 | /* Disable AGP and PCI arbiters */ |
| 300 | outb(3, 0x22); |
| 301 | } else if ((pr != NULL) && pr->flags.bm_control) { |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 302 | /* Disable bus master arbitration */ |
Lin Ming | fb318cb | 2009-03-18 09:09:01 +0800 | [diff] [blame] | 303 | acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 1); |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 304 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 305 | switch (longhaul_version) { |
| 306 | |
| 307 | /* |
| 308 | * Longhaul v1. (Samuel[C5A] and Samuel2 stepping 0[C5B]) |
| 309 | * Software controlled multipliers only. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 310 | */ |
| 311 | case TYPE_LONGHAUL_V1: |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 312 | do_longhaul1(mults_index); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 313 | break; |
| 314 | |
| 315 | /* |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 316 | * Longhaul v2 appears in Samuel2 Steppings 1->7 [C5B] and Ezra [C5C] |
| 317 | * |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 318 | * Longhaul v3 (aka Powersaver). (Ezra-T [C5M] & Nehemiah [C5N]) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 319 | * Nehemiah can do FSB scaling too, but this has never been proven |
| 320 | * to work in practice. |
| 321 | */ |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 322 | case TYPE_LONGHAUL_V2: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 323 | case TYPE_POWERSAVER: |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 324 | if (longhaul_flags & USE_ACPI_C3) { |
| 325 | /* Don't allow wakeup */ |
Lin Ming | fb318cb | 2009-03-18 09:09:01 +0800 | [diff] [blame] | 326 | acpi_write_bit_register(ACPI_BITREG_BUS_MASTER_RLD, 0); |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 327 | do_powersaver(cx->address, mults_index, dir); |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 328 | } else { |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 329 | do_powersaver(0, mults_index, dir); |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 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 */ |
Lin Ming | fb318cb | 2009-03-18 09:09:01 +0800 | [diff] [blame] | 339 | acpi_write_bit_register(ACPI_BITREG_ARB_DISABLE, 0); |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 340 | } |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 341 | outb(pic2_mask, 0xA1); /* restore mask */ |
| 342 | outb(pic1_mask, 0x21); |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 343 | |
| 344 | local_irq_restore(flags); |
| 345 | preempt_enable(); |
| 346 | |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 347 | freqs.new = calc_speed(longhaul_get_cpu_mult()); |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 348 | /* Check if requested frequency is set. */ |
| 349 | if (unlikely(freqs.new != speed)) { |
| 350 | printk(KERN_INFO PFX "Failed to set requested frequency!\n"); |
| 351 | /* Revision ID = 1 but processor is expecting revision key |
| 352 | * equal to 0. Jumpers at the bottom of processor will change |
| 353 | * multiplier and FSB, but will not change bits in Longhaul |
| 354 | * MSR nor enable voltage scaling. */ |
| 355 | if (!revid_errata) { |
| 356 | printk(KERN_INFO PFX "Enabling \"Ignore Revision ID\" " |
| 357 | "option.\n"); |
| 358 | revid_errata = 1; |
| 359 | msleep(200); |
| 360 | goto retry_loop; |
| 361 | } |
| 362 | /* Why ACPI C3 sometimes doesn't work is a mystery for me. |
| 363 | * But it does happen. Processor is entering ACPI C3 state, |
| 364 | * but it doesn't change frequency. I tried poking various |
| 365 | * bits in northbridge registers, but without success. */ |
| 366 | if (longhaul_flags & USE_ACPI_C3) { |
| 367 | printk(KERN_INFO PFX "Disabling ACPI C3 support.\n"); |
| 368 | longhaul_flags &= ~USE_ACPI_C3; |
| 369 | if (revid_errata) { |
| 370 | printk(KERN_INFO PFX "Disabling \"Ignore " |
| 371 | "Revision ID\" option.\n"); |
| 372 | revid_errata = 0; |
| 373 | } |
| 374 | msleep(200); |
| 375 | goto retry_loop; |
| 376 | } |
| 377 | /* This shouldn't happen. Longhaul ver. 2 was reported not |
| 378 | * working on processors without voltage scaling, but with |
| 379 | * RevID = 1. RevID errata will make things right. Just |
| 380 | * to be 100% sure. */ |
| 381 | if (longhaul_version == TYPE_LONGHAUL_V2) { |
| 382 | printk(KERN_INFO PFX "Switching to Longhaul ver. 1\n"); |
| 383 | longhaul_version = TYPE_LONGHAUL_V1; |
| 384 | msleep(200); |
| 385 | goto retry_loop; |
| 386 | } |
| 387 | } |
Rafał Bilski | 489dc5c | 2007-05-17 22:39:02 +0200 | [diff] [blame] | 388 | |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 389 | if (!bm_timeout) { |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 390 | printk(KERN_INFO PFX "Warning: Timeout while waiting for " |
| 391 | "idle PCI bus.\n"); |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 392 | return -EBUSY; |
| 393 | } |
| 394 | |
| 395 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 396 | } |
| 397 | |
| 398 | /* |
| 399 | * Centaur decided to make life a little more tricky. |
| 400 | * Only longhaul v1 is allowed to read EBLCR BSEL[0:1]. |
| 401 | * Samuel2 and above have to try and guess what the FSB is. |
| 402 | * We do this by assuming we booted at maximum multiplier, and interpolate |
| 403 | * between that value multiplied by possible FSBs and cpu_mhz which |
| 404 | * was calculated at boot time. Really ugly, but no other way to do this. |
| 405 | */ |
| 406 | |
| 407 | #define ROUNDING 0xf |
| 408 | |
Rafa³ Bilski | 24ebead | 2007-01-01 23:49:34 +0100 | [diff] [blame] | 409 | static int guess_fsb(int mult) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 410 | { |
Rafa³ Bilski | 46ef955 | 2007-02-04 15:58:46 +0100 | [diff] [blame] | 411 | int speed = cpu_khz / 1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | int i; |
Rafa³ Bilski | 46ef955 | 2007-02-04 15:58:46 +0100 | [diff] [blame] | 413 | int speeds[] = { 666, 1000, 1333, 2000 }; |
| 414 | int f_max, f_min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 415 | |
Rafa³ Bilski | 46ef955 | 2007-02-04 15:58:46 +0100 | [diff] [blame] | 416 | for (i = 0; i < 4; i++) { |
| 417 | f_max = ((speeds[i] * mult) + 50) / 100; |
| 418 | f_max += (ROUNDING / 2); |
| 419 | f_min = f_max - ROUNDING; |
| 420 | if ((speed <= f_max) && (speed >= f_min)) |
| 421 | return speeds[i] / 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 422 | } |
| 423 | return 0; |
| 424 | } |
| 425 | |
| 426 | |
Paul Gortmaker | 2760984 | 2013-06-19 13:54:04 -0400 | [diff] [blame] | 427 | static int longhaul_get_ranges(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 428 | { |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 429 | unsigned int i, j, k = 0; |
| 430 | unsigned int ratio; |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 431 | int mult; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 432 | |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 433 | /* Get current frequency */ |
| 434 | mult = longhaul_get_cpu_mult(); |
| 435 | if (mult == -1) { |
| 436 | printk(KERN_INFO PFX "Invalid (reserved) multiplier!\n"); |
| 437 | return -EINVAL; |
| 438 | } |
| 439 | fsb = guess_fsb(mult); |
| 440 | if (fsb == 0) { |
| 441 | printk(KERN_INFO PFX "Invalid (reserved) FSB!\n"); |
| 442 | return -EINVAL; |
| 443 | } |
| 444 | /* Get max multiplier - as we always did. |
Lucas De Marchi | 0d2eb44 | 2011-03-17 16:24:16 -0300 | [diff] [blame] | 445 | * Longhaul MSR is useful only when voltage scaling is enabled. |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 446 | * C3 is booting at max anyway. */ |
| 447 | maxmult = mult; |
| 448 | /* Get min multiplier */ |
Rafa³ Bilski | 9addf3b | 2007-02-07 22:53:29 +0100 | [diff] [blame] | 449 | switch (cpu_model) { |
| 450 | case CPU_NEHEMIAH: |
| 451 | minmult = 50; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 452 | break; |
Rafa³ Bilski | 9addf3b | 2007-02-07 22:53:29 +0100 | [diff] [blame] | 453 | case CPU_NEHEMIAH_C: |
| 454 | minmult = 40; |
| 455 | break; |
| 456 | default: |
| 457 | minmult = 30; |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 458 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | } |
| 460 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 461 | pr_debug("MinMult:%d.%dx MaxMult:%d.%dx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 462 | minmult/10, minmult%10, maxmult/10, maxmult%10); |
| 463 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 464 | highest_speed = calc_speed(maxmult); |
| 465 | lowest_speed = calc_speed(minmult); |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 466 | pr_debug("FSB:%dMHz Lowest speed: %s Highest speed:%s\n", fsb, |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 467 | print_speed(lowest_speed/1000), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 468 | print_speed(highest_speed/1000)); |
| 469 | |
| 470 | if (lowest_speed == highest_speed) { |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 471 | printk(KERN_INFO PFX "highestspeed == lowest, aborting.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 472 | return -EINVAL; |
| 473 | } |
| 474 | if (lowest_speed > highest_speed) { |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 475 | printk(KERN_INFO PFX "nonsense! lowest (%d > %d) !\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 476 | lowest_speed, highest_speed); |
| 477 | return -EINVAL; |
| 478 | } |
| 479 | |
Viresh Kumar | 71508a1 | 2014-03-28 19:11:46 +0530 | [diff] [blame] | 480 | longhaul_table = kzalloc((numscales + 1) * sizeof(*longhaul_table), |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 481 | GFP_KERNEL); |
| 482 | if (!longhaul_table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 483 | return -ENOMEM; |
| 484 | |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 485 | for (j = 0; j < numscales; j++) { |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 486 | ratio = mults[j]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 487 | if (ratio == -1) |
| 488 | continue; |
| 489 | if (ratio > maxmult || ratio < minmult) |
| 490 | continue; |
| 491 | longhaul_table[k].frequency = calc_speed(ratio); |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 492 | longhaul_table[k].driver_data = j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 493 | k++; |
| 494 | } |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 495 | if (k <= 1) { |
| 496 | kfree(longhaul_table); |
| 497 | return -ENODEV; |
| 498 | } |
| 499 | /* Sort */ |
| 500 | for (j = 0; j < k - 1; j++) { |
| 501 | unsigned int min_f, min_i; |
| 502 | min_f = longhaul_table[j].frequency; |
| 503 | min_i = j; |
| 504 | for (i = j + 1; i < k; i++) { |
| 505 | if (longhaul_table[i].frequency < min_f) { |
| 506 | min_f = longhaul_table[i].frequency; |
| 507 | min_i = i; |
| 508 | } |
| 509 | } |
| 510 | if (min_i != j) { |
Dave Jones | 9142022 | 2009-02-04 15:28:54 -0500 | [diff] [blame] | 511 | swap(longhaul_table[j].frequency, |
| 512 | longhaul_table[min_i].frequency); |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 513 | swap(longhaul_table[j].driver_data, |
| 514 | longhaul_table[min_i].driver_data); |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 515 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 516 | } |
| 517 | |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 518 | longhaul_table[k].frequency = CPUFREQ_TABLE_END; |
| 519 | |
| 520 | /* Find index we are running on */ |
| 521 | for (j = 0; j < k; j++) { |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 522 | if (mults[longhaul_table[j].driver_data & 0x1f] == mult) { |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 523 | longhaul_index = j; |
| 524 | break; |
| 525 | } |
| 526 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 527 | return 0; |
| 528 | } |
| 529 | |
| 530 | |
Paul Gortmaker | 2760984 | 2013-06-19 13:54:04 -0400 | [diff] [blame] | 531 | static void longhaul_setup_voltagescaling(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 532 | { |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 533 | struct cpufreq_frequency_table *freq_pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 534 | union msr_longhaul longhaul; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 535 | struct mV_pos minvid, maxvid, vid; |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 536 | unsigned int j, speed, pos, kHz_step, numvscales; |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 537 | int min_vid_speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 538 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 539 | rdmsrl(MSR_VIA_LONGHAUL, longhaul.val); |
| 540 | if (!(longhaul.bits.RevisionID & 1)) { |
| 541 | printk(KERN_INFO PFX "Voltage scaling not supported by CPU.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 542 | return; |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 543 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 544 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 545 | if (!longhaul.bits.VRMRev) { |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 546 | printk(KERN_INFO PFX "VRM 8.5\n"); |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 547 | vrm_mV_table = &vrm85_mV[0]; |
| 548 | mV_vrm_table = &mV_vrm85[0]; |
| 549 | } else { |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 550 | printk(KERN_INFO PFX "Mobile VRM\n"); |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 551 | if (cpu_model < CPU_NEHEMIAH) |
| 552 | return; |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 553 | vrm_mV_table = &mobilevrm_mV[0]; |
| 554 | mV_vrm_table = &mV_mobilevrm[0]; |
| 555 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 556 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 557 | minvid = vrm_mV_table[longhaul.bits.MinimumVID]; |
| 558 | maxvid = vrm_mV_table[longhaul.bits.MaximumVID]; |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 559 | |
| 560 | if (minvid.mV == 0 || maxvid.mV == 0 || minvid.mV > maxvid.mV) { |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 561 | printk(KERN_INFO PFX "Bogus values Min:%d.%03d Max:%d.%03d. " |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 562 | "Voltage scaling disabled.\n", |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 563 | minvid.mV/1000, minvid.mV%1000, |
| 564 | maxvid.mV/1000, maxvid.mV%1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 565 | return; |
| 566 | } |
| 567 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 568 | if (minvid.mV == maxvid.mV) { |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 569 | printk(KERN_INFO PFX "Claims to support voltage scaling but " |
| 570 | "min & max are both %d.%03d. " |
| 571 | "Voltage scaling disabled\n", |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 572 | maxvid.mV/1000, maxvid.mV%1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 573 | return; |
| 574 | } |
| 575 | |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 576 | /* How many voltage steps*/ |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 577 | numvscales = maxvid.pos - minvid.pos + 1; |
| 578 | printk(KERN_INFO PFX |
| 579 | "Max VID=%d.%03d " |
| 580 | "Min VID=%d.%03d, " |
| 581 | "%d possible voltage scales\n", |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 582 | maxvid.mV/1000, maxvid.mV%1000, |
| 583 | minvid.mV/1000, minvid.mV%1000, |
| 584 | numvscales); |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 585 | |
| 586 | /* Calculate max frequency at min voltage */ |
| 587 | j = longhaul.bits.MinMHzBR; |
| 588 | if (longhaul.bits.MinMHzBR4) |
| 589 | j += 16; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 590 | min_vid_speed = eblcr[j]; |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 591 | if (min_vid_speed == -1) |
| 592 | return; |
| 593 | switch (longhaul.bits.MinMHzFSB) { |
| 594 | case 0: |
| 595 | min_vid_speed *= 13333; |
| 596 | break; |
| 597 | case 1: |
| 598 | min_vid_speed *= 10000; |
| 599 | break; |
| 600 | case 3: |
| 601 | min_vid_speed *= 6666; |
| 602 | break; |
| 603 | default: |
| 604 | return; |
| 605 | break; |
| 606 | } |
| 607 | if (min_vid_speed >= highest_speed) |
| 608 | return; |
| 609 | /* Calculate kHz for one voltage step */ |
| 610 | kHz_step = (highest_speed - min_vid_speed) / numvscales; |
| 611 | |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 612 | cpufreq_for_each_entry(freq_pos, longhaul_table) { |
| 613 | speed = freq_pos->frequency; |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 614 | if (speed > min_vid_speed) |
| 615 | pos = (speed - min_vid_speed) / kHz_step + minvid.pos; |
| 616 | else |
| 617 | pos = minvid.pos; |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 618 | freq_pos->driver_data |= mV_vrm_table[pos] << 8; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 619 | vid = vrm_mV_table[mV_vrm_table[pos]]; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 620 | printk(KERN_INFO PFX "f: %d kHz, index: %d, vid: %d mV\n", |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 621 | speed, (int)(freq_pos - longhaul_table), vid.mV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | } |
| 623 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 624 | can_scale_voltage = 1; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 625 | printk(KERN_INFO PFX "Voltage scaling enabled.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 626 | } |
| 627 | |
| 628 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 629 | static int longhaul_target(struct cpufreq_policy *policy, |
Viresh Kumar | 9c0ebcf | 2013-10-25 19:45:48 +0530 | [diff] [blame] | 630 | unsigned int table_index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 631 | { |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 632 | unsigned int i; |
| 633 | unsigned int dir = 0; |
| 634 | u8 vid, current_vid; |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 635 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 636 | |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 637 | if (!can_scale_voltage) |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 638 | retval = longhaul_setstate(policy, table_index); |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 639 | else { |
| 640 | /* On test system voltage transitions exceeding single |
| 641 | * step up or down were turning motherboard off. Both |
| 642 | * "ondemand" and "userspace" are unsafe. C7 is doing |
| 643 | * this in hardware, C3 is old and we need to do this |
| 644 | * in software. */ |
| 645 | i = longhaul_index; |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 646 | current_vid = (longhaul_table[longhaul_index].driver_data >> 8); |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 647 | current_vid &= 0x1f; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 648 | if (table_index > longhaul_index) |
| 649 | dir = 1; |
| 650 | while (i != table_index) { |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 651 | vid = (longhaul_table[i].driver_data >> 8) & 0x1f; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 652 | if (vid != current_vid) { |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 653 | retval = longhaul_setstate(policy, i); |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 654 | current_vid = vid; |
| 655 | msleep(200); |
| 656 | } |
| 657 | if (dir) |
| 658 | i++; |
| 659 | else |
| 660 | i--; |
| 661 | } |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 662 | retval = longhaul_setstate(policy, table_index); |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 663 | } |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 664 | |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 665 | longhaul_index = table_index; |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 666 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | |
| 670 | static unsigned int longhaul_get(unsigned int cpu) |
| 671 | { |
| 672 | if (cpu) |
| 673 | return 0; |
| 674 | return calc_speed(longhaul_get_cpu_mult()); |
| 675 | } |
| 676 | |
Adrian Bunk | c4a96c1 | 2006-07-09 19:53:08 +0200 | [diff] [blame] | 677 | static acpi_status longhaul_walk_callback(acpi_handle obj_handle, |
| 678 | u32 nesting_level, |
| 679 | void *context, void **return_value) |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 680 | { |
| 681 | struct acpi_device *d; |
| 682 | |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 683 | if (acpi_bus_get_device(obj_handle, &d)) |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 684 | return 0; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 685 | |
Jan Engelhardt | ade1af7 | 2008-01-30 13:33:23 +0100 | [diff] [blame] | 686 | *return_value = acpi_driver_data(d); |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 687 | return 1; |
| 688 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 689 | |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 690 | /* VIA don't support PM2 reg, but have something similar */ |
| 691 | static int enable_arbiter_disable(void) |
| 692 | { |
| 693 | struct pci_dev *dev; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 694 | int status = 1; |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 695 | int reg; |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 696 | u8 pci_cmd; |
| 697 | |
| 698 | /* Find PLE133 host bridge */ |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 699 | reg = 0x78; |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 700 | dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8601_0, |
| 701 | NULL); |
Linus Torvalds | 4d5709a | 2007-10-12 15:42:01 -0700 | [diff] [blame] | 702 | /* Find PM133/VT8605 host bridge */ |
| 703 | if (dev == NULL) |
| 704 | dev = pci_get_device(PCI_VENDOR_ID_VIA, |
| 705 | PCI_DEVICE_ID_VIA_8605_0, NULL); |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 706 | /* Find CLE266 host bridge */ |
| 707 | if (dev == NULL) { |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 708 | reg = 0x76; |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 709 | dev = pci_get_device(PCI_VENDOR_ID_VIA, |
| 710 | PCI_DEVICE_ID_VIA_862X_0, NULL); |
Rafa³ Bilski | db2fb9d | 2006-11-30 03:47:41 +0100 | [diff] [blame] | 711 | /* Find CN400 V-Link host bridge */ |
| 712 | if (dev == NULL) |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 713 | dev = pci_get_device(PCI_VENDOR_ID_VIA, 0x7259, NULL); |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 714 | } |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 715 | if (dev != NULL) { |
| 716 | /* Enable access to port 0x22 */ |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 717 | pci_read_config_byte(dev, reg, &pci_cmd); |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 718 | if (!(pci_cmd & 1<<7)) { |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 719 | pci_cmd |= 1<<7; |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 720 | pci_write_config_byte(dev, reg, pci_cmd); |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 721 | pci_read_config_byte(dev, reg, &pci_cmd); |
| 722 | if (!(pci_cmd & 1<<7)) { |
| 723 | printk(KERN_ERR PFX |
| 724 | "Can't enable access to port 0x22.\n"); |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 725 | status = 0; |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 726 | } |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 727 | } |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 728 | pci_dev_put(dev); |
| 729 | return status; |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 730 | } |
| 731 | return 0; |
| 732 | } |
| 733 | |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 734 | static int longhaul_setup_southbridge(void) |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 735 | { |
| 736 | struct pci_dev *dev; |
| 737 | u8 pci_cmd; |
| 738 | |
| 739 | /* Find VT8235 southbridge */ |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 740 | dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, NULL); |
Rafał Bilski | 920dd0f | 2007-05-17 22:35:29 +0200 | [diff] [blame] | 741 | if (dev == NULL) |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 742 | /* Find VT8237 southbridge */ |
Rafał Bilski | 920dd0f | 2007-05-17 22:35:29 +0200 | [diff] [blame] | 743 | dev = pci_get_device(PCI_VENDOR_ID_VIA, |
| 744 | PCI_DEVICE_ID_VIA_8237, NULL); |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 745 | if (dev != NULL) { |
| 746 | /* Set transition time to max */ |
| 747 | pci_read_config_byte(dev, 0xec, &pci_cmd); |
| 748 | pci_cmd &= ~(1 << 2); |
| 749 | pci_write_config_byte(dev, 0xec, pci_cmd); |
| 750 | pci_read_config_byte(dev, 0xe4, &pci_cmd); |
| 751 | pci_cmd &= ~(1 << 7); |
| 752 | pci_write_config_byte(dev, 0xe4, pci_cmd); |
| 753 | pci_read_config_byte(dev, 0xe5, &pci_cmd); |
| 754 | pci_cmd |= 1 << 7; |
| 755 | pci_write_config_byte(dev, 0xe5, pci_cmd); |
Rafał Bilski | 275bc6b | 2007-06-05 22:08:50 +0200 | [diff] [blame] | 756 | /* Get address of ACPI registers block*/ |
| 757 | pci_read_config_byte(dev, 0x81, &pci_cmd); |
| 758 | if (pci_cmd & 1 << 7) { |
| 759 | pci_read_config_dword(dev, 0x88, &acpi_regs_addr); |
| 760 | acpi_regs_addr &= 0xff00; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 761 | printk(KERN_INFO PFX "ACPI I/O at 0x%x\n", |
| 762 | acpi_regs_addr); |
Rafał Bilski | 275bc6b | 2007-06-05 22:08:50 +0200 | [diff] [blame] | 763 | } |
| 764 | |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 765 | pci_dev_put(dev); |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 766 | return 1; |
| 767 | } |
| 768 | return 0; |
| 769 | } |
| 770 | |
Paul Gortmaker | 2760984 | 2013-06-19 13:54:04 -0400 | [diff] [blame] | 771 | static int longhaul_cpu_init(struct cpufreq_policy *policy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 772 | { |
Mike Travis | 92cb761 | 2007-10-19 20:35:04 +0200 | [diff] [blame] | 773 | struct cpuinfo_x86 *c = &cpu_data(0); |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 774 | char *cpuname = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | int ret; |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 776 | u32 lo, hi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 777 | |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 778 | /* Check what we have on this motherboard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 779 | switch (c->x86_model) { |
| 780 | case 6: |
| 781 | cpu_model = CPU_SAMUEL; |
| 782 | cpuname = "C3 'Samuel' [C5A]"; |
| 783 | longhaul_version = TYPE_LONGHAUL_V1; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 784 | memcpy(mults, samuel1_mults, sizeof(samuel1_mults)); |
| 785 | memcpy(eblcr, samuel1_eblcr, sizeof(samuel1_eblcr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 786 | break; |
| 787 | |
| 788 | case 7: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 789 | switch (c->x86_mask) { |
| 790 | case 0: |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 791 | longhaul_version = TYPE_LONGHAUL_V1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 792 | cpu_model = CPU_SAMUEL2; |
| 793 | cpuname = "C3 'Samuel 2' [C5B]"; |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 794 | /* Note, this is not a typo, early Samuel2's had |
| 795 | * Samuel1 ratios. */ |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 796 | memcpy(mults, samuel1_mults, sizeof(samuel1_mults)); |
| 797 | memcpy(eblcr, samuel2_eblcr, sizeof(samuel2_eblcr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 798 | break; |
| 799 | case 1 ... 15: |
Krzysztof Helt | f7f3cad | 2009-10-24 17:25:38 +0200 | [diff] [blame] | 800 | longhaul_version = TYPE_LONGHAUL_V2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 801 | if (c->x86_mask < 8) { |
| 802 | cpu_model = CPU_SAMUEL2; |
| 803 | cpuname = "C3 'Samuel 2' [C5B]"; |
| 804 | } else { |
| 805 | cpu_model = CPU_EZRA; |
| 806 | cpuname = "C3 'Ezra' [C5C]"; |
| 807 | } |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 808 | memcpy(mults, ezra_mults, sizeof(ezra_mults)); |
| 809 | memcpy(eblcr, ezra_eblcr, sizeof(ezra_eblcr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | break; |
| 811 | } |
| 812 | break; |
| 813 | |
| 814 | case 8: |
| 815 | cpu_model = CPU_EZRA_T; |
| 816 | cpuname = "C3 'Ezra-T' [C5M]"; |
| 817 | longhaul_version = TYPE_POWERSAVER; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 818 | numscales = 32; |
| 819 | memcpy(mults, ezrat_mults, sizeof(ezrat_mults)); |
| 820 | memcpy(eblcr, ezrat_eblcr, sizeof(ezrat_eblcr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | break; |
| 822 | |
| 823 | case 9: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 824 | longhaul_version = TYPE_POWERSAVER; |
Rafa³ Bilski | 0d44b2b | 2007-01-31 23:50:49 +0100 | [diff] [blame] | 825 | numscales = 32; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 826 | memcpy(mults, nehemiah_mults, sizeof(nehemiah_mults)); |
| 827 | memcpy(eblcr, nehemiah_eblcr, sizeof(nehemiah_eblcr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 828 | switch (c->x86_mask) { |
| 829 | case 0 ... 1: |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 830 | cpu_model = CPU_NEHEMIAH; |
Rafa³ Bilski | e57501c | 2007-02-08 23:12:02 +0100 | [diff] [blame] | 831 | cpuname = "C3 'Nehemiah A' [C5XLOE]"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 832 | break; |
| 833 | case 2 ... 4: |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 834 | cpu_model = CPU_NEHEMIAH; |
Rafa³ Bilski | e57501c | 2007-02-08 23:12:02 +0100 | [diff] [blame] | 835 | cpuname = "C3 'Nehemiah B' [C5XLOH]"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 836 | break; |
| 837 | case 5 ... 15: |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 838 | cpu_model = CPU_NEHEMIAH_C; |
Rafa³ Bilski | e57501c | 2007-02-08 23:12:02 +0100 | [diff] [blame] | 839 | cpuname = "C3 'Nehemiah C' [C5P]"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 840 | break; |
| 841 | } |
| 842 | break; |
| 843 | |
| 844 | default: |
| 845 | cpuname = "Unknown"; |
| 846 | break; |
| 847 | } |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 848 | /* Check Longhaul ver. 2 */ |
| 849 | if (longhaul_version == TYPE_LONGHAUL_V2) { |
| 850 | rdmsr(MSR_VIA_LONGHAUL, lo, hi); |
| 851 | if (lo == 0 && hi == 0) |
| 852 | /* Looks like MSR isn't present */ |
| 853 | longhaul_version = TYPE_LONGHAUL_V1; |
| 854 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 855 | |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 856 | printk(KERN_INFO PFX "VIA %s CPU detected. ", cpuname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 857 | switch (longhaul_version) { |
| 858 | case TYPE_LONGHAUL_V1: |
| 859 | case TYPE_LONGHAUL_V2: |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 860 | printk(KERN_CONT "Longhaul v%d supported.\n", longhaul_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 861 | break; |
| 862 | case TYPE_POWERSAVER: |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 863 | printk(KERN_CONT "Powersaver supported.\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 864 | break; |
| 865 | }; |
| 866 | |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 867 | /* Doesn't hurt */ |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 868 | longhaul_setup_southbridge(); |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 869 | |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 870 | /* Find ACPI data for processor */ |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 871 | acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 872 | ACPI_UINT32_MAX, &longhaul_walk_callback, NULL, |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 873 | NULL, (void *)&pr); |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 874 | |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 875 | /* Check ACPI support for C3 state */ |
Dave Jones | 7ab77e0 | 2007-04-20 15:58:00 -0400 | [diff] [blame] | 876 | if (pr != NULL && longhaul_version == TYPE_POWERSAVER) { |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 877 | cx = &pr->power.states[ACPI_STATE_C3]; |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 878 | if (cx->address > 0 && cx->latency <= 1000) |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 879 | longhaul_flags |= USE_ACPI_C3; |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 880 | } |
Rafał Bilski | 905497c | 2007-07-08 21:51:26 +0200 | [diff] [blame] | 881 | /* Disable if it isn't working */ |
| 882 | if (disable_acpi_c3) |
| 883 | longhaul_flags &= ~USE_ACPI_C3; |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 884 | /* Check if northbridge is friendly */ |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 885 | if (enable_arbiter_disable()) |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 886 | longhaul_flags |= USE_NORTHBRIDGE; |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 887 | |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 888 | /* Check ACPI support for bus master arbiter disable */ |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 889 | if (!(longhaul_flags & USE_ACPI_C3 |
| 890 | || longhaul_flags & USE_NORTHBRIDGE) |
| 891 | && ((pr == NULL) || !(pr->flags.bm_control))) { |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 892 | printk(KERN_ERR PFX |
| 893 | "No ACPI support. Unsupported northbridge.\n"); |
| 894 | return -ENODEV; |
| 895 | } |
| 896 | |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 897 | if (longhaul_flags & USE_NORTHBRIDGE) |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 898 | printk(KERN_INFO PFX "Using northbridge support.\n"); |
| 899 | if (longhaul_flags & USE_ACPI_C3) |
| 900 | printk(KERN_INFO PFX "Using ACPI support.\n"); |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 901 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 902 | ret = longhaul_get_ranges(); |
| 903 | if (ret != 0) |
| 904 | return ret; |
| 905 | |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 906 | if ((longhaul_version != TYPE_LONGHAUL_V1) && (scale_voltage != 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | longhaul_setup_voltagescaling(); |
| 908 | |
Dave Jones | 6778bae | 2005-05-31 19:03:51 -0700 | [diff] [blame] | 909 | policy->cpuinfo.transition_latency = 200000; /* nsec */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 910 | |
Viresh Kumar | 30aa534 | 2013-09-16 18:56:20 +0530 | [diff] [blame] | 911 | return cpufreq_table_validate_and_show(policy, longhaul_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 912 | } |
| 913 | |
Linus Torvalds | 221dee2 | 2007-02-26 14:55:48 -0800 | [diff] [blame] | 914 | static struct cpufreq_driver longhaul_driver = { |
Viresh Kumar | 3a4d034 | 2013-10-03 20:28:10 +0530 | [diff] [blame] | 915 | .verify = cpufreq_generic_frequency_table_verify, |
Viresh Kumar | 9c0ebcf | 2013-10-25 19:45:48 +0530 | [diff] [blame] | 916 | .target_index = longhaul_target, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 917 | .get = longhaul_get, |
| 918 | .init = longhaul_cpu_init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 919 | .name = "longhaul", |
Viresh Kumar | 3a4d034 | 2013-10-03 20:28:10 +0530 | [diff] [blame] | 920 | .attr = cpufreq_generic_attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 921 | }; |
| 922 | |
Andi Kleen | fa8031a | 2012-01-26 00:09:12 +0100 | [diff] [blame] | 923 | static const struct x86_cpu_id longhaul_id[] = { |
| 924 | { X86_VENDOR_CENTAUR, 6 }, |
| 925 | {} |
| 926 | }; |
| 927 | MODULE_DEVICE_TABLE(x86cpu, longhaul_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 928 | |
| 929 | static int __init longhaul_init(void) |
| 930 | { |
Mike Travis | 92cb761 | 2007-10-19 20:35:04 +0200 | [diff] [blame] | 931 | struct cpuinfo_x86 *c = &cpu_data(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 932 | |
Andi Kleen | fa8031a | 2012-01-26 00:09:12 +0100 | [diff] [blame] | 933 | if (!x86_match_cpu(longhaul_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 934 | return -ENODEV; |
| 935 | |
Rafał Bilski | b5811bc | 2012-12-15 00:45:02 +0100 | [diff] [blame] | 936 | if (!enable) { |
| 937 | printk(KERN_ERR PFX "Option \"enable\" not set. Aborting.\n"); |
| 938 | return -ENODEV; |
| 939 | } |
Rafa³ Bilski | 48b7bde | 2006-07-04 17:50:57 +0200 | [diff] [blame] | 940 | #ifdef CONFIG_SMP |
| 941 | if (num_online_cpus() > 1) { |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 942 | printk(KERN_ERR PFX "More than 1 CPU detected, " |
| 943 | "longhaul disabled.\n"); |
Dave Jones | 1cfe201 | 2006-12-28 22:30:16 -0500 | [diff] [blame] | 944 | return -ENODEV; |
Rafa³ Bilski | 48b7bde | 2006-07-04 17:50:57 +0200 | [diff] [blame] | 945 | } |
| 946 | #endif |
| 947 | #ifdef CONFIG_X86_IO_APIC |
Borislav Petkov | 93984fb | 2016-04-04 22:25:00 +0200 | [diff] [blame^] | 948 | if (boot_cpu_has(X86_FEATURE_APIC)) { |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 949 | printk(KERN_ERR PFX "APIC detected. Longhaul is currently " |
| 950 | "broken in this configuration.\n"); |
Rafa³ Bilski | 48b7bde | 2006-07-04 17:50:57 +0200 | [diff] [blame] | 951 | return -ENODEV; |
| 952 | } |
| 953 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 954 | switch (c->x86_model) { |
| 955 | case 6 ... 9: |
| 956 | return cpufreq_register_driver(&longhaul_driver); |
Dave Jones | 8ec9822 | 2006-12-17 19:07:35 -0500 | [diff] [blame] | 957 | case 10: |
| 958 | printk(KERN_ERR PFX "Use acpi-cpufreq driver for VIA C7\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 959 | default: |
Fernando Carrijo | c19a28e | 2009-01-07 18:09:08 -0800 | [diff] [blame] | 960 | ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 961 | } |
| 962 | |
| 963 | return -ENODEV; |
| 964 | } |
| 965 | |
| 966 | |
| 967 | static void __exit longhaul_exit(void) |
| 968 | { |
Viresh Kumar | b43a7ff | 2013-03-24 11:56:43 +0530 | [diff] [blame] | 969 | struct cpufreq_policy *policy = cpufreq_cpu_get(0); |
Dave Jones | 8eebf1a | 2006-05-30 17:40:16 -0400 | [diff] [blame] | 970 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 971 | |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 972 | for (i = 0; i < numscales; i++) { |
| 973 | if (mults[i] == maxmult) { |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 974 | struct cpufreq_freqs freqs; |
| 975 | |
| 976 | freqs.old = policy->cur; |
| 977 | freqs.new = longhaul_table[i].frequency; |
| 978 | freqs.flags = 0; |
| 979 | |
| 980 | cpufreq_freq_transition_begin(policy, &freqs); |
Viresh Kumar | b43a7ff | 2013-03-24 11:56:43 +0530 | [diff] [blame] | 981 | longhaul_setstate(policy, i); |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 982 | cpufreq_freq_transition_end(policy, &freqs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 983 | break; |
| 984 | } |
| 985 | } |
| 986 | |
Viresh Kumar | b43a7ff | 2013-03-24 11:56:43 +0530 | [diff] [blame] | 987 | cpufreq_cpu_put(policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 988 | cpufreq_unregister_driver(&longhaul_driver); |
| 989 | kfree(longhaul_table); |
| 990 | } |
| 991 | |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 992 | /* Even if BIOS is exporting ACPI C3 state, and it is used |
| 993 | * with success when CPU is idle, this state doesn't |
| 994 | * trigger frequency transition in some cases. */ |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 995 | module_param(disable_acpi_c3, int, 0644); |
Rafał Bilski | 905497c | 2007-07-08 21:51:26 +0200 | [diff] [blame] | 996 | MODULE_PARM_DESC(disable_acpi_c3, "Don't use ACPI C3 support"); |
Lucas De Marchi | 0d2eb44 | 2011-03-17 16:24:16 -0300 | [diff] [blame] | 997 | /* Change CPU voltage with frequency. Very useful to save |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 998 | * power, but most VIA C3 processors aren't supporting it. */ |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 999 | module_param(scale_voltage, int, 0644); |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 1000 | MODULE_PARM_DESC(scale_voltage, "Scale voltage of processor"); |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 1001 | /* Force revision key to 0 for processors which doesn't |
| 1002 | * support voltage scaling, but are introducing itself as |
| 1003 | * such. */ |
| 1004 | module_param(revid_errata, int, 0644); |
| 1005 | MODULE_PARM_DESC(revid_errata, "Ignore CPU Revision ID"); |
Rafał Bilski | b5811bc | 2012-12-15 00:45:02 +0100 | [diff] [blame] | 1006 | /* By default driver is disabled to prevent incompatible |
| 1007 | * system freeze. */ |
| 1008 | module_param(enable, int, 0644); |
| 1009 | MODULE_PARM_DESC(enable, "Enable driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1010 | |
Dave Jones | d5e80b4 | 2014-12-19 11:20:43 -0500 | [diff] [blame] | 1011 | MODULE_AUTHOR("Dave Jones"); |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 1012 | MODULE_DESCRIPTION("Longhaul driver for VIA Cyrix processors."); |
| 1013 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1014 | |
Rafa³ Bilski | 0d6daba | 2006-07-07 08:48:26 +0200 | [diff] [blame] | 1015 | late_initcall(longhaul_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1016 | module_exit(longhaul_exit); |