ARM: SAMSUNG: Add helper to clone and set platform data
authorBen Dooks <ben-linux@fluff.org>
Thu, 10 Jun 2010 03:57:15 +0000 (12:57 +0900)
committerKukjin Kim <kgene.kim@samsung.com>
Thu, 5 Aug 2010 09:32:49 +0000 (18:32 +0900)
This is intended to replace a number of sites in the Samsung kernel
where the same thing is being repeated in specific platform setting
code. See next patches for replacements.

Signed-off-by: Ben Dooks <ben-linux@fluff.org>
[kgene.kim@samsung.com: This is for building test]
Signed-off-by: Kukjin Kim <kgene.kim@samsung.com>
arch/arm/plat-samsung/Makefile
arch/arm/plat-samsung/include/plat/devs.h
arch/arm/plat-samsung/platformdata.c [new file with mode: 0644]

index b1d82cc..228c2ad 100644 (file)
@@ -30,6 +30,8 @@ obj-$(CONFIG_S3C_ADC) += adc.o
 
 # devices
 
+obj-y                          += platformdata.o
+
 obj-$(CONFIG_S3C_DEV_HSMMC)    += dev-hsmmc.o
 obj-$(CONFIG_S3C_DEV_HSMMC1)   += dev-hsmmc1.o
 obj-$(CONFIG_S3C_DEV_HSMMC2)   += dev-hsmmc2.o
index e6144e4..6760999 100644 (file)
@@ -108,3 +108,15 @@ extern struct platform_device s3c_device_camif;
 extern struct platform_device s3c_device_ac97;
 
 #endif
+
+/**
+ * s3c_set_platdata() - helper for setting platform data
+ * @pd: The default platform data for this device.
+ * @pdsize: The size of the platform data.
+ * @pdev: Pointer to the device to fill in.
+ *
+ * This helper replaces a number of calls that copy and then set the
+ * platform data of the device.
+ */
+extern void *s3c_set_platdata(void *pd, size_t pdsize,
+                             struct platform_device *pdev);
diff --git a/arch/arm/plat-samsung/platformdata.c b/arch/arm/plat-samsung/platformdata.c
new file mode 100644 (file)
index 0000000..7cf2e1e
--- /dev/null
@@ -0,0 +1,37 @@
+/* linux/arch/arm/plat-samsung/platformdata.c
+ *
+ * Copyright 2010 Ben Dooks <ben-linux <at> fluff.org>
+ *
+ * Helper for platform data setting
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2 as
+ * published by the Free Software Foundation.
+*/
+
+#include <linux/kernel.h>
+#include <linux/string.h>
+#include <linux/platform_device.h>
+
+#include <plat/devs.h>
+
+void __init *s3c_set_platdata(void *pd, size_t pdsize,
+                             struct platform_device *pdev)
+{
+       void *npd;
+
+       if (!pd) {
+               /* too early to use dev_name(), may not be registered */
+               printk(KERN_ERR "%s: no platform data supplied\n", pdev->name);
+               return NULL;
+       }
+
+       npd = kmemdup(pd, pdsize, GFP_KERNEL);
+       if (!npd) {
+               printk(KERN_ERR "%s: cannot clone platform data\n", pdev->name);
+               return NULL;
+       }
+
+       pdev->dev.platform_data = npd;
+       return npd;
+}