added mtd driver
[linux-2.4.git] / drivers / mtd / maps / usi-flash.c
1 /*
2  * Flash memory access on IDT 79S334 boards
3  * 
4  * (C) 2001 Pete Popov <ppopov@mvista.com>
5  * 
6  * $Id: usi-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 //jackl
28 //#define WINDOW_ADDR 0xFF800000
29 //#define WINDOW_SIZE 0x800000
30 #define WINDOW_ADDR 0xFFC00000
31 #define WINDOW_SIZE 0x400000
32
33 __u8 physmap_read8(struct map_info *map, unsigned long ofs)
34 {
35         __u8 ret;
36         ret = readb(map->map_priv_1 + ofs);
37         DBG("read8 from %x, %x\n", (unsigned)(map->map_priv_1 + ofs), ret);
38         return ret;
39 }
40
41 __u16 physmap_read16(struct map_info *map, unsigned long ofs)
42 {
43         __u16 ret;
44         ret = readw(map->map_priv_1 + ofs);
45         DBG("read16 from %x, %x\n", (unsigned)(map->map_priv_1 + ofs), ret);
46         return ret;
47 }
48
49 __u32 physmap_read32(struct map_info *map, unsigned long ofs)
50 {
51         __u32 ret;
52         ret = readl(map->map_priv_1 + ofs);
53         DBG("read32 from %x, %x\n", (unsigned)(map->map_priv_1 + ofs), ret);
54         return ret;
55 }
56
57 void physmap_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len)
58 {
59         DBG("physmap_copy from %x to %x\n", (unsigned)from, (unsigned)to);
60         memcpy_fromio(to, map->map_priv_1 + from, len);
61 }
62
63 void physmap_write8(struct map_info *map, __u8 d, unsigned long adr)
64 {
65         DBG("write8 at %x, %x\n", (unsigned)(map->map_priv_1 + adr), d);
66         writeb(d, map->map_priv_1 + adr);
67         mb();
68 }
69
70 void physmap_write16(struct map_info *map, __u16 d, unsigned long adr)
71 {
72         DBG("write16 at %x, %x\n", (unsigned)(map->map_priv_1 + adr), d);
73         writew(d, map->map_priv_1 + adr);
74         mb();
75 }
76
77 void physmap_write32(struct map_info *map, __u32 d, unsigned long adr)
78 {
79         DBG("write32 at %x, %x\n", (unsigned)(map->map_priv_1 + adr), d);
80         writel(d, map->map_priv_1 + adr);
81         mb();
82 }
83
84 void physmap_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len)
85 {
86         DBG("physmap_copy_to %x from %x\n", (unsigned)to, (unsigned)from);
87         memcpy_toio(map->map_priv_1 + to, from, len);
88 }
89
90
91
92 static struct map_info usi_map = {
93         name:           "USI Intel flash",
94         read8:          physmap_read8,
95         read16:         physmap_read16,
96         read32:         physmap_read32,
97         copy_from:      physmap_copy_from,
98         write8:         physmap_write8,
99         write16:        physmap_write16,
100         write32:        physmap_write32,
101         copy_to:        physmap_copy_to,
102
103         //map_priv_1:     WINDOW_ADDR,   
104 };
105
106 //jackl
107 //static unsigned long flash_size = 0x00800000;
108 static unsigned long flash_size = 0x00400000;
109
110 static unsigned char flash_buswidth = 1;
111 //static struct mtd_partition usi_partitions[] = {
112 //        {
113 //                name: "Linux Kernel",
114 //                size: 0x00100000,
115 //                offset: 0,
116 //        },{ 
117 //                name: "Linux Ramdisk",
118 //                size: 0x00600000,
119 //                offset: 0x00100000,
120 //        },{               
121 //              name: "U-BOOT BOOT LOADER",
122 //                size: 0x00040000,
123 //                offset: 0x00700000,
124 //        },{               
125 //              name: "ETC",
126 //                size: 0x000C0000,
127 //                offset: 0x00740000,
128 //       }
129 //};
130
131 static struct mtd_partition usi_partitions[] = {
132         {
133                 name: "Linux mtd1",
134                 size: 0x00010000,
135                 offset: 0,
136         },{ 
137                 name: "Linux mtd2",
138                 size: 0x00010000,
139                 offset: 0x00010000,
140         },{
141                         name: "Linux Ramdisk",
142                 size: 0x002e0000,
143                 offset: 0x00020000,
144         },{
145                 name: "U-BOOT BOOT LOADER",
146                 size: 0x00010000,
147                 offset: 0x00300000,
148         },{               
149                 name: "Linux Kernel",
150                 size: 0x000f0000,
151                 offset: 0x00310000,
152        }
153 };
154
155 #define NB_OF(x)  (sizeof(x)/sizeof(x[0]))
156
157 static struct mtd_partition *parsed_parts;
158 static struct mtd_info *mymtd;
159
160 int __init usi_mtd_init(void)
161 {
162         struct mtd_partition *parts;
163         int nb_parts = 0;
164         char *part_type;
165         
166         /* Default flash buswidth */
167         usi_map.buswidth = flash_buswidth;
168
169         /*
170          * Static partition definition selection
171          */
172         part_type = "static";
173         parts = usi_partitions;
174         nb_parts = NB_OF(usi_partitions);
175         usi_map.size = flash_size;
176
177         /*
178          * Now let's probe for the actual flash.  Do it here since
179          * specific machine settings might have been set above.
180          */
181         printk(KERN_NOTICE "USI AMD/FUJITSU flash: probing %d-bit flash bus\n", 
182                         usi_map.buswidth*8);
183         usi_map.map_priv_1 = 
184                 (unsigned long)ioremap(WINDOW_ADDR, WINDOW_SIZE);
185         mymtd = do_map_probe("cfi_probe", &usi_map);
186         if (!mymtd) return -ENXIO;
187         mymtd->module = THIS_MODULE;
188
189         add_mtd_partitions(mymtd, parts, nb_parts);
190         return 0;
191 }
192
193 static void __exit usi_mtd_cleanup(void)
194 {
195         if (mymtd) {
196                 del_mtd_partitions(mymtd);
197                 map_destroy(mymtd);
198                 if (parsed_parts)
199                         kfree(parsed_parts);
200         }
201 }
202
203 module_init(usi_mtd_init);
204 module_exit(usi_mtd_cleanup);
205
206 MODULE_AUTHOR("Pete Popov");
207 MODULE_DESCRIPTION("USI Intel CFI map driver");
208 MODULE_LICENSE("GPL");