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.
9 #include <linux/kernel.h>
10 #include <linux/platform_device.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/partitions.h>
16 #include <plat/devs.h>
17 #include <plat/nand.h>
19 static struct resource s3c_nand_resource
[] = {
22 .end
= S3C_PA_NAND
+ SZ_1M
,
23 .flags
= IORESOURCE_MEM
,
27 struct platform_device s3c_device_nand
= {
28 .name
= "s3c2410-nand",
30 .num_resources
= ARRAY_SIZE(s3c_nand_resource
),
31 .resource
= s3c_nand_resource
,
34 EXPORT_SYMBOL(s3c_device_nand
);
37 * s3c_nand_copy_set() - copy nand set data
38 * @set: The new structure, directly copied from the old.
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.
44 * Note, we currently do not try and look to see if we've already copied the
45 * data in a previous set.
47 static int __init
s3c_nand_copy_set(struct s3c2410_nand_set
*set
)
52 size
= sizeof(struct mtd_partition
) * set
->nr_partitions
;
54 ptr
= kmemdup(set
->partitions
, size
, GFP_KERNEL
);
55 set
->partitions
= ptr
;
61 if (set
->nr_map
&& set
->nr_chips
) {
62 size
= sizeof(int) * set
->nr_chips
;
63 ptr
= kmemdup(set
->nr_map
, size
, GFP_KERNEL
);
70 if (set
->ecc_layout
) {
71 ptr
= kmemdup(set
->ecc_layout
,
72 sizeof(struct nand_ecclayout
), GFP_KERNEL
);
73 set
->ecc_layout
= ptr
;
82 void __init
s3c_nand_set_platdata(struct s3c2410_platform_nand
*nand
)
84 struct s3c2410_platform_nand
*npd
;
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.
93 npd
= kmemdup(nand
, sizeof(struct s3c2410_platform_nand
), GFP_KERNEL
);
95 printk(KERN_ERR
"%s: failed copying platform data\n", __func__
);
99 /* now see if we need to copy any of the nand set data */
101 size
= sizeof(struct s3c2410_nand_set
) * npd
->nr_sets
;
103 struct s3c2410_nand_set
*from
= npd
->sets
;
104 struct s3c2410_nand_set
*to
;
107 to
= kmemdup(from
, size
, GFP_KERNEL
);
108 npd
->sets
= to
; /* set, even if we failed */
111 printk(KERN_ERR
"%s: no memory for sets\n", __func__
);
115 for (i
= 0; i
< npd
->nr_sets
; i
++) {
116 ret
= s3c_nand_copy_set(to
);
118 printk(KERN_ERR
"%s: failed to copy set %d\n",
126 s3c_device_nand
.dev
.platform_data
= npd
;
129 EXPORT_SYMBOL_GPL(s3c_nand_set_platdata
);