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: 617085 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id BC155C433FE for ; Thu, 20 Oct 2022 19:54:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229835AbiJTTyF (ORCPT ); Thu, 20 Oct 2022 15:54:05 -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 Precedence: bulk List-ID: X-Mailing-List: linux-spi@vger.kernel.org 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) {