From patchwork Thu Apr 26 11:26:43 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 10365647 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id E3241601D3 for ; Thu, 26 Apr 2018 11:27:31 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D0E202906A for ; Thu, 26 Apr 2018 11:27:31 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C506B29089; Thu, 26 Apr 2018 11:27:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.8 required=2.0 tests=BAYES_00,DKIM_SIGNED, MAILING_LIST_MULTI, RCVD_IN_DNSWL_HI, T_DKIM_INVALID autolearn=unavailable version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 3F7AD2906A for ; Thu, 26 Apr 2018 11:27:31 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1755363AbeDZL1X (ORCPT ); Thu, 26 Apr 2018 07:27:23 -0400 Received: from relmlor3.renesas.com ([210.160.252.173]:34854 "EHLO relmlie2.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1754865AbeDZL1M (ORCPT ); Thu, 26 Apr 2018 07:27:12 -0400 Received: from unknown (HELO relmlir3.idc.renesas.com) ([10.200.68.153]) by relmlie2.idc.renesas.com with ESMTP; 26 Apr 2018 20:27:10 +0900 Received: from relmlii1.idc.renesas.com (relmlii1.idc.renesas.com [10.200.68.65]) by relmlir3.idc.renesas.com (Postfix) with ESMTP id BDDB776C06; Thu, 26 Apr 2018 20:27:10 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.49,330,1520866800"; d="scan'208";a="277957260" Received: from mail-ty1jpn01lp0176.outbound.protection.outlook.com (HELO JPN01-TY1-obe.outbound.protection.outlook.com) ([23.103.139.176]) by relmlii1.idc.renesas.com with ESMTP/TLS/AES256-SHA256; 26 Apr 2018 20:27:10 +0900 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=renesasgroup.onmicrosoft.com; s=selector1-renesas-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version; bh=WcXiKgB6XfEn7TI4/Ok75Y919u6HbGTqGGqE91LdseA=; b=TcFyzOyabYCFXvKZr6tJR3F6CxEBkszsIsydMMiEDL+I0KMyajIKNonL3wQc0IHwpGj9L2cbdkexhKtsx1IKCzo8sis8g5rOoTuT2gYuzKyAjtPgIVLVMpinxQWKIjQMovAIJJ3jDuplEJuOXrEPBXqc0wD/MTReqyBSNTRu80Q= Received: from localhost.localdomain (211.11.155.138) by TYAPR01MB2304.jpnprd01.prod.outlook.com (2603:1096:404:8::18) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.696.13; Thu, 26 Apr 2018 11:27:08 +0000 From: Yoshihiro Shimoda To: gregkh@linuxfoundation.org, robh+dt@kernel.org, mark.rutland@arm.com Cc: heikki.krogerus@linux.intel.com, hdegoede@redhat.com, andy.shevchenko@gmail.com, linux-usb@vger.kernel.org, linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH/RFC v2 3/6] usb: common: roles: add a new API to find the graph Date: Thu, 26 Apr 2018 20:26:43 +0900 Message-Id: <1524742006-17984-4-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524742006-17984-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1524742006-17984-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.138] X-ClientProxiedBy: OSAPR01CA0066.jpnprd01.prod.outlook.com (2603:1096:604:a::30) To TYAPR01MB2304.jpnprd01.prod.outlook.com (2603:1096:404:8::18) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(48565401081)(5600026)(4534165)(4627221)(201703031133081)(8559017)(2017052603328)(7153060)(7193020); SRVR:TYAPR01MB2304; X-Microsoft-Exchange-Diagnostics: 1; TYAPR01MB2304; 3:huZgrQe3m8B+PwxVt8n9MJCnxPbs93BFePDqb503PNSezVEvsMF4aD/Z3t/hOjldyzcfZ50gludv4nvAHT5YtMcYXfufqAdZwwJo/TK3NvlCgR93HYcE6npp20aKryoXHEXI9YZAcUHAEHuz5T02fuv13Z3S+lGnrcRWVzb2tXSu7ld0P2NhhM/zNzvK9Vm08nEhWT1WKTa4zQNDRokksO5E7w+Gp06hrG/k8JNnIu3kMVnBhSus7fW1MLswKNEs; 25:Rt+tE7uEUUu5hpgUCT06N0l177NNdpYHe6F25CNFOm+rOSnjyLka7pFIjRzejvadF1xv+pdPb/UwzoX4EjERPGdzyKVjXUPzR7yfee9pkMLZyRAztAupEtpTMTprQwM900kTWEEWrBbAlGq5vZzZqQlBN2ZFmU9tkeDTS9HCrJL71F67+8nHbRVMx3jrY3xN0u6rK/9/PdYj/HMvMpA6Rcoq+Jguk4F6ChUNvTuSc6KriZ1iYXmLb147WH7REYlj+2JWpZXVo9uxNBwGx0p3mkreqpmNVKfhIF5j3SS1xBJpYiLU+2qnnsKxz7Zx/t+H6zfUqbavebzaNVcL2a6N4A==; 31:no+5yZsQyaXIHyT1GKSyoxCImR8Fehwugus56JxS9RexWwiXKfmxjIgW7FUoGfx94xQtd2+C7Iigd9TCFxgnZWr4wJbk1ScPDs8XnS2jojy74KrwZMkiKeuTBNNT9w2ybW1uMlIIMAmhgLE/M9JB/4FaEr5hSKeVNKCtotLXuUyurOKdrTiLzW/y5rgqVddxYcxoVDbGjrkWgNYOp7GzgtTlm+N2hbWjT89ij5dHoPk= X-MS-TrafficTypeDiagnostic: TYAPR01MB2304: Authentication-Results: spf=none (sender IP is ) smtp.mailfrom=<>; X-Microsoft-Exchange-Diagnostics: 1; TYAPR01MB2304; 20:cA/DejtAI/KXcQSxxsOVkwrTQ5Hifjph/RRpXikV0vJK8YX3UBnnmYEYUP3dARj5DJYbX2gg9dJiDPaPlVdF6BjhWRVCvO7g+EeBVy+fbcb4XlL3qc1aIMuvCYl2CoRxtxHyOAK26IyiHduoAQmaPDiRO8Qc56+kkPYO71hUKzKgHYL7nQLdpCl0nUy0nCU3R0sC/dAI4tXMXZS4Z5Ixdp6+BphlTuqxws4eCNeNtwd6rhFZAT1aoXfX2e5bbCThZ15suYiTD/xp+54/Zd6evBLa6jrgh2e+r49VzYXR7kJ8qy0u+2R3UK2KZpPwQE2mXih9H4m+HuMBkzXFdHVSEtQf12R74XXaaoau0VPlffgGzOBgA0Tu5pLZ7iKHCORPpxpAuRQjrVtOtWa66nm9QbY8HDrBbfN/iCzfDbmxmI3Dd/BwKuFatE3PP+cTEn9X4NhyshqUDEwD4NuzQOjUm1U3qsW4oBSVYYuet8T9I2A2kV759lx8SkO75Q+qRMOT; 4:wRYlGlaEWSvJX85b4/gBsP6n6GTIldb7TTIdAqtRv/+LtTVSEargXU84jjVJCFUhpKe9vKyzAnN3p4kGBaOUrNMouNwwenNLvGDZ6wZ6V1l3UqosT8I8xGtV7hl+8PgtcPHjClGzKvlIaU9+TbePjtzxzXtdZxaBL9sizGjYF01gmkX/aZdnvQ8ZP14LKnrPylaZQhA8IAle3eBqsmvnOxnjTqW3XxIr68ZiGVZZOwH3Z+/MqPX71albwQkz1VKT1aeAenGfoL1W/iONCmhUZw== X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(8121501046)(5005006)(3002001)(3231232)(944501410)(52105095)(93006095)(10201501046)(6055026)(6041310)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061750153)(20161123564045)(20161123560045)(20161123558120)(20161123562045)(6072148)(201708071742011); SRVR:TYAPR01MB2304; BCL:0; PCL:0; RULEID:; SRVR:TYAPR01MB2304; X-Forefront-PRVS: 0654257CF5 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(346002)(39380400002)(376002)(39860400002)(396003)(366004)(189003)(199004)(25786009)(48376002)(386003)(81166006)(6506007)(106356001)(316002)(16526019)(305945005)(50466002)(42882007)(26005)(16586007)(51416003)(52116002)(8936002)(81156014)(8676002)(50226002)(11346002)(53936002)(6666003)(78352004)(476003)(486006)(2616005)(446003)(7736002)(956004)(6486002)(6512007)(97736004)(2906002)(66066001)(6116002)(39060400002)(107886003)(3846002)(5660300001)(105586002)(4326008)(47776003)(498600001)(68736007)(36756003)(76176011)(37363001)(3720700003); DIR:OUT; SFP:1102; SCL:1; SRVR:TYAPR01MB2304; H:localhost.localdomain; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:0; A:0; Received-SPF: None (protection.outlook.com: localhost.localdomain does not designate permitted sender hosts) X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; TYAPR01MB2304; 23:/XZ2vdZ+EMl4xBSMMOgeSWwiswaPpyVMvR7Vpenbi?= =?us-ascii?Q?uM/ITTCUsPXf20I5kAq+86YBNZOmWvGbYF7Jmppbln0urQjyGWfwP2jHrsqx?= =?us-ascii?Q?ko3pS/YGt0swYQj5U/YptNH2ue4qBrFAPGbTu1s3fGMBFsInUCuESnwNQ+3h?= =?us-ascii?Q?0tIyhVHAZ+V6bZNm9CTRXOdIQVL84csRmFjQ8Kizeidl+33G6kcfCUPpGDzV?= =?us-ascii?Q?AxdXvjhwL4HDCY+FCchusVW8VzdbBWShG+2XKcnY0h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3UazZktZWbQdhWjnOC7spmjudrimEj8Vw1zL+cTboAZ6zqhxtDDyiO2oLTVJa2KEwjl/mWlbB8Ftf969up03s= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; TYAPR01MB2304; 7:lBIz/weSK9VxgKKnxcpcED7QCFUmFHvqWm4ReLFUVxIPFby9trDVibnRZTxqN52PsjN+f7tJSeC8P4sJpMC/1keBl+UCrb514EK14DzMH+ckk+TjQMzFowMO01YwoVI0G2SSunVggbcQ2ccKij7beW/6xyniLeD5My2igODwmS3qE0gGk8vcQ9274IEcvnV+vV6e2SAC0eDCw5lrpHlC3cQmwtd/l4ilf9S14LfQaLxYuSrlG6MeRHeXuvkt0U5Q; 20:Ay/IHqf7ntgakzuWY/HXMUsaDflRBgFh0FhXhUoF9v2lheLTzlfC3D79h4j7g53hJI5ZkfZdT+9nUqv0v1LVlhoJaK33b7SpuzHhabbamUZwz4uGGaIw/hsnDCvFpEspXTjVkBhP50DAs5uG32460/ctfX1mV1+Tj2KZMdOSItE= X-MS-Office365-Filtering-Correlation-Id: 612f8d45-c2f6-4c9a-3b2c-08d5ab68a585 X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 26 Apr 2018 11:27:08.1276 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 612f8d45-c2f6-4c9a-3b2c-08d5ab68a585 X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: TYAPR01MB2304 Sender: linux-usb-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-usb@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch adds a new API "usb_role_switch_get_by_graph()" to find device connection by using graph. Signed-off-by: Yoshihiro Shimoda --- drivers/usb/common/roles.c | 30 ++++++++++++++++++++++++++++++ include/linux/usb/role.h | 2 ++ 2 files changed, 32 insertions(+) diff --git a/drivers/usb/common/roles.c b/drivers/usb/common/roles.c index 15cc76e..9fa26c1 100644 --- a/drivers/usb/common/roles.c +++ b/drivers/usb/common/roles.c @@ -114,6 +114,36 @@ struct usb_role_switch *usb_role_switch_get(struct device *dev) } EXPORT_SYMBOL_GPL(usb_role_switch_get); +static int by_graph_match(struct device *dev, void *parent) +{ + return dev->parent == parent; +} + +/** + * usb_role_switch_get_by_graph - Find USB role switch linked with the caller + * @dev: The caller device + * @port: identifier of the @dev port node + * @endpoint: identifier of the @dev endpoint node + * + * Finds and returns role switch linked with @dev, port and endpoint. + * The reference count for the found switch is incremented. + */ +struct usb_role_switch *usb_role_switch_get_by_graph(struct device *dev, + u32 port, u32 endpoint) +{ + struct device *conn; + struct device *sw; + + conn = device_connection_find_by_graph(dev, port, endpoint); + if (IS_ERR_OR_NULL(conn)) + return ERR_PTR(-EPROBE_DEFER); + + sw = device_find_child(conn, conn, by_graph_match); + + return !IS_ERR(sw) ? to_role_switch(sw) : ERR_PTR(-EPROBE_DEFER); +} +EXPORT_SYMBOL_GPL(usb_role_switch_get_by_graph); + /** * 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 edc51be..6573fdd 100644 --- a/include/linux/usb/role.h +++ b/include/linux/usb/role.h @@ -43,6 +43,8 @@ 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 *usb_role_switch_get_by_graph(struct device *dev, + u32 port, u32 endpoint); void usb_role_switch_put(struct usb_role_switch *sw); struct usb_role_switch *