charger-manager.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  1. /*
  2. * Copyright (C) 2011 Samsung Electronics Co., Ltd.
  3. * MyungJoo.Ham <myungjoo.ham@samsung.com>
  4. *
  5. * Charger Manager.
  6. * This framework enables to control and multiple chargers and to
  7. * monitor charging even in the context of suspend-to-RAM with
  8. * an interface combining the chargers.
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License version 2 as
  12. * published by the Free Software Foundation.
  13. **/
  14. #ifndef _CHARGER_MANAGER_H
  15. #define _CHARGER_MANAGER_H
  16. #include <linux/power_supply.h>
  17. enum data_source {
  18. CM_FUEL_GAUGE,
  19. CM_CHARGER_STAT,
  20. };
  21. enum polling_modes {
  22. CM_POLL_DISABLE = 0,
  23. CM_POLL_ALWAYS,
  24. CM_POLL_EXTERNAL_POWER_ONLY,
  25. CM_POLL_CHARGING_ONLY,
  26. };
  27. /**
  28. * struct charger_global_desc
  29. * @rtc_name: the name of RTC used to wake up the system from suspend.
  30. * @rtc_only_wakeup:
  31. * If the system is woken up by waekup-sources other than the RTC or
  32. * callbacks, Charger Manager should recognize with
  33. * rtc_only_wakeup() returning false.
  34. * If the RTC given to CM is the only wakeup reason,
  35. * rtc_only_wakeup should return true.
  36. */
  37. struct charger_global_desc {
  38. char *rtc_name;
  39. bool (*rtc_only_wakeup)(void);
  40. };
  41. /**
  42. * struct charger_desc
  43. * @polling_mode:
  44. * Determine which polling mode will be used
  45. * @polling_interval_ms: interval in millisecond at which
  46. * charger manager will monitor battery health
  47. * @battery_present:
  48. * Specify where information for existance of battery can be obtained
  49. * @psy_charger_stat: the names of power-supply for chargers
  50. * @num_charger_regulator: the number of entries in charger_regulators
  51. * @charger_regulators: array of regulator_bulk_data for chargers
  52. * @psy_fuel_gauge: the name of power-supply for fuel gauge
  53. * @temperature_out_of_range:
  54. * Determine whether the status is overheat or cold or normal.
  55. * return_value > 0: overheat
  56. * return_value == 0: normal
  57. * return_value < 0: cold
  58. */
  59. struct charger_desc {
  60. enum polling_modes polling_mode;
  61. unsigned int polling_interval_ms;
  62. enum data_source battery_present;
  63. char **psy_charger_stat;
  64. int num_charger_regulators;
  65. struct regulator_bulk_data *charger_regulators;
  66. char *psy_fuel_gauge;
  67. int (*temperature_out_of_range)(int *mC);
  68. };
  69. #define PSY_NAME_MAX 30
  70. /**
  71. * struct charger_manager
  72. * @entry: entry for list
  73. * @dev: device pointer
  74. * @desc: instance of charger_desc
  75. * @fuel_gauge: power_supply for fuel gauge
  76. * @charger_stat: array of power_supply for chargers
  77. * @charger_enabled: the state of charger
  78. * @emergency_stop:
  79. * When setting true, stop charging
  80. * @last_temp_mC: the measured temperature in milli-Celsius
  81. * @status_save_ext_pwr_inserted:
  82. * saved status of external power before entering suspend-to-RAM
  83. * @status_save_batt:
  84. * saved status of battery before entering suspend-to-RAM
  85. */
  86. struct charger_manager {
  87. struct list_head entry;
  88. struct device *dev;
  89. struct charger_desc *desc;
  90. struct power_supply *fuel_gauge;
  91. struct power_supply **charger_stat;
  92. bool charger_enabled;
  93. int emergency_stop;
  94. int last_temp_mC;
  95. bool status_save_ext_pwr_inserted;
  96. bool status_save_batt;
  97. };
  98. #ifdef CONFIG_CHARGER_MANAGER
  99. extern int setup_charger_manager(struct charger_global_desc *gd);
  100. extern bool cm_suspend_again(void);
  101. #else
  102. static void __maybe_unused setup_charger_manager(struct charger_global_desc *gd)
  103. { }
  104. static bool __maybe_unused cm_suspend_again(void)
  105. {
  106. return false;
  107. }
  108. #endif
  109. #endif /* _CHARGER_MANAGER_H */