aboutsummaryrefslogtreecommitdiffstats
path: root/arch/arm/plat-s3c
diff options
context:
space:
mode:
authorBen Dooks <ben-linux@fluff.org>2009-09-28 06:59:49 -0400
committerBen Dooks <ben-linux@fluff.org>2009-11-30 20:34:16 -0500
commit2a3a18045b136487b22733d57410e6dccd34ac84 (patch)
tree4152d54029bd5c82e210dacbbba3b7629c14ca3c /arch/arm/plat-s3c
parentff34aaa9535afc46b017f7a9b553dbf3e0ad5084 (diff)
ARM: S3C: Add NAND device platform data set call
Diffstat (limited to 'arch/arm/plat-s3c')
-rw-r--r--arch/arm/plat-s3c/dev-nand.c97
-rw-r--r--arch/arm/plat-s3c/include/plat/nand.h8
2 files changed, 105 insertions, 0 deletions
diff --git a/arch/arm/plat-s3c/dev-nand.c b/arch/arm/plat-s3c/dev-nand.c
index 4e5323732434..e771e77dcd54 100644
--- a/arch/arm/plat-s3c/dev-nand.c
+++ b/arch/arm/plat-s3c/dev-nand.c
@@ -9,8 +9,12 @@
9#include <linux/kernel.h> 9#include <linux/kernel.h>
10#include <linux/platform_device.h> 10#include <linux/platform_device.h>
11 11
12#include <linux/mtd/mtd.h>
13#include <linux/mtd/partitions.h>
14
12#include <mach/map.h> 15#include <mach/map.h>
13#include <plat/devs.h> 16#include <plat/devs.h>
17#include <plat/nand.h>
14 18
15static struct resource s3c_nand_resource[] = { 19static struct resource s3c_nand_resource[] = {
16 [0] = { 20 [0] = {
@@ -28,3 +32,96 @@ struct platform_device s3c_device_nand = {
28}; 32};
29 33
30EXPORT_SYMBOL(s3c_device_nand); 34EXPORT_SYMBOL(s3c_device_nand);
35
36/**
37 * s3c_nand_copy_set() - copy nand set data
38 * @set: The new structure, directly copied from the old.
39 *
40 * Copy all the fields from the NAND set field from what is probably __initdata
41 * to new kernel memory. The code returns 0 if the copy happened correctly or
42 * an error code for the calling function to display.
43 *
44 * Note, we currently do not try and look to see if we've already copied the
45 * data in a previous set.
46 */
47static int __init s3c_nand_copy_set(struct s3c2410_nand_set *set)
48{
49 void *ptr;
50 int size;
51
52 size = sizeof(struct mtd_partition) * set->nr_partitions;
53 if (size) {
54 ptr = kmemdup(set->partitions, size, GFP_KERNEL);
55 set->partitions = ptr;
56
57 if (!ptr)
58 return -ENOMEM;
59 }
60
61 size = sizeof(int) * set->nr_chips;
62 if (size) {
63 ptr = kmemdup(set->nr_map, size, GFP_KERNEL);
64 set->nr_map = ptr;
65
66 if (!ptr)
67 return -ENOMEM;
68 }
69
70 if (set->ecc_layout) {
71 ptr = kmemdup(set->ecc_layout,
72 sizeof(struct nand_ecclayout), GFP_KERNEL);
73 set->ecc_layout = ptr;
74
75 if (!ptr)
76 return -ENOMEM;
77 }
78
79 return 0;
80}
81
82void __init s3c_nand_set_platdata(struct s3c2410_platform_nand *nand)
83{
84 struct s3c2410_platform_nand *npd;
85 int size;
86 int ret;
87
88 /* note, if we get a failure in allocation, we simply drop out of the
89 * function. If there is so little memory available at initialisation
90 * time then there is little chance the system is going to run.
91 */
92
93 npd = kmemdup(nand, sizeof(struct s3c2410_platform_nand), GFP_KERNEL);
94 if (!npd) {
95 printk(KERN_ERR "%s: failed copying platform data\n", __func__);
96 return;
97 }
98
99 /* now see if we need to copy any of the nand set data */
100
101 size = sizeof(struct s3c2410_nand_set) * npd->nr_sets;
102 if (size) {
103 struct s3c2410_nand_set *from = npd->sets;
104 struct s3c2410_nand_set *to;
105 int i;
106
107 to = kmemdup(from, size, GFP_KERNEL);
108 npd->sets = to; /* set, even if we failed */
109
110 if (!to) {
111 printk(KERN_ERR "%s: no memory for sets\n", __func__);
112 return;
113 }
114
115 for (i = 0; i < npd->nr_sets; i++) {
116 ret = s3c_nand_copy_set(to);
117 if (!ret) {
118 printk(KERN_ERR "%s: failed to copy set %d\n",
119 __func__, i);
120 return;
121 }
122 to++;
123 }
124 }
125}
126
127EXPORT_SYMBOL_GPL(s3c_nand_set_platdata);
diff --git a/arch/arm/plat-s3c/include/plat/nand.h b/arch/arm/plat-s3c/include/plat/nand.h
index 18f958801e64..065985978413 100644
--- a/arch/arm/plat-s3c/include/plat/nand.h
+++ b/arch/arm/plat-s3c/include/plat/nand.h
@@ -55,3 +55,11 @@ struct s3c2410_platform_nand {
55 int chip); 55 int chip);
56}; 56};
57 57
58/**
59 * s3c_nand_set_platdata() - register NAND platform data.
60 * @nand: The NAND platform data to register with s3c_device_nand.
61 *
62 * This function copies the given NAND platform data, @nand and registers
63 * it with the s3c_device_nand. This allows @nand to be __initdata.
64*/
65extern void s3c_nand_set_platdata(struct s3c2410_platform_nand *nand);