ucmd_sensors.c 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219
  1. /* sensors: CPU DTS plus the board's hardware monitor.
  2. *
  3. * Two board sources exist: the IT87xx Super I/O (AT3IONT-I, three
  4. * temperatures and fan tachometers) and the ThinkPad embedded controller
  5. * (X201, temperatures at EC 0x78..0x7F / 0xC0..0xC7 plus the fan tachometer).
  6. *
  7. * The DTS TjMax of the Atom 330 is not published; Intel only specifies
  8. * TJ = 90 C and Tcase-max = 85.2 C, while Linux coretemp uses 125 C for this
  9. * model. This command prints the raw DTS delta and the resulting absolute
  10. * temperature for each common TjMax, plus the board's independent readings.
  11. */
  12. #include "ucmd_lib.h"
  13. static void put_temp(int t)
  14. {
  15. if (t <= -50) {
  16. u_puts("--");
  17. return;
  18. }
  19. if (t < 0) {
  20. u_putc('-');
  21. u_putdec((unsigned int)(-t));
  22. } else {
  23. u_putdec((unsigned int)t);
  24. }
  25. }
  26. static void put_hex16(unsigned int v)
  27. {
  28. static const char hex[] = "0123456789ABCDEF";
  29. u_putc(hex[(v >> 12) & 0xF]);
  30. u_putc(hex[(v >> 8) & 0xF]);
  31. u_putc(hex[(v >> 4) & 0xF]);
  32. u_putc(hex[v & 0xF]);
  33. }
  34. static void put_scale(int tjmax, int delta)
  35. {
  36. int t = tjmax - delta;
  37. if (t < -20 || t > 150)
  38. u_puts("--");
  39. else {
  40. u_putdec((unsigned int)t);
  41. u_puts(" C");
  42. }
  43. }
  44. static void show_dts(void)
  45. {
  46. struct sys_cputemp ct;
  47. unsigned int i;
  48. u_puts("dts ");
  49. if (u_cpu_temp(&ct) != 0 || ct.temp_c < 0) {
  50. u_puts("unavailable (no Intel DTS)\n");
  51. return;
  52. }
  53. u_puts("max ");
  54. put_temp(ct.temp_c);
  55. u_puts(" C (tjmax ");
  56. u_putdec((unsigned int)ct.tjmax_c);
  57. u_puts(" C)\n");
  58. if (ct.delta_c >= 0) {
  59. u_puts("this core delta ");
  60. u_putdec((unsigned int)ct.delta_c);
  61. u_puts(", status 0x");
  62. u_puthex(ct.status);
  63. u_putc('\n');
  64. /* The scales are for CPUs whose TjMax is not published (the Atom
  65. * 330); when the MSR reports a real value such as 105 C for
  66. * Arrandale there is nothing to guess. */
  67. if (ct.tjmax_c == 90 || ct.tjmax_c == 100 ||
  68. ct.tjmax_c == 125) {
  69. u_puts("scale 90: ");
  70. put_scale(90, ct.delta_c);
  71. u_puts(", 100: ");
  72. put_scale(100, ct.delta_c);
  73. u_puts(", 125: ");
  74. put_scale(125, ct.delta_c);
  75. u_putc('\n');
  76. }
  77. }
  78. u_puts("cores ");
  79. for (i = 0; i < ct.ncpus && i < SYS_CPU_MAX; i++) {
  80. put_temp(ct.cpu_temp_c[i]);
  81. u_puts(" C");
  82. if (i + 1 < ct.ncpus && i + 1 < SYS_CPU_MAX)
  83. u_puts(", ");
  84. }
  85. u_putc('\n');
  86. }
  87. static int show_it87(void)
  88. {
  89. struct sys_sensors s;
  90. unsigned int i;
  91. if (u_sensors(&s) != 0 || !s.present)
  92. return 0;
  93. u_puts("it87 chip 0x");
  94. put_hex16(s.chip_id);
  95. u_puts(" base 0x");
  96. put_hex16(s.base);
  97. u_puts(" enable 0x");
  98. u_put_hex2(s.temp_enable);
  99. u_puts(" extra 0x");
  100. u_put_hex2(s.temp_extra);
  101. u_putc('\n');
  102. for (i = 0; i < 3; i++) {
  103. int enabled = (s.temp_enable & (1u << i)) ||
  104. (s.temp_enable & (1u << (i + 3))) ||
  105. (i == 2 && (s.temp_enable & 0xC0) == 0xC0);
  106. u_puts("temp");
  107. u_putdec(i + 1);
  108. u_puts(" ");
  109. if (enabled)
  110. put_temp(s.temp_c[i]);
  111. else
  112. u_puts("--");
  113. u_puts(" C");
  114. if (i < 2)
  115. u_puts(", ");
  116. }
  117. u_putc('\n');
  118. for (i = 0; i < 3; i++) {
  119. u_puts("fan");
  120. u_putdec(i + 1);
  121. u_puts(" ");
  122. u_putdec(s.fan_rpm[i]);
  123. u_puts(" RPM");
  124. if (i < 2)
  125. u_puts(", ");
  126. }
  127. u_putc('\n');
  128. return 1;
  129. }
  130. /* EC 0x2F: bit 7 = automatic, bit 6 = disengaged/full speed (takes
  131. * precedence), bits 2:0 = manual level (0 stops the fan, 7 is the usual max).
  132. */
  133. static void put_fan_level(unsigned int level)
  134. {
  135. u_puts(" (0x");
  136. u_put_hex2(level);
  137. if (level & 0x40)
  138. u_puts(", full speed");
  139. else if (level & 0x80)
  140. u_puts(", auto");
  141. else if ((level & 0x3F) == 0)
  142. u_puts(", stopped");
  143. else {
  144. u_puts(", level ");
  145. u_putdec(level & 0x3F);
  146. }
  147. u_puts(")");
  148. }
  149. static int show_tpec(void)
  150. {
  151. struct sys_tpec_sensors s;
  152. unsigned int i, shown = 0;
  153. if (u_tpec_sensors(&s) != 0 || !s.present)
  154. return 0;
  155. u_puts("thinkpad");
  156. if (s.vendor[0]) {
  157. u_puts(" ");
  158. u_puts(s.vendor);
  159. }
  160. if (s.product[0]) {
  161. u_puts(" ");
  162. u_puts(s.product);
  163. }
  164. if (s.version[0]) {
  165. u_puts(" ");
  166. u_puts(s.version);
  167. }
  168. u_putc('\n');
  169. for (i = 0; i < SYS_TPEC_TEMP_MAX; i++) {
  170. unsigned int reg = i < 8 ? 0x78 + i : 0xC0 + i - 8;
  171. if (s.temp_c[i] <= -50)
  172. continue;
  173. if (shown)
  174. u_puts(", ");
  175. u_puts("temp");
  176. u_putdec(i + 1);
  177. u_puts(" (0x");
  178. u_put_hex2(reg);
  179. u_puts(") ");
  180. put_temp(s.temp_c[i]);
  181. u_puts(" C");
  182. shown++;
  183. }
  184. if (!shown)
  185. u_puts("no EC temperature sensors");
  186. u_putc('\n');
  187. u_puts("fan ");
  188. u_putdec(s.fan_rpm);
  189. u_puts(" RPM");
  190. put_fan_level(s.fan_level);
  191. u_putc('\n');
  192. return 1;
  193. }
  194. void _start(void)
  195. {
  196. int any;
  197. show_dts();
  198. any = show_it87();
  199. any |= show_tpec();
  200. if (!any)
  201. u_puts("no board sensors found\n");
  202. u_exit(0);
  203. }