The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: Russell King <rmk+lkml@arm.linux.org.uk>
To: Linux Kernel List <linux-kernel@vger.kernel.org>
Subject: Re: [DRIVER MODEL] Add platform_driver
Date: Sat, 5 Nov 2005 18:12:17 +0000	[thread overview]
Message-ID: <20051105181217.GA14419@flint.arm.linux.org.uk> (raw)
In-Reply-To: <20051105181122.GD12228@flint.arm.linux.org.uk>

Introduce struct platform_driver.  This allows the platform device
driver methods to be passed a platform_device structure instead of
instead of a plain device structure, and therefore requiring casting
in every platform driver.

We introduce this in such a way that any existing platform drivers
registered directly via driver_register continue to work as before,
thereby allowing a gradual conversion to the new platform_driver
methods.

Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>

diff -u b/drivers/base/platform.c b/drivers/base/platform.c
--- b/drivers/base/platform.c
+++ b/drivers/base/platform.c
@@ -20,6 +20,8 @@
 
 #include "base.h"
 
+#define to_platform_driver(drv)	(container_of((drv), struct platform_driver, driver))
+
 struct device platform_bus = {
 	.bus_id		= "platform",
 };
@@ -354,6 +356,77 @@
 	return ERR_PTR(retval);
 }
 
+static int platform_drv_probe(struct device *_dev)
+{
+	struct platform_driver *drv = to_platform_driver(_dev->driver);
+	struct platform_device *dev = to_platform_device(_dev);
+
+	return drv->probe(dev);
+}
+
+static int platform_drv_remove(struct device *_dev)
+{
+	struct platform_driver *drv = to_platform_driver(_dev->driver);
+	struct platform_device *dev = to_platform_device(_dev);
+
+	return drv->remove(dev);
+}
+
+static void platform_drv_shutdown(struct device *_dev)
+{
+	struct platform_driver *drv = to_platform_driver(_dev->driver);
+	struct platform_device *dev = to_platform_device(_dev);
+
+	drv->shutdown(dev);
+}
+
+static int platform_drv_suspend(struct device *_dev, pm_message_t state)
+{
+	struct platform_driver *drv = to_platform_driver(_dev->driver);
+	struct platform_device *dev = to_platform_device(_dev);
+
+	return drv->suspend(dev, state);
+}
+
+static int platform_drv_resume(struct device *_dev)
+{
+	struct platform_driver *drv = to_platform_driver(_dev->driver);
+	struct platform_device *dev = to_platform_device(_dev);
+
+	return drv->resume(dev);
+}
+
+/**
+ *	platform_driver_register
+ *	@drv: platform driver structure
+ */
+int platform_driver_register(struct platform_driver *drv)
+{
+	drv->driver.bus = &platform_bus_type;
+	if (drv->probe)
+		drv->driver.probe = platform_drv_probe;
+	if (drv->remove)
+		drv->driver.remove = platform_drv_remove;
+	if (drv->shutdown)
+		drv->driver.shutdown = platform_drv_shutdown;
+	if (drv->suspend)
+		drv->driver.suspend = platform_drv_suspend;
+	if (drv->resume)
+		drv->driver.resume = platform_drv_resume;
+	return driver_register(&drv->driver);
+}
+EXPORT_SYMBOL_GPL(platform_driver_register);
+
+/**
+ *	platform_driver_unregister
+ *	@drv: platform driver structure
+ */
+void platform_driver_unregister(struct platform_driver *drv)
+{
+	driver_unregister(&drv->driver);
+}
+EXPORT_SYMBOL_GPL(platform_driver_unregister);
+
 
 /**
  *	platform_match - bind platform device to platform driver.
diff -u b/include/linux/platform_device.h b/include/linux/platform_device.h
--- b/include/linux/platform_device.h
+++ b/include/linux/platform_device.h
@@ -43,4 +43,19 @@
 extern int platform_device_add(struct platform_device *pdev);
 extern void platform_device_put(struct platform_device *pdev);
 
+struct platform_driver {
+	int (*probe)(struct platform_device *);
+	int (*remove)(struct platform_device *);
+	void (*shutdown)(struct platform_device *);
+	int (*suspend)(struct platform_device *, pm_message_t state);
+	int (*resume)(struct platform_device *);
+	struct device_driver driver;
+};
+
+extern int platform_driver_register(struct platform_driver *);
+extern void platform_driver_unregister(struct platform_driver *);
+
+#define platform_get_drvdata(_dev)	dev_get_drvdata(&(_dev)->dev)
+#define platform_set_drvdata(_dev,data)	dev_set_drvdata(&(_dev)->dev, (data))
+
 #endif /* _PLATFORM_DEVICE_H_ */


-- 
Russell King
 Linux kernel    2.6 ARM Linux   - http://www.arm.linux.org.uk/
 maintainer of:  2.6 Serial core

  reply	other threads:[~2005-11-05 18:12 UTC|newest]

Thread overview: 23+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-05 18:11 [DRIVER MODEL] Add platform_driver Russell King
2005-11-05 18:12 ` Russell King [this message]
2005-11-06 20:39   ` Greg KH
2005-11-05 18:12 ` [DRIVER MODEL] Convert arch/arm Russell King
2005-11-05 18:13 ` [DRIVER MODEL] Convert arch/um/ Russell King
2005-11-05 18:14 ` [DRIVER MODEL] Convert arch/xtensa/ Russell King
2005-11-05 18:14 ` [DRIVER MODEL] Convert ARM s3c2410 drivers Russell King
2005-11-05 18:15 ` [DRIVER MODEL] Convert ARM SA1100 drivers Russell King
2005-11-05 18:15 ` [DRIVER MODEL] Convert ARM PXA drivers Russell King
2005-11-05 18:15 ` [DRIVER MODEL] Convert ARM IMX drivers Russell King
2005-11-05 18:16 ` [DRIVER MODEL] Convert ARM OMAP drivers Russell King
2005-11-05 18:16 ` [DRIVER MODEL] Convert ARM Zaurus drivers Russell King
2005-11-05 18:17 ` [DRIVER MODEL] Convert MMC drivers Russell King
2005-11-05 18:17 ` [DRIVER MODEL] Convert MTD drivers Russell King
2005-11-05 18:17 ` [DRIVER MODEL] Convert serial drivers Russell King
2005-11-05 18:17 ` [DRIVER MODEL] Convert i2c drivers Russell King
2005-11-05 18:18 ` [DRIVER MODEL] Convert input drivers Russell King
2005-11-05 18:18 ` [DRIVER MODEL] Convert network drivers Russell King
2005-11-05 18:18 ` [DRIVER MODEL] Convert USB drivers Russell King
2005-11-05 18:19 ` [DRIVER MODEL] Convert miscellaneous char drivers Russell King
2005-11-05 18:19 ` [DRIVER MODEL] Convert video drivers Russell King
2005-11-05 18:19 ` [DRIVER MODEL] Convert ALSA Russell King
2005-11-05 18:20 ` [DRIVER MODEL] Convert drivers/misc/hdpuftrs Russell King

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20051105181217.GA14419@flint.arm.linux.org.uk \
    --to=rmk+lkml@arm.linux.org.uk \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox