Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp5990469ybi; Wed, 29 May 2019 00:47:21 -0700 (PDT) X-Google-Smtp-Source: APXvYqyyTwr7xP+IcAB1IoqQyy75QEqcYHEZFPeB8UFnP59PJmF8KGGlgSKJniU5M0Cp4kcmpApw X-Received: by 2002:a17:902:b201:: with SMTP id t1mr38161307plr.328.1559116041659; Wed, 29 May 2019 00:47:21 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1559116041; cv=none; d=google.com; s=arc-20160816; b=FXotOXpWG9RGXNajmJLc2Wu0M4pAuhcdq85f4nbEb2sljFm0MBOh8PgZgH6a7mvQvu z14bkR4bLnOvp+1R9bKmqHERxJFMBTOv0wOAkw+d/NykjtBXR5k29IXzH29XprGOcuK0 idZ+7LJ7Iac2g1t0S+bKso//fnyy9/UqrTARvevm09p+FGmBuCwAtr/baE0P8gzzi7NO d8euPtzH/omz8WlzbBQaZoDdjiO8X7z/ru3XbYoxFhD4o6Muy60HsXfJnSJQtMkoVmr1 6iob01yBxl8o3a7gY1ScQO7Dv0XLTKfE0JlUpnC50IocDeTS3sNr0BfDX/eOwt6U7fH6 0xbw== 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=oYwBqaZZ3iJOIakj9YaRCDNPHcjP4zUUd8DdmpcoN1o=; b=xFi/mt6xthDHvHg+p4pP4S/RNFta8R3IDz8f4WhdrfoH44wfm3LabcCIxWsfyE6YH5 YliZuN8v2iCvlWdrbMlI82A3WKowZfrkwCtu2K3ZdefNgryE9r1lD8Fr7I7rsrHXxvrh eb3peZ4X9Zaq1VNINGIDZB75tV7KwRm6sp388QOjFkUPwakdcZ9Ytm8RNhae+6K/KgOY SEtHZjr77ghXc+H2TgvomdiwXEdn8/ruRuDMWWmU42tbpOk9yUv8kz05dfY82KyHf4QQ SsgFjWl5RJ0h+V6w611dNU9RmAOl7SHdaQu9cJqfgDQsEqaigymQ1YfPkMqlbXIuAr70 wU6Q== 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 x13si19679134pgi.165.2019.05.29.00.47.06; Wed, 29 May 2019 00:47:21 -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 S1727048AbfE2Hod (ORCPT + 99 others); Wed, 29 May 2019 03:44:33 -0400 Received: from Mailgw01.mediatek.com ([1.203.163.78]:27133 "EHLO mailgw01.mediatek.com" rhost-flags-OK-FAIL-OK-FAIL) by vger.kernel.org with ESMTP id S1726956AbfE2HoZ (ORCPT ); Wed, 29 May 2019 03:44:25 -0400 X-UUID: 0786f40890024462bae5f42eb606e44a-20190529 X-UUID: 0786f40890024462bae5f42eb606e44a-20190529 Received: from mtkcas36.mediatek.inc [(172.27.4.253)] by mailgw01.mediatek.com (envelope-from ) (mailgw01.mediatek.com ESMTP with TLS) with ESMTP id 586233352; Wed, 29 May 2019 15:44:19 +0800 Received: from MTKCAS06.mediatek.inc (172.21.101.30) by MTKMBS31DR.mediatek.inc (172.27.6.102) with Microsoft SMTP Server (TLS) id 15.0.1395.4; Wed, 29 May 2019 15:44:17 +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:16 +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 07/10] usb: roles: Add fwnode_usb_role_switch_get() function Date: Wed, 29 May 2019 15:43:45 +0800 Message-ID: <1559115828-19146-8-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 From: Heikki Krogerus The fwnode_usb_role_switch_get() function is exactly the same as usb_role_switch_get(), except that it takes struct fwnode_handle as parameter instead of struct device. Signed-off-by: Heikki Krogerus --- v6: new patch --- drivers/usb/roles/class.c | 20 ++++++++++++++++++++ include/linux/usb/role.h | 7 +++++++ 2 files changed, 27 insertions(+) diff --git a/drivers/usb/roles/class.c b/drivers/usb/roles/class.c index f45d8df5cfb8..aab795b54c7f 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -135,6 +135,26 @@ 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 linked with the caller + * @fwnode: The caller device node + * + * This is similar to the usb_role_switch_get() function above, but it searches + * the switch using fwnode instead of device entry. + */ +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); + if (!IS_ERR_OR_NULL(sw)) + 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..2d77f97df72d 100644 --- a/include/linux/usb/role.h +++ b/include/linux/usb/role.h @@ -47,6 +47,7 @@ struct usb_role_switch_desc { 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); +struct usb_role_switch *fwnode_usb_role_switch_get(struct fwnode_handle *node); void usb_role_switch_put(struct usb_role_switch *sw); struct usb_role_switch * @@ -70,6 +71,12 @@ static inline struct usb_role_switch *usb_role_switch_get(struct device *dev) return ERR_PTR(-ENODEV); } +static inline struct usb_role_switch * +fwnode_usb_role_switch_get(struct fwnode_handle *node) +{ + return ERR_PTR(-ENODEV); +} + static inline void usb_role_switch_put(struct usb_role_switch *sw) { } static inline struct usb_role_switch * -- 2.21.0