From patchwork Thu Oct 20 19:54:21 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Shevchenko X-Patchwork-Id: 6375 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a5d:4242:0:0:0:0:0 with SMTP id s2csp296159wrr; Thu, 20 Oct 2022 12:56:28 -0700 (PDT) X-Google-Smtp-Source: AMsMyM7RaV9uBUpvWKkYVSLwU+ZYFSg8IVn1J+jNrood4yNuiFy9TZlFbUABCXmxPSpGDd9aK6OV X-Received: by 2002:a17:906:cc58:b0:78d:d47e:19f2 with SMTP id mm24-20020a170906cc5800b0078dd47e19f2mr12403819ejb.388.1666295788185; Thu, 20 Oct 2022 12:56:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666295788; cv=none; d=google.com; s=arc-20160816; b=XHhnZKMbOJV6oUs0sdeTV2kQ9oQHZm/MYr+HfiPW3lCO0WG8AEW6QzFgxSIEqdp9QK r0JzoAkQ2Jj2l6ZvX3xD3J/z+XFqQ+g9DpcIh+CXKx1hPG2rqz6Z/hHtU1F1eWMaeGEJ fKnqEE+k9+vZ7+A9f8o7e5aQoqMpRtdKfMNb67X6t2LzIqGRxcrOyRtlw24ERkKzWaar YA6gwak3daK/wgf16GhDGxcbGy9ioPccXZU3sHYX8w5cALA0yskSLus1WfDyhpVyLlwY eSnd2XFpcuCn8oYyrR5Mwe9urI0xvZSbD/UR7XlddUr7favBX9HNl7R6/8BFmrvKoFc0 pgRQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :message-id:date:subject:cc:to:from:dkim-signature; bh=Vf5k/pV2Pt+Kfr78zlNvmVzix/3jd0cz9ohKxcom/E4=; b=b9G4c514OtHV2JQaJ0lU2MJp3I+SCKc2ryp9kzWgXI57dVHsJJqLUYWRxj3rRCq8hN Vp9uzzUiFQ8RVDf+AsGCCSrxHqGNaGkIOeJ65SXKAaVjY25Kp0bqQcvHZTOgp0H91IDC Fi1pUB03/yNo8dMUGCZGJTe9p8giWltfRvB3j5xRmqp15VpyEUFiahJo0tU8UNwoAFPp aLTKsnhs8gQYsHlwbSAyKUqw1WRJilxVpIME89CsLJQ3P01XzIRqwd+tHzHmoCwv5F6W bDExpdM4mOVYEzxRCzh7cTXyNlWUHkizd2fiwA1//7lf38NJPrA4w9ABRod68CmRm17Q afSQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CbJu2aJj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ji3-20020a170907980300b0078e254ae419si20780341ejc.643.2022.10.20.12.56.03; Thu, 20 Oct 2022 12:56:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@intel.com header.s=Intel header.b=CbJu2aJj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229768AbiJTTyG (ORCPT + 99 others); Thu, 20 Oct 2022 15:54:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:36838 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229799AbiJTTyF (ORCPT ); Thu, 20 Oct 2022 15:54:05 -0400 Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 51BD8215503; Thu, 20 Oct 2022 12:54:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=intel.com; i=@intel.com; q=dns/txt; s=Intel; t=1666295644; x=1697831644; h=from:to:cc:subject:date:message-id:mime-version: content-transfer-encoding; bh=qsMqdU9A1dj40AcyQFiHsoLDiAxuAbQUMYuX1A7KJR0=; b=CbJu2aJjspNdnDbRt8Ve1uaOOXlw+/KsznA8wBDzywEG7D/whIaFxEq+ WQqHxaXBf0fPDnoVo0L7QaUu34Wi3cr+TiirN1hOLNxEYMHX9PJSreMb2 hZ44t22Fq2rHPT/cfEXbpA/t3h/LLt/pGp7B8TVWHJ+gYLcXOp+OahhzB wUiEJKdUpbtoYtMOqN9JIfIDClhyi67dU6Wzd96Nhd/GogGrOETC/Yqup bFXVyd5kJqwJOpWGSuQI6Oc1u1kzaOqMtV+YYs1cOY5TTXyVtpCkZ/2un 9+VV3rMpEm5cQMci9O17dOZIZG1yDltfLoXNkye+vFbZ75cokII2Lxk6J w==; X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="307920214" X-IronPort-AV: E=Sophos;i="5.95,199,1661842800"; d="scan'208";a="307920214" Received: from fmsmga005.fm.intel.com ([10.253.24.32]) by orsmga102.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 20 Oct 2022 12:54:03 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=McAfee;i="6500,9779,10506"; a="959164973" X-IronPort-AV: E=Sophos;i="5.95,199,1661842800"; d="scan'208";a="959164973" Received: from black.fi.intel.com ([10.237.72.28]) by fmsmga005.fm.intel.com with ESMTP; 20 Oct 2022 12:54:02 -0700 Received: by black.fi.intel.com (Postfix, from userid 1003) id A6FA1107; Thu, 20 Oct 2022 22:54:23 +0300 (EEST) From: Andy Shevchenko To: Mark Brown , David Jander , linux-spi@vger.kernel.org, linux-kernel@vger.kernel.org Cc: Andy Shevchenko Subject: [PATCH v2 1/1] spi: Introduce spi_get_device_match_data() helper Date: Thu, 20 Oct 2022 22:54:21 +0300 Message-Id: <20221020195421.10482-1-andriy.shevchenko@linux.intel.com> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 X-Spam-Status: No, score=-4.5 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_EF,RCVD_IN_DNSWL_MED, RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE,SPF_NONE, URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1747237772721947967?= X-GMAIL-MSGID: =?utf-8?q?1747237772721947967?= The proposed spi_get_device_match_data() helper is for retrieving a driver data associated with the ID in an ID table. First, it tries to get driver data of the device enumerated by firmware interface (usually Device Tree or ACPI). If none is found it falls back to the SPI ID table matching. Signed-off-by: Andy Shevchenko --- v2: rebased on top of v6.1-rc1, so shouldn't be any compilation errors drivers/spi/spi.c | 12 ++++++++++++ include/linux/spi/spi.h | 3 +++ 2 files changed, 15 insertions(+) diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c index 5f9aedd1f0b6..aaf07052fd01 100644 --- a/drivers/spi/spi.c +++ b/drivers/spi/spi.c @@ -360,6 +360,18 @@ const struct spi_device_id *spi_get_device_id(const struct spi_device *sdev) } EXPORT_SYMBOL_GPL(spi_get_device_id); +const void *spi_get_device_match_data(const struct spi_device *sdev) +{ + const void *match; + + match = device_get_match_data(&sdev->dev); + if (match) + return match; + + return (const void *)spi_get_device_id(sdev)->driver_data; +} +EXPORT_SYMBOL_GPL(spi_get_device_match_data); + static int spi_match_device(struct device *dev, struct device_driver *drv) { const struct spi_device *spi = to_spi_device(dev); diff --git a/include/linux/spi/spi.h b/include/linux/spi/spi.h index fbf8c0d95968..8fe3d0a9d2c9 100644 --- a/include/linux/spi/spi.h +++ b/include/linux/spi/spi.h @@ -1514,6 +1514,9 @@ extern void spi_unregister_device(struct spi_device *spi); extern const struct spi_device_id * spi_get_device_id(const struct spi_device *sdev); +extern const void * +spi_get_device_match_data(const struct spi_device *sdev); + static inline bool spi_transfer_is_last(struct spi_controller *ctlr, struct spi_transfer *xfer) {