From patchwork Thu Sep 2 21:34:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 12472525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32817C433F5 for ; Thu, 2 Sep 2021 21:35:53 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 0B6F861100 for ; Thu, 2 Sep 2021 21:35:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347352AbhIBVgu (ORCPT ); Thu, 2 Sep 2021 17:36:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35296 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1345929AbhIBVgu (ORCPT ); Thu, 2 Sep 2021 17:36:50 -0400 Received: from mail-pj1-x102e.google.com (mail-pj1-x102e.google.com [IPv6:2607:f8b0:4864:20::102e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 638DBC061575 for ; Thu, 2 Sep 2021 14:35:51 -0700 (PDT) Received: by mail-pj1-x102e.google.com with SMTP id 28-20020a17090a031cb0290178dcd8a4d1so2038244pje.0 for ; Thu, 02 Sep 2021 14:35:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=7zCkd3JvyHoZ9LAWIPQYbpkAo5YW68kDeuOEoBqJRhY=; b=hKwCC7KdDOszi7xScsH3Xrs/7EFRh3iHI9sSxQgX3PbIySek1TBQ37ie8B3w+R/PVJ 3W+tMwoFWQVSkHd2Y3T/yz72jRA/QIYpC2qUHq8f4L15lw4AIzkn0fHST0Ta2VWV/37Z haA0lf9LeyIwlCHvYDAJPSepF88x5nEGEpZaQ= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=7zCkd3JvyHoZ9LAWIPQYbpkAo5YW68kDeuOEoBqJRhY=; b=aHGUK+Kui2Kqi5FRup1p0i95yQabU8o2oMNxP0Z3Yja0WzirMuBgYTqNRZPPjWQSM3 Isedm2TjHRDB353OFdRc2LWIcu1l60QpN5sw3a5SZA8eD5AOdPXJaXc3snTKLbhQsKpe IW7Toe7LotM2LpcVTgk6d3sFDrEbE/G7WJlVyqNXAWf7jBRQtMSgG2rQO0BZYCGrDKnq YNCrQkPAR3y+nuyB4xPMrdGZVHKZIdmEjTku0jIbqcAR2bIXntwimY2qkW063HD7Qep6 aPymGekg3XBzfK58qlyLeLa1II12kqB816jAuKgD9qFrNYtM3urM/necMi7UKJAErrfm bB5A== X-Gm-Message-State: AOAM5319v3fvm1pbxqky+cagLNpqJqaX+aM/0M127Ga5HNyoOlvcGGup PWbNpjFEd76JXgK30HwViwLmEg== X-Google-Smtp-Source: ABdhPJw/kFot2iDRgNRI52oS3yjvEq82wiDachQhMt8HLLKkbzugaw+VBNDlC6IszciAmYmI1enbNw== X-Received: by 2002:a17:90b:fc6:: with SMTP id gd6mr6167950pjb.186.1630618550978; Thu, 02 Sep 2021 14:35:50 -0700 (PDT) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:d082:352a:f346:411a]) by smtp.gmail.com with ESMTPSA id c68sm3167872pfc.150.2021.09.02.14.35.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 14:35:50 -0700 (PDT) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-pm@vger.kernel.org, bleung@chromium.org, heikki.krogerus@linux.intel.com, badhri@google.com Cc: Prashant Malani , Greg Kroah-Hartman , Sebastian Reichel Subject: [RFC PATCH 1/3] usb: pd: Increase max PDO objects to 13 Date: Thu, 2 Sep 2021 14:34:58 -0700 Message-Id: <20210902213500.3795948-2-pmalani@chromium.org> X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog In-Reply-To: <20210902213500.3795948-1-pmalani@chromium.org> References: <20210902213500.3795948-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Increase the max number of PDO objects to 13, to accommodate the extra PDOs added as a part of EPR (Extended Power Range) operation introduced in the USB PD Spec Rev 3.1, v 1.0. See Figure 6-54 for details. Signed-off-by: Prashant Malani --- include/linux/usb/pd.h | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/include/linux/usb/pd.h b/include/linux/usb/pd.h index 96b7ff66f074..7e8bdca1ce6e 100644 --- a/include/linux/usb/pd.h +++ b/include/linux/usb/pd.h @@ -201,7 +201,13 @@ struct pd_message { } __packed; /* PDO: Power Data Object */ -#define PDO_MAX_OBJECTS 7 + +/* + * The EPR (Extended Power Range) structure is a superset of the SPR (Standard Power Range) + * capabilities structure, so set the max number of PDOs to 13 instead of 7. On SPR-only systems, + * objects 8 through 13 will just be empty. + */ +#define PDO_MAX_OBJECTS 13 enum pd_pdo_type { PDO_TYPE_FIXED = 0, From patchwork Thu Sep 2 21:35:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 12472527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9137DC433FE for ; Thu, 2 Sep 2021 21:36:13 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 743D860238 for ; Thu, 2 Sep 2021 21:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347450AbhIBVhL (ORCPT ); Thu, 2 Sep 2021 17:37:11 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35374 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347441AbhIBVhJ (ORCPT ); Thu, 2 Sep 2021 17:37:09 -0400 Received: from mail-pf1-x42b.google.com (mail-pf1-x42b.google.com [IPv6:2607:f8b0:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 115FAC061575 for ; Thu, 2 Sep 2021 14:36:10 -0700 (PDT) Received: by mail-pf1-x42b.google.com with SMTP id g14so2694903pfm.1 for ; Thu, 02 Sep 2021 14:36:10 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1QHuvNA0GE/QTmVf5qMVWbh81vw1JSnVPC3ftDnCQ2o=; b=gua2HzSTeHuCTlzTtSh9R215ubwL7XqKG670iNIAzOeVu4z8GygQnSmoL/98bEeYFZ r3C6TZnOkZEeIzlRCPfR3ZdVxxd68+kRIQQ0c/YP17msZlbyVdKbrKagj/XucPb14tyM 3X3klBlrhAk6HnJoH3HYtzt6up6BkBFVWj0F4= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1QHuvNA0GE/QTmVf5qMVWbh81vw1JSnVPC3ftDnCQ2o=; b=ISBqYvsoTdlotWHolyJwagTwy8mTv1Cpx+a4E6YTYVTCdBCKDY7O9C2Qp6qn7I9okK fH7KG7SJv8uB1+FoP3A6Ob7HjrPeM1UCDC9CapA4P/PUBy0AnVNMA1tf5aCp4SgesX43 LiPdcIXeJWSOCS/CAEQhz1Z2KLlhKvp4BguyTu3KAK6VmcgWxItZaBwl4KloVi2zARTi XqYd7BTNaHiXcpcY+lFXlIwk1q5J9P778tPz5iR/Nn6W2T5ReqiYCmNN4pEz/8iSoOTk IVlPkLSb0oQJibobGJEKUn2V9OocsimyQ1J8uB29xzV1U6gEUY62HKp6QsyVe27fsNhm S60g== X-Gm-Message-State: AOAM532fu7TQmRgAS3PsqdkRHIrVXuOW/L/t9yOA/vfSmNxiiNxJEAJe VZWmtMFPE36n+dHOuK70iV3kcg== X-Google-Smtp-Source: ABdhPJx7sq5ohmQvvTlzv3h+qRM+7CoompHfl9c5KeAecA71P5FVpCLxdsQFsNAY6McN+gS8ZsenrQ== X-Received: by 2002:a65:6393:: with SMTP id h19mr435842pgv.64.1630618569489; Thu, 02 Sep 2021 14:36:09 -0700 (PDT) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:d082:352a:f346:411a]) by smtp.gmail.com with ESMTPSA id c68sm3167872pfc.150.2021.09.02.14.36.08 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 14:36:09 -0700 (PDT) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-pm@vger.kernel.org, bleung@chromium.org, heikki.krogerus@linux.intel.com, badhri@google.com Cc: Prashant Malani , Greg Kroah-Hartman , Sebastian Reichel Subject: [RFC PATCH 2/3] power: supply: Add support for PDOs props Date: Thu, 2 Sep 2021 14:35:00 -0700 Message-Id: <20210902213500.3795948-3-pmalani@chromium.org> X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog In-Reply-To: <20210902213500.3795948-1-pmalani@chromium.org> References: <20210902213500.3795948-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add support for reporting Source and Sink Capabilities Power Data Object (PDO) property. These are reported by USB Power Delivery (PD) capable power sources. Signed-off-by: Prashant Malani --- Documentation/ABI/testing/sysfs-class-power | 30 +++++++++++++++++++++ drivers/power/supply/power_supply_sysfs.c | 18 ++++++++++++- include/linux/power_supply.h | 5 ++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/Documentation/ABI/testing/sysfs-class-power b/Documentation/ABI/testing/sysfs-class-power index ca830c6cd809..90d4198e6dfb 100644 --- a/Documentation/ABI/testing/sysfs-class-power +++ b/Documentation/ABI/testing/sysfs-class-power @@ -562,6 +562,36 @@ Description: "Unknown", "SDP", "DCP", "CDP", "ACA", "C", "PD", "PD_DRP", "PD_PPS", "BrickID" +What: /sys/class/power_supply//source_cap_pdos +Date: September 2021 +Contact: linux-pm@vger.kernel.org +Description: + Reports the Source Capabilities Power Data Objects (PDO) reported by the USB + PD-capable power source. 13 PDOs are listed. PDOs 1-7 represent the Source Caps + for devices which only support Standard Power Range (SPR), whereas PDOs 8-13 + are for Extended Power Range (EPR) capable sources. + NOTE: The EPR Source Caps message is a superset of the Source Cap message, so on + SPR-only sources, PDOs 8-13 will be 0. + + Access: Read-Only + + Valid values: Represented as a list of 13 32-bit PDO objects in hexadecimal format. + +What: /sys/class/power_supply//sink_cap_pdos +Date: September 2021 +Contact: linux-pm@vger.kernel.org +Description: + Reports the Sink Capabilities Power Data Objects (PDO) reported by the USB + PD-capable power source. 13 PDOs are listed. PDOs 1-7 represent the Sink Caps + for devices which only support Standard Power Range (SPR), whereas PDOs 8-13 + are for Extended Power Range (EPR) capable sinks. + NOTE: The EPR Sink Caps message is a superset of the Sink Cap message, so on + SPR-only sinks, PDOs 8-13 will be 0. + + Access: Read-Only + + Valid values: Represented as a list of 13 32-bit PDO objects in hexadecimal format. + **Device Specific Properties** What: /sys/class/power/ds2760-battery.*/charge_now diff --git a/drivers/power/supply/power_supply_sysfs.c b/drivers/power/supply/power_supply_sysfs.c index c3d7cbcd4fad..9d17d3376949 100644 --- a/drivers/power/supply/power_supply_sysfs.c +++ b/drivers/power/supply/power_supply_sysfs.c @@ -211,6 +211,9 @@ static struct power_supply_attr power_supply_attrs[] = { POWER_SUPPLY_ATTR(MODEL_NAME), POWER_SUPPLY_ATTR(MANUFACTURER), POWER_SUPPLY_ATTR(SERIAL_NUMBER), + /* Array properties */ + POWER_SUPPLY_ATTR(SINK_CAP_PDOS), + POWER_SUPPLY_ATTR(SOURCE_CAP_PDOS), }; static struct attribute * @@ -267,7 +270,11 @@ static ssize_t power_supply_show_property(struct device *dev, struct power_supply *psy = dev_get_drvdata(dev); struct power_supply_attr *ps_attr = to_ps_attr(attr); enum power_supply_property psp = dev_attr_psp(attr); - union power_supply_propval value; + union power_supply_propval value = { + .pdos = {0} + }; + size_t count; + int i; if (psp == POWER_SUPPLY_PROP_TYPE) { value.intval = psy->desc->type; @@ -299,6 +306,15 @@ static ssize_t power_supply_show_property(struct device *dev, case POWER_SUPPLY_PROP_MODEL_NAME ... POWER_SUPPLY_PROP_SERIAL_NUMBER: ret = sprintf(buf, "%s\n", value.strval); break; + case POWER_SUPPLY_PROP_SINK_CAP_PDOS: + case POWER_SUPPLY_PROP_SOURCE_CAP_PDOS: + ret = 0; + for (i = 0; i < PDO_MAX_OBJECTS; i++) { + count = sprintf(buf, "0x%08x\n", value.pdos[i]); + buf += count; + ret += count; + } + break; default: ret = sprintf(buf, "%d\n", value.intval); } diff --git a/include/linux/power_supply.h b/include/linux/power_supply.h index 9ca1f120a211..a53c8fa4c1c9 100644 --- a/include/linux/power_supply.h +++ b/include/linux/power_supply.h @@ -17,6 +17,7 @@ #include #include #include +#include /* * All voltages, currents, charges, energies, time and temperatures in uV, @@ -171,6 +172,9 @@ enum power_supply_property { POWER_SUPPLY_PROP_MODEL_NAME, POWER_SUPPLY_PROP_MANUFACTURER, POWER_SUPPLY_PROP_SERIAL_NUMBER, + /* Array properties */ + POWER_SUPPLY_PROP_SINK_CAP_PDOS, + POWER_SUPPLY_PROP_SOURCE_CAP_PDOS, }; enum power_supply_type { @@ -209,6 +213,7 @@ enum power_supply_notifier_events { union power_supply_propval { int intval; const char *strval; + u32 pdos[PDO_MAX_OBJECTS]; }; struct device_node; From patchwork Thu Sep 2 21:35:02 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 12472529 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-19.1 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_CR_TRAILER,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 835A7C433EF for ; Thu, 2 Sep 2021 21:36:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6B8776054E for ; Thu, 2 Sep 2021 21:36:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347424AbhIBVhW (ORCPT ); Thu, 2 Sep 2021 17:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35438 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347474AbhIBVhV (ORCPT ); Thu, 2 Sep 2021 17:37:21 -0400 Received: from mail-pg1-x533.google.com (mail-pg1-x533.google.com [IPv6:2607:f8b0:4864:20::533]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DEB5EC061757 for ; Thu, 2 Sep 2021 14:36:22 -0700 (PDT) Received: by mail-pg1-x533.google.com with SMTP id k24so3401534pgh.8 for ; Thu, 02 Sep 2021 14:36:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8y6wF+XQ52afzGRquz6577KWZV/UU/rjnNku3tx/TIU=; b=kFc970RVraCTGWGhfGtzUtm6CShTtpLV6TYXR2MBGnvekHUyEEaaQSUT0tUYlYS+Nn uKCZcYkaK0K3mDCNttkgSUi38AOq4FCuXmk+6T4krnNlME6t+hcN8JH3b8HlBqeQ1SK1 KzwIWj6/LXmU76t7TWm7sqUfT+P6slzw4wZ0s= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=8y6wF+XQ52afzGRquz6577KWZV/UU/rjnNku3tx/TIU=; b=m0zhuwc0waIEyCpFvVR6kjudeqf/83k9AiHKwMUQJQrboBmbazVbbtppp/GTf5I7sE TFfF2WIqozGJTU5Ekp1+SWUg2iusfQuzguAhRXpAvCfHLlYrKZUXwzzUwdf11WJIoXdi x9jLa3suAVpqoqQSQmxo9FC2FZG5wHmkCh6r2LSC6Gfn5szvD2lU4ddDk4HgrblzCvmw PdELHEMgqjon5u9dbvXqxiweonz97txbLYrp8duALfTZ/RSHMl1eXN9Hp0nA4KDFDmfn rRnvsO1/MhNkXNVN5Th5RQmTRV3JsT0eZgL9U8c+Qlouk83xMhWUgOZRWDBJfpgJwobJ bw9g== X-Gm-Message-State: AOAM530NNsz2Ma9fcg17qRB8qoS1ElSQWTaoEjYM7T1kYdy4u0f89Q2v aGHNfbyLQRsH4R5i1F3p/c54dA== X-Google-Smtp-Source: ABdhPJyYmRju1CuAw4JTzujNjj7+qmkPyWJVyeKPIhKs5FgBhCIzTZw+RvZ6xOVOlv942yLfLLnJKg== X-Received: by 2002:aa7:9250:0:b0:3f9:2b90:b34f with SMTP id 16-20020aa79250000000b003f92b90b34fmr237985pfp.7.1630618582491; Thu, 02 Sep 2021 14:36:22 -0700 (PDT) Received: from pmalani2.mtv.corp.google.com ([2620:15c:202:201:d082:352a:f346:411a]) by smtp.gmail.com with ESMTPSA id c68sm3167872pfc.150.2021.09.02.14.36.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 02 Sep 2021 14:36:22 -0700 (PDT) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, linux-pm@vger.kernel.org, bleung@chromium.org, heikki.krogerus@linux.intel.com, badhri@google.com Cc: Prashant Malani , Greg Kroah-Hartman Subject: [RFC PATCH 3/3] usb: typec: Add partner power registration call Date: Thu, 2 Sep 2021 14:35:02 -0700 Message-Id: <20210902213500.3795948-4-pmalani@chromium.org> X-Mailer: git-send-email 2.33.0.153.gba50c8fa24-goog In-Reply-To: <20210902213500.3795948-1-pmalani@chromium.org> References: <20210902213500.3795948-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Add a function to register a power supply device for a partner. Also, ensure that the registered power supply gets unregistered when the partner is removed. Signed-off-by: Prashant Malani --- drivers/usb/typec/class.c | 18 +++++++++++++++++- drivers/usb/typec/class.h | 2 ++ include/linux/usb/typec.h | 5 +++++ 3 files changed, 24 insertions(+), 1 deletion(-) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index aeef453aa658..14a898440342 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -845,11 +845,27 @@ EXPORT_SYMBOL_GPL(typec_register_partner); */ void typec_unregister_partner(struct typec_partner *partner) { - if (!IS_ERR_OR_NULL(partner)) + if (!IS_ERR_OR_NULL(partner)) { + power_supply_unregister(partner->psy); device_unregister(&partner->dev); + } } EXPORT_SYMBOL_GPL(typec_unregister_partner); +int typec_partner_register_psy(struct typec_partner *partner, const struct power_supply_desc *desc, + const struct power_supply_config *cfg) +{ + partner->psy = power_supply_register(&partner->dev, desc, cfg); + if (IS_ERR(partner->psy)) { + dev_err(&partner->dev, "failed to register partner power supply (%ld)\n", + PTR_ERR(partner->psy)); + return PTR_ERR(partner->psy); + } + + return 0; +} +EXPORT_SYMBOL_GPL(typec_partner_register_psy); + /* ------------------------------------------------------------------------- */ /* Type-C Cable Plugs */ diff --git a/drivers/usb/typec/class.h b/drivers/usb/typec/class.h index aef03eb7e152..b75b0f22d982 100644 --- a/drivers/usb/typec/class.h +++ b/drivers/usb/typec/class.h @@ -4,6 +4,7 @@ #define __USB_TYPEC_CLASS__ #include +#include #include struct typec_mux; @@ -33,6 +34,7 @@ struct typec_partner { int num_altmodes; u16 pd_revision; /* 0300H = "3.0" */ enum usb_pd_svdm_ver svdm_version; + struct power_supply *psy; }; struct typec_port { diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index e2e44bb1dad8..905527dab78c 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -22,6 +22,9 @@ struct typec_altmode_ops; struct fwnode_handle; struct device; +struct power_supply_desc; +struct power_supply_config; + enum typec_port_type { TYPEC_PORT_SRC, TYPEC_PORT_SNK, @@ -132,6 +135,8 @@ int typec_partner_set_num_altmodes(struct typec_partner *partner, int num_altmod struct typec_altmode *typec_partner_register_altmode(struct typec_partner *partner, const struct typec_altmode_desc *desc); +int typec_partner_register_psy(struct typec_partner *partner, const struct power_supply_desc *desc, + const struct power_supply_config *cfg); int typec_plug_set_num_altmodes(struct typec_plug *plug, int num_altmodes); struct typec_altmode *typec_plug_register_altmode(struct typec_plug *plug,