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

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

Pull power supply and reset updates from Sebastian Reichel:
"Nothing too fancy in the power-supply subsystem this time. There are
less patches than usual, since I did not have enough time to review
them in time. The good news is, that all patches have been in
linux-next for more than two weeks and there are no complicated
cross-subsystem patchsets this time!

Summary:

- at91-reset: add sam9x60 support

- sc27xx: improve capacity logic

- goldfish_battery: enhance driver by adding many new properties

- isp1704: drop platform data and migrate to gpiod

- misc small fixes and improvements"

* tag 'for-v5.1' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: (25 commits)
power: reset: at91-reset: add support for sam9x60 SoC
dt-bindings: arm: atmel: add new sam9x60 reset controller binding
dt-bindings: arm: atmel: add missing samx7 to reset controller
max17042_battery: fix potential use-after-free on device remove
power: supply: core: Add a field to support battery max voltage
dt-bindings: power: supply: Add voltage-max-design-microvolt property
bq27x00: use cached flags
power: supply: ds2782: fix possible use-after-free on remove
power: supply: bq25890: show max charge current/voltage as configured
power: supply: sc27xx: Fix capacity saving function
power: supply: sc27xx: Fix the incorrect formula when converting capacity to coulomb counter
power: supply: sc27xx: Add one property to read charge voltage
dt-bindings: power: sc27xx: Add one IIO channel to read charge voltage
drivers: power: supply: goldfish_battery: Add support for reading more properties
power: supply: charger-manager: Fix trivial language typos
cpcap-charger: generate events for userspace
power: supply: remove some duplicated includes
power: twl4030: fix a missing check of return value
drivers: power: supply: goldfish_battery: Use tabs for alignment
drivers: power: supply: goldfish_battery: Fix alignment
...

+220 -162
+2 -1
Documentation/devicetree/bindings/arm/atmel-sysregs.txt
··· 21 21 22 22 RSTC Reset Controller required properties: 23 23 - compatible: Should be "atmel,<chip>-rstc". 24 - <chip> can be "at91sam9260" or "at91sam9g45" or "sama5d3" 24 + <chip> can be "at91sam9260", "at91sam9g45", "sama5d3" or "samx7" 25 + it also can be "microchip,sam9x60-rstc" 25 26 - reg: Should contain registers location and length 26 27 - clocks: phandle to input clock. 27 28
+2
Documentation/devicetree/bindings/power/supply/battery.txt
··· 16 16 17 17 Optional Properties: 18 18 - voltage-min-design-microvolt: drained battery voltage 19 + - voltage-max-design-microvolt: fully charged battery voltage 19 20 - energy-full-design-microwatt-hours: battery design energy 20 21 - charge-full-design-microamp-hours: battery design capacity 21 22 - precharge-current-microamp: current for pre-charge phase ··· 49 48 bat: battery { 50 49 compatible = "simple-battery"; 51 50 voltage-min-design-microvolt = <3200000>; 51 + voltage-max-design-microvolt = <4200000>; 52 52 energy-full-design-microwatt-hours = <5290000>; 53 53 charge-full-design-microamp-hours = <1430000>; 54 54 precharge-current-microamp = <256000>;
+4 -4
Documentation/devicetree/bindings/power/supply/sc27xx-fg.txt
··· 9 9 "sprd,sc2731-fgu". 10 10 - reg: The address offset of fuel gauge unit. 11 11 - battery-detect-gpios: GPIO for battery detection. 12 - - io-channels: Specify the IIO ADC channel to get temperature. 13 - - io-channel-names: Should be "bat-temp". 12 + - io-channels: Specify the IIO ADC channels to get temperature and charge voltage. 13 + - io-channel-names: Should be "bat-temp" or "charge-vol". 14 14 - nvmem-cells: A phandle to the calibration cells provided by eFuse device. 15 15 - nvmem-cell-names: Should be "fgu_calib". 16 16 - monitored-battery: Phandle of battery characteristics devicetree node. ··· 47 47 compatible = "sprd,sc2731-fgu"; 48 48 reg = <0xa00>; 49 49 battery-detect-gpios = <&pmic_eic 9 GPIO_ACTIVE_HIGH>; 50 - io-channels = <&pmic_adc 5>; 51 - io-channel-names = "bat-temp"; 50 + io-channels = <&pmic_adc 5>, <&pmic_adc 14>; 51 + io-channel-names = "bat-temp", "charge-vol"; 52 52 nvmem-cells = <&fgu_calib>; 53 53 nvmem-cell-names = "fgu_calib"; 54 54 monitored-battery = <&bat>;
+13
drivers/power/reset/at91-reset.c
··· 44 44 RESET_TYPE_WATCHDOG = 2, 45 45 RESET_TYPE_SOFTWARE = 3, 46 46 RESET_TYPE_USER = 4, 47 + RESET_TYPE_CPU_FAIL = 6, 48 + RESET_TYPE_XTAL_FAIL = 7, 49 + RESET_TYPE_ULP2 = 8, 47 50 }; 48 51 49 52 static void __iomem *at91_ramc_base[2], *at91_rstc_base; ··· 167 164 case RESET_TYPE_USER: 168 165 reason = "user reset"; 169 166 break; 167 + case RESET_TYPE_CPU_FAIL: 168 + reason = "CPU clock failure detection"; 169 + break; 170 + case RESET_TYPE_XTAL_FAIL: 171 + reason = "32.768 kHz crystal failure detection"; 172 + break; 173 + case RESET_TYPE_ULP2: 174 + reason = "ULP2 reset"; 175 + break; 170 176 default: 171 177 reason = "unknown reset"; 172 178 break; ··· 195 183 { .compatible = "atmel,at91sam9g45-rstc", .data = at91sam9g45_restart }, 196 184 { .compatible = "atmel,sama5d3-rstc", .data = sama5d3_restart }, 197 185 { .compatible = "atmel,samx7-rstc", .data = samx7_restart }, 186 + { .compatible = "microchip,sam9x60-rstc", .data = samx7_restart }, 198 187 { /* sentinel */ } 199 188 }; 200 189 MODULE_DEVICE_TABLE(of, at91_reset_of_match);
+2 -12
drivers/power/supply/axp288_fuel_gauge.c
··· 307 307 return 0; 308 308 } 309 309 310 - static int debug_open(struct inode *inode, struct file *file) 311 - { 312 - return single_open(file, fuel_gauge_debug_show, inode->i_private); 313 - } 314 - 315 - static const struct file_operations fg_debug_fops = { 316 - .open = debug_open, 317 - .read = seq_read, 318 - .llseek = seq_lseek, 319 - .release = single_release, 320 - }; 310 + DEFINE_SHOW_ATTRIBUTE(fuel_gauge_debug); 321 311 322 312 static void fuel_gauge_create_debugfs(struct axp288_fg_info *info) 323 313 { 324 314 info->debug_file = debugfs_create_file("fuelgauge", 0666, NULL, 325 - info, &fg_debug_fops); 315 + info, &fuel_gauge_debug_fops); 326 316 } 327 317 328 318 static void fuel_gauge_remove_debugfs(struct axp288_fg_info *info)
+2 -2
drivers/power/supply/bq25890_charger.c
··· 436 436 break; 437 437 438 438 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_CURRENT_MAX: 439 - val->intval = bq25890_tables[TBL_ICHG].rt.max; 439 + val->intval = bq25890_find_val(bq->init_data.ichg, TBL_ICHG); 440 440 break; 441 441 442 442 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: ··· 454 454 break; 455 455 456 456 case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE_MAX: 457 - val->intval = bq25890_tables[TBL_VREG].rt.max; 457 + val->intval = bq25890_find_val(bq->init_data.vreg, TBL_VREG); 458 458 break; 459 459 460 460 case POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT:
+4 -16
drivers/power/supply/bq27xxx_battery.c
··· 1555 1555 return flags & (BQ27XXX_FLAG_SOC1 | BQ27XXX_FLAG_SOCF); 1556 1556 } 1557 1557 1558 - /* 1559 - * Read flag register. 1560 - * Return < 0 if something fails. 1561 - */ 1562 1558 static int bq27xxx_battery_read_health(struct bq27xxx_device_info *di) 1563 1559 { 1564 - int flags; 1565 - bool has_singe_flag = di->opts & BQ27XXX_O_ZERO; 1566 - 1567 - flags = bq27xxx_read(di, BQ27XXX_REG_FLAGS, has_singe_flag); 1568 - if (flags < 0) { 1569 - dev_err(di->dev, "error reading flag register:%d\n", flags); 1570 - return flags; 1571 - } 1572 - 1573 1560 /* Unlikely but important to return first */ 1574 - if (unlikely(bq27xxx_battery_overtemp(di, flags))) 1561 + if (unlikely(bq27xxx_battery_overtemp(di, di->cache.flags))) 1575 1562 return POWER_SUPPLY_HEALTH_OVERHEAT; 1576 - if (unlikely(bq27xxx_battery_undertemp(di, flags))) 1563 + if (unlikely(bq27xxx_battery_undertemp(di, di->cache.flags))) 1577 1564 return POWER_SUPPLY_HEALTH_COLD; 1578 - if (unlikely(bq27xxx_battery_dead(di, flags))) 1565 + if (unlikely(bq27xxx_battery_dead(di, di->cache.flags))) 1579 1566 return POWER_SUPPLY_HEALTH_DEAD; 1580 1567 1581 1568 return POWER_SUPPLY_HEALTH_GOOD; ··· 1599 1612 cache.capacity = bq27xxx_battery_read_soc(di); 1600 1613 if (di->regs[BQ27XXX_REG_AE] != INVALID_REG_ADDR) 1601 1614 cache.energy = bq27xxx_battery_read_energy(di); 1615 + di->cache.flags = cache.flags; 1602 1616 cache.health = bq27xxx_battery_read_health(di); 1603 1617 } 1604 1618 if (di->regs[BQ27XXX_REG_CYCT] != INVALID_REG_ADDR)
+9 -9
drivers/power/supply/charger-manager.c
··· 4 4 * 5 5 * This driver enables to monitor battery health and control charger 6 6 * during suspend-to-mem. 7 - * Charger manager depends on other devices. register this later than 7 + * Charger manager depends on other devices. Register this later than 8 8 * the depending devices. 9 9 * 10 10 * This program is free software; you can redistribute it and/or modify ··· 29 29 #include <linux/thermal.h> 30 30 31 31 /* 32 - * Default termperature threshold for charging. 32 + * Default temperature threshold for charging. 33 33 * Every temperature units are in tenth of centigrade. 34 34 */ 35 35 #define CM_DEFAULT_RECHARGE_TEMP_DIFF 50 ··· 356 356 * Note that Charger Manager keeps the charger enabled regardless whether 357 357 * the charger is charging or not (because battery is full or no external 358 358 * power source exists) except when CM needs to disable chargers forcibly 359 - * bacause of emergency causes; when the battery is overheated or too cold. 359 + * because of emergency causes; when the battery is overheated or too cold. 360 360 */ 361 361 static int try_charger_enable(struct charger_manager *cm, bool enable) 362 362 { ··· 643 643 if (ret) { 644 644 /* FIXME: 645 645 * No information of battery temperature might 646 - * occur hazadous result. We have to handle it 646 + * occur hazardous result. We have to handle it 647 647 * depending on battery type. 648 648 */ 649 649 dev_err(cm->dev, "Failed to get battery temperature\n"); ··· 693 693 uevent_notify(cm, default_event_names[temp_alrt]); 694 694 695 695 /* 696 - * Check whole charging duration and discharing duration 696 + * Check whole charging duration and discharging duration 697 697 * after full-batt. 698 698 */ 699 699 } else if (!cm->emergency_stop && check_charging_duration(cm)) { ··· 866 866 } 867 867 868 868 /** 869 - * misc_event_handler - Handler for other evnets 869 + * misc_event_handler - Handler for other events 870 870 * @cm: the Charger Manager representing the battery. 871 871 * @type: the Charger Manager representing the battery. 872 872 */ ··· 1218 1218 } 1219 1219 1220 1220 /** 1221 - * charger_manager_register_extcon - Register extcon device to recevie state 1221 + * charger_manager_register_extcon - Register extcon device to receive state 1222 1222 * of charger cable. 1223 1223 * @cm: the Charger Manager representing the battery. 1224 1224 * ··· 1538 1538 of_property_read_u32(np, "cm-discharging-max", 1539 1539 &desc->discharging_max_duration_ms); 1540 1540 1541 - /* battery charger regualtors */ 1541 + /* battery charger regulators */ 1542 1542 desc->num_charger_regulators = of_get_child_count(np); 1543 1543 if (desc->num_charger_regulators) { 1544 1544 struct charger_regulator *chg_regs; ··· 1801 1801 1802 1802 /* 1803 1803 * Charger-manager have to check the charging state right after 1804 - * tialization of charger-manager and then update current charging 1804 + * initialization of charger-manager and then update current charging 1805 1805 * state. 1806 1806 */ 1807 1807 cm_monitor();
+1
drivers/power/supply/cpcap-charger.c
··· 458 458 goto out_err; 459 459 } 460 460 461 + power_supply_changed(ddata->usb); 461 462 return; 462 463 463 464 out_err:
+4 -4
drivers/power/supply/ds2782_battery.c
··· 319 319 static int ds278x_battery_remove(struct i2c_client *client) 320 320 { 321 321 struct ds278x_info *info = i2c_get_clientdata(client); 322 + int id = info->id; 322 323 323 324 power_supply_unregister(info->battery); 325 + cancel_delayed_work_sync(&info->bat_work); 324 326 kfree(info->battery_desc.name); 327 + kfree(info); 325 328 326 329 mutex_lock(&battery_lock); 327 - idr_remove(&battery_id, info->id); 330 + idr_remove(&battery_id, id); 328 331 mutex_unlock(&battery_lock); 329 332 330 - cancel_delayed_work(&info->bat_work); 331 - 332 - kfree(info); 333 333 return 0; 334 334 } 335 335
+59 -27
drivers/power/supply/goldfish_battery.c
··· 1 + // SPDX-License-Identifier: GPL 1 2 /* 2 3 * Power supply driver for the goldfish emulator 3 4 * ··· 6 5 * Copyright (C) 2012 Intel, Inc. 7 6 * Copyright (C) 2013 Intel, Inc. 8 7 * Author: Mike Lockwood <lockwood@android.com> 9 - * 10 - * This software is licensed under the terms of the GNU General Public 11 - * License version 2, as published by the Free Software Foundation, and 12 - * may be copied, distributed, and modified under those terms. 13 - * 14 - * This program is distributed in the hope that it will be useful, 15 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 16 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 17 - * GNU General Public License for more details. 18 8 */ 19 9 20 10 #include <linux/module.h> ··· 32 40 #define GOLDFISH_BATTERY_WRITE(data, addr, x) \ 33 41 (writel(x, data->reg_base + addr)) 34 42 35 - /* 36 - * Temporary variable used between goldfish_battery_probe() and 37 - * goldfish_battery_open(). 38 - */ 39 - static struct goldfish_battery_data *battery_data; 40 - 41 43 enum { 42 44 /* status register */ 43 - BATTERY_INT_STATUS = 0x00, 45 + BATTERY_INT_STATUS = 0x00, 44 46 /* set this to enable IRQ */ 45 - BATTERY_INT_ENABLE = 0x04, 47 + BATTERY_INT_ENABLE = 0x04, 46 48 47 - BATTERY_AC_ONLINE = 0x08, 48 - BATTERY_STATUS = 0x0C, 49 - BATTERY_HEALTH = 0x10, 50 - BATTERY_PRESENT = 0x14, 51 - BATTERY_CAPACITY = 0x18, 49 + BATTERY_AC_ONLINE = 0x08, 50 + BATTERY_STATUS = 0x0C, 51 + BATTERY_HEALTH = 0x10, 52 + BATTERY_PRESENT = 0x14, 53 + BATTERY_CAPACITY = 0x18, 54 + BATTERY_VOLTAGE = 0x1C, 55 + BATTERY_TEMP = 0x20, 56 + BATTERY_CHARGE_COUNTER = 0x24, 57 + BATTERY_VOLTAGE_MAX = 0x28, 58 + BATTERY_CURRENT_MAX = 0x2C, 59 + BATTERY_CURRENT_NOW = 0x30, 60 + BATTERY_CURRENT_AVG = 0x34, 61 + BATTERY_CHARGE_FULL_UAH = 0x38, 62 + BATTERY_CYCLE_COUNT = 0x40, 52 63 53 64 BATTERY_STATUS_CHANGED = 1U << 0, 54 65 AC_STATUS_CHANGED = 1U << 1, 55 - BATTERY_INT_MASK = BATTERY_STATUS_CHANGED | AC_STATUS_CHANGED, 66 + BATTERY_INT_MASK = BATTERY_STATUS_CHANGED | AC_STATUS_CHANGED, 56 67 }; 57 68 58 69 ··· 69 74 switch (psp) { 70 75 case POWER_SUPPLY_PROP_ONLINE: 71 76 val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_AC_ONLINE); 77 + break; 78 + case POWER_SUPPLY_PROP_VOLTAGE_MAX: 79 + val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_VOLTAGE_MAX); 80 + break; 81 + case POWER_SUPPLY_PROP_CURRENT_MAX: 82 + val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_CURRENT_MAX); 72 83 break; 73 84 default: 74 85 ret = -EINVAL; ··· 106 105 case POWER_SUPPLY_PROP_CAPACITY: 107 106 val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_CAPACITY); 108 107 break; 108 + case POWER_SUPPLY_PROP_VOLTAGE_NOW: 109 + val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_VOLTAGE); 110 + break; 111 + case POWER_SUPPLY_PROP_TEMP: 112 + val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_TEMP); 113 + break; 114 + case POWER_SUPPLY_PROP_CHARGE_COUNTER: 115 + val->intval = GOLDFISH_BATTERY_READ(data, 116 + BATTERY_CHARGE_COUNTER); 117 + break; 118 + case POWER_SUPPLY_PROP_CURRENT_NOW: 119 + val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_CURRENT_NOW); 120 + break; 121 + case POWER_SUPPLY_PROP_CURRENT_AVG: 122 + val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_CURRENT_AVG); 123 + break; 124 + case POWER_SUPPLY_PROP_CHARGE_FULL: 125 + val->intval = GOLDFISH_BATTERY_READ(data, 126 + BATTERY_CHARGE_FULL_UAH); 127 + break; 128 + case POWER_SUPPLY_PROP_CYCLE_COUNT: 129 + val->intval = GOLDFISH_BATTERY_READ(data, BATTERY_CYCLE_COUNT); 130 + break; 109 131 default: 110 132 ret = -EINVAL; 111 133 break; ··· 143 119 POWER_SUPPLY_PROP_PRESENT, 144 120 POWER_SUPPLY_PROP_TECHNOLOGY, 145 121 POWER_SUPPLY_PROP_CAPACITY, 122 + POWER_SUPPLY_PROP_VOLTAGE_NOW, 123 + POWER_SUPPLY_PROP_TEMP, 124 + POWER_SUPPLY_PROP_CHARGE_COUNTER, 125 + POWER_SUPPLY_PROP_CURRENT_NOW, 126 + POWER_SUPPLY_PROP_CURRENT_AVG, 127 + POWER_SUPPLY_PROP_CHARGE_FULL, 128 + POWER_SUPPLY_PROP_CYCLE_COUNT, 146 129 }; 147 130 148 131 static enum power_supply_property goldfish_ac_props[] = { 149 132 POWER_SUPPLY_PROP_ONLINE, 133 + POWER_SUPPLY_PROP_VOLTAGE_MAX, 134 + POWER_SUPPLY_PROP_CURRENT_MAX, 150 135 }; 151 136 152 137 static irqreturn_t goldfish_battery_interrupt(int irq, void *dev_id) ··· 226 193 return -ENODEV; 227 194 } 228 195 229 - ret = devm_request_irq(&pdev->dev, data->irq, goldfish_battery_interrupt, 230 - IRQF_SHARED, pdev->name, data); 196 + ret = devm_request_irq(&pdev->dev, data->irq, 197 + goldfish_battery_interrupt, 198 + IRQF_SHARED, pdev->name, data); 231 199 if (ret) 232 200 return ret; 233 201 ··· 246 212 } 247 213 248 214 platform_set_drvdata(pdev, data); 249 - battery_data = data; 250 215 251 216 GOLDFISH_BATTERY_WRITE(data, BATTERY_INT_ENABLE, BATTERY_INT_MASK); 252 217 return 0; ··· 257 224 258 225 power_supply_unregister(data->battery); 259 226 power_supply_unregister(data->ac); 260 - battery_data = NULL; 261 227 return 0; 262 228 } 263 229
+12 -48
drivers/power/supply/isp1704_charger.c
··· 30 30 #include <linux/power_supply.h> 31 31 #include <linux/delay.h> 32 32 #include <linux/of.h> 33 - #include <linux/of_gpio.h> 34 33 34 + #include <linux/gpio/consumer.h> 35 35 #include <linux/usb/otg.h> 36 36 #include <linux/usb/ulpi.h> 37 37 #include <linux/usb/ch9.h> 38 38 #include <linux/usb/gadget.h> 39 - #include <linux/power/isp1704_charger.h> 40 39 41 40 /* Vendor specific Power Control register */ 42 41 #define ISP1704_PWR_CTRL 0x3d ··· 59 60 struct device *dev; 60 61 struct power_supply *psy; 61 62 struct power_supply_desc psy_desc; 63 + struct gpio_desc *enable_gpio; 62 64 struct usb_phy *phy; 63 65 struct notifier_block nb; 64 66 struct work_struct work; ··· 81 81 return usb_phy_io_write(isp->phy, val, reg); 82 82 } 83 83 84 - /* 85 - * Disable/enable the power from the isp1704 if a function for it 86 - * has been provided with platform data. 87 - */ 88 84 static void isp1704_charger_set_power(struct isp1704_charger *isp, bool on) 89 85 { 90 - struct isp1704_charger_data *board = isp->dev->platform_data; 91 - 92 - if (board && board->set_power) 93 - board->set_power(on); 94 - else if (board) 95 - gpio_set_value(board->enable_gpio, on); 86 + gpiod_set_value(isp->enable_gpio, on); 96 87 } 97 88 98 89 /* ··· 396 405 int ret = -ENODEV; 397 406 struct power_supply_config psy_cfg = {}; 398 407 399 - struct isp1704_charger_data *pdata = dev_get_platdata(&pdev->dev); 400 - struct device_node *np = pdev->dev.of_node; 401 - 402 - if (np) { 403 - int gpio = of_get_named_gpio(np, "nxp,enable-gpio", 0); 404 - 405 - if (gpio < 0) { 406 - dev_err(&pdev->dev, "missing DT GPIO nxp,enable-gpio\n"); 407 - return gpio; 408 - } 409 - 410 - pdata = devm_kzalloc(&pdev->dev, 411 - sizeof(struct isp1704_charger_data), GFP_KERNEL); 412 - if (!pdata) { 413 - ret = -ENOMEM; 414 - goto fail0; 415 - } 416 - pdata->enable_gpio = gpio; 417 - 418 - dev_info(&pdev->dev, "init gpio %d\n", pdata->enable_gpio); 419 - 420 - ret = devm_gpio_request_one(&pdev->dev, pdata->enable_gpio, 421 - GPIOF_OUT_INIT_HIGH, "isp1704_reset"); 422 - if (ret) { 423 - dev_err(&pdev->dev, "gpio request failed\n"); 424 - goto fail0; 425 - } 426 - } 427 - 428 - if (!pdata) { 429 - dev_err(&pdev->dev, "missing platform data!\n"); 430 - return -ENODEV; 431 - } 432 - 433 - 434 408 isp = devm_kzalloc(&pdev->dev, sizeof(*isp), GFP_KERNEL); 435 409 if (!isp) 436 410 return -ENOMEM; 437 411 438 - if (np) 412 + isp->enable_gpio = devm_gpiod_get(&pdev->dev, "nxp,enable", 413 + GPIOD_OUT_HIGH); 414 + if (IS_ERR(isp->enable_gpio)) { 415 + ret = PTR_ERR(isp->enable_gpio); 416 + dev_err(&pdev->dev, "Could not get reset gpio: %d\n", ret); 417 + return ret; 418 + } 419 + 420 + if (pdev->dev.of_node) 439 421 isp->phy = devm_usb_get_phy_by_phandle(&pdev->dev, "usb-phy", 0); 440 422 else 441 423 isp->phy = devm_usb_get_phy(&pdev->dev, USB_PHY_TYPE_USB2);
+10
drivers/power/supply/max17042_battery.c
··· 995 995 .num_properties = ARRAY_SIZE(max17042_battery_props) - 2, 996 996 }; 997 997 998 + static void max17042_stop_work(void *data) 999 + { 1000 + struct max17042_chip *chip = data; 1001 + 1002 + cancel_work_sync(&chip->work); 1003 + } 1004 + 998 1005 static int max17042_probe(struct i2c_client *client, 999 1006 const struct i2c_device_id *id) 1000 1007 { ··· 1108 1101 regmap_read(chip->regmap, MAX17042_STATUS, &val); 1109 1102 if (val & STATUS_POR_BIT) { 1110 1103 INIT_WORK(&chip->work, max17042_init_worker); 1104 + ret = devm_add_action(&client->dev, max17042_stop_work, chip); 1105 + if (ret) 1106 + return ret; 1111 1107 schedule_work(&chip->work); 1112 1108 } else { 1113 1109 chip->init_complete = 1;
+3 -2
drivers/power/supply/power_supply_core.c
··· 156 156 } 157 157 158 158 #ifdef CONFIG_OF 159 - #include <linux/of.h> 160 - 161 159 static int __power_supply_populate_supplied_from(struct device *dev, 162 160 void *data) 163 161 { ··· 573 575 info->energy_full_design_uwh = -EINVAL; 574 576 info->charge_full_design_uah = -EINVAL; 575 577 info->voltage_min_design_uv = -EINVAL; 578 + info->voltage_max_design_uv = -EINVAL; 576 579 info->precharge_current_ua = -EINVAL; 577 580 info->charge_term_current_ua = -EINVAL; 578 581 info->constant_charge_current_max_ua = -EINVAL; ··· 614 615 &info->charge_full_design_uah); 615 616 of_property_read_u32(battery_np, "voltage-min-design-microvolt", 616 617 &info->voltage_min_design_uv); 618 + of_property_read_u32(battery_np, "voltage-max-design-microvolt", 619 + &info->voltage_max_design_uv); 617 620 of_property_read_u32(battery_np, "precharge-current-microamp", 618 621 &info->precharge_current_ua); 619 622 of_property_read_u32(battery_np, "charge-term-current-microamp",
+89 -6
drivers/power/supply/sc27xx_fuel_gauge.c
··· 72 72 * @lock: protect the structure 73 73 * @gpiod: GPIO for battery detection 74 74 * @channel: IIO channel to get battery temperature 75 + * @charge_chan: IIO channel to get charge voltage 75 76 * @internal_resist: the battery internal resistance in mOhm 76 77 * @total_cap: the total capacity of the battery in mAh 77 78 * @init_cap: the initial capacity of the battery in mAh ··· 93 92 struct mutex lock; 94 93 struct gpio_desc *gpiod; 95 94 struct iio_channel *channel; 95 + struct iio_channel *charge_chan; 96 96 bool bat_present; 97 97 int internal_resist; 98 98 int total_cap; ··· 171 169 if (ret) 172 170 return ret; 173 171 172 + /* 173 + * Since the user area registers are put on power always-on region, 174 + * then these registers changing time will be a little long. Thus 175 + * here we should delay 200us to wait until values are updated 176 + * successfully according to the datasheet. 177 + */ 178 + udelay(200); 179 + 180 + ret = regmap_update_bits(data->regmap, 181 + data->base + SC27XX_FGU_USER_AREA_SET, 182 + SC27XX_FGU_MODE_AREA_MASK, 183 + boot_mode << SC27XX_FGU_MODE_AREA_SHIFT); 184 + if (ret) 185 + return ret; 186 + 187 + /* 188 + * Since the user area registers are put on power always-on region, 189 + * then these registers changing time will be a little long. Thus 190 + * here we should delay 200us to wait until values are updated 191 + * successfully according to the datasheet. 192 + */ 193 + udelay(200); 194 + 195 + /* 196 + * According to the datasheet, we should set the USER_AREA_CLEAR to 0 to 197 + * make the user area data available, otherwise we can not save the user 198 + * area data. 199 + */ 174 200 return regmap_update_bits(data->regmap, 175 - data->base + SC27XX_FGU_USER_AREA_SET, 176 - SC27XX_FGU_MODE_AREA_MASK, 177 - boot_mode << SC27XX_FGU_MODE_AREA_SHIFT); 201 + data->base + SC27XX_FGU_USER_AREA_CLEAR, 202 + SC27XX_FGU_MODE_AREA_MASK, 0); 178 203 } 179 204 180 205 static int sc27xx_fgu_save_last_cap(struct sc27xx_fgu_data *data, int cap) ··· 215 186 if (ret) 216 187 return ret; 217 188 189 + /* 190 + * Since the user area registers are put on power always-on region, 191 + * then these registers changing time will be a little long. Thus 192 + * here we should delay 200us to wait until values are updated 193 + * successfully according to the datasheet. 194 + */ 195 + udelay(200); 196 + 197 + ret = regmap_update_bits(data->regmap, 198 + data->base + SC27XX_FGU_USER_AREA_SET, 199 + SC27XX_FGU_CAP_AREA_MASK, cap); 200 + if (ret) 201 + return ret; 202 + 203 + /* 204 + * Since the user area registers are put on power always-on region, 205 + * then these registers changing time will be a little long. Thus 206 + * here we should delay 200us to wait until values are updated 207 + * successfully according to the datasheet. 208 + */ 209 + udelay(200); 210 + 211 + /* 212 + * According to the datasheet, we should set the USER_AREA_CLEAR to 0 to 213 + * make the user area data available, otherwise we can not save the user 214 + * area data. 215 + */ 218 216 return regmap_update_bits(data->regmap, 219 - data->base + SC27XX_FGU_USER_AREA_SET, 220 - SC27XX_FGU_CAP_AREA_MASK, cap); 217 + data->base + SC27XX_FGU_USER_AREA_CLEAR, 218 + SC27XX_FGU_CAP_AREA_MASK, 0); 221 219 } 222 220 223 221 static int sc27xx_fgu_read_last_cap(struct sc27xx_fgu_data *data, int *cap) ··· 447 391 return 0; 448 392 } 449 393 394 + static int sc27xx_fgu_get_charge_vol(struct sc27xx_fgu_data *data, int *val) 395 + { 396 + int ret, vol; 397 + 398 + ret = iio_read_channel_processed(data->charge_chan, &vol); 399 + if (ret < 0) 400 + return ret; 401 + 402 + *val = vol * 1000; 403 + return 0; 404 + } 405 + 450 406 static int sc27xx_fgu_get_temp(struct sc27xx_fgu_data *data, int *temp) 451 407 { 452 408 return iio_read_channel_processed(data->channel, temp); ··· 570 502 val->intval = value; 571 503 break; 572 504 505 + case POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE: 506 + ret = sc27xx_fgu_get_charge_vol(data, &value); 507 + if (ret) 508 + goto error; 509 + 510 + val->intval = value; 511 + break; 512 + 573 513 case POWER_SUPPLY_PROP_CURRENT_NOW: 574 514 case POWER_SUPPLY_PROP_CURRENT_AVG: 575 515 ret = sc27xx_fgu_get_current(data, &value); ··· 643 567 POWER_SUPPLY_PROP_VOLTAGE_OCV, 644 568 POWER_SUPPLY_PROP_CURRENT_NOW, 645 569 POWER_SUPPLY_PROP_CURRENT_AVG, 570 + POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, 646 571 }; 647 572 648 573 static const struct power_supply_desc sc27xx_fgu_desc = { ··· 785 708 * Convert current capacity (mAh) to coulomb counter according to the 786 709 * formula: 1 mAh =3.6 coulomb. 787 710 */ 788 - return DIV_ROUND_CLOSEST(cur_cap * 36, 10); 711 + return DIV_ROUND_CLOSEST(cur_cap * 36 * data->cur_1000ma_adc, 10); 789 712 } 790 713 791 714 static int sc27xx_fgu_calibration(struct sc27xx_fgu_data *data) ··· 982 905 if (IS_ERR(data->channel)) { 983 906 dev_err(&pdev->dev, "failed to get IIO channel\n"); 984 907 return PTR_ERR(data->channel); 908 + } 909 + 910 + data->charge_chan = devm_iio_channel_get(&pdev->dev, "charge-vol"); 911 + if (IS_ERR(data->charge_chan)) { 912 + dev_err(&pdev->dev, "failed to get charge IIO channel\n"); 913 + return PTR_ERR(data->charge_chan); 985 914 } 986 915 987 916 data->gpiod = devm_gpiod_get(&pdev->dev, "bat-detect", GPIOD_IN);
+3 -1
drivers/power/supply/twl4030_charger.c
··· 809 809 is_charging = state & TWL4030_MSTATEC_AC; 810 810 if (!is_charging) { 811 811 u8 s; 812 - twl4030_bci_read(TWL4030_BCIMDEN, &s); 812 + ret = twl4030_bci_read(TWL4030_BCIMDEN, &s); 813 + if (ret < 0) 814 + return ret; 813 815 if (psy->desc->type == POWER_SUPPLY_TYPE_USB) 814 816 is_charging = s & 1; 815 817 else
-30
include/linux/power/isp1704_charger.h
··· 1 - /* 2 - * ISP1704 USB Charger Detection driver 3 - * 4 - * Copyright (C) 2011 Nokia Corporation 5 - * 6 - * This program is free software; you can redistribute it and/or modify 7 - * it under the terms of the GNU General Public License as published by 8 - * the Free Software Foundation; either version 2 of the License, or 9 - * (at your option) any later version. 10 - * 11 - * This program is distributed in the hope that it will be useful, 12 - * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 - * GNU General Public License for more details. 15 - * 16 - * You should have received a copy of the GNU General Public License 17 - * along with this program; if not, write to the Free Software 18 - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 19 - */ 20 - 21 - 22 - #ifndef __ISP1704_CHARGER_H 23 - #define __ISP1704_CHARGER_H 24 - 25 - struct isp1704_charger_data { 26 - void (*set_power)(bool on); 27 - int enable_gpio; 28 - }; 29 - 30 - #endif
+1
include/linux/power_supply.h
··· 332 332 int energy_full_design_uwh; /* microWatt-hours */ 333 333 int charge_full_design_uah; /* microAmp-hours */ 334 334 int voltage_min_design_uv; /* microVolts */ 335 + int voltage_max_design_uv; /* microVolts */ 335 336 int precharge_current_ua; /* microAmps */ 336 337 int charge_term_current_ua; /* microAmps */ 337 338 int constant_charge_current_max_ua; /* microAmps */