tpec.h 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /* ThinkPad embedded-controller sensors and power sources (X201/Arrandale class). */
  2. #ifndef TPEC_H
  3. #define TPEC_H
  4. #define TPEC_TEMP_COUNT 16
  5. #define TPEC_BATTERY_COUNT 2
  6. /* Temperatures are indexed like thinkpad_acpi's temp1..temp16:
  7. * temp_c[0..7] come from EC 0x78..0x7F, temp_c[8..15] from EC 0xC0..0xC7.
  8. * -128 means the EC reports the sensor as not present. */
  9. struct tpec_info {
  10. int present;
  11. char vendor[16];
  12. char product[32];
  13. char version[32];
  14. int temp_c[TPEC_TEMP_COUNT];
  15. unsigned int fan_rpm;
  16. unsigned int fan_level; /* raw EC 0x2F value */
  17. };
  18. /* One battery from the H8 battery information area (EC page selector 0x81). */
  19. struct tpec_battery {
  20. int present;
  21. int error; /* at least one EC read failed */
  22. unsigned int status; /* raw EC 0x38/0x39 status byte */
  23. int charging;
  24. int discharging;
  25. int percent; /* 0..100 when percent_valid */
  26. int percent_valid;
  27. unsigned int remaining; /* reported remaining capacity */
  28. unsigned int full; /* reported last full charge capacity */
  29. unsigned int design; /* reported design capacity */
  30. unsigned int voltage_mv;
  31. int rate; /* signed reported present rate */
  32. int unit_known;
  33. int unit_mwh; /* 1 = mWh/mW, 0 = mAh/mA */
  34. char manufacturer[16];
  35. char model[16];
  36. };
  37. struct tpec_power {
  38. int present; /* ThinkPad EC found */
  39. int ac_online; /* -1 unknown, 0 offline, 1 online */
  40. unsigned int ec_rev;
  41. char vendor[16];
  42. char product[32];
  43. char version[32];
  44. unsigned int battery_count;
  45. struct tpec_battery battery[TPEC_BATTERY_COUNT];
  46. };
  47. /* Probe SMBIOS + the EC once on the BSP; logs the result to COM1. Does
  48. * nothing (present = 0) unless SMBIOS identifies a Lenovo/IBM machine and the
  49. * EC answers, so boards without one are never touched. */
  50. void tpec_init(void);
  51. /* Read the current temperatures, fan speed and fan level. present is 0 when
  52. * no ThinkPad EC was found. */
  53. void tpec_read(struct tpec_info *out);
  54. /* Read the AC adapter and battery state through the H8 battery information
  55. * pages; detail also reads design capacity, the capacity unit and the
  56. * manufacturer/model strings. The only EC write is the page selector at
  57. * 0x81, and it is restored when it had to be changed. */
  58. void tpec_power_read(struct tpec_power *out, int detail);
  59. #endif