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