From patchwork Fri Oct 28 06:50:17 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangbo Lu X-Patchwork-Id: 9401347 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 6733B60588 for ; Fri, 28 Oct 2016 07:05:16 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5408C2A5CE for ; Fri, 28 Oct 2016 07:05:16 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4851D2A5D1; Fri, 28 Oct 2016 07:05:16 +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=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 B98C82A5CE for ; Fri, 28 Oct 2016 07:05:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965102AbcJ1HEv (ORCPT ); Fri, 28 Oct 2016 03:04:51 -0400 Received: from mail-sn1nam01on0044.outbound.protection.outlook.com ([104.47.32.44]:53341 "EHLO NAM01-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965879AbcJ1HD5 (ORCPT ); Fri, 28 Oct 2016 03:03:57 -0400 Received: from CY1PR03CA0037.namprd03.prod.outlook.com (10.174.128.47) by SN2PR03MB2384.namprd03.prod.outlook.com (10.166.210.151) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.12; Fri, 28 Oct 2016 07:03:54 +0000 Received: from BN1AFFO11FD047.protection.gbl (2a01:111:f400:7c10::160) by CY1PR03CA0037.outlook.office365.com (2603:10b6:600::47) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.679.12 via Frontend Transport; Fri, 28 Oct 2016 07:03:54 +0000 Authentication-Results: spf=fail (sender IP is 192.88.168.50) smtp.mailfrom=nxp.com; nxp.com; dkim=none (message not signed) header.d=none; nxp.com; dmarc=fail action=none header.from=nxp.com; nxp.com; dkim=none (message not signed) header.d=none; Received-SPF: Fail (protection.outlook.com: domain of nxp.com does not designate 192.88.168.50 as permitted sender) receiver=protection.outlook.com; client-ip=192.88.168.50; helo=tx30smr01.am.freescale.net; Received: from tx30smr01.am.freescale.net (192.88.168.50) by BN1AFFO11FD047.mail.protection.outlook.com (10.58.53.62) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.679.5 via Frontend Transport; Fri, 28 Oct 2016 07:03:53 +0000 Received: from titan.ap.freescale.net ([10.192.208.233]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id u9S72smg019535; Fri, 28 Oct 2016 00:03:45 -0700 From: Yangbo Lu To: , , Scott Wood , Arnd Bergmann CC: , , , , , , , , Greg Kroah-Hartman , Mark Rutland , Rob Herring , Russell King , Jochen Friedrich , Joerg Roedel , Claudiu Manoil , Bhupesh Sharma , Qiang Zhao , Kumar Gala , Santosh Shilimkar , Leo Li , Xiaobo Xie , Minghuan Lian , Yangbo Lu Subject: [v15, 6/7] base: soc: introduce soc_device_match() interface Date: Fri, 28 Oct 2016 14:50:17 +0800 Message-ID: <1477637418-38938-7-git-send-email-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.1.0.27.g96db324 In-Reply-To: <1477637418-38938-1-git-send-email-yangbo.lu@nxp.com> References: <1477637418-38938-1-git-send-email-yangbo.lu@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131221118336300591; (91ab9b29-cfa4-454e-5278-08d120cd25b8); () X-Forefront-Antispam-Report: CIP:192.88.168.50; IPV:NLI; CTRY:US; EFV:NLI; SFV:NSPM; SFS:(10009020)(6009001)(7916002)(2980300002)(1109001)(1110001)(339900001)(199003)(189002)(87936001)(11100500001)(19580395003)(356003)(5003940100001)(36756003)(8666005)(50986999)(76176999)(19580405001)(2906002)(97736004)(7846002)(81156014)(189998001)(8676002)(5001770100001)(81166006)(5660300001)(305945005)(47776003)(4326007)(106466001)(50226002)(229853001)(2950100002)(68736007)(92566002)(586003)(104016004)(6666003)(7416002)(33646002)(48376002)(8936002)(77096005)(105606002)(626004)(85426001)(50466002)(86362001)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:SN2PR03MB2384; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD047; 1:ElAGkvCwZwSnxdn+JrjSbnJdbbvXKKh17x0XmsiF5xe6ckXV1R4ZLiO+MZ6IqPBeTI27pSRzb7wAsZYls9hFhRTvwHYc1O9YDd10FbHZ9MvUOYgOrMbJjDmXMJ3S85qmTai9rUIw3yixCAuFIDUMc0hcBPM8fcA7vdOboKnaf6lRFI7h3mCQlt6kFwKkI1gKkXyd7lu+acuf1guBqljrnBnEUMOwz4exd/flmtpHMBEKWXqynWqzdFFE03gHRXW1zIc03N7Wjqv95bJIjfqaKlOtzemFcnahxQLPyFwWUk3VrFECfEcvPA/QfC1apWcS7sJ43IwZ4P/qNnnNv5gcHgINrAj0ssgRVZNm23B/2bVjplVW2PV+yqTvRFDgOPjFi1qs1PPiSyZnmInVCndxtmr7mFPF9hFYpz6WEjVuHe8NqDp62xXVXG+Oi3QLdBpksGMWhybk77aWt0PI6xYc20erxhkn8jC9EDJsRkzP9e8FQbrjFQihFSXbpMe66jxciuA3O0i0RAN83YAgQQAXcGWbrsrMp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Ghxpt07JNGdMXC9oUiKNN1dpMZPDw00Yf/CeVGNvOdFI1bPnBtME88Vu8zDR6GcWJ9b6HEgD4f4jeF7onbHekFaL6gUiWxbqkueUkKjfxJZ X-Microsoft-Antispam-PRVS: X-Exchange-Antispam-Report-Test: UriScan:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13015025)(8121501046)(13024025)(13017025)(13018025)(5005006)(13023025)(3002001)(10201501046)(6055026); SRVR:SN2PR03MB2384; BCL:0; PCL:0; RULEID:(400006); SRVR:SN2PR03MB2384; X-Forefront-PRVS: 0109D382B0 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; SN2PR03MB2384; 23:zcV+Lw45U3of0AmHDSaGv1nh4S29kZX/r65MdhZ/C?= =?us-ascii?Q?34KzzTvRg0vCw37R3RFPc32jhVQw7Q1pVcqEzliIW3NAa/O6fLt/Twgy8oyy?= =?us-ascii?Q?rge2TVKuuuastIYjydwLLzzTEOP0ze4ASz+mTEJSa5hMLjwyx2s9QVNleSKU?= =?us-ascii?Q?YYpsojjD3LbeAnI8d/hCD0up1xJEhFMwv3j9CA78foUwz2dzeA04MAVR2q6T?= =?us-ascii?Q?zDMIYcukWyPhJ1XZMrXOKe7avXgsCp0qA3FhrFkQwzSmCiOqrjYzHTLbN5th?= =?us-ascii?Q?6Y4drYB6ybKasD578iLij5+hMKwLDmGeH0iNX8RTcBroWH+xn9ZPSLfw2z2x?= =?us-ascii?Q?JXEwHH8ZOXoAOzhwMKLFnKEZzQOw6MyAZpNLsMyEGwxJPxCBQhu4CnvL6aS2?= =?us-ascii?Q?lhXmc9m+EIIz0TZZxDas2Ug+0OVy0RseoS/WOLxYGwD1e9FkWLZjCfOSMfNP?= =?us-ascii?Q?1zZTjJTjPUuBV5z2GoamXBsYeLUbh1REQypf+hfIRT8njPLhpAgytSpSyXvs?= =?us-ascii?Q?ffVbHRXJ5Ah5fSCsySFIwTmpzQgyvCeGr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N6jRS+I8rf2pStmnQoXOoPIDEN1Kaz8673gHV+XixYDr6O3lqYt+iN08TpW08xr5G5sgzBwMNBPxITzQC4hq/ROeJvPGN; 5:VpzPFZjDQjrHbR4mJPbRwjGrQ4hpipYpCkSQDlQIH7nmeNRIKx/gfF38334Zke1tNdl91eQJZgYye5hY5tTETkXQFJuhii4mgXHjb8zqtp83oCS9J6n2k2aD4EKBbKgO3aaqL2q5o62XT10CHcMvJjEXjWzshkmXchy2D0m8Hj3qd2++QsrqVCIJHw3R0Keh; 24:dMQT7AQNBQBkOTRCegmggp7xUgvnUBSKlrZ/abdVrb1UizN2BsrSmzFRqY16be2WTXq63vyygybX4OyILdKb9X3Yb0hVh4LQAPblFt+ybkQ= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; SN2PR03MB2384; 7:nTvrCBImdTfbLniHEKbk7yjnmbJbCuE337bIJAb2baOCIgXgNIe71WFqac6c40htjIVPPAaGDYmqOkNOal3RIH2qxX2mSxlpcI0sYZhyZ602SwajcyG2XVvr1lUqw+g400W7PGXYaOLdo6ORFYeLBcU/est9bEAHSj89I9ZXug5At40jazFcpzb4SCT8Ds1PxJNBCHFxjlHqUaVEXf3ibLbdzM9MvIbbPJPR26G8mbNtTVIqD/33bZkLJwoB8DSis7SRPcvOG5KFp7iQutw7xa5r/0qVqbpL7MPqnpV7K0x7M0hyTWDR5ZLUbj56GCjZ1FCSBv6YZNgdZyR7OKwyDQQROJ9i4wmUZhwzQNdk2qU= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2016 07:03:53.3492 (UTC) X-MS-Exchange-CrossTenant-Id: 5afe0b00-7697-4969-b663-5eab37d5f47e X-MS-Exchange-CrossTenant-OriginalAttributedTenantConnectingIp: TenantId=5afe0b00-7697-4969-b663-5eab37d5f47e; Ip=[192.88.168.50]; Helo=[tx30smr01.am.freescale.net] X-MS-Exchange-CrossTenant-FromEntityHeader: HybridOnPrem X-MS-Exchange-Transport-CrossTenantHeadersStamped: SN2PR03MB2384 Sender: linux-clk-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-clk@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Arnd Bergmann We keep running into cases where device drivers want to know the exact version of the a SoC they are currently running on. In the past, this has usually been done through a vendor specific API that can be called by a driver, or by directly accessing some kind of version register that is not part of the device itself but that belongs to a global register area of the chip. Common reasons for doing this include: - A machine is not using devicetree or similar for passing data about on-chip devices, but just announces their presence using boot-time platform devices, and the machine code itself does not care about the revision. - There is existing firmware or boot loaders with existing DT binaries with generic compatible strings that do not identify the particular revision of each device, but the driver knows which SoC revisions include which part. - A prerelease version of a chip has some quirks and we are using the same version of the bootloader and the DT blob on both the prerelease and the final version. An update of the DT binding seems inappropriate because that would involve maintaining multiple copies of the dts and/or bootloader. This patch introduces the soc_device_match() interface that is meant to work like of_match_node() but instead of identifying the version of a device, it identifies the SoC itself using a vendor-agnostic interface. Unlike of_match_node(), we do not do an exact string compare but instead use glob_match() to allow wildcards in strings. Signed-off-by: Arnd Bergmann Signed-off-by: Yangbo Lu Acked-by: Greg Kroah-Hartman --- Changes for v11: - Added this patch for soc match Changes for v12: - Corrected the author - Rewrited soc_device_match with while loop Changes for v13: - Added ack from Greg Changes for v14: - None Changes for v15: - None --- drivers/base/Kconfig | 1 + drivers/base/soc.c | 66 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/sys_soc.h | 3 +++ 3 files changed, 70 insertions(+) diff --git a/drivers/base/Kconfig b/drivers/base/Kconfig index fdf44ca..991b21e 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig @@ -235,6 +235,7 @@ config GENERIC_CPU_AUTOPROBE config SOC_BUS bool + select GLOB source "drivers/base/regmap/Kconfig" diff --git a/drivers/base/soc.c b/drivers/base/soc.c index b63f23e..0c5cf87 100644 --- a/drivers/base/soc.c +++ b/drivers/base/soc.c @@ -13,6 +13,7 @@ #include #include #include +#include static DEFINE_IDA(soc_ida); @@ -159,3 +160,68 @@ static int __init soc_bus_register(void) return bus_register(&soc_bus_type); } core_initcall(soc_bus_register); + +static int soc_device_match_one(struct device *dev, void *arg) +{ + struct soc_device *soc_dev = container_of(dev, struct soc_device, dev); + const struct soc_device_attribute *match = arg; + + if (match->machine && + !glob_match(match->machine, soc_dev->attr->machine)) + return 0; + + if (match->family && + !glob_match(match->family, soc_dev->attr->family)) + return 0; + + if (match->revision && + !glob_match(match->revision, soc_dev->attr->revision)) + return 0; + + if (match->soc_id && + !glob_match(match->soc_id, soc_dev->attr->soc_id)) + return 0; + + return 1; +} + +/* + * soc_device_match - identify the SoC in the machine + * @matches: zero-terminated array of possible matches + * + * returns the first matching entry of the argument array, or NULL + * if none of them match. + * + * This function is meant as a helper in place of of_match_node() + * in cases where either no device tree is available or the information + * in a device node is insufficient to identify a particular variant + * by its compatible strings or other properties. For new devices, + * the DT binding should always provide unique compatible strings + * that allow the use of of_match_node() instead. + * + * The calling function can use the .data entry of the + * soc_device_attribute to pass a structure or function pointer for + * each entry. + */ +const struct soc_device_attribute *soc_device_match( + const struct soc_device_attribute *matches) +{ + int ret = 0; + + if (!matches) + return NULL; + + while (!ret) { + if (!(matches->machine || matches->family || + matches->revision || matches->soc_id)) + break; + ret = bus_for_each_dev(&soc_bus_type, NULL, (void *)matches, + soc_device_match_one); + if (!ret) + matches++; + else + return matches; + } + return NULL; +} +EXPORT_SYMBOL_GPL(soc_device_match); diff --git a/include/linux/sys_soc.h b/include/linux/sys_soc.h index 2739ccb..9f5eb06 100644 --- a/include/linux/sys_soc.h +++ b/include/linux/sys_soc.h @@ -13,6 +13,7 @@ struct soc_device_attribute { const char *family; const char *revision; const char *soc_id; + const void *data; }; /** @@ -34,4 +35,6 @@ void soc_device_unregister(struct soc_device *soc_dev); */ struct device *soc_device_to_device(struct soc_device *soc); +const struct soc_device_attribute *soc_device_match( + const struct soc_device_attribute *matches); #endif /* __SOC_BUS_H */