[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <20210527084531.18989-1-christian.gmeiner@gmail.com>
Date: Thu, 27 May 2021 10:45:15 +0200
From: Christian Gmeiner <christian.gmeiner@...il.com>
To: linux-kernel@...r.kernel.org
Cc: Christian Gmeiner <christian.gmeiner@...il.com>,
Mark Brown <broonie@...nel.org>, linux-spi@...r.kernel.org
Subject: [PATCH] spidev: add platform driver support
This makes it possible to use spidev in combination with the
MFD subsystem. The MFD subsystem add platform_driver devices.
Signed-off-by: Christian Gmeiner <christian.gmeiner@...il.com>
---
drivers/spi/spidev.c | 45 ++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 45 insertions(+)
diff --git a/drivers/spi/spidev.c b/drivers/spi/spidev.c
index f56e0e975a46..fb7b483ff70d 100644
--- a/drivers/spi/spidev.c
+++ b/drivers/spi/spidev.c
@@ -25,6 +25,8 @@
#include <linux/spi/spi.h>
#include <linux/spi/spidev.h>
+#include <linux/platform_device.h>
+
#include <linux/uaccess.h>
@@ -827,6 +829,40 @@ static struct spi_driver spidev_spi_driver = {
*/
};
+static int spidev_platform_probe(struct platform_device *pdev)
+{
+ struct device *parent = pdev->dev.parent;
+ struct spi_device *spi;
+
+ if (strcmp(parent->bus->name, "spi"))
+ return -ENODEV;
+
+ spi = to_spi_device(parent);
+
+ /* This only works if no drvdata is stored */
+ if (spi_get_drvdata(spi)) {
+ dev_err(&pdev->dev, "drvdata is not NULL\n");
+ return -EOPNOTSUPP;
+ }
+
+ return spidev_probe(spi);
+}
+
+static int spidev_platform_remove(struct platform_device *pdev)
+{
+ struct spi_device *spi = to_spi_device(pdev->dev.parent);
+
+ return spidev_remove(spi);
+}
+
+static struct platform_driver spidev_platfoem_driver = {
+ .probe = spidev_platform_probe,
+ .remove = spidev_platform_remove,
+ .driver = {
+ .name = "spidev",
+ },
+};
+
/*-------------------------------------------------------------------------*/
static int __init spidev_init(void)
@@ -853,12 +889,21 @@ static int __init spidev_init(void)
class_destroy(spidev_class);
unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
}
+
+ status = platform_driver_register(&spidev_platfoem_driver);
+ if (status < 0) {
+ spi_unregister_driver(&spidev_spi_driver);
+ class_destroy(spidev_class);
+ unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
+ }
+
return status;
}
module_init(spidev_init);
static void __exit spidev_exit(void)
{
+ platform_driver_unregister(&spidev_platfoem_driver);
spi_unregister_driver(&spidev_spi_driver);
class_destroy(spidev_class);
unregister_chrdev(SPIDEV_MAJOR, spidev_spi_driver.driver.name);
--
2.31.1
Powered by blists - more mailing lists