• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 #ifndef _AXP2202_CHARGER_H_
2 #define _AXP2202_CHARGER_H_
3 
4 #include "linux/types.h"
5 
6 #define AXP2202_VBAT_MAX        (8000)
7 #define AXP2202_VBAT_MIN        (2000)
8 #define AXP2202_SOC_MAX         (100)
9 #define AXP2202_SOC_MIN         (0)
10 #define AXP2202_MAX_PARAM       512
11 #define AXP2202_MANUFACTURER  "xpower,axp2202"
12 
13 /* reg AXP2202_COMM_STAT0  */
14 #define AXP2202_MASK_VBUS_STAT        BIT(5)
15 #define AXP2202_MASK_BATFET_STAT      BIT(4)
16 #define AXP2202_MASK_BAT_STAT         BIT(3)
17 #define AXP2202_MASK_BAT_ACT_STAT     BIT(2)
18 #define AXP2202_MASK_THREM_STAT       BIT(1)
19 #define AXP2202_MASK_ILIM_STAT        BIT(0)
20 
21 /* reg AXP2202_COMM_FAULT  */
22 #define AXP2202_MASK_BAT_WOT          BIT(1)
23 #define AXP2202_MASK_BAT_WUT          BIT(0)
24 
25 /* reg AXP2202_RESET_CFG  */
26 #define AXP2202_MODE_RSTGAUGE        BIT(3)
27 #define AXP2202_MODE_RSTMCU          BIT(2)
28 #define AXP2202_MODE_POR             BIT(0)
29 
30 /* reg AXP2202_ROM_SEL  */
31 #define AXP2202_BROMUP_EN           BIT(0)
32 #define AXP2202_CFG_UPDATE_MARK     BIT(4)
33 #define AXP2202_CFG_WDT_EN          BIT(5)
34 
35 /* reg AXP2202_COMM_STAT1  */
36 #define AXP2202_STATUS_BAT_CUR_DIRCT GENMASK(6, 5)
37 #define AXP2202_CHARGING_TRI  (0)
38 #define AXP2202_CHARGING_PRE  (1)
39 #define AXP2202_CHARGING_CC   (2)
40 #define AXP2202_CHARGING_CV   (3)
41 #define AXP2202_CHARGING_DONE (4)
42 #define AXP2202_CHARGING_NCHG (5)
43 
44 /* reg AXP2202_ADC_CH_EN0  */
45 #define AXP2202_ADC_TS_SEL	(0x00)
46 #define AXP2202_ADC_TDIE_SEL	(0x01)
47 #define AXP2202_ADC_VMID_SEL	(0x02)
48 #define AXP2202_ADC_VBK_SEL	(0x03)
49 
50 /* reg AXP2202_VTERM_CFG  */
51 #define AXP2202_CHRG_TGT_VOLT		GENMASK(2, 0)
52 #define AXP2202_CHRG_CTRL1_TGT_4_0V	(0)
53 #define AXP2202_CHRG_CTRL1_TGT_4_1V	(1)
54 #define AXP2202_CHRG_CTRL1_TGT_4_2V	(2)
55 #define AXP2202_CHRG_CTRL1_TGT_4_35V	(3)
56 #define AXP2202_CHRG_CTRL1_TGT_4_4V	(4)
57 #define AXP2202_CHRG_CTRL1_TGT_5_0V	(7)
58 
59 /* reg AXP2202_TS_CFG  */
60 #define AXP2202_TS_ENABLE_MARK     BIT(4)
61 #define AXP2202_TS_CURR_MARK       BIT(0)
62 
63 /* reg AXP2202_JEITA_CFG  */
64 #define AXP2202_JEITA_ENABLE_MARK  BIT(0)
65 
66 /* reg AXP2202_ACIN_CC_OTG  */
67 #define AXP2202_OTG_MARK  (0x0F)
68 #define AXP2202_CHARGER_ENABLE_MARK BIT(1)
69 
70 struct axp2202_model_data {
71 	uint8_t *model;
72 	size_t model_size;
73 };
74 
75 
76 struct axp_config_info {
77 	u32 pmu_used;
78 	u32 pmu_id;
79 	u32 pmu_battery_rdc;
80 	u32 pmu_battery_cap;
81 	u32 pmu_batdeten;
82 	u32 pmu_button_bat_en;
83 	u32 pmu_chg_ic_temp;
84 	u32 pmu_runtime_chgcur;
85 	u32 pmu_suspend_chgcur;
86 	u32 pmu_shutdown_chgcur;
87 	u32 pmu_prechg_chgcur;
88 	u32 pmu_terminal_chgcur;
89 	u32 pmu_init_chgvol;
90 	u32 pmu_init_chgend_rate;
91 	u32 pmu_init_chg_enabled;
92 	u32 pmu_init_bc_en;
93 	u32 pmu_init_adc_freq;
94 	u32 pmu_init_adcts_freq;
95 	u32 pmu_init_chg_pretime;
96 	u32 pmu_init_chg_csttime;
97 	u32 pmu_batt_cap_correct;
98 	u32 pmu_chg_end_on_en;
99 	u32 ocv_coulumb_100;
100 
101 	u32 pmu_bat_ts_current;
102 
103 	u32 pmu_jetia_en;
104 	u32 pmu_jetia_cool;
105 	u32 pmu_jetia_warm;
106 	u32 pmu_jcool_ifall;
107 	u32 pmu_jwarm_ifall;
108 
109 	/* For Gauge2.0 */
110 	u32 pmu_bat_para1;
111 	u32 pmu_bat_para2;
112 	u32 pmu_bat_para3;
113 	u32 pmu_bat_para4;
114 	u32 pmu_bat_para5;
115 	u32 pmu_bat_para6;
116 	u32 pmu_bat_para7;
117 	u32 pmu_bat_para8;
118 	u32 pmu_bat_para9;
119 	u32 pmu_bat_para10;
120 	u32 pmu_bat_para11;
121 	u32 pmu_bat_para12;
122 	u32 pmu_bat_para13;
123 	u32 pmu_bat_para14;
124 	u32 pmu_bat_para15;
125 	u32 pmu_bat_para16;
126 	u32 pmu_bat_para17;
127 	u32 pmu_bat_para18;
128 	u32 pmu_bat_para19;
129 	u32 pmu_bat_para20;
130 	u32 pmu_bat_para21;
131 	u32 pmu_bat_para22;
132 	u32 pmu_bat_para23;
133 	u32 pmu_bat_para24;
134 	u32 pmu_bat_para25;
135 	u32 pmu_bat_para26;
136 	u32 pmu_bat_para27;
137 	u32 pmu_bat_para28;
138 	u32 pmu_bat_para29;
139 	u32 pmu_bat_para30;
140 	u32 pmu_bat_para31;
141 	u32 pmu_bat_para32;
142 
143 	u32 pmu_ac_vol;
144 	u32 pmu_ac_cur;
145 	u32 pmu_usbpc_vol;
146 	u32 pmu_usbpc_cur;
147 	u32 pmu_usbad_vol;
148 	u32 pmu_usbad_cur;
149 	u32 pmu_gpio_vol;
150 	u32 pmu_gpio_cur;
151 	u32 pmu_usb_typec_used;
152 	u32 pmu_pwroff_vol;
153 	u32 pmu_pwron_vol;
154 	u32 pmu_powkey_off_time;
155 	u32 pmu_powkey_off_en;
156 	u32 pmu_powkey_off_delay_time;
157 	u32 pmu_powkey_off_func;
158 	u32 pmu_powkey_long_time;
159 	u32 pmu_powkey_on_time;
160 	u32 pmu_powkey_wakeup_irq;
161 	u32 pmu_pwrok_time;
162 	u32 pmu_pwrnoe_time;
163 	u32 pmu_reset_shutdown_en;
164 	u32 pmu_battery_warning_level1;
165 	u32 pmu_battery_warning_level2;
166 	u32 pmu_restvol_adjust_time;
167 	u32 pmu_ocv_cou_adjust_time;
168 	u32 pmu_chgled_func;
169 	u32 pmu_chgled_type;
170 	u32 pmu_vbusen_func;
171 	u32 pmu_reset;
172 	u32 pmu_irq_wakeup;
173 	u32 pmu_hot_shutdown;
174 	u32 pmu_inshort;
175 	u32 power_start;
176 	u32 pmu_as_slave;
177 	u32 pmu_bat_unused;
178 	u32 pmu_ocv_en;
179 	u32 pmu_cou_en;
180 	u32 pmu_update_min_time;
181 
182 	u32 pmu_bat_temp_enable;
183 	u32 pmu_bat_charge_ltf;
184 	u32 pmu_bat_charge_htf;
185 	u32 pmu_bat_shutdown_ltf;
186 	u32 pmu_bat_shutdown_htf;
187 	u32 pmu_bat_temp_para1;
188 	u32 pmu_bat_temp_para2;
189 	u32 pmu_bat_temp_para3;
190 	u32 pmu_bat_temp_para4;
191 	u32 pmu_bat_temp_para5;
192 	u32 pmu_bat_temp_para6;
193 	u32 pmu_bat_temp_para7;
194 	u32 pmu_bat_temp_para8;
195 	u32 pmu_bat_temp_para9;
196 	u32 pmu_bat_temp_para10;
197 	u32 pmu_bat_temp_para11;
198 	u32 pmu_bat_temp_para12;
199 	u32 pmu_bat_temp_para13;
200 	u32 pmu_bat_temp_para14;
201 	u32 pmu_bat_temp_para15;
202 	u32 pmu_bat_temp_para16;
203 
204 	u32 wakeup_usb_in;
205 	u32 wakeup_usb_out;
206 	u32 wakeup_bat_in;
207 	u32 wakeup_bat_out;
208 	u32 wakeup_bat_charging;
209 	u32 wakeup_bat_charge_over;
210 	u32 wakeup_low_warning1;
211 	u32 wakeup_low_warning2;
212 	u32 wakeup_bat_untemp_work;
213 	u32 wakeup_bat_ovtemp_work;
214 	u32 wakeup_untemp_chg;
215 	u32 wakeup_ovtemp_chg;
216 	u32 wakeup_bat_ov;
217 	u32 wakeup_gpio;
218 
219 	u32 pmu_bc12_en;
220 	u32 pmu_cc_logic_en;
221 	u32 pmu_boost_en;
222 	u32 pmu_boost_vol;
223 };
224 
225 
226 
227 #define BATRDC          100
228 #define INTCHGCUR       300000      /* set initial charging current limite */
229 #define SUSCHGCUR       1000000     /* set suspend charging current limite */
230 #define RESCHGCUR       INTCHGCUR   /* set resume charging current limite */
231 #define CLSCHGCUR       SUSCHGCUR   /* set shutdown charging current limite */
232 #define INTCHGVOL       4200000     /* set initial charing target voltage */
233 #define INTCHGENDRATE   10          /* set initial charing end current rate */
234 #define INTCHGENABLED   1           /* set initial charing enabled */
235 #define INTADCFREQ      25          /* set initial adc frequency */
236 #define INTADCFREQC     100         /* set initial coulomb adc coufrequency */
237 #define INTCHGPRETIME   50          /* set initial pre-charging time */
238 #define INTCHGCSTTIME   480         /* set initial pre-charging time */
239 #define BATMAXVOL       4200000     /* set battery max design volatge */
240 #define BATMINVOL       3500000     /* set battery min design volatge */
241 #define UPDATEMINTIME   30          /* set bat percent update min time */
242 
243 #define AXP_OF_PROP_READ(name, def_value)\
244 do {\
245 	if (of_property_read_u32(node, #name, &axp_config->name))\
246 		axp_config->name = def_value;\
247 } while (0)
248 
249 struct axp_interrupts {
250 	char *name;
251 	irq_handler_t isr;
252 	int irq;
253 };
254 
255 #endif
256 
257