Commit | Line | Data |
---|---|---|
1da177e4 | 1 | /* |
69f34c98 | 2 | * Flash memory access on Hynix GMS30C7201/HMS30C7202 based |
1da177e4 | 3 | * evaluation boards |
69f34c98 | 4 | * |
1da177e4 | 5 | * (C) 2002 Jungjun Kim <jungjun.kim@hynix.com> |
69f34c98 | 6 | * 2003 Thomas Gleixner <tglx@linutronix.de> |
1da177e4 LT |
7 | */ |
8 | ||
1da177e4 LT |
9 | #include <linux/module.h> |
10 | #include <linux/types.h> | |
11 | #include <linux/kernel.h> | |
12 | #include <linux/init.h> | |
13 | #include <linux/errno.h> | |
14 | #include <linux/slab.h> | |
15 | ||
16 | #include <linux/mtd/mtd.h> | |
17 | #include <linux/mtd/map.h> | |
18 | #include <linux/mtd/partitions.h> | |
a09e64fb | 19 | #include <mach/hardware.h> |
1da177e4 LT |
20 | #include <asm/io.h> |
21 | ||
22 | static struct mtd_info *mymtd; | |
23 | ||
24 | static struct map_info h720x_map = { | |
25 | .name = "H720X", | |
26 | .bankwidth = 4, | |
d9a682a5 RK |
27 | .size = H720X_FLASH_SIZE, |
28 | .phys = H720X_FLASH_PHYS, | |
1da177e4 LT |
29 | }; |
30 | ||
31 | static struct mtd_partition h720x_partitions[] = { | |
32 | { | |
33 | .name = "ArMon", | |
34 | .size = 0x00080000, | |
35 | .offset = 0, | |
36 | .mask_flags = MTD_WRITEABLE | |
37 | },{ | |
38 | .name = "Env", | |
39 | .size = 0x00040000, | |
40 | .offset = 0x00080000, | |
41 | .mask_flags = MTD_WRITEABLE | |
42 | },{ | |
43 | .name = "Kernel", | |
44 | .size = 0x00180000, | |
45 | .offset = 0x000c0000, | |
46 | .mask_flags = MTD_WRITEABLE | |
47 | },{ | |
48 | .name = "Ramdisk", | |
49 | .size = 0x00400000, | |
50 | .offset = 0x00240000, | |
51 | .mask_flags = MTD_WRITEABLE | |
52 | },{ | |
53 | .name = "jffs2", | |
54 | .size = MTDPART_SIZ_FULL, | |
55 | .offset = MTDPART_OFS_APPEND | |
56 | } | |
57 | }; | |
58 | ||
87d10f3c | 59 | #define NUM_PARTITIONS ARRAY_SIZE(h720x_partitions) |
1da177e4 LT |
60 | |
61 | static int nr_mtd_parts; | |
62 | static struct mtd_partition *mtd_parts; | |
1da177e4 LT |
63 | /* |
64 | * Initialize FLASH support | |
65 | */ | |
2257594f | 66 | static int __init h720x_mtd_init(void) |
1da177e4 LT |
67 | { |
68 | ||
69 | char *part_type = NULL; | |
69f34c98 | 70 | |
d9a682a5 | 71 | h720x_map.virt = ioremap(h720x_map.phys, h720x_map.size); |
1da177e4 LT |
72 | |
73 | if (!h720x_map.virt) { | |
74 | printk(KERN_ERR "H720x-MTD: ioremap failed\n"); | |
75 | return -EIO; | |
76 | } | |
77 | ||
78 | simple_map_init(&h720x_map); | |
79 | ||
80 | // Probe for flash bankwidth 4 | |
81 | printk (KERN_INFO "H720x-MTD probing 32bit FLASH\n"); | |
82 | mymtd = do_map_probe("cfi_probe", &h720x_map); | |
83 | if (!mymtd) { | |
84 | printk (KERN_INFO "H720x-MTD probing 16bit FLASH\n"); | |
85 | // Probe for bankwidth 2 | |
86 | h720x_map.bankwidth = 2; | |
87 | mymtd = do_map_probe("cfi_probe", &h720x_map); | |
88 | } | |
69f34c98 | 89 | |
1da177e4 LT |
90 | if (mymtd) { |
91 | mymtd->owner = THIS_MODULE; | |
92 | ||
3af035c9 | 93 | nr_mtd_parts = parse_mtd_partitions(mymtd, NULL, &mtd_parts, 0); |
1da177e4 LT |
94 | if (nr_mtd_parts > 0) |
95 | part_type = "command line"; | |
1da177e4 LT |
96 | if (nr_mtd_parts <= 0) { |
97 | mtd_parts = h720x_partitions; | |
98 | nr_mtd_parts = NUM_PARTITIONS; | |
99 | part_type = "builtin"; | |
100 | } | |
101 | printk(KERN_INFO "Using %s partition table\n", part_type); | |
360e40ae | 102 | mtd_device_register(mymtd, mtd_parts, nr_mtd_parts); |
1da177e4 LT |
103 | return 0; |
104 | } | |
105 | ||
106 | iounmap((void *)h720x_map.virt); | |
107 | return -ENXIO; | |
108 | } | |
109 | ||
110 | /* | |
111 | * Cleanup | |
112 | */ | |
113 | static void __exit h720x_mtd_cleanup(void) | |
114 | { | |
115 | ||
116 | if (mymtd) { | |
360e40ae | 117 | mtd_device_unregister(mymtd); |
1da177e4 LT |
118 | map_destroy(mymtd); |
119 | } | |
69f34c98 | 120 | |
1da177e4 LT |
121 | /* Free partition info, if commandline partition was used */ |
122 | if (mtd_parts && (mtd_parts != h720x_partitions)) | |
123 | kfree (mtd_parts); | |
69f34c98 | 124 | |
1da177e4 LT |
125 | if (h720x_map.virt) { |
126 | iounmap((void *)h720x_map.virt); | |
127 | h720x_map.virt = 0; | |
128 | } | |
129 | } | |
130 | ||
131 | ||
132 | module_init(h720x_mtd_init); | |
133 | module_exit(h720x_mtd_cleanup); | |
134 | ||
135 | MODULE_LICENSE("GPL"); | |
136 | MODULE_AUTHOR("Thomas Gleixner <tglx@linutronix.de>"); | |
137 | MODULE_DESCRIPTION("MTD map driver for Hynix evaluation boards"); |