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 | |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 24 | #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt |
| 25 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | #include <linux/kernel.h> |
| 27 | #include <linux/module.h> |
| 28 | #include <linux/moduleparam.h> |
| 29 | #include <linux/init.h> |
| 30 | #include <linux/cpufreq.h> |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 31 | #include <linux/pci.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 32 | #include <linux/slab.h> |
| 33 | #include <linux/string.h> |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 34 | #include <linux/delay.h> |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 35 | #include <linux/timex.h> |
| 36 | #include <linux/io.h> |
| 37 | #include <linux/acpi.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | |
| 39 | #include <asm/msr.h> |
Andi Kleen | fa8031a | 2012-01-26 00:09:12 +0100 | [diff] [blame] | 40 | #include <asm/cpu_device_id.h> |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 41 | #include <acpi/processor.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 42 | |
| 43 | #include "longhaul.h" |
| 44 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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)) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 350 | pr_info("Failed to set requested frequency!\n"); |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 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) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 356 | pr_info("Enabling \"Ignore Revision ID\" option\n"); |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 357 | revid_errata = 1; |
| 358 | msleep(200); |
| 359 | goto retry_loop; |
| 360 | } |
| 361 | /* Why ACPI C3 sometimes doesn't work is a mystery for me. |
| 362 | * But it does happen. Processor is entering ACPI C3 state, |
| 363 | * but it doesn't change frequency. I tried poking various |
| 364 | * bits in northbridge registers, but without success. */ |
| 365 | if (longhaul_flags & USE_ACPI_C3) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 366 | pr_info("Disabling ACPI C3 support\n"); |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 367 | longhaul_flags &= ~USE_ACPI_C3; |
| 368 | if (revid_errata) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 369 | pr_info("Disabling \"Ignore Revision ID\" option\n"); |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 370 | revid_errata = 0; |
| 371 | } |
| 372 | msleep(200); |
| 373 | goto retry_loop; |
| 374 | } |
| 375 | /* This shouldn't happen. Longhaul ver. 2 was reported not |
| 376 | * working on processors without voltage scaling, but with |
| 377 | * RevID = 1. RevID errata will make things right. Just |
| 378 | * to be 100% sure. */ |
| 379 | if (longhaul_version == TYPE_LONGHAUL_V2) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 380 | pr_info("Switching to Longhaul ver. 1\n"); |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 381 | longhaul_version = TYPE_LONGHAUL_V1; |
| 382 | msleep(200); |
| 383 | goto retry_loop; |
| 384 | } |
| 385 | } |
Rafał Bilski | 489dc5c | 2007-05-17 22:39:02 +0200 | [diff] [blame] | 386 | |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 387 | if (!bm_timeout) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 388 | pr_info("Warning: Timeout while waiting for idle PCI bus\n"); |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 389 | return -EBUSY; |
| 390 | } |
| 391 | |
| 392 | return 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 393 | } |
| 394 | |
| 395 | /* |
| 396 | * Centaur decided to make life a little more tricky. |
| 397 | * Only longhaul v1 is allowed to read EBLCR BSEL[0:1]. |
| 398 | * Samuel2 and above have to try and guess what the FSB is. |
| 399 | * We do this by assuming we booted at maximum multiplier, and interpolate |
| 400 | * between that value multiplied by possible FSBs and cpu_mhz which |
| 401 | * was calculated at boot time. Really ugly, but no other way to do this. |
| 402 | */ |
| 403 | |
| 404 | #define ROUNDING 0xf |
| 405 | |
Rafa³ Bilski | 24ebead | 2007-01-01 23:49:34 +0100 | [diff] [blame] | 406 | static int guess_fsb(int mult) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 407 | { |
Rafa³ Bilski | 46ef955 | 2007-02-04 15:58:46 +0100 | [diff] [blame] | 408 | int speed = cpu_khz / 1000; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 409 | int i; |
Rafa³ Bilski | 46ef955 | 2007-02-04 15:58:46 +0100 | [diff] [blame] | 410 | int speeds[] = { 666, 1000, 1333, 2000 }; |
| 411 | int f_max, f_min; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 412 | |
Rafa³ Bilski | 46ef955 | 2007-02-04 15:58:46 +0100 | [diff] [blame] | 413 | for (i = 0; i < 4; i++) { |
| 414 | f_max = ((speeds[i] * mult) + 50) / 100; |
| 415 | f_max += (ROUNDING / 2); |
| 416 | f_min = f_max - ROUNDING; |
| 417 | if ((speed <= f_max) && (speed >= f_min)) |
| 418 | return speeds[i] / 10; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 419 | } |
| 420 | return 0; |
| 421 | } |
| 422 | |
| 423 | |
Paul Gortmaker | 2760984 | 2013-06-19 13:54:04 -0400 | [diff] [blame] | 424 | static int longhaul_get_ranges(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 425 | { |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 426 | unsigned int i, j, k = 0; |
| 427 | unsigned int ratio; |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 428 | int mult; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 429 | |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 430 | /* Get current frequency */ |
| 431 | mult = longhaul_get_cpu_mult(); |
| 432 | if (mult == -1) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 433 | pr_info("Invalid (reserved) multiplier!\n"); |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 434 | return -EINVAL; |
| 435 | } |
| 436 | fsb = guess_fsb(mult); |
| 437 | if (fsb == 0) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 438 | pr_info("Invalid (reserved) FSB!\n"); |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 439 | return -EINVAL; |
| 440 | } |
| 441 | /* Get max multiplier - as we always did. |
Lucas De Marchi | 0d2eb44 | 2011-03-17 16:24:16 -0300 | [diff] [blame] | 442 | * Longhaul MSR is useful only when voltage scaling is enabled. |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 443 | * C3 is booting at max anyway. */ |
| 444 | maxmult = mult; |
| 445 | /* Get min multiplier */ |
Rafa³ Bilski | 9addf3b | 2007-02-07 22:53:29 +0100 | [diff] [blame] | 446 | switch (cpu_model) { |
| 447 | case CPU_NEHEMIAH: |
| 448 | minmult = 50; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 449 | break; |
Rafa³ Bilski | 9addf3b | 2007-02-07 22:53:29 +0100 | [diff] [blame] | 450 | case CPU_NEHEMIAH_C: |
| 451 | minmult = 40; |
| 452 | break; |
| 453 | default: |
| 454 | minmult = 30; |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 455 | break; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 456 | } |
| 457 | |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 458 | pr_debug("MinMult:%d.%dx MaxMult:%d.%dx\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 459 | minmult/10, minmult%10, maxmult/10, maxmult%10); |
| 460 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 461 | highest_speed = calc_speed(maxmult); |
| 462 | lowest_speed = calc_speed(minmult); |
Dominik Brodowski | 2d06d8c | 2011-03-27 15:04:46 +0200 | [diff] [blame] | 463 | pr_debug("FSB:%dMHz Lowest speed: %s Highest speed:%s\n", fsb, |
Alexey Starikovskiy | cee324b | 2007-02-02 19:48:22 +0300 | [diff] [blame] | 464 | print_speed(lowest_speed/1000), |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 465 | print_speed(highest_speed/1000)); |
| 466 | |
| 467 | if (lowest_speed == highest_speed) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 468 | pr_info("highestspeed == lowest, aborting\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 469 | return -EINVAL; |
| 470 | } |
| 471 | if (lowest_speed > highest_speed) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 472 | pr_info("nonsense! lowest (%d > %d) !\n", |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 473 | lowest_speed, highest_speed); |
| 474 | return -EINVAL; |
| 475 | } |
| 476 | |
Viresh Kumar | 71508a1 | 2014-03-28 19:11:46 +0530 | [diff] [blame] | 477 | longhaul_table = kzalloc((numscales + 1) * sizeof(*longhaul_table), |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 478 | GFP_KERNEL); |
| 479 | if (!longhaul_table) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 480 | return -ENOMEM; |
| 481 | |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 482 | for (j = 0; j < numscales; j++) { |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 483 | ratio = mults[j]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 484 | if (ratio == -1) |
| 485 | continue; |
| 486 | if (ratio > maxmult || ratio < minmult) |
| 487 | continue; |
| 488 | longhaul_table[k].frequency = calc_speed(ratio); |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 489 | longhaul_table[k].driver_data = j; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 490 | k++; |
| 491 | } |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 492 | if (k <= 1) { |
| 493 | kfree(longhaul_table); |
| 494 | return -ENODEV; |
| 495 | } |
| 496 | /* Sort */ |
| 497 | for (j = 0; j < k - 1; j++) { |
| 498 | unsigned int min_f, min_i; |
| 499 | min_f = longhaul_table[j].frequency; |
| 500 | min_i = j; |
| 501 | for (i = j + 1; i < k; i++) { |
| 502 | if (longhaul_table[i].frequency < min_f) { |
| 503 | min_f = longhaul_table[i].frequency; |
| 504 | min_i = i; |
| 505 | } |
| 506 | } |
| 507 | if (min_i != j) { |
Dave Jones | 9142022 | 2009-02-04 15:28:54 -0500 | [diff] [blame] | 508 | swap(longhaul_table[j].frequency, |
| 509 | longhaul_table[min_i].frequency); |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 510 | swap(longhaul_table[j].driver_data, |
| 511 | longhaul_table[min_i].driver_data); |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 512 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 513 | } |
| 514 | |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 515 | longhaul_table[k].frequency = CPUFREQ_TABLE_END; |
| 516 | |
| 517 | /* Find index we are running on */ |
| 518 | for (j = 0; j < k; j++) { |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 519 | if (mults[longhaul_table[j].driver_data & 0x1f] == mult) { |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 520 | longhaul_index = j; |
| 521 | break; |
| 522 | } |
| 523 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 524 | return 0; |
| 525 | } |
| 526 | |
| 527 | |
Paul Gortmaker | 2760984 | 2013-06-19 13:54:04 -0400 | [diff] [blame] | 528 | static void longhaul_setup_voltagescaling(void) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 529 | { |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 530 | struct cpufreq_frequency_table *freq_pos; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 531 | union msr_longhaul longhaul; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 532 | struct mV_pos minvid, maxvid, vid; |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 533 | unsigned int j, speed, pos, kHz_step, numvscales; |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 534 | int min_vid_speed; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 535 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 536 | rdmsrl(MSR_VIA_LONGHAUL, longhaul.val); |
| 537 | if (!(longhaul.bits.RevisionID & 1)) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 538 | pr_info("Voltage scaling not supported by CPU\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 539 | return; |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 540 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 541 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 542 | if (!longhaul.bits.VRMRev) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 543 | pr_info("VRM 8.5\n"); |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 544 | vrm_mV_table = &vrm85_mV[0]; |
| 545 | mV_vrm_table = &mV_vrm85[0]; |
| 546 | } else { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 547 | pr_info("Mobile VRM\n"); |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 548 | if (cpu_model < CPU_NEHEMIAH) |
| 549 | return; |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 550 | vrm_mV_table = &mobilevrm_mV[0]; |
| 551 | mV_vrm_table = &mV_mobilevrm[0]; |
| 552 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 553 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 554 | minvid = vrm_mV_table[longhaul.bits.MinimumVID]; |
| 555 | maxvid = vrm_mV_table[longhaul.bits.MaximumVID]; |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 556 | |
| 557 | if (minvid.mV == 0 || maxvid.mV == 0 || minvid.mV > maxvid.mV) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 558 | pr_info("Bogus values Min:%d.%03d Max:%d.%03d - Voltage scaling disabled\n", |
Joe Perches | b49c22a | 2016-04-05 13:28:24 -0700 | [diff] [blame] | 559 | minvid.mV/1000, minvid.mV%1000, |
| 560 | maxvid.mV/1000, maxvid.mV%1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 561 | return; |
| 562 | } |
| 563 | |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 564 | if (minvid.mV == maxvid.mV) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 565 | pr_info("Claims to support voltage scaling but min & max are both %d.%03d - Voltage scaling disabled\n", |
Joe Perches | b49c22a | 2016-04-05 13:28:24 -0700 | [diff] [blame] | 566 | maxvid.mV/1000, maxvid.mV%1000); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 567 | return; |
| 568 | } |
| 569 | |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 570 | /* How many voltage steps*/ |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 571 | numvscales = maxvid.pos - minvid.pos + 1; |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 572 | pr_info("Max VID=%d.%03d Min VID=%d.%03d, %d possible voltage scales\n", |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 573 | maxvid.mV/1000, maxvid.mV%1000, |
| 574 | minvid.mV/1000, minvid.mV%1000, |
| 575 | numvscales); |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 576 | |
| 577 | /* Calculate max frequency at min voltage */ |
| 578 | j = longhaul.bits.MinMHzBR; |
| 579 | if (longhaul.bits.MinMHzBR4) |
| 580 | j += 16; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 581 | min_vid_speed = eblcr[j]; |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 582 | if (min_vid_speed == -1) |
| 583 | return; |
| 584 | switch (longhaul.bits.MinMHzFSB) { |
| 585 | case 0: |
| 586 | min_vid_speed *= 13333; |
| 587 | break; |
| 588 | case 1: |
| 589 | min_vid_speed *= 10000; |
| 590 | break; |
| 591 | case 3: |
| 592 | min_vid_speed *= 6666; |
| 593 | break; |
| 594 | default: |
| 595 | return; |
| 596 | break; |
| 597 | } |
| 598 | if (min_vid_speed >= highest_speed) |
| 599 | return; |
| 600 | /* Calculate kHz for one voltage step */ |
| 601 | kHz_step = (highest_speed - min_vid_speed) / numvscales; |
| 602 | |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 603 | cpufreq_for_each_entry(freq_pos, longhaul_table) { |
| 604 | speed = freq_pos->frequency; |
Rafa³ Bilski | 348f31e | 2007-02-08 18:56:04 +0100 | [diff] [blame] | 605 | if (speed > min_vid_speed) |
| 606 | pos = (speed - min_vid_speed) / kHz_step + minvid.pos; |
| 607 | else |
| 608 | pos = minvid.pos; |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 609 | freq_pos->driver_data |= mV_vrm_table[pos] << 8; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 610 | vid = vrm_mV_table[mV_vrm_table[pos]]; |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 611 | pr_info("f: %d kHz, index: %d, vid: %d mV\n", |
Stratos Karafotis | 041526f | 2014-04-25 23:15:38 +0300 | [diff] [blame] | 612 | speed, (int)(freq_pos - longhaul_table), vid.mV); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 613 | } |
| 614 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 615 | can_scale_voltage = 1; |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 616 | pr_info("Voltage scaling enabled\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 617 | } |
| 618 | |
| 619 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 620 | static int longhaul_target(struct cpufreq_policy *policy, |
Viresh Kumar | 9c0ebcf | 2013-10-25 19:45:48 +0530 | [diff] [blame] | 621 | unsigned int table_index) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 622 | { |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 623 | unsigned int i; |
| 624 | unsigned int dir = 0; |
| 625 | u8 vid, current_vid; |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 626 | int retval = 0; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 627 | |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 628 | if (!can_scale_voltage) |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 629 | retval = longhaul_setstate(policy, table_index); |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 630 | else { |
| 631 | /* On test system voltage transitions exceeding single |
| 632 | * step up or down were turning motherboard off. Both |
| 633 | * "ondemand" and "userspace" are unsafe. C7 is doing |
| 634 | * this in hardware, C3 is old and we need to do this |
| 635 | * in software. */ |
| 636 | i = longhaul_index; |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 637 | current_vid = (longhaul_table[longhaul_index].driver_data >> 8); |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 638 | current_vid &= 0x1f; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 639 | if (table_index > longhaul_index) |
| 640 | dir = 1; |
| 641 | while (i != table_index) { |
Viresh Kumar | 5070158 | 2013-03-30 16:25:15 +0530 | [diff] [blame] | 642 | vid = (longhaul_table[i].driver_data >> 8) & 0x1f; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 643 | if (vid != current_vid) { |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 644 | retval = longhaul_setstate(policy, i); |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 645 | current_vid = vid; |
| 646 | msleep(200); |
| 647 | } |
| 648 | if (dir) |
| 649 | i++; |
| 650 | else |
| 651 | i--; |
| 652 | } |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 653 | retval = longhaul_setstate(policy, table_index); |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 654 | } |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 655 | |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 656 | longhaul_index = table_index; |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 657 | return retval; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 658 | } |
| 659 | |
| 660 | |
| 661 | static unsigned int longhaul_get(unsigned int cpu) |
| 662 | { |
| 663 | if (cpu) |
| 664 | return 0; |
| 665 | return calc_speed(longhaul_get_cpu_mult()); |
| 666 | } |
| 667 | |
Adrian Bunk | c4a96c1 | 2006-07-09 19:53:08 +0200 | [diff] [blame] | 668 | static acpi_status longhaul_walk_callback(acpi_handle obj_handle, |
| 669 | u32 nesting_level, |
| 670 | void *context, void **return_value) |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 671 | { |
| 672 | struct acpi_device *d; |
| 673 | |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 674 | if (acpi_bus_get_device(obj_handle, &d)) |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 675 | return 0; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 676 | |
Jan Engelhardt | ade1af7 | 2008-01-30 13:33:23 +0100 | [diff] [blame] | 677 | *return_value = acpi_driver_data(d); |
Rafa³ Bilski | dadb49d | 2006-07-03 07:19:05 +0200 | [diff] [blame] | 678 | return 1; |
| 679 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 680 | |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 681 | /* VIA don't support PM2 reg, but have something similar */ |
| 682 | static int enable_arbiter_disable(void) |
| 683 | { |
| 684 | struct pci_dev *dev; |
Rafał Bilski | 73e107d | 2007-05-28 21:56:19 +0200 | [diff] [blame] | 685 | int status = 1; |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 686 | int reg; |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 687 | u8 pci_cmd; |
| 688 | |
| 689 | /* Find PLE133 host bridge */ |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 690 | reg = 0x78; |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 691 | dev = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8601_0, |
| 692 | NULL); |
Linus Torvalds | 4d5709a | 2007-10-12 15:42:01 -0700 | [diff] [blame] | 693 | /* Find PM133/VT8605 host bridge */ |
| 694 | if (dev == NULL) |
| 695 | dev = pci_get_device(PCI_VENDOR_ID_VIA, |
| 696 | PCI_DEVICE_ID_VIA_8605_0, NULL); |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 697 | /* Find CLE266 host bridge */ |
| 698 | if (dev == NULL) { |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 699 | reg = 0x76; |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 700 | dev = pci_get_device(PCI_VENDOR_ID_VIA, |
| 701 | PCI_DEVICE_ID_VIA_862X_0, NULL); |
Rafa³ Bilski | db2fb9d | 2006-11-30 03:47:41 +0100 | [diff] [blame] | 702 | /* Find CN400 V-Link host bridge */ |
| 703 | if (dev == NULL) |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 704 | dev = pci_get_device(PCI_VENDOR_ID_VIA, 0x7259, NULL); |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 705 | } |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 706 | if (dev != NULL) { |
| 707 | /* Enable access to port 0x22 */ |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 708 | pci_read_config_byte(dev, reg, &pci_cmd); |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 709 | if (!(pci_cmd & 1<<7)) { |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 710 | pci_cmd |= 1<<7; |
rafalbilski@interia.pl | 7f1be89 | 2006-09-24 20:28:13 +0200 | [diff] [blame] | 711 | pci_write_config_byte(dev, reg, pci_cmd); |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 712 | pci_read_config_byte(dev, reg, &pci_cmd); |
| 713 | if (!(pci_cmd & 1<<7)) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 714 | pr_err("Can't enable access to port 0x22\n"); |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 715 | status = 0; |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 716 | } |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 717 | } |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 718 | pci_dev_put(dev); |
| 719 | return status; |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 720 | } |
| 721 | return 0; |
| 722 | } |
| 723 | |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 724 | static int longhaul_setup_southbridge(void) |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 725 | { |
| 726 | struct pci_dev *dev; |
| 727 | u8 pci_cmd; |
| 728 | |
| 729 | /* Find VT8235 southbridge */ |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 730 | 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] | 731 | if (dev == NULL) |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 732 | /* Find VT8237 southbridge */ |
Rafał Bilski | 920dd0f | 2007-05-17 22:35:29 +0200 | [diff] [blame] | 733 | dev = pci_get_device(PCI_VENDOR_ID_VIA, |
| 734 | PCI_DEVICE_ID_VIA_8237, NULL); |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 735 | if (dev != NULL) { |
| 736 | /* Set transition time to max */ |
| 737 | pci_read_config_byte(dev, 0xec, &pci_cmd); |
| 738 | pci_cmd &= ~(1 << 2); |
| 739 | pci_write_config_byte(dev, 0xec, pci_cmd); |
| 740 | pci_read_config_byte(dev, 0xe4, &pci_cmd); |
| 741 | pci_cmd &= ~(1 << 7); |
| 742 | pci_write_config_byte(dev, 0xe4, pci_cmd); |
| 743 | pci_read_config_byte(dev, 0xe5, &pci_cmd); |
| 744 | pci_cmd |= 1 << 7; |
| 745 | pci_write_config_byte(dev, 0xe5, pci_cmd); |
Rafał Bilski | 275bc6b | 2007-06-05 22:08:50 +0200 | [diff] [blame] | 746 | /* Get address of ACPI registers block*/ |
| 747 | pci_read_config_byte(dev, 0x81, &pci_cmd); |
| 748 | if (pci_cmd & 1 << 7) { |
| 749 | pci_read_config_dword(dev, 0x88, &acpi_regs_addr); |
| 750 | acpi_regs_addr &= 0xff00; |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 751 | pr_info("ACPI I/O at 0x%x\n", acpi_regs_addr); |
Rafał Bilski | 275bc6b | 2007-06-05 22:08:50 +0200 | [diff] [blame] | 752 | } |
| 753 | |
Rafał Bilski | fb48e15 | 2007-03-02 20:12:27 +0100 | [diff] [blame] | 754 | pci_dev_put(dev); |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 755 | return 1; |
| 756 | } |
| 757 | return 0; |
| 758 | } |
| 759 | |
Paul Gortmaker | 2760984 | 2013-06-19 13:54:04 -0400 | [diff] [blame] | 760 | static int longhaul_cpu_init(struct cpufreq_policy *policy) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 761 | { |
Mike Travis | 92cb761 | 2007-10-19 20:35:04 +0200 | [diff] [blame] | 762 | struct cpuinfo_x86 *c = &cpu_data(0); |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 763 | char *cpuname = NULL; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 764 | int ret; |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 765 | u32 lo, hi; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 766 | |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 767 | /* Check what we have on this motherboard */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 768 | switch (c->x86_model) { |
| 769 | case 6: |
| 770 | cpu_model = CPU_SAMUEL; |
| 771 | cpuname = "C3 'Samuel' [C5A]"; |
| 772 | longhaul_version = TYPE_LONGHAUL_V1; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 773 | memcpy(mults, samuel1_mults, sizeof(samuel1_mults)); |
| 774 | memcpy(eblcr, samuel1_eblcr, sizeof(samuel1_eblcr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 775 | break; |
| 776 | |
| 777 | case 7: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 778 | switch (c->x86_mask) { |
| 779 | case 0: |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 780 | longhaul_version = TYPE_LONGHAUL_V1; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 781 | cpu_model = CPU_SAMUEL2; |
| 782 | cpuname = "C3 'Samuel 2' [C5B]"; |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 783 | /* Note, this is not a typo, early Samuel2's had |
| 784 | * Samuel1 ratios. */ |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 785 | memcpy(mults, samuel1_mults, sizeof(samuel1_mults)); |
| 786 | memcpy(eblcr, samuel2_eblcr, sizeof(samuel2_eblcr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 787 | break; |
| 788 | case 1 ... 15: |
Krzysztof Helt | f7f3cad | 2009-10-24 17:25:38 +0200 | [diff] [blame] | 789 | longhaul_version = TYPE_LONGHAUL_V2; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 790 | if (c->x86_mask < 8) { |
| 791 | cpu_model = CPU_SAMUEL2; |
| 792 | cpuname = "C3 'Samuel 2' [C5B]"; |
| 793 | } else { |
| 794 | cpu_model = CPU_EZRA; |
| 795 | cpuname = "C3 'Ezra' [C5C]"; |
| 796 | } |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 797 | memcpy(mults, ezra_mults, sizeof(ezra_mults)); |
| 798 | memcpy(eblcr, ezra_eblcr, sizeof(ezra_eblcr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 799 | break; |
| 800 | } |
| 801 | break; |
| 802 | |
| 803 | case 8: |
| 804 | cpu_model = CPU_EZRA_T; |
| 805 | cpuname = "C3 'Ezra-T' [C5M]"; |
| 806 | longhaul_version = TYPE_POWERSAVER; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 807 | numscales = 32; |
| 808 | memcpy(mults, ezrat_mults, sizeof(ezrat_mults)); |
| 809 | memcpy(eblcr, ezrat_eblcr, sizeof(ezrat_eblcr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 810 | break; |
| 811 | |
| 812 | case 9: |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 813 | longhaul_version = TYPE_POWERSAVER; |
Rafa³ Bilski | 0d44b2b | 2007-01-31 23:50:49 +0100 | [diff] [blame] | 814 | numscales = 32; |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 815 | memcpy(mults, nehemiah_mults, sizeof(nehemiah_mults)); |
| 816 | memcpy(eblcr, nehemiah_eblcr, sizeof(nehemiah_eblcr)); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 817 | switch (c->x86_mask) { |
| 818 | case 0 ... 1: |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 819 | cpu_model = CPU_NEHEMIAH; |
Rafa³ Bilski | e57501c | 2007-02-08 23:12:02 +0100 | [diff] [blame] | 820 | cpuname = "C3 'Nehemiah A' [C5XLOE]"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 821 | break; |
| 822 | case 2 ... 4: |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 823 | cpu_model = CPU_NEHEMIAH; |
Rafa³ Bilski | e57501c | 2007-02-08 23:12:02 +0100 | [diff] [blame] | 824 | cpuname = "C3 'Nehemiah B' [C5XLOH]"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 825 | break; |
| 826 | case 5 ... 15: |
Rafa³ Bilski | 980342a | 2007-01-31 23:42:47 +0100 | [diff] [blame] | 827 | cpu_model = CPU_NEHEMIAH_C; |
Rafa³ Bilski | e57501c | 2007-02-08 23:12:02 +0100 | [diff] [blame] | 828 | cpuname = "C3 'Nehemiah C' [C5P]"; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 829 | break; |
| 830 | } |
| 831 | break; |
| 832 | |
| 833 | default: |
| 834 | cpuname = "Unknown"; |
| 835 | break; |
| 836 | } |
Rafa³ Bilski | 2b8c0e1 | 2007-02-14 22:00:37 +0100 | [diff] [blame] | 837 | /* Check Longhaul ver. 2 */ |
| 838 | if (longhaul_version == TYPE_LONGHAUL_V2) { |
| 839 | rdmsr(MSR_VIA_LONGHAUL, lo, hi); |
| 840 | if (lo == 0 && hi == 0) |
| 841 | /* Looks like MSR isn't present */ |
| 842 | longhaul_version = TYPE_LONGHAUL_V1; |
| 843 | } |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 844 | |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 845 | pr_info("VIA %s CPU detected. ", cpuname); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 846 | switch (longhaul_version) { |
| 847 | case TYPE_LONGHAUL_V1: |
| 848 | case TYPE_LONGHAUL_V2: |
Joe Perches | b49c22a | 2016-04-05 13:28:24 -0700 | [diff] [blame] | 849 | pr_cont("Longhaul v%d supported\n", longhaul_version); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 850 | break; |
| 851 | case TYPE_POWERSAVER: |
Joe Perches | b49c22a | 2016-04-05 13:28:24 -0700 | [diff] [blame] | 852 | pr_cont("Powersaver supported\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 853 | break; |
| 854 | }; |
| 855 | |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 856 | /* Doesn't hurt */ |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 857 | longhaul_setup_southbridge(); |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 858 | |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 859 | /* Find ACPI data for processor */ |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 860 | acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT, |
Lin Ming | 2263576 | 2009-11-13 10:06:08 +0800 | [diff] [blame] | 861 | ACPI_UINT32_MAX, &longhaul_walk_callback, NULL, |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 862 | NULL, (void *)&pr); |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 863 | |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 864 | /* Check ACPI support for C3 state */ |
Dave Jones | 7ab77e0 | 2007-04-20 15:58:00 -0400 | [diff] [blame] | 865 | if (pr != NULL && longhaul_version == TYPE_POWERSAVER) { |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 866 | cx = &pr->power.states[ACPI_STATE_C3]; |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 867 | if (cx->address > 0 && cx->latency <= 1000) |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 868 | longhaul_flags |= USE_ACPI_C3; |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 869 | } |
Rafał Bilski | 905497c | 2007-07-08 21:51:26 +0200 | [diff] [blame] | 870 | /* Disable if it isn't working */ |
| 871 | if (disable_acpi_c3) |
| 872 | longhaul_flags &= ~USE_ACPI_C3; |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 873 | /* Check if northbridge is friendly */ |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 874 | if (enable_arbiter_disable()) |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 875 | longhaul_flags |= USE_NORTHBRIDGE; |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 876 | |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 877 | /* Check ACPI support for bus master arbiter disable */ |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 878 | if (!(longhaul_flags & USE_ACPI_C3 |
| 879 | || longhaul_flags & USE_NORTHBRIDGE) |
| 880 | && ((pr == NULL) || !(pr->flags.bm_control))) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 881 | pr_err("No ACPI support: Unsupported northbridge\n"); |
Rafa³ Bilski | 264166e | 2006-12-24 14:04:23 +0100 | [diff] [blame] | 882 | return -ENODEV; |
| 883 | } |
| 884 | |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 885 | if (longhaul_flags & USE_NORTHBRIDGE) |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 886 | pr_info("Using northbridge support\n"); |
Rafał Bilski | 7d5edcc | 2007-05-17 22:33:46 +0200 | [diff] [blame] | 887 | if (longhaul_flags & USE_ACPI_C3) |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 888 | pr_info("Using ACPI support\n"); |
Rafa³ Bilski | 179da8e | 2006-08-08 19:12:20 +0200 | [diff] [blame] | 889 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 890 | ret = longhaul_get_ranges(); |
| 891 | if (ret != 0) |
| 892 | return ret; |
| 893 | |
Rafa³ Bilski | 786f46b | 2007-02-04 18:43:12 +0100 | [diff] [blame] | 894 | if ((longhaul_version != TYPE_LONGHAUL_V1) && (scale_voltage != 0)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 895 | longhaul_setup_voltagescaling(); |
| 896 | |
Dave Jones | 6778bae | 2005-05-31 19:03:51 -0700 | [diff] [blame] | 897 | policy->cpuinfo.transition_latency = 200000; /* nsec */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 898 | |
Viresh Kumar | 30aa534 | 2013-09-16 18:56:20 +0530 | [diff] [blame] | 899 | return cpufreq_table_validate_and_show(policy, longhaul_table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 900 | } |
| 901 | |
Linus Torvalds | 221dee2 | 2007-02-26 14:55:48 -0800 | [diff] [blame] | 902 | static struct cpufreq_driver longhaul_driver = { |
Viresh Kumar | 3a4d034 | 2013-10-03 20:28:10 +0530 | [diff] [blame] | 903 | .verify = cpufreq_generic_frequency_table_verify, |
Viresh Kumar | 9c0ebcf | 2013-10-25 19:45:48 +0530 | [diff] [blame] | 904 | .target_index = longhaul_target, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 905 | .get = longhaul_get, |
| 906 | .init = longhaul_cpu_init, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 907 | .name = "longhaul", |
Viresh Kumar | 3a4d034 | 2013-10-03 20:28:10 +0530 | [diff] [blame] | 908 | .attr = cpufreq_generic_attr, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 909 | }; |
| 910 | |
Andi Kleen | fa8031a | 2012-01-26 00:09:12 +0100 | [diff] [blame] | 911 | static const struct x86_cpu_id longhaul_id[] = { |
| 912 | { X86_VENDOR_CENTAUR, 6 }, |
| 913 | {} |
| 914 | }; |
| 915 | MODULE_DEVICE_TABLE(x86cpu, longhaul_id); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 916 | |
| 917 | static int __init longhaul_init(void) |
| 918 | { |
Mike Travis | 92cb761 | 2007-10-19 20:35:04 +0200 | [diff] [blame] | 919 | struct cpuinfo_x86 *c = &cpu_data(0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 920 | |
Andi Kleen | fa8031a | 2012-01-26 00:09:12 +0100 | [diff] [blame] | 921 | if (!x86_match_cpu(longhaul_id)) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 922 | return -ENODEV; |
| 923 | |
Rafał Bilski | b5811bc | 2012-12-15 00:45:02 +0100 | [diff] [blame] | 924 | if (!enable) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 925 | pr_err("Option \"enable\" not set - Aborting\n"); |
Rafał Bilski | b5811bc | 2012-12-15 00:45:02 +0100 | [diff] [blame] | 926 | return -ENODEV; |
| 927 | } |
Rafa³ Bilski | 48b7bde | 2006-07-04 17:50:57 +0200 | [diff] [blame] | 928 | #ifdef CONFIG_SMP |
| 929 | if (num_online_cpus() > 1) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 930 | pr_err("More than 1 CPU detected, longhaul disabled\n"); |
Dave Jones | 1cfe201 | 2006-12-28 22:30:16 -0500 | [diff] [blame] | 931 | return -ENODEV; |
Rafa³ Bilski | 48b7bde | 2006-07-04 17:50:57 +0200 | [diff] [blame] | 932 | } |
| 933 | #endif |
| 934 | #ifdef CONFIG_X86_IO_APIC |
Borislav Petkov | 93984fb | 2016-04-04 22:25:00 +0200 | [diff] [blame] | 935 | if (boot_cpu_has(X86_FEATURE_APIC)) { |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 936 | pr_err("APIC detected. Longhaul is currently broken in this configuration.\n"); |
Rafa³ Bilski | 48b7bde | 2006-07-04 17:50:57 +0200 | [diff] [blame] | 937 | return -ENODEV; |
| 938 | } |
| 939 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 940 | switch (c->x86_model) { |
| 941 | case 6 ... 9: |
| 942 | return cpufreq_register_driver(&longhaul_driver); |
Dave Jones | 8ec9822 | 2006-12-17 19:07:35 -0500 | [diff] [blame] | 943 | case 10: |
Joe Perches | 1c5864e | 2016-04-05 13:28:25 -0700 | [diff] [blame] | 944 | pr_err("Use acpi-cpufreq driver for VIA C7\n"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 945 | default: |
Fernando Carrijo | c19a28e | 2009-01-07 18:09:08 -0800 | [diff] [blame] | 946 | ; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 947 | } |
| 948 | |
| 949 | return -ENODEV; |
| 950 | } |
| 951 | |
| 952 | |
| 953 | static void __exit longhaul_exit(void) |
| 954 | { |
Viresh Kumar | b43a7ff | 2013-03-24 11:56:43 +0530 | [diff] [blame] | 955 | struct cpufreq_policy *policy = cpufreq_cpu_get(0); |
Dave Jones | 8eebf1a | 2006-05-30 17:40:16 -0400 | [diff] [blame] | 956 | int i; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 957 | |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 958 | for (i = 0; i < numscales; i++) { |
| 959 | if (mults[i] == maxmult) { |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 960 | struct cpufreq_freqs freqs; |
| 961 | |
| 962 | freqs.old = policy->cur; |
| 963 | freqs.new = longhaul_table[i].frequency; |
| 964 | freqs.flags = 0; |
| 965 | |
| 966 | cpufreq_freq_transition_begin(policy, &freqs); |
Viresh Kumar | b43a7ff | 2013-03-24 11:56:43 +0530 | [diff] [blame] | 967 | longhaul_setstate(policy, i); |
Srivatsa S. Bhat | 7aa0557 | 2014-04-29 00:24:09 +0530 | [diff] [blame] | 968 | cpufreq_freq_transition_end(policy, &freqs, 0); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 969 | break; |
| 970 | } |
| 971 | } |
| 972 | |
Viresh Kumar | b43a7ff | 2013-03-24 11:56:43 +0530 | [diff] [blame] | 973 | cpufreq_cpu_put(policy); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 974 | cpufreq_unregister_driver(&longhaul_driver); |
| 975 | kfree(longhaul_table); |
| 976 | } |
| 977 | |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 978 | /* Even if BIOS is exporting ACPI C3 state, and it is used |
| 979 | * with success when CPU is idle, this state doesn't |
| 980 | * trigger frequency transition in some cases. */ |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 981 | module_param(disable_acpi_c3, int, 0644); |
Rafał Bilski | 905497c | 2007-07-08 21:51:26 +0200 | [diff] [blame] | 982 | 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] | 983 | /* Change CPU voltage with frequency. Very useful to save |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 984 | * power, but most VIA C3 processors aren't supporting it. */ |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 985 | module_param(scale_voltage, int, 0644); |
Rafa³ Bilski | db44aaf | 2006-08-16 01:07:33 +0200 | [diff] [blame] | 986 | MODULE_PARM_DESC(scale_voltage, "Scale voltage of processor"); |
Rafal Bilski | 52a2638 | 2007-10-07 00:24:32 -0700 | [diff] [blame] | 987 | /* Force revision key to 0 for processors which doesn't |
| 988 | * support voltage scaling, but are introducing itself as |
| 989 | * such. */ |
| 990 | module_param(revid_errata, int, 0644); |
| 991 | MODULE_PARM_DESC(revid_errata, "Ignore CPU Revision ID"); |
Rafał Bilski | b5811bc | 2012-12-15 00:45:02 +0100 | [diff] [blame] | 992 | /* By default driver is disabled to prevent incompatible |
| 993 | * system freeze. */ |
| 994 | module_param(enable, int, 0644); |
| 995 | MODULE_PARM_DESC(enable, "Enable driver"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 996 | |
Dave Jones | d5e80b4 | 2014-12-19 11:20:43 -0500 | [diff] [blame] | 997 | MODULE_AUTHOR("Dave Jones"); |
Dave Jones | ac617bd | 2009-01-17 23:29:53 -0500 | [diff] [blame] | 998 | MODULE_DESCRIPTION("Longhaul driver for VIA Cyrix processors."); |
| 999 | MODULE_LICENSE("GPL"); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1000 | |
Rafa³ Bilski | 0d6daba | 2006-07-07 08:48:26 +0200 | [diff] [blame] | 1001 | late_initcall(longhaul_init); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1002 | module_exit(longhaul_exit); |