1303760b4SJean Delvare /* 215872212SFrank Myhr * hwmon-vid.c - VID/VRM/VRD voltage conversions 315872212SFrank Myhr * 415872212SFrank Myhr * Copyright (c) 2004 Rudolf Marek <r.marek@assembler.cz> 515872212SFrank Myhr * 615872212SFrank Myhr * Partly imported from i2c-vid.h of the lm_sensors project 715872212SFrank Myhr * Copyright (c) 2002 Mark D. Studebaker <mdsxyz123@yahoo.com> 815872212SFrank Myhr * With assistance from Trent Piepho <xyzzy@speakeasy.org> 915872212SFrank Myhr * 1015872212SFrank Myhr * This program is free software; you can redistribute it and/or modify 1115872212SFrank Myhr * it under the terms of the GNU General Public License as published by 1215872212SFrank Myhr * the Free Software Foundation; either version 2 of the License, or 1315872212SFrank Myhr * (at your option) any later version. 1415872212SFrank Myhr * 1515872212SFrank Myhr * This program is distributed in the hope that it will be useful, 1615872212SFrank Myhr * but WITHOUT ANY WARRANTY; without even the implied warranty of 1715872212SFrank Myhr * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 1815872212SFrank Myhr * GNU General Public License for more details. 1915872212SFrank Myhr * 2015872212SFrank Myhr * You should have received a copy of the GNU General Public License 2115872212SFrank Myhr * along with this program; if not, write to the Free Software 2215872212SFrank Myhr * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 23303760b4SJean Delvare */ 24303760b4SJean Delvare 25303760b4SJean Delvare #include <linux/module.h> 26303760b4SJean Delvare #include <linux/kernel.h> 27303760b4SJean Delvare #include <linux/hwmon-vid.h> 28303760b4SJean Delvare 29d0f28270SJean Delvare /* 3015872212SFrank Myhr * Common code for decoding VID pins. 3115872212SFrank Myhr * 3215872212SFrank Myhr * References: 3315872212SFrank Myhr * 3415872212SFrank Myhr * For VRM 8.4 to 9.1, "VRM x.y DC-DC Converter Design Guidelines", 3515872212SFrank Myhr * available at http://developer.intel.com/. 3615872212SFrank Myhr * 3715872212SFrank Myhr * For VRD 10.0 and up, "VRD x.y Design Guide", 3815872212SFrank Myhr * available at http://developer.intel.com/. 3915872212SFrank Myhr * 40*116d0486SFrank Myhr * AMD NPT 0Fh (Athlon64 & Opteron), AMD Publication 32559, 41*116d0486SFrank Myhr * http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/32559.pdf 42*116d0486SFrank Myhr * Table 71. VID Code Voltages 4315872212SFrank Myhr * AMD Opteron processors don't follow the Intel specifications. 4415872212SFrank Myhr * I'm going to "make up" 2.4 as the spec number for the Opterons. 4515872212SFrank Myhr * No good reason just a mnemonic for the 24x Opteron processor 4615872212SFrank Myhr * series. 4715872212SFrank Myhr * 4815872212SFrank Myhr * The 17 specification is in fact Intel Mobile Voltage Positioning - 4915872212SFrank Myhr * (IMVP-II). You can find more information in the datasheet of Max1718 5015872212SFrank Myhr * http://www.maxim-ic.com/quick_view2.cfm/qv_pk/2452 5115872212SFrank Myhr * 5215872212SFrank Myhr * The 13 specification corresponds to the Intel Pentium M series. There 5315872212SFrank Myhr * doesn't seem to be any named specification for these. The conversion 5415872212SFrank Myhr * tables are detailed directly in the various Pentium M datasheets: 5515872212SFrank Myhr * http://www.intel.com/design/intarch/pentiumm/docs_pentiumm.htm 5615872212SFrank Myhr * 5715872212SFrank Myhr * The 14 specification corresponds to Intel Core series. There 5815872212SFrank Myhr * doesn't seem to be any named specification for these. The conversion 5915872212SFrank Myhr * tables are detailed directly in the various Pentium Core datasheets: 6015872212SFrank Myhr * http://www.intel.com/design/mobile/datashts/309221.htm 6115872212SFrank Myhr * 6215872212SFrank Myhr * The 110 (VRM 11) specification corresponds to Intel Conroe based series. 6315872212SFrank Myhr * http://www.intel.com/design/processor/applnots/313214.htm 64d0f28270SJean Delvare */ 65d0f28270SJean Delvare 6615872212SFrank Myhr /* 6715872212SFrank Myhr * vrm is the VRM/VRD document version multiplied by 10. 6815872212SFrank Myhr * val is the 4-bit or more VID code. 6915872212SFrank Myhr * Returned value is in mV to avoid floating point in the kernel. 7015872212SFrank Myhr * Some VID have some bits in uV scale, this is rounded to mV. 7115872212SFrank Myhr */ 72734a12a3SRudolf Marek int vid_from_reg(int val, u8 vrm) 73d0f28270SJean Delvare { 74d0f28270SJean Delvare int vid; 75d0f28270SJean Delvare 76d0f28270SJean Delvare switch(vrm) { 77d0f28270SJean Delvare 78d0f28270SJean Delvare case 100: /* VRD 10.0 */ 796af586dcSRudolf Marek /* compute in uV, round to mV */ 80177d165dSRudolf Marek val &= 0x3f; 81d0f28270SJean Delvare if((val & 0x1f) == 0x1f) 82d0f28270SJean Delvare return 0; 83d0f28270SJean Delvare if((val & 0x1f) <= 0x09 || val == 0x0a) 846af586dcSRudolf Marek vid = 1087500 - (val & 0x1f) * 25000; 85d0f28270SJean Delvare else 866af586dcSRudolf Marek vid = 1862500 - (val & 0x1f) * 25000; 87d0f28270SJean Delvare if(val & 0x20) 886af586dcSRudolf Marek vid -= 12500; 896af586dcSRudolf Marek return((vid + 500) / 1000); 90d0f28270SJean Delvare 916af586dcSRudolf Marek case 110: /* Intel Conroe */ 926af586dcSRudolf Marek /* compute in uV, round to mV */ 936af586dcSRudolf Marek val &= 0xff; 949fab2d8bSJean Delvare if (val < 0x02 || val > 0xb2) 956af586dcSRudolf Marek return 0; 966af586dcSRudolf Marek return((1600000 - (val - 2) * 6250 + 500) / 1000); 97*116d0486SFrank Myhr 98*116d0486SFrank Myhr case 24: /* AMD NPT 0Fh (Athlon64 & Opteron) */ 99*116d0486SFrank Myhr val &= 0x3f; 100*116d0486SFrank Myhr return (val < 32) ? 1550 - 25 * val 101*116d0486SFrank Myhr : 775 - (25 * (val - 31)) / 2; 102d0f28270SJean Delvare 103d0f28270SJean Delvare case 91: /* VRM 9.1 */ 104d0f28270SJean Delvare case 90: /* VRM 9.0 */ 105177d165dSRudolf Marek val &= 0x1f; 106d0f28270SJean Delvare return(val == 0x1f ? 0 : 107d0f28270SJean Delvare 1850 - val * 25); 108d0f28270SJean Delvare 109d0f28270SJean Delvare case 85: /* VRM 8.5 */ 110177d165dSRudolf Marek val &= 0x1f; 111d0f28270SJean Delvare return((val & 0x10 ? 25 : 0) + 112d0f28270SJean Delvare ((val & 0x0f) > 0x04 ? 2050 : 1250) - 113d0f28270SJean Delvare ((val & 0x0f) * 50)); 114d0f28270SJean Delvare 115d0f28270SJean Delvare case 84: /* VRM 8.4 */ 116d0f28270SJean Delvare val &= 0x0f; 117d0f28270SJean Delvare /* fall through */ 118734a12a3SRudolf Marek case 82: /* VRM 8.2 */ 119177d165dSRudolf Marek val &= 0x1f; 120d0f28270SJean Delvare return(val == 0x1f ? 0 : 121d0f28270SJean Delvare val & 0x10 ? 5100 - (val) * 100 : 122d0f28270SJean Delvare 2050 - (val) * 50); 123734a12a3SRudolf Marek case 17: /* Intel IMVP-II */ 124177d165dSRudolf Marek val &= 0x1f; 125734a12a3SRudolf Marek return(val & 0x10 ? 975 - (val & 0xF) * 25 : 126734a12a3SRudolf Marek 1750 - val * 50); 1274c537fb2SJean Delvare case 13: 128177d165dSRudolf Marek val &= 0x3f; 129177d165dSRudolf Marek return(1708 - val * 16); 1306af586dcSRudolf Marek case 14: /* Intel Core */ 1316af586dcSRudolf Marek /* compute in uV, round to mV */ 1326af586dcSRudolf Marek val &= 0x7f; 1336af586dcSRudolf Marek return(val > 0x77 ? 0 : (1500000 - (val * 12500) + 500) / 1000); 134734a12a3SRudolf Marek default: /* report 0 for unknown */ 13545f2acc4SJean Delvare if (vrm) 13645f2acc4SJean Delvare printk(KERN_WARNING "hwmon-vid: Requested unsupported " 13745f2acc4SJean Delvare "VRM version (%u)\n", (unsigned int)vrm); 138734a12a3SRudolf Marek return 0; 139d0f28270SJean Delvare } 140d0f28270SJean Delvare } 141d0f28270SJean Delvare 142d0f28270SJean Delvare 143d0f28270SJean Delvare /* 14415872212SFrank Myhr * After this point is the code to automatically determine which 14515872212SFrank Myhr * VRM/VRD specification should be used depending on the CPU. 146d0f28270SJean Delvare */ 147d0f28270SJean Delvare 148303760b4SJean Delvare struct vrm_model { 149303760b4SJean Delvare u8 vendor; 150303760b4SJean Delvare u8 eff_family; 151303760b4SJean Delvare u8 eff_model; 152734a12a3SRudolf Marek u8 eff_stepping; 153734a12a3SRudolf Marek u8 vrm_type; 154303760b4SJean Delvare }; 155303760b4SJean Delvare 156303760b4SJean Delvare #define ANY 0xFF 157303760b4SJean Delvare 158303760b4SJean Delvare #ifdef CONFIG_X86 159303760b4SJean Delvare 160734a12a3SRudolf Marek /* the stepping parameter is highest acceptable stepping for current line */ 161734a12a3SRudolf Marek 162303760b4SJean Delvare static struct vrm_model vrm_models[] = { 163734a12a3SRudolf Marek {X86_VENDOR_AMD, 0x6, ANY, ANY, 90}, /* Athlon Duron etc */ 164734a12a3SRudolf Marek {X86_VENDOR_AMD, 0xF, ANY, ANY, 24}, /* Athlon 64, Opteron and above VRM 24 */ 1654c537fb2SJean Delvare {X86_VENDOR_INTEL, 0x6, 0x9, ANY, 13}, /* Pentium M (130 nm) */ 166734a12a3SRudolf Marek {X86_VENDOR_INTEL, 0x6, 0xB, ANY, 85}, /* Tualatin */ 1674c537fb2SJean Delvare {X86_VENDOR_INTEL, 0x6, 0xD, ANY, 13}, /* Pentium M (90 nm) */ 1686af586dcSRudolf Marek {X86_VENDOR_INTEL, 0x6, 0xE, ANY, 14}, /* Intel Core (65 nm) */ 1696af586dcSRudolf Marek {X86_VENDOR_INTEL, 0x6, 0xF, ANY, 110}, /* Intel Conroe */ 170734a12a3SRudolf Marek {X86_VENDOR_INTEL, 0x6, ANY, ANY, 82}, /* any P6 */ 171734a12a3SRudolf Marek {X86_VENDOR_INTEL, 0xF, 0x0, ANY, 90}, /* P4 */ 172734a12a3SRudolf Marek {X86_VENDOR_INTEL, 0xF, 0x1, ANY, 90}, /* P4 Willamette */ 173734a12a3SRudolf Marek {X86_VENDOR_INTEL, 0xF, 0x2, ANY, 90}, /* P4 Northwood */ 174734a12a3SRudolf Marek {X86_VENDOR_INTEL, 0xF, ANY, ANY, 100}, /* Prescott and above assume VRD 10 */ 175734a12a3SRudolf Marek {X86_VENDOR_CENTAUR, 0x6, 0x7, ANY, 85}, /* Eden ESP/Ezra */ 176734a12a3SRudolf Marek {X86_VENDOR_CENTAUR, 0x6, 0x8, 0x7, 85}, /* Ezra T */ 177734a12a3SRudolf Marek {X86_VENDOR_CENTAUR, 0x6, 0x9, 0x7, 85}, /* Nemiah */ 178e46751bfSRudolf Marek {X86_VENDOR_CENTAUR, 0x6, 0x9, ANY, 17}, /* C3-M, Eden-N */ 179e46751bfSRudolf Marek {X86_VENDOR_CENTAUR, 0x6, 0xA, 0x7, 0}, /* No information */ 180e46751bfSRudolf Marek {X86_VENDOR_CENTAUR, 0x6, 0xA, ANY, 13}, /* C7, Esther */ 181734a12a3SRudolf Marek {X86_VENDOR_UNKNOWN, ANY, ANY, ANY, 0} /* stop here */ 182303760b4SJean Delvare }; 183303760b4SJean Delvare 184734a12a3SRudolf Marek static u8 find_vrm(u8 eff_family, u8 eff_model, u8 eff_stepping, u8 vendor) 185303760b4SJean Delvare { 186303760b4SJean Delvare int i = 0; 187303760b4SJean Delvare 188303760b4SJean Delvare while (vrm_models[i].vendor!=X86_VENDOR_UNKNOWN) { 189303760b4SJean Delvare if (vrm_models[i].vendor==vendor) 190da97a5a3SJean Delvare if ((vrm_models[i].eff_family==eff_family) 191da97a5a3SJean Delvare && ((vrm_models[i].eff_model==eff_model) || 192734a12a3SRudolf Marek (vrm_models[i].eff_model==ANY)) && 193734a12a3SRudolf Marek (eff_stepping <= vrm_models[i].eff_stepping)) 194303760b4SJean Delvare return vrm_models[i].vrm_type; 195303760b4SJean Delvare i++; 196303760b4SJean Delvare } 197303760b4SJean Delvare 198303760b4SJean Delvare return 0; 199303760b4SJean Delvare } 200303760b4SJean Delvare 201734a12a3SRudolf Marek u8 vid_which_vrm(void) 202303760b4SJean Delvare { 20392cb7612SMike Travis struct cpuinfo_x86 *c = &cpu_data(0); 204303760b4SJean Delvare u32 eax; 205734a12a3SRudolf Marek u8 eff_family, eff_model, eff_stepping, vrm_ret; 206303760b4SJean Delvare 207da97a5a3SJean Delvare if (c->x86 < 6) /* Any CPU with family lower than 6 */ 208da97a5a3SJean Delvare return 0; /* doesn't have VID and/or CPUID */ 209da97a5a3SJean Delvare 210303760b4SJean Delvare eax = cpuid_eax(1); 211303760b4SJean Delvare eff_family = ((eax & 0x00000F00)>>8); 212303760b4SJean Delvare eff_model = ((eax & 0x000000F0)>>4); 213734a12a3SRudolf Marek eff_stepping = eax & 0xF; 214303760b4SJean Delvare if (eff_family == 0xF) { /* use extended model & family */ 215303760b4SJean Delvare eff_family += ((eax & 0x00F00000)>>20); 216303760b4SJean Delvare eff_model += ((eax & 0x000F0000)>>16)<<4; 217303760b4SJean Delvare } 218734a12a3SRudolf Marek vrm_ret = find_vrm(eff_family, eff_model, eff_stepping, c->x86_vendor); 219303760b4SJean Delvare if (vrm_ret == 0) 220303760b4SJean Delvare printk(KERN_INFO "hwmon-vid: Unknown VRM version of your " 221303760b4SJean Delvare "x86 CPU\n"); 222303760b4SJean Delvare return vrm_ret; 223303760b4SJean Delvare } 224303760b4SJean Delvare 225734a12a3SRudolf Marek /* and now for something completely different for the non-x86 world */ 226303760b4SJean Delvare #else 227734a12a3SRudolf Marek u8 vid_which_vrm(void) 228303760b4SJean Delvare { 229303760b4SJean Delvare printk(KERN_INFO "hwmon-vid: Unknown VRM version of your CPU\n"); 230303760b4SJean Delvare return 0; 231303760b4SJean Delvare } 232303760b4SJean Delvare #endif 233303760b4SJean Delvare 234d0f28270SJean Delvare EXPORT_SYMBOL(vid_from_reg); 235303760b4SJean Delvare EXPORT_SYMBOL(vid_which_vrm); 236303760b4SJean Delvare 2377188cc66SJean Delvare MODULE_AUTHOR("Rudolf Marek <r.marek@assembler.cz>"); 238303760b4SJean Delvare 239303760b4SJean Delvare MODULE_DESCRIPTION("hwmon-vid driver"); 240303760b4SJean Delvare MODULE_LICENSE("GPL"); 241