summaryrefslogtreecommitdiffstats
path: root/drivers/power/supply/generic-adc-battery.c
Commit message (Collapse)AuthorAgeFilesLines
* power: supply: generic-adc-battery: style fixesSebastian Reichel2023-03-291-16/+10
| | | | | | | | | | | | | This does the following code-style changes: * fix inconsistent indentation in 'struct gab' * remove unused cable_plugged from 'struct gab' * remove pointless temporary is_plugged variable * add gab_ prefix to read_channel No functionality changes are intended. Signed-off-by: Sebastian Reichel <sre@kernel.org>
* power: supply: generic-adc-battery: improve error messageSebastian Reichel2023-03-291-1/+1
| | | | | | | | | Add device context and error code to the error messages to make it useful. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
* power: supply: generic-adc-battery: update copyright infoSebastian Reichel2023-03-291-8/+3
| | | | | | | | | | | | | jz4740-battery.c and s3c_adc_battery.c have been removed from the tree and after all of my restructuring the driver is basically no longer based on them. Thus update the copyright information and switch to SPDX license identifier while being at it. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
* power: supply: generic-adc-battery: add DT supportSebastian Reichel2023-03-291-0/+9
| | | | | | | | | This adds full DT support to the driver. Because of the previous changes just adding a compatible value is enough. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
* power: supply: generic-adc-battery: add temperature supportSebastian Reichel2023-03-291-1/+6
| | | | | | | | | Another typical thing to monitor via an ADC line is the battery temperature. Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
* power: supply: generic-adc-battery: simplify read_channel logicSebastian Reichel2023-03-291-30/+5
| | | | | | | | | Drop mostly useless gab_prop_to_chan() function by directly supplying the correct enum value to read_channel(). Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
* power: supply: generic-adc-battery: use simple-battery APISebastian Reichel2023-03-291-56/+4
| | | | | | | | | | | | | | | | | Constant battery data is available through power-supply's simple-battery API. This works automatically, so the manual handling can be removed without loosing any feature :) Note, that the POWER_SUPPLY_STATUS_FULL check for the level variable can be dropped, since the variable is never written. It can be re-introduced properly once the driver gets functionality to calculate the current charge level. Apart from that the check must be done fuzzy anyways, since charge estimation usually is not precise enough to always return exactly the full charge capacity for a full battery. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
* power: supply: generic-adc-battery: drop memory alloc error messageSebastian Reichel2023-03-291-3/+1
| | | | | | | | Error printing happens automatically for memory allocation problems. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
* power: supply: generic-adc-battery: drop charge now supportSebastian Reichel2023-03-291-4/+0
| | | | | | | | | Drop CHARGE_NOW support, which requires a platform specific calculation method. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
* power: supply: generic-adc-battery: drop jitter delay supportSebastian Reichel2023-03-291-9/+4
| | | | | | | | Drop support for configuring IRQ jitter delay by using big enough fixed value. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
* power: supply: generic-adc-battery: fix unit scalingSebastian Reichel2023-03-291-0/+3
| | | | | | | | | | | power-supply properties are reported in µV, µA and µW. The IIO API provides mV, mA, mW, so the values need to be multiplied by 1000. Fixes: e60fea794e6e ("power: battery: Generic battery driver using IIO") Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
* power: supply: generic-adc-battery: convert to managed resourcesSebastian Reichel2023-03-291-58/+23
| | | | | | | | Convert driver to use managed resources to simplify driver code. Reviewed-by: Linus Walleij <linus.walleij@linaro.org> Reviewed-by: Matti Vaittinen <mazziesaccount@gmail.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
* power: supply: generic-adc-battery: fix possible use-after-free in gab_remove()Yang Yingliang2021-04-081-1/+1
| | | | | | | | | | | | | | | This driver's remove path calls cancel_delayed_work(). However, that function does not wait until the work function finishes. This means that the callback function may still be 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 the work is properly cancelled, no longer running, and unable to re-schedule itself. Reported-by: Hulk Robot <hulkci@huawei.com> Signed-off-by: Yang Yingliang <yangyingliang@huawei.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
* power: supply: generic-adc-battery: Use GPIO descriptorsLinus Walleij2020-11-301-20/+11
| | | | | | | | | | | | | | | | This driver uses platform data to pass GPIO lines using the deprecated global GPIO numbers. There are no in-tree users of this platform data. Any out-of-tree or coming users of this driver can easily be migrated to use machine descriptor tables as described in Documentation/driver-api/gpio/board.rst section "platform data". Cc: Anish Kumar <anish198519851985@gmail.com> Cc: H. Nikolaus Schaller <hns@goldelico.com> Signed-off-by: Linus Walleij <linus.walleij@linaro.org> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
* power: supply: generic-adc-battery: Prepare for const propertiesSebastian Reichel2020-05-011-11/+11
| | | | | | | | This prepares the driver to work with the properties entry in power_supply_desc marked as const. Reviewed-by: Enric Balletbo i Serra <enric.balletbo@collabora.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.com>
* power: generic-adc-battery: check for duplicate properties copied from iio ↵H. Nikolaus Schaller2018-07-061-2/+13
| | | | | | | | | | | | | | | channels If an iio channel defines a basic property, there are duplicate entries in /sys/class/power/*/uevent. So add a check to avoid duplicates. Since all channels may be duplicates, we have to modify the related error check. Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com> Cc: stable@vger.kernel.org Fixes: e60fea794e6e ("power: battery: Generic battery driver using IIO") Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
* power: generic-adc-battery: fix out-of-bounds write when copying channel ↵H. Nikolaus Schaller2018-07-061-10/+4
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | properties We did have sporadic problems in the pinctrl framework during boot where a pin group name unexpectedly became NULL leading to a NULL dereference in strcmp. Detailled analysis of the failing cases did reveal that there were two devm allocated objects close to each other. The second one was the affected group_desc in pinmux and the first one was the psy_desc->properties buffer of the gab driver. Review of the gab code showed that the address calculation for one memcpy() is wrong. It does properties + sizeof(type) * index but C is defined to do the index multiplication already for pointer + integer additions. Hence the factor was applied twice and the memcpy() does write outside of the properties buffer. Sometimes it happened to be the pinctrl and triggered the strcmp(NULL). Anyways, it is overkill to use a memcpy() here instead of a simple assignment, which is easier to read and has less risk for wrong address calculations. So we change code to a simple assignment. If we initialize the index to the first free location, we can even remove the local variable 'properties'. This bug seems to exist right from the beginning in 3.7-rc1 in commit e60fea794e6e ("power: battery: Generic battery driver using IIO") Signed-off-by: H. Nikolaus Schaller <hns@goldelico.com> Cc: stable@vger.kernel.org Fixes: e60fea794e6e ("power: battery: Generic battery driver using IIO") Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
* power: supply: generic-adc-battery: remove redundant variable pdataColin Ian King2017-11-061-2/+0
| | | | | | | | | | | Pointer pdata is assigned but never used, so remove it. Cleans up the clang warning: drivers/power/supply/generic-adc-battery.c:211:2: warning: Value stored to 'pdata' is never read Signed-off-by: Colin Ian King <colin.king@canonical.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
* power: supply: generic-adc-battery: use SIMPLE_DEV_PM_OPS helper macroRahul Bedarkar2017-05-011-13/+4
| | | | | | | Replace ifdefs with SIMPLE_DEV_PM_OPS helper macro. Signed-off-by: Rahul Bedarkar <rahulbedarkar89@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
* power: move power supply drivers to power/supplySebastian Reichel2016-08-111-0/+432
This moves all power supply drivers from drivers/power/ to drivers/power/supply/. The intention is a cleaner source tree, since drivers/power/ also contains frameworks unrelated to power supply, like adaptive voltage scaling. Signed-off-by: Sebastian Reichel <sre@kernel.org>