From patchwork Wed Sep 21 06:57:19 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangbo Lu X-Patchwork-Id: 672615 X-Patchwork-Delegate: scottwood@freescale.com Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3sfB0D5Q0Nz9sCZ for ; Wed, 21 Sep 2016 17:22:20 +1000 (AEST) Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 3sfB0D4dHWzDvLC for ; Wed, 21 Sep 2016 17:22:20 +1000 (AEST) X-Original-To: linuxppc-dev@lists.ozlabs.org Delivered-To: linuxppc-dev@lists.ozlabs.org Received: from NAM02-SN1-obe.outbound.protection.outlook.com (mail-sn1nam02on0047.outbound.protection.outlook.com [104.47.36.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 3sf9kT5S9szDshB for ; Wed, 21 Sep 2016 17:10:25 +1000 (AEST) Received: from BY2PR03CA079.namprd03.prod.outlook.com (10.141.249.52) by DM2PR0301MB0718.namprd03.prod.outlook.com (10.160.97.139) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.619.10; Wed, 21 Sep 2016 07:10:21 +0000 Received: from BN1AFFO11FD025.protection.gbl (2a01:111:f400:7c10::150) by BY2PR03CA079.outlook.office365.com (2a01:111:e400:2c5d::52) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.629.8 via Frontend Transport; Wed, 21 Sep 2016 07:10:21 +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 BN1AFFO11FD025.mail.protection.outlook.com (10.58.52.85) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.629.5 via Frontend Transport; Wed, 21 Sep 2016 07:10:20 +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 u8L79HVq027711; Wed, 21 Sep 2016 00:10:13 -0700 From: Yangbo Lu To: , , Scott Wood , Arnd Bergmann Subject: [v12, 7/8] base: soc: introduce soc_device_match() interface Date: Wed, 21 Sep 2016 14:57:19 +0800 Message-ID: <1474441040-11946-8-git-send-email-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.1.0.27.g96db324 In-Reply-To: <1474441040-11946-1-git-send-email-yangbo.lu@nxp.com> References: <1474441040-11946-1-git-send-email-yangbo.lu@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131189154211643545; (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)(11100500001)(5003940100001)(106466001)(4326007)(86362001)(50986999)(76176999)(356003)(104016004)(105606002)(92566002)(77096005)(5660300001)(626004)(36756003)(586003)(7846002)(68736007)(33646002)(8666005)(50226002)(2906002)(7416002)(5001770100001)(97736004)(189998001)(305945005)(81166006)(19580405001)(19580395003)(81156014)(48376002)(229853001)(87936001)(8676002)(50466002)(85426001)(2950100001)(47776003)(8936002)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:DM2PR0301MB0718; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD025; 1:jX7NdDjwtcqv8r9D7Ne5X6fjM13meDF3j1P50GxyJnh9+M6YbZC/Ni9yD5PGj1Au7Eu+F5yKETCMXTwg0bU2UCzEobjOwcugBoYfwnIAC79dyhHEXa3aaHqL2NhXBbeCnkDKjWwqe8I7ByJLANGReyd12vvoLE7qixkMBwq800HiS89Gg1iFQLYpCvhbekINXiLM7yYy5aEgO3/eizXlnG1831VM8oOgWZ1yum4+Cjx+OWUawTlGpCHZbFIZq5R9+AJJSWIVXJOO+1WZ3C1Oxrd86X+tMxH2HMoYajiB9D0W1YTu2hXeWY6FjJ27MYDao0+nfVz53Gjb5jz4vFmDlOcfd/WTfqJ4GKDNPUz+4alRtDaX/VsDpyOWsoRHhg8LdN68jircL64TwBdM9khFJXrXpYUtjGdKCELxqgjlLtt7OILc9g516NvNTF7uhvWtLnxahejDU5oX3D1ZX/9jfwiLGyG9OGwjO6Ro0zzlMMczEXdX5Xz9FMTvp35T/HxsSxxPjVvpGgrpqiKy5++2iU9Uxwskq73uxusiwHSlcgbSgbutnHTnyhzMznhy+0lGDO3BJk2lusC9MKc5sJlRUPIPlCNkYhc3HEHt/1k+MgnN9lgvaoF1nEM3c70nHxMAfoaVzUCfy1ofQ+odqh4yn/XGW/uPHqc9ojeKsTgrp16G7/bdnpEUKvbL6coXUsq3qsyh9uHMsYmRgtn+orx24O4sN0gB19po/h3eh4dC4IPmAlxppRBOvaRBC5SGdf1M MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: b4c3ec3e-db9e-4ede-df38-08d3e1ee599f X-Microsoft-Exchange-Diagnostics: 1; DM2PR0301MB0718; 2:ojZc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:(185117386973197); X-Exchange-Antispam-Report-CFA-Test: BCL:0; PCL:0; RULEID:(6040176)(601004)(2401047)(13015025)(13017025)(13023025)(13024025)(13018025)(8121501046)(5005006)(10201501046)(3002001)(6055026); SRVR:DM2PR0301MB0718; BCL:0; PCL:0; RULEID:(400006); SRVR:DM2PR0301MB0718; X-Forefront-PRVS: 007271867D X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; DM2PR0301MB0718; 23:xxQ5j/j8t2WFqOQNiElOnCBgNezcsFpe+SvebXU?= =?us-ascii?Q?J945cU/wLTD9HD7B1c9q1WnynsoGNekDuVLpaVUF2pZwXuv0W6YSfNqkieem?= =?us-ascii?Q?V3ZMFbKBirxihao45vQzizn/FfPu7rsMHas2Q7h6Pf226jSbc71LVNCT8xCU?= =?us-ascii?Q?e7nn288GPF+ZyL2entIymNqB6gSWpDxJKScrWzUtq86tED0aold+63iiVrFn?= =?us-ascii?Q?/foxx5wP3Lp5BRRKm18xzd8RGMy+2aPBbrXmFlqESBYlkyRQ7yRXhfdBBhXV?= =?us-ascii?Q?dJ6ww6HtC/56dvN51gjXYBjc4a4gg/MKr8jSS3MTooKjWuyHJJfHU2ou2B1O?= =?us-ascii?Q?FoIzUKQTN1Dkmp9fzEzJqzu+g4fSd4NrrktXImxZ2yWl19snlOB9jQdWWzXx?= =?us-ascii?Q?B+Mc6swXRB9J9nyZLxk4QCtvtDhPSJM3peYiIZybXnD0yB0JhGlW/r2hAhE5?= =?us-ascii?Q?U7Sl+374mnKpCCa16CYzrcAZ/9ot9GZR1EerXOUEmBF9xOopccwR+vQHQY1x?= =?us-ascii?Q?/WXQIdb7DD9/5i44ehUO1N3gglV72idWQxK6NS/AK6AvYZv+Tv5M4ayZo26c?= =?us-ascii?Q?tWRAuGheDK1qm1orwtv81udABMAHvc4ysY0mAxkK4K6BB5BeY8wPRPx2oHbo?= =?us-ascii?Q?XdgZmKpU+pkQtU+slX7tyWxSNnCy3QdGCIpQT2KIzjva7RJadHsCuk0w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cX3PySzDfhkd0nqsShMnXdWu1OUBAwuNlBJDKn+l69Poja5fPIEe8G1twW7E81F8c=; 24:VzPOtShzIOFOYcl8KimOoH2H6pNWdnPxwtzKn2+HMLHZg/PFjchoFIujHtjymcvAD3jK0/QpQ8i9ujYJJiiVYfqN8LI1WFPa4TM730MciZI=; 7:7kwxmeXhuM3hHRMvO1GO/kw/4DZUwf45DCQG55uF2HhGbrCzBBIXKCND9TqfkSlSFqO0S4sFaYvaPCmBuU1Yg0+ybg3Rlc+euC0GJUDXkPj+8TyOGpTL0uYerqGaSW2QlQAgosakoIaKeVp/arKdwWJ1f4AHat02Nyz4bYjfYZVb0r1rLyPHsXyc8LLD2fHlsBbhjnuaGkeUy1wiUA47Wn7N7TOtxImyshIOGBYnY0EylDjl7TM2eWEYf1HEaQewqPkgEsGcHUN2+S83QxjiGq4Wbs7TaIKyIp6Z7gBoD9gKR+mgl3D7ruZMgw80SwxD SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 21 Sep 2016 07:10:20.9147 (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: DM2PR0301MB0718 X-BeenThere: linuxppc-dev@lists.ozlabs.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Linux on PowerPC Developers Mail List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , Xiaobo Xie , Minghuan Lian , linux-i2c@vger.kernel.org, linux-clk@vger.kernel.org, Qiang Zhao , Russell King , Bhupesh Sharma , Joerg Roedel , Claudiu Manoil , devicetree@vger.kernel.org, Kumar Gala , Rob Herring , Santosh Shilimkar , linux-arm-kernel@lists.infradead.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, Leo Li , iommu@lists.linux-foundation.org, Yangbo Lu , linuxppc-dev@lists.ozlabs.org Errors-To: linuxppc-dev-bounces+patchwork-incoming=ozlabs.org@lists.ozlabs.org Sender: "Linuxppc-dev" 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 --- Changes for v11: - Added this patch for soc match Changes for v12: - Corrected the author - Rewrited soc_device_match with while loop --- 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 98504ec..f1591ad2 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig @@ -225,6 +225,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 75b98aa..d2fd1ad 100644 --- a/drivers/base/soc.c +++ b/drivers/base/soc.c @@ -14,6 +14,7 @@ #include #include #include +#include static DEFINE_IDA(soc_ida); @@ -168,3 +169,68 @@ static void __exit soc_bus_unregister(void) bus_unregister(&soc_bus_type); } module_exit(soc_bus_unregister); + +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 */