hwmon-vid.c 2.9 KB

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