setup enviroment for compilation
[linux-2.4.21-pre4.git] / drivers / mtd / maps / 79s334-flash.c
1 /*
2  * Flash memory access on IDT 79S334 boards
3  * 
4  * (C) 2001 Pete Popov <ppopov@mvista.com>
5  * 
6  * $Id: 79s334-flash.c,v 1.1.1.1 2005/04/11 02:50:26 jack Exp $
7  */
8
9 #include <linux/config.h>
10 #include <linux/module.h>
11 #include <linux/types.h>
12 #include <linux/kernel.h>
13
14 #include <linux/mtd/mtd.h>
15 #include <linux/mtd/map.h>
16 #include <linux/mtd/partitions.h>
17
18 #include <asm/io.h>
19 //#include <asm/au1000.h>
20
21 #ifdef  DEBUG_RW
22 #define DBG(x...)       printk(x)
23 #else
24 #define DBG(x...)       
25 #endif
26
27 #define WINDOW_ADDR 0x1FC00000
28 #define WINDOW_SIZE 0x400000
29
30 __u8 physmap_read8(struct map_info *map, unsigned long ofs)
31 {
32         __u8 ret;
33         ret = readb(map->map_priv_1 + ofs);
34         DBG("read8 from %x, %x\n", (unsigned)(map->map_priv_1 + ofs), ret);
35         return ret;
36 }
37
38 __u16 physmap_read16(struct map_info *map, unsigned long ofs)
39 {
40         __u16 ret;
41         ret = readw(map->map_priv_1 + ofs);
42         DBG("read16 from %x, %x\n", (unsigned)(map->map_priv_1 + ofs), ret);
43         return ret;
44 }
45
46 __u32 physmap_read32(struct map_info *map, unsigned long ofs)
47 {
48         __u32 ret;
49         ret = readl(map->map_priv_1 + ofs);
50         DBG("read32 from %x, %x\n", (unsigned)(map->map_priv_1 + ofs), ret);
51         return ret;
52 }
53
54 void physmap_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
55 {
56         DBG("physmap_copy from %x to %x\n", (unsigned)from, (unsigned)to);
57         memcpy_fromio(to, map->map_priv_1 + from, len);
58 }
59
60 void physmap_write8(struct map_info *map, __u8 d, unsigned long adr)
61 {
62         DBG("write8 at %x, %x\n", (unsigned)(map->map_priv_1 + adr), d);
63         writeb(d, map->map_priv_1 + adr);
64         mb();
65 }
66
67 void physmap_write16(struct map_info *map, __u16 d, unsigned long adr)
68 {
69         DBG("write16 at %x, %x\n", (unsigned)(map->map_priv_1 + adr), d);
70         writew(d, map->map_priv_1 + adr);
71         mb();
72 }
73
74 void physmap_write32(struct map_info *map, __u32 d, unsigned long adr)
75 {
76         DBG("write32 at %x, %x\n", (unsigned)(map->map_priv_1 + adr), d);
77         writel(d, map->map_priv_1 + adr);
78         mb();
79 }
80
81 void physmap_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
82 {
83         DBG("physmap_copy_to %x from %x\n", (unsigned)to, (unsigned)from);
84         memcpy_toio(map->map_priv_1 + to, from, len);
85 }
86
87
88
89 static struct map_info idt79s334_map = {
90         name:           "idt79s334 flash",
91         read8:          physmap_read8,
92         read16:         physmap_read16,
93         read32:         physmap_read32,
94         copy_from:      physmap_copy_from,
95         write8:         physmap_write8,
96         write16:        physmap_write16,
97         write32:        physmap_write32,
98         copy_to:        physmap_copy_to,
99
100         //map_priv_1:     WINDOW_ADDR,   
101 };
102
103
104 static unsigned long flash_size = 0x00400000;
105 static unsigned char flash_buswidth = 2;
106 static struct mtd_partition idt79s334_partitions[] = {
107         {
108                 name: "jmp BIOS",
109                 size: 0x00002000,
110                 offset: 0,
111         },{ 
112                 name: "SIM",
113                 size: 0x00002000,
114                 offset: 0x00002000,
115                 mask_flags: MTD_WRITEABLE
116         },{
117                 name: "reserved 1",
118                 size: 0x00002000,
119                 offset: 0x00004000,
120         },{
121                 name: "reserved 2",
122                 size: 0x00002000,
123                 offset: 0x00006000,
124         },{
125                 name: "reserved 3",
126                 size: 0x00002000,
127                 offset: 0x00008000,
128         },{
129                 name: "reserved 4",
130                 size: 0x00002000,
131                 offset: 0x0000a000,
132         },{
133                 name: "reserved 5",
134                 size: 0x00002000,
135                 offset: 0x0000c000,
136         },{
137                 name: "reserved 6",
138                 size: 0x00002000,
139                 offset: 0x0000e000,
140         },{
141                 name: "BIOS",
142                 size: 0x00010000,
143                 offset: 0x00010000,
144         },{
145                 name: "POST",
146                 size: 0x00040000,
147                 offset: 0x00020000,
148         },{
149                 name: "ETC",
150                 size: 0x00040000,
151                 offset: 0x00060000,
152         },{
153                 name: "firmware",
154                 size: 0x00360000,
155                 offset: 0x000a0000,
156         }
157 };
158
159
160 #define NB_OF(x)  (sizeof(x)/sizeof(x[0]))
161
162 static struct mtd_partition *parsed_parts;
163 static struct mtd_info *mymtd;
164
165 int __init idt79s334_mtd_init(void)
166 {
167         struct mtd_partition *parts;
168         int nb_parts = 0;
169         char *part_type;
170         
171         /* Default flash buswidth */
172         idt79s334_map.buswidth = flash_buswidth;
173
174         /*
175          * Static partition definition selection
176          */
177         part_type = "static";
178         parts = idt79s334_partitions;
179         nb_parts = NB_OF(idt79s334_partitions);
180         idt79s334_map.size = flash_size;
181
182         /*
183          * Now let's probe for the actual flash.  Do it here since
184          * specific machine settings might have been set above.
185          */
186         printk(KERN_NOTICE "idt79s334 flash: probing %d-bit flash bus\n", 
187                         idt79s334_map.buswidth*8);
188         idt79s334_map.map_priv_1 = 
189                 (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
190         mymtd = do_map_probe("cfi_probe", &idt79s334_map);
191         if (!mymtd) return -ENXIO;
192         mymtd->module = THIS_MODULE;
193
194         add_mtd_partitions(mymtd, parts, nb_parts);
195         return 0;
196 }
197
198 static void __exit idt79s334_mtd_cleanup(void)
199 {
200         if (mymtd) {
201                 del_mtd_partitions(mymtd);
202                 map_destroy(mymtd);
203                 if (parsed_parts)
204                         kfree(parsed_parts);
205         }
206 }
207
208 module_init(idt79s334_mtd_init);
209 module_exit(idt79s334_mtd_cleanup);
210
211 MODULE_AUTHOR("Pete Popov");
212 MODULE_DESCRIPTION("idt79s334 CFI map driver");
213 MODULE_LICENSE("GPL");