diff options
author | Daniel Vetter <daniel.vetter@ffwll.ch> | 2017-07-26 14:23:10 +0300 |
---|---|---|
committer | Daniel Vetter <daniel.vetter@ffwll.ch> | 2017-07-26 14:43:33 +0300 |
commit | af055598542670c8533a58582813b1419949cae0 (patch) | |
tree | 901fa1bf635d5c1e91d08f9f4c2e4943516dbb71 /drivers/power/supply/power_supply_sysfs.c | |
parent | 9f15a4ab19ab33658dbc9fd37be5210e8c1ac622 (diff) | |
parent | 2d62c799f8ffac4f7ffba6a4e7f148827dfc24c7 (diff) | |
download | linux-af055598542670c8533a58582813b1419949cae0.tar.xz |
Merge airlied/drm-next into drm-misc-next
I need this to be able to apply the deferred fbdev setup patches, I
need the relevant prep work that landed through the drm-intel tree.
Also squash in conflict fixup from Laurent Pinchart.
Signed-off-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Diffstat (limited to 'drivers/power/supply/power_supply_sysfs.c')
-rw-r--r-- | drivers/power/supply/power_supply_sysfs.c | 125 |
1 files changed, 86 insertions, 39 deletions
diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index bcde8d13476a..5204f115970f 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -40,35 +40,42 @@ static struct device_attribute power_supply_attrs[]; +static const char * const power_supply_type_text[] = { + "Unknown", "Battery", "UPS", "Mains", "USB", + "USB_DCP", "USB_CDP", "USB_ACA", "USB_C", + "USB_PD", "USB_PD_DRP", "BrickID" +}; + +static const char * const power_supply_status_text[] = { + "Unknown", "Charging", "Discharging", "Not charging", "Full" +}; + +static const char * const power_supply_charge_type_text[] = { + "Unknown", "N/A", "Trickle", "Fast" +}; + +static const char * const power_supply_health_text[] = { + "Unknown", "Good", "Overheat", "Dead", "Over voltage", + "Unspecified failure", "Cold", "Watchdog timer expire", + "Safety timer expire" +}; + +static const char * const power_supply_technology_text[] = { + "Unknown", "NiMH", "Li-ion", "Li-poly", "LiFe", "NiCd", + "LiMn" +}; + +static const char * const power_supply_capacity_level_text[] = { + "Unknown", "Critical", "Low", "Normal", "High", "Full" +}; + +static const char * const power_supply_scope_text[] = { + "Unknown", "System", "Device" +}; + static ssize_t power_supply_show_property(struct device *dev, struct device_attribute *attr, char *buf) { - static char *type_text[] = { - "Unknown", "Battery", "UPS", "Mains", "USB", - "USB_DCP", "USB_CDP", "USB_ACA", "USB_C", - "USB_PD", "USB_PD_DRP" - }; - static char *status_text[] = { - "Unknown", "Charging", "Discharging", "Not charging", "Full" - }; - static char *charge_type[] = { - "Unknown", "N/A", "Trickle", "Fast" - }; - static char *health_text[] = { - "Unknown", "Good", "Overheat", "Dead", "Over voltage", - "Unspecified failure", "Cold", "Watchdog timer expire", - "Safety timer expire" - }; - static char *technology_text[] = { - "Unknown", "NiMH", "Li-ion", "Li-poly", "LiFe", "NiCd", - "LiMn" - }; - static char *capacity_level_text[] = { - "Unknown", "Critical", "Low", "Normal", "High", "Full" - }; - static char *scope_text[] = { - "Unknown", "System", "Device" - }; ssize_t ret = 0; struct power_supply *psy = dev_get_drvdata(dev); const ptrdiff_t off = attr - power_supply_attrs; @@ -91,19 +98,26 @@ static ssize_t power_supply_show_property(struct device *dev, } if (off == POWER_SUPPLY_PROP_STATUS) - return sprintf(buf, "%s\n", status_text[value.intval]); + return sprintf(buf, "%s\n", + power_supply_status_text[value.intval]); else if (off == POWER_SUPPLY_PROP_CHARGE_TYPE) - return sprintf(buf, "%s\n", charge_type[value.intval]); + return sprintf(buf, "%s\n", + power_supply_charge_type_text[value.intval]); else if (off == POWER_SUPPLY_PROP_HEALTH) - return sprintf(buf, "%s\n", health_text[value.intval]); + return sprintf(buf, "%s\n", + power_supply_health_text[value.intval]); else if (off == POWER_SUPPLY_PROP_TECHNOLOGY) - return sprintf(buf, "%s\n", technology_text[value.intval]); + return sprintf(buf, "%s\n", + power_supply_technology_text[value.intval]); else if (off == POWER_SUPPLY_PROP_CAPACITY_LEVEL) - return sprintf(buf, "%s\n", capacity_level_text[value.intval]); + return sprintf(buf, "%s\n", + power_supply_capacity_level_text[value.intval]); else if (off == POWER_SUPPLY_PROP_TYPE) - return sprintf(buf, "%s\n", type_text[value.intval]); + return sprintf(buf, "%s\n", + power_supply_type_text[value.intval]); else if (off == POWER_SUPPLY_PROP_SCOPE) - return sprintf(buf, "%s\n", scope_text[value.intval]); + return sprintf(buf, "%s\n", + power_supply_scope_text[value.intval]); else if (off >= POWER_SUPPLY_PROP_MODEL_NAME) return sprintf(buf, "%s\n", value.strval); @@ -117,14 +131,46 @@ static ssize_t power_supply_store_property(struct device *dev, struct power_supply *psy = dev_get_drvdata(dev); const ptrdiff_t off = attr - power_supply_attrs; union power_supply_propval value; - long long_val; - /* TODO: support other types than int */ - ret = kstrtol(buf, 10, &long_val); - if (ret < 0) - return ret; + /* maybe it is a enum property? */ + switch (off) { + case POWER_SUPPLY_PROP_STATUS: + ret = sysfs_match_string(power_supply_status_text, buf); + break; + case POWER_SUPPLY_PROP_CHARGE_TYPE: + ret = sysfs_match_string(power_supply_charge_type_text, buf); + break; + case POWER_SUPPLY_PROP_HEALTH: + ret = sysfs_match_string(power_supply_health_text, buf); + break; + case POWER_SUPPLY_PROP_TECHNOLOGY: + ret = sysfs_match_string(power_supply_technology_text, buf); + break; + case POWER_SUPPLY_PROP_CAPACITY_LEVEL: + ret = sysfs_match_string(power_supply_capacity_level_text, buf); + break; + case POWER_SUPPLY_PROP_SCOPE: + ret = sysfs_match_string(power_supply_scope_text, buf); + break; + default: + ret = -EINVAL; + } + + /* + * If no match was found, then check to see if it is an integer. + * Integer values are valid for enums in addition to the text value. + */ + if (ret < 0) { + long long_val; + + ret = kstrtol(buf, 10, &long_val); + if (ret < 0) + return ret; + + ret = long_val; + } - value.intval = long_val; + value.intval = ret; ret = power_supply_set_property(psy, off, &value); if (ret < 0) @@ -196,6 +242,7 @@ static struct device_attribute power_supply_attrs[] = { POWER_SUPPLY_ATTR(time_to_full_avg), POWER_SUPPLY_ATTR(type), POWER_SUPPLY_ATTR(scope), + POWER_SUPPLY_ATTR(precharge_current), POWER_SUPPLY_ATTR(charge_term_current), POWER_SUPPLY_ATTR(calibrate), /* Properties of type `const char *' */ |