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