blob: 1e4d479a4f656439530ca26bd68902ac69904734 [file] [log] [blame]
Bryan Huntsman3f2bc4d2011-08-16 17:27:22 -07001/* Copyright (c) 2010-2011, Code Aurora Forum. 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 __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);
62
63 void *charger_private; /* used by the msm_charger.c */
64};
65
66struct msm_battery_gauge {
67 int (*get_battery_mvolts) (void);
68 int (*get_battery_temperature) (void);
69 int (*is_battery_present) (void);
70 int (*is_battery_temp_within_range) (void);
71 int (*is_battery_id_valid) (void);
72 int (*get_battery_status)(void);
73 int (*get_batt_remaining_capacity) (void);
74 int (*monitor_for_recharging) (void);
75};
76/**
77 * struct msm_charger_platform_data
78 * @safety_time: max charging time in minutes
79 * @update_time: how often the userland be updated of the charging progress
80 * @max_voltage: the max voltage the battery should be charged upto
81 * @min_voltage: the voltage where charging method switches from trickle to fast
82 * @get_batt_capacity_percent: a board specific function to return battery
83 * capacity. Can be null - a default one will be used
84 */
85struct msm_charger_platform_data {
86 unsigned int safety_time;
87 unsigned int update_time;
88 unsigned int max_voltage;
89 unsigned int min_voltage;
90 unsigned int (*get_batt_capacity_percent) (void);
91};
92
93typedef void (*notify_vbus_state) (int);
94#if defined(CONFIG_BATTERY_MSM8X60) || defined(CONFIG_BATTERY_MSM8X60_MODULE)
95void msm_battery_gauge_register(struct msm_battery_gauge *batt_gauge);
96void msm_battery_gauge_unregister(struct msm_battery_gauge *batt_gauge);
97int msm_charger_register(struct msm_hardware_charger *hw_chg);
98int msm_charger_unregister(struct msm_hardware_charger *hw_chg);
99int msm_charger_notify_event(struct msm_hardware_charger *hw_chg,
100 enum msm_hardware_charger_event event);
101void msm_charger_vbus_draw(unsigned int mA);
102
103int msm_charger_register_vbus_sn(void (*callback)(int));
104void msm_charger_unregister_vbus_sn(void (*callback)(int));
105#else
106static inline void msm_battery_gauge_register(struct msm_battery_gauge *gauge)
107{
108}
109static inline void msm_battery_gauge_unregister(struct msm_battery_gauge *gauge)
110{
111}
112static inline int msm_charger_register(struct msm_hardware_charger *hw_chg)
113{
114 return -ENXIO;
115}
116static inline int msm_charger_unregister(struct msm_hardware_charger *hw_chg)
117{
118 return -ENXIO;
119}
120static inline int msm_charger_notify_event(struct msm_hardware_charger *hw_chg,
121 enum msm_hardware_charger_event event)
122{
123 return -ENXIO;
124}
125static inline void msm_charger_vbus_draw(unsigned int mA)
126{
127}
128static inline int msm_charger_register_vbus_sn(void (*callback)(int))
129{
130 return -ENXIO;
131}
132static inline void msm_charger_unregister_vbus_sn(void (*callback)(int))
133{
134}
135#endif
136#endif /* __MSM_CHARGER_H__ */