aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/power/power_supply_core.c (follow)
AgeCommit message (Collapse)AuthorFilesLines
2014-10-28power_supply: Add no_thermal property to prevent recursive get_temp callsKrzysztof Kozlowski1-0/+3
Add a 'no_thermal' property to the power supply class. If true then thermal zone won't be created for this power supply in power_supply_register(). Power supply drivers may want to set it if they support POWER_SUPPLY_PROP_TEMP and they are forwarding this get property call to other thermal zone. If they won't set it lockdep may report false positive deadlock for thermal zone's mutex because of nested calls to thermal_zone_get_temp(). First is the call to thermal_zone_get_temp() of the driver's thermal zone. Thermal core gets POWER_SUPPLY_PROP_TEMP property from this driver. The driver then calls other thermal zone thermal_zone_get_temp() and returns result. Example of such driver is charger manager. Signed-off-by: Krzysztof Kozlowski <k.kozlowski@samsung.com> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-09-16power_supply: Don't iterate over devices to return -EPROBE_DEFERViresh Kumar1-13/+0
This piece of code was added so that we return -EPROBE_DEFER when no devices are registered. But even if class_for_each_device() returns 0, we are going to return -EPROBE_DEFER only. And so this code isn't required at all. Remove it. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-09-16power-supply: Avoid unnecessary 'goto' statementsViresh Kumar1-2/+1
Using 'goto' statements for freeing resources on failures is a good choice as it makes code very clean, and reduces the chances of human errors. Though in most cases compiler may take care of this. But adding unnecessary 'goto' statements wouldn't make anything better. Code becomes less readable actually. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-09-16power-supply: Use PTR_ERR_OR_ZERO() routineViresh Kumar1-6/+2
At multiple places we are doing exactly what PTR_ERR_OR_ZERO() does. And so that routine can be reused instead of increasing lines of code here. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-09-16power-supply: Mark 'if' blocks in power_supply_changed_work() with 'likely'Viresh Kumar1-5/+13
The 'if' statements in power_supply_changed_work() are mostly there for taking care of races and normally they will always evaluate to true. Optimize them for fast execution with 'likely' statements. Also there is need to have better comments in code to mention about the races clearly. Get them in place. Cc: Zoran Markovic <zrn.markovic@gmail.com> Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-09-16power-supply: Drop useless 'if (ret.intval)' statementsViresh Kumar1-9/+5
There is no need to check the value of ret.intval before returning it, as we will be returning zero explicitly when ret.intval is zero. So essentially we will end up returning value of ret.intval as it is. Drop the unnecessary 'if' statements. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-09-16power-supply: Don't return -EINVAL from __power_supply_find_supply_from_node()Viresh Kumar1-7/+11
We need to stop 'class_for_each_device' loop when a supply matches with the of-node. In order to achieve this we currently return -EINVAL from __power_supply_populate_supplied_from() on successful match. class_for_each_device() is free to return similar errors in other cases as well and so the choice of return value here isn't particularly great. This commit isn't removing the Hack but making it more elegant by returning '1' instead. Also power_supply_find_supply_from_node() can return errors other than -EPROBE_DEFER now if class_for_each_device() fails. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-09-16power-supply: Propagate error returned by power_supply_find_supply_from_node()Viresh Kumar1-2/+2
Callers of power_supply_find_supply_from_node(), i.e. power_supply_check_supplies(), must propagate the errors returned by it instead of returning their own. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-09-16power-supply: Rearrange code to remove duplicate linesViresh Kumar1-2/+2
of_node_put() was called twice in power_supply_check_supplies() whereas a single call will also work. Rearrange code a bit to make that feasible. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-09-16power-supply: Use 'break' instead of 'continue' to end loopViresh Kumar1-2/+2
In few routines, we need to end the do-while loop when no more "power-supplies" are available. Currently we are doing 'continue' which will make the 'while(np)' conditional statement run again. Skip this by doing a 'break' instead. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-09-16power-supply: Drop unnecessary typecastsViresh Kumar1-4/+4
Typecast from 'void *' to any other pointer type falls under implicit typecasts category and so doesn't require explicit typecasts. Drop them. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-09-16power-supply: Return early if "power-supplies" property isn't validViresh Kumar1-0/+4
If power-supply's DT node doesn't have a valid "power-supplies" entry, then power_supply_check_supplies() should return early instead of trying to allocate memory for "supplied_from" array. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-09-16power-supply: Don't over-allocate memory for "supplied-from" arrayViresh Kumar1-1/+1
In routine power_supply_check_supplies(), 'cnt' is counting the number of supplies passed in "power-supplies" field of a node. The value of 'cnt' will always be one more than the number of supplies after the do-while loop ends. And so we need to allocate memory for 'cnt - 1' char pointers. But we are allocating memory for 'cnt' instead. Fix this by not over-allocating memory. Signed-off-by: Viresh Kumar <viresh.kumar@linaro.org> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-07-20power_supply: Fix sparse non static symbol warningWei Yongjun1-1/+2
Fixes the following sparse warnings: drivers/power/power_supply_core.c:540:5: warning: symbol '__power_supply_register' was not declared. Should it be static? Signed-off-by: Wei Yongjun <yongjun_wei@trendmicro.com.cn> Signed-off-by: Sebastian Reichel <sre@kernel.org>
2014-05-30power_supply: allow power supply devices registered w/o wakeup sourceZhang Rui1-2/+13
Currently, all the power supply devices are registered with wakeup source, this results in that every power_supply_changed() invocation brings the system out of suspend-to-freeze state. This is overkill as some device drivers, e.g. ACPI battery driver, have the ability to check the device status and wake up the system from sleeping only when necessary. Thus introduce a new API which allows device to be registered w/o wakeup source. Signed-off-by: Zhang Rui <rui.zhang@intel.com> Signed-off-by: Rafael J. Wysocki <rafael.j.wysocki@intel.com>
2013-12-23power_supply: Add power_supply_get_by_phandleSebastian Reichel1-0/+26
Add method to get power supply by device tree phandle. Signed-off-by: Sebastian Reichel <sre@debian.org> Reviewed-by: Pavel Machek <pavel@ucw.cz> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
2013-12-01power_supply: Add power_supply notifierPali Rohár1-0/+18
This patch adds a notifier chain to the power_supply, this helps drivers in other subsystem to listen to changes in power supply subsystem. This would help to take some actions in those drivers on changing the power supply properties. One such scenario is to increase/decrease system performance based on the battery capacity/voltage. Another scenario is to adjust the h/w peak current detection voltage/current thresholds based on battery voltage/capacity. The notifier helps drivers to listen to changes in power_suppy susbystem without polling the power_supply properties Signed-off-by: Jenny TC <jenny.tc@intel.com> Signed-off-by: Pali Rohár <pali.rohar@gmail.com> Acked-by: Jenny TC <jenny.tc@intel.com> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
2013-12-01power_supply: Fix Oops from NULL pointer dereference from wakeup_source_activateShuah Khan1-6/+6
power_supply_register() calls device_init_wakeup() to register a wakeup source before initializing dev_name. As a result, device_wakeup_enable() end up registering wakeup source with a null name when wakeup_source_register() gets called with dev_name(dev) which is null at the time. When kernel is booted with wakeup_source_activate enabled, it will panic when the trace point code tries to dereference ws->name. Fixed the problem by moving up the kobject_set_name() call prior to accesses to dev_name(). Replaced kobject_set_name() with dev_set_name() which is the right interface to be called from drivers. Fixed the call to device_del() prior to device_add() in for wakeup_init_failed error handling code. Trace after the change: bash-2143 [003] d... 132.280697: wakeup_source_activate: BAT1 state=0x20001 kworker/3:2-1169 [003] d... 132.281305: wakeup_source_deactivate: BAT1 state=0x30000 Oops message: [ 819.769934] device: 'BAT1': device_add [ 819.770078] PM: Adding info for No Bus:BAT1 [ 819.770235] BUG: unable to handle kernel NULL pointer dereference at (null) [ 819.770435] IP: [<ffffffff813381c0>] skip_spaces+0x30/0x30 [ 819.770572] PGD 3efd90067 PUD 3eff61067 PMD 0 [ 819.770716] Oops: 0000 [#1] SMP [ 819.770829] Modules linked in: arc4 iwldvm mac80211 x86_pkg_temp_thermal coretemp kvm_intel joydev i915 kvm uvcvideo ghash_clmulni_intel videobuf2_vmalloc aesni_intel videobuf2_memops videobuf2_core aes_x86_64 ablk_helper cryptd videodev iwlwifi lrw rfcomm gf128mul glue_helper bnep btusb media bluetooth parport_pc hid_generic ppdev snd_hda_codec_hdmi drm_kms_helper snd_hda_codec_realtek cfg80211 drm tpm_infineon samsung_laptop snd_hda_intel usbhid snd_hda_codec hid snd_hwdep snd_pcm microcode snd_page_alloc snd_timer psmouse i2c_algo_bit lpc_ich tpm_tis video wmi mac_hid serio_raw ext2 lp parport r8169 mii [ 819.771802] CPU: 0 PID: 2167 Comm: bash Not tainted 3.12.0+ #25 [ 819.771876] Hardware name: SAMSUNG ELECTRONICS CO., LTD. 900X3C/900X3D/900X4C/900X4D/SAMSUNG_NP1234567890, BIOS P03AAC 07/12/2012 [ 819.772022] task: ffff88002e6ddcc0 ti: ffff8804015ca000 task.ti: ffff8804015ca000 [ 819.772119] RIP: 0010:[<ffffffff813381c0>] [<ffffffff813381c0>] skip_spaces+0x30/0x30 [ 819.772242] RSP: 0018:ffff8804015cbc70 EFLAGS: 00010046 [ 819.772310] RAX: 0000000000000003 RBX: ffff88040cfd6d40 RCX: 0000000000000018 [ 819.772397] RDX: 0000000000020001 RSI: 0000000000000000 RDI: 0000000000000000 [ 819.772484] RBP: ffff8804015cbcc0 R08: 0000000000000000 R09: ffff8803f0768d40 [ 819.772570] R10: ffffea001033b800 R11: 0000000000000000 R12: ffffffff81c519c0 [ 819.772656] R13: 0000000000020001 R14: 0000000000000000 R15: 0000000000020001 [ 819.772744] FS: 00007ff98309b740(0000) GS:ffff88041f200000(0000) knlGS:0000000000000000 [ 819.772845] CS: 0010 DS: 0000 ES: 0000 CR0: 0000000080050033 [ 819.772917] CR2: 0000000000000000 CR3: 00000003f59dc000 CR4: 00000000001407f0 [ 819.773001] Stack: [ 819.773030] ffffffff81114003 ffff8804015cbcb0 0000000000000000 0000000000000046 [ 819.773146] ffff880409757a18 ffff8803f065a160 0000000000000000 0000000000020001 [ 819.773273] 0000000000000000 0000000000000000 ffff8804015cbce8 ffffffff8143e388 [ 819.773387] Call Trace: [ 819.773434] [<ffffffff81114003>] ? ftrace_raw_event_wakeup_source+0x43/0xe0 [ 819.773520] [<ffffffff8143e388>] wakeup_source_report_event+0xb8/0xd0 [ 819.773595] [<ffffffff8143e3cd>] __pm_stay_awake+0x2d/0x50 [ 819.773724] [<ffffffff8153395c>] power_supply_changed+0x3c/0x90 [ 819.773795] [<ffffffff8153407c>] power_supply_register+0x18c/0x250 [ 819.773869] [<ffffffff813d8d18>] sysfs_add_battery+0x61/0x7b [ 819.773935] [<ffffffff813d8d69>] battery_notify+0x37/0x3f [ 819.774001] [<ffffffff816ccb7c>] notifier_call_chain+0x4c/0x70 [ 819.774071] [<ffffffff81073ded>] __blocking_notifier_call_chain+0x4d/0x70 [ 819.774149] [<ffffffff81073e26>] blocking_notifier_call_chain+0x16/0x20 [ 819.774227] [<ffffffff8109397a>] pm_notifier_call_chain+0x1a/0x40 [ 819.774316] [<ffffffff81095b66>] hibernate+0x66/0x1c0 [ 819.774407] [<ffffffff81093931>] state_store+0x71/0xa0 [ 819.774507] [<ffffffff81331d8f>] kobj_attr_store+0xf/0x20 [ 819.774613] [<ffffffff811f8618>] sysfs_write_file+0x128/0x1c0 [ 819.774735] [<ffffffff8118579d>] vfs_write+0xbd/0x1e0 [ 819.774841] [<ffffffff811861d9>] SyS_write+0x49/0xa0 [ 819.774939] [<ffffffff816d1052>] system_call_fastpath+0x16/0x1b [ 819.775055] Code: 89 f8 48 89 e5 f6 82 c0 a6 84 81 20 74 15 0f 1f 44 00 00 48 83 c0 01 0f b6 10 f6 82 c0 a6 84 81 20 75 f0 5d c3 66 0f 1f 44 00 00 <80> 3f 00 55 48 89 e5 74 15 48 89 f8 0f 1f 40 00 48 83 c0 01 80 [ 819.775760] RIP [<ffffffff813381c0>] skip_spaces+0x30/0x30 [ 819.775881] RSP <ffff8804015cbc70> [ 819.775949] CR2: 0000000000000000 [ 819.794175] ---[ end trace c4ef25127039952e ]--- Signed-off-by: Shuah Khan <shuah.kh@samsung.com> Acked-by: Anton Vorontsov <anton@enomsg.org> Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org> Cc: stable@vger.kernel.org Signed-off-by: Anton Vorontsov <anton@enomsg.org>
2013-08-27power_supply: Prevent suspend until power supply events are processedZoran Markovic1-6/+32
This patch, originally authored by Arve Hjonnevag and Todd Poynor, prevents the system from entering suspend mode until the power supply plug, unplug, or any other change of state event is fully processed. This guarantees that the screen lights up and displays the battery charging state. The implementation uses the power supply wakeup_source object. Cc: David Woodhouse <dwmw2@infradead.org> Cc: Arve Hjonnevag <arve@android.com> Cc: Todd Poynor <toddpoynor@google.com> Cc: John Stultz <john.stultz@linaro.org> Signed-off-by: Zoran Markovic <zoran.markovic@linaro.org> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
2013-06-28power_supply: Add of_node_put to fix refcountRhyland Klein1-0/+4
of_parse_phandle increments the refcount for a dt node before returning it. Add of_node_put where needed to properly decrement the refcount when we are done using a given node. Signed-off-by: Rhyland Klein <rklein@nvidia.com> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
2013-04-16power_supply: Populate supplied_from hierarchy from the device treeRhyland Klein1-0/+140
With this patch the power_supply_core will try to populate supplied_from hierarchy from the device tree. Signed-off-by: Rhyland Klein <rklein@nvidia.com> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
2013-04-16power_supply: Add core support for supplied_fromRhyland Klein1-13/+34
This patch adds support for supplies to register a list of char *'s which represent the list of supplies which supply them. This is the opposite as the supplied_to list. This change maintains support for supplied_to until all drivers which make use of it already are converted. Signed-off-by: Rhyland Klein <rklein@nvidia.com> Reviewed-by: Stephen Warren <swarren@nvidia.com> Signed-off-by: Anton Vorontsov <anton@enomsg.org>
2013-02-06driver-core: constify data for class_find_device()Michał Mirosław1-2/+2
All in-kernel users of class_find_device() don't really need mutable data for match callback. In two places (kernel/power/suspend_test.c, drivers/scsi/osd/osd_uld.c) this patch changes match callbacks to use const search data. The const is propagated to rtc_class_open() and power_supply_get_by_name() parameters. Note that there's a dev reference leak in suspend_test.c that's not touched in this patch. Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl> Acked-by: Grant Likely <grant.likely@secretlab.ca> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2012-12-13Merge tag 'for-v3.8-merged' of git://git.infradead.org/battery-2.6Linus Torvalds1-0/+96
Pull battery subsystem updates from Anton Vorontsov: "Highlights: - Two new drivers from Pali Rohár and N900 hackers: rx51_battery and bq2415x_charger. The drivers are a part of a solution to replace the proprietary Nokia BME stack - Power supply core now registers devices with a thermal cooling subsystem, so we can now automatically throttle charging. Thanks to Ramakrishna Pallala! - Device tree support for ab8500 and max8925_power drivers - Random fixups and enhancements for a bunch of drivers." * tag 'for-v3.8-merged' of git://git.infradead.org/battery-2.6: (22 commits) max8925_power: Add support for device-tree initialization ab8500: Add devicetree support for chargalg ab8500: Add devicetree support for charger ab8500: Add devicetree support for btemp ab8500: Add devicetree support for fuelgauge twl4030_charger: Change TWL4030_MODULE_* ids to TWL_MODULE_* jz4740-battery: Use devm_request_and_ioremap jz4740-battery: Use devm_kzalloc bq27x00_battery: Fixup nominal available capacity reporting bq2415x_charger: Fix style issues bq2415x_charger: Add Kconfig/Makefile entries power_supply: Add bq2415x charger driver power_supply: Add new Nokia RX-51 (N900) power supply battery driver max17042_battery: Fix missing verify_model_lock() return value check ds2782_battery: Fix signedness bug in ds278x_read_reg16() lp8788-charger: Fix ADC channel names lp8788-charger: Fix wrong ADC conversion lp8788-charger: Use consumer device name on setting IIO channels power_supply: Register power supply for thermal cooling device power_supply: Add support for CHARGE_CONTROL_* attributes ...
2012-11-17power_supply: Register power supply for thermal cooling deviceRamakrishna Pallala1-0/+96
This patch registers the power supply as a cooling device if the power supply has support for charge throttling. Now with this change low level drivers need not register with thermal framework as it is automatically done by power supply framework. Signed-off-by: Ramakrishna Pallala <ramakrishna.pallala@intel.com> Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
2012-11-05Thermal: Pass zone parameters as argument to tzd_registerDurgadoss R1-1/+1
This patch adds the thermal zone parameter as an argument to the tzd_register() function call; and updates other drivers using this function. Signed-off-by: Durgadoss R <durgadoss.r@intel.com> Signed-off-by: Zhang Rui <rui.zhang@intel.com>
2012-09-24Thermal: Remove tc1/tc2 in generic thermal layer.Zhang Rui1-1/+1
Remove tc1/tc2 in generic thermal layer. .get_trend() callback starts to take effect from this patch. Signed-off-by: Zhang Rui <rui.zhang@intel.com> Reviewed-by: Rafael J. Wysocki <rjw@sisk.pl> Reviewed-by: Valentin, Eduardo <eduardo.valentin@ti.com>
2012-07-31Merge with upstream to accommodate with thermal changesAnton Vorontsov1-1/+1
This merge is performed to take commit c56f5c0342dfee11a1 ("Thermal: Make Thermal trip points writeable") out of Linus' tree and then fixup power supply class. This is needed since thermal stuff added a new argument: CC drivers/power/power_supply_core.o drivers/power/power_supply_core.c: In function ‘psy_register_thermal’: drivers/power/power_supply_core.c:204:6: warning: passing argument 3 of ‘thermal_zone_device_register’ makes integer from pointer without a cast [enabled by default] include/linux/thermal.h:154:29: note: expected ‘int’ but argument is of type ‘struct power_supply *’ drivers/power/power_supply_core.c:204:6: error: too few arguments to function ‘thermal_zone_device_register’ include/linux/thermal.h:154:29: note: declared here make[1]: *** [drivers/power/power_supply_core.o] Error 1 make: *** [drivers/power/] Error 2 Signed-off-by: Anton Vorontsov <anton.vorontsov@linaro.org>
2012-06-17power_supply: Register battery as a thermal zoneJenny TC1-0/+65
Battery and charger contribute to Thermals in most of the embedded devices. So, it makes sense to identify them as Thermal zones in a particular platform. This patch registers a thermal zone if the power supply is reporting a temperature property. The thermal zone will be used by platform's thermal management solution. Signed-off-by: Jenny TC <jenny.tc@intel.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2012-01-07power_supply: Drop usage of nowarn variant of sysfs_create_link()Anton Vorontsov1-1/+1
The function is not exported to modules, plus we do want to catch anyone who tries to create complex hierarchy (in that case we'd need to change 'powers' symlink to a directory, probably under a different name to not break ABI). This patch fixes the following build error: ERROR: "sysfs_create_link_nowarn" [drivers/power/power_supply.ko] undefined! Reported-by: Stephen Rothwell <sfr@canb.auug.org.au> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2012-01-06power_supply: Assume mains power by defaultJean Delvare1-1/+11
If no power class device is found in power_supply_is_system_supplied(), the function currently returns 0, which basically means that the system is supposed to be running on battery. In practice, mobile devices tend to always implement at least one power class device and more often two (battery and AC adapter). Systems with no registered power class devices are more likely to be desktop systems, where the system is always powered by mains. So, change the default return value of power_supply_is_system_supplied() from 0 (running on battery) to 1 (running on mains.) Signed-off-by: Jean Delvare <jdelvare@suse.de> Cc: David Woodhouse <dwmw2@infradead.org> Cc: Matthew Garrett <mjg59@srcf.ucam.org> Cc: Alex Deucher <alexander.deucher@amd.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2011-12-09power_supply: allow a power supply to explicitly point to powered deviceJeremy Fitzhardinge1-0/+7
If a power supply has a scope of "Device", then allow the power supply to indicate what device it actually powers. This is represented in the power supply's sysfs directory as a symlink named "powers", which points to the sysfs directory of the powered device. If the device has children, then the sub-devices are also powered by the same power supply. Signed-off-by: Jeremy Fitzhardinge <jeremy@goop.org> Cc: Richard Hughes <richard@hughsie.com>
2011-02-22power_supply: Initialize changed_work before calling device_addLars-Peter Clausen1-2/+2
Calling device_add causes an inital uevent for that device to be generated. The power_supply uevent function calls the drivers get_property function, which might causes the driver to update its state, which again might causes the driver to call power_supply_changed(). Since the power_supplys changed_work has not been initialized at this point the behavior is undefined and can result in an OOPS. This patch fixes the issue by initializing the power_supplys changed_work prior to adding the power_supplys device to the device tree. Reported-by: Grazvydas Ignotas <notasas@gmail.com> Signed-off-by: Lars-Peter Clausen <lars@metafoo.de> Tested-by: Grazvydas Ignotas <notasas@gmail.com>
2010-12-22power_supply: Don't use flush_scheduled_work()Tejun Heo1-1/+1
flush_scheduled_work() is deprecated and scheduled to be removed. In battery drivers, the work can be canceled on probe failure and removal and should be flushed on suspend. Replace flush_scheduled_work() usages with direct cancels and flushes. Signed-off-by: Tejun Heo <tj@kernel.org> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2010-12-22power_supply: Fix use after free and memory leakVasiliy Kulikov1-2/+2
device_unregister() might free its argument. This leads to freed memory use in kfree(). Also use put_device() instead of kfree() as dev may be already used in another layer after call to device_add(). Signed-off-by: Vasiliy Kulikov <segoon@openwall.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2010-05-19power_supply: Use attribute groupsAnton Vorontsov1-14/+34
This fixes a race between power supply device and initial attributes creation, plus makes it possible to implement writable properties. [Daniel Mack - removed superflous return statement and dropped .mode attribute from POWER_SUPPLY_ATTR] Suggested-by: Greg KH <gregkh@suse.de> Suggested-by: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com> Tested-by: Daniel Mack <daniel@caiaq.de>
2009-07-30power_supply: get_by_name and set_charged functionalityDaniel Mack1-0/+28
This adds a function that indicates that a battery is fully charged. It also includes functions to get a power_supply device from the class of registered devices by name reference. These can be used to find a specific battery to call power_supply_set_battery_charged() on. Some battery drivers might need this information to calibrate themselves. Signed-off-by: Daniel Mack <daniel@caiaq.de> Cc: Ian Molton <spyro@f2s.com> Cc: Anton Vorontsov <cbou@mail.ru> Cc: Matt Reimer <mreimer@vpop.net> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2009-07-30power_supply: EXPORT_SYMBOL cleanupsDaniel Mack1-9/+7
While I'm at it, cleanup the power supply code so that EXPORT_SYMBOL_GPL appears directly after the symbole declaration. checkpatch.pl wants it that way. Signed-off-by: Daniel Mack <daniel@caiaq.de> Cc: Ian Molton <spyro@f2s.com> Cc: Matt Reimer <mreimer@vpop.net> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2008-10-18Merge branch 'master' of git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6Anton Vorontsov1-2/+2
Conflicts: drivers/power/Makefile
2008-10-16device create: misc: convert device_create_drvdata to device_createGreg Kroah-Hartman1-2/+2
Now that device_create() has been audited, rename things back to the original call to be sane. Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-09-01power_supply: Add function to return system-wide power stateMatthew Garrett1-0/+25
Certain drivers benefit from knowing whether the system is on ac or battery, for instance when determining which backlight registers to read. This adds a simple call to determine whether there's an online power supply other than any batteries. Signed-off-by: Matthew Garrett <mjg@redhat.com> Signed-off-by: Anton Vorontsov <cbouatmailru@gmail.com>
2008-07-21Driver Core: add ability for class_for_each_device to start in middle of listGreg Kroah-Hartman1-2/+2
This mirrors the functionality that driver_for_each_device has as well. We add a start variable, and all callers of the function are fixed up at the same time. The block layer will be using this new functionality in a follow-on patch. Cc: Kay Sievers <kay.sievers@vrfy.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-05-20Power Supply: fix race in device_createGreg Kroah-Hartman1-4/+2
There is a race from when a device is created with device_create() and then the drvdata is set with a call to dev_set_drvdata() in which a sysfs file could be open, yet the drvdata will be NULL, causing all sorts of bad things to happen. This patch fixes the problem by using the new function, device_create_drvdata(). Cc: Kay Sievers <kay.sievers@vrfy.org> Cc: Anton Vorontsov <cbou@mail.ru> Cc: David Woodhouse <dwmw2@infradead.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2008-04-29power: replace remaining __FUNCTION__ occurrencesHarvey Harrison1-3/+3
__FUNCTION__ is gcc-specific, use __func__ Signed-off-by: Harvey Harrison <harvey.harrison@gmail.com> Cc: Greg KH <greg@kroah.com> Cc: "Rafael J. Wysocki" <rjw@sisk.pl> Cc: Len Brown <lenb@kernel.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2008-01-24power supply : use class iteration apiDave Young1-35/+39
Convert to use the class iteration api. Signed-off-by: Dave Young <hidave.darkstar@gmail.com> Cc: Anton Vorontsov <cbou@mail.ru> Cc: David Woodhouse <dwmw2@infradead.org> Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
2007-07-15Power supply class and drivers: remove non obligatory return statementsAnton Vorontsov1-6/+0
Per Jeff Garzik request. Signed-off-by: Jeff Garzik <jeff@garzik.org> Signed-off-by: Anton Vorontsov <cbou@mail.ru>
2007-07-10[BATTERY] Universal power supply class (was: battery class)Anton Vorontsov1-0/+168
This class is result of "external power" and "battery" classes merge, as suggested by David Woodhouse. He also implemented uevent support. Here how userspace seeing it now: # ls /sys/class/power\ supply/ ac main-battery usb # cat /sys/class/power\ supply/ac/type AC # cat /sys/class/power\ supply/usb/type USB # cat /sys/class/power\ supply/main-battery/type Battery # cat /sys/class/power\ supply/ac/online 1 # cat /sys/class/power\ supply/usb/online 0 # cat /sys/class/power\ supply/main-battery/status Charging # cat /sys/class/leds/h5400\:red-left/trigger none h5400-radio timer hwtimer ac-online usb-online main-battery-charging-or-full [main-battery-charging] main-battery-full Signed-off-by: Anton Vorontsov <cbou@mail.ru> Signed-off-by: David Woodhouse <dwmw2@infradead.org> Signed-off-by: Andrew Morton <akpm@linux-foundation.org>