Received: by 2002:a05:6a10:1d13:0:0:0:0 with SMTP id pp19csp760219pxb; Thu, 2 Sep 2021 14:38:05 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwLsgzCGPEV+QIQdtc516YbRnyHBKTI8VZDEjPPRU7qGC1zgy8f7LF7SLmFuor+1nNl+YuQ X-Received: by 2002:a92:d112:: with SMTP id a18mr208871ilb.34.1630618684869; Thu, 02 Sep 2021 14:38:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1630618684; cv=none; d=google.com; s=arc-20160816; b=TbSbQ5y7XuCJtrsf+ra6W8r9S+TJ0uBEu8giR8sTRar+ZZX6HTNi5GJfCSn/f3aoZg Mbz/Iz/GWXIkiJFAr8Bbkn2g4bT092nlrNGKmJrCO+4DMN1nBayFlHIk8FF0clH40/As WDzc0dTw1egPcMA3uaIdFCQEuzsLOY5J2UGudC+GG04rpuVHYWSY87QmjX+627sGFKxm 8CQVzR4sjEbGChNYtUkUaIN4Xy5gupo+0jMiJLWffCK6evTvFj3x/vbtpIeRTRR0q/CG Vln3i2jnlflwDDgoLatju55Wup+M2pk9Vp37UY060RUUZNNfdXT+4CaaxXBbJ8+VLGnP 8FRw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=8y6wF+XQ52afzGRquz6577KWZV/UU/rjnNku3tx/TIU=; b=jPoZgT1vnSCCTTFCkYFflOSi73FMlywD2p+k9IP6k7UeU2fnPDid/VMhKE0T2RZC/k 979VIG0wh3nNOloCPJpz2MFIE0Iwg+NOc16vZjKURj7xSnLZzyM716S4NGRIr79PDyxa BF9qi1YTCb05U6nJasVjbGuwhcwcEa4M886TRhcCCjs6ODe8q6PvkrxZ9YEsmD6xRs4w 9ZOP6GpDS4Jux3aEb5eNd+nb46VEV4/1cD8WedQZsKZiG+ZosUH3n4YyedstFEIunCFz CMdaSFRPKQxHX2TMGxlqss0qnx42P5rWfkZxUitIUOihIVYpzfDkd8afVAtvfAz7lKED R1Hg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kFc970RV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id v17si3149219ilm.40.2021.09.02.14.37.53; Thu, 02 Sep 2021 14:38:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@chromium.org header.s=google header.b=kFc970RV; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=chromium.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1347485AbhIBVhX (ORCPT + 99 others); Thu, 2 Sep 2021 17:37:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35440 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1347479AbhIBVhW (ORCPT ); Thu, 2 Sep 2021 17:37:22 -0400 Received: from mail-pg1-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 21247C061760 for ; Thu, 2 Sep 2021 14:36:23 -0700 (PDT) Received: by mail-pg1-x536.google.com with SMTP id w8so3402368pgf.5 for ; Thu, 02 Sep 2021 14:36:23 -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=OZ3TAHDJF9b7F6kXGj5lX+ARLo4VxbMoIxtIifr2d32Apv9Vd5p9HdVojyMYajt3Kc hz2AzZhTVqLwfMoZn+GofDOpjOjfhyLjX/bb71rYCQFtuCMoEZW2v+G0ZrE99uUm6oeQ bvQ6HOdCgPI2WCWrmUI1v8vMfzpAE1ZwWvz53EFN7gDUcUgdT4wzAvKcqQa8TcHaQy8i Xi6a8HdH0jS/ge+J807E78Jb9xwSkNOHC25H/O1Yh+NXxrD4gPLu3VPEtiieoU6ZdMxe 7+psCYa6GwQu23oHYPVi49JdA97kQjCmuB6Jrdsd6mhigqDzCUin7bKUYc21KiMjVuRJ 2PGg== X-Gm-Message-State: AOAM533KWSa42/p7uWk5yz9FeI3IhASIqdxw2rjtv6GeF8igNYHwrMkn 4G70pUlvHGssKZlixw3foqzFYgHJmctKXg== 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 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@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, -- 2.33.0.153.gba50c8fa24-goog