1 /****************************************************************************/
4 * nettel.c -- mappings for NETtel/SecureEdge/SnapGear (x86) boards.
6 * (C) Copyright 2000-2001, Greg Ungerer (gerg@snapgear.com)
7 * (C) Copyright 2001-2002, SnapGear (www.snapgear.com)
9 * $Id: nettel.c,v 1.12 2005/11/29 14:30:00 gleixner Exp $
12 /****************************************************************************/
14 #include <linux/module.h>
15 #include <linux/init.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/mtd/mtd.h>
19 #include <linux/mtd/map.h>
20 #include <linux/mtd/partitions.h>
21 #include <linux/mtd/cfi.h>
22 #include <linux/reboot.h>
23 #include <linux/kdev_t.h>
24 #include <linux/root_dev.h>
27 /****************************************************************************/
29 #define INTEL_BUSWIDTH 1
30 #define AMD_WINDOW_MAXSIZE 0x00200000
31 #define AMD_BUSWIDTH 1
34 * PAR masks and shifts, assuming 64K pages.
36 #define SC520_PAR_ADDR_MASK 0x00003fff
37 #define SC520_PAR_ADDR_SHIFT 16
38 #define SC520_PAR_TO_ADDR(par) \
39 (((par)&SC520_PAR_ADDR_MASK) << SC520_PAR_ADDR_SHIFT)
41 #define SC520_PAR_SIZE_MASK 0x01ffc000
42 #define SC520_PAR_SIZE_SHIFT 2
43 #define SC520_PAR_TO_SIZE(par) \
44 ((((par)&SC520_PAR_SIZE_MASK) << SC520_PAR_SIZE_SHIFT) + (64*1024))
46 #define SC520_PAR(cs, addr, size) \
48 ((((size)-(64*1024)) >> SC520_PAR_SIZE_SHIFT) & SC520_PAR_SIZE_MASK) | \
49 (((addr) >> SC520_PAR_ADDR_SHIFT) & SC520_PAR_ADDR_MASK))
51 #define SC520_PAR_BOOTCS 0x8a000000
52 #define SC520_PAR_ROMCS1 0xaa000000
53 #define SC520_PAR_ROMCS2 0xca000000 /* Cache disabled, 64K page */
55 static void *nettel_mmcrp = NULL;
57 #ifdef CONFIG_MTD_CFI_INTELEXT
58 static struct mtd_info *intel_mtd;
60 static struct mtd_info *amd_mtd;
62 /****************************************************************************/
64 /****************************************************************************/
66 #ifdef CONFIG_MTD_CFI_INTELEXT
67 static struct map_info nettel_intel_map = {
68 .name = "SnapGear Intel",
70 .bankwidth = INTEL_BUSWIDTH,
73 static struct mtd_partition nettel_intel_partitions[] = {
75 .name = "SnapGear kernel",
80 .name = "SnapGear filesystem",
84 .name = "SnapGear config",
89 .name = "SnapGear Intel",
93 .name = "SnapGear BIOS Config",
98 .name = "SnapGear BIOS",
105 static struct map_info nettel_amd_map = {
106 .name = "SnapGear AMD",
107 .size = AMD_WINDOW_MAXSIZE,
108 .bankwidth = AMD_BUSWIDTH,
111 static struct mtd_partition nettel_amd_partitions[] = {
113 .name = "SnapGear BIOS config",
114 .offset = 0x000e0000,
118 .name = "SnapGear BIOS",
119 .offset = 0x000f0000,
123 .name = "SnapGear AMD",
127 .name = "SnapGear high BIOS",
128 .offset = 0x001f0000,
133 #define NUM_AMD_PARTITIONS ARRAY_SIZE(nettel_amd_partitions)
135 /****************************************************************************/
137 #ifdef CONFIG_MTD_CFI_INTELEXT
140 * Set the Intel flash back to read mode since some old boot
143 static int nettel_reboot_notifier(struct notifier_block *nb, unsigned long val, void *v)
145 struct cfi_private *cfi = nettel_intel_map.fldrv_priv;
148 /* Make sure all FLASH chips are put back into read mode */
149 for (b = 0; (b < nettel_intel_partitions[3].size); b += 0x100000) {
150 cfi_send_gen_cmd(0xff, 0x55, b, &nettel_intel_map, cfi,
151 cfi->device_type, NULL);
156 static struct notifier_block nettel_notifier_block = {
157 nettel_reboot_notifier, NULL, 0
161 * Erase the configuration file system.
162 * Used to support the software reset button.
164 static void nettel_erasecallback(struct erase_info *done)
166 wait_queue_head_t *wait_q = (wait_queue_head_t *)done->priv;
170 static struct erase_info nettel_erase;
172 int nettel_eraseconfig(void)
174 struct mtd_info *mtd;
175 DECLARE_WAITQUEUE(wait, current);
176 wait_queue_head_t wait_q;
179 init_waitqueue_head(&wait_q);
180 mtd = get_mtd_device(NULL, 2);
182 nettel_erase.mtd = mtd;
183 nettel_erase.callback = nettel_erasecallback;
184 nettel_erase.callback = NULL;
185 nettel_erase.addr = 0;
186 nettel_erase.len = mtd->size;
187 nettel_erase.priv = (u_long) &wait_q;
188 nettel_erase.priv = 0;
190 set_current_state(TASK_INTERRUPTIBLE);
191 add_wait_queue(&wait_q, &wait);
193 ret = mtd->erase(mtd, &nettel_erase);
195 set_current_state(TASK_RUNNING);
196 remove_wait_queue(&wait_q, &wait);
201 schedule(); /* Wait for erase to finish. */
202 remove_wait_queue(&wait_q, &wait);
212 int nettel_eraseconfig(void)
219 /****************************************************************************/
221 int __init nettel_init(void)
223 volatile unsigned long *amdpar;
224 unsigned long amdaddr, maxsize;
225 int num_amd_partitions=0;
226 #ifdef CONFIG_MTD_CFI_INTELEXT
227 volatile unsigned long *intel0par, *intel1par;
228 unsigned long orig_bootcspar, orig_romcs1par;
229 unsigned long intel0addr, intel0size;
230 unsigned long intel1addr, intel1size;
231 int intelboot, intel0cs, intel1cs;
232 int num_intel_partitions;
236 nettel_mmcrp = (void *) ioremap_nocache(0xfffef000, 4096);
237 if (nettel_mmcrp == NULL) {
238 printk("SNAPGEAR: failed to disable MMCR cache??\n");
242 /* Set CPU clock to be 33.000MHz */
243 *((unsigned char *) (nettel_mmcrp + 0xc64)) = 0x01;
245 amdpar = (volatile unsigned long *) (nettel_mmcrp + 0xc4);
247 #ifdef CONFIG_MTD_CFI_INTELEXT
249 intel0cs = SC520_PAR_ROMCS1;
250 intel0par = (volatile unsigned long *) (nettel_mmcrp + 0xc0);
251 intel1cs = SC520_PAR_ROMCS2;
252 intel1par = (volatile unsigned long *) (nettel_mmcrp + 0xbc);
255 * Save the CS settings then ensure ROMCS1 and ROMCS2 are off,
256 * otherwise they might clash with where we try to map BOOTCS.
258 orig_bootcspar = *amdpar;
259 orig_romcs1par = *intel0par;
265 * The first thing to do is determine if we have a separate
266 * boot FLASH device. Typically this is a small (1 to 2MB)
267 * AMD FLASH part. It seems that device size is about the
268 * only way to tell if this is the case...
270 amdaddr = 0x20000000;
271 maxsize = AMD_WINDOW_MAXSIZE;
273 *amdpar = SC520_PAR(SC520_PAR_BOOTCS, amdaddr, maxsize);
276 nettel_amd_map.phys = amdaddr;
277 nettel_amd_map.virt = ioremap_nocache(amdaddr, maxsize);
278 if (!nettel_amd_map.virt) {
279 printk("SNAPGEAR: failed to ioremap() BOOTCS\n");
280 iounmap(nettel_mmcrp);
283 simple_map_init(&nettel_amd_map);
285 if ((amd_mtd = do_map_probe("jedec_probe", &nettel_amd_map))) {
286 printk(KERN_NOTICE "SNAPGEAR: AMD flash device size = %dK\n",
289 amd_mtd->owner = THIS_MODULE;
291 /* The high BIOS partition is only present for 2MB units */
292 num_amd_partitions = NUM_AMD_PARTITIONS;
293 if (amd_mtd->size < AMD_WINDOW_MAXSIZE)
294 num_amd_partitions--;
295 /* Don't add the partition until after the primary INTEL's */
297 #ifdef CONFIG_MTD_CFI_INTELEXT
299 * Map the Intel flash into memory after the AMD
300 * It has to start on a multiple of maxsize.
302 maxsize = SC520_PAR_TO_SIZE(orig_romcs1par);
303 if (maxsize < (32 * 1024 * 1024))
304 maxsize = (32 * 1024 * 1024);
305 intel0addr = amdaddr + maxsize;
308 #ifdef CONFIG_MTD_CFI_INTELEXT
309 /* INTEL boot FLASH */
312 if (!orig_romcs1par) {
313 intel0cs = SC520_PAR_BOOTCS;
314 intel0par = (volatile unsigned long *)
315 (nettel_mmcrp + 0xc4);
316 intel1cs = SC520_PAR_ROMCS1;
317 intel1par = (volatile unsigned long *)
318 (nettel_mmcrp + 0xc0);
320 intel0addr = SC520_PAR_TO_ADDR(orig_bootcspar);
321 maxsize = SC520_PAR_TO_SIZE(orig_bootcspar);
323 /* Kernel base is on ROMCS1, not BOOTCS */
324 intel0cs = SC520_PAR_ROMCS1;
325 intel0par = (volatile unsigned long *)
326 (nettel_mmcrp + 0xc0);
327 intel1cs = SC520_PAR_BOOTCS;
328 intel1par = (volatile unsigned long *)
329 (nettel_mmcrp + 0xc4);
331 intel0addr = SC520_PAR_TO_ADDR(orig_romcs1par);
332 maxsize = SC520_PAR_TO_SIZE(orig_romcs1par);
335 /* Destroy useless AMD MTD mapping */
337 iounmap(nettel_amd_map.virt);
338 nettel_amd_map.virt = NULL;
340 /* Only AMD flash supported */
346 #ifdef CONFIG_MTD_CFI_INTELEXT
348 * We have determined the INTEL FLASH configuration, so lets
349 * go ahead and probe for them now.
352 /* Set PAR to the maximum size */
353 if (maxsize < (32 * 1024 * 1024))
354 maxsize = (32 * 1024 * 1024);
355 *intel0par = SC520_PAR(intel0cs, intel0addr, maxsize);
357 /* Turn other PAR off so the first probe doesn't find it */
360 /* Probe for the the size of the first Intel flash */
361 nettel_intel_map.size = maxsize;
362 nettel_intel_map.phys = intel0addr;
363 nettel_intel_map.virt = ioremap_nocache(intel0addr, maxsize);
364 if (!nettel_intel_map.virt) {
365 printk("SNAPGEAR: failed to ioremap() ROMCS1\n");
369 simple_map_init(&nettel_intel_map);
371 intel_mtd = do_map_probe("cfi_probe", &nettel_intel_map);
377 /* Set PAR to the detected size */
378 intel0size = intel_mtd->size;
379 *intel0par = SC520_PAR(intel0cs, intel0addr, intel0size);
382 * Map second Intel FLASH right after first. Set its size to the
383 * same maxsize used for the first Intel FLASH.
385 intel1addr = intel0addr + intel0size;
386 *intel1par = SC520_PAR(intel1cs, intel1addr, maxsize);
389 maxsize += intel0size;
391 /* Delete the old map and probe again to do both chips */
392 map_destroy(intel_mtd);
394 iounmap(nettel_intel_map.virt);
396 nettel_intel_map.size = maxsize;
397 nettel_intel_map.virt = ioremap_nocache(intel0addr, maxsize);
398 if (!nettel_intel_map.virt) {
399 printk("SNAPGEAR: failed to ioremap() ROMCS1/2\n");
404 intel_mtd = do_map_probe("cfi_probe", &nettel_intel_map);
410 intel1size = intel_mtd->size - intel0size;
411 if (intel1size > 0) {
412 *intel1par = SC520_PAR(intel1cs, intel1addr, intel1size);
418 printk(KERN_NOTICE "SNAPGEAR: Intel flash device size = %dK\n",
419 (intel_mtd->size >> 10));
421 intel_mtd->owner = THIS_MODULE;
423 #ifndef CONFIG_BLK_DEV_INITRD
424 ROOT_DEV = MKDEV(MTD_BLOCK_MAJOR, 1);
427 num_intel_partitions = sizeof(nettel_intel_partitions) /
428 sizeof(nettel_intel_partitions[0]);
432 * Adjust offset and size of last boot partition.
433 * Must allow for BIOS region at end of FLASH.
435 nettel_intel_partitions[1].size = (intel0size + intel1size) -
436 (1024*1024 + intel_mtd->erasesize);
437 nettel_intel_partitions[3].size = intel0size + intel1size;
438 nettel_intel_partitions[4].offset =
439 (intel0size + intel1size) - intel_mtd->erasesize;
440 nettel_intel_partitions[4].size = intel_mtd->erasesize;
441 nettel_intel_partitions[5].offset =
442 nettel_intel_partitions[4].offset;
443 nettel_intel_partitions[5].size =
444 nettel_intel_partitions[4].size;
446 /* No BIOS regions when AMD boot */
447 num_intel_partitions -= 2;
449 rc = add_mtd_partitions(intel_mtd, nettel_intel_partitions,
450 num_intel_partitions);
454 rc = add_mtd_partitions(amd_mtd, nettel_amd_partitions,
458 #ifdef CONFIG_MTD_CFI_INTELEXT
459 register_reboot_notifier(&nettel_notifier_block);
464 #ifdef CONFIG_MTD_CFI_INTELEXT
466 iounmap((void *) nettel_intel_map.virt);
470 iounmap(nettel_mmcrp);
471 iounmap(nettel_amd_map.virt);
477 /****************************************************************************/
479 void __exit nettel_cleanup(void)
481 #ifdef CONFIG_MTD_CFI_INTELEXT
482 unregister_reboot_notifier(&nettel_notifier_block);
485 del_mtd_partitions(amd_mtd);
486 map_destroy(amd_mtd);
489 iounmap(nettel_mmcrp);
492 if (nettel_amd_map.virt) {
493 iounmap(nettel_amd_map.virt);
494 nettel_amd_map.virt = NULL;
496 #ifdef CONFIG_MTD_CFI_INTELEXT
498 del_mtd_partitions(intel_mtd);
499 map_destroy(intel_mtd);
501 if (nettel_intel_map.virt) {
502 iounmap(nettel_intel_map.virt);
503 nettel_intel_map.virt = NULL;
508 /****************************************************************************/
510 module_init(nettel_init);
511 module_exit(nettel_cleanup);
513 MODULE_LICENSE("GPL");
514 MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>");
515 MODULE_DESCRIPTION("SnapGear/SecureEdge FLASH support");
517 /****************************************************************************/