summaryrefslogtreecommitdiffstats
path: root/drivers/power/supply/bq24190_charger.c
AgeCommit message (Collapse)AuthorFilesLines
2022-11-20power: supply: bq24190: Convert to i2c's .probe_new()Uwe Kleine-König1-3/+3
.probe_new() doesn't get the i2c_device_id * parameter, so determine that explicitly in the probe function. Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-08-16i2c: Make remove callback return voidUwe Kleine-König1-3/+1
The value returned by an i2c driver's remove function is mostly ignored. (Only an error message is printed if the value is non-zero that the error is ignored.) So change the prototype of the remove function to return no value. This way driver authors are not tempted to assume that passing an error to the upper layer is a good idea. All drivers are adapted accordingly. There is no intended change of behaviour, all callbacks were prepared to return 0 before. Reviewed-by: Peter Senna Tschudin <peter.senna@gmail.com> Reviewed-by: Jeremy Kerr <jk@codeconstruct.com.au> Reviewed-by: Benjamin Mugnier <benjamin.mugnier@foss.st.com> Reviewed-by: Javier Martinez Canillas <javierm@redhat.com> Reviewed-by: Crt Mori <cmo@melexis.com> Reviewed-by: Heikki Krogerus <heikki.krogerus@linux.intel.com> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Acked-by: Marek Behún <kabel@kernel.org> # for leds-turris-omnia Acked-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Reviewed-by: Petr Machata <petrm@nvidia.com> # for mlxsw Reviewed-by: Maximilian Luz <luzmaximilian@gmail.com> # for surface3_power Acked-by: Srinivas Pandruvada <srinivas.pandruvada@linux.intel.com> # for bmc150-accel-i2c + kxcjk-1013 Reviewed-by: Hans Verkuil <hverkuil-cisco@xs4all.nl> # for media/* + staging/media/* Acked-by: Miguel Ojeda <ojeda@kernel.org> # for auxdisplay/ht16k33 + auxdisplay/lcd2s Reviewed-by: Luca Ceresoli <luca.ceresoli@bootlin.com> # for versaclock5 Reviewed-by: Ajay Gupta <ajayg@nvidia.com> # for ucsi_ccg Acked-by: Jonathan Cameron <Jonathan.Cameron@huawei.com> # for iio Acked-by: Peter Rosin <peda@axentia.se> # for i2c-mux-*, max9860 Acked-by: Adrien Grassein <adrien.grassein@gmail.com> # for lontium-lt8912b Reviewed-by: Jean Delvare <jdelvare@suse.de> # for hwmon, i2c-core and i2c/muxes Acked-by: Corey Minyard <cminyard@mvista.com> # for IPMI Reviewed-by: Vladimir Oltean <olteanv@gmail.com> Acked-by: Dmitry Torokhov <dmitry.torokhov@gmail.com> Acked-by: Sebastian Reichel <sebastian.reichel@collabora.com> # for drivers/power Acked-by: Krzysztof Hałasa <khalasa@piap.pl> Signed-off-by: Uwe Kleine-König <u.kleine-koenig@pengutronix.de> Signed-off-by: Wolfram Sang <wsa@kernel.org>
2022-05-04power: supply: bq24190_charger: using pm_runtime_resume_and_get instead of ↵Minghao Chi1-42/+21
pm_runtime_get_sync Using pm_runtime_resume_and_get is more appropriate for simplifing code Reported-by: Zeal Robot <zealci@zte.com.cn> Signed-off-by: Minghao Chi <chi.minghao@zte.com.cn> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-25power: supply: bq24190_charger: Delay applying charge_type changes when OTG ↵Hans de Goede1-11/+30
5V Vbus boost is on Recently userspace has started switching power_supply class devices with a charge_type psy-property between fast and trickle charge mode, see: https://gitlab.freedesktop.org/hadess/power-profiles-daemon/-/issues/85 Before this patch bq24190_charger_set_charge_type() would unconditionally write charging or none to the BQ24190_REG_POC_CHG_CONFIG bits, replacing the otg setting of those bits when the OTG 5V Vbus boost converter was on, turning the 5V Vbus off, removing the power from any attached peripherals. This fixes this by keeping track of otg_vbus_enabled and the requested charger_type settings and when otg_vbus_enabled is true, delay applying the charger_type until the 5V boost converter is turned off. Cc: Bastien Nocera <hadess@hadess.net> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-25power: supply: bq24190_charger: Fix bq24190_vbus_is_enabled() wrong false returnHans de Goede1-1/+6
The datasheet says that the BQ24190_REG_POC_CHG_CONFIG bits can have a value of either 10(0x2) or 11(0x3) for OTG (5V boost regulator) mode. Sofar bq24190_vbus_is_enabled() was only checking for 10 but some BIOS-es uses 11 when enabling the regulator at boot. Make bq24190_vbus_is_enabled() also check for 11 so that it does not wrongly returns false when the bits are set to 11. Fixes: 66b6bef2c4e0 ("power: supply: bq24190_charger: Export 5V boost converter as regulator") Cc: Bastien Nocera <hadess@hadess.net> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11power: supply: bq24190_charger: Disallow ccc_ireg and cvc_vreg to be higher ↵Hans de Goede1-2/+8
then the fwnode values If the fwnode data as parsed by power_supply_get_battery_info() provides max values for ccc_ireg and cvc_vreg then do not allow the user to later set these to higher values then those specified by the firmware, otherwise the battery might get damaged. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11power: supply: bq24190_charger: Program charger with fwnode supplied ↵Hans de Goede1-2/+49
ccc_ireg and cvc_vreg So far the bq24190_charger driver has been relying on either the chips default constant_charge_current_max_ua and constant_charge_voltage_max_uv values, or on the BIOS or bootloader to program these for us. This does not happen on all boards, causing e.g. the wrong (too low) values to be used on Lenovo Yoga Tablet 2 830F/L and 1050F/L tablets. If power_supply_get_battery_info() provides us with values for these settings, then program the charger accordingly. And if the user later overrides these values then save the user-values so that these will be restored after a suspend/resume. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11power: supply: bq24190_charger: Store ichg-max and vreg-max in bq24190_dev_infoHans de Goede1-21/+13
Store ichg-max and vreg-max in bq24190_dev_info once from bq24190_get_config() and drop the bq24190_charger_get_current_max() and bq24190_charger_get_voltage_max() helpers. This is a preparation patch for honoring the constant_charge_current_max_ua and constant_charge_voltage_max_uv values from power_supply_get_battery_info(). Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11power: supply: bq24190_charger: Always call power_supply_get_battery_info()Hans de Goede1-2/+1
power_supply_get_battery_info() now also supports getting battery_info on boards not using dt/of. Remove the of_node check. If neither of nor other battery-info is present the function will fail making this change a no-op in that case. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-11power: supply: bq24190_charger: Turn off 5V boost regulator on shutdownHans de Goede1-5/+15
Turn off the 5V boost regulator on shutdown, there are 3 reasons for doing this: 1. It drains he battery if left on 2. If left on the device will not charge when plugged into a charger 3. If left on and the powered peripheral attached to a Type-C port is removed before the next boot, then the Type-C port-controller will see VBus being present while nothing is attached confusing the TCPM state-machine. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-02-01power: supply: core: Refactor ↵Hans de Goede1-1/+11
power_supply_set_input_current_limit_from_supplier() Some (USB) charger ICs have variants with USB D+ and D- pins to do their own builtin charger-type detection, like e.g. the bq24190 and bq25890 and also variants which lack this functionality, e.g. the bq24192 and bq25892. In case the charger-type; and thus the input-current-limit detection is done outside the charger IC then we need some way to communicate this to the charger IC. In the past extcon was used for this, but if the external detection does e.g. full USB PD negotiation then the extcon cable-types do not convey enough information. For these setups it was decided to model the external charging "brick" and the parameters negotiated with it as a power_supply class-device itself; and power_supply_set_input_current_limit_from_supplier() was introduced to allow drivers to get the input-current-limit this way. But in some cases psy drivers may want to know other properties, e.g. the bq25892 can do "quick-charge" negotiation by pulsing its current draw, but this should only be done if the usb_type psy-property of its supplier is set to DCP (and device-properties indicate the board allows higher voltages). Instead of adding extra helper functions for each property which a psy-driver wants to query from its supplier, refactor power_supply_set_input_current_limit_from_supplier() into a more generic power_supply_get_property_from_supplier() function. Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2022-01-03power: supply_core: Pass pointer to battery infoLinus Walleij1-3/+3
The function to retrieve battery info (from the device tree) assumes we have a static info struct that gets populated by calling into power_supply_get_battery_info(). This is awkward since I want to support tables of static battery info by just assigning a pointer to all info based on e.g. a compatible value in the device tree. We also have a mixture of static and dynamically allocated variables here. Bite the bullet and let power_supply_get_battery_info() allocate also the memory used for the very top level struct power_supply_battery_info container. Pass pointers around and lifecycle this with the psy device just like the stuff we allocate inside it. Change all current users over. As part of the change, initializers need to be added to some previously uninitialized fields in struct power_supply_battery_info. Reviewed-By: Matti Vaittinen <matti.vaittinen@fi.rohmeurope.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-06-30power: supply: bq24190_charger: drop of_match_ptr() from device ID tableAndy Shevchenko1-9/+2
The driver can match only via the DT table so the table should be always used and the of_match_ptr() does not have any sense (this also allows ACPI matching via PRP0001, even though it might be not relevant here). This fixes compile warning (!CONFIG_OF): drivers/power/supply/bq24190_charger.c:1972:34: warning: ‘bq24190_of_match’ defined but not used [-Wunused-const-variable=] Signed-off-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2021-01-16power: supply: bq24190_charger: convert comma to semicolonZheng Yongjun1-1/+1
Replace a comma between expression statements by a semicolon. Signed-off-by: Zheng Yongjun <zhengyongjun3@huawei.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-11-30power: supply: bq24190_charger: Drop unused includeLinus Walleij1-1/+0
The driver includes <linux/gpio.h> but fails to use any symbols from the file. Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-11-30power: supply: bq24190_charger: fix reference leakZhang Qilong1-5/+15
pm_runtime_get_sync will increment pm usage counter even it failed. Forgetting to call pm_runtime_put_noidle will result in reference leak in callers(bq24190_sysfs_show, bq24190_charger_get_property, bq24190_charger_set_property, bq24190_battery_get_property, bq24190_battery_set_property), so we should fix it. Fixes: f385e6e2a1532 ("power: bq24190_charger: Use PM runtime autosuspend") Signed-off-by: Zhang Qilong <zhangqilong3@huawei.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-06-19power: supply: bq24190_charger: Fix runtime PM imbalance on errorDinghao Liu1-1/+3
pm_runtime_get_sync() increments the runtime PM usage counter even it returns an error code. Thus a pairing decrement is needed on the error handling path to keep the counter balanced. Signed-off-by: Dinghao Liu <dinghao.liu@zju.edu.cn> Reviewed-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2020-05-12power: supply: bq24190_charger: convert to use i2c_new_client_device()Wolfram Sang1-1/+1
Move away from the deprecated API in this comment. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-07-15Merge tag 'for-v5.3' of ↵Linus Torvalds1-1/+1
git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply Pull power supply and reset updates from Sebastian Reichel: "Core: - add HWMON compat layer - new properties: - input power limit - input voltage limit Drivers: - qcom-pon: add gen2 support - new driver for storing reboot move in NVMEM - new driver for Wilco EC charger configuration - simplify getting the adapter of a client" * tag 'for-v5.3' of git://git.kernel.org/pub/scm/linux/kernel/git/sre/linux-power-supply: power: reset: nvmem-reboot-mode: add CONFIG_OF dependency power_supply: wilco_ec: Add charging config driver power: supply: cros: allow to set input voltage and current limit power: supply: add input power and voltage limit properties power: supply: fix semicolon.cocci warnings power: reset: nvmem-reboot-mode: use NVMEM as reboot mode write interface dt-bindings: power: reset: add document for NVMEM based reboot-mode reset: qcom-pon: Add support for gen2 pon dt-bindings: power: reset: qcom: Add qcom,pm8998-pon compatibility line power: supply: Add HWMON compatibility layer power: supply: sbs-manager: simplify getting the adapter of a client power: supply: rt9455_charger: simplify getting the adapter of a client power: supply: rt5033_battery: simplify getting the adapter of a client power: supply: max17042_battery: simplify getting the adapter of a client power: supply: max17040_battery: simplify getting the adapter of a client power: supply: max14656_charger_detector: simplify getting the adapter of a client power: supply: bq25890_charger: simplify getting the adapter of a client power: supply: bq24257_charger: simplify getting the adapter of a client power: supply: bq24190_charger: simplify getting the adapter of a client
2019-06-23power: supply: bq24190_charger: simplify getting the adapter of a clientWolfram Sang1-1/+1
We have a dedicated pointer for that, so use it. Much easier to read and less computation involved. Signed-off-by: Wolfram Sang <wsa+renesas@sang-engineering.com> Reviewed-by: Simon Horman <horms+renesas@verge.net.au> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2019-06-19treewide: Replace GPLv2 boilerplate/reference with SPDX - rule 500Thomas Gleixner1-4/+1
Based on 2 normalized pattern(s): this program is free software you can redistribute it and or modify it under the terms of the gnu general public license version 2 as published by the free software foundation this program is free software you can redistribute it and or modify it under the terms of the gnu general public license version 2 as published by the free software foundation # extracted by the scancode license scanner the SPDX license identifier GPL-2.0-only has been chosen to replace the boilerplate/reference in 4122 file(s). Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Reviewed-by: Enrico Weigelt <info@metux.net> Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Reviewed-by: Allison Randal <allison@lohutok.net> Cc: linux-spdx@vger.kernel.org Link: https://lkml.kernel.org/r/20190604081206.933168790@linutronix.de Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-12-13power: supply: bq24190_charger: fix race-condition in sysfs registrationSebastian Reichel1-35/+8
This registers custom sysfs properties using the native functionality of the power-supply framework, which cleans up the code a bit and fixes a race-condition. Before this patch the sysfs attributes were not properly registered to udev. Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2018-12-05power: supply: bq24190_charger: add support for bq24196 variantHeiko Stuebner1-1/+3
The bq24196 is another variant of the bq24190 charger ic. Its register set is identical to the bq24192 and it even reuses the same part number (0x5). Signed-off-by: Heiko Stuebner <heiko.stuebner@bq.com> Reviewed-by: Rob Herring <robh@kernel.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2018-12-05power: supply: bq24190_charger: add extcon support for USB OTGBrian Masney1-1/+36
Add extcon support so that we can notify USB drivers of cable state changes. Based on work from Jonathan Marek. USB OTG was tested on a LG Nexus 5 (hammerhead) phone. Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2018-12-05power: supply: bq24190_charger: add of_match for usb-otg-vbus regulatorJonathan Marek1-0/+1
This patch adds an of_match for the usb-otg-vbus regulator to bq24190_charger. Signed-off-by: Jonathan Marek <jonathan@marek.ca> Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2018-12-05power: supply: bq24190_charger: add support for bq24192 variantJonathan Marek1-2/+8
This patch adds support for the bq24192 variant to bq24190_charger. Signed-off-by: Jonathan Marek <jonathan@marek.ca> [masneyb@onstation.org: Changed if statement to a switch based on feedback from Sebastian Reichel.] Signed-off-by: Brian Masney <masneyb@onstation.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
2018-01-08bq24190: Simplify code in property_is_writeablePavel Machek1-7/+2
Simplify function that should be trivial. Signed-off-by: Pavel machek <pavel@ucw.cz> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-12-01power: supply: bq24190_charger: Remove extcon handlingHans de Goede1-107/+10
Now that drivers/i2c/busses/i2c-cht-wc.c uses "input-current-limit-from-supplier" instead of "extcon-name" the last user of the bq24190 extcon code is gone, remove it. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-08-30power: supply: bq24190_charger: Get input_current_limit from our supplierHans de Goede1-0/+30
On some devices the USB Type-C port power (USB PD 2.0) negotiation is done by a separate port-controller IC, while the current limit is controlled through another (charger) IC. It has been decided to model this by modelling the external Type-C power brick (adapter/charger) as a power-supply class device which supplies the charger-IC, with its voltage-now and current-max representing the negotiated voltage and max current draw. This commit adds support for this to the bq24190_charger driver by adding an external_power_changed callback and calling power_supply_set_input_current_limit_from_supplier from this callback. This callback will only get called if the bq24190 has a parent-supply. Note this replaces the functionality to get the current-limit from an extcon device, which will be removed in a follow-up commit. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-08-30power: supply: bq24190_charger: Export 5V boost converter as regulatorHans de Goede1-0/+112
Register the 5V boost converter as a regulator named "usb_otg_vbus". This commit also adds support for bq24190_platform_data, through which non device-tree platforms can pass the regulator_init_data (containing mappings for the consumer amongst other things). Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-08-29power: supply: bq24190_charger: Add power_supply_battery_info supportLiam Breck1-0/+87
Set pre-charge and charge-term current, obtained from power_supply_battery_info. Add sysfs attributes precharge_current & charge_term_current. Cc: Hans de Goede <hdegoede@redhat.com> Acked-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Liam Breck <kernel@networkimprov.net> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-08-29power: supply: bq24190_charger: Add property system-minimum-microvoltLiam Breck1-0/+25
Set minimum system voltage limit obtained from device property. Cc: Hans de Goede <hdegoede@redhat.com> Acked-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Liam Breck <kernel@networkimprov.net> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-08-29power: supply: bq24190_charger: Enable devicetree configLiam Breck1-20/+36
Add get_config(). Rename set_mode_host() to set_config(). Call get_config() and hw_init() after power_supply_register(). No functional changes. Cc: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Liam Breck <kernel@networkimprov.net> Acked-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-08-29power: supply: bq24190_charger: Add ti,bq24192i to devicetree tableLiam Breck1-0/+1
bq24192i was previously only in ID table, so add it to DT table. Cc: Tony Lindgren <tony@atomide.com> Cc: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Liam Breck <kernel@networkimprov.net> Acked-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-08-29power: supply: bq24190_charger: Add input_current_limit propertyHans de Goede1-0/+35
Export the input current limit of the charger as a POWER_SUPPLY_PROP_INPUT_CURRENT_LIMIT property on the charger power_supply class device. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-05-01power: supply: bq24190_charger: Deprecate battery class and replicate its ↵Liam Breck1-35/+111
features in charger The driver was registering two classes, bq24190-battery & -charger. Because the power supply framework cannot surface features from multiple drivers in a single class, a fuel gauge driver would create a third class, which some power management utilities cannot see. Deprecate the -battery class for future removal and replicate its features in -charger. Set /sys/class...-charger/online = pg_stat && !batfet_disable. If device_property "omit-battery-class" is set, don't register -battery. Cc: Tony Lindgren <tony@atomide.com> Cc: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Liam Breck <kernel@networkimprov.net> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-05-01power: supply: bq24190_charger: Add disable-reset device-propertyHans de Goede1-0/+3
Allow platform-code to disable the reset on probe and suspend/resume by setting a "disable-reset" boolean device property on the device. There are several reasons why the platform-code may want to disable the reset on probe and suspend/resume: 1) Resetting the charger should never be necessary it should always have sane values programmed. If it is running with invalid values while we are not running (system turned off or suspended) there is a big problem as that may lead to overcharging the battery. 2) The reset in suspend() is meant to put the charger back into default mode, but this is not necessary and not a good idea. If the charger has been programmed with a higher max charge_current / charge_voltage then putting it back in default-mode will reset those to the safe power-on defaults, leading to slower charging, or charging to a lower voltage (and thus not using the full capacity) while suspended which is undesirable. Reprogramming the max charge_current / charge_voltage after the reset will not help here as that will put the charger back in host mode and start the i2c watchdog if the host then does not do anything for 40s (iow if we're suspended for more then 40s) the watchdog expires resetting the device to default-mode, including resetting all the registers to there safe power-on defaults. So the only way to keep using custom charge settings while suspending is to keep the charger in its normal running state with the i2c watchdog disabled. This is fine as the charger will still automatically switch from constant current to constant voltage and stop charging when the battery is full. 3) Besides never being necessary resetting the charger also causes problems on systems where the charge voltage limit is set higher then the reset value, if this is the case and the charger is reset while charging and the battery voltage is between the 2 voltages, then about half the time the charger gets confused and claims to be charging (REG08 contains 0x64) but in reality the charger has decoupled itself from VBUS (Q1 off) and is drawing 0A from VBUS, leaving the system running from the battery. This last problem is happening on a GPD-win mini PC with a bq24292i charger chip combined with a max17047 fuel-gauge and a LiHV battery. I've checked and TI does not list any errata for the bq24292i which could explain this (there are no errata at all). Cc: Liam Breck <kernel@networkimprov.net> Cc: Tony Lindgren <tony@atomide.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Liam Breck <kernel@networkimprov.net> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-04-14power: supply: bq24190_charger: Use new extcon_register_notifier_all()Hans de Goede1-2/+2
When I submitted the extcon handling I had a patch pending for the extcon sub-system for extcon_register_notifier to take -1 as cable id for listening for all type cable events on an extcon with a single notifier. In the end it was decided to instead add a new extcon_register_notifier_all function for this, switch to using this. Signed-off-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Liam Breck <kernel@networkimprov.net> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2017-04-14power: supply: bq24190_charger: Longer delay while polling reset flagLiam Breck1-7/+4
On chip reset, polling loop used udelay(10) which is too short to be useful. Instead, use usleep_range(100, 200). Signed-off-by: Liam Breck <kernel@networkimprov.net> Acked-by: Tony Lindgren <tony@atomide.com> Acked-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2017-04-14power: supply: bq24190_charger: Uniform pm_runtime_get() failure handlingLiam Breck1-18/+19
On pm_runtime_get() failure, always emit an error message. Prevent unbalanced pm_runtime_get by calling: pm_runtime_put_noidle() in irq handler pm_runtime_put_sync() on any probe() failure Rename probe() out labels instead of renumbering them. Fixes: 13d6fa8447fa ("power: bq24190_charger: Use PM runtime autosuspend") Signed-off-by: Liam Breck <kernel@networkimprov.net> Acked-by: Tony Lindgren <tony@atomide.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Acked-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2017-04-14power: supply: bq24190_charger: Clean up extcon codeLiam Breck1-38/+46
Polishing and fixes for initial extcon patch. Fixes: 4db249b6f3b4 ("power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boost") Cc: Tony Lindgren <tony@atomide.com> Signed-off-by: Liam Breck <kernel@networkimprov.net> Acked-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2017-04-14power: supply: bq24190_charger: Limit over/under voltage fault loggingLiam Breck1-1/+6
If the charger is unplugged before the battery is full we may see an over/under voltage fault. Ignore this rather then emitting a message or uevent. This fixes messages like these getting logged on charger unplug + replug: bq24190-charger 15-006b: Fault: boost 0, charge 1, battery 0, ntc 0 bq24190-charger 15-006b: Fault: boost 0, charge 0, battery 0, ntc 0 Cc: Tony Lindgren <tony@atomide.com> Cc: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Liam Breck <kernel@networkimprov.net> Acked-by: Tony Lindgren <tony@atomide.com> Reviewed-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2017-04-14power: supply: bq24190_charger: Use extcon to determine ilimit, 5v boostHans de Goede1-0/+109
Add support for monitoring an extcon device with USB SDP/CDP/DCP and HOST cables and adjust ilimit and enable/disable the 5V boost converter accordingly. This is necessary on systems where the PSEL pin is hardwired high and ILIM needs to be set by software based on the detected charger type, as well as on systems where the 5V boost converter is used, as that always needs to be enabled from software. Cc: Liam Breck <kernel@networkimprov.net> Cc: Tony Lindgren <tony@atomide.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2017-04-14power: supply: bq24190_charger: Add support for bq24192iHans de Goede1-9/+6
The bq24192 and bq24192i are mostly identical to the bq24190, TI even published a single datasheet for all 3 of them. The difference between the bq24190 and bq24192[i] is the way charger-type detection is done, the bq24190 is to be directly connected to the USB a/b lines, where as the the bq24192[i] has a gpio which should be driven high/low externally depending on the type of charger connected, from a register level access pov there is no difference. The differences between the bq24192 and bq24192i are: 1) Lower default charge rate on the bq24192i 2) Pre-charge-current can be max 640 mA on the bq24192i On x86/ACPI systems the code which instantiates the i2c client may not know the exact variant being used, so instead of coding the model-id in the i2c_id struct and bailing if it does not match, check the reported model-id matches one of the supported variants. This commit only adds support for the bq24192i as I don't have a bq24192 to test with, adding support for the bq24192 should be as simple as also accepting its model-id in the model-id test. Cc: Liam Breck <kernel@networkimprov.net> Cc: Tony Lindgren <tony@atomide.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2017-04-14power: supply: bq24190_charger: Use i2c-core irq-mapping codeHans de Goede1-63/+3
The i2c-core already maps of irqs before calling the driver's probe function and there are no in tree users of bq24190_platform_data->gpio_int. Remove the redundant custom irq-mapping code and just use client->irq. Cc: Liam Breck <kernel@networkimprov.net> Cc: Tony Lindgren <tony@atomide.com> Signed-off-by: Hans de Goede <hdegoede@redhat.com> Reviewed-by: Andy Shevchenko <andriy.shevchenko@linux.intel.com> Acked-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2017-04-14power: bq24190_charger: mark PM functions as __maybe_unusedArnd Bergmann1-6/+4
Without CONFIG_PM, we get a harmless warning: drivers/power/supply/bq24190_charger.c:1514:12: error: 'bq24190_runtime_resume' defined but not used [-Werror=unused-function] drivers/power/supply/bq24190_charger.c:1501:12: error: 'bq24190_runtime_suspend' defined but not used [-Werror=unused-function] To avoid the warning, we can mark all four PM functions as __maybe_unused, which also lets us remove the incorrect #ifdef. Fixes: 3d8090cba638 ("power: bq24190_charger: Check the interrupt status on resume") Signed-off-by: Arnd Bergmann <arnd@arndb.de> Acked-by: Tony Lindgren <tony@atomide.com> Acked-by: Liam Breck <kernel@networkimprov.net> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2017-04-14power: bq24190_charger: Use PM runtime autosuspendTony Lindgren1-42/+114
We can get quite a few interrupts when the battery is trickle charging. Let's enable PM runtime autosuspend to avoid constantly toggling device driver PM runtime state. Let's use a 600 ms timeout as that's how long the USB chager detection might take. Acked-by: Mark Greer <mgreer@animalcreek.com> Acked-by: Liam Breck <kernel@networkimprov.net> Signed-off-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2017-04-14power: bq24190_charger: Check the interrupt status on resumeTony Lindgren1-10/+52
Some SoCs like omap3 can configure GPIO irqs to use Linux generic dedicated wakeirq support. If the dedicated wakeirq is configured, the SoC will use a always-on interrupt controller to produce wake-up events. If bq24190 is configured for dedicated wakeirq, we need to check the interrupt status on PM runtime resume. This is because the Linux generic wakeirq will call pm_runtime_resume() on the device on a wakeirq. And as the bq24190 interrupt is falling edge sensitive and only active for 250 us, there will be no device interrupt seen by the runtime SoC IRQ controller. Note that this can cause spurious interrupts on omap3 devices with bq24190 connected to gpio banks 2 - 5 as there's a glitch on those pins waking from off mode as listed in "Advisory 1.45". Devices with this issue should not configure the optional wakeirq interrupt in the dts file. Acked-by: Mark Greer <mgreer@animalcreek.com> Acked-by: Liam Breck <kernel@networkimprov.net> Signed-off-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2017-01-20power: supply: bq24190_charger: Adjust formattingLiam Breck1-1/+3
Add breathing room in probe() out* section. Signed-off-by: Liam Breck <kernel@networkimprov.net> Acked-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2017-01-20power: supply: bq24190_charger: Handle fault before status on interruptLiam Breck1-23/+23
Reading both fault and status registers and logging any fault should take priority over handling status register update. Fix by moving the status handling to later in interrupt routine. Fixes: d7bf353fd0aa3 ("bq24190_charger: Add support for TI BQ24190 Battery Charger") Signed-off-by: Liam Breck <kernel@networkimprov.net> Acked-by: Mark Greer <mgreer@animalcreek.com> Acked-by: Tony Lindgren <tony@atomide.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>