special usb hub handling, IDE disks, and retries all over the place
[linux-2.4.git] / drivers / mtd / maps / dbox2-flash.c
1 /*
2  * $Id: dbox2-flash.c,v 1.4 2001/10/02 15:05:14 dwmw2 Exp $
3  *
4  * Nokia / Sagem D-Box 2 flash driver
5  */
6
7 #include <linux/module.h>
8 #include <linux/types.h>
9 #include <linux/kernel.h>
10 #include <asm/io.h>
11 #include <linux/mtd/mtd.h>
12 #include <linux/mtd/map.h>
13 #include <linux/mtd/partitions.h>
14 #include <linux/config.h>
15
16 /* partition_info gives details on the logical partitions that the split the
17  * single flash device into. If the size if zero we use up to the end of the
18  * device. */
19 static struct mtd_partition partition_info[]= {{name: "BR bootloader",          // raw
20                                                       size: 128 * 1024, 
21                                                       offset: 0,                  
22                                                       mask_flags: MTD_WRITEABLE},
23                                                      {name: "PPC bootloader",           // flfs
24                                                       size: 128 * 1024, 
25                                                       offset: MTDPART_OFS_APPEND, 
26                                                       mask_flags: 0},
27                                                      {name: "Kernel",                   // idxfs
28                                                       size: 768 * 1024, 
29                                                       offset: MTDPART_OFS_APPEND, 
30                                                       mask_flags: 0},
31                                                      {name: "System",                   // jffs
32                                                       size: MTDPART_SIZ_FULL, 
33                                                       offset: MTDPART_OFS_APPEND, 
34                                                       mask_flags: 0}};
35
36 #define NUM_PARTITIONS (sizeof(partition_info) / sizeof(partition_info[0]))
37
38 #define WINDOW_ADDR 0x10000000
39 #define WINDOW_SIZE 0x800000
40
41 static struct mtd_info *mymtd;
42
43 __u8 dbox2_flash_read8(struct map_info *map, unsigned long ofs)
44 {
45         return __raw_readb(map->map_priv_1 + ofs);
46 }
47
48 __u16 dbox2_flash_read16(struct map_info *map, unsigned long ofs)
49 {
50         return __raw_readw(map->map_priv_1 + ofs);
51 }
52
53 __u32 dbox2_flash_read32(struct map_info *map, unsigned long ofs)
54 {
55         return __raw_readl(map->map_priv_1 + ofs);
56 }
57
58 void dbox2_flash_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
59 {
60         memcpy_fromio(to, map->map_priv_1 + from, len);
61 }
62
63 void dbox2_flash_write8(struct map_info *map, __u8 d, unsigned long adr)
64 {
65         __raw_writeb(d, map->map_priv_1 + adr);
66         mb();
67 }
68
69 void dbox2_flash_write16(struct map_info *map, __u16 d, unsigned long adr)
70 {
71         __raw_writew(d, map->map_priv_1 + adr);
72         mb();
73 }
74
75 void dbox2_flash_write32(struct map_info *map, __u32 d, unsigned long adr)
76 {
77         __raw_writel(d, map->map_priv_1 + adr);
78         mb();
79 }
80
81 void dbox2_flash_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
82 {
83         memcpy_toio(map->map_priv_1 + to, from, len);
84 }
85
86 struct map_info dbox2_flash_map = {
87         name: "D-Box 2 flash memory",
88         size: WINDOW_SIZE,
89         buswidth: 4,
90         read8: dbox2_flash_read8,
91         read16: dbox2_flash_read16,
92         read32: dbox2_flash_read32,
93         copy_from: dbox2_flash_copy_from,
94         write8: dbox2_flash_write8,
95         write16: dbox2_flash_write16,
96         write32: dbox2_flash_write32,
97         copy_to: dbox2_flash_copy_to
98 };
99
100 int __init init_dbox2_flash(void)
101 {
102         printk(KERN_NOTICE "D-Box 2 flash driver (size->0x%X mem->0x%X)\n", WINDOW_SIZE, WINDOW_ADDR);
103         dbox2_flash_map.map_priv_1 = (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
104
105         if (!dbox2_flash_map.map_priv_1) {
106                 printk("Failed to ioremap\n");
107                 return -EIO;
108         }
109
110         // Probe for dual Intel 28F320 or dual AMD
111         mymtd = do_map_probe("cfi_probe", &dbox2_flash_map);
112         if (!mymtd) {
113             // Probe for single Intel 28F640
114             dbox2_flash_map.buswidth = 2;
115         
116             mymtd = do_map_probe("cfi_probe", &dbox2_flash_map);
117         }
118             
119         if (mymtd) {
120                 mymtd->module = THIS_MODULE;
121
122                 /* Create MTD devices for each partition. */
123                 add_mtd_partitions(mymtd, partition_info, NUM_PARTITIONS);
124                 
125                 return 0;
126         }
127
128         iounmap((void *)dbox2_flash_map.map_priv_1);
129         return -ENXIO;
130 }
131
132 static void __exit cleanup_dbox2_flash(void)
133 {
134         if (mymtd) {
135                 del_mtd_partitions(mymtd);
136                 map_destroy(mymtd);
137         }
138         if (dbox2_flash_map.map_priv_1) {
139                 iounmap((void *)dbox2_flash_map.map_priv_1);
140                 dbox2_flash_map.map_priv_1 = 0;
141         }
142 }
143
144 module_init(init_dbox2_flash);
145 module_exit(cleanup_dbox2_flash);
146
147
148 MODULE_LICENSE("GPL");
149 MODULE_AUTHOR("Kári Davíðsson <kd@flaga.is>");
150 MODULE_DESCRIPTION("MTD map driver for Nokia/Sagem D-Box 2 board");