drm/prime: add return check for dma_buf_fd
[profile/mobile/platform/kernel/linux-3.10-sc7730.git] / drivers / battery / sprd_battery.h
1 /*
2  * Copyright (C) 2012 Spreadtrum Communications Inc.
3  *
4  * This software is licensed under the terms of the GNU General Public
5  * License version 2, as published by the Free Software Foundation, and
6  * may be copied, distributed, and modified under those terms.
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13
14 #ifndef _SPRD_BATTERY_H_
15 #define _SPRD_BATTERY_H_
16
17 #include <linux/types.h>
18 #include <linux/hrtimer.h>
19 #include <linux/wakelock.h>
20 #include <linux/power_supply.h>
21 #include <linux/sprd_battery_common.h>
22
23 #include <mach/adc.h>
24
25 #if defined(CONFIG_SPRD_2713_POWER) || defined(CONFIG_SPRD_EXT_IC_POWER)
26 #include "../power/sprd_2713_charge.h"
27 #include "../power/sprd_2713_fgu.h"
28 #endif
29
30 #define SPRDBAT_AUXADC_CAL_NO         0
31 #define SPRDBAT_AUXADC_CAL_NV         1
32 #define SPRDBAT_AUXADC_CAL_CHIP      2
33
34 #define SPRDBAT_CHG_END_NONE_BIT                        0
35 #define SPRDBAT_CHG_END_FULL_BIT                (1 << 0)
36 #define SPRDBAT_CHG_END_OTP_OVERHEAT_BIT        (1 << 1)
37 #define SPRDBAT_CHG_END_OTP_COLD_BIT    (1 << 2)
38 #define SPRDBAT_CHG_END_TIMEOUT_BIT             (1 << 3)
39 #define SPRDBAT_CHG_END_OVP_BIT         (1 << 4)
40
41 #define SPRDBAT_AVERAGE_COUNT   8
42 #define SPRDBAT_PLUG_WAKELOCK_TIME_SEC 3
43
44 #define SPRDBAT_AUXADC_CAL_TYPE_NO         0
45 #define SPRDBAT_AUXADC_CAL_TYPE_NV         1
46 #define SPRDBAT_AUXADC_CAL_TYPE_EFUSE      2
47
48 enum sprd_adapter_type {
49         ADP_TYPE_UNKNOW = 0,    //unknow adapter type
50         ADP_TYPE_CDP = 1,       //Charging Downstream Port,USB&standard charger
51         ADP_TYPE_DCP = 2,       //Dedicated Charging Port, standard charger
52         ADP_TYPE_SDP = 4,       //Standard Downstream Port,USB and nonstandard charge
53 };
54
55 struct sprdbat_info {
56         uint32_t module_state;
57         uint32_t bat_health;
58         uint32_t chging_current;
59         int bat_current;
60         uint32_t chg_current_type;
61         uint32_t adp_type;
62         uint32_t usb_online;
63         uint32_t ac_online;
64         uint32_t vchg_vol;
65         uint32_t cccv_point;
66         unsigned long chg_start_time;
67         uint32_t chg_stop_flags;
68         uint32_t vbat_vol;
69         uint32_t vbat_ocv;
70         int cur_temp;
71         uint32_t capacity;
72         uint32_t soc;
73         uint32_t chg_this_timeout;
74 };
75
76 struct sprdbat_drivier_data {
77         struct sprd_battery_platform_data *pdata;
78         struct sprdbat_info bat_info;
79         struct mutex lock;
80         struct device *dev;
81         struct power_supply battery;
82         struct power_supply ac;
83         struct power_supply usb;
84         uint32_t gpio_charger_detect;
85         uint32_t gpio_chg_cv_state;
86         uint32_t gpio_vchg_ovi;
87         uint32_t irq_charger_detect;
88         uint32_t irq_chg_cv_state;
89         uint32_t irq_vchg_ovi;
90         struct wake_lock charger_plug_out_lock;
91         struct workqueue_struct *monitor_wqueue;
92         struct delayed_work cv_irq_work;
93         struct delayed_work battery_work;
94         struct delayed_work battery_sleep_work;
95         struct work_struct ovi_irq_work;
96         struct delayed_work *charge_work;
97         int (*start_charge) (void);
98         int (*stop_charge) (void);
99 #ifdef CONFIG_LEDS_TRIGGERS
100         struct led_classdev charging_led;
101 #endif
102
103 };
104
105 struct sprdbat_auxadc_cal {
106         uint16_t p0_vol;        //4.2V
107         uint16_t p0_adc;
108         uint16_t p1_vol;        //3.6V
109         uint16_t p1_adc;
110         uint16_t cal_type;
111 };
112
113 #define sprdbat_read_vbat_vol sprdfgu_read_vbat_vol
114 #define sprdbat_read_temp sprdchg_read_temp
115 #define sprdbat_adp_plug_nodify sprdfgu_adp_status_set
116 #define sprdbat_read_temp_adc sprdchg_read_temp_adc
117
118 int sprdbat_interpolate(int x, int n, struct sprdbat_table_data *tab);
119
120 #ifdef SPRDBAT_TWO_CHARGE_CHANNEL
121 #define SPRDBAT_CHG_EVENT_EXT_OVI   1
122 #define SPRDBAT_CHG_EVENT_EXT_OVI_RESTART   2
123 void sprdchg_start_charge_ext(void);
124 void sprdchg_stop_charge_ext(void);
125 int sprdchg_is_chg_done_ext(void);
126 int sprdchg_charge_init_ext(struct platform_device *pdev);
127 void sprdchg_chg_monitor_cb_ext(void *data);
128 void sprdchg_open_ovi_fun_ext(void);
129 void sprdchg_close_ovi_fun_ext(void);
130 void sprdbat_charge_event_ext(uint32_t event);
131 #endif
132
133 #endif /* _CHG_DRVAPI_H_ */