summaryrefslogtreecommitdiff
path: root/drivers/power
AgeCommit message (Collapse)AuthorFilesLines
2022-01-27power: reset: mt6397: Check for null res pointerJiasheng Jiang1-0/+3
[ Upstream commit 1c1348bf056dee665760a3bd1cd30b0be7554fc2 ] The return value of platform_get_resource() needs to be checked. To avoid use of error pointer in case that there is no suitable resource. Fixes: d28c74c10751 ("power: reset: add driver for mt6323 poweroff") Signed-off-by: Jiasheng Jiang <jiasheng@iscas.ac.cn> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
2022-01-11power: bq25890: Enable continuous conversion for ADC at chargingYauhen Kharuzhy1-2/+2
commit 80211be1b9dec04cc2805d3d81e2091ecac289a1 upstream. Instead of one shot run of ADC at beginning of charging, run continuous conversion to ensure that all charging-related values are monitored properly (input voltage, input current, themperature etc.). Signed-off-by: Yauhen Kharuzhy <jekhor@gmail.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-01-11power: reset: ltc2952: Fix use of floating point literalsNathan Chancellor1-2/+2
commit 644106cdb89844be2496b21175b7c0c2e0fab381 upstream. A new commit in LLVM causes an error on the use of 'long double' when '-mno-x87' is used, which the kernel does through an alias, '-mno-80387' (see the LLVM commit below for more details around why it does this). drivers/power/reset/ltc2952-poweroff.c:162:28: error: expression requires 'long double' type support, but target 'x86_64-unknown-linux-gnu' does not support it data->wde_interval = 300L * 1E6L; ^ drivers/power/reset/ltc2952-poweroff.c:162:21: error: expression requires 'long double' type support, but target 'x86_64-unknown-linux-gnu' does not support it data->wde_interval = 300L * 1E6L; ^ drivers/power/reset/ltc2952-poweroff.c:163:41: error: expression requires 'long double' type support, but target 'x86_64-unknown-linux-gnu' does not support it data->trigger_delay = ktime_set(2, 500L*1E6L); ^ 3 errors generated. This happens due to the use of a 'long double' literal. The 'E6' part of '1E6L' causes the literal to be a 'double' then the 'L' suffix promotes it to 'long double'. There is no visible reason for floating point values in this driver, as the values are only assigned to integer types. Use NSEC_PER_MSEC, which is the same integer value as '1E6L', to avoid changing functionality but fix the error. Fixes: 6647156c00cc ("power: reset: add LTC2952 poweroff driver") Link: https://github.com/ClangBuiltLinux/linux/issues/1497 Link: https://github.com/llvm/llvm-project/commit/a8083d42b1c346e21623a1d36d1f0cadd7801d83 Signed-off-by: Nathan Chancellor <nathan@kernel.org> Reviewed-by: Nick Desaulniers <ndesaulniers@google.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2022-01-11power: supply: core: Break capacity loopLinus Walleij1-0/+4
commit 51c7b6a0398f54b9120795796a4cff4fc9634f7d upstream. We should not go on looking for more capacity tables after we realize we have looked at the last one in power_supply_find_ocv2cap_table(). Fixes: 3afb50d7125b ("power: supply: core: Add some helpers to use the battery OCV capacity table") Cc: Chunyan Zhang <chunyan.zhang@unisoc.com> Cc: Baolin Wang <baolin.wang@linux.alibaba.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Baolin Wang <baolin.wang@linux.alibaba.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-18power: supply: bq27xxx: Fix kernel crash on IRQ handler register errorHans de Goede1-1/+2
[ Upstream commit cdf10ffe8f626d8a2edc354abf063df0078b2d71 ] When registering the IRQ handler fails, do not just return the error code, this will free the devm_kzalloc()-ed data struct while leaving the queued work queued and the registered power_supply registered with both of them now pointing to free-ed memory, resulting in various kernel crashes soon afterwards. Instead properly tear-down things on IRQ handler register errors. Fixes: 703df6c09795 ("power: bq27xxx_battery: Reorganize I2C into a module") Cc: Andrew F. Davis <afd@ti.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Andy Shevchenko <andy.shevchenko@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-11-18power: supply: max17040: fix null-ptr-deref in max17040_probe()Yang Yingliang1-0/+2
[ Upstream commit 1d422ecfc48ee683ae1ccc9217764f6310c0ffce ] Add check the return value of devm_regmap_init_i2c(), otherwise later access may cause null-ptr-deref as follows: KASAN: null-ptr-deref in range [0x0000000000000360-0x0000000000000367] RIP: 0010:regmap_read+0x33/0x170 Call Trace: max17040_probe+0x61b/0xff0 [max17040_battery] ? write_comp_data+0x2a/0x90 ? max17040_set_property+0x1d0/0x1d0 [max17040_battery] ? tracer_hardirqs_on+0x33/0x520 ? __sanitizer_cov_trace_pc+0x1d/0x50 ? _raw_spin_unlock_irqrestore+0x4b/0x60 ? trace_hardirqs_on+0x63/0x2d0 ? write_comp_data+0x2a/0x90 ? __sanitizer_cov_trace_pc+0x1d/0x50 ? max17040_set_property+0x1d0/0x1d0 [max17040_battery] i2c_device_probe+0xa31/0xbe0 Fixes: 6455a8a84bdf ("power: supply: max17040: Use regmap i2c") Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-11-18power: supply: rt5033_battery: Change voltage values to µVJakob Hauser1-1/+1
[ Upstream commit bf895295e9a73411889816f1a0c1f4f1a2d9c678 ] Currently the rt5033_battery driver provides voltage values in mV. It should be µV as stated in Documentation/power/power_supply_class.rst. Fixes: b847dd96e659 ("power: rt5033_battery: Add RT5033 Fuel gauge device driver") Cc: Beomho Seo <beomho.seo@samsung.com> Cc: Chanwoo Choi <cw00.choi@samsung.com> Signed-off-by: Jakob Hauser <jahau@rocketmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-11-18power: reset: at91-reset: check properly the return value of devm_of_iomapClaudiu Beznea1-2/+2
[ Upstream commit f558c8072c3461b65c12c0068b108f78cebc8246 ] devm_of_iomap() returns error code or valid pointer. Check its return value with IS_ERR(). Fixes: bd3127733f2c ("power: reset: at91-reset: use devm_of_iomap") Reported-by: Cristian Birsan <cristian.birsan@microchip.com> Signed-off-by: Claudiu Beznea <claudiu.beznea@microchip.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Sasha Levin <sashal@kernel.org>
2021-11-18power: supply: max17042_battery: Clear status bits in interrupt handlerSebastian Krzyszkowiak1-0/+4
commit 0cf48167b87e388fa1268c9fe6d2443ae7f43d8a upstream. The gauge requires us to clear the status bits manually for some alerts to be properly dismissed. Previously the IRQ was configured to react only on falling edge, which wasn't technically correct (the ALRT line is active low), but it had a happy side-effect of preventing interrupt storms on uncleared alerts from happening. Fixes: 7fbf6b731bca ("power: supply: max17042: Do not enforce (incorrect) interrupt trigger type") Cc: <stable@vger.kernel.org> Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-18power: supply: max17042_battery: use VFSOC for capacity when no rsnsHenrik Grimler1-1/+4
commit 223a3b82834f036a62aa831f67cbf1f1d644c6e2 upstream. On Galaxy S3 (i9300/i9305), which has the max17047 fuel gauge and no current sense resistor (rsns), the RepSOC register does not provide an accurate state of charge value. The reported value is wrong, and does not change over time. VFSOC however, which uses the voltage fuel gauge to determine the state of charge, always shows an accurate value. For devices without current sense, VFSOC is already used for the soc-alert (0x0003 is written to MiscCFG register), so with this change the source of the alert and the PROP_CAPACITY value match. Fixes: 359ab9f5b154 ("power_supply: Add MAX17042 Fuel Gauge Driver") Cc: <stable@vger.kernel.org> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> Suggested-by: Wolfgang Wiedmeyer <wolfgit@wiedmeyer.de> Signed-off-by: Henrik Grimler <henrik@grimler.se> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-11-18power: supply: max17042_battery: Prevent int underflow in set_soc_thresholdSebastian Krzyszkowiak1-1/+2
commit e660dbb68c6b3f7b9eb8b9775846a44f9798b719 upstream. max17042_set_soc_threshold gets called with offset set to 1, which means that minimum threshold value would underflow once SOC got down to 0, causing invalid alerts from the gauge. Fixes: e5f3872d2044 ("max17042: Add support for signalling change in SOC") Cc: <stable@vger.kernel.org> Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm> Reviewed-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2021-08-30Merge tag 'for-v5.15' of ↵Linus Torvalds25-919/+2391
git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply Pull power supply and reset updates from Sebastian Reichel: "Battery/charger related: - cros-peripheral-charger: new driver - mt6360-charger: new driver - simple-battery: support reading chemistry info - max17042-battery: add max77849 support - sbs-battery: add time_to_empty_now support - smb347-charger: prepare USB OTG support - rn5t618: add voltage_now support - axp288: cleanup & optimizations - max17042_battery: cleanups - ab8500: cleanups - misc minor cleanups and DT binding fixes reset related: - tps65086-restart: new driver - linkstation-poweroff: support NETGEAR ReadyNAS Duo v2" * tag 'for-v5.15' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: (51 commits) power: supply: core: Fix parsing of battery chemistry/technology power: supply: max17042_battery: log SOC threshold using debug log level power: supply: max17042_battery: more robust chip type checks power: supply: max17042_battery: fix typo in MAx17042_TOFF power: supply: max17042_battery: clean up MAX17055_V_empty power: supply: smb347-charger: Implement USB VBUS regulator power: supply: smb347-charger: Add missing pin control activation power: supply: smb347-charger: Utilize generic regmap caching power: supply: smb347-charger: Make smb347_set_writable() IRQ-safe dt-bindings: power: supply: smb347-charger: Document USB VBUS regulator power: reset: Add TPS65086 restart driver dt-bindings: power: supply: max17042: describe interrupt power: supply: max17042: remove duplicated STATUS bit defines power: supply: max17042: handle fails of reading status register power: supply: core: Parse battery chemistry/technology dt-bindings: power: Extend battery bindings with chemistry power: reset: linkstation-poweroff: add new device power: reset: linkstation-poweroff: prepare for new devices power: supply: bq24735: reorganize ChargeOption command macros power: supply: rn5t618: Add voltage_now property ...
2021-08-20power: supply: core: Fix parsing of battery chemistry/technologyDmitry Osipenko1-2/+1
The power_supply_get_battery_info() fails if device-chemistry property is missing in a device-tree because error variable is propagated to the final return of the function, fix it. Fixes: 4eef766b7d4d ("power: supply: core: Parse battery chemistry/technology") Signed-off-by: Dmitry Osipenko <digetx@gmail.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-17power: supply: max17042_battery: log SOC threshold using debug log levelSebastian Krzyszkowiak1-1/+1
There's no need to print a message on every change in battery percentage on regular log levels. Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-17power: supply: max17042_battery: more robust chip type checksSebastian Krzyszkowiak1-19/+21
Prepared by checking the datasheets of max17042, max17047/50 and max170455 for differences in register maps. Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-17power: supply: max17042_battery: fix typo in MAx17042_TOFFSebastian Krzyszkowiak1-1/+1
Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-17power: supply: max17042_battery: clean up MAX17055_V_emptySebastian Krzyszkowiak1-4/+0
This register is same as in MAX17047 and MAX17050, so there's no need for custom casing it. Signed-off-by: Sebastian Krzyszkowiak <sebastian.krzyszkowiak@puri.sm> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-16power: supply: smb347-charger: Implement USB VBUS regulatorDmitry Osipenko2-0/+220
SMB347 can supply power to USB VBUS, implement the USB VBUS regulator. USB VBUS needs to be powered for switching OTG-cable USB port into host mode. Signed-off-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-16power: supply: smb347-charger: Add missing pin control activationDmitry Osipenko1-0/+10
Pin control needs to be activated by setting the enable bit, otherwise hardware rejects all pin changes. Previously this stayed unnoticed on Nexus 7 because pin control was enabled by default after rebooting from downstream kernel, which uses driver that enables the bit and charger registers are non-volatile until power supply (battery) is disconnected. Configure the pin control enable bit. This fixes the potentially never-enabled charging on devices that use pin control. Signed-off-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-16power: supply: smb347-charger: Utilize generic regmap cachingDmitry Osipenko1-12/+4
Utilize generic regmap caching in order to avoid unnecessary slow I2C accesses to all constant registers each time the supply status updated and remove local caching of charger state to make code cleaner. Signed-off-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-16power: supply: smb347-charger: Make smb347_set_writable() IRQ-safeDmitry Osipenko1-9/+21
The smb347_set_writable() is used by interrupt handler and outside of it. The interrupt should be disabled when the function is used outside of interrupt handler in order to prevent racing with the interrupt context. Add new parameter to smb347_set_writable() that allows to disable IRQ. Signed-off-by: Dmitry Osipenko <digetx@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-16power: reset: Add TPS65086 restart driverEmil Renner Berthing3-0/+105
The only way to reset the BeagleV Starlight v0.9 board[1] properly is to tell the PMIC to reset itself which will then assert the external reset lines of the SoC, USB hub and ethernet phy. This adds a driver to register a reset handler to do just that. [1] https://github.com/beagleboard/beaglev-starlight Signed-off-by: Emil Renner Berthing <kernel@esmil.dk> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-16power: supply: max17042: remove duplicated STATUS bit definesKrzysztof Kozlowski1-4/+1
All bits of STATUS register are already defined (see STATUS_SMN_BIT and further) so there is no need to define status SoC threshold min/max values one more time. Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-16power: supply: max17042: handle fails of reading status registerKrzysztof Kozlowski1-1/+5
Reading status register can fail in the interrupt handler. In such case, the regmap_read() will not store anything useful under passed 'val' variable and random stack value will be used to determine type of interrupt. Handle the regmap_read() failure to avoid handling interrupt type and triggering changed power supply event based on random stack value. Fixes: 39e7213edc4f ("max17042_battery: Support regmap to access device's registers") Cc: <stable@vger.kernel.org> Signed-off-by: Krzysztof Kozlowski <krzysztof.kozlowski@canonical.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-14power: supply: core: Parse battery chemistry/technologyLinus Walleij1-0/+20
This extends the struct power_supply_battery_info with a "technology" field makes the core DT parser optionally obtain this from the device tree. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-13power: reset: linkstation-poweroff: add new devicePawel Dembicki1-0/+42
This commit introduces support for NETGEAR ReadyNAS Duo v2. This device use bit 4 of LED[2:0] Polarity Control Register to indicate AC Power loss. For more details about AC loss detection in NETGEAR ReadyNAS Duo v2, please look at the file: RND_5.3.13_WW.src/u-boot/board/mv_feroceon/mv_hal/usibootup/usibootup.c from Netgear GPL sources. Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-13power: reset: linkstation-poweroff: prepare for new devicesPawel Dembicki1-6/+29
This commit prepare driver for another device support. New power_off_cfg structure describes two most important things: name of mdio bus and pointer to register setting function. It allow to add new device with different mdio bus node and other phy register config. Signed-off-by: Pawel Dembicki <paweldembicki@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-13Merge tag 'ib-mt6360-for-5.15-signed' into psy-nextSebastian Reichel3-0/+879
Immutable branch between regulator and power-supply for for 5.15 This immutable branch introduces the MT6360 charger driver, which requires a new linear range helper. Signed-off-by: Sebastian Reichel <sre@kernel.org>
2021-08-13power: supply: bq24735: reorganize ChargeOption command macrosBruno Meneguele1-12/+15
Rename ChargeOption macros to match the others for ChargeCurrent and ChargeVoltage and also separate the command & masks macros from the bits of interest macros for each command. This macro doesn't introduce any functional change, only code re-org. Signed-off-by: Bruno Meneguele <bruno.meneguele@smartgreen.net> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-13power: supply: rn5t618: Add voltage_now propertyAndreas Kemnade2-0/+40
Read voltage_now via IIO and provide the property. Signed-off-by: Andreas Kemnade <andreas@kemnade.info> Reported-by: kernel test robot <lkp@intel.com> # missing depends on IIO Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-13power: supply: mt6360_charger: add MT6360 charger supportGene Chen3-0/+879
Add basic support for the battery charger for MT6360 PMIC Signed-off-by: Gene Chen <gene_chen@richtek.com> Reviewed-by: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-13power: supply: ab8500: clean up warnings found by checkpatchColin Ian King1-14/+10
Clean up a handful of checkpatch warnings: - static const char * array should probably be static const char * const - function arguments should have identifier names - else should follow close brace '}' - suspect code indent for conditional statements - unnecessary parentheses in an if condition - avoid multiple line dereference - remove debug showing function execution, ftrace can trace these better - prefer 'long' over 'long int' as the int is unnecessary Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-13power: supply: axp288_charger: Use the defined variable to clean codeTang Bin1-6/+5
Use the defined variable "dev" to make the code cleaner. Co-developed-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com> Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com> Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-07power: supply: sbs-battery: add support for time_to_empty_now attributeMatthias Schiffer1-4/+10
As defined by the Smart Battery Data Specification. An _AVG suffix is added to the enum values REG_TIME_TO_EMPTY and REG_TIME_TO_FULL to make the distinction clear. Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-07power: supply: sbs-battery: relax voltage limitMatthias Schiffer1-1/+1
The Smart Battery Data Specification allows for values 0..65535 mV, there is no reason to limit the value to 20000. Signed-off-by: Matthias Schiffer <matthias.schiffer@ew.tq-group.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-07power: supply: qcom_smbb: Remove superfluous error messageTang Bin1-4/+1
In the probe function, when get irq failed, the function platform_get_irq_byname() logs an error message, so remove redundant message here. Co-developed-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com> Signed-off-by: Zhang Shengju <zhangshengju@cmss.chinamobile.com> Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-07power: supply: max17042_battery: Add support for MAX77849 Fuel-GaugeNikita Travkin1-0/+2
MAX77849 is a combined fuel-gauge, charger and MUIC IC. Notably, fuel-gauge has dedicated i2c lines and seems to be fully compatible with max17047. Add new compatible for it reusing max17047 code paths. Signed-off-by: Nikita Travkin <nikita@trvn.ru> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05power: supply: axp288_fuel_gauge: Take the P-Unit semaphore only once during ↵Hans de Goede1-7/+17
probe() The I2C-bus to the XPower AXP288 is shared between the Linux kernel and the SoCs P-Unit. The P-Unit has a semaphore which the kernel must "lock" before it may use the bus. If not explicitly taken by the I2C-driver, then this semaphore is automatically taken by the I2C-bus-driver for each I2C-transfer and this is a quite expensive operation. Explicitly take the semaphore in probe() around the register-accesses done during probe, so that this only needs to be done once, rather then once per register-access. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05power: supply: axp288_fuel_gauge: Move the AXP20X_CC_CTRL check together ↵Hans de Goede1-10/+12
with the other checks The I2C-bus to the XPower AXP288 is shared between the Linux kernel and the SoCs P-Unit. The P-Unit has a semaphore which the kernel must "lock" before it may use the bus. If not explicitly taken by the I2C-driver, then this semaphore is automatically taken by the I2C-bus-driver for each I2C-transfer. Move the AXP20X_CC_CTRL check done in probe() together with the other register-accesses done in probe, so that we can take the semaphore once for the entire set of register-accesses. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05power: supply: axp288_fuel_gauge: Refresh all registers in one goAndrejus Basovas2-97/+106
The I2C-bus to the XPower AXP288 is shared between the Linux kernel and the SoCs P-Unit. The P-Unit has a semaphore which the kernel must "lock" before it may use the bus and while the kernel holds the semaphore the CPU and GPU power-states must not be changed otherwise the system will freeze. This is a complex process, which is quite expensive. This is all done by iosf_mbi_block_punit_i2c_access(). To ensure that no unguarded I2C-bus accesses happen, iosf_mbi_block_punit_i2c_access() gets called by the I2C-bus-driver for every I2C transfer. Because this is so expensive it is allowed to call iosf_mbi_block_punit_i2c_access() in a nested fashion, so that higher-level code which does multiple I2C-transfers can call it once for a group of transfers, turning the calls done by the I2C-bus-driver into no-ops. Userspace power-supply API users typically will read all provided properties in one go, refreshing the last read values when power_supply_changed() is called by the driver and/or periodically (e.g. every 2 minutes). The reading of all properties in one go causes the P-Unit semaphore to quickly be taken and released multiple times in a row. Certain PMIC registers like AXP20X_FG_RES are even used in multiple properties so they get read multiple times, leading to a P-Unit take + release each time the register is read. As already mentioned the taking of the P-Unit semaphore is a quite expensive operation and it has also been reported that the "hammering" of the P-Unit semaphore done by the axp288_fuel_gauge driver can even cause stability issues with the system as a whole. Switch over to a scheme where the axp288_fuel_gauge driver keeps a local copy of all the registers which it uses for properties and make it only refresh its copy of the registers if the values are older then 1 minute; or when a fuel-gauge interrupt has triggered since the last read. This not only reduces the amount of reads, it also makes the code do all the reads in one go, rather then reading specific registers based on which property is being queried. This allows calling iosf_mbi_block_punit_i2c_access() once before doing all the reads, so that we now only take the P-Unit semaphore once per update. Tested-by: Andrejus Basovas <cpp@gcc.lt> Signed-off-by: Andrejus Basovas <cpp@gcc.lt> Co-developed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05power: supply: axp288_fuel_gauge: Only read PWR_OP_MODE, FG_LOW_CAP_REG regs ↵Hans de Goede1-16/+21
once Accessing registers on the AXP288 is quite expensive, so we should avoid doing unnecessary accesses. The FG_LOW_CAP_REG never changes underneath us, so we only need to read it once. Devices with an AXP288 do not have user-replace (let alone hot-swappable) batteries and the only bit we care about in the PWR_OP_MODE register is the CHRG_STAT_BAT_PRESENT bit, so we can get away with only reading the PWR_OP_MODE register once too. Note that the FG_LOW_CAP_REG is not marked volatile in the regmap, so we were effectively already reading it once. This change makes this explicit, this is done as preparation of a further patch which moves all remaining register accesses in fuel_gauge_get_property() out of that function. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05power: supply: axp288_fuel_gauge: Store struct device pointer in axp288_fg_infoHans de Goede1-35/+24
Directly store the struct device pointer in axp288_fg_info, rather then storing a pointer to the struct platform_device there and then using "&info->pdev->dev" everywhere. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05power: supply: axp288_fuel_gauge: Drop retry logic from fuel_gauge_reg_readb()Hans de Goede1-8/+2
The I2C-bus to the XPower AXP288 is shared between the Linux kernel and the SoCs P-Unit. The P-Unit has a semaphore which the kernel must "lock" before it may use the bus. This semaphore is automatically taken by the I2C-bus-driver. The retry on -EBUSY logic in fuel_gauge_reg_readb() likely was added to deal with the I2C-bus-drive returning -EBUSY when it failed to take the semaphore, but this really should never happen. The semaphore code even has a WARN_ON(ret) to log a kernel backtrace if this does somehow happen, when this happens something is seriously wrong and the system typically freezes soon afterwards. TL;DR: the regmap_read() should never fail with -EBUSY so the retries are unnecessary. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05power: supply: axp288_fuel_gauge: Report register-address on readb / writeb ↵Hans de Goede1-2/+2
errors When fuel_gauge_reg_readb()/_writeb() fails, report which register we were trying to read / write when the error happened. Also reword the message a bit: - Drop the axp288 prefix, dev_err() already prints this - Switch from telegram / abbreviated style to a normal sentence, aligning the message with those from fuel_gauge_read_*bit_word() Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05power: supply: axp288_fuel_gauge: Silence the chatty IRQ mapping codeHans de Goede1-3/+0
Drop the IRQ mapping messages, because they are really not interesting at all. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05power: supply: axp288_fuel_gauge: Remove debugfs supportHans de Goede1-123/+0
The debugfs code is simply just dumping a bunch of registers, the same information can also easily be gotten through the regmap debugfs interface or through the i2cdump utility. I've not used the debugfs interface once in all these years that I've been working on the axp288_fuel_gauge driver, so lets just remove it. Note this also removes the temperature-channels from the list of IIO ADC channels used by the driver, since these were only used in the debugfs interface. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05power: supply: axp288_fuel_gauge: Fix define alignmentHans de Goede1-19/+19
The values of various defines used in the driver are not aligned properly when tabsize is set to 8 (I guess they were created with a different tabsize). Properly align the defines to make the code easier to read. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-08-05power: supply: sc27xx: Delete superfluous error messageTang Bin1-3/+1
In the function sc27xx_fgu_probe(), when get irq failed, platform_get_irq() logs an error message, so remove redundant message here. Signed-off-by: Tang Bin <tangbin@cmss.chinamobile.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-07-16power: supply: cw2015: use dev_err_probe to allow deferred probePeter Robinson1-1/+3
Deal with deferred probe using dev_err_probe so the error is handled and avoid logging lots probe defer information like the following: [ 9.125121] cw2015 4-0062: Failed to register power supply [ 9.211131] cw2015 4-0062: Failed to register power supply Fixes: b4c7715c10c1 ("power: supply: add CellWise cw2015 fuel gauge driver") Signed-off-by: Peter Robinson <pbrobinson@gmail.com> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-07-16power: supply: PCHG: Peripheral device chargerDaisuke Nojiri3-0/+397
This patch adds a driver for PCHG (Peripheral CHarGer). PCHG is a framework managing power supplies for peripheral devices. This driver creates a sysfs node for each peripheral charge port: /sys/class/power_supply/peripheral<n> where <n> is the index of a charge port. For example, when a stylus is connected to a NFC/WLC port, the node returns: /sys/class/power_supply/peripheral0/ capacity=50 charge_type=Standard scope=Device status=Charging type=Battery Signed-off-by: Daisuke Nojiri <dnojiri@chromium.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>