From patchwork Tue Nov 6 18:36:06 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stephen Boyd X-Patchwork-Id: 10671293 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1393514BD for ; Tue, 6 Nov 2018 18:37:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 062752AAF1 for ; Tue, 6 Nov 2018 18:37:07 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id ECB282AB9D; Tue, 6 Nov 2018 18:37:06 +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=-3.6 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,MAILING_LIST_MULTI,RCVD_IN_DNSWL_LOW 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 94BD22AAF1 for ; Tue, 6 Nov 2018 18:37:06 +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:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version: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=siFITNew04LyzOwVzR5u+0YEqSHWPE5FCU//YKwJltc=; b=LmudTd7KJJKzHi /64WtCFi5Xhe5nrsaYPTk+H2gRD8LFnnURySweEN5F0679h8Vdlj8pJbnmVQyetXwR1Nc7nbZg3p7 +9IinsEldqPKHLBuIQ6ImCWNcaL3uYlN0QdYC9jT7illLbKQlizNuyh5DNl+pElG007EUWSFaWkU2 4SuyWgcJqqUnoEteAXaFF3uUEIVO36fnrWZctAyKBe0Eqs2cnUT5G7Lqpyi9YOKDJF2PQcsh8rD5w WkEx5rBm5hQUpQs2upiHQqCZ2apQ8Ue0GgMmDYJPTZ+2NtfrRaQ/QfySvbPuccikHQQugrdqt/vMu aTYLv2c/xOU2mXhRKHjw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1gK6Do-00034k-GD; Tue, 06 Nov 2018 18:37:04 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gK6DF-0002K6-AY; Tue, 06 Nov 2018 18:36:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: References:In-Reply-To:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To: Content-Type: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=gj6WRiqmNoW0bmYW98fbS5/BK2B5npYLuXEjbBUQhjY=; b=VXEu8gkD16IUzTDL/jQ8xo4UaI 8lpjtfkV4lBdzwav2HTT//eC18JCB/Wtasb05cZGEu0W7LfFRRz7gxcWAxk9RYiEBSz7K9ZdabJyb NMg361MZKmRTtsXL4VnwFuayKgc7QGcbjbBKg06GUhgj9T5H1ojY2r+yJH5y/piZ9Xdi+U+94B8na chFxdbuo63BAECFUzJB0IcYWUqpg7U39JFLnUGa/1CZdjlcy6DIbFsnn4nuTnT01bCPZDWNxpsfmE OWqS0mc28RDbeK/CrFjet/pLFS625Urt4zmqRq0hsDa+A/Svu9Ze+K7+4AuYSAmSWq5L85iMT71g2 STPDKYxg==; Received: from mail.kernel.org ([198.145.29.99]) by casper.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1gK6D9-0000HM-Vv; Tue, 06 Nov 2018 18:36:27 +0000 Received: from mail.kernel.org (unknown [104.132.0.74]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id DEE1E2086A; Tue, 6 Nov 2018 18:36:10 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1541529371; bh=DKKrHcZEDvckhztoXQTQEnrDWU/3m1rqWN3NL85hfTU=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YvlFanP6vaGAN6nhlrLV9C/on7L+sJ+of5UEB5QRLkPhIQ5XB27/g28ynEAXbbHG3 BXNZ8QfDfRJelJVaoXrD6pVTwgjA3lxCPmmW9K4y0v64jh0f/ugqteJR67h1I4AwjJ 3ksKm5x5YOg38CQjU+kyINxXkuhjg7ldCK1MbTUI= From: Stephen Boyd To: Michael Turquette , Stephen Boyd Subject: [PATCH 1/4] of/device: Add a way to probe drivers by match data Date: Tue, 6 Nov 2018 10:36:06 -0800 Message-Id: <20181106183609.207702-2-sboyd@kernel.org> X-Mailer: git-send-email 2.19.1.930.g4563a0d9d0-goog In-Reply-To: <20181106183609.207702-1-sboyd@kernel.org> References: <20181106183609.207702-1-sboyd@kernel.org> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181106_183624_422131_A245732A X-CRM114-Status: GOOD ( 17.40 ) X-BeenThere: linux-mediatek@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: devicetree@vger.kernel.org, Ryder Lee , linux-kernel@vger.kernel.org, Rob Herring , linux-mediatek@lists.infradead.org, Matthias Brugger , Frank Rowand , linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org Sender: "Linux-mediatek" Errors-To: linux-mediatek-bounces+patchwork-linux-mediatek=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP We have a handful of clk drivers that have a collection of slightly variant device support keyed off of the compatible string. In each of these drivers, we demux the variant and then call the "real" probe function based on whatever is stored in the match data for that compatible string. Let's generalize this function so that it can be re-used as the platform_driver probe function directly. Cc: Ryder Lee Cc: Rob Herring Cc: Frank Rowand Signed-off-by: Stephen Boyd --- drivers/of/device.c | 31 +++++++++++++++++++++++++++++++ include/linux/of_device.h | 1 + 2 files changed, 32 insertions(+) diff --git a/drivers/of/device.c b/drivers/of/device.c index 0f27fad9fe94..8381f33ed2d8 100644 --- a/drivers/of/device.c +++ b/drivers/of/device.c @@ -195,6 +195,37 @@ const void *of_device_get_match_data(const struct device *dev) } EXPORT_SYMBOL(of_device_get_match_data); +/** + * platform_driver_probe_by_of_match_data - Probe a platform device using match data + * @pdev: platform device to probe + * + * For use by device drivers that multiplex their probe function through DT + * match data. Drivers can use this function to call their platform + * device probe directly without having to implement a wrapper function. + * + * static const struct of_device_id probe_funcs[] = { + * { .compatible = "compat,foo", .data = foo_probe }, + * {} + * }; + * + * struct platform_driver foo_driver = { + * .probe = platform_driver_probe_by_of_match_data, + * .driver = { + * of_match_table = probe_funcs, + * }, + * }; + * + */ +int platform_driver_probe_by_of_match_data(struct platform_device *pdev) +{ + int (*probe_func)(struct platform_device *pdev); + + probe_func = of_device_get_match_data(&pdev->dev); + + return probe_func(pdev); +} +EXPORT_SYMBOL_GPL(platform_driver_probe_by_of_match_data); + static ssize_t of_device_get_modalias(struct device *dev, char *str, ssize_t len) { const char *compat; diff --git a/include/linux/of_device.h b/include/linux/of_device.h index 8d31e39dd564..4de84691d1c6 100644 --- a/include/linux/of_device.h +++ b/include/linux/of_device.h @@ -33,6 +33,7 @@ extern int of_device_add(struct platform_device *pdev); extern int of_device_register(struct platform_device *ofdev); extern void of_device_unregister(struct platform_device *ofdev); +extern int platform_driver_probe_by_of_match_data(struct platform_device *pdev); extern const void *of_device_get_match_data(const struct device *dev); extern ssize_t of_device_modalias(struct device *dev, char *str, ssize_t len);