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