aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/bq27x00_battery.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2015-03-13power_supply: Change ownership from driver to coreKrzysztof Kozlowski1-36/+38
Change the ownership of power_supply structure from each driver implementing the class to the power supply core. The patch changes power_supply_register() function thus all drivers implementing power supply class are adjusted. Each driver provides the implementation of power supply. However it should not be the owner of power supply class instance because it is exposed by core to other subsystems with power_supply_get_by_name(). These other subsystems have no knowledge when the driver will unregister the power supply. This leads to several issues when driver is unbound - mostly because user of power supply accesses freed memory. Instead let the core own the instance of struct 'power_supply'. Other users of this power supply will still access valid memory because it will be freed when device reference count reaches 0. Currently this means "it will leak" but power_supply_put() call in next patches will solve it. This solves invalid memory references in following race condition scenario: Thread 1: charger manager Thread 2: power supply driver, used by charger manager THREAD 1 (charger manager) THREAD 2 (power supply driver) ========================== ============================== psy = power_supply_get_by_name() Driver unbind, .remove power_supply_unregister() Device fully removed psy->get_property() The 'get_property' call is executed in invalid context because the driver was unbound and struct 'power_supply' memory was freed. This could be observed easily with charger manager driver (here compiled with max17040 fuel gauge): $ cat /sys/devices/virtual/power_supply/cm-battery/capacity & $ echo "1-0036" > /sys/bus/i2c/drivers/max17040/unbind [ 55.725123] Unable to handle kernel NULL pointer dereference at virtual address 00000000 [ 55.732584] pgd = d98d4000 [ 55.734060] [00000000] *pgd=5afa2831, *pte=00000000, *ppte=00000000 [ 55.740318] Internal error: Oops: 80000007 [#1] PREEMPT SMP ARM [ 55.746210] Modules linked in: [ 55.749259] CPU: 1 PID: 2936 Comm: cat Tainted: G W 3.19.0-rc1-next-20141226-00048-gf79f475f3c44-dirty #1496 [ 55.760190] Hardware name: SAMSUNG EXYNOS (Flattened Device Tree) [ 55.766270] task: d9b76f00 ti: daf54000 task.ti: daf54000 [ 55.771647] PC is at 0x0 [ 55.774182] LR is at charger_get_property+0x2f4/0x36c [ 55.779201] pc : [<00000000>] lr : [<c034b0b4>] psr: 60000013 [ 55.779201] sp : daf55e90 ip : 00000003 fp : 00000000 [ 55.790657] r10: 00000000 r9 : c06e2878 r8 : d9b26c68 [ 55.795865] r7 : dad81610 r6 : daec7410 r5 : daf55ebc r4 : 00000000 [ 55.802367] r3 : 00000000 r2 : daf55ebc r1 : 0000002a r0 : d9b26c68 [ 55.808879] Flags: nZCv IRQs on FIQs on Mode SVC_32 ISA ARM Segment user [ 55.815994] Control: 10c5387d Table: 598d406a DAC: 00000015 [ 55.821723] Process cat (pid: 2936, stack limit = 0xdaf54210) [ 55.827451] Stack: (0xdaf55e90 to 0xdaf56000) [ 55.831795] 5e80: 60000013 c01459c4 0000002a c06f8ef8 [ 55.839956] 5ea0: db651000 c06f8ef8 daebac00 c04cb668 daebac08 c0346864 00000000 c01459c4 [ 55.848115] 5ec0: d99eaa80 c06f8ef8 00000fff 00001000 db651000 c027f25c c027f240 d99eaa80 [ 55.856274] 5ee0: d9a06c00 c0146218 daf55f18 00001000 d99eaa80 db4c18c0 00000001 00000001 [ 55.864468] 5f00: daf55f80 c0144c78 c0144c54 c0107f90 00015000 d99eaab0 00000000 00000000 [ 55.872603] 5f20: 000051c7 00000000 db4c18c0 c04a9370 00015000 00001000 daf55f80 00001000 [ 55.880763] 5f40: daf54000 00015000 00000000 c00e53dc db4c18c0 c00e548c 0000000d 00008124 [ 55.888937] 5f60: 00000001 00000000 00000000 db4c18c0 db4c18c0 00001000 00015000 c00e5550 [ 55.897099] 5f80: 00000000 00000000 00001000 00001000 00015000 00000003 00000003 c000f364 [ 55.905239] 5fa0: 00000000 c000f1a0 00001000 00015000 00000003 00015000 00001000 0001333c [ 55.913399] 5fc0: 00001000 00015000 00000003 00000003 00000002 00000000 00000000 00000000 [ 55.921560] 5fe0: 7fffe000 be999850 0000a225 b6f3c19c 60000010 00000003 00000000 00000000 [ 55.929744] [<c034b0b4>] (charger_get_property) from [<c0346864>] (power_supply_show_property+0x48/0x20c) [ 55.939286] [<c0346864>] (power_supply_show_property) from [<c027f25c>] (dev_attr_show+0x1c/0x48) [ 55.948130] [<c027f25c>] (dev_attr_show) from [<c0146218>] (sysfs_kf_seq_show+0x84/0x104) [ 55.956298] [<c0146218>] (sysfs_kf_seq_show) from [<c0144c78>] (kernfs_seq_show+0x24/0x28) [ 55.964536] [<c0144c78>] (kernfs_seq_show) from [<c0107f90>] (seq_read+0x1b0/0x484) [ 55.972172] [<c0107f90>] (seq_read) from [<c00e53dc>] (__vfs_read+0x18/0x4c) [ 55.979188] [<c00e53dc>] (__vfs_read) from [<c00e548c>] (vfs_read+0x7c/0x100) [ 55.986304] [<c00e548c>] (vfs_read) from [<c00e5550>] (SyS_read+0x40/0x8c) [ 55.993164] [<c00e5550>] (SyS_read) from [<c000f1a0>] (ret_fast_syscall+0x0/0x48) [ 56.000626] Code: bad PC value [ 56.011652] ---[ end trace 7b64343fbdae8ef1 ]--- Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> [for the nvec part] Reviewed-by: Marc Dietrich <marvin24@gmx.de> [for compal-laptop.c] Acked-by: Darren Hart <dvhart@linux.intel.com> [for the mfd part] Acked-by: Lee Jones <lee.jones@linaro.org> [for the hid part] Acked-by: Jiri Kosina <jkosina@suse.cz> [for the acpi part] Acked-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2015-03-13power_supply: Move run-time configuration to separate structureKrzysztof Kozlowski1-1/+1
Add new structure 'power_supply_config' for holding run-time initialization data like of_node, supplies and private driver data. The power_supply_register() function is changed so all power supply drivers need updating. When registering the power supply this new 'power_supply_config' should be used instead of directly initializing 'struct power_supply'. This allows changing the ownership of power_supply structure from driver to the power supply core in next patches. When a driver does not use of_node or supplies then it should use NULL as config. If driver uses of_node or supplies then it should allocate config on stack and initialize it with proper values. Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Reviewed-by: Bartlomiej Zolnierkiewicz <b.zolnierkie@samsung.com> Acked-by: Pavel Machek <pavel@ucw.cz> [for the nvec part] Reviewed-by: Marc Dietrich <marvin24@gmx.de> [for drivers/platform/x86/compal-laptop.c] Reviewed-by: Darren Hart <dvhart@linux.intel.com> [for drivers/hid/*] Reviewed-by: Jiri Kosina <jkosina@suse.cz> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2015-02-28power: bq27x00_battery: add bq27510 supportAlexandre Belloni1-5/+45
Add support for bq27510 to the bq27x00 driver. Signed-off-by: Alexandre Belloni <alexandre.belloni@free-electrons.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2015-02-25bq2415x_charger, bq27x00_battery.c: comment cleanupsPavel Machek1-3/+0
Cleanup comments for bq2415x_charger, bq27x00_battery.c. Signed-off-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2015-02-25bq27x00_battery: register as non-wakeup power supply.NeilBrown1-1/+1
power_supply status changes for the bq27x00 are only noticed via polling, not via interrupts. So they are never the source of events which should reliably wake the system from suspend. So it is appropriate to register as a no_ws power source, just like the ACPI battery. This removes some debugging messages which occasionally confusingly identify bq27x00 as a wakeup source. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2015-01-21bq27x00_battery: Call power_supply_changed only when capacity changedPuthikorn Voravootivat1-3/+4
In current driver, power_supply_changed() is called whenever any of the battery attribute changed. This causes kernel to increases the '/sys/power/wakeup_count' and make suspend not working correctly. This patch change this behavior to call power_supply_changed() only when the battery capacity changed. Signed-off-by: Puthikorn Voravootivat <puthik@chromium.org> Reviewed-by: David Riley <davidriley@chromium.org> Reviewed-by: Benson Leung <bleung@chromium.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2015-01-21bq27x00_battery: fix register offset for bq27425Eric Bénard1-4/+8
- SOC is at 0x1C so we must add 0x4 as stated in the comment to read the right value. - DCAP is at 0x3c so we also must use a value with the right offset to get the correct design capacity. Actually testing on a bq27410 which has the same register map as bq27425 (but adds new registers). Signed-off-by: Eric Bénard <eric@eukrea.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-10-20power: drop owner assignment from platform_driversWolfram Sang1-1/+0
A platform_driver does not need to set an owner, it will be populated by the driver core. Signed-off-by: Wolfram Sang <wsa@the-dreams.de>
2014-10-01bq27x00_battery: Fix flag reading for bq27742Puthikorn Voravootivat1-6/+7
This patch fix the following issues. - Flag for bq27742 is 2 bytes contracy to 1 byte for older hardware - Don't read FLAG_CI as bq27742 does not have it - Use Battery full capacity register as last measure discharge Signed-off-by: Puthikorn Voravootivat <puthik@chromium.org> Reviewed-by: Benson Leung <bleung@chromium.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-09-25bq27x00_battery: Add support to bq27742Puthikorn Voravootivat1-7/+45
Add support to bq27742 in bq27x00 driver. bq27742 register addresses are mostly mostly the same as bq27500 addresses with minor differences. Signed-off-by: Puthikorn Voravootivat <puthik@chromium.org> Reviewed-by: Gwendal Grignou <gwendal@chromium.org> Reviewed-by: Rhyland Klein <rklein@nvidia.com> Reviewed-by: Benson Leung <bleung@chromium.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-07-18bq27000: report missing device better.Marek Belisko1-0/+3
One an hdq buss, a missing device reads as 0xff, not -1. So do a translation to allow detecting of a missing bus. Signed-off-by: NeilBrown <neilb@suse.de> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-07-18bq27x00_battery: Introduce the use of the managed version of kzallocHimangi Saraogi1-20/+5
This patch moves data allocated using kzalloc to managed data allocated using devm_kzalloc and cleans now unnecessary kfrees in probe and remove functions for both platform and i2c drivers. Also, the unecessary variable ret and labels batt_failed3, err_free were removed. The following Coccinele script was used for making the change: @platform@ identifier p, probefn, removefn; @@ struct platform_driver p = { .probe = probefn, .remove = removefn, }; @prb@ identifier platform.probefn, pdev; expression e, e1, e2; @@ probefn(struct platform_device *pdev, ...) { <+... - e = kzalloc(e1, e2) + e = devm_kzalloc(&pdev->dev, e1, e2) ... ?-kfree(e); ...+> } @rem depends on prb@ identifier platform.removefn; expression e; @@ removefn(...) { <... - kfree(e); ...> } Signed-off-by: Himangi Saraogi <himangi774@gmail.com> Acked-by: Julia Lawall <julia.lawall@lip6.fr> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2013-06-06bq27x00_battery: Remove unnecessary platform_set_drvdata()Jingoo Han1-2/+0
The driver core clears the driver data to NULL after device_release or on probe failure, since commit 0998d0631001288a5974afc0b2a5f568bcdecb4d (device-core: Ensure drvdata = NULL when no driver is bound). Thus, it is not needed to manually clear the device driver data to NULL. Signed-off-by: Jingoo Han <jg1.han@samsung.com> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
2013-02-27power: convert to idr_alloc()Tejun Heo1-6/+3
Convert to the much saner new idr interface. Signed-off-by: Tejun Heo <tj@kernel.org> Acked-by: Anton Vorontsov <cbou@mail.ru> Cc: David Woodhouse <dwmw2@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2013-02-02bq27x00_battery: Fix reporting battery temperaturePali Rohár1-5/+5
Reported temperature can be also negative, so cache value in non negative Kelvin degree. Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
2013-01-05bq27x00_battery: Fix bugs introduced with BQ27425 supportNeilBrown1-2/+0
commit a66f59ba2e994bf70274ef0513e24e0e7ae20c63 bq27x00_battery: Add support for BQ27425 chip introduced 2 bugs. 1/ 'chip' was set to BQ27425 unconditionally - breaking support for other devices; 2/ BQ27425 does not support cycle count, how the code still tries to get the cycle count for BQ27425, and now does it twice for other chips. Signed-off-by: NeilBrown <neilb@suse.de> Cc: Saranya Gopal <saranya.gopal@intel.com> Cc: stable@vger.kernel.org Signed-off-by: Anton Vorontsov <anton@enomsg.org>
2012-12-11Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linuxAnton Vorontsov1-3/+3
The merge is merely to fix conflicts before sending a pull request. Conflicts: drivers/power/ab8500_btemp.c drivers/power/ab8500_charger.c drivers/power/ab8500_fg.c drivers/power/abx500_chargalg.c drivers/power/max8925_power.c Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
2012-11-28power: remove use of __devexitBill Pemberton1-1/+1
CONFIG_HOTPLUG is going away as an option so __devexit is no longer needed. Signed-off-by: Bill Pemberton <wfp5p@virginia.edu> Cc: Anton Vorontsov <cbou@mail.ru> Cc: David Woodhouse <dwmw2@infradead.org> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-11-28power: remove use of __devinitBill Pemberton1-1/+1
CONFIG_HOTPLUG is going away as an option so __devinit is no longer needed. Signed-off-by: Bill Pemberton <wfp5p@virginia.edu> Cc: Anton Vorontsov <cbou@mail.ru> Cc: David Woodhouse <dwmw2@infradead.org> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-11-28power: remove use of __devexit_pBill Pemberton1-1/+1
CONFIG_HOTPLUG is going away as an option so __devexit_p is no longer needed. Signed-off-by: Bill Pemberton <wfp5p@virginia.edu> Cc: Anton Vorontsov <cbou@mail.ru> Cc: David Woodhouse <dwmw2@infradead.org> Acked-by: Mark Brown <broonie@opensource.wolfsonmicro.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-11-18bq27x00_battery: Fixup nominal available capacity reportingPali Rohár1-0/+8
We should not not report nominal available capacity if battery is not calibrated, as we don't want to represent bogus values in the sysfs and confuse userland. Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
2012-08-22bq27x00_battery: Fix error return codeJulia Lawall1-1/+2
Initialize return variable before exiting on an error path. A simplified version of the semantic match that finds this problem is as follows: (http://coccinelle.lip6.fr/) // <smpl> ( if@p1 (\(ret < 0\|ret != 0\)) { ... return ret; } | ret@p1 = 0 ) ... when != ret = e1 when != &ret *if(...) { ... when != ret = e2 when forall return ret; } // </smpl> Signed-off-by: Julia Lawall <Julia.Lawall@lip6.fr> Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
2012-07-13bq27x00_battery: Add support for BQ27425 chipSaranya Gopal1-15/+69
This patch adds support for BQ27425 (TI) chip. This chip is same as BQ27500 with few registers removed and register address map changed. The data sheet for this chip is publicly available at http://www.ti.com/product/bq27425-g1 Signed-off-by: Saranya Gopal <saranya.gopal@intel.com> Reviewed-by: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
2012-06-19bq27x00_battery: Add support for power average and health propertiesSyed Rafiuddin1-0/+71
Addition of power average and health properties. Signed-off-by: Syed Rafiuddin <srafiuddin@nvidia.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2012-04-08Merge branch 'master' into for-nextJiri Kosina1-10/+5
Merge with latest Linus' tree, as I have incoming patches that fix code that is newer than current HEAD of for-next. Conflicts: drivers/net/ethernet/realtek/r8169.c
2012-04-05Fix typo milivolt => millivoltThomas Weber1-1/+1
Signed-off-by: Thomas Weber <thomas@tweber.de> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-03-20Merge branch 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivialLinus Torvalds1-2/+2
Pull trivial tree from Jiri Kosina: "It's indeed trivial -- mostly documentation updates and a bunch of typo fixes from Masanari. There are also several linux/version.h include removals from Jesper." * 'for-linus' of git://git.kernel.org/pub/scm/linux/kernel/git/jikos/trivial: (101 commits) kcore: fix spelling in read_kcore() comment constify struct pci_dev * in obvious cases Revert "char: Fix typo in viotape.c" init: fix wording error in mm_init comment usb: gadget: Kconfig: fix typo for 'different' Revert "power, max8998: Include linux/module.h just once in drivers/power/max8998_charger.c" writeback: fix fn name in writeback_inodes_sb_nr_if_idle() comment header writeback: fix typo in the writeback_control comment Documentation: Fix multiple typo in Documentation tpm_tis: fix tis_lock with respect to RCU Revert "media: Fix typo in mixer_drv.c and hdmi_drv.c" Doc: Update numastat.txt qla4xxx: Add missing spaces to error messages compiler.h: Fix typo security: struct security_operations kerneldoc fix Documentation: broken URL in libata.tmpl Documentation: broken URL in filesystems.tmpl mtd: simplify return logic in do_map_probe() mm: fix comment typo of truncate_inode_pages_range power: bq27x00: Fix typos in comment ...
2012-02-21power: bq27x00: Fix typos in commentThomas Weber1-2/+2
Fix two typos in comments. Signed-off-by: Thomas Weber <weber@corscience.de> Signed-off-by: Jiri Kosina <jkosina@suse.cz>
2012-02-01bq27x00_battery: Fix flag register readGrazvydas Ignotas1-1/+1
When reading flags, bq27x00_read() argument is inverted and causes reads 2 of bytes for bq27200 and 1 byte for bq27500, while their register sizes are 1 and 2 bytes respectively. This causes bq27500 upper flag bits always to be returned as 0, causing full charge state to never be reported correctly, so fix it. Cc: Lars-Peter Clausen <lars@metafoo.de> Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Acked-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2012-02-01Revert "bq27x00_battery: Fix reporting status value for bq27500 battery"Anton Vorontsov1-9/+4
This reverts commit 270968c0984aeed096da3cfffb0e131f4c416166. Grazvydas Ignotas wrote: After 270968c0984ae "bq27x00_battery: Fix reporting status value for bq27500 battery" status doesn't seem to be reported correctly when the battery is close to fully charged state. It reports "Not charging" while in fact there is >130mA current flowing to the battery according to current_now. This status report seems to be based on CHG bit in status register, but looking at the datasheet the description says "(Fast) charging allowed", which I guess means that the chip recommends charging and not that charging is actually going on? If you check the bit while battery is discharging and it's not full, the bit is also set. Suggested-by: Grazvydas Ignotas <notasas@gmail.com> Acked-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2011-11-26bq27x00_battery: Fix OOPS caused by unregistring bq27x00 driverPali Rohár1-0/+8
* power_supply_unregister call bq27x00_battery_get_property which call bq27x00_battery_poll * make sure that bq27x00_battery_poll will not call schedule_delayed_work again after unregister (which cause OOPS) Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2011-11-26bq27x00_battery: Fix reporting error messagesPali Rohár1-7/+14
* Do not be noise if battery is not calibrated (use dev_dbg) Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2011-11-25bq27x00_battery: Fix reporting status value for bq27500 batteryPali Rohár1-4/+9
Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2011-11-25bq27x00_battery: Cache temperature value in converted unitPali Rohár1-21/+24
Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2011-11-25bq27x00_battery: Cache energy propertyPali Rohár1-27/+26
Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2011-11-25bq27x00_battery: Report -ENODATA if bq27000 battery was not calibratedPali Rohár1-5/+14
* CI (Capacity Inaccurate) flag is set after full reset on bq27000 battery * when is set, all capacity properties should be reported incorrectly, because there was no learning cycle and battery was not calibrated * instead reporting incorrect values, report -ENODATA Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2011-11-25bq27x00_battery: Add support for property POWER_SUPPLY_PROP_CAPACITY_LEVELPali Rohár1-1/+39
Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2011-11-25bq27x00_battery: Do not cache current_now value for bq27000 bateryPali Rohár1-14/+5
* This prevent reporting old current_now value for bq27000 * Also ask for current flags, to make sure that current_now will be reported with correct signature Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2011-05-20bq27x00_battery: Name of cycle count propertyPali Rohár1-5/+6
This patch fix using correct property POWER_SUPPLY_PROP_CYCLE_COUNT for cycle count instead POWER_SUPPLY_PROP_CHARGE_COUNTER Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Tested-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2011-02-22bq27x00: Use single i2c_transfer call for property readGrazvydas Ignotas1-16/+11
Doing this by using 2 calls sometimes results in unexpected values being returned on OMAP3 i2c controller. Signed-off-by: Grazvydas Ignotas <notasas@gmail.com> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
2011-02-22bq27x00: Cleanup bq27x00_i2c_readLars-Peter Clausen1-21/+24
Some minor stylistic cleanups. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Tested-by: Grazvydas Ignotas <notasas@gmail.com>
2011-02-22bq27x00: Minor cleanupsPali Rohár1-2/+2
* Consistently use uppercase for hexadecimal values. * Clarify/fix the unit of functions return value in its comment. Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Tested-by: Grazvydas Ignotas <notasas@gmail.com>
2011-02-22bq27x00: Give more specific reports on battery statusLars-Peter Clausen1-1/+6
The current code only reports whether the battery is charging or discharging. But the battery also reports whether it is fully charged, furthermore by look at if the battery is supplied we can tell whether it is discharging or not charging. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Rodolfo Giometti <giometti@linux.it> Tested-by: Grazvydas Ignotas <notasas@gmail.com>
2011-02-22bq27x00: Add MODULE_DEVICE_TABLEPali Rohár1-0/+1
This patch adds MODULE_DEVICE_TABLE for module bq27x00_battery. Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Tested-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Rodolfo Giometti <giometti@linux.it> Tested-by: Grazvydas Ignotas <notasas@gmail.com>
2011-02-22bq27x00: Add new propertiesPali Rohár1-1/+151
This patch add support for reporting properties POWER_SUPPLY_PROP_CHARGE_NOW, POWER_SUPPLY_PROP_CHARGE_FULL, POWER_SUPPLY_PROP_CHARGE_FULL_DESIGN, POWER_SUPPLY_PROP_CHARGE_COUNTER, POWER_SUPPLY_PROP_ENERGY_NOW in module bq27x00_battery. Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Tested-by: Grazvydas Ignotas <notasas@gmail.com>
2011-02-22bq27x00: Poll battery stateLars-Peter Clausen1-5/+53
This patch adds support for polling the battery state and generating a power_supply_changed() event if it has changed. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Tested-by: Grazvydas Ignotas <notasas@gmail.com>
2011-02-22bq27x00: Cache battery registersLars-Peter Clausen1-121/+150
This patch adds a register cache to the bq27x00 battery driver. Usually multiple, if not all, power_supply properties are queried at once, for example when an uevent is generated. Since some registers are used by multiple properties caching the registers should reduce the number of reads. The cache is valid for 5 seconds this roughly matches the internal update interval of the current register for the bq27000/bq27200. Fast changing properties(*_NOW) which can be obtained by reading a single register are not cached. It will also be used in the follow up patch to check if the battery status has been changed since the last update to emit power_supply_changed events. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Tested-by: Grazvydas Ignotas <notasas@gmail.com>
2011-02-22bq27x00: Add bq27000 supportLars-Peter Clausen1-15/+169
This patch adds support for the bq27000 battery to the bq27x00 driver. The bq27000 is similar to the bq27200 except that it uses the HDQ bus instead of I2C to communicate with the host system. The driver is implemented as a platform driver. The driver expects to be provided with a read callback function through its platform data. The read function is assumed to do the lowlevel HDQ handling and read out the value of a certain register. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Tested-by: Grazvydas Ignotas <notasas@gmail.com>
2011-02-22bq27x00: Prepare code for addition of bq27000 platform driverLars-Peter Clausen1-47/+39
This patch simplifies the drivers data structure and moves code to be shared by the bq27000 and bq27200/bq27500 init functions into a common function. This patch has no functional changes, it only moves code around. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Rodolfo Giometti <giometti@linux.it> Tested-by: Grazvydas Ignotas <notasas@gmail.com>
2011-02-22bq27x00: Return -ENODEV for properties if the battery is not presentLars-Peter Clausen1-2/+7
This patch changes get_property callback of the bq27x00 battery to return -ENODEV for properties other then the PROP_PRESENT if the battery is not present. The power subsystem core expects a driver to behave that way. Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Acked-by: Rodolfo Giometti <giometti@linux.it> Tested-by: Grazvydas Ignotas <notasas@gmail.com>