power: rk818: support rk818 battery driver
[firefly-linux-kernel-4.4.55.git] / drivers / power / rk818_battery.h
1 /*
2  * rk818_battery.h: fuel gauge driver structures
3  *
4  * Copyright (C) 2016 Rockchip Electronics Co., Ltd
5  * Author: chenjh <chenjh@rock-chips.com>
6  *
7  * This program is free software; you can redistribute it and/or modify it
8  * under the terms and conditions of the GNU General Public License,
9  * version 2, as published by the Free Software Foundation.
10  *
11  * This program is distributed in the hope it will be useful, but WITHOUT
12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
14  * more details.
15  */
16
17 #ifndef RK818_BATTERY
18 #define RK818_BATTERY
19
20 /* RK818_INT_STS_MSK_REG2 */
21 #define PLUG_IN_MSK             BIT(0)
22 #define PLUG_OUT_MSK            BIT(1)
23 #define CHRG_CVTLMT_INT_MSK     BIT(6)
24
25 /* RK818_TS_CTRL_REG */
26 #define GG_EN                   BIT(7)
27 #define ADC_CUR_EN              BIT(6)
28 #define ADC_TS1_EN              BIT(5)
29 #define ADC_TS2_EN              BIT(4)
30
31 /* RK818_GGCON */
32 #define OCV_SAMP_MIN_MSK        0x0c
33 #define OCV_SAMP_8MIN           (0x00 << 2)
34
35 #define ADC_CAL_MIN_MSK         0x30
36 #define ADC_CAL_8MIN            (0x00 << 4)
37 #define ADC_CUR_MODE            BIT(1)
38
39 /* RK818_GGSTS */
40 #define BAT_CON                 BIT(4)
41 #define RELAX_VOL1_UPD          BIT(3)
42 #define RELAX_VOL2_UPD          BIT(2)
43 #define RELAX_VOL12_UPD_MSK     (RELAX_VOL1_UPD | RELAX_VOL2_UPD)
44
45 /* RK818_SUP_STS_REG */
46 #define CHRG_STATUS_MSK         0x70
47 #define BAT_EXS                 BIT(7)
48 #define CHARGE_OFF              (0x0 << 4)
49 #define DEAD_CHARGE             (0x1 << 4)
50 #define TRICKLE_CHARGE          (0x2 << 4)
51 #define CC_OR_CV                (0x3 << 4)
52 #define CHARGE_FINISH           (0x4 << 4)
53 #define USB_OVER_VOL            (0x5 << 4)
54 #define BAT_TMP_ERR             (0x6 << 4)
55 #define TIMER_ERR               (0x7 << 4)
56 #define USB_VLIMIT_EN           BIT(3)
57 #define USB_CLIMIT_EN           BIT(2)
58 #define USB_EXIST               BIT(1)
59 #define USB_EFF                 BIT(0)
60
61 /* RK818_USB_CTRL_REG */
62 #define CHRG_CT_EN              BIT(7)
63 #define FINISH_CUR_MSK          0xc0
64 #define TEMP_105C               (0x02 << 2)
65 #define FINISH_100MA            (0x00 << 6)
66 #define FINISH_150MA            (0x01 << 6)
67 #define FINISH_200MA            (0x02 << 6)
68 #define FINISH_250MA            (0x03 << 6)
69
70 /* RK818_CHRG_CTRL_REG3 */
71 #define CHRG_TERM_MODE_MSK      BIT(5)
72 #define CHRG_TERM_ANA_SIGNAL    (0 << 5)
73 #define CHRG_TERM_DIG_SIGNAL    BIT(5)
74 #define CHRG_TIMER_CCCV_EN      BIT(2)
75 #define CHRG_EN                 BIT(7)
76
77 /* RK818_VB_MON_REG */
78 #define RK818_VBAT_LOW_3V0      0x02
79 #define RK818_VBAT_LOW_3V4      0x06
80 #define PLUG_IN_STS             BIT(6)
81
82 /* RK818_THERMAL_REG */
83 #define FB_TEMP_MSK             0x0c
84
85 /* RK818_INT_STS_MSK_REG1 */
86 #define VB_LOW_INT_EN           BIT(1)
87
88 /* RK818_MISC_MARK_REG */
89 #define FG_INIT                 BIT(5)
90 #define FG_RESET_LATE           BIT(4)
91 #define FG_RESET_NOW            BIT(3)
92 #define ALGO_REST_MODE_MSK      (0xc0)
93 #define ALGO_REST_MODE_SHIFT    6
94
95 /* bit shift */
96 #define FB_TEMP_SHIFT           2
97
98 /* parse ocv table param */
99 #define TIMER_MS_COUNTS         1000
100 #define MAX_PERCENTAGE          100
101 #define MAX_INTERPOLATE         1000
102 #define MAX_INT                 0x7FFF
103
104 #define DRIVER_VERSION          "7.0"
105
106 struct battery_platform_data {
107         u32 *ocv_table;
108         u32 *zero_table;
109         u32 *ntc_table;
110         u32 ocv_size;
111         u32 max_chrg_voltage;
112         u32 ntc_size;
113         int ntc_degree_from;
114         u32 pwroff_vol;
115         u32 monitor_sec;
116         u32 zero_algorithm_vol;
117         u32 bat_res;
118         u32 design_capacity;
119         u32 design_qmax;
120         u32 sleep_enter_current;
121         u32 sleep_exit_current;
122         u32 max_soc_offset;
123         u32 sample_res;
124         u32 bat_mode;
125         u32 fb_temp;
126         u32 energy_mode;
127         u32 cccv_hour;
128 };
129
130 enum work_mode {
131         MODE_ZERO = 0,
132         MODE_FINISH,
133         MODE_SMOOTH_CHRG,
134         MODE_SMOOTH_DISCHRG,
135         MODE_SMOOTH,
136 };
137
138 enum bat_mode {
139         MODE_BATTARY = 0,
140         MODE_VIRTUAL,
141 };
142
143 static const u16 feedback_temp_array[] = {
144         85, 95, 105, 115
145 };
146
147 static const u16 chrg_vol_sel_array[] = {
148         4050, 4100, 4150, 4200, 4250, 4300, 4350
149 };
150
151 static const u16 chrg_cur_sel_array[] = {
152         1000, 1200, 1400, 1600, 1800, 2000, 2250, 2400, 2600, 2800, 3000
153 };
154
155 static const u16 chrg_cur_input_array[] = {
156         450, 800, 850, 1000, 1250, 1500, 1750, 2000, 2250, 2500, 2750, 3000
157 };
158
159 void kernel_power_off(void);
160 void rk_send_wakeup_key(void);
161
162 #endif