PageRenderTime 26ms CodeModel.GetById 13ms app.highlight 9ms RepoModel.GetById 1ms app.codeStats 0ms

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