14 #include <linux/ctype.h>
15 #include <linux/device.h>
17 #include <linux/slab.h>
18 #include <linux/stat.h>
34 #define POWER_SUPPLY_ATTR(_name) \
36 .attr = { .name = #_name }, \
37 .show = power_supply_show_property, \
38 .store = power_supply_store_property, \
46 static char *type_text[] = {
47 "Unknown",
"Battery",
"UPS",
"Mains",
"USB",
48 "USB_DCP",
"USB_CDP",
"USB_ACA"
50 static char *status_text[] = {
51 "Unknown",
"Charging",
"Discharging",
"Not charging",
"Full"
54 "Unknown",
"N/A",
"Trickle",
"Fast"
56 static char *health_text[] = {
57 "Unknown",
"Good",
"Overheat",
"Dead",
"Over voltage",
58 "Unspecified failure",
"Cold",
60 static char *technology_text[] = {
61 "Unknown",
"NiMH",
"Li-ion",
"Li-poly",
"LiFe",
"NiCd",
64 static char *capacity_level_text[] = {
65 "Unknown",
"Critical",
"Low",
"Normal",
"High",
"Full"
67 static char *scope_text[] = {
68 "Unknown",
"System",
"Device"
72 const ptrdiff_t off = attr - power_supply_attrs;
82 dev_dbg(dev,
"driver has no data for `%s' property\n",
85 dev_err(dev,
"driver failed to report `%s' property: %zd\n",
86 attr->
attr.name, ret);
97 return sprintf(buf,
"%s\n", technology_text[
value.intval]);
99 return sprintf(buf,
"%s\n", capacity_level_text[
value.intval]);
110 static ssize_t power_supply_store_property(
struct device *dev,
112 const char *buf,
size_t count) {
115 const ptrdiff_t off = attr - power_supply_attrs;
124 value.intval = long_val;
196 __power_supply_attrs[
ARRAY_SIZE(power_supply_attrs) + 1];
226 .attrs = __power_supply_attrs,
227 .is_visible = power_supply_attr_is_visible,
231 &power_supply_attr_group,
239 dev_type->
groups = power_supply_attr_groups;
241 for (i = 0; i <
ARRAY_SIZE(power_supply_attrs); i++)
242 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
245 static char *kstruprdup(
const char *
str,
gfp_t gfp)
271 if (!psy || !psy->
dev) {
272 dev_dbg(dev,
"No power supply yet\n");
292 ret = power_supply_show_property(dev, attr, prop_buf);
303 line =
strchr(prop_buf,
'\n');
313 dev_dbg(dev,
"prop %s=%s\n", attrname, prop_buf);
315 ret =
add_uevent_var(env,
"POWER_SUPPLY_%s=%s", attrname, prop_buf);