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