/*1* hwmon-vid.c - VID/VRM/VRD voltage conversions2*3* Copyright (c) 2004 Rudolf Marek <[email protected]>4*5* Partly imported from i2c-vid.h of the lm_sensors project6* Copyright (c) 2002 Mark D. Studebaker <[email protected]>7* With assistance from Trent Piepho <[email protected]>8*9* This program is free software; you can redistribute it and/or modify10* it under the terms of the GNU General Public License as published by11* the Free Software Foundation; either version 2 of the License, or12* (at your option) any later version.13*14* This program is distributed in the hope that it will be useful,15* but WITHOUT ANY WARRANTY; without even the implied warranty of16* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the17* GNU General Public License for more details.18*19* You should have received a copy of the GNU General Public License20* along with this program; if not, write to the Free Software21* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.22*/2324#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt2526#include <linux/module.h>27#include <linux/kernel.h>28#include <linux/hwmon-vid.h>2930/*31* Common code for decoding VID pins.32*33* References:34*35* For VRM 8.4 to 9.1, "VRM x.y DC-DC Converter Design Guidelines",36* available at http://developer.intel.com/.37*38* For VRD 10.0 and up, "VRD x.y Design Guide",39* available at http://developer.intel.com/.40*41* AMD Athlon 64 and AMD Opteron Processors, AMD Publication 26094,42* http://support.amd.com/us/Processor_TechDocs/26094.PDF43* Table 74. VID Code Voltages44* This corresponds to an arbitrary VRM code of 24 in the functions below.45* These CPU models (K8 revision <= E) have 5 VID pins. See also:46* Revision Guide for AMD Athlon 64 and AMD Opteron Processors, AMD Publication 25759,47* http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/25759.pdf48*49* AMD NPT Family 0Fh Processors, AMD Publication 32559,50* http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/32559.pdf51* Table 71. VID Code Voltages52* This corresponds to an arbitrary VRM code of 25 in the functions below.53* These CPU models (K8 revision >= F) have 6 VID pins. See also:54* Revision Guide for AMD NPT Family 0Fh Processors, AMD Publication 33610,55* http://www.amd.com/us-en/assets/content_type/white_papers_and_tech_docs/33610.pdf56*57* The 17 specification is in fact Intel Mobile Voltage Positioning -58* (IMVP-II). You can find more information in the datasheet of Max171859* http://www.maxim-ic.com/quick_view2.cfm/qv_pk/245260*61* The 13 specification corresponds to the Intel Pentium M series. There62* doesn't seem to be any named specification for these. The conversion63* tables are detailed directly in the various Pentium M datasheets:64* http://www.intel.com/design/intarch/pentiumm/docs_pentiumm.htm65*66* The 14 specification corresponds to Intel Core series. There67* doesn't seem to be any named specification for these. The conversion68* tables are detailed directly in the various Pentium Core datasheets:69* http://www.intel.com/design/mobile/datashts/309221.htm70*71* The 110 (VRM 11) specification corresponds to Intel Conroe based series.72* http://www.intel.com/design/processor/applnots/313214.htm73*/7475/*76* vrm is the VRM/VRD document version multiplied by 10.77* val is the 4-bit or more VID code.78* Returned value is in mV to avoid floating point in the kernel.79* Some VID have some bits in uV scale, this is rounded to mV.80*/81int vid_from_reg(int val, u8 vrm)82{83int vid;8485switch(vrm) {8687case 100: /* VRD 10.0 */88/* compute in uV, round to mV */89val &= 0x3f;90if((val & 0x1f) == 0x1f)91return 0;92if((val & 0x1f) <= 0x09 || val == 0x0a)93vid = 1087500 - (val & 0x1f) * 25000;94else95vid = 1862500 - (val & 0x1f) * 25000;96if(val & 0x20)97vid -= 12500;98return((vid + 500) / 1000);99100case 110: /* Intel Conroe */101/* compute in uV, round to mV */102val &= 0xff;103if (val < 0x02 || val > 0xb2)104return 0;105return((1600000 - (val - 2) * 6250 + 500) / 1000);106107case 24: /* Athlon64 & Opteron */108val &= 0x1f;109if (val == 0x1f)110return 0;111/* fall through */112case 25: /* AMD NPT 0Fh */113val &= 0x3f;114return (val < 32) ? 1550 - 25 * val115: 775 - (25 * (val - 31)) / 2;116117case 91: /* VRM 9.1 */118case 90: /* VRM 9.0 */119val &= 0x1f;120return(val == 0x1f ? 0 :1211850 - val * 25);122123case 85: /* VRM 8.5 */124val &= 0x1f;125return((val & 0x10 ? 25 : 0) +126((val & 0x0f) > 0x04 ? 2050 : 1250) -127((val & 0x0f) * 50));128129case 84: /* VRM 8.4 */130val &= 0x0f;131/* fall through */132case 82: /* VRM 8.2 */133val &= 0x1f;134return(val == 0x1f ? 0 :135val & 0x10 ? 5100 - (val) * 100 :1362050 - (val) * 50);137case 17: /* Intel IMVP-II */138val &= 0x1f;139return(val & 0x10 ? 975 - (val & 0xF) * 25 :1401750 - val * 50);141case 13:142val &= 0x3f;143return(1708 - val * 16);144case 14: /* Intel Core */145/* compute in uV, round to mV */146val &= 0x7f;147return(val > 0x77 ? 0 : (1500000 - (val * 12500) + 500) / 1000);148default: /* report 0 for unknown */149if (vrm)150pr_warn("Requested unsupported VRM version (%u)\n",151(unsigned int)vrm);152return 0;153}154}155156157/*158* After this point is the code to automatically determine which159* VRM/VRD specification should be used depending on the CPU.160*/161162struct vrm_model {163u8 vendor;164u8 eff_family;165u8 eff_model;166u8 eff_stepping;167u8 vrm_type;168};169170#define ANY 0xFF171172#ifdef CONFIG_X86173174/*175* The stepping parameter is highest acceptable stepping for current line.176* The model match must be exact for 4-bit values. For model values 0x10177* and above (extended model), all models below the parameter will match.178*/179180static struct vrm_model vrm_models[] = {181{X86_VENDOR_AMD, 0x6, ANY, ANY, 90}, /* Athlon Duron etc */182{X86_VENDOR_AMD, 0xF, 0x3F, ANY, 24}, /* Athlon 64, Opteron */183/* In theory, all NPT family 0Fh processors have 6 VID pins and should184thus use vrm 25, however in practice not all mainboards route the1856th VID pin because it is never needed. So we use the 5 VID pin186variant (vrm 24) for the models which exist today. */187{X86_VENDOR_AMD, 0xF, 0x7F, ANY, 24}, /* NPT family 0Fh */188{X86_VENDOR_AMD, 0xF, ANY, ANY, 25}, /* future fam. 0Fh */189{X86_VENDOR_AMD, 0x10, ANY, ANY, 25}, /* NPT family 10h */190191{X86_VENDOR_INTEL, 0x6, 0x9, ANY, 13}, /* Pentium M (130 nm) */192{X86_VENDOR_INTEL, 0x6, 0xB, ANY, 85}, /* Tualatin */193{X86_VENDOR_INTEL, 0x6, 0xD, ANY, 13}, /* Pentium M (90 nm) */194{X86_VENDOR_INTEL, 0x6, 0xE, ANY, 14}, /* Intel Core (65 nm) */195{X86_VENDOR_INTEL, 0x6, 0xF, ANY, 110}, /* Intel Conroe */196{X86_VENDOR_INTEL, 0x6, ANY, ANY, 82}, /* any P6 */197{X86_VENDOR_INTEL, 0xF, 0x0, ANY, 90}, /* P4 */198{X86_VENDOR_INTEL, 0xF, 0x1, ANY, 90}, /* P4 Willamette */199{X86_VENDOR_INTEL, 0xF, 0x2, ANY, 90}, /* P4 Northwood */200{X86_VENDOR_INTEL, 0xF, ANY, ANY, 100}, /* Prescott and above assume VRD 10 */201202{X86_VENDOR_CENTAUR, 0x6, 0x7, ANY, 85}, /* Eden ESP/Ezra */203{X86_VENDOR_CENTAUR, 0x6, 0x8, 0x7, 85}, /* Ezra T */204{X86_VENDOR_CENTAUR, 0x6, 0x9, 0x7, 85}, /* Nehemiah */205{X86_VENDOR_CENTAUR, 0x6, 0x9, ANY, 17}, /* C3-M, Eden-N */206{X86_VENDOR_CENTAUR, 0x6, 0xA, 0x7, 0}, /* No information */207{X86_VENDOR_CENTAUR, 0x6, 0xA, ANY, 13}, /* C7, Esther */208209{X86_VENDOR_UNKNOWN, ANY, ANY, ANY, 0} /* stop here */210};211212static u8 find_vrm(u8 eff_family, u8 eff_model, u8 eff_stepping, u8 vendor)213{214int i = 0;215216while (vrm_models[i].vendor!=X86_VENDOR_UNKNOWN) {217if (vrm_models[i].vendor==vendor)218if ((vrm_models[i].eff_family==eff_family)219&& ((vrm_models[i].eff_model==eff_model) ||220(vrm_models[i].eff_model >= 0x10 &&221eff_model <= vrm_models[i].eff_model) ||222(vrm_models[i].eff_model==ANY)) &&223(eff_stepping <= vrm_models[i].eff_stepping))224return vrm_models[i].vrm_type;225i++;226}227228return 0;229}230231u8 vid_which_vrm(void)232{233struct cpuinfo_x86 *c = &cpu_data(0);234u32 eax;235u8 eff_family, eff_model, eff_stepping, vrm_ret;236237if (c->x86 < 6) /* Any CPU with family lower than 6 */238return 0; /* doesn't have VID and/or CPUID */239240eax = cpuid_eax(1);241eff_family = ((eax & 0x00000F00)>>8);242eff_model = ((eax & 0x000000F0)>>4);243eff_stepping = eax & 0xF;244if (eff_family == 0xF) { /* use extended model & family */245eff_family += ((eax & 0x00F00000)>>20);246eff_model += ((eax & 0x000F0000)>>16)<<4;247}248vrm_ret = find_vrm(eff_family, eff_model, eff_stepping, c->x86_vendor);249if (vrm_ret == 0)250pr_info("Unknown VRM version of your x86 CPU\n");251return vrm_ret;252}253254/* and now for something completely different for the non-x86 world */255#else256u8 vid_which_vrm(void)257{258pr_info("Unknown VRM version of your CPU\n");259return 0;260}261#endif262263EXPORT_SYMBOL(vid_from_reg);264EXPORT_SYMBOL(vid_which_vrm);265266MODULE_AUTHOR("Rudolf Marek <[email protected]>");267268MODULE_DESCRIPTION("hwmon-vid driver");269MODULE_LICENSE("GPL");270271272