/include/linux/mfd/pm8xxx/pm8921-charger.h

https://github.com/airy09/android_kernel_sony_apq8064 · C Header · 403 lines · 187 code · 25 blank · 191 comment · 1 complexity · e82247695ea4b4037a5af3fe71206a25 MD5 · raw file

  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. * @hysteresis_temp: the hysteresis between temp thresholds in degC
  78. * @temp_check_period: The polling interval in seconds to check battery
  79. * temeperature if it has gone to cool or warm temperature
  80. * area
  81. * @max_bat_chg_current: Max charge current of the battery in mA
  82. * Usually 70% of full charge capacity
  83. * @usb_max_current: Maximum USB current in mA
  84. * @cool_bat_chg_current: chg current (mA) when the battery is cool
  85. * @warm_bat_chg_current: chg current (mA) when the battery is warm
  86. * @cool_bat_voltage: chg voltage (mV) when the battery is cool
  87. * @warm_bat_voltage: chg voltage (mV) when the battery is warm
  88. * @get_batt_capacity_percent:
  89. * a board specific function to return battery
  90. * capacity. If null - a default one will be used
  91. * @ibat_calib_enable: enables the ibatmax calibration algorithm
  92. * @has_dc_supply: report DC online if this bit is set in board file
  93. * @trkl_voltage: the trkl voltage in (mV) below which hw controlled
  94. * trkl charging happens with linear charger
  95. * @weak_voltage: the weak voltage (mV) below which hw controlled
  96. * trkl charging happens with switching mode charger
  97. * @trkl_current: the trkl current in (mA) to use for trkl charging phase
  98. * @weak_current: the weak current in (mA) to use for weak charging phase
  99. * @vin_min: the input voltage regulation point (mV) - if the
  100. * voltage falls below this, the charger reduces charge
  101. * current or stop charging temporarily
  102. * @thermal_mitigation: the array of charge currents to use as temperature
  103. * increases
  104. * @thermal_levels: the number of thermal mitigation levels supported
  105. * @cold_thr: if high battery will be cold when VBAT_THERM goes above
  106. * 80% of VREF_THERM (typically 1.8volts), if low the
  107. * battery will be considered cold if VBAT_THERM goes above
  108. * 70% of VREF_THERM. Hardware defaults to low.
  109. * @hot_thr: if high the battery will be considered hot when the
  110. * VBAT_THERM goes below 35% of VREF_THERM, if low the
  111. * battery will be considered hot when VBAT_THERM goes
  112. * below 25% of VREF_THERM. Hardware defaults to low.
  113. * @rconn_mohm: resistance in milliOhm from the vbat sense to ground
  114. * with the battery terminals shorted. This indicates
  115. * resistance of the pads, connectors, battery terminals
  116. * and rsense.
  117. * @led_src_config: Power source for anode of charger indicator LED.
  118. * @btc_override: disable the comparators for conifugrations where a
  119. * suitable voltages don't appear on vbatt therm line
  120. * for the charger to detect battery is either cold / hot.
  121. * @btc_override_cold_degc: Temperature in degCelcius when the battery is
  122. * deemed cold and charging never happens. Used
  123. * only if btc_override = 1
  124. * @btc_override_hot_degc: Temperature in degCelcius when the battery is
  125. * deemed hot and charging never happens. Used
  126. * only if btc_override = 1
  127. * @btc_delay_ms: Delay in milliseconds to monitor the battery temperature
  128. * while charging when btc_override = 1
  129. * @btc_panic_if_cant_stop_chg: flag to instruct the driver to panic if the
  130. * driver couldn't stop charging when battery
  131. * temperature is out of bounds. Used only if
  132. * btc_override = 1
  133. * stop_chg_upon_expiry: flag to indicate that the charger driver should
  134. * stop charging the battery when the safety timer
  135. * expires. If not set the charger driver will
  136. * restart charging upon expiry.
  137. * @repeat_safety_time: how many times safety_time should should repeat
  138. * @safety_time: charging safety timer in minutes
  139. * @soc_scaling: indicates whether capacity scaling is to be used
  140. */
  141. struct pm8921_charger_platform_data {
  142. struct pm8xxx_charger_core_data charger_cdata;
  143. unsigned int ttrkl_time;
  144. unsigned int update_time;
  145. unsigned int max_voltage;
  146. unsigned int min_voltage;
  147. unsigned int uvd_thresh_voltage;
  148. unsigned int safe_current_ma;
  149. unsigned int alarm_low_mv;
  150. unsigned int alarm_high_mv;
  151. unsigned int resume_voltage_delta;
  152. int resume_charge_percent;
  153. unsigned int term_current;
  154. int cool_temp;
  155. int warm_temp;
  156. unsigned int temp_check_period;
  157. unsigned int max_bat_chg_current;
  158. unsigned int usb_max_current;
  159. unsigned int cool_bat_chg_current;
  160. unsigned int warm_bat_chg_current;
  161. unsigned int cool_bat_voltage;
  162. unsigned int warm_bat_voltage;
  163. int hysteresis_temp;
  164. unsigned int (*get_batt_capacity_percent) (void);
  165. int64_t batt_id_min;
  166. int64_t batt_id_max;
  167. bool keep_btm_on_suspend;
  168. bool ibat_calib_enable;
  169. bool has_dc_supply;
  170. int trkl_voltage;
  171. int weak_voltage;
  172. int trkl_current;
  173. int weak_current;
  174. int vin_min;
  175. int *thermal_mitigation;
  176. int thermal_levels;
  177. enum pm8921_chg_cold_thr cold_thr;
  178. enum pm8921_chg_hot_thr hot_thr;
  179. int rconn_mohm;
  180. enum pm8921_chg_led_src_config led_src_config;
  181. int battery_less_hardware;
  182. int btc_override;
  183. int btc_override_cold_degc;
  184. int btc_override_hot_degc;
  185. int btc_delay_ms;
  186. int btc_panic_if_cant_stop_chg;
  187. int stop_chg_upon_expiry;
  188. int repeat_safety_time;
  189. unsigned int safety_time;
  190. bool disable_chg_rmvl_wrkarnd;
  191. bool enable_tcxo_warmup_delay;
  192. int soc_scaling;
  193. };
  194. enum pm8921_charger_source {
  195. PM8921_CHG_SRC_NONE,
  196. PM8921_CHG_SRC_USB,
  197. PM8921_CHG_SRC_DC,
  198. };
  199. #if defined(CONFIG_PM8921_CHARGER) || defined(CONFIG_PM8921_CHARGER_MODULE)
  200. void pm8921_charger_vbus_draw(unsigned int mA);
  201. int pm8921_charger_register_vbus_sn(void (*callback)(int));
  202. void pm8921_charger_unregister_vbus_sn(void (*callback)(int));
  203. /**
  204. * pm8921_is_usb_chg_plugged_in - is usb plugged in
  205. *
  206. * if usb is under voltage or over voltage this will return false
  207. */
  208. int pm8921_is_usb_chg_plugged_in(void);
  209. /**
  210. * pm8921_is_dc_chg_plugged_in - is dc plugged in
  211. *
  212. * if dc is under voltage or over voltage this will return false
  213. */
  214. int pm8921_is_dc_chg_plugged_in(void);
  215. /**
  216. * pm8921_is_battery_present -
  217. *
  218. * returns if the pmic sees the battery present
  219. */
  220. int pm8921_is_battery_present(void);
  221. /**
  222. * pm8921_set_max_battery_charge_current - set max battery chg current
  223. *
  224. * @ma: max charge current in milliAmperes
  225. */
  226. int pm8921_set_max_battery_charge_current(int ma);
  227. /**
  228. * pm8921_disable_input_current_limt - disable input current limit
  229. *
  230. * @disable: disable input curren_limit limit
  231. *
  232. * Disabling the charge current limit causes current
  233. * current limits to have no monitoring. An adequate charger
  234. * capable of supplying high current while sustaining VIN_MIN
  235. * is required if input current limiting is disabled.
  236. */
  237. int pm8921_disable_input_current_limit(bool disable);
  238. /**
  239. * pm8921_set_usb_power_supply_type - set USB supply type
  240. *
  241. * @type: power_supply_type enum
  242. *
  243. * This api lets one set a specific usb power_supply_type.
  244. * USB drivers can distinguish between types of USB connections
  245. * and set the appropriate type for the USB supply.
  246. */
  247. int pm8921_set_usb_power_supply_type(enum power_supply_type type);
  248. /**
  249. * pm8921_disable_source_current - disable drawing current from source
  250. * @disable: true to disable current drawing from source false otherwise
  251. *
  252. * This function will stop all charging activities and disable any current
  253. * drawn from the charger. The battery provides the system current.
  254. */
  255. int pm8921_disable_source_current(bool disable);
  256. /**
  257. * pm8921_regulate_input_voltage -
  258. * @voltage: voltage in millivolts to regulate
  259. * allowable values are from 4300mV to 6500mV
  260. */
  261. int pm8921_regulate_input_voltage(int voltage);
  262. /**
  263. * pm8921_is_battery_charging -
  264. * @source: when the battery is charging the source is updated to reflect which
  265. * charger, usb or dc, is charging the battery.
  266. *
  267. * RETURNS: bool, whether the battery is being charged or not
  268. */
  269. bool pm8921_is_battery_charging(int *source);
  270. /**
  271. * pm8921_batt_temperature - get battery temp in degC
  272. *
  273. */
  274. int pm8921_batt_temperature(void);
  275. /**
  276. * pm8921_usb_ovp_set_threshold -
  277. * Set the usb threshold as defined in by
  278. * enum usb_ov_threshold
  279. */
  280. int pm8921_usb_ovp_set_threshold(enum pm8921_usb_ov_threshold ov);
  281. /**
  282. * pm8921_usb_ovp_set_hystersis -
  283. * @ms: the debounce time enum
  284. *
  285. * Sets the debounce time for usb insertion/removal detection
  286. *
  287. */
  288. int pm8921_usb_ovp_set_hystersis(enum pm8921_usb_debounce_time ms);
  289. /**
  290. * pm8921_usb_ovp_disable -
  291. *
  292. * when disabled there is no over voltage protection. The usb voltage is
  293. * fed to the pmic as is. This should be disabled only when there is
  294. * over voltage protection circuitry present outside the pmic chip.
  295. *
  296. */
  297. int pm8921_usb_ovp_disable(int disable);
  298. /**
  299. * pm8921_is_batfet_closed - battery fet status
  300. *
  301. * Returns 1 if batfet is closed 0 if open. On configurations without
  302. * batfet this will return 0.
  303. */
  304. int pm8921_is_batfet_closed(void);
  305. #else
  306. static inline void pm8921_charger_vbus_draw(unsigned int mA)
  307. {
  308. }
  309. static inline int pm8921_charger_register_vbus_sn(void (*callback)(int))
  310. {
  311. return -ENXIO;
  312. }
  313. static inline void pm8921_charger_unregister_vbus_sn(void (*callback)(int))
  314. {
  315. }
  316. static inline int pm8921_is_usb_chg_plugged_in(void)
  317. {
  318. return -ENXIO;
  319. }
  320. static inline int pm8921_is_dc_chg_plugged_in(void)
  321. {
  322. return -ENXIO;
  323. }
  324. static inline int pm8921_is_battery_present(void)
  325. {
  326. return -ENXIO;
  327. }
  328. static inline int pm8917_set_under_voltage_detection_threshold(int mv)
  329. {
  330. return -ENXIO;
  331. }
  332. static inline int pm8921_disable_input_current_limit(bool disable)
  333. {
  334. return -ENXIO;
  335. }
  336. static inline int pm8921_set_usb_power_supply_type(enum power_supply_type type)
  337. {
  338. return -ENXIO;
  339. }
  340. static inline int pm8921_set_max_battery_charge_current(int ma)
  341. {
  342. return -ENXIO;
  343. }
  344. static inline int pm8921_disable_source_current(bool disable)
  345. {
  346. return -ENXIO;
  347. }
  348. static inline int pm8921_regulate_input_voltage(int voltage)
  349. {
  350. return -ENXIO;
  351. }
  352. static inline bool pm8921_is_battery_charging(int *source)
  353. {
  354. *source = PM8921_CHG_SRC_NONE;
  355. return 0;
  356. }
  357. static inline int pm8921_batt_temperature(void)
  358. {
  359. return -ENXIO;
  360. }
  361. static inline int pm8921_usb_ovp_set_threshold(enum pm8921_usb_ov_threshold ov)
  362. {
  363. return -ENXIO;
  364. }
  365. static inline int pm8921_usb_ovp_set_hystersis(enum pm8921_usb_debounce_time ms)
  366. {
  367. return -ENXIO;
  368. }
  369. static inline int pm8921_usb_ovp_disable(int disable)
  370. {
  371. return -ENXIO;
  372. }
  373. static inline int pm8921_is_batfet_closed(void)
  374. {
  375. return 1;
  376. }
  377. #endif
  378. #endif