ARM64: dts: rockchip: enable tsadc node for rk3366-tb
[firefly-linux-kernel-4.4.55.git] / include / linux / mfd / rt5025.h
1 /*
2  *  include/linux/mfd/rt5025/rt5025.h
3  *  Include header file for Richtek RT5025 Core file
4  *
5  *  Copyright (C) 2013 Richtek Technology Corp.
6  *  cy_huang <cy_huang@richtek.com>
7  *
8  * This program is free software; you can redistribute it and/or modify
9  * it under the terms of the GNU General Public License version 2 as
10  * published by the Free Software Foundation; either version 2
11  * of the License, or (at your option) any later version.
12  */
13
14 #ifndef __LINUX_MFD_RT5025_H
15 #define __LINUX_MFD_RT5025_H
16
17 #include <linux/power_supply.h>
18 #include <linux/alarmtimer.h>
19 #include <linux/wakelock.h>
20 #ifdef CONFIG_HAS_EARLYSUSPEND
21 #include <linux/earlysuspend.h>
22 #endif /* CONFIG_HAS_EARLYSUSPEND */
23
24 #define RT5025_DEV_NAME "rt5025"
25 #define RT5025_DRV_VER     "1.1.1_R"
26
27 #define RT_BATT_NAME    "rt-battery"
28
29 enum {
30         RT5025_REG_DEVID,
31         RT5025_REG_RANGE1START = RT5025_REG_DEVID,
32         RT5025_REG_CHGCTL1,
33         RT5025_REG_CHGCTL2,
34         RT5025_REG_CHGCTL3,
35         RT5025_REG_CHGCTL4,
36         RT5025_REG_CHGCTL5,
37         RT5025_REG_CHGCTL6,
38         RT5025_REG_CHGCTL7,
39         RT5025_REG_DCDCCTL1,
40         RT5025_REG_DCDCCTL2,
41         RT5025_REG_DCDCCTL3,
42         RT5025_REG_VRCCTL,
43         RT5025_REG_DCDCCTL4,
44         RT5025_REG_LDOCTL1,
45         RT5025_REG_LDOCTL2,
46         RT5025_REG_LDOCTL3,
47         RT5025_REG_LDOCTL4,
48         RT5025_REG_LDOCTL5,
49         RT5025_REG_LDOCTL6,
50         RT5025_REG_RESV0,
51         RT5025_REG_LDOOMS,
52         RT5025_REG_MISC1,
53         RT5025_REG_ONEVENT,
54         RT5025_REG_DCDCONOFF,
55         RT5025_REG_LDOONOFF,
56         RT5025_REG_MISC2,
57         RT5025_REG_MISC3,
58         RT5025_REG_MISC4,
59         RT5025_REG_GPIO0,
60         RT5025_REG_GPIO1,
61         RT5025_REG_GPIO2,
62         RT5025_REG_RANGE1END = RT5025_REG_GPIO2,
63         RT5025_REG_OFFEVENT = 0x20,
64         RT5025_REG_RANGE2START = RT5025_REG_OFFEVENT,
65         RT5025_REG_RESV1,
66         RT5025_REG_RESV2,
67         RT5025_REG_RESV3,
68         RT5025_REG_RESV4,
69         RT5025_REG_RESV5,
70         RT5025_REG_RESV6,
71         RT5025_REG_RESV7,
72         RT5025_REG_RESV8,
73         RT5025_REG_RESV9,
74         RT5025_REG_RESV10,
75         RT5025_REG_RESV11,
76         RT5025_REG_RESV12,
77         RT5025_REG_RESV13,
78         RT5025_REG_RESV14,
79         RT5025_REG_RESV15,
80         RT5025_REG_IRQEN1,
81         RT5025_REG_IRQSTAT1,
82         RT5025_REG_IRQEN2,
83         RT5025_REG_IRQSTAT2,
84         RT5025_REG_IRQEN3,
85         RT5025_REG_IRQSTAT3,
86         RT5025_REG_IRQEN4,
87         RT5025_REG_IRQSTAT4,
88         RT5025_REG_IRQEN5,
89         RT5025_REG_IRQSTAT5,
90         RT5025_REG_RANGE2END = RT5025_REG_IRQSTAT5,
91         RT5025_REG_IRQCTL = 0x50,
92         RT5025_REG_RANGE3START = RT5025_REG_IRQCTL,
93         RT5025_REG_IRQFLG,
94         RT5025_REG_FGRESV1,
95         RT5025_REG_VALRTMAX,
96         RT5025_REG_VALRTMIN1,
97         RT5025_REG_VALRTMIN2,
98         RT5025_REG_TALRTMAX,
99         RT5025_REG_TALRTMIN,
100         RT5025_REG_VBATSH,
101         RT5025_REG_VBATSL,
102         RT5025_REG_INTEMPH,
103         RT5025_REG_INTEMPL,
104         RT5025_REG_FGRESV2,
105         RT5025_REG_CONFIG,
106         RT5025_REG_AINH,
107         RT5025_REG_AINL,
108         RT5025_REG_TIMERH,
109         RT5025_REG_TIMERL,
110         RT5025_REG_CHANNELH,
111         RT5025_REG_CHANNELL,
112         RT5025_REG_INACVLTH,
113         RT5025_REG_INACVLTL,
114         RT5025_REG_INUSBVLTH,
115         RT5025_REG_INUSBVLTL,
116         RT5025_REG_VSYSVLTH,
117         RT5025_REG_VSYSVLTL,
118         RT5025_REG_GPIO0VLTH,
119         RT5025_REG_GPIO0VLTL,
120         RT5025_REG_GPIO1VLTH,
121         RT5025_REG_GPIO1VLTL,
122         RT5025_REG_GPIO2VLTH,
123         RT5025_REG_GPIO2VLTL,
124         RT5025_REG_DCDC1VLTH,
125         RT5025_REG_DCDC1VLTL,
126         RT5025_REG_DCDC2VLTH,
127         RT5025_REG_DCDC2VLTL,
128         RT5025_REG_DCDC3VLTH,
129         RT5025_REG_DCDC3VLTL,
130         RT5025_REG_CURRH,
131         RT5025_REG_CURRL,
132         RT5025_REG_QCHGHH,
133         RT5025_REG_QCHGHL,
134         RT5025_REG_QCHGLH,
135         RT5025_REG_QCHGLL,
136         RT5025_REG_QDCHGHH,
137         RT5025_REG_QDCHGHL,
138         RT5025_REG_QDCHGLH,
139         RT5025_REG_QDCHGLL,
140         RT5025_REG_RANGE3END = RT5025_REG_QDCHGLL,
141         RT5025_REG_DCDC4OVP = 0xA9,
142         RT5025_REG_RANGE4START = RT5025_REG_DCDC4OVP,
143         RT5025_REG_RANGE4END = RT5025_REG_DCDC4OVP,
144         RT5025_REG_MAX,
145 };
146
147 enum {
148         RT5025_VOFF_2P8V,
149         RT5025_VOFF_2P9V,
150         RT5025_VOFF_3P0V,
151         RT5025_VOFF_3P1V,
152         RT5025_VOFF_3P2V,
153         RT5025_VOFF_3P3V,
154         RT5025_VOFF_3P4V,
155         RT5025_VOFF_3P5V,
156         RT5025_VOFF_MAX = RT5025_VOFF_3P5V,
157 };
158
159 enum {
160         RT5025_STARTIME_100MS,
161         RT5025_STARTIME_1S,
162         RT5025_STARTIME_2S,
163         RT5025_STARTIME_3S,
164         RT5025_STARTIME_MAX = RT5025_STARTIME_3S,
165 };
166
167 enum {
168         RT5025_SHDNPRESS_4S,
169         RT5025_SHDNPRESS_6S,
170         RT5025_SHDNPRESS_8S,
171         RT5025_SHDNPRESS_10S,
172         RT5025_SHDNPRESS_MAX = RT5025_SHDNPRESS_10S,
173 };
174
175 enum {
176         RT5025_VDPM_4V,
177         RT5025_VDPM_4P25V,
178         RT5025_VDPM_4P5V,
179         RT5025_VDPM_DIS,
180         RT5025_VDPM_MAX = RT5025_VDPM_DIS,
181 };
182
183 enum {
184         RT5025_IEOC_10P,
185         RT5025_IEOC_20P,
186         RT5025_IEOC_MAX = RT5025_IEOC_20P,
187 };
188
189 enum {
190         RT5025_VPREC_2V,
191         RT5025_VPREC_2P2V,
192         RT5025_VPREC_2P4V,
193         RT5025_VPREC_2P6V,
194         RT5025_VPREC_2P8V,
195         RT5025_VPREC_3V,
196         RT5025_VPREC_MAX = RT5025_VPREC_3V,
197 };
198
199 enum {
200         RT5025_IPREC_10P,
201         RT5025_IPREC_20P,
202         RT5025_IPREC_MAX = RT5025_IPREC_20P,
203 };
204
205 enum {
206         RT5025_ID_DCDC1,
207         RT5025_ID_DCDC2,
208         RT5025_ID_DCDC3,
209         RT5025_ID_DCDC4,
210         RT5025_ID_LDO1,
211         RT5025_ID_LDO2,
212         RT5025_ID_LDO3,
213         RT5025_ID_LDO4,
214         RT5025_ID_LDO5,
215         RT5025_ID_LDO6,
216         RT5025_MAX_REGULATOR,
217 };
218
219 typedef void (*rt_irq_handler)(void *info, int eventno);
220
221 #define RT5025_DCDCRAMP_MAX     0x03
222 struct rt5025_regulator_ramp {
223         unsigned char ramp_sel:2;
224 };
225
226 struct rt5025_charger_info {
227         struct i2c_client       *i2c;
228         struct device           *dev;
229         struct power_supply     psy;
230 #ifdef CONFIG_HAS_EARLYSUSPEND
231         struct early_suspend early_suspend;
232 #endif /* CONFIG_HAS_EARLYSUSPEND */
233         struct delayed_work tempmon_work;
234         int temp[4];
235         u32 temp_scalar[8];
236         unsigned int te_en:1;
237         unsigned int online:1;
238         unsigned int batabs:1;
239         unsigned int battemp_region:3;
240         unsigned int inttemp_region:2;
241         unsigned int otg_en:1;
242         unsigned int init_once:1;
243         unsigned int suspend:1;
244         unsigned int screenon_adjust:1;
245         unsigned int screen_on:1;
246         int chg_status;
247         int charger_cable;
248         int chg_volt;
249         int acchg_icc;
250         int usbtachg_icc;
251         int usbchg_icc;
252         int screenon_icc;
253 };
254
255 struct rt5025_battery_info {
256         struct i2c_client *client;
257         struct power_supply     battery;
258         struct delayed_work monitor_work;
259         struct wake_lock monitor_wake_lock;
260         struct wake_lock low_battery_wake_lock;
261         struct wake_lock status_wake_lock;
262         struct wake_lock smooth0_wake_lock;
263         struct wake_lock smooth100_wake_lock;
264         struct wake_lock full_battery_wake_lock;
265         /*#if RT5025_TEST_WAKE_LOCK
266         //      struct wake_lock test_wake_lock;
267         //#endif*/
268         struct mutex status_change_lock;
269         struct alarm wakeup_alarm;
270
271         bool temp_range_0_5;
272         bool temp_range_5_10;
273         bool temp_range_10_15;
274         bool temp_range_15_20;
275         bool temp_range_20_30;
276         bool temp_range_30_35;
277         bool temp_range_35_40;
278         bool temp_range_40_45;
279         bool temp_range_45_50;
280
281         bool range_0_5_done;
282         bool range_5_10_done;
283         bool range_10_15_done;
284         bool range_15_20_done;
285         bool range_20_30_done;
286         bool range_30_35_done;
287         bool range_35_40_done;
288         bool range_40_45_done;
289         bool range_45_50_done;
290
291         bool    suspend_poll;
292         ktime_t last_poll;
293         /*      ktime_t last_event;*/
294         struct timespec last_event;
295
296         u16 update_time;
297
298         /* previous battery voltage */
299         u16 pre_vcell;
300         /* previous battery current */
301         s16 pre_curr;
302         /* battery voltage */
303         u16 vcell;
304         /* battery current */
305         s16 curr;
306         /* battery current offset */
307         u16 curr_offset;
308         /* AIN voltage */
309         u16 ain_volt;
310         /* battery internal temperature */
311         s16 int_temp;
312         /* battery external temperature */
313         s16 ext_temp;
314         /* charge coulomb counter */
315         u32 chg_cc;
316         u32 chg_cc_unuse;
317         /* discharge coulomb counter */
318         u32 dchg_cc;
319         u32 dchg_cc_unuse;
320         /* battery capacity */
321         u16 soc;
322         u16 temp_soc;
323         u16 pre_soc;
324         u16 last_soc;
325
326         u16 time_interval;
327         u16 pre_gauge_timer;
328
329         u8 online;
330         u8 status;
331         u8 internal_status;
332         u8 health;
333         u8 present;
334         u8 batt_present;
335
336         /* IRQ flag */
337         u8 irq_flag;
338
339         /* max voltage IRQ flag */
340         bool max_volt_irq;
341         /* min voltage1 IRQ flag */
342         bool min_volt1_irq;
343         /* min voltage2 IRQ flag */
344         bool min_volt2_irq;
345         /* max temperature IRQ flag */
346         bool max_temp_irq;
347         /* min temperature IRQ flag */
348         bool min_temp_irq;
349
350         bool min_volt2_alert;
351
352         u8 temp_high_cnt;
353         u8 temp_low_cnt;
354         u8 temp_recover_cnt;
355
356         bool init_cap;
357         bool avg_flag;
358
359         /* remain capacity */
360         u32 rm;
361         /* SOC permille  */
362         u16 permille;
363         /* full capccity */
364         u16 fcc_aging;
365         u16 fcc;
366         u16     dc;
367         s16 tempcmp;
368
369         bool edv_flag;
370         bool edv_detection;
371         u8 edv_cnt;
372
373         bool tp_flag;
374         u8 tp_cnt;
375
376         u8 cycle_cnt;
377         u32 acc_dchg_cap;
378
379         bool smooth_flag;
380
381         u16 gauge_timer;
382         s16 curr_raw;
383         u32 empty_edv;
384         u8  edv_region;
385         u32  soc1_lock_cnt;
386         u32  soc99_lock_cnt;
387
388         bool init_once;
389         bool device_suspend;
390         bool last_suspend;
391         bool last_tp_flag;
392         bool fcc_update_flag;
393         u32 cal_fcc;
394         u8 test_temp;
395         u8  last_tp;
396         u32 cal_eoc_fcc;
397         u32 cal_soc_offset;
398 };
399
400
401 struct rt5025_charger_data {
402         int *temp;
403         u32 *temp_scalar;
404         int chg_volt;
405         int acchg_icc;
406         int usbtachg_icc;
407         int usbchg_icc;
408         int screenon_icc;
409         unsigned int ieoc:1;
410         unsigned int vdpm:2;
411         unsigned int te_en:1;
412         unsigned int vprec:3;
413         unsigned int iprec:1;
414         unsigned int screenon_adjust:1;
415 };
416
417 struct rt5025_gpio_data {
418         int ngpio;
419 };
420
421 struct rt5025_misc_data {
422         unsigned char vsyslv:3;
423         unsigned char shdnlpress_time:2;
424         unsigned char startlpress_time:2;
425         unsigned char vsyslv_enshdn:1;
426 };
427
428 struct rt5025_irq_data {
429         int irq_gpio;
430 };
431
432 struct rt5025_chip;
433 struct rt5025_platform_data {
434         struct regulator_init_data *regulator[RT5025_MAX_REGULATOR];
435         struct rt5025_charger_data *chg_pdata;
436         struct rt5025_gpio_data *gpio_pdata;
437         struct rt5025_misc_data *misc_pdata;
438         struct rt5025_irq_data *irq_pdata;
439         int (*pre_init)(struct rt5025_chip *rt5025_chip);
440         /** Called after subdevices are set up */
441         int (*post_init)(void);
442 };
443
444 struct rt5025_misc_info {
445         struct i2c_client *i2c;
446         struct device *dev;
447 };
448
449 struct rt5025_chip {
450         struct i2c_client *i2c;
451         struct device *dev;
452         struct rt5025_charger_info *charger_info;
453         struct rt5025_battery_info *battery_info;
454         struct rt5025_misc_info *misc_info;
455         struct mutex io_lock;
456         int suspend;
457 };
458
459 #ifdef CONFIG_CHARGER_RT5025
460 void rt5025_charger_irq_handler(struct rt5025_charger_info *ci, unsigned int event);
461 #endif /* #ifdef CONFIG_CHARGER_RT5025 */
462 #ifdef CONFIG_MISC_RT5025
463 void rt5025_misc_irq_handler(struct rt5025_misc_info *mi, unsigned int event);
464 #endif /* #ifdef CONFIG_MISC_RT5025 */
465 #ifdef CONFIG_BATTERY_RT5025
466 void rt5025_gauge_irq_handler(struct rt5025_battery_info *bi, unsigned int event);
467 #endif /* #ifdef CONFIG_BATTERY_RT5025 */
468
469 extern int rt5025_reg_block_read(struct i2c_client *, int, int, void *);
470 extern int rt5025_reg_block_write(struct i2c_client *, int, int, void *);
471 extern int rt5025_reg_read(struct i2c_client *, int);
472 extern int rt5025_reg_write(struct i2c_client *, int, unsigned char);
473 extern int rt5025_assign_bits(struct i2c_client *, int, unsigned char, unsigned char);
474 extern int rt5025_set_bits(struct i2c_client *, int, unsigned char);
475 extern int rt5025_clr_bits(struct i2c_client *, int, unsigned char);
476
477 extern int rt5025_core_init(struct rt5025_chip *, struct rt5025_platform_data *);
478 extern int rt5025_core_deinit(struct rt5025_chip *);
479
480 #ifdef CONFIG_MFD_RT_SHOW_INFO
481 #define RTINFO(format, args...) \
482         printk(KERN_INFO "%s:%s() line-%d: " format, RT5025_DEV_NAME, __FUNCTION__, __LINE__, ##args)
483 #else
484 #define RTINFO(format, args...)
485 #endif /* CONFIG_MFD_RT_SHOW_INFO */
486
487 #endif /* __LINUX_MFD_RT5025_H */