ab8500_bmdata.c 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507
  1. #include <linux/export.h>
  2. #include <linux/power_supply.h>
  3. #include <linux/of.h>
  4. #include <linux/mfd/abx500.h>
  5. #include <linux/mfd/abx500/ab8500.h>
  6. #include <linux/mfd/abx500/ab8500-bm.h>
  7. /*
  8. * These are the defined batteries that uses a NTC and ID resistor placed
  9. * inside of the battery pack.
  10. * Note that the res_to_temp table must be strictly sorted by falling resistance
  11. * values to work.
  12. */
  13. static struct abx500_res_to_temp temp_tbl_A_thermistor[] = {
  14. {-5, 53407},
  15. { 0, 48594},
  16. { 5, 43804},
  17. {10, 39188},
  18. {15, 34870},
  19. {20, 30933},
  20. {25, 27422},
  21. {30, 24347},
  22. {35, 21694},
  23. {40, 19431},
  24. {45, 17517},
  25. {50, 15908},
  26. {55, 14561},
  27. {60, 13437},
  28. {65, 12500},
  29. };
  30. static struct abx500_res_to_temp temp_tbl_B_thermistor[] = {
  31. {-5, 200000},
  32. { 0, 159024},
  33. { 5, 151921},
  34. {10, 144300},
  35. {15, 136424},
  36. {20, 128565},
  37. {25, 120978},
  38. {30, 113875},
  39. {35, 107397},
  40. {40, 101629},
  41. {45, 96592},
  42. {50, 92253},
  43. {55, 88569},
  44. {60, 85461},
  45. {65, 82869},
  46. };
  47. static struct abx500_v_to_cap cap_tbl_A_thermistor[] = {
  48. {4171, 100},
  49. {4114, 95},
  50. {4009, 83},
  51. {3947, 74},
  52. {3907, 67},
  53. {3863, 59},
  54. {3830, 56},
  55. {3813, 53},
  56. {3791, 46},
  57. {3771, 33},
  58. {3754, 25},
  59. {3735, 20},
  60. {3717, 17},
  61. {3681, 13},
  62. {3664, 8},
  63. {3651, 6},
  64. {3635, 5},
  65. {3560, 3},
  66. {3408, 1},
  67. {3247, 0},
  68. };
  69. static struct abx500_v_to_cap cap_tbl_B_thermistor[] = {
  70. {4161, 100},
  71. {4124, 98},
  72. {4044, 90},
  73. {4003, 85},
  74. {3966, 80},
  75. {3933, 75},
  76. {3888, 67},
  77. {3849, 60},
  78. {3813, 55},
  79. {3787, 47},
  80. {3772, 30},
  81. {3751, 25},
  82. {3718, 20},
  83. {3681, 16},
  84. {3660, 14},
  85. {3589, 10},
  86. {3546, 7},
  87. {3495, 4},
  88. {3404, 2},
  89. {3250, 0},
  90. };
  91. static struct abx500_v_to_cap cap_tbl[] = {
  92. {4186, 100},
  93. {4163, 99},
  94. {4114, 95},
  95. {4068, 90},
  96. {3990, 80},
  97. {3926, 70},
  98. {3898, 65},
  99. {3866, 60},
  100. {3833, 55},
  101. {3812, 50},
  102. {3787, 40},
  103. {3768, 30},
  104. {3747, 25},
  105. {3730, 20},
  106. {3705, 15},
  107. {3699, 14},
  108. {3684, 12},
  109. {3672, 9},
  110. {3657, 7},
  111. {3638, 6},
  112. {3556, 4},
  113. {3424, 2},
  114. {3317, 1},
  115. {3094, 0},
  116. };
  117. /*
  118. * Note that the res_to_temp table must be strictly sorted by falling
  119. * resistance values to work.
  120. */
  121. static struct abx500_res_to_temp temp_tbl[] = {
  122. {-5, 214834},
  123. { 0, 162943},
  124. { 5, 124820},
  125. {10, 96520},
  126. {15, 75306},
  127. {20, 59254},
  128. {25, 47000},
  129. {30, 37566},
  130. {35, 30245},
  131. {40, 24520},
  132. {45, 20010},
  133. {50, 16432},
  134. {55, 13576},
  135. {60, 11280},
  136. {65, 9425},
  137. };
  138. /*
  139. * Note that the batres_vs_temp table must be strictly sorted by falling
  140. * temperature values to work.
  141. */
  142. static struct batres_vs_temp temp_to_batres_tbl_thermistor[] = {
  143. { 40, 120},
  144. { 30, 135},
  145. { 20, 165},
  146. { 10, 230},
  147. { 00, 325},
  148. {-10, 445},
  149. {-20, 595},
  150. };
  151. /*
  152. * Note that the batres_vs_temp table must be strictly sorted by falling
  153. * temperature values to work.
  154. */
  155. static struct batres_vs_temp temp_to_batres_tbl_ext_thermistor[] = {
  156. { 60, 300},
  157. { 30, 300},
  158. { 20, 300},
  159. { 10, 300},
  160. { 00, 300},
  161. {-10, 300},
  162. {-20, 300},
  163. };
  164. /* battery resistance table for LI ION 9100 battery */
  165. static struct batres_vs_temp temp_to_batres_tbl_9100[] = {
  166. { 60, 180},
  167. { 30, 180},
  168. { 20, 180},
  169. { 10, 180},
  170. { 00, 180},
  171. {-10, 180},
  172. {-20, 180},
  173. };
  174. static struct abx500_battery_type bat_type_thermistor[] = {
  175. [BATTERY_UNKNOWN] = {
  176. /* First element always represent the UNKNOWN battery */
  177. .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
  178. .resis_high = 0,
  179. .resis_low = 0,
  180. .battery_resistance = 300,
  181. .charge_full_design = 612,
  182. .nominal_voltage = 3700,
  183. .termination_vol = 4050,
  184. .termination_curr = 200,
  185. .recharge_cap = 95,
  186. .normal_cur_lvl = 400,
  187. .normal_vol_lvl = 4100,
  188. .maint_a_cur_lvl = 400,
  189. .maint_a_vol_lvl = 4050,
  190. .maint_a_chg_timer_h = 60,
  191. .maint_b_cur_lvl = 400,
  192. .maint_b_vol_lvl = 4000,
  193. .maint_b_chg_timer_h = 200,
  194. .low_high_cur_lvl = 300,
  195. .low_high_vol_lvl = 4000,
  196. .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
  197. .r_to_t_tbl = temp_tbl,
  198. .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
  199. .v_to_cap_tbl = cap_tbl,
  200. .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  201. .batres_tbl = temp_to_batres_tbl_thermistor,
  202. },
  203. {
  204. .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
  205. .resis_high = 53407,
  206. .resis_low = 12500,
  207. .battery_resistance = 300,
  208. .charge_full_design = 900,
  209. .nominal_voltage = 3600,
  210. .termination_vol = 4150,
  211. .termination_curr = 80,
  212. .recharge_cap = 95,
  213. .normal_cur_lvl = 700,
  214. .normal_vol_lvl = 4200,
  215. .maint_a_cur_lvl = 600,
  216. .maint_a_vol_lvl = 4150,
  217. .maint_a_chg_timer_h = 60,
  218. .maint_b_cur_lvl = 600,
  219. .maint_b_vol_lvl = 4100,
  220. .maint_b_chg_timer_h = 200,
  221. .low_high_cur_lvl = 300,
  222. .low_high_vol_lvl = 4000,
  223. .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl_A_thermistor),
  224. .r_to_t_tbl = temp_tbl_A_thermistor,
  225. .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_A_thermistor),
  226. .v_to_cap_tbl = cap_tbl_A_thermistor,
  227. .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  228. .batres_tbl = temp_to_batres_tbl_thermistor,
  229. },
  230. {
  231. .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
  232. .resis_high = 200000,
  233. .resis_low = 82869,
  234. .battery_resistance = 300,
  235. .charge_full_design = 900,
  236. .nominal_voltage = 3600,
  237. .termination_vol = 4150,
  238. .termination_curr = 80,
  239. .recharge_cap = 95,
  240. .normal_cur_lvl = 700,
  241. .normal_vol_lvl = 4200,
  242. .maint_a_cur_lvl = 600,
  243. .maint_a_vol_lvl = 4150,
  244. .maint_a_chg_timer_h = 60,
  245. .maint_b_cur_lvl = 600,
  246. .maint_b_vol_lvl = 4100,
  247. .maint_b_chg_timer_h = 200,
  248. .low_high_cur_lvl = 300,
  249. .low_high_vol_lvl = 4000,
  250. .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl_B_thermistor),
  251. .r_to_t_tbl = temp_tbl_B_thermistor,
  252. .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_B_thermistor),
  253. .v_to_cap_tbl = cap_tbl_B_thermistor,
  254. .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  255. .batres_tbl = temp_to_batres_tbl_thermistor,
  256. },
  257. };
  258. static struct abx500_battery_type bat_type_ext_thermistor[] = {
  259. [BATTERY_UNKNOWN] = {
  260. /* First element always represent the UNKNOWN battery */
  261. .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN,
  262. .resis_high = 0,
  263. .resis_low = 0,
  264. .battery_resistance = 300,
  265. .charge_full_design = 612,
  266. .nominal_voltage = 3700,
  267. .termination_vol = 4050,
  268. .termination_curr = 200,
  269. .recharge_cap = 95,
  270. .normal_cur_lvl = 400,
  271. .normal_vol_lvl = 4100,
  272. .maint_a_cur_lvl = 400,
  273. .maint_a_vol_lvl = 4050,
  274. .maint_a_chg_timer_h = 60,
  275. .maint_b_cur_lvl = 400,
  276. .maint_b_vol_lvl = 4000,
  277. .maint_b_chg_timer_h = 200,
  278. .low_high_cur_lvl = 300,
  279. .low_high_vol_lvl = 4000,
  280. .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
  281. .r_to_t_tbl = temp_tbl,
  282. .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
  283. .v_to_cap_tbl = cap_tbl,
  284. .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  285. .batres_tbl = temp_to_batres_tbl_thermistor,
  286. },
  287. /*
  288. * These are the batteries that doesn't have an internal NTC resistor to measure
  289. * its temperature. The temperature in this case is measure with a NTC placed
  290. * near the battery but on the PCB.
  291. */
  292. {
  293. .name = POWER_SUPPLY_TECHNOLOGY_LIPO,
  294. .resis_high = 76000,
  295. .resis_low = 53000,
  296. .battery_resistance = 300,
  297. .charge_full_design = 900,
  298. .nominal_voltage = 3700,
  299. .termination_vol = 4150,
  300. .termination_curr = 100,
  301. .recharge_cap = 95,
  302. .normal_cur_lvl = 700,
  303. .normal_vol_lvl = 4200,
  304. .maint_a_cur_lvl = 600,
  305. .maint_a_vol_lvl = 4150,
  306. .maint_a_chg_timer_h = 60,
  307. .maint_b_cur_lvl = 600,
  308. .maint_b_vol_lvl = 4100,
  309. .maint_b_chg_timer_h = 200,
  310. .low_high_cur_lvl = 300,
  311. .low_high_vol_lvl = 4000,
  312. .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
  313. .r_to_t_tbl = temp_tbl,
  314. .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
  315. .v_to_cap_tbl = cap_tbl,
  316. .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  317. .batres_tbl = temp_to_batres_tbl_thermistor,
  318. },
  319. {
  320. .name = POWER_SUPPLY_TECHNOLOGY_LION,
  321. .resis_high = 30000,
  322. .resis_low = 10000,
  323. .battery_resistance = 300,
  324. .charge_full_design = 950,
  325. .nominal_voltage = 3700,
  326. .termination_vol = 4150,
  327. .termination_curr = 100,
  328. .recharge_cap = 95,
  329. .normal_cur_lvl = 700,
  330. .normal_vol_lvl = 4200,
  331. .maint_a_cur_lvl = 600,
  332. .maint_a_vol_lvl = 4150,
  333. .maint_a_chg_timer_h = 60,
  334. .maint_b_cur_lvl = 600,
  335. .maint_b_vol_lvl = 4100,
  336. .maint_b_chg_timer_h = 200,
  337. .low_high_cur_lvl = 300,
  338. .low_high_vol_lvl = 4000,
  339. .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
  340. .r_to_t_tbl = temp_tbl,
  341. .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
  342. .v_to_cap_tbl = cap_tbl,
  343. .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  344. .batres_tbl = temp_to_batres_tbl_thermistor,
  345. },
  346. {
  347. .name = POWER_SUPPLY_TECHNOLOGY_LION,
  348. .resis_high = 95000,
  349. .resis_low = 76001,
  350. .battery_resistance = 300,
  351. .charge_full_design = 950,
  352. .nominal_voltage = 3700,
  353. .termination_vol = 4150,
  354. .termination_curr = 100,
  355. .recharge_cap = 95,
  356. .normal_cur_lvl = 700,
  357. .normal_vol_lvl = 4200,
  358. .maint_a_cur_lvl = 600,
  359. .maint_a_vol_lvl = 4150,
  360. .maint_a_chg_timer_h = 60,
  361. .maint_b_cur_lvl = 600,
  362. .maint_b_vol_lvl = 4100,
  363. .maint_b_chg_timer_h = 200,
  364. .low_high_cur_lvl = 300,
  365. .low_high_vol_lvl = 4000,
  366. .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl),
  367. .r_to_t_tbl = temp_tbl,
  368. .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl),
  369. .v_to_cap_tbl = cap_tbl,
  370. .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor),
  371. .batres_tbl = temp_to_batres_tbl_thermistor,
  372. },
  373. };
  374. static const struct abx500_bm_capacity_levels cap_levels = {
  375. .critical = 2,
  376. .low = 10,
  377. .normal = 70,
  378. .high = 95,
  379. .full = 100,
  380. };
  381. static const struct abx500_fg_parameters fg = {
  382. .recovery_sleep_timer = 10,
  383. .recovery_total_time = 100,
  384. .init_timer = 1,
  385. .init_discard_time = 5,
  386. .init_total_time = 40,
  387. .high_curr_time = 60,
  388. .accu_charging = 30,
  389. .accu_high_curr = 30,
  390. .high_curr_threshold = 50,
  391. .lowbat_threshold = 3100,
  392. .battok_falling_th_sel0 = 2860,
  393. .battok_raising_th_sel1 = 2860,
  394. .maint_thres = 95,
  395. .user_cap_limit = 15,
  396. };
  397. static const struct abx500_maxim_parameters maxi_params = {
  398. .ena_maxi = true,
  399. .chg_curr = 910,
  400. .wait_cycles = 10,
  401. .charger_curr_step = 100,
  402. };
  403. static const struct abx500_bm_charger_parameters chg = {
  404. .usb_volt_max = 5500,
  405. .usb_curr_max = 1500,
  406. .ac_volt_max = 7500,
  407. .ac_curr_max = 1500,
  408. };
  409. struct abx500_bm_data ab8500_bm_data = {
  410. .temp_under = 3,
  411. .temp_low = 8,
  412. .temp_high = 43,
  413. .temp_over = 48,
  414. .main_safety_tmr_h = 4,
  415. .temp_interval_chg = 20,
  416. .temp_interval_nochg = 120,
  417. .usb_safety_tmr_h = 4,
  418. .bkup_bat_v = BUP_VCH_SEL_2P6V,
  419. .bkup_bat_i = BUP_ICH_SEL_150UA,
  420. .no_maintenance = false,
  421. .capacity_scaling = false,
  422. .adc_therm = ABx500_ADC_THERM_BATCTRL,
  423. .chg_unknown_bat = false,
  424. .enable_overshoot = false,
  425. .fg_res = 100,
  426. .cap_levels = &cap_levels,
  427. .bat_type = bat_type_thermistor,
  428. .n_btypes = 3,
  429. .batt_id = 0,
  430. .interval_charging = 5,
  431. .interval_not_charging = 120,
  432. .temp_hysteresis = 3,
  433. .gnd_lift_resistance = 34,
  434. .maxi = &maxi_params,
  435. .chg_params = &chg,
  436. .fg_params = &fg,
  437. };
  438. int ab8500_bm_of_probe(struct device *dev,
  439. struct device_node *np,
  440. struct abx500_bm_data *bm)
  441. {
  442. struct batres_vs_temp *tmp_batres_tbl;
  443. struct device_node *battery_node;
  444. const char *btech;
  445. int i;
  446. /* get phandle to 'battery-info' node */
  447. battery_node = of_parse_phandle(np, "battery", 0);
  448. if (!battery_node) {
  449. dev_err(dev, "battery node or reference missing\n");
  450. return -EINVAL;
  451. }
  452. btech = of_get_property(battery_node, "stericsson,battery-type", NULL);
  453. if (!btech) {
  454. dev_warn(dev, "missing property battery-name/type\n");
  455. return -EINVAL;
  456. }
  457. if (strncmp(btech, "LION", 4) == 0) {
  458. bm->no_maintenance = true;
  459. bm->chg_unknown_bat = true;
  460. bm->bat_type[BATTERY_UNKNOWN].charge_full_design = 2600;
  461. bm->bat_type[BATTERY_UNKNOWN].termination_vol = 4150;
  462. bm->bat_type[BATTERY_UNKNOWN].recharge_cap = 95;
  463. bm->bat_type[BATTERY_UNKNOWN].normal_cur_lvl = 520;
  464. bm->bat_type[BATTERY_UNKNOWN].normal_vol_lvl = 4200;
  465. }
  466. if (of_property_read_bool(battery_node, "thermistor-on-batctrl")) {
  467. if (strncmp(btech, "LION", 4) == 0)
  468. tmp_batres_tbl = temp_to_batres_tbl_9100;
  469. else
  470. tmp_batres_tbl = temp_to_batres_tbl_thermistor;
  471. } else {
  472. bm->n_btypes = 4;
  473. bm->bat_type = bat_type_ext_thermistor;
  474. bm->adc_therm = ABx500_ADC_THERM_BATTEMP;
  475. tmp_batres_tbl = temp_to_batres_tbl_ext_thermistor;
  476. }
  477. /* select the battery resolution table */
  478. for (i = 0; i < bm->n_btypes; ++i)
  479. bm->bat_type[i].batres_tbl = tmp_batres_tbl;
  480. of_node_put(battery_node);
  481. return 0;
  482. }