1
2
3#ifndef _AB8500_CHARGER_H_
4#define _AB8500_CHARGER_H_
5
6#include <linux/kernel.h>
7
8
9
10
11
12#define AB8500_MAIN_WDOG_CTRL_REG 0x01
13#define AB8500_LOW_BAT_REG 0x03
14#define AB8500_BATT_OK_REG 0x04
15
16
17
18
19#define AB8500_USB_LINE_STAT_REG 0x80
20#define AB8500_USB_LINE_CTRL2_REG 0x82
21#define AB8500_USB_LINK1_STAT_REG 0x94
22
23
24
25
26
27#define AB8500_CH_STATUS1_REG 0x00
28#define AB8500_CH_STATUS2_REG 0x01
29#define AB8500_CH_USBCH_STAT1_REG 0x02
30#define AB8500_CH_USBCH_STAT2_REG 0x03
31#define AB8540_CH_USBCH_STAT3_REG 0x04
32#define AB8500_CH_STAT_REG 0x05
33
34
35
36
37
38#define AB8500_CH_VOLT_LVL_REG 0x40
39#define AB8500_CH_VOLT_LVL_MAX_REG 0x41
40#define AB8500_CH_OPT_CRNTLVL_REG 0x42
41#define AB8500_CH_OPT_CRNTLVL_MAX_REG 0x43
42#define AB8500_CH_WD_TIMER_REG 0x50
43#define AB8500_CHARG_WD_CTRL 0x51
44#define AB8500_BTEMP_HIGH_TH 0x52
45#define AB8500_LED_INDICATOR_PWM_CTRL 0x53
46#define AB8500_LED_INDICATOR_PWM_DUTY 0x54
47#define AB8500_BATT_OVV 0x55
48#define AB8500_CHARGER_CTRL 0x56
49#define AB8500_BAT_CTRL_CURRENT_SOURCE 0x60
50
51
52
53
54
55#define AB8500_MCH_CTRL1 0x80
56#define AB8500_MCH_CTRL2 0x81
57#define AB8500_MCH_IPT_CURLVL_REG 0x82
58#define AB8500_CH_WD_REG 0x83
59
60
61
62
63
64#define AB8500_USBCH_CTRL1_REG 0xC0
65#define AB8500_USBCH_CTRL2_REG 0xC1
66#define AB8500_USBCH_IPT_CRNTLVL_REG 0xC2
67#define AB8540_USB_PP_MODE_REG 0xC5
68#define AB8540_USB_PP_CHR_REG 0xC6
69
70
71
72
73
74#define AB8500_GASG_CC_CTRL_REG 0x00
75#define AB8500_GASG_CC_ACCU1_REG 0x01
76#define AB8500_GASG_CC_ACCU2_REG 0x02
77#define AB8500_GASG_CC_ACCU3_REG 0x03
78#define AB8500_GASG_CC_ACCU4_REG 0x04
79#define AB8500_GASG_CC_SMPL_CNTRL_REG 0x05
80#define AB8500_GASG_CC_SMPL_CNTRH_REG 0x06
81#define AB8500_GASG_CC_SMPL_CNVL_REG 0x07
82#define AB8500_GASG_CC_SMPL_CNVH_REG 0x08
83#define AB8500_GASG_CC_CNTR_AVGOFF_REG 0x09
84#define AB8500_GASG_CC_OFFSET_REG 0x0A
85#define AB8500_GASG_CC_NCOV_ACCU 0x10
86#define AB8500_GASG_CC_NCOV_ACCU_CTRL 0x11
87#define AB8500_GASG_CC_NCOV_ACCU_LOW 0x12
88#define AB8500_GASG_CC_NCOV_ACCU_MED 0x13
89#define AB8500_GASG_CC_NCOV_ACCU_HIGH 0x14
90
91
92
93
94
95#define AB8500_IT_SOURCE2_REG 0x01
96#define AB8500_IT_SOURCE21_REG 0x14
97
98
99
100
101
102#define AB8500_RTC_BACKUP_CHG_REG 0x0C
103#define AB8500_RTC_CC_CONF_REG 0x01
104#define AB8500_RTC_CTRL_REG 0x0B
105#define AB8500_RTC_CTRL1_REG 0x11
106
107
108
109
110
111#define AB8500_OTP_CONF_15 0x0E
112
113
114#define ADC_RESOLUTION 1024
115#define ADC_CH_MAIN_MIN 0
116#define ADC_CH_MAIN_MAX 20030
117#define ADC_CH_VBUS_MIN 0
118#define ADC_CH_VBUS_MAX 20030
119#define ADC_CH_VBAT_MIN 2300
120#define ADC_CH_VBAT_MAX 4800
121#define ADC_CH_BKBAT_MIN 0
122#define ADC_CH_BKBAT_MAX 3200
123
124
125#define MAIN_CH_IP_CUR_0P9A 0x80
126#define MAIN_CH_IP_CUR_1P0A 0x90
127#define MAIN_CH_IP_CUR_1P1A 0xA0
128#define MAIN_CH_IP_CUR_1P2A 0xB0
129#define MAIN_CH_IP_CUR_1P3A 0xC0
130#define MAIN_CH_IP_CUR_1P4A 0xD0
131#define MAIN_CH_IP_CUR_1P5A 0xE0
132
133
134#define CH_VOL_LVL_3P5 0x00
135#define CH_VOL_LVL_4P0 0x14
136#define CH_VOL_LVL_4P05 0x16
137#define CH_VOL_LVL_4P1 0x1B
138#define CH_VOL_LVL_4P15 0x20
139#define CH_VOL_LVL_4P2 0x25
140#define CH_VOL_LVL_4P6 0x4D
141
142
143#define CH_OP_CUR_LVL_0P1 0x00
144#define CH_OP_CUR_LVL_0P2 0x01
145#define CH_OP_CUR_LVL_0P3 0x02
146#define CH_OP_CUR_LVL_0P4 0x03
147#define CH_OP_CUR_LVL_0P5 0x04
148#define CH_OP_CUR_LVL_0P6 0x05
149#define CH_OP_CUR_LVL_0P7 0x06
150#define CH_OP_CUR_LVL_0P8 0x07
151#define CH_OP_CUR_LVL_0P9 0x08
152#define CH_OP_CUR_LVL_1P4 0x0D
153#define CH_OP_CUR_LVL_1P5 0x0E
154#define CH_OP_CUR_LVL_1P6 0x0F
155#define CH_OP_CUR_LVL_2P 0x3F
156
157
158#define BTEMP_HIGH_TH_57_0 0x00
159#define BTEMP_HIGH_TH_52 0x01
160#define BTEMP_HIGH_TH_57_1 0x02
161#define BTEMP_HIGH_TH_62 0x03
162
163
164#define USB_0P1A 100
165#define USB_0P2A 200
166#define USB_0P3A 300
167#define USB_0P4A 400
168#define USB_0P5A 500
169
170#define LOW_BAT_3P1V 0x20
171#define LOW_BAT_2P3V 0x00
172#define LOW_BAT_RESET 0x01
173#define LOW_BAT_ENABLE 0x01
174
175
176#define BUP_ICH_SEL_50UA 0x00
177#define BUP_ICH_SEL_150UA 0x04
178#define BUP_ICH_SEL_300UA 0x08
179#define BUP_ICH_SEL_700UA 0x0C
180
181enum bup_vch_sel {
182 BUP_VCH_SEL_2P5V,
183 BUP_VCH_SEL_2P6V,
184 BUP_VCH_SEL_2P8V,
185 BUP_VCH_SEL_3P1V,
186
187
188
189
190
191 BUP_VCH_SEL_2P7V,
192 BUP_VCH_SEL_2P9V,
193 BUP_VCH_SEL_3P0V,
194 BUP_VCH_SEL_3P2V,
195 BUP_VCH_SEL_3P3V,
196};
197
198#define BUP_VCH_RANGE 0x02
199#define VBUP33_VRTCN 0x01
200
201
202#define BATT_OVV_ENA 0x02
203#define BATT_OVV_TH_3P7 0x00
204#define BATT_OVV_TH_4P75 0x01
205
206
207#define BATT_OVV_VALUE 4750
208
209
210#define VBUS_OVV_SELECT_MASK 0x78
211#define VBUS_OVV_SELECT_5P6V 0x00
212#define VBUS_OVV_SELECT_5P7V 0x08
213#define VBUS_OVV_SELECT_5P8V 0x10
214#define VBUS_OVV_SELECT_5P9V 0x18
215#define VBUS_OVV_SELECT_6P0V 0x20
216#define VBUS_OVV_SELECT_6P1V 0x28
217#define VBUS_OVV_SELECT_6P2V 0x30
218#define VBUS_OVV_SELECT_6P3V 0x38
219
220#define VBUS_AUTO_IN_CURR_LIM_ENA 0x04
221
222
223#define RESET_ACCU 0x02
224#define READ_REQ 0x01
225#define CC_DEEP_SLEEP_ENA 0x02
226#define CC_PWR_UP_ENA 0x01
227#define CC_SAMPLES_40 0x28
228#define RD_NCONV_ACCU_REQ 0x01
229#define CC_CALIB 0x08
230#define CC_INTAVGOFFSET_ENA 0x10
231#define CC_MUXOFFSET 0x80
232#define CC_INT_CAL_N_AVG_MASK 0x60
233#define CC_INT_CAL_SAMPLES_16 0x40
234#define CC_INT_CAL_SAMPLES_8 0x20
235#define CC_INT_CAL_SAMPLES_4 0x00
236
237
238#define RTC_BUP_CH_ENA 0x10
239
240
241#define BAT_CTRL_7U_ENA 0x01
242#define BAT_CTRL_20U_ENA 0x02
243#define BAT_CTRL_18U_ENA 0x01
244#define BAT_CTRL_16U_ENA 0x02
245#define BAT_CTRL_CMP_ENA 0x04
246#define FORCE_BAT_CTRL_CMP_HIGH 0x08
247#define BAT_CTRL_PULL_UP_ENA 0x10
248
249
250#define BATTERY_UNKNOWN 00
251
252
253#define AB8505_RTC_PCUT_CTL_STATUS_REG 0x12
254#define AB8505_RTC_PCUT_TIME_REG 0x13
255#define AB8505_RTC_PCUT_MAX_TIME_REG 0x14
256#define AB8505_RTC_PCUT_FLAG_TIME_REG 0x15
257#define AB8505_RTC_PCUT_RESTART_REG 0x16
258#define AB8505_RTC_PCUT_DEBOUNCE_REG 0x17
259
260
261#define BUS_VSYS_VOL_SELECT_MASK 0x06
262#define BUS_VSYS_VOL_SELECT_3P6V 0x00
263#define BUS_VSYS_VOL_SELECT_3P325V 0x02
264#define BUS_VSYS_VOL_SELECT_3P9V 0x04
265#define BUS_VSYS_VOL_SELECT_4P3V 0x06
266#define BUS_POWER_PATH_MODE_ENA 0x01
267#define BUS_PP_PRECHG_CURRENT_MASK 0x0E
268#define BUS_POWER_PATH_PRECHG_ENA 0x01
269
270
271
272
273
274
275
276
277enum abx500_adc_therm {
278 ABx500_ADC_THERM_BATCTRL,
279 ABx500_ADC_THERM_BATTEMP,
280};
281
282
283
284
285
286
287
288
289struct abx500_res_to_temp {
290 int temp;
291 int resist;
292};
293
294
295
296
297
298
299struct abx500_v_to_cap {
300 int voltage;
301 int capacity;
302};
303
304
305struct abx500_fg;
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336struct abx500_fg_parameters {
337 int recovery_sleep_timer;
338 int recovery_total_time;
339 int init_timer;
340 int init_discard_time;
341 int init_total_time;
342 int high_curr_time;
343 int accu_charging;
344 int accu_high_curr;
345 int high_curr_threshold;
346 int lowbat_threshold;
347 int overbat_threshold;
348 int battok_falling_th_sel0;
349 int battok_raising_th_sel1;
350 int user_cap_limit;
351 int maint_thres;
352 bool pcut_enable;
353 u8 pcut_max_time;
354 u8 pcut_flag_time;
355 u8 pcut_max_restart;
356 u8 pcut_debounce_time;
357};
358
359
360
361
362
363
364
365
366struct abx500_maxim_parameters {
367 bool ena_maxi;
368 int chg_curr;
369 int wait_cycles;
370 int charger_curr_step;
371};
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403struct abx500_battery_type {
404 int name;
405 int resis_high;
406 int resis_low;
407 int charge_full_design;
408 int nominal_voltage;
409 int termination_vol;
410 int termination_curr;
411 int recharge_cap;
412 int normal_cur_lvl;
413 int normal_vol_lvl;
414 int maint_a_cur_lvl;
415 int maint_a_vol_lvl;
416 int maint_a_chg_timer_h;
417 int maint_b_cur_lvl;
418 int maint_b_vol_lvl;
419 int maint_b_chg_timer_h;
420 int low_high_cur_lvl;
421 int low_high_vol_lvl;
422 int battery_resistance;
423 int n_temp_tbl_elements;
424 const struct abx500_res_to_temp *r_to_t_tbl;
425 int n_v_cap_tbl_elements;
426 const struct abx500_v_to_cap *v_to_cap_tbl;
427 int n_batres_tbl_elements;
428 const struct batres_vs_temp *batres_tbl;
429};
430
431
432
433
434
435
436
437
438
439struct abx500_bm_capacity_levels {
440 int critical;
441 int low;
442 int normal;
443 int high;
444 int full;
445};
446
447
448
449
450
451
452
453
454struct abx500_bm_charger_parameters {
455 int usb_volt_max;
456 int usb_curr_max;
457 int ac_volt_max;
458 int ac_curr_max;
459};
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497struct abx500_bm_data {
498 int temp_under;
499 int temp_low;
500 int temp_high;
501 int temp_over;
502 int temp_now;
503 int temp_interval_chg;
504 int temp_interval_nochg;
505 int main_safety_tmr_h;
506 int usb_safety_tmr_h;
507 int bkup_bat_v;
508 int bkup_bat_i;
509 bool autopower_cfg;
510 bool ac_enabled;
511 bool usb_enabled;
512 bool no_maintenance;
513 bool capacity_scaling;
514 bool chg_unknown_bat;
515 bool enable_overshoot;
516 bool auto_trig;
517 enum abx500_adc_therm adc_therm;
518 int fg_res;
519 int n_btypes;
520 int batt_id;
521 int interval_charging;
522 int interval_not_charging;
523 int temp_hysteresis;
524 int gnd_lift_resistance;
525 int n_chg_out_curr;
526 int n_chg_in_curr;
527 int *chg_output_curr;
528 int *chg_input_curr;
529 const struct abx500_maxim_parameters *maxi;
530 const struct abx500_bm_capacity_levels *cap_levels;
531 struct abx500_battery_type *bat_type;
532 const struct abx500_bm_charger_parameters *chg_params;
533 const struct abx500_fg_parameters *fg_params;
534};
535
536enum {
537 NTC_EXTERNAL = 0,
538 NTC_INTERNAL,
539};
540
541
542
543
544
545
546
547
548struct res_to_temp {
549 int temp;
550 int resist;
551};
552
553
554
555
556
557
558
559struct batres_vs_temp {
560 int temp;
561 int resist;
562};
563
564
565struct ab8500_fg;
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595struct ab8500_fg_parameters {
596 int recovery_sleep_timer;
597 int recovery_total_time;
598 int init_timer;
599 int init_discard_time;
600 int init_total_time;
601 int high_curr_time;
602 int accu_charging;
603 int accu_high_curr;
604 int high_curr_threshold;
605 int lowbat_threshold;
606 int battok_falling_th_sel0;
607 int battok_raising_th_sel1;
608 int user_cap_limit;
609 int maint_thres;
610 bool pcut_enable;
611 u8 pcut_max_time;
612 u8 pcut_flag_time;
613 u8 pcut_max_restart;
614 u8 pcut_debunce_time;
615};
616
617
618
619
620
621
622
623
624struct ab8500_maxim_parameters {
625 bool ena_maxi;
626 int chg_curr;
627 int wait_cycles;
628 int charger_curr_step;
629};
630
631
632
633
634
635
636
637
638
639struct ab8500_bm_capacity_levels {
640 int critical;
641 int low;
642 int normal;
643 int high;
644 int full;
645};
646
647
648
649
650
651
652
653
654struct ab8500_bm_charger_parameters {
655 int usb_volt_max;
656 int usb_curr_max;
657 int ac_volt_max;
658 int ac_curr_max;
659};
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691struct ab8500_bm_data {
692 int temp_under;
693 int temp_low;
694 int temp_high;
695 int temp_over;
696 int temp_interval_chg;
697 int temp_interval_nochg;
698 int main_safety_tmr_h;
699 int usb_safety_tmr_h;
700 int bkup_bat_v;
701 int bkup_bat_i;
702 bool no_maintenance;
703 bool capacity_scaling;
704 bool chg_unknown_bat;
705 bool enable_overshoot;
706 enum abx500_adc_therm adc_therm;
707 int fg_res;
708 int n_btypes;
709 int batt_id;
710 int interval_charging;
711 int interval_not_charging;
712 int temp_hysteresis;
713 int gnd_lift_resistance;
714 const struct ab8500_maxim_parameters *maxi;
715 const struct ab8500_bm_capacity_levels *cap_levels;
716 const struct ab8500_bm_charger_parameters *chg_params;
717 const struct ab8500_fg_parameters *fg_params;
718};
719
720extern struct abx500_bm_data ab8500_bm_data;
721
722void ab8500_charger_usb_state_changed(u8 bm_usb_state, u16 mA);
723struct ab8500_fg *ab8500_fg_get(void);
724int ab8500_fg_inst_curr_blocking(struct ab8500_fg *dev);
725int ab8500_fg_inst_curr_start(struct ab8500_fg *di);
726int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res);
727int ab8500_fg_inst_curr_started(struct ab8500_fg *di);
728int ab8500_fg_inst_curr_done(struct ab8500_fg *di);
729int ab8500_bm_of_probe(struct device *dev,
730 struct device_node *np,
731 struct abx500_bm_data *bm);
732
733#endif
734