From patchwork Tue Jan 2 15:50:53 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Adam Thomson X-Patchwork-Id: 10140951 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 539F96035E for ; Tue, 2 Jan 2018 15:52:21 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3B49C2239D for ; Tue, 2 Jan 2018 15:52:21 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2FA3B25404; Tue, 2 Jan 2018 15:52:21 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.4 required=2.0 tests=BAYES_00,FROM_WORDY, RCVD_IN_DNSWL_HI autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 727212239D for ; Tue, 2 Jan 2018 15:52:20 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751273AbeABPvp (ORCPT ); Tue, 2 Jan 2018 10:51:45 -0500 Received: from mail1.bemta6.messagelabs.com ([193.109.254.111]:17732 "EHLO mail1.bemta6.messagelabs.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751382AbeABPu4 (ORCPT ); Tue, 2 Jan 2018 10:50:56 -0500 Received: from [85.158.140.195] (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256 bits)) by server-7.bemta-6.messagelabs.com id 8C/88-24969-E5AAB4A5; Tue, 02 Jan 2018 15:50:54 +0000 X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFprMKsWRWlGSWpSXmKPExsUSt3OpsW7cKu8 ogy2T2SyaF69ns3hzfDqTRdfqnSwWl3fNYbP43HuE0WLRslZmiycLzzBZNC54z2JxeneJxZ/n t9gcuDx2zrrL7rFpVSebx7yTgR77565h93i/7yqbx87vDewenzfJBbBHsWbmJeVXJLBmTJy2m 6lgoXbFyn9X2BsYb6p0MXJxCAmsY5TY2XqWvYuRA8ipkPjZotzFyMnBK5Ap8e7tCVaQMKeAu8 TWT8wQFW4Ss97WgVSwCVhITD7xgA3EZhFQkXizYy87iC0sECnx/vkdRpDpIgLzmCRebbgLVsQ sUCfR+/stC8R4QYmTM5+wQMQlJA6+eMEMYgsJGEicXtAIFpcQsJeY/v4q2F4JAX2JxmOxEGFD ie+zvkGVmEvsuH2DdQKj4CwkU2chmbqAkWkVo0ZxalFZapGukYVeUlFmekZJbmJmjq6hgZleb mpxcWJ6ak5iUrFecn7uJkZgpDAAwQ7G82sDDzFKcjApifLmpHpHCfEl5adUZiQWZ8QXleakFh 9i1ODgEGi5ePIgkxRLXn5eqpIEb+RKoDrBotT01Iq0zBxgLMOUSnDwKInwLgJJ8xYXJOYWZ6Z DpE4x6nI8m/m6gVkIbIaUOG8GSJEASFFGaR7cCFhaucQoKyXMywh0oBBPQWpRbmYJqvwrRnEO RiVhXm2QKTyZeSVwm14BHcEEdMSf854gR5QkIqSkGhj5OCUnvKxq1FNbdHPzJTH36fMstUOYK 91WzxGWXuj97KZt+HO7js9NE2Sn8H5/aHnir162zaJu6RcyTazWTWJbt/5w3XjAgkVZTU0vrI Bdfjv/HK4zOwICbzta16k9Dzr5qIi/IPh/XE7Rs9rEiNAcY86AkHWL+FKvpzi/9H3xZgr7LIW c40osxRmJhlrMRcWJADhD790mAwAA X-Env-Sender: Adam.Thomson.Opensource@diasemi.com X-Msg-Ref: server-13.tower-193.messagelabs.com!1514908253!118664466!2 X-Originating-IP: [94.185.165.51] X-StarScan-Received: X-StarScan-Version: 9.4.45; banners=-,-,- X-VirusChecked: Checked Received: (qmail 10668 invoked from network); 2 Jan 2018 15:50:54 -0000 Received: from mailrelay2.diasemi.com (HELO sw-ex-cashub01.diasemi.com) (94.185.165.51) by server-13.tower-193.messagelabs.com with AES128-SHA encrypted SMTP; 2 Jan 2018 15:50:54 -0000 Received: from swsrvapps-01.diasemi.com (10.20.28.141) by SW-EX-CASHUB01.diasemi.com (10.20.16.140) with Microsoft SMTP Server id 14.3.248.2; Tue, 2 Jan 2018 15:50:53 +0000 Received: by swsrvapps-01.diasemi.com (Postfix, from userid 22379) id 85A033FBE8; Tue, 2 Jan 2018 15:50:53 +0000 (GMT) Message-ID: <3af7db87e0e6bdfa46ef3c1c9053297f711aee5a.1514904983.git.Adam.Thomson.Opensource@diasemi.com> In-Reply-To: References: From: Adam Thomson Date: Tue, 2 Jan 2018 15:50:53 +0000 Subject: [PATCH v4 5/7] power: supply: Add 'connected_type' property and supporting code To: Heikki Krogerus , Guenter Roeck , Greg Kroah-Hartman , Sebastian Reichel , Hans de Goede , Yueyao Zhu , Rui Miguel Silva CC: , , , MIME-Version: 1.0 X-KSE-AttachmentFiltering-Interceptor-Info: protection disabled X-KSE-ServerInfo: sw-ex-cashub01.diasemi.com, 9 X-KSE-Antivirus-Interceptor-Info: scan successful X-KSE-Antivirus-Info: Clean, bases: 02/01/2018 11:56:00 Sender: linux-pm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-pm@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP 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 Reviewed-by: Heikki Krogerus Reviewed-by: Sebastian Reichel --- 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;