ab8500-bm.h 13 KB

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