aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/supply (follow)
AgeCommit message (Collapse)AuthorFilesLines
2020-02-04Merge tag 'tag-chrome-platform-for-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linuxLinus Torvalds1-1/+0
Pull chrome platform updates from Benson Leung: "CrOS EC: - Refactoring of some of cros_ec's headers: include/linux/mfd/cros_ec.h now removed, new cros_ec.h added to drivers/platform/chrome which contains shared operations of cros_ec transport drivers. - Response tracing in cros_ec_proto Wilco EC: - Fix unregistration order. - Fix keyboard backlight probing on systems without keyboard backlight - Minor cleanup (newlines in printks, COMPILE_TEST) Misc: - chromeos_laptop converted to use i2c_new_scanned_device instead of i2c_new_probed_device" * tag 'tag-chrome-platform-for-v5.6' of git://git.kernel.org/pub/scm/linux/kernel/git/chrome-platform/linux: platform/chrome: cros_ec: Match implementation with headers platform/chrome: cros_ec: Drop unaligned.h include platform/chrome: wilco_ec: Allow wilco to be compiled in COMPILE_TEST platform/chrome: wilco_ec: Add newlines to printks platform/chrome: wilco_ec: Fix unregistration order cros_ec: treewide: Remove 'include/linux/mfd/cros_ec.h' platform/chrome: cros_ec_ishtp: Make init_lock static platform/chrome: chromeos_laptop: Convert to i2c_new_scanned_device platform/chrome: cros_ec_lpc: Use platform_get_irq_optional() for optional IRQs platform/chrome: cros_ec_proto: Add response tracing platform/chrome: cros_ec_trace: Match trace commands with EC commands
2020-01-17power: supply: ipaq_micro_battery: remove unneeded semicolonChen Zhou1-3/+3
Fixes coccicheck warning: ./drivers/power/supply/ipaq_micro_battery.c:188:2-3: Unneeded semicolon ./drivers/power/supply/ipaq_micro_battery.c:152:3-4: Unneeded semicolon ./drivers/power/supply/ipaq_micro_battery.c:171:2-3: Unneeded semicolon Signed-off-by: Chen Zhou <chenzhou10@huawei.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-16power: supply: bq25890_charger: fix incorrect error return when bq25890_field_read failsColin Ian King1-1/+1
Currently a read failure by bq25890_field_read on F_DEV_REV is returning an error in id instead of rev. Fix this by returning the value in rev. Addresses-Coverity: ("Copy-paste error") Fixes: d20267c9a98e ("power: supply: bq25890_charger: Add support of BQ25892 and BQ25896 chips") Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-15power: supply: axp20x_usb_power: Only poll while offlineSamuel Holland1-9/+21
Investigation on the AXP803 shows that VBUS_PLUGIN/VBUS_REMOVAL IRQs are triggered on the rising/falling edge of AXP20X_PWR_STATUS_VBUS_USED. The reason IRQs do not arrive while N_VBUSEN/DRIVEVBUS is high is because AXP20X_PWR_STATUS_VBUS_USED also never goes high. This also means that if VBUS is online, a VBUS_REMOVAL IRQ is received immediately on setting N_VBUSEN/DRIVEVBUS high (and VBUS_PLUGIN shortly after it is set back low). This was also verified to be the case when manually offlining VBUS through AXP20X_VBUS_PATH_SELECT. As long as VBUS is online, a present->absent transition necessarily implies an online->offline transition. Since will cause an IRQ, there is no need to poll while VBUS is online. To ensure the driver's view of VBUS online status remains accurate, unconditionally poll once when receiving an IRQ and when resuming. If VBUS is still online at that time, polling will cease until the next VBUS_REMOVAL IRQ. Reviewed-by: Chen-Yu Tsai <wens@csie.org> Signed-off-by: Samuel Holland <samuel@sholland.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-15power: supply: axp20x_usb_power: Add wakeup controlSamuel Holland1-16/+67
The USB power supply input can be used as a wakeup source. Hook up the VBUS_PLUGIN IRQ to trigger wakeup based on userspace configuration. To do this, we must remember the list of IRQs for the life of the device. To know how much space to allocate for the flexible array member, we switch from using a NULL sentinel to using an array length. Because we now depend on the specific order of the IRQs (we assume VBUS_PLUGIN is first and always present), failing to acquire an IRQ during probe must be a fatal error. To avoid spuriously waking up the system when the USB power supply is not configured as a wakeup source, we must explicitly disable all non- wake IRQs during system suspend. This is because the SoC's NMI input is shared among all IRQs on the AXP PMIC. Due to the use of regmap-irq, the individual IRQs within the PMIC are nested threaded interrupts, and are therefore not automatically disabled during system suspend. The upshot is that if any other device within the MFD (such as the power key) is an enabled wakeup source, all enabled IRQs within the PMIC will cause wakeup. We still need to call enable_irq_wake() when we *do* want wakeup, in case those other wakeup sources on the PMIC are all disabled. Reviewed-by: Chen-Yu Tsai <wens@csie.org> Signed-off-by: Samuel Holland <samuel@sholland.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-15power: supply: axp20x_usb_power: Allow offliningSamuel Holland1-0/+30
AXP803/AXP813 have a flag that enables/disables the USB power supply input. Allow control of this flag via the ONLINE property on those variants. It may be necessary to offline the USB power supply input when using the USB port in OTG mode, or to allow userspace to disable charging. When the USB VBUS input is disabled via the PATH_SEL bit, the VBUS_USED bit in PWR_INPUT_STATUS is cleared, so there is no change needed when getting the property. Reviewed-by: Chen-Yu Tsai <wens@csie.org> Signed-off-by: Samuel Holland <samuel@sholland.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-15power: supply: axp20x_usb_power: Use a match structureSamuel Holland1-29/+57
Instead of ad-hoc variant ID checks throughout the code, let's start moving the variant-specific details to a match structure. This allows for future flexibility, and it better matches the other axp20x power supply drivers. This commit removes most variant checks from axp20x_usb_power_probe(). Other parts of the driver still do ID matching; they are left unchanged for now. Reviewed-by: Chen-Yu Tsai <wens@csie.org> Signed-off-by: Samuel Holland <samuel@sholland.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-15power: suppy: ucs1002: Make the symbol 'ucs1002_regulator_enable' staticChen Wandun1-1/+1
Fix the following sparse warning: drivers/power/supply/ucs1002_power.c:492:5: warning: symbol 'ucs1002_regulator_enable' was not declared. Should it be static? Fixes: a3d70dacc727 ("power: suppy: ucs1002: disable power when max current is 0") Signed-off-by: Chen Wandun <chenwandun@huawei.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-14power: supply: bq25890_charger: Add DT and I2C ids for all supported chipsYauhen Kharuzhy1-0/+6
Add bq25892, bq25895 and bq25896 to list of supported device IDs for DeviceTree and I2C. Signed-off-by: Yauhen Kharuzhy <jekhor@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-14power: supply: bq25890_charger: Add support of BQ25892 and BQ25896 chipsYauhen Kharuzhy1-21/+76
Support BQ25892 and BQ25896 chips by this driver. They shared one chip ID 0, so distinquish them by device revisions (2 for 25896 and 1 for 25892). Signed-off-by: Yauhen Kharuzhy <jekhor@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-14power: supply: sbs-battery: Fix a signedness bug in sbs_get_battery_capacity()Dan Carpenter1-1/+1
The "mode" variable is an enum and in this context GCC treats it as an unsigned int so the error handling is never triggered. Fixes: 51d075660457 ("bq20z75: Add support for charge properties") Signed-off-by: Dan Carpenter <dan.carpenter@oracle.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-14power: supply: ltc2941-battery-gauge: fix use-after-freeSven Van Asbroeck1-1/+1
This driver's remove path calls cancel_delayed_work(). However, that function does not wait until the work function finishes. This could mean that the work function is still running after the driver's remove function has finished, which would result in a use-after-free. Fix by calling cancel_delayed_work_sync(), which ensures that that the work is properly cancelled, no longer running, and unable to re-schedule itself. This issue was detected with the help of Coccinelle. Cc: stable <stable@vger.kernel.org> Signed-off-by: Sven Van Asbroeck <TheSven73@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-14power: supply: max17040: Correct IRQ wake handlingMarek Szyprowski1-12/+4
Don't disable IRQ wake feature without prior enabling it. This fixes following warning observed on Exynos3250-based Rinato board: ------------[ cut here ]------------ WARNING: CPU: 0 PID: 1288 at kernel/irq/manage.c:724 irq_set_irq_wake+0xfc/0x134 Unbalanced IRQ 83 wake disable Modules linked in: CPU: 0 PID: 1288 Comm: rtcwake Not tainted 5.5.0-rc5-next-20200110-00031-g6289fffbb3f5 #7266 Hardware name: Samsung Exynos (Flattened Device Tree) [<c0112e48>] (unwind_backtrace) from [<c010e090>] (show_stack+0x10/0x14) [<c010e090>] (show_stack) from [<c0b25b28>] (dump_stack+0xa4/0xd0) [<c0b25b28>] (dump_stack) from [<c0128088>] (__warn+0xf4/0x10c) [<c0128088>] (__warn) from [<c0128114>] (warn_slowpath_fmt+0x74/0xb8) [<c0128114>] (warn_slowpath_fmt) from [<c019e9a0>] (irq_set_irq_wake+0xfc/0x134) [<c019e9a0>] (irq_set_irq_wake) from [<c0772708>] (max17040_suspend+0x50/0x58) [<c0772708>] (max17040_suspend) from [<c05f55ac>] (dpm_run_callback+0xb4/0x400) [<c05f55ac>] (dpm_run_callback) from [<c05f5e38>] (__device_suspend+0x140/0x814) [<c05f5e38>] (__device_suspend) from [<c05f9548>] (dpm_suspend+0x16c/0x564) [<c05f9548>] (dpm_suspend) from [<c05fa2e4>] (dpm_suspend_start+0x90/0x98) [<c05fa2e4>] (dpm_suspend_start) from [<c01977f4>] (suspend_devices_and_enter+0xec/0xc0c) [<c01977f4>] (suspend_devices_and_enter) from [<c019862c>] (pm_suspend+0x318/0x3e8) [<c019862c>] (pm_suspend) from [<c01963cc>] (state_store+0x68/0xc8) [<c01963cc>] (state_store) from [<c03531a4>] (kernfs_fop_write+0x10c/0x220) [<c03531a4>] (kernfs_fop_write) from [<c02b44c4>] (__vfs_write+0x2c/0x1c4) [<c02b44c4>] (__vfs_write) from [<c02b7288>] (vfs_write+0xa4/0x180) [<c02b7288>] (vfs_write) from [<c02b74d0>] (ksys_write+0x58/0xcc) [<c02b74d0>] (ksys_write) from [<c0101000>] (ret_fast_syscall+0x0/0x28) Exception stack(0xd6e83fa8 to 0xd6e83ff0) ... irq event stamp: 18028 hardirqs last enabled at (18027): [<c014b99c>] cancel_delayed_work+0x84/0xf8 hardirqs last disabled at (18028): [<c0b49b1c>] _raw_spin_lock_irqsave+0x1c/0x58 softirqs last enabled at (17876): [<c01026d8>] __do_softirq+0x4f0/0x5e4 softirqs last disabled at (17869): [<c0130d34>] irq_exit+0x16c/0x170 ---[ end trace 0728005730004e60 ]--- Fixes: 2e17ed94de68 ("power: supply: max17040: Add IRQ handler for low SOC alert") Signed-off-by: Marek Szyprowski <m.szyprowski@samsung.com> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-14power: supply: axp20x_usb_power: Remove unused device_nodeSamuel Holland1-2/+0
This member of struct axp20x_usb_power is not used anywhere. Remove it. Reviewed-by: Chen-Yu Tsai <wens@csie.org> Signed-off-by: Samuel Holland <samuel@sholland.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-14power: supply: axp20x_ac_power: Add wakeup controlSamuel Holland1-17/+74
The AC power supply input can be used as a wakeup source. Hook up the ACIN_PLUGIN IRQ to trigger wakeup based on userspace configuration. To do this, we must remember the list of IRQs for the life of the device. To know how much space to allocate for the flexible array member, we switch from using a NULL sentinel to using an array length. Because we now depend on the specific order of the IRQs (we assume ACIN_PLUGIN is first and always present), failing to acquire an IRQ during probe must be a fatal error. To avoid spuriously waking up the system when the AC power supply is not configured as a wakeup source, we must explicitly disable all non- wake IRQs during system suspend. This is because the SoC's NMI input is shared among all IRQs on the AXP PMIC. Due to the use of regmap-irq, the individual IRQs within the PMIC are nested threaded interrupts, and are therefore not automatically disabled during system suspend. The upshot is that if any other device within the MFD (such as the power key) is an enabled wakeup source, all enabled IRQs within the PMIC will cause wakeup. We still need to call enable_irq_wake() when we *do* want wakeup, in case those other wakeup sources on the PMIC are all disabled. Reviewed-by: Chen-Yu Tsai <wens@csie.org> Signed-off-by: Samuel Holland <samuel@sholland.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-14power: supply: axp20x_ac_power: Allow offliningSamuel Holland1-1/+8
AXP803/AXP813 have a flag that enables/disables the AC power supply input. Allow control of this flag via the ONLINE property on those variants. Reviewed-by: Chen-Yu Tsai <wens@csie.org> Signed-off-by: Samuel Holland <samuel@sholland.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-14power: supply: axp20x_ac_power: Fix reporting online statusSamuel Holland1-6/+25
AXP803/AXP813 have a flag that enables/disables the AC power supply input. This flag does not affect the status bits in PWR_INPUT_STATUS. Its effect can be verified by checking the battery charge/discharge state (bit 2 of PWR_INPUT_STATUS), or by examining the current draw on the AC input. Take this flag into account when getting the ONLINE property of the AC input, on PMICs where this flag is present. Fixes: 7693b5643fd2 ("power: supply: add AC power supply driver for AXP813") Cc: stable@vger.kernel.org Signed-off-by: Samuel Holland <samuel@sholland.org> Reviewed-by: Chen-Yu Tsai <wens@csie.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-01-07cros_ec: treewide: Remove 'include/linux/mfd/cros_ec.h'Enric Balletbo i Serra1-1/+0
This header file now only includes the cros_ec_dev struct, however, is the 'include/linux/platform_data/cros_ec_proto.h' who contains the definition of all the Chrome OS EC related structs. There is no reason to have a separate include for this struct so move to the place where other structs are defined. That way, we can remove the include itself, but also simplify the common pattern #include <linux/mfd/cros_ec.h> #include <linux/platform_data/cros_ec_proto.h> for a single include #include <linux/platform_data/cros_ec_proto.h> The changes to remove the cros_ec.h include were generated with the following shell script: git grep -l "<linux/mfd/cros_ec.h>" | xargs sed -i '/<linux\/mfd\/cros_ec.h>/d' Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com> Acked-by: Lee Jones <lee.jones@linaro.org> Acked-by: Alexandre Belloni <alexandre.belloni@bootlin.com> Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Acked-by: Sebastian Reichel <sre@kernel.org> Acked-by: Hans Verkuil <hverkuil-cisco@xs4all.nl>
2019-12-19power: supply: abx500_chargalg: Remove unneeded semicolonMa Feng1-1/+1
Fixes coccicheck warning: drivers/power/supply/abx500_chargalg.c:1826:2-3: Unneeded semicolon Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Ma Feng <mafeng.ma@huawei.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: ab8500_charger: Remove unneeded semicolonMa Feng1-3/+3
Fixes coccicheck warning: drivers/power/supply/ab8500_charger.c:1082:2-3: Unneeded semicolon drivers/power/supply/ab8500_charger.c:792:2-3: Unneeded semicolon drivers/power/supply/ab8500_charger.c:2430:2-3: Unneeded semicolon Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Ma Feng <mafeng.ma@huawei.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: ab8500: Remove unneeded semicolonMa Feng1-7/+7
Fixes coccicheck warning: drivers/power/supply/ab8500_fg.c:2224:5-6: Unneeded semicolon drivers/power/supply/ab8500_fg.c:2227:4-5: Unneeded semicolon drivers/power/supply/ab8500_fg.c:2334:3-4: Unneeded semicolon drivers/power/supply/ab8500_fg.c:2342:3-4: Unneeded semicolon drivers/power/supply/ab8500_fg.c:2350:3-4: Unneeded semicolon drivers/power/supply/ab8500_fg.c:2358:3-4: Unneeded semicolon drivers/power/supply/ab8500_fg.c:2366:3-4: Unneeded semicolon Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Ma Feng <mafeng.ma@huawei.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: sbs-battery: fix CAPACITY_MODE bit namingJean-Francois Dagenais1-15/+16
"Battery mode" is the name of the register, the bit manipulated by this code is "CAPACITY_MODE" (Smart Battery System Specifications). Signed-off-by: Jean-Francois Dagenais <jeff.dagenais@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: sbs-battery: use octal permissions on module paramJean-Francois Dagenais1-1/+1
Symbolic permissions 'S_IRUSR | S_IRGRP | S_IROTH' are not preferred. Use octal permissions '0444'. Signed-off-by: Jean-Francois Dagenais <jeff.dagenais@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: cros_usbpd: Remove dev_err() getting the number of portsEnric Balletbo i Serra1-8/+2
When a device has no support to get the charger number of ports, it doesn't have to result in a dev_err(), print saying "Could not get charger port count" using a dev_info() would suffice. In such case, the dev_info() message is already printed but the dev_err() is annoying, specially, on those devices that doesn't support the command. So remove the dev_err(). Signed-off-by: Enric Balletbo i Serra <enric.balletbo@collabora.com> Reviewed-by: Guenter Roeck <groeck@chromium.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: max17040: Send uevent in SOC and status changeMatheus Castello1-0/+9
Notify core through power_supply_changed() in case of changes in state of charge and power supply status. This is useful for user-space to efficiently update current battery level. Signed-off-by: Matheus Castello <matheus@castello.eng.br> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: max17040: Config alert SOC low level threshold from FDTMatheus Castello1-1/+51
For configuration of fuel gauge alert for a low level state of charge interrupt we add a function to config level threshold and a device tree binding property to set it in flatned device tree node. Now we can use "maxim,alert-low-soc-level" property with the values from 1% up to 32% to configure alert interrupt threshold. Signed-off-by: Matheus Castello <matheus@castello.eng.br> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: max17040: Add IRQ handler for low SOC alertMatheus Castello1-5/+68
According datasheet max17040 has a pin for alert host for low SOC. This pin can be used as external interrupt, so we need to check for interrupts assigned for device and handle it. In handler we are checking and storing fuel gauge registers values and send an uevent to notificate user space, so user space can decide save work or turn off since the alert demonstrate that the battery may no have the power to keep the system turned on for much longer. Signed-off-by: Matheus Castello <matheus@castello.eng.br> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: sc27xx: Calibrate the resistance of coulomb counterBaolin Wang1-1/+16
There are some deviations between the real resistance and the ideal resistance of coulomb counter, which will affect the accuracy of the coulomb counter, thus calibrate the real resistance of coulomb counter to improve the accuracy. Signed-off-by: Baolin Wang <baolin.wang@linaro.org> Signed-off-by: Baolin Wang <baolin.wang7@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: sc27xx: Optimize the battery resistance with measuring temperatureYuanjiang Yu1-2/+30
Optimize the battery internal resistance in a certain temerature to get a accurate battery internal resistance. Signed-off-by: Yuanjiang Yu <yuanjiang.yu@unisoc.com> Signed-off-by: Baolin Wang <baolin.wang@linaro.org> Signed-off-by: Baolin Wang <baolin.wang7@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: core: Add battery internal resistance temperature table supportBaolin Wang1-1/+66
Since the battery internal resistance can be changed with the temperature changes, thus add a resistance temperature table support to look up the accurate battery internal resistance in a certain temperature. Signed-off-by: Baolin Wang <baolin.wang@linaro.org> Signed-off-by: Baolin Wang <baolin.wang7@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: max77650: add of_match tableBartosz Golaszewski1-0/+7
We need the of_match table if we want to use the compatible string in the pmic's child node and get the charger driver loaded automatically. Signed-off-by: Bartosz Golaszewski <bgolaszewski@baylibre.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: max17042: add MAX17055 supportAngus Ainslie (Purism)1-3/+14
The MAX17055 is very similar to the MAX17042 so extend the driver. Signed-off-by: Angus Ainslie (Purism) <angus@akkea.ca> Reviewed-by: Krzysztof Kozlowski <krzk@kernel.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: suppy: ucs1002: disable power when max current is 0Lucas Stach1-4/+38
For some devices userspace needs the ability to completely cut the power to the USB devices connected to the charge controller. An easy way to achieve this is by allowing 0 as a valid max current and forcibly disable the output in that case, as well as enable it again if the regulator is in use and a non-0 max current is set. Signed-off-by: Lucas Stach <l.stach@pengutronix.de> Tested-by: Chris Healy <cphealy@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: Fix Kconfig indentationKrzysztof Kozlowski1-15/+15
Adjust indentation from spaces to tab (+optional two spaces) as in coding style with command like: $ sed -e 's/^ /\t/' -i */Kconfig Signed-off-by: Krzysztof Kozlowski <krzk@kernel.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power/supply: ingenic-battery: Don't change scale if there's only onePaul Cercueil1-4/+11
The ADC in the JZ4740 can work either in high-precision mode with a 2.5V range, or in low-precision mode with a 7.5V range. The code in place in this driver will select the proper scale according to the maximum voltage of the battery. The JZ4770 however only has one mode, with a 6.6V range. If only one scale is available, there's no need to change it (and nothing to change it to), and trying to do so will fail with -EINVAL. Fixes: fb24ccfbe1e0 ("power: supply: add Ingenic JZ47xx battery driver.") Signed-off-by: Paul Cercueil <paul@crapouillou.net> Acked-by: Artur Rojek <contact@artur-rojek.eu> Cc: stable@vger.kernel.org Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-12-19power: supply: pda_power: add missed usb_unregister_notifierChuhong Yuan1-0/+4
The driver forgets to unregister the notifier in remove. Add the call to fix it. Signed-off-by: Chuhong Yuan <hslester96@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-10-27power: supply: bd70528: Add MODULE_ALIAS to allow module auto loadingMatti Vaittinen1-0/+1
The bd70528 charger driver is probed by MFD driver. Add MODULE_ALIAS in order to allow udev to load the module when MFD sub-device cell for charger is added. Fixes: f8c7f7ddd8ef0 ("power: supply: Initial support for ROHM BD70528 PMIC charger block") Signed-off-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-10-27power: supply: ab8500_charger: Fix inconsistent IS_ERR and PTR_ERRGustavo A. R. Silva1-1/+1
Fix inconsistent IS_ERR and PTR_ERR in ab8500_charger_probe(). The proper pointer to be passed as argument is di->adc_main_charger_c This bug was detected with the help of Coccinelle. Fixes: 97ab78bac5d0 ("power: supply: ab8500_charger: Convert to IIO ADC") Signed-off-by: Gustavo A. R. Silva <gustavo@embeddedor.com> Reviewed-by: Signed-off-by: Wei Yongjun <weiyongjun1@huawei.com> Acked-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-10-21power: supply: cpcap-charger: cpcap_charger_voltage_to_regval() can be statickbuild test robot1-1/+1
Add 'static' keyword to internal function as reported by sparse using the following configuration: make ARCH=x86_64 allmodconfig make C=1 CF='-fdiagnostic-prefix -D__CHECK_ENDIAN__' Fixes: d4ee021c410f ("power: supply: cpcap-charger: Limit voltage to 4.2V for battery") Signed-off-by: kbuild test robot <lkp@intel.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-10-20power: supply: cpcap-battery: Add basic coulomb counter calibrate supportTony Lindgren1-8/+88
This patch adds support for the coulomb counter calibration on init. We do this by polling for now, and only add partial calibration done interrupt support. Then later on when we know for sure we have the calibration done interrupt available in the device tree, we can switch to using the calibration done interrupt. Cc: Merlijn Wajer <merlijn@wizzup.org> Signed-off-by: Tony Lindgren <tony@atomide.com> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-10-20power: supply: cpcap-battery: Read and save integrator register CCITony Lindgren1-1/+9
We can simplify code in the later patches by reading and saving the integrator register CCI. Let's also fix a comment typo for register range naming while at it. Cc: Merlijn Wajer <merlijn@wizzup.org> Signed-off-by: Tony Lindgren <tony@atomide.com> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-10-20power: supply: cpcap-battery: Simplify short term power average calculationTony Lindgren1-13/+10
We can use sign_extend32() here to simplify things. And let's fix the comment for CCM register, that contains the calibration offset. Cc: Merlijn Wajer <merlijn@wizzup.org> Signed-off-by: Tony Lindgren <tony@atomide.com> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-10-20power: supply: cpcap-battery: Simplify coulomb counter calculation with div_s64Tony Lindgren1-18/+5
We can simplify cpcap_battery_cc_raw_div() with div_s64. Cc: Merlijn Wajer <merlijn@wizzup.org> Signed-off-by: Tony Lindgren <tony@atomide.com> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-10-20power: supply: cpcap-battery: Move coulomb counter units per lsb to ddataTony Lindgren1-14/+14
We can simplify cpcap_battery_cc_raw_div() a bit by moving the units per lsb to ddata. Cc: Merlijn Wajer <merlijn@wizzup.org> Signed-off-by: Tony Lindgren <tony@atomide.com> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-10-20power: supply: cpcap-charger: Allow changing constant charge voltageTony Lindgren1-0/+83
Let's allow reconfiguring the cpcap-charger max charge voltage and default to 4.2V that should be safe for the known users. This allows the users to use 4.35V for the extra capacity if really needed at a cost of probably shorter battery life. We check the constant charge voltage limit set by the battery. Some pieces of the property setting code is based on an earlier patch from Pavel Machek <pavel@ucw.cz> but limited to configuring the charge voltage for now. Cc: Merlijn Wajer <merlijn@wizzup.org> Cc: Pavel Machek <pavel@ucw.cz> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-10-20power: supply: cpcap-battery: Fix handling of lowered charger voltageTony Lindgren1-7/+78
With cpcap-charger now using 4.2V instead of 4.35V, we never reach POWER_SUPPLY_CAPACITY_LEVEL_FULL unless we handle the lowered charge voltage. Let's do this by implementing POWER_SUPPLY_PROP_CONSTANT_CHARGE_VOLTAGE, and assume anything at that level or higher is a full battery. Let's also make it configurable for users who may still want to reconfigure it, and notify the charger if supported by the charger. Cc: Merlijn Wajer <merlijn@wizzup.org> Cc: Pavel Machek <pavel@ucw.cz> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-10-20power: supply: cpcap-charger: Improve battery detectionTony Lindgren1-3/+4
We are currently using a wrong ADC range for the battery detection. The ADC returns the battery temperature if connected. Cc: Merlijn Wajer <merlijn@wizzup.org> Cc: Pavel Machek <pavel@ucw.cz> Acked-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-10-20power: supply: cpcap-battery: Check voltage before orderly_poweroffTony Lindgren1-3/+5
We can get the low voltage interrupt trigger sometimes way too early, maybe because of CPU load spikes. This causes orderly_poweroff() be called too easily. Let's check the voltage before orderly_poweroff in case it was not yet a permanent condition. We will be getting more interrupts anyways if the condition persists. Let's also show the measured voltages for low battery and battery empty warnings since we have them. Cc: Merlijn Wajer <merlijn@wizzup.org> Cc: Pavel Machek <pavel@ucw.cz> Signed-off-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-10-20Merge tag 'psy-cpcap-charge-volt-limit-signed' into psy-nextSebastian Reichel1-2/+130
Immutable branch between arm and power-supply for cpcap-charger This immutable branch contains CPCAP charger changes, which touch ARM and power-supply subsystem. Signed-off-by: Sebastian Reichel <sre@kernel.org>
2019-10-20power: supply: cpcap-charger: Limit voltage to 4.2V for batteryTony Lindgren1-2/+130
There have been some cases of droid4 battery bulging that seem to be related to being left connected to the charger for several weeks. It is suspected that the 4.35V charge voltage configured for the battery is too much in the long run, so lets limit the charge voltage to 4.2V. It could also be that the batteries are just getting old. We don't really want to just change the charge voltage to 4.2V as Android may have charged the battery to 4.35V as pointed out by Pavel Machek. To add checks for battery voltage, the driver needs to understand the voltage it's charging at, and also needs to better understand it's charger state. Right now it only understands connect and disconnect, while now we need to know also a connected state but not charging. So let's add better charger state handling with help of chrgcurr2 interrupt for detecting charge full and retry, and add a check for battery voltage before we start charging. And then we finally can lower the charge voltage to 4.2V. Note that we've been using the same register values as the Android distros on droid4, so it is suspected that the same problem also exists in Android. Cc: Pavel Machek <pavel@ucw.cz> Cc: Rob Herring <robh+dt@kernel.org> Reported-by: Merlijn Wajer <merlijn@wizzup.org> Signed-off-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>