Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp6114790yba; Tue, 14 May 2019 01:49:13 -0700 (PDT) X-Google-Smtp-Source: APXvYqw2bXbTz+q7l7IAgFEmaLAquygeKgxOExPxnrR6eC53T3LLrdUOFwYoWV6zsCHuQxKyIozJ X-Received: by 2002:a65:5785:: with SMTP id b5mr291522pgr.252.1557823753285; Tue, 14 May 2019 01:49:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1557823753; cv=none; d=google.com; s=arc-20160816; b=SHPZ1EWJH0oaKIHyibGPpJDKPU1xtZ2KtuN7J9JI2NNmVJvD8GU+NxbwIzFXpzk33/ l6yDTa5q0ootB0lAiqo7jEOvZJfjn2SfK0MNWzHAwrQT8TEmOSMbrzMfWG+XVh1tHRu1 gGLULg4rJNP5iWQQL7bFSDy9Uwj2p0kRpJMm3rV7cmqWdakgF4Dvt/GMcM2qwx6Nqrxb B0tZrFMaPHYPEQgp26bjbE0n7wnFNnu55CUTeJGDpE92Nwvz5xGo2KUvn0M35s1yV1Xg yYuxtGqmE2Be48mo3dREeLaj1n32ZrKAmr95Si63II/sfaB1EWn8BV2uacbzOedwv4BJ wZSg== 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=NE/JlG2ITesBMt79u7ZkeMh5IVLZmf4jXaesr8LF69E=; b=HZnnNqkHrvdASRCSuUvRgkmg5Z4OWaZIG6qyUdO2VqasFjrvThqYodGzJOY1psg6X2 lDfHVJ+F0A9pFz68HJL0ZB2ldeEuR/7vYp0T+aFGpvE34c+PEhQIqIPMDhPGc32yRNNj VSkEzuew7Z/wDwQQUTbmb39EqjB4uXmSNi3RjOyor7ZOMddc9Qg/VSqZTTtxl6DycVx3 A4sUviamonj82qi+MKFTD+AVGPmxY0/K5ZTbgak6nZqI19asYGQ/DMkS3ZY4GWtAJHPX efsfg8h1BJifyeGdHj1d7L5Whc4YTAIDnWnVmB29O3wpxPNN+IaAGFjonRyA35/3Ncfr mDvA== 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 z10si19037266pgl.245.2019.05.14.01.48.58; Tue, 14 May 2019 01:49:13 -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 S1726666AbfENIrp (ORCPT + 99 others); Tue, 14 May 2019 04:47:45 -0400 Received: from Mailgw01.mediatek.com ([1.203.163.78]:16331 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726078AbfENIrn (ORCPT ); Tue, 14 May 2019 04:47:43 -0400 X-UUID: bf67b581522545769da9ebb09abf606a-20190514 X-UUID: bf67b581522545769da9ebb09abf606a-20190514 Received: from mtkcas32.mediatek.inc [(172.27.4.253)] by mailgw01.mediatek.com (envelope-from ) (mailgw01.mediatek.com ESMTP with TLS) with ESMTP id 1296192849; Tue, 14 May 2019 16:47:37 +0800 Received: from mtkcas08.mediatek.inc (172.21.101.126) by MTKMBS31N1.mediatek.inc (172.27.4.69) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Tue, 14 May 2019 16:47:36 +0800 Received: from localhost.localdomain (10.17.3.153) by mtkcas08.mediatek.inc (172.21.101.73) with Microsoft SMTP Server id 15.0.1395.4 via Frontend Transport; Tue, 14 May 2019 16:47:34 +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 Subject: [PATCH v5 4/6] usb: roles: add API to get usb_role_switch by node Date: Tue, 14 May 2019 16:47:21 +0800 Message-ID: <1557823643-8616-5-git-send-email-chunfeng.yun@mediatek.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: <1557823643-8616-1-git-send-email-chunfeng.yun@mediatek.com> References: <1557823643-8616-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 Add fwnode_usb_role_switch_get() to make easier to get usb_role_switch by fwnode which register it. It's useful when there is not device_connection registered between two drivers and only knows the fwnode which register usb_role_switch. Signed-off-by: Chunfeng Yun Tested-by: Biju Das --- v5 changes: 1. remove linux/of.h suggested by Biju 2. add tested by Biju Note: still depends on [1] [1]: [v6,08/13] usb: roles: Introduce stubs for the exiting functions in role.h https://patchwork.kernel.org/patch/10909971/ v4 changes: 1. use switch_fwnode_match() to find fwnode suggested by Heikki 2. this patch now depends on [1] [1] [v6,08/13] usb: roles: Introduce stubs for the exiting functions in role.h https://patchwork.kernel.org/patch/10909971/ v3 changes: 1. use fwnodes instead of node suggested by Andy 2. rebuild the API suggested by Heikki v2 no changes --- drivers/usb/roles/class.c | 24 ++++++++++++++++++++++++ include/linux/usb/role.h | 8 ++++++++ 2 files changed, 32 insertions(+) diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index f45d8df5cfb8..4a1f09a41ec0 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -135,6 +135,30 @@ struct usb_role_switch *usb_role_switch_get(struct device *dev) } EXPORT_SYMBOL_GPL(usb_role_switch_get); +/** + * fwnode_usb_role_switch_get - Find USB role switch by it's parent fwnode + * @fwnode: The fwnode that register USB role switch + * + * Finds and returns role switch registered by @fwnode. The reference count + * for the found switch is incremented. + */ +struct usb_role_switch * +fwnode_usb_role_switch_get(struct fwnode_handle *fwnode) +{ + struct usb_role_switch *sw; + struct device *dev; + + dev = class_find_device(role_class, NULL, fwnode, switch_fwnode_match); + if (!dev) + return ERR_PTR(-EPROBE_DEFER); + + sw = to_role_switch(dev); + WARN_ON(!try_module_get(sw->dev.parent->driver->owner)); + + return sw; +} +EXPORT_SYMBOL_GPL(fwnode_usb_role_switch_get); + /** * usb_role_switch_put - Release handle to a switch * @sw: USB Role Switch diff --git a/include/linux/usb/role.h b/include/linux/usb/role.h index da2b9641b877..35d460f9ec40 100644 --- a/include/linux/usb/role.h +++ b/include/linux/usb/role.h @@ -48,6 +48,8 @@ int usb_role_switch_set_role(struct usb_role_switch *sw, enum usb_role role); enum usb_role usb_role_switch_get_role(struct usb_role_switch *sw); struct usb_role_switch *usb_role_switch_get(struct device *dev); void usb_role_switch_put(struct usb_role_switch *sw); +struct usb_role_switch * +fwnode_usb_role_switch_get(struct fwnode_handle *fwnode); struct usb_role_switch * usb_role_switch_register(struct device *parent, @@ -72,6 +74,12 @@ static inline struct usb_role_switch *usb_role_switch_get(struct device *dev) static inline void usb_role_switch_put(struct usb_role_switch *sw) { } +static inline struct usb_role_switch * +fwnode_usb_role_switch_get(struct fwnode_handle *fwnode) +{ + return ERR_PTR(-ENODEV); +} + static inline struct usb_role_switch * usb_role_switch_register(struct device *parent, const struct usb_role_switch_desc *desc) -- 2.21.0