]> git.ipfire.org Git - thirdparty/kernel/stable.git/commitdiff
spi: Introduce spi_get_device_match_data() helper
authorAndy Shevchenko <andriy.shevchenko@linux.intel.com>
Thu, 20 Oct 2022 19:54:21 +0000 (22:54 +0300)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Fri, 5 Jan 2024 14:18:37 +0000 (15:18 +0100)
[ Upstream commit aea672d054a21782ed8450c75febb6ba3c208ca4 ]

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 <andriy.shevchenko@linux.intel.com>
Link: https://lore.kernel.org/r/20221020195421.10482-1-andriy.shevchenko@linux.intel.com
Signed-off-by: Mark Brown <broonie@kernel.org>
Stable-dep-of: ee4d79055aee ("iio: imu: adis16475: add spi_device_id table")
Signed-off-by: Sasha Levin <sashal@kernel.org>
drivers/spi/spi.c
include/linux/spi/spi.h

index 5d046be8b2dd5603b63303c4e1bd315230073a21..dfce0f7d4c6402e670b2e9377710421f28334308 100644 (file)
@@ -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);
index 877395e075afed43e787b45ff86ae95c6bd92e79..635a05c30283c3a0c719632b8e8a72d742272b2d 100644 (file)
@@ -1515,6 +1515,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)
 {