power_supply: EXPORT_SYMBOL cleanups
[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>
16#include <linux/device.h>
17#include <linux/err.h>
18#include <linux/power_supply.h>
19#include "power_supply.h"
20
ff3417e7 21/* exported for the APM Power driver, APM emulation */
4a11b59d 22struct class *power_supply_class;
ff3417e7 23EXPORT_SYMBOL_GPL(power_supply_class);
4a11b59d 24
443cad92
DY
25static int __power_supply_changed_work(struct device *dev, void *data)
26{
27 struct power_supply *psy = (struct power_supply *)data;
28 struct power_supply *pst = dev_get_drvdata(dev);
29 int i;
30
31 for (i = 0; i < psy->num_supplicants; i++)
32 if (!strcmp(psy->supplied_to[i], pst->name)) {
33 if (pst->external_power_changed)
34 pst->external_power_changed(pst);
35 }
36 return 0;
37}
38
4a11b59d
AV
39static void power_supply_changed_work(struct work_struct *work)
40{
41 struct power_supply *psy = container_of(work, struct power_supply,
42 changed_work);
4a11b59d 43
0cddc0a9 44 dev_dbg(psy->dev, "%s\n", __func__);
4a11b59d 45
93562b53 46 class_for_each_device(power_supply_class, NULL, psy,
443cad92 47 __power_supply_changed_work);
4a11b59d
AV
48
49 power_supply_update_leds(psy);
50
51 kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE);
4a11b59d
AV
52}
53
54void power_supply_changed(struct power_supply *psy)
55{
0cddc0a9 56 dev_dbg(psy->dev, "%s\n", __func__);
4a11b59d
AV
57
58 schedule_work(&psy->changed_work);
4a11b59d 59}
ff3417e7 60EXPORT_SYMBOL_GPL(power_supply_changed);
4a11b59d 61
443cad92 62static int __power_supply_am_i_supplied(struct device *dev, void *data)
4a11b59d
AV
63{
64 union power_supply_propval ret = {0,};
443cad92
DY
65 struct power_supply *psy = (struct power_supply *)data;
66 struct power_supply *epsy = dev_get_drvdata(dev);
67 int i;
68
69 for (i = 0; i < epsy->num_supplicants; i++) {
70 if (!strcmp(epsy->supplied_to[i], psy->name)) {
71 if (epsy->get_property(epsy,
72 POWER_SUPPLY_PROP_ONLINE, &ret))
73 continue;
74 if (ret.intval)
75 return ret.intval;
4a11b59d
AV
76 }
77 }
443cad92
DY
78 return 0;
79}
80
81int power_supply_am_i_supplied(struct power_supply *psy)
82{
83 int error;
84
93562b53 85 error = class_for_each_device(power_supply_class, NULL, psy,
443cad92 86 __power_supply_am_i_supplied);
4a11b59d 87
0cddc0a9 88 dev_dbg(psy->dev, "%s %d\n", __func__, error);
4a11b59d 89
443cad92 90 return error;
4a11b59d 91}
ff3417e7 92EXPORT_SYMBOL_GPL(power_supply_am_i_supplied);
4a11b59d 93
942ed161
MG
94static int __power_supply_is_system_supplied(struct device *dev, void *data)
95{
96 union power_supply_propval ret = {0,};
97 struct power_supply *psy = dev_get_drvdata(dev);
98
99 if (psy->type != POWER_SUPPLY_TYPE_BATTERY) {
100 if (psy->get_property(psy, POWER_SUPPLY_PROP_ONLINE, &ret))
101 return 0;
102 if (ret.intval)
103 return ret.intval;
104 }
105 return 0;
106}
107
108int power_supply_is_system_supplied(void)
109{
110 int error;
111
112 error = class_for_each_device(power_supply_class, NULL, NULL,
113 __power_supply_is_system_supplied);
114
115 return error;
116}
ff3417e7 117EXPORT_SYMBOL_GPL(power_supply_is_system_supplied);
942ed161 118
4a11b59d
AV
119int power_supply_register(struct device *parent, struct power_supply *psy)
120{
121 int rc = 0;
122
a9b12619
GKH
123 psy->dev = device_create(power_supply_class, parent, 0, psy,
124 "%s", psy->name);
4a11b59d
AV
125 if (IS_ERR(psy->dev)) {
126 rc = PTR_ERR(psy->dev);
127 goto dev_create_failed;
128 }
129
4a11b59d
AV
130 INIT_WORK(&psy->changed_work, power_supply_changed_work);
131
132 rc = power_supply_create_attrs(psy);
133 if (rc)
134 goto create_attrs_failed;
135
136 rc = power_supply_create_triggers(psy);
137 if (rc)
138 goto create_triggers_failed;
139
140 power_supply_changed(psy);
141
142 goto success;
143
144create_triggers_failed:
145 power_supply_remove_attrs(psy);
146create_attrs_failed:
147 device_unregister(psy->dev);
148dev_create_failed:
149success:
150 return rc;
151}
ff3417e7 152EXPORT_SYMBOL_GPL(power_supply_register);
4a11b59d
AV
153
154void power_supply_unregister(struct power_supply *psy)
155{
156 flush_scheduled_work();
157 power_supply_remove_triggers(psy);
158 power_supply_remove_attrs(psy);
159 device_unregister(psy->dev);
4a11b59d 160}
ff3417e7 161EXPORT_SYMBOL_GPL(power_supply_unregister);
4a11b59d
AV
162
163static int __init power_supply_class_init(void)
164{
165 power_supply_class = class_create(THIS_MODULE, "power_supply");
166
167 if (IS_ERR(power_supply_class))
168 return PTR_ERR(power_supply_class);
169
170 power_supply_class->dev_uevent = power_supply_uevent;
171
172 return 0;
173}
174
175static void __exit power_supply_class_exit(void)
176{
177 class_destroy(power_supply_class);
4a11b59d
AV
178}
179
4a11b59d
AV
180subsys_initcall(power_supply_class_init);
181module_exit(power_supply_class_exit);
182
183MODULE_DESCRIPTION("Universal power supply monitor class");
184MODULE_AUTHOR("Ian Molton <spyro@f2s.com>, "
185 "Szabolcs Gyurko, "
186 "Anton Vorontsov <cbou@mail.ru>");
187MODULE_LICENSE("GPL");
This page took 0.261455 seconds and 5 git commands to generate.