power_src.h 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. /* Shared AC/battery snapshot for the board embedded controllers.
  2. *
  3. * Two backends fill this: the ThinkPad H8 EC (tpec.c) and the Chrome OS EC
  4. * (cros_ec.c). sys_info.c copies it into struct sys_powerinfo for
  5. * SYS_POWER_INFO, so the WM top bar and the powerinfo command do not need to
  6. * know which laptop they are running on.
  7. */
  8. #ifndef POWER_SRC_H
  9. #define POWER_SRC_H
  10. #include "syscall.h"
  11. #define POWER_BATT_MAX SYS_POWER_BATT_MAX
  12. /* One battery. rate is the signed present rate in the unit selected by
  13. * unit_mwh: mW when set, mA when clear. Capacities use the matching
  14. * mWh/mAh unit. percent is valid only when percent_valid is set. */
  15. struct power_battery {
  16. int present;
  17. int error; /* at least one EC read failed */
  18. unsigned int status; /* raw EC status/flags byte */
  19. int charging;
  20. int discharging;
  21. int percent; /* 0..100 when percent_valid */
  22. int percent_valid;
  23. unsigned int remaining; /* reported remaining capacity */
  24. unsigned int full; /* reported last full charge capacity */
  25. unsigned int design; /* reported design capacity */
  26. unsigned int voltage_mv;
  27. int rate; /* signed reported present rate */
  28. int unit_known;
  29. int unit_mwh; /* 1 = mWh/mW, 0 = mAh/mA */
  30. unsigned int cycle_count;
  31. char manufacturer[16];
  32. char model[16];
  33. char serial[16];
  34. };
  35. struct power_info {
  36. int present;
  37. int source; /* SYS_POWER_SRC_* */
  38. int ac_online; /* -1 unknown, 0 offline, 1 online */
  39. unsigned int ec_rev;
  40. char vendor[16];
  41. char product[32];
  42. char version[32];
  43. unsigned int battery_count;
  44. struct power_battery battery[POWER_BATT_MAX];
  45. };
  46. /* Fill out from the first available backend (ThinkPad EC, then Chrome EC).
  47. * detail also reads design data and the manufacturer/model/serial strings;
  48. * the periodic WM query passes 0. */
  49. void power_source_read(struct power_info *out, int detail);
  50. #endif