All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] spidev: add platform driver support
@ 2021-05-27  8:45 Christian Gmeiner
  2021-05-27 10:10 ` Mark Brown
  2021-06-16 19:16 ` Christian Gmeiner
  0 siblings, 2 replies; 6+ messages in thread
From: Christian Gmeiner @ 2021-05-27  8:45 UTC (permalink / raw)
  To: linux-kernel; +Cc: Christian Gmeiner, Mark Brown, linux-spi

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@gmail.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


^ permalink raw reply related	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2021-06-21 14:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-05-27  8:45 [PATCH] spidev: add platform driver support Christian Gmeiner
2021-05-27 10:10 ` Mark Brown
2021-06-16 19:16 ` Christian Gmeiner
2021-06-16 19:43   ` Mark Brown
2021-06-21 13:57     ` Christian Gmeiner
2021-06-21 14:41       ` Mark Brown

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.