pm8921-charger.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394
  1. /* Copyright (c) 2011-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. */
  12. #ifndef __PM8XXX_CHARGER_H
  13. #define __PM8XXX_CHARGER_H
  14. #include <linux/errno.h>
  15. #include <linux/power_supply.h>
  16. #define PM8921_CHARGER_DEV_NAME "pm8921-charger"
  17. struct pm8xxx_charger_core_data {
  18. unsigned int vbat_channel;
  19. unsigned int batt_temp_channel;
  20. unsigned int batt_id_channel;
  21. };
  22. enum pm8921_chg_cold_thr {
  23. PM_SMBC_BATT_TEMP_COLD_THR__LOW,
  24. PM_SMBC_BATT_TEMP_COLD_THR__HIGH
  25. };
  26. enum pm8921_chg_hot_thr {
  27. PM_SMBC_BATT_TEMP_HOT_THR__LOW,
  28. PM_SMBC_BATT_TEMP_HOT_THR__HIGH
  29. };
  30. enum pm8921_usb_ov_threshold {
  31. PM_USB_OV_5P5V,
  32. PM_USB_OV_6V,
  33. PM_USB_OV_6P5V,
  34. PM_USB_OV_7V,
  35. };
  36. enum pm8921_usb_debounce_time {
  37. PM_USB_BYPASS_DEBOUNCER,
  38. PM_USB_DEBOUNCE_20P5MS,
  39. PM_USB_DEBOUNCE_40P5MS,
  40. PM_USB_DEBOUNCE_80P5MS,
  41. };
  42. enum pm8921_chg_led_src_config {
  43. LED_SRC_GND,
  44. LED_SRC_VPH_PWR,
  45. LED_SRC_5V,
  46. LED_SRC_MIN_VPH_5V,
  47. LED_SRC_BYPASS,
  48. };
  49. /**
  50. * struct pm8921_charger_platform_data -
  51. * valid range 4 to 512 min. PON default 120 min
  52. * @ttrkl_time: max trckl charging time in minutes
  53. * valid range 1 to 64 mins. PON default 15 min
  54. * @update_time: how often the userland be updated of the charging (msec)
  55. * @alarm_low_mv: the voltage (mV) when low battery alarm is triggered
  56. * @alarm_high_mv: the voltage (mV) when high battery alarm is triggered
  57. * @max_voltage: the max voltage (mV) the battery should be charged up to
  58. * @min_voltage: the voltage (mV) where charging method switches from
  59. * trickle to fast. This is also the minimum voltage the
  60. * system operates at
  61. * @uvd_thresh_voltage: the USB falling UVD threshold (mV) (PM8917 only)
  62. * @safe_current_ma: The upper limit of current allowed to be pushed in
  63. * battery. This ends up writing in a one time
  64. * programmable register.
  65. * @resume_voltage_delta: the (mV) drop to wait for before resume charging
  66. * after the battery has been fully charged
  67. * @resume_charge_percent: the % SOC the charger will drop to after the
  68. * battery is fully charged before resuming
  69. * charging.
  70. * @term_current: the charger current (mA) at which EOC happens
  71. * @cool_temp: the temperature (degC) at which the battery is
  72. * considered cool charging current and voltage is reduced.
  73. * Use INT_MIN to indicate not valid.
  74. * @warm_temp: the temperature (degC) at which the battery is
  75. * considered warm charging current and voltage is reduced
  76. * Use INT_MIN to indicate not valid.
  77. * @temp_check_period: The polling interval in seconds to check battery
  78. * temeperature if it has gone to cool or warm temperature
  79. * area
  80. * @max_bat_chg_current: Max charge current of the battery in mA
  81. * Usually 70% of full charge capacity
  82. * @usb_max_current: Maximum USB current in mA
  83. * @cool_bat_chg_current: chg current (mA) when the battery is cool
  84. * @warm_bat_chg_current: chg current (mA) when the battery is warm
  85. * @cool_bat_voltage: chg voltage (mV) when the battery is cool
  86. * @warm_bat_voltage: chg voltage (mV) when the battery is warm
  87. * @get_batt_capacity_percent:
  88. * a board specific function to return battery
  89. * capacity. If null - a default one will be used
  90. * @has_dc_supply: report DC online if this bit is set in board file
  91. * @trkl_voltage: the trkl voltage in (mV) below which hw controlled
  92. * trkl charging happens with linear charger
  93. * @weak_voltage: the weak voltage (mV) below which hw controlled
  94. * trkl charging happens with switching mode charger
  95. * @trkl_current: the trkl current in (mA) to use for trkl charging phase
  96. * @weak_current: the weak current in (mA) to use for weak charging phase
  97. * @vin_min: the input voltage regulation point (mV) - if the
  98. * voltage falls below this, the charger reduces charge
  99. * current or stop charging temporarily
  100. * @thermal_mitigation: the array of charge currents to use as temperature
  101. * increases
  102. * @thermal_levels: the number of thermal mitigation levels supported
  103. * @cold_thr: if high battery will be cold when VBAT_THERM goes above
  104. * 80% of VREF_THERM (typically 1.8volts), if low the
  105. * battery will be considered cold if VBAT_THERM goes above
  106. * 70% of VREF_THERM. Hardware defaults to low.
  107. * @hot_thr: if high the battery will be considered hot when the
  108. * VBAT_THERM goes below 35% of VREF_THERM, if low the
  109. * battery will be considered hot when VBAT_THERM goes
  110. * below 25% of VREF_THERM. Hardware defaults to low.
  111. * @rconn_mohm: resistance in milliOhm from the vbat sense to ground
  112. * with the battery terminals shorted. This indicates
  113. * resistance of the pads, connectors, battery terminals
  114. * and rsense.
  115. * @led_src_config: Power source for anode of charger indicator LED.
  116. * @btc_override: disable the comparators for conifugrations where a
  117. * suitable voltages don't appear on vbatt therm line
  118. * for the charger to detect battery is either cold / hot.
  119. * @btc_override_cold_degc: Temperature in degCelcius when the battery is
  120. * deemed cold and charging never happens. Used
  121. * only if btc_override = 1
  122. * @btc_override_hot_degc: Temperature in degCelcius when the battery is
  123. * deemed hot and charging never happens. Used
  124. * only if btc_override = 1
  125. * @btc_delay_ms: Delay in milliseconds to monitor the battery temperature
  126. * while charging when btc_override = 1
  127. * @btc_panic_if_cant_stop_chg: flag to instruct the driver to panic if the
  128. * driver couldn't stop charging when battery
  129. * temperature is out of bounds. Used only if
  130. * btc_override = 1
  131. * stop_chg_upon_expiry: flag to indicate that the charger driver should
  132. * stop charging the battery when the safety timer
  133. * expires. If not set the charger driver will
  134. * restart charging upon expiry.
  135. */
  136. struct pm8921_charger_platform_data {
  137. struct pm8xxx_charger_core_data charger_cdata;
  138. unsigned int ttrkl_time;
  139. unsigned int update_time;
  140. unsigned int max_voltage;
  141. unsigned int min_voltage;
  142. unsigned int uvd_thresh_voltage;
  143. unsigned int safe_current_ma;
  144. unsigned int alarm_low_mv;
  145. unsigned int alarm_high_mv;
  146. unsigned int resume_voltage_delta;
  147. int resume_charge_percent;
  148. unsigned int term_current;
  149. int cool_temp;
  150. int warm_temp;
  151. unsigned int temp_check_period;
  152. unsigned int max_bat_chg_current;
  153. unsigned int usb_max_current;
  154. unsigned int cool_bat_chg_current;
  155. unsigned int warm_bat_chg_current;
  156. unsigned int cool_bat_voltage;
  157. unsigned int warm_bat_voltage;
  158. int hysteresis_temp;
  159. unsigned int (*get_batt_capacity_percent) (void);
  160. int64_t batt_id_min;
  161. int64_t batt_id_max;
  162. bool keep_btm_on_suspend;
  163. bool has_dc_supply;
  164. int trkl_voltage;
  165. int weak_voltage;
  166. int trkl_current;
  167. int weak_current;
  168. int vin_min;
  169. int *thermal_mitigation;
  170. int thermal_levels;
  171. enum pm8921_chg_cold_thr cold_thr;
  172. enum pm8921_chg_hot_thr hot_thr;
  173. int rconn_mohm;
  174. enum pm8921_chg_led_src_config led_src_config;
  175. int battery_less_hardware;
  176. int btc_override;
  177. int btc_override_cold_degc;
  178. int btc_override_hot_degc;
  179. int btc_delay_ms;
  180. int btc_panic_if_cant_stop_chg;
  181. int stop_chg_upon_expiry;
  182. bool disable_chg_rmvl_wrkarnd;
  183. };
  184. enum pm8921_charger_source {
  185. PM8921_CHG_SRC_NONE,
  186. PM8921_CHG_SRC_USB,
  187. PM8921_CHG_SRC_DC,
  188. };
  189. #if defined(CONFIG_PM8921_CHARGER) || defined(CONFIG_PM8921_CHARGER_MODULE)
  190. void pm8921_charger_vbus_draw(unsigned int mA);
  191. int pm8921_charger_register_vbus_sn(void (*callback)(int));
  192. void pm8921_charger_unregister_vbus_sn(void (*callback)(int));
  193. /**
  194. * pm8921_is_usb_chg_plugged_in - is usb plugged in
  195. *
  196. * if usb is under voltage or over voltage this will return false
  197. */
  198. int pm8921_is_usb_chg_plugged_in(void);
  199. /**
  200. * pm8921_is_dc_chg_plugged_in - is dc plugged in
  201. *
  202. * if dc is under voltage or over voltage this will return false
  203. */
  204. int pm8921_is_dc_chg_plugged_in(void);
  205. /**
  206. * pm8921_is_battery_present -
  207. *
  208. * returns if the pmic sees the battery present
  209. */
  210. int pm8921_is_battery_present(void);
  211. /**
  212. * pm8921_set_max_battery_charge_current - set max battery chg current
  213. *
  214. * @ma: max charge current in milliAmperes
  215. */
  216. int pm8921_set_max_battery_charge_current(int ma);
  217. /**
  218. * pm8921_disable_input_current_limt - disable input current limit
  219. *
  220. * @disable: disable input curren_limit limit
  221. *
  222. * Disabling the charge current limit causes current
  223. * current limits to have no monitoring. An adequate charger
  224. * capable of supplying high current while sustaining VIN_MIN
  225. * is required if input current limiting is disabled.
  226. */
  227. int pm8921_disable_input_current_limit(bool disable);
  228. /**
  229. * pm8921_set_usb_power_supply_type - set USB supply type
  230. *
  231. * @type: power_supply_type enum
  232. *
  233. * This api lets one set a specific usb power_supply_type.
  234. * USB drivers can distinguish between types of USB connections
  235. * and set the appropriate type for the USB supply.
  236. */
  237. int pm8921_set_usb_power_supply_type(enum power_supply_type type);
  238. /**
  239. * pm8921_disable_source_current - disable drawing current from source
  240. * @disable: true to disable current drawing from source false otherwise
  241. *
  242. * This function will stop all charging activities and disable any current
  243. * drawn from the charger. The battery provides the system current.
  244. */
  245. int pm8921_disable_source_current(bool disable);
  246. /**
  247. * pm8921_regulate_input_voltage -
  248. * @voltage: voltage in millivolts to regulate
  249. * allowable values are from 4300mV to 6500mV
  250. */
  251. int pm8921_regulate_input_voltage(int voltage);
  252. /**
  253. * pm8921_is_battery_charging -
  254. * @source: when the battery is charging the source is updated to reflect which
  255. * charger, usb or dc, is charging the battery.
  256. *
  257. * RETURNS: bool, whether the battery is being charged or not
  258. */
  259. bool pm8921_is_battery_charging(int *source);
  260. /**
  261. * pm8921_batt_temperature - get battery temp in degC
  262. *
  263. */
  264. int pm8921_batt_temperature(void);
  265. /**
  266. * pm8921_usb_ovp_set_threshold -
  267. * Set the usb threshold as defined in by
  268. * enum usb_ov_threshold
  269. */
  270. int pm8921_usb_ovp_set_threshold(enum pm8921_usb_ov_threshold ov);
  271. /**
  272. * pm8921_usb_ovp_set_hystersis -
  273. * @ms: the debounce time enum
  274. *
  275. * Sets the debounce time for usb insertion/removal detection
  276. *
  277. */
  278. int pm8921_usb_ovp_set_hystersis(enum pm8921_usb_debounce_time ms);
  279. /**
  280. * pm8921_usb_ovp_disable -
  281. *
  282. * when disabled there is no over voltage protection. The usb voltage is
  283. * fed to the pmic as is. This should be disabled only when there is
  284. * over voltage protection circuitry present outside the pmic chip.
  285. *
  286. */
  287. int pm8921_usb_ovp_disable(int disable);
  288. /**
  289. * pm8921_is_batfet_closed - battery fet status
  290. *
  291. * Returns 1 if batfet is closed 0 if open. On configurations without
  292. * batfet this will return 0.
  293. */
  294. int pm8921_is_batfet_closed(void);
  295. #else
  296. static inline void pm8921_charger_vbus_draw(unsigned int mA)
  297. {
  298. }
  299. static inline int pm8921_charger_register_vbus_sn(void (*callback)(int))
  300. {
  301. return -ENXIO;
  302. }
  303. static inline void pm8921_charger_unregister_vbus_sn(void (*callback)(int))
  304. {
  305. }
  306. static inline int pm8921_is_usb_chg_plugged_in(void)
  307. {
  308. return -ENXIO;
  309. }
  310. static inline int pm8921_is_dc_chg_plugged_in(void)
  311. {
  312. return -ENXIO;
  313. }
  314. static inline int pm8921_is_battery_present(void)
  315. {
  316. return -ENXIO;
  317. }
  318. static inline int pm8917_set_under_voltage_detection_threshold(int mv)
  319. {
  320. return -ENXIO;
  321. }
  322. static inline int pm8921_disable_input_current_limit(bool disable)
  323. {
  324. return -ENXIO;
  325. }
  326. static inline int pm8921_set_usb_power_supply_type(enum power_supply_type type)
  327. {
  328. return -ENXIO;
  329. }
  330. static inline int pm8921_set_max_battery_charge_current(int ma)
  331. {
  332. return -ENXIO;
  333. }
  334. static inline int pm8921_disable_source_current(bool disable)
  335. {
  336. return -ENXIO;
  337. }
  338. static inline int pm8921_regulate_input_voltage(int voltage)
  339. {
  340. return -ENXIO;
  341. }
  342. static inline bool pm8921_is_battery_charging(int *source)
  343. {
  344. *source = PM8921_CHG_SRC_NONE;
  345. return 0;
  346. }
  347. static inline int pm8921_batt_temperature(void)
  348. {
  349. return -ENXIO;
  350. }
  351. static inline int pm8921_usb_ovp_set_threshold(enum pm8921_usb_ov_threshold ov)
  352. {
  353. return -ENXIO;
  354. }
  355. static inline int pm8921_usb_ovp_set_hystersis(enum pm8921_usb_debounce_time ms)
  356. {
  357. return -ENXIO;
  358. }
  359. static inline int pm8921_usb_ovp_disable(int disable)
  360. {
  361. return -ENXIO;
  362. }
  363. static inline int pm8921_is_batfet_closed(void)
  364. {
  365. return 1;
  366. }
  367. #endif
  368. #endif