blob: f98b224853fb91933bbb7c199b683c05b19e460d [file] [log] [blame]
xjb04a4022021-11-25 15:01:52 +08001/* SPDX-License-Identifier: GPL-2.0 */
2/*
3 * Copyright (c) 2019 MediaTek Inc.
4 */
5
6#ifndef __RT9467_CHARGER_H
7#define __RT9467_CHARGER_H
8
9#define RT9467_SLAVE_ADDR 0x5B
10#define RT9467_VENDOR_ID 0x90
11#define RT9467_CHIP_REV_E1 0x01
12#define RT9467_CHIP_REV_E2 0x02
13#define RT9467_CHIP_REV_E3 0x03
14#define RT9467_CHIP_REV_E4 0x04
15
16enum rt9467_reg_addr {
17 RT9467_REG_CORE_CTRL0,
18 RT9467_REG_CHG_CTRL1,
19 RT9467_REG_CHG_CTRL2,
20 RT9467_REG_CHG_CTRL3,
21 RT9467_REG_CHG_CTRL4,
22 RT9467_REG_CHG_CTRL5,
23 RT9467_REG_CHG_CTRL6,
24 RT9467_REG_CHG_CTRL7,
25 RT9467_REG_CHG_CTRL8,
26 RT9467_REG_CHG_CTRL9,
27 RT9467_REG_CHG_CTRL10,
28 RT9467_REG_CHG_CTRL11,
29 RT9467_REG_CHG_CTRL12,
30 RT9467_REG_CHG_CTRL13,
31 RT9467_REG_CHG_CTRL14,
32 RT9467_REG_CHG_CTRL15,
33 RT9467_REG_CHG_CTRL16,
34 RT9467_REG_CHG_ADC,
35 RT9467_REG_CHG_DPDM1,
36 RT9467_REG_CHG_DPDM2,
37 RT9467_REG_CHG_DPDM3,
38 RT9467_REG_CHG_CTRL19 = 0x18,
39 RT9467_REG_CHG_CTRL17,
40 RT9467_REG_CHG_CTRL18,
41 RT9467_REG_CHG_HIDDEN_CTRL1 = 0x20,
42 RT9467_REG_CHG_HIDDEN_CTRL2,
43 RT9467_REG_CHG_HIDDEN_CTRL4 = 0x23,
44 RT9467_REG_CHG_HIDDEN_CTRL6 = 0x25,
45 RT9467_REG_CHG_HIDDEN_CTRL7,
46 RT9467_REG_CHG_HIDDEN_CTRL8,
47 RT9467_REG_CHG_HIDDEN_CTRL9,
48 RT9467_REG_CHG_HIDDEN_CTRL15 = 0x2E,
49 RT9467_REG_DEVICE_ID = 0x40,
50 RT9467_REG_CHG_STAT = 0x42,
51 RT9467_REG_CHG_NTC,
52 RT9467_REG_ADC_DATA_H,
53 RT9467_REG_ADC_DATA_L,
54 RT9467_REG_ADC_DATA_TUNE_H,
55 RT9467_REG_ADC_DATA_TUNE_L,
56 RT9467_REG_ADC_DATA_ORG_H,
57 RT9467_REG_ADC_DATA_ORG_L,
58 RT9467_REG_CHG_STATC = 0x50,
59 RT9467_REG_CHG_FAULT,
60 RT9467_REG_TS_STATC,
61 RT9467_REG_CHG_IRQ1,
62 RT9467_REG_CHG_IRQ2,
63 RT9467_REG_CHG_IRQ3,
64 RT9467_REG_DPDM_IRQ,
65 RT9467_REG_CHG_STATC_CTRL = 0x60,
66 RT9467_REG_CHG_FAULT_CTRL,
67 RT9467_REG_TS_STATC_CTRL,
68 RT9467_REG_CHG_IRQ1_CTRL,
69 RT9467_REG_CHG_IRQ2_CTRL,
70 RT9467_REG_CHG_IRQ3_CTRL,
71 RT9467_REG_DPDM_IRQ_CTRL,
72 RT9467_REG_MAX,
73};
74
75/* =========================== */
76/* RT9467 Parameter */
77/* =========================== */
78
79/* uA */
80#define RT9467_ICHG_NUM 64
81#define RT9467_ICHG_MIN 100000
82#define RT9467_ICHG_MAX 5000000
83#define RT9467_ICHG_STEP 100000
84
85/* uA */
86#define RT9467_IEOC_NUM 16
87#define RT9467_IEOC_MIN 100000
88#define RT9467_IEOC_MAX 850000
89#define RT9467_IEOC_STEP 50000
90
91/* uV */
92#define RT9467_MIVR_NUM 128
93#define RT9467_MIVR_MIN 3900000
94#define RT9467_MIVR_MAX 13400000
95#define RT9467_MIVR_STEP 100000
96
97/* uA */
98#define RT9467_AICR_NUM 64
99#define RT9467_AICR_MIN 100000
100#define RT9467_AICR_MAX 3250000
101#define RT9467_AICR_STEP 50000
102
103/* uV */
104#define RT9467_CV_NUM 128
105#define RT9467_CV_MIN 3900000
106#define RT9467_CV_MAX 4710000
107#define RT9467_CV_STEP 10000
108
109/* uV */
110#define RT9467_BOOST_VOREG_NUM 64
111#define RT9467_BOOST_VOREG_MIN 4425000
112#define RT9467_BOOST_VOREG_MAX 5825000
113#define RT9467_BOOST_VOREG_STEP 25000
114
115/* uV */
116#define RT9467_VPREC_NUM 16
117#define RT9467_VPREC_MIN 2000000
118#define RT9467_VPREC_MAX 3500000
119#define RT9467_VPREC_STEP 100000
120
121/* uA */
122#define RT9467_IPREC_NUM 16
123#define RT9467_IPREC_MIN 100000
124#define RT9467_IPREC_MAX 850000
125#define RT9467_IPREC_STEP 50000
126
127/* IR compensation */
128/* uohm */
129#define RT9467_IRCMP_RES_NUM 8
130#define RT9467_IRCMP_RES_MIN 0
131#define RT9467_IRCMP_RES_MAX 175000
132#define RT9467_IRCMP_RES_STEP 25000
133
134/* IR compensation maximum voltage clamp */
135/* uV */
136#define RT9467_IRCMP_VCLAMP_NUM 8
137#define RT9467_IRCMP_VCLAMP_MIN 0
138#define RT9467_IRCMP_VCLAMP_MAX 224000
139#define RT9467_IRCMP_VCLAMP_STEP 32000
140
141/* PE+20 voltage */
142/* uV */
143#define RT9467_PEP20_VOLT_NUM 19
144#define RT9467_PEP20_VOLT_MIN 5500000
145#define RT9467_PEP20_VOLT_MAX 14500000
146#define RT9467_PEP20_VOLT_STEP 500000
147
148/* IIN VTH */
149/* uV */
150#define RT9467_AICL_VTH_NUM 8
151#define RT9467_AICL_VTH_MIN 4100000
152#define RT9467_AICL_VTH_MAX 4800000
153#define RT9467_AICL_VTH_STEP 100000
154
155/* ADC unit/offset */
156#define RT9467_ADC_UNIT_VBUS_DIV5 25000 /* uV */
157#define RT9467_ADC_UNIT_VBUS_DIV2 10000 /* uV */
158#define RT9467_ADC_UNIT_VBAT 5000 /* uV */
159#define RT9467_ADC_UNIT_VSYS 5000 /* uV */
160#define RT9467_ADC_UNIT_REGN 5000 /* uV */
161#define RT9467_ADC_UNIT_TS_BAT 25 /* 0.01% */
162#define RT9467_ADC_UNIT_IBUS 50000 /* uA */
163#define RT9467_ADC_UNIT_IBAT 50000 /* uA */
164#define RT9467_ADC_UNIT_TEMP_JC 2 /* degree */
165
166#define RT9467_ADC_OFFSET_VBUS_DIV5 0 /* uV */
167#define RT9467_ADC_OFFSET_VBUS_DIV2 0 /* uV */
168#define RT9467_ADC_OFFSET_VBAT 0 /* uV */
169#define RT9467_ADC_OFFSET_VSYS 0 /* uV */
170#define RT9467_ADC_OFFSET_REGN 0 /* uV */
171#define RT9467_ADC_OFFSET_TS_BAT 0 /* % */
172#define RT9467_ADC_OFFSET_IBUS 0 /* uA */
173#define RT9467_ADC_OFFSET_IBAT 0 /* uA */
174#define RT9467_ADC_OFFSET_TEMP_JC (-40) /* degree */
175
176
177/* ========== CORE_CTRL0 0x00 ============ */
178#define RT9467_SHIFT_RST 7
179#define RT9467_MASK_RST (1 << RT9467_SHIFT_RST)
180
181/* ========== CHG_CTRL1 0x01 ============ */
182#define RT9467_SHIFT_OPA_MODE 0
183#define RT9467_SHIFT_HZ_EN 2
184#define RT9467_SHIFT_IRQ_PULSE 3
185
186#define RT9467_MASK_OPA_MODE (1 << RT9467_SHIFT_OPA_MODE)
187#define RT9467_MASK_HZ_EN (1 << RT9467_SHIFT_HZ_EN)
188#define RT9467_MASK_IRQ_PULSE (1 << RT9467_SHIFT_IRQ_PULSE)
189
190/* ========== CHG_CTRL2 0x02 ============ */
191#define RT9467_SHIFT_CHG_EN 0
192#define RT9467_SHIFT_CFO_EN 1
193#define RT9467_SHIFT_IINLMTSEL 2
194#define RT9467_SHIFT_TE_EN 4
195#define RT9467_SHIFT_SHIP_MODE 7
196
197#define RT9467_MASK_CHG_EN (1 << RT9467_SHIFT_CHG_EN)
198#define RT9467_MASK_CFO_EN (1 << RT9467_SHIFT_CFO_EN)
199#define RT9467_MASK_IINLMTSEL 0x0C
200#define RT9467_MASK_TE_EN (1 << RT9467_SHIFT_TE_EN)
201#define RT9467_MASK_SHIP_MODE (1 << RT9467_SHIFT_SHIP_MODE)
202
203/* ========== CHG_CTRL3 0x03 ============ */
204#define RT9467_SHIFT_AICR 2
205#define RT9467_SHIFT_AICR_EN 1
206#define RT9467_SHIFT_ILIM_EN 0
207
208#define RT9467_MASK_AICR 0xFC
209#define RT9467_MASK_AICR_EN (1 << RT9467_SHIFT_AICR_EN)
210#define RT9467_MASK_ILIM_EN (1 << RT9467_SHIFT_ILIM_EN)
211
212/* ========== CHG_CTRL4 0x04 ============ */
213#define RT9467_SHIFT_CV 1
214
215#define RT9467_MASK_CV 0xFE
216
217/* ========== CHG_CTRL5 0x05 ============ */
218#define RT9467_SHIFT_BOOST_VOREG 2
219
220#define RT9467_MASK_BOOST_VOREG 0xFC
221
222/* ========== CHG_CTRL6 0x06 ============ */
223#define RT9467_SHIFT_MIVR 1
224#define RT9467_SHIFT_MIVR_EN 0
225
226#define RT9467_MASK_MIVR 0xFE
227#define RT9467_MASK_MIVR_EN (1 << RT9467_SHIFT_MIVR_EN)
228
229/* ========== CHG_CTRL7 0x07 ============ */
230#define RT9467_SHIFT_ICHG 2
231
232#define RT9467_MASK_ICHG 0xFC
233
234/* ========== CHG_CTRL8 0x08 ============ */
235#define RT9467_SHIFT_VPREC 4
236#define RT9467_SHIFT_IPREC 0
237
238#define RT9467_MASK_VPREC 0xF0
239#define RT9467_MASK_IPREC 0x0F
240
241/* ========== CHG_CTRL9 0x09 ============ */
242#define RT9467_SHIFT_IEOC 4
243
244#define RT9467_MASK_IEOC 0xF0
245
246/* ========== CHG_CTRL10 0x0A ============ */
247#define RT9467_SHIFT_BOOST_OC 0
248
249#define RT9467_MASK_BOOST_OC 0x07
250
251/* ========== CHG_CTRL12 0x0C ============ */
252#define RT9467_SHIFT_TMR_EN 1
253#define RT9467_SHIFT_WT_FC 5
254
255#define RT9467_MASK_TMR_EN (1 << RT9467_SHIFT_TMR_EN)
256#define RT9467_MASK_WT_FC 0xE0
257
258/* ========== CHG_CTRL13 0x0D ============ */
259#define RT9467_SHIFT_WDT_EN 7
260#define RT9467_SHIFT_IRQ_REZ 0
261#define RT9467_SHIFT_OCP 2
262
263#define RT9467_MASK_WDT_EN (1 << RT9467_SHIFT_WDT_EN)
264#define RT9467_MASK_IRQ_REZ (1 << RT9467_SHIFT_IRQ_REZ)
265#define RT9467_MASK_OCP (1 << RT9467_SHIFT_OCP)
266
267/* ========== CHG_CTRL14 0x0E ============ */
268#define RT9467_SHIFT_AICL_MEAS 7
269#define RT9467_SHIFT_AICL_VTH 0
270
271#define RT9467_MASK_AICL_MEAS (1 << RT9467_SHIFT_AICL_MEAS)
272#define RT9467_MASK_AICL_VTH 0x07
273
274/* ========== CHG_CTRL16 0x10 ============ */
275#define RT9467_SHIFT_JEITA_EN 4
276
277#define RT9467_MASK_JEITA_EN (1 << RT9467_SHIFT_JEITA_EN)
278
279/* ========== CHG_ADC 0x11 ============ */
280#define RT9467_SHIFT_ADC_IN_SEL 4
281#define RT9467_SHIFT_ADC_START 0
282
283#define RT9467_MASK_ADC_IN_SEL 0xF0
284#define RT9467_MASK_ADC_START (1 << RT9467_SHIFT_ADC_START)
285
286/* ========== CHG_DPDM1 0x12 ============ */
287#define RT9467_SHIFT_USBCHGEN 7
288
289#define RT9467_MASK_USBCHGEN (1 << RT9467_SHIFT_USBCHGEN)
290
291/* ========== CHG_DPDM2 0x13 ============ */
292#define RT9467_SHIFT_USB_STATUS 0
293
294#define RT9467_MASK_USB_STATUS 0x07
295
296/* ========== CHG_CTRL17 0x19 ============ */
297#define RT9467_SHIFT_PUMPX_EN 7
298#define RT9467_SHIFT_PUMPX_20_10 6 /* Version of PE */
299#define RT9467_SHIFT_PUMPX_UP_DN 5
300#define RT9467_SHIFT_PUMPX_DEC 0
301
302
303#define RT9467_MASK_PUMPX_EN (1 << RT9467_SHIFT_PUMPX_EN)
304#define RT9467_MASK_PUMPX_20_10 (1 << RT9467_SHIFT_PUMPX_20_10)
305#define RT9467_MASK_PUMPX_UP_DN (1 << RT9467_SHIFT_PUMPX_UP_DN)
306#define RT9467_MASK_PUMPX_DEC 0x1F
307
308/* ========== CHG_CTRL18 0x1A ============ */
309#define RT9467_SHIFT_IRCMP_RES 3
310#define RT9467_SHIFT_IRCMP_VCLAMP 0
311
312#define RT9467_MASK_IRCMP_RES 0x38
313#define RT9467_MASK_IRCMP_VCLAMP 0x07
314
315/* ========== CHG_STAT 0x42 ============ */
316#define RT9467_SHIFT_ADC_STAT 0
317#define RT9467_SHIFT_CHG_STAT 6
318
319#define RT9467_MASK_ADC_STAT (1 << RT9467_SHIFT_ADC_STAT)
320#define RT9467_MASK_CHG_STAT 0xC0
321
322/* ========== CHG_STATC 0x50 ============ */
323#define RT9467_SHIFT_PWR_RDY 7
324#define RT9467_SHIFT_CHG_MIVR 6
325#define RT9467_SHIFT_CHG_AICR 5
326
327#define RT9467_MASK_PWR_RDY (1 << RT9467_SHIFT_PWR_RDY)
328#define RT9467_MASK_CHG_MIVR (1 << RT9467_SHIFT_CHG_MIVR)
329#define RT9467_MASK_CHG_AICR (1 << RT9467_SHIFT_CHG_AICR)
330
331/* ========== CHG_FAULT 0x51 ============ */
332#define RT9467_SHIFT_VBUSOV 7
333
334#define RT9467_MASK_VBUSOV (1 << RT9467_SHIFT_VBUSOV)
335
336/* ========== CHG_IRQ2 0x54 ============ */
337#define RT9467_SHIFT_CHG_AICLMEASI 0
338#define RT9467_SHIFT_WDTMRI 3
339#define RT9467_SHIFT_SSFINISHI 4
340
341#define RT9467_MASK_CHG_AICLMEASI (1 << RT9467_SHIFT_CHG_AICLMEASI)
342#define RT9467_MASK_WDTMRI (1 << RT9467_SHIFT_WDTMRI)
343#define RT9467_MASK_SSFINISHI (1 << RT9467_SHIFT_SSFINISHI)
344
345/* ========== CHG_IRQ3 0x55 ============ */
346#define RT9467_SHIFT_ADC_DONEI 0
347#define RT9467_SHIFT_PUMPX_DONEI 1
348
349#define RT9467_MASK_ADC_DONEI (1 << RT9467_SHIFT_ADC_DONEI)
350#define RT9467_MASK_PUMPX_DONEI (1 << RT9467_SHIFT_PUMPX_DONEI)
351
352/* ========== DPDM_IRQ 0x56 ============ */
353#define RT9467_SHIFT_ATTACHI 0
354
355#define RT9467_MASK_ATTACHI (1 << RT9467_SHIFT_ATTACHI)
356
357/* ========== CHG_STATC_CTRL 0x60 ============ */
358#define RT9467_SHIFT_PWR_RDYM 7
359#define RT9467_SHIFT_CHG_MIVRM 6
360#define RT9467_SHIFT_CHG_AICRM 5
361
362#define RT9467_MASK_PWR_RDYM (1 << RT9467_SHIFT_PWR_RDYM)
363#define RT9467_MASK_CHG_MIVRM (1 << RT9467_SHIFT_CHG_MIVRM)
364#define RT9467_MASK_CHG_AICRM (1 << RT9467_SHIFT_CHG_AICRM)
365
366/* ========== CHG_FAULT_CTRL 0x61 ============ */
367#define RT9467_SHIFT_VBUSOVM 7
368
369#define RT9467_MASK_VBUSOVM (1 << RT9467_SHIFT_VBUSOVM)
370
371/* ========== CHG_TS_STATC_CTRL 0x62 ============ */
372#define RT9467_SHIFT_TS_BAT_HOTM 7
373#define RT9467_SHIFT_TS_BAT_WARMM 6
374#define RT9467_SHIFT_TS_BAT_COOLM 5
375#define RT9467_SHIFT_TS_BAT_COLDM 4
376
377#define RT9467_MASK_TS_BAT_HOTM (1 << RT9467_SHIFT_TS_BAT_HOTM)
378#define RT9467_MASK_TS_BAT_WARMM (1 << RT9467_SHIFT_TS_BAT_WARMM)
379#define RT9467_MASK_TS_BAT_COOLM (1 << RT9467_SHIFT_TS_BAT_COOLM)
380#define RT9467_MASK_TS_BAT_COLDM (1 << RT9467_SHIFT_TS_BAT_COLDM)
381#define RT9467_MASK_TS_STATC_RESERVED 0x0F
382
383/* ========== CHG_IRQ1_CTRL 0x63 ============ */
384#define RT9467_SHIFT_CHG_OTPM 7
385#define RT9467_SHIFT_CHG_RVPM 6
386#define RT9467_SHIFT_CHG_ADPBADM 5
387#define RT9467_SHIFT_CHG_STATCM 2
388#define RT9467_SHIFT_CHG_FAULTM 1
389#define RT9467_SHIFT_TS_STATCM 0
390
391#define RT9467_MASK_CHG_OTPM (1 << RT9467_SHIFT_CHG_OTPM)
392#define RT9467_MASK_CHG_RVPM (1 << RT9467_SHIFT_CHG_RVPM)
393#define RT9467_MASK_CHG_ADPBADM (1 << RT9467_SHIFT_CHG_ADPBADM)
394#define RT9467_MASK_CHG_STATCM (1 << RT9467_SHIFT_CHG_STATCM)
395#define RT9467_MASK_CHG_FAULTM (1 << RT9467_SHIFT_CHG_FAULTM)
396#define RT9467_MASK_TS_STATCM (1 << RT9467_SHIFT_TS_STATCM)
397
398/* ========== CHG_IRQ2_CTRL 0x64 ============ */
399#define RT9467_SHIFT_IEOCM 7
400#define RT9467_SHIFT_TERMM 6
401#define RT9467_SHIFT_SSFINISHM 4
402#define RT9467_SHIFT_CHG_AICLMEASM 0
403
404#define RT9467_MASK_IEOCM (1 << RT9467_SHIFT_IEOCM)
405#define RT9467_MASK_TERMM (1 << RT9467_SHIFT_TERMM)
406#define RT9467_MASK_SSFINISHM (1 << RT9467_SHIFT_SSFINISHM)
407#define RT9467_MASK_CHG_AICLMEASM (1 << RT9467_SHIFT_CHG_AICLMEASM)
408#define RT9467_MASK_IRQ2_RESERVED 0x04
409
410/* ========== CHG_IRQ3_CTRL 0x65 ============ */
411#define RT9467_SHIFT_BST_BATUVM 5
412#define RT9467_SHIFT_PUMPX_DONEM 1
413#define RT9467_SHIFT_ADC_DONEM 0
414
415#define RT9467_MASK_BST_BATUVM (1 << RT9467_SHIFT_BST_BATUVM)
416#define RT9467_MASK_PUMPX_DONEM (1 << RT9467_SHIFT_PUMPX_DONEM)
417#define RT9467_MASK_ADC_DONEM (1 << RT9467_SHIFT_ADC_DONEM)
418#define RT9467_MASK_IRQ3_RESERVED 0x1C
419
420/* ========== DPDM_IRQ_CTRL 0x66 ============ */
421#define RT9467_SHIFT_DCDTM 7
422#define RT9467_SHIFT_CHGDETM 6
423#define RT9467_SHIFT_HVDCP_DETM 5
424#define RT9467_SHIFT_DETACHM 1
425#define RT9467_SHIFT_ATTACHM 0
426
427#define RT9467_MASK_DCDTM (1 << RT9467_SHIFT_DCDTM)
428#define RT9467_MASK_CHGDETM (1 << RT9467_SHIFT_CHGDETM)
429#define RT9467_MASK_HVDCP_DETM (1 << RT9467_SHIFT_HVDCP_DETM)
430#define RT9467_MASK_DETACHM (1 << RT9467_SHIFT_DETACHM)
431#define RT9467_MASK_ATTACHM (1 << RT9467_SHIFT_ATTACHM)
432#define RT9467_MASK_DPDMIRQ_RESERVED 0x1C
433
434
435#endif /* __RT9467_CHARGER_H */