ab8500-bm.h 13 KB

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