charger-manager.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148
  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. * @psy_name: the name of power-supply-class for charger manager
  44. * @polling_mode:
  45. * Determine which polling mode will be used
  46. * @fullbatt_uV: voltage in microvolt
  47. * If it is not being charged and VBATT >= fullbatt_uV,
  48. * it is assumed to be full.
  49. * @polling_interval_ms: interval in millisecond at which
  50. * charger manager will monitor battery health
  51. * @battery_present:
  52. * Specify where information for existance of battery can be obtained
  53. * @psy_charger_stat: the names of power-supply for chargers
  54. * @num_charger_regulator: the number of entries in charger_regulators
  55. * @charger_regulators: array of regulator_bulk_data for chargers
  56. * @psy_fuel_gauge: the name of power-supply for fuel gauge
  57. * @temperature_out_of_range:
  58. * Determine whether the status is overheat or cold or normal.
  59. * return_value > 0: overheat
  60. * return_value == 0: normal
  61. * return_value < 0: cold
  62. * @measure_battery_temp:
  63. * true: measure battery temperature
  64. * false: measure ambient temperature
  65. */
  66. struct charger_desc {
  67. char *psy_name;
  68. enum polling_modes polling_mode;
  69. unsigned int polling_interval_ms;
  70. unsigned int fullbatt_uV;
  71. enum data_source battery_present;
  72. char **psy_charger_stat;
  73. int num_charger_regulators;
  74. struct regulator_bulk_data *charger_regulators;
  75. char *psy_fuel_gauge;
  76. int (*temperature_out_of_range)(int *mC);
  77. bool measure_battery_temp;
  78. };
  79. #define PSY_NAME_MAX 30
  80. /**
  81. * struct charger_manager
  82. * @entry: entry for list
  83. * @dev: device pointer
  84. * @desc: instance of charger_desc
  85. * @fuel_gauge: power_supply for fuel gauge
  86. * @charger_stat: array of power_supply for chargers
  87. * @charger_enabled: the state of charger
  88. * @emergency_stop:
  89. * When setting true, stop charging
  90. * @last_temp_mC: the measured temperature in milli-Celsius
  91. * @psy_name_buf: the name of power-supply-class for charger manager
  92. * @charger_psy: power_supply for charger manager
  93. * @status_save_ext_pwr_inserted:
  94. * saved status of external power before entering suspend-to-RAM
  95. * @status_save_batt:
  96. * saved status of battery before entering suspend-to-RAM
  97. */
  98. struct charger_manager {
  99. struct list_head entry;
  100. struct device *dev;
  101. struct charger_desc *desc;
  102. struct power_supply *fuel_gauge;
  103. struct power_supply **charger_stat;
  104. bool charger_enabled;
  105. int emergency_stop;
  106. int last_temp_mC;
  107. char psy_name_buf[PSY_NAME_MAX + 1];
  108. struct power_supply charger_psy;
  109. bool status_save_ext_pwr_inserted;
  110. bool status_save_batt;
  111. };
  112. #ifdef CONFIG_CHARGER_MANAGER
  113. extern int setup_charger_manager(struct charger_global_desc *gd);
  114. extern bool cm_suspend_again(void);
  115. #else
  116. static void __maybe_unused setup_charger_manager(struct charger_global_desc *gd)
  117. { }
  118. static bool __maybe_unused cm_suspend_again(void)
  119. {
  120. return false;
  121. }
  122. #endif
  123. #endif /* _CHARGER_MANAGER_H */