From patchwork Fri Feb 21 16:51:51 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marian-Cristian Rotariu X-Patchwork-Id: 11396939 X-Patchwork-Delegate: pavel@denx.de Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 740BA13A4 for ; Fri, 21 Feb 2020 16:52:22 +0000 (UTC) Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 5A331222C4 for ; Fri, 21 Feb 2020 16:52:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5A331222C4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=bp.renesas.com Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=cip-dev-bounces@lists.cip-project.org Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 3E56A20432; Fri, 21 Feb 2020 16:52:22 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id aJE02S9J1q1n; Fri, 21 Feb 2020 16:52:21 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id 5AA4520408; Fri, 21 Feb 2020 16:52:21 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 42950C013E; Fri, 21 Feb 2020 16:52:21 +0000 (UTC) X-Original-To: cip-dev@lists.cip-project.org Delivered-To: cip-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 10F7CC013E for ; Fri, 21 Feb 2020 16:52:19 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id F1595875CD for ; Fri, 21 Feb 2020 16:52:18 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id JmBpDHArEGg5 for ; Fri, 21 Feb 2020 16:52:17 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relmlie6.idc.renesas.com (relmlor2.renesas.com [210.160.252.172]) by whitealder.osuosl.org (Postfix) with ESMTP id 1B8AE875DC for ; Fri, 21 Feb 2020 16:52:16 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.70,468,1574089200"; d="scan'208";a="39726114" Received: from unknown (HELO relmlir6.idc.renesas.com) ([10.200.68.152]) by relmlie6.idc.renesas.com with ESMTP; 22 Feb 2020 01:52:15 +0900 Received: from marian-VirtualBox.ree.adwin.renesas.com (unknown [10.226.36.164]) by relmlir6.idc.renesas.com (Postfix) with ESMTP id C7ED340A35F7; Sat, 22 Feb 2020 01:52:14 +0900 (JST) From: Marian-Cristian Rotariu To: cip-dev@lists.cip-project.org Date: Fri, 21 Feb 2020 16:51:51 +0000 Message-Id: <1582303929-5773-5-git-send-email-marian-cristian.rotariu.rb@bp.renesas.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1582303929-5773-1-git-send-email-marian-cristian.rotariu.rb@bp.renesas.com> References: <1582303929-5773-1-git-send-email-marian-cristian.rotariu.rb@bp.renesas.com> Subject: [cip-dev] [PATCH v2 4.19.y-cip 04/22] usb: roles: Find the muxes by also matching against the device node X-BeenThere: cip-dev@lists.cip-project.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: cip-dev-bounces@lists.cip-project.org Sender: "cip-dev" From: Heikki Krogerus commit ec69e9533c4879c81eb7122771792864eb49af35 upstream. When the connections are defined in firmware, struct device_connection will have the fwnode member pointing to the device node (struct fwnode_handle) of the requested device, and the endpoint will not be used at all in that case. Acked-by: Hans de Goede Reviewed-by: Andy Shevchenko Reviewed-by: Jun Li Tested-by: Jun Li Signed-off-by: Heikki Krogerus Signed-off-by: Greg Kroah-Hartman Signed-off-by: Marian-Cristian Rotariu --- drivers/usb/roles/class.c | 21 ++++++++++++++++++--- include/linux/usb/role.h | 2 ++ 2 files changed, 20 insertions(+), 3 deletions(-) diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index 1dd492e..44a4af2 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -8,6 +8,7 @@ */ #include +#include #include #include #include @@ -84,7 +85,12 @@ enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw) } EXPORT_SYMBOL_GPL(usb_role_switch_get_role); -static int __switch_match(struct device *dev, const void *name) +static int switch_fwnode_match(struct device *dev, const void *fwnode) +{ + return dev_fwnode(dev) == fwnode; +} + +static int switch_name_match(struct device *dev, const void *name) { return !strcmp((const char *)name, dev_name(dev)); } @@ -94,8 +100,16 @@ static void *usb_role_switch_match(struct device_connection *con, int ep, { struct device *dev; - dev = class_find_device(role_class, NULL, con->endpoint[ep], - __switch_match); + if (con->fwnode) { + if (!fwnode_property_present(con->fwnode, con->id)) + return NULL; + + dev = class_find_device(role_class, NULL, con->fwnode, + switch_fwnode_match); + } else { + dev = class_find_device(role_class, NULL, con->endpoint[ep], + switch_name_match); + } return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); } @@ -266,6 +280,7 @@ usb_role_switch_register(struct device *parent, sw->get = desc->get; sw->dev.parent = parent; + sw->dev.fwnode = desc->fwnode; sw->dev.class = role_class; sw->dev.type = &usb_role_dev_type; dev_set_name(&sw->dev, "%s-role-switch", dev_name(parent)); diff --git a/include/linux/usb/role.h b/include/linux/usb/role.h index edc51be..c05ffa6 100644 --- a/include/linux/usb/role.h +++ b/include/linux/usb/role.h @@ -18,6 +18,7 @@ typedef enum usb_role (*usb_role_switch_get_t)(struct device *dev); /** * struct usb_role_switch_desc - USB Role Switch Descriptor + * @fwnode: The device node to be associated with the role switch * @usb2_port: Optional reference to the host controller port device (USB2) * @usb3_port: Optional reference to the host controller port device (USB3) * @udc: Optional reference to the peripheral controller device @@ -32,6 +33,7 @@ typedef enum usb_role (*usb_role_switch_get_t)(struct device *dev); * usb_role_switch_register() before registering the switch. */ struct usb_role_switch_desc { + struct fwnode_handle *fwnode; struct device *usb2_port; struct device *usb3_port; struct device *udc;