From patchwork Fri Feb 23 10:23:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10237411 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 6720D60209 for ; Fri, 23 Feb 2018 10:56:00 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5AF8629519 for ; Fri, 23 Feb 2018 10:56:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4E0132951B; Fri, 23 Feb 2018 10:56:00 +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=-1.9 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id F12DD29519 for ; Fri, 23 Feb 2018 10:55:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=zRAqyX7qz/Q1MKpXbHyd3u8F5rofa1vHCitrzBy2z6k=; b=kabMd1jxZLx/f0SCrB3k3fBG0k iuXYs1bq0pvDI5G0Xj1/yHb7cwqzHp03uwMJL0v9JztzJIb9pqavumt1QEeK4Muhh88lpFl7gski2 0Ol0b7KuCnelzNVO+vZGq93l86Im6TUoTQkYJRZNSqnGLQB2SucaaitE4LlWv505uhsUYp8BBgbGG +GSigXJMCVPc2nH+Cs0efpTzsKx25OQ/+aIZMUEd79TG9JipAtKaaBuMLV6PrT+dE0qtESXK2NUvD phXFPvivfYNQwWnEh7O2GXxNzsQakX0FXyirsLdtiqzKSUABtLXpkSqxCDh/jDftvlYr6nP67NkJi /ArIbnaQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.89 #1 (Red Hat Linux)) id 1epB19-0002zq-6J; Fri, 23 Feb 2018 10:55:55 +0000 Received: from merlin.infradead.org ([2001:8b0:10b:1231::1]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1epAnQ-0002ym-6F for linux-arm-kernel@bombadil.infradead.org; Fri, 23 Feb 2018 10:41:44 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=merlin.20170209; h=References:In-Reply-To:Message-Id:Date: Subject:Cc:To:From:Sender:Reply-To:MIME-Version:Content-Type: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=hKE+dtbHYf0RuN0sOC8TzmR2sRg9XSryiPC5z8/Fkcs=; b=IPd/nmGAKGeA3NaZ6DmA4yqyg ucRGsvq1ZRzqD9GxbJIx0DT8vnZywPFwG8cuAtdUh56laYtHB5JWspqqsRrsm/ng/k0zeEMGdAkm/ CBOc0vNtwSoX2g1pV3UhgBRJc5rz/FZ2+3ZztiQhEbPVNBHpyHs76yuAg9YbEbQvZ6eeLXCElEOCU mxPnLp5YTQWbMMv1g1qVO3Xp1DIvIMirhg6EoshA4OvgT4r0DIKKSo1hqFBE9KuyBtOKFsmL4giRj jqRJOW+hZAuahfnVe/8jRVuRbm2ORXvzANGRTG4ZyEiz4y8WhxIbbVdSLKLhduiPmjKTkeUy/+u5/ /+lx5BUAw==; Received: from mail-pl0-x242.google.com ([2607:f8b0:400e:c01::242]) by merlin.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1epAWg-00079Z-Ru for linux-arm-kernel@lists.infradead.org; Fri, 23 Feb 2018 10:24:28 +0000 Received: by mail-pl0-x242.google.com with SMTP id bb3so4662894plb.2 for ; Fri, 23 Feb 2018 02:24:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :in-reply-to:references; bh=hKE+dtbHYf0RuN0sOC8TzmR2sRg9XSryiPC5z8/Fkcs=; b=Mgg8E91skrRWsa2B2JvNIkC6Ea3SOi685GMwsEzBqmJ4Jo3hscWGj4dVSC749q1ll+ 1P6cq1mTvcjxlD/jf52SKzz1tyvVNq+YVeF3ucZjC9tNfrDkORarukHDLglmsX1h3tIT V1WBoFLReBrwXUjigbfjjGWzC07BbHyuv2TSg= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:in-reply-to:references; bh=hKE+dtbHYf0RuN0sOC8TzmR2sRg9XSryiPC5z8/Fkcs=; b=PHIOqhAc72v0oc0qxbhg2Tnvct8Bm8lAEwKWMMPXAKDW2I48A3tX/C9WpvJXVuTo18 EipxUU/HBxoIh2KnUfeHsMjTVVQ91Da4FmpwARruOnne2AC9CuliAvPtakqg6/L96/q+ xq9x0fe87/VzOm0fhy1wUI8PxSIlBFCcov/YEga6eFB/SC4zyxCkfqNu5+uwSAnLe445 BjuJSlmj1vLjCMqkraHhY1W2iHxvQi60ZlGabRkqxBmzB/IfQbM8xTwhefFoX+SlHpgY zqTC5iAKjYzqItcfdrp7WnhJto2TEyMHcFl8RDwZA8caGqYb5QzGBAfo33pREWLDq4af VEKA== X-Gm-Message-State: APf1xPD1zqI3lKYziBBBbMjANAhTXhAVWeyLMQ4jIMr2RX6pxGORTOSR /ANsROaEgxda1pFMf/zPOudGDw== X-Google-Smtp-Source: AH8x22621bYZ3ZKghUlZn1GVm8lfP4caKLiiUa33jOTWcFR00jIeSYSQ5oPFACAMJ5qm9AvpIIfUjw== X-Received: by 2002:a17:902:14cb:: with SMTP id y11-v6mr1279789plg.294.1519381447793; Fri, 23 Feb 2018 02:24:07 -0800 (PST) Received: from localhost ([122.167.232.138]) by smtp.gmail.com with ESMTPSA id a3sm4356866pfh.120.2018.02.23.02.24.06 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 23 Feb 2018 02:24:07 -0800 (PST) From: Viresh Kumar To: Greg Kroah-Hartman Subject: [PATCH V7 01/13] of: platform: Add of_find_any_device_by_node() Date: Fri, 23 Feb 2018 15:53:40 +0530 Message-Id: <483bc64db23821497d0634a86e801510e439fe3d.1519380923.git.viresh.kumar@linaro.org> X-Mailer: git-send-email 2.15.0.194.g9af6a3dea062 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20180223_052426_913861_E4C18A17 X-CRM114-Status: GOOD ( 16.95 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: nm@ti.com, Rajendra Nayak , Stephen Boyd , Viresh Kumar , s.hauer@pengutronix.de, linux-kernel@vger.kernel.org, xuwei5@hisilicon.com, olof@lixom.net, robdclark@gmail.com, robh+dt@kernel.org, fabio.estevam@nxp.com, Vincent Guittot , shawnguo@kernel.org, linux-arm-kernel@lists.infradead.org, l.stach@pengutronix.de MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP This creates a new helper that returns the struct device corresponding to a struct device_node. This currently works only for amba and platform devices, but can be easily extended to include other bus types. This also creates an internal of_find_amba_device_by_node() helper, which isn't exported as of now. Signed-off-by: Viresh Kumar --- drivers/of/platform.c | 55 +++++++++++++++++++++++++++++++++++++++++++++ include/linux/of_platform.h | 5 +++++ 2 files changed, 60 insertions(+) diff --git a/drivers/of/platform.c b/drivers/of/platform.c index c00d81dfac0b..72853f9043e6 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -55,6 +55,61 @@ struct platform_device *of_find_device_by_node(struct device_node *np) } EXPORT_SYMBOL(of_find_device_by_node); +#ifdef CONFIG_ARM_AMBA +/** + * of_find_amba_device_by_node - Find the amba_device associated with a node + * @np: Pointer to device tree node + * + * Takes a reference to the embedded struct device which needs to be dropped + * after use. + * + * Returns amba_device pointer, or NULL if not found + */ +static struct amba_device *of_find_amba_device_by_node(struct device_node *np) +{ + struct device *dev; + + dev = bus_find_device(&amba_bustype, NULL, np, of_dev_node_match); + return dev ? to_amba_device(dev) : NULL; +} +#else +static inline struct amba_device *of_find_amba_device_by_node(struct device_node *np) +{ + return NULL; +} +#endif + +/** + * of_find_any_device_by_node - Find the struct device associated with a node + * @np: Pointer to device tree node + * + * Takes a reference to the embedded struct device which needs to be dropped + * after use. + * + * This currently supports only AMBA and platform devices. + * + * Returns struct device pointer, or NULL if not found + */ +struct device *of_find_any_device_by_node(struct device_node *np) +{ + struct device *dev = NULL; + + if (of_device_is_compatible(np, "arm,primecell")) { + struct amba_device *adev = of_find_amba_device_by_node(np); + + if (adev) + dev = &adev->dev; + } else { + struct platform_device *pdev = of_find_device_by_node(np); + + if (pdev) + dev = &pdev->dev; + } + + return dev; +} +EXPORT_SYMBOL(of_find_any_device_by_node); + #ifdef CONFIG_OF_ADDRESS /* * The following routines scan a subtree and registers a device for diff --git a/include/linux/of_platform.h b/include/linux/of_platform.h index 84a966623e78..5fb20afaf895 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -54,11 +54,16 @@ extern struct platform_device *of_device_alloc(struct device_node *np, struct device *parent); #ifdef CONFIG_OF extern struct platform_device *of_find_device_by_node(struct device_node *np); +extern struct device *of_find_any_device_by_node(struct device_node *np); #else static inline struct platform_device *of_find_device_by_node(struct device_node *np) { return NULL; } +static inline struct device *of_find_any_device_by_node(struct device_node *np) +{ + return NULL; +} #endif /* Platform devices and busses creation */