Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5990923ybi; Wed, 29 May 2019 00:47:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqzim6bZZpEZtY3vOfgdITCi3RJrACBLv+9TJXh4NxVaHdsnRhakMdLxNxJUxD+tK7ICAzBM X-Received: by 2002:a63:fc5b:: with SMTP id r27mr38790007pgk.219.1559116077399; Wed, 29 May 2019 00:47:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559116077; cv=none; d=google.com; s=arc-20160816; b=koId5GlitFPVayArR8guB3xT/C/93QR/QgmKAXfu7YR697nDJM+URKLvVrrb0erqxU i047YN4ongeGLVjHGthuHmLKbstets8auGT8wwdsKodqtn7Q6ixdos2bz9m9RAdeWaQd rmZ866bGmmRILaVlBFsGsQznRnRALknVlw2nCozIow0RY+Qb55eYPMmKYg3tvMMezeJL qezNmBZACLkDXObvP1aJxsOXQyykTwjWbRFz/DzbKsxmUZvOjFq+le5V/3Z6VHH2qmOm FZWtr3t8ZVckV25D71dcSYBLZ2nPdXuNhf8UDCiZf56bYwElC6cE0w991DG+5nZ0JxcN wUuA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from; bh=p/81JYaVknefyY0xTh8kuEpGJnRojIFJFrbRsUsr+IQ=; b=UpjwWu9y34LrIMJfJ9RFZgeEkuScZndplWz8SXh41tycqH9CrMSM1qt88eYJcuW3Wv UwOktOBKyFf6iOsjzDu0qjQBEEluqOojhH3Z2dHikwnCbwHflay0eQSOqv4QfxAGSAw+ 7aINWapz46vTwmpKN+HHcwwTL7K0VBA88XX9Gdwyk+Cpik6wNXLwqTyDXmiid1YYgx8e kSgqfzORuJh/fBRAl/oLuLAkTGwjIgDTSgbqVr0r+ETBnanNNIdLPP45ilLlJh7kxk5P Cxn/Ir62vBuR3gWmQq9H3RjCE2OmzJXhtmjWWFzm7s4EtfpdtRUHGZxtJdSJpk1sgTXL u61w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id f8si23274344pgv.482.2019.05.29.00.47.42; Wed, 29 May 2019 00:47:57 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727109AbfE2Hoy (ORCPT + 99 others); Wed, 29 May 2019 03:44:54 -0400 Received: from Mailgw01.mediatek.com ([1.203.163.78]:25457 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726976AbfE2Ho0 (ORCPT ); Wed, 29 May 2019 03:44:26 -0400 X-UUID: ced8f32f83ee4e7592dd05e4f9172581-20190529 X-UUID: ced8f32f83ee4e7592dd05e4f9172581-20190529 Received: from mtkcas32.mediatek.inc [(172.27.4.253)] by mailgw01.mediatek.com (envelope-from ) (mailgw01.mediatek.com ESMTP with TLS) with ESMTP id 1939931420; Wed, 29 May 2019 15:44:21 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by MTKMBS31N2.mediatek.inc (172.27.4.87) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 29 May 2019 15:44:19 +0800 Received: from localhost.localdomain (10.17.3.153) by MTKCAS06.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Wed, 29 May 2019 15:44:18 +0800 From: Chunfeng Yun To: Rob Herring , Greg Kroah-Hartman , Heikki Krogerus CC: Mark Rutland , Chunfeng Yun , Matthias Brugger , Adam Thomson , Li Jun , Badhri Jagan Sridharan , Hans de Goede , Andy Shevchenko , Min Guo , , , , , , Biju Das , Linus Walleij , Yu Chen Subject: [PATCH v6 08/10] usb: roles: get usb-role-switch from parent Date: Wed, 29 May 2019 15:43:46 +0800 Message-ID: <1559115828-19146-9-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1559115828-19146-1-git-send-email-chunfeng.yun@mediatek.com> References: <1559115828-19146-1-git-send-email-chunfeng.yun@mediatek.com> MIME-Version: 1.0 Content-Type: text/plain X-MTK: N Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org when the USB host controller is the parent of the connector, usually type-B, sometimes don't need the graph, so we should check whether it's parent registers usb-role-switch or not firstly, and get it if exists. Signed-off-by: Heikki Krogerus Signed-off-by: Chunfeng Yun --- v6: new patch --- drivers/usb/roles/class.c | 25 +++++++++++++++++++++---- 1 file changed, 21 insertions(+), 4 deletions(-) diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index aab795b54c7f..1f6af0ef3954 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -114,6 +114,19 @@ static void *usb_role_switch_match(struct device_connection *con, int ep, return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); } +static struct usb_role_switch * +usb_role_switch_is_parent(struct fwnode_handle *fwnode) +{ + struct fwnode_handle *parent = fwnode_get_parent(fwnode); + struct device *dev; + + if (!parent || !fwnode_property_present(parent, "usb-role-switch")) + return NULL; + + dev = class_find_device(role_class, NULL, parent, switch_fwnode_match); + return dev ? to_role_switch(dev) : ERR_PTR(-EPROBE_DEFER); +} + /** * usb_role_switch_get - Find USB role switch linked with the caller * @dev: The caller device @@ -125,8 +138,10 @@ struct usb_role_switch *usb_role_switch_get(struct device *dev) { struct usb_role_switch *sw; - sw = device_connection_find_match(dev, "usb-role-switch", NULL, - usb_role_switch_match); + sw = usb_role_switch_is_parent(dev_fwnode(dev)); + if (!sw) + sw = device_connection_find_match(dev, "usb-role-switch", NULL, + usb_role_switch_match); if (!IS_ERR_OR_NULL(sw)) WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); @@ -146,8 +161,10 @@ struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *fwnode) { struct usb_role_switch *sw; - sw = fwnode_connection_find_match(fwnode, "usb-role-switch", NULL, - usb_role_switch_match); + sw = usb_role_switch_is_parent(fwnode); + if (!sw) + sw = fwnode_connection_find_match(fwnode, "usb-role-switch", + NULL, usb_role_switch_match); if (!IS_ERR_OR_NULL(sw)) WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); -- 2.21.0