2 * Universal power supply monitor class
4 * Copyright © 2007 Anton Vorontsov <cbou@mail.ru>
5 * Copyright © 2004 Szabolcs Gyurko
6 * Copyright © 2003 Ian Molton <spyro@f2s.com>
8 * Modified: 2004, Oct Szabolcs Gyurko
10 * You may use this code as per GPL version 2
13 #include <linux/module.h>
14 #include <linux/types.h>
15 #include <linux/init.h>
16 #include <linux/slab.h>
17 #include <linux/delay.h>
18 #include <linux/device.h>
19 #include <linux/notifier.h>
20 #include <linux/err.h>
21 #include <linux/power_supply.h>
22 #include <linux/thermal.h>
23 #include "power_supply.h"
25 /* exported for the APM Power driver, APM emulation */
26 struct class *power_supply_class;
27 EXPORT_SYMBOL_GPL(power_supply_class);
29 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
30 EXPORT_SYMBOL_GPL(power_supply_notifier);
32 static struct device_type power_supply_dev_type;
34 #define POWER_SUPPLY_DEFERRED_REGISTER_TIME msecs_to_jiffies(10)
36 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
37 struct power_supply *supply)
41 if (!supply->supplied_from && !supplier->supplied_to)
44 /* Support both supplied_to and supplied_from modes */
45 if (supply->supplied_from) {
46 if (!supplier->desc->name)
48 for (i = 0; i < supply->num_supplies; i++)
49 if (!strcmp(supplier->desc->name, supply->supplied_from[i]))
52 if (!supply->desc->name)
54 for (i = 0; i < supplier->num_supplicants; i++)
55 if (!strcmp(supplier->supplied_to[i], supply->desc->name))
62 static int __power_supply_changed_work(struct device *dev, void *data)
64 struct power_supply *psy = data;
65 struct power_supply *pst = dev_get_drvdata(dev);
67 if (__power_supply_is_supplied_by(psy, pst)) {
68 if (pst->desc->external_power_changed)
69 pst->desc->external_power_changed(pst);
75 static void power_supply_changed_work(struct work_struct *work)
78 struct power_supply *psy = container_of(work, struct power_supply,
81 dev_dbg(&psy->dev, "%s\n", __func__);
83 spin_lock_irqsave(&psy->changed_lock, flags);
85 * Check 'changed' here to avoid issues due to race between
86 * power_supply_changed() and this routine. In worst case
87 * power_supply_changed() can be called again just before we take above
88 * lock. During the first call of this routine we will mark 'changed' as
89 * false and it will stay false for the next call as well.
91 if (likely(psy->changed)) {
93 spin_unlock_irqrestore(&psy->changed_lock, flags);
94 class_for_each_device(power_supply_class, NULL, psy,
95 __power_supply_changed_work);
96 power_supply_update_leds(psy);
97 atomic_notifier_call_chain(&power_supply_notifier,
98 PSY_EVENT_PROP_CHANGED, psy);
99 kobject_uevent(&psy->dev.kobj, KOBJ_CHANGE);
100 spin_lock_irqsave(&psy->changed_lock, flags);
104 * Hold the wakeup_source until all events are processed.
105 * power_supply_changed() might have called again and have set 'changed'
108 if (likely(!psy->changed))
110 spin_unlock_irqrestore(&psy->changed_lock, flags);
113 void power_supply_changed(struct power_supply *psy)
117 dev_dbg(&psy->dev, "%s\n", __func__);
119 spin_lock_irqsave(&psy->changed_lock, flags);
121 pm_stay_awake(&psy->dev);
122 spin_unlock_irqrestore(&psy->changed_lock, flags);
123 schedule_work(&psy->changed_work);
125 EXPORT_SYMBOL_GPL(power_supply_changed);
128 * Notify that power supply was registered after parent finished the probing.
130 * Often power supply is registered from driver's probe function. However
131 * calling power_supply_changed() directly from power_supply_register()
132 * would lead to execution of get_property() function provided by the driver
133 * too early - before the probe ends.
135 * Avoid that by waiting on parent's mutex.
137 static void power_supply_deferred_register_work(struct work_struct *work)
139 struct power_supply *psy = container_of(work, struct power_supply,
140 deferred_register_work.work);
142 if (psy->dev.parent) {
143 while (!mutex_trylock(&psy->dev.parent->mutex)) {
150 power_supply_changed(psy);
153 mutex_unlock(&psy->dev.parent->mutex);
157 #include <linux/of.h>
159 static int __power_supply_populate_supplied_from(struct device *dev,
162 struct power_supply *psy = data;
163 struct power_supply *epsy = dev_get_drvdata(dev);
164 struct device_node *np;
168 np = of_parse_phandle(psy->of_node, "power-supplies", i++);
172 if (np == epsy->of_node) {
173 dev_info(&psy->dev, "%s: Found supply : %s\n",
174 psy->desc->name, epsy->desc->name);
175 psy->supplied_from[i-1] = (char *)epsy->desc->name;
186 static int power_supply_populate_supplied_from(struct power_supply *psy)
190 error = class_for_each_device(power_supply_class, NULL, psy,
191 __power_supply_populate_supplied_from);
193 dev_dbg(&psy->dev, "%s %d\n", __func__, error);
198 static int __power_supply_find_supply_from_node(struct device *dev,
201 struct device_node *np = data;
202 struct power_supply *epsy = dev_get_drvdata(dev);
204 /* returning non-zero breaks out of class_for_each_device loop */
205 if (epsy->of_node == np)
211 static int power_supply_find_supply_from_node(struct device_node *supply_node)
216 * class_for_each_device() either returns its own errors or values
217 * returned by __power_supply_find_supply_from_node().
219 * __power_supply_find_supply_from_node() will return 0 (no match)
222 * We return 0 if class_for_each_device() returned 1, -EPROBE_DEFER if
223 * it returned 0, or error as returned by it.
225 error = class_for_each_device(power_supply_class, NULL, supply_node,
226 __power_supply_find_supply_from_node);
228 return error ? (error == 1 ? 0 : error) : -EPROBE_DEFER;
231 static int power_supply_check_supplies(struct power_supply *psy)
233 struct device_node *np;
236 /* If there is already a list honor it */
237 if (psy->supplied_from && psy->num_supplies > 0)
240 /* No device node found, nothing to do */
247 np = of_parse_phandle(psy->of_node, "power-supplies", cnt++);
251 ret = power_supply_find_supply_from_node(np);
255 dev_dbg(&psy->dev, "Failed to find supply!\n");
260 /* Missing valid "power-supplies" entries */
264 /* All supplies found, allocate char ** array for filling */
265 psy->supplied_from = devm_kzalloc(&psy->dev, sizeof(psy->supplied_from),
267 if (!psy->supplied_from) {
268 dev_err(&psy->dev, "Couldn't allocate memory for supply list\n");
272 *psy->supplied_from = devm_kzalloc(&psy->dev,
273 sizeof(char *) * (cnt - 1),
275 if (!*psy->supplied_from) {
276 dev_err(&psy->dev, "Couldn't allocate memory for supply list\n");
280 return power_supply_populate_supplied_from(psy);
283 static inline int power_supply_check_supplies(struct power_supply *psy)
289 static int __power_supply_am_i_supplied(struct device *dev, void *data)
291 union power_supply_propval ret = {0,};
292 struct power_supply *psy = data;
293 struct power_supply *epsy = dev_get_drvdata(dev);
295 if (__power_supply_is_supplied_by(epsy, psy))
296 if (!epsy->desc->get_property(epsy, POWER_SUPPLY_PROP_ONLINE,
303 int power_supply_am_i_supplied(struct power_supply *psy)
307 error = class_for_each_device(power_supply_class, NULL, psy,
308 __power_supply_am_i_supplied);
310 dev_dbg(&psy->dev, "%s %d\n", __func__, error);
314 EXPORT_SYMBOL_GPL(power_supply_am_i_supplied);
316 static int __power_supply_is_system_supplied(struct device *dev, void *data)
318 union power_supply_propval ret = {0,};
319 struct power_supply *psy = dev_get_drvdata(dev);
320 unsigned int *count = data;
323 if (psy->desc->type != POWER_SUPPLY_TYPE_BATTERY)
324 if (!psy->desc->get_property(psy, POWER_SUPPLY_PROP_ONLINE,
331 int power_supply_is_system_supplied(void)
334 unsigned int count = 0;
336 error = class_for_each_device(power_supply_class, NULL, &count,
337 __power_supply_is_system_supplied);
340 * If no power class device was found at all, most probably we are
341 * running on a desktop system, so assume we are on mains power.
348 EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);
350 int power_supply_set_battery_charged(struct power_supply *psy)
352 if (atomic_read(&psy->use_cnt) >= 0 &&
353 psy->desc->type == POWER_SUPPLY_TYPE_BATTERY &&
354 psy->desc->set_charged) {
355 psy->desc->set_charged(psy);
361 EXPORT_SYMBOL_GPL(power_supply_set_battery_charged);
363 static int power_supply_match_device_by_name(struct device *dev, const void *data)
365 const char *name = data;
366 struct power_supply *psy = dev_get_drvdata(dev);
368 return strcmp(psy->desc->name, name) == 0;
372 * power_supply_get_by_name() - Search for a power supply and returns its ref
373 * @name: Power supply name to fetch
375 * If power supply was found, it increases reference count for the
376 * internal power supply's device. The user should power_supply_put()
379 * Return: On success returns a reference to a power supply with
380 * matching name equals to @name, a NULL otherwise.
382 struct power_supply *power_supply_get_by_name(const char *name)
384 struct power_supply *psy = NULL;
385 struct device *dev = class_find_device(power_supply_class, NULL, name,
386 power_supply_match_device_by_name);
389 psy = dev_get_drvdata(dev);
390 atomic_inc(&psy->use_cnt);
395 EXPORT_SYMBOL_GPL(power_supply_get_by_name);
398 * power_supply_put() - Drop reference obtained with power_supply_get_by_name
399 * @psy: Reference to put
401 * The reference to power supply should be put before unregistering
404 void power_supply_put(struct power_supply *psy)
408 atomic_dec(&psy->use_cnt);
409 put_device(&psy->dev);
411 EXPORT_SYMBOL_GPL(power_supply_put);
414 static int power_supply_match_device_node(struct device *dev, const void *data)
416 return dev->parent && dev->parent->of_node == data;
420 * power_supply_get_by_phandle() - Search for a power supply and returns its ref
421 * @np: Pointer to device node holding phandle property
422 * @phandle_name: Name of property holding a power supply name
424 * If power supply was found, it increases reference count for the
425 * internal power supply's device. The user should power_supply_put()
428 * Return: On success returns a reference to a power supply with
429 * matching name equals to value under @property, NULL or ERR_PTR otherwise.
431 struct power_supply *power_supply_get_by_phandle(struct device_node *np,
432 const char *property)
434 struct device_node *power_supply_np;
435 struct power_supply *psy = NULL;
438 power_supply_np = of_parse_phandle(np, property, 0);
439 if (!power_supply_np)
440 return ERR_PTR(-ENODEV);
442 dev = class_find_device(power_supply_class, NULL, power_supply_np,
443 power_supply_match_device_node);
445 of_node_put(power_supply_np);
448 psy = dev_get_drvdata(dev);
449 atomic_inc(&psy->use_cnt);
454 EXPORT_SYMBOL_GPL(power_supply_get_by_phandle);
456 static void devm_power_supply_put(struct device *dev, void *res)
458 struct power_supply **psy = res;
460 power_supply_put(*psy);
464 * devm_power_supply_get_by_phandle() - Resource managed version of
465 * power_supply_get_by_phandle()
466 * @dev: Pointer to device holding phandle property
467 * @phandle_name: Name of property holding a power supply phandle
469 * Return: On success returns a reference to a power supply with
470 * matching name equals to value under @property, NULL or ERR_PTR otherwise.
472 struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,
473 const char *property)
475 struct power_supply **ptr, *psy;
478 return ERR_PTR(-ENODEV);
480 ptr = devres_alloc(devm_power_supply_put, sizeof(*ptr), GFP_KERNEL);
482 return ERR_PTR(-ENOMEM);
484 psy = power_supply_get_by_phandle(dev->of_node, property);
485 if (IS_ERR_OR_NULL(psy)) {
489 devres_add(dev, ptr);
493 EXPORT_SYMBOL_GPL(devm_power_supply_get_by_phandle);
494 #endif /* CONFIG_OF */
496 int power_supply_get_property(struct power_supply *psy,
497 enum power_supply_property psp,
498 union power_supply_propval *val)
500 if (atomic_read(&psy->use_cnt) <= 0) {
501 if (!psy->initialized)
506 return psy->desc->get_property(psy, psp, val);
508 EXPORT_SYMBOL_GPL(power_supply_get_property);
510 int power_supply_set_property(struct power_supply *psy,
511 enum power_supply_property psp,
512 const union power_supply_propval *val)
514 if (atomic_read(&psy->use_cnt) <= 0 || !psy->desc->set_property)
517 return psy->desc->set_property(psy, psp, val);
519 EXPORT_SYMBOL_GPL(power_supply_set_property);
521 int power_supply_property_is_writeable(struct power_supply *psy,
522 enum power_supply_property psp)
524 if (atomic_read(&psy->use_cnt) <= 0 ||
525 !psy->desc->property_is_writeable)
528 return psy->desc->property_is_writeable(psy, psp);
530 EXPORT_SYMBOL_GPL(power_supply_property_is_writeable);
532 void power_supply_external_power_changed(struct power_supply *psy)
534 if (atomic_read(&psy->use_cnt) <= 0 ||
535 !psy->desc->external_power_changed)
538 psy->desc->external_power_changed(psy);
540 EXPORT_SYMBOL_GPL(power_supply_external_power_changed);
542 int power_supply_powers(struct power_supply *psy, struct device *dev)
544 return sysfs_create_link(&psy->dev.kobj, &dev->kobj, "powers");
546 EXPORT_SYMBOL_GPL(power_supply_powers);
548 static void power_supply_dev_release(struct device *dev)
550 struct power_supply *psy = container_of(dev, struct power_supply, dev);
551 pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
555 int power_supply_reg_notifier(struct notifier_block *nb)
557 return atomic_notifier_chain_register(&power_supply_notifier, nb);
559 EXPORT_SYMBOL_GPL(power_supply_reg_notifier);
561 void power_supply_unreg_notifier(struct notifier_block *nb)
563 atomic_notifier_chain_unregister(&power_supply_notifier, nb);
565 EXPORT_SYMBOL_GPL(power_supply_unreg_notifier);
567 #ifdef CONFIG_THERMAL
568 static int power_supply_read_temp(struct thermal_zone_device *tzd,
571 struct power_supply *psy;
572 union power_supply_propval val;
575 WARN_ON(tzd == NULL);
577 ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_TEMP, &val);
581 /* Convert tenths of degree Celsius to milli degree Celsius. */
582 *temp = val.intval * 100;
587 static struct thermal_zone_device_ops psy_tzd_ops = {
588 .get_temp = power_supply_read_temp,
591 static int psy_register_thermal(struct power_supply *psy)
595 if (psy->desc->no_thermal)
598 /* Register battery zone device psy reports temperature */
599 for (i = 0; i < psy->desc->num_properties; i++) {
600 if (psy->desc->properties[i] == POWER_SUPPLY_PROP_TEMP) {
601 psy->tzd = thermal_zone_device_register(psy->desc->name,
602 0, 0, psy, &psy_tzd_ops, NULL, 0, 0);
603 return PTR_ERR_OR_ZERO(psy->tzd);
609 static void psy_unregister_thermal(struct power_supply *psy)
611 if (IS_ERR_OR_NULL(psy->tzd))
613 thermal_zone_device_unregister(psy->tzd);
616 /* thermal cooling device callbacks */
617 static int ps_get_max_charge_cntl_limit(struct thermal_cooling_device *tcd,
618 unsigned long *state)
620 struct power_supply *psy;
621 union power_supply_propval val;
625 ret = power_supply_get_property(psy,
626 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, &val);
635 static int ps_get_cur_chrage_cntl_limit(struct thermal_cooling_device *tcd,
636 unsigned long *state)
638 struct power_supply *psy;
639 union power_supply_propval val;
643 ret = power_supply_get_property(psy,
644 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
653 static int ps_set_cur_charge_cntl_limit(struct thermal_cooling_device *tcd,
656 struct power_supply *psy;
657 union power_supply_propval val;
662 ret = psy->desc->set_property(psy,
663 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
668 static struct thermal_cooling_device_ops psy_tcd_ops = {
669 .get_max_state = ps_get_max_charge_cntl_limit,
670 .get_cur_state = ps_get_cur_chrage_cntl_limit,
671 .set_cur_state = ps_set_cur_charge_cntl_limit,
674 static int psy_register_cooler(struct power_supply *psy)
678 /* Register for cooling device if psy can control charging */
679 for (i = 0; i < psy->desc->num_properties; i++) {
680 if (psy->desc->properties[i] ==
681 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT) {
682 psy->tcd = thermal_cooling_device_register(
683 (char *)psy->desc->name,
685 return PTR_ERR_OR_ZERO(psy->tcd);
691 static void psy_unregister_cooler(struct power_supply *psy)
693 if (IS_ERR_OR_NULL(psy->tcd))
695 thermal_cooling_device_unregister(psy->tcd);
698 static int psy_register_thermal(struct power_supply *psy)
703 static void psy_unregister_thermal(struct power_supply *psy)
707 static int psy_register_cooler(struct power_supply *psy)
712 static void psy_unregister_cooler(struct power_supply *psy)
717 static struct power_supply *__must_check
718 __power_supply_register(struct device *parent,
719 const struct power_supply_desc *desc,
720 const struct power_supply_config *cfg,
724 struct power_supply *psy;
728 pr_warn("%s: Expected proper parent device for '%s'\n",
729 __func__, desc->name);
731 psy = kzalloc(sizeof(*psy), GFP_KERNEL);
733 return ERR_PTR(-ENOMEM);
737 device_initialize(dev);
739 dev->class = power_supply_class;
740 dev->type = &power_supply_dev_type;
741 dev->parent = parent;
742 dev->release = power_supply_dev_release;
743 dev_set_drvdata(dev, psy);
746 psy->drv_data = cfg->drv_data;
747 psy->of_node = cfg->of_node;
748 psy->supplied_to = cfg->supplied_to;
749 psy->num_supplicants = cfg->num_supplicants;
752 rc = dev_set_name(dev, "%s", desc->name);
754 goto dev_set_name_failed;
756 INIT_WORK(&psy->changed_work, power_supply_changed_work);
757 INIT_DELAYED_WORK(&psy->deferred_register_work,
758 power_supply_deferred_register_work);
760 rc = power_supply_check_supplies(psy);
762 dev_info(dev, "Not all required supplies found, defer probe\n");
763 goto check_supplies_failed;
766 spin_lock_init(&psy->changed_lock);
767 rc = device_add(dev);
769 goto device_add_failed;
771 rc = device_init_wakeup(dev, ws);
773 goto wakeup_init_failed;
775 rc = psy_register_thermal(psy);
777 goto register_thermal_failed;
779 rc = psy_register_cooler(psy);
781 goto register_cooler_failed;
783 rc = power_supply_create_triggers(psy);
785 goto create_triggers_failed;
788 * Update use_cnt after any uevents (most notably from device_add()).
789 * We are here still during driver's probe but
790 * the power_supply_uevent() calls back driver's get_property
792 * 1. Driver did not assigned the returned struct power_supply,
793 * 2. Driver could not finish initialization (anything in its probe
794 * after calling power_supply_register()).
796 atomic_inc(&psy->use_cnt);
797 psy->initialized = true;
799 queue_delayed_work(system_power_efficient_wq,
800 &psy->deferred_register_work,
801 POWER_SUPPLY_DEFERRED_REGISTER_TIME);
805 create_triggers_failed:
806 psy_unregister_cooler(psy);
807 register_cooler_failed:
808 psy_unregister_thermal(psy);
809 register_thermal_failed:
813 check_supplies_failed:
820 * power_supply_register() - Register new power supply
821 * @parent: Device to be a parent of power supply's device, usually
822 * the device which probe function calls this
823 * @desc: Description of power supply, must be valid through whole
824 * lifetime of this power supply
825 * @cfg: Run-time specific configuration accessed during registering,
828 * Return: A pointer to newly allocated power_supply on success
829 * or ERR_PTR otherwise.
830 * Use power_supply_unregister() on returned power_supply pointer to release
833 struct power_supply *__must_check power_supply_register(struct device *parent,
834 const struct power_supply_desc *desc,
835 const struct power_supply_config *cfg)
837 return __power_supply_register(parent, desc, cfg, true);
839 EXPORT_SYMBOL_GPL(power_supply_register);
842 * power_supply_register_no_ws() - Register new non-waking-source power supply
843 * @parent: Device to be a parent of power supply's device, usually
844 * the device which probe function calls this
845 * @desc: Description of power supply, must be valid through whole
846 * lifetime of this power supply
847 * @cfg: Run-time specific configuration accessed during registering,
850 * Return: A pointer to newly allocated power_supply on success
851 * or ERR_PTR otherwise.
852 * Use power_supply_unregister() on returned power_supply pointer to release
855 struct power_supply *__must_check
856 power_supply_register_no_ws(struct device *parent,
857 const struct power_supply_desc *desc,
858 const struct power_supply_config *cfg)
860 return __power_supply_register(parent, desc, cfg, false);
862 EXPORT_SYMBOL_GPL(power_supply_register_no_ws);
864 static void devm_power_supply_release(struct device *dev, void *res)
866 struct power_supply **psy = res;
868 power_supply_unregister(*psy);
872 * devm_power_supply_register() - Register managed power supply
873 * @parent: Device to be a parent of power supply's device, usually
874 * the device which probe function calls this
875 * @desc: Description of power supply, must be valid through whole
876 * lifetime of this power supply
877 * @cfg: Run-time specific configuration accessed during registering,
880 * Return: A pointer to newly allocated power_supply on success
881 * or ERR_PTR otherwise.
882 * The returned power_supply pointer will be automatically unregistered
885 struct power_supply *__must_check
886 devm_power_supply_register(struct device *parent,
887 const struct power_supply_desc *desc,
888 const struct power_supply_config *cfg)
890 struct power_supply **ptr, *psy;
892 ptr = devres_alloc(devm_power_supply_release, sizeof(*ptr), GFP_KERNEL);
895 return ERR_PTR(-ENOMEM);
896 psy = __power_supply_register(parent, desc, cfg, true);
901 devres_add(parent, ptr);
905 EXPORT_SYMBOL_GPL(devm_power_supply_register);
908 * devm_power_supply_register_no_ws() - Register managed non-waking-source power supply
909 * @parent: Device to be a parent of power supply's device, usually
910 * the device which probe function calls this
911 * @desc: Description of power supply, must be valid through whole
912 * lifetime of this power supply
913 * @cfg: Run-time specific configuration accessed during registering,
916 * Return: A pointer to newly allocated power_supply on success
917 * or ERR_PTR otherwise.
918 * The returned power_supply pointer will be automatically unregistered
921 struct power_supply *__must_check
922 devm_power_supply_register_no_ws(struct device *parent,
923 const struct power_supply_desc *desc,
924 const struct power_supply_config *cfg)
926 struct power_supply **ptr, *psy;
928 ptr = devres_alloc(devm_power_supply_release, sizeof(*ptr), GFP_KERNEL);
931 return ERR_PTR(-ENOMEM);
932 psy = __power_supply_register(parent, desc, cfg, false);
937 devres_add(parent, ptr);
941 EXPORT_SYMBOL_GPL(devm_power_supply_register_no_ws);
944 * power_supply_unregister() - Remove this power supply from system
945 * @psy: Pointer to power supply to unregister
947 * Remove this power supply from the system. The resources of power supply
948 * will be freed here or on last power_supply_put() call.
950 void power_supply_unregister(struct power_supply *psy)
952 WARN_ON(atomic_dec_return(&psy->use_cnt));
953 psy->removing = true;
954 cancel_work_sync(&psy->changed_work);
955 cancel_delayed_work_sync(&psy->deferred_register_work);
956 sysfs_remove_link(&psy->dev.kobj, "powers");
957 power_supply_remove_triggers(psy);
958 psy_unregister_cooler(psy);
959 psy_unregister_thermal(psy);
960 device_init_wakeup(&psy->dev, false);
961 device_unregister(&psy->dev);
963 EXPORT_SYMBOL_GPL(power_supply_unregister);
965 void *power_supply_get_drvdata(struct power_supply *psy)
967 return psy->drv_data;
969 EXPORT_SYMBOL_GPL(power_supply_get_drvdata);
971 static int __init power_supply_class_init(void)
973 power_supply_class = class_create(THIS_MODULE, "power_supply");
975 if (IS_ERR(power_supply_class))
976 return PTR_ERR(power_supply_class);
978 power_supply_class->dev_uevent = power_supply_uevent;
979 power_supply_init_attrs(&power_supply_dev_type);
984 static void __exit power_supply_class_exit(void)
986 class_destroy(power_supply_class);
989 subsys_initcall(power_supply_class_init);
990 module_exit(power_supply_class_exit);
992 MODULE_DESCRIPTION("Universal power supply monitor class");
993 MODULE_AUTHOR("Ian Molton <spyro@f2s.com>, "
995 "Anton Vorontsov <cbou@mail.ru>");
996 MODULE_LICENSE("GPL");