blob: 7c8ed0353302ad26062f8076a596f65ce8785dd2 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
Jean Delvare303760b2005-07-31 21:52:01 +02002 hwmon-vid.c - VID/VRM/VRD voltage conversions
Linus Torvalds1da177e2005-04-16 15:20:36 -07003
4 Copyright (c) 2004 Rudolf Marek <r.marek@sh.cvut.cz>
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
19*/
20
21#include <linux/config.h>
22#include <linux/module.h>
23#include <linux/kernel.h>
Jean Delvare303760b2005-07-31 21:52:01 +020024#include <linux/hwmon-vid.h>
Linus Torvalds1da177e2005-04-16 15:20:36 -070025
26struct vrm_model {
27 u8 vendor;
28 u8 eff_family;
29 u8 eff_model;
30 int vrm_type;
31};
32
33#define ANY 0xFF
34
35#ifdef CONFIG_X86
36
37static struct vrm_model vrm_models[] = {
38 {X86_VENDOR_AMD, 0x6, ANY, 90}, /* Athlon Duron etc */
39 {X86_VENDOR_AMD, 0xF, ANY, 24}, /* Athlon 64, Opteron */
40 {X86_VENDOR_INTEL, 0x6, 0x9, 85}, /* 0.13um too */
Jean Delvareda97a5a2005-07-31 21:54:28 +020041 {X86_VENDOR_INTEL, 0x6, 0xB, 85}, /* Tualatin */
Linus Torvalds1da177e2005-04-16 15:20:36 -070042 {X86_VENDOR_INTEL, 0x6, ANY, 82}, /* any P6 */
43 {X86_VENDOR_INTEL, 0x7, ANY, 0}, /* Itanium */
44 {X86_VENDOR_INTEL, 0xF, 0x3, 100}, /* P4 Prescott */
45 {X86_VENDOR_INTEL, 0xF, ANY, 90}, /* P4 before Prescott */
46 {X86_VENDOR_INTEL, 0x10,ANY, 0}, /* Itanium 2 */
47 {X86_VENDOR_UNKNOWN, ANY, ANY, 0} /* stop here */
Jean Delvareda97a5a2005-07-31 21:54:28 +020048};
Linus Torvalds1da177e2005-04-16 15:20:36 -070049
50static int find_vrm(u8 eff_family, u8 eff_model, u8 vendor)
51{
52 int i = 0;
53
54 while (vrm_models[i].vendor!=X86_VENDOR_UNKNOWN) {
55 if (vrm_models[i].vendor==vendor)
Jean Delvareda97a5a2005-07-31 21:54:28 +020056 if ((vrm_models[i].eff_family==eff_family)
57 && ((vrm_models[i].eff_model==eff_model) ||
58 (vrm_models[i].eff_model==ANY)))
Linus Torvalds1da177e2005-04-16 15:20:36 -070059 return vrm_models[i].vrm_type;
60 i++;
61 }
62
63 return 0;
64}
65
Jean Delvare303760b2005-07-31 21:52:01 +020066int vid_which_vrm(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070067{
68 struct cpuinfo_x86 *c = cpu_data;
69 u32 eax;
70 u8 eff_family, eff_model;
71 int vrm_ret;
72
Jean Delvareda97a5a2005-07-31 21:54:28 +020073 if (c->x86 < 6) /* Any CPU with family lower than 6 */
74 return 0; /* doesn't have VID and/or CPUID */
75
Linus Torvalds1da177e2005-04-16 15:20:36 -070076 eax = cpuid_eax(1);
77 eff_family = ((eax & 0x00000F00)>>8);
78 eff_model = ((eax & 0x000000F0)>>4);
79 if (eff_family == 0xF) { /* use extended model & family */
80 eff_family += ((eax & 0x00F00000)>>20);
81 eff_model += ((eax & 0x000F0000)>>16)<<4;
82 }
83 vrm_ret = find_vrm(eff_family,eff_model,c->x86_vendor);
84 if (vrm_ret == 0)
Jean Delvareda97a5a2005-07-31 21:54:28 +020085 printk(KERN_INFO "hwmon-vid: Unknown VRM version of your "
86 "x86 CPU\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070087 return vrm_ret;
88}
89
Jean Delvareda97a5a2005-07-31 21:54:28 +020090/* and now something completely different for the non-x86 world */
Linus Torvalds1da177e2005-04-16 15:20:36 -070091#else
Jean Delvare303760b2005-07-31 21:52:01 +020092int vid_which_vrm(void)
Linus Torvalds1da177e2005-04-16 15:20:36 -070093{
Jean Delvare303760b2005-07-31 21:52:01 +020094 printk(KERN_INFO "hwmon-vid: Unknown VRM version of your CPU\n");
Linus Torvalds1da177e2005-04-16 15:20:36 -070095 return 0;
96}
97#endif
98
Jean Delvare303760b2005-07-31 21:52:01 +020099EXPORT_SYMBOL(vid_which_vrm);
Jean Delvare96478ef2005-07-31 21:45:27 +0200100
101MODULE_AUTHOR("Rudolf Marek <r.marek@sh.cvut.cz>");
102
Jean Delvare303760b2005-07-31 21:52:01 +0200103MODULE_DESCRIPTION("hwmon-vid driver");
Jean Delvare96478ef2005-07-31 21:45:27 +0200104MODULE_LICENSE("GPL");