Pull bugzilla-5452 into release branch
[sfrench/cifs-2.6.git] / drivers / mtd / maps / dbox2-flash.c
1 /*
2  * $Id: dbox2-flash.c,v 1.14 2005/11/07 11:14:26 gleixner Exp $
3  *
4  * D-Box 2 flash driver
5  */
6
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
10 #include <linux/init.h>
11 #include <asm/io.h>
12 #include <linux/mtd/mtd.h>
13 #include <linux/mtd/map.h>
14 #include <linux/mtd/partitions.h>
15 #include <linux/config.h>
16 #include <linux/errno.h>
17
18 /* partition_info gives details on the logical partitions that the split the
19  * single flash device into. If the size if zero we use up to the end of the
20  * device. */
21 static struct mtd_partition partition_info[]= {
22         {
23         .name           = "BR bootloader",
24         .size           = 128 * 1024,
25         .offset         = 0,
26         .mask_flags     = MTD_WRITEABLE
27         },
28         {
29         .name           = "FLFS (U-Boot)",
30         .size           = 128 * 1024,
31         .offset         = MTDPART_OFS_APPEND,
32         .mask_flags     = 0
33         },
34         {
35         .name           = "Root (SquashFS)",
36         .size           = 7040 * 1024,
37         .offset         = MTDPART_OFS_APPEND,
38         .mask_flags     = 0
39         },
40         {
41         .name           = "var (JFFS2)",
42         .size           = 896 * 1024,
43         .offset         = MTDPART_OFS_APPEND,
44         .mask_flags     = 0
45         },
46         {
47         .name           = "Flash without bootloader",
48         .size           = MTDPART_SIZ_FULL,
49         .offset         = 128 * 1024,
50         .mask_flags     = 0
51         },
52         {
53         .name           = "Complete Flash",
54         .size           = MTDPART_SIZ_FULL,
55         .offset         = 0,
56         .mask_flags     = MTD_WRITEABLE
57         }
58 };
59
60 #define NUM_PARTITIONS ARRAY_SIZE(partition_info)
61
62 #define WINDOW_ADDR 0x10000000
63 #define WINDOW_SIZE 0x800000
64
65 static struct mtd_info *mymtd;
66
67
68 struct map_info dbox2_flash_map = {
69         .name           = "D-Box 2 flash memory",
70         .size           = WINDOW_SIZE,
71         .bankwidth      = 4,
72         .phys           = WINDOW_ADDR,
73 };
74
75 int __init init_dbox2_flash(void)
76 {
77         printk(KERN_NOTICE "D-Box 2 flash driver (size->0x%X mem->0x%X)\n", WINDOW_SIZE, WINDOW_ADDR);
78         dbox2_flash_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE);
79
80         if (!dbox2_flash_map.virt) {
81                 printk("Failed to ioremap\n");
82                 return -EIO;
83         }
84         simple_map_init(&dbox2_flash_map);
85
86         // Probe for dual Intel 28F320 or dual AMD
87         mymtd = do_map_probe("cfi_probe", &dbox2_flash_map);
88         if (!mymtd) {
89             // Probe for single Intel 28F640
90             dbox2_flash_map.bankwidth = 2;
91
92             mymtd = do_map_probe("cfi_probe", &dbox2_flash_map);
93         }
94
95         if (mymtd) {
96                 mymtd->owner = THIS_MODULE;
97
98                 /* Create MTD devices for each partition. */
99                 add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS);
100
101                 return 0;
102         }
103
104         iounmap((void *)dbox2_flash_map.virt);
105         return -ENXIO;
106 }
107
108 static void __exit cleanup_dbox2_flash(void)
109 {
110         if (mymtd) {
111                 del_mtd_partitions(mymtd);
112                 map_destroy(mymtd);
113         }
114         if (dbox2_flash_map.virt) {
115                 iounmap((void *)dbox2_flash_map.virt);
116                 dbox2_flash_map.virt = 0;
117         }
118 }
119
120 module_init(init_dbox2_flash);
121 module_exit(cleanup_dbox2_flash);
122
123
124 MODULE_LICENSE("GPL");
125 MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>, Bastian Blank <waldi@tuxbox.org>, Alexander Wild <wild@te-elektronik.com>");
126 MODULE_DESCRIPTION("MTD map driver for D-Box 2 board");