xref: /OK3568_Linux_fs/kernel/drivers/power/supply/rk818_battery.h (revision 4882a59341e53eb6f0b4789bf948001014eff981)
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 #define TS1_CUR_MSK		0x03
31 
32 /* RK818_GGCON */
33 #define OCV_SAMP_MIN_MSK	0x0c
34 #define OCV_SAMP_8MIN		(0x00 << 2)
35 
36 #define ADC_CAL_MIN_MSK		0x30
37 #define ADC_CAL_8MIN		(0x00 << 4)
38 #define ADC_CUR_MODE		BIT(1)
39 
40 /* RK818_GGSTS */
41 #define BAT_CON			BIT(4)
42 #define RELAX_VOL1_UPD		BIT(3)
43 #define RELAX_VOL2_UPD		BIT(2)
44 #define RELAX_VOL12_UPD_MSK	(RELAX_VOL1_UPD | RELAX_VOL2_UPD)
45 
46 /* RK818_SUP_STS_REG */
47 #define CHRG_STATUS_MSK		0x70
48 #define BAT_EXS			BIT(7)
49 #define CHARGE_OFF		(0x0 << 4)
50 #define DEAD_CHARGE		(0x1 << 4)
51 #define TRICKLE_CHARGE		(0x2 << 4)
52 #define CC_OR_CV		(0x3 << 4)
53 #define CHARGE_FINISH		(0x4 << 4)
54 #define USB_OVER_VOL		(0x5 << 4)
55 #define BAT_TMP_ERR		(0x6 << 4)
56 #define TIMER_ERR		(0x7 << 4)
57 #define USB_VLIMIT_EN		BIT(3)
58 #define USB_CLIMIT_EN		BIT(2)
59 #define USB_EXIST		BIT(1)
60 #define USB_EFF			BIT(0)
61 
62 /* RK818_USB_CTRL_REG */
63 #define CHRG_CT_EN		BIT(7)
64 #define FINISH_CUR_MSK		0xc0
65 #define TEMP_105C		(0x02 << 2)
66 #define FINISH_100MA		(0x00 << 6)
67 #define FINISH_150MA		(0x01 << 6)
68 #define FINISH_200MA		(0x02 << 6)
69 #define FINISH_250MA		(0x03 << 6)
70 
71 /* RK818_CHRG_CTRL_REG3 */
72 #define CHRG_TERM_MODE_MSK	BIT(5)
73 #define CHRG_TERM_ANA_SIGNAL	(0 << 5)
74 #define CHRG_TERM_DIG_SIGNAL	BIT(5)
75 #define CHRG_TIMER_CCCV_EN	BIT(2)
76 #define CHRG_EN			BIT(7)
77 
78 /* RK818_VB_MON_REG */
79 #define	RK818_VBAT_LOW_3V0      0x02
80 #define	RK818_VBAT_LOW_3V4      0x06
81 #define PLUG_IN_STS		BIT(6)
82 
83 /* RK818_THERMAL_REG */
84 #define FB_TEMP_MSK		0x0c
85 #define HOTDIE_STS		BIT(1)
86 
87 /* RK818_INT_STS_MSK_REG1 */
88 #define VB_LOW_INT_EN		BIT(1)
89 
90 /* RK818_MISC_MARK_REG */
91 #define FG_INIT			BIT(5)
92 #define FG_RESET_LATE		BIT(4)
93 #define FG_RESET_NOW		BIT(3)
94 #define ALGO_REST_MODE_MSK	(0xc0)
95 #define ALGO_REST_MODE_SHIFT	6
96 
97 /* bit shift */
98 #define FB_TEMP_SHIFT		2
99 
100 /* parse ocv table param */
101 #define TIMER_MS_COUNTS		1000
102 #define MAX_PERCENTAGE		100
103 #define MAX_INTERPOLATE		1000
104 #define MAX_INT			0x7FFF
105 
106 #define DRIVER_VERSION		"7.1"
107 
108 struct battery_platform_data {
109 	u32 *ocv_table;
110 	u32 *zero_table;
111 	u32 *ntc_table;
112 	u32 ocv_size;
113 	u32 max_chrg_voltage;
114 	u32 ntc_size;
115 	int ntc_degree_from;
116 	u32 pwroff_vol;
117 	u32 monitor_sec;
118 	u32 zero_algorithm_vol;
119 	u32 zero_reserve_dsoc;
120 	u32 bat_res;
121 	u32 design_capacity;
122 	u32 design_qmax;
123 	u32 sleep_enter_current;
124 	u32 sleep_exit_current;
125 	u32 max_soc_offset;
126 	u32 sample_res;
127 	u32 bat_mode;
128 	u32 fb_temp;
129 	u32 energy_mode;
130 	u32 cccv_hour;
131 	u32 ntc_uA;
132 	u32 ntc_factor;
133 };
134 
135 enum work_mode {
136 	MODE_ZERO = 0,
137 	MODE_FINISH,
138 	MODE_SMOOTH_CHRG,
139 	MODE_SMOOTH_DISCHRG,
140 	MODE_SMOOTH,
141 };
142 
143 enum bat_mode {
144 	MODE_BATTARY = 0,
145 	MODE_VIRTUAL,
146 };
147 
148 static const u16 feedback_temp_array[] = {
149 	85, 95, 105, 115
150 };
151 
152 static const u16 chrg_vol_sel_array[] = {
153 	4050, 4100, 4150, 4200, 4250, 4300, 4350
154 };
155 
156 static const u16 chrg_cur_sel_array[] = {
157 	1000, 1200, 1400, 1600, 1800, 2000, 2250, 2400, 2600, 2800, 3000
158 };
159 
160 static const u16 chrg_cur_input_array[] = {
161 	450, 80, 850, 1000, 1250, 1500, 1750, 2000, 2250, 2500, 2750, 3000
162 };
163 
164 void kernel_power_off(void);
165 int rk818_bat_temp_notifier_register(struct notifier_block *nb);
166 int rk818_bat_temp_notifier_unregister(struct notifier_block *nb);
167 
168 #endif
169