summaryrefslogtreecommitdiff
path: root/drivers/power/supply/sbs-battery.c
AgeCommit message (Collapse)AuthorFilesLines
2017-05-01power: supply: sbs-battery: Add alert callbackPhil Reid1-3/+13
To simplify the sbs-manager code and notification of battery removal use the i2c alert callback to notify the sbs-battery driver that an event has occurred. Signed-off-by: Phil Reid <preid@electromag.com.au> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-05-01power: supply: sbs-battery: Correct supply status with current drawPaul Kocialkowski1-0/+29
The status reported directly by the battery controller is not always reliable and should be corrected based on the current draw information. This implements such a correction with a dedicated function, called where the supply status is retrieved. Signed-off-by: Paul Kocialkowski <contact@paulk.fr> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-05-01power: supply: sbs-battery: Don't ignore the first external power changePaul Kocialkowski1-10/+0
A mechanism to ignore the first external power change notification was put in place years ago to ignore the power_supply_register notification. However, this doesn't apply to the current situation anymore, as the first notification is always the result of a legitimate power change. This removes this deprecated mechanism, which puts back the driver's state machine to a sane state (an ignored first notification previously caused a charging/discharging status inversion). Signed-off-by: Paul Kocialkowski <contact@paulk.fr> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2017-05-01power: supply: sbs-battery: fix the sbs interrupt requestRyosuke Saito1-1/+1
Since we use the default primary handler for the irq, IRQF_ONESHOT must be set. Otherwise the request fails and the following errors are displayed: genirq: Threaded irq requested with handler=NULL and !ONESHOT for irq 129 sbs-battery 0-000b: Failed to request irq: -22 Signed-off-by: Ryosuke Saito <raitosyo@gmail.com> Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
2016-09-21power: supply: sbs-battery: Cleanup removal of chip->pdataPhil Reid1-13/+9
There where still a few lingering references to pdata after commit power: supply: sbs-battery: simplify DT parsing. Remove pdata from struct·sbs_info and conditional checks to ser if this was set from the i2c read / write functions. Instead of call max in each function for incrementing poll_retry_count do it once in the probe function. Fixup null pointer dereference in to pdata in sbs_external_power_changed. Change retry counts to u32 to avoid need for max. Signed-off-by: Phil Reid <preid@electromag.com.au> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2016-09-19sbs-battery: make writes to ManufacturerAccess optionalGuenter Roeck1-14/+15
According to the Smart Battery Data Specification, the use of ManufacturerAcess (register 0x0) is implementation-defined. It appears that some batteries use writes to this register in order to implement certain functionality, but others may simply NAK all writes to it. As a result, write failures to ManufacturerAccess should not be used as an indicator of battery presence, nor as a failure to enter sleep mode. The failed write access was seen with SANYO AP13J3K. Cc: Brian Norris <briannorris@chromium.org> Signed-off-by: Guenter Roeck <linux@roeck-us.net> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2016-09-07power: supply: sbs-battery: simplify DT parsingArnd Bergmann1-67/+31
After the change to use the gpio descriptor interface, we get a warning if -Wmaybe-uninitialized is added back to the build flags (it is currently disabled: drivers/power/supply/sbs-battery.c: In function 'sbs_probe': drivers/power/supply/sbs-battery.c:760:28: error: 'pdata' may be used uninitialized in this function [-Werror=maybe-uninitialized] The problem is that if neither the DT properties nor a platform_data pointer are provided, the chip->pdata pointer gets set to an uninitialized value. Looking at the code some more, I found that the sbs_of_populate_pdata function is more complex than necessary and has confusing calling conventions of possibly returning a valid pointer, a NULL pointer or an ERR_PTR pointer (in addition to the uninitialized pointer). To fix all of that, this gets rid of the chip->pdata pointer and simply moves the two integers into the sbs_info structure. This makes it much clearer from reading sbs_probe() what the precedence of the three possible values are (pdata, DT, hardcoded defaults) and completely avoids the #ifdef CONFIG_OF guards as of_property_read_u32() gets replaced with a compile-time stub when that is disabled, and returns an error if passed a NULL of_node pointer. Signed-off-by: Arnd Bergmann <arnd@arndb.de> Fixes: 3b5dd3a49496 ("power: supply: sbs-battery: Use gpio_desc and sleeping calls for battery detect") Signed-off-by: Sebastian Reichel <sre@kernel.org>
2016-09-01power: supply: sbs-battery: Use gpio_desc and sleeping calls for battery detectPhil Reid1-67/+34
Switch to using new gpio_desc interface and devm gpio get calls to automatically manage gpio resource. Use gpiod_get_value which handles active high / low calls. If gpio_detect is set then force loading of the driver as it is reasonable to assume that the battery may not be present. Update the is_present flag immediately in the IRQ. Remove legacy gpio specification from platform data. Signed-off-by: Phil Reid <preid@electromag.com.au> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2016-08-16sbs-battery: add ability to get battery capacityJoshua Clayton1-1/+22
Battery capacity level is a standard feature of sbs battery That can be used to tell what the remainig battery capacity is, and can tell if the battery has not been calibrated/initialized, which makes the capacity and charging/discharging percentages invalid. Signed-off-by: Joshua Clayton <stillcompiling@gmail.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2016-08-15power: sbs-battery: Use devm_power_supply_registerPhil Reid1-3/+1
Use devm_power_supply_register instead of power_supply_register. Remove call to power_supply_unregister. Signed-off-by: Phil Reid <preid@electromag.com.au> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2016-08-15power: sbs-battery: Request threaded irq and fix dev callback cookiePhil Reid1-10/+4
Currently the battery detect gpio can not be used with a chained interrupt controller that requires threaded irq handlers. Use threaded irq instead. In addition this was not going to be working at present because chip->power_supply is assigned after the request irq call. Signed-off-by: Phil Reid <preid@electromag.com.au> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2016-08-15power: sbs-battery: Use devm_kzalloc to alloc dataPhil Reid1-6/+1
Use devm_kzalloc to allow memory to be freed automatically on driver probe failure or removal. Signed-off-by: Phil Reid <preid@electromag.com.au> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2016-08-11power: move power supply drivers to power/supplySebastian Reichel1-0/+998
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>