it87.c 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119
  1. /* ITE IT87xx hardware monitor (read-only).
  2. *
  3. * The ASUS AT3IONT-I exposes CPU/MB temperatures and its three fan tach
  4. * inputs through an IT87xx Super I/O. This gives an independent cross-check
  5. * for the CPU DTS (whose TjMax is not published for the Atom 330) and shows
  6. * whether the CPU fan is actually turning.
  7. *
  8. * Only the standard config-space probe and the environment controller's
  9. * read-only registers are touched; nothing is written to the fan control.
  10. */
  11. #include "it87.h"
  12. #include "pci.h" /* port_inb/port_outb */
  13. static unsigned short cfg_port;
  14. static unsigned char sio_inb(unsigned char reg)
  15. {
  16. port_outb(cfg_port, reg);
  17. return port_inb(cfg_port + 1);
  18. }
  19. static void sio_outb(unsigned char reg, unsigned char val)
  20. {
  21. port_outb(cfg_port, reg);
  22. port_outb(cfg_port + 1, val);
  23. }
  24. static void sio_enter(unsigned short port)
  25. {
  26. cfg_port = port;
  27. port_outb(cfg_port, 0x87);
  28. port_outb(cfg_port, 0x01);
  29. port_outb(cfg_port, 0x55);
  30. port_outb(cfg_port, port == 0x4E ? 0xAA : 0x55);
  31. }
  32. static void sio_exit(void)
  33. {
  34. port_outb(cfg_port, 0x02);
  35. port_outb(cfg_port + 1, 0x02);
  36. }
  37. static int has_16bit_fans(unsigned int id)
  38. {
  39. /* IT8705F/IT8712F use 8-bit tachometers; IT8716F and later have
  40. * 16-bit counters (low byte at 0x0D..0x0F, high at 0x18..0x1A). */
  41. return id != 0x8705 && id != 0x8712;
  42. }
  43. void it87_read(struct it87_info *out)
  44. {
  45. unsigned int i, base;
  46. unsigned char div;
  47. out->present = 0;
  48. out->chip_id = 0;
  49. out->base = 0;
  50. out->temp_enable = 0;
  51. out->temp_extra = 0;
  52. for (i = 0; i < IT87_TEMP_COUNT; i++)
  53. out->temp_c[i] = -128;
  54. for (i = 0; i < IT87_FAN_COUNT; i++)
  55. out->fan_rpm[i] = 0;
  56. for (i = 0; i < 2; i++) {
  57. unsigned short port = i ? 0x4E : 0x2E;
  58. unsigned int id;
  59. sio_enter(port);
  60. id = ((unsigned int)sio_inb(0x20) << 8) | sio_inb(0x21);
  61. if ((id & 0xFF00u) != 0x8700u) {
  62. sio_exit();
  63. continue;
  64. }
  65. /* Environment controller (logical device 4) base address. */
  66. sio_outb(0x07, 0x04);
  67. base = ((unsigned int)sio_inb(0x60) << 8) | sio_inb(0x61);
  68. base &= ~7u;
  69. if (sio_inb(0x30) != 0x01) {
  70. sio_exit();
  71. continue;
  72. }
  73. sio_exit();
  74. if (base < 0x100 || base > 0xFFF0)
  75. continue;
  76. out->present = 1;
  77. out->chip_id = id;
  78. out->base = base;
  79. break;
  80. }
  81. if (!out->present)
  82. return;
  83. for (i = 0; i < IT87_TEMP_COUNT; i++)
  84. out->temp_c[i] =
  85. (signed char)port_inb((unsigned short)(base + 0x29 + i));
  86. out->temp_enable = port_inb((unsigned short)(base + 0x51));
  87. out->temp_extra = port_inb((unsigned short)(base + 0x55));
  88. div = port_inb((unsigned short)(base + 0x0B));
  89. for (i = 0; i < IT87_FAN_COUNT; i++) {
  90. unsigned int count, d;
  91. count = port_inb((unsigned short)(base + 0x0D + i));
  92. if (has_16bit_fans(out->chip_id)) {
  93. count |= (unsigned int)port_inb((unsigned short)(base + 0x18 + i)) << 8;
  94. if (count == 0 || count == 0xFFFF)
  95. out->fan_rpm[i] = 0;
  96. else
  97. out->fan_rpm[i] = 1350000u / (count * 2);
  98. continue;
  99. }
  100. d = 1u << ((div >> (2 + i * 2)) & 3u);
  101. if (count == 0 || count >= 0xFF)
  102. out->fan_rpm[i] = 0;
  103. else
  104. out->fan_rpm[i] = 1350000u / (count * d);
  105. }
  106. }