14 Mar, 2015
3 commits
-
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 managerTHREAD 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 : [] lr : [] 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] [] (charger_get_property) from [] (power_supply_show_property+0x48/0x20c)
[ 55.939286] [] (power_supply_show_property) from [] (dev_attr_show+0x1c/0x48)
[ 55.948130] [] (dev_attr_show) from [] (sysfs_kf_seq_show+0x84/0x104)
[ 55.956298] [] (sysfs_kf_seq_show) from [] (kernfs_seq_show+0x24/0x28)
[ 55.964536] [] (kernfs_seq_show) from [] (seq_read+0x1b0/0x484)
[ 55.972172] [] (seq_read) from [] (__vfs_read+0x18/0x4c)
[ 55.979188] [] (__vfs_read) from [] (vfs_read+0x7c/0x100)
[ 55.986304] [] (vfs_read) from [] (SyS_read+0x40/0x8c)
[ 55.993164] [] (SyS_read) from [] (ret_fast_syscall+0x0/0x48)
[ 56.000626] Code: bad PC value
[ 56.011652] ---[ end trace 7b64343fbdae8ef1 ]---Signed-off-by: Krzysztof Kozlowski
Reviewed-by: Bartlomiej Zolnierkiewicz[for the nvec part]
Reviewed-by: Marc Dietrich[for compal-laptop.c]
Acked-by: Darren Hart[for the mfd part]
Acked-by: Lee Jones[for the hid part]
Acked-by: Jiri Kosina[for the acpi part]
Acked-by: Rafael J. WysockiSigned-off-by: Sebastian Reichel
-
Replace direct calls to power supply function attributes with wrappers.
Wrappers provide safe access in case of unregistering the power
supply (e.g. by removing the driver). Replace:
- get_property -> power_supply_get_propertySigned-off-by: Krzysztof Kozlowski
Acked-by: Jonghwa Lee
Acked-by: Pavel Machek
Acked-by: Linus Walleij
Reviewed-by: Bartlomiej Zolnierkiewicz
Reviewed-by: Sebastian Reichel
Signed-off-by: Sebastian Reichel -
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
Reviewed-by: Bartlomiej Zolnierkiewicz
Acked-by: Pavel Machek[for the nvec part]
Reviewed-by: Marc Dietrich[for drivers/platform/x86/compal-laptop.c]
Reviewed-by: Darren Hart[for drivers/hid/*]
Reviewed-by: Jiri KosinaSigned-off-by: Sebastian Reichel
08 Mar, 2015
1 commit
-
All 5 IRQ handlers of the driver are requested as threaded interrupt
handlers. However, only 1 handler can block. The remaining 4 handlers
defer the actual handling to a workqueue. Hence, 4 of 5 IRQ handlers
have a considerable overhead, since they are executed in a kernel thread
to schedule another kernel thread (workqueue).This change splits up the 5 interrupt handlers into top halves (_th) and
bottom halves (_bh) and resolves the aforementioned overhead by only
requesting threaded interrupts (i.e., bottom halves) when necessary.Signed-off-by: Valentin Rothberg
Signed-off-by: Sebastian Reichel
26 Feb, 2015
3 commits
-
Converting jiffies to milliseconds by "val * 1000 / HZ" is technically
OK but jiffies_to_msecs(val) is the cleaner solution and handles all
corner cases correctly. This is a minor API consolidation only and
should make things more readable.Signed-off-by: Nicholas Mc Guire
Signed-off-by: Sebastian Reichel -
return type of wait_for_completion_timeout is unsigned long not int. as
timeout is used for wait_for_completion_timeout exclusively here its
type is simply changed to unsigned long.Signed-off-by: Nicholas Mc Guire
Signed-off-by: Sebastian Reichel -
Simplify a little ab8500_fg_sysfs_psy_create_attrs () and
ab8500_fg_sysfs_psy_remove_attrs() functions because they received
pointer to power supply device which was then converted into power
supply instance. Then it was converted into struct ab8500_fg. The path
looked like:
ab8500_fg->psy.dev -> psy -> ab8500_fgInstead just pass pointer to struct ab8500_fg directly so all
conversions won't be necessary.Signed-off-by: Krzysztof Kozlowski
Signed-off-by: Sebastian Reichel
21 Jan, 2015
1 commit
-
Remove the function ab8500_fg_reinit() that is not used anywhere.
This was partially found by using a static code analysis program called cppcheck.
Signed-off-by: Rickard Strandqvist
Acked-by: Arnd Bergmann
Signed-off-by: Sebastian Reichel
15 Dec, 2014
1 commit
-
Pull driver core update from Greg KH:
"Here's the set of driver core patches for 3.19-rc1.They are dominated by the removal of the .owner field in platform
drivers. They touch a lot of files, but they are "simple" changes,
just removing a line in a structure.Other than that, a few minor driver core and debugfs changes. There
are some ath9k patches coming in through this tree that have been
acked by the wireless maintainers as they relied on the debugfs
changes.Everything has been in linux-next for a while"
* tag 'driver-core-3.19-rc1' of git://git.kernel.org/pub/scm/linux/kernel/git/gregkh/driver-core: (324 commits)
Revert "ath: ath9k: use debugfs_create_devm_seqfile() helper for seq_file entries"
fs: debugfs: add forward declaration for struct device type
firmware class: Deletion of an unnecessary check before the function call "vunmap"
firmware loader: fix hung task warning dump
devcoredump: provide a one-way disable function
device: Add dev__once variants
ath: ath9k: use debugfs_create_devm_seqfile() helper for seq_file entries
ath: use seq_file api for ath9k debugfs files
debugfs: add helper function to create device related seq_file
drivers/base: cacheinfo: remove noisy error boot message
Revert "core: platform: add warning if driver has no owner"
drivers: base: support cpu cache information interface to userspace via sysfs
drivers: base: add cpu_device_create to support per-cpu devices
topology: replace custom attribute macros with standard DEVICE_ATTR*
cpumask: factor out show_cpumap into separate helper function
driver core: Fix unbalanced device reference in drivers_probe
driver core: fix race with userland in device_add()
sysfs/kernfs: make read requests on pre-alloc files use the buffer.
sysfs/kernfs: allow attributes to request write buffer be pre-allocated.
fs: sysfs: return EGBIG on write if offset is larger than file size
...
20 Oct, 2014
1 commit
-
A platform_driver does not need to set an owner, it will be populated by the
driver core.Signed-off-by: Wolfram Sang
15 Oct, 2014
1 commit
-
This patch changes 32-bit time types to 64-bit in
drivers/power/ab8500_fg.ctimespec and time_t can only represent signed 32-bit
dates but the driver should represent dates that are
after January 2038. So used time64.h header file and
its proper types and functions.Use time64_t type instead of __kernel_time_t for
time_stamps variable of ab8500_fg_avg_cap structSigned-off-by: Ebru Akagunduz
Acked-by: Arnd Bergmann
Signed-off-by: Sebastian Reichel
05 Oct, 2014
1 commit
-
Fix
drivers/power/ab8500_fg.c: In function 'ab8500_fg_probe':
drivers/power/ab8500_fg.c:2989:27:
warning: 'i' may be used uninitialized in this function
drivers/power/ab8500_fg.c:2972:15: note: 'i' was declared herewhich actually points to a real bug.
Signed-off-by: Guenter Roeck
Signed-off-by: Sebastian Reichel
15 Nov, 2013
1 commit
-
Use this new function to make code more comprehensible, since we are
reinitialzing the completion, not initializing.[akpm@linux-foundation.org: linux-next resyncs]
Signed-off-by: Wolfram Sang
Acked-by: Linus Walleij (personally at LCE13)
Cc: Ingo Molnar
Signed-off-by: Andrew Morton
Signed-off-by: Linus Torvalds
07 Jun, 2013
2 commits
-
The usage of strict_strtoul() is not preferred, because strict_strtoul()
is obsolete. Thus, kstrtoul() should be used.Signed-off-by: Jingoo Han
Reviewed-by: Andy Shevchenko
Signed-off-by: Anton Vorontsov -
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
Acked-by: Lee Jones
Signed-off-by: Anton Vorontsov
17 Apr, 2013
1 commit
-
This patch adds const attributes to AB8500 power and temperature related
read-only data arrays.Signed-off-by: Hongbo Zhang
Signed-off-by: Anton Vorontsov
07 Mar, 2013
6 commits
-
This patch updates the gas gauge constant for electric current
calculation according to hardware specification.Signed-off-by: Benoit GAUTHIER
Signed-off-by: Lee Jones
Reviewed-by: Marcus COOPER
Reviewed-by: Philippe LANGLAIS
Tested-by: Benoit GAUTHIER -
Some of the comments in the ab8500 drivers reflect the behaviour
of the original device. As this driver now supports newer devices
then these comments are now redundant. Also some IRQ comments are
incorrect.Signed-off-by: Marcus Cooper
Signed-off-by: Lee Jones
Reviewed-by: Rabin VINCENT
Tested-by: Rabin VINCENT -
Signed-off-by: Lee Jones
-
When battery capacity was going below 1% fg is not supposed
to report 0% unless we've got the LOW_BAT IRQ, no matter
what the FG-algorithm says. This made fg get stuck at 1% if
charger is connected when capacity is 1%.Signed-off-by: Hakan BERG
Signed-off-by: Lee Jones
Reviewed-by: Marcus COOPER
Reviewed-by: Srinidhi KASAGAR -
Unscaled capacity should be reported for POWER_SUPPLY_PROP_CAPACITY.
Signed-off-by: Martin Bergstrom
Signed-off-by: Lee Jones
Reviewed-by: Marcus COOPER
Tested-by: Jonas ABERG -
Add support for a power cut feature which allows user to
configure when ab8505 and ab8540 based platforms should shut
down system due to low battery.Signed-off-by: Lee Jones
23 Jan, 2013
4 commits
-
If battery is not identified while fg probe, mah_max_design gets
initialized with unknown battery's charge full design. Reinitialize
mah_max_design if battery is identified after fg probe.Signed-off-by: Rajkumar Kasirajan
Signed-off-by: Lee Jones
Reviewed-by: Vijaya Kumar K-1
Reviewed-by: Marcus COOPER
Reviewed-by: Olivier CLERGEAUD
Reviewed-by: Arun MURTHY
Reviewed-by: Rabin VINCENT
Tested-by: Rupesh KUMAR
Tested-by: Jonas ABERG -
Flush all workqueues at suspend time to avoid suspending during work.
Signed-off-by: Jonas Aaberg
Signed-off-by: Lee Jones
Reviewed-by: Marcus COOPER -
When the charger is removed we need to go to INIT_RECOVERY
state instead of directly to RECOVERY state.Signed-off-by: Martin Bergstrom
Signed-off-by: Lee Jones
Reviewed-by: Marcus COOPER
Reviewed-by: Jonas ABERG
Tested-by: Jonas ABERG -
Changed conditions for restarting low battery measurements counter
and adjusted the interval between measurements to avoid RF burst
induced voltage drops, and to shorten time to decide to shut down.Signed-off-by: Hakan Berg
Signed-off-by: Martin Bergstrom
Signed-off-by: Lee Jones
Reviewed-by: Jonas ABERG
Reviewed-by: Marcus COOPER
16 Jan, 2013
8 commits
-
As HZ is a full-second, there is little point in rounding it.
Let's save a few cycles by using HZ directly.Signed-off-by: Lee Jones
Signed-off-by: Anton Vorontsov -
When calculating the average current the nominator will
overflow when the charging current is high.Signed-off-by: Lee Jones
Signed-off-by: Henrik Sölver
Reviewed-by: Par-Olof HAKANSSON
Reviewed-by: Jonas ABERG
Tested-by: Par-Olof HAKANSSON
Signed-off-by: Anton Vorontsov -
Add support for the battery over-voltage situation
Signed-off-by: Lee Jones
Signed-off-by: Hakan Berg
Reviewed-by: Karl KOMIEROWSKI
Signed-off-by: Anton Vorontsov -
Round the capacity values for better enduser experience.
Signed-off-by: Lee Jones
Signed-off-by: pender01
Reviewed-by: Jonas ABERG
Tested-by: Marcus COOPER
Signed-off-by: Anton Vorontsov -
In case of time out error IRQ needs to be disabled
otherwise we will get unbalanced enable/disable pairs.Signed-off-by: Lee Jones
Signed-off-by: Rickard Andersson
Reviewed-by: Jonas ABERG
Signed-off-by: Anton Vorontsov -
Today the battery recharge is determined with a voltage threshold. This
voltage threshold is only valid when the battery is relaxed. In charging
algorithm the voltage read is the loaded battery voltage and no
compensation is done to get the relaxed voltage. When maintenance
charging is not selected, this makes the recharging condition to almost
immediately activate when there is a discharge present on the battery.Depending on which vendor the battery comes from this behavior can wear
out the battery much faster than normal.The fuelgauge driver is responsible to monitor the actual battery
capacity and is able to estimate the remaining capacity. It is better to
use the remaining capacity as a limit to determine when battery should
be recharged.Signed-off-by: Lee Jones
Signed-off-by: Marcus Cooper
Reviewed-by: Hakan BERG
Reviewed-by: Jonas ABERG
Signed-off-by: Anton Vorontsov -
Doing so provides a greater degree of accuracy when dealing with
time-frames between 1us and 20ms. msleep() is only accurate for
wake-ups greater than 20ms.Signed-off-by: Lee Jones
Signed-off-by: Jonas ABERG
Reviewed-by: Johan BJORNSTEDT
Signed-off-by: Anton Vorontsov -
When enabling the CCEOC irq we might get false interrupt
from ab8500-driver due to the latched value will be saved
and interpreted as an IRQ when enabledSigned-off-by: Lee Jones
Signed-off-by: Johan Bjornstedt
Signed-off-by: Henrik Solver
Reviewed-by: Karl KOMIEROWSKI
Signed-off-by: Anton Vorontsov
06 Jan, 2013
1 commit
12 Dec, 2012
1 commit
-
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.cSigned-off-by: Anton Vorontsov
11 Dec, 2012
4 commits
-
Now that we always pass platform specific battery management data
through platform_data instead of obtaining it via different means
depending the way be boot the system (DT or ATAGs); we need to
re-jiggle the way we acquire it in the driver start-up functions.
Now it is wrong for it to be missing, but we still allow Device
Tree code to fiddle with it once we've confirmed it's there.Signed-off-by: Lee Jones
-
Currently the AB8500 battery management subsystem receives platform
specific information via two different means depending on how the
platform is booted. If DT is not enabled, a reference to a *_bm_data
data structure containing each platform specific attribute is passed
though platform_data. However, if DT is enabled, then platform_data
is empty and the reference is gained though a DT specific probe
function. There are two issues here 1) the same reference is
being collected each time and 2) the DT way doesn't allow any
provisions to select different platform specific attributes, which
kind of defeats the object.Cc: Samuel Ortiz
Signed-off-by: Lee Jones -
The platform specific battery management configuration data structure
is currently called 'bat' short for 'battery'; however, it contains
information for all components of the battery management group, rather
than information pertaining to the battery itself - there are other
structures for that. So, in keeping with its structure namesake
'abx500_bm_data', we rename it to 'bm' here. Using similar logic,
we're also renaming 'bmdevs_of_probe' to the more device specific
'ab8500_bm_of_probe'.Signed-off-by: Lee Jones
-
The CCMuxOffset bit is not kept set. This will force the
columb counter of the AB8500 to use the measure offset
calibration. This should increase the accuracy of the fuel
gauge.Signed-off-by: Kalle Komierowski
Signed-off-by: Marcus Cooper
Signed-off-by: Lee Jones
Reviewed-by: Jonas ABERG