From patchwork Fri Oct 28 03:32:33 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yangbo Lu X-Patchwork-Id: 9401051 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 9C8A9601C0 for ; Fri, 28 Oct 2016 03:51:33 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7F80A2A52E for ; Fri, 28 Oct 2016 03:51:33 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7072A2A536; Fri, 28 Oct 2016 03:51:33 +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 DE6292A52E for ; Fri, 28 Oct 2016 03:51:32 +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 1bzyB4-0001LT-42; Fri, 28 Oct 2016 03:49:58 +0000 Received: from mail-dm3nam03on0086.outbound.protection.outlook.com ([104.47.41.86] helo=NAM03-DM3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bzy7p-0007IL-KJ for linux-arm-kernel@lists.infradead.org; Fri, 28 Oct 2016 03:46:41 +0000 Received: from BN6PR03CA0035.namprd03.prod.outlook.com (10.175.124.21) by CO2PR03MB2374.namprd03.prod.outlook.com (10.166.93.22) 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 03:46:15 +0000 Received: from BN1AFFO11FD050.protection.gbl (2a01:111:f400:7c10::131) by BN6PR03CA0035.outlook.office365.com (2603:10b6:404:10c::21) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA384_P384) id 15.1.639.5 via Frontend Transport; Fri, 28 Oct 2016 03:46:15 +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 BN1AFFO11FD050.mail.protection.outlook.com (10.58.53.65) 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 03:46:15 +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 u9S3jA03026194; Thu, 27 Oct 2016 20:46:07 -0700 From: Yangbo Lu To: , , Scott Wood , Arnd Bergmann Subject: [v13, 7/8] base: soc: introduce soc_device_match() interface Date: Fri, 28 Oct 2016 11:32:33 +0800 Message-ID: <1477625554-46700-8-git-send-email-yangbo.lu@nxp.com> X-Mailer: git-send-email 2.1.0.27.g96db324 In-Reply-To: <1477625554-46700-1-git-send-email-yangbo.lu@nxp.com> References: <1477625554-46700-1-git-send-email-yangbo.lu@nxp.com> X-EOPAttributedMessage: 0 X-Matching-Connectors: 131220999755008144; (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)(189998001)(229853001)(36756003)(5003940100001)(8676002)(106466001)(11100500001)(6666003)(47776003)(4326007)(92566002)(86362001)(76176999)(50986999)(77096005)(626004)(586003)(68736007)(5660300001)(97736004)(50226002)(19580395003)(5001770100001)(19580405001)(305945005)(48376002)(8936002)(356003)(33646002)(8666005)(81166006)(2906002)(105606002)(81156014)(7846002)(50466002)(85426001)(7416002)(104016004)(2950100002)(87936001)(7059030); DIR:OUT; SFP:1101; SCL:1; SRVR:CO2PR03MB2374; H:tx30smr01.am.freescale.net; FPR:; SPF:Fail; PTR:InfoDomainNonexistent; MX:1; A:1; LANG:en; X-Microsoft-Exchange-Diagnostics: 1; BN1AFFO11FD050; 1:5DE1Umar4l+dNK5yRnSubvgz8ftGsh6DLsjFXoD/NWuFts37eWb5Gbb5fpqzWqhb6+hNsR+IATk7nCSkVu4HbhlxPo1sHs8j7nuXa6UHk7I2YbftcZEw2hda1IH9fuuO/m0IFybLIXbN+ZjmANehpzx2QLKqo2mrAfgIeAD62e1b+FLT4khuNS9qXeTwBhMM9AvhGfd4aBvhy1i9XNzgZwRA0sw74NMk6u0T8tDpwKc3XGMDPzANAvytCWRahrSGp/DHuaOzisftXXKeKXRitZsLO/xeEkAsW8UGzFcMlUECRhy06cVB57LBTbktRfXx3xyibG0z7dT77xKASUj1BZovIUUIFuHJeJdEz0cD3237ZyBDkpgJTZHmncp/8m0GqidSVUdHUMQN5cNFLJPfqd4Y5cTwiKmsWQYXlx7/5zzvC0hpHmN/uCQKhaIMMphg2aSGuhiwtnw33LUHpdI6y6aIpm0MDyhSgfuQ6rWEm+a+Sjaw8HZFeiF61H/UeEDexexXirLpIZVYRsPRGSFowU1uJQ/nRgbgr1AVU/YWpslDR8WunlW7s9j93VpxFNai4v/0v4q/mmHiWeiM5Roo9IW77zdUfand/QT3mL4zSE+oIAObREWxqze/7u2u0B4IIyqyEb1urUmKcLedUSxgBNtTlFyCHeob6Z8AoEHzullPsgSD2MGtV6gXlC5B+BjKYMdW4VECZZ1t3YwB1b/5GHwD58oLNniFYCvKGxagzeSznhpgJqc6KBO1h3arM1ZW MIME-Version: 1.0 X-MS-Office365-Filtering-Correlation-Id: cadeb9a4-8a0e-44d2-a731-08d3fee4f7ec X-Microsoft-Exchange-Diagnostics: 1; CO2PR03MB2374; 2:EZz3I/J/TPWnPXXwlvVH0YWTuzq8y9M7AcYjNpyIAZqN1f3SH9XQwGcJ3QFnWb/JE07xfa2nUrOa2h9E+0z3aGwZM/T3DvdQA7zkVwW7n5AFsK/R8X7lFIQesAdkm4/pR2g5JhMoKvAYkOLno/6yAHoRwkql9XxepmSCmqcRoHuvrfx9ulfKK9s5rGz5UEwQidNSX+pDyG6qalFmKmq9yg==; 3:fliijAER7mO2ybjBuFu1p3ud722gvHjuclljqatMBX/pOw9Vfz8dSZDNQJdwlUn9qh8xsCkTeoFcl9vZd0EQQua6SPqWRpDCtKkQzptuFC6VlnA+8XFatXl5pU5Y/wnQQk60M8Yu1vOih+t0a74nQO14jKyN5SKrIQ9XcicXHn02olSPHrDS8XPzcM0Lw7gHirFEqelPG73Aj1oaraUoa2+14Ldr6nH6soUcAhrKudsHn5ZOHryI+BNmsEoyeabH X-Microsoft-Antispam: UriScan:;BCL:0;PCL:0;RULEID:;SRVR:CO2PR03MB2374; X-Microsoft-Exchange-Diagnostics: 1; CO2PR03MB2374; 25:gymiNw37rwRTMArlios7aIvNjQwHYeF8tmhfgJNqO0coQKi8PS2JYlBFiH2B9o+ZqsUnoJhj8D/BYrSeB1qVdNNC/lQN1M4ehZ8EMegyN32VSK0e6kTqJvHaUUdVm/YktgJUbV3vmnetPIRRxX7wxVY/Bd4yCSkczkk240YEKYA0k0u6Uuu6caLIoXZdUUREFTvu9Kc5bQCgkWxx0xoPgD+f6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yRIviJwfE6YznuOafRuiCKbs0/5yE5upyCLqgAeqd9cE8REFqMlJJfd74wY1LMUSOkf/W/Cz4fWz3ZKdTXEYsBy8gJmScGz+9gWgbb1IuRDJ8lhYJXG0zeqBc2304blMBwUama3dUuiYnvaIV0yZtWlPNIaOv7tB5P5NA6dp+WNEcpLyonfpvHTVpts/ETuUYvWnmk9l5zIquyWy4w/8aAhIh3anIGpeygPEMNRSG1aKDwxbmZ/N472JsDAZUSGiDf5p4GCYESABhiAK6EXKSZtSNx8al3RRTkJSctvPC+GZMe0K9S4WOpeW5yZX0oI6vRuRDivDWuF0N1h6nwYmYnUjnOzsY27OumR6OYj7imi8Y7xpK1xSzVJrEex6IrrpvUdyYjqBNn8aJ8T0u3PK/uCw8VB1+x6qhnO6eRcOAm9bPoRKyUuypiRk5ptDmZ 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)(13018025)(13015025)(13017025)(13023025)(5005006)(8121501046)(3002001)(10201501046)(6055026); SRVR:CO2PR03MB2374; BCL:0; PCL:0; RULEID:(400006); SRVR:CO2PR03MB2374; X-Forefront-PRVS: 0109D382B0 X-Microsoft-Exchange-Diagnostics: =?us-ascii?Q?1; CO2PR03MB2374; 23:qIOdvOHYWo6fXpA/5p+WOLaiaBVIyPsQ8IzAU5sX2?= =?us-ascii?Q?/01V+Eb0uIfhBM8s+9DOHiAKy9QkIdPXhARonKGb8HJnp/E+ORYnfTFlwurb?= =?us-ascii?Q?MMcEM3SEwXKUEhJjfCLwDHOc4UDDS/cud1Lv2bbjtf9ux4vrrJTBgqDHh+Nh?= =?us-ascii?Q?EGcwEv++2XRe+QcNq/FDkLl7TA0BvZDlF31Nn1ow6h9P8DTWxM+ktuwHK6i3?= =?us-ascii?Q?fGQm8lmNyB2bg9hvpPfP6+v+tozPe7mwQZsOfjpx6rjeb3CzZnFHfBGJW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IaZJaXs9UpjUMP2I/cx?= =?us-ascii?Q?X/LxvkPQBsRb+aoRuABOQVRa1o7PNaZ6Y5S?= X-Microsoft-Exchange-Diagnostics: 1; CO2PR03MB2374; 6:clka+C2LjUafpIMnlz+6VrMfhD4MsTXi7SbzIP15fhypUzh7fsGQ59ibjMvFqP1DSbn+N383cxTTUGQBdx6j2spKhpf3vx53Ov/69cYzfrldIDRBhYWI07KabJlT9ltmTKF3aLV/FERvY/TRW4OH2nIJeK1pSuL1a4K9XULD3pW2batg2rLSo5swxKGGgdlTR0pFVoR6e6p4FUQy/HnN57OGDc24ctZ83i8KsaqLrKxTAai80v/Tn5tP51+dGCQYeonuUzXOxR8NfpBhHk+fuVXKYxUm3ULpxSSPGqiRFH/xErouIA3Y76Kr7hjUE3lN; 5:jH+IAiDhD5V/BeP76oEA0PH6Lt2ClLF4hRSv1w/EBD1m4c/WjULQzF4M8yCwoSBuqxI59afSZNcTv7EzYtSuN5A6zRfCRfYy9a2z2mtIZAB1JUg/nVRFjiV3ee8qL9Q/ywRjxhE50dcYQBe1peKxwO+xhLpUdegf+G7+3C+rqdN5FrQ5Aslr7d0l3iDzRKpT; 24:zYIpPHVvhjokE/0WAgQcirOGYrmkD7zurV8X2RRorcOKiT0ZZ9m+WtfxIxrtpiRKD9h36yKoppdu5R48EIopBRjDrdsO5QSKq7Uf6HoCAlg= SpamDiagnosticOutput: 1:99 SpamDiagnosticMetadata: NSPM X-Microsoft-Exchange-Diagnostics: 1; CO2PR03MB2374; 7:tSb3xEnb2ojPP0PObKc/HzGWnklQHi2/FS4LVGzrcPgZ1LH3BYAF27rrZeuqrXJLc9juqVT563AVVx6iKk6F33/WhVpXW+RINi9Bj7Uxu4H2TFmqGH2lV/+L98m/Ql8wvtu8u00EX9L5Zn6lokFXa8l8qUqSpcoZSYsQozJyraipAhjlBDkJyVpqIXiA0SzWTRgDMMmDkraY097nitc+W0suLw0wzgKRK5bJFuQlUsT5IviHOmsf43kKlAeV3xedvuGhoNgVIpzmiRFeEAhXIAarZZ3bktdi478Kj0r09Kgx5bnVyyyj7taOwzA1ubqLfulZVf2LznDnUpaMVJ+BBb3jn5IeU/jKTq47mnjJ4Zg= X-MS-Exchange-CrossTenant-OriginalArrivalTime: 28 Oct 2016 03:46:15.2044 (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: CO2PR03MB2374 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20161027_204637_922130_B5F1A751 X-CRM114-Status: GOOD ( 26.82 ) 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 , Greg Kroah-Hartman , Xiaobo Xie , Minghuan Lian , linux-i2c@vger.kernel.org, linux-clk@vger.kernel.org, Qiang Zhao , Russell King , Bhupesh Sharma , Joerg Roedel , Jochen Friedrich , Claudiu Manoil , devicetree@vger.kernel.org, Yangbo Lu , 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, Kumar Gala , linuxppc-dev@lists.ozlabs.org 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 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 --- 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 */