ucmd_sensors.c 5.9 KB

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