From patchwork Tue Feb 18 14:05:09 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: 11388505 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 A3CA2138D for ; Tue, 18 Feb 2020 14:05:41 +0000 (UTC) Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (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 8BB212176D for ; Tue, 18 Feb 2020 14:05:41 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8BB212176D 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 whitealder.osuosl.org (Postfix) with ESMTP id 6E4D28614D; Tue, 18 Feb 2020 14:05:41 +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 YUAWgUmfb6s4; Tue, 18 Feb 2020 14:05:40 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 1C71484B8B; Tue, 18 Feb 2020 14:05:40 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 18B2AC013E; Tue, 18 Feb 2020 14:05:40 +0000 (UTC) X-Original-To: cip-dev@lists.cip-project.org Delivered-To: cip-dev@lists.linuxfoundation.org Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) by lists.linuxfoundation.org (Postfix) with ESMTP id AA8FBC013E for ; Tue, 18 Feb 2020 14:05:38 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 9973487447 for ; Tue, 18 Feb 2020 14:05:38 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id A+txTme0xjqX for ; Tue, 18 Feb 2020 14:05:38 +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 hemlock.osuosl.org (Postfix) with ESMTP id DD44C8741F for ; Tue, 18 Feb 2020 14:05:37 +0000 (UTC) X-IronPort-AV: E=Sophos;i="5.70,456,1574089200"; d="scan'208";a="39401313" Received: from unknown (HELO relmlir5.idc.renesas.com) ([10.200.68.151]) by relmlie6.idc.renesas.com with ESMTP; 18 Feb 2020 23:05:37 +0900 Received: from marian-VirtualBox.ree.adwin.renesas.com (unknown [10.226.36.164]) by relmlir5.idc.renesas.com (Postfix) with ESMTP id D442D40061A5; Tue, 18 Feb 2020 23:05:36 +0900 (JST) From: Marian-Cristian Rotariu To: cip-dev@lists.cip-project.org Date: Tue, 18 Feb 2020 14:05:09 +0000 Message-Id: <1582034720-5249-13-git-send-email-marian-cristian.rotariu.rb@bp.renesas.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1582034720-5249-1-git-send-email-marian-cristian.rotariu.rb@bp.renesas.com> References: <1582034720-5249-1-git-send-email-marian-cristian.rotariu.rb@bp.renesas.com> Subject: [cip-dev] [PATCH 4.19.y-cip 12/23] usb: roles: Add fwnode_usb_role_switch_get() function 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 a31f01777bc54a0a9d57628956d05f8d454d3418 upstream. 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 Signed-off-by: Chunfeng Yun Tested-by: Biju Das Link: https://lore.kernel.org/r/1567070558-29417-8-git-send-email-chunfeng.yun@mediatek.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Marian-Cristian Rotariu --- 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 6b3c087..a4e498e 100644 --- a/drivers/usb/roles/class.c +++ b/drivers/usb/roles/class.c @@ -136,6 +136,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 b880e6a..8029d1b 100644 --- a/include/linux/usb/role.h +++ b/include/linux/usb/role.h @@ -46,6 +46,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 * @@ -69,6 +70,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 *