rk3188:pmu:rt5025:modify some bug for pmu charger & irq & guage
[firefly-linux-kernel-4.4.55.git] / include / linux / mfd / rt5025.h
1 /*
2  *  include/linux/mfd/rt5025.h
3  *  Include header file for Richtek RT5025 Core file
4  *
5  *  Copyright (C) 2013 Richtek Electronics
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.
11  */
12
13 #ifndef __LINUX_MFD_RT5025_H
14 #define __LINUX_MFD_RT5025_H
15
16 #include <linux/power_supply.h>
17
18 #define RT5025_DEVICE_NAME "RT5025"
19
20 enum {
21         RT5025_RSTDELAY1_100MS,
22         RT5025_RSTDELAY1_500MS,
23         RT5025_RSTDELAY1_1S,
24         RT5025_RSTDELAY1_2S,
25 };
26
27 enum {
28         RT5025_RSTDELAY2_100MS,
29         RT5025_RSTDELAY2_500MS,
30         RT5025_RSTDELAY2_1S,
31         RT5025_RSTDELAY2_2S,
32 };
33
34 enum {
35         RT5025_VOFF_2P8V,
36         RT5025_VOFF_2P9V,
37         RT5025_VOFF_3P0V,
38         RT5025_VOFF_3P1V,
39         RT5025_VOFF_3P2V,
40         RT5025_VOFF_3P3V,
41         RT5025_VOFF_3P4V,
42         RT5025_VOFF_3P5V,
43 };
44
45 enum {
46         RT5025_STARTIME_100MS,
47         RT5025_STARTIME_1S,
48         RT5025_STARTIME_2S,
49         RT5025_STARTIME_3S,
50 };
51
52 enum {
53         RT5025_LPRESS_1S,
54         RT5025_LPRESS_1P5S,
55         RT5025_LPRESS_2S,
56         RT5025_LPRESS_2P5S,
57 };
58
59 enum {
60         RT5025_SHDNPRESS_4S,
61         RT5025_SHDNPRESS_6S,
62         RT5025_SHDNPRESS_8S,
63         RT5025_SHDNPRESS_10S,
64 };
65
66 enum {
67         RT5025_PGDLY_10MS,
68         RT5025_PGDLY_50MS,
69         RT5025_PGDLY_100MS,
70         RT5025_PGDLY_200MS,
71 };
72
73 enum {
74         RT5025_SHDNDLY_100MS,
75         RT5025_SHDNDLY_500MS,
76         RT5025_SHDNDLY_1S,
77         RT5025_SHDNDLY_2S,
78 };
79
80 enum {
81         RT5025_CCCHG_TO_4H,
82         RT5025_CCCHG_TO_6H,
83         RT5025_CCCHG_TO_8H,
84         RT5025_CCCHG_TO_10H,
85 };
86
87 enum {
88         RT5025_PRECHG_TO_30M,
89         RT5025_PRECHG_TO_40M,
90         RT5025_PRECHG_TO_50M,
91         RT5025_PRECHG_TO_60M,
92 };
93
94 enum {
95         RT5025_ICC_0P5A,
96         RT5025_ICC_0P6A,
97         RT5025_ICC_0P7A,
98         RT5025_ICC_0P8A,
99         RT5025_ICC_0P9A,
100         RT5025_ICC_1A,
101         RT5025_ICC_1P1A,
102         RT5025_ICC_1P2A,
103         RT5025_ICC_1P3A,
104         RT5025_ICC_1P4A,
105         RT5025_ICC_1P5A,
106         RT5025_ICC_1P6A,
107         RT5025_ICC_1P7A,
108         RT5025_ICC_1P8A,
109         RT5025_ICC_1P9A,
110         RT5025_ICC_2A,
111         RT5025_ICC_MAX,
112 };
113
114 enum {
115         RT5025_AICR_100MA,
116         RT5025_AICR_500MA,
117         RT5025_AICR_1A,
118         RT5025_AICR_NOLIMIT,
119 };
120
121 enum {
122         RT5025_DPM_4V,
123         RT5025_DPM_4P25V,
124         RT5025_DPM_4P5V,
125         RT5025_DPM_DIS,
126 };
127
128 enum {
129         RT5025_VPREC_2V,
130         RT5025_VPREC_2P2V,
131         RT5025_VPREC_2P4V,
132         RT5025_VPREC_2P6V,
133         RT5025_VPREC_2P8V,
134         RT5025_VPREC_3V,
135         RT5025_VPREC_3V_1,
136         RT5025_VPREC_3V_2,
137 };
138
139 enum {
140         RT5025_IEOC_10P,
141         RT5025_IEOC_20P,
142 };
143
144 enum {
145         RT5025_IPREC_10P,
146         RT5025_IPREC_20P,
147 };
148
149 enum {
150         RT5025_ID_DCDC1,
151         RT5025_ID_DCDC2,
152         RT5025_ID_DCDC3,
153         RT5025_ID_DCDC4,
154         RT5025_ID_LDO1,
155         RT5025_ID_LDO2,
156         RT5025_ID_LDO3,
157         RT5025_ID_LDO4,
158         RT5025_ID_LDO5,
159         RT5025_ID_LDO6,
160         RT5025_MAX_REGULATOR,
161 };
162
163 struct rt5025_power_data {
164         union {
165                 struct {
166                         unsigned char Resv1:1;
167                         unsigned char CHGBC_EN:1;
168                         unsigned char TE:1;
169                         unsigned char Resv2:1;
170                         unsigned char CCCHG_TIMEOUT:2;
171                         unsigned char PRECHG_TIMEOUT:2;
172                 }bitfield;
173                 unsigned char val;
174         }CHGControl2;
175         union {
176                 struct {
177                         unsigned char Resv:2;
178                         unsigned char VOREG:6;
179                 }bitfield;
180                 unsigned char val;
181         }CHGControl3;
182         union {
183                 struct {
184                         unsigned char AICR_CON:1;
185                         unsigned char AICR:2;
186                         unsigned char ICC:4;
187                         unsigned char CHG_RST:1;
188                 }bitfield;
189                 unsigned char val;
190         }CHGControl4;
191         union {
192                 struct {
193                         unsigned char Resv1:4;
194                         unsigned char DPM:2;
195                         unsigned char Resv2:2;
196                 }bitfield;
197                 unsigned char val;
198         }CHGControl5;
199         union {
200                 struct {
201                         unsigned char IPREC:1;
202                         unsigned char IEOC:1;
203                         unsigned char VPREC:3;
204                         unsigned char Resv:3;
205                 }bitfield;
206                 unsigned char val;
207         }CHGControl6;
208         union {
209                 struct {
210                         unsigned char Resv1:4;
211                         unsigned char CHGC_EN:1;
212                         unsigned char CHG_DCDC_MODE:1;
213                         unsigned char BATD_EN:1;
214                         unsigned char Resv2:1;
215                 }bitfield;
216                 unsigned char val;
217         }CHGControl7;
218         u32 fcc;
219 };
220
221 struct rt5025_gpio_data {
222         unsigned gpio_base;
223         unsigned irq_base;
224 };
225
226 struct rt5025_misc_data {
227         union {
228                 struct {
229                         unsigned char Action:2;
230                         unsigned char Delayed1:2;
231                         unsigned char Delayed2:2;
232                         unsigned char Resv:2;
233                 }bitfield;
234                 unsigned char val;
235         }RSTCtrl;
236         union {
237                 struct {
238                         unsigned char Resv:5;
239                         unsigned char VOFF:3;
240                 }bitfield;
241                 unsigned char val;
242         }VSYSCtrl;
243         union {
244                 struct {
245                         unsigned char PG_DLY:2;
246                         unsigned char SHDN_PRESS:2;
247                         unsigned char LPRESS_TIME:2;
248                         unsigned char START_TIME:2;
249                 }bitfield;
250                 unsigned char val;
251         }PwrOnCfg;
252         union {
253                 struct {
254                         unsigned char Resv:4;
255                         unsigned char SHDN_DLYTIME:2;
256                         unsigned char SHDN_TIMING:1;
257                         unsigned char SHDN_CTRL:1;
258                 }bitfield;
259                 unsigned char val;
260         }SHDNCtrl;
261         union {
262                 struct {
263                         unsigned char Resv:2;
264                         unsigned char OT_ENSHDN:1;
265                         unsigned char PWRON_ENSHDN:1;
266                         unsigned char DCDC3LV_ENSHDN:1;
267                         unsigned char DCDC2LV_ENSHDN:1;
268                         unsigned char DCDC1LV_ENSHDN:1;
269                         unsigned char SYSLV_ENSHDN:1;
270                 }bitfield;
271                 unsigned char val;
272         }PwrOffCond;
273 };
274
275 struct rt5025_irq_data {
276         union {
277                 struct {
278                         unsigned char BATABS:1;
279                         unsigned char Resv1:2;
280                         unsigned char INUSB_PLUGIN:1;
281                         unsigned char INUSBOVP:1;
282                         unsigned char Resv2:1;
283                         unsigned char INAC_PLUGIN:1;
284                         unsigned char INACOVP:1;
285                 }bitfield;
286                 unsigned char val;
287         }irq_enable1;
288         union {
289                 struct {
290                         unsigned char CHTERMI:1;
291                         unsigned char CHBATOVI:1;
292                         unsigned char CHGOODI_INUSB:1;
293                         unsigned char CHBADI_INUSB:1;
294                         unsigned char CHSLPI_INUSB:1;
295                         unsigned char CHGOODI_INAC:1;
296                         unsigned char CHBADI_INAC:1;
297                         unsigned char CHSLPI_INAC:1;
298                 }bitfield;
299                 unsigned char val;
300         }irq_enable2;
301         union {
302                 struct {
303                         unsigned char TIMEOUT_CC:1;
304                         unsigned char TIMEOUT_PC:1;
305                         unsigned char Resv:3;
306                         unsigned char CHVSREGI:1;
307                         unsigned char CHTREGI:1;
308                         unsigned char CHRCHGI:1;
309                 }bitfield;
310                 unsigned char val;
311         }irq_enable3;
312         union {
313                 struct {
314                         unsigned char SYSLV:1;
315                         unsigned char DCDC4LVHV:1;
316                         unsigned char PWRONLP:1;
317                         unsigned char PWRONSP:1;
318                         unsigned char DCDC3LV:1;
319                         unsigned char DCDC2LV:1;
320                         unsigned char DCDC1LV:1;
321                         unsigned char OT:1;
322                 }bitfield;
323                 unsigned char val;
324         }irq_enable4;
325         union {
326                 struct {
327                         unsigned char Resv:1;
328                         unsigned char GPIO0_IE:1;
329                         unsigned char GPIO1_IE:1;
330                         unsigned char GPIO2_IE:1;
331                         unsigned char RESETB:1;
332                         unsigned char PWRONF:1;
333                         unsigned char PWRONR:1;
334                         unsigned char KPSHDN:1;
335                 }bitfield;
336                 unsigned char val;
337         }irq_enable5;
338 };
339
340 #define CHG_EVENT_INACOVP       (0x80<<16)
341 #define CHG_EVENT_INAC_PLUGIN   (0x40<<16)
342 #define CHG_EVENT_INUSBOVP      (0x10<<16)
343 #define CHG_EVENT_INUSB_PLUGIN  (0x08<<16)
344 #define CHG_EVENT_BAT_ABS       (0x01<<16)
345
346 #define CHG_EVENT_CHSLPI_INAC   (0x80<<8)
347 #define CHG_EVENT_CHBADI_INAC   (0x40<<8)
348 #define CHG_EVENT_CHGOODI_INAC  (0x20<<8)
349 #define CHG_EVENT_CHSLPI_INUSB  (0x10<<8)
350 #define CHG_EVENT_CHBADI_INUSB  (0x08<<8)
351 #define CHG_EVENT_CHGOODI_INUSB (0x04<<8)
352 #define CHG_EVENT_CHBATOVI      (0x02<<8)
353 #define CHG_EVENT_CHTERMI       (0x01<<8)
354
355 #define CHG_EVENT_CHRCHGI       (0x80<<0)
356 #define CHG_EVENT_CHTREGI       (0x40<<0)
357 #define CHG_EVENT_CHVSREGI      (0x20<<0)
358 #define CHG_EVENT_TIMEOUTPC     (0x02<<0)
359 #define CHG_EVENT_TIMEOUTCC     (0x01<<0)
360
361 #define CHARGER_DETECT_MASK     (CHG_EVENT_INAC_PLUGIN | CHG_EVENT_INUSB_PLUGIN | \
362                                  CHG_EVENT_CHSLPI_INAC | CHG_EVENT_CHSLPI_INUSB | \
363                                  CHG_EVENT_CHBADI_INAC | CHG_EVENT_CHBADI_INUSB)
364
365 #define PWR_EVENT_OTIQ          (0x80<<8)
366 #define PWR_EVENT_DCDC1LV       (0x40<<8)
367 #define PWR_EVENT_DCDC2LV       (0x20<<8)
368 #define PWR_EVENT_DCDC3LV       (0x10<<8)
369 #define PWR_EVENT_PWRONSP       (0x08<<8)
370 #define PWR_EVENT_PWRONLP       (0x04<<8)
371 #define PWR_EVENT_DCDC4LVHV     (0x02<<8)
372 #define PWR_EVENT_SYSLV         (0x01<<8)
373
374 #define PWR_EVENT_KPSHDN        (0x80<<0)
375 #define PWR_EVNET_PWRONR        (0x40<<0)
376 #define PWR_EVENT_PWRONF        (0x20<<0)
377 #define PWR_EVENT_RESETB        (0x10<<0)
378 #define PWR_EVENT_GPIO2IE       (0x08<<0)
379 #define PWR_EVENT_GPIO1IE       (0x04<<0)
380 #define PWR_EVENT_GPIO0IE       (0x02<<0)
381
382 struct rt5025_event_callback {
383         #if 1
384         void (*charger_event_callback)(uint32_t detected);
385         void (*power_event_callkback)(uint32_t detected);
386         #else
387         void (*over_temperature_callback)(uint8_t detected);
388         void (*charging_complete_callback)(void);
389         void (*over_voltage_callback)(uint8_t detected);
390         void (*under_voltage_callback)(uint8_t detected);
391         void (*charge_fault_callback)(uint8_t detected);
392         void (*charge_warning_callback)(uint8_t detected);
393         #endif
394 };
395
396 struct rt5025_power_info {
397         struct i2c_client       *i2c;
398         struct device           *dev;
399         struct rt5025_gauge_callbacks *event_callback;
400         struct power_supply     ac;
401         struct power_supply     usb;
402         struct mutex    var_lock;
403         struct delayed_work usb_detect_work;
404         int usb_cnt;
405         u32     fcc;
406         unsigned                ac_online:1;
407         unsigned                usb_online:1;
408         unsigned                chg_stat:3;
409 };
410
411 struct rt5025_chip {
412         struct i2c_client *i2c;
413         struct workqueue_struct *wq;
414         struct device *dev;
415         struct rt5025_power_info *power_info;
416         int suspend;
417         int irq;
418         struct delayed_work delayed_work;
419         struct mutex io_lock;
420 };
421
422 struct rt5025_platform_data {
423         struct regulator_init_data* regulator[RT5025_MAX_REGULATOR];
424         struct rt5025_power_data* power_data;
425         struct rt5025_gpio_data* gpio_data;
426         struct rt5025_misc_data* misc_data;
427         struct rt5025_irq_data* irq_data;
428         struct rt5025_event_callback *cb;
429         int (*pre_init)(struct rt5025_chip *rt5025_chip);
430         /** Called after subdevices are set up */
431         int (*post_init)(void);
432         int intr_pin;
433 };
434
435 #ifdef CONFIG_MFD_RT5025_MISC
436 extern void rt5025_power_off(void);
437 #endif /* CONFIG_MFD_RT5025_MISC */
438
439 #ifdef CONFIG_POWER_RT5025
440 extern int rt5025_gauge_init(struct rt5025_power_info *);
441 extern int rt5025_power_passirq_to_gauge(struct rt5025_power_info *);
442 extern int rt5025_power_charge_detect(struct rt5025_power_info *);
443 #endif /* CONFIG_POEWR_RT5025 */
444
445 extern int rt5025_reg_block_read(struct i2c_client *, int, int, void *);
446 extern int rt5025_reg_block_write(struct i2c_client *, int, int, void *);
447 extern int rt5025_reg_read(struct i2c_client *, int);
448 extern int rt5025_reg_write(struct i2c_client *, int, unsigned char);
449 extern int rt5025_assign_bits(struct i2c_client *, int, unsigned char, unsigned char);
450 extern int rt5025_set_bits(struct i2c_client *, int, unsigned char);
451 extern int rt5025_clr_bits(struct i2c_client *, int, unsigned char);
452
453 extern int rt5025_core_init(struct rt5025_chip *, struct rt5025_platform_data *);
454 extern int rt5025_core_deinit(struct rt5025_chip *);
455
456 #ifdef CONFIG_MFD_RT_SHOW_INFO
457 #define RTINFO(format, args...) \
458         printk(KERN_INFO "%s:%s() line-%d: " format, RT5025_DEVICE_NAME,__FUNCTION__,__LINE__, ##args)
459 #else
460 #define RTINFO(format,args...)
461 #endif /* CONFIG_MFD_RT_SHOW_INFO */
462
463 #endif /* __LINUX_MFD_RT5025_H */