Blame view
drivers/mtd/maps/nettel.c
11.4 KB
1da177e4c Linux-2.6.12-rc2 |
1 2 3 4 5 6 7 |
/****************************************************************************/ /* * nettel.c -- mappings for NETtel/SecureEdge/SnapGear (x86) boards. * * (C) Copyright 2000-2001, Greg Ungerer (gerg@snapgear.com) * (C) Copyright 2001-2002, SnapGear (www.snapgear.com) |
1da177e4c Linux-2.6.12-rc2 |
8 9 10 11 12 13 14 15 16 17 18 19 20 |
*/ /****************************************************************************/ #include <linux/module.h> #include <linux/init.h> #include <linux/types.h> #include <linux/kernel.h> #include <linux/mtd/mtd.h> #include <linux/mtd/map.h> #include <linux/mtd/partitions.h> #include <linux/mtd/cfi.h> #include <linux/reboot.h> |
9c74034f8 [MTD] return erro... |
21 |
#include <linux/err.h> |
6cc449c7d [PATCH] mtd, nett... |
22 23 |
#include <linux/kdev_t.h> #include <linux/root_dev.h> |
1da177e4c Linux-2.6.12-rc2 |
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
#include <asm/io.h> /****************************************************************************/ #define INTEL_BUSWIDTH 1 #define AMD_WINDOW_MAXSIZE 0x00200000 #define AMD_BUSWIDTH 1 /* * PAR masks and shifts, assuming 64K pages. */ #define SC520_PAR_ADDR_MASK 0x00003fff #define SC520_PAR_ADDR_SHIFT 16 #define SC520_PAR_TO_ADDR(par) \ (((par)&SC520_PAR_ADDR_MASK) << SC520_PAR_ADDR_SHIFT) #define SC520_PAR_SIZE_MASK 0x01ffc000 #define SC520_PAR_SIZE_SHIFT 2 #define SC520_PAR_TO_SIZE(par) \ ((((par)&SC520_PAR_SIZE_MASK) << SC520_PAR_SIZE_SHIFT) + (64*1024)) #define SC520_PAR(cs, addr, size) \ ((cs) | \ ((((size)-(64*1024)) >> SC520_PAR_SIZE_SHIFT) & SC520_PAR_SIZE_MASK) | \ (((addr) >> SC520_PAR_ADDR_SHIFT) & SC520_PAR_ADDR_MASK)) #define SC520_PAR_BOOTCS 0x8a000000 #define SC520_PAR_ROMCS1 0xaa000000 #define SC520_PAR_ROMCS2 0xca000000 /* Cache disabled, 64K page */ static void *nettel_mmcrp = NULL; #ifdef CONFIG_MTD_CFI_INTELEXT static struct mtd_info *intel_mtd; #endif static struct mtd_info *amd_mtd; /****************************************************************************/ /****************************************************************************/ #ifdef CONFIG_MTD_CFI_INTELEXT static struct map_info nettel_intel_map = { .name = "SnapGear Intel", .size = 0, .bankwidth = INTEL_BUSWIDTH, }; static struct mtd_partition nettel_intel_partitions[] = { { .name = "SnapGear kernel", .offset = 0, .size = 0x000e0000 }, { .name = "SnapGear filesystem", .offset = 0x00100000, }, { .name = "SnapGear config", .offset = 0x000e0000, .size = 0x00020000 }, { .name = "SnapGear Intel", .offset = 0 }, { .name = "SnapGear BIOS Config", .offset = 0x007e0000, .size = 0x00020000 }, { .name = "SnapGear BIOS", .offset = 0x007e0000, .size = 0x00020000 }, }; #endif static struct map_info nettel_amd_map = { .name = "SnapGear AMD", .size = AMD_WINDOW_MAXSIZE, .bankwidth = AMD_BUSWIDTH, }; static struct mtd_partition nettel_amd_partitions[] = { { .name = "SnapGear BIOS config", .offset = 0x000e0000, .size = 0x00010000 }, { .name = "SnapGear BIOS", .offset = 0x000f0000, .size = 0x00010000 }, { .name = "SnapGear AMD", .offset = 0 }, { .name = "SnapGear high BIOS", .offset = 0x001f0000, .size = 0x00010000 } }; |
87d10f3c7 [PATCH] drivers/m... |
131 |
#define NUM_AMD_PARTITIONS ARRAY_SIZE(nettel_amd_partitions) |
1da177e4c Linux-2.6.12-rc2 |
132 133 134 135 136 137 138 139 140 141 142 143 144 |
/****************************************************************************/ #ifdef CONFIG_MTD_CFI_INTELEXT /* * Set the Intel flash back to read mode since some old boot * loaders don't. */ static int nettel_reboot_notifier(struct notifier_block *nb, unsigned long val, void *v) { struct cfi_private *cfi = nettel_intel_map.fldrv_priv; unsigned long b; |
69f34c98c [MTD] maps: Clean... |
145 |
|
1da177e4c Linux-2.6.12-rc2 |
146 147 148 149 150 151 152 153 154 155 156 |
/* Make sure all FLASH chips are put back into read mode */ for (b = 0; (b < nettel_intel_partitions[3].size); b += 0x100000) { cfi_send_gen_cmd(0xff, 0x55, b, &nettel_intel_map, cfi, cfi->device_type, NULL); } return(NOTIFY_OK); } static struct notifier_block nettel_notifier_block = { nettel_reboot_notifier, NULL, 0 }; |
1da177e4c Linux-2.6.12-rc2 |
157 158 159 |
#endif /****************************************************************************/ |
663d77a7c [MTD] [MAPS] Clea... |
160 |
static int __init nettel_init(void) |
1da177e4c Linux-2.6.12-rc2 |
161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 |
{ volatile unsigned long *amdpar; unsigned long amdaddr, maxsize; int num_amd_partitions=0; #ifdef CONFIG_MTD_CFI_INTELEXT volatile unsigned long *intel0par, *intel1par; unsigned long orig_bootcspar, orig_romcs1par; unsigned long intel0addr, intel0size; unsigned long intel1addr, intel1size; int intelboot, intel0cs, intel1cs; int num_intel_partitions; #endif int rc = 0; nettel_mmcrp = (void *) ioremap_nocache(0xfffef000, 4096); if (nettel_mmcrp == NULL) { printk("SNAPGEAR: failed to disable MMCR cache?? "); return(-EIO); } /* Set CPU clock to be 33.000MHz */ *((unsigned char *) (nettel_mmcrp + 0xc64)) = 0x01; amdpar = (volatile unsigned long *) (nettel_mmcrp + 0xc4); #ifdef CONFIG_MTD_CFI_INTELEXT intelboot = 0; intel0cs = SC520_PAR_ROMCS1; intel0par = (volatile unsigned long *) (nettel_mmcrp + 0xc0); intel1cs = SC520_PAR_ROMCS2; intel1par = (volatile unsigned long *) (nettel_mmcrp + 0xbc); /* * Save the CS settings then ensure ROMCS1 and ROMCS2 are off, * otherwise they might clash with where we try to map BOOTCS. */ orig_bootcspar = *amdpar; orig_romcs1par = *intel0par; *intel0par = 0; *intel1par = 0; #endif /* * The first thing to do is determine if we have a separate * boot FLASH device. Typically this is a small (1 to 2MB) * AMD FLASH part. It seems that device size is about the * only way to tell if this is the case... */ amdaddr = 0x20000000; maxsize = AMD_WINDOW_MAXSIZE; *amdpar = SC520_PAR(SC520_PAR_BOOTCS, amdaddr, maxsize); __asm__ ("wbinvd"); nettel_amd_map.phys = amdaddr; nettel_amd_map.virt = ioremap_nocache(amdaddr, maxsize); if (!nettel_amd_map.virt) { printk("SNAPGEAR: failed to ioremap() BOOTCS "); |
25f0c659f ioremap balanced ... |
221 |
iounmap(nettel_mmcrp); |
1da177e4c Linux-2.6.12-rc2 |
222 223 224 225 226 227 228 |
return(-EIO); } simple_map_init(&nettel_amd_map); if ((amd_mtd = do_map_probe("jedec_probe", &nettel_amd_map))) { printk(KERN_NOTICE "SNAPGEAR: AMD flash device size = %dK ", |
69423d99f [MTD] update inte... |
229 |
(int)(amd_mtd->size>>10)); |
1da177e4c Linux-2.6.12-rc2 |
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 |
amd_mtd->owner = THIS_MODULE; /* The high BIOS partition is only present for 2MB units */ num_amd_partitions = NUM_AMD_PARTITIONS; if (amd_mtd->size < AMD_WINDOW_MAXSIZE) num_amd_partitions--; /* Don't add the partition until after the primary INTEL's */ #ifdef CONFIG_MTD_CFI_INTELEXT /* * Map the Intel flash into memory after the AMD * It has to start on a multiple of maxsize. */ maxsize = SC520_PAR_TO_SIZE(orig_romcs1par); if (maxsize < (32 * 1024 * 1024)) maxsize = (32 * 1024 * 1024); intel0addr = amdaddr + maxsize; #endif } else { #ifdef CONFIG_MTD_CFI_INTELEXT /* INTEL boot FLASH */ intelboot++; if (!orig_romcs1par) { intel0cs = SC520_PAR_BOOTCS; intel0par = (volatile unsigned long *) (nettel_mmcrp + 0xc4); intel1cs = SC520_PAR_ROMCS1; intel1par = (volatile unsigned long *) (nettel_mmcrp + 0xc0); intel0addr = SC520_PAR_TO_ADDR(orig_bootcspar); maxsize = SC520_PAR_TO_SIZE(orig_bootcspar); } else { /* Kernel base is on ROMCS1, not BOOTCS */ intel0cs = SC520_PAR_ROMCS1; intel0par = (volatile unsigned long *) (nettel_mmcrp + 0xc0); intel1cs = SC520_PAR_BOOTCS; intel1par = (volatile unsigned long *) (nettel_mmcrp + 0xc4); intel0addr = SC520_PAR_TO_ADDR(orig_romcs1par); maxsize = SC520_PAR_TO_SIZE(orig_romcs1par); } /* Destroy useless AMD MTD mapping */ amd_mtd = NULL; iounmap(nettel_amd_map.virt); nettel_amd_map.virt = NULL; #else /* Only AMD flash supported */ |
25f0c659f ioremap balanced ... |
283 284 |
rc = -ENXIO; goto out_unmap2; |
1da177e4c Linux-2.6.12-rc2 |
285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 |
#endif } #ifdef CONFIG_MTD_CFI_INTELEXT /* * We have determined the INTEL FLASH configuration, so lets * go ahead and probe for them now. */ /* Set PAR to the maximum size */ if (maxsize < (32 * 1024 * 1024)) maxsize = (32 * 1024 * 1024); *intel0par = SC520_PAR(intel0cs, intel0addr, maxsize); /* Turn other PAR off so the first probe doesn't find it */ *intel1par = 0; |
59c51591a Fix occurrences o... |
301 |
/* Probe for the size of the first Intel flash */ |
1da177e4c Linux-2.6.12-rc2 |
302 303 304 305 306 307 |
nettel_intel_map.size = maxsize; nettel_intel_map.phys = intel0addr; nettel_intel_map.virt = ioremap_nocache(intel0addr, maxsize); if (!nettel_intel_map.virt) { printk("SNAPGEAR: failed to ioremap() ROMCS1 "); |
25f0c659f ioremap balanced ... |
308 309 |
rc = -EIO; goto out_unmap2; |
1da177e4c Linux-2.6.12-rc2 |
310 311 312 313 314 |
} simple_map_init(&nettel_intel_map); intel_mtd = do_map_probe("cfi_probe", &nettel_intel_map); if (!intel_mtd) { |
25f0c659f ioremap balanced ... |
315 316 |
rc = -ENXIO; goto out_unmap1; |
1da177e4c Linux-2.6.12-rc2 |
317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 |
} /* Set PAR to the detected size */ intel0size = intel_mtd->size; *intel0par = SC520_PAR(intel0cs, intel0addr, intel0size); /* * Map second Intel FLASH right after first. Set its size to the * same maxsize used for the first Intel FLASH. */ intel1addr = intel0addr + intel0size; *intel1par = SC520_PAR(intel1cs, intel1addr, maxsize); __asm__ ("wbinvd"); maxsize += intel0size; /* Delete the old map and probe again to do both chips */ map_destroy(intel_mtd); intel_mtd = NULL; iounmap(nettel_intel_map.virt); nettel_intel_map.size = maxsize; nettel_intel_map.virt = ioremap_nocache(intel0addr, maxsize); if (!nettel_intel_map.virt) { printk("SNAPGEAR: failed to ioremap() ROMCS1/2 "); |
25f0c659f ioremap balanced ... |
343 344 |
rc = -EIO; goto out_unmap2; |
1da177e4c Linux-2.6.12-rc2 |
345 346 347 348 |
} intel_mtd = do_map_probe("cfi_probe", &nettel_intel_map); if (! intel_mtd) { |
25f0c659f ioremap balanced ... |
349 350 |
rc = -ENXIO; goto out_unmap1; |
1da177e4c Linux-2.6.12-rc2 |
351 352 353 354 355 356 357 358 359 |
} intel1size = intel_mtd->size - intel0size; if (intel1size > 0) { *intel1par = SC520_PAR(intel1cs, intel1addr, intel1size); __asm__ ("wbinvd"); } else { *intel1par = 0; } |
85795dac7 [MTD] [MAPS] Fix ... |
360 361 362 |
printk(KERN_NOTICE "SNAPGEAR: Intel flash device size = %lldKiB ", (unsigned long long)(intel_mtd->size >> 10)); |
1da177e4c Linux-2.6.12-rc2 |
363 364 |
intel_mtd->owner = THIS_MODULE; |
002f6aab4 [MTD] drivers/mtd... |
365 |
num_intel_partitions = ARRAY_SIZE(nettel_intel_partitions); |
1da177e4c Linux-2.6.12-rc2 |
366 367 368 369 370 371 372 373 374 |
if (intelboot) { /* * Adjust offset and size of last boot partition. * Must allow for BIOS region at end of FLASH. */ nettel_intel_partitions[1].size = (intel0size + intel1size) - (1024*1024 + intel_mtd->erasesize); nettel_intel_partitions[3].size = intel0size + intel1size; |
69f34c98c [MTD] maps: Clean... |
375 |
nettel_intel_partitions[4].offset = |
1da177e4c Linux-2.6.12-rc2 |
376 377 378 379 380 381 382 383 384 385 |
(intel0size + intel1size) - intel_mtd->erasesize; nettel_intel_partitions[4].size = intel_mtd->erasesize; nettel_intel_partitions[5].offset = nettel_intel_partitions[4].offset; nettel_intel_partitions[5].size = nettel_intel_partitions[4].size; } else { /* No BIOS regions when AMD boot */ num_intel_partitions -= 2; } |
ee0e87b17 mtd: convert rema... |
386 387 |
rc = mtd_device_register(intel_mtd, nettel_intel_partitions, num_intel_partitions); |
1da177e4c Linux-2.6.12-rc2 |
388 389 390 |
#endif if (amd_mtd) { |
ee0e87b17 mtd: convert rema... |
391 392 |
rc = mtd_device_register(amd_mtd, nettel_amd_partitions, num_amd_partitions); |
1da177e4c Linux-2.6.12-rc2 |
393 394 395 396 397 398 399 |
} #ifdef CONFIG_MTD_CFI_INTELEXT register_reboot_notifier(&nettel_notifier_block); #endif return(rc); |
25f0c659f ioremap balanced ... |
400 401 402 |
#ifdef CONFIG_MTD_CFI_INTELEXT out_unmap1: |
76a5027c3 [MTD] Cleanup of ... |
403 |
iounmap(nettel_intel_map.virt); |
25f0c659f ioremap balanced ... |
404 405 406 407 408 409 410 |
#endif out_unmap2: iounmap(nettel_mmcrp); iounmap(nettel_amd_map.virt); return(rc); |
c9ac59772 [MTD] Remove trai... |
411 |
|
1da177e4c Linux-2.6.12-rc2 |
412 413 414 |
} /****************************************************************************/ |
663d77a7c [MTD] [MAPS] Clea... |
415 |
static void __exit nettel_cleanup(void) |
1da177e4c Linux-2.6.12-rc2 |
416 417 418 419 420 |
{ #ifdef CONFIG_MTD_CFI_INTELEXT unregister_reboot_notifier(&nettel_notifier_block); #endif if (amd_mtd) { |
ee0e87b17 mtd: convert rema... |
421 |
mtd_device_unregister(amd_mtd); |
1da177e4c Linux-2.6.12-rc2 |
422 423 |
map_destroy(amd_mtd); } |
25f0c659f ioremap balanced ... |
424 425 426 427 |
if (nettel_mmcrp) { iounmap(nettel_mmcrp); nettel_mmcrp = NULL; } |
1da177e4c Linux-2.6.12-rc2 |
428 429 430 431 432 433 |
if (nettel_amd_map.virt) { iounmap(nettel_amd_map.virt); nettel_amd_map.virt = NULL; } #ifdef CONFIG_MTD_CFI_INTELEXT if (intel_mtd) { |
ee0e87b17 mtd: convert rema... |
434 |
mtd_device_unregister(intel_mtd); |
1da177e4c Linux-2.6.12-rc2 |
435 436 437 438 |
map_destroy(intel_mtd); } if (nettel_intel_map.virt) { iounmap(nettel_intel_map.virt); |
e2602b347 [MTD] maps: spars... |
439 |
nettel_intel_map.virt = NULL; |
1da177e4c Linux-2.6.12-rc2 |
440 441 442 443 444 445 446 447 448 449 450 451 452 453 |
} #endif } /****************************************************************************/ module_init(nettel_init); module_exit(nettel_cleanup); MODULE_LICENSE("GPL"); MODULE_AUTHOR("Greg Ungerer <gerg@snapgear.com>"); MODULE_DESCRIPTION("SnapGear/SecureEdge FLASH support"); /****************************************************************************/ |