1 /* fortunet.c memory map
5 #include <linux/module.h>
6 #include <linux/types.h>
7 #include <linux/kernel.h>
8 #include <linux/init.h>
9 #include <linux/string.h>
11 #include <linux/mtd/mtd.h>
12 #include <linux/mtd/map.h>
13 #include <linux/mtd/partitions.h>
17 #define MAX_NUM_REGIONS 4
18 #define MAX_NUM_PARTITIONS 8
20 #define DEF_WINDOW_ADDR_PHY 0x00000000
21 #define DEF_WINDOW_SIZE 0x00800000 // 8 Mega Bytes
23 #define MTD_FORTUNET_PK "MTD FortuNet: "
25 #define MAX_NAME_SIZE 128
29 int window_addr_physical;
31 struct map_info map_info;
32 struct mtd_info *mymtd;
33 struct mtd_partition parts[MAX_NUM_PARTITIONS];
34 char map_name[MAX_NAME_SIZE];
35 char parts_name[MAX_NUM_PARTITIONS][MAX_NAME_SIZE];
38 static struct map_region map_regions[MAX_NUM_REGIONS];
39 static int map_regions_set[MAX_NUM_REGIONS] = {0,0,0,0};
40 static int map_regions_parts[MAX_NUM_REGIONS] = {0,0,0,0};
44 struct map_info default_map = {
45 .size = DEF_WINDOW_SIZE,
49 static char * __init get_string_option(char *dest,int dest_size,char *sor)
99 static int __init MTD_New_Region(char *line)
101 char string[MAX_NAME_SIZE];
103 get_options (get_string_option(string,sizeof(string),line),6,params);
106 printk(MTD_FORTUNET_PK "Bad parameters for MTD Region "
107 " name,region-number[,base,size,bankwidth,altbankwidth]\n");
110 if((params[1]<0)||(params[1]>=MAX_NUM_REGIONS))
112 printk(MTD_FORTUNET_PK "Bad region index of %d only have 0..%u regions\n",
113 params[1],MAX_NUM_REGIONS-1);
116 memset(&map_regions[params[1]],0,sizeof(map_regions[params[1]]));
117 memcpy(&map_regions[params[1]].map_info,
118 &default_map,sizeof(map_regions[params[1]].map_info));
119 map_regions_set[params[1]] = 1;
120 map_regions[params[1]].window_addr_physical = DEF_WINDOW_ADDR_PHY;
121 map_regions[params[1]].altbankwidth = 2;
122 map_regions[params[1]].mymtd = NULL;
123 map_regions[params[1]].map_info.name = map_regions[params[1]].map_name;
124 strcpy(map_regions[params[1]].map_info.name,string);
127 map_regions[params[1]].window_addr_physical = params[2];
131 map_regions[params[1]].map_info.size = params[3];
135 map_regions[params[1]].map_info.bankwidth = params[4];
139 map_regions[params[1]].altbankwidth = params[5];
144 static int __init MTD_New_Partition(char *line)
146 char string[MAX_NAME_SIZE];
148 get_options (get_string_option(string,sizeof(string),line),4,params);
151 printk(MTD_FORTUNET_PK "Bad parameters for MTD Partition "
152 " name,region-number,size,offset\n");
155 if((params[1]<0)||(params[1]>=MAX_NUM_REGIONS))
157 printk(MTD_FORTUNET_PK "Bad region index of %d only have 0..%u regions\n",
158 params[1],MAX_NUM_REGIONS-1);
161 if(map_regions_parts[params[1]]>=MAX_NUM_PARTITIONS)
163 printk(MTD_FORTUNET_PK "Out of space for partition in this region\n");
166 map_regions[params[1]].parts[map_regions_parts[params[1]]].name =
167 map_regions[params[1]]. parts_name[map_regions_parts[params[1]]];
168 strcpy(map_regions[params[1]].parts[map_regions_parts[params[1]]].name,string);
169 map_regions[params[1]].parts[map_regions_parts[params[1]]].size =
171 map_regions[params[1]].parts[map_regions_parts[params[1]]].offset =
173 map_regions[params[1]].parts[map_regions_parts[params[1]]].mask_flags = 0;
174 map_regions_parts[params[1]]++;
178 __setup("MTD_Region=", MTD_New_Region);
179 __setup("MTD_Partition=", MTD_New_Partition);
181 /* Backwards-spelling-compatibility */
182 __setup("MTD_Partion=", MTD_New_Partition);
184 static int __init init_fortunet(void)
187 for(iy=ix=0;ix<MAX_NUM_REGIONS;ix++)
189 if(map_regions_parts[ix]&&(!map_regions_set[ix]))
191 printk(MTD_FORTUNET_PK "Region %d is not setup (Setting to default)\n",
193 memset(&map_regions[ix],0,sizeof(map_regions[ix]));
194 memcpy(&map_regions[ix].map_info,&default_map,
195 sizeof(map_regions[ix].map_info));
196 map_regions_set[ix] = 1;
197 map_regions[ix].window_addr_physical = DEF_WINDOW_ADDR_PHY;
198 map_regions[ix].altbankwidth = 2;
199 map_regions[ix].mymtd = NULL;
200 map_regions[ix].map_info.name = map_regions[ix].map_name;
201 strcpy(map_regions[ix].map_info.name,"FORTUNET");
203 if(map_regions_set[ix])
206 printk(KERN_NOTICE MTD_FORTUNET_PK "%s flash device at physically "
207 " address %x size %x\n",
208 map_regions[ix].map_info.name,
209 map_regions[ix].window_addr_physical,
210 map_regions[ix].map_info.size);
212 map_regions[ix].map_info.phys = map_regions[ix].window_addr_physical,
214 map_regions[ix].map_info.virt =
216 map_regions[ix].window_addr_physical,
217 map_regions[ix].map_info.size);
218 if(!map_regions[ix].map_info.virt)
221 printk(MTD_FORTUNET_PK "%s flash failed to ioremap!\n",
222 map_regions[ix].map_info.name);
223 for (j = 0 ; j < ix; j++)
224 iounmap(map_regions[j].map_info.virt);
227 simple_map_init(&map_regions[ix].map_info);
229 printk(KERN_NOTICE MTD_FORTUNET_PK "%s flash is virtually at: %x\n",
230 map_regions[ix].map_info.name,
231 map_regions[ix].map_info.virt);
232 map_regions[ix].mymtd = do_map_probe("cfi_probe",
233 &map_regions[ix].map_info);
234 if((!map_regions[ix].mymtd)&&(
235 map_regions[ix].altbankwidth!=map_regions[ix].map_info.bankwidth))
237 printk(KERN_NOTICE MTD_FORTUNET_PK "Trying alternate bankwidth "
239 map_regions[ix].map_info.name);
240 map_regions[ix].map_info.bankwidth =
241 map_regions[ix].altbankwidth;
242 map_regions[ix].mymtd = do_map_probe("cfi_probe",
243 &map_regions[ix].map_info);
245 map_regions[ix].mymtd->owner = THIS_MODULE;
246 add_mtd_partitions(map_regions[ix].mymtd,
247 map_regions[ix].parts,map_regions_parts[ix]);
255 static void __exit cleanup_fortunet(void)
258 for(ix=0;ix<MAX_NUM_REGIONS;ix++)
260 if(map_regions_set[ix])
262 if( map_regions[ix].mymtd )
264 del_mtd_partitions( map_regions[ix].mymtd );
265 map_destroy( map_regions[ix].mymtd );
267 iounmap((void *)map_regions[ix].map_info.virt);
272 module_init(init_fortunet);
273 module_exit(cleanup_fortunet);
275 MODULE_AUTHOR("FortuNet, Inc.");
276 MODULE_DESCRIPTION("MTD map driver for FortuNet boards");