Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge tag 'for-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply

Pull power supply and reset updates from Sebastian Reichel:
"Power-supply core:

- introduce "No Battery" health status

- use library interpolation

- add power_supply_battery_info documentation

- migrate power_supply_battery_info to be fully heap allocated making
it more obvious that it needs to be free'd manually

Drivers:

- max77976-charger: new driver

- qcom-smbb: add pm8226 charger support

- bq25890-charger: support battery temperature readings

- ab8500: continue migrating towards using standard core APIs"

* tag 'for-v5.17' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: (28 commits)
power: supply_core: Pass pointer to battery info
power: supply: ab8500: Fix the error handling path of ab8500_charger_probe()
power: reset: mt6397: Check for null res pointer
power: bq25890: add POWER_SUPPLY_PROP_TEMP
power: supply: qcom_smbb: support pm8226
dt-bindings: power: supply: pm8941-charger: add pm8226
power: supply: ab8500: Standardize capacity lookup
power: supply: ab8500: Standardize temp res lookup
power: supply: ab8500: Standardize CV voltage
power: supply: ab8500: Standardize CC current
power: supply: ab8500: Make recharge capacity a constant
power: supply: ab8500: Standardize termination current
power: supply: ab8500: Standardize internal resistance
power: supply: ab8500_fg: Init battery data in bind()
power: supply: ab8500: Standardize voltages
power: supply: ab8500: Standardize technology
power: supply: ab8500: Standardize design capacity
power: supply: ab8500: Use only one battery type
power: supply: ab8500: Drop unused battery types
power: supply: ab8500: Standardize operating temperature
...

+1842 -1383
+1 -1
Documentation/ABI/testing/sysfs-class-power
··· 413 413 "Over voltage", "Unspecified failure", "Cold", 414 414 "Watchdog timer expire", "Safety timer expire", 415 415 "Over current", "Calibration required", "Warm", 416 - "Cool", "Hot" 416 + "Cool", "Hot", "No battery" 417 417 418 418 What: /sys/class/power_supply/<supply_name>/precharge_current 419 419 Date: June 2017
-41
Documentation/devicetree/bindings/power/reset/gpio-poweroff.txt
··· 1 - Driver a GPIO line that can be used to turn the power off. 2 - 3 - The driver supports both level triggered and edge triggered power off. 4 - At driver load time, the driver will request the given gpio line and 5 - install a handler to power off the system. If the optional properties 6 - 'input' is not found, the GPIO line will be driven in the inactive 7 - state. Otherwise its configured as an input. 8 - 9 - When the power-off handler is called, the gpio is configured as an 10 - output, and drive active, so triggering a level triggered power off 11 - condition. This will also cause an inactive->active edge condition, so 12 - triggering positive edge triggered power off. After a delay of 100ms, 13 - the GPIO is set to inactive, thus causing an active->inactive edge, 14 - triggering negative edge triggered power off. After another 100ms 15 - delay the GPIO is driver active again. If the power is still on and 16 - the CPU still running after a 3000ms delay, a WARN_ON(1) is emitted. 17 - 18 - Required properties: 19 - - compatible : should be "gpio-poweroff". 20 - - gpios : The GPIO to set high/low, see "gpios property" in 21 - Documentation/devicetree/bindings/gpio/gpio.txt. If the pin should be 22 - low to power down the board set it to "Active Low", otherwise set 23 - gpio to "Active High". 24 - 25 - Optional properties: 26 - - input : Initially configure the GPIO line as an input. Only reconfigure 27 - it to an output when the power-off handler is called. If this optional 28 - property is not specified, the GPIO is initialized as an output in its 29 - inactive state. 30 - - active-delay-ms: Delay (default 100) to wait after driving gpio active 31 - - inactive-delay-ms: Delay (default 100) to wait after driving gpio inactive 32 - - timeout-ms: Time to wait before asserting a WARN_ON(1). If nothing is 33 - specified, 3000 ms is used. 34 - 35 - Examples: 36 - 37 - gpio-poweroff { 38 - compatible = "gpio-poweroff"; 39 - gpios = <&gpio 4 0>; 40 - timeout-ms = <3000>; 41 - };
+59
Documentation/devicetree/bindings/power/reset/gpio-poweroff.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0-only or BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/power/reset/gpio-poweroff.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: GPIO controlled power off 8 + 9 + maintainers: 10 + - Sebastian Reichel <sre@kernel.org> 11 + 12 + description: > 13 + System power off support via a GPIO line. When a shutdown is 14 + executed the operating system is expected to switch the GPIO 15 + from inactive to active. After a delay (active-delay-ms) it 16 + is expected to be switched back to inactive. After another 17 + delay (inactive-delay-ms) it is configured as active again. 18 + Finally the operating system assumes the power off failed if 19 + the system is still running after waiting some time (timeout-ms). 20 + 21 + properties: 22 + compatible: 23 + const: gpio-poweroff 24 + 25 + gpios: 26 + maxItems: 1 27 + 28 + input: 29 + type: boolean 30 + description: > 31 + Initially configure the GPIO line as an input. Only reconfigure 32 + it to an output when the power-off sequence is initiated. If this optional 33 + property is not specified, the GPIO is initialized as an output in its inactive state. 34 + 35 + active-delay-ms: 36 + default: 100 37 + description: Delay to wait after driving gpio active 38 + 39 + inactive-delay-ms: 40 + default: 100 41 + description: Delay to wait after driving gpio inactive 42 + 43 + timeout-ms: 44 + default: 3000 45 + description: Time to wait before assuming the power off sequence failed. 46 + 47 + required: 48 + - compatible 49 + - gpios 50 + 51 + additionalProperties: false 52 + 53 + examples: 54 + - | 55 + gpio-poweroff { 56 + compatible = "gpio-poweroff"; 57 + gpios = <&gpio 4 0>; 58 + timeout-ms = <3000>; 59 + };
+44
Documentation/devicetree/bindings/power/supply/maxim,max77976.yaml
··· 1 + # SPDX-License-Identifier: (GPL-2.0 OR BSD-2-Clause) 2 + %YAML 1.2 3 + --- 4 + $id: http://devicetree.org/schemas/power/supply/maxim,max77976.yaml# 5 + $schema: http://devicetree.org/meta-schemas/core.yaml# 6 + 7 + title: Maxim Integrated MAX77976 Battery charger 8 + 9 + maintainers: 10 + - Luca Ceresoli <luca@lucaceresoli.net> 11 + 12 + description: | 13 + The Maxim MAX77976 is a 19Vin / 5.5A, 1-Cell Li+ battery charger 14 + configured via I2C. 15 + 16 + allOf: 17 + - $ref: power-supply.yaml# 18 + 19 + properties: 20 + compatible: 21 + const: maxim,max77976 22 + 23 + reg: 24 + maxItems: 1 25 + 26 + required: 27 + - compatible 28 + - reg 29 + 30 + unevaluatedProperties: false 31 + 32 + examples: 33 + - | 34 + i2c { 35 + #address-cells = <1>; 36 + #size-cells = <0>; 37 + 38 + charger@6b { 39 + compatible = "maxim,max77976"; 40 + reg = <0x6b>; 41 + }; 42 + }; 43 + 44 + ...
+3 -1
Documentation/devicetree/bindings/power/supply/qcom,pm8941-charger.yaml
··· 11 11 12 12 properties: 13 13 compatible: 14 - const: qcom,pm8941-charger 14 + enum: 15 + - qcom,pm8226-charger 16 + - qcom,pm8941-charger 15 17 16 18 reg: 17 19 maxItems: 1
+6
MAINTAINERS
··· 11668 11668 F: drivers/regulator/max77802-regulator.c 11669 11669 F: include/dt-bindings/*/*max77802.h 11670 11670 11671 + MAXIM MAX77976 BATTERY CHARGER 11672 + M: Luca Ceresoli <luca@lucaceresoli.net> 11673 + S: Supported 11674 + F: Documentation/devicetree/bindings/power/supply/maxim,max77976.yaml 11675 + F: drivers/power/supply/max77976_charger.c 11676 + 11671 11677 MAXIM MUIC CHARGER DRIVERS FOR EXYNOS BASED BOARDS 11672 11678 M: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> 11673 11679 M: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com>
+3
drivers/power/reset/mt6323-poweroff.c
··· 57 57 return -ENOMEM; 58 58 59 59 res = platform_get_resource(pdev, IORESOURCE_MEM, 0); 60 + if (!res) 61 + return -EINVAL; 62 + 60 63 pwrc->base = res->start; 61 64 pwrc->regmap = mt6397_chip->regmap; 62 65 pwrc->dev = &pdev->dev;
+12
drivers/power/supply/Kconfig
··· 557 557 help 558 558 Say Y to enable support for the Maxim MAX77693 battery charger. 559 559 560 + config CHARGER_MAX77976 561 + tristate "Maxim MAX77976 battery charger driver" 562 + depends on I2C 563 + select REGMAP_I2C 564 + help 565 + The Maxim MAX77976 is a 19 Vin, 5.5A 1-Cell Li+ Battery Charger 566 + USB OTG support. It has an I2C interface for configuration. 567 + 568 + Say Y to enable support for the Maxim MAX77976 battery charger. 569 + This driver can also be built as a module. If so, the module will be 570 + called max77976_charger. 571 + 560 572 config CHARGER_MAX8997 561 573 tristate "Maxim MAX8997/MAX8966 PMIC battery charger driver" 562 574 depends on MFD_MAX8997 && REGULATOR_MAX8997
+1
drivers/power/supply/Makefile
··· 75 75 obj-$(CONFIG_CHARGER_DETECTOR_MAX14656) += max14656_charger_detector.o 76 76 obj-$(CONFIG_CHARGER_MAX77650) += max77650-charger.o 77 77 obj-$(CONFIG_CHARGER_MAX77693) += max77693_charger.o 78 + obj-$(CONFIG_CHARGER_MAX77976) += max77976_charger.o 78 79 obj-$(CONFIG_CHARGER_MAX8997) += max8997_charger.o 79 80 obj-$(CONFIG_CHARGER_MAX8998) += max8998_charger.o 80 81 obj-$(CONFIG_CHARGER_MP2629) += mp2629_charger.o
+24 -99
drivers/power/supply/ab8500-bm.h
··· 160 160 #define BTEMP_HIGH_TH_57_1 0x02 161 161 #define BTEMP_HIGH_TH_62 0x03 162 162 163 - /* current is mA */ 164 - #define USB_0P1A 100 165 - #define USB_0P2A 200 166 - #define USB_0P3A 300 167 - #define USB_0P4A 400 168 - #define USB_0P5A 500 169 - 170 163 #define LOW_BAT_3P1V 0x20 171 164 #define LOW_BAT_2P3V 0x00 172 165 #define LOW_BAT_RESET 0x01 ··· 196 203 #define BATT_OVV_TH_3P7 0x00 197 204 #define BATT_OVV_TH_4P75 0x01 198 205 199 - /* A value to indicate over voltage */ 200 - #define BATT_OVV_VALUE 4750 206 + /* A value to indicate over voltage (microvolts) */ 207 + #define BATT_OVV_VALUE 4750000 201 208 202 209 /* VBUS OVV constants */ 203 210 #define VBUS_OVV_SELECT_MASK 0x78 ··· 284 291 int resist; 285 292 }; 286 293 287 - /** 288 - * struct ab8500_v_to_cap - Table for translating voltage to capacity 289 - * @voltage: Voltage in mV 290 - * @capacity: Capacity in percent 291 - */ 292 - struct ab8500_v_to_cap { 293 - int voltage; 294 - int capacity; 295 - }; 296 - 297 294 /* Forward declaration */ 298 295 struct ab8500_fg; 299 296 ··· 297 314 * @init_total_time: Total init time during startup 298 315 * @high_curr_time: Time current has to be high to go to recovery 299 316 * @accu_charging: FG accumulation time while charging 300 - * @accu_high_curr: FG accumulation time in high current mode 301 - * @high_curr_threshold: High current threshold, in mA 302 - * @lowbat_threshold: Low battery threshold, in mV 303 - * @overbat_threshold: Over battery threshold, in mV 317 + * @accu_high_curr_ua: FG accumulation time in high current mode 318 + * @high_curr_threshold_ua: High current threshold, in uA 319 + * @lowbat_threshold_uv: Low battery threshold, in uV 304 320 * @battok_falling_th_sel0 Threshold in mV for battOk signal sel0 305 321 * Resolution in 50 mV step. 306 322 * @battok_raising_th_sel1 Threshold in mV for battOk signal sel1 ··· 324 342 int high_curr_time; 325 343 int accu_charging; 326 344 int accu_high_curr; 327 - int high_curr_threshold; 328 - int lowbat_threshold; 329 - int overbat_threshold; 345 + int high_curr_threshold_ua; 346 + int lowbat_threshold_uv; 330 347 int battok_falling_th_sel0; 331 348 int battok_raising_th_sel1; 332 349 int user_cap_limit; ··· 340 359 /** 341 360 * struct ab8500_charger_maximization - struct used by the board config. 342 361 * @use_maxi: Enable maximization for this battery type 343 - * @maxi_chg_curr: Maximum charger current allowed 362 + * @maxi_chg_curr_ua: Maximum charger current allowed in microampere 344 363 * @maxi_wait_cycles: cycles to wait before setting charger current 345 - * @charger_curr_step delta between two charger current settings (mA) 364 + * @charger_curr_step_ua: delta between two charger current settings (uA) 346 365 */ 347 366 struct ab8500_maxim_parameters { 348 367 bool ena_maxi; 349 - int chg_curr; 368 + int chg_curr_ua; 350 369 int wait_cycles; 351 - int charger_curr_step; 370 + int charger_curr_step_ua; 352 371 }; 353 372 354 373 /** 355 374 * struct ab8500_battery_type - different batteries supported 356 - * @name: battery technology 357 375 * @resis_high: battery upper resistance limit 358 376 * @resis_low: battery lower resistance limit 359 - * @charge_full_design: Maximum battery capacity in mAh 360 - * @nominal_voltage: Nominal voltage of the battery in mV 361 - * @termination_vol: max voltage upto which battery can be charged 362 - * @termination_curr battery charging termination current in mA 363 - * @recharge_cap battery capacity limit that will trigger a new 364 - * full charging cycle in the case where maintenan- 365 - * -ce charging has been disabled 366 - * @normal_cur_lvl: charger current in normal state in mA 367 - * @normal_vol_lvl: charger voltage in normal state in mV 368 377 * @maint_a_cur_lvl: charger current in maintenance A state in mA 369 378 * @maint_a_vol_lvl: charger voltage in maintenance A state in mV 370 379 * @maint_a_chg_timer_h: charge time in maintenance A state ··· 363 392 * @maint_b_chg_timer_h: charge time in maintenance B state 364 393 * @low_high_cur_lvl: charger current in temp low/high state in mA 365 394 * @low_high_vol_lvl: charger voltage in temp low/high state in mV' 366 - * @battery_resistance: battery inner resistance in mOhm. 367 395 * @n_r_t_tbl_elements: number of elements in r_to_t_tbl 368 396 * @r_to_t_tbl: table containing resistance to temp points 369 - * @n_v_cap_tbl_elements: number of elements in v_to_cap_tbl 370 - * @v_to_cap_tbl: Voltage to capacity (in %) table 371 - * @n_batres_tbl_elements number of elements in the batres_tbl 372 - * @batres_tbl battery internal resistance vs temperature table 373 397 */ 374 398 struct ab8500_battery_type { 375 - int name; 376 399 int resis_high; 377 400 int resis_low; 378 - int charge_full_design; 379 - int nominal_voltage; 380 - int termination_vol; 381 - int termination_curr; 382 - int recharge_cap; 383 - int normal_cur_lvl; 384 - int normal_vol_lvl; 385 401 int maint_a_cur_lvl; 386 402 int maint_a_vol_lvl; 387 403 int maint_a_chg_timer_h; ··· 377 419 int maint_b_chg_timer_h; 378 420 int low_high_cur_lvl; 379 421 int low_high_vol_lvl; 380 - int battery_resistance; 381 422 int n_temp_tbl_elements; 382 423 const struct ab8500_res_to_temp *r_to_t_tbl; 383 - int n_v_cap_tbl_elements; 384 - const struct ab8500_v_to_cap *v_to_cap_tbl; 385 - int n_batres_tbl_elements; 386 - const struct batres_vs_temp *batres_tbl; 387 424 }; 388 425 389 426 /** ··· 399 446 400 447 /** 401 448 * struct ab8500_bm_charger_parameters - Charger specific parameters 402 - * @usb_volt_max: maximum allowed USB charger voltage in mV 403 - * @usb_curr_max: maximum allowed USB charger current in mA 404 - * @ac_volt_max: maximum allowed AC charger voltage in mV 405 - * @ac_curr_max: maximum allowed AC charger current in mA 449 + * @usb_volt_max_uv: maximum allowed USB charger voltage in uV 450 + * @usb_curr_max_ua: maximum allowed USB charger current in uA 451 + * @ac_volt_max_uv: maximum allowed AC charger voltage in uV 452 + * @ac_curr_max_ua: maximum allowed AC charger current in uA 406 453 */ 407 454 struct ab8500_bm_charger_parameters { 408 - int usb_volt_max; 409 - int usb_curr_max; 410 - int ac_volt_max; 411 - int ac_curr_max; 455 + int usb_volt_max_uv; 456 + int usb_curr_max_ua; 457 + int ac_volt_max_uv; 458 + int ac_curr_max_ua; 412 459 }; 413 460 414 461 /** 415 462 * struct ab8500_bm_data - ab8500 battery management data 416 - * @temp_under under this temp, charging is stopped 417 - * @temp_low between this temp and temp_under charging is reduced 418 - * @temp_high between this temp and temp_over charging is reduced 419 - * @temp_over over this temp, charging is stopped 463 + * @bi battery info from device tree 420 464 * @temp_now present battery temperature 421 465 * @temp_interval_chg temperature measurement interval in s when charging 422 466 * @temp_interval_nochg temperature measurement interval in s when not charging ··· 428 478 * @enable_overshoot flag to enable VBAT overshoot control 429 479 * @auto_trig flag to enable auto adc trigger 430 480 * @fg_res resistance of FG resistor in 0.1mOhm 431 - * @n_btypes number of elements in array bat_type 432 - * @batt_id index of the identified battery in array bat_type 433 481 * @interval_charging charge alg cycle period time when charging (sec) 434 482 * @interval_not_charging charge alg cycle period time when not charging (sec) 435 483 * @temp_hysteresis temperature hysteresis 436 484 * @gnd_lift_resistance Battery ground to phone ground resistance (mOhm) 437 - * @n_chg_out_curr number of elements in array chg_output_curr 438 - * @n_chg_in_curr number of elements in array chg_input_curr 439 - * @chg_output_curr charger output current level map 440 - * @chg_input_curr charger input current level map 441 485 * @maxi maximization parameters 442 486 * @cap_levels capacity in percent for the different capacity levels 443 487 * @bat_type table of supported battery types ··· 439 495 * @fg_params fuel gauge parameters 440 496 */ 441 497 struct ab8500_bm_data { 442 - int temp_under; 443 - int temp_low; 444 - int temp_high; 445 - int temp_over; 498 + struct power_supply_battery_info *bi; 446 499 int temp_now; 447 500 int temp_interval_chg; 448 501 int temp_interval_nochg; ··· 454 513 bool auto_trig; 455 514 enum ab8500_adc_therm adc_therm; 456 515 int fg_res; 457 - int n_btypes; 458 - int batt_id; 459 516 int interval_charging; 460 517 int interval_not_charging; 461 518 int temp_hysteresis; 462 519 int gnd_lift_resistance; 463 - int n_chg_out_curr; 464 - int n_chg_in_curr; 465 - int *chg_output_curr; 466 - int *chg_input_curr; 467 520 const struct ab8500_maxim_parameters *maxi; 468 521 const struct ab8500_bm_capacity_levels *cap_levels; 469 522 struct ab8500_battery_type *bat_type; ··· 482 547 int resist; 483 548 }; 484 549 485 - /** 486 - * struct batres_vs_temp - defines one point in a temp vs battery internal 487 - * resistance curve. 488 - * @temp: battery pack temperature in Celsius 489 - * @resist: battery internal reistance in mOhm 490 - */ 491 - struct batres_vs_temp { 492 - int temp; 493 - int resist; 494 - }; 495 - 496 550 /* Forward declaration */ 497 551 struct ab8500_fg; 498 552 ··· 494 570 int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res); 495 571 int ab8500_fg_inst_curr_started(struct ab8500_fg *di); 496 572 int ab8500_fg_inst_curr_done(struct ab8500_fg *di); 497 - int ab8500_bm_of_probe(struct device *dev, 498 - struct device_node *np, 573 + int ab8500_bm_of_probe(struct power_supply *psy, 499 574 struct ab8500_bm_data *bm); 575 + void ab8500_bm_of_remove(struct power_supply *psy, 576 + struct ab8500_bm_data *bm); 500 577 501 578 extern struct platform_driver ab8500_fg_driver; 502 579 extern struct platform_driver ab8500_btemp_driver;
+4 -4
drivers/power/supply/ab8500-chargalg.h
··· 31 31 * struct ux500_charger - power supply ux500 charger sub class 32 32 * @psy power supply base class 33 33 * @ops ux500 charger operations 34 - * @max_out_volt maximum output charger voltage in mV 35 - * @max_out_curr maximum output charger current in mA 34 + * @max_out_volt_uv maximum output charger voltage in uV 35 + * @max_out_curr_ua maximum output charger current in uA 36 36 * @enabled indicates if this charger is used or not 37 37 * @external external charger unit (pm2xxx) 38 38 */ 39 39 struct ux500_charger { 40 40 struct power_supply *psy; 41 41 struct ux500_charger_ops ops; 42 - int max_out_volt; 43 - int max_out_curr; 42 + int max_out_volt_uv; 43 + int max_out_curr_ua; 44 44 int wdt_refresh; 45 45 bool enabled; 46 46 bool external;
+136 -433
drivers/power/supply/ab8500_bmdata.c
··· 5 5 6 6 #include "ab8500-bm.h" 7 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 - */ 14 - const struct ab8500_res_to_temp ab8500_temp_tbl_a_thermistor[] = { 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 - EXPORT_SYMBOL(ab8500_temp_tbl_a_thermistor); 8 + /* Default: under this temperature, charging is stopped */ 9 + #define AB8500_TEMP_UNDER 3 10 + /* Default: between this temp and AB8500_TEMP_UNDER charging is reduced */ 11 + #define AB8500_TEMP_LOW 8 12 + /* Default: between this temp and AB8500_TEMP_OVER charging is reduced */ 13 + #define AB8500_TEMP_HIGH 43 14 + /* Default: over this temp, charging is stopped */ 15 + #define AB8500_TEMP_OVER 48 16 + /* Default: temperature hysteresis */ 17 + #define AB8500_TEMP_HYSTERESIS 3 32 18 33 - const int ab8500_temp_tbl_a_size = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor); 34 - EXPORT_SYMBOL(ab8500_temp_tbl_a_size); 35 - 36 - const struct ab8500_res_to_temp ab8500_temp_tbl_b_thermistor[] = { 37 - {-5, 200000}, 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 - }; 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); 57 - 58 - static const struct ab8500_v_to_cap cap_tbl_a_thermistor[] = { 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 - 81 - static const struct ab8500_v_to_cap cap_tbl_b_thermistor[] = { 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 - 104 - static const struct ab8500_v_to_cap cap_tbl[] = { 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}, 19 + static struct power_supply_battery_ocv_table ocv_cap_tbl[] = { 20 + { .ocv = 4186000, .capacity = 100}, 21 + { .ocv = 4163000, .capacity = 99}, 22 + { .ocv = 4114000, .capacity = 95}, 23 + { .ocv = 4068000, .capacity = 90}, 24 + { .ocv = 3990000, .capacity = 80}, 25 + { .ocv = 3926000, .capacity = 70}, 26 + { .ocv = 3898000, .capacity = 65}, 27 + { .ocv = 3866000, .capacity = 60}, 28 + { .ocv = 3833000, .capacity = 55}, 29 + { .ocv = 3812000, .capacity = 50}, 30 + { .ocv = 3787000, .capacity = 40}, 31 + { .ocv = 3768000, .capacity = 30}, 32 + { .ocv = 3747000, .capacity = 25}, 33 + { .ocv = 3730000, .capacity = 20}, 34 + { .ocv = 3705000, .capacity = 15}, 35 + { .ocv = 3699000, .capacity = 14}, 36 + { .ocv = 3684000, .capacity = 12}, 37 + { .ocv = 3672000, .capacity = 9}, 38 + { .ocv = 3657000, .capacity = 7}, 39 + { .ocv = 3638000, .capacity = 6}, 40 + { .ocv = 3556000, .capacity = 4}, 41 + { .ocv = 3424000, .capacity = 2}, 42 + { .ocv = 3317000, .capacity = 1}, 43 + { .ocv = 3094000, .capacity = 0}, 129 44 }; 130 45 131 46 /* ··· 67 152 68 153 /* 69 154 * Note that the batres_vs_temp table must be strictly sorted by falling 70 - * temperature values to work. 155 + * temperature values to work. Factory resistance is 300 mOhm and the 156 + * resistance values to the right are percentages of 300 mOhm. 71 157 */ 72 - static const struct batres_vs_temp temp_to_batres_tbl_thermistor[] = { 73 - { 40, 120}, 74 - { 30, 135}, 75 - { 20, 165}, 76 - { 10, 230}, 77 - { 00, 325}, 78 - {-10, 445}, 79 - {-20, 595}, 158 + static struct power_supply_resistance_temp_table temp_to_batres_tbl_thermistor[] = { 159 + { .temp = 40, .resistance = 40 /* 120 mOhm */ }, 160 + { .temp = 30, .resistance = 45 /* 135 mOhm */ }, 161 + { .temp = 20, .resistance = 55 /* 165 mOhm */ }, 162 + { .temp = 10, .resistance = 77 /* 230 mOhm */ }, 163 + { .temp = 00, .resistance = 108 /* 325 mOhm */ }, 164 + { .temp = -10, .resistance = 158 /* 445 mOhm */ }, 165 + { .temp = -20, .resistance = 198 /* 595 mOhm */ }, 80 166 }; 81 167 82 - /* 83 - * Note that the batres_vs_temp table must be strictly sorted by falling 84 - * temperature values to work. 85 - */ 86 - static const struct batres_vs_temp temp_to_batres_tbl_ext_thermistor[] = { 87 - { 60, 300}, 88 - { 30, 300}, 89 - { 20, 300}, 90 - { 10, 300}, 91 - { 00, 300}, 92 - {-10, 300}, 93 - {-20, 300}, 94 - }; 95 - 96 - /* battery resistance table for LI ION 9100 battery */ 97 - static const struct batres_vs_temp temp_to_batres_tbl_9100[] = { 98 - { 60, 180}, 99 - { 30, 180}, 100 - { 20, 180}, 101 - { 10, 180}, 102 - { 00, 180}, 103 - {-10, 180}, 104 - {-20, 180}, 105 - }; 106 - 107 - static struct ab8500_battery_type bat_type_thermistor[] = { 108 - [BATTERY_UNKNOWN] = { 109 - /* First element always represent the UNKNOWN battery */ 110 - .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN, 111 - .resis_high = 0, 112 - .resis_low = 0, 113 - .battery_resistance = 300, 114 - .charge_full_design = 612, 115 - .nominal_voltage = 3700, 116 - .termination_vol = 4050, 117 - .termination_curr = 200, 118 - .recharge_cap = 95, 119 - .normal_cur_lvl = 400, 120 - .normal_vol_lvl = 4100, 121 - .maint_a_cur_lvl = 400, 122 - .maint_a_vol_lvl = 4050, 123 - .maint_a_chg_timer_h = 60, 124 - .maint_b_cur_lvl = 400, 125 - .maint_b_vol_lvl = 4000, 126 - .maint_b_chg_timer_h = 200, 127 - .low_high_cur_lvl = 300, 128 - .low_high_vol_lvl = 4000, 129 - .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl), 130 - .r_to_t_tbl = temp_tbl, 131 - .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl), 132 - .v_to_cap_tbl = cap_tbl, 133 - .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), 134 - .batres_tbl = temp_to_batres_tbl_thermistor, 135 - }, 136 - { 137 - .name = POWER_SUPPLY_TECHNOLOGY_LIPO, 138 - .resis_high = 53407, 139 - .resis_low = 12500, 140 - .battery_resistance = 300, 141 - .charge_full_design = 900, 142 - .nominal_voltage = 3600, 143 - .termination_vol = 4150, 144 - .termination_curr = 80, 145 - .recharge_cap = 95, 146 - .normal_cur_lvl = 700, 147 - .normal_vol_lvl = 4200, 148 - .maint_a_cur_lvl = 600, 149 - .maint_a_vol_lvl = 4150, 150 - .maint_a_chg_timer_h = 60, 151 - .maint_b_cur_lvl = 600, 152 - .maint_b_vol_lvl = 4100, 153 - .maint_b_chg_timer_h = 200, 154 - .low_high_cur_lvl = 300, 155 - .low_high_vol_lvl = 4000, 156 - .n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_a_thermistor), 157 - .r_to_t_tbl = ab8500_temp_tbl_a_thermistor, 158 - .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_a_thermistor), 159 - .v_to_cap_tbl = cap_tbl_a_thermistor, 160 - .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), 161 - .batres_tbl = temp_to_batres_tbl_thermistor, 162 - 163 - }, 164 - { 165 - .name = POWER_SUPPLY_TECHNOLOGY_LIPO, 166 - .resis_high = 200000, 167 - .resis_low = 82869, 168 - .battery_resistance = 300, 169 - .charge_full_design = 900, 170 - .nominal_voltage = 3600, 171 - .termination_vol = 4150, 172 - .termination_curr = 80, 173 - .recharge_cap = 95, 174 - .normal_cur_lvl = 700, 175 - .normal_vol_lvl = 4200, 176 - .maint_a_cur_lvl = 600, 177 - .maint_a_vol_lvl = 4150, 178 - .maint_a_chg_timer_h = 60, 179 - .maint_b_cur_lvl = 600, 180 - .maint_b_vol_lvl = 4100, 181 - .maint_b_chg_timer_h = 200, 182 - .low_high_cur_lvl = 300, 183 - .low_high_vol_lvl = 4000, 184 - .n_temp_tbl_elements = ARRAY_SIZE(ab8500_temp_tbl_b_thermistor), 185 - .r_to_t_tbl = ab8500_temp_tbl_b_thermistor, 186 - .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl_b_thermistor), 187 - .v_to_cap_tbl = cap_tbl_b_thermistor, 188 - .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), 189 - .batres_tbl = temp_to_batres_tbl_thermistor, 190 - }, 191 - }; 192 - 193 - static struct ab8500_battery_type bat_type_ext_thermistor[] = { 194 - [BATTERY_UNKNOWN] = { 195 - /* First element always represent the UNKNOWN battery */ 196 - .name = POWER_SUPPLY_TECHNOLOGY_UNKNOWN, 197 - .resis_high = 0, 198 - .resis_low = 0, 199 - .battery_resistance = 300, 200 - .charge_full_design = 612, 201 - .nominal_voltage = 3700, 202 - .termination_vol = 4050, 203 - .termination_curr = 200, 204 - .recharge_cap = 95, 205 - .normal_cur_lvl = 400, 206 - .normal_vol_lvl = 4100, 207 - .maint_a_cur_lvl = 400, 208 - .maint_a_vol_lvl = 4050, 209 - .maint_a_chg_timer_h = 60, 210 - .maint_b_cur_lvl = 400, 211 - .maint_b_vol_lvl = 4000, 212 - .maint_b_chg_timer_h = 200, 213 - .low_high_cur_lvl = 300, 214 - .low_high_vol_lvl = 4000, 215 - .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl), 216 - .r_to_t_tbl = temp_tbl, 217 - .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl), 218 - .v_to_cap_tbl = cap_tbl, 219 - .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), 220 - .batres_tbl = temp_to_batres_tbl_thermistor, 221 - }, 222 - /* 223 - * These are the batteries that doesn't have an internal NTC resistor to measure 224 - * its temperature. The temperature in this case is measure with a NTC placed 225 - * near the battery but on the PCB. 226 - */ 227 - { 228 - .name = POWER_SUPPLY_TECHNOLOGY_LIPO, 229 - .resis_high = 76000, 230 - .resis_low = 53000, 231 - .battery_resistance = 300, 232 - .charge_full_design = 900, 233 - .nominal_voltage = 3700, 234 - .termination_vol = 4150, 235 - .termination_curr = 100, 236 - .recharge_cap = 95, 237 - .normal_cur_lvl = 700, 238 - .normal_vol_lvl = 4200, 239 - .maint_a_cur_lvl = 600, 240 - .maint_a_vol_lvl = 4150, 241 - .maint_a_chg_timer_h = 60, 242 - .maint_b_cur_lvl = 600, 243 - .maint_b_vol_lvl = 4100, 244 - .maint_b_chg_timer_h = 200, 245 - .low_high_cur_lvl = 300, 246 - .low_high_vol_lvl = 4000, 247 - .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl), 248 - .r_to_t_tbl = temp_tbl, 249 - .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl), 250 - .v_to_cap_tbl = cap_tbl, 251 - .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), 252 - .batres_tbl = temp_to_batres_tbl_thermistor, 253 - }, 254 - { 255 - .name = POWER_SUPPLY_TECHNOLOGY_LION, 256 - .resis_high = 30000, 257 - .resis_low = 10000, 258 - .battery_resistance = 300, 259 - .charge_full_design = 950, 260 - .nominal_voltage = 3700, 261 - .termination_vol = 4150, 262 - .termination_curr = 100, 263 - .recharge_cap = 95, 264 - .normal_cur_lvl = 700, 265 - .normal_vol_lvl = 4200, 266 - .maint_a_cur_lvl = 600, 267 - .maint_a_vol_lvl = 4150, 268 - .maint_a_chg_timer_h = 60, 269 - .maint_b_cur_lvl = 600, 270 - .maint_b_vol_lvl = 4100, 271 - .maint_b_chg_timer_h = 200, 272 - .low_high_cur_lvl = 300, 273 - .low_high_vol_lvl = 4000, 274 - .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl), 275 - .r_to_t_tbl = temp_tbl, 276 - .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl), 277 - .v_to_cap_tbl = cap_tbl, 278 - .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), 279 - .batres_tbl = temp_to_batres_tbl_thermistor, 280 - }, 281 - { 282 - .name = POWER_SUPPLY_TECHNOLOGY_LION, 283 - .resis_high = 95000, 284 - .resis_low = 76001, 285 - .battery_resistance = 300, 286 - .charge_full_design = 950, 287 - .nominal_voltage = 3700, 288 - .termination_vol = 4150, 289 - .termination_curr = 100, 290 - .recharge_cap = 95, 291 - .normal_cur_lvl = 700, 292 - .normal_vol_lvl = 4200, 293 - .maint_a_cur_lvl = 600, 294 - .maint_a_vol_lvl = 4150, 295 - .maint_a_chg_timer_h = 60, 296 - .maint_b_cur_lvl = 600, 297 - .maint_b_vol_lvl = 4100, 298 - .maint_b_chg_timer_h = 200, 299 - .low_high_cur_lvl = 300, 300 - .low_high_vol_lvl = 4000, 301 - .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl), 302 - .r_to_t_tbl = temp_tbl, 303 - .n_v_cap_tbl_elements = ARRAY_SIZE(cap_tbl), 304 - .v_to_cap_tbl = cap_tbl, 305 - .n_batres_tbl_elements = ARRAY_SIZE(temp_to_batres_tbl_thermistor), 306 - .batres_tbl = temp_to_batres_tbl_thermistor, 307 - }, 168 + /* Default battery type for reference designs is the unknown type */ 169 + static struct ab8500_battery_type bat_type_thermistor_unknown = { 170 + .resis_high = 0, 171 + .resis_low = 0, 172 + .maint_a_cur_lvl = 400, 173 + .maint_a_vol_lvl = 4050, 174 + .maint_a_chg_timer_h = 60, 175 + .maint_b_cur_lvl = 400, 176 + .maint_b_vol_lvl = 4000, 177 + .maint_b_chg_timer_h = 200, 178 + .low_high_cur_lvl = 300, 179 + .low_high_vol_lvl = 4000, 180 + .n_temp_tbl_elements = ARRAY_SIZE(temp_tbl), 181 + .r_to_t_tbl = temp_tbl, 308 182 }; 309 183 310 184 static const struct ab8500_bm_capacity_levels cap_levels = { ··· 113 409 .high_curr_time = 60, 114 410 .accu_charging = 30, 115 411 .accu_high_curr = 30, 116 - .high_curr_threshold = 50, 117 - .lowbat_threshold = 3100, 412 + .high_curr_threshold_ua = 50000, 413 + .lowbat_threshold_uv = 3100000, 118 414 .battok_falling_th_sel0 = 2860, 119 415 .battok_raising_th_sel1 = 2860, 120 416 .maint_thres = 95, ··· 128 424 129 425 static const struct ab8500_maxim_parameters ab8500_maxi_params = { 130 426 .ena_maxi = true, 131 - .chg_curr = 910, 427 + .chg_curr_ua = 910000, 132 428 .wait_cycles = 10, 133 - .charger_curr_step = 100, 429 + .charger_curr_step_ua = 100000, 134 430 }; 135 431 136 432 static const struct ab8500_bm_charger_parameters chg = { 137 - .usb_volt_max = 5500, 138 - .usb_curr_max = 1500, 139 - .ac_volt_max = 7500, 140 - .ac_curr_max = 1500, 433 + .usb_volt_max_uv = 5500000, 434 + .usb_curr_max_ua = 1500000, 435 + .ac_volt_max_uv = 7500000, 436 + .ac_curr_max_ua = 1500000, 141 437 }; 142 438 143 - /* 144 - * This array maps the raw hex value to charger output current used by the 145 - * AB8500 values 146 - */ 147 - static int ab8500_charge_output_curr_map[] = { 148 - 100, 200, 300, 400, 500, 600, 700, 800, 149 - 900, 1000, 1100, 1200, 1300, 1400, 1500, 1500, 150 - }; 151 - 152 - /* 153 - * This array maps the raw hex value to charger input current used by the 154 - * AB8500 values 155 - */ 156 - static int ab8500_charge_input_curr_map[] = { 157 - 50, 98, 193, 290, 380, 450, 500, 600, 158 - 700, 800, 900, 1000, 1100, 1300, 1400, 1500, 159 - }; 160 - 439 + /* This is referenced directly in the charger code */ 161 440 struct ab8500_bm_data ab8500_bm_data = { 162 - .temp_under = 3, 163 - .temp_low = 8, 164 - .temp_high = 43, 165 - .temp_over = 48, 166 441 .main_safety_tmr_h = 4, 167 442 .temp_interval_chg = 20, 168 443 .temp_interval_nochg = 120, ··· 155 472 .enable_overshoot = false, 156 473 .fg_res = 100, 157 474 .cap_levels = &cap_levels, 158 - .bat_type = bat_type_thermistor, 159 - .n_btypes = ARRAY_SIZE(bat_type_thermistor), 160 - .batt_id = 0, 475 + .bat_type = &bat_type_thermistor_unknown, 161 476 .interval_charging = 5, 162 477 .interval_not_charging = 120, 163 - .temp_hysteresis = 3, 164 478 .gnd_lift_resistance = 34, 165 - .chg_output_curr = ab8500_charge_output_curr_map, 166 - .n_chg_out_curr = ARRAY_SIZE(ab8500_charge_output_curr_map), 167 479 .maxi = &ab8500_maxi_params, 168 480 .chg_params = &chg, 169 481 .fg_params = &fg, 170 - .chg_input_curr = ab8500_charge_input_curr_map, 171 - .n_chg_in_curr = ARRAY_SIZE(ab8500_charge_input_curr_map), 172 482 }; 173 483 174 - int ab8500_bm_of_probe(struct device *dev, 175 - struct device_node *np, 484 + int ab8500_bm_of_probe(struct power_supply *psy, 176 485 struct ab8500_bm_data *bm) 177 486 { 178 - const struct batres_vs_temp *tmp_batres_tbl; 179 - struct device_node *battery_node; 180 - const char *btech; 181 - int i; 487 + struct power_supply_battery_info *bi; 488 + struct device *dev = &psy->dev; 489 + int ret; 182 490 183 - battery_node = of_parse_phandle(np, "monitored-battery", 0); 184 - if (!battery_node) { 185 - dev_err(dev, "battery node or reference missing\n"); 186 - return -EINVAL; 491 + ret = power_supply_get_battery_info(psy, &bm->bi); 492 + if (ret) { 493 + dev_err(dev, "cannot retrieve battery info\n"); 494 + return ret; 495 + } 496 + bi = bm->bi; 497 + 498 + /* Fill in defaults for any data missing from the device tree */ 499 + if (bi->charge_full_design_uah < 0) 500 + /* The default capacity is 612 mAh for unknown batteries */ 501 + bi->charge_full_design_uah = 612000; 502 + 503 + /* 504 + * All of these voltages need to be specified or we will simply 505 + * fall back to safe defaults. 506 + */ 507 + if ((bi->voltage_min_design_uv < 0) || 508 + (bi->voltage_max_design_uv < 0) || 509 + (bi->overvoltage_limit_uv < 0)) { 510 + /* Nominal voltage is 3.7V for unknown batteries */ 511 + bi->voltage_min_design_uv = 3700000; 512 + bi->voltage_max_design_uv = 3700000; 513 + /* Termination voltage (overcharge limit) 4.05V */ 514 + bi->overvoltage_limit_uv = 4050000; 187 515 } 188 516 189 - btech = of_get_property(battery_node, "stericsson,battery-type", NULL); 190 - if (!btech) { 191 - dev_warn(dev, "missing property battery-name/type\n"); 192 - of_node_put(battery_node); 193 - return -EINVAL; 517 + if (bi->constant_charge_current_max_ua < 0) 518 + bi->constant_charge_current_max_ua = 400000; 519 + 520 + if (bi->constant_charge_voltage_max_uv < 0) 521 + bi->constant_charge_voltage_max_uv = 4100000; 522 + 523 + if (bi->charge_term_current_ua) 524 + /* Charging stops when we drop below this current */ 525 + bi->charge_term_current_ua = 200000; 526 + 527 + /* 528 + * Internal resistance and factory resistance are tightly coupled 529 + * so both MUST be defined or we fall back to defaults. 530 + */ 531 + if ((bi->factory_internal_resistance_uohm < 0) || 532 + !bi->resist_table) { 533 + bi->factory_internal_resistance_uohm = 300000; 534 + bi->resist_table = temp_to_batres_tbl_thermistor; 535 + bi->resist_table_size = ARRAY_SIZE(temp_to_batres_tbl_thermistor); 194 536 } 195 537 196 - if (strncmp(btech, "LION", 4) == 0) { 197 - bm->no_maintenance = true; 198 - bm->chg_unknown_bat = true; 199 - bm->bat_type[BATTERY_UNKNOWN].charge_full_design = 2600; 200 - bm->bat_type[BATTERY_UNKNOWN].termination_vol = 4150; 201 - bm->bat_type[BATTERY_UNKNOWN].recharge_cap = 95; 202 - bm->bat_type[BATTERY_UNKNOWN].normal_cur_lvl = 520; 203 - bm->bat_type[BATTERY_UNKNOWN].normal_vol_lvl = 4200; 538 + if (!bi->ocv_table[0]) { 539 + /* Default capacity table at say 25 degrees Celsius */ 540 + bi->ocv_temp[0] = 25; 541 + bi->ocv_table[0] = ocv_cap_tbl; 542 + bi->ocv_table_size[0] = ARRAY_SIZE(ocv_cap_tbl); 204 543 } 205 544 206 - if (of_property_read_bool(battery_node, "thermistor-on-batctrl")) { 207 - if (strncmp(btech, "LION", 4) == 0) 208 - tmp_batres_tbl = temp_to_batres_tbl_9100; 209 - else 210 - tmp_batres_tbl = temp_to_batres_tbl_thermistor; 211 - } else { 212 - bm->n_btypes = 4; 213 - bm->bat_type = bat_type_ext_thermistor; 214 - bm->adc_therm = AB8500_ADC_THERM_BATTEMP; 215 - tmp_batres_tbl = temp_to_batres_tbl_ext_thermistor; 216 - } 217 - 218 - /* select the battery resolution table */ 219 - for (i = 0; i < bm->n_btypes; ++i) 220 - bm->bat_type[i].batres_tbl = tmp_batres_tbl; 221 - 222 - of_node_put(battery_node); 545 + if (bi->temp_min == INT_MIN) 546 + bi->temp_min = AB8500_TEMP_UNDER; 547 + if (bi->temp_max == INT_MAX) 548 + bi->temp_max = AB8500_TEMP_OVER; 549 + if (bi->temp_alert_min == INT_MIN) 550 + bi->temp_alert_min = AB8500_TEMP_LOW; 551 + if (bi->temp_alert_max == INT_MAX) 552 + bi->temp_alert_max = AB8500_TEMP_HIGH; 553 + bm->temp_hysteresis = AB8500_TEMP_HYSTERESIS; 223 554 224 555 return 0; 556 + } 557 + 558 + void ab8500_bm_of_remove(struct power_supply *psy, 559 + struct ab8500_bm_data *bm) 560 + { 561 + power_supply_put_battery_info(psy, bm->bi); 225 562 }
+31 -34
drivers/power/supply/ab8500_btemp.c
··· 451 451 */ 452 452 static int ab8500_btemp_measure_temp(struct ab8500_btemp *di) 453 453 { 454 + struct power_supply_battery_info *bi = di->bm->bi; 454 455 int temp, ret; 455 456 static int prev; 456 457 int rbat, rntc, vntc; 457 - u8 id; 458 458 459 - id = di->bm->batt_id; 460 - 461 - if (di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL && 462 - id != BATTERY_UNKNOWN) { 459 + if ((di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL) && 460 + (bi && (bi->technology == POWER_SUPPLY_TECHNOLOGY_UNKNOWN))) { 463 461 464 462 rbat = ab8500_btemp_get_batctrl_res(di); 465 463 if (rbat < 0) { ··· 471 473 } 472 474 473 475 temp = ab8500_btemp_res_to_temp(di, 474 - di->bm->bat_type[id].r_to_t_tbl, 475 - di->bm->bat_type[id].n_temp_tbl_elements, rbat); 476 + di->bm->bat_type->r_to_t_tbl, 477 + di->bm->bat_type->n_temp_tbl_elements, rbat); 476 478 } else { 477 479 ret = iio_read_channel_processed(di->btemp_ball, &vntc); 478 480 if (ret < 0) { ··· 488 490 rntc = 230000 * vntc / (VTVOUT_V - vntc); 489 491 490 492 temp = ab8500_btemp_res_to_temp(di, 491 - di->bm->bat_type[id].r_to_t_tbl, 492 - di->bm->bat_type[id].n_temp_tbl_elements, rntc); 493 + di->bm->bat_type->r_to_t_tbl, 494 + di->bm->bat_type->n_temp_tbl_elements, rntc); 493 495 prev = temp; 494 496 } 495 497 dev_dbg(di->dev, "Battery temperature is %d\n", temp); ··· 510 512 u8 i; 511 513 512 514 di->curr_source = BTEMP_BATCTRL_CURR_SRC_7UA; 513 - di->bm->batt_id = BATTERY_UNKNOWN; 514 515 515 516 res = ab8500_btemp_get_batctrl_res(di); 516 517 if (res < 0) { ··· 517 520 return -ENXIO; 518 521 } 519 522 520 - /* BATTERY_UNKNOWN is defined on position 0, skip it! */ 521 - for (i = BATTERY_UNKNOWN + 1; i < di->bm->n_btypes; i++) { 522 - if ((res <= di->bm->bat_type[i].resis_high) && 523 - (res >= di->bm->bat_type[i].resis_low)) { 524 - dev_dbg(di->dev, "Battery detected on %s" 525 - " low %d < res %d < high: %d" 526 - " index: %d\n", 527 - di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL ? 528 - "BATCTRL" : "BATTEMP", 529 - di->bm->bat_type[i].resis_low, res, 530 - di->bm->bat_type[i].resis_high, i); 531 - 532 - di->bm->batt_id = i; 533 - break; 534 - } 535 - } 536 - 537 - if (di->bm->batt_id == BATTERY_UNKNOWN) { 523 + if ((res <= di->bm->bat_type->resis_high) && 524 + (res >= di->bm->bat_type->resis_low)) { 525 + dev_info(di->dev, "Battery detected on %s" 526 + " low %d < res %d < high: %d" 527 + " index: %d\n", 528 + di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL ? 529 + "BATCTRL" : "BATTEMP", 530 + di->bm->bat_type->resis_low, res, 531 + di->bm->bat_type->resis_high, i); 532 + } else { 538 533 dev_warn(di->dev, "Battery identified as unknown" 539 - ", resistance %d Ohm\n", res); 534 + ", resistance %d Ohm\n", res); 540 535 return -ENXIO; 541 536 } 542 537 543 538 /* 544 539 * We only have to change current source if the 545 - * detected type is Type 1. 540 + * detected type is Type 1 (LIPO) resis_high = 53407, resis_low = 12500 541 + * if someone hacks this in. 542 + * 543 + * FIXME: make sure this is done automatically for the batteries 544 + * that need it. 546 545 */ 547 - if (di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL && 548 - di->bm->batt_id == 1) { 546 + if ((di->bm->adc_therm == AB8500_ADC_THERM_BATCTRL) && 547 + (di->bm->bi && (di->bm->bi->technology == POWER_SUPPLY_TECHNOLOGY_LIPO)) && 548 + (res <= 53407) && (res >= 12500)) { 549 549 dev_dbg(di->dev, "Set BATCTRL current source to 20uA\n"); 550 550 di->curr_source = BTEMP_BATCTRL_CURR_SRC_20UA; 551 551 } 552 552 553 - return di->bm->batt_id; 553 + return 0; 554 554 } 555 555 556 556 /** ··· 808 814 val->intval = 1; 809 815 break; 810 816 case POWER_SUPPLY_PROP_TECHNOLOGY: 811 - val->intval = di->bm->bat_type[di->bm->batt_id].name; 817 + if (di->bm->bi) 818 + val->intval = di->bm->bi->technology; 819 + else 820 + val->intval = POWER_SUPPLY_TECHNOLOGY_UNKNOWN; 812 821 break; 813 822 case POWER_SUPPLY_PROP_TEMP: 814 823 val->intval = ab8500_btemp_get_temp(di);
+158 -157
drivers/power/supply/ab8500_chargalg.c
··· 46 46 /* Five minutes expressed in seconds */ 47 47 #define FIVE_MINUTES_IN_SECONDS 300 48 48 49 - #define CHARGALG_CURR_STEP_LOW 0 50 - #define CHARGALG_CURR_STEP_HIGH 100 49 + #define CHARGALG_CURR_STEP_LOW_UA 0 50 + #define CHARGALG_CURR_STEP_HIGH_UA 100000 51 + 52 + /* 53 + * This is the battery capacity limit that will trigger a new 54 + * full charging cycle in the case where maintenance charging 55 + * has been disabled 56 + */ 57 + #define AB8500_RECHARGE_CAP 95 51 58 52 59 enum ab8500_chargers { 53 60 NO_CHG, ··· 70 63 enum ab8500_chargers charger_type; 71 64 bool usb_chg_ok; 72 65 bool ac_chg_ok; 73 - int usb_volt; 74 - int usb_curr; 75 - int ac_volt; 76 - int ac_curr; 77 - int usb_vset; 78 - int usb_iset; 79 - int ac_vset; 80 - int ac_iset; 66 + int usb_volt_uv; 67 + int usb_curr_ua; 68 + int ac_volt_uv; 69 + int ac_curr_ua; 70 + int usb_vset_uv; 71 + int usb_iset_ua; 72 + int ac_vset_uv; 73 + int ac_iset_ua; 81 74 }; 82 75 83 76 struct ab8500_chargalg_suspension_status { ··· 88 81 89 82 struct ab8500_chargalg_current_step_status { 90 83 bool curr_step_change; 91 - int curr_step; 84 + int curr_step_ua; 92 85 }; 93 86 94 87 struct ab8500_chargalg_battery_data { 95 88 int temp; 96 - int volt; 97 - int avg_curr; 98 - int inst_curr; 89 + int volt_uv; 90 + int avg_curr_ua; 91 + int inst_curr_ua; 99 92 int percent; 100 93 }; 101 94 ··· 184 177 185 178 /** 186 179 * struct ab8500_charge_curr_maximization - Charger maximization parameters 187 - * @original_iset: the non optimized/maximised charger current 188 - * @current_iset: the charging current used at this moment 189 - * @test_delta_i: the delta between the current we want to charge and the 180 + * @original_iset_ua: the non optimized/maximised charger current 181 + * @current_iset_ua: the charging current used at this moment 182 + * @test_delta_i_ua: the delta between the current we want to charge and the 190 183 current that is really going into the battery 191 184 * @condition_cnt: number of iterations needed before a new charger current 192 185 is set 193 - * @max_current: maximum charger current 186 + * @max_current_ua: maximum charger current 194 187 * @wait_cnt: to avoid too fast current step down in case of charger 195 188 * voltage collapse, we insert this delay between step 196 189 * down ··· 198 191 increased 199 192 */ 200 193 struct ab8500_charge_curr_maximization { 201 - int original_iset; 202 - int current_iset; 203 - int test_delta_i; 194 + int original_iset_ua; 195 + int current_iset_ua; 196 + int test_delta_i_ua; 204 197 int condition_cnt; 205 - int max_current; 198 + int max_current_ua; 206 199 int wait_cnt; 207 200 u8 level; 208 201 }; ··· 352 345 353 346 static int ab8500_chargalg_check_charger_enable(struct ab8500_chargalg *di) 354 347 { 348 + struct power_supply_battery_info *bi = di->bm->bi; 349 + 355 350 switch (di->charge_state) { 356 351 case STATE_NORMAL: 357 352 case STATE_MAINTENANCE_A: ··· 365 356 366 357 if (di->chg_info.charger_type & USB_CHG) { 367 358 return di->usb_chg->ops.check_enable(di->usb_chg, 368 - di->bm->bat_type[di->bm->batt_id].normal_vol_lvl, 369 - di->bm->bat_type[di->bm->batt_id].normal_cur_lvl); 359 + bi->constant_charge_voltage_max_uv, 360 + bi->constant_charge_current_max_ua); 370 361 } else if ((di->chg_info.charger_type & AC_CHG) && 371 362 !(di->ac_chg->external)) { 372 363 return di->ac_chg->ops.check_enable(di->ac_chg, 373 - di->bm->bat_type[di->bm->batt_id].normal_vol_lvl, 374 - di->bm->bat_type[di->bm->batt_id].normal_cur_lvl); 364 + bi->constant_charge_voltage_max_uv, 365 + bi->constant_charge_current_max_ua); 375 366 } 376 367 return 0; 377 368 } ··· 546 537 * ab8500_chargalg_ac_en() - Turn on/off the AC charger 547 538 * @di: pointer to the ab8500_chargalg structure 548 539 * @enable: charger on/off 549 - * @vset: requested charger output voltage 550 - * @iset: requested charger output current 540 + * @vset_uv: requested charger output voltage in microvolt 541 + * @iset_ua: requested charger output current in microampere 551 542 * 552 543 * The AC charger will be turned on/off with the requested charge voltage and 553 544 * current 554 545 */ 555 546 static int ab8500_chargalg_ac_en(struct ab8500_chargalg *di, int enable, 556 - int vset, int iset) 547 + int vset_uv, int iset_ua) 557 548 { 558 549 static int ab8500_chargalg_ex_ac_enable_toggle; 559 550 ··· 561 552 return -ENXIO; 562 553 563 554 /* Select maximum of what both the charger and the battery supports */ 564 - if (di->ac_chg->max_out_volt) 565 - vset = min(vset, di->ac_chg->max_out_volt); 566 - if (di->ac_chg->max_out_curr) 567 - iset = min(iset, di->ac_chg->max_out_curr); 555 + if (di->ac_chg->max_out_volt_uv) 556 + vset_uv = min(vset_uv, di->ac_chg->max_out_volt_uv); 557 + if (di->ac_chg->max_out_curr_ua) 558 + iset_ua = min(iset_ua, di->ac_chg->max_out_curr_ua); 568 559 569 - di->chg_info.ac_iset = iset; 570 - di->chg_info.ac_vset = vset; 560 + di->chg_info.ac_iset_ua = iset_ua; 561 + di->chg_info.ac_vset_uv = vset_uv; 571 562 572 563 /* Enable external charger */ 573 564 if (enable && di->ac_chg->external && ··· 577 568 ab8500_chargalg_ex_ac_enable_toggle++; 578 569 } 579 570 580 - return di->ac_chg->ops.enable(di->ac_chg, enable, vset, iset); 571 + return di->ac_chg->ops.enable(di->ac_chg, enable, vset_uv, iset_ua); 581 572 } 582 573 583 574 /** 584 575 * ab8500_chargalg_usb_en() - Turn on/off the USB charger 585 576 * @di: pointer to the ab8500_chargalg structure 586 577 * @enable: charger on/off 587 - * @vset: requested charger output voltage 588 - * @iset: requested charger output current 578 + * @vset_uv: requested charger output voltage in microvolt 579 + * @iset_ua: requested charger output current in microampere 589 580 * 590 581 * The USB charger will be turned on/off with the requested charge voltage and 591 582 * current 592 583 */ 593 584 static int ab8500_chargalg_usb_en(struct ab8500_chargalg *di, int enable, 594 - int vset, int iset) 585 + int vset_uv, int iset_ua) 595 586 { 596 587 if (!di->usb_chg || !di->usb_chg->ops.enable) 597 588 return -ENXIO; 598 589 599 590 /* Select maximum of what both the charger and the battery supports */ 600 - if (di->usb_chg->max_out_volt) 601 - vset = min(vset, di->usb_chg->max_out_volt); 602 - if (di->usb_chg->max_out_curr) 603 - iset = min(iset, di->usb_chg->max_out_curr); 591 + if (di->usb_chg->max_out_volt_uv) 592 + vset_uv = min(vset_uv, di->usb_chg->max_out_volt_uv); 593 + if (di->usb_chg->max_out_curr_ua) 594 + iset_ua = min(iset_ua, di->usb_chg->max_out_curr_ua); 604 595 605 - di->chg_info.usb_iset = iset; 606 - di->chg_info.usb_vset = vset; 596 + di->chg_info.usb_iset_ua = iset_ua; 597 + di->chg_info.usb_vset_uv = vset_uv; 607 598 608 - return di->usb_chg->ops.enable(di->usb_chg, enable, vset, iset); 599 + return di->usb_chg->ops.enable(di->usb_chg, enable, vset_uv, iset_ua); 609 600 } 610 601 611 602 /** 612 603 * ab8500_chargalg_update_chg_curr() - Update charger current 613 604 * @di: pointer to the ab8500_chargalg structure 614 - * @iset: requested charger output current 605 + * @iset_ua: requested charger output current in microampere 615 606 * 616 607 * The charger output current will be updated for the charger 617 608 * that is currently in use 618 609 */ 619 610 static int ab8500_chargalg_update_chg_curr(struct ab8500_chargalg *di, 620 - int iset) 611 + int iset_ua) 621 612 { 622 613 /* Check if charger exists and update current if charging */ 623 614 if (di->ac_chg && di->ac_chg->ops.update_curr && ··· 626 617 * Select maximum of what both the charger 627 618 * and the battery supports 628 619 */ 629 - if (di->ac_chg->max_out_curr) 630 - iset = min(iset, di->ac_chg->max_out_curr); 620 + if (di->ac_chg->max_out_curr_ua) 621 + iset_ua = min(iset_ua, di->ac_chg->max_out_curr_ua); 631 622 632 - di->chg_info.ac_iset = iset; 623 + di->chg_info.ac_iset_ua = iset_ua; 633 624 634 - return di->ac_chg->ops.update_curr(di->ac_chg, iset); 625 + return di->ac_chg->ops.update_curr(di->ac_chg, iset_ua); 635 626 } else if (di->usb_chg && di->usb_chg->ops.update_curr && 636 627 di->chg_info.charger_type & USB_CHG) { 637 628 /* 638 629 * Select maximum of what both the charger 639 630 * and the battery supports 640 631 */ 641 - if (di->usb_chg->max_out_curr) 642 - iset = min(iset, di->usb_chg->max_out_curr); 632 + if (di->usb_chg->max_out_curr_ua) 633 + iset_ua = min(iset_ua, di->usb_chg->max_out_curr_ua); 643 634 644 - di->chg_info.usb_iset = iset; 635 + di->chg_info.usb_iset_ua = iset_ua; 645 636 646 - return di->usb_chg->ops.update_curr(di->usb_chg, iset); 637 + return di->usb_chg->ops.update_curr(di->usb_chg, iset_ua); 647 638 } 648 639 649 640 return -ENXIO; ··· 692 683 /** 693 684 * ab8500_chargalg_start_charging() - Start the charger 694 685 * @di: pointer to the ab8500_chargalg structure 695 - * @vset: requested charger output voltage 696 - * @iset: requested charger output current 686 + * @vset_uv: requested charger output voltage in microvolt 687 + * @iset_ua: requested charger output current in microampere 697 688 * 698 689 * A charger will be enabled depending on the requested charger type that was 699 690 * detected previously. 700 691 */ 701 692 static void ab8500_chargalg_start_charging(struct ab8500_chargalg *di, 702 - int vset, int iset) 693 + int vset_uv, int iset_ua) 703 694 { 704 695 switch (di->chg_info.charger_type) { 705 696 case AC_CHG: 706 697 dev_dbg(di->dev, 707 - "AC parameters: Vset %d, Ich %d\n", vset, iset); 698 + "AC parameters: Vset %d, Ich %d\n", vset_uv, iset_ua); 708 699 ab8500_chargalg_usb_en(di, false, 0, 0); 709 - ab8500_chargalg_ac_en(di, true, vset, iset); 700 + ab8500_chargalg_ac_en(di, true, vset_uv, iset_ua); 710 701 break; 711 702 712 703 case USB_CHG: 713 704 dev_dbg(di->dev, 714 - "USB parameters: Vset %d, Ich %d\n", vset, iset); 705 + "USB parameters: Vset %d, Ich %d\n", vset_uv, iset_ua); 715 706 ab8500_chargalg_ac_en(di, false, 0, 0); 716 - ab8500_chargalg_usb_en(di, true, vset, iset); 707 + ab8500_chargalg_usb_en(di, true, vset_uv, iset_ua); 717 708 break; 718 709 719 710 default: ··· 731 722 */ 732 723 static void ab8500_chargalg_check_temp(struct ab8500_chargalg *di) 733 724 { 734 - if (di->batt_data.temp > (di->bm->temp_low + di->t_hyst_norm) && 735 - di->batt_data.temp < (di->bm->temp_high - di->t_hyst_norm)) { 725 + struct power_supply_battery_info *bi = di->bm->bi; 726 + 727 + if (di->batt_data.temp > (bi->temp_alert_min + di->t_hyst_norm) && 728 + di->batt_data.temp < (bi->temp_alert_max - di->t_hyst_norm)) { 736 729 /* Temp OK! */ 737 730 di->events.btemp_underover = false; 738 731 di->events.btemp_lowhigh = false; 739 732 di->t_hyst_norm = 0; 740 733 di->t_hyst_lowhigh = 0; 741 734 } else { 742 - if (((di->batt_data.temp >= di->bm->temp_high) && 735 + if (((di->batt_data.temp >= bi->temp_alert_max) && 743 736 (di->batt_data.temp < 744 - (di->bm->temp_over - di->t_hyst_lowhigh))) || 737 + (bi->temp_max - di->t_hyst_lowhigh))) || 745 738 ((di->batt_data.temp > 746 - (di->bm->temp_under + di->t_hyst_lowhigh)) && 747 - (di->batt_data.temp <= di->bm->temp_low))) { 739 + (bi->temp_min + di->t_hyst_lowhigh)) && 740 + (di->batt_data.temp <= bi->temp_alert_min))) { 748 741 /* TEMP minor!!!!! */ 749 742 di->events.btemp_underover = false; 750 743 di->events.btemp_lowhigh = true; 751 744 di->t_hyst_norm = di->bm->temp_hysteresis; 752 745 di->t_hyst_lowhigh = 0; 753 - } else if (di->batt_data.temp <= di->bm->temp_under || 754 - di->batt_data.temp >= di->bm->temp_over) { 746 + } else if (di->batt_data.temp <= bi->temp_min || 747 + di->batt_data.temp >= bi->temp_max) { 755 748 /* TEMP major!!!!! */ 756 749 di->events.btemp_underover = true; 757 750 di->events.btemp_lowhigh = false; ··· 777 766 */ 778 767 static void ab8500_chargalg_check_charger_voltage(struct ab8500_chargalg *di) 779 768 { 780 - if (di->chg_info.usb_volt > di->bm->chg_params->usb_volt_max) 769 + if (di->chg_info.usb_volt_uv > di->bm->chg_params->usb_volt_max_uv) 781 770 di->chg_info.usb_chg_ok = false; 782 771 else 783 772 di->chg_info.usb_chg_ok = true; 784 773 785 - if (di->chg_info.ac_volt > di->bm->chg_params->ac_volt_max) 774 + if (di->chg_info.ac_volt_uv > di->bm->chg_params->ac_volt_max_uv) 786 775 di->chg_info.ac_chg_ok = false; 787 776 else 788 777 di->chg_info.ac_chg_ok = true; ··· 801 790 { 802 791 if (di->charge_status == POWER_SUPPLY_STATUS_CHARGING && 803 792 di->charge_state == STATE_NORMAL && 804 - !di->maintenance_chg && (di->batt_data.volt >= 805 - di->bm->bat_type[di->bm->batt_id].termination_vol || 793 + !di->maintenance_chg && (di->batt_data.volt_uv >= 794 + di->bm->bi->overvoltage_limit_uv || 806 795 di->events.usb_cv_active || di->events.ac_cv_active) && 807 - di->batt_data.avg_curr < 808 - di->bm->bat_type[di->bm->batt_id].termination_curr && 809 - di->batt_data.avg_curr > 0) { 796 + di->batt_data.avg_curr_ua < 797 + di->bm->bi->charge_term_current_ua && 798 + di->batt_data.avg_curr_ua > 0) { 810 799 if (++di->eoc_cnt >= EOC_COND_CNT) { 811 800 di->eoc_cnt = 0; 812 801 di->charge_status = POWER_SUPPLY_STATUS_FULL; ··· 827 816 828 817 static void init_maxim_chg_curr(struct ab8500_chargalg *di) 829 818 { 830 - di->ccm.original_iset = 831 - di->bm->bat_type[di->bm->batt_id].normal_cur_lvl; 832 - di->ccm.current_iset = 833 - di->bm->bat_type[di->bm->batt_id].normal_cur_lvl; 834 - di->ccm.test_delta_i = di->bm->maxi->charger_curr_step; 835 - di->ccm.max_current = di->bm->maxi->chg_curr; 819 + struct power_supply_battery_info *bi = di->bm->bi; 820 + 821 + di->ccm.original_iset_ua = bi->constant_charge_current_max_ua; 822 + di->ccm.current_iset_ua = bi->constant_charge_current_max_ua; 823 + di->ccm.test_delta_i_ua = di->bm->maxi->charger_curr_step_ua; 824 + di->ccm.max_current_ua = di->bm->maxi->chg_curr_ua; 836 825 di->ccm.condition_cnt = di->bm->maxi->wait_cycles; 837 826 di->ccm.level = 0; 838 827 } ··· 848 837 */ 849 838 static enum maxim_ret ab8500_chargalg_chg_curr_maxim(struct ab8500_chargalg *di) 850 839 { 851 - int delta_i; 840 + int delta_i_ua; 852 841 853 842 if (!di->bm->maxi->ena_maxi) 854 843 return MAXIM_RET_NOACTION; 855 844 856 - delta_i = di->ccm.original_iset - di->batt_data.inst_curr; 845 + delta_i_ua = di->ccm.original_iset_ua - di->batt_data.inst_curr_ua; 857 846 858 847 if (di->events.vbus_collapsed) { 859 848 dev_dbg(di->dev, "Charger voltage has collapsed %d\n", ··· 862 851 dev_dbg(di->dev, "lowering current\n"); 863 852 di->ccm.wait_cnt++; 864 853 di->ccm.condition_cnt = di->bm->maxi->wait_cycles; 865 - di->ccm.max_current = 866 - di->ccm.current_iset - di->ccm.test_delta_i; 867 - di->ccm.current_iset = di->ccm.max_current; 854 + di->ccm.max_current_ua = 855 + di->ccm.current_iset_ua - di->ccm.test_delta_i_ua; 856 + di->ccm.current_iset_ua = di->ccm.max_current_ua; 868 857 di->ccm.level--; 869 858 return MAXIM_RET_CHANGE; 870 859 } else { ··· 877 866 878 867 di->ccm.wait_cnt = 0; 879 868 880 - if (di->batt_data.inst_curr > di->ccm.original_iset) { 881 - dev_dbg(di->dev, " Maximization Ibat (%dmA) too high" 882 - " (limit %dmA) (current iset: %dmA)!\n", 883 - di->batt_data.inst_curr, di->ccm.original_iset, 884 - di->ccm.current_iset); 869 + if (di->batt_data.inst_curr_ua > di->ccm.original_iset_ua) { 870 + dev_dbg(di->dev, " Maximization Ibat (%duA) too high" 871 + " (limit %duA) (current iset: %duA)!\n", 872 + di->batt_data.inst_curr_ua, di->ccm.original_iset_ua, 873 + di->ccm.current_iset_ua); 885 874 886 - if (di->ccm.current_iset == di->ccm.original_iset) 875 + if (di->ccm.current_iset_ua == di->ccm.original_iset_ua) 887 876 return MAXIM_RET_NOACTION; 888 877 889 878 di->ccm.condition_cnt = di->bm->maxi->wait_cycles; 890 - di->ccm.current_iset = di->ccm.original_iset; 879 + di->ccm.current_iset_ua = di->ccm.original_iset_ua; 891 880 di->ccm.level = 0; 892 881 893 882 return MAXIM_RET_IBAT_TOO_HIGH; 894 883 } 895 884 896 - if (delta_i > di->ccm.test_delta_i && 897 - (di->ccm.current_iset + di->ccm.test_delta_i) < 898 - di->ccm.max_current) { 885 + if (delta_i_ua > di->ccm.test_delta_i_ua && 886 + (di->ccm.current_iset_ua + di->ccm.test_delta_i_ua) < 887 + di->ccm.max_current_ua) { 899 888 if (di->ccm.condition_cnt-- == 0) { 900 889 /* Increse the iset with cco.test_delta_i */ 901 890 di->ccm.condition_cnt = di->bm->maxi->wait_cycles; 902 - di->ccm.current_iset += di->ccm.test_delta_i; 891 + di->ccm.current_iset_ua += di->ccm.test_delta_i_ua; 903 892 di->ccm.level++; 904 893 dev_dbg(di->dev, " Maximization needed, increase" 905 - " with %d mA to %dmA (Optimal ibat: %d)" 894 + " with %d uA to %duA (Optimal ibat: %d uA)" 906 895 " Level %d\n", 907 - di->ccm.test_delta_i, 908 - di->ccm.current_iset, 909 - di->ccm.original_iset, 896 + di->ccm.test_delta_i_ua, 897 + di->ccm.current_iset_ua, 898 + di->ccm.original_iset_ua, 910 899 di->ccm.level); 911 900 return MAXIM_RET_CHANGE; 912 901 } else { ··· 920 909 921 910 static void handle_maxim_chg_curr(struct ab8500_chargalg *di) 922 911 { 912 + struct power_supply_battery_info *bi = di->bm->bi; 923 913 enum maxim_ret ret; 924 914 int result; 925 915 ··· 928 916 switch (ret) { 929 917 case MAXIM_RET_CHANGE: 930 918 result = ab8500_chargalg_update_chg_curr(di, 931 - di->ccm.current_iset); 919 + di->ccm.current_iset_ua); 932 920 if (result) 933 921 dev_err(di->dev, "failed to set chg curr\n"); 934 922 break; 935 923 case MAXIM_RET_IBAT_TOO_HIGH: 936 924 result = ab8500_chargalg_update_chg_curr(di, 937 - di->bm->bat_type[di->bm->batt_id].normal_cur_lvl); 925 + bi->constant_charge_current_max_ua); 938 926 if (result) 939 927 dev_err(di->dev, "failed to set chg curr\n"); 940 928 break; ··· 1170 1158 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 1171 1159 switch (ext->desc->type) { 1172 1160 case POWER_SUPPLY_TYPE_BATTERY: 1173 - di->batt_data.volt = ret.intval / 1000; 1161 + di->batt_data.volt_uv = ret.intval; 1174 1162 break; 1175 1163 case POWER_SUPPLY_TYPE_MAINS: 1176 - di->chg_info.ac_volt = ret.intval / 1000; 1164 + di->chg_info.ac_volt_uv = ret.intval; 1177 1165 break; 1178 1166 case POWER_SUPPLY_TYPE_USB: 1179 - di->chg_info.usb_volt = ret.intval / 1000; 1167 + di->chg_info.usb_volt_uv = ret.intval; 1180 1168 break; 1181 1169 default: 1182 1170 break; ··· 1229 1217 case POWER_SUPPLY_PROP_CURRENT_NOW: 1230 1218 switch (ext->desc->type) { 1231 1219 case POWER_SUPPLY_TYPE_MAINS: 1232 - di->chg_info.ac_curr = 1233 - ret.intval / 1000; 1234 - break; 1220 + di->chg_info.ac_curr_ua = ret.intval; 1221 + break; 1235 1222 case POWER_SUPPLY_TYPE_USB: 1236 - di->chg_info.usb_curr = 1237 - ret.intval / 1000; 1223 + di->chg_info.usb_curr_ua = ret.intval; 1238 1224 break; 1239 1225 case POWER_SUPPLY_TYPE_BATTERY: 1240 - di->batt_data.inst_curr = ret.intval / 1000; 1226 + di->batt_data.inst_curr_ua = ret.intval; 1241 1227 break; 1242 1228 default: 1243 1229 break; ··· 1245 1235 case POWER_SUPPLY_PROP_CURRENT_AVG: 1246 1236 switch (ext->desc->type) { 1247 1237 case POWER_SUPPLY_TYPE_BATTERY: 1248 - di->batt_data.avg_curr = ret.intval / 1000; 1238 + di->batt_data.avg_curr_ua = ret.intval; 1249 1239 break; 1250 1240 case POWER_SUPPLY_TYPE_USB: 1251 1241 if (ret.intval) ··· 1299 1289 */ 1300 1290 static void ab8500_chargalg_algorithm(struct ab8500_chargalg *di) 1301 1291 { 1292 + struct power_supply_battery_info *bi = di->bm->bi; 1302 1293 int charger_status; 1303 1294 int ret; 1304 - int curr_step_lvl; 1295 + int curr_step_lvl_ua; 1305 1296 1306 1297 /* Collect data from all power_supply class devices */ 1307 1298 class_for_each_device(power_supply_class, NULL, ··· 1406 1395 "State %s Active_chg %d Chg_status %d AC %d USB %d " 1407 1396 "AC_online %d USB_online %d AC_CV %d USB_CV %d AC_I %d " 1408 1397 "USB_I %d AC_Vset %d AC_Iset %d USB_Vset %d USB_Iset %d\n", 1409 - di->batt_data.volt, 1410 - di->batt_data.avg_curr, 1411 - di->batt_data.inst_curr, 1398 + di->batt_data.volt_uv, 1399 + di->batt_data.avg_curr_ua, 1400 + di->batt_data.inst_curr_ua, 1412 1401 di->batt_data.temp, 1413 1402 di->batt_data.percent, 1414 1403 di->maintenance_chg, ··· 1421 1410 di->chg_info.online_chg & USB_CHG, 1422 1411 di->events.ac_cv_active, 1423 1412 di->events.usb_cv_active, 1424 - di->chg_info.ac_curr, 1425 - di->chg_info.usb_curr, 1426 - di->chg_info.ac_vset, 1427 - di->chg_info.ac_iset, 1428 - di->chg_info.usb_vset, 1429 - di->chg_info.usb_iset); 1413 + di->chg_info.ac_curr_ua, 1414 + di->chg_info.usb_curr_ua, 1415 + di->chg_info.ac_vset_uv, 1416 + di->chg_info.ac_iset_ua, 1417 + di->chg_info.usb_vset_uv, 1418 + di->chg_info.usb_iset_ua); 1430 1419 1431 1420 switch (di->charge_state) { 1432 1421 case STATE_HANDHELD_INIT: ··· 1511 1500 break; 1512 1501 1513 1502 case STATE_NORMAL_INIT: 1514 - if (di->curr_status.curr_step == CHARGALG_CURR_STEP_LOW) 1503 + if (di->curr_status.curr_step_ua == CHARGALG_CURR_STEP_LOW_UA) 1515 1504 ab8500_chargalg_stop_charging(di); 1516 1505 else { 1517 - curr_step_lvl = di->bm->bat_type[ 1518 - di->bm->batt_id].normal_cur_lvl 1519 - * di->curr_status.curr_step 1520 - / CHARGALG_CURR_STEP_HIGH; 1506 + curr_step_lvl_ua = bi->constant_charge_current_max_ua 1507 + * di->curr_status.curr_step_ua 1508 + / CHARGALG_CURR_STEP_HIGH_UA; 1521 1509 ab8500_chargalg_start_charging(di, 1522 - di->bm->bat_type[di->bm->batt_id] 1523 - .normal_vol_lvl, curr_step_lvl); 1510 + bi->constant_charge_voltage_max_uv, 1511 + curr_step_lvl_ua); 1524 1512 } 1525 1513 1526 1514 ab8500_chargalg_state_to(di, STATE_NORMAL); ··· 1553 1543 fallthrough; 1554 1544 1555 1545 case STATE_WAIT_FOR_RECHARGE: 1556 - if (di->batt_data.percent <= 1557 - di->bm->bat_type[di->bm->batt_id].recharge_cap) 1546 + if (di->batt_data.percent <= AB8500_RECHARGE_CAP) 1558 1547 ab8500_chargalg_state_to(di, STATE_NORMAL_INIT); 1559 1548 break; 1560 1549 1561 1550 case STATE_MAINTENANCE_A_INIT: 1562 1551 ab8500_chargalg_stop_safety_timer(di); 1563 1552 ab8500_chargalg_start_maintenance_timer(di, 1564 - di->bm->bat_type[ 1565 - di->bm->batt_id].maint_a_chg_timer_h); 1553 + di->bm->bat_type->maint_a_chg_timer_h); 1566 1554 ab8500_chargalg_start_charging(di, 1567 - di->bm->bat_type[ 1568 - di->bm->batt_id].maint_a_vol_lvl, 1569 - di->bm->bat_type[ 1570 - di->bm->batt_id].maint_a_cur_lvl); 1555 + di->bm->bat_type->maint_a_vol_lvl, 1556 + di->bm->bat_type->maint_a_cur_lvl); 1571 1557 ab8500_chargalg_state_to(di, STATE_MAINTENANCE_A); 1572 1558 power_supply_changed(di->chargalg_psy); 1573 1559 fallthrough; ··· 1577 1571 1578 1572 case STATE_MAINTENANCE_B_INIT: 1579 1573 ab8500_chargalg_start_maintenance_timer(di, 1580 - di->bm->bat_type[ 1581 - di->bm->batt_id].maint_b_chg_timer_h); 1574 + di->bm->bat_type->maint_b_chg_timer_h); 1582 1575 ab8500_chargalg_start_charging(di, 1583 - di->bm->bat_type[ 1584 - di->bm->batt_id].maint_b_vol_lvl, 1585 - di->bm->bat_type[ 1586 - di->bm->batt_id].maint_b_cur_lvl); 1576 + di->bm->bat_type->maint_b_vol_lvl, 1577 + di->bm->bat_type->maint_b_cur_lvl); 1587 1578 ab8500_chargalg_state_to(di, STATE_MAINTENANCE_B); 1588 1579 power_supply_changed(di->chargalg_psy); 1589 1580 fallthrough; ··· 1594 1591 1595 1592 case STATE_TEMP_LOWHIGH_INIT: 1596 1593 ab8500_chargalg_start_charging(di, 1597 - di->bm->bat_type[ 1598 - di->bm->batt_id].low_high_vol_lvl, 1599 - di->bm->bat_type[ 1600 - di->bm->batt_id].low_high_cur_lvl); 1594 + di->bm->bat_type->low_high_vol_lvl, 1595 + di->bm->bat_type->low_high_cur_lvl); 1601 1596 ab8500_chargalg_stop_maintenance_timer(di); 1602 1597 di->charge_status = POWER_SUPPLY_STATUS_CHARGING; 1603 1598 ab8500_chargalg_state_to(di, STATE_TEMP_LOWHIGH); ··· 1723 1722 if (di->events.batt_ovv) { 1724 1723 val->intval = POWER_SUPPLY_HEALTH_OVERVOLTAGE; 1725 1724 } else if (di->events.btemp_underover) { 1726 - if (di->batt_data.temp <= di->bm->temp_under) 1725 + if (di->batt_data.temp <= di->bm->bi->temp_min) 1727 1726 val->intval = POWER_SUPPLY_HEALTH_COLD; 1728 1727 else 1729 1728 val->intval = POWER_SUPPLY_HEALTH_OVERHEAT; ··· 1745 1744 static ssize_t ab8500_chargalg_curr_step_show(struct ab8500_chargalg *di, 1746 1745 char *buf) 1747 1746 { 1748 - return sprintf(buf, "%d\n", di->curr_status.curr_step); 1747 + return sprintf(buf, "%d\n", di->curr_status.curr_step_ua); 1749 1748 } 1750 1749 1751 1750 static ssize_t ab8500_chargalg_curr_step_store(struct ab8500_chargalg *di, ··· 1758 1757 if (ret < 0) 1759 1758 return ret; 1760 1759 1761 - di->curr_status.curr_step = param; 1762 - if (di->curr_status.curr_step >= CHARGALG_CURR_STEP_LOW && 1763 - di->curr_status.curr_step <= CHARGALG_CURR_STEP_HIGH) { 1760 + di->curr_status.curr_step_ua = param; 1761 + if (di->curr_status.curr_step_ua >= CHARGALG_CURR_STEP_LOW_UA && 1762 + di->curr_status.curr_step_ua <= CHARGALG_CURR_STEP_HIGH_UA) { 1764 1763 di->curr_status.curr_step_change = true; 1765 1764 queue_work(di->chargalg_wq, &di->chargalg_work); 1766 1765 } else ··· 2057 2056 dev_err(di->dev, "failed to create sysfs entry\n"); 2058 2057 return ret; 2059 2058 } 2060 - di->curr_status.curr_step = CHARGALG_CURR_STEP_HIGH; 2059 + di->curr_status.curr_step_ua = CHARGALG_CURR_STEP_HIGH_UA; 2061 2060 2062 2061 dev_info(di->dev, "probe success\n"); 2063 2062 return component_add(dev, &ab8500_chargalg_component_ops);
+289 -255
drivers/power/supply/ab8500_charger.c
··· 145 145 AB8500_BM_USB_STATE_MAX, 146 146 }; 147 147 148 - /* VBUS input current limits supported in AB8500 in mA */ 149 - #define USB_CH_IP_CUR_LVL_0P05 50 150 - #define USB_CH_IP_CUR_LVL_0P09 98 151 - #define USB_CH_IP_CUR_LVL_0P19 193 152 - #define USB_CH_IP_CUR_LVL_0P29 290 153 - #define USB_CH_IP_CUR_LVL_0P38 380 154 - #define USB_CH_IP_CUR_LVL_0P45 450 155 - #define USB_CH_IP_CUR_LVL_0P5 500 156 - #define USB_CH_IP_CUR_LVL_0P6 600 157 - #define USB_CH_IP_CUR_LVL_0P7 700 158 - #define USB_CH_IP_CUR_LVL_0P8 800 159 - #define USB_CH_IP_CUR_LVL_0P9 900 160 - #define USB_CH_IP_CUR_LVL_1P0 1000 161 - #define USB_CH_IP_CUR_LVL_1P1 1100 162 - #define USB_CH_IP_CUR_LVL_1P3 1300 163 - #define USB_CH_IP_CUR_LVL_1P4 1400 164 - #define USB_CH_IP_CUR_LVL_1P5 1500 148 + /* VBUS input current limits supported in AB8500 in uA */ 149 + #define USB_CH_IP_CUR_LVL_0P05 50000 150 + #define USB_CH_IP_CUR_LVL_0P09 98000 151 + #define USB_CH_IP_CUR_LVL_0P19 193000 152 + #define USB_CH_IP_CUR_LVL_0P29 290000 153 + #define USB_CH_IP_CUR_LVL_0P38 380000 154 + #define USB_CH_IP_CUR_LVL_0P45 450000 155 + #define USB_CH_IP_CUR_LVL_0P5 500000 156 + #define USB_CH_IP_CUR_LVL_0P6 600000 157 + #define USB_CH_IP_CUR_LVL_0P7 700000 158 + #define USB_CH_IP_CUR_LVL_0P8 800000 159 + #define USB_CH_IP_CUR_LVL_0P9 900000 160 + #define USB_CH_IP_CUR_LVL_1P0 1000000 161 + #define USB_CH_IP_CUR_LVL_1P1 1100000 162 + #define USB_CH_IP_CUR_LVL_1P3 1300000 163 + #define USB_CH_IP_CUR_LVL_1P4 1400000 164 + #define USB_CH_IP_CUR_LVL_1P5 1500000 165 165 166 166 #define VBAT_TRESH_IP_CUR_RED 3800 167 167 ··· 183 183 struct ab8500_charger_info { 184 184 int charger_connected; 185 185 int charger_online; 186 - int charger_voltage; 186 + int charger_voltage_uv; 187 187 int cv_active; 188 188 bool wd_expired; 189 - int charger_current; 189 + int charger_current_ua; 190 190 }; 191 191 192 192 struct ab8500_charger_event_flags { ··· 201 201 }; 202 202 203 203 struct ab8500_charger_usb_state { 204 - int usb_current; 205 - int usb_current_tmp; 204 + int usb_current_ua; 205 + int usb_current_tmp_ua; 206 206 enum ab8500_usb_state state; 207 207 enum ab8500_usb_state state_tmp; 208 208 spinlock_t usb_lock; 209 209 }; 210 210 211 211 struct ab8500_charger_max_usb_in_curr { 212 - int usb_type_max; 213 - int set_max; 214 - int calculated_max; 212 + int usb_type_max_ua; 213 + int set_max_ua; 214 + int calculated_max_ua; 215 215 }; 216 216 217 217 /** ··· 479 479 * ab8500_charger_get_ac_voltage() - get ac charger voltage 480 480 * @di: pointer to the ab8500_charger structure 481 481 * 482 - * Returns ac charger voltage (on success) 482 + * Returns ac charger voltage in microvolt (on success) 483 483 */ 484 484 static int ab8500_charger_get_ac_voltage(struct ab8500_charger *di) 485 485 { ··· 493 493 } else { 494 494 vch = 0; 495 495 } 496 - return vch; 496 + /* Convert to microvolt, IIO returns millivolt */ 497 + return vch * 1000; 497 498 } 498 499 499 500 /** ··· 531 530 * @di: pointer to the ab8500_charger structure 532 531 * 533 532 * This function returns the vbus voltage. 534 - * Returns vbus voltage (on success) 533 + * Returns vbus voltage in microvolt (on success) 535 534 */ 536 535 static int ab8500_charger_get_vbus_voltage(struct ab8500_charger *di) 537 536 { ··· 545 544 } else { 546 545 vch = 0; 547 546 } 548 - return vch; 547 + /* Convert to microvolt, IIO returns millivolt */ 548 + return vch * 1000; 549 549 } 550 550 551 551 /** ··· 554 552 * @di: pointer to the ab8500_charger structure 555 553 * 556 554 * This function returns the usb charger current. 557 - * Returns usb current (on success) and error code on failure 555 + * Returns usb current in microamperes (on success) and error code on failure 558 556 */ 559 557 static int ab8500_charger_get_usb_current(struct ab8500_charger *di) 560 558 { ··· 568 566 } else { 569 567 ich = 0; 570 568 } 571 - return ich; 569 + /* Return microamperes */ 570 + return ich * 1000; 572 571 } 573 572 574 573 /** ··· 577 574 * @di: pointer to the ab8500_charger structure 578 575 * 579 576 * This function returns the ac charger current. 580 - * Returns ac current (on success) and error code on failure. 577 + * Returns ac current in microamperes (on success) and error code on failure. 581 578 */ 582 579 static int ab8500_charger_get_ac_current(struct ab8500_charger *di) 583 580 { ··· 591 588 } else { 592 589 ich = 0; 593 590 } 594 - return ich; 591 + /* Return microamperes */ 592 + return ich * 1000; 595 593 } 596 594 597 595 /** ··· 715 711 case USB_STAT_STD_HOST_C_S: 716 712 dev_dbg(di->dev, "USB Type - Standard host is " 717 713 "detected through USB driver\n"); 718 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; 714 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; 719 715 di->is_aca_rid = 0; 720 716 break; 721 717 case USB_STAT_HOST_CHG_HS_CHIRP: 722 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; 718 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; 723 719 di->is_aca_rid = 0; 724 720 break; 725 721 case USB_STAT_HOST_CHG_HS: 726 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; 722 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; 727 723 di->is_aca_rid = 0; 728 724 break; 729 725 case USB_STAT_ACA_RID_C_HS: 730 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P9; 726 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P9; 731 727 di->is_aca_rid = 0; 732 728 break; 733 729 case USB_STAT_ACA_RID_A: ··· 736 732 * can consume (900mA). Closest level is 500mA 737 733 */ 738 734 dev_dbg(di->dev, "USB_STAT_ACA_RID_A detected\n"); 739 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; 735 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; 740 736 di->is_aca_rid = 1; 741 737 break; 742 738 case USB_STAT_ACA_RID_B: ··· 744 740 * Dedicated charger level minus 120mA (20mA for ACA and 745 741 * 100mA for potential accessory). Closest level is 1300mA 746 742 */ 747 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_1P3; 743 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_1P3; 748 744 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, 749 - di->max_usb_in_curr.usb_type_max); 745 + di->max_usb_in_curr.usb_type_max_ua); 750 746 di->is_aca_rid = 1; 751 747 break; 752 748 case USB_STAT_HOST_CHG_NM: 753 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; 749 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; 754 750 di->is_aca_rid = 0; 755 751 break; 756 752 case USB_STAT_DEDICATED_CHG: 757 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_1P5; 753 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_1P5; 758 754 di->is_aca_rid = 0; 759 755 break; 760 756 case USB_STAT_ACA_RID_C_HS_CHIRP: 761 757 case USB_STAT_ACA_RID_C_NM: 762 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_1P5; 758 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_1P5; 763 759 di->is_aca_rid = 1; 764 760 break; 765 761 case USB_STAT_NOT_CONFIGURED: 766 762 if (di->vbus_detected) { 767 763 di->usb_device_is_unrecognised = true; 768 764 dev_dbg(di->dev, "USB Type - Legacy charger.\n"); 769 - di->max_usb_in_curr.usb_type_max = 765 + di->max_usb_in_curr.usb_type_max_ua = 770 766 USB_CH_IP_CUR_LVL_1P5; 771 767 break; 772 768 } 773 769 fallthrough; 774 770 case USB_STAT_HM_IDGND: 775 771 dev_err(di->dev, "USB Type - Charging not allowed\n"); 776 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P05; 772 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P05; 777 773 ret = -ENXIO; 778 774 break; 779 775 case USB_STAT_RESERVED: ··· 785 781 break; 786 782 } else { 787 783 dev_dbg(di->dev, "USB Type - Charging not allowed\n"); 788 - di->max_usb_in_curr.usb_type_max = 784 + di->max_usb_in_curr.usb_type_max_ua = 789 785 USB_CH_IP_CUR_LVL_0P05; 790 786 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", 791 787 link_status, 792 - di->max_usb_in_curr.usb_type_max); 788 + di->max_usb_in_curr.usb_type_max_ua); 793 789 ret = -ENXIO; 794 790 break; 795 791 } ··· 797 793 case USB_STAT_CARKIT_2: 798 794 case USB_STAT_ACA_DOCK_CHARGER: 799 795 case USB_STAT_CHARGER_LINE_1: 800 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; 796 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; 801 797 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", link_status, 802 - di->max_usb_in_curr.usb_type_max); 798 + di->max_usb_in_curr.usb_type_max_ua); 803 799 break; 804 800 case USB_STAT_NOT_VALID_LINK: 805 801 dev_err(di->dev, "USB Type invalid - try charging anyway\n"); 806 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; 802 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; 807 803 break; 808 804 809 805 default: 810 806 dev_err(di->dev, "USB Type - Unknown\n"); 811 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P05; 807 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P05; 812 808 ret = -ENXIO; 813 809 break; 814 810 } 815 811 816 - di->max_usb_in_curr.set_max = di->max_usb_in_curr.usb_type_max; 812 + di->max_usb_in_curr.set_max_ua = di->max_usb_in_curr.usb_type_max_ua; 817 813 dev_dbg(di->dev, "USB Type - 0x%02x MaxCurr: %d", 818 - link_status, di->max_usb_in_curr.set_max); 814 + link_status, di->max_usb_in_curr.set_max_ua); 819 815 820 816 return ret; 821 817 } ··· 925 921 926 922 /* 927 923 * This array maps the raw hex value to charger voltage used by the AB8500 928 - * Values taken from the UM0836 924 + * Values taken from the UM0836, in microvolt. 929 925 */ 930 926 static int ab8500_charger_voltage_map[] = { 931 - 3500 , 932 - 3525 , 933 - 3550 , 934 - 3575 , 935 - 3600 , 936 - 3625 , 937 - 3650 , 938 - 3675 , 939 - 3700 , 940 - 3725 , 941 - 3750 , 942 - 3775 , 943 - 3800 , 944 - 3825 , 945 - 3850 , 946 - 3875 , 947 - 3900 , 948 - 3925 , 949 - 3950 , 950 - 3975 , 951 - 4000 , 952 - 4025 , 953 - 4050 , 954 - 4060 , 955 - 4070 , 956 - 4080 , 957 - 4090 , 958 - 4100 , 959 - 4110 , 960 - 4120 , 961 - 4130 , 962 - 4140 , 963 - 4150 , 964 - 4160 , 965 - 4170 , 966 - 4180 , 967 - 4190 , 968 - 4200 , 969 - 4210 , 970 - 4220 , 971 - 4230 , 972 - 4240 , 973 - 4250 , 974 - 4260 , 975 - 4270 , 976 - 4280 , 977 - 4290 , 978 - 4300 , 979 - 4310 , 980 - 4320 , 981 - 4330 , 982 - 4340 , 983 - 4350 , 984 - 4360 , 985 - 4370 , 986 - 4380 , 987 - 4390 , 988 - 4400 , 989 - 4410 , 990 - 4420 , 991 - 4430 , 992 - 4440 , 993 - 4450 , 994 - 4460 , 995 - 4470 , 996 - 4480 , 997 - 4490 , 998 - 4500 , 999 - 4510 , 1000 - 4520 , 1001 - 4530 , 1002 - 4540 , 1003 - 4550 , 1004 - 4560 , 1005 - 4570 , 1006 - 4580 , 1007 - 4590 , 1008 - 4600 , 927 + 3500000, 928 + 3525000, 929 + 3550000, 930 + 3575000, 931 + 3600000, 932 + 3625000, 933 + 3650000, 934 + 3675000, 935 + 3700000, 936 + 3725000, 937 + 3750000, 938 + 3775000, 939 + 3800000, 940 + 3825000, 941 + 3850000, 942 + 3875000, 943 + 3900000, 944 + 3925000, 945 + 3950000, 946 + 3975000, 947 + 4000000, 948 + 4025000, 949 + 4050000, 950 + 4060000, 951 + 4070000, 952 + 4080000, 953 + 4090000, 954 + 4100000, 955 + 4110000, 956 + 4120000, 957 + 4130000, 958 + 4140000, 959 + 4150000, 960 + 4160000, 961 + 4170000, 962 + 4180000, 963 + 4190000, 964 + 4200000, 965 + 4210000, 966 + 4220000, 967 + 4230000, 968 + 4240000, 969 + 4250000, 970 + 4260000, 971 + 4270000, 972 + 4280000, 973 + 4290000, 974 + 4300000, 975 + 4310000, 976 + 4320000, 977 + 4330000, 978 + 4340000, 979 + 4350000, 980 + 4360000, 981 + 4370000, 982 + 4380000, 983 + 4390000, 984 + 4400000, 985 + 4410000, 986 + 4420000, 987 + 4430000, 988 + 4440000, 989 + 4450000, 990 + 4460000, 991 + 4470000, 992 + 4480000, 993 + 4490000, 994 + 4500000, 995 + 4510000, 996 + 4520000, 997 + 4530000, 998 + 4540000, 999 + 4550000, 1000 + 4560000, 1001 + 4570000, 1002 + 4580000, 1003 + 4590000, 1004 + 4600000, 1009 1005 }; 1010 1006 1011 - static int ab8500_voltage_to_regval(int voltage) 1007 + static int ab8500_voltage_to_regval(int voltage_uv) 1012 1008 { 1013 1009 int i; 1014 1010 1015 1011 /* Special case for voltage below 3.5V */ 1016 - if (voltage < ab8500_charger_voltage_map[0]) 1012 + if (voltage_uv < ab8500_charger_voltage_map[0]) 1017 1013 return LOW_VOLT_REG; 1018 1014 1019 1015 for (i = 1; i < ARRAY_SIZE(ab8500_charger_voltage_map); i++) { 1020 - if (voltage < ab8500_charger_voltage_map[i]) 1016 + if (voltage_uv < ab8500_charger_voltage_map[i]) 1021 1017 return i - 1; 1022 1018 } 1023 1019 1024 1020 /* If not last element, return error */ 1025 1021 i = ARRAY_SIZE(ab8500_charger_voltage_map) - 1; 1026 - if (voltage == ab8500_charger_voltage_map[i]) 1022 + if (voltage_uv == ab8500_charger_voltage_map[i]) 1027 1023 return i; 1028 1024 else 1029 1025 return -1; 1030 1026 } 1031 1027 1032 - static int ab8500_current_to_regval(struct ab8500_charger *di, int curr) 1028 + /* This array maps the raw register value to charger input current */ 1029 + static int ab8500_charge_input_curr_map[] = { 1030 + 50000, 98000, 193000, 290000, 380000, 450000, 500000, 600000, 1031 + 700000, 800000, 900000, 1000000, 1100000, 1300000, 1400000, 1500000, 1032 + }; 1033 + 1034 + /* This array maps the raw register value to charger output current */ 1035 + static int ab8500_charge_output_curr_map[] = { 1036 + 100000, 200000, 300000, 400000, 500000, 600000, 700000, 800000, 1037 + 900000, 1000000, 1100000, 1200000, 1300000, 1400000, 1500000, 1500000, 1038 + }; 1039 + 1040 + static int ab8500_current_to_regval(struct ab8500_charger *di, int curr_ua) 1033 1041 { 1034 1042 int i; 1035 1043 1036 - if (curr < di->bm->chg_output_curr[0]) 1044 + if (curr_ua < ab8500_charge_output_curr_map[0]) 1037 1045 return 0; 1038 1046 1039 - for (i = 0; i < di->bm->n_chg_out_curr; i++) { 1040 - if (curr < di->bm->chg_output_curr[i]) 1047 + for (i = 0; i < ARRAY_SIZE(ab8500_charge_output_curr_map); i++) { 1048 + if (curr_ua < ab8500_charge_output_curr_map[i]) 1041 1049 return i - 1; 1042 1050 } 1043 1051 1044 1052 /* If not last element, return error */ 1045 - i = di->bm->n_chg_out_curr - 1; 1046 - if (curr == di->bm->chg_output_curr[i]) 1053 + i = ARRAY_SIZE(ab8500_charge_output_curr_map) - 1; 1054 + if (curr_ua == ab8500_charge_output_curr_map[i]) 1047 1055 return i; 1048 1056 else 1049 1057 return -1; 1050 1058 } 1051 1059 1052 - static int ab8500_vbus_in_curr_to_regval(struct ab8500_charger *di, int curr) 1060 + static int ab8500_vbus_in_curr_to_regval(struct ab8500_charger *di, int curr_ua) 1053 1061 { 1054 1062 int i; 1055 1063 1056 - if (curr < di->bm->chg_input_curr[0]) 1064 + if (curr_ua < ab8500_charge_input_curr_map[0]) 1057 1065 return 0; 1058 1066 1059 - for (i = 0; i < di->bm->n_chg_in_curr; i++) { 1060 - if (curr < di->bm->chg_input_curr[i]) 1067 + for (i = 0; i < ARRAY_SIZE(ab8500_charge_input_curr_map); i++) { 1068 + if (curr_ua < ab8500_charge_input_curr_map[i]) 1061 1069 return i - 1; 1062 1070 } 1063 1071 1064 1072 /* If not last element, return error */ 1065 - i = di->bm->n_chg_in_curr - 1; 1066 - if (curr == di->bm->chg_input_curr[i]) 1073 + i = ARRAY_SIZE(ab8500_charge_input_curr_map) - 1; 1074 + if (curr_ua == ab8500_charge_input_curr_map[i]) 1067 1075 return i; 1068 1076 else 1069 1077 return -1; ··· 1086 1070 * @di: pointer to the ab8500_charger structre 1087 1071 * 1088 1072 * The usb stack provides the maximum current that can be drawn from 1089 - * the standard usb host. This will be in mA. 1090 - * This function converts current in mA to a value that can be written 1073 + * the standard usb host. This will be in uA. 1074 + * This function converts current in uA to a value that can be written 1091 1075 * to the register. Returns -1 if charging is not allowed 1092 1076 */ 1093 1077 static int ab8500_charger_get_usb_cur(struct ab8500_charger *di) 1094 1078 { 1095 1079 int ret = 0; 1096 - switch (di->usb_state.usb_current) { 1097 - case 100: 1098 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P09; 1080 + switch (di->usb_state.usb_current_ua) { 1081 + case 100000: 1082 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P09; 1099 1083 break; 1100 - case 200: 1101 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P19; 1084 + case 200000: 1085 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P19; 1102 1086 break; 1103 - case 300: 1104 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P29; 1087 + case 300000: 1088 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P29; 1105 1089 break; 1106 - case 400: 1107 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P38; 1090 + case 400000: 1091 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P38; 1108 1092 break; 1109 - case 500: 1110 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P5; 1093 + case 500000: 1094 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P5; 1111 1095 break; 1112 1096 default: 1113 - di->max_usb_in_curr.usb_type_max = USB_CH_IP_CUR_LVL_0P05; 1097 + di->max_usb_in_curr.usb_type_max_ua = USB_CH_IP_CUR_LVL_0P05; 1114 1098 ret = -EPERM; 1115 1099 break; 1116 1100 } 1117 - di->max_usb_in_curr.set_max = di->max_usb_in_curr.usb_type_max; 1101 + di->max_usb_in_curr.set_max_ua = di->max_usb_in_curr.usb_type_max_ua; 1118 1102 return ret; 1119 1103 } 1120 1104 ··· 1139 1123 /** 1140 1124 * ab8500_charger_set_current() - set charger current 1141 1125 * @di: pointer to the ab8500_charger structure 1142 - * @ich: charger current, in mA 1126 + * @ich_ua: charger current, in uA 1143 1127 * @reg: select what charger register to set 1144 1128 * 1145 1129 * Set charger current. ··· 1150 1134 * Returns error code in case of failure else 0(on success) 1151 1135 */ 1152 1136 static int ab8500_charger_set_current(struct ab8500_charger *di, 1153 - int ich, int reg) 1137 + int ich_ua, int reg) 1154 1138 { 1155 1139 int ret = 0; 1156 1140 int curr_index, prev_curr_index, shift_value, i; ··· 1171 1155 case AB8500_MCH_IPT_CURLVL_REG: 1172 1156 shift_value = MAIN_CH_INPUT_CURR_SHIFT; 1173 1157 prev_curr_index = (reg_value >> shift_value); 1174 - curr_index = ab8500_current_to_regval(di, ich); 1158 + curr_index = ab8500_current_to_regval(di, ich_ua); 1175 1159 step_udelay = STEP_UDELAY; 1176 1160 if (!di->ac.charger_connected) 1177 1161 no_stepping = true; ··· 1179 1163 case AB8500_USBCH_IPT_CRNTLVL_REG: 1180 1164 shift_value = VBUS_IN_CURR_LIM_SHIFT; 1181 1165 prev_curr_index = (reg_value >> shift_value); 1182 - curr_index = ab8500_vbus_in_curr_to_regval(di, ich); 1166 + curr_index = ab8500_vbus_in_curr_to_regval(di, ich_ua); 1183 1167 step_udelay = STEP_UDELAY * 100; 1184 1168 1185 1169 if (!di->usb.charger_connected) ··· 1188 1172 case AB8500_CH_OPT_CRNTLVL_REG: 1189 1173 shift_value = 0; 1190 1174 prev_curr_index = (reg_value >> shift_value); 1191 - curr_index = ab8500_current_to_regval(di, ich); 1175 + curr_index = ab8500_current_to_regval(di, ich_ua); 1192 1176 step_udelay = STEP_UDELAY; 1193 1177 if (curr_index && (curr_index - prev_curr_index) > 1) 1194 1178 step_udelay *= 100; ··· 1217 1201 goto exit_set_current; 1218 1202 } 1219 1203 1220 - dev_dbg(di->dev, "%s set charger current: %d mA for reg: 0x%02x\n", 1221 - __func__, ich, reg); 1204 + dev_dbg(di->dev, "%s set charger current: %d uA for reg: 0x%02x\n", 1205 + __func__, ich_ua, reg); 1222 1206 1223 1207 if (no_stepping) { 1224 1208 ret = abx500_set_register_interruptible(di->dev, AB8500_CHARGER, ··· 1265 1249 /** 1266 1250 * ab8500_charger_set_vbus_in_curr() - set VBUS input current limit 1267 1251 * @di: pointer to the ab8500_charger structure 1268 - * @ich_in: charger input current limit 1252 + * @ich_in_ua: charger input current limit in microampere 1269 1253 * 1270 1254 * Sets the current that can be drawn from the USB host 1271 1255 * Returns error code in case of failure else 0(on success) 1272 1256 */ 1273 1257 static int ab8500_charger_set_vbus_in_curr(struct ab8500_charger *di, 1274 - int ich_in) 1258 + int ich_in_ua) 1275 1259 { 1276 1260 int min_value; 1277 1261 int ret; 1278 1262 1279 1263 /* We should always use to lowest current limit */ 1280 - min_value = min(di->bm->chg_params->usb_curr_max, ich_in); 1281 - if (di->max_usb_in_curr.set_max > 0) 1282 - min_value = min(di->max_usb_in_curr.set_max, min_value); 1264 + min_value = min(di->bm->chg_params->usb_curr_max_ua, ich_in_ua); 1265 + if (di->max_usb_in_curr.set_max_ua > 0) 1266 + min_value = min(di->max_usb_in_curr.set_max_ua, min_value); 1283 1267 1284 - if (di->usb_state.usb_current >= 0) 1285 - min_value = min(di->usb_state.usb_current, min_value); 1268 + if (di->usb_state.usb_current_ua >= 0) 1269 + min_value = min(di->usb_state.usb_current_ua, min_value); 1286 1270 1287 1271 switch (min_value) { 1288 - case 100: 1272 + case 100000: 1289 1273 if (di->vbat < VBAT_TRESH_IP_CUR_RED) 1290 1274 min_value = USB_CH_IP_CUR_LVL_0P05; 1291 1275 break; 1292 - case 500: 1276 + case 500000: 1293 1277 if (di->vbat < VBAT_TRESH_IP_CUR_RED) 1294 1278 min_value = USB_CH_IP_CUR_LVL_0P45; 1295 1279 break; ··· 1297 1281 break; 1298 1282 } 1299 1283 1300 - dev_info(di->dev, "VBUS input current limit set to %d mA\n", min_value); 1284 + dev_info(di->dev, "VBUS input current limit set to %d uA\n", min_value); 1301 1285 1302 1286 mutex_lock(&di->usb_ipt_crnt_lock); 1303 1287 ret = ab8500_charger_set_current(di, min_value, ··· 1310 1294 /** 1311 1295 * ab8500_charger_set_main_in_curr() - set main charger input current 1312 1296 * @di: pointer to the ab8500_charger structure 1313 - * @ich_in: input charger current, in mA 1297 + * @ich_in_ua: input charger current, in uA 1314 1298 * 1315 1299 * Set main charger input current. 1316 1300 * Returns error code in case of failure else 0(on success) 1317 1301 */ 1318 1302 static int ab8500_charger_set_main_in_curr(struct ab8500_charger *di, 1319 - int ich_in) 1303 + int ich_in_ua) 1320 1304 { 1321 - return ab8500_charger_set_current(di, ich_in, 1305 + return ab8500_charger_set_current(di, ich_in_ua, 1322 1306 AB8500_MCH_IPT_CURLVL_REG); 1323 1307 } 1324 1308 1325 1309 /** 1326 1310 * ab8500_charger_set_output_curr() - set charger output current 1327 1311 * @di: pointer to the ab8500_charger structure 1328 - * @ich_out: output charger current, in mA 1312 + * @ich_out_ua: output charger current, in uA 1329 1313 * 1330 1314 * Set charger output current. 1331 1315 * Returns error code in case of failure else 0(on success) 1332 1316 */ 1333 1317 static int ab8500_charger_set_output_curr(struct ab8500_charger *di, 1334 - int ich_out) 1318 + int ich_out_ua) 1335 1319 { 1336 - return ab8500_charger_set_current(di, ich_out, 1320 + return ab8500_charger_set_current(di, ich_out_ua, 1337 1321 AB8500_CH_OPT_CRNTLVL_REG); 1338 1322 } 1339 1323 ··· 1384 1368 * ab8500_charger_ac_en() - enable or disable ac charging 1385 1369 * @di: pointer to the ab8500_charger structure 1386 1370 * @enable: enable/disable flag 1387 - * @vset: charging voltage 1388 - * @iset: charging current 1371 + * @vset_uv: charging voltage in microvolt 1372 + * @iset_ua: charging current in microampere 1389 1373 * 1390 1374 * Enable/Disable AC/Mains charging and turns on/off the charging led 1391 1375 * respectively. 1392 1376 **/ 1393 1377 static int ab8500_charger_ac_en(struct ux500_charger *charger, 1394 - int enable, int vset, int iset) 1378 + int enable, int vset_uv, int iset_ua) 1395 1379 { 1396 1380 int ret; 1397 1381 int volt_index; ··· 1409 1393 } 1410 1394 1411 1395 /* Enable AC charging */ 1412 - dev_dbg(di->dev, "Enable AC: %dmV %dmA\n", vset, iset); 1396 + dev_dbg(di->dev, "Enable AC: %duV %duA\n", vset_uv, iset_ua); 1413 1397 1414 1398 /* 1415 1399 * Due to a bug in AB8500, BTEMP_HIGH/LOW interrupts ··· 1431 1415 } 1432 1416 1433 1417 /* Check if the requested voltage or current is valid */ 1434 - volt_index = ab8500_voltage_to_regval(vset); 1435 - curr_index = ab8500_current_to_regval(di, iset); 1418 + volt_index = ab8500_voltage_to_regval(vset_uv); 1419 + curr_index = ab8500_current_to_regval(di, iset_ua); 1436 1420 input_curr_index = ab8500_current_to_regval(di, 1437 - di->bm->chg_params->ac_curr_max); 1421 + di->bm->chg_params->ac_curr_max_ua); 1438 1422 if (volt_index < 0 || curr_index < 0 || input_curr_index < 0) { 1439 1423 dev_err(di->dev, 1440 1424 "Charger voltage or current too high, " ··· 1451 1435 } 1452 1436 /* MainChInputCurr: current that can be drawn from the charger*/ 1453 1437 ret = ab8500_charger_set_main_in_curr(di, 1454 - di->bm->chg_params->ac_curr_max); 1438 + di->bm->chg_params->ac_curr_max_ua); 1455 1439 if (ret) { 1456 1440 dev_err(di->dev, "%s Failed to set MainChInputCurr\n", 1457 1441 __func__); 1458 1442 return ret; 1459 1443 } 1460 1444 /* ChOutputCurentLevel: protected output current */ 1461 - ret = ab8500_charger_set_output_curr(di, iset); 1445 + ret = ab8500_charger_set_output_curr(di, iset_ua); 1462 1446 if (ret) { 1463 1447 dev_err(di->dev, "%s " 1464 1448 "Failed to set ChOutputCurentLevel\n", ··· 1561 1545 * ab8500_charger_usb_en() - enable usb charging 1562 1546 * @di: pointer to the ab8500_charger structure 1563 1547 * @enable: enable/disable flag 1564 - * @vset: charging voltage 1565 - * @ich_out: charger output current 1548 + * @vset_uv: charging voltage in microvolt 1549 + * @ich_out_ua: charger output current in microampere 1566 1550 * 1567 1551 * Enable/Disable USB charging and turns on/off the charging led respectively. 1568 1552 * Returns error code in case of failure else 0(on success) 1569 1553 */ 1570 1554 static int ab8500_charger_usb_en(struct ux500_charger *charger, 1571 - int enable, int vset, int ich_out) 1555 + int enable, int vset_uv, int ich_out_ua) 1572 1556 { 1573 1557 int ret; 1574 1558 int volt_index; ··· 1604 1588 } 1605 1589 1606 1590 /* Enable USB charging */ 1607 - dev_dbg(di->dev, "Enable USB: %dmV %dmA\n", vset, ich_out); 1591 + dev_dbg(di->dev, "Enable USB: %d uV %d uA\n", vset_uv, ich_out_ua); 1608 1592 1609 1593 /* Check if the requested voltage or current is valid */ 1610 - volt_index = ab8500_voltage_to_regval(vset); 1611 - curr_index = ab8500_current_to_regval(di, ich_out); 1594 + volt_index = ab8500_voltage_to_regval(vset_uv); 1595 + curr_index = ab8500_current_to_regval(di, ich_out_ua); 1612 1596 if (volt_index < 0 || curr_index < 0) { 1613 1597 dev_err(di->dev, 1614 1598 "Charger voltage or current too high, " ··· 1649 1633 1650 1634 /* USBChInputCurr: current that can be drawn from the usb */ 1651 1635 ret = ab8500_charger_set_vbus_in_curr(di, 1652 - di->max_usb_in_curr.usb_type_max); 1636 + di->max_usb_in_curr.usb_type_max_ua); 1653 1637 if (ret) { 1654 1638 dev_err(di->dev, "setting USBChInputCurr failed\n"); 1655 1639 return ret; 1656 1640 } 1657 1641 1658 1642 /* ChOutputCurentLevel: protected output current */ 1659 - ret = ab8500_charger_set_output_curr(di, ich_out); 1643 + ret = ab8500_charger_set_output_curr(di, ich_out_ua); 1660 1644 if (ret) { 1661 1645 dev_err(di->dev, "%s " 1662 1646 "Failed to set ChOutputCurentLevel\n", ··· 1742 1726 /** 1743 1727 * ab8500_charger_usb_check_enable() - enable usb charging 1744 1728 * @charger: pointer to the ux500_charger structure 1745 - * @vset: charging voltage 1746 - * @iset: charger output current 1729 + * @vset_uv: charging voltage in microvolt 1730 + * @iset_ua: charger output current in microampere 1747 1731 * 1748 1732 * Check if the VBUS charger has been disconnected and reconnected without 1749 1733 * AB8500 rising an interrupt. Returns 0 on success. 1750 1734 */ 1751 1735 static int ab8500_charger_usb_check_enable(struct ux500_charger *charger, 1752 - int vset, int iset) 1736 + int vset_uv, int iset_ua) 1753 1737 { 1754 1738 u8 usbch_ctrl1 = 0; 1755 1739 int ret = 0; ··· 1778 1762 return ret; 1779 1763 } 1780 1764 1781 - ret = ab8500_charger_usb_en(&di->usb_chg, true, vset, iset); 1765 + ret = ab8500_charger_usb_en(&di->usb_chg, true, vset_uv, iset_ua); 1782 1766 if (ret < 0) { 1783 1767 dev_err(di->dev, "Failed to enable VBUS charger %d\n", 1784 1768 __LINE__); ··· 1791 1775 /** 1792 1776 * ab8500_charger_ac_check_enable() - enable usb charging 1793 1777 * @charger: pointer to the ux500_charger structure 1794 - * @vset: charging voltage 1795 - * @iset: charger output current 1778 + * @vset_uv: charging voltage in microvolt 1779 + * @iset_ua: charger output current in micrompere 1796 1780 * 1797 1781 * Check if the AC charger has been disconnected and reconnected without 1798 1782 * AB8500 rising an interrupt. Returns 0 on success. 1799 1783 */ 1800 1784 static int ab8500_charger_ac_check_enable(struct ux500_charger *charger, 1801 - int vset, int iset) 1785 + int vset_uv, int iset_ua) 1802 1786 { 1803 1787 u8 mainch_ctrl1 = 0; 1804 1788 int ret = 0; ··· 1828 1812 return ret; 1829 1813 } 1830 1814 1831 - ret = ab8500_charger_ac_en(&di->usb_chg, true, vset, iset); 1815 + ret = ab8500_charger_ac_en(&di->usb_chg, true, vset_uv, iset_ua); 1832 1816 if (ret < 0) { 1833 1817 dev_err(di->dev, "failed to enable AC charger %d\n", 1834 1818 __LINE__); ··· 1867 1851 1868 1852 /** 1869 1853 * ab8500_charger_update_charger_current() - update charger current 1870 - * @di: pointer to the ab8500_charger structure 1854 + * @charger: pointer to the ab8500_charger structure 1855 + * @ich_out_ua: desired output current in microampere 1871 1856 * 1872 1857 * Update the charger output current for the specified charger 1873 1858 * Returns error code in case of failure else 0(on success) 1874 1859 */ 1875 1860 static int ab8500_charger_update_charger_current(struct ux500_charger *charger, 1876 - int ich_out) 1861 + int ich_out_ua) 1877 1862 { 1878 1863 int ret; 1879 1864 struct ab8500_charger *di; ··· 1886 1869 else 1887 1870 return -ENXIO; 1888 1871 1889 - ret = ab8500_charger_set_output_curr(di, ich_out); 1872 + ret = ab8500_charger_set_output_curr(di, ich_out_ua); 1890 1873 if (ret) { 1891 1874 dev_err(di->dev, "%s " 1892 1875 "Failed to set ChOutputCurentLevel\n", ··· 1978 1961 di->vbat > VBAT_TRESH_IP_CUR_RED))) { 1979 1962 1980 1963 dev_dbg(di->dev, "Vbat did cross threshold, curr: %d, new: %d," 1981 - " old: %d\n", di->max_usb_in_curr.usb_type_max, 1964 + " old: %d\n", di->max_usb_in_curr.usb_type_max_ua, 1982 1965 di->vbat, di->old_vbat); 1983 1966 ab8500_charger_set_vbus_in_curr(di, 1984 - di->max_usb_in_curr.usb_type_max); 1967 + di->max_usb_in_curr.usb_type_max_ua); 1985 1968 power_supply_changed(di->usb_chg.psy); 1986 1969 } 1987 1970 ··· 2262 2245 /* Update maximum input current if USB enumeration is not detected */ 2263 2246 if (!di->usb.charger_online) { 2264 2247 ret = ab8500_charger_set_vbus_in_curr(di, 2265 - di->max_usb_in_curr.usb_type_max); 2248 + di->max_usb_in_curr.usb_type_max_ua); 2266 2249 if (ret) 2267 2250 return; 2268 2251 } ··· 2424 2407 2425 2408 spin_lock_irqsave(&di->usb_state.usb_lock, flags); 2426 2409 di->usb_state.state = di->usb_state.state_tmp; 2427 - di->usb_state.usb_current = di->usb_state.usb_current_tmp; 2410 + di->usb_state.usb_current_ua = di->usb_state.usb_current_tmp_ua; 2428 2411 spin_unlock_irqrestore(&di->usb_state.usb_lock, flags); 2429 2412 2430 - dev_dbg(di->dev, "%s USB state: 0x%02x mA: %d\n", 2431 - __func__, di->usb_state.state, di->usb_state.usb_current); 2413 + dev_dbg(di->dev, "%s USB state: 0x%02x uA: %d\n", 2414 + __func__, di->usb_state.state, di->usb_state.usb_current_ua); 2432 2415 2433 2416 switch (di->usb_state.state) { 2434 2417 case AB8500_BM_USB_STATE_RESET_HS: ··· 2454 2437 if (!ab8500_charger_get_usb_cur(di)) { 2455 2438 /* Update maximum input current */ 2456 2439 ret = ab8500_charger_set_vbus_in_curr(di, 2457 - di->max_usb_in_curr.usb_type_max); 2440 + di->max_usb_in_curr.usb_type_max_ua); 2458 2441 if (ret) 2459 2442 return; 2460 2443 ··· 2674 2657 { 2675 2658 struct ab8500_charger *di = container_of(work, 2676 2659 struct ab8500_charger, vbus_drop_end_work.work); 2677 - int ret, curr; 2660 + int ret, curr_ua; 2678 2661 u8 reg_value; 2679 2662 2680 2663 di->flags.vbus_drop_end = false; ··· 2690 2673 return; 2691 2674 } 2692 2675 2693 - curr = di->bm->chg_input_curr[ 2676 + curr_ua = ab8500_charge_input_curr_map[ 2694 2677 reg_value >> AUTO_VBUS_IN_CURR_LIM_SHIFT]; 2695 2678 2696 - if (di->max_usb_in_curr.calculated_max != curr) { 2679 + if (di->max_usb_in_curr.calculated_max_ua != curr_ua) { 2697 2680 /* USB source is collapsing */ 2698 - di->max_usb_in_curr.calculated_max = curr; 2681 + di->max_usb_in_curr.calculated_max_ua = curr_ua; 2699 2682 dev_dbg(di->dev, 2700 - "VBUS input current limiting to %d mA\n", 2701 - di->max_usb_in_curr.calculated_max); 2683 + "VBUS input current limiting to %d uA\n", 2684 + di->max_usb_in_curr.calculated_max_ua); 2702 2685 } else { 2703 2686 /* 2704 2687 * USB source can not give more than this amount. 2705 2688 * Taking more will collapse the source. 2706 2689 */ 2707 - di->max_usb_in_curr.set_max = 2708 - di->max_usb_in_curr.calculated_max; 2690 + di->max_usb_in_curr.set_max_ua = 2691 + di->max_usb_in_curr.calculated_max_ua; 2709 2692 dev_dbg(di->dev, 2710 - "VBUS input current limited to %d mA\n", 2711 - di->max_usb_in_curr.set_max); 2693 + "VBUS input current limited to %d uA\n", 2694 + di->max_usb_in_curr.set_max_ua); 2712 2695 } 2713 2696 2714 2697 if (di->usb.charger_connected) 2715 2698 ab8500_charger_set_vbus_in_curr(di, 2716 - di->max_usb_in_curr.usb_type_max); 2699 + di->max_usb_in_curr.usb_type_max_ua); 2717 2700 } 2718 2701 2719 2702 /** ··· 2943 2926 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 2944 2927 ret = ab8500_charger_get_ac_voltage(di); 2945 2928 if (ret >= 0) 2946 - di->ac.charger_voltage = ret; 2929 + di->ac.charger_voltage_uv = ret; 2947 2930 /* On error, use previous value */ 2948 - val->intval = di->ac.charger_voltage * 1000; 2931 + val->intval = di->ac.charger_voltage_uv; 2949 2932 break; 2950 2933 case POWER_SUPPLY_PROP_VOLTAGE_AVG: 2951 2934 /* ··· 2958 2941 case POWER_SUPPLY_PROP_CURRENT_NOW: 2959 2942 ret = ab8500_charger_get_ac_current(di); 2960 2943 if (ret >= 0) 2961 - di->ac.charger_current = ret; 2962 - val->intval = di->ac.charger_current * 1000; 2944 + di->ac.charger_current_ua = ret; 2945 + val->intval = di->ac.charger_current_ua; 2963 2946 break; 2964 2947 default: 2965 2948 return -EINVAL; ··· 3012 2995 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 3013 2996 ret = ab8500_charger_get_vbus_voltage(di); 3014 2997 if (ret >= 0) 3015 - di->usb.charger_voltage = ret; 3016 - val->intval = di->usb.charger_voltage * 1000; 2998 + di->usb.charger_voltage_uv = ret; 2999 + val->intval = di->usb.charger_voltage_uv; 3017 3000 break; 3018 3001 case POWER_SUPPLY_PROP_VOLTAGE_AVG: 3019 3002 /* ··· 3026 3009 case POWER_SUPPLY_PROP_CURRENT_NOW: 3027 3010 ret = ab8500_charger_get_usb_current(di); 3028 3011 if (ret >= 0) 3029 - di->usb.charger_current = ret; 3030 - val->intval = di->usb.charger_current * 1000; 3012 + di->usb.charger_current_ua = ret; 3013 + val->intval = di->usb.charger_current_ua; 3031 3014 break; 3032 3015 case POWER_SUPPLY_PROP_CURRENT_AVG: 3033 3016 /* ··· 3203 3186 struct ab8500_charger *di = 3204 3187 container_of(nb, struct ab8500_charger, nb); 3205 3188 enum ab8500_usb_state bm_usb_state; 3189 + /* 3190 + * FIXME: it appears the AB8500 PHY never sends what it should here. 3191 + * Fix the PHY driver to properly notify the desired current. 3192 + * Also broadcast microampere and not milliampere. 3193 + */ 3206 3194 unsigned mA = *((unsigned *)power); 3207 3195 3208 3196 if (event != USB_EVENT_VBUS) { ··· 3218 3196 /* TODO: State is fabricate here. See if charger really needs USB 3219 3197 * state or if mA is enough 3220 3198 */ 3221 - if ((di->usb_state.usb_current == 2) && (mA > 2)) 3199 + if ((di->usb_state.usb_current_ua == 2000) && (mA > 2)) 3222 3200 bm_usb_state = AB8500_BM_USB_STATE_RESUME; 3223 3201 else if (mA == 0) 3224 3202 bm_usb_state = AB8500_BM_USB_STATE_RESET_HS; ··· 3234 3212 3235 3213 spin_lock(&di->usb_state.usb_lock); 3236 3214 di->usb_state.state_tmp = bm_usb_state; 3237 - di->usb_state.usb_current_tmp = mA; 3215 + /* FIXME: broadcast ua instead, see above */ 3216 + di->usb_state.usb_current_tmp_ua = mA * 1000; 3238 3217 spin_unlock(&di->usb_state.usb_lock); 3239 3218 3240 3219 /* ··· 3436 3413 3437 3414 di->bm = &ab8500_bm_data; 3438 3415 3439 - ret = ab8500_bm_of_probe(dev, np, di->bm); 3440 - if (ret) { 3441 - dev_err(dev, "failed to get battery information\n"); 3442 - return ret; 3443 - } 3444 3416 di->autopower_cfg = of_property_read_bool(np, "autopower_cfg"); 3445 3417 3446 3418 /* get parent data */ ··· 3508 3490 di->invalid_charger_detect_state = 0; 3509 3491 3510 3492 /* AC and USB supply config */ 3493 + ac_psy_cfg.of_node = np; 3511 3494 ac_psy_cfg.supplied_to = supply_interface; 3512 3495 ac_psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface); 3513 3496 ac_psy_cfg.drv_data = &di->ac_chg; 3497 + usb_psy_cfg.of_node = np; 3514 3498 usb_psy_cfg.supplied_to = supply_interface; 3515 3499 usb_psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface); 3516 3500 usb_psy_cfg.drv_data = &di->usb_chg; ··· 3523 3503 di->ac_chg.ops.check_enable = &ab8500_charger_ac_check_enable; 3524 3504 di->ac_chg.ops.kick_wd = &ab8500_charger_watchdog_kick; 3525 3505 di->ac_chg.ops.update_curr = &ab8500_charger_update_charger_current; 3526 - di->ac_chg.max_out_volt = ab8500_charger_voltage_map[ 3506 + di->ac_chg.max_out_volt_uv = ab8500_charger_voltage_map[ 3527 3507 ARRAY_SIZE(ab8500_charger_voltage_map) - 1]; 3528 - di->ac_chg.max_out_curr = 3529 - di->bm->chg_output_curr[di->bm->n_chg_out_curr - 1]; 3508 + di->ac_chg.max_out_curr_ua = 3509 + ab8500_charge_output_curr_map[ARRAY_SIZE(ab8500_charge_output_curr_map) - 1]; 3530 3510 di->ac_chg.wdt_refresh = CHG_WD_INTERVAL; 3531 3511 /* 3532 3512 * The AB8505 only supports USB charging. If we are not the ··· 3544 3524 di->usb_chg.ops.check_enable = &ab8500_charger_usb_check_enable; 3545 3525 di->usb_chg.ops.kick_wd = &ab8500_charger_watchdog_kick; 3546 3526 di->usb_chg.ops.update_curr = &ab8500_charger_update_charger_current; 3547 - di->usb_chg.max_out_volt = ab8500_charger_voltage_map[ 3527 + di->usb_chg.max_out_volt_uv = ab8500_charger_voltage_map[ 3548 3528 ARRAY_SIZE(ab8500_charger_voltage_map) - 1]; 3549 - di->usb_chg.max_out_curr = 3550 - di->bm->chg_output_curr[di->bm->n_chg_out_curr - 1]; 3529 + di->usb_chg.max_out_curr_ua = 3530 + ab8500_charge_output_curr_map[ARRAY_SIZE(ab8500_charge_output_curr_map) - 1]; 3551 3531 di->usb_chg.wdt_refresh = CHG_WD_INTERVAL; 3552 3532 di->usb_chg.external = false; 3553 - di->usb_state.usb_current = -1; 3533 + di->usb_state.usb_current_ua = -1; 3554 3534 3555 3535 mutex_init(&di->charger_attached_mutex); 3556 3536 ··· 3630 3610 return PTR_ERR(di->usb_chg.psy); 3631 3611 } 3632 3612 3613 + /* 3614 + * Check what battery we have, since we always have the USB 3615 + * psy, use that as a handle. 3616 + */ 3617 + ret = ab8500_bm_of_probe(di->usb_chg.psy, di->bm); 3618 + if (ret) 3619 + return dev_err_probe(dev, ret, 3620 + "failed to get battery information\n"); 3621 + 3633 3622 /* Identify the connected charger types during startup */ 3634 3623 charger_status = ab8500_charger_detect_chargers(di, true); 3635 3624 if (charger_status & AC_PW_CONN) { ··· 3665 3636 } 3666 3637 if (!match) { 3667 3638 dev_err(dev, "no matching components\n"); 3668 - return -ENODEV; 3639 + ret = -ENODEV; 3640 + goto remove_ab8500_bm; 3669 3641 } 3670 3642 if (IS_ERR(match)) { 3671 3643 dev_err(dev, "could not create component match\n"); 3672 - return PTR_ERR(match); 3644 + ret = PTR_ERR(match); 3645 + goto remove_ab8500_bm; 3673 3646 } 3674 3647 3675 3648 /* Notifier for external charger enabling */ ··· 3712 3681 if (!di->ac_chg.enabled) 3713 3682 blocking_notifier_chain_unregister( 3714 3683 &charger_notifier_list, &charger_nb); 3684 + remove_ab8500_bm: 3685 + ab8500_bm_of_remove(di->usb_chg.psy, di->bm); 3715 3686 return ret; 3716 3687 } 3717 3688 ··· 3724 3691 component_master_del(&pdev->dev, &ab8500_charger_comp_ops); 3725 3692 3726 3693 usb_unregister_notifier(di->usb_phy, &di->nb); 3694 + ab8500_bm_of_remove(di->usb_chg.psy, di->bm); 3727 3695 usb_put_phy(di->usb_phy); 3728 3696 if (!di->ac_chg.enabled) 3729 3697 blocking_notifier_chain_unregister(
+173 -200
drivers/power/supply/ab8500_fg.c
··· 38 38 39 39 #include "ab8500-bm.h" 40 40 41 - #define MILLI_TO_MICRO 1000 42 41 #define FG_LSB_IN_MA 1627 43 42 #define QLSB_NANO_AMP_HOURS_X10 1071 44 43 #define INS_CURR_TIMEOUT (3 * HZ) ··· 156 157 * @dev: Pointer to the structure device 157 158 * @node: a list of AB8500 FGs, hence prepared for reentrance 158 159 * @irq holds the CCEOC interrupt number 159 - * @vbat: Battery voltage in mV 160 - * @vbat_nom: Nominal battery voltage in mV 161 - * @inst_curr: Instantenous battery current in mA 162 - * @avg_curr: Average battery current in mA 160 + * @vbat_uv: Battery voltage in uV 161 + * @vbat_nom_uv: Nominal battery voltage in uV 162 + * @inst_curr_ua: Instantenous battery current in uA 163 + * @avg_curr_ua: Average battery current in uA 163 164 * @bat_temp battery temperature 164 165 * @fg_samples: Number of samples used in the FG accumulation 165 166 * @accu_charge: Accumulated charge from the last conversion ··· 198 199 struct device *dev; 199 200 struct list_head node; 200 201 int irq; 201 - int vbat; 202 - int vbat_nom; 203 - int inst_curr; 204 - int avg_curr; 202 + int vbat_uv; 203 + int vbat_nom_uv; 204 + int inst_curr_ua; 205 + int avg_curr_ua; 205 206 int bat_temp; 206 207 int fg_samples; 207 208 int accu_charge; ··· 265 266 266 267 /* 267 268 * This array maps the raw hex value to lowbat voltage used by the AB8500 268 - * Values taken from the UM0836 269 + * Values taken from the UM0836, in microvolts. 269 270 */ 270 271 static int ab8500_fg_lowbat_voltage_map[] = { 271 - 2300 , 272 - 2325 , 273 - 2350 , 274 - 2375 , 275 - 2400 , 276 - 2425 , 277 - 2450 , 278 - 2475 , 279 - 2500 , 280 - 2525 , 281 - 2550 , 282 - 2575 , 283 - 2600 , 284 - 2625 , 285 - 2650 , 286 - 2675 , 287 - 2700 , 288 - 2725 , 289 - 2750 , 290 - 2775 , 291 - 2800 , 292 - 2825 , 293 - 2850 , 294 - 2875 , 295 - 2900 , 296 - 2925 , 297 - 2950 , 298 - 2975 , 299 - 3000 , 300 - 3025 , 301 - 3050 , 302 - 3075 , 303 - 3100 , 304 - 3125 , 305 - 3150 , 306 - 3175 , 307 - 3200 , 308 - 3225 , 309 - 3250 , 310 - 3275 , 311 - 3300 , 312 - 3325 , 313 - 3350 , 314 - 3375 , 315 - 3400 , 316 - 3425 , 317 - 3450 , 318 - 3475 , 319 - 3500 , 320 - 3525 , 321 - 3550 , 322 - 3575 , 323 - 3600 , 324 - 3625 , 325 - 3650 , 326 - 3675 , 327 - 3700 , 328 - 3725 , 329 - 3750 , 330 - 3775 , 331 - 3800 , 332 - 3825 , 333 - 3850 , 334 - 3850 , 272 + 2300000, 273 + 2325000, 274 + 2350000, 275 + 2375000, 276 + 2400000, 277 + 2425000, 278 + 2450000, 279 + 2475000, 280 + 2500000, 281 + 2525000, 282 + 2550000, 283 + 2575000, 284 + 2600000, 285 + 2625000, 286 + 2650000, 287 + 2675000, 288 + 2700000, 289 + 2725000, 290 + 2750000, 291 + 2775000, 292 + 2800000, 293 + 2825000, 294 + 2850000, 295 + 2875000, 296 + 2900000, 297 + 2925000, 298 + 2950000, 299 + 2975000, 300 + 3000000, 301 + 3025000, 302 + 3050000, 303 + 3075000, 304 + 3100000, 305 + 3125000, 306 + 3150000, 307 + 3175000, 308 + 3200000, 309 + 3225000, 310 + 3250000, 311 + 3275000, 312 + 3300000, 313 + 3325000, 314 + 3350000, 315 + 3375000, 316 + 3400000, 317 + 3425000, 318 + 3450000, 319 + 3475000, 320 + 3500000, 321 + 3525000, 322 + 3550000, 323 + 3575000, 324 + 3600000, 325 + 3625000, 326 + 3650000, 327 + 3675000, 328 + 3700000, 329 + 3725000, 330 + 3750000, 331 + 3775000, 332 + 3800000, 333 + 3825000, 334 + 3850000, 335 + 3850000, 335 336 }; 336 337 337 - static u8 ab8500_volt_to_regval(int voltage) 338 + static u8 ab8500_volt_to_regval(int voltage_uv) 338 339 { 339 340 int i; 340 341 341 - if (voltage < ab8500_fg_lowbat_voltage_map[0]) 342 + if (voltage_uv < ab8500_fg_lowbat_voltage_map[0]) 342 343 return 0; 343 344 344 345 for (i = 0; i < ARRAY_SIZE(ab8500_fg_lowbat_voltage_map); i++) { 345 - if (voltage < ab8500_fg_lowbat_voltage_map[i]) 346 + if (voltage_uv < ab8500_fg_lowbat_voltage_map[i]) 346 347 return (u8) i - 1; 347 348 } 348 349 ··· 353 354 /** 354 355 * ab8500_fg_is_low_curr() - Low or high current mode 355 356 * @di: pointer to the ab8500_fg structure 356 - * @curr: the current to base or our decision on 357 + * @curr_ua: the current to base or our decision on in microampere 357 358 * 358 359 * Low current mode if the current consumption is below a certain threshold 359 360 */ 360 - static int ab8500_fg_is_low_curr(struct ab8500_fg *di, int curr) 361 + static int ab8500_fg_is_low_curr(struct ab8500_fg *di, int curr_ua) 361 362 { 362 363 /* 363 364 * We want to know if we're in low current mode 364 365 */ 365 - if (curr > -di->bm->fg_params->high_curr_threshold) 366 + if (curr_ua > -di->bm->fg_params->high_curr_threshold_ua) 366 367 return true; 367 368 else 368 369 return false; ··· 600 601 /** 601 602 * ab8500_fg_inst_curr_finalize() - battery instantaneous current 602 603 * @di: pointer to the ab8500_fg structure 603 - * @res: battery instantenous current(on success) 604 + * @curr_ua: battery instantenous current in microampere (on success) 604 605 * 605 606 * Returns 0 or an error code 606 607 * Note: This is part "two" and has to be called at earliest 250 ms 607 608 * after ab8500_fg_inst_curr_start() 608 609 */ 609 - int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *res) 610 + int ab8500_fg_inst_curr_finalize(struct ab8500_fg *di, int *curr_ua) 610 611 { 611 612 u8 low, high; 612 613 int val; ··· 662 663 /* 663 664 * Convert to unit value in mA 664 665 * Full scale input voltage is 665 - * 63.160mV => LSB = 63.160mV/(4096*res) = 1.542mA 666 + * 63.160mV => LSB = 63.160mV/(4096*res) = 1.542.000 uA 666 667 * Given a 250ms conversion cycle time the LSB corresponds 667 668 * to 107.1 nAh. Convert to current by dividing by the conversion 668 669 * time in hours (250ms = 1 / (3600 * 4)h) 669 670 * 107.1nAh assumes 10mOhm, but fg_res is in 0.1mOhm 670 671 */ 671 - val = (val * QLSB_NANO_AMP_HOURS_X10 * 36 * 4) / 672 - (1000 * di->bm->fg_res); 672 + val = (val * QLSB_NANO_AMP_HOURS_X10 * 36 * 4) / di->bm->fg_res; 673 673 674 674 if (di->turn_off_fg) { 675 675 dev_dbg(di->dev, "%s Disable FG\n", __func__); ··· 686 688 goto fail; 687 689 } 688 690 mutex_unlock(&di->cc_lock); 689 - (*res) = val; 691 + *curr_ua = val; 690 692 691 693 return 0; 692 694 fail: ··· 697 699 /** 698 700 * ab8500_fg_inst_curr_blocking() - battery instantaneous current 699 701 * @di: pointer to the ab8500_fg structure 700 - * @res: battery instantenous current(on success) 701 702 * 702 - * Returns 0 else error code 703 + * Returns battery instantenous current in microampere (on success) 704 + * else error code 703 705 */ 704 706 int ab8500_fg_inst_curr_blocking(struct ab8500_fg *di) 705 707 { 706 708 int ret; 707 709 unsigned long timeout; 708 - int res = 0; 710 + int curr_ua = 0; 709 711 710 712 ret = ab8500_fg_inst_curr_start(di); 711 713 if (ret) { ··· 728 730 } 729 731 } 730 732 731 - ret = ab8500_fg_inst_curr_finalize(di, &res); 733 + ret = ab8500_fg_inst_curr_finalize(di, &curr_ua); 732 734 if (ret) { 733 735 dev_err(di->dev, "Failed to finalize fg_inst\n"); 734 736 return 0; 735 737 } 736 738 737 - dev_dbg(di->dev, "%s instant current: %d", __func__, res); 738 - return res; 739 + dev_dbg(di->dev, "%s instant current: %d uA", __func__, curr_ua); 740 + return curr_ua; 739 741 fail: 740 742 disable_irq(di->irq); 741 743 mutex_unlock(&di->cc_lock); ··· 795 797 (100 * di->bm->fg_res); 796 798 797 799 /* 798 - * Convert to unit value in mA 800 + * Convert to unit value in uA 799 801 * by dividing by the conversion 800 802 * time in hours (= samples / (3600 * 4)h) 801 - * and multiply with 1000 802 803 */ 803 - di->avg_curr = (val * QLSB_NANO_AMP_HOURS_X10 * 36) / 804 - (1000 * di->bm->fg_res * (di->fg_samples / 4)); 804 + di->avg_curr_ua = (val * QLSB_NANO_AMP_HOURS_X10 * 36) / 805 + (di->bm->fg_res * (di->fg_samples / 4)); 805 806 806 807 di->flags.conv_done = true; 807 808 ··· 822 825 * ab8500_fg_bat_voltage() - get battery voltage 823 826 * @di: pointer to the ab8500_fg structure 824 827 * 825 - * Returns battery voltage(on success) else error code 828 + * Returns battery voltage in microvolts (on success) else error code 826 829 */ 827 830 static int ab8500_fg_bat_voltage(struct ab8500_fg *di) 828 831 { ··· 837 840 return prev; 838 841 } 839 842 843 + /* IIO returns millivolts but we want microvolts */ 844 + vbat *= 1000; 840 845 prev = vbat; 841 846 return vbat; 842 847 } ··· 846 847 /** 847 848 * ab8500_fg_volt_to_capacity() - Voltage based capacity 848 849 * @di: pointer to the ab8500_fg structure 849 - * @voltage: The voltage to convert to a capacity 850 + * @voltage_uv: The voltage to convert to a capacity in microvolt 850 851 * 851 852 * Returns battery capacity in per mille based on voltage 852 853 */ 853 - static int ab8500_fg_volt_to_capacity(struct ab8500_fg *di, int voltage) 854 + static int ab8500_fg_volt_to_capacity(struct ab8500_fg *di, int voltage_uv) 854 855 { 855 - int i, tbl_size; 856 - const struct ab8500_v_to_cap *tbl; 857 - int cap = 0; 856 + struct power_supply_battery_info *bi = di->bm->bi; 858 857 859 - tbl = di->bm->bat_type[di->bm->batt_id].v_to_cap_tbl; 860 - tbl_size = di->bm->bat_type[di->bm->batt_id].n_v_cap_tbl_elements; 861 - 862 - for (i = 0; i < tbl_size; ++i) { 863 - if (voltage > tbl[i].voltage) 864 - break; 865 - } 866 - 867 - if ((i > 0) && (i < tbl_size)) { 868 - cap = fixp_linear_interpolate( 869 - tbl[i].voltage, 870 - tbl[i].capacity * 10, 871 - tbl[i-1].voltage, 872 - tbl[i-1].capacity * 10, 873 - voltage); 874 - } else if (i == 0) { 875 - cap = 1000; 876 - } else { 877 - cap = 0; 878 - } 879 - 880 - dev_dbg(di->dev, "%s Vbat: %d, Cap: %d per mille", 881 - __func__, voltage, cap); 882 - 883 - return cap; 858 + /* Multiply by 10 because the capacity is tracked in per mille */ 859 + return power_supply_batinfo_ocv2cap(bi, voltage_uv, di->bat_temp) * 10; 884 860 } 885 861 886 862 /** ··· 867 893 */ 868 894 static int ab8500_fg_uncomp_volt_to_capacity(struct ab8500_fg *di) 869 895 { 870 - di->vbat = ab8500_fg_bat_voltage(di); 871 - return ab8500_fg_volt_to_capacity(di, di->vbat); 896 + di->vbat_uv = ab8500_fg_bat_voltage(di); 897 + return ab8500_fg_volt_to_capacity(di, di->vbat_uv); 872 898 } 873 899 874 900 /** ··· 876 902 * @di: pointer to the ab8500_fg structure 877 903 * 878 904 * Returns battery inner resistance added with the fuel gauge resistor value 879 - * to get the total resistance in the whole link from gnd to bat+ node. 905 + * to get the total resistance in the whole link from gnd to bat+ node 906 + * in milliohm. 880 907 */ 881 908 static int ab8500_fg_battery_resistance(struct ab8500_fg *di) 882 909 { 883 - int i, tbl_size; 884 - const struct batres_vs_temp *tbl; 885 - int resist = 0; 910 + struct power_supply_battery_info *bi = di->bm->bi; 911 + int resistance_percent = 0; 912 + int resistance; 886 913 887 - tbl = di->bm->bat_type[di->bm->batt_id].batres_tbl; 888 - tbl_size = di->bm->bat_type[di->bm->batt_id].n_batres_tbl_elements; 889 - 890 - for (i = 0; i < tbl_size; ++i) { 891 - if (di->bat_temp / 10 > tbl[i].temp) 892 - break; 893 - } 894 - 895 - if ((i > 0) && (i < tbl_size)) { 896 - resist = fixp_linear_interpolate( 897 - tbl[i].temp, 898 - tbl[i].resist, 899 - tbl[i-1].temp, 900 - tbl[i-1].resist, 901 - di->bat_temp / 10); 902 - } else if (i == 0) { 903 - resist = tbl[0].resist; 904 - } else { 905 - resist = tbl[tbl_size - 1].resist; 906 - } 914 + resistance_percent = power_supply_temp2resist_simple(bi->resist_table, 915 + bi->resist_table_size, 916 + di->bat_temp / 10); 917 + /* 918 + * We get a percentage of factory resistance here so first get 919 + * the factory resistance in milliohms then calculate how much 920 + * resistance we have at this temperature. 921 + */ 922 + resistance = (bi->factory_internal_resistance_uohm / 1000); 923 + resistance = resistance * resistance_percent / 100; 907 924 908 925 dev_dbg(di->dev, "%s Temp: %d battery internal resistance: %d" 909 926 " fg resistance %d, total: %d (mOhm)\n", 910 - __func__, di->bat_temp, resist, di->bm->fg_res / 10, 911 - (di->bm->fg_res / 10) + resist); 927 + __func__, di->bat_temp, resistance, di->bm->fg_res / 10, 928 + (di->bm->fg_res / 10) + resistance); 912 929 913 930 /* fg_res variable is in 0.1mOhm */ 914 - resist += di->bm->fg_res / 10; 931 + resistance += di->bm->fg_res / 10; 915 932 916 - return resist; 933 + return resistance; 917 934 } 918 935 919 936 /** ··· 916 951 */ 917 952 static int ab8500_fg_load_comp_volt_to_capacity(struct ab8500_fg *di) 918 953 { 919 - int vbat_comp, res; 954 + int vbat_comp_uv, res; 920 955 int i = 0; 921 - int vbat = 0; 956 + int vbat_uv = 0; 922 957 923 958 ab8500_fg_inst_curr_start(di); 924 959 925 960 do { 926 - vbat += ab8500_fg_bat_voltage(di); 961 + vbat_uv += ab8500_fg_bat_voltage(di); 927 962 i++; 928 963 usleep_range(5000, 6000); 929 964 } while (!ab8500_fg_inst_curr_done(di)); 930 965 931 - ab8500_fg_inst_curr_finalize(di, &di->inst_curr); 966 + ab8500_fg_inst_curr_finalize(di, &di->inst_curr_ua); 932 967 933 - di->vbat = vbat / i; 968 + di->vbat_uv = vbat_uv / i; 934 969 res = ab8500_fg_battery_resistance(di); 935 970 936 - /* Use Ohms law to get the load compensated voltage */ 937 - vbat_comp = di->vbat - (di->inst_curr * res) / 1000; 971 + /* 972 + * Use Ohms law to get the load compensated voltage. 973 + * Divide by 1000 to get from milliohms to ohms. 974 + */ 975 + vbat_comp_uv = di->vbat_uv - (di->inst_curr_ua * res) / 1000; 938 976 939 - dev_dbg(di->dev, "%s Measured Vbat: %dmV,Compensated Vbat %dmV, " 940 - "R: %dmOhm, Current: %dmA Vbat Samples: %d\n", 941 - __func__, di->vbat, vbat_comp, res, di->inst_curr, i); 977 + dev_dbg(di->dev, "%s Measured Vbat: %d uV,Compensated Vbat %d uV, " 978 + "R: %d mOhm, Current: %d uA Vbat Samples: %d\n", 979 + __func__, di->vbat_uv, vbat_comp_uv, res, di->inst_curr_ua, i); 942 980 943 - return ab8500_fg_volt_to_capacity(di, vbat_comp); 981 + return ab8500_fg_volt_to_capacity(di, vbat_comp_uv); 944 982 } 945 983 946 984 /** ··· 982 1014 u64 div_res; 983 1015 u32 div_rem; 984 1016 985 - div_res = ((u64) cap_mah) * ((u64) di->vbat_nom); 986 - div_rem = do_div(div_res, 1000); 1017 + /* 1018 + * Capacity is in milli ampere hours (10^-3)Ah 1019 + * Nominal voltage is in microvolts (10^-6)V 1020 + * divide by 1000000 after multiplication to get to mWh 1021 + */ 1022 + div_res = ((u64) cap_mah) * ((u64) di->vbat_nom_uv); 1023 + div_rem = do_div(div_res, 1000000); 987 1024 988 1025 /* Make sure to round upwards if necessary */ 989 - if (div_rem >= 1000 / 2) 1026 + if (div_rem >= 1000000 / 2) 990 1027 div_res++; 991 1028 992 1029 return (int) div_res; ··· 1030 1057 ab8500_fg_convert_mah_to_permille(di, di->bat_cap.mah); 1031 1058 1032 1059 /* We need to update battery voltage and inst current when charging */ 1033 - di->vbat = ab8500_fg_bat_voltage(di); 1034 - di->inst_curr = ab8500_fg_inst_curr_blocking(di); 1060 + di->vbat_uv = ab8500_fg_bat_voltage(di); 1061 + di->inst_curr_ua = ab8500_fg_inst_curr_blocking(di); 1035 1062 1036 1063 return di->bat_cap.mah; 1037 1064 } ··· 1558 1585 * RECOVERY_SLEEP if time left. 1559 1586 * If high, go to READOUT 1560 1587 */ 1561 - di->inst_curr = ab8500_fg_inst_curr_blocking(di); 1588 + di->inst_curr_ua = ab8500_fg_inst_curr_blocking(di); 1562 1589 1563 - if (ab8500_fg_is_low_curr(di, di->inst_curr)) { 1590 + if (ab8500_fg_is_low_curr(di, di->inst_curr_ua)) { 1564 1591 if (di->recovery_cnt > 1565 1592 di->bm->fg_params->recovery_total_time) { 1566 1593 di->fg_samples = SEC_TO_SAMPLE( ··· 1593 1620 break; 1594 1621 1595 1622 case AB8500_FG_DISCHARGE_READOUT: 1596 - di->inst_curr = ab8500_fg_inst_curr_blocking(di); 1623 + di->inst_curr_ua = ab8500_fg_inst_curr_blocking(di); 1597 1624 1598 - if (ab8500_fg_is_low_curr(di, di->inst_curr)) { 1625 + if (ab8500_fg_is_low_curr(di, di->inst_curr_ua)) { 1599 1626 /* Detect mode change */ 1600 1627 if (di->high_curr_mode) { 1601 1628 di->high_curr_mode = false; ··· 1741 1768 di->bat_cap.prev_mah, 1742 1769 di->bat_cap.prev_percent, 1743 1770 di->bat_cap.prev_level, 1744 - di->vbat, 1745 - di->inst_curr, 1746 - di->avg_curr, 1771 + di->vbat_uv, 1772 + di->inst_curr_ua, 1773 + di->avg_curr_ua, 1747 1774 di->accu_charge, 1748 1775 di->flags.charging, 1749 1776 di->charge_state, ··· 1836 1863 */ 1837 1864 static void ab8500_fg_low_bat_work(struct work_struct *work) 1838 1865 { 1839 - int vbat; 1866 + int vbat_uv; 1840 1867 1841 1868 struct ab8500_fg *di = container_of(work, struct ab8500_fg, 1842 1869 fg_low_bat_work.work); 1843 1870 1844 - vbat = ab8500_fg_bat_voltage(di); 1871 + vbat_uv = ab8500_fg_bat_voltage(di); 1845 1872 1846 1873 /* Check if LOW_BAT still fulfilled */ 1847 - if (vbat < di->bm->fg_params->lowbat_threshold) { 1874 + if (vbat_uv < di->bm->fg_params->lowbat_threshold_uv) { 1848 1875 /* Is it time to shut down? */ 1849 1876 if (di->low_bat_cnt < 1) { 1850 1877 di->flags.low_bat = true; ··· 2074 2101 switch (psp) { 2075 2102 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 2076 2103 if (di->flags.bat_ovv) 2077 - val->intval = BATT_OVV_VALUE * 1000; 2104 + val->intval = BATT_OVV_VALUE; 2078 2105 else 2079 - val->intval = di->vbat * 1000; 2106 + val->intval = di->vbat_uv; 2080 2107 break; 2081 2108 case POWER_SUPPLY_PROP_CURRENT_NOW: 2082 - val->intval = di->inst_curr * 1000; 2109 + val->intval = di->inst_curr_ua; 2083 2110 break; 2084 2111 case POWER_SUPPLY_PROP_CURRENT_AVG: 2085 - val->intval = di->avg_curr * 1000; 2112 + val->intval = di->avg_curr_ua; 2086 2113 break; 2087 2114 case POWER_SUPPLY_PROP_ENERGY_FULL_DESIGN: 2088 2115 val->intval = ab8500_fg_convert_mah_to_uwh(di, ··· 2140 2167 struct power_supply *ext = dev_get_drvdata(dev); 2141 2168 const char **supplicants = (const char **)ext->supplied_to; 2142 2169 struct ab8500_fg *di; 2170 + struct power_supply_battery_info *bi; 2143 2171 union power_supply_propval ret; 2144 2172 int j; 2145 2173 2146 2174 psy = (struct power_supply *)data; 2147 2175 di = power_supply_get_drvdata(psy); 2176 + bi = di->bm->bi; 2148 2177 2149 2178 /* 2150 2179 * For all psy where the name of your driver ··· 2209 2234 switch (ext->desc->type) { 2210 2235 case POWER_SUPPLY_TYPE_BATTERY: 2211 2236 if (!di->flags.batt_id_received && 2212 - di->bm->batt_id != BATTERY_UNKNOWN) { 2237 + (bi && (bi->technology != 2238 + POWER_SUPPLY_TECHNOLOGY_UNKNOWN))) { 2213 2239 const struct ab8500_battery_type *b; 2214 2240 2215 - b = &(di->bm->bat_type[di->bm->batt_id]); 2241 + b = di->bm->bat_type; 2216 2242 2217 2243 di->flags.batt_id_received = true; 2218 2244 2219 2245 di->bat_cap.max_mah_design = 2220 - MILLI_TO_MICRO * 2221 - b->charge_full_design; 2246 + di->bm->bi->charge_full_design_uah; 2222 2247 2223 2248 di->bat_cap.max_mah = 2224 2249 di->bat_cap.max_mah_design; 2225 2250 2226 - di->vbat_nom = b->nominal_voltage; 2251 + di->vbat_nom_uv = 2252 + di->bm->bi->voltage_max_design_uv; 2227 2253 } 2228 2254 2229 2255 if (ret.intval) ··· 2290 2314 AB8500_SYS_CTRL2_BLOCK, 2291 2315 AB8500_LOW_BAT_REG, 2292 2316 ab8500_volt_to_regval( 2293 - di->bm->fg_params->lowbat_threshold) << 1 | 2317 + di->bm->fg_params->lowbat_threshold_uv) << 1 | 2294 2318 LOW_BAT_ENABLE); 2295 2319 if (ret) { 2296 2320 dev_err(di->dev, "%s write failed\n", __func__); ··· 2994 3018 return -ENOMEM; 2995 3019 } 2996 3020 3021 + di->bat_cap.max_mah_design = di->bm->bi->charge_full_design_uah; 3022 + di->bat_cap.max_mah = di->bat_cap.max_mah_design; 3023 + di->vbat_nom_uv = di->bm->bi->voltage_max_design_uv; 3024 + 2997 3025 /* Start the coulomb counter */ 2998 3026 ab8500_fg_coulomb_counter(di, true); 2999 3027 /* Run the FG algorithm */ ··· 3056 3076 psy_cfg.supplied_to = supply_interface; 3057 3077 psy_cfg.num_supplicants = ARRAY_SIZE(supply_interface); 3058 3078 psy_cfg.drv_data = di; 3059 - 3060 - di->bat_cap.max_mah_design = MILLI_TO_MICRO * 3061 - di->bm->bat_type[di->bm->batt_id].charge_full_design; 3062 - 3063 - di->bat_cap.max_mah = di->bat_cap.max_mah_design; 3064 - 3065 - di->vbat_nom = di->bm->bat_type[di->bm->batt_id].nominal_voltage; 3066 3079 3067 3080 di->init_capacity = true; 3068 3081
+3 -3
drivers/power/supply/axp20x_battery.c
··· 561 561 { 562 562 struct axp20x_batt_ps *axp20x_batt; 563 563 struct power_supply_config psy_cfg = {}; 564 - struct power_supply_battery_info info; 564 + struct power_supply_battery_info *info; 565 565 struct device *dev = &pdev->dev; 566 566 567 567 if (!of_device_is_available(pdev->dev.of_node)) ··· 615 615 } 616 616 617 617 if (!power_supply_get_battery_info(axp20x_batt->batt, &info)) { 618 - int vmin = info.voltage_min_design_uv; 619 - int ccc = info.constant_charge_current_max_ua; 618 + int vmin = info->voltage_min_design_uv; 619 + int ccc = info->constant_charge_current_max_ua; 620 620 621 621 if (vmin > 0 && axp20x_set_voltage_min_design(axp20x_batt, 622 622 vmin))
+13 -11
drivers/power/supply/bd99954-charger.c
··· 882 882 static int bd9995x_fw_probe(struct bd9995x_device *bd) 883 883 { 884 884 int ret; 885 - struct power_supply_battery_info info; 885 + struct power_supply_battery_info *info; 886 886 u32 property; 887 887 int i; 888 888 int regval; ··· 891 891 struct battery_init battery_inits[] = { 892 892 { 893 893 .name = "trickle-charging current", 894 - .info_data = &info.tricklecharge_current_ua, 895 894 .range = &charging_current_ranges[0], 896 895 .ranges = 2, 897 896 .data = &init->itrich_set, 898 897 }, { 899 898 .name = "pre-charging current", 900 - .info_data = &info.precharge_current_ua, 901 899 .range = &charging_current_ranges[0], 902 900 .ranges = 2, 903 901 .data = &init->iprech_set, 904 902 }, { 905 903 .name = "pre-to-trickle charge voltage threshold", 906 - .info_data = &info.precharge_voltage_max_uv, 907 904 .range = &trickle_to_pre_threshold_ranges[0], 908 905 .ranges = 2, 909 906 .data = &init->vprechg_th_set, 910 907 }, { 911 908 .name = "charging termination current", 912 - .info_data = &info.charge_term_current_ua, 913 909 .range = &charging_current_ranges[0], 914 910 .ranges = 2, 915 911 .data = &init->iterm_set, 916 912 }, { 917 913 .name = "charging re-start voltage", 918 - .info_data = &info.charge_restart_voltage_uv, 919 914 .range = &charge_voltage_regulation_ranges[0], 920 915 .ranges = 2, 921 916 .data = &init->vrechg_set, 922 917 }, { 923 918 .name = "battery overvoltage limit", 924 - .info_data = &info.overvoltage_limit_uv, 925 919 .range = &charge_voltage_regulation_ranges[0], 926 920 .ranges = 2, 927 921 .data = &init->vbatovp_set, 928 922 }, { 929 923 .name = "fast-charging max current", 930 - .info_data = &info.constant_charge_current_max_ua, 931 924 .range = &fast_charge_current_ranges[0], 932 925 .ranges = 1, 933 926 .data = &init->ichg_set, 934 927 }, { 935 928 .name = "fast-charging voltage", 936 - .info_data = &info.constant_charge_voltage_max_uv, 937 929 .range = &charge_voltage_regulation_ranges[0], 938 930 .ranges = 2, 939 931 .data = &init->vfastchg_reg_set1, ··· 958 966 if (ret < 0) 959 967 return ret; 960 968 969 + /* Put pointers to the generic battery info */ 970 + battery_inits[0].info_data = &info->tricklecharge_current_ua; 971 + battery_inits[1].info_data = &info->precharge_current_ua; 972 + battery_inits[2].info_data = &info->precharge_voltage_max_uv; 973 + battery_inits[3].info_data = &info->charge_term_current_ua; 974 + battery_inits[4].info_data = &info->charge_restart_voltage_uv; 975 + battery_inits[5].info_data = &info->overvoltage_limit_uv; 976 + battery_inits[6].info_data = &info->constant_charge_current_max_ua; 977 + battery_inits[7].info_data = &info->constant_charge_voltage_max_uv; 978 + 961 979 for (i = 0; i < ARRAY_SIZE(battery_inits); i++) { 962 980 int val = *battery_inits[i].info_data; 963 981 const struct linear_range *range = battery_inits[i].range; ··· 982 980 dev_err(bd->dev, "Unsupported value for %s\n", 983 981 battery_inits[i].name); 984 982 985 - power_supply_put_battery_info(bd->charger, &info); 983 + power_supply_put_battery_info(bd->charger, info); 986 984 return -EINVAL; 987 985 } 988 986 if (!found) { ··· 993 991 *(battery_inits[i].data) = regval; 994 992 } 995 993 996 - power_supply_put_battery_info(bd->charger, &info); 994 + power_supply_put_battery_info(bd->charger, info); 997 995 998 996 for (i = 0; i < ARRAY_SIZE(props); i++) { 999 997 ret = device_property_read_u32(bd->dev, props[i].prop,
+3 -3
drivers/power/supply/bq24190_charger.c
··· 1670 1670 static int bq24190_get_config(struct bq24190_dev_info *bdi) 1671 1671 { 1672 1672 const char * const s = "ti,system-minimum-microvolt"; 1673 - struct power_supply_battery_info info = {}; 1673 + struct power_supply_battery_info *info; 1674 1674 int v; 1675 1675 1676 1676 if (device_property_read_u32(bdi->dev, s, &v) == 0) { ··· 1684 1684 1685 1685 if (bdi->dev->of_node && 1686 1686 !power_supply_get_battery_info(bdi->charger, &info)) { 1687 - v = info.precharge_current_ua / 1000; 1687 + v = info->precharge_current_ua / 1000; 1688 1688 if (v >= BQ24190_REG_PCTCC_IPRECHG_MIN 1689 1689 && v <= BQ24190_REG_PCTCC_IPRECHG_MAX) 1690 1690 bdi->iprechg = v; ··· 1692 1692 dev_warn(bdi->dev, "invalid value for battery:precharge-current-microamp: %d\n", 1693 1693 v); 1694 1694 1695 - v = info.charge_term_current_ua / 1000; 1695 + v = info->charge_term_current_ua / 1000; 1696 1696 if (v >= BQ24190_REG_PCTCC_ITERM_MIN 1697 1697 && v <= BQ24190_REG_PCTCC_ITERM_MAX) 1698 1698 bdi->iterm = v;
+4 -4
drivers/power/supply/bq2515x_charger.c
··· 945 945 static int bq2515x_hw_init(struct bq2515x_device *bq2515x) 946 946 { 947 947 int ret; 948 - struct power_supply_battery_info bat_info = { }; 948 + struct power_supply_battery_info *bat_info; 949 949 950 950 ret = bq2515x_disable_watchdog_timers(bq2515x); 951 951 if (ret) ··· 969 969 970 970 } else { 971 971 bq2515x->init_data.ichg = 972 - bat_info.constant_charge_current_max_ua; 972 + bat_info->constant_charge_current_max_ua; 973 973 974 974 bq2515x->init_data.vbatreg = 975 - bat_info.constant_charge_voltage_max_uv; 975 + bat_info->constant_charge_voltage_max_uv; 976 976 977 977 bq2515x->init_data.iprechg = 978 - bat_info.precharge_current_ua; 978 + bat_info->precharge_current_ua; 979 979 } 980 980 981 981 ret = bq2515x_set_const_charge_current(bq2515x,
+12 -12
drivers/power/supply/bq256xx_charger.c
··· 1504 1504 1505 1505 static int bq256xx_hw_init(struct bq256xx_device *bq) 1506 1506 { 1507 - struct power_supply_battery_info bat_info = { }; 1507 + struct power_supply_battery_info *bat_info; 1508 1508 int wd_reg_val = BQ256XX_WATCHDOG_DIS; 1509 1509 int ret = 0; 1510 1510 int i; ··· 1526 1526 if (ret) { 1527 1527 dev_warn(bq->dev, "battery info missing, default values will be applied\n"); 1528 1528 1529 - bat_info.constant_charge_current_max_ua = 1529 + bat_info->constant_charge_current_max_ua = 1530 1530 bq->chip_info->bq256xx_def_ichg; 1531 1531 1532 - bat_info.constant_charge_voltage_max_uv = 1532 + bat_info->constant_charge_voltage_max_uv = 1533 1533 bq->chip_info->bq256xx_def_vbatreg; 1534 1534 1535 - bat_info.precharge_current_ua = 1535 + bat_info->precharge_current_ua = 1536 1536 bq->chip_info->bq256xx_def_iprechg; 1537 1537 1538 - bat_info.charge_term_current_ua = 1538 + bat_info->charge_term_current_ua = 1539 1539 bq->chip_info->bq256xx_def_iterm; 1540 1540 1541 1541 bq->init_data.ichg_max = ··· 1545 1545 bq->chip_info->bq256xx_max_vbatreg; 1546 1546 } else { 1547 1547 bq->init_data.ichg_max = 1548 - bat_info.constant_charge_current_max_ua; 1548 + bat_info->constant_charge_current_max_ua; 1549 1549 1550 1550 bq->init_data.vbatreg_max = 1551 - bat_info.constant_charge_voltage_max_uv; 1551 + bat_info->constant_charge_voltage_max_uv; 1552 1552 } 1553 1553 1554 1554 ret = bq->chip_info->bq256xx_set_vindpm(bq, bq->init_data.vindpm); ··· 1560 1560 return ret; 1561 1561 1562 1562 ret = bq->chip_info->bq256xx_set_ichg(bq, 1563 - bat_info.constant_charge_current_max_ua); 1563 + bat_info->constant_charge_current_max_ua); 1564 1564 if (ret) 1565 1565 return ret; 1566 1566 1567 1567 ret = bq->chip_info->bq256xx_set_iprechg(bq, 1568 - bat_info.precharge_current_ua); 1568 + bat_info->precharge_current_ua); 1569 1569 if (ret) 1570 1570 return ret; 1571 1571 1572 1572 ret = bq->chip_info->bq256xx_set_vbatreg(bq, 1573 - bat_info.constant_charge_voltage_max_uv); 1573 + bat_info->constant_charge_voltage_max_uv); 1574 1574 if (ret) 1575 1575 return ret; 1576 1576 1577 1577 ret = bq->chip_info->bq256xx_set_iterm(bq, 1578 - bat_info.charge_term_current_ua); 1578 + bat_info->charge_term_current_ua); 1579 1579 if (ret) 1580 1580 return ret; 1581 1581 1582 - power_supply_put_battery_info(bq->charger, &bat_info); 1582 + power_supply_put_battery_info(bq->charger, bat_info); 1583 1583 1584 1584 return 0; 1585 1585 }
+36 -1
drivers/power/supply/bq25890_charger.c
··· 266 266 /* lookup tables */ 267 267 TBL_TREG, 268 268 TBL_BOOSTI, 269 + TBL_TSPCT, 269 270 }; 270 271 271 272 /* Thermal Regulation Threshold lookup table, in degrees Celsius */ ··· 280 279 }; 281 280 282 281 #define BQ25890_BOOSTI_TBL_SIZE ARRAY_SIZE(bq25890_boosti_tbl) 282 + 283 + /* NTC 10K temperature lookup table in tenths of a degree */ 284 + static const u32 bq25890_tspct_tbl[] = { 285 + 850, 840, 830, 820, 810, 800, 790, 780, 286 + 770, 760, 750, 740, 730, 720, 710, 700, 287 + 690, 685, 680, 675, 670, 660, 650, 645, 288 + 640, 630, 620, 615, 610, 600, 590, 585, 289 + 580, 570, 565, 560, 550, 540, 535, 530, 290 + 520, 515, 510, 500, 495, 490, 480, 475, 291 + 470, 460, 455, 450, 440, 435, 430, 425, 292 + 420, 410, 405, 400, 390, 385, 380, 370, 293 + 365, 360, 355, 350, 340, 335, 330, 320, 294 + 310, 305, 300, 290, 285, 280, 275, 270, 295 + 260, 250, 245, 240, 230, 225, 220, 210, 296 + 205, 200, 190, 180, 175, 170, 160, 150, 297 + 145, 140, 130, 120, 115, 110, 100, 90, 298 + 80, 70, 60, 50, 40, 30, 20, 10, 299 + 0, -10, -20, -30, -40, -60, -70, -80, 300 + -90, -10, -120, -140, -150, -170, -190, -210, 301 + }; 302 + 303 + #define BQ25890_TSPCT_TBL_SIZE ARRAY_SIZE(bq25890_tspct_tbl) 283 304 284 305 struct bq25890_range { 285 306 u32 min; ··· 331 308 332 309 /* lookup tables */ 333 310 [TBL_TREG] = { .lt = {bq25890_treg_tbl, BQ25890_TREG_TBL_SIZE} }, 334 - [TBL_BOOSTI] = { .lt = {bq25890_boosti_tbl, BQ25890_BOOSTI_TBL_SIZE} } 311 + [TBL_BOOSTI] = { .lt = {bq25890_boosti_tbl, BQ25890_BOOSTI_TBL_SIZE} }, 312 + [TBL_TSPCT] = { .lt = {bq25890_tspct_tbl, BQ25890_TSPCT_TBL_SIZE} } 335 313 }; 336 314 337 315 static int bq25890_field_read(struct bq25890_device *bq, ··· 412 388 switch (psp) { 413 389 case POWER_SUPPLY_PROP_VOLTAGE_NOW: 414 390 case POWER_SUPPLY_PROP_CURRENT_NOW: 391 + case POWER_SUPPLY_PROP_TEMP: 415 392 return true; 416 393 417 394 default: ··· 551 526 552 527 /* converted_val = ADC_val * 50mA (table 10.3.19) */ 553 528 val->intval = ret * -50000; 529 + break; 530 + 531 + case POWER_SUPPLY_PROP_TEMP: 532 + ret = bq25890_field_read(bq, F_TSPCT); 533 + if (ret < 0) 534 + return ret; 535 + 536 + /* convert TS percentage into rough temperature */ 537 + val->intval = bq25890_find_val(ret, TBL_TSPCT); 554 538 break; 555 539 556 540 default: ··· 747 713 POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, 748 714 POWER_SUPPLY_PROP_VOLTAGE_NOW, 749 715 POWER_SUPPLY_PROP_CURRENT_NOW, 716 + POWER_SUPPLY_PROP_TEMP, 750 717 }; 751 718 752 719 static char *bq25890_charger_supplied_to[] = {
+3 -3
drivers/power/supply/bq25980_charger.c
··· 1079 1079 1080 1080 static int bq25980_hw_init(struct bq25980_device *bq) 1081 1081 { 1082 - struct power_supply_battery_info bat_info = { }; 1082 + struct power_supply_battery_info *bat_info; 1083 1083 int wd_reg_val = BQ25980_WATCHDOG_DIS; 1084 1084 int wd_max_val = BQ25980_NUM_WD_VAL - 1; 1085 1085 int ret = 0; ··· 1112 1112 return -EINVAL; 1113 1113 } 1114 1114 1115 - bq->init_data.ichg_max = bat_info.constant_charge_current_max_ua; 1116 - bq->init_data.vreg_max = bat_info.constant_charge_voltage_max_uv; 1115 + bq->init_data.ichg_max = bat_info->constant_charge_current_max_ua; 1116 + bq->init_data.vreg_max = bat_info->constant_charge_voltage_max_uv; 1117 1117 1118 1118 if (bq->state.bypass) { 1119 1119 ret = regmap_update_bits(bq->regmap, BQ25980_CHRGR_CTRL_2,
+19 -19
drivers/power/supply/bq27xxx_battery.c
··· 1474 1474 1475 1475 static void bq27xxx_battery_settings(struct bq27xxx_device_info *di) 1476 1476 { 1477 - struct power_supply_battery_info info = {}; 1477 + struct power_supply_battery_info *info; 1478 1478 unsigned int min, max; 1479 1479 1480 1480 if (power_supply_get_battery_info(di->bat, &info) < 0) ··· 1485 1485 return; 1486 1486 } 1487 1487 1488 - if (info.energy_full_design_uwh != info.charge_full_design_uah) { 1489 - if (info.energy_full_design_uwh == -EINVAL) 1488 + if (info->energy_full_design_uwh != info->charge_full_design_uah) { 1489 + if (info->energy_full_design_uwh == -EINVAL) 1490 1490 dev_warn(di->dev, "missing battery:energy-full-design-microwatt-hours\n"); 1491 - else if (info.charge_full_design_uah == -EINVAL) 1491 + else if (info->charge_full_design_uah == -EINVAL) 1492 1492 dev_warn(di->dev, "missing battery:charge-full-design-microamp-hours\n"); 1493 1493 } 1494 1494 1495 1495 /* assume min == 0 */ 1496 1496 max = di->dm_regs[BQ27XXX_DM_DESIGN_ENERGY].max; 1497 - if (info.energy_full_design_uwh > max * 1000) { 1497 + if (info->energy_full_design_uwh > max * 1000) { 1498 1498 dev_err(di->dev, "invalid battery:energy-full-design-microwatt-hours %d\n", 1499 - info.energy_full_design_uwh); 1500 - info.energy_full_design_uwh = -EINVAL; 1499 + info->energy_full_design_uwh); 1500 + info->energy_full_design_uwh = -EINVAL; 1501 1501 } 1502 1502 1503 1503 /* assume min == 0 */ 1504 1504 max = di->dm_regs[BQ27XXX_DM_DESIGN_CAPACITY].max; 1505 - if (info.charge_full_design_uah > max * 1000) { 1505 + if (info->charge_full_design_uah > max * 1000) { 1506 1506 dev_err(di->dev, "invalid battery:charge-full-design-microamp-hours %d\n", 1507 - info.charge_full_design_uah); 1508 - info.charge_full_design_uah = -EINVAL; 1507 + info->charge_full_design_uah); 1508 + info->charge_full_design_uah = -EINVAL; 1509 1509 } 1510 1510 1511 1511 min = di->dm_regs[BQ27XXX_DM_TERMINATE_VOLTAGE].min; 1512 1512 max = di->dm_regs[BQ27XXX_DM_TERMINATE_VOLTAGE].max; 1513 - if ((info.voltage_min_design_uv < min * 1000 || 1514 - info.voltage_min_design_uv > max * 1000) && 1515 - info.voltage_min_design_uv != -EINVAL) { 1513 + if ((info->voltage_min_design_uv < min * 1000 || 1514 + info->voltage_min_design_uv > max * 1000) && 1515 + info->voltage_min_design_uv != -EINVAL) { 1516 1516 dev_err(di->dev, "invalid battery:voltage-min-design-microvolt %d\n", 1517 - info.voltage_min_design_uv); 1518 - info.voltage_min_design_uv = -EINVAL; 1517 + info->voltage_min_design_uv); 1518 + info->voltage_min_design_uv = -EINVAL; 1519 1519 } 1520 1520 1521 - if ((info.energy_full_design_uwh != -EINVAL && 1522 - info.charge_full_design_uah != -EINVAL) || 1523 - info.voltage_min_design_uv != -EINVAL) 1524 - bq27xxx_battery_set_config(di, &info); 1521 + if ((info->energy_full_design_uwh != -EINVAL && 1522 + info->charge_full_design_uah != -EINVAL) || 1523 + info->voltage_min_design_uv != -EINVAL) 1524 + bq27xxx_battery_set_config(di, info); 1525 1525 } 1526 1526 1527 1527 /*
+13 -7
drivers/power/supply/cw2015_battery.c
··· 61 61 struct delayed_work battery_delay_work; 62 62 struct regmap *regmap; 63 63 struct power_supply *rk_bat; 64 - struct power_supply_battery_info battery; 64 + struct power_supply_battery_info *battery; 65 65 u8 *bat_profile; 66 66 67 67 bool charger_attached; ··· 505 505 506 506 case POWER_SUPPLY_PROP_CHARGE_FULL: 507 507 case POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN: 508 - if (cw_bat->battery.charge_full_design_uah > 0) 509 - val->intval = cw_bat->battery.charge_full_design_uah; 508 + if (cw_bat->battery->charge_full_design_uah > 0) 509 + val->intval = cw_bat->battery->charge_full_design_uah; 510 510 else 511 511 val->intval = 0; 512 512 break; 513 513 514 514 case POWER_SUPPLY_PROP_CHARGE_NOW: 515 - val->intval = cw_bat->battery.charge_full_design_uah; 515 + val->intval = cw_bat->battery->charge_full_design_uah; 516 516 val->intval = val->intval * cw_bat->soc / 100; 517 517 break; 518 518 519 519 case POWER_SUPPLY_PROP_CURRENT_NOW: 520 520 if (cw_battery_valid_time_to_empty(cw_bat) && 521 - cw_bat->battery.charge_full_design_uah > 0) { 521 + cw_bat->battery->charge_full_design_uah > 0) { 522 522 /* calculate remaining capacity */ 523 - val->intval = cw_bat->battery.charge_full_design_uah; 523 + val->intval = cw_bat->battery->charge_full_design_uah; 524 524 val->intval = val->intval * cw_bat->soc / 100; 525 525 526 526 /* estimate current based on time to empty */ ··· 687 687 688 688 ret = power_supply_get_battery_info(cw_bat->rk_bat, &cw_bat->battery); 689 689 if (ret) { 690 + /* Allocate an empty battery */ 691 + cw_bat->battery = devm_kzalloc(&client->dev, 692 + sizeof(cw_bat->battery), 693 + GFP_KERNEL); 694 + if (!cw_bat->battery) 695 + return -ENOMEM; 690 696 dev_warn(cw_bat->dev, 691 697 "No monitored battery, some properties will be missing\n"); 692 698 } ··· 730 724 struct cw_battery *cw_bat = i2c_get_clientdata(client); 731 725 732 726 cancel_delayed_work_sync(&cw_bat->battery_delay_work); 733 - power_supply_put_battery_info(cw_bat->rk_bat, &cw_bat->battery); 727 + power_supply_put_battery_info(cw_bat->rk_bat, cw_bat->battery); 734 728 return 0; 735 729 } 736 730
+7 -7
drivers/power/supply/ingenic-battery.c
··· 18 18 struct iio_channel *channel; 19 19 struct power_supply_desc desc; 20 20 struct power_supply *battery; 21 - struct power_supply_battery_info info; 21 + struct power_supply_battery_info *info; 22 22 }; 23 23 24 24 static int ingenic_battery_get_property(struct power_supply *psy, ··· 26 26 union power_supply_propval *val) 27 27 { 28 28 struct ingenic_battery *bat = power_supply_get_drvdata(psy); 29 - struct power_supply_battery_info *info = &bat->info; 29 + struct power_supply_battery_info *info = bat->info; 30 30 int ret; 31 31 32 32 switch (psp) { ··· 80 80 if (ret != IIO_AVAIL_LIST || scale_type != IIO_VAL_FRACTIONAL_LOG2) 81 81 return -EINVAL; 82 82 83 - max_mV = bat->info.voltage_max_design_uv / 1000; 83 + max_mV = bat->info->voltage_max_design_uv / 1000; 84 84 85 85 for (i = 0; i < scale_len; i += 2) { 86 86 u64 scale_mV = (max_raw * scale_raw[i]) >> scale_raw[i + 1]; ··· 156 156 dev_err(dev, "Unable to get battery info: %d\n", ret); 157 157 return ret; 158 158 } 159 - if (bat->info.voltage_min_design_uv < 0) { 159 + if (bat->info->voltage_min_design_uv < 0) { 160 160 dev_err(dev, "Unable to get voltage min design\n"); 161 - return bat->info.voltage_min_design_uv; 161 + return bat->info->voltage_min_design_uv; 162 162 } 163 - if (bat->info.voltage_max_design_uv < 0) { 163 + if (bat->info->voltage_max_design_uv < 0) { 164 164 dev_err(dev, "Unable to get voltage max design\n"); 165 - return bat->info.voltage_max_design_uv; 165 + return bat->info->voltage_max_design_uv; 166 166 } 167 167 168 168 return ingenic_battery_set_scale(bat);
+509
drivers/power/supply/max77976_charger.c
··· 1 + // SPDX-License-Identifier: GPL-2.0+ 2 + /* 3 + * max77976_charger.c - Driver for the Maxim MAX77976 battery charger 4 + * 5 + * Copyright (C) 2021 Luca Ceresoli 6 + * Author: Luca Ceresoli <luca@lucaceresoli.net> 7 + */ 8 + 9 + #include <linux/i2c.h> 10 + #include <linux/module.h> 11 + #include <linux/power_supply.h> 12 + #include <linux/regmap.h> 13 + 14 + #define MAX77976_DRIVER_NAME "max77976-charger" 15 + #define MAX77976_CHIP_ID 0x76 16 + 17 + static const char *max77976_manufacturer = "Maxim Integrated"; 18 + static const char *max77976_model = "MAX77976"; 19 + 20 + /* -------------------------------------------------------------------------- 21 + * Register map 22 + */ 23 + 24 + #define MAX77976_REG_CHIP_ID 0x00 25 + #define MAX77976_REG_CHIP_REVISION 0x01 26 + #define MAX77976_REG_CHG_INT_OK 0x12 27 + #define MAX77976_REG_CHG_DETAILS_01 0x14 28 + #define MAX77976_REG_CHG_CNFG_00 0x16 29 + #define MAX77976_REG_CHG_CNFG_02 0x18 30 + #define MAX77976_REG_CHG_CNFG_06 0x1c 31 + #define MAX77976_REG_CHG_CNFG_09 0x1f 32 + 33 + /* CHG_DETAILS_01.CHG_DTLS values */ 34 + enum max77976_charging_state { 35 + MAX77976_CHARGING_PREQUALIFICATION = 0x0, 36 + MAX77976_CHARGING_FAST_CONST_CURRENT, 37 + MAX77976_CHARGING_FAST_CONST_VOLTAGE, 38 + MAX77976_CHARGING_TOP_OFF, 39 + MAX77976_CHARGING_DONE, 40 + MAX77976_CHARGING_RESERVED_05, 41 + MAX77976_CHARGING_TIMER_FAULT, 42 + MAX77976_CHARGING_SUSPENDED_QBATT_OFF, 43 + MAX77976_CHARGING_OFF, 44 + MAX77976_CHARGING_RESERVED_09, 45 + MAX77976_CHARGING_THERMAL_SHUTDOWN, 46 + MAX77976_CHARGING_WATCHDOG_EXPIRED, 47 + MAX77976_CHARGING_SUSPENDED_JEITA, 48 + MAX77976_CHARGING_SUSPENDED_THM_REMOVAL, 49 + MAX77976_CHARGING_SUSPENDED_PIN, 50 + MAX77976_CHARGING_RESERVED_0F, 51 + }; 52 + 53 + /* CHG_DETAILS_01.BAT_DTLS values */ 54 + enum max77976_battery_state { 55 + MAX77976_BATTERY_BATTERY_REMOVAL = 0x0, 56 + MAX77976_BATTERY_PREQUALIFICATION, 57 + MAX77976_BATTERY_TIMER_FAULT, 58 + MAX77976_BATTERY_REGULAR_VOLTAGE, 59 + MAX77976_BATTERY_LOW_VOLTAGE, 60 + MAX77976_BATTERY_OVERVOLTAGE, 61 + MAX77976_BATTERY_RESERVED, 62 + MAX77976_BATTERY_BATTERY_ONLY, // No valid adapter is present 63 + }; 64 + 65 + /* CHG_CNFG_00.MODE values */ 66 + enum max77976_mode { 67 + MAX77976_MODE_CHARGER_BUCK = 0x5, 68 + MAX77976_MODE_BOOST = 0x9, 69 + }; 70 + 71 + /* CHG_CNFG_02.CHG_CC: charge current limit, 100..5500 mA, 50 mA steps */ 72 + #define MAX77976_CHG_CC_STEP 50000U 73 + #define MAX77976_CHG_CC_MIN 100000U 74 + #define MAX77976_CHG_CC_MAX 5500000U 75 + 76 + /* CHG_CNFG_09.CHGIN_ILIM: input current limit, 100..3200 mA, 100 mA steps */ 77 + #define MAX77976_CHGIN_ILIM_STEP 100000U 78 + #define MAX77976_CHGIN_ILIM_MIN 100000U 79 + #define MAX77976_CHGIN_ILIM_MAX 3200000U 80 + 81 + enum max77976_field_idx { 82 + VERSION, REVISION, /* CHIP_REVISION */ 83 + CHGIN_OK, /* CHG_INT_OK */ 84 + BAT_DTLS, CHG_DTLS, /* CHG_DETAILS_01 */ 85 + MODE, /* CHG_CNFG_00 */ 86 + CHG_CC, /* CHG_CNFG_02 */ 87 + CHGPROT, /* CHG_CNFG_06 */ 88 + CHGIN_ILIM, /* CHG_CNFG_09 */ 89 + MAX77976_N_REGMAP_FIELDS 90 + }; 91 + 92 + static const struct reg_field max77976_reg_field[MAX77976_N_REGMAP_FIELDS] = { 93 + [VERSION] = REG_FIELD(MAX77976_REG_CHIP_REVISION, 4, 7), 94 + [REVISION] = REG_FIELD(MAX77976_REG_CHIP_REVISION, 0, 3), 95 + [CHGIN_OK] = REG_FIELD(MAX77976_REG_CHG_INT_OK, 6, 6), 96 + [CHG_DTLS] = REG_FIELD(MAX77976_REG_CHG_DETAILS_01, 0, 3), 97 + [BAT_DTLS] = REG_FIELD(MAX77976_REG_CHG_DETAILS_01, 4, 6), 98 + [MODE] = REG_FIELD(MAX77976_REG_CHG_CNFG_00, 0, 3), 99 + [CHG_CC] = REG_FIELD(MAX77976_REG_CHG_CNFG_02, 0, 6), 100 + [CHGPROT] = REG_FIELD(MAX77976_REG_CHG_CNFG_06, 2, 3), 101 + [CHGIN_ILIM] = REG_FIELD(MAX77976_REG_CHG_CNFG_09, 0, 5), 102 + }; 103 + 104 + static const struct regmap_config max77976_regmap_config = { 105 + .reg_bits = 8, 106 + .val_bits = 8, 107 + .max_register = 0x24, 108 + }; 109 + 110 + /* -------------------------------------------------------------------------- 111 + * Data structures 112 + */ 113 + 114 + struct max77976 { 115 + struct i2c_client *client; 116 + struct regmap *regmap; 117 + struct regmap_field *rfield[MAX77976_N_REGMAP_FIELDS]; 118 + }; 119 + 120 + /* -------------------------------------------------------------------------- 121 + * power_supply properties 122 + */ 123 + 124 + static int max77976_get_status(struct max77976 *chg, int *val) 125 + { 126 + unsigned int regval; 127 + int err; 128 + 129 + err = regmap_field_read(chg->rfield[CHG_DTLS], &regval); 130 + if (err < 0) 131 + return err; 132 + 133 + switch (regval) { 134 + case MAX77976_CHARGING_PREQUALIFICATION: 135 + case MAX77976_CHARGING_FAST_CONST_CURRENT: 136 + case MAX77976_CHARGING_FAST_CONST_VOLTAGE: 137 + case MAX77976_CHARGING_TOP_OFF: 138 + *val = POWER_SUPPLY_STATUS_CHARGING; 139 + break; 140 + case MAX77976_CHARGING_DONE: 141 + *val = POWER_SUPPLY_STATUS_FULL; 142 + break; 143 + case MAX77976_CHARGING_TIMER_FAULT: 144 + case MAX77976_CHARGING_SUSPENDED_QBATT_OFF: 145 + case MAX77976_CHARGING_SUSPENDED_JEITA: 146 + case MAX77976_CHARGING_SUSPENDED_THM_REMOVAL: 147 + case MAX77976_CHARGING_SUSPENDED_PIN: 148 + *val = POWER_SUPPLY_STATUS_NOT_CHARGING; 149 + break; 150 + case MAX77976_CHARGING_OFF: 151 + case MAX77976_CHARGING_THERMAL_SHUTDOWN: 152 + case MAX77976_CHARGING_WATCHDOG_EXPIRED: 153 + *val = POWER_SUPPLY_STATUS_DISCHARGING; 154 + break; 155 + default: 156 + *val = POWER_SUPPLY_STATUS_UNKNOWN; 157 + } 158 + 159 + return 0; 160 + } 161 + 162 + static int max77976_get_charge_type(struct max77976 *chg, int *val) 163 + { 164 + unsigned int regval; 165 + int err; 166 + 167 + err = regmap_field_read(chg->rfield[CHG_DTLS], &regval); 168 + if (err < 0) 169 + return err; 170 + 171 + switch (regval) { 172 + case MAX77976_CHARGING_PREQUALIFICATION: 173 + *val = POWER_SUPPLY_CHARGE_TYPE_TRICKLE; 174 + break; 175 + case MAX77976_CHARGING_FAST_CONST_CURRENT: 176 + case MAX77976_CHARGING_FAST_CONST_VOLTAGE: 177 + *val = POWER_SUPPLY_CHARGE_TYPE_FAST; 178 + break; 179 + case MAX77976_CHARGING_TOP_OFF: 180 + *val = POWER_SUPPLY_CHARGE_TYPE_STANDARD; 181 + break; 182 + case MAX77976_CHARGING_DONE: 183 + case MAX77976_CHARGING_TIMER_FAULT: 184 + case MAX77976_CHARGING_SUSPENDED_QBATT_OFF: 185 + case MAX77976_CHARGING_OFF: 186 + case MAX77976_CHARGING_THERMAL_SHUTDOWN: 187 + case MAX77976_CHARGING_WATCHDOG_EXPIRED: 188 + case MAX77976_CHARGING_SUSPENDED_JEITA: 189 + case MAX77976_CHARGING_SUSPENDED_THM_REMOVAL: 190 + case MAX77976_CHARGING_SUSPENDED_PIN: 191 + *val = POWER_SUPPLY_CHARGE_TYPE_NONE; 192 + break; 193 + default: 194 + *val = POWER_SUPPLY_CHARGE_TYPE_UNKNOWN; 195 + } 196 + 197 + return 0; 198 + } 199 + 200 + static int max77976_get_health(struct max77976 *chg, int *val) 201 + { 202 + unsigned int regval; 203 + int err; 204 + 205 + err = regmap_field_read(chg->rfield[BAT_DTLS], &regval); 206 + if (err < 0) 207 + return err; 208 + 209 + switch (regval) { 210 + case MAX77976_BATTERY_BATTERY_REMOVAL: 211 + *val = POWER_SUPPLY_HEALTH_NO_BATTERY; 212 + break; 213 + case MAX77976_BATTERY_LOW_VOLTAGE: 214 + case MAX77976_BATTERY_REGULAR_VOLTAGE: 215 + *val = POWER_SUPPLY_HEALTH_GOOD; 216 + break; 217 + case MAX77976_BATTERY_TIMER_FAULT: 218 + *val = POWER_SUPPLY_HEALTH_SAFETY_TIMER_EXPIRE; 219 + break; 220 + case MAX77976_BATTERY_OVERVOLTAGE: 221 + *val = POWER_SUPPLY_HEALTH_OVERVOLTAGE; 222 + break; 223 + case MAX77976_BATTERY_PREQUALIFICATION: 224 + case MAX77976_BATTERY_BATTERY_ONLY: 225 + *val = POWER_SUPPLY_HEALTH_UNKNOWN; 226 + break; 227 + default: 228 + *val = POWER_SUPPLY_HEALTH_UNKNOWN; 229 + } 230 + 231 + return 0; 232 + } 233 + 234 + static int max77976_get_online(struct max77976 *chg, int *val) 235 + { 236 + unsigned int regval; 237 + int err; 238 + 239 + err = regmap_field_read(chg->rfield[CHGIN_OK], &regval); 240 + if (err < 0) 241 + return err; 242 + 243 + *val = (regval ? 1 : 0); 244 + 245 + return 0; 246 + } 247 + 248 + static int max77976_get_integer(struct max77976 *chg, enum max77976_field_idx fidx, 249 + unsigned int clamp_min, unsigned int clamp_max, 250 + unsigned int mult, int *val) 251 + { 252 + unsigned int regval; 253 + int err; 254 + 255 + err = regmap_field_read(chg->rfield[fidx], &regval); 256 + if (err < 0) 257 + return err; 258 + 259 + *val = clamp_val(regval * mult, clamp_min, clamp_max); 260 + 261 + return 0; 262 + } 263 + 264 + static int max77976_set_integer(struct max77976 *chg, enum max77976_field_idx fidx, 265 + unsigned int clamp_min, unsigned int clamp_max, 266 + unsigned int div, int val) 267 + { 268 + unsigned int regval; 269 + 270 + regval = clamp_val(val, clamp_min, clamp_max) / div; 271 + 272 + return regmap_field_write(chg->rfield[fidx], regval); 273 + } 274 + 275 + static int max77976_get_property(struct power_supply *psy, 276 + enum power_supply_property psp, 277 + union power_supply_propval *val) 278 + { 279 + struct max77976 *chg = power_supply_get_drvdata(psy); 280 + int err = 0; 281 + 282 + switch (psp) { 283 + case POWER_SUPPLY_PROP_STATUS: 284 + err = max77976_get_status(chg, &val->intval); 285 + break; 286 + case POWER_SUPPLY_PROP_CHARGE_TYPE: 287 + err = max77976_get_charge_type(chg, &val->intval); 288 + break; 289 + case POWER_SUPPLY_PROP_HEALTH: 290 + err = max77976_get_health(chg, &val->intval); 291 + break; 292 + case POWER_SUPPLY_PROP_ONLINE: 293 + err = max77976_get_online(chg, &val->intval); 294 + break; 295 + case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX: 296 + val->intval = MAX77976_CHG_CC_MAX; 297 + break; 298 + case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT: 299 + err = max77976_get_integer(chg, CHG_CC, 300 + MAX77976_CHG_CC_MIN, 301 + MAX77976_CHG_CC_MAX, 302 + MAX77976_CHG_CC_STEP, 303 + &val->intval); 304 + break; 305 + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: 306 + err = max77976_get_integer(chg, CHGIN_ILIM, 307 + MAX77976_CHGIN_ILIM_MIN, 308 + MAX77976_CHGIN_ILIM_MAX, 309 + MAX77976_CHGIN_ILIM_STEP, 310 + &val->intval); 311 + break; 312 + case POWER_SUPPLY_PROP_MODEL_NAME: 313 + val->strval = max77976_model; 314 + break; 315 + case POWER_SUPPLY_PROP_MANUFACTURER: 316 + val->strval = max77976_manufacturer; 317 + break; 318 + default: 319 + err = -EINVAL; 320 + } 321 + 322 + return err; 323 + } 324 + 325 + static int max77976_set_property(struct power_supply *psy, 326 + enum power_supply_property psp, 327 + const union power_supply_propval *val) 328 + { 329 + struct max77976 *chg = power_supply_get_drvdata(psy); 330 + int err = 0; 331 + 332 + switch (psp) { 333 + case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT: 334 + err = max77976_set_integer(chg, CHG_CC, 335 + MAX77976_CHG_CC_MIN, 336 + MAX77976_CHG_CC_MAX, 337 + MAX77976_CHG_CC_STEP, 338 + val->intval); 339 + break; 340 + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: 341 + err = max77976_set_integer(chg, CHGIN_ILIM, 342 + MAX77976_CHGIN_ILIM_MIN, 343 + MAX77976_CHGIN_ILIM_MAX, 344 + MAX77976_CHGIN_ILIM_STEP, 345 + val->intval); 346 + break; 347 + default: 348 + err = -EINVAL; 349 + } 350 + 351 + return err; 352 + }; 353 + 354 + static int max77976_property_is_writeable(struct power_supply *psy, 355 + enum power_supply_property psp) 356 + { 357 + switch (psp) { 358 + case POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT: 359 + case POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT: 360 + return true; 361 + default: 362 + return false; 363 + } 364 + } 365 + 366 + static enum power_supply_property max77976_psy_props[] = { 367 + POWER_SUPPLY_PROP_STATUS, 368 + POWER_SUPPLY_PROP_CHARGE_TYPE, 369 + POWER_SUPPLY_PROP_HEALTH, 370 + POWER_SUPPLY_PROP_ONLINE, 371 + POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, 372 + POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, 373 + POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT, 374 + POWER_SUPPLY_PROP_MODEL_NAME, 375 + POWER_SUPPLY_PROP_MANUFACTURER, 376 + }; 377 + 378 + static const struct power_supply_desc max77976_psy_desc = { 379 + .name = MAX77976_DRIVER_NAME, 380 + .type = POWER_SUPPLY_TYPE_USB, 381 + .properties = max77976_psy_props, 382 + .num_properties = ARRAY_SIZE(max77976_psy_props), 383 + .get_property = max77976_get_property, 384 + .set_property = max77976_set_property, 385 + .property_is_writeable = max77976_property_is_writeable, 386 + }; 387 + 388 + /* -------------------------------------------------------------------------- 389 + * Entry point 390 + */ 391 + 392 + static int max77976_detect(struct max77976 *chg) 393 + { 394 + struct device *dev = &chg->client->dev; 395 + unsigned int id, ver, rev; 396 + int err; 397 + 398 + err = regmap_read(chg->regmap, MAX77976_REG_CHIP_ID, &id); 399 + if (err) 400 + return dev_err_probe(dev, err, "cannot read chip ID\n"); 401 + 402 + if (id != MAX77976_CHIP_ID) 403 + return dev_err_probe(dev, -ENXIO, "unknown model ID 0x%02x\n", id); 404 + 405 + err = regmap_field_read(chg->rfield[VERSION], &ver); 406 + if (!err) 407 + err = regmap_field_read(chg->rfield[REVISION], &rev); 408 + if (err) 409 + return dev_err_probe(dev, -ENXIO, "cannot read version/revision\n"); 410 + 411 + dev_info(dev, "detected model MAX779%02x ver %u rev %u", id, ver, rev); 412 + 413 + return 0; 414 + } 415 + 416 + static int max77976_configure(struct max77976 *chg) 417 + { 418 + struct device *dev = &chg->client->dev; 419 + int err; 420 + 421 + /* Magic value to unlock writing to some registers */ 422 + err = regmap_field_write(chg->rfield[CHGPROT], 0x3); 423 + if (err) 424 + goto err; 425 + 426 + /* 427 + * Mode 5 = Charger ON, OTG OFF, buck ON, boost OFF. 428 + * Other modes are not implemented by this driver. 429 + */ 430 + err = regmap_field_write(chg->rfield[MODE], MAX77976_MODE_CHARGER_BUCK); 431 + if (err) 432 + goto err; 433 + 434 + return 0; 435 + 436 + err: 437 + return dev_err_probe(dev, err, "error while configuring"); 438 + } 439 + 440 + static int max77976_probe(struct i2c_client *client) 441 + { 442 + struct device *dev = &client->dev; 443 + struct power_supply_config psy_cfg = {}; 444 + struct power_supply *psy; 445 + struct max77976 *chg; 446 + int err; 447 + int i; 448 + 449 + chg = devm_kzalloc(dev, sizeof(*chg), GFP_KERNEL); 450 + if (!chg) 451 + return -ENOMEM; 452 + 453 + i2c_set_clientdata(client, chg); 454 + psy_cfg.drv_data = chg; 455 + chg->client = client; 456 + 457 + chg->regmap = devm_regmap_init_i2c(client, &max77976_regmap_config); 458 + if (IS_ERR(chg->regmap)) 459 + return dev_err_probe(dev, PTR_ERR(chg->regmap), 460 + "cannot allocate regmap\n"); 461 + 462 + for (i = 0; i < MAX77976_N_REGMAP_FIELDS; i++) { 463 + chg->rfield[i] = devm_regmap_field_alloc(dev, chg->regmap, 464 + max77976_reg_field[i]); 465 + if (IS_ERR(chg->rfield[i])) 466 + return dev_err_probe(dev, PTR_ERR(chg->rfield[i]), 467 + "cannot allocate regmap field\n"); 468 + } 469 + 470 + err = max77976_detect(chg); 471 + if (err) 472 + return err; 473 + 474 + err = max77976_configure(chg); 475 + if (err) 476 + return err; 477 + 478 + psy = devm_power_supply_register_no_ws(dev, &max77976_psy_desc, &psy_cfg); 479 + if (IS_ERR(psy)) 480 + return dev_err_probe(dev, PTR_ERR(psy), "cannot register\n"); 481 + 482 + return 0; 483 + } 484 + 485 + static const struct i2c_device_id max77976_i2c_id[] = { 486 + { MAX77976_DRIVER_NAME, 0 }, 487 + { }, 488 + }; 489 + MODULE_DEVICE_TABLE(i2c, max77976_i2c_id); 490 + 491 + static const struct of_device_id max77976_of_id[] = { 492 + { .compatible = "maxim,max77976" }, 493 + { }, 494 + }; 495 + MODULE_DEVICE_TABLE(of, max77976_of_id); 496 + 497 + static struct i2c_driver max77976_driver = { 498 + .driver = { 499 + .name = MAX77976_DRIVER_NAME, 500 + .of_match_table = max77976_of_id, 501 + }, 502 + .probe_new = max77976_probe, 503 + .id_table = max77976_i2c_id, 504 + }; 505 + module_i2c_driver(max77976_driver); 506 + 507 + MODULE_AUTHOR("Luca Ceresoli <luca@lucaceresoli.net>"); 508 + MODULE_DESCRIPTION("Maxim MAX77976 charger driver"); 509 + MODULE_LICENSE("GPL v2");
+46 -30
drivers/power/supply/power_supply_core.c
··· 21 21 #include <linux/power_supply.h> 22 22 #include <linux/property.h> 23 23 #include <linux/thermal.h> 24 + #include <linux/fixp-arith.h> 24 25 #include "power_supply.h" 25 26 26 27 /* exported for the APM Power driver, APM emulation */ ··· 564 563 #endif /* CONFIG_OF */ 565 564 566 565 int power_supply_get_battery_info(struct power_supply *psy, 567 - struct power_supply_battery_info *info) 566 + struct power_supply_battery_info **info_out) 568 567 { 569 568 struct power_supply_resistance_temp_table *resist_table; 569 + struct power_supply_battery_info *info; 570 570 struct device_node *battery_np; 571 571 const char *value; 572 572 int err, len, index; 573 573 const __be32 *list; 574 + 575 + info = devm_kmalloc(&psy->dev, sizeof(*info), GFP_KERNEL); 576 + if (!info) 577 + return -ENOMEM; 574 578 575 579 info->technology = POWER_SUPPLY_TECHNOLOGY_UNKNOWN; 576 580 info->energy_full_design_uwh = -EINVAL; ··· 586 580 info->charge_term_current_ua = -EINVAL; 587 581 info->constant_charge_current_max_ua = -EINVAL; 588 582 info->constant_charge_voltage_max_uv = -EINVAL; 583 + info->tricklecharge_current_ua = -EINVAL; 584 + info->precharge_voltage_max_uv = -EINVAL; 585 + info->charge_restart_voltage_uv = -EINVAL; 586 + info->overvoltage_limit_uv = -EINVAL; 589 587 info->temp_ambient_alert_min = INT_MIN; 590 588 info->temp_ambient_alert_max = INT_MAX; 591 589 info->temp_alert_min = INT_MIN; ··· 737 727 738 728 list = of_get_property(battery_np, "resistance-temp-table", &len); 739 729 if (!list || !len) 740 - goto out_put_node; 730 + goto out_ret_pointer; 741 731 742 732 info->resist_table_size = len / (2 * sizeof(__be32)); 743 733 resist_table = info->resist_table = devm_kcalloc(&psy->dev, ··· 754 744 resist_table[index].temp = be32_to_cpu(*list++); 755 745 resist_table[index].resistance = be32_to_cpu(*list++); 756 746 } 747 + 748 + out_ret_pointer: 749 + /* Finally return the whole thing */ 750 + *info_out = info; 757 751 758 752 out_put_node: 759 753 of_node_put(battery_np); ··· 777 763 778 764 if (info->resist_table) 779 765 devm_kfree(&psy->dev, info->resist_table); 766 + 767 + devm_kfree(&psy->dev, info); 780 768 } 781 769 EXPORT_SYMBOL_GPL(power_supply_put_battery_info); 782 770 ··· 799 783 int power_supply_temp2resist_simple(struct power_supply_resistance_temp_table *table, 800 784 int table_len, int temp) 801 785 { 802 - int i, resist; 786 + int i, high, low; 803 787 804 - for (i = 0; i < table_len; i++) 788 + /* Break loop at table_len - 1 because that is the highest index */ 789 + for (i = 0; i < table_len - 1; i++) 805 790 if (temp > table[i].temp) 806 791 break; 807 792 808 - if (i > 0 && i < table_len) { 809 - int tmp; 793 + /* The library function will deal with high == low */ 794 + if ((i == 0) || (i == (table_len - 1))) 795 + high = i; 796 + else 797 + high = i - 1; 798 + low = i; 810 799 811 - tmp = (table[i - 1].resistance - table[i].resistance) * 812 - (temp - table[i].temp); 813 - tmp /= table[i - 1].temp - table[i].temp; 814 - resist = tmp + table[i].resistance; 815 - } else if (i == 0) { 816 - resist = table[0].resistance; 817 - } else { 818 - resist = table[table_len - 1].resistance; 819 - } 820 - 821 - return resist; 800 + return fixp_linear_interpolate(table[low].temp, 801 + table[low].resistance, 802 + table[high].temp, 803 + table[high].resistance, 804 + temp); 822 805 } 823 806 EXPORT_SYMBOL_GPL(power_supply_temp2resist_simple); 824 807 ··· 836 821 int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table, 837 822 int table_len, int ocv) 838 823 { 839 - int i, cap, tmp; 824 + int i, high, low; 840 825 841 - for (i = 0; i < table_len; i++) 826 + /* Break loop at table_len - 1 because that is the highest index */ 827 + for (i = 0; i < table_len - 1; i++) 842 828 if (ocv > table[i].ocv) 843 829 break; 844 830 845 - if (i > 0 && i < table_len) { 846 - tmp = (table[i - 1].capacity - table[i].capacity) * 847 - (ocv - table[i].ocv); 848 - tmp /= table[i - 1].ocv - table[i].ocv; 849 - cap = tmp + table[i].capacity; 850 - } else if (i == 0) { 851 - cap = table[0].capacity; 852 - } else { 853 - cap = table[table_len - 1].capacity; 854 - } 831 + /* The library function will deal with high == low */ 832 + if ((i == 0) || (i == (table_len - 1))) 833 + high = i - 1; 834 + else 835 + high = i; /* i.e. i == 0 */ 836 + low = i; 855 837 856 - return cap; 838 + return fixp_linear_interpolate(table[low].ocv, 839 + table[low].capacity, 840 + table[high].ocv, 841 + table[high].capacity, 842 + ocv); 857 843 } 858 844 EXPORT_SYMBOL_GPL(power_supply_ocv2cap_simple); 859 845
+1
drivers/power/supply/power_supply_sysfs.c
··· 106 106 [POWER_SUPPLY_HEALTH_WARM] = "Warm", 107 107 [POWER_SUPPLY_HEALTH_COOL] = "Cool", 108 108 [POWER_SUPPLY_HEALTH_HOT] = "Hot", 109 + [POWER_SUPPLY_HEALTH_NO_BATTERY] = "No battery", 109 110 }; 110 111 111 112 static const char * const POWER_SUPPLY_TECHNOLOGY_TEXT[] = {
+3 -2
drivers/power/supply/qcom_smbb.c
··· 863 863 } 864 864 865 865 chg->revision += 1; 866 - if (chg->revision != 2 && chg->revision != 3) { 867 - dev_err(&pdev->dev, "v1 hardware not supported\n"); 866 + if (chg->revision != 1 && chg->revision != 2 && chg->revision != 3) { 867 + dev_err(&pdev->dev, "v%d hardware not supported\n", chg->revision); 868 868 return -ENODEV; 869 869 } 870 870 dev_info(&pdev->dev, "Initializing SMBB rev %u", chg->revision); ··· 1012 1012 } 1013 1013 1014 1014 static const struct of_device_id smbb_charger_id_table[] = { 1015 + { .compatible = "qcom,pm8226-charger" }, 1015 1016 { .compatible = "qcom,pm8941-charger" }, 1016 1017 { } 1017 1018 };
+4 -4
drivers/power/supply/sc2731_charger.c
··· 368 368 369 369 static int sc2731_charger_hw_init(struct sc2731_charger_info *info) 370 370 { 371 - struct power_supply_battery_info bat_info = { }; 371 + struct power_supply_battery_info *bat_info; 372 372 u32 term_currrent, term_voltage, cur_val, vol_val; 373 373 int ret; 374 374 ··· 390 390 cur_val = 0x2; 391 391 vol_val = 0x1; 392 392 } else { 393 - term_currrent = bat_info.charge_term_current_ua / 1000; 393 + term_currrent = bat_info->charge_term_current_ua / 1000; 394 394 395 395 if (term_currrent <= 90) 396 396 cur_val = 0; ··· 399 399 else 400 400 cur_val = ((term_currrent - 90) / 25) + 1; 401 401 402 - term_voltage = bat_info.constant_charge_voltage_max_uv / 1000; 402 + term_voltage = bat_info->constant_charge_voltage_max_uv / 1000; 403 403 404 404 if (term_voltage > 4500) 405 405 term_voltage = 4500; ··· 409 409 else 410 410 vol_val = 0; 411 411 412 - power_supply_put_battery_info(info->psy_usb, &bat_info); 412 + power_supply_put_battery_info(info->psy_usb, bat_info); 413 413 } 414 414 415 415 /* Set charge termination current */
+11 -11
drivers/power/supply/sc27xx_fuel_gauge.c
··· 998 998 999 999 static int sc27xx_fgu_hw_init(struct sc27xx_fgu_data *data) 1000 1000 { 1001 - struct power_supply_battery_info info = { }; 1001 + struct power_supply_battery_info *info; 1002 1002 struct power_supply_battery_ocv_table *table; 1003 1003 int ret, delta_clbcnt, alarm_adc; 1004 1004 ··· 1008 1008 return ret; 1009 1009 } 1010 1010 1011 - data->total_cap = info.charge_full_design_uah / 1000; 1012 - data->max_volt = info.constant_charge_voltage_max_uv / 1000; 1013 - data->internal_resist = info.factory_internal_resistance_uohm / 1000; 1014 - data->min_volt = info.voltage_min_design_uv; 1011 + data->total_cap = info->charge_full_design_uah / 1000; 1012 + data->max_volt = info->constant_charge_voltage_max_uv / 1000; 1013 + data->internal_resist = info->factory_internal_resistance_uohm / 1000; 1014 + data->min_volt = info->voltage_min_design_uv; 1015 1015 1016 1016 /* 1017 1017 * For SC27XX fuel gauge device, we only use one ocv-capacity 1018 1018 * table in normal temperature 20 Celsius. 1019 1019 */ 1020 - table = power_supply_find_ocv2cap_table(&info, 20, &data->table_len); 1020 + table = power_supply_find_ocv2cap_table(info, 20, &data->table_len); 1021 1021 if (!table) 1022 1022 return -EINVAL; 1023 1023 ··· 1025 1025 data->table_len * sizeof(*table), 1026 1026 GFP_KERNEL); 1027 1027 if (!data->cap_table) { 1028 - power_supply_put_battery_info(data->battery, &info); 1028 + power_supply_put_battery_info(data->battery, info); 1029 1029 return -ENOMEM; 1030 1030 } 1031 1031 ··· 1035 1035 if (!data->alarm_cap) 1036 1036 data->alarm_cap += 1; 1037 1037 1038 - data->resist_table_len = info.resist_table_size; 1038 + data->resist_table_len = info->resist_table_size; 1039 1039 if (data->resist_table_len > 0) { 1040 - data->resist_table = devm_kmemdup(data->dev, info.resist_table, 1040 + data->resist_table = devm_kmemdup(data->dev, info->resist_table, 1041 1041 data->resist_table_len * 1042 1042 sizeof(struct power_supply_resistance_temp_table), 1043 1043 GFP_KERNEL); 1044 1044 if (!data->resist_table) { 1045 - power_supply_put_battery_info(data->battery, &info); 1045 + power_supply_put_battery_info(data->battery, info); 1046 1046 return -ENOMEM; 1047 1047 } 1048 1048 } 1049 1049 1050 - power_supply_put_battery_info(data->battery, &info); 1050 + power_supply_put_battery_info(data->battery, info); 1051 1051 1052 1052 ret = sc27xx_fgu_calibration(data); 1053 1053 if (ret)
+17 -17
drivers/power/supply/smb347-charger.c
··· 1281 1281 1282 1282 static int smb347_get_battery_info(struct smb347_charger *smb) 1283 1283 { 1284 - struct power_supply_battery_info info = {}; 1284 + struct power_supply_battery_info *info; 1285 1285 struct power_supply *supply; 1286 1286 int err; 1287 1287 ··· 1296 1296 if (err) 1297 1297 return err; 1298 1298 1299 - if (info.constant_charge_current_max_ua != -EINVAL) 1300 - smb->max_charge_current = info.constant_charge_current_max_ua; 1299 + if (info->constant_charge_current_max_ua != -EINVAL) 1300 + smb->max_charge_current = info->constant_charge_current_max_ua; 1301 1301 1302 - if (info.constant_charge_voltage_max_uv != -EINVAL) 1303 - smb->max_charge_voltage = info.constant_charge_voltage_max_uv; 1302 + if (info->constant_charge_voltage_max_uv != -EINVAL) 1303 + smb->max_charge_voltage = info->constant_charge_voltage_max_uv; 1304 1304 1305 - if (info.precharge_current_ua != -EINVAL) 1306 - smb->pre_charge_current = info.precharge_current_ua; 1305 + if (info->precharge_current_ua != -EINVAL) 1306 + smb->pre_charge_current = info->precharge_current_ua; 1307 1307 1308 - if (info.charge_term_current_ua != -EINVAL) 1309 - smb->termination_current = info.charge_term_current_ua; 1308 + if (info->charge_term_current_ua != -EINVAL) 1309 + smb->termination_current = info->charge_term_current_ua; 1310 1310 1311 - if (info.temp_alert_min != INT_MIN) 1312 - smb->soft_cold_temp_limit = info.temp_alert_min; 1311 + if (info->temp_alert_min != INT_MIN) 1312 + smb->soft_cold_temp_limit = info->temp_alert_min; 1313 1313 1314 - if (info.temp_alert_max != INT_MAX) 1315 - smb->soft_hot_temp_limit = info.temp_alert_max; 1314 + if (info->temp_alert_max != INT_MAX) 1315 + smb->soft_hot_temp_limit = info->temp_alert_max; 1316 1316 1317 - if (info.temp_min != INT_MIN) 1318 - smb->hard_cold_temp_limit = info.temp_min; 1317 + if (info->temp_min != INT_MIN) 1318 + smb->hard_cold_temp_limit = info->temp_min; 1319 1319 1320 - if (info.temp_max != INT_MAX) 1321 - smb->hard_hot_temp_limit = info.temp_max; 1320 + if (info->temp_max != INT_MAX) 1321 + smb->hard_hot_temp_limit = info->temp_max; 1322 1322 1323 1323 /* Suspend when battery temperature is outside hard limits */ 1324 1324 if (smb->hard_cold_temp_limit != SMB3XX_TEMP_USE_DEFAULT ||
+194 -24
include/linux/power_supply.h
··· 66 66 POWER_SUPPLY_HEALTH_WARM, 67 67 POWER_SUPPLY_HEALTH_COOL, 68 68 POWER_SUPPLY_HEALTH_HOT, 69 + POWER_SUPPLY_HEALTH_NO_BATTERY, 69 70 }; 70 71 71 72 enum { ··· 343 342 344 343 #define POWER_SUPPLY_OCV_TEMP_MAX 20 345 344 346 - /* 345 + /** 346 + * struct power_supply_battery_info - information about batteries 347 + * @technology: from the POWER_SUPPLY_TECHNOLOGY_* enum 348 + * @energy_full_design_uwh: energy content when fully charged in microwatt 349 + * hours 350 + * @charge_full_design_uah: charge content when fully charged in microampere 351 + * hours 352 + * @voltage_min_design_uv: minimum voltage across the poles when the battery 353 + * is at minimum voltage level in microvolts. If the voltage drops below this 354 + * level the battery will need precharging when using CC/CV charging. 355 + * @voltage_max_design_uv: voltage across the poles when the battery is fully 356 + * charged in microvolts. This is the "nominal voltage" i.e. the voltage 357 + * printed on the label of the battery. 358 + * @tricklecharge_current_ua: the tricklecharge current used when trickle 359 + * charging the battery in microamperes. This is the charging phase when the 360 + * battery is completely empty and we need to carefully trickle in some 361 + * charge until we reach the precharging voltage. 362 + * @precharge_current_ua: current to use in the precharge phase in microamperes, 363 + * the precharge rate is limited by limiting the current to this value. 364 + * @precharge_voltage_max_uv: the maximum voltage allowed when precharging in 365 + * microvolts. When we pass this voltage we will nominally switch over to the 366 + * CC (constant current) charging phase defined by constant_charge_current_ua 367 + * and constant_charge_voltage_max_uv. 368 + * @charge_term_current_ua: when the current in the CV (constant voltage) 369 + * charging phase drops below this value in microamperes the charging will 370 + * terminate completely and not restart until the voltage over the battery 371 + * poles reach charge_restart_voltage_uv unless we use maintenance charging. 372 + * @charge_restart_voltage_uv: when the battery has been fully charged by 373 + * CC/CV charging and charging has been disabled, and the voltage subsequently 374 + * drops below this value in microvolts, the charging will be restarted 375 + * (typically using CV charging). 376 + * @overvoltage_limit_uv: If the voltage exceeds the nominal voltage 377 + * voltage_max_design_uv and we reach this voltage level, all charging must 378 + * stop and emergency procedures take place, such as shutting down the system 379 + * in some cases. 380 + * @constant_charge_current_max_ua: current in microamperes to use in the CC 381 + * (constant current) charging phase. The charging rate is limited 382 + * by this current. This is the main charging phase and as the current is 383 + * constant into the battery the voltage slowly ascends to 384 + * constant_charge_voltage_max_uv. 385 + * @constant_charge_voltage_max_uv: voltage in microvolts signifying the end of 386 + * the CC (constant current) charging phase and the beginning of the CV 387 + * (constant voltage) charging phase. 388 + * @factory_internal_resistance_uohm: the internal resistance of the battery 389 + * at fabrication time, expressed in microohms. This resistance will vary 390 + * depending on the lifetime and charge of the battery, so this is just a 391 + * nominal ballpark figure. 392 + * @ocv_temp: array indicating the open circuit voltage (OCV) capacity 393 + * temperature indices. This is an array of temperatures in degrees Celsius 394 + * indicating which capacity table to use for a certain temperature, since 395 + * the capacity for reasons of chemistry will be different at different 396 + * temperatures. Determining capacity is a multivariate problem and the 397 + * temperature is the first variable we determine. 398 + * @temp_ambient_alert_min: the battery will go outside of operating conditions 399 + * when the ambient temperature goes below this temperature in degrees 400 + * Celsius. 401 + * @temp_ambient_alert_max: the battery will go outside of operating conditions 402 + * when the ambient temperature goes above this temperature in degrees 403 + * Celsius. 404 + * @temp_alert_min: the battery should issue an alert if the internal 405 + * temperature goes below this temperature in degrees Celsius. 406 + * @temp_alert_max: the battery should issue an alert if the internal 407 + * temperature goes above this temperature in degrees Celsius. 408 + * @temp_min: the battery will go outside of operating conditions when 409 + * the internal temperature goes below this temperature in degrees Celsius. 410 + * Normally this means the system should shut down. 411 + * @temp_max: the battery will go outside of operating conditions when 412 + * the internal temperature goes above this temperature in degrees Celsius. 413 + * Normally this means the system should shut down. 414 + * @ocv_table: for each entry in ocv_temp there is a corresponding entry in 415 + * ocv_table and a size for each entry in ocv_table_size. These arrays 416 + * determine the capacity in percent in relation to the voltage in microvolts 417 + * at the indexed temperature. 418 + * @ocv_table_size: for each entry in ocv_temp this array is giving the size of 419 + * each entry in the array of capacity arrays in ocv_table. 420 + * @resist_table: this is a table that correlates a battery temperature to the 421 + * expected internal resistance at this temperature. The resistance is given 422 + * as a percentage of factory_internal_resistance_uohm. Knowing the 423 + * resistance of the battery is usually necessary for calculating the open 424 + * circuit voltage (OCV) that is then used with the ocv_table to calculate 425 + * the capacity of the battery. The resist_table must be ordered descending 426 + * by temperature: highest temperature with lowest resistance first, lowest 427 + * temperature with highest resistance last. 428 + * @resist_table_size: the number of items in the resist_table. 429 + * 347 430 * This is the recommended struct to manage static battery parameters, 348 431 * populated by power_supply_get_battery_info(). Most platform drivers should 349 432 * use these for consistency. 433 + * 350 434 * Its field names must correspond to elements in enum power_supply_property. 351 435 * The default field value is -EINVAL. 352 - * Power supply class itself doesn't use this. 436 + * 437 + * The charging parameters here assume a CC/CV charging scheme. This method 438 + * is most common with Lithium Ion batteries (other methods are possible) and 439 + * looks as follows: 440 + * 441 + * ^ Battery voltage 442 + * | --- overvoltage_limit_uv 443 + * | 444 + * | ................................................... 445 + * | .. constant_charge_voltage_max_uv 446 + * | .. 447 + * | . 448 + * | . 449 + * | . 450 + * | . 451 + * | . 452 + * | .. precharge_voltage_max_uv 453 + * | .. 454 + * |. (trickle charging) 455 + * +------------------------------------------------------------------> time 456 + * 457 + * ^ Current into the battery 458 + * | 459 + * | ............. constant_charge_current_max_ua 460 + * | . . 461 + * | . . 462 + * | . . 463 + * | . . 464 + * | . .. 465 + * | . .... 466 + * | . ..... 467 + * | ... precharge_current_ua ....... charge_term_current_ua 468 + * | . . 469 + * | . . 470 + * |.... tricklecharge_current_ua . 471 + * | . 472 + * +-----------------------------------------------------------------> time 473 + * 474 + * These diagrams are synchronized on time and the voltage and current 475 + * follow each other. 476 + * 477 + * With CC/CV charging commence over time like this for an empty battery: 478 + * 479 + * 1. When the battery is completely empty it may need to be charged with 480 + * an especially small current so that electrons just "trickle in", 481 + * this is the tricklecharge_current_ua. 482 + * 483 + * 2. Next a small initial pre-charge current (precharge_current_ua) 484 + * is applied if the voltage is below precharge_voltage_max_uv until we 485 + * reach precharge_voltage_max_uv. CAUTION: in some texts this is referred 486 + * to as "trickle charging" but the use in the Linux kernel is different 487 + * see below! 488 + * 489 + * 3. Then the main charging current is applied, which is called the constant 490 + * current (CC) phase. A current regulator is set up to allow 491 + * constant_charge_current_max_ua of current to flow into the battery. 492 + * The chemical reaction in the battery will make the voltage go up as 493 + * charge goes into the battery. This current is applied until we reach 494 + * the constant_charge_voltage_max_uv voltage. 495 + * 496 + * 4. At this voltage we switch over to the constant voltage (CV) phase. This 497 + * means we allow current to go into the battery, but we keep the voltage 498 + * fixed. This current will continue to charge the battery while keeping 499 + * the voltage the same. A chemical reaction in the battery goes on 500 + * storing energy without affecting the voltage. Over time the current 501 + * will slowly drop and when we reach charge_term_current_ua we will 502 + * end the constant voltage phase. 503 + * 504 + * After this the battery is fully charged, and if we do not support maintenance 505 + * charging, the charging will not restart until power dissipation makes the 506 + * voltage fall so that we reach charge_restart_voltage_uv and at this point 507 + * we restart charging at the appropriate phase, usually this will be inside 508 + * the CV phase. 509 + * 510 + * If we support maintenance charging the voltage is however kept high after 511 + * the CV phase with a very low current. This is meant to let the same charge 512 + * go in for usage while the charger is still connected, mainly for 513 + * dissipation for the power consuming entity while connected to the 514 + * charger. 515 + * 516 + * All charging MUST terminate if the overvoltage_limit_uv is ever reached. 517 + * Overcharging Lithium Ion cells can be DANGEROUS and lead to fire or 518 + * explosions. 519 + * 520 + * The power supply class itself doesn't use this struct as of now. 353 521 */ 354 522 355 523 struct power_supply_battery_info { 356 - unsigned int technology; /* from the enum above */ 357 - int energy_full_design_uwh; /* microWatt-hours */ 358 - int charge_full_design_uah; /* microAmp-hours */ 359 - int voltage_min_design_uv; /* microVolts */ 360 - int voltage_max_design_uv; /* microVolts */ 361 - int tricklecharge_current_ua; /* microAmps */ 362 - int precharge_current_ua; /* microAmps */ 363 - int precharge_voltage_max_uv; /* microVolts */ 364 - int charge_term_current_ua; /* microAmps */ 365 - int charge_restart_voltage_uv; /* microVolts */ 366 - int overvoltage_limit_uv; /* microVolts */ 367 - int constant_charge_current_max_ua; /* microAmps */ 368 - int constant_charge_voltage_max_uv; /* microVolts */ 369 - int factory_internal_resistance_uohm; /* microOhms */ 370 - int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX];/* celsius */ 371 - int temp_ambient_alert_min; /* celsius */ 372 - int temp_ambient_alert_max; /* celsius */ 373 - int temp_alert_min; /* celsius */ 374 - int temp_alert_max; /* celsius */ 375 - int temp_min; /* celsius */ 376 - int temp_max; /* celsius */ 524 + unsigned int technology; 525 + int energy_full_design_uwh; 526 + int charge_full_design_uah; 527 + int voltage_min_design_uv; 528 + int voltage_max_design_uv; 529 + int tricklecharge_current_ua; 530 + int precharge_current_ua; 531 + int precharge_voltage_max_uv; 532 + int charge_term_current_ua; 533 + int charge_restart_voltage_uv; 534 + int overvoltage_limit_uv; 535 + int constant_charge_current_max_ua; 536 + int constant_charge_voltage_max_uv; 537 + int factory_internal_resistance_uohm; 538 + int ocv_temp[POWER_SUPPLY_OCV_TEMP_MAX]; 539 + int temp_ambient_alert_min; 540 + int temp_ambient_alert_max; 541 + int temp_alert_min; 542 + int temp_alert_max; 543 + int temp_min; 544 + int temp_max; 377 545 struct power_supply_battery_ocv_table *ocv_table[POWER_SUPPLY_OCV_TEMP_MAX]; 378 546 int ocv_table_size[POWER_SUPPLY_OCV_TEMP_MAX]; 379 547 struct power_supply_resistance_temp_table *resist_table; ··· 575 405 #endif /* CONFIG_OF */ 576 406 577 407 extern int power_supply_get_battery_info(struct power_supply *psy, 578 - struct power_supply_battery_info *info); 408 + struct power_supply_battery_info **info_out); 579 409 extern void power_supply_put_battery_info(struct power_supply *psy, 580 410 struct power_supply_battery_info *info); 581 411 extern int power_supply_ocv2cap_simple(struct power_supply_battery_ocv_table *table,