Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756229AbcJ1F7T (ORCPT ); Fri, 28 Oct 2016 01:59:19 -0400 Received: from mail-cys01nam02on0043.outbound.protection.outlook.com ([104.47.37.43]:42736 "EHLO NAM02-CY1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S965533AbcJ1F7E (ORCPT ); Fri, 28 Oct 2016 01:59:04 -0400 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; 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: [v14, 7/8] base: soc: introduce soc_device_match() interface Date: Fri, 28 Oct 2016 13:45:20 +0800 Message-ID: <1477633521-7391-8-git-send-email-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.1.0.27.g96db324 In-Reply-To: <1477633521-7391-1-git-send-email-yangbo.lu@nxp.com> References: <1477633521-7391-1-git-send-email-yangbo.lu@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131221079412199555;(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)(1110001)(1109001)(339900001)(199003)(189002)(2950100002)(50466002)(189998001)(6666003)(87936001)(11100500001)(81156014)(104016004)(36756003)(5003940100001)(626004)(50986999)(76176999)(85426001)(5001770100001)(48376002)(97736004)(47776003)(5660300001)(7416002)(106466001)(586003)(105606002)(50226002)(92566002)(4326007)(2906002)(68736007)(8676002)(81166006)(77096005)(8666005)(356003)(7846002)(305945005)(19580405001)(8936002)(19580395003)(229853001)(33646002)(86362001)(7059030);DIR:OUT;SFP:1101;SCL:1;SRVR:BY2PR0301MB1622;H:tx30smr01.am.freescale.net;FPR:;SPF:Fail;PTR:InfoDomainNonexistent;A:1;MX:1;LANG:en; X-Microsoft-Exchange-Diagnostics: 1;BN1BFFO11FD028;1:8BHLjAq4Jx78StqUqadx+rh9kw9tSSxSsnH5acPI22DJjF+rPqTaTAblrQd7dgw4LSe3GtJ87/SIF+wkN3VCNwc3ZO0OT1RhUVm9SbSRcsMl6vwmNGdtHUJ9bnRcL7TyiZCb6S6GRmjvVwWexUbZcprfh2qpxG6fkwAigIQeGu51DTvp8+IW2mpnjxswrqGVHHm8Nqr8thDFKRYeIKOrMnQIKb2+ckgo0QU5oI/n+1XoOvaEy0RdvKggNA8xIM4P5L3zhYntaJbPnPiHJ2Zm2AF4bNTsuDqr3JfV9ry8q+dxw+qoVF3a7FYZin/A8gG4WDaMg1cLIP0uNS49cx7ysfCh5BIVSughb74kFris+kyBLvPZihcRnaGuL1+fFq8XSoT1nzRPBH/FGyi5E05QAqAkEvlZCTt9KGSkkJibCEHNA5mqeqlec7XipLUE+qvUtV5OPsQyAYgnOZCd+hAPyhR6NYyNz6kjJBy8dW3lPu/PLwnq7MV+GheSw7jfFjYRI/UZHi7rnW9NE6X5N8Qt2EJ2hvQ5SqjPqLOM1NMeUR5AuwIt1VHkmm1soyiwSo9BpcdNqUqO36dATglDg9a+FqWjFmltoOOkZQPNednC9LSkJdhPqq6bbWbFeiZHSKdyAC3REZX+r9GUmjp2ngzFs5UnRE47SSfefdf/D5lCX+iFwVw2lUTEuAxhy1MmGVpSEng8XW0oXGOQEXWQO+KKPPuoAkehf5q56HcVVO+6NesVdN5B1+ZbX+6XicNT7l+8 MIME-Version: 1.0 Content-Type: text/plain X-MS-Office365-Filtering-Correlation-Id: b66bb2e2-1b0f-493d-ef23-08d3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hCW3AnO4UwuisWjdiQV6VyZbOp3BDJ04LnSnfGgFpZDqIeQnmeFB4Kssiozf2sJcH5iBTSScwW9jpFf/XjoYTwXn0O6OjQYOM4Lyz/tnfnToIuqsB3w+VJuWwczhsGkXoEv4FpGHJA3igHLQEbCFULpSwRs68DOwMWRyfo1tuQ1pJ9gnO3lovnx4ORg5nsib/+DlycVOcD0NFeeVFuqU0gLN 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)(13024025)(13015025)(8121501046)(13017025)(13018025)(13023025)(5005006)(3002001)(10201501046)(6055026);SRVR:BY2PR0301MB1622;BCL:0;PCL:0;RULEID:(400006);SRVR:BY2PR0301MB1622; X-Forefront-PRVS: 0109D382B0 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1;BY2PR0301MB1622;23:FqYZB+FODK80dCAN85I4VWpT7xZ99hk+Eo8qy1t?= =?us-ascii?Q?9BDyKx5FQ8OSIiSKm3xv6RVRWNWnUAFgipQBIbbZLXiHWbyOhj6utD2SUIaz?= =?us-ascii?Q?eu2CWP/no43dFoJyepZLF3SeJFyP/gArARd+b/e5hsqWUW9nYiiEBIKPLhkK?= =?us-ascii?Q?qwXy3fBj8JBWis1gEoA2NX1k16Rh6NJMWmP+DLqmwsLfGMceppsseUnC32IE?= =?us-ascii?Q?7SFUR6fee31yIClN/A9ZHa04GC7IQZYzm+BitUG9HXxJ0GC+dRvihXU9ww/m?= =?us-ascii?Q?I+8NtZ69vVfNcV02gCptzaf6fYFTjQuSgPah1G2acizrPK2j7LKjHMePwQFi?= =?us-ascii?Q?jM975lAlbsID7sIeR/dzC+N1+qmwQjSCKNMuuvxY+EohAEv87D6g/5COzw3b?= =?us-ascii?Q?6cW8e41ygB8aTR6oJUm2GYqiN6LhjkOn58p7NDlTZDSWKpWHPEvqZ1FaIhBQ?= =?us-ascii?Q?mQojBEWL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4hMf+tu9h8Th1fnHgKIcmp5rlDBHRW7pF/mL6VMNuOXgNu5OKmEag5PKWXkMfMA8E6UXqn22um8zBkGavpOKSpTlJSECX6gzYzJq8aOJww9TutQ/OFWsfHEM0SebLkb3/cBBEWAaCaqlFE1Txkl577vD3axFDC9L02iU+o1vDCvGYeA9SxXWUQLtHNIVZfw/YoleD77qN;5:bpZHXQX3/eUGDZuwmBf6RAPaL1bQ9QFbeg0h4VEC4Baz/PDJIUKOGUI1IYCKYCA/pFMmkCoPZ5rrtrFxoGDrcin0CL00xDf4W/6LtEPev3cpFRiz5njz2BoetE65DH1YRgtBuTSdOLvCvkYpHIweK5P0GVGkPxP5P76XReZKBnhd/Ed9kgz8zsDnuxciJIgT;24:zK/9SnGL56C4XjYYiqDJdvW1eB0Q2X7Q6AFAJrglsp6BWmwaiupl/sSLofI+hgVTnb7pi/kQIJ1NClxj2AVOlm45Byw6lR/Q9D7vwLJS6/g= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1;BY2PR0301MB1622;7:QiIzFtxgpyp3FOlRFJLfwLtraAc7rKxskZsrp1Do8WUPfOsHZZsiruL8cdEvmMYEV5flE9pPq2jWs/MQrHWcmMOGhPWGpUc6YuxBhSzRcQseHRvshDsgsMdQbYDfx4/u1KH3BLFPuW6o7WmnrKYT3dJ23sbyXVPCOlhR0HfhWEvB5p2VHdMfy39U0Fhq5UzkDq+CrudmO7j7FJhndz/Yrh/Lxw3nWfXmBy6Yol7or2i3IEID2WBi0WcYIlmrzpf2fEu2sP8DI2wBZEPXBsDXA7NqL4CBDUAwtY5KEZTAy1NL8XITZva0VmRJh2M0T4ksqgQRq2lCIDpdic+AGynsrnRNbEqGhT3dUCuXA/vDD7g= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2016 05:59:00.7831 (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: BY2PR0301MB1622 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 5238 Lines: 167 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 --- 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 */ -- 2.1.0.27.g96db324