From patchwork Wed Apr 18 08:09:58 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yoshihiro Shimoda X-Patchwork-Id: 10347513 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 3213460365 for ; Wed, 18 Apr 2018 08:10:56 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2899D28590 for ; Wed, 18 Apr 2018 08:10:56 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1C9D528599; Wed, 18 Apr 2018 08:10:56 +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 A15D428590 for ; Wed, 18 Apr 2018 08:10:55 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753692AbeDRIKq (ORCPT ); Wed, 18 Apr 2018 04:10:46 -0400 Received: from relmlor2.renesas.com ([210.160.252.172]:39097 "EHLO relmlie1.idc.renesas.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1753668AbeDRIKm (ORCPT ); Wed, 18 Apr 2018 04:10:42 -0400 Received: from unknown (HELO relmlir4.idc.renesas.com) ([10.200.68.154]) by relmlie1.idc.renesas.com with ESMTP; 18 Apr 2018 17:10:41 +0900 Received: from relmlii2.idc.renesas.com (relmlii2.idc.renesas.com [10.200.68.66]) by relmlir4.idc.renesas.com (Postfix) with ESMTP id B2A788A1C2; Wed, 18 Apr 2018 17:10:41 +0900 (JST) X-IronPort-AV: E=Sophos;i="5.48,464,1517842800"; d="scan'208";a="278555599" Received: from mail-pu1apc01lp0019.outbound.protection.outlook.com (HELO APC01-PU1-obe.outbound.protection.outlook.com) ([65.55.88.19]) by relmlii2.idc.renesas.com with ESMTP/TLS/AES256-GCM-SHA384; 18 Apr 2018 17:10:40 +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=TQyyPGcI11FwR10D7fjeKVfGoiPhZdElIkSiU9I6GRY=; b=hzG4BalXPrjKjbMaJc0hyXu6sB/QNEowTJB6pXJ1rxh7bnEQIdw5/NAyNRrJKr+2Ha4sI8b2yuzOYqeUN8z7Y/ZfOjdctMB800MHGSncXSHdIWUVqQL8hiJUmmj56TFstp94NTseeGVJ9nO3LQsqJ9HJhrKZVln+vdHSfkcxLkA= Authentication-Results: linuxfoundation.org; dkim=none (message not signed) header.d=none; linuxfoundation.org; dmarc=none action=none header.from=renesas.com; Received: from localhost.localdomain (211.11.155.138) by SG2PR06MB0982.apcprd06.prod.outlook.com (2a01:111:e400:5213::24) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P256) id 15.20.675.14; Wed, 18 Apr 2018 08:10:33 +0000 From: Yoshihiro Shimoda To: gregkh@linuxfoundation.org, robh+dt@kernel.org, mark.rutland@arm.com, frowand.list@gmail.com Cc: heikki.krogerus@linux.intel.com, hdegoede@redhat.com, andy.shevchenko@gmail.com, p.zabel@pengutronix.de, linux-usb@vger.kernel.org, linux-renesas-soc@vger.kernel.org, devicetree@vger.kernel.org, Yoshihiro Shimoda Subject: [PATCH/RFC 04/11] of: platform: add device connection parsing Date: Wed, 18 Apr 2018 17:09:58 +0900 Message-Id: <1524039005-30618-5-git-send-email-yoshihiro.shimoda.uh@renesas.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1524039005-30618-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> References: <1524039005-30618-1-git-send-email-yoshihiro.shimoda.uh@renesas.com> MIME-Version: 1.0 X-Originating-IP: [211.11.155.138] X-ClientProxiedBy: OSAPR01CA0023.jpnprd01.prod.outlook.com (2603:1096:603:2a::35) To SG2PR06MB0982.apcprd06.prod.outlook.com (2a01:111:e400:5213::24) X-MS-PublicTrafficType: Email X-MS-Office365-Filtering-HT: Tenant X-Microsoft-Antispam: UriScan:; BCL:0; PCL:0; RULEID:(7020095)(4652020)(5600026)(4534165)(4627221)(201703031133081)(48565401081)(2017052603328)(7153060)(7193020); SRVR:SG2PR06MB0982; X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0982; 3:ydPC6suDCQZJh2ghVVivtTs2/edF+ZXqzLF/vuFrOUzq44MQ4G9MUj/65Ug2tdH+d6TEQZd8QKjb6mmQFRXOX/nXuTctak7uZmbAyblLCrU6decOefQUgsB/RH91hWjHJy0884NEo/cbQq8RoZc/66XqafcwtP+MZ77bQypQzaFIL1DUbj2/3Po7B/8nNVvAfpQp7ae0k/izJyN50csfMcNJ0LmZ1G5JF1IxcLrNd/9h9xOlEuo0XXBFpGMij0tP; 25:hNapB8I8GX2Je4dI158B4iVWM9QbXhvjhEBquyYIrs+8Vmx5oTnZ6nz5Rd8rNjwVsP+mdqOvXB7j75pWuqv+ankzL09W5G0XuI3T2N80q5saJ9IjzFMGAwiFSbmDebWzw4XI3WhZMhfC64O88HOQYSIQcPooZ46UVHBLYDpiLe/1S+14tpiykkDPcc+jEAiKKdCBI6nCuW0ejJniVS4BYKuMKcJLiZBHBJRBAyH5t8V/7xKrRVceWKONSZvwbmb6nUhVKQTnOOQzRq3RY9mcdVcQaeGheMorsLDHZePcFCG7bxAeAL0Rcu2D90kOErxTtEwFMyhYKJuCBVWppvwS4g==; 31:QHs47ruh6L20k1xOfwkFYzPXt4xB/mf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antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:; X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(8211001083)(6040522)(2401047)(5005006)(8121501046)(10201501046)(3002001)(3231232)(944501327)(52105095)(93006095)(6055026)(6041310)(20161123562045)(20161123558120)(20161123560045)(20161123564045)(201703131423095)(201702281528075)(20161123555045)(201703061421075)(201703061750153)(6072148)(201708071742011); SRVR:SG2PR06MB0982; BCL:0; PCL:0; RULEID:; SRVR:SG2PR06MB0982; X-Forefront-PRVS: 06469BCC91 X-Forefront-Antispam-Report: SFV:NSPM; SFS:(10019020)(6069001)(39860400002)(346002)(376002)(396003)(366004)(39380400002)(7416002)(956004)(2616005)(6116002)(446003)(3846002)(47776003)(8936002)(97736004)(66066001)(50466002)(4326008)(2906002)(76176011)(42882007)(53936002)(52116002)(6512007)(476003)(107886003)(386003)(11346002)(6506007)(51416003)(36756003)(25786009)(316002)(6666003)(305945005)(16586007)(5660300001)(7736002)(48376002)(78352004)(8676002)(6486002)(50226002)(16526019)(81166006)(39060400002)(498600001)(26005)(3720700003); DIR:OUT; SFP:1102; SCL:1; SRVR:SG2PR06MB0982; H:localhost.localdomain; FPR:; SPF:None; LANG:en; MLV:ovr; PTR:InfoNoRecords; X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SG2PR06MB0982; 23:rlPPGJsLS94GbwEbl16RByT8mDKUkyj81p3Rr/3Sk?= =?us-ascii?Q?sEjQqNb/f7vXTB7d7mzn/U+qn7DfEmvsC7+sPESdz/7fK1PWDNTnMEycCVFv?= =?us-ascii?Q?iyPlvY/7w9h5McRI6d9DEC6xGNBk7t0q/Opjl7hndeAiDN4XMtj/T6eLytmw?= =?us-ascii?Q?iVJ7WSn7J+xfM5HVka7oGbMC4Pk34zvwW2JifYDgrPezIWvFNJUYq0wh7wqE?= =?us-ascii?Q?OZTc/Wt5vnUz79DrhNqgtGuYIfhMlBgjBKc0Bmz6Ggw22XKs1rJ/esWaInTz?= =?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61H+7KUBx?= X-Microsoft-Antispam-Message-Info: FSOGwuS6XGq40gx88jdhf/0oF/Y9UuAXSBvh3YIb8SYk0mHXF/T7o5/aJ7LVFcQmVEYfzcNsPwDIqRIB7oTK2Jc4eoc3TAhOXF6YnDH7RcsXUPUrHfwLLyN/AWptfCcsCW4u4GpzZ0hihvbKlmxxGKVr3nNvKsRm1xE8kQGEhLA0migjnypH9brWL5NK9t+3 X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0982; 6:LpukUuHmWxgFeBneYlSthNHKzI/dq593TxYPVqb6/HDa4K4XsLDriveC+wQjH6yyvIus7/k71o4hiNjhhYlOSPI2xoWqwkjMhCvVPW8jJO/U1FmsZkXQQmNbufbZK9i85AtW4Tar8KPL2rAytucI0uJJitgcwopumm6VSJbt72pqzyx/7eLAGC6dSKQTRasM4FtHfc6VL5GziTwr8GVb7SWH49YtdsG0rbw3Uh9nTo9tzrRw2s3acIwSb97H28SdHlCY9So4K4U8bVSPhara272OIDhcMU3PIAlTl2xIAF5dgYdPc+9MNX2UhTvKdpPz0NR+YkZqh9VNfl4+18KZo9+usGZIfxhjLMaNE/cnjS6x32qAwk34jBT7rGsiEOgOuBKQhpxkyboaDuLqOwsJIn+eWT5YEt6Z9J9ViuU3kRWhLHQYKCGpBUC0jBOTPwhSqWJwKQEjS+lxBxlilp+4Uw==; 5:2YETN4Gq91wgURMc8wj8Ao9fh1sFgdfSj3jum5NEEtK5Z/SeCrPRneh1Ikj3yTrdLOdyLW5c+S3XFHDGCSDj34aVdOVP62i2T0nWh/vJqIytgYvojqFrAsyUYHXKB05MFGkniXmjs17o/vKUihHx1ce4tQhYQivPoskWWE9zXm4=; 24:alNMJNii6726Fed+HJiw6FeS3xWpjwsep6jF3DN1ER86xsnauNVJeSvA1Ah5fTQ8datJ02m4860XUB2iD+j4d0jlQ9Ltne4iFHAR1l5hEII= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SG2PR06MB0982; 7:m1EpwqHpfEDyAs3RaQMlpc58jC21YXL4TfeBO2CkI0cwH2yWM8aXIgQJYsm8ZyDwpC25D5g+FH3F7fieZMvqjcwPQgMsEJ28eyesN1P46srRdgiOR0JKu9xaxdA7V8UarIBbIGsWHSvpVMOF2H2ONQcXykHPu1NQToqabiBiQ4nXGO4ZQ8W73iTAY2729sgAPYmQ5VH41NKarPTARUd+2ylGIPeolEdMtEuA43ZvWgv1otGYsLuH/cWqm4y0yRhT; 20:9K4FRaKFCgAr0O7ZDKv/sfAiPxbUj5SiH1bwQqa/BNit8hQ8jfilD2WjrSOR64zWBBwPm9NjqBPux8STQeFSfWgENWnaPx6RNZi4+raiswr/uxHi2DzlIH8HpnRhPvsFYzbmawxDNxivtS+FoYzbmK0DAJzDVrYBqvVKHaxZyYQ= X-MS-Office365-Filtering-Correlation-Id: 41847888-3dc6-4ad7-a94a-08d5a503dccf X-OriginatorOrg: renesas.com X-MS-Exchange-CrossTenant-OriginalArrivalTime: 18 Apr 2018 08:10:33.8218 (UTC) X-MS-Exchange-CrossTenant-Network-Message-Id: 41847888-3dc6-4ad7-a94a-08d5a503dccf X-MS-Exchange-CrossTenant-FromEntityHeader: Hosted X-MS-Exchange-CrossTenant-Id: 53d82571-da19-47e4-9cb4-625a166a4a2a X-MS-Exchange-Transport-CrossTenantHeadersStamped: SG2PR06MB0982 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 device connection parsing in of_platform_populate(). TODO: - How to free the devcon memories? - How to remove the devcon instances? Signed-off-by: Yoshihiro Shimoda --- drivers/of/platform.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/of.h | 1 + 2 files changed, 67 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index c00d81d..41c018d 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -17,6 +17,7 @@ #include #include #include +#include #include #include #include @@ -326,6 +327,63 @@ static const struct of_dev_auxdata *of_dev_lookup(const struct of_dev_auxdata *l return NULL; } +static int of_parse_device_connection(struct device_node *np) +{ + struct device_node *child_ep, *parent, *remote_parent; + struct platform_device *pdev, *remote_pdev; + struct device_connection *devcon = NULL; + const char *id; + + if (of_node_check_flag(np, OF_DEVICE_CONNECTED)) { + pr_debug("%s() - skipping %pOF, already device connected\n", + __func__, np); + return 0; + } + + of_node_set_flag(np, OF_DEVICE_CONNECTED); + + for_each_endpoint_of_node(np, child_ep) { + if (of_property_read_string(child_ep, "device-connection-id", + &id) < 0) + continue; + + remote_parent = of_graph_get_remote_port_parent(child_ep); + if (!remote_parent) + return 0; + + parent = of_graph_get_port_parent(child_ep); + if (!parent) + return 0; + + pdev = of_find_device_by_node(parent); + if (!pdev) + return 0; + + /* + * WARN_ON in really_probe() may happen if devm_kzalloc is + * used. TODO: How to free this? + */ + devcon = kzalloc(sizeof(*devcon), GFP_KERNEL); + if (!devcon) + return -ENOMEM; + + devcon->id = id; + remote_pdev = of_find_device_by_node(remote_parent); + if (!remote_pdev) { + kfree(devcon); + return 0; + } + + devcon->endpoint[0] = dev_name(&pdev->dev); + devcon->endpoint[1] = dev_name(&remote_pdev->dev); + + /* TODO: How to remove the connection? */ + device_connection_add(devcon); + } + + return 0; +} + /** * of_platform_bus_create() - Create a device for a node and its children. * @bus: device node of the bus to instantiate @@ -477,6 +535,14 @@ int of_platform_populate(struct device_node *root, } of_node_set_flag(root, OF_POPULATED_BUS); + for_each_child_of_node(root, child) { + rc = of_parse_device_connection(child); + if (rc) { + of_node_put(child); + break; + } + } + of_node_put(root); return rc; } diff --git a/include/linux/of.h b/include/linux/of.h index 4d25e4f..30aa103 100644 --- a/include/linux/of.h +++ b/include/linux/of.h @@ -143,6 +143,7 @@ static inline void of_node_put(struct device_node *node) { } #define OF_DETACHED 2 /* node has been detached from the device tree */ #define OF_POPULATED 3 /* device already created for the node */ #define OF_POPULATED_BUS 4 /* of_platform_populate recursed to children of this node */ +#define OF_DEVICE_CONNECTED 5 /* checked devcon on of_platform_populate */ #define OF_BAD_ADDR ((u64)-1)