power_supply: Move run-time configuration to separate structure
[deliverable/linux.git] / drivers / power / power_supply_core.c
CommitLineData
4a11b59d
AV
1/*
2 * Universal power supply monitor class
3 *
4 * Copyright © 2007 Anton Vorontsov <cbou@mail.ru>
5 * Copyright © 2004 Szabolcs Gyurko
6 * Copyright © 2003 Ian Molton <spyro@f2s.com>
7 *
8 * Modified: 2004, Oct Szabolcs Gyurko
9 *
10 * You may use this code as per GPL version 2
11 */
12
13#include <linux/module.h>
14#include <linux/types.h>
15#include <linux/init.h>
5f487cd3 16#include <linux/slab.h>
4a11b59d 17#include <linux/device.h>
d36240d2 18#include <linux/notifier.h>
4a11b59d
AV
19#include <linux/err.h>
20#include <linux/power_supply.h>
3be330bf 21#include <linux/thermal.h>
4a11b59d
AV
22#include "power_supply.h"
23
ff3417e7 24/* exported for the APM Power driver, APM emulation */
4a11b59d 25struct class *power_supply_class;
ff3417e7 26EXPORT_SYMBOL_GPL(power_supply_class);
4a11b59d 27
d36240d2
PR
28ATOMIC_NOTIFIER_HEAD(power_supply_notifier);
29EXPORT_SYMBOL_GPL(power_supply_notifier);
30
5f487cd3
AV
31static struct device_type power_supply_dev_type;
32
5e0848c6
RK
33static bool __power_supply_is_supplied_by(struct power_supply *supplier,
34 struct power_supply *supply)
35{
36 int i;
37
38 if (!supply->supplied_from && !supplier->supplied_to)
39 return false;
40
41 /* Support both supplied_to and supplied_from modes */
42 if (supply->supplied_from) {
43 if (!supplier->name)
44 return false;
45 for (i = 0; i < supply->num_supplies; i++)
46 if (!strcmp(supplier->name, supply->supplied_from[i]))
47 return true;
48 } else {
49 if (!supply->name)
50 return false;
51 for (i = 0; i < supplier->num_supplicants; i++)
52 if (!strcmp(supplier->supplied_to[i], supply->name))
53 return true;
54 }
55
56 return false;
57}
58
443cad92
DY
59static int __power_supply_changed_work(struct device *dev, void *data)
60{
e80cf421 61 struct power_supply *psy = data;
443cad92 62 struct power_supply *pst = dev_get_drvdata(dev);
443cad92 63
5e0848c6
RK
64 if (__power_supply_is_supplied_by(psy, pst)) {
65 if (pst->external_power_changed)
66 pst->external_power_changed(pst);
67 }
68
443cad92
DY
69 return 0;
70}
71
4a11b59d
AV
72static void power_supply_changed_work(struct work_struct *work)
73{
948dcf96 74 unsigned long flags;
4a11b59d
AV
75 struct power_supply *psy = container_of(work, struct power_supply,
76 changed_work);
4a11b59d 77
0cddc0a9 78 dev_dbg(psy->dev, "%s\n", __func__);
4a11b59d 79
948dcf96 80 spin_lock_irqsave(&psy->changed_lock, flags);
061f3806
VK
81 /*
82 * Check 'changed' here to avoid issues due to race between
83 * power_supply_changed() and this routine. In worst case
84 * power_supply_changed() can be called again just before we take above
85 * lock. During the first call of this routine we will mark 'changed' as
86 * false and it will stay false for the next call as well.
87 */
88 if (likely(psy->changed)) {
948dcf96
ZM
89 psy->changed = false;
90 spin_unlock_irqrestore(&psy->changed_lock, flags);
91 class_for_each_device(power_supply_class, NULL, psy,
92 __power_supply_changed_work);
93 power_supply_update_leds(psy);
d36240d2
PR
94 atomic_notifier_call_chain(&power_supply_notifier,
95 PSY_EVENT_PROP_CHANGED, psy);
948dcf96
ZM
96 kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE);
97 spin_lock_irqsave(&psy->changed_lock, flags);
98 }
061f3806 99
948dcf96 100 /*
061f3806
VK
101 * Hold the wakeup_source until all events are processed.
102 * power_supply_changed() might have called again and have set 'changed'
103 * to true.
948dcf96 104 */
061f3806 105 if (likely(!psy->changed))
948dcf96
ZM
106 pm_relax(psy->dev);
107 spin_unlock_irqrestore(&psy->changed_lock, flags);
4a11b59d
AV
108}
109
110void power_supply_changed(struct power_supply *psy)
111{
948dcf96
ZM
112 unsigned long flags;
113
0cddc0a9 114 dev_dbg(psy->dev, "%s\n", __func__);
4a11b59d 115
948dcf96
ZM
116 spin_lock_irqsave(&psy->changed_lock, flags);
117 psy->changed = true;
118 pm_stay_awake(psy->dev);
119 spin_unlock_irqrestore(&psy->changed_lock, flags);
4a11b59d 120 schedule_work(&psy->changed_work);
4a11b59d 121}
ff3417e7 122EXPORT_SYMBOL_GPL(power_supply_changed);
4a11b59d 123
f6e0b081
RK
124#ifdef CONFIG_OF
125#include <linux/of.h>
126
127static int __power_supply_populate_supplied_from(struct device *dev,
128 void *data)
129{
e80cf421 130 struct power_supply *psy = data;
f6e0b081
RK
131 struct power_supply *epsy = dev_get_drvdata(dev);
132 struct device_node *np;
133 int i = 0;
134
135 do {
136 np = of_parse_phandle(psy->of_node, "power-supplies", i++);
137 if (!np)
a0f93b42 138 break;
f6e0b081
RK
139
140 if (np == epsy->of_node) {
141 dev_info(psy->dev, "%s: Found supply : %s\n",
142 psy->name, epsy->name);
143 psy->supplied_from[i-1] = (char *)epsy->name;
144 psy->num_supplies++;
2054d6e9 145 of_node_put(np);
f6e0b081
RK
146 break;
147 }
2054d6e9 148 of_node_put(np);
f6e0b081
RK
149 } while (np);
150
151 return 0;
152}
153
154static int power_supply_populate_supplied_from(struct power_supply *psy)
155{
156 int error;
157
158 error = class_for_each_device(power_supply_class, NULL, psy,
159 __power_supply_populate_supplied_from);
160
161 dev_dbg(psy->dev, "%s %d\n", __func__, error);
162
163 return error;
164}
165
166static int __power_supply_find_supply_from_node(struct device *dev,
167 void *data)
168{
e80cf421 169 struct device_node *np = data;
f6e0b081
RK
170 struct power_supply *epsy = dev_get_drvdata(dev);
171
585b0087 172 /* returning non-zero breaks out of class_for_each_device loop */
f6e0b081 173 if (epsy->of_node == np)
585b0087 174 return 1;
f6e0b081
RK
175
176 return 0;
177}
178
179static int power_supply_find_supply_from_node(struct device_node *supply_node)
180{
181 int error;
f6e0b081
RK
182
183 /*
585b0087
VK
184 * class_for_each_device() either returns its own errors or values
185 * returned by __power_supply_find_supply_from_node().
186 *
187 * __power_supply_find_supply_from_node() will return 0 (no match)
188 * or 1 (match).
189 *
190 * We return 0 if class_for_each_device() returned 1, -EPROBE_DEFER if
191 * it returned 0, or error as returned by it.
f6e0b081
RK
192 */
193 error = class_for_each_device(power_supply_class, NULL, supply_node,
194 __power_supply_find_supply_from_node);
195
585b0087 196 return error ? (error == 1 ? 0 : error) : -EPROBE_DEFER;
f6e0b081
RK
197}
198
199static int power_supply_check_supplies(struct power_supply *psy)
200{
201 struct device_node *np;
202 int cnt = 0;
203
204 /* If there is already a list honor it */
205 if (psy->supplied_from && psy->num_supplies > 0)
206 return 0;
207
208 /* No device node found, nothing to do */
209 if (!psy->of_node)
210 return 0;
211
212 do {
213 int ret;
214
215 np = of_parse_phandle(psy->of_node, "power-supplies", cnt++);
216 if (!np)
a0f93b42 217 break;
f6e0b081
RK
218
219 ret = power_supply_find_supply_from_node(np);
8468b029
VK
220 of_node_put(np);
221
f6e0b081 222 if (ret) {
f5b89aff
VK
223 dev_dbg(psy->dev, "Failed to find supply!\n");
224 return ret;
f6e0b081
RK
225 }
226 } while (np);
227
f9c85486
VK
228 /* Missing valid "power-supplies" entries */
229 if (cnt == 1)
230 return 0;
231
f6e0b081
RK
232 /* All supplies found, allocate char ** array for filling */
233 psy->supplied_from = devm_kzalloc(psy->dev, sizeof(psy->supplied_from),
234 GFP_KERNEL);
235 if (!psy->supplied_from) {
236 dev_err(psy->dev, "Couldn't allocate memory for supply list\n");
237 return -ENOMEM;
238 }
239
8f5a37cb 240 *psy->supplied_from = devm_kzalloc(psy->dev, sizeof(char *) * (cnt - 1),
f6e0b081
RK
241 GFP_KERNEL);
242 if (!*psy->supplied_from) {
243 dev_err(psy->dev, "Couldn't allocate memory for supply list\n");
244 return -ENOMEM;
245 }
246
247 return power_supply_populate_supplied_from(psy);
248}
249#else
250static inline int power_supply_check_supplies(struct power_supply *psy)
251{
252 return 0;
253}
254#endif
255
443cad92 256static int __power_supply_am_i_supplied(struct device *dev, void *data)
4a11b59d
AV
257{
258 union power_supply_propval ret = {0,};
e80cf421 259 struct power_supply *psy = data;
443cad92 260 struct power_supply *epsy = dev_get_drvdata(dev);
443cad92 261
5e0848c6 262 if (__power_supply_is_supplied_by(epsy, psy))
1c42a389
VK
263 if (!epsy->get_property(epsy, POWER_SUPPLY_PROP_ONLINE, &ret))
264 return ret.intval;
5e0848c6 265
443cad92
DY
266 return 0;
267}
268
269int power_supply_am_i_supplied(struct power_supply *psy)
270{
271 int error;
272
93562b53 273 error = class_for_each_device(power_supply_class, NULL, psy,
443cad92 274 __power_supply_am_i_supplied);
4a11b59d 275
0cddc0a9 276 dev_dbg(psy->dev, "%s %d\n", __func__, error);
4a11b59d 277
443cad92 278 return error;
4a11b59d 279}
ff3417e7 280EXPORT_SYMBOL_GPL(power_supply_am_i_supplied);
4a11b59d 281
942ed161
MG
282static int __power_supply_is_system_supplied(struct device *dev, void *data)
283{
284 union power_supply_propval ret = {0,};
285 struct power_supply *psy = dev_get_drvdata(dev);
2530daa1 286 unsigned int *count = data;
942ed161 287
2530daa1 288 (*count)++;
1c42a389
VK
289 if (psy->type != POWER_SUPPLY_TYPE_BATTERY)
290 if (!psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret))
942ed161 291 return ret.intval;
1c42a389 292
942ed161
MG
293 return 0;
294}
295
296int power_supply_is_system_supplied(void)
297{
298 int error;
2530daa1 299 unsigned int count = 0;
942ed161 300
2530daa1 301 error = class_for_each_device(power_supply_class, NULL, &count,
942ed161
MG
302 __power_supply_is_system_supplied);
303
2530daa1
JD
304 /*
305 * If no power class device was found at all, most probably we are
306 * running on a desktop system, so assume we are on mains power.
307 */
308 if (count == 0)
309 return 1;
310
942ed161
MG
311 return error;
312}
ff3417e7 313EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);
942ed161 314
e5f5ccb6
DM
315int power_supply_set_battery_charged(struct power_supply *psy)
316{
317 if (psy->type == POWER_SUPPLY_TYPE_BATTERY && psy->set_charged) {
318 psy->set_charged(psy);
319 return 0;
320 }
321
322 return -EINVAL;
323}
324EXPORT_SYMBOL_GPL(power_supply_set_battery_charged);
325
9f3b795a 326static int power_supply_match_device_by_name(struct device *dev, const void *data)
e5f5ccb6
DM
327{
328 const char *name = data;
329 struct power_supply *psy = dev_get_drvdata(dev);
330
331 return strcmp(psy->name, name) == 0;
332}
333
9f3b795a 334struct power_supply *power_supply_get_by_name(const char *name)
e5f5ccb6
DM
335{
336 struct device *dev = class_find_device(power_supply_class, NULL, name,
337 power_supply_match_device_by_name);
338
339 return dev ? dev_get_drvdata(dev) : NULL;
340}
341EXPORT_SYMBOL_GPL(power_supply_get_by_name);
342
abce9770
SR
343#ifdef CONFIG_OF
344static int power_supply_match_device_node(struct device *dev, const void *data)
345{
346 return dev->parent && dev->parent->of_node == data;
347}
348
349struct power_supply *power_supply_get_by_phandle(struct device_node *np,
350 const char *property)
351{
352 struct device_node *power_supply_np;
353 struct device *dev;
354
355 power_supply_np = of_parse_phandle(np, property, 0);
356 if (!power_supply_np)
357 return ERR_PTR(-ENODEV);
358
359 dev = class_find_device(power_supply_class, NULL, power_supply_np,
360 power_supply_match_device_node);
361
362 of_node_put(power_supply_np);
363
364 return dev ? dev_get_drvdata(dev) : NULL;
365}
366EXPORT_SYMBOL_GPL(power_supply_get_by_phandle);
367#endif /* CONFIG_OF */
368
83516651
JF
369int power_supply_powers(struct power_supply *psy, struct device *dev)
370{
93278d15 371 return sysfs_create_link(&psy->dev->kobj, &dev->kobj, "powers");
83516651
JF
372}
373EXPORT_SYMBOL_GPL(power_supply_powers);
374
5f487cd3
AV
375static void power_supply_dev_release(struct device *dev)
376{
377 pr_debug("device: '%s': %s\n", dev_name(dev), __func__);
378 kfree(dev);
379}
380
d36240d2
PR
381int power_supply_reg_notifier(struct notifier_block *nb)
382{
383 return atomic_notifier_chain_register(&power_supply_notifier, nb);
384}
385EXPORT_SYMBOL_GPL(power_supply_reg_notifier);
386
387void power_supply_unreg_notifier(struct notifier_block *nb)
388{
389 atomic_notifier_chain_unregister(&power_supply_notifier, nb);
390}
391EXPORT_SYMBOL_GPL(power_supply_unreg_notifier);
392
3be330bf
JT
393#ifdef CONFIG_THERMAL
394static int power_supply_read_temp(struct thermal_zone_device *tzd,
395 unsigned long *temp)
396{
397 struct power_supply *psy;
398 union power_supply_propval val;
399 int ret;
400
401 WARN_ON(tzd == NULL);
402 psy = tzd->devdata;
403 ret = psy->get_property(psy, POWER_SUPPLY_PROP_TEMP, &val);
404
405 /* Convert tenths of degree Celsius to milli degree Celsius. */
406 if (!ret)
407 *temp = val.intval * 100;
408
409 return ret;
410}
411
412static struct thermal_zone_device_ops psy_tzd_ops = {
413 .get_temp = power_supply_read_temp,
414};
415
416static int psy_register_thermal(struct power_supply *psy)
417{
418 int i;
419
a69d82b9
KK
420 if (psy->no_thermal)
421 return 0;
422
3be330bf
JT
423 /* Register battery zone device psy reports temperature */
424 for (i = 0; i < psy->num_properties; i++) {
425 if (psy->properties[i] == POWER_SUPPLY_PROP_TEMP) {
e6db06a5 426 psy->tzd = thermal_zone_device_register(psy->name, 0, 0,
50125a9b 427 psy, &psy_tzd_ops, NULL, 0, 0);
9d2410c7 428 return PTR_ERR_OR_ZERO(psy->tzd);
3be330bf
JT
429 }
430 }
431 return 0;
432}
433
434static void psy_unregister_thermal(struct power_supply *psy)
435{
436 if (IS_ERR_OR_NULL(psy->tzd))
437 return;
438 thermal_zone_device_unregister(psy->tzd);
439}
952aeeb3
RP
440
441/* thermal cooling device callbacks */
442static int ps_get_max_charge_cntl_limit(struct thermal_cooling_device *tcd,
443 unsigned long *state)
444{
445 struct power_supply *psy;
446 union power_supply_propval val;
447 int ret;
448
449 psy = tcd->devdata;
450 ret = psy->get_property(psy,
451 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT_MAX, &val);
452 if (!ret)
453 *state = val.intval;
454
455 return ret;
456}
457
458static int ps_get_cur_chrage_cntl_limit(struct thermal_cooling_device *tcd,
459 unsigned long *state)
460{
461 struct power_supply *psy;
462 union power_supply_propval val;
463 int ret;
464
465 psy = tcd->devdata;
466 ret = psy->get_property(psy,
467 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
468 if (!ret)
469 *state = val.intval;
470
471 return ret;
472}
473
474static int ps_set_cur_charge_cntl_limit(struct thermal_cooling_device *tcd,
475 unsigned long state)
476{
477 struct power_supply *psy;
478 union power_supply_propval val;
479 int ret;
480
481 psy = tcd->devdata;
482 val.intval = state;
483 ret = psy->set_property(psy,
484 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT, &val);
485
486 return ret;
487}
488
489static struct thermal_cooling_device_ops psy_tcd_ops = {
490 .get_max_state = ps_get_max_charge_cntl_limit,
491 .get_cur_state = ps_get_cur_chrage_cntl_limit,
492 .set_cur_state = ps_set_cur_charge_cntl_limit,
493};
494
495static int psy_register_cooler(struct power_supply *psy)
496{
497 int i;
498
499 /* Register for cooling device if psy can control charging */
500 for (i = 0; i < psy->num_properties; i++) {
501 if (psy->properties[i] ==
502 POWER_SUPPLY_PROP_CHARGE_CONTROL_LIMIT) {
503 psy->tcd = thermal_cooling_device_register(
504 (char *)psy->name,
505 psy, &psy_tcd_ops);
9d2410c7 506 return PTR_ERR_OR_ZERO(psy->tcd);
952aeeb3
RP
507 }
508 }
509 return 0;
510}
511
512static void psy_unregister_cooler(struct power_supply *psy)
513{
514 if (IS_ERR_OR_NULL(psy->tcd))
515 return;
516 thermal_cooling_device_unregister(psy->tcd);
517}
3be330bf
JT
518#else
519static int psy_register_thermal(struct power_supply *psy)
520{
521 return 0;
522}
523
524static void psy_unregister_thermal(struct power_supply *psy)
525{
526}
952aeeb3
RP
527
528static int psy_register_cooler(struct power_supply *psy)
529{
530 return 0;
531}
532
533static void psy_unregister_cooler(struct power_supply *psy)
534{
535}
3be330bf
JT
536#endif
537
c128d397 538static int __power_supply_register(struct device *parent,
2dc9215d
KK
539 struct power_supply *psy,
540 const struct power_supply_config *cfg,
541 bool ws)
4a11b59d 542{
5f487cd3
AV
543 struct device *dev;
544 int rc;
4a11b59d 545
5f487cd3
AV
546 dev = kzalloc(sizeof(*dev), GFP_KERNEL);
547 if (!dev)
548 return -ENOMEM;
4a11b59d 549
5f487cd3 550 device_initialize(dev);
4a11b59d 551
5f487cd3
AV
552 dev->class = power_supply_class;
553 dev->type = &power_supply_dev_type;
554 dev->parent = parent;
555 dev->release = power_supply_dev_release;
556 dev_set_drvdata(dev, psy);
557 psy->dev = dev;
2dc9215d
KK
558 if (cfg) {
559 psy->drv_data = cfg->drv_data;
560 psy->of_node = cfg->of_node;
561 psy->supplied_to = cfg->supplied_to;
562 psy->num_supplicants = cfg->num_supplicants;
563 }
5f487cd3 564
80c6463e
SK
565 rc = dev_set_name(dev, "%s", psy->name);
566 if (rc)
567 goto dev_set_name_failed;
568
97774672
LPC
569 INIT_WORK(&psy->changed_work, power_supply_changed_work);
570
f6e0b081
RK
571 rc = power_supply_check_supplies(psy);
572 if (rc) {
573 dev_info(dev, "Not all required supplies found, defer probe\n");
574 goto check_supplies_failed;
575 }
576
948dcf96 577 spin_lock_init(&psy->changed_lock);
9113e260 578 rc = device_init_wakeup(dev, ws);
948dcf96
ZM
579 if (rc)
580 goto wakeup_init_failed;
581
5f487cd3 582 rc = device_add(dev);
4a11b59d 583 if (rc)
5f487cd3
AV
584 goto device_add_failed;
585
3be330bf
JT
586 rc = psy_register_thermal(psy);
587 if (rc)
588 goto register_thermal_failed;
589
952aeeb3
RP
590 rc = psy_register_cooler(psy);
591 if (rc)
592 goto register_cooler_failed;
593
4a11b59d
AV
594 rc = power_supply_create_triggers(psy);
595 if (rc)
596 goto create_triggers_failed;
597
598 power_supply_changed(psy);
599
464069ca 600 return 0;
4a11b59d
AV
601
602create_triggers_failed:
952aeeb3
RP
603 psy_unregister_cooler(psy);
604register_cooler_failed:
3be330bf
JT
605 psy_unregister_thermal(psy);
606register_thermal_failed:
3a2dbd61 607 device_del(dev);
5f487cd3 608device_add_failed:
80c6463e 609wakeup_init_failed:
f6e0b081 610check_supplies_failed:
80c6463e 611dev_set_name_failed:
3a2dbd61 612 put_device(dev);
4a11b59d
AV
613 return rc;
614}
9113e260 615
2dc9215d
KK
616int power_supply_register(struct device *parent, struct power_supply *psy,
617 const struct power_supply_config *cfg)
9113e260 618{
2dc9215d 619 return __power_supply_register(parent, psy, cfg, true);
9113e260 620}
ff3417e7 621EXPORT_SYMBOL_GPL(power_supply_register);
4a11b59d 622
2dc9215d
KK
623int power_supply_register_no_ws(struct device *parent, struct power_supply *psy,
624 const struct power_supply_config *cfg)
9113e260 625{
2dc9215d 626 return __power_supply_register(parent, psy, cfg, false);
9113e260
ZR
627}
628EXPORT_SYMBOL_GPL(power_supply_register_no_ws);
629
5d8a4219
N
630static void devm_power_supply_release(struct device *dev, void *res)
631{
632 struct power_supply **psy = res;
633
634 power_supply_unregister(*psy);
635}
636
2dc9215d
KK
637int devm_power_supply_register(struct device *parent, struct power_supply *psy,
638 const struct power_supply_config *cfg)
5d8a4219
N
639{
640 struct power_supply **ptr = devres_alloc(devm_power_supply_release,
641 sizeof(*ptr), GFP_KERNEL);
642 int ret;
643
644 if (!ptr)
645 return -ENOMEM;
2dc9215d 646 ret = __power_supply_register(parent, psy, cfg, true);
5d8a4219
N
647 if (ret < 0)
648 devres_free(ptr);
649 else {
650 *ptr = psy;
651 devres_add(parent, ptr);
652 }
653 return ret;
654}
655EXPORT_SYMBOL_GPL(devm_power_supply_register);
656
2dc9215d
KK
657int devm_power_supply_register_no_ws(struct device *parent, struct power_supply *psy,
658 const struct power_supply_config *cfg)
5d8a4219
N
659{
660 struct power_supply **ptr = devres_alloc(devm_power_supply_release,
661 sizeof(*ptr), GFP_KERNEL);
662 int ret;
663
664 if (!ptr)
665 return -ENOMEM;
2dc9215d 666 ret = __power_supply_register(parent, psy, cfg, false);
5d8a4219
N
667 if (ret < 0)
668 devres_free(ptr);
669 else {
670 *ptr = psy;
671 devres_add(parent, ptr);
672 }
673 return ret;
674}
675EXPORT_SYMBOL_GPL(devm_power_supply_register_no_ws);
676
4a11b59d
AV
677void power_supply_unregister(struct power_supply *psy)
678{
bc51e7ff 679 cancel_work_sync(&psy->changed_work);
83516651 680 sysfs_remove_link(&psy->dev->kobj, "powers");
4a11b59d 681 power_supply_remove_triggers(psy);
952aeeb3 682 psy_unregister_cooler(psy);
3be330bf 683 psy_unregister_thermal(psy);
948dcf96 684 device_init_wakeup(psy->dev, false);
4a11b59d 685 device_unregister(psy->dev);
4a11b59d 686}
ff3417e7 687EXPORT_SYMBOL_GPL(power_supply_unregister);
4a11b59d 688
e44ea364
KK
689void *power_supply_get_drvdata(struct power_supply *psy)
690{
691 return psy->drv_data;
692}
693EXPORT_SYMBOL_GPL(power_supply_get_drvdata);
694
4a11b59d
AV
695static int __init power_supply_class_init(void)
696{
697 power_supply_class = class_create(THIS_MODULE, "power_supply");
698
699 if (IS_ERR(power_supply_class))
700 return PTR_ERR(power_supply_class);
701
702 power_supply_class->dev_uevent = power_supply_uevent;
5f487cd3 703 power_supply_init_attrs(&power_supply_dev_type);
4a11b59d
AV
704
705 return 0;
706}
707
708static void __exit power_supply_class_exit(void)
709{
710 class_destroy(power_supply_class);
4a11b59d
AV
711}
712
4a11b59d
AV
713subsys_initcall(power_supply_class_init);
714module_exit(power_supply_class_exit);
715
716MODULE_DESCRIPTION("Universal power supply monitor class");
717MODULE_AUTHOR("Ian Molton <spyro@f2s.com>, "
718 "Szabolcs Gyurko, "
719 "Anton Vorontsov <cbou@mail.ru>");
720MODULE_LICENSE("GPL");
This page took 0.791454 seconds and 5 git commands to generate.