From patchwork Tue Sep 6 08:28:22 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangbo Lu X-Patchwork-Id: 9316029 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 247EC601C0 for ; Tue, 6 Sep 2016 08:45:03 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A6682871A for ; Tue, 6 Sep 2016 08:45:03 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 1BD7C28BF4; Tue, 6 Sep 2016 08:45:03 +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=-4.2 required=2.0 tests=BAD_ENC_HEADER,BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id E3A3D2871A for ; Tue, 6 Sep 2016 08:45:01 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bhByP-0002mY-J2; Tue, 06 Sep 2016 08:43:17 +0000 Received: from mail-sn1nam02on0083.outbound.protection.outlook.com ([104.47.36.83] helo=NAM02-SN1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bhBwg-0001UE-FE for linux-arm-kernel@lists.infradead.org; Tue, 06 Sep 2016 08:41:40 +0000 Received: from BLUPR0301CA0038.namprd03.prod.outlook.com (10.162.113.176) by BLUPR0301MB2001.namprd03.prod.outlook.com (10.164.22.15) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.599.9; Tue, 6 Sep 2016 08:41:08 +0000 Received: from BY2FFO11FD038.protection.gbl (2a01:111:f400:7c0c::180) by BLUPR0301CA0038.outlook.office365.com (2a01:111:e400:5259::48) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA_P384) id 15.1.609.9 via Frontend Transport; Tue, 6 Sep 2016 08:41:08 +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 BY2FFO11FD038.mail.protection.outlook.com (10.1.14.223) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.587.6 via Frontend Transport; Tue, 6 Sep 2016 08:41:07 +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 u868e7Nr032344; Tue, 6 Sep 2016 01:41:00 -0700 From: Yangbo Lu To: , , Scott Wood , Arnd Bergmann Subject: [v11, 7/8] base: soc: introduce soc_device_match() interface Date: Tue, 6 Sep 2016 16:28:22 +0800 Message-ID: <1473150503-9550-8-git-send-email-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.1.0.27.g96db324 In-Reply-To: <1473150503-9550-1-git-send-email-yangbo.lu@nxp.com> References: <1473150503-9550-1-git-send-email-yangbo.lu@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131176248677419792; (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)(189002)(199003)(85426001)(105606002)(4326007)(50986999)(5003940100001)(77096005)(19580405001)(81156014)(7416002)(48376002)(68736007)(81166006)(86362001)(19580395003)(76176999)(8676002)(50466002)(50226002)(97736004)(11100500001)(586003)(36756003)(7846002)(229853001)(8666005)(8936002)(33646002)(5001770100001)(92566002)(5660300001)(2950100001)(47776003)(189998001)(87936001)(356003)(106466001)(2906002)(305945005)(626004)(104016004)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:BLUPR0301MB2001; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BY2FFO11FD038; 1:THoCPmcAZAKwAFMcsi58o+yHXApZUHS8okfMI4KF46NoxAckjlWju5dsxkwkHqWvg3pSkmBSg1NqZRGXWhjMA9t2o6zAQBz2hJA7Ml7n1PI7ntR/wMMuH7/W12BPZaoF/j/RK8JpyCkOBp8oNkbvx3w0Cqp7JkLod3HD8Y1N4OTBJnI4fMyn2kfRy6LnVS+nbF39soLoliRN5g6N8Hh0yuruGsmyUHS7vSIqGUm0HGXjsN4H3hef2w1Fv/QjGLNnunQ+0j8UZyXmpL8Lx3y046vB/0d1droLgINZmCoQdO81hVYSLsNBkVj8xXQB5lkGVDIEkAm6OJ23ntHb+iR51yvOnQ+WEz0jSdZl4awXACBoQKZL/tVS2JKdUKvwEG1EcKSYBOkJ7dCGGISedsUDlX8LvABtfWMXqZN6lTSCIDN6TtParJWXNgSUYJ3I6GqQZY8nANjVv2EN0r5lGQ1ZMkJtlOiNxczcciiEjiuWKgcYaH8BniKIvfQSZksL2BR7sIM6QA711JUfMy1NCATaTwIQywseYgsKwSK1oBjMXqwVEyXhC0FHJ1qenKCA/Vf2JHB0QjHovLYrH+jURKJ6uhDADiJrLeR3ZGcf3pfDTdAivbW38l0g2VMJirehr0PeU7h/LMhubPllyAnjcqPTF63vaeRBj3sYYfw02WjsUrOsoDh0kmILL4as30jxnB3u/+sww6INVqyNk7GGCFn7Y1yoLS1ZEufyFkIVA7bb+Zzs9DKfln98xRvZpSpxdwns MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: aea7e954-169c-4e7f-69af-08d3d6318bd7 X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB2001; 2:QOyEiykUYAVhG7nqQ2t5S5C0Y6PNEyd1DGIPgYpjhKNvvyumTXROmSG7CHvpNPjJyoDVdUuIiqy+AW1cBqBQHG4Hc+4YuVSSh9XpPLcnMhpqY243IT2jU4zWNkDS2AdaxrGezOZvPyjOPHBwtJz7jz7HXz5r17y/c8wYZ2WJWBCsoux77K7KxR5lW8DFUFt5; 3:a+OAuEdGuD/GKZxSFVn9hCpKN1h4QjjvAaOsK46aNTUoLXgKtaCBLx13VM75SQHpguoyTE+ifK3VAU0rappEbToDj/2zZ+nc8m2GPOc11fpkbfjoFcz/XjxnWb+iQP8VUzsZn4s6e/CZsrS+1I6MrvU5TcUZtCHueJ3j24Tm0zCq7qonP3kIKhpaB6Md4QXibJWXLJW65b4He669e310/altO/6sVEAZphJ+kYs9vYs=; 25:KBWC0/ZDc4lti+SK1ft9SwgL7K0TOlOriiowwW79I41AY7sF/aYLHXRz01KdckdYWKYNEwsY6kgoIi3rSQqp3pwqambgicaRvv0n8iEgLQsM6Qx4t4uyVigXJZEPxIagPfUVxFC1ANyfQbIMA8ROe8PT4N9U/odpzG9P3pBRBI6+iKIKTpOMyvtMJJ80L5wXl421AJzopxaohGWTPW5ZwBzKCxyDGrEf/p93JRjwxbrfXGhBUHKR15tOcONlp6Muu2N7k4fhKdjrKfSXXXIeLu5JcyLcKZ1Xcv+weL0UnpV1lCB/jxLHui32RJ8+UMUqsIh/E+MOwcFVKvs73tYWkdr4az7GxwEwCFX1ZOHzQmX9xfr3HLnVWIGZ2Nf8Dc5GagpZ4Q7Ji8lCQXKjES9E0j/deD0oVRHiO1Tw3ClKu4Y= X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:BLUPR0301MB2001; X-Microsoft-Exchange-Diagnostics: 1; BLUPR0301MB2001; 31:TNexM8diacPp0gy3tKQAiBdV3wzzwm1PGV/ipMjEY6oMzgVSXki/rH8R7O0XOqaqMfOEL8XQBuZ6VEcP9LEVTwgUoO72TmCZIgZX0LhBBybpVnGT011CMxfWYwakv8ov0b+8NCculrlQm3XJjn7lQ1dNxVnBlwgN/dqy+BaAdTW9pYdFJjzyt2Pz8WknYjiBCw6veCTcz3dw9EkeHuAltet8pIZldlSKA9fHDea8A4U=; 4:ygJXx/BKRfGlwT2l2EVWouPy8av+7St5pH4aACClDflJbzYNip3OK0pk92hOBPY1b45+uJ1zN8PUCuHvIiEfYC4MeY+BcgNBrIpH8csrzEiDvjnlStGG58NyIrrp0o+75mVwYY3Novy02Pd/NCI4ZU0zjwB3/zdTpGS5jf2melxL59poeoMWNcAUcGyrgfQ0sEYPsiFtaJU/t2XZkYSxFAaz3gv9PeSzTy4ctma/VJCXRo2DFt5fo36XzX97q29jsuB/dYooGDknNncb94tZvkdhtC2fLEFtBTR6LAFK1jceEs+Pl/S9DetlBMbrRZVShwSPc7OWjPav9g3B8KlqIJYyQGBL+py7F/swoQ+AxUuExieTZqh+JwZLeIsEmH2YIvrtG9axIr/eakSc6SXnr2xhEQa2YH/xR3M5dVCphUPeRUHQpTDVo2TRHV6qafqHaz3oTl4HaIsfPuL2UmNITLQ7NX+3NPS7VUbCNbUvoFu0vS93py0n9fjfFmVEpDsugTI6WRXXu+dN7kz+QfvQGd/B2zwG9r/dxsO/l9f+Rpo= 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)(13017025)(13023025)(13024025)(13018025)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:BLUPR0301MB2001; BCL:0; PCL:0; RULEID:(400006); SRVR:BLUPR0301MB2001; X-Forefront-PRVS: 0057EE387C X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; BLUPR0301MB2001; 23:5XzL4kOjNZRWJgsHi9ZHurppP3eswuXv/hikYmu?= =?us-ascii?Q?PinyXF0ROk94DML0HS6UjlqxWwvcDU1GDUmBiZkybJGOB51Nr8dlMowGK7Zx?= =?us-ascii?Q?r8k3fpKid8B6eq+nowYlY4LBg1bWkY7WDM/KQ6OFCEWRe4dqgJ9r9Nc2G1LG?= =?us-ascii?Q?5pjDEtpoOGIfNckmvQ9JOg+OkgH6w30Pgn6ioRBHX2iGkwC2+57j19z3NIQI?= =?us-ascii?Q?BSj3t0BSpDlfCSfAoyVOvDPzb2BF6EFmYWJsEoJJQnW5lLegtuqLMCjDiAEe?= =?us-ascii?Q?4NHpNG8Wos1I6JFjAABb+Th/k+vyfH0r0+AdKqVJY/4+6BSsTSz9jZuCuvqk?= =?us-ascii?Q?zZLFqx1EyHpsGeWoNN+fiCMdH/HJ48SBoxzpNlEGxM8VAfGouGxY3bccfdV5?= =?us-ascii?Q?+Sbt5uhjQgab27/kG/tjtOF9Hrx4K4Xxx9A5Z1jl67t1z9M6zCke4UsSukfA?= =?us-ascii?Q?zPP9vxyittzwz11qBBavX3evp5BNNNUpFBIcYzWv/2hTcU8fCHhBK4ByyHBC?= =?us-ascii?Q?b+nRMzuwQrJKhuqZr/Ww3duYcG398Us1yiFrgnUWUDrGad4JwVZ9hlagdD55?= =?us-ascii?Q?LHR31976ePQB79CYhNF7YlaMDhNbfwpGfqjb1NuHAmsM8+3d4hJ3Ko5Qhbyl?= =?us-ascii?Q?85Bs2T3U0IyT+AB+ER4wFMXgflYIXGjUiEk1skZVjfUU0FJfTG1/Sc6I+663?= =?us-ascii?Q?2HCK+SM+bIj7Y93Kn2KYFZ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IPM128JL7FsGeU8KywTQnr8Uq0oRf4zug=; 24:SsoBWCf0cL2tKcS3fpgSGdPXgNrS2syb3WcFGrqMZq0gsIrTiUbc6vJFyvP8rgG5rK6usZYJo2SJbIauxEKoIPejyT/8pQIjff4n5KhI6B8=; 7:3U2VQBPtsn0dzMMP1eC13C5QDpTQoGE1ahZFq2BVsCxHRRWAoBaoGZhHh6iACIMuojphW73+0EmJqDxRZ3+5tkrJaeTPT+Fp72NJ4PVd1gljLdeFtbFoG93tS8PvtaUNxXGOX5mT7o6Rxx796exICD9mgSXPxvt/pxNx2cHvDAreqoFOr+lhP4Ct0yl6Mkde+pxeYFAn2e0t3vgSK3bLbrA4xCAzJ6p//FJbtmGc2oJAZLyyDoJtok/uoi28Wdia SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-MS-Exchange-CrossTenant-OriginalArrivalTime: 06 Sep 2016 08:41:07.4611 (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: BLUPR0301MB2001 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160906_014130_959486_997F67DB X-CRM114-Status: GOOD ( 25.81 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Mark Rutland , devicetree@vger.kernel.org, Russell King , Yangbo Lu , Bhupesh Sharma , netdev@vger.kernel.org, Joerg Roedel , Santosh Shilimkar , linux-kernel@vger.kernel.org, Jochen Friedrich , xiaobo.xie@nxp.com, iommu@lists.linux-foundation.org, Rob Herring , linux-i2c@vger.kernel.org, Claudiu Manoil , Kumar Gala , leoyang.li@nxp.com, linuxppc-dev@lists.ozlabs.org, linux-clk@vger.kernel.org, linux-arm-kernel@lists.infradead.org, Qiang Zhao Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP 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 --- drivers/base/Kconfig | 1 + drivers/base/soc.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/sys_soc.h | 3 +++ 3 files changed, 65 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..5c4e84a 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,63 @@ 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) +{ + struct device *dev; + int ret; + + for (ret = 0; ret == 0; matches++) { + if (!(matches->machine || matches->family || + matches->revision || matches->soc_id)) + return NULL; + dev = NULL; + ret = bus_for_each_dev(&soc_bus_type, dev, (void *)matches, + soc_device_match_one); + } + return matches; +} +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 */