driver core: Add ability for arch code to setup pdev_archdata
authorKumar Gala <galak@kernel.crashing.org>
Fri, 10 Jun 2011 06:52:57 +0000 (01:52 -0500)
committerKumar Gala <galak@kernel.crashing.org>
Fri, 8 Jul 2011 05:21:35 +0000 (00:21 -0500)
On some architectures we need to setup pdev_archdata before we add the
device.  Waiting til a bus_notifier is too late since we might need the
pdev_archdata in the bus notifier.  One example is setting up of dma_mask
pointers such that it can be used in a bus_notifier.

We add weak noop version of arch_setup_pdev_archdata() and allow the arch
code to override with access the full definitions of struct device,
struct platform_device, and struct pdev_archdata.

Acked-by: Greg Kroah-Hartman <gregkh@suse.de>
Signed-off-by: Kumar Gala <galak@kernel.crashing.org>
drivers/base/platform.c
include/linux/platform_device.h

index 6040717..0cad9c7 100644 (file)
@@ -31,6 +31,25 @@ struct device platform_bus = {
 };
 EXPORT_SYMBOL_GPL(platform_bus);
 
+/**
+ * arch_setup_pdev_archdata - Allow manipulation of archdata before its used
+ * @dev: platform device
+ *
+ * This is called before platform_device_add() such that any pdev_archdata may
+ * be setup before the platform_notifier is called.  So if a user needs to
+ * manipulate any relevant information in the pdev_archdata they can do:
+ *
+ *     platform_devic_alloc()
+ *     ... manipulate ...
+ *     platform_device_add()
+ *
+ * And if they don't care they can just call platform_device_register() and
+ * everything will just work out.
+ */
+void __weak arch_setup_pdev_archdata(struct platform_device *pdev)
+{
+}
+
 /**
  * platform_get_resource - get a resource for a device
  * @dev: platform device
@@ -173,6 +192,7 @@ struct platform_device *platform_device_alloc(const char *name, int id)
                pa->pdev.id = id;
                device_initialize(&pa->pdev.dev);
                pa->pdev.dev.release = platform_device_release;
+               arch_setup_pdev_archdata(&pa->pdev);
        }
 
        return pa ? &pa->pdev : NULL;
@@ -334,6 +354,7 @@ EXPORT_SYMBOL_GPL(platform_device_del);
 int platform_device_register(struct platform_device *pdev)
 {
        device_initialize(&pdev->dev);
+       arch_setup_pdev_archdata(pdev);
        return platform_device_add(pdev);
 }
 EXPORT_SYMBOL_GPL(platform_device_register);
index ede1a80..27bb05a 100644 (file)
@@ -42,6 +42,7 @@ extern void platform_device_unregister(struct platform_device *);
 extern struct bus_type platform_bus_type;
 extern struct device platform_bus;
 
+extern void arch_setup_pdev_archdata(struct platform_device *);
 extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int);
 extern int platform_get_irq(struct platform_device *, unsigned int);
 extern struct resource *platform_get_resource_byname(struct platform_device *, unsigned int, const char *);