2 * Universal power supply monitor class
5 * Copyright © 2004 Szabolcs Gyurko
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/device.h>
18 #include <linux/notifier.h>
19 #include <linux/err.h>
20 #include <linux/power_supply.h>
21 #include <linux/thermal.h>
22 #include "power_supply.h"
24 /* exported for the APM Power driver, APM emulation */
25 struct class *power_supply_class;
26 EXPORT_SYMBOL_GPL(power_supply_class);
28 ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
29 EXPORT_SYMBOL_GPL(power_supply_notifier);
31 static struct device_type power_supply_dev_type;
33 #define POWER_SUPPLY_DEFERRED_REGISTER_TIME msecs_to_jiffies(10)
35 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
36 struct power_supply *supply)
40 if (!supply->supplied_from && !supplier->supplied_to)
43 /* Support both supplied_to and supplied_from modes */
44 if (supply->supplied_from) {
45 if (!supplier->desc->name)
47 for (i = 0; i < supply->num_supplies; i++)
48 if (!strcmp(supplier->desc->name, supply->supplied_from[i]))
51 if (!supply->desc->name)
53 for (i = 0; i < supplier->num_supplicants; i++)
54 if (!strcmp(supplier->supplied_to[i], supply->desc->name))
61 static int __power_supply_changed_work(struct device *dev, void *data)
63 struct power_supply *psy = data;
64 struct power_supply *pst = dev_get_drvdata(dev);
66 if (__power_supply_is_supplied_by(psy, pst)) {
67 if (pst->desc->external_power_changed)
68 pst->desc->external_power_changed(pst);
74 static void power_supply_changed_work(struct work_struct *work)
77 struct power_supply *psy = container_of(work, struct power_supply,
80 dev_dbg(&psy->dev, "%s\n", __func__);
82 spin_lock_irqsave(&psy->changed_lock, flags);
84 * Check 'changed' here to avoid issues due to race between
85 * power_supply_changed() and this routine. In worst case
86 * power_supply_changed() can be called again just before we take above
87 * lock. During the first call of this routine we will mark 'changed' as
88 * false and it will stay false for the next call as well.
90 if (likely(psy->changed)) {
92 spin_unlock_irqrestore(&psy->changed_lock, flags);
93 class_for_each_device(power_supply_class, NULL, psy,
94 __power_supply_changed_work);
95 power_supply_update_leds(psy);
96 atomic_notifier_call_chain(&power_supply_notifier,
97 PSY_EVENT_PROP_CHANGED, psy);
98 kobject_uevent(&psy->dev.kobj, KOBJ_CHANGE);
99 spin_lock_irqsave(&psy->changed_lock, flags);
103 * Hold the wakeup_source until all events are processed.
104 * power_supply_changed() might have called again and have set 'changed'
107 if (likely(!psy->changed))
109 spin_unlock_irqrestore(&psy->changed_lock, flags);
112 void power_supply_changed(struct power_supply *psy)
116 dev_dbg(&psy->dev, "%s\n", __func__);
118 spin_lock_irqsave(&psy->changed_lock, flags);
120 pm_stay_awake(&psy->dev);
121 spin_unlock_irqrestore(&psy->changed_lock, flags);
122 schedule_work(&psy->changed_work);
124 EXPORT_SYMBOL_GPL(power_supply_changed);
127 * Notify that power supply was registered after parent finished the probing.
129 * Often power supply is registered from driver's probe function. However
130 * calling power_supply_changed() directly from power_supply_register()
131 * would lead to execution of get_property() function provided by the driver
132 * too early - before the probe ends.
134 * Avoid that by waiting on parent's mutex.
136 static void power_supply_deferred_register_work(struct work_struct *work)
138 struct power_supply *psy = container_of(work, struct power_supply,
139 deferred_register_work.work);
142 mutex_lock(&psy->dev.parent->mutex);
144 power_supply_changed(psy);
147 mutex_unlock(&psy->dev.parent->mutex);
151 #include <linux/of.h>
153 static int __power_supply_populate_supplied_from(struct device *dev,
156 struct power_supply *psy = data;
157 struct power_supply *epsy = dev_get_drvdata(dev);
158 struct device_node *np;
162 np = of_parse_phandle(psy->of_node, "power-supplies", i++);
166 if (np == epsy->of_node) {
167 dev_info(&psy->dev, "%s: Found supply : %s\n",
168 psy->desc->name, epsy->desc->name);
169 psy->supplied_from[i-1] = (char *)epsy->desc->name;
180 static int power_supply_populate_supplied_from(struct power_supply *psy)
184 error = class_for_each_device(power_supply_class, NULL, psy,
185 __power_supply_populate_supplied_from);
187 dev_dbg(&psy->dev, "%s %d\n", __func__, error);
192 static int __power_supply_find_supply_from_node(struct device *dev,
195 struct device_node *np = data;
196 struct power_supply *epsy = dev_get_drvdata(dev);
198 /* returning non-zero breaks out of class_for_each_device loop */
199 if (epsy->of_node == np)
205 static int power_supply_find_supply_from_node(struct device_node *supply_node)
210 * class_for_each_device() either returns its own errors or values
211 * returned by __power_supply_find_supply_from_node().
213 * __power_supply_find_supply_from_node() will return 0 (no match)
216 * We return 0 if class_for_each_device() returned 1, -EPROBE_DEFER if
217 * it returned 0, or error as returned by it.
219 error = class_for_each_device(power_supply_class, NULL, supply_node,
220 __power_supply_find_supply_from_node);
222 return error ? (error == 1 ? 0 : error) : -EPROBE_DEFER;
225 static int power_supply_check_supplies(struct power_supply *psy)
227 struct device_node *np;
230 /* If there is already a list honor it */
231 if (psy->supplied_from && psy->num_supplies > 0)
234 /* No device node found, nothing to do */
241 np = of_parse_phandle(psy->of_node, "power-supplies", cnt++);
245 ret = power_supply_find_supply_from_node(np);
249 dev_dbg(&psy->dev, "Failed to find supply!\n");
254 /* Missing valid "power-supplies" entries */
258 /* All supplies found, allocate char ** array for filling */
259 psy->supplied_from = devm_kzalloc(&psy->dev, sizeof(psy->supplied_from),
261 if (!psy->supplied_from) {
262 dev_err(&psy->dev, "Couldn't allocate memory for supply list\n");
266 *psy->supplied_from = devm_kzalloc(&psy->dev,
267 sizeof(char *) * (cnt - 1),
269 if (!*psy->supplied_from) {
270 dev_err(&psy->dev, "Couldn't allocate memory for supply list\n");
274 return power_supply_populate_supplied_from(psy);
277 static inline int power_supply_check_supplies(struct power_supply *psy)
283 static int __power_supply_am_i_supplied(struct device *dev, void *data)
285 union power_supply_propval ret = {0,};
286 struct power_supply *psy = data;
287 struct power_supply *epsy = dev_get_drvdata(dev);
289 if (__power_supply_is_supplied_by(epsy, psy))
290 if (!epsy->desc->get_property(epsy, POWER_SUPPLY_PROP_ONLINE,
297 int power_supply_am_i_supplied(struct power_supply *psy)
301 error = class_for_each_device(power_supply_class, NULL, psy,
302 __power_supply_am_i_supplied);
304 dev_dbg(&psy->dev, "%s %d\n", __func__, error);
308 EXPORT_SYMBOL_GPL(power_supply_am_i_supplied);
310 static int __power_supply_is_system_supplied(struct device *dev, void *data)
312 union power_supply_propval ret = {0,};
313 struct power_supply *psy = dev_get_drvdata(dev);
314 unsigned int *count = data;
317 if (psy->desc->type != POWER_SUPPLY_TYPE_BATTERY)
318 if (!psy->desc->get_property(psy, POWER_SUPPLY_PROP_ONLINE,
325 int power_supply_is_system_supplied(void)
328 unsigned int count = 0;
330 error = class_for_each_device(power_supply_class, NULL, &count,
331 __power_supply_is_system_supplied);
334 * If no power class device was found at all, most probably we are
335 * running on a desktop system, so assume we are on mains power.
342 EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);
344 int power_supply_set_battery_charged(struct power_supply *psy)
346 if (atomic_read(&psy->use_cnt) >= 0 &&
347 psy->desc->type == POWER_SUPPLY_TYPE_BATTERY &&
348 psy->desc->set_charged) {
349 psy->desc->set_charged(psy);
355 EXPORT_SYMBOL_GPL(power_supply_set_battery_charged);
357 static int power_supply_match_device_by_name(struct device *dev, const void *data)
359 const char *name = data;
360 struct power_supply *psy = dev_get_drvdata(dev);
362 return strcmp(psy->desc->name, name) == 0;
366 * power_supply_get_by_name() - Search for a power supply and returns its ref
367 * @name: Power supply name to fetch
369 * If power supply was found, it increases reference count for the
370 * internal power supply's device. The user should power_supply_put()
373 * Return: On success returns a reference to a power supply with
374 * matching name equals to @name, a NULL otherwise.
376 struct power_supply *power_supply_get_by_name(const char *name)
378 struct power_supply *psy = NULL;
379 struct device *dev = class_find_device(power_supply_class, NULL, name,
380 power_supply_match_device_by_name);
383 psy = dev_get_drvdata(dev);
384 atomic_inc(&psy->use_cnt);
389 EXPORT_SYMBOL_GPL(power_supply_get_by_name);
392 * power_supply_put() - Drop reference obtained with power_supply_get_by_name
393 * @psy: Reference to put
395 * The reference to power supply should be put before unregistering
398 void power_supply_put(struct power_supply *psy)
402 atomic_dec(&psy->use_cnt);
403 put_device(&psy->dev);
405 EXPORT_SYMBOL_GPL(power_supply_put);
408 static int power_supply_match_device_node(struct device *dev, const void *data)
410 return dev->parent && dev->parent->of_node == data;
414 * power_supply_get_by_phandle() - Search for a power supply and returns its ref
415 * @np: Pointer to device node holding phandle property
416 * @phandle_name: Name of property holding a power supply name
418 * If power supply was found, it increases reference count for the
419 * internal power supply's device. The user should power_supply_put()
422 * Return: On success returns a reference to a power supply with
423 * matching name equals to value under @property, NULL or ERR_PTR otherwise.
425 struct power_supply *power_supply_get_by_phandle(struct device_node *np,
426 const char *property)
428 struct device_node *power_supply_np;
429 struct power_supply *psy = NULL;
432 power_supply_np = of_parse_phandle(np, property, 0);
433 if (!power_supply_np)
434 return ERR_PTR(-ENODEV);
436 dev = class_find_device(power_supply_class, NULL, power_supply_np,
437 power_supply_match_device_node);
439 of_node_put(power_supply_np);
442 psy = dev_get_drvdata(dev);
443 atomic_inc(&psy->use_cnt);
448 EXPORT_SYMBOL_GPL(power_supply_get_by_phandle);
450 static void devm_power_supply_put(struct device *dev, void *res)
452 struct power_supply **psy = res;
454 power_supply_put(*psy);
458 * devm_power_supply_get_by_phandle() - Resource managed version of
459 * power_supply_get_by_phandle()
460 * @dev: Pointer to device holding phandle property
461 * @phandle_name: Name of property holding a power supply phandle
463 * Return: On success returns a reference to a power supply with
464 * matching name equals to value under @property, NULL or ERR_PTR otherwise.
466 struct power_supply *devm_power_supply_get_by_phandle(struct device *dev,
467 const char *property)
469 struct power_supply **ptr, *psy;
472 return ERR_PTR(-ENODEV);
474 ptr = devres_alloc(devm_power_supply_put, sizeof(*ptr), GFP_KERNEL);
476 return ERR_PTR(-ENOMEM);
478 psy = power_supply_get_by_phandle(dev->of_node, property);
479 if (IS_ERR_OR_NULL(psy)) {
483 devres_add(dev, ptr);
487 EXPORT_SYMBOL_GPL(devm_power_supply_get_by_phandle);
488 #endif /* CONFIG_OF */
490 int power_supply_get_property(struct power_supply *psy,
491 enum power_supply_property psp,
492 union power_supply_propval *val)
494 if (atomic_read(&psy->use_cnt) <= 0) {
495 if (!psy->initialized)
500 return psy->desc->get_property(psy, psp, val);
502 EXPORT_SYMBOL_GPL(power_supply_get_property);
504 int power_supply_set_property(struct power_supply *psy,
505 enum power_supply_property psp,
506 const union power_supply_propval *val)
508 if (atomic_read(&psy->use_cnt) <= 0 || !psy->desc->set_property)
511 return psy->desc->set_property(psy, psp, val);
513 EXPORT_SYMBOL_GPL(power_supply_set_property);
515 int power_supply_property_is_writeable(struct power_supply *psy,
516 enum power_supply_property psp)
518 if (atomic_read(&psy->use_cnt) <= 0 ||
519 !psy->desc->property_is_writeable)
522 return psy->desc->property_is_writeable(psy, psp);
524 EXPORT_SYMBOL_GPL(power_supply_property_is_writeable);
526 void power_supply_external_power_changed(struct power_supply *psy)
528 if (atomic_read(&psy->use_cnt) <= 0 ||
529 !psy->desc->external_power_changed)
532 psy->desc->external_power_changed(psy);
534 EXPORT_SYMBOL_GPL(power_supply_external_power_changed);
536 int power_supply_powers(struct power_supply *psy, struct device *dev)
538 return sysfs_create_link(&psy->dev.kobj, &dev->kobj, "powers");
540 EXPORT_SYMBOL_GPL(power_supply_powers);
542 static void power_supply_dev_release(struct device *dev)
544 struct power_supply *psy = container_of(dev, struct power_supply, dev);
545 pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
549 int power_supply_reg_notifier(struct notifier_block *nb)
551 return atomic_notifier_chain_register(&power_supply_notifier, nb);
553 EXPORT_SYMBOL_GPL(power_supply_reg_notifier);
555 void power_supply_unreg_notifier(struct notifier_block *nb)
557 atomic_notifier_chain_unregister(&power_supply_notifier, nb);
559 EXPORT_SYMBOL_GPL(power_supply_unreg_notifier);
561 #ifdef CONFIG_THERMAL
562 static int power_supply_read_temp(struct thermal_zone_device *tzd,
565 struct power_supply *psy;
566 union power_supply_propval val;
569 WARN_ON(tzd == NULL);
571 ret = power_supply_get_property(psy, POWER_SUPPLY_PROP_TEMP, &val);
575 /* Convert tenths of degree Celsius to milli degree Celsius. */
576 *temp = val.intval * 100;
581 static struct thermal_zone_device_ops psy_tzd_ops = {
582 .get_temp = power_supply_read_temp,
585 static int psy_register_thermal(struct power_supply *psy)
589 if (psy->desc->no_thermal)
592 /* Register battery zone device psy reports temperature */
593 for (i = 0; i < psy->desc->num_properties; i++) {
594 if (psy->desc->properties[i] == POWER_SUPPLY_PROP_TEMP) {
595 psy->tzd = thermal_zone_device_register(psy->desc->name,
596 0, 0, psy, &psy_tzd_ops, NULL, 0, 0);
597 return PTR_ERR_OR_ZERO(psy->tzd);
603 static void psy_unregister_thermal(struct power_supply *psy)
605 if (IS_ERR_OR_NULL(psy->tzd))
607 thermal_zone_device_unregister(psy->tzd);
610 /* thermal cooling device callbacks */
611 static int ps_get_max_charge_cntl_limit(struct thermal_cooling_device *tcd,
612 unsigned long *state)
614 struct power_supply *psy;
615 union power_supply_propval val;
619 ret = power_supply_get_property(psy,
620 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, &val);
629 static int ps_get_cur_chrage_cntl_limit(struct thermal_cooling_device *tcd,
630 unsigned long *state)
632 struct power_supply *psy;
633 union power_supply_propval val;
637 ret = power_supply_get_property(psy,
638 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
647 static int ps_set_cur_charge_cntl_limit(struct thermal_cooling_device *tcd,
650 struct power_supply *psy;
651 union power_supply_propval val;
656 ret = psy->desc->set_property(psy,
657 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
662 static struct thermal_cooling_device_ops psy_tcd_ops = {
663 .get_max_state = ps_get_max_charge_cntl_limit,
664 .get_cur_state = ps_get_cur_chrage_cntl_limit,
665 .set_cur_state = ps_set_cur_charge_cntl_limit,
668 static int psy_register_cooler(struct power_supply *psy)
672 /* Register for cooling device if psy can control charging */
673 for (i = 0; i < psy->desc->num_properties; i++) {
674 if (psy->desc->properties[i] ==
675 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT) {
676 psy->tcd = thermal_cooling_device_register(
677 (char *)psy->desc->name,
679 return PTR_ERR_OR_ZERO(psy->tcd);
685 static void psy_unregister_cooler(struct power_supply *psy)
687 if (IS_ERR_OR_NULL(psy->tcd))
689 thermal_cooling_device_unregister(psy->tcd);
692 static int psy_register_thermal(struct power_supply *psy)
697 static void psy_unregister_thermal(struct power_supply *psy)
701 static int psy_register_cooler(struct power_supply *psy)
706 static void psy_unregister_cooler(struct power_supply *psy)
711 static struct power_supply *__must_check
712 __power_supply_register(struct device *parent,
713 const struct power_supply_desc *desc,
714 const struct power_supply_config *cfg,
718 struct power_supply *psy;
722 pr_warn("%s: Expected proper parent device for '%s'\n",
723 __func__, desc->name);
725 psy = kzalloc(sizeof(*psy), GFP_KERNEL);
727 return ERR_PTR(-ENOMEM);
731 device_initialize(dev);
733 dev->class = power_supply_class;
734 dev->type = &power_supply_dev_type;
735 dev->parent = parent;
736 dev->release = power_supply_dev_release;
737 dev_set_drvdata(dev, psy);
740 psy->drv_data = cfg->drv_data;
741 psy->of_node = cfg->of_node;
742 psy->supplied_to = cfg->supplied_to;
743 psy->num_supplicants = cfg->num_supplicants;
746 rc = dev_set_name(dev, "%s", desc->name);
748 goto dev_set_name_failed;
750 INIT_WORK(&psy->changed_work, power_supply_changed_work);
751 INIT_DELAYED_WORK(&psy->deferred_register_work,
752 power_supply_deferred_register_work);
754 rc = power_supply_check_supplies(psy);
756 dev_info(dev, "Not all required supplies found, defer probe\n");
757 goto check_supplies_failed;
760 spin_lock_init(&psy->changed_lock);
761 rc = device_init_wakeup(dev, ws);
763 goto wakeup_init_failed;
765 rc = device_add(dev);
767 goto device_add_failed;
769 rc = psy_register_thermal(psy);
771 goto register_thermal_failed;
773 rc = psy_register_cooler(psy);
775 goto register_cooler_failed;
777 rc = power_supply_create_triggers(psy);
779 goto create_triggers_failed;
782 * Update use_cnt after any uevents (most notably from device_add()).
783 * We are here still during driver's probe but
784 * the power_supply_uevent() calls back driver's get_property
786 * 1. Driver did not assigned the returned struct power_supply,
787 * 2. Driver could not finish initialization (anything in its probe
788 * after calling power_supply_register()).
790 atomic_inc(&psy->use_cnt);
791 psy->initialized = true;
793 queue_delayed_work(system_power_efficient_wq,
794 &psy->deferred_register_work,
795 POWER_SUPPLY_DEFERRED_REGISTER_TIME);
799 create_triggers_failed:
800 psy_unregister_cooler(psy);
801 register_cooler_failed:
802 psy_unregister_thermal(psy);
803 register_thermal_failed:
807 check_supplies_failed:
814 * power_supply_register() - Register new power supply
815 * @parent: Device to be a parent of power supply's device, usually
816 * the device which probe function calls this
817 * @desc: Description of power supply, must be valid through whole
818 * lifetime of this power supply
819 * @cfg: Run-time specific configuration accessed during registering,
822 * Return: A pointer to newly allocated power_supply on success
823 * or ERR_PTR otherwise.
824 * Use power_supply_unregister() on returned power_supply pointer to release
827 struct power_supply *__must_check power_supply_register(struct device *parent,
828 const struct power_supply_desc *desc,
829 const struct power_supply_config *cfg)
831 return __power_supply_register(parent, desc, cfg, true);
833 EXPORT_SYMBOL_GPL(power_supply_register);
836 * power_supply_register_no_ws() - Register new non-waking-source power supply
837 * @parent: Device to be a parent of power supply's device, usually
838 * the device which probe function calls this
839 * @desc: Description of power supply, must be valid through whole
840 * lifetime of this power supply
841 * @cfg: Run-time specific configuration accessed during registering,
844 * Return: A pointer to newly allocated power_supply on success
845 * or ERR_PTR otherwise.
846 * Use power_supply_unregister() on returned power_supply pointer to release
849 struct power_supply *__must_check
850 power_supply_register_no_ws(struct device *parent,
851 const struct power_supply_desc *desc,
852 const struct power_supply_config *cfg)
854 return __power_supply_register(parent, desc, cfg, false);
856 EXPORT_SYMBOL_GPL(power_supply_register_no_ws);
858 static void devm_power_supply_release(struct device *dev, void *res)
860 struct power_supply **psy = res;
862 power_supply_unregister(*psy);
866 * devm_power_supply_register() - Register managed power supply
867 * @parent: Device to be a parent of power supply's device, usually
868 * the device which probe function calls this
869 * @desc: Description of power supply, must be valid through whole
870 * lifetime of this power supply
871 * @cfg: Run-time specific configuration accessed during registering,
874 * Return: A pointer to newly allocated power_supply on success
875 * or ERR_PTR otherwise.
876 * The returned power_supply pointer will be automatically unregistered
879 struct power_supply *__must_check
880 devm_power_supply_register(struct device *parent,
881 const struct power_supply_desc *desc,
882 const struct power_supply_config *cfg)
884 struct power_supply **ptr, *psy;
886 ptr = devres_alloc(devm_power_supply_release, sizeof(*ptr), GFP_KERNEL);
889 return ERR_PTR(-ENOMEM);
890 psy = __power_supply_register(parent, desc, cfg, true);
895 devres_add(parent, ptr);
899 EXPORT_SYMBOL_GPL(devm_power_supply_register);
902 * devm_power_supply_register_no_ws() - Register managed non-waking-source power supply
903 * @parent: Device to be a parent of power supply's device, usually
904 * the device which probe function calls this
905 * @desc: Description of power supply, must be valid through whole
906 * lifetime of this power supply
907 * @cfg: Run-time specific configuration accessed during registering,
910 * Return: A pointer to newly allocated power_supply on success
911 * or ERR_PTR otherwise.
912 * The returned power_supply pointer will be automatically unregistered
915 struct power_supply *__must_check
916 devm_power_supply_register_no_ws(struct device *parent,
917 const struct power_supply_desc *desc,
918 const struct power_supply_config *cfg)
920 struct power_supply **ptr, *psy;
922 ptr = devres_alloc(devm_power_supply_release, sizeof(*ptr), GFP_KERNEL);
925 return ERR_PTR(-ENOMEM);
926 psy = __power_supply_register(parent, desc, cfg, false);
931 devres_add(parent, ptr);
935 EXPORT_SYMBOL_GPL(devm_power_supply_register_no_ws);
938 * power_supply_unregister() - Remove this power supply from system
939 * @psy: Pointer to power supply to unregister
941 * Remove this power supply from the system. The resources of power supply
942 * will be freed here or on last power_supply_put() call.
944 void power_supply_unregister(struct power_supply *psy)
946 WARN_ON(atomic_dec_return(&psy->use_cnt));
947 cancel_work_sync(&psy->changed_work);
948 cancel_delayed_work_sync(&psy->deferred_register_work);
949 sysfs_remove_link(&psy->dev.kobj, "powers");
950 power_supply_remove_triggers(psy);
951 psy_unregister_cooler(psy);
952 psy_unregister_thermal(psy);
953 device_init_wakeup(&psy->dev, false);
954 device_unregister(&psy->dev);
956 EXPORT_SYMBOL_GPL(power_supply_unregister);
958 void *power_supply_get_drvdata(struct power_supply *psy)
960 return psy->drv_data;
962 EXPORT_SYMBOL_GPL(power_supply_get_drvdata);
964 static int __init power_supply_class_init(void)
966 power_supply_class = class_create(THIS_MODULE, "power_supply");
968 if (IS_ERR(power_supply_class))
969 return PTR_ERR(power_supply_class);
971 power_supply_class->dev_uevent = power_supply_uevent;
972 power_supply_init_attrs(&power_supply_dev_type);
977 static void __exit power_supply_class_exit(void)
979 class_destroy(power_supply_class);
982 subsys_initcall(power_supply_class_init);
983 module_exit(power_supply_class_exit);
985 MODULE_DESCRIPTION("Universal power supply monitor class");
989 MODULE_LICENSE("GPL");