From patchwork Mon Nov 21 20:13:35 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 13051603 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id E3B6BC4332F for ; Mon, 21 Nov 2022 20:14:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231880AbiKUUOA (ORCPT ); Mon, 21 Nov 2022 15:14:00 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59070 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231858AbiKUUN7 (ORCPT ); Mon, 21 Nov 2022 15:13:59 -0500 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 55FC151C1A for ; Mon, 21 Nov 2022 12:13:57 -0800 (PST) Received: by mail-pj1-x1030.google.com with SMTP id k2-20020a17090a4c8200b002187cce2f92so10063279pjh.2 for ; Mon, 21 Nov 2022 12:13:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Louc5ADJT348/nCzYaDBybvP94Rx6fwNzSnISAStWy0=; b=TGHF/B4CquhA/lZbHuol0RLDFg6PJB0gRf2Aun3KZ/xka1JqEdr0e61iQx2sOJ+ULu WJYlkRxiP50J7ZlY+iRtqu+ZjJ+FhQMnr4fq8/jeQ++Cwde9vs15gjihEdXE8D6wD9uD q9h7qRmg41GUQQ7THip2b3tHYH6V7rGLhgl+U= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Louc5ADJT348/nCzYaDBybvP94Rx6fwNzSnISAStWy0=; b=uxQQAlYO+9CEEw96udJdNKYs8dZDSD/1TxyHNmTUx56+RHG5BrXOy5essxW4ZGmIUP m0YSlkeW1offHng6emGy54p1IR4JeA/iVfRRuLPig4a4X+rpBbogzP9AdaW96AvEBaxb LULalFwoaCKb5RrhF99dgZKhYb/k7vHkJP7I0FV7BiNXBf+7/oPaFij0GDuBuC6idBNp 4g0a7T6qaqqYDTvNQXciqL9eJF1dz0GCfGtbHNc2dYi5RShb43eW+uxq+5ulKcjK5Hyy VE6kT/jQbPBGNJYk7vpvNxqTOcWrXebp+GsCuonMshirYFCaNrSm9g7iRAe0b0asRHbY f2VA== X-Gm-Message-State: ANoB5pmfzDuStdyTXzGEoifROJTq+K5TZsFfuIaFD7NZNKHOnXX2RlEX o86S2/IAgHo8jmde6Y7hF4s7CQ== X-Google-Smtp-Source: AA0mqf5BBgF1qALgJYt0DK5mjq1LPUTO6oL6myxfNUYDOB0e/UcQ/yi/iReVRzYVAr0RKrrr95gNAw== X-Received: by 2002:a17:903:1311:b0:189:1e5:8422 with SMTP id iy17-20020a170903131100b0018901e58422mr461190plb.17.1669061636874; Mon, 21 Nov 2022 12:13:56 -0800 (PST) Received: from pmalani.c.googlers.com.com (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id h8-20020a170902f70800b001822121c45asm10178507plo.28.2022.11.21.12.13.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 12:13:56 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: Prashant Malani , Benson Leung , Heikki Krogerus , Greg Kroah-Hartman , Guenter Roeck Subject: [PATCH 1/2] usb: typec: Add helper to get partner device struct Date: Mon, 21 Nov 2022 20:13:35 +0000 Message-Id: <20221121201337.2772216-2-pmalani@chromium.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221121201337.2772216-1-pmalani@chromium.org> References: <20221121201337.2772216-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org Some port drivers may want to set a Type-C partner as a parent for a USB Power Delivery object, but the Type-C partner struct isn't exposed outside of the Type-C class driver. Add a helper which returns a pointer to the Type-C partner's device struct, so that it can be supplied as the parent to the PD object. Cc: Benson Leung Cc: Heikki Krogerus Signed-off-by: Prashant Malani --- drivers/usb/typec/class.c | 13 +++++++++++++ include/linux/usb/typec.h | 2 ++ 2 files changed, 15 insertions(+) diff --git a/drivers/usb/typec/class.c b/drivers/usb/typec/class.c index bd5e5dd70431..154c70630432 100644 --- a/drivers/usb/typec/class.c +++ b/drivers/usb/typec/class.c @@ -821,6 +821,19 @@ void typec_partner_set_svdm_version(struct typec_partner *partner, } EXPORT_SYMBOL_GPL(typec_partner_set_svdm_version); + +/** + * typec_partner_to_dev - Get the device struct of a USB Type-C partner. + * @partner: USB Type-C Partner + * + * Returns a pointer to the device struct or NULL. + */ +struct device *typec_partner_to_dev(struct typec_partner *partner) +{ + return partner ? &partner->dev : NULL; +} +EXPORT_SYMBOL_GPL(typec_partner_to_dev); + /** * typec_register_partner - Register a USB Type-C Partner * @port: The USB Type-C Port the partner is connected to diff --git a/include/linux/usb/typec.h b/include/linux/usb/typec.h index 7751bedcae5d..085be3e94ff8 100644 --- a/include/linux/usb/typec.h +++ b/include/linux/usb/typec.h @@ -327,6 +327,8 @@ void typec_partner_set_svdm_version(struct typec_partner *partner, enum usb_pd_svdm_ver svdm_version); int typec_get_negotiated_svdm_version(struct typec_port *port); +struct device *typec_partner_to_dev(struct typec_partner *partner); + int typec_port_set_usb_power_delivery(struct typec_port *port, struct usb_power_delivery *pd); int typec_partner_set_usb_power_delivery(struct typec_partner *partner, struct usb_power_delivery *pd); From patchwork Mon Nov 21 20:13:36 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Prashant Malani X-Patchwork-Id: 13051604 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 779B3C4332F for ; Mon, 21 Nov 2022 20:14:03 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231899AbiKUUOC (ORCPT ); Mon, 21 Nov 2022 15:14:02 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59098 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231887AbiKUUOB (ORCPT ); Mon, 21 Nov 2022 15:14:01 -0500 Received: from mail-pj1-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id A98AF42F5F for ; Mon, 21 Nov 2022 12:13:59 -0800 (PST) Received: by mail-pj1-x1035.google.com with SMTP id 71-20020a17090a09cd00b00218adeb3549so3922181pjo.1 for ; Mon, 21 Nov 2022 12:13:59 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=+miEWjJAtnDGZKESGC2K13aQrBJTCpBeMrGNcOOuCUo=; b=h72e6p/FkTIdXBoJPIHLPAwYiX0sUKoIYNfLigO8S8y3c5Hmp3ItR+mjG8pawk/swt 0rYb7PZGEFIBlW4wV8boeOS0y/Tpq1t9tBOauGJCVvcBRUZtsZJm2m7Jbl96APMGvc4b 5XGoN2yZR2a/iKRPfuWT02FW/jZppd6CW53xY= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=+miEWjJAtnDGZKESGC2K13aQrBJTCpBeMrGNcOOuCUo=; b=nVHnqZNe+21Z3lDHk7quCWzm62UD0l3kKlX6lWBtJMCDXZZYSGj7JDPFMN5YxHqzZB VIPqoe7IKBddGGViFXkJXPBmjZLMPo6WRkHbJDDmuIHXFF9pYBdP28nZjaukSziiifWd PH56vFTiJe0c4fObzO/IUGGbZNkBaLuKnlvTCYs853g6K4Rg6VbQKVC/A6N4kHTmmOGv 0j2DWjdoQg5Fpm8YbGZDWEorwXwsMO0wtQUz+inNJ+cb95E3+qMFMgdJ82ejOeMLQZGI DrgjWmrrV7WER70dgFIHCr0DA9zO9IlWcxY6jLrKVH2zHJ0Wh3VxnVqZv7HCDpIdn9Hw ddjQ== X-Gm-Message-State: ANoB5plx+otSn05NObXW3a+xbZa3jp1c/TwPdotq03YJdB2K0MHBdJZJ ZWaseGqGnZMPQ+5/z8iCuMMIYQ== X-Google-Smtp-Source: AA0mqf4J2H1pH7NHOK+06xGanIwq/IsfLuMtmvKrdt5ShfRBmYOT3EPi6ihcIuBrDAvRaEvm7bUiNw== X-Received: by 2002:a17:902:f609:b0:178:2a08:2e7f with SMTP id n9-20020a170902f60900b001782a082e7fmr1199139plg.128.1669061639225; Mon, 21 Nov 2022 12:13:59 -0800 (PST) Received: from pmalani.c.googlers.com.com (33.5.83.34.bc.googleusercontent.com. [34.83.5.33]) by smtp.gmail.com with ESMTPSA id h8-20020a170902f70800b001822121c45asm10178507plo.28.2022.11.21.12.13.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Nov 2022 12:13:58 -0800 (PST) From: Prashant Malani To: linux-kernel@vger.kernel.org, linux-usb@vger.kernel.org, chrome-platform@lists.linux.dev Cc: Prashant Malani , Benson Leung , Heikki Krogerus , Greg Kroah-Hartman , Guenter Roeck Subject: [PATCH 2/2] platform/chrome: cros_ec_typec: Set parent of partner PD object Date: Mon, 21 Nov 2022 20:13:36 +0000 Message-Id: <20221121201337.2772216-3-pmalani@chromium.org> X-Mailer: git-send-email 2.38.1.584.g0f3c55d4c2-goog In-Reply-To: <20221121201337.2772216-1-pmalani@chromium.org> References: <20221121201337.2772216-1-pmalani@chromium.org> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org In order to tell what Type-C device a PD object belongs to, its parent needs to be set. Set the parent appropriately for PD objects which are created for connected Type-C partners. Cc: Benson Leung Cc: Heikki Krogerus Signed-off-by: Prashant Malani --- drivers/platform/chrome/cros_ec_typec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/drivers/platform/chrome/cros_ec_typec.c b/drivers/platform/chrome/cros_ec_typec.c index 2a7ff14dc37e..a1cc23b86f3c 100644 --- a/drivers/platform/chrome/cros_ec_typec.c +++ b/drivers/platform/chrome/cros_ec_typec.c @@ -968,7 +968,7 @@ static void cros_typec_register_partner_pdos(struct cros_typec_data *typec, if (!resp->source_cap_count && !resp->sink_cap_count) return; - port->partner_pd = usb_power_delivery_register(NULL, &desc); + port->partner_pd = usb_power_delivery_register(typec_partner_to_dev(port->partner), &desc); if (IS_ERR(port->partner_pd)) { dev_warn(typec->dev, "Failed to register partner PD device, port: %d\n", port_num); return;