From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Cyrus-Session-Id: sloti22d1t05-1922291-1517316899-2-9503291069465076580 X-Sieve: CMU Sieve 3.0 X-Spam-known-sender: no X-Spam-score: 0.0 X-Spam-hits: BAYES_00 -1.9, HEADER_FROM_DIFFERENT_DOMAINS 0.001, ME_NOAUTH 0.01, RCVD_IN_DNSWL_HI -5, T_RP_MATCHES_RCVD -0.01, LANGUAGES en, BAYES_USED global, SA_VERSION 3.4.0 X-Spam-source: IP='209.132.180.67', Host='vger.kernel.org', Country='US', FromHeader='com', MailFrom='org' X-Spam-charsets: plain='us-ascii' X-Resolved-to: greg@kroah.com X-Delivered-to: greg@kroah.com X-Mail-from: linux-usb-owner@vger.kernel.org ARC-Seal: i=1; a=rsa-sha256; cv=none; d=messagingengine.com; s=arctest; t=1517316898; b=nTq+k/uLtJ4bqikuKTqTQ0OVDr4vovNjvv6xvvQT256Bwni y86OXXHE4UF/IFCMgSQI7IB+Sg+GK8IfQ7tT971PLJQtlVLHmNRy8K7F+xkDiKdV 0tMjiKpFzoITWF2VaNfHpPaWrbgZiac+tP0Q4HSMPqgtpA5GUKf3tf3vjEOAmx2m 9kj/Fe/QtsAodhuGuYIB9sKaBg2Jqkz1PHQyJJtYKnj3Ka9gtCc8VbNfIfNYehBb GsAWkU7fAh7f3zf+QGfnGH3aG4l5gvebfhM4+Y15xm913Cml0u1u5VdGzZ0I/BnM 9oNcXqfSaf1q22C22G3mfMV2xJLE6K2mIG+eGqA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=date:from:to:cc:subject:message-id :references:mime-version:content-type:in-reply-to:sender :list-id; s=arctest; t=1517316898; bh=0W4Co6xME/+bKBCgm6ZzVpgJSv LQQcnoVSYi4dHR7w4=; b=YdcgtpabURUPDQKnJDO87xlOA/ow1tVzkAQzfKI+BQ aPLDD/rc5CcKFghvIgqWT5gU8bZX7W7eB4kRaSeYkKPT3HZ4Ng45bCFjcEuIXM9+ vkEfJZ/kDOVqTu1StKY6e9KTyqT+liJ715UYWskc9AHdNsu8ZFq09I9V7aVVrrfl Wo6Dppyb0Gifh9+y5jjqEHi6INXUf8yBe60CtMq5dv966pQ+IaKdgfJid6Nl+gOc q8cGhLhGzEMPOgC3oR+yzwJR8a+tft4VZdoShISGW3jTZIhl4C/eVVFtoiAz0zjV vGBIUSkzSLpAxfHJeyjTz5Mk+qUX9zkrxFycluR3hCFQ== ARC-Authentication-Results: i=1; mx4.messagingengine.com; arc=none (no signatures found); dkim=none (no signatures found); dmarc=none (p=none,has-list-id=yes,d=none) header.from=linux.intel.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=linux-usb-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=linux.intel.com header.result=pass header_org.domain=intel.com header_org.result=pass header_is_org_domain=no Authentication-Results: mx4.messagingengine.com; arc=none (no signatures found); dkim=none (no signatures found); dmarc=none (p=none,has-list-id=yes,d=none) header.from=linux.intel.com; iprev=pass policy.iprev=209.132.180.67 (vger.kernel.org); spf=none smtp.mailfrom=linux-usb-owner@vger.kernel.org smtp.helo=vger.kernel.org; x-aligned-from=fail; x-ptr=pass x-ptr-helo=vger.kernel.org x-ptr-lookup=vger.kernel.org; x-return-mx=pass smtp.domain=vger.kernel.org smtp.result=pass smtp_org.domain=kernel.org smtp_org.result=pass smtp_is_org_domain=no header.domain=linux.intel.com header.result=pass header_org.domain=intel.com header_org.result=pass header_is_org_domain=no Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751714AbeA3Myo (ORCPT ); Tue, 30 Jan 2018 07:54:44 -0500 Received: from mga11.intel.com ([192.55.52.93]:51142 "EHLO mga11.intel.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751451AbeA3Myn (ORCPT ); Tue, 30 Jan 2018 07:54:43 -0500 X-Amp-Result: UNKNOWN X-Amp-Original-Verdict: FILE UNKNOWN X-Amp-File-Uploaded: False X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.46,435,1511856000"; d="scan'208";a="26619151" Date: Tue, 30 Jan 2018 14:54:38 +0200 From: Heikki Krogerus To: Adam Thomson Cc: Guenter Roeck , Greg Kroah-Hartman , Sebastian Reichel , Hans de Goede , Yueyao Zhu , Rui Miguel Silva , linux-usb@vger.kernel.org, linux-pm@vger.kernel.org, linux-kernel@vger.kernel.org, support.opensource@diasemi.com Subject: Re: [PATCH v4 5/7] power: supply: Add 'connected_type' property and supporting code Message-ID: <20180130125438.GE14922@kuha.fi.intel.com> References: <3af7db87e0e6bdfa46ef3c1c9053297f711aee5a.1514904983.git.Adam.Thomson.Opensource@diasemi.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <3af7db87e0e6bdfa46ef3c1c9053297f711aee5a.1514904983.git.Adam.Thomson.Opensource@diasemi.com> User-Agent: Mutt/1.9.1 (2017-09-22) Sender: linux-usb-owner@vger.kernel.org X-Mailing-List: linux-usb@vger.kernel.org X-getmail-retrieved-from-mailbox: INBOX X-Mailing-List: linux-kernel@vger.kernel.org List-ID: On Tue, Jan 02, 2018 at 03:50:53PM +0000, Adam Thomson wrote: > This commit adds the 'connected_type' property to represent supplies > which can report a number of different types of supply based on a > connection event. > > Examples of this already exist in drivers whereby the existing 'type' > property is updated, based on an event, to represent what was > connected (e.g. USB_DCP, USB_ACA, ...). Current implementations > however don't show all supported connectable types, so this knowledge > has to be exlicitly known for each driver that supports this. > > The 'connected_type' property is intended to fill this void and show > users all possible types supported by a driver. The property, when > read, shows all available types for the driver, and the one currently > chosen is highlighted/bracketed. It is expected that the 'type' > property would then just show the top-level type, such as 'USB', and > this would be static. > > Currently the 'conn_type' enum contains all of the USB variant types > that exist for the 'type' enum at this time, and in addition has > the PPS type. In the future this can be extended further for other > types which have multiple connected types supported. The mirroring > is intentional so as to not impact existing usage of the 'type' > property. > > Signed-off-by: Adam Thomson Looks good to me: Reviewed-by: Heikki Krogerus > --- > drivers/power/supply/power_supply_sysfs.c | 50 +++++++++++++++++++++++++++++++ > include/linux/power_supply.h | 15 ++++++++++ > 2 files changed, 65 insertions(+) > > diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c > index 5204f11..1b3b202 100644 > --- a/drivers/power/supply/power_supply_sysfs.c > +++ b/drivers/power/supply/power_supply_sysfs.c > @@ -46,6 +46,11 @@ > "USB_PD", "USB_PD_DRP", "BrickID" > }; > > +static const char * const power_supply_conn_type_text[] = { > + "Unknown", "USB_DCP", "USB_CDP", "USB_ACA", "USB_C", > + "USB_PD", "USB_PD_DRP", "USB_PD_PPS", "BrickID" > +}; > + > static const char * const power_supply_status_text[] = { > "Unknown", "Charging", "Discharging", "Not charging", "Full" > }; > @@ -73,6 +78,46 @@ > "Unknown", "System", "Device" > }; > > +static ssize_t power_supply_show_conn_type(struct device *dev, > + enum power_supply_conn_type *conn_types, > + ssize_t num_conn_types, > + union power_supply_propval *value, > + char *buf) > +{ > + enum power_supply_conn_type conn_type; > + ssize_t count = 0; > + bool match = false; > + int i; > + > + if ((!conn_types) || (num_conn_types <= 0)) { > + dev_warn(dev, "driver has no valid connected types\n"); > + return -ENODATA; > + } > + > + for (i = 0; i < num_conn_types; ++i) { > + conn_type = conn_types[i]; > + > + if (value->intval == conn_type) { > + count += sprintf(buf + count, "[%s] ", > + power_supply_conn_type_text[conn_type]); > + match = true; > + } else { > + count += sprintf(buf + count, "%s ", > + power_supply_conn_type_text[conn_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) { > @@ -115,6 +160,10 @@ static ssize_t power_supply_show_property(struct device *dev, > else if (off == POWER_SUPPLY_PROP_TYPE) > return sprintf(buf, "%s\n", > power_supply_type_text[value.intval]); > + else if (off == POWER_SUPPLY_PROP_CONNECTED_TYPE) > + return power_supply_show_conn_type(dev, psy->desc->conn_types, > + psy->desc->num_conn_types, > + &value, buf); > else if (off == POWER_SUPPLY_PROP_SCOPE) > return sprintf(buf, "%s\n", > power_supply_scope_text[value.intval]); > @@ -241,6 +290,7 @@ static ssize_t power_supply_store_property(struct device *dev, > POWER_SUPPLY_ATTR(time_to_full_now), > POWER_SUPPLY_ATTR(time_to_full_avg), > POWER_SUPPLY_ATTR(type), > + POWER_SUPPLY_ATTR(connected_type), > POWER_SUPPLY_ATTR(scope), > POWER_SUPPLY_ATTR(precharge_current), > POWER_SUPPLY_ATTR(charge_term_current), > diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h > index 79e90b3..e15a629 100644 > --- a/include/linux/power_supply.h > +++ b/include/linux/power_supply.h > @@ -145,6 +145,7 @@ enum power_supply_property { > POWER_SUPPLY_PROP_TIME_TO_FULL_NOW, > POWER_SUPPLY_PROP_TIME_TO_FULL_AVG, > POWER_SUPPLY_PROP_TYPE, /* use power_supply.type instead */ > + POWER_SUPPLY_PROP_CONNECTED_TYPE, > POWER_SUPPLY_PROP_SCOPE, > POWER_SUPPLY_PROP_PRECHARGE_CURRENT, > POWER_SUPPLY_PROP_CHARGE_TERM_CURRENT, > @@ -170,6 +171,18 @@ enum power_supply_type { > POWER_SUPPLY_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */ > }; > > +enum power_supply_conn_type { > + POWER_SUPPLY_CONN_TYPE_UNKNOWN = 0, > + POWER_SUPPLY_CONN_TYPE_USB_DCP, /* Dedicated Charging Port */ > + POWER_SUPPLY_CONN_TYPE_USB_CDP, /* Charging Downstream Port */ > + POWER_SUPPLY_CONN_TYPE_USB_ACA, /* Accessory Charger Adapters */ > + POWER_SUPPLY_CONN_TYPE_USB_TYPE_C, /* Type C Port */ > + POWER_SUPPLY_CONN_TYPE_USB_PD, /* Power Delivery Port */ > + POWER_SUPPLY_CONN_TYPE_USB_PD_DRP, /* PD Dual Role Port */ > + POWER_SUPPLY_CONN_TYPE_USB_PD_PPS, /* PD Programmable Power Supply */ > + POWER_SUPPLY_CONN_TYPE_APPLE_BRICK_ID, /* Apple Charging Method */ > +}; > + > enum power_supply_notifier_events { > PSY_EVENT_PROP_CHANGED, > }; > @@ -196,6 +209,8 @@ struct power_supply_config { > struct power_supply_desc { > const char *name; > enum power_supply_type type; > + enum power_supply_conn_type *conn_types; > + size_t num_conn_types; > enum power_supply_property *properties; > size_t num_properties; > > -- > 1.9.1 -- heikki