From patchwork Wed Jan 10 03:47:30 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Viresh Kumar X-Patchwork-Id: 10153859 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 90FC5602D8 for ; Wed, 10 Jan 2018 03:48:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7FBCB27528 for ; Wed, 10 Jan 2018 03:48:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7496927853; Wed, 10 Jan 2018 03:48:09 +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=-4.2 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.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 DE22727813 for ; Wed, 10 Jan 2018 03:48:08 +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=GS/C+0um+r8luyAL6a8PGlw8M0g4V9QjyJR+gmrE26Y=; b=dgidE9nUVgrX0YpPoIWhpfTTbM devtom2wBACeFwme/o9cAiRPSKo2fVbRPLEMw/80QWrHGP0ocn8blpgm6fv1RnbKr6JWN+9P+QH0t 06P7Cy3jo5AZyr5SbXMRx/iUod0/0RTRhzhbgi2zk+nTgpGQUOq9W8RcD4mkD7bXVmTJzRtgnugbQ 3TG9n7ChoE9c7ooVwOiCiGJ/SM5GSITYtXMapxHf1bR9xbmLXxri+58V2Px5VqQ75XqjNipvos2h3 HmD9Im/gUbSds6A17AooNhmRIFPkc0QXKhno39f2JhthEocf4ex2swLNn9qOM9Q4auxpmExPYtH0X YBqaNt+Q==; 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 1eZ7N1-00027r-O7; Wed, 10 Jan 2018 03:48:07 +0000 Received: from mail-pg0-x242.google.com ([2607:f8b0:400e:c05::242]) by bombadil.infradead.org with esmtps (Exim 4.89 #1 (Red Hat Linux)) id 1eZ7My-00025j-60 for linux-arm-kernel@lists.infradead.org; Wed, 10 Jan 2018 03:48:05 +0000 Received: by mail-pg0-x242.google.com with SMTP id i5so9808434pgq.11 for ; Tue, 09 Jan 2018 19:47:56 -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=JvF1dk+O7f0i+Fy6jVvZS+EaoWZtI51KnXjLkfkaMqQ=; b=Ce6DzfwYVXN+KftvKMbWxtfcaTa1QZCA3Xl0+JEjS8s50iVeSmmSeBRCFOyx9zexcV tK3C5ehEOI1PiythfXoT4IIgelUT4lhW20il+QkuQj8Jqb7jPmLEj7AFjz2Ywagd5tAo 4pLc+EMrw2KFTxS6aRyyAudfk2JO+76X6Y1b0= 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=JvF1dk+O7f0i+Fy6jVvZS+EaoWZtI51KnXjLkfkaMqQ=; b=GSFSugdxELeLHlc+Hfoo6LfnkHkqaReNqZcc35Aw1JH9fSABFdIAAo6D1NunXJphCK X2AWRolJ/2RnWxyTEYf4N9UeThhIPL5weg/gHdB2+ng5jRWAkdlioJOE3iZB+VcihjWS JWp5jBbbvSjN1i9bbI0v90/nUJEIgsFcZofii0LGuiEt01rGu8aX+wWr/PbB2JFEjjQZ hvtTHlnPpqKzjeoCdYztNi5Livza85pri6halDTpA6AYD1QzD2xsHe6/xCRaF9ec+p9Q aa7iyaptw09hx55VJx45Tvs+RL+dt1dDAMWt1ilXf2vypoIAdqmjoZGA/Tzhzq4md6uZ tnbA== X-Gm-Message-State: AKwxytcRv0tiMeRTgZQ879az99h5TYIfK09XG1EZMAfeupxzXTuI87NN zZk0DvADTFH0eKclrxSPsdoypQ== X-Google-Smtp-Source: ACJfBouLtm3eoTWv4LGZWroJV7TQDy/aV7DouHbX7xgpdzIe+UcOUdUl+baDU3Qtewte3pzuiGAdsA== X-Received: by 10.99.2.136 with SMTP id 130mr2613478pgc.268.1515556075532; Tue, 09 Jan 2018 19:47:55 -0800 (PST) Received: from localhost ([122.172.19.39]) by smtp.gmail.com with ESMTPSA id i186sm30474804pfg.178.2018.01.09.19.47.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 09 Jan 2018 19:47:55 -0800 (PST) From: Viresh Kumar To: Greg Kroah-Hartman Subject: [PATCH V6 01/13] of: platform: Add of_find_any_device_by_node() Date: Wed, 10 Jan 2018 09:17:30 +0530 Message-Id: <744c2ed81cfe95768369b061c422eec3708447a0.1515554879.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-20180109_194804_251141_ED8EC516 X-CRM114-Status: GOOD ( 13.49 ) 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 , Viresh Kumar , s.hauer@pengutronix.de, Stephen Boyd , linux-kernel@vger.kernel.org, xuwei5@hisilicon.com, 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 b7cf84b29737..61a4a81bea9f 100644 --- a/drivers/of/platform.c +++ b/drivers/of/platform.c @@ -60,6 +60,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 fb908e598348..4909d1aa47ec 100644 --- a/include/linux/of_platform.h +++ b/include/linux/of_platform.h @@ -59,11 +59,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 */