ab8500-bm.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478
  1. /*
  2. * Copyright ST-Ericsson 2012.
  3. *
  4. * Author: Arun Murthy <arun.murthy@stericsson.com>
  5. * Licensed under GPLv2.
  6. */
  7. #ifndef _AB8500_BM_H
  8. #define _AB8500_BM_H
  9. #include <linux/kernel.h>
  10. #include <linux/mfd/abx500.h>
  11. /*
  12. * System control 2 register offsets.
  13. * bank = 0x02
  14. */
  15. #define AB8500_MAIN_WDOG_CTRL_REG 0x01
  16. #define AB8500_LOW_BAT_REG 0x03
  17. #define AB8500_BATT_OK_REG 0x04
  18. /*
  19. * USB/ULPI register offsets
  20. * Bank : 0x5
  21. */
  22. #define AB8500_USB_LINE_STAT_REG 0x80
  23. #define AB8500_USB_LINE_CTRL2_REG 0x82
  24. #define AB8500_USB_LINK1_STAT_REG 0x94
  25. /*
  26. * Charger / status register offfsets
  27. * Bank : 0x0B
  28. */
  29. #define AB8500_CH_STATUS1_REG 0x00
  30. #define AB8500_CH_STATUS2_REG 0x01
  31. #define AB8500_CH_USBCH_STAT1_REG 0x02
  32. #define AB8500_CH_USBCH_STAT2_REG 0x03
  33. #define AB8540_CH_USBCH_STAT3_REG 0x04
  34. #define AB8500_CH_STAT_REG 0x05
  35. /*
  36. * Charger / control register offfsets
  37. * Bank : 0x0B
  38. */
  39. #define AB8500_CH_VOLT_LVL_REG 0x40
  40. #define AB8500_CH_VOLT_LVL_MAX_REG 0x41 /*Only in Cut2.0*/
  41. #define AB8500_CH_OPT_CRNTLVL_REG 0x42
  42. #define AB8500_CH_OPT_CRNTLVL_MAX_REG 0x43 /*Only in Cut2.0*/
  43. #define AB8500_CH_WD_TIMER_REG 0x50
  44. #define AB8500_CHARG_WD_CTRL 0x51
  45. #define AB8500_BTEMP_HIGH_TH 0x52
  46. #define AB8500_LED_INDICATOR_PWM_CTRL 0x53
  47. #define AB8500_LED_INDICATOR_PWM_DUTY 0x54
  48. #define AB8500_BATT_OVV 0x55
  49. #define AB8500_CHARGER_CTRL 0x56
  50. #define AB8500_BAT_CTRL_CURRENT_SOURCE 0x60 /*Only in Cut2.0*/
  51. /*
  52. * Charger / main control register offsets
  53. * Bank : 0x0B
  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. * Charger / USB control register offsets
  61. * Bank : 0x0B
  62. */
  63. #define AB8500_USBCH_CTRL1_REG 0xC0
  64. #define AB8500_USBCH_CTRL2_REG 0xC1
  65. #define AB8500_USBCH_IPT_CRNTLVL_REG 0xC2
  66. #define AB8540_USB_PP_MODE_REG 0xC5
  67. #define AB8540_USB_PP_CHR_REG 0xC6
  68. /*
  69. * Gas Gauge register offsets
  70. * Bank : 0x0C
  71. */
  72. #define AB8500_GASG_CC_CTRL_REG 0x00
  73. #define AB8500_GASG_CC_ACCU1_REG 0x01
  74. #define AB8500_GASG_CC_ACCU2_REG 0x02
  75. #define AB8500_GASG_CC_ACCU3_REG 0x03
  76. #define AB8500_GASG_CC_ACCU4_REG 0x04
  77. #define AB8500_GASG_CC_SMPL_CNTRL_REG 0x05
  78. #define AB8500_GASG_CC_SMPL_CNTRH_REG 0x06
  79. #define AB8500_GASG_CC_SMPL_CNVL_REG 0x07
  80. #define AB8500_GASG_CC_SMPL_CNVH_REG 0x08
  81. #define AB8500_GASG_CC_CNTR_AVGOFF_REG 0x09
  82. #define AB8500_GASG_CC_OFFSET_REG 0x0A
  83. #define AB8500_GASG_CC_NCOV_ACCU 0x10
  84. #define AB8500_GASG_CC_NCOV_ACCU_CTRL 0x11
  85. #define AB8500_GASG_CC_NCOV_ACCU_LOW 0x12
  86. #define AB8500_GASG_CC_NCOV_ACCU_MED 0x13
  87. #define AB8500_GASG_CC_NCOV_ACCU_HIGH 0x14
  88. /*
  89. * Interrupt register offsets
  90. * Bank : 0x0E
  91. */
  92. #define AB8500_IT_SOURCE2_REG 0x01
  93. #define AB8500_IT_SOURCE21_REG 0x14
  94. /*
  95. * RTC register offsets
  96. * Bank: 0x0F
  97. */
  98. #define AB8500_RTC_BACKUP_CHG_REG 0x0C
  99. #define AB8500_RTC_CC_CONF_REG 0x01
  100. #define AB8500_RTC_CTRL_REG 0x0B
  101. #define AB8500_RTC_CTRL1_REG 0x11
  102. /*
  103. * OTP register offsets
  104. * Bank : 0x15
  105. */
  106. #define AB8500_OTP_CONF_15 0x0E
  107. /* GPADC constants from AB8500 spec, UM0836 */
  108. #define ADC_RESOLUTION 1024
  109. #define ADC_CH_MAIN_MIN 0
  110. #define ADC_CH_MAIN_MAX 20030
  111. #define ADC_CH_VBUS_MIN 0
  112. #define ADC_CH_VBUS_MAX 20030
  113. #define ADC_CH_VBAT_MIN 2300
  114. #define ADC_CH_VBAT_MAX 4800
  115. #define ADC_CH_BKBAT_MIN 0
  116. #define ADC_CH_BKBAT_MAX 3200
  117. /* Main charge i/p current */
  118. #define MAIN_CH_IP_CUR_0P9A 0x80
  119. #define MAIN_CH_IP_CUR_1P0A 0x90
  120. #define MAIN_CH_IP_CUR_1P1A 0xA0
  121. #define MAIN_CH_IP_CUR_1P2A 0xB0
  122. #define MAIN_CH_IP_CUR_1P3A 0xC0
  123. #define MAIN_CH_IP_CUR_1P4A 0xD0
  124. #define MAIN_CH_IP_CUR_1P5A 0xE0
  125. /* ChVoltLevel */
  126. #define CH_VOL_LVL_3P5 0x00
  127. #define CH_VOL_LVL_4P0 0x14
  128. #define CH_VOL_LVL_4P05 0x16
  129. #define CH_VOL_LVL_4P1 0x1B
  130. #define CH_VOL_LVL_4P15 0x20
  131. #define CH_VOL_LVL_4P2 0x25
  132. #define CH_VOL_LVL_4P6 0x4D
  133. /* ChOutputCurrentLevel */
  134. #define CH_OP_CUR_LVL_0P1 0x00
  135. #define CH_OP_CUR_LVL_0P2 0x01
  136. #define CH_OP_CUR_LVL_0P3 0x02
  137. #define CH_OP_CUR_LVL_0P4 0x03
  138. #define CH_OP_CUR_LVL_0P5 0x04
  139. #define CH_OP_CUR_LVL_0P6 0x05
  140. #define CH_OP_CUR_LVL_0P7 0x06
  141. #define CH_OP_CUR_LVL_0P8 0x07
  142. #define CH_OP_CUR_LVL_0P9 0x08
  143. #define CH_OP_CUR_LVL_1P4 0x0D
  144. #define CH_OP_CUR_LVL_1P5 0x0E
  145. #define CH_OP_CUR_LVL_1P6 0x0F
  146. #define CH_OP_CUR_LVL_2P 0x3F
  147. /* BTEMP High thermal limits */
  148. #define BTEMP_HIGH_TH_57_0 0x00
  149. #define BTEMP_HIGH_TH_52 0x01
  150. #define BTEMP_HIGH_TH_57_1 0x02
  151. #define BTEMP_HIGH_TH_62 0x03
  152. /* current is mA */
  153. #define USB_0P1A 100
  154. #define USB_0P2A 200
  155. #define USB_0P3A 300
  156. #define USB_0P4A 400
  157. #define USB_0P5A 500
  158. #define LOW_BAT_3P1V 0x20
  159. #define LOW_BAT_2P3V 0x00
  160. #define LOW_BAT_RESET 0x01
  161. #define LOW_BAT_ENABLE 0x01
  162. /* Backup battery constants */
  163. #define BUP_ICH_SEL_50UA 0x00
  164. #define BUP_ICH_SEL_150UA 0x04
  165. #define BUP_ICH_SEL_300UA 0x08
  166. #define BUP_ICH_SEL_700UA 0x0C
  167. enum bup_vch_sel {
  168. BUP_VCH_SEL_2P5V,
  169. BUP_VCH_SEL_2P6V,
  170. BUP_VCH_SEL_2P8V,
  171. BUP_VCH_SEL_3P1V,
  172. /*
  173. * Note that the following 5 values 2.7v, 2.9v, 3.0v, 3.2v, 3.3v
  174. * are only available on ab8540. You can't choose these 5
  175. * voltage on ab8500/ab8505/ab9540.
  176. */
  177. BUP_VCH_SEL_2P7V,
  178. BUP_VCH_SEL_2P9V,
  179. BUP_VCH_SEL_3P0V,
  180. BUP_VCH_SEL_3P2V,
  181. BUP_VCH_SEL_3P3V,
  182. };
  183. #define BUP_VCH_RANGE 0x02
  184. #define VBUP33_VRTCN 0x01
  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. /* A value to indicate over voltage */
  190. #define BATT_OVV_VALUE 4750
  191. /* VBUS OVV constants */
  192. #define VBUS_OVV_SELECT_MASK 0x78
  193. #define VBUS_OVV_SELECT_5P6V 0x00
  194. #define VBUS_OVV_SELECT_5P7V 0x08
  195. #define VBUS_OVV_SELECT_5P8V 0x10
  196. #define VBUS_OVV_SELECT_5P9V 0x18
  197. #define VBUS_OVV_SELECT_6P0V 0x20
  198. #define VBUS_OVV_SELECT_6P1V 0x28
  199. #define VBUS_OVV_SELECT_6P2V 0x30
  200. #define VBUS_OVV_SELECT_6P3V 0x38
  201. #define VBUS_AUTO_IN_CURR_LIM_ENA 0x04
  202. /* Fuel Gauge constants */
  203. #define RESET_ACCU 0x02
  204. #define READ_REQ 0x01
  205. #define CC_DEEP_SLEEP_ENA 0x02
  206. #define CC_PWR_UP_ENA 0x01
  207. #define CC_SAMPLES_40 0x28
  208. #define RD_NCONV_ACCU_REQ 0x01
  209. #define CC_CALIB 0x08
  210. #define CC_INTAVGOFFSET_ENA 0x10
  211. #define CC_MUXOFFSET 0x80
  212. #define CC_INT_CAL_N_AVG_MASK 0x60
  213. #define CC_INT_CAL_SAMPLES_16 0x40
  214. #define CC_INT_CAL_SAMPLES_8 0x20
  215. #define CC_INT_CAL_SAMPLES_4 0x00
  216. /* RTC constants */
  217. #define RTC_BUP_CH_ENA 0x10
  218. /* BatCtrl Current Source Constants */
  219. #define BAT_CTRL_7U_ENA 0x01
  220. #define BAT_CTRL_20U_ENA 0x02
  221. #define BAT_CTRL_18U_ENA 0x01
  222. #define BAT_CTRL_16U_ENA 0x02
  223. #define BAT_CTRL_60U_ENA 0x01
  224. #define BAT_CTRL_120U_ENA 0x02
  225. #define BAT_CTRL_CMP_ENA 0x04
  226. #define FORCE_BAT_CTRL_CMP_HIGH 0x08
  227. #define BAT_CTRL_PULL_UP_ENA 0x10
  228. /* Battery type */
  229. #define BATTERY_UNKNOWN 00
  230. /* Registers for pcut feature in ab8505 and ab9540 */
  231. #define AB8505_RTC_PCUT_CTL_STATUS_REG 0x12
  232. #define AB8505_RTC_PCUT_TIME_REG 0x13
  233. #define AB8505_RTC_PCUT_MAX_TIME_REG 0x14
  234. #define AB8505_RTC_PCUT_FLAG_TIME_REG 0x15
  235. #define AB8505_RTC_PCUT_RESTART_REG 0x16
  236. #define AB8505_RTC_PCUT_DEBOUNCE_REG 0x17
  237. /* USB Power Path constants for ab8540 */
  238. #define BUS_VSYS_VOL_SELECT_MASK 0x06
  239. #define BUS_VSYS_VOL_SELECT_3P6V 0x00
  240. #define BUS_VSYS_VOL_SELECT_3P325V 0x02
  241. #define BUS_VSYS_VOL_SELECT_3P9V 0x04
  242. #define BUS_VSYS_VOL_SELECT_4P3V 0x06
  243. #define BUS_POWER_PATH_MODE_ENA 0x01
  244. #define BUS_PP_PRECHG_CURRENT_MASK 0x0E
  245. #define BUS_POWER_PATH_PRECHG_ENA 0x01
  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. */
  253. struct res_to_temp {
  254. int temp;
  255. int resist;
  256. };
  257. /**
  258. * struct batres_vs_temp - defines one point in a temp vs battery internal
  259. * resistance curve.
  260. * @temp: battery pack temperature in Celcius
  261. * @resist: battery internal reistance in mOhm
  262. */
  263. struct batres_vs_temp {
  264. int temp;
  265. int resist;
  266. };
  267. /* Forward declaration */
  268. struct ab8500_fg;
  269. /**
  270. * struct ab8500_fg_parameters - Fuel gauge algorithm parameters, in seconds
  271. * if not specified
  272. * @recovery_sleep_timer: Time between measurements while recovering
  273. * @recovery_total_time: Total recovery time
  274. * @init_timer: Measurement interval during startup
  275. * @init_discard_time: Time we discard voltage measurement at startup
  276. * @init_total_time: Total init time during startup
  277. * @high_curr_time: Time current has to be high to go to recovery
  278. * @accu_charging: FG accumulation time while charging
  279. * @accu_high_curr: FG accumulation time in high current mode
  280. * @high_curr_threshold: High current threshold, in mA
  281. * @lowbat_threshold: Low battery threshold, in mV
  282. * @battok_falling_th_sel0 Threshold in mV for battOk signal sel0
  283. * Resolution in 50 mV step.
  284. * @battok_raising_th_sel1 Threshold in mV for battOk signal sel1
  285. * Resolution in 50 mV step.
  286. * @user_cap_limit Capacity reported from user must be within this
  287. * limit to be considered as sane, in percentage
  288. * points.
  289. * @maint_thres This is the threshold where we stop reporting
  290. * battery full while in maintenance, in per cent
  291. * @pcut_enable: Enable power cut feature in ab8505
  292. * @pcut_max_time: Max time threshold
  293. * @pcut_flag_time: Flagtime threshold
  294. * @pcut_max_restart: Max number of restarts
  295. * @pcut_debunce_time: Sets battery debounce time
  296. */
  297. struct ab8500_fg_parameters {
  298. int recovery_sleep_timer;
  299. int recovery_total_time;
  300. int init_timer;
  301. int init_discard_time;
  302. int init_total_time;
  303. int high_curr_time;
  304. int accu_charging;
  305. int accu_high_curr;
  306. int high_curr_threshold;
  307. int lowbat_threshold;
  308. int battok_falling_th_sel0;
  309. int battok_raising_th_sel1;
  310. int user_cap_limit;
  311. int maint_thres;
  312. bool pcut_enable;
  313. u8 pcut_max_time;
  314. u8 pcut_flag_time;
  315. u8 pcut_max_restart;
  316. u8 pcut_debunce_time;
  317. };
  318. /**
  319. * struct ab8500_charger_maximization - struct used by the board config.
  320. * @use_maxi: Enable maximization for this battery type
  321. * @maxi_chg_curr: Maximum charger current allowed
  322. * @maxi_wait_cycles: cycles to wait before setting charger current
  323. * @charger_curr_step delta between two charger current settings (mA)
  324. */
  325. struct ab8500_maxim_parameters {
  326. bool ena_maxi;
  327. int chg_curr;
  328. int wait_cycles;
  329. int charger_curr_step;
  330. };
  331. /**
  332. * struct ab8500_bm_capacity_levels - ab8500 capacity level data
  333. * @critical: critical capacity level in percent
  334. * @low: low capacity level in percent
  335. * @normal: normal capacity level in percent
  336. * @high: high capacity level in percent
  337. * @full: full capacity level in percent
  338. */
  339. struct ab8500_bm_capacity_levels {
  340. int critical;
  341. int low;
  342. int normal;
  343. int high;
  344. int full;
  345. };
  346. /**
  347. * struct ab8500_bm_charger_parameters - Charger specific parameters
  348. * @usb_volt_max: maximum allowed USB charger voltage in mV
  349. * @usb_curr_max: maximum allowed USB charger current in mA
  350. * @ac_volt_max: maximum allowed AC charger voltage in mV
  351. * @ac_curr_max: maximum allowed AC charger current in mA
  352. */
  353. struct ab8500_bm_charger_parameters {
  354. int usb_volt_max;
  355. int usb_curr_max;
  356. int ac_volt_max;
  357. int ac_curr_max;
  358. };
  359. /**
  360. * struct ab8500_bm_data - ab8500 battery management data
  361. * @temp_under under this temp, charging is stopped
  362. * @temp_low between this temp and temp_under charging is reduced
  363. * @temp_high between this temp and temp_over charging is reduced
  364. * @temp_over over this temp, charging is stopped
  365. * @temp_interval_chg temperature measurement interval in s when charging
  366. * @temp_interval_nochg temperature measurement interval in s when not charging
  367. * @main_safety_tmr_h safety timer for main charger
  368. * @usb_safety_tmr_h safety timer for usb charger
  369. * @bkup_bat_v voltage which we charge the backup battery with
  370. * @bkup_bat_i current which we charge the backup battery with
  371. * @no_maintenance indicates that maintenance charging is disabled
  372. * @capacity_scaling indicates whether capacity scaling is to be used
  373. * @adc_therm placement of thermistor, batctrl or battemp adc
  374. * @chg_unknown_bat flag to enable charging of unknown batteries
  375. * @enable_overshoot flag to enable VBAT overshoot control
  376. * @fg_res resistance of FG resistor in 0.1mOhm
  377. * @n_btypes number of elements in array bat_type
  378. * @batt_id index of the identified battery in array bat_type
  379. * @interval_charging charge alg cycle period time when charging (sec)
  380. * @interval_not_charging charge alg cycle period time when not charging (sec)
  381. * @temp_hysteresis temperature hysteresis
  382. * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm)
  383. * @maxi: maximization parameters
  384. * @cap_levels capacity in percent for the different capacity levels
  385. * @bat_type table of supported battery types
  386. * @chg_params charger parameters
  387. * @fg_params fuel gauge parameters
  388. */
  389. struct ab8500_bm_data {
  390. int temp_under;
  391. int temp_low;
  392. int temp_high;
  393. int temp_over;
  394. int temp_interval_chg;
  395. int temp_interval_nochg;
  396. int main_safety_tmr_h;
  397. int usb_safety_tmr_h;
  398. int bkup_bat_v;
  399. int bkup_bat_i;
  400. bool no_maintenance;
  401. bool capacity_scaling;
  402. bool chg_unknown_bat;
  403. bool enable_overshoot;
  404. enum abx500_adc_therm adc_therm;
  405. int fg_res;
  406. int n_btypes;
  407. int batt_id;
  408. int interval_charging;
  409. int interval_not_charging;
  410. int temp_hysteresis;
  411. int gnd_lift_resistance;
  412. const struct ab8500_maxim_parameters *maxi;
  413. const struct ab8500_bm_capacity_levels *cap_levels;
  414. const struct ab8500_bm_charger_parameters *chg_params;
  415. const struct ab8500_fg_parameters *fg_params;
  416. };
  417. struct ab8500_btemp;
  418. struct ab8500_gpadc;
  419. struct ab8500_fg;
  420. #ifdef CONFIG_AB8500_BM
  421. extern struct abx500_bm_data ab8500_bm_data;
  422. void ab8500_charger_usb_state_changed(u8 bm_usb_state, u16 mA);
  423. struct ab8500_btemp *ab8500_btemp_get(void);
  424. int ab8500_btemp_get_batctrl_temp(struct ab8500_btemp *btemp);
  425. int ab8500_btemp_get_temp(struct ab8500_btemp *btemp);
  426. struct ab8500_fg *ab8500_fg_get(void);
  427. int ab8500_fg_inst_curr_blocking(struct ab8500_fg *dev);
  428. int ab8500_fg_inst_curr_start(struct ab8500_fg *di);
  429. int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res);
  430. int ab8500_fg_inst_curr_started(struct ab8500_fg *di);
  431. int ab8500_fg_inst_curr_done(struct ab8500_fg *di);
  432. #else
  433. static struct abx500_bm_data ab8500_bm_data;
  434. #endif
  435. #endif /* _AB8500_BM_H */