blob: 93ed7cfd76bf32cb47a74f3c2fcf110fc0fa26a4 [file] [log] [blame]
Duy Truong790f06d2013-02-13 16:38:12 -08001/* Copyright (c) 2010-2011, The Linux Foundation. All rights reserved.
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07002 *
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 __MSM_CHARGER_H__
14#define __MSM_CHARGER_H__
15
16#include <linux/power_supply.h>
17
18enum {
19 CHG_TYPE_USB,
20 CHG_TYPE_AC
21};
22
23enum msm_hardware_charger_event {
24 CHG_INSERTED_EVENT,
25 CHG_ENUMERATED_EVENT,
26 CHG_REMOVED_EVENT,
27 CHG_DONE_EVENT,
28 CHG_BATT_BEGIN_FAST_CHARGING,
29 CHG_BATT_CHG_RESUME,
30 CHG_BATT_TEMP_OUTOFRANGE,
31 CHG_BATT_TEMP_INRANGE,
32 CHG_BATT_INSERTED,
33 CHG_BATT_REMOVED,
34 CHG_BATT_STATUS_CHANGE,
35 CHG_BATT_NEEDS_RECHARGING,
36};
37
38/**
39 * enum hardware_charger_state
40 * @CHG_ABSENT_STATE: charger cable is unplugged
41 * @CHG_PRESENT_STATE: charger cable is plugged but charge current isnt drawn
42 * @CHG_READY_STATE: charger cable is plugged and kernel knows how much current
43 * it can draw
44 * @CHG_CHARGING_STATE: charger cable is plugged and current is drawn for
45 * charging
46 */
47enum msm_hardware_charger_state {
48 CHG_ABSENT_STATE,
49 CHG_PRESENT_STATE,
50 CHG_READY_STATE,
51 CHG_CHARGING_STATE,
52};
53
54struct msm_hardware_charger {
55 int type;
56 int rating;
57 const char *name;
58 int (*start_charging) (struct msm_hardware_charger *hw_chg,
59 int chg_voltage, int chg_current);
60 int (*stop_charging) (struct msm_hardware_charger *hw_chg);
61 int (*charging_switched) (struct msm_hardware_charger *hw_chg);
Abhijeet Dharmapurikar57390b02011-07-14 18:05:11 -070062 void (*start_system_current) (struct msm_hardware_charger *hw_chg,
63 int chg_current);
64 void (*stop_system_current) (struct msm_hardware_charger *hw_chg);
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -070065
66 void *charger_private; /* used by the msm_charger.c */
67};
68
69struct msm_battery_gauge {
70 int (*get_battery_mvolts) (void);
71 int (*get_battery_temperature) (void);
72 int (*is_battery_present) (void);
73 int (*is_battery_temp_within_range) (void);
74 int (*is_battery_id_valid) (void);
75 int (*get_battery_status)(void);
76 int (*get_batt_remaining_capacity) (void);
77 int (*monitor_for_recharging) (void);
78};
79/**
80 * struct msm_charger_platform_data
81 * @safety_time: max charging time in minutes
82 * @update_time: how often the userland be updated of the charging progress
83 * @max_voltage: the max voltage the battery should be charged upto
84 * @min_voltage: the voltage where charging method switches from trickle to fast
85 * @get_batt_capacity_percent: a board specific function to return battery
86 * capacity. Can be null - a default one will be used
87 */
88struct msm_charger_platform_data {
89 unsigned int safety_time;
90 unsigned int update_time;
91 unsigned int max_voltage;
92 unsigned int min_voltage;
93 unsigned int (*get_batt_capacity_percent) (void);
94};
95
96typedef void (*notify_vbus_state) (int);
97#if defined(CONFIG_BATTERY_MSM8X60) || defined(CONFIG_BATTERY_MSM8X60_MODULE)
98void msm_battery_gauge_register(struct msm_battery_gauge *batt_gauge);
99void msm_battery_gauge_unregister(struct msm_battery_gauge *batt_gauge);
100int msm_charger_register(struct msm_hardware_charger *hw_chg);
101int msm_charger_unregister(struct msm_hardware_charger *hw_chg);
102int msm_charger_notify_event(struct msm_hardware_charger *hw_chg,
103 enum msm_hardware_charger_event event);
104void msm_charger_vbus_draw(unsigned int mA);
105
106int msm_charger_register_vbus_sn(void (*callback)(int));
107void msm_charger_unregister_vbus_sn(void (*callback)(int));
108#else
109static inline void msm_battery_gauge_register(struct msm_battery_gauge *gauge)
110{
111}
112static inline void msm_battery_gauge_unregister(struct msm_battery_gauge *gauge)
113{
114}
115static inline int msm_charger_register(struct msm_hardware_charger *hw_chg)
116{
117 return -ENXIO;
118}
119static inline int msm_charger_unregister(struct msm_hardware_charger *hw_chg)
120{
121 return -ENXIO;
122}
123static inline int msm_charger_notify_event(struct msm_hardware_charger *hw_chg,
124 enum msm_hardware_charger_event event)
125{
126 return -ENXIO;
127}
128static inline void msm_charger_vbus_draw(unsigned int mA)
129{
130}
131static inline int msm_charger_register_vbus_sn(void (*callback)(int))
132{
133 return -ENXIO;
134}
135static inline void msm_charger_unregister_vbus_sn(void (*callback)(int))
136{
137}
138#endif
139#endif /* __MSM_CHARGER_H__ */