blob: a03d4fdf9c2c1fe26f06c4305fd231914570185a [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
Hakan Berg74a8e342013-01-11 13:12:58 +000026#define AB8500_USB_LINK1_STAT_REG 0x94
Arun Murthy84edbee2012-02-29 21:54:26 +053027
28/*
29 * Charger / status register offfsets
30 * Bank : 0x0B
31 */
32#define AB8500_CH_STATUS1_REG 0x00
33#define AB8500_CH_STATUS2_REG 0x01
34#define AB8500_CH_USBCH_STAT1_REG 0x02
35#define AB8500_CH_USBCH_STAT2_REG 0x03
36#define AB8500_CH_FSM_STAT_REG 0x04
37#define AB8500_CH_STAT_REG 0x05
38
39/*
40 * Charger / control register offfsets
41 * Bank : 0x0B
42 */
43#define AB8500_CH_VOLT_LVL_REG 0x40
44#define AB8500_CH_VOLT_LVL_MAX_REG 0x41 /*Only in Cut2.0*/
45#define AB8500_CH_OPT_CRNTLVL_REG 0x42
46#define AB8500_CH_OPT_CRNTLVL_MAX_REG 0x43 /*Only in Cut2.0*/
47#define AB8500_CH_WD_TIMER_REG 0x50
48#define AB8500_CHARG_WD_CTRL 0x51
49#define AB8500_BTEMP_HIGH_TH 0x52
50#define AB8500_LED_INDICATOR_PWM_CTRL 0x53
51#define AB8500_LED_INDICATOR_PWM_DUTY 0x54
52#define AB8500_BATT_OVV 0x55
53#define AB8500_CHARGER_CTRL 0x56
54#define AB8500_BAT_CTRL_CURRENT_SOURCE 0x60 /*Only in Cut2.0*/
55
56/*
57 * Charger / main control register offsets
58 * Bank : 0x0B
59 */
60#define AB8500_MCH_CTRL1 0x80
61#define AB8500_MCH_CTRL2 0x81
62#define AB8500_MCH_IPT_CURLVL_REG 0x82
63#define AB8500_CH_WD_REG 0x83
64
65/*
66 * Charger / USB control register offsets
67 * Bank : 0x0B
68 */
69#define AB8500_USBCH_CTRL1_REG 0xC0
70#define AB8500_USBCH_CTRL2_REG 0xC1
71#define AB8500_USBCH_IPT_CRNTLVL_REG 0xC2
72
73/*
74 * Gas Gauge register offsets
75 * Bank : 0x0C
76 */
77#define AB8500_GASG_CC_CTRL_REG 0x00
78#define AB8500_GASG_CC_ACCU1_REG 0x01
79#define AB8500_GASG_CC_ACCU2_REG 0x02
80#define AB8500_GASG_CC_ACCU3_REG 0x03
81#define AB8500_GASG_CC_ACCU4_REG 0x04
82#define AB8500_GASG_CC_SMPL_CNTRL_REG 0x05
83#define AB8500_GASG_CC_SMPL_CNTRH_REG 0x06
84#define AB8500_GASG_CC_SMPL_CNVL_REG 0x07
85#define AB8500_GASG_CC_SMPL_CNVH_REG 0x08
86#define AB8500_GASG_CC_CNTR_AVGOFF_REG 0x09
87#define AB8500_GASG_CC_OFFSET_REG 0x0A
88#define AB8500_GASG_CC_NCOV_ACCU 0x10
89#define AB8500_GASG_CC_NCOV_ACCU_CTRL 0x11
90#define AB8500_GASG_CC_NCOV_ACCU_LOW 0x12
91#define AB8500_GASG_CC_NCOV_ACCU_MED 0x13
92#define AB8500_GASG_CC_NCOV_ACCU_HIGH 0x14
93
94/*
95 * Interrupt register offsets
96 * Bank : 0x0E
97 */
98#define AB8500_IT_SOURCE2_REG 0x01
99#define AB8500_IT_SOURCE21_REG 0x14
100
101/*
102 * RTC register offsets
103 * Bank: 0x0F
104 */
105#define AB8500_RTC_BACKUP_CHG_REG 0x0C
106#define AB8500_RTC_CC_CONF_REG 0x01
107#define AB8500_RTC_CTRL_REG 0x0B
108
109/*
110 * OTP register offsets
111 * Bank : 0x15
112 */
113#define AB8500_OTP_CONF_15 0x0E
114
115/* GPADC constants from AB8500 spec, UM0836 */
116#define ADC_RESOLUTION 1024
117#define ADC_CH_MAIN_MIN 0
118#define ADC_CH_MAIN_MAX 20030
119#define ADC_CH_VBUS_MIN 0
120#define ADC_CH_VBUS_MAX 20030
121#define ADC_CH_VBAT_MIN 2300
122#define ADC_CH_VBAT_MAX 4800
123#define ADC_CH_BKBAT_MIN 0
124#define ADC_CH_BKBAT_MAX 3200
125
126/* Main charge i/p current */
127#define MAIN_CH_IP_CUR_0P9A 0x80
128#define MAIN_CH_IP_CUR_1P0A 0x90
129#define MAIN_CH_IP_CUR_1P1A 0xA0
130#define MAIN_CH_IP_CUR_1P2A 0xB0
131#define MAIN_CH_IP_CUR_1P3A 0xC0
132#define MAIN_CH_IP_CUR_1P4A 0xD0
133#define MAIN_CH_IP_CUR_1P5A 0xE0
134
135/* ChVoltLevel */
136#define CH_VOL_LVL_3P5 0x00
137#define CH_VOL_LVL_4P0 0x14
138#define CH_VOL_LVL_4P05 0x16
139#define CH_VOL_LVL_4P1 0x1B
140#define CH_VOL_LVL_4P15 0x20
141#define CH_VOL_LVL_4P2 0x25
142#define CH_VOL_LVL_4P6 0x4D
143
144/* ChOutputCurrentLevel */
145#define CH_OP_CUR_LVL_0P1 0x00
146#define CH_OP_CUR_LVL_0P2 0x01
147#define CH_OP_CUR_LVL_0P3 0x02
148#define CH_OP_CUR_LVL_0P4 0x03
149#define CH_OP_CUR_LVL_0P5 0x04
150#define CH_OP_CUR_LVL_0P6 0x05
151#define CH_OP_CUR_LVL_0P7 0x06
152#define CH_OP_CUR_LVL_0P8 0x07
153#define CH_OP_CUR_LVL_0P9 0x08
154#define CH_OP_CUR_LVL_1P4 0x0D
155#define CH_OP_CUR_LVL_1P5 0x0E
156#define CH_OP_CUR_LVL_1P6 0x0F
157
158/* BTEMP High thermal limits */
159#define BTEMP_HIGH_TH_57_0 0x00
160#define BTEMP_HIGH_TH_52 0x01
161#define BTEMP_HIGH_TH_57_1 0x02
162#define BTEMP_HIGH_TH_62 0x03
163
164/* current is mA */
165#define USB_0P1A 100
166#define USB_0P2A 200
167#define USB_0P3A 300
168#define USB_0P4A 400
169#define USB_0P5A 500
170
171#define LOW_BAT_3P1V 0x20
172#define LOW_BAT_2P3V 0x00
173#define LOW_BAT_RESET 0x01
174#define LOW_BAT_ENABLE 0x01
175
176/* Backup battery constants */
177#define BUP_ICH_SEL_50UA 0x00
178#define BUP_ICH_SEL_150UA 0x04
179#define BUP_ICH_SEL_300UA 0x08
180#define BUP_ICH_SEL_700UA 0x0C
181
182#define BUP_VCH_SEL_2P5V 0x00
183#define BUP_VCH_SEL_2P6V 0x01
184#define BUP_VCH_SEL_2P8V 0x02
185#define BUP_VCH_SEL_3P1V 0x03
186
187/* Battery OVV constants */
188#define BATT_OVV_ENA 0x02
189#define BATT_OVV_TH_3P7 0x00
190#define BATT_OVV_TH_4P75 0x01
191
192/* A value to indicate over voltage */
193#define BATT_OVV_VALUE 4750
194
195/* VBUS OVV constants */
196#define VBUS_OVV_SELECT_MASK 0x78
197#define VBUS_OVV_SELECT_5P6V 0x00
198#define VBUS_OVV_SELECT_5P7V 0x08
199#define VBUS_OVV_SELECT_5P8V 0x10
200#define VBUS_OVV_SELECT_5P9V 0x18
201#define VBUS_OVV_SELECT_6P0V 0x20
202#define VBUS_OVV_SELECT_6P1V 0x28
203#define VBUS_OVV_SELECT_6P2V 0x30
204#define VBUS_OVV_SELECT_6P3V 0x38
205
206#define VBUS_AUTO_IN_CURR_LIM_ENA 0x04
207
208/* Fuel Gauge constants */
209#define RESET_ACCU 0x02
210#define READ_REQ 0x01
211#define CC_DEEP_SLEEP_ENA 0x02
212#define CC_PWR_UP_ENA 0x01
213#define CC_SAMPLES_40 0x28
214#define RD_NCONV_ACCU_REQ 0x01
215#define CC_CALIB 0x08
216#define CC_INTAVGOFFSET_ENA 0x10
217#define CC_MUXOFFSET 0x80
218#define CC_INT_CAL_N_AVG_MASK 0x60
219#define CC_INT_CAL_SAMPLES_16 0x40
220#define CC_INT_CAL_SAMPLES_8 0x20
221#define CC_INT_CAL_SAMPLES_4 0x00
222
223/* RTC constants */
224#define RTC_BUP_CH_ENA 0x10
225
226/* BatCtrl Current Source Constants */
227#define BAT_CTRL_7U_ENA 0x01
228#define BAT_CTRL_20U_ENA 0x02
229#define BAT_CTRL_CMP_ENA 0x04
230#define FORCE_BAT_CTRL_CMP_HIGH 0x08
231#define BAT_CTRL_PULL_UP_ENA 0x10
232
233/* Battery type */
234#define BATTERY_UNKNOWN 00
235
Arun Murthy84edbee2012-02-29 21:54:26 +0530236/**
237 * struct res_to_temp - defines one point in a temp to res curve. To
238 * be used in battery packs that combines the identification resistor with a
239 * NTC resistor.
240 * @temp: battery pack temperature in Celcius
241 * @resist: NTC resistor net total resistance
242 */
243struct res_to_temp {
244 int temp;
245 int resist;
246};
247
248/**
249 * struct batres_vs_temp - defines one point in a temp vs battery internal
250 * resistance curve.
251 * @temp: battery pack temperature in Celcius
252 * @resist: battery internal reistance in mOhm
253 */
254struct batres_vs_temp {
255 int temp;
256 int resist;
257};
258
Arun Murthy84edbee2012-02-29 21:54:26 +0530259/* Forward declaration */
260struct ab8500_fg;
261
262/**
263 * struct ab8500_fg_parameters - Fuel gauge algorithm parameters, in seconds
264 * if not specified
265 * @recovery_sleep_timer: Time between measurements while recovering
266 * @recovery_total_time: Total recovery time
267 * @init_timer: Measurement interval during startup
268 * @init_discard_time: Time we discard voltage measurement at startup
269 * @init_total_time: Total init time during startup
270 * @high_curr_time: Time current has to be high to go to recovery
271 * @accu_charging: FG accumulation time while charging
272 * @accu_high_curr: FG accumulation time in high current mode
273 * @high_curr_threshold: High current threshold, in mA
274 * @lowbat_threshold: Low battery threshold, in mV
275 * @battok_falling_th_sel0 Threshold in mV for battOk signal sel0
276 * Resolution in 50 mV step.
277 * @battok_raising_th_sel1 Threshold in mV for battOk signal sel1
278 * Resolution in 50 mV step.
279 * @user_cap_limit Capacity reported from user must be within this
280 * limit to be considered as sane, in percentage
281 * points.
282 * @maint_thres This is the threshold where we stop reporting
283 * battery full while in maintenance, in per cent
284 */
285struct ab8500_fg_parameters {
286 int recovery_sleep_timer;
287 int recovery_total_time;
288 int init_timer;
289 int init_discard_time;
290 int init_total_time;
291 int high_curr_time;
292 int accu_charging;
293 int accu_high_curr;
294 int high_curr_threshold;
295 int lowbat_threshold;
296 int battok_falling_th_sel0;
297 int battok_raising_th_sel1;
298 int user_cap_limit;
299 int maint_thres;
300};
301
302/**
303 * struct ab8500_charger_maximization - struct used by the board config.
304 * @use_maxi: Enable maximization for this battery type
305 * @maxi_chg_curr: Maximum charger current allowed
306 * @maxi_wait_cycles: cycles to wait before setting charger current
307 * @charger_curr_step delta between two charger current settings (mA)
308 */
309struct ab8500_maxim_parameters {
310 bool ena_maxi;
311 int chg_curr;
312 int wait_cycles;
313 int charger_curr_step;
314};
315
316/**
Arun Murthy84edbee2012-02-29 21:54:26 +0530317 * struct ab8500_bm_capacity_levels - ab8500 capacity level data
318 * @critical: critical capacity level in percent
319 * @low: low capacity level in percent
320 * @normal: normal capacity level in percent
321 * @high: high capacity level in percent
322 * @full: full capacity level in percent
323 */
324struct ab8500_bm_capacity_levels {
325 int critical;
326 int low;
327 int normal;
328 int high;
329 int full;
330};
331
332/**
333 * struct ab8500_bm_charger_parameters - Charger specific parameters
334 * @usb_volt_max: maximum allowed USB charger voltage in mV
335 * @usb_curr_max: maximum allowed USB charger current in mA
336 * @ac_volt_max: maximum allowed AC charger voltage in mV
337 * @ac_curr_max: maximum allowed AC charger current in mA
338 */
339struct ab8500_bm_charger_parameters {
340 int usb_volt_max;
341 int usb_curr_max;
342 int ac_volt_max;
343 int ac_curr_max;
344};
345
346/**
347 * struct ab8500_bm_data - ab8500 battery management data
348 * @temp_under under this temp, charging is stopped
349 * @temp_low between this temp and temp_under charging is reduced
350 * @temp_high between this temp and temp_over charging is reduced
351 * @temp_over over this temp, charging is stopped
352 * @temp_interval_chg temperature measurement interval in s when charging
353 * @temp_interval_nochg temperature measurement interval in s when not charging
354 * @main_safety_tmr_h safety timer for main charger
355 * @usb_safety_tmr_h safety timer for usb charger
356 * @bkup_bat_v voltage which we charge the backup battery with
357 * @bkup_bat_i current which we charge the backup battery with
358 * @no_maintenance indicates that maintenance charging is disabled
Marcus Cooperea402402013-01-11 13:12:54 +0000359 * @capacity_scaling indicates whether capacity scaling is to be used
Arun Murthy84edbee2012-02-29 21:54:26 +0530360 * @adc_therm placement of thermistor, batctrl or battemp adc
361 * @chg_unknown_bat flag to enable charging of unknown batteries
362 * @enable_overshoot flag to enable VBAT overshoot control
363 * @fg_res resistance of FG resistor in 0.1mOhm
364 * @n_btypes number of elements in array bat_type
365 * @batt_id index of the identified battery in array bat_type
366 * @interval_charging charge alg cycle period time when charging (sec)
367 * @interval_not_charging charge alg cycle period time when not charging (sec)
368 * @temp_hysteresis temperature hysteresis
369 * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
370 * @maxi: maximization parameters
371 * @cap_levels capacity in percent for the different capacity levels
372 * @bat_type table of supported battery types
373 * @chg_params charger parameters
374 * @fg_params fuel gauge parameters
375 */
376struct ab8500_bm_data {
377 int temp_under;
378 int temp_low;
379 int temp_high;
380 int temp_over;
381 int temp_interval_chg;
382 int temp_interval_nochg;
383 int main_safety_tmr_h;
384 int usb_safety_tmr_h;
385 int bkup_bat_v;
386 int bkup_bat_i;
387 bool no_maintenance;
Marcus Cooperea402402013-01-11 13:12:54 +0000388 bool capacity_scaling;
Arun Murthy84edbee2012-02-29 21:54:26 +0530389 bool chg_unknown_bat;
390 bool enable_overshoot;
Anton Vorontsovd3291292012-03-14 04:27:20 +0400391 enum abx500_adc_therm adc_therm;
Arun Murthy84edbee2012-02-29 21:54:26 +0530392 int fg_res;
393 int n_btypes;
394 int batt_id;
395 int interval_charging;
396 int interval_not_charging;
397 int temp_hysteresis;
398 int gnd_lift_resistance;
399 const struct ab8500_maxim_parameters *maxi;
400 const struct ab8500_bm_capacity_levels *cap_levels;
Arun Murthy84edbee2012-02-29 21:54:26 +0530401 const struct ab8500_bm_charger_parameters *chg_params;
402 const struct ab8500_fg_parameters *fg_params;
403};
404
405struct ab8500_charger_platform_data {
406 char **supplied_to;
407 size_t num_supplicants;
408 bool autopower_cfg;
Michel JAOUEN01ec8c52012-04-26 10:00:04 +0200409 bool ac_enabled;
410 bool usb_enabled;
Arun Murthy84edbee2012-02-29 21:54:26 +0530411};
412
413struct ab8500_btemp_platform_data {
414 char **supplied_to;
415 size_t num_supplicants;
416};
417
418struct ab8500_fg_platform_data {
419 char **supplied_to;
420 size_t num_supplicants;
421};
422
423struct ab8500_chargalg_platform_data {
424 char **supplied_to;
425 size_t num_supplicants;
426};
427struct ab8500_btemp;
428struct ab8500_gpadc;
429struct ab8500_fg;
430#ifdef CONFIG_AB8500_BM
431void ab8500_fg_reinit(void);
432void ab8500_charger_usb_state_changed(u8 bm_usb_state, u16 mA);
433struct ab8500_btemp *ab8500_btemp_get(void);
434int ab8500_btemp_get_batctrl_temp(struct ab8500_btemp *btemp);
435struct ab8500_fg *ab8500_fg_get(void);
436int ab8500_fg_inst_curr_blocking(struct ab8500_fg *dev);
437int ab8500_fg_inst_curr_start(struct ab8500_fg *di);
438int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res);
Johan Bjornstedt3988a4d2013-01-11 13:12:50 +0000439int ab8500_fg_inst_curr_started(struct ab8500_fg *di);
Arun Murthy84edbee2012-02-29 21:54:26 +0530440int ab8500_fg_inst_curr_done(struct ab8500_fg *di);
441
442#else
Johan Bjornstedt3988a4d2013-01-11 13:12:50 +0000443int ab8500_fg_inst_curr_started(struct ab8500_fg *di)
444{
445 return 0;
446}
447
Arun Murthy84edbee2012-02-29 21:54:26 +0530448int ab8500_fg_inst_curr_done(struct ab8500_fg *di)
449{
Johan Bjornstedt3988a4d2013-01-11 13:12:50 +0000450 return 0;
Arun Murthy84edbee2012-02-29 21:54:26 +0530451}
452static void ab8500_fg_reinit(void)
453{
454}
455static void ab8500_charger_usb_state_changed(u8 bm_usb_state, u16 mA)
456{
457}
458static struct ab8500_btemp *ab8500_btemp_get(void)
459{
460 return NULL;
461}
462static int ab8500_btemp_get_batctrl_temp(struct ab8500_btemp *btemp)
463{
464 return 0;
465}
466struct ab8500_fg *ab8500_fg_get(void)
467{
468 return NULL;
469}
470static int ab8500_fg_inst_curr_blocking(struct ab8500_fg *dev)
471{
472 return -ENODEV;
473}
474
475static inline int ab8500_fg_inst_curr_start(struct ab8500_fg *di)
476{
477 return -ENODEV;
478}
479
480static inline int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res)
481{
482 return -ENODEV;
483}
484
485#endif
486#endif /* _AB8500_BM_H */