Commit | Line | Data |
---|---|---|
6fa3eb70 S |
1 | #include <generated/autoconf.h> |
2 | #include <linux/kernel.h> | |
3 | #include <linux/init.h> | |
4 | #include <linux/module.h> | |
5 | #include <linux/slab.h> | |
6 | #include <linux/sched.h> | |
7 | #include <linux/spinlock.h> | |
8 | #include <linux/interrupt.h> | |
9 | #include <linux/list.h> | |
10 | #include <linux/mutex.h> | |
11 | #include <linux/kthread.h> | |
12 | #include <linux/wakelock.h> | |
13 | #include <linux/device.h> | |
14 | #include <linux/kdev_t.h> | |
15 | #include <linux/fs.h> | |
16 | #include <linux/cdev.h> | |
17 | #include <linux/delay.h> | |
18 | #include <linux/platform_device.h> | |
19 | #include <linux/aee.h> | |
20 | #include <linux/xlog.h> | |
21 | #include <linux/proc_fs.h> | |
22 | #include <linux/syscalls.h> | |
23 | #include <linux/sched.h> | |
24 | #include <linux/writeback.h> | |
25 | #include <linux/earlysuspend.h> | |
26 | #include <linux/seq_file.h> | |
27 | ||
28 | #include <asm/uaccess.h> | |
29 | ||
30 | #include <mach/upmu_common.h> | |
31 | #include <mach/upmu_sw.h> | |
32 | #include <mach/upmu_hw.h> | |
33 | #include <mach/mt_pm_ldo.h> | |
34 | #include <mach/mt_pmic_wrap.h> | |
35 | #include <mach/mt_gpio.h> | |
36 | #include <mach/mtk_rtc.h> | |
37 | #include <mach/mt_spm_mtcmos.h> | |
38 | ||
39 | #include <mach/battery_common.h> | |
40 | #include <linux/time.h> | |
41 | ||
42 | // ============================================================ // | |
43 | //extern function | |
44 | // ============================================================ // | |
45 | extern kal_uint32 upmu_get_reg_value(kal_uint32 reg); | |
46 | extern void Charger_Detect_Init(void); | |
47 | extern void Charger_Detect_Release(void); | |
48 | ||
49 | static void hw_bc11_init(void) | |
50 | { | |
51 | //FIXME_8127 | |
52 | Charger_Detect_Init(); | |
53 | ||
54 | //RG_BC11_BIAS_EN=1 | |
55 | upmu_set_rg_bc11_bias_en(0x1); | |
56 | //RG_BC11_VSRC_EN[1:0]=00 | |
57 | upmu_set_rg_bc11_vsrc_en(0x0); | |
58 | //RG_BC11_VREF_VTH = [1:0]=00 | |
59 | upmu_set_rg_bc11_vref_vth(0x0); | |
60 | //RG_BC11_CMP_EN[1.0] = 00 | |
61 | upmu_set_rg_bc11_cmp_en(0x0); | |
62 | //RG_BC11_IPU_EN[1.0] = 00 | |
63 | upmu_set_rg_bc11_ipu_en(0x0); | |
64 | //RG_BC11_IPD_EN[1.0] = 00 | |
65 | upmu_set_rg_bc11_ipd_en(0x0); | |
66 | //BC11_RST=1 | |
67 | upmu_set_rg_bc11_rst(0x1); | |
68 | //BC11_BB_CTRL=1 | |
69 | upmu_set_rg_bc11_bb_ctrl(0x1); | |
70 | ||
71 | //msleep(10); | |
72 | mdelay(50); | |
73 | } | |
74 | ||
75 | static U32 hw_bc11_DCD(void) | |
76 | { | |
77 | U32 wChargerAvail = 0; | |
78 | ||
79 | //RG_BC11_IPU_EN[1.0] = 10 | |
80 | upmu_set_rg_bc11_ipu_en(0x2); | |
81 | //RG_BC11_IPD_EN[1.0] = 01 | |
82 | upmu_set_rg_bc11_ipd_en(0x1); | |
83 | //RG_BC11_VREF_VTH = [1:0]=01 | |
84 | upmu_set_rg_bc11_vref_vth(0x1); | |
85 | //RG_BC11_CMP_EN[1.0] = 10 | |
86 | upmu_set_rg_bc11_cmp_en(0x2); | |
87 | ||
88 | //msleep(20); | |
89 | mdelay(80); | |
90 | ||
91 | wChargerAvail = upmu_get_rgs_bc11_cmp_out(); | |
92 | ||
93 | //RG_BC11_IPU_EN[1.0] = 00 | |
94 | upmu_set_rg_bc11_ipu_en(0x0); | |
95 | //RG_BC11_IPD_EN[1.0] = 00 | |
96 | upmu_set_rg_bc11_ipd_en(0x0); | |
97 | //RG_BC11_CMP_EN[1.0] = 00 | |
98 | upmu_set_rg_bc11_cmp_en(0x0); | |
99 | //RG_BC11_VREF_VTH = [1:0]=00 | |
100 | upmu_set_rg_bc11_vref_vth(0x0); | |
101 | ||
102 | return wChargerAvail; | |
103 | } | |
104 | ||
105 | #ifndef CONFIG_MTK_PMIC_MT6397 //only for mt6323 use | |
106 | static U32 hw_bc11_stepA1(void) | |
107 | { | |
108 | U32 wChargerAvail = 0; | |
109 | ||
110 | //RG_BC11_IPU_EN[1.0] = 10 | |
111 | upmu_set_rg_bc11_ipu_en(0x2); | |
112 | //RG_BC11_VREF_VTH = [1:0]=10 | |
113 | upmu_set_rg_bc11_vref_vth(0x2); | |
114 | //RG_BC11_CMP_EN[1.0] = 10 | |
115 | upmu_set_rg_bc11_cmp_en(0x2); | |
116 | ||
117 | //msleep(80); | |
118 | mdelay(80); | |
119 | ||
120 | wChargerAvail = upmu_get_rgs_bc11_cmp_out(); | |
121 | ||
122 | //RG_BC11_IPU_EN[1.0] = 00 | |
123 | upmu_set_rg_bc11_ipu_en(0x0); | |
124 | //RG_BC11_CMP_EN[1.0] = 00 | |
125 | upmu_set_rg_bc11_cmp_en(0x0); | |
126 | ||
127 | return wChargerAvail; | |
128 | } | |
129 | #endif | |
130 | static U32 hw_bc11_stepA2(void) | |
131 | { | |
132 | U32 wChargerAvail = 0; | |
133 | ||
134 | //RG_BC11_VSRC_EN[1.0] = 10 | |
135 | upmu_set_rg_bc11_vsrc_en(0x2); | |
136 | //RG_BC11_IPD_EN[1:0] = 01 | |
137 | upmu_set_rg_bc11_ipd_en(0x1); | |
138 | //RG_BC11_VREF_VTH = [1:0]=00 | |
139 | upmu_set_rg_bc11_vref_vth(0x0); | |
140 | //RG_BC11_CMP_EN[1.0] = 01 | |
141 | upmu_set_rg_bc11_cmp_en(0x1); | |
142 | ||
143 | //msleep(80); | |
144 | mdelay(80); | |
145 | ||
146 | wChargerAvail = upmu_get_rgs_bc11_cmp_out(); | |
147 | ||
148 | //RG_BC11_VSRC_EN[1:0]=00 | |
149 | upmu_set_rg_bc11_vsrc_en(0x0); | |
150 | //RG_BC11_IPD_EN[1.0] = 00 | |
151 | upmu_set_rg_bc11_ipd_en(0x0); | |
152 | //RG_BC11_CMP_EN[1.0] = 00 | |
153 | upmu_set_rg_bc11_cmp_en(0x0); | |
154 | ||
155 | return wChargerAvail; | |
156 | } | |
157 | ||
158 | static U32 hw_bc11_stepB2(void) | |
159 | { | |
160 | U32 wChargerAvail = 0; | |
161 | ||
162 | //RG_BC11_IPU_EN[1:0]=10 | |
163 | upmu_set_rg_bc11_ipu_en(0x2); | |
164 | //RG_BC11_VREF_VTH = [1:0]=10 | |
165 | upmu_set_rg_bc11_vref_vth(0x1); | |
166 | //RG_BC11_CMP_EN[1.0] = 01 | |
167 | upmu_set_rg_bc11_cmp_en(0x1); | |
168 | ||
169 | //msleep(80); | |
170 | mdelay(80); | |
171 | ||
172 | wChargerAvail = upmu_get_rgs_bc11_cmp_out(); | |
173 | ||
174 | //RG_BC11_IPU_EN[1.0] = 00 | |
175 | upmu_set_rg_bc11_ipu_en(0x0); | |
176 | //RG_BC11_CMP_EN[1.0] = 00 | |
177 | upmu_set_rg_bc11_cmp_en(0x0); | |
178 | //RG_BC11_VREF_VTH = [1:0]=00 | |
179 | upmu_set_rg_bc11_vref_vth(0x0); | |
180 | ||
181 | return wChargerAvail; | |
182 | } | |
183 | ||
184 | static void hw_bc11_done(void) | |
185 | { | |
186 | //RG_BC11_VSRC_EN[1:0]=00 | |
187 | upmu_set_rg_bc11_vsrc_en(0x0); | |
188 | //RG_BC11_VREF_VTH = [1:0]=0 | |
189 | upmu_set_rg_bc11_vref_vth(0x0); | |
190 | //RG_BC11_CMP_EN[1.0] = 00 | |
191 | upmu_set_rg_bc11_cmp_en(0x0); | |
192 | //RG_BC11_IPU_EN[1.0] = 00 | |
193 | upmu_set_rg_bc11_ipu_en(0x0); | |
194 | //RG_BC11_IPD_EN[1.0] = 00 | |
195 | upmu_set_rg_bc11_ipd_en(0x0); | |
196 | //RG_BC11_BIAS_EN=0 | |
197 | upmu_set_rg_bc11_bias_en(0x0); | |
198 | ||
199 | //FIXME_8127 | |
200 | Charger_Detect_Release(); | |
201 | } | |
202 | #if defined(CONFIG_POWER_EXT) || defined(CONFIG_MTK_FPGA) | |
203 | ||
204 | CHARGER_TYPE hw_charger_type_detection(void) | |
205 | { | |
206 | return STANDARD_HOST; | |
207 | } | |
208 | ||
209 | #else | |
210 | ||
211 | #ifdef CONFIG_MTK_PMIC_MT6397 //for mt6397 detect flow | |
212 | ||
213 | CHARGER_TYPE hw_charger_type_detection(void) | |
214 | { | |
215 | CHARGER_TYPE ret = CHARGER_UNKNOWN; | |
216 | hw_bc11_init(); | |
217 | ||
218 | if(1 == hw_bc11_DCD()) | |
219 | { | |
220 | ret = NONSTANDARD_CHARGER; | |
221 | } else { | |
222 | if(1 == hw_bc11_stepA2()) | |
223 | { | |
224 | if(1 == hw_bc11_stepB2()) | |
225 | { | |
226 | ret = STANDARD_CHARGER; | |
227 | } else { | |
228 | ret = CHARGING_HOST; | |
229 | } | |
230 | } else { | |
231 | ret = STANDARD_HOST; | |
232 | } | |
233 | } | |
234 | hw_bc11_done(); | |
235 | ||
236 | return ret; | |
237 | } | |
238 | #else //for mt6323 detect flow | |
239 | ||
240 | CHARGER_TYPE hw_charger_type_detection(void) | |
241 | { | |
242 | CHARGER_TYPE ret = CHARGER_UNKNOWN; | |
243 | hw_bc11_init(); | |
244 | ||
245 | if(1 == hw_bc11_DCD()) | |
246 | { | |
247 | if(1 == hw_bc11_stepA1()) | |
248 | { | |
249 | ret = APPLE_2_1A_CHARGER; | |
250 | } else { | |
251 | ret = NONSTANDARD_CHARGER; | |
252 | } | |
253 | } else { | |
254 | if(1 == hw_bc11_stepA2()) | |
255 | { | |
256 | if(1 == hw_bc11_stepB2()) | |
257 | { | |
258 | ret = STANDARD_CHARGER; | |
259 | } else { | |
260 | ret = CHARGING_HOST; | |
261 | } | |
262 | } else { | |
263 | ret = STANDARD_HOST; | |
264 | } | |
265 | } | |
266 | hw_bc11_done(); | |
267 | ||
268 | return ret; | |
269 | } | |
270 | #endif | |
271 | #endif |