diff options
author | Sebastian Reichel <sre@kernel.org> | 2018-04-26 12:18:30 +0200 |
---|---|---|
committer | Sebastian Reichel <sre@kernel.org> | 2018-04-26 12:18:30 +0200 |
commit | 1f140ff467081212562327da6561edb6b3b3ed10 (patch) | |
tree | da65d766f3501c3366bd12c2856b15af28fd60e9 /drivers/power/supply | |
parent | a78c0c30ec73e90d1b5d8b06f593091d9b9f76d3 (diff) | |
parent | 0c718676ab3f02e98e85e7049e03d2879c62cb10 (diff) | |
download | linux-1f140ff467081212562327da6561edb6b3b3ed10.tar.gz linux-1f140ff467081212562327da6561edb6b3b3ed10.tar.bz2 linux-1f140ff467081212562327da6561edb6b3b3ed10.zip |
Merge tag 'tags/tcpm-pps-4.18' into psy-next
Tag/Merge point for adding typeC power supply support
This is a signed tag/merge point to handle the cross-tree merge of the
USB and power supply subsystems for the patch series:
Subject: [PATCH v8 0/6] typec: tcpm: Add sink side support for PPS
It is based on the usb.git tree, in the usb-next branch, for merging in
4.18-rc1.
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Sebastian Reichel <sebastian.reichel@collabora.co.uk>
Diffstat (limited to 'drivers/power/supply')
-rw-r--r-- | drivers/power/supply/power_supply_core.c | 11 | ||||
-rw-r--r-- | drivers/power/supply/power_supply_sysfs.c | 46 |
2 files changed, 56 insertions, 1 deletions
diff --git a/drivers/power/supply/power_supply_core.c b/drivers/power/supply/power_supply_core.c index feac7b066e6c..ecd68c2053c5 100644 --- a/drivers/power/supply/power_supply_core.c +++ b/drivers/power/supply/power_supply_core.c @@ -843,12 +843,21 @@ __power_supply_register(struct device *parent, { struct device *dev; struct power_supply *psy; - int rc; + int i, rc; if (!parent) pr_warn("%s: Expected proper parent device for '%s'\n", __func__, desc->name); + if (!desc || !desc->name || !desc->properties || !desc->num_properties) + return ERR_PTR(-EINVAL); + + for (i = 0; i < desc->num_properties; ++i) { + if ((desc->properties[i] == POWER_SUPPLY_PROP_USB_TYPE) && + (!desc->usb_types || !desc->num_usb_types)) + return ERR_PTR(-EINVAL); + } + psy = kzalloc(sizeof(*psy), GFP_KERNEL); if (!psy) return ERR_PTR(-ENOMEM); diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index ca2f869165ed..6170ed8b6854 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -46,6 +46,11 @@ static const char * const power_supply_type_text[] = { "USB_PD", "USB_PD_DRP", "BrickID" }; +static const char * const power_supply_usb_type_text[] = { + "Unknown", "SDP", "DCP", "CDP", "ACA", "C", + "PD", "PD_DRP", "PD_PPS", "BrickID" +}; + static const char * const power_supply_status_text[] = { "Unknown", "Charging", "Discharging", "Not charging", "Full" }; @@ -73,6 +78,41 @@ static const char * const power_supply_scope_text[] = { "Unknown", "System", "Device" }; +static ssize_t power_supply_show_usb_type(struct device *dev, + enum power_supply_usb_type *usb_types, + ssize_t num_usb_types, + union power_supply_propval *value, + char *buf) +{ + enum power_supply_usb_type usb_type; + ssize_t count = 0; + bool match = false; + int i; + + for (i = 0; i < num_usb_types; ++i) { + usb_type = usb_types[i]; + + if (value->intval == usb_type) { + count += sprintf(buf + count, "[%s] ", + power_supply_usb_type_text[usb_type]); + match = true; + } else { + count += sprintf(buf + count, "%s ", + power_supply_usb_type_text[usb_type]); + } + } + + if (!match) { + dev_warn(dev, "driver reporting unsupported connected type\n"); + return -EINVAL; + } + + if (count) + buf[count - 1] = '\n'; + + return count; +} + static ssize_t power_supply_show_property(struct device *dev, struct device_attribute *attr, char *buf) { @@ -122,6 +162,11 @@ static ssize_t power_supply_show_property(struct device *dev, ret = sprintf(buf, "%s\n", power_supply_type_text[value.intval]); break; + case POWER_SUPPLY_PROP_USB_TYPE: + ret = power_supply_show_usb_type(dev, psy->desc->usb_types, + psy->desc->num_usb_types, + &value, buf); + break; case POWER_SUPPLY_PROP_SCOPE: ret = sprintf(buf, "%s\n", power_supply_scope_text[value.intval]); @@ -252,6 +297,7 @@ static struct device_attribute power_supply_attrs[] = { POWER_SUPPLY_ATTR(time_to_full_now), POWER_SUPPLY_ATTR(time_to_full_avg), POWER_SUPPLY_ATTR(type), + POWER_SUPPLY_ATTR(usb_type), POWER_SUPPLY_ATTR(scope), POWER_SUPPLY_ATTR(precharge_current), POWER_SUPPLY_ATTR(charge_term_current), |