blob: 4b7342c54b414892619233bfd86fcbff184b8576 [file] [log] [blame]
Arun Murthy84edbee2012-02-29 21:54:26 +05301/*
2 * Copyright ST-Ericsson 2012.
3 *
4 * Author: Arun Murthy <arun.murthy@stericsson.com>
5 * Licensed under GPLv2.
6 */
7
8#ifndef _AB8500_BM_H
9#define _AB8500_BM_H
10
11#include <linux/kernel.h>
12
13/*
14 * System control 2 register offsets.
15 * bank = 0x02
16 */
17#define AB8500_MAIN_WDOG_CTRL_REG 0x01
18#define AB8500_LOW_BAT_REG 0x03
19#define AB8500_BATT_OK_REG 0x04
20/*
21 * USB/ULPI register offsets
22 * Bank : 0x5
23 */
24#define AB8500_USB_LINE_STAT_REG 0x80
25
26/*
27 * Charger / status register offfsets
28 * Bank : 0x0B
29 */
30#define AB8500_CH_STATUS1_REG 0x00
31#define AB8500_CH_STATUS2_REG 0x01
32#define AB8500_CH_USBCH_STAT1_REG 0x02
33#define AB8500_CH_USBCH_STAT2_REG 0x03
34#define AB8500_CH_FSM_STAT_REG 0x04
35#define AB8500_CH_STAT_REG 0x05
36
37/*
38 * Charger / control register offfsets
39 * Bank : 0x0B
40 */
41#define AB8500_CH_VOLT_LVL_REG 0x40
42#define AB8500_CH_VOLT_LVL_MAX_REG 0x41 /*Only in Cut2.0*/
43#define AB8500_CH_OPT_CRNTLVL_REG 0x42
44#define AB8500_CH_OPT_CRNTLVL_MAX_REG 0x43 /*Only in Cut2.0*/
45#define AB8500_CH_WD_TIMER_REG 0x50
46#define AB8500_CHARG_WD_CTRL 0x51
47#define AB8500_BTEMP_HIGH_TH 0x52
48#define AB8500_LED_INDICATOR_PWM_CTRL 0x53
49#define AB8500_LED_INDICATOR_PWM_DUTY 0x54
50#define AB8500_BATT_OVV 0x55
51#define AB8500_CHARGER_CTRL 0x56
52#define AB8500_BAT_CTRL_CURRENT_SOURCE 0x60 /*Only in Cut2.0*/
53
54/*
55 * Charger / main control register offsets
56 * Bank : 0x0B
57 */
58#define AB8500_MCH_CTRL1 0x80
59#define AB8500_MCH_CTRL2 0x81
60#define AB8500_MCH_IPT_CURLVL_REG 0x82
61#define AB8500_CH_WD_REG 0x83
62
63/*
64 * Charger / USB control register offsets
65 * Bank : 0x0B
66 */
67#define AB8500_USBCH_CTRL1_REG 0xC0
68#define AB8500_USBCH_CTRL2_REG 0xC1
69#define AB8500_USBCH_IPT_CRNTLVL_REG 0xC2
70
71/*
72 * Gas Gauge register offsets
73 * Bank : 0x0C
74 */
75#define AB8500_GASG_CC_CTRL_REG 0x00
76#define AB8500_GASG_CC_ACCU1_REG 0x01
77#define AB8500_GASG_CC_ACCU2_REG 0x02
78#define AB8500_GASG_CC_ACCU3_REG 0x03
79#define AB8500_GASG_CC_ACCU4_REG 0x04
80#define AB8500_GASG_CC_SMPL_CNTRL_REG 0x05
81#define AB8500_GASG_CC_SMPL_CNTRH_REG 0x06
82#define AB8500_GASG_CC_SMPL_CNVL_REG 0x07
83#define AB8500_GASG_CC_SMPL_CNVH_REG 0x08
84#define AB8500_GASG_CC_CNTR_AVGOFF_REG 0x09
85#define AB8500_GASG_CC_OFFSET_REG 0x0A
86#define AB8500_GASG_CC_NCOV_ACCU 0x10
87#define AB8500_GASG_CC_NCOV_ACCU_CTRL 0x11
88#define AB8500_GASG_CC_NCOV_ACCU_LOW 0x12
89#define AB8500_GASG_CC_NCOV_ACCU_MED 0x13
90#define AB8500_GASG_CC_NCOV_ACCU_HIGH 0x14
91
92/*
93 * Interrupt register offsets
94 * Bank : 0x0E
95 */
96#define AB8500_IT_SOURCE2_REG 0x01
97#define AB8500_IT_SOURCE21_REG 0x14
98
99/*
100 * RTC register offsets
101 * Bank: 0x0F
102 */
103#define AB8500_RTC_BACKUP_CHG_REG 0x0C
104#define AB8500_RTC_CC_CONF_REG 0x01
105#define AB8500_RTC_CTRL_REG 0x0B
106
107/*
108 * OTP register offsets
109 * Bank : 0x15
110 */
111#define AB8500_OTP_CONF_15 0x0E
112
113/* GPADC constants from AB8500 spec, UM0836 */
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/* Main charge i/p current */
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/* ChVoltLevel */
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/* ChOutputCurrentLevel */
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
156/* BTEMP High thermal limits */
157#define BTEMP_HIGH_TH_57_0 0x00
158#define BTEMP_HIGH_TH_52 0x01
159#define BTEMP_HIGH_TH_57_1 0x02
160#define BTEMP_HIGH_TH_62 0x03
161
162/* current is mA */
163#define USB_0P1A 100
164#define USB_0P2A 200
165#define USB_0P3A 300
166#define USB_0P4A 400
167#define USB_0P5A 500
168
169#define LOW_BAT_3P1V 0x20
170#define LOW_BAT_2P3V 0x00
171#define LOW_BAT_RESET 0x01
172#define LOW_BAT_ENABLE 0x01
173
174/* Backup battery constants */
175#define BUP_ICH_SEL_50UA 0x00
176#define BUP_ICH_SEL_150UA 0x04
177#define BUP_ICH_SEL_300UA 0x08
178#define BUP_ICH_SEL_700UA 0x0C
179
180#define BUP_VCH_SEL_2P5V 0x00
181#define BUP_VCH_SEL_2P6V 0x01
182#define BUP_VCH_SEL_2P8V 0x02
183#define BUP_VCH_SEL_3P1V 0x03
184
185/* Battery OVV constants */
186#define BATT_OVV_ENA 0x02
187#define BATT_OVV_TH_3P7 0x00
188#define BATT_OVV_TH_4P75 0x01
189
190/* A value to indicate over voltage */
191#define BATT_OVV_VALUE 4750
192
193/* VBUS OVV constants */
194#define VBUS_OVV_SELECT_MASK 0x78
195#define VBUS_OVV_SELECT_5P6V 0x00
196#define VBUS_OVV_SELECT_5P7V 0x08
197#define VBUS_OVV_SELECT_5P8V 0x10
198#define VBUS_OVV_SELECT_5P9V 0x18
199#define VBUS_OVV_SELECT_6P0V 0x20
200#define VBUS_OVV_SELECT_6P1V 0x28
201#define VBUS_OVV_SELECT_6P2V 0x30
202#define VBUS_OVV_SELECT_6P3V 0x38
203
204#define VBUS_AUTO_IN_CURR_LIM_ENA 0x04
205
206/* Fuel Gauge constants */
207#define RESET_ACCU 0x02
208#define READ_REQ 0x01
209#define CC_DEEP_SLEEP_ENA 0x02
210#define CC_PWR_UP_ENA 0x01
211#define CC_SAMPLES_40 0x28
212#define RD_NCONV_ACCU_REQ 0x01
213#define CC_CALIB 0x08
214#define CC_INTAVGOFFSET_ENA 0x10
215#define CC_MUXOFFSET 0x80
216#define CC_INT_CAL_N_AVG_MASK 0x60
217#define CC_INT_CAL_SAMPLES_16 0x40
218#define CC_INT_CAL_SAMPLES_8 0x20
219#define CC_INT_CAL_SAMPLES_4 0x00
220
221/* RTC constants */
222#define RTC_BUP_CH_ENA 0x10
223
224/* BatCtrl Current Source Constants */
225#define BAT_CTRL_7U_ENA 0x01
226#define BAT_CTRL_20U_ENA 0x02
227#define BAT_CTRL_CMP_ENA 0x04
228#define FORCE_BAT_CTRL_CMP_HIGH 0x08
229#define BAT_CTRL_PULL_UP_ENA 0x10
230
231/* Battery type */
232#define BATTERY_UNKNOWN 00
233
234/*
235 * ADC for the battery thermistor.
236 * When using the ADC_THERM_BATCTRL the battery ID resistor is combined with
237 * a NTC resistor to both identify the battery and to measure its temperature.
238 * Different phone manufactures uses different techniques to both identify the
239 * battery and to read its temperature.
240 */
241enum adc_therm {
242 ADC_THERM_BATCTRL,
243 ADC_THERM_BATTEMP,
244};
245
246/**
247 * struct res_to_temp - defines one point in a temp to res curve. To
248 * be used in battery packs that combines the identification resistor with a
249 * NTC resistor.
250 * @temp: battery pack temperature in Celcius
251 * @resist: NTC resistor net total resistance
252 */
253struct res_to_temp {
254 int temp;
255 int resist;
256};
257
258/**
259 * struct batres_vs_temp - defines one point in a temp vs battery internal
260 * resistance curve.
261 * @temp: battery pack temperature in Celcius
262 * @resist: battery internal reistance in mOhm
263 */
264struct batres_vs_temp {
265 int temp;
266 int resist;
267};
268
269/**
270 * struct v_to_cap - Table for translating voltage to capacity
271 * @voltage: Voltage in mV
272 * @capacity: Capacity in percent
273 */
274struct v_to_cap {
275 int voltage;
276 int capacity;
277};
278
279/* Forward declaration */
280struct ab8500_fg;
281
282/**
283 * struct ab8500_fg_parameters - Fuel gauge algorithm parameters, in seconds
284 * if not specified
285 * @recovery_sleep_timer: Time between measurements while recovering
286 * @recovery_total_time: Total recovery time
287 * @init_timer: Measurement interval during startup
288 * @init_discard_time: Time we discard voltage measurement at startup
289 * @init_total_time: Total init time during startup
290 * @high_curr_time: Time current has to be high to go to recovery
291 * @accu_charging: FG accumulation time while charging
292 * @accu_high_curr: FG accumulation time in high current mode
293 * @high_curr_threshold: High current threshold, in mA
294 * @lowbat_threshold: Low battery threshold, in mV
295 * @battok_falling_th_sel0 Threshold in mV for battOk signal sel0
296 * Resolution in 50 mV step.
297 * @battok_raising_th_sel1 Threshold in mV for battOk signal sel1
298 * Resolution in 50 mV step.
299 * @user_cap_limit Capacity reported from user must be within this
300 * limit to be considered as sane, in percentage
301 * points.
302 * @maint_thres This is the threshold where we stop reporting
303 * battery full while in maintenance, in per cent
304 */
305struct ab8500_fg_parameters {
306 int recovery_sleep_timer;
307 int recovery_total_time;
308 int init_timer;
309 int init_discard_time;
310 int init_total_time;
311 int high_curr_time;
312 int accu_charging;
313 int accu_high_curr;
314 int high_curr_threshold;
315 int lowbat_threshold;
316 int battok_falling_th_sel0;
317 int battok_raising_th_sel1;
318 int user_cap_limit;
319 int maint_thres;
320};
321
322/**
323 * struct ab8500_charger_maximization - struct used by the board config.
324 * @use_maxi: Enable maximization for this battery type
325 * @maxi_chg_curr: Maximum charger current allowed
326 * @maxi_wait_cycles: cycles to wait before setting charger current
327 * @charger_curr_step delta between two charger current settings (mA)
328 */
329struct ab8500_maxim_parameters {
330 bool ena_maxi;
331 int chg_curr;
332 int wait_cycles;
333 int charger_curr_step;
334};
335
336/**
337 * struct battery_type - different batteries supported
338 * @name: battery technology
339 * @resis_high: battery upper resistance limit
340 * @resis_low: battery lower resistance limit
341 * @charge_full_design: Maximum battery capacity in mAh
342 * @nominal_voltage: Nominal voltage of the battery in mV
343 * @termination_vol: max voltage upto which battery can be charged
344 * @termination_curr battery charging termination current in mA
345 * @recharge_vol battery voltage limit that will trigger a new
346 * full charging cycle in the case where maintenan-
347 * -ce charging has been disabled
348 * @normal_cur_lvl: charger current in normal state in mA
349 * @normal_vol_lvl: charger voltage in normal state in mV
350 * @maint_a_cur_lvl: charger current in maintenance A state in mA
351 * @maint_a_vol_lvl: charger voltage in maintenance A state in mV
352 * @maint_a_chg_timer_h: charge time in maintenance A state
353 * @maint_b_cur_lvl: charger current in maintenance B state in mA
354 * @maint_b_vol_lvl: charger voltage in maintenance B state in mV
355 * @maint_b_chg_timer_h: charge time in maintenance B state
356 * @low_high_cur_lvl: charger current in temp low/high state in mA
357 * @low_high_vol_lvl: charger voltage in temp low/high state in mV'
358 * @battery_resistance: battery inner resistance in mOhm.
359 * @n_r_t_tbl_elements: number of elements in r_to_t_tbl
360 * @r_to_t_tbl: table containing resistance to temp points
361 * @n_v_cap_tbl_elements: number of elements in v_to_cap_tbl
362 * @v_to_cap_tbl: Voltage to capacity (in %) table
363 * @n_batres_tbl_elements number of elements in the batres_tbl
364 * @batres_tbl battery internal resistance vs temperature table
365 */
366struct battery_type {
367 int name;
368 int resis_high;
369 int resis_low;
370 int charge_full_design;
371 int nominal_voltage;
372 int termination_vol;
373 int termination_curr;
374 int recharge_vol;
375 int normal_cur_lvl;
376 int normal_vol_lvl;
377 int maint_a_cur_lvl;
378 int maint_a_vol_lvl;
379 int maint_a_chg_timer_h;
380 int maint_b_cur_lvl;
381 int maint_b_vol_lvl;
382 int maint_b_chg_timer_h;
383 int low_high_cur_lvl;
384 int low_high_vol_lvl;
385 int battery_resistance;
386 int n_temp_tbl_elements;
387 struct res_to_temp *r_to_t_tbl;
388 int n_v_cap_tbl_elements;
389 struct v_to_cap *v_to_cap_tbl;
390 int n_batres_tbl_elements;
391 struct batres_vs_temp *batres_tbl;
392};
393
394/**
395 * struct ab8500_bm_capacity_levels - ab8500 capacity level data
396 * @critical: critical capacity level in percent
397 * @low: low capacity level in percent
398 * @normal: normal capacity level in percent
399 * @high: high capacity level in percent
400 * @full: full capacity level in percent
401 */
402struct ab8500_bm_capacity_levels {
403 int critical;
404 int low;
405 int normal;
406 int high;
407 int full;
408};
409
410/**
411 * struct ab8500_bm_charger_parameters - Charger specific parameters
412 * @usb_volt_max: maximum allowed USB charger voltage in mV
413 * @usb_curr_max: maximum allowed USB charger current in mA
414 * @ac_volt_max: maximum allowed AC charger voltage in mV
415 * @ac_curr_max: maximum allowed AC charger current in mA
416 */
417struct ab8500_bm_charger_parameters {
418 int usb_volt_max;
419 int usb_curr_max;
420 int ac_volt_max;
421 int ac_curr_max;
422};
423
424/**
425 * struct ab8500_bm_data - ab8500 battery management data
426 * @temp_under under this temp, charging is stopped
427 * @temp_low between this temp and temp_under charging is reduced
428 * @temp_high between this temp and temp_over charging is reduced
429 * @temp_over over this temp, charging is stopped
430 * @temp_interval_chg temperature measurement interval in s when charging
431 * @temp_interval_nochg temperature measurement interval in s when not charging
432 * @main_safety_tmr_h safety timer for main charger
433 * @usb_safety_tmr_h safety timer for usb charger
434 * @bkup_bat_v voltage which we charge the backup battery with
435 * @bkup_bat_i current which we charge the backup battery with
436 * @no_maintenance indicates that maintenance charging is disabled
437 * @adc_therm placement of thermistor, batctrl or battemp adc
438 * @chg_unknown_bat flag to enable charging of unknown batteries
439 * @enable_overshoot flag to enable VBAT overshoot control
440 * @fg_res resistance of FG resistor in 0.1mOhm
441 * @n_btypes number of elements in array bat_type
442 * @batt_id index of the identified battery in array bat_type
443 * @interval_charging charge alg cycle period time when charging (sec)
444 * @interval_not_charging charge alg cycle period time when not charging (sec)
445 * @temp_hysteresis temperature hysteresis
446 * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
447 * @maxi: maximization parameters
448 * @cap_levels capacity in percent for the different capacity levels
449 * @bat_type table of supported battery types
450 * @chg_params charger parameters
451 * @fg_params fuel gauge parameters
452 */
453struct ab8500_bm_data {
454 int temp_under;
455 int temp_low;
456 int temp_high;
457 int temp_over;
458 int temp_interval_chg;
459 int temp_interval_nochg;
460 int main_safety_tmr_h;
461 int usb_safety_tmr_h;
462 int bkup_bat_v;
463 int bkup_bat_i;
464 bool no_maintenance;
465 bool chg_unknown_bat;
466 bool enable_overshoot;
467 enum adc_therm adc_therm;
468 int fg_res;
469 int n_btypes;
470 int batt_id;
471 int interval_charging;
472 int interval_not_charging;
473 int temp_hysteresis;
474 int gnd_lift_resistance;
475 const struct ab8500_maxim_parameters *maxi;
476 const struct ab8500_bm_capacity_levels *cap_levels;
477 const struct battery_type *bat_type;
478 const struct ab8500_bm_charger_parameters *chg_params;
479 const struct ab8500_fg_parameters *fg_params;
480};
481
482struct ab8500_charger_platform_data {
483 char **supplied_to;
484 size_t num_supplicants;
485 bool autopower_cfg;
486};
487
488struct ab8500_btemp_platform_data {
489 char **supplied_to;
490 size_t num_supplicants;
491};
492
493struct ab8500_fg_platform_data {
494 char **supplied_to;
495 size_t num_supplicants;
496};
497
498struct ab8500_chargalg_platform_data {
499 char **supplied_to;
500 size_t num_supplicants;
501};
502struct ab8500_btemp;
503struct ab8500_gpadc;
504struct ab8500_fg;
505#ifdef CONFIG_AB8500_BM
506void ab8500_fg_reinit(void);
507void ab8500_charger_usb_state_changed(u8 bm_usb_state, u16 mA);
508struct ab8500_btemp *ab8500_btemp_get(void);
509int ab8500_btemp_get_batctrl_temp(struct ab8500_btemp *btemp);
510struct ab8500_fg *ab8500_fg_get(void);
511int ab8500_fg_inst_curr_blocking(struct ab8500_fg *dev);
512int ab8500_fg_inst_curr_start(struct ab8500_fg *di);
513int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res);
514int ab8500_fg_inst_curr_done(struct ab8500_fg *di);
515
516#else
517int ab8500_fg_inst_curr_done(struct ab8500_fg *di)
518{
519}
520static void ab8500_fg_reinit(void)
521{
522}
523static void ab8500_charger_usb_state_changed(u8 bm_usb_state, u16 mA)
524{
525}
526static struct ab8500_btemp *ab8500_btemp_get(void)
527{
528 return NULL;
529}
530static int ab8500_btemp_get_batctrl_temp(struct ab8500_btemp *btemp)
531{
532 return 0;
533}
534struct ab8500_fg *ab8500_fg_get(void)
535{
536 return NULL;
537}
538static int ab8500_fg_inst_curr_blocking(struct ab8500_fg *dev)
539{
540 return -ENODEV;
541}
542
543static inline int ab8500_fg_inst_curr_start(struct ab8500_fg *di)
544{
545 return -ENODEV;
546}
547
548static inline int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res)
549{
550 return -ENODEV;
551}
552
553#endif
554#endif /* _AB8500_BM_H */