From patchwork Wed Nov 9 03:14:10 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangbo Lu X-Patchwork-Id: 9418401 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 1D5AD60720 for ; Wed, 9 Nov 2016 03:28:23 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1080A289EF for ; Wed, 9 Nov 2016 03:28:23 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 04A1F29111; Wed, 9 Nov 2016 03:28:22 +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 CF2EA289FD for ; Wed, 9 Nov 2016 03:28:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932307AbcKID2H (ORCPT ); Tue, 8 Nov 2016 22:28:07 -0500 Received: from mail-sn1nam02on0045.outbound.protection.outlook.com ([104.47.36.45]:51893 "EHLO NAM02-SN1-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S932217AbcKID14 (ORCPT ); Tue, 8 Nov 2016 22:27:56 -0500 Received: from DM5PR03CA0004.namprd03.prod.outlook.com (10.175.104.14) by DM5PR03MB2891.namprd03.prod.outlook.com (10.175.106.13) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.707.6; Wed, 9 Nov 2016 03:27:52 +0000 Received: from BY2FFO11FD029.protection.gbl (2a01:111:f400:7c0c::190) by DM5PR03CA0004.outlook.office365.com (2603:10b6:3:118::14) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.693.12 via Frontend Transport; Wed, 9 Nov 2016 03:27:51 +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 BY2FFO11FD029.mail.protection.outlook.com (10.1.14.212) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.707.3 via Frontend Transport; Wed, 9 Nov 2016 03:27:50 +0000 X-IncomingTopHeaderMarker: OriginalChecksum:; UpperCasedChecksum:; SizeAsReceived:1562; Count:10 Received: from titan.ap.freescale.net ([10.192.208.233]) by tx30smr01.am.freescale.net (8.14.3/8.14.0) with ESMTP id uA93R133018726; Tue, 8 Nov 2016 20:27:43 -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 , Leo Li , Xiaobo Xie , Minghuan Lian , Yangbo Lu Subject: [v16, 5/7] base: soc: introduce soc_device_match() interface Date: Wed, 9 Nov 2016 11:14:10 +0800 Message-ID: <1478661252-42439-6-git-send-email-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.1.0.27.g96db324 In-Reply-To: <1478661252-42439-1-git-send-email-yangbo.lu@nxp.com> References: <1478661252-42439-1-git-send-email-yangbo.lu@nxp.com> X-IncomingHeaderCount: 10 X-EOPAttributedMessage: 0 X-Matching-Connectors: 131231356712531759; (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)(50986999)(87936001)(189998001)(2906002)(5003940100001)(8666005)(2950100002)(76176999)(77096005)(36756003)(50466002)(8936002)(48376002)(68736007)(229853001)(97736004)(106466001)(85426001)(7416002)(5660300001)(86362001)(105606002)(626004)(33646002)(4326007)(47776003)(305945005)(586003)(92566002)(104016004)(81156014)(8676002)(5001770100001)(7846002)(50226002)(6666003)(81166006)(356003)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:DM5PR03MB2891; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; A:1; MX:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD029; 1:hgEtqc8EBiUUB1Q+XqKsjMcq7umRNb1unr/tZDNpHJoz91MCqfQLhKE6p5bK7d2XuEGa2aCtXXqukZwE63S2yZc4T06SNbWZlQbnOXQUfk4Vv8AoxgCkOUcyFjp9unSWFCEgZpZH8fVMUvuvBUaGgszR19oRjhZI1RGwyCiFmdV2QHoTbkUKUi6fCr4h8MRTbXdwR/WMMWtWoxqYuhDN1/1nNRX2P0+AXAnNjfpSdVFlKFD/PDGkQtESZcj/JTRYoC5EuKerCQUWdGgZuGpfC47XrZJTeAKdpe86Mc5bGP9Y8dTB+ePAW+giO949c6WQCMrYBdT1u/2yS/ttxueVw0uhM0SqsKhJwPbU+iKQEUEvG+s+roakN4PqWLBsantwt92HIa5vfPB/lM40CGYo3VQWB4fZDqh261ER7rB966P2Hx2L/Bt3ROGirAJQOR0ruq4/IZ8bTg1/o8m0VjIBY4YuwIGNiyQxpY0p4F74TGMrW50JgdBpX09lcrMMy/IaFfyXzvdtOrVxkgGLCbiu5oZnXSu5h5l4bYzv+h6f2uS+om3Ti1SkiHMi+9C0eVFygsiQpnatvrUJ577/YbCPJAndSY7ElcLkdxaWSEuYiYejeFyDGIdhYQ+KEG1C1yAl22mCc2NVDLzmAWZ/vMMsvhORSy3K3BsSj/Sf7rpEH88Q7x42ITJ2gRl2vnTgIeBW/DkibVIG2hXRfumGptmiP40L4l4RHWzjssSwzSVr8eV1cmz0p4SexvIVJAb5lU2kPG5+9/bTwHeQPPrVOE1pJQ== MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: 21c4bb94-cb57-4e93-372f-08d4085062b5 X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2891; 2:DprJT/BFNNUNb6DvPng9i+LD9+JZzJLNmCcjJe1iKF6/6nAkPAw5AcmKF1spAcmpctiqenY7F+f6NSdvubLS12/tc3M3M2c6Cve0E4PD1v8bzqfpqAvVFBe9ueaU4lXQrP2v2IipNUNKkpKytzYKfbNffXHmSA4si45sYE8i4+DGXSTdk3rFqzzmH09EtTVBCbMXzoYZnsPElDNh3ezsEg==; 3:VWUKLGisqPlYBUkgfQNineqeC7qD6WMCcRC/SnmASzLuTt21lQmzRktZ9+/xbynOHGmR/4jaf4St+jYOkhvwv55J6XXF7GAf/GMyduEmN0EhSw1Gb/jzl7ppfifefv65QnmOpMR172xiFK7lVy97vOxKYGpNAdJjEvZn83Q2wlgB+BMg+lF+o/Pky75KV/js4vf91VRkzNgGJt78yAFycMd+LrNZIY2Yt4TARKQESM3eqgGsNunywvPadXS197kG X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:DM5PR03MB2891; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2891; 25:JE9f1AQ24VvNoFSOsRuDhGkJnMQ64OFv3Vw+Dw1hKgs8OSlxbDkkO2fdKO0uKN8BY/uTZrRkWjbEGIFFUfdCOX0QIdSxGBwZi1q3qY4R/jOrQRjR2o3Zk/2sdZeE8Q8grnPb+hBo4lw/6ykABkfq9fWJiLm9MsFyOl2rTvys79b2ySjJY08AdLs4yU1z+C8fgS20O/dRrQDWbdo9hHwn0uaBBNmU+mimK0y2lJ3tTMPASoEMDS2RFzeVxE1XnphnadqoCMc0AAFsbeloYdckEAXFWj2XpWBgdqkqbne5Z+AqKUKbM+/6jqyz9zP2Q9xJ0KTrvwxq91NYipIy/oP5rsfyXdndZ+LYKyLj2HgRho1eyMIE8LcTDs01zOGKBWJrL2NVdvAYcO9xRDRvMlUsMwCbTvXf4wTzXJTPSHxE8/t/v30rdmQLPVsYxr8G+E37YiRL7chq2AZBxijPvUstSQ==; 31:y6iVi3/9aLGkIAD1TgBGHyTPFSs0OJORSrjqi2jhWtXFz4Q6QZnmMjLLS0pTNIPnRtkU/Wre6E0ASFU1JSpspVp7K7/FsycKrtDpT+Fv6QfNu7+8QKSXozPQsNfzSDPaHDKTthzNDMSf9oU2x583bgApCx7eDsS2m1178EwVcQGs5pXMMQ8jYi/5cVfUiXCNU5FyMqjyoXbSeqP6PD/jV2ZSe4SqGng7y/DoPBtoj2KwYKtRjU+jO5rjXZN2u34sbocwWzWLVhjMDyH11zb30w== 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)(13023025)(13015025)(8121501046)(13024025)(13018025)(13017025)(5005006)(10201501046)(3002001)(6055026); SRVR:DM5PR03MB2891; BCL:0; PCL:0; RULEID:(400006); SRVR:DM5PR03MB2891; X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2891; 4:bck+ZqNZloVjmvdVN2sLr+aRjiMaHUFpqvto9egiibvJ259zwLsCLipTyYa1suTy5qp2Hl0bXSIdx7CO3lYqg+nH88CemJKoYptCxNMEeFsz8nzU1UHttrJRbPLlEJPZukT8sv+7Ynv2GIzGrVynGoWf3GVOOT7/z7aJAYMfK6yWC+3nmsCUXar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IYB+83YW/GnMvpTIkosDhxGAsfGLyRubzjBBvCLJCPquZp3kfAPRNoOmv7OSXCVl3G/; 5:33PCT2mHESdDK6kvjMWxeCMkirQMTrCPUtCGI61b/CL0gzb0mzisMbOJB+h7DCYSq3Hn+mRviE3BHClKhwjpvPTI0F1UMr2wG5E1zhnAAfAnbePaujVv5EZlx1aqoCzFYk9UeMNPkxQCFCO3ear7hufu6EpwouoKtCbEXd3AiSlKH0g2dM8mjBJ991cAxbQm; 24:4a5qISRpxgukCIJHi4D//GcRrVVQXAVI9WpsNu9gveLdcC3mG0q7ijND6ieMSRO98uDn9dW27mhbFi2HsNCTa/Rdq2PzyqtAzmhB/zfKh8o= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; DM5PR03MB2891; 7:zO7vcR0kxG1ioQuZcEfk3e9F6tCx1M/V+69r2LsbDojo0dgpgWbGdjMGczdDd4HfAtZIYSFHSi3XrCy0UFnianuQiOm+ij6DXOR20sH3EK77fMZ4GAMKIG4cE0Tl0+PLjpvGs7aDpecGoHB/Ljy8/Tf9kp536+lKjXG8AEmlw2YZy6QNDbFd4LCZDeRS8TqjNmRHGWp/vs7BEIeDdVR15UZupxh5Z6cQwxoNMYQ6/SSdpvT3TihW9zqIiJJaSXNd0ne2AlTaY+kg9+f/6x5UPR1domzWXFv8Ct92Y1w2sybPq03zANJLinHyYVgzrn8WzFyIvD+cX+pKgY4odW6S/LXN+VlWJxbJgYChJYQYI1E= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 09 Nov 2016 03:27:50.8475 (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: DM5PR03MB2891 Sender: linux-mmc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-mmc@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 Changes for v16: - 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 d02e7c0..2abea87 100644 --- a/drivers/base/Kconfig +++ b/drivers/base/Kconfig @@ -237,6 +237,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 */