Merge remote-tracking branch 'moduleh/module.h-split'
[linux-2.6/next.git] / arch / arm / plat-samsung / dev-nand.c
blobbe53a658725035ff81c29b24e9bff6fda01ab6fc
1 /*
2 * S3C series device definition for nand device
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 */
9 #include <linux/gfp.h>
10 #include <linux/kernel.h>
11 #include <linux/platform_device.h>
13 #include <linux/mtd/mtd.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/export.h>
17 #include <mach/map.h>
18 #include <plat/devs.h>
19 #include <plat/nand.h>
21 static struct resource s3c_nand_resource[] = {
22 [0] = {
23 .start = S3C_PA_NAND,
24 .end = S3C_PA_NAND + SZ_1M,
25 .flags = IORESOURCE_MEM,
29 struct platform_device s3c_device_nand = {
30 .name = "s3c2410-nand",
31 .id = -1,
32 .num_resources = ARRAY_SIZE(s3c_nand_resource),
33 .resource = s3c_nand_resource,
36 EXPORT_SYMBOL(s3c_device_nand);
38 /**
39 * s3c_nand_copy_set() - copy nand set data
40 * @set: The new structure, directly copied from the old.
42 * Copy all the fields from the NAND set field from what is probably __initdata
43 * to new kernel memory. The code returns 0 if the copy happened correctly or
44 * an error code for the calling function to display.
46 * Note, we currently do not try and look to see if we've already copied the
47 * data in a previous set.
49 static int __init s3c_nand_copy_set(struct s3c2410_nand_set *set)
51 void *ptr;
52 int size;
54 size = sizeof(struct mtd_partition) * set->nr_partitions;
55 if (size) {
56 ptr = kmemdup(set->partitions, size, GFP_KERNEL);
57 set->partitions = ptr;
59 if (!ptr)
60 return -ENOMEM;
63 if (set->nr_map && set->nr_chips) {
64 size = sizeof(int) * set->nr_chips;
65 ptr = kmemdup(set->nr_map, size, GFP_KERNEL);
66 set->nr_map = ptr;
68 if (!ptr)
69 return -ENOMEM;
72 if (set->ecc_layout) {
73 ptr = kmemdup(set->ecc_layout,
74 sizeof(struct nand_ecclayout), GFP_KERNEL);
75 set->ecc_layout = ptr;
77 if (!ptr)
78 return -ENOMEM;
81 return 0;
84 void __init s3c_nand_set_platdata(struct s3c2410_platform_nand *nand)
86 struct s3c2410_platform_nand *npd;
87 int size;
88 int ret;
90 /* note, if we get a failure in allocation, we simply drop out of the
91 * function. If there is so little memory available at initialisation
92 * time then there is little chance the system is going to run.
93 */
95 npd = s3c_set_platdata(nand, sizeof(struct s3c2410_platform_nand),
96 &s3c_device_nand);
97 if (!npd)
98 return;
100 /* now see if we need to copy any of the nand set data */
102 size = sizeof(struct s3c2410_nand_set) * npd->nr_sets;
103 if (size) {
104 struct s3c2410_nand_set *from = npd->sets;
105 struct s3c2410_nand_set *to;
106 int i;
108 to = kmemdup(from, size, GFP_KERNEL);
109 npd->sets = to; /* set, even if we failed */
111 if (!to) {
112 printk(KERN_ERR "%s: no memory for sets\n", __func__);
113 return;
116 for (i = 0; i < npd->nr_sets; i++) {
117 ret = s3c_nand_copy_set(to);
118 if (ret) {
119 printk(KERN_ERR "%s: failed to copy set %d\n",
120 __func__, i);
121 return;
123 to++;