Skip to content
Navigation Menu
Toggle navigation
Sign in
In this repository
All GitHub Enterprise
↵
Jump to
↵
No suggested jump to results
In this repository
All GitHub Enterprise
↵
Jump to
↵
In this organization
All GitHub Enterprise
↵
Jump to
↵
In this repository
All GitHub Enterprise
↵
Jump to
↵
Sign in
Reseting focus
You signed in with another tab or window.
Reload
to refresh your session.
You signed out in another tab or window.
Reload
to refresh your session.
You switched accounts on another tab or window.
Reload
to refresh your session.
Dismiss alert
{{ message }}
mariux64
/
linux
Public
Notifications
You must be signed in to change notification settings
Fork
0
Star
0
Code
Issues
2
Pull requests
0
Actions
Projects
0
Wiki
Security
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Wiki
Security
Insights
Files
54d29ad
Documentation
arch
block
crypto
drivers
accessibility
acorn
acpi
amba
ata
atm
auxdisplay
base
block
bluetooth
cdrom
char
clocksource
connector
cpufreq
cpuidle
crypto
dca
dio
dma
edac
eisa
firewire
firmware
gpio
hid
hwmon
i2c
ide
ieee1394
infiniband
input
isdn
leds
lguest
macintosh
mca
md
media
memstick
message
mfd
misc
mmc
mtd
net
nubus
of
oprofile
parisc
parport
pci
pcmcia
pnp
power
Kconfig
Makefile
apm_power.c
ds2760_battery.c
olpc_battery.c
pda_power.c
pmu_battery.c
power_supply.h
power_supply_core.c
power_supply_leds.c
power_supply_sysfs.c
ps3
rapidio
rtc
s390
sbus
scsi
serial
sh
sn
spi
ssb
tc
telephony
thermal
uio
usb
video
virtio
w1
watchdog
xen
zorro
Kconfig
Makefile
fs
include
init
ipc
kernel
lib
mm
net
samples
scripts
security
sound
usr
virt
.gitignore
.mailmap
COPYING
CREDITS
Kbuild
MAINTAINERS
Makefile
README
REPORTING-BUGS
Breadcrumbs
linux
/
drivers
/
power
/
power_supply_core.c
Copy path
Blame
Blame
Latest commit
History
History
164 lines (129 loc) · 3.76 KB
Breadcrumbs
linux
/
drivers
/
power
/
power_supply_core.c
Top
File metadata and controls
Code
Blame
164 lines (129 loc) · 3.76 KB
Raw
/* * Universal power supply monitor class * * Copyright © 2007 Anton Vorontsov <cbou@mail.ru> * Copyright © 2004 Szabolcs Gyurko * Copyright © 2003 Ian Molton <spyro@f2s.com> * * Modified: 2004, Oct Szabolcs Gyurko * * You may use this code as per GPL version 2 */ #include <linux/module.h> #include <linux/types.h> #include <linux/init.h> #include <linux/device.h> #include <linux/err.h> #include <linux/power_supply.h> #include "power_supply.h" struct class *power_supply_class; static int __power_supply_changed_work(struct device *dev, void *data) { struct power_supply *psy = (struct power_supply *)data; struct power_supply *pst = dev_get_drvdata(dev); int i; for (i = 0; i < psy->num_supplicants; i++) if (!strcmp(psy->supplied_to[i], pst->name)) { if (pst->external_power_changed) pst->external_power_changed(pst); } return 0; } static void power_supply_changed_work(struct work_struct *work) { struct power_supply *psy = container_of(work, struct power_supply, changed_work); dev_dbg(psy->dev, "%s\n", __func__); class_for_each_device(power_supply_class, psy, __power_supply_changed_work); power_supply_update_leds(psy); kobject_uevent(&psy->dev->kobj, KOBJ_CHANGE); } void power_supply_changed(struct power_supply *psy) { dev_dbg(psy->dev, "%s\n", __func__); schedule_work(&psy->changed_work); } static int __power_supply_am_i_supplied(struct device *dev, void *data) { union power_supply_propval ret = {0,}; struct power_supply *psy = (struct power_supply *)data; struct power_supply *epsy = dev_get_drvdata(dev); int i; for (i = 0; i < epsy->num_supplicants; i++) { if (!strcmp(epsy->supplied_to[i], psy->name)) { if (epsy->get_property(epsy, POWER_SUPPLY_PROP_ONLINE, &ret)) continue; if (ret.intval) return ret.intval; } } return 0; } int power_supply_am_i_supplied(struct power_supply *psy) { int error; error = class_for_each_device(power_supply_class, psy, __power_supply_am_i_supplied); dev_dbg(psy->dev, "%s %d\n", __func__, error); return error; } int power_supply_register(struct device *parent, struct power_supply *psy) { int rc = 0; psy->dev = device_create_drvdata(power_supply_class, parent, 0, psy, "%s", psy->name); if (IS_ERR(psy->dev)) { rc = PTR_ERR(psy->dev); goto dev_create_failed; } INIT_WORK(&psy->changed_work, power_supply_changed_work); rc = power_supply_create_attrs(psy); if (rc) goto create_attrs_failed; rc = power_supply_create_triggers(psy); if (rc) goto create_triggers_failed; power_supply_changed(psy); goto success; create_triggers_failed: power_supply_remove_attrs(psy); create_attrs_failed: device_unregister(psy->dev); dev_create_failed: success: return rc; } void power_supply_unregister(struct power_supply *psy) { flush_scheduled_work(); power_supply_remove_triggers(psy); power_supply_remove_attrs(psy); device_unregister(psy->dev); } static int __init power_supply_class_init(void) { power_supply_class = class_create(THIS_MODULE, "power_supply"); if (IS_ERR(power_supply_class)) return PTR_ERR(power_supply_class); power_supply_class->dev_uevent = power_supply_uevent; return 0; } static void __exit power_supply_class_exit(void) { class_destroy(power_supply_class); } EXPORT_SYMBOL_GPL(power_supply_changed); EXPORT_SYMBOL_GPL(power_supply_am_i_supplied); EXPORT_SYMBOL_GPL(power_supply_register); EXPORT_SYMBOL_GPL(power_supply_unregister); /* exported for the APM Power driver, APM emulation */ EXPORT_SYMBOL_GPL(power_supply_class); subsys_initcall(power_supply_class_init); module_exit(power_supply_class_exit); MODULE_DESCRIPTION("Universal power supply monitor class"); MODULE_AUTHOR("Ian Molton <spyro@f2s.com>, " "Szabolcs Gyurko, " "Anton Vorontsov <cbou@mail.ru>"); MODULE_LICENSE("GPL");
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
You can’t perform that action at this time.