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: 12472533 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 23C4AC433EF 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 F1AEF610E9 for ; Thu, 2 Sep 2021 21:35:52 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347070AbhIBVgu (ORCPT ); Thu, 2 Sep 2021 17:36:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35298 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347066AbhIBVgu (ORCPT ); Thu, 2 Sep 2021 17:36:50 -0400 Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 63ED7C061757 for ; Thu, 2 Sep 2021 14:35:51 -0700 (PDT) Received: by mail-pj1-x1034.google.com with SMTP id ot2-20020a17090b3b4200b0019127f8ed87so2014684pjb.1 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=iccVtQkWY1K8pgkB4mR4lE6zkgEnji5/94VQYQxYGjGSQGStw4Z+ztdYhk1IwPbsgi aVsizbi0GR4b7f6LBRVGfdhRF6UzGaGsOoBHIKZ+YOIfWGhPC7FbKYI8Kf6rkGuVLgZw MvAWGwFbS6silY2+qXfHUUj1skdVHKb2vUXmXNTfxBcNaxJwS147F0LKhjvFuEWkqvFD B0EUx4Af/+MlErcNqDQylrW/J/p0vjsOaLlwlM8WOg7kJR9dK+DNZUJbQotJNlEuXcZJ n/qZvE9PVm5nvtAk6dWj5yZxKVVXf5CS0dQDfWvOkwU5icKEOysfXuFPV6YufGck7FpH ZR9Q== X-Gm-Message-State: AOAM531uzBywufLLNC/Mn9XSXBLDxfLJgPaWu3WpR6pSwiZkUPtc+BpX 5wjGA6eEDXNvvo8FrW600+6vDw== 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-pm@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: 12472535 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 4F09BC433F5 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 2AE8D60238 for ; Thu, 2 Sep 2021 21:36:13 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347069AbhIBVhJ (ORCPT ); Thu, 2 Sep 2021 17:37:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35376 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347431AbhIBVhJ (ORCPT ); Thu, 2 Sep 2021 17:37:09 -0400 Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 11A92C061757 for ; Thu, 2 Sep 2021 14:36:10 -0700 (PDT) Received: by mail-pg1-x529.google.com with SMTP id c17so3444487pgc.0 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=ga3P0CI2Z86j/PMepmw22dQNIQYdkFlfckUlUgSFuxeur/08PzD/GhPGN3SdOdI7EK 2TWx0aaDFJ5/qYSu6o/mAJH9dTMfnjo4muUqxAGEPAYRlzlVcfgoneu79K/uzhcLYV4L dNkeZ4nHPG2dvHovUm9d19gF7LnnsCbjf5ociTWROl7iBQHcnWLfVmfOCdtSPMYGYg7m o43oy+gCfz0H08CSA3KAvgWdpyfiVdKxrJSb7jDjqtMY6Q0LukyB11xAwlR43mUWFbCN Xqcuv2M6AqLxvGZpQJI1d1N/edxzwobCQTnSnMTi1MnsNOmLQgoebuEkkCpG2L4LEdEG VgLA== X-Gm-Message-State: AOAM533u++wupLrEjWtdngKycSeR4E1Uy/L0gY0ifw2eyr98x6OcbgBs tuONqKrj5o/7XnMVEc+dxGxRtw== 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-pm@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: 12472537 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 BE699C433F5 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 A7F2860698 for ; Thu, 2 Sep 2021 21:36:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347481AbhIBVhW (ORCPT ); Thu, 2 Sep 2021 17:37:22 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35436 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347471AbhIBVhV (ORCPT ); Thu, 2 Sep 2021 17:37:21 -0400 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DCD13C061575 for ; Thu, 2 Sep 2021 14:36:22 -0700 (PDT) Received: by mail-pf1-x432.google.com with SMTP id m26so2695274pff.3 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=ZQ1W637lIHFmcLRB1Dn52TCjiv0jQFFg02iSmUR2ZEYWWJFeLwodRmNg9HIDoY2t/H B9cQDlkqxwZXT7uuSmaHH+NIGGxVp1Pum9pzDEN0ue7qt4CTWsIhHqvK0wTiGiJw9AZl 9szxRM3WTw19i4Wkjd4WsksfSCTSh8QutanYkocLkuXWFMee8ddgQTssyUk8ijPVlQaU 1Tdn0kM4S9iLId5JVbcuEJZnO20LnrXcB5CnHjcwhLsnGpL1T7aveUHzn3Cl4DLfTKN2 ehu4pb2YAfU/rxCOPsx8wrYWopMeZUsdzksTN7puFa/AWvUDuy9wXD9tP1CyhWXLWQUx qwMQ== X-Gm-Message-State: AOAM533IkMCvJOv0wssLkptnJrfX+5ZJ4O9YWjbwbLAsDJeD/oW7RxDp iEr0l3rlqrbR0aaMjyqW9IhAEg== 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-pm@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,