2 * Handle mapping of the flash memory access routines
3 * on TQM8xxL based devices.
5 * $Id: tqm8xxl.c,v 1.13 2004/10/20 22:21:53 dwmw2 Exp $
9 * Copyright(C) 2001 Kirk Lee <kirk@hpc.ee.ntu.edu.tw>
16 * According to TQM8xxL hardware manual, TQM8xxL series have
17 * following flash memory organisations:
18 * | capacity | | chip type | | bank0 | | bank1 |
21 * 8MiB 1Mx16 4MiB 4MiB
22 * Thus, we choose CONFIG_MTD_CFI_I2 & CONFIG_MTD_CFI_B4 at
23 * kernel configuration.
25 #include <linux/config.h>
26 #include <linux/module.h>
27 #include <linux/types.h>
28 #include <linux/kernel.h>
29 #include <linux/init.h>
30 #include <linux/slab.h>
32 #include <linux/mtd/mtd.h>
33 #include <linux/mtd/map.h>
34 #include <linux/mtd/partitions.h>
38 #define FLASH_ADDR 0x40000000
39 #define FLASH_SIZE 0x00800000
40 #define FLASH_BANK_MAX 4
42 // trivial struct to describe partition information
47 struct mtd_partition
* mtd_part
;
50 //static struct mtd_info *mymtd;
51 static struct mtd_info
* mtd_banks
[FLASH_BANK_MAX
];
52 static struct map_info
* map_banks
[FLASH_BANK_MAX
];
53 static struct mtd_part_def part_banks
[FLASH_BANK_MAX
];
54 static unsigned long num_banks
;
55 static void __iomem
*start_scan_addr
;
58 * Here are partition information for all known TQM8xxL series devices.
59 * See include/linux/mtd/partitions.h for definition of the mtd_partition
62 * The *_max_flash_size is the maximum possible mapped flash size which
63 * is not necessarily the actual flash size. It must correspond to the
64 * value specified in the mapping definition defined by the
65 * "struct map_desc *_io_desc" for the corresponding machine.
68 #ifdef CONFIG_MTD_PARTITIONS
69 /* Currently, TQM8xxL has upto 8MiB flash */
70 static unsigned long tqm8xxl_max_flash_size
= 0x00800000;
72 /* partition definition for first flash bank
73 * (cf. "drivers/char/flash_config.c")
75 static struct mtd_partition tqm8xxl_partitions
[] = {
79 .size
= 0x00020000, /* 128KB */
80 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
83 .name
= "kernel", /* default kernel image */
86 .mask_flags
= MTD_WRITEABLE
, /* force read-only */
99 /* partition definition for second flash bank */
100 static struct mtd_partition tqm8xxl_fs_partitions
[] = {
103 .offset
= 0x00000000,
108 .offset
= 0x00200000,
110 //.size = MTDPART_SIZ_FULL,
115 int __init
init_tqm_mtd(void)
117 int idx
= 0, ret
= 0;
118 unsigned long flash_addr
, flash_size
, mtd_size
= 0;
119 /* pointer to TQM8xxL board info data */
120 bd_t
*bd
= (bd_t
*)__res
;
122 flash_addr
= bd
->bi_flashstart
;
123 flash_size
= bd
->bi_flashsize
;
125 //request maximum flash size address space
126 start_scan_addr
= ioremap(flash_addr
, flash_size
);
127 if (!start_scan_addr
) {
128 printk(KERN_WARNING
"%s:Failed to ioremap address:0x%x\n", __FUNCTION__
, flash_addr
);
132 for (idx
= 0 ; idx
< FLASH_BANK_MAX
; idx
++) {
133 if(mtd_size
>= flash_size
)
136 printk(KERN_INFO
"%s: chip probing count %d\n", __FUNCTION__
, idx
);
138 map_banks
[idx
] = (struct map_info
*)kmalloc(sizeof(struct map_info
), GFP_KERNEL
);
139 if(map_banks
[idx
] == NULL
) {
141 /* FIXME: What if some MTD devices were probed already? */
145 memset((void *)map_banks
[idx
], 0, sizeof(struct map_info
));
146 map_banks
[idx
]->name
= (char *)kmalloc(16, GFP_KERNEL
);
148 if (!map_banks
[idx
]->name
) {
150 /* FIXME: What if some MTD devices were probed already? */
153 sprintf(map_banks
[idx
]->name
, "TQM8xxL%d", idx
);
155 map_banks
[idx
]->size
= flash_size
;
156 map_banks
[idx
]->bankwidth
= 4;
158 simple_map_init(map_banks
[idx
]);
160 map_banks
[idx
]->virt
= start_scan_addr
;
161 map_banks
[idx
]->phys
= flash_addr
;
162 /* FIXME: This looks utterly bogus, but I'm trying to
163 preserve the behaviour of the original (shown here)...
165 map_banks[idx]->map_priv_1 =
166 start_scan_addr + ((idx > 0) ?
167 (mtd_banks[idx-1] ? mtd_banks[idx-1]->size : 0) : 0);
170 if (idx
&& mtd_banks
[idx
-1]) {
171 map_banks
[idx
]->virt
+= mtd_banks
[idx
-1]->size
;
172 map_banks
[idx
]->phys
+= mtd_banks
[idx
-1]->size
;
175 //start to probe flash chips
176 mtd_banks
[idx
] = do_map_probe("cfi_probe", map_banks
[idx
]);
178 if (mtd_banks
[idx
]) {
179 mtd_banks
[idx
]->owner
= THIS_MODULE
;
180 mtd_size
+= mtd_banks
[idx
]->size
;
183 printk(KERN_INFO
"%s: bank%d, name:%s, size:%dbytes \n", __FUNCTION__
, num_banks
,
184 mtd_banks
[idx
]->name
, mtd_banks
[idx
]->size
);
188 /* no supported flash chips found */
190 printk(KERN_NOTICE
"TQM8xxL: No support flash chips found!\n");
195 #ifdef CONFIG_MTD_PARTITIONS
197 * Select Static partition definitions
199 part_banks
[0].mtd_part
= tqm8xxl_partitions
;
200 part_banks
[0].type
= "Static image";
201 part_banks
[0].nums
= ARRAY_SIZE(tqm8xxl_partitions
);
203 part_banks
[1].mtd_part
= tqm8xxl_fs_partitions
;
204 part_banks
[1].type
= "Static file system";
205 part_banks
[1].nums
= ARRAY_SIZE(tqm8xxl_fs_partitions
);
207 for(idx
= 0; idx
< num_banks
; idx
++) {
208 if (part_banks
[idx
].nums
== 0) {
209 printk(KERN_NOTICE
"TQM flash%d: no partition info available, registering whole flash at once\n", idx
);
210 add_mtd_device(mtd_banks
[idx
]);
212 printk(KERN_NOTICE
"TQM flash%d: Using %s partition definition\n",
213 idx
, part_banks
[idx
].type
);
214 add_mtd_partitions(mtd_banks
[idx
], part_banks
[idx
].mtd_part
,
215 part_banks
[idx
].nums
);
219 printk(KERN_NOTICE
"TQM flash: registering %d whole flash banks at once\n", num_banks
);
220 for(idx
= 0 ; idx
< num_banks
; idx
++)
221 add_mtd_device(mtd_banks
[idx
]);
225 for(idx
= 0 ; idx
< FLASH_BANK_MAX
; idx
++) {
226 if(map_banks
[idx
] != NULL
) {
227 kfree(map_banks
[idx
]->name
);
228 map_banks
[idx
]->name
= NULL
;
229 kfree(map_banks
[idx
]);
230 map_banks
[idx
] = NULL
;
234 iounmap(start_scan_addr
);
238 static void __exit
cleanup_tqm_mtd(void)
240 unsigned int idx
= 0;
241 for(idx
= 0 ; idx
< num_banks
; idx
++) {
242 /* destroy mtd_info previously allocated */
243 if (mtd_banks
[idx
]) {
244 del_mtd_partitions(mtd_banks
[idx
]);
245 map_destroy(mtd_banks
[idx
]);
247 /* release map_info not used anymore */
248 kfree(map_banks
[idx
]->name
);
249 kfree(map_banks
[idx
]);
252 if (start_scan_addr
) {
253 iounmap(start_scan_addr
);
258 module_init(init_tqm_mtd
);
259 module_exit(cleanup_tqm_mtd
);
261 MODULE_LICENSE("GPL");
262 MODULE_AUTHOR("Kirk Lee <kirk@hpc.ee.ntu.edu.tw>");
263 MODULE_DESCRIPTION("MTD map driver for TQM8xxL boards");