Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

Merge master.kernel.org:/pub/scm/linux/kernel/git/tglx/mtd-2.6

+3622 -3243
+27 -2
drivers/mtd/chips/Kconfig
··· 1 1 # drivers/mtd/chips/Kconfig 2 - # $Id: Kconfig,v 1.13 2004/12/01 15:49:10 nico Exp $ 2 + # $Id: Kconfig,v 1.15 2005/06/06 23:04:35 tpoynor Exp $ 3 3 4 4 menu "RAM/ROM/Flash chip drivers" 5 5 depends on MTD!=n ··· 155 155 If your flash chips are interleaved in eights - i.e. you have eight 156 156 flash chips addressed by each bus cycle, then say 'Y'. 157 157 158 + config MTD_OTP 159 + bool "Protection Registers aka one-time programmable (OTP) bits" 160 + depends on MTD_CFI_ADV_OPTIONS 161 + default n 162 + help 163 + This enables support for reading, writing and locking so called 164 + "Protection Registers" present on some flash chips. 165 + A subset of them are pre-programmed at the factory with a 166 + unique set of values. The rest is user-programmable. 167 + 168 + The user-programmable Protection Registers contain one-time 169 + programmable (OTP) bits; when programmed, register bits cannot be 170 + erased. Each Protection Register can be accessed multiple times to 171 + program individual bits, as long as the register remains unlocked. 172 + 173 + Each Protection Register has an associated Lock Register bit. When a 174 + Lock Register bit is programmed, the associated Protection Register 175 + can only be read; it can no longer be programmed. Additionally, 176 + because the Lock Register bits themselves are OTP, when programmed, 177 + Lock Register bits cannot be erased. Therefore, when a Protection 178 + Register is locked, it cannot be unlocked. 179 + 180 + This feature should therefore be used with extreme care. Any mistake 181 + in the programming of OTP bits will waste them. 182 + 158 183 config MTD_CFI_INTELEXT 159 184 tristate "Support for Intel/Sharp flash chips" 160 185 depends on MTD_GEN_PROBE ··· 300 275 301 276 config MTD_XIP 302 277 bool "XIP aware MTD support" 303 - depends on !SMP && MTD_CFI_INTELEXT && EXPERIMENTAL 278 + depends on !SMP && (MTD_CFI_INTELEXT || MTD_CFI_AMDSTD) && EXPERIMENTAL 304 279 default y if XIP_KERNEL 305 280 help 306 281 This allows MTD support to work with flash memory which is also
+1 -13
drivers/mtd/chips/amd_flash.c
··· 3 3 * 4 4 * Author: Jonas Holmberg <jonas.holmberg@axis.com> 5 5 * 6 - * $Id: amd_flash.c,v 1.26 2004/11/20 12:49:04 dwmw2 Exp $ 6 + * $Id: amd_flash.c,v 1.27 2005/02/04 07:43:09 jonashg Exp $ 7 7 * 8 8 * Copyright (c) 2001 Axis Communications AB 9 9 * ··· 67 67 #define AM29LV160DT 0x22C4 68 68 #define AM29LV160DB 0x2249 69 69 #define AM29BDS323D 0x22D1 70 - #define AM29BDS643D 0x227E 71 70 72 71 /* Atmel */ 73 72 #define AT49xV16x 0x00C0 ··· 615 616 { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 48 }, 616 617 { .offset = 0x300000, .erasesize = 0x10000, .numblocks = 15 }, 617 618 { .offset = 0x3f0000, .erasesize = 0x02000, .numblocks = 8 }, 618 - } 619 - }, { 620 - .mfr_id = MANUFACTURER_AMD, 621 - .dev_id = AM29BDS643D, 622 - .name = "AMD AM29BDS643D", 623 - .size = 0x00800000, 624 - .numeraseregions = 3, 625 - .regions = { 626 - { .offset = 0x000000, .erasesize = 0x10000, .numblocks = 96 }, 627 - { .offset = 0x600000, .erasesize = 0x10000, .numblocks = 31 }, 628 - { .offset = 0x7f0000, .erasesize = 0x02000, .numblocks = 8 }, 629 619 } 630 620 }, { 631 621 .mfr_id = MANUFACTURER_ATMEL,
+400 -180
drivers/mtd/chips/cfi_cmdset_0001.c
··· 4 4 * 5 5 * (C) 2000 Red Hat. GPL'd 6 6 * 7 - * $Id: cfi_cmdset_0001.c,v 1.164 2004/11/16 18:29:00 dwmw2 Exp $ 7 + * $Id: cfi_cmdset_0001.c,v 1.178 2005/05/19 17:05:43 nico Exp $ 8 8 * 9 9 * 10 10 * 10/10/2000 Nicolas Pitre <nico@cam.org> ··· 29 29 #include <linux/slab.h> 30 30 #include <linux/delay.h> 31 31 #include <linux/interrupt.h> 32 + #include <linux/reboot.h> 32 33 #include <linux/mtd/xip.h> 33 34 #include <linux/mtd/map.h> 34 35 #include <linux/mtd/mtd.h> ··· 49 48 #define M50LPW080 0x002F 50 49 51 50 static int cfi_intelext_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 52 - //static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 53 - //static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 54 51 static int cfi_intelext_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 55 52 static int cfi_intelext_write_buffers(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); 56 53 static int cfi_intelext_erase_varsize(struct mtd_info *, struct erase_info *); 57 54 static void cfi_intelext_sync (struct mtd_info *); 58 55 static int cfi_intelext_lock(struct mtd_info *mtd, loff_t ofs, size_t len); 59 56 static int cfi_intelext_unlock(struct mtd_info *mtd, loff_t ofs, size_t len); 57 + #ifdef CONFIG_MTD_OTP 58 + static int cfi_intelext_read_fact_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 59 + static int cfi_intelext_read_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 60 + static int cfi_intelext_write_user_prot_reg (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 61 + static int cfi_intelext_lock_user_prot_reg (struct mtd_info *, loff_t, size_t); 62 + static int cfi_intelext_get_fact_prot_info (struct mtd_info *, 63 + struct otp_info *, size_t); 64 + static int cfi_intelext_get_user_prot_info (struct mtd_info *, 65 + struct otp_info *, size_t); 66 + #endif 60 67 static int cfi_intelext_suspend (struct mtd_info *); 61 68 static void cfi_intelext_resume (struct mtd_info *); 69 + static int cfi_intelext_reboot (struct notifier_block *, unsigned long, void *); 62 70 63 71 static void cfi_intelext_destroy(struct mtd_info *); 64 72 ··· 262 252 int nb_parts, i; 263 253 264 254 /* Protection Register info */ 265 - extra_size += (extp->NumProtectionFields - 1) * (4 + 6); 255 + extra_size += (extp->NumProtectionFields - 1) * 256 + sizeof(struct cfi_intelext_otpinfo); 266 257 267 258 /* Burst Read info */ 268 259 extra_size += 6; ··· 335 324 mtd->resume = cfi_intelext_resume; 336 325 mtd->flags = MTD_CAP_NORFLASH; 337 326 mtd->name = map->name; 338 - 327 + 328 + mtd->reboot_notifier.notifier_call = cfi_intelext_reboot; 329 + 339 330 if (cfi->cfi_mode == CFI_MODE_CFI) { 340 331 /* 341 332 * It's a real CFI chip, not one for which the probe ··· 435 422 mtd->eraseregions[i].numblocks); 436 423 } 437 424 438 - #if 0 439 - mtd->read_user_prot_reg = cfi_intelext_read_user_prot_reg; 425 + #ifdef CONFIG_MTD_OTP 440 426 mtd->read_fact_prot_reg = cfi_intelext_read_fact_prot_reg; 427 + mtd->read_user_prot_reg = cfi_intelext_read_user_prot_reg; 428 + mtd->write_user_prot_reg = cfi_intelext_write_user_prot_reg; 429 + mtd->lock_user_prot_reg = cfi_intelext_lock_user_prot_reg; 430 + mtd->get_fact_prot_info = cfi_intelext_get_fact_prot_info; 431 + mtd->get_user_prot_info = cfi_intelext_get_user_prot_info; 441 432 #endif 442 433 443 434 /* This function has the potential to distort the reality ··· 450 433 goto setup_err; 451 434 452 435 __module_get(THIS_MODULE); 436 + register_reboot_notifier(&mtd->reboot_notifier); 453 437 return mtd; 454 438 455 439 setup_err: ··· 489 471 int offs, numregions, numparts, partshift, numvirtchips, i, j; 490 472 491 473 /* Protection Register info */ 492 - offs = (extp->NumProtectionFields - 1) * (4 + 6); 474 + offs = (extp->NumProtectionFields - 1) * 475 + sizeof(struct cfi_intelext_otpinfo); 493 476 494 477 /* Burst Read info */ 495 478 offs += 6; ··· 582 563 resettime: 583 564 timeo = jiffies + HZ; 584 565 retry: 585 - if (chip->priv && (mode == FL_WRITING || mode == FL_ERASING)) { 566 + if (chip->priv && (mode == FL_WRITING || mode == FL_ERASING || mode == FL_OTP_WRITE)) { 586 567 /* 587 568 * OK. We have possibility for contension on the write/erase 588 569 * operations which are global to the real chip and not per ··· 826 807 * assembly to make sure inline functions were actually inlined and that gcc 827 808 * didn't emit calls to its own support functions). Also configuring MTD CFI 828 809 * support to a single buswidth and a single interleave is also recommended. 829 - * Note that not only IRQs are disabled but the preemption count is also 830 - * increased to prevent other locking primitives (namely spin_unlock) from 831 - * decrementing the preempt count to zero and scheduling the CPU away while 832 - * not in array mode. 833 810 */ 834 811 835 812 static void xip_disable(struct map_info *map, struct flchip *chip, ··· 833 818 { 834 819 /* TODO: chips with no XIP use should ignore and return */ 835 820 (void) map_read(map, adr); /* ensure mmu mapping is up to date */ 836 - preempt_disable(); 837 821 local_irq_disable(); 838 822 } 839 823 ··· 845 831 chip->state = FL_READY; 846 832 } 847 833 (void) map_read(map, adr); 848 - asm volatile (".rep 8; nop; .endr"); /* fill instruction prefetch */ 834 + xip_iprefetch(); 849 835 local_irq_enable(); 850 - preempt_enable(); 851 836 } 852 837 853 838 /* ··· 922 909 (void) map_read(map, adr); 923 910 asm volatile (".rep 8; nop; .endr"); 924 911 local_irq_enable(); 925 - preempt_enable(); 912 + spin_unlock(chip->mutex); 926 913 asm volatile (".rep 8; nop; .endr"); 927 914 cond_resched(); 928 915 ··· 932 919 * a suspended erase state. If so let's wait 933 920 * until it's done. 934 921 */ 935 - preempt_disable(); 922 + spin_lock(chip->mutex); 936 923 while (chip->state != newstate) { 937 924 DECLARE_WAITQUEUE(wait, current); 938 925 set_current_state(TASK_UNINTERRUPTIBLE); 939 926 add_wait_queue(&chip->wq, &wait); 940 - preempt_enable(); 927 + spin_unlock(chip->mutex); 941 928 schedule(); 942 929 remove_wait_queue(&chip->wq, &wait); 943 - preempt_disable(); 930 + spin_lock(chip->mutex); 944 931 } 945 932 /* Disallow XIP again */ 946 933 local_irq_disable(); ··· 969 956 * The INVALIDATE_CACHED_RANGE() macro is normally used in parallel while 970 957 * the flash is actively programming or erasing since we have to poll for 971 958 * the operation to complete anyway. We can't do that in a generic way with 972 - * a XIP setup so do it before the actual flash operation in this case. 959 + * a XIP setup so do it before the actual flash operation in this case 960 + * and stub it out from INVALIDATE_CACHE_UDELAY. 973 961 */ 974 - #undef INVALIDATE_CACHED_RANGE 975 - #define INVALIDATE_CACHED_RANGE(x...) 976 - #define XIP_INVAL_CACHED_RANGE(map, from, size) \ 977 - do { if(map->inval_cache) map->inval_cache(map, from, size); } while(0) 962 + #define XIP_INVAL_CACHED_RANGE(map, from, size) \ 963 + INVALIDATE_CACHED_RANGE(map, from, size) 964 + 965 + #define INVALIDATE_CACHE_UDELAY(map, chip, adr, len, usec) \ 966 + UDELAY(map, chip, adr, usec) 978 967 979 968 /* 980 969 * Extra notes: ··· 999 984 1000 985 #define xip_disable(map, chip, adr) 1001 986 #define xip_enable(map, chip, adr) 1002 - 1003 - #define UDELAY(map, chip, adr, usec) cfi_udelay(usec) 1004 - 1005 987 #define XIP_INVAL_CACHED_RANGE(x...) 988 + 989 + #define UDELAY(map, chip, adr, usec) \ 990 + do { \ 991 + spin_unlock(chip->mutex); \ 992 + cfi_udelay(usec); \ 993 + spin_lock(chip->mutex); \ 994 + } while (0) 995 + 996 + #define INVALIDATE_CACHE_UDELAY(map, chip, adr, len, usec) \ 997 + do { \ 998 + spin_unlock(chip->mutex); \ 999 + INVALIDATE_CACHED_RANGE(map, adr, len); \ 1000 + cfi_udelay(usec); \ 1001 + spin_lock(chip->mutex); \ 1002 + } while (0) 1006 1003 1007 1004 #endif 1008 1005 ··· 1203 1176 return ret; 1204 1177 } 1205 1178 1206 - #if 0 1207 - static int __xipram cfi_intelext_read_prot_reg (struct mtd_info *mtd, 1208 - loff_t from, size_t len, 1209 - size_t *retlen, 1210 - u_char *buf, 1211 - int base_offst, int reg_sz) 1212 - { 1213 - struct map_info *map = mtd->priv; 1214 - struct cfi_private *cfi = map->fldrv_priv; 1215 - struct cfi_pri_intelext *extp = cfi->cmdset_priv; 1216 - struct flchip *chip; 1217 - int ofs_factor = cfi->interleave * cfi->device_type; 1218 - int count = len; 1219 - int chip_num, offst; 1220 - int ret; 1221 - 1222 - chip_num = ((unsigned int)from/reg_sz); 1223 - offst = from - (reg_sz*chip_num)+base_offst; 1224 - 1225 - while (count) { 1226 - /* Calculate which chip & protection register offset we need */ 1227 - 1228 - if (chip_num >= cfi->numchips) 1229 - goto out; 1230 - 1231 - chip = &cfi->chips[chip_num]; 1232 - 1233 - spin_lock(chip->mutex); 1234 - ret = get_chip(map, chip, chip->start, FL_JEDEC_QUERY); 1235 - if (ret) { 1236 - spin_unlock(chip->mutex); 1237 - return (len-count)?:ret; 1238 - } 1239 - 1240 - xip_disable(map, chip, chip->start); 1241 - 1242 - if (chip->state != FL_JEDEC_QUERY) { 1243 - map_write(map, CMD(0x90), chip->start); 1244 - chip->state = FL_JEDEC_QUERY; 1245 - } 1246 - 1247 - while (count && ((offst-base_offst) < reg_sz)) { 1248 - *buf = map_read8(map,(chip->start+((extp->ProtRegAddr+1)*ofs_factor)+offst)); 1249 - buf++; 1250 - offst++; 1251 - count--; 1252 - } 1253 - 1254 - xip_enable(map, chip, chip->start); 1255 - put_chip(map, chip, chip->start); 1256 - spin_unlock(chip->mutex); 1257 - 1258 - /* Move on to the next chip */ 1259 - chip_num++; 1260 - offst = base_offst; 1261 - } 1262 - 1263 - out: 1264 - return len-count; 1265 - } 1266 - 1267 - static int cfi_intelext_read_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) 1268 - { 1269 - struct map_info *map = mtd->priv; 1270 - struct cfi_private *cfi = map->fldrv_priv; 1271 - struct cfi_pri_intelext *extp=cfi->cmdset_priv; 1272 - int base_offst,reg_sz; 1273 - 1274 - /* Check that we actually have some protection registers */ 1275 - if(!extp || !(extp->FeatureSupport&64)){ 1276 - printk(KERN_WARNING "%s: This flash device has no protection data to read!\n",map->name); 1277 - return 0; 1278 - } 1279 - 1280 - base_offst=(1<<extp->FactProtRegSize); 1281 - reg_sz=(1<<extp->UserProtRegSize); 1282 - 1283 - return cfi_intelext_read_prot_reg(mtd, from, len, retlen, buf, base_offst, reg_sz); 1284 - } 1285 - 1286 - static int cfi_intelext_read_fact_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf) 1287 - { 1288 - struct map_info *map = mtd->priv; 1289 - struct cfi_private *cfi = map->fldrv_priv; 1290 - struct cfi_pri_intelext *extp=cfi->cmdset_priv; 1291 - int base_offst,reg_sz; 1292 - 1293 - /* Check that we actually have some protection registers */ 1294 - if(!extp || !(extp->FeatureSupport&64)){ 1295 - printk(KERN_WARNING "%s: This flash device has no protection data to read!\n",map->name); 1296 - return 0; 1297 - } 1298 - 1299 - base_offst=0; 1300 - reg_sz=(1<<extp->FactProtRegSize); 1301 - 1302 - return cfi_intelext_read_prot_reg(mtd, from, len, retlen, buf, base_offst, reg_sz); 1303 - } 1304 - #endif 1305 - 1306 1179 static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, 1307 - unsigned long adr, map_word datum) 1180 + unsigned long adr, map_word datum, int mode) 1308 1181 { 1309 1182 struct cfi_private *cfi = map->fldrv_priv; 1310 - map_word status, status_OK; 1183 + map_word status, status_OK, write_cmd; 1311 1184 unsigned long timeo; 1312 1185 int z, ret=0; 1313 1186 ··· 1215 1288 1216 1289 /* Let's determine this according to the interleave only once */ 1217 1290 status_OK = CMD(0x80); 1291 + switch (mode) { 1292 + case FL_WRITING: write_cmd = CMD(0x40); break; 1293 + case FL_OTP_WRITE: write_cmd = CMD(0xc0); break; 1294 + default: return -EINVAL; 1295 + } 1218 1296 1219 1297 spin_lock(chip->mutex); 1220 - ret = get_chip(map, chip, adr, FL_WRITING); 1298 + ret = get_chip(map, chip, adr, mode); 1221 1299 if (ret) { 1222 1300 spin_unlock(chip->mutex); 1223 1301 return ret; ··· 1231 1299 XIP_INVAL_CACHED_RANGE(map, adr, map_bankwidth(map)); 1232 1300 ENABLE_VPP(map); 1233 1301 xip_disable(map, chip, adr); 1234 - map_write(map, CMD(0x40), adr); 1302 + map_write(map, write_cmd, adr); 1235 1303 map_write(map, datum, adr); 1236 - chip->state = FL_WRITING; 1304 + chip->state = mode; 1237 1305 1238 - spin_unlock(chip->mutex); 1239 - INVALIDATE_CACHED_RANGE(map, adr, map_bankwidth(map)); 1240 - UDELAY(map, chip, adr, chip->word_write_time); 1241 - spin_lock(chip->mutex); 1306 + INVALIDATE_CACHE_UDELAY(map, chip, 1307 + adr, map_bankwidth(map), 1308 + chip->word_write_time); 1242 1309 1243 1310 timeo = jiffies + (HZ/2); 1244 1311 z = 0; 1245 1312 for (;;) { 1246 - if (chip->state != FL_WRITING) { 1313 + if (chip->state != mode) { 1247 1314 /* Someone's suspended the write. Sleep */ 1248 1315 DECLARE_WAITQUEUE(wait, current); 1249 1316 ··· 1270 1339 } 1271 1340 1272 1341 /* Latency issues. Drop the lock, wait a while and retry */ 1273 - spin_unlock(chip->mutex); 1274 1342 z++; 1275 1343 UDELAY(map, chip, adr, 1); 1276 - spin_lock(chip->mutex); 1277 1344 } 1278 1345 if (!z) { 1279 1346 chip->word_write_time--; ··· 1328 1399 datum = map_word_load_partial(map, datum, buf, gap, n); 1329 1400 1330 1401 ret = do_write_oneword(map, &cfi->chips[chipnum], 1331 - bus_ofs, datum); 1402 + bus_ofs, datum, FL_WRITING); 1332 1403 if (ret) 1333 1404 return ret; 1334 1405 ··· 1349 1420 map_word datum = map_word_load(map, buf); 1350 1421 1351 1422 ret = do_write_oneword(map, &cfi->chips[chipnum], 1352 - ofs, datum); 1423 + ofs, datum, FL_WRITING); 1353 1424 if (ret) 1354 1425 return ret; 1355 1426 ··· 1373 1444 datum = map_word_load_partial(map, datum, buf, 0, len); 1374 1445 1375 1446 ret = do_write_oneword(map, &cfi->chips[chipnum], 1376 - ofs, datum); 1447 + ofs, datum, FL_WRITING); 1377 1448 if (ret) 1378 1449 return ret; 1379 1450 ··· 1435 1506 if (map_word_andequal(map, status, status_OK, status_OK)) 1436 1507 break; 1437 1508 1438 - spin_unlock(chip->mutex); 1439 1509 UDELAY(map, chip, cmd_adr, 1); 1440 - spin_lock(chip->mutex); 1441 1510 1442 1511 if (++z > 20) { 1443 1512 /* Argh. Not ready for write to buffer */ ··· 1481 1554 map_write(map, CMD(0xd0), cmd_adr); 1482 1555 chip->state = FL_WRITING; 1483 1556 1484 - spin_unlock(chip->mutex); 1485 - INVALIDATE_CACHED_RANGE(map, adr, len); 1486 - UDELAY(map, chip, cmd_adr, chip->buffer_write_time); 1487 - spin_lock(chip->mutex); 1557 + INVALIDATE_CACHE_UDELAY(map, chip, 1558 + cmd_adr, len, 1559 + chip->buffer_write_time); 1488 1560 1489 1561 timeo = jiffies + (HZ/2); 1490 1562 z = 0; ··· 1515 1589 } 1516 1590 1517 1591 /* Latency issues. Drop the lock, wait a while and retry */ 1518 - spin_unlock(chip->mutex); 1519 - UDELAY(map, chip, cmd_adr, 1); 1520 1592 z++; 1521 - spin_lock(chip->mutex); 1593 + UDELAY(map, chip, cmd_adr, 1); 1522 1594 } 1523 1595 if (!z) { 1524 1596 chip->buffer_write_time--; ··· 1644 1720 chip->state = FL_ERASING; 1645 1721 chip->erase_suspended = 0; 1646 1722 1647 - spin_unlock(chip->mutex); 1648 - INVALIDATE_CACHED_RANGE(map, adr, len); 1649 - UDELAY(map, chip, adr, chip->erase_time*1000/2); 1650 - spin_lock(chip->mutex); 1723 + INVALIDATE_CACHE_UDELAY(map, chip, 1724 + adr, len, 1725 + chip->erase_time*1000/2); 1651 1726 1652 1727 /* FIXME. Use a timer to check this, and return immediately. */ 1653 1728 /* Once the state machine's known to be working I'll do that */ ··· 1691 1768 } 1692 1769 1693 1770 /* Latency issues. Drop the lock, wait a while and retry */ 1694 - spin_unlock(chip->mutex); 1695 1771 UDELAY(map, chip, adr, 1000000/HZ); 1696 - spin_lock(chip->mutex); 1697 1772 } 1698 1773 1699 1774 /* We've broken this before. It doesn't hurt to be safe */ ··· 1701 1780 1702 1781 /* check for lock bit */ 1703 1782 if (map_word_bitsset(map, status, CMD(0x3a))) { 1704 - unsigned char chipstatus; 1783 + unsigned long chipstatus; 1705 1784 1706 1785 /* Reset the error bits */ 1707 1786 map_write(map, CMD(0x50), adr); 1708 1787 map_write(map, CMD(0x70), adr); 1709 1788 xip_enable(map, chip, adr); 1710 1789 1711 - chipstatus = status.x[0]; 1712 - if (!map_word_equal(map, status, CMD(chipstatus))) { 1713 - int i, w; 1714 - for (w=0; w<map_words(map); w++) { 1715 - for (i = 0; i<cfi_interleave(cfi); i++) { 1716 - chipstatus |= status.x[w] >> (cfi->device_type * 8); 1717 - } 1718 - } 1719 - printk(KERN_WARNING "Status is not identical for all chips: 0x%lx. Merging to give 0x%02x\n", 1720 - status.x[0], chipstatus); 1721 - } 1790 + chipstatus = MERGESTATUS(status); 1722 1791 1723 1792 if ((chipstatus & 0x30) == 0x30) { 1724 - printk(KERN_NOTICE "Chip reports improper command sequence: status 0x%x\n", chipstatus); 1793 + printk(KERN_NOTICE "Chip reports improper command sequence: status 0x%lx\n", chipstatus); 1725 1794 ret = -EIO; 1726 1795 } else if (chipstatus & 0x02) { 1727 1796 /* Protection bit set */ 1728 1797 ret = -EROFS; 1729 1798 } else if (chipstatus & 0x8) { 1730 1799 /* Voltage */ 1731 - printk(KERN_WARNING "Chip reports voltage low on erase: status 0x%x\n", chipstatus); 1800 + printk(KERN_WARNING "Chip reports voltage low on erase: status 0x%lx\n", chipstatus); 1732 1801 ret = -EIO; 1733 1802 } else if (chipstatus & 0x20) { 1734 1803 if (retries--) { 1735 - printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%x. Retrying...\n", adr, chipstatus); 1804 + printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%lx. Retrying...\n", adr, chipstatus); 1736 1805 timeo = jiffies + HZ; 1737 1806 put_chip(map, chip, adr); 1738 1807 spin_unlock(chip->mutex); 1739 1808 goto retry; 1740 1809 } 1741 - printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%x\n", adr, chipstatus); 1810 + printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%lx\n", adr, chipstatus); 1742 1811 ret = -EIO; 1743 1812 } 1744 1813 } else { ··· 1793 1882 1794 1883 if (chip->state == FL_SYNCING) { 1795 1884 chip->state = chip->oldstate; 1885 + chip->oldstate = FL_READY; 1796 1886 wake_up(&chip->wq); 1797 1887 } 1798 1888 spin_unlock(chip->mutex); ··· 1809 1897 struct cfi_private *cfi = map->fldrv_priv; 1810 1898 int status, ofs_factor = cfi->interleave * cfi->device_type; 1811 1899 1900 + adr += chip->start; 1812 1901 xip_disable(map, chip, adr+(2*ofs_factor)); 1813 - cfi_send_gen_cmd(0x90, 0x55, 0, map, cfi, cfi->device_type, NULL); 1902 + map_write(map, CMD(0x90), adr+(2*ofs_factor)); 1814 1903 chip->state = FL_JEDEC_QUERY; 1815 1904 status = cfi_read_query(map, adr+(2*ofs_factor)); 1816 1905 xip_enable(map, chip, 0); ··· 1828 1915 unsigned long adr, int len, void *thunk) 1829 1916 { 1830 1917 struct cfi_private *cfi = map->fldrv_priv; 1918 + struct cfi_pri_intelext *extp = cfi->cmdset_priv; 1831 1919 map_word status, status_OK; 1832 1920 unsigned long timeo = jiffies + HZ; 1833 1921 int ret; ··· 1858 1944 } else 1859 1945 BUG(); 1860 1946 1861 - spin_unlock(chip->mutex); 1862 - UDELAY(map, chip, adr, 1000000/HZ); 1863 - spin_lock(chip->mutex); 1947 + /* 1948 + * If Instant Individual Block Locking supported then no need 1949 + * to delay. 1950 + */ 1951 + 1952 + if (!extp || !(extp->FeatureSupport & (1 << 5))) 1953 + UDELAY(map, chip, adr, 1000000/HZ); 1864 1954 1865 1955 /* FIXME. Use a timer to check this, and return immediately. */ 1866 1956 /* Once the state machine's known to be working I'll do that */ ··· 1891 1973 } 1892 1974 1893 1975 /* Latency issues. Drop the lock, wait a while and retry */ 1894 - spin_unlock(chip->mutex); 1895 1976 UDELAY(map, chip, adr, 1); 1896 - spin_lock(chip->mutex); 1897 1977 } 1898 1978 1899 1979 /* Done and happy. */ ··· 1949 2033 1950 2034 return ret; 1951 2035 } 2036 + 2037 + #ifdef CONFIG_MTD_OTP 2038 + 2039 + typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip, 2040 + u_long data_offset, u_char *buf, u_int size, 2041 + u_long prot_offset, u_int groupno, u_int groupsize); 2042 + 2043 + static int __xipram 2044 + do_otp_read(struct map_info *map, struct flchip *chip, u_long offset, 2045 + u_char *buf, u_int size, u_long prot, u_int grpno, u_int grpsz) 2046 + { 2047 + struct cfi_private *cfi = map->fldrv_priv; 2048 + int ret; 2049 + 2050 + spin_lock(chip->mutex); 2051 + ret = get_chip(map, chip, chip->start, FL_JEDEC_QUERY); 2052 + if (ret) { 2053 + spin_unlock(chip->mutex); 2054 + return ret; 2055 + } 2056 + 2057 + /* let's ensure we're not reading back cached data from array mode */ 2058 + INVALIDATE_CACHED_RANGE(map, chip->start + offset, size); 2059 + 2060 + xip_disable(map, chip, chip->start); 2061 + if (chip->state != FL_JEDEC_QUERY) { 2062 + map_write(map, CMD(0x90), chip->start); 2063 + chip->state = FL_JEDEC_QUERY; 2064 + } 2065 + map_copy_from(map, buf, chip->start + offset, size); 2066 + xip_enable(map, chip, chip->start); 2067 + 2068 + /* then ensure we don't keep OTP data in the cache */ 2069 + INVALIDATE_CACHED_RANGE(map, chip->start + offset, size); 2070 + 2071 + put_chip(map, chip, chip->start); 2072 + spin_unlock(chip->mutex); 2073 + return 0; 2074 + } 2075 + 2076 + static int 2077 + do_otp_write(struct map_info *map, struct flchip *chip, u_long offset, 2078 + u_char *buf, u_int size, u_long prot, u_int grpno, u_int grpsz) 2079 + { 2080 + int ret; 2081 + 2082 + while (size) { 2083 + unsigned long bus_ofs = offset & ~(map_bankwidth(map)-1); 2084 + int gap = offset - bus_ofs; 2085 + int n = min_t(int, size, map_bankwidth(map)-gap); 2086 + map_word datum = map_word_ff(map); 2087 + 2088 + datum = map_word_load_partial(map, datum, buf, gap, n); 2089 + ret = do_write_oneword(map, chip, bus_ofs, datum, FL_OTP_WRITE); 2090 + if (ret) 2091 + return ret; 2092 + 2093 + offset += n; 2094 + buf += n; 2095 + size -= n; 2096 + } 2097 + 2098 + return 0; 2099 + } 2100 + 2101 + static int 2102 + do_otp_lock(struct map_info *map, struct flchip *chip, u_long offset, 2103 + u_char *buf, u_int size, u_long prot, u_int grpno, u_int grpsz) 2104 + { 2105 + struct cfi_private *cfi = map->fldrv_priv; 2106 + map_word datum; 2107 + 2108 + /* make sure area matches group boundaries */ 2109 + if (size != grpsz) 2110 + return -EXDEV; 2111 + 2112 + datum = map_word_ff(map); 2113 + datum = map_word_clr(map, datum, CMD(1 << grpno)); 2114 + return do_write_oneword(map, chip, prot, datum, FL_OTP_WRITE); 2115 + } 2116 + 2117 + static int cfi_intelext_otp_walk(struct mtd_info *mtd, loff_t from, size_t len, 2118 + size_t *retlen, u_char *buf, 2119 + otp_op_t action, int user_regs) 2120 + { 2121 + struct map_info *map = mtd->priv; 2122 + struct cfi_private *cfi = map->fldrv_priv; 2123 + struct cfi_pri_intelext *extp = cfi->cmdset_priv; 2124 + struct flchip *chip; 2125 + struct cfi_intelext_otpinfo *otp; 2126 + u_long devsize, reg_prot_offset, data_offset; 2127 + u_int chip_num, chip_step, field, reg_fact_size, reg_user_size; 2128 + u_int groups, groupno, groupsize, reg_fact_groups, reg_user_groups; 2129 + int ret; 2130 + 2131 + *retlen = 0; 2132 + 2133 + /* Check that we actually have some OTP registers */ 2134 + if (!extp || !(extp->FeatureSupport & 64) || !extp->NumProtectionFields) 2135 + return -ENODATA; 2136 + 2137 + /* we need real chips here not virtual ones */ 2138 + devsize = (1 << cfi->cfiq->DevSize) * cfi->interleave; 2139 + chip_step = devsize >> cfi->chipshift; 2140 + chip_num = 0; 2141 + 2142 + /* Some chips have OTP located in the _top_ partition only. 2143 + For example: Intel 28F256L18T (T means top-parameter device) */ 2144 + if (cfi->mfr == MANUFACTURER_INTEL) { 2145 + switch (cfi->id) { 2146 + case 0x880b: 2147 + case 0x880c: 2148 + case 0x880d: 2149 + chip_num = chip_step - 1; 2150 + } 2151 + } 2152 + 2153 + for ( ; chip_num < cfi->numchips; chip_num += chip_step) { 2154 + chip = &cfi->chips[chip_num]; 2155 + otp = (struct cfi_intelext_otpinfo *)&extp->extra[0]; 2156 + 2157 + /* first OTP region */ 2158 + field = 0; 2159 + reg_prot_offset = extp->ProtRegAddr; 2160 + reg_fact_groups = 1; 2161 + reg_fact_size = 1 << extp->FactProtRegSize; 2162 + reg_user_groups = 1; 2163 + reg_user_size = 1 << extp->UserProtRegSize; 2164 + 2165 + while (len > 0) { 2166 + /* flash geometry fixup */ 2167 + data_offset = reg_prot_offset + 1; 2168 + data_offset *= cfi->interleave * cfi->device_type; 2169 + reg_prot_offset *= cfi->interleave * cfi->device_type; 2170 + reg_fact_size *= cfi->interleave; 2171 + reg_user_size *= cfi->interleave; 2172 + 2173 + if (user_regs) { 2174 + groups = reg_user_groups; 2175 + groupsize = reg_user_size; 2176 + /* skip over factory reg area */ 2177 + groupno = reg_fact_groups; 2178 + data_offset += reg_fact_groups * reg_fact_size; 2179 + } else { 2180 + groups = reg_fact_groups; 2181 + groupsize = reg_fact_size; 2182 + groupno = 0; 2183 + } 2184 + 2185 + while (len > 0 && groups > 0) { 2186 + if (!action) { 2187 + /* 2188 + * Special case: if action is NULL 2189 + * we fill buf with otp_info records. 2190 + */ 2191 + struct otp_info *otpinfo; 2192 + map_word lockword; 2193 + len -= sizeof(struct otp_info); 2194 + if (len <= 0) 2195 + return -ENOSPC; 2196 + ret = do_otp_read(map, chip, 2197 + reg_prot_offset, 2198 + (u_char *)&lockword, 2199 + map_bankwidth(map), 2200 + 0, 0, 0); 2201 + if (ret) 2202 + return ret; 2203 + otpinfo = (struct otp_info *)buf; 2204 + otpinfo->start = from; 2205 + otpinfo->length = groupsize; 2206 + otpinfo->locked = 2207 + !map_word_bitsset(map, lockword, 2208 + CMD(1 << groupno)); 2209 + from += groupsize; 2210 + buf += sizeof(*otpinfo); 2211 + *retlen += sizeof(*otpinfo); 2212 + } else if (from >= groupsize) { 2213 + from -= groupsize; 2214 + data_offset += groupsize; 2215 + } else { 2216 + int size = groupsize; 2217 + data_offset += from; 2218 + size -= from; 2219 + from = 0; 2220 + if (size > len) 2221 + size = len; 2222 + ret = action(map, chip, data_offset, 2223 + buf, size, reg_prot_offset, 2224 + groupno, groupsize); 2225 + if (ret < 0) 2226 + return ret; 2227 + buf += size; 2228 + len -= size; 2229 + *retlen += size; 2230 + data_offset += size; 2231 + } 2232 + groupno++; 2233 + groups--; 2234 + } 2235 + 2236 + /* next OTP region */ 2237 + if (++field == extp->NumProtectionFields) 2238 + break; 2239 + reg_prot_offset = otp->ProtRegAddr; 2240 + reg_fact_groups = otp->FactGroups; 2241 + reg_fact_size = 1 << otp->FactProtRegSize; 2242 + reg_user_groups = otp->UserGroups; 2243 + reg_user_size = 1 << otp->UserProtRegSize; 2244 + otp++; 2245 + } 2246 + } 2247 + 2248 + return 0; 2249 + } 2250 + 2251 + static int cfi_intelext_read_fact_prot_reg(struct mtd_info *mtd, loff_t from, 2252 + size_t len, size_t *retlen, 2253 + u_char *buf) 2254 + { 2255 + return cfi_intelext_otp_walk(mtd, from, len, retlen, 2256 + buf, do_otp_read, 0); 2257 + } 2258 + 2259 + static int cfi_intelext_read_user_prot_reg(struct mtd_info *mtd, loff_t from, 2260 + size_t len, size_t *retlen, 2261 + u_char *buf) 2262 + { 2263 + return cfi_intelext_otp_walk(mtd, from, len, retlen, 2264 + buf, do_otp_read, 1); 2265 + } 2266 + 2267 + static int cfi_intelext_write_user_prot_reg(struct mtd_info *mtd, loff_t from, 2268 + size_t len, size_t *retlen, 2269 + u_char *buf) 2270 + { 2271 + return cfi_intelext_otp_walk(mtd, from, len, retlen, 2272 + buf, do_otp_write, 1); 2273 + } 2274 + 2275 + static int cfi_intelext_lock_user_prot_reg(struct mtd_info *mtd, 2276 + loff_t from, size_t len) 2277 + { 2278 + size_t retlen; 2279 + return cfi_intelext_otp_walk(mtd, from, len, &retlen, 2280 + NULL, do_otp_lock, 1); 2281 + } 2282 + 2283 + static int cfi_intelext_get_fact_prot_info(struct mtd_info *mtd, 2284 + struct otp_info *buf, size_t len) 2285 + { 2286 + size_t retlen; 2287 + int ret; 2288 + 2289 + ret = cfi_intelext_otp_walk(mtd, 0, len, &retlen, (u_char *)buf, NULL, 0); 2290 + return ret ? : retlen; 2291 + } 2292 + 2293 + static int cfi_intelext_get_user_prot_info(struct mtd_info *mtd, 2294 + struct otp_info *buf, size_t len) 2295 + { 2296 + size_t retlen; 2297 + int ret; 2298 + 2299 + ret = cfi_intelext_otp_walk(mtd, 0, len, &retlen, (u_char *)buf, NULL, 1); 2300 + return ret ? : retlen; 2301 + } 2302 + 2303 + #endif 1952 2304 1953 2305 static int cfi_intelext_suspend(struct mtd_info *mtd) 1954 2306 { ··· 2309 2125 } 2310 2126 } 2311 2127 2128 + static int cfi_intelext_reset(struct mtd_info *mtd) 2129 + { 2130 + struct map_info *map = mtd->priv; 2131 + struct cfi_private *cfi = map->fldrv_priv; 2132 + int i, ret; 2133 + 2134 + for (i=0; i < cfi->numchips; i++) { 2135 + struct flchip *chip = &cfi->chips[i]; 2136 + 2137 + /* force the completion of any ongoing operation 2138 + and switch to array mode so any bootloader in 2139 + flash is accessible for soft reboot. */ 2140 + spin_lock(chip->mutex); 2141 + ret = get_chip(map, chip, chip->start, FL_SYNCING); 2142 + if (!ret) { 2143 + map_write(map, CMD(0xff), chip->start); 2144 + chip->state = FL_READY; 2145 + } 2146 + spin_unlock(chip->mutex); 2147 + } 2148 + 2149 + return 0; 2150 + } 2151 + 2152 + static int cfi_intelext_reboot(struct notifier_block *nb, unsigned long val, 2153 + void *v) 2154 + { 2155 + struct mtd_info *mtd; 2156 + 2157 + mtd = container_of(nb, struct mtd_info, reboot_notifier); 2158 + cfi_intelext_reset(mtd); 2159 + return NOTIFY_DONE; 2160 + } 2161 + 2312 2162 static void cfi_intelext_destroy(struct mtd_info *mtd) 2313 2163 { 2314 2164 struct map_info *map = mtd->priv; 2315 2165 struct cfi_private *cfi = map->fldrv_priv; 2166 + cfi_intelext_reset(mtd); 2167 + unregister_reboot_notifier(&mtd->reboot_notifier); 2316 2168 kfree(cfi->cmdset_priv); 2317 2169 kfree(cfi->cfiq); 2318 2170 kfree(cfi->chips[0].priv);
+380 -123
drivers/mtd/chips/cfi_cmdset_0002.c
··· 4 4 * 5 5 * Copyright (C) 2000 Crossnet Co. <info@crossnet.co.jp> 6 6 * Copyright (C) 2004 Arcom Control Systems Ltd <linux@arcom.com> 7 + * Copyright (C) 2005 MontaVista Software Inc. <source@mvista.com> 7 8 * 8 9 * 2_by_8 routines added by Simon Munton 9 10 * 10 11 * 4_by_16 work by Carolyn J. Smith 11 12 * 13 + * XIP support hooks by Vitaly Wool (based on code for Intel flash 14 + * by Nicolas Pitre) 15 + * 12 16 * Occasionally maintained by Thayne Harbaugh tharbaugh at lnxi dot com 13 17 * 14 18 * This code is GPL 15 19 * 16 - * $Id: cfi_cmdset_0002.c,v 1.114 2004/12/11 15:43:53 dedekind Exp $ 20 + * $Id: cfi_cmdset_0002.c,v 1.118 2005/07/04 22:34:29 gleixner Exp $ 17 21 * 18 22 */ 19 23 ··· 38 34 #include <linux/mtd/map.h> 39 35 #include <linux/mtd/mtd.h> 40 36 #include <linux/mtd/cfi.h> 37 + #include <linux/mtd/xip.h> 41 38 42 39 #define AMD_BOOTLOC_BUG 43 40 #define FORCE_WORD_WRITE 0 ··· 48 43 #define MANUFACTURER_AMD 0x0001 49 44 #define MANUFACTURER_SST 0x00BF 50 45 #define SST49LF004B 0x0060 46 + #define SST49LF008A 0x005a 51 47 52 48 static int cfi_amdstd_read (struct mtd_info *, loff_t, size_t, size_t *, u_char *); 53 49 static int cfi_amdstd_write_words(struct mtd_info *, loff_t, size_t, size_t *, const u_char *); ··· 197 191 }; 198 192 static struct cfi_fixup jedec_fixup_table[] = { 199 193 { MANUFACTURER_SST, SST49LF004B, fixup_use_fwh_lock, NULL, }, 194 + { MANUFACTURER_SST, SST49LF008A, fixup_use_fwh_lock, NULL, }, 200 195 { 0, 0, NULL, NULL } 201 196 }; 202 197 ··· 398 391 * correctly and is therefore not done (particulary with interleaved chips 399 392 * as each chip must be checked independantly of the others). 400 393 */ 401 - static int chip_ready(struct map_info *map, unsigned long addr) 394 + static int __xipram chip_ready(struct map_info *map, unsigned long addr) 402 395 { 403 396 map_word d, t; 404 397 ··· 406 399 t = map_read(map, addr); 407 400 408 401 return map_word_equal(map, d, t); 402 + } 403 + 404 + /* 405 + * Return true if the chip is ready and has the correct value. 406 + * 407 + * Ready is one of: read mode, query mode, erase-suspend-read mode (in any 408 + * non-suspended sector) and it is indicated by no bits toggling. 409 + * 410 + * Error are indicated by toggling bits or bits held with the wrong value, 411 + * or with bits toggling. 412 + * 413 + * Note that anything more complicated than checking if no bits are toggling 414 + * (including checking DQ5 for an error status) is tricky to get working 415 + * correctly and is therefore not done (particulary with interleaved chips 416 + * as each chip must be checked independantly of the others). 417 + * 418 + */ 419 + static int __xipram chip_good(struct map_info *map, unsigned long addr, map_word expected) 420 + { 421 + map_word oldd, curd; 422 + 423 + oldd = map_read(map, addr); 424 + curd = map_read(map, addr); 425 + 426 + return map_word_equal(map, oldd, curd) && 427 + map_word_equal(map, curd, expected); 409 428 } 410 429 411 430 static int get_chip(struct map_info *map, struct flchip *chip, unsigned long adr, int mode) ··· 453 420 454 421 if (time_after(jiffies, timeo)) { 455 422 printk(KERN_ERR "Waiting for chip to be ready timed out.\n"); 456 - cfi_spin_unlock(chip->mutex); 423 + spin_unlock(chip->mutex); 457 424 return -EIO; 458 425 } 459 - cfi_spin_unlock(chip->mutex); 426 + spin_unlock(chip->mutex); 460 427 cfi_udelay(1); 461 - cfi_spin_lock(chip->mutex); 428 + spin_lock(chip->mutex); 462 429 /* Someone else might have been playing with it. */ 463 430 goto retry; 464 431 } ··· 506 473 return -EIO; 507 474 } 508 475 509 - cfi_spin_unlock(chip->mutex); 476 + spin_unlock(chip->mutex); 510 477 cfi_udelay(1); 511 - cfi_spin_lock(chip->mutex); 478 + spin_lock(chip->mutex); 512 479 /* Nobody will touch it while it's in state FL_ERASE_SUSPENDING. 513 480 So we can just loop here. */ 514 481 } 482 + chip->state = FL_READY; 483 + return 0; 484 + 485 + case FL_XIP_WHILE_ERASING: 486 + if (mode != FL_READY && mode != FL_POINT && 487 + (!cfip || !(cfip->EraseSuspend&2))) 488 + goto sleep; 489 + chip->oldstate = chip->state; 515 490 chip->state = FL_READY; 516 491 return 0; 517 492 ··· 532 491 sleep: 533 492 set_current_state(TASK_UNINTERRUPTIBLE); 534 493 add_wait_queue(&chip->wq, &wait); 535 - cfi_spin_unlock(chip->mutex); 494 + spin_unlock(chip->mutex); 536 495 schedule(); 537 496 remove_wait_queue(&chip->wq, &wait); 538 - cfi_spin_lock(chip->mutex); 497 + spin_lock(chip->mutex); 539 498 goto resettime; 540 499 } 541 500 } ··· 553 512 chip->state = FL_ERASING; 554 513 break; 555 514 515 + case FL_XIP_WHILE_ERASING: 516 + chip->state = chip->oldstate; 517 + chip->oldstate = FL_READY; 518 + break; 519 + 556 520 case FL_READY: 557 521 case FL_STATUS: 558 522 /* We should really make set_vpp() count, rather than doing this */ ··· 569 523 wake_up(&chip->wq); 570 524 } 571 525 526 + #ifdef CONFIG_MTD_XIP 527 + 528 + /* 529 + * No interrupt what so ever can be serviced while the flash isn't in array 530 + * mode. This is ensured by the xip_disable() and xip_enable() functions 531 + * enclosing any code path where the flash is known not to be in array mode. 532 + * And within a XIP disabled code path, only functions marked with __xipram 533 + * may be called and nothing else (it's a good thing to inspect generated 534 + * assembly to make sure inline functions were actually inlined and that gcc 535 + * didn't emit calls to its own support functions). Also configuring MTD CFI 536 + * support to a single buswidth and a single interleave is also recommended. 537 + */ 538 + 539 + static void xip_disable(struct map_info *map, struct flchip *chip, 540 + unsigned long adr) 541 + { 542 + /* TODO: chips with no XIP use should ignore and return */ 543 + (void) map_read(map, adr); /* ensure mmu mapping is up to date */ 544 + local_irq_disable(); 545 + } 546 + 547 + static void __xipram xip_enable(struct map_info *map, struct flchip *chip, 548 + unsigned long adr) 549 + { 550 + struct cfi_private *cfi = map->fldrv_priv; 551 + 552 + if (chip->state != FL_POINT && chip->state != FL_READY) { 553 + map_write(map, CMD(0xf0), adr); 554 + chip->state = FL_READY; 555 + } 556 + (void) map_read(map, adr); 557 + xip_iprefetch(); 558 + local_irq_enable(); 559 + } 560 + 561 + /* 562 + * When a delay is required for the flash operation to complete, the 563 + * xip_udelay() function is polling for both the given timeout and pending 564 + * (but still masked) hardware interrupts. Whenever there is an interrupt 565 + * pending then the flash erase operation is suspended, array mode restored 566 + * and interrupts unmasked. Task scheduling might also happen at that 567 + * point. The CPU eventually returns from the interrupt or the call to 568 + * schedule() and the suspended flash operation is resumed for the remaining 569 + * of the delay period. 570 + * 571 + * Warning: this function _will_ fool interrupt latency tracing tools. 572 + */ 573 + 574 + static void __xipram xip_udelay(struct map_info *map, struct flchip *chip, 575 + unsigned long adr, int usec) 576 + { 577 + struct cfi_private *cfi = map->fldrv_priv; 578 + struct cfi_pri_amdstd *extp = cfi->cmdset_priv; 579 + map_word status, OK = CMD(0x80); 580 + unsigned long suspended, start = xip_currtime(); 581 + flstate_t oldstate; 582 + 583 + do { 584 + cpu_relax(); 585 + if (xip_irqpending() && extp && 586 + ((chip->state == FL_ERASING && (extp->EraseSuspend & 2))) && 587 + (cfi_interleave_is_1(cfi) || chip->oldstate == FL_READY)) { 588 + /* 589 + * Let's suspend the erase operation when supported. 590 + * Note that we currently don't try to suspend 591 + * interleaved chips if there is already another 592 + * operation suspended (imagine what happens 593 + * when one chip was already done with the current 594 + * operation while another chip suspended it, then 595 + * we resume the whole thing at once). Yes, it 596 + * can happen! 597 + */ 598 + map_write(map, CMD(0xb0), adr); 599 + usec -= xip_elapsed_since(start); 600 + suspended = xip_currtime(); 601 + do { 602 + if (xip_elapsed_since(suspended) > 100000) { 603 + /* 604 + * The chip doesn't want to suspend 605 + * after waiting for 100 msecs. 606 + * This is a critical error but there 607 + * is not much we can do here. 608 + */ 609 + return; 610 + } 611 + status = map_read(map, adr); 612 + } while (!map_word_andequal(map, status, OK, OK)); 613 + 614 + /* Suspend succeeded */ 615 + oldstate = chip->state; 616 + if (!map_word_bitsset(map, status, CMD(0x40))) 617 + break; 618 + chip->state = FL_XIP_WHILE_ERASING; 619 + chip->erase_suspended = 1; 620 + map_write(map, CMD(0xf0), adr); 621 + (void) map_read(map, adr); 622 + asm volatile (".rep 8; nop; .endr"); 623 + local_irq_enable(); 624 + spin_unlock(chip->mutex); 625 + asm volatile (".rep 8; nop; .endr"); 626 + cond_resched(); 627 + 628 + /* 629 + * We're back. However someone else might have 630 + * decided to go write to the chip if we are in 631 + * a suspended erase state. If so let's wait 632 + * until it's done. 633 + */ 634 + spin_lock(chip->mutex); 635 + while (chip->state != FL_XIP_WHILE_ERASING) { 636 + DECLARE_WAITQUEUE(wait, current); 637 + set_current_state(TASK_UNINTERRUPTIBLE); 638 + add_wait_queue(&chip->wq, &wait); 639 + spin_unlock(chip->mutex); 640 + schedule(); 641 + remove_wait_queue(&chip->wq, &wait); 642 + spin_lock(chip->mutex); 643 + } 644 + /* Disallow XIP again */ 645 + local_irq_disable(); 646 + 647 + /* Resume the write or erase operation */ 648 + map_write(map, CMD(0x30), adr); 649 + chip->state = oldstate; 650 + start = xip_currtime(); 651 + } else if (usec >= 1000000/HZ) { 652 + /* 653 + * Try to save on CPU power when waiting delay 654 + * is at least a system timer tick period. 655 + * No need to be extremely accurate here. 656 + */ 657 + xip_cpu_idle(); 658 + } 659 + status = map_read(map, adr); 660 + } while (!map_word_andequal(map, status, OK, OK) 661 + && xip_elapsed_since(start) < usec); 662 + } 663 + 664 + #define UDELAY(map, chip, adr, usec) xip_udelay(map, chip, adr, usec) 665 + 666 + /* 667 + * The INVALIDATE_CACHED_RANGE() macro is normally used in parallel while 668 + * the flash is actively programming or erasing since we have to poll for 669 + * the operation to complete anyway. We can't do that in a generic way with 670 + * a XIP setup so do it before the actual flash operation in this case 671 + * and stub it out from INVALIDATE_CACHE_UDELAY. 672 + */ 673 + #define XIP_INVAL_CACHED_RANGE(map, from, size) \ 674 + INVALIDATE_CACHED_RANGE(map, from, size) 675 + 676 + #define INVALIDATE_CACHE_UDELAY(map, chip, adr, len, usec) \ 677 + UDELAY(map, chip, adr, usec) 678 + 679 + /* 680 + * Extra notes: 681 + * 682 + * Activating this XIP support changes the way the code works a bit. For 683 + * example the code to suspend the current process when concurrent access 684 + * happens is never executed because xip_udelay() will always return with the 685 + * same chip state as it was entered with. This is why there is no care for 686 + * the presence of add_wait_queue() or schedule() calls from within a couple 687 + * xip_disable()'d areas of code, like in do_erase_oneblock for example. 688 + * The queueing and scheduling are always happening within xip_udelay(). 689 + * 690 + * Similarly, get_chip() and put_chip() just happen to always be executed 691 + * with chip->state set to FL_READY (or FL_XIP_WHILE_*) where flash state 692 + * is in array mode, therefore never executing many cases therein and not 693 + * causing any problem with XIP. 694 + */ 695 + 696 + #else 697 + 698 + #define xip_disable(map, chip, adr) 699 + #define xip_enable(map, chip, adr) 700 + #define XIP_INVAL_CACHED_RANGE(x...) 701 + 702 + #define UDELAY(map, chip, adr, usec) \ 703 + do { \ 704 + spin_unlock(chip->mutex); \ 705 + cfi_udelay(usec); \ 706 + spin_lock(chip->mutex); \ 707 + } while (0) 708 + 709 + #define INVALIDATE_CACHE_UDELAY(map, chip, adr, len, usec) \ 710 + do { \ 711 + spin_unlock(chip->mutex); \ 712 + INVALIDATE_CACHED_RANGE(map, adr, len); \ 713 + cfi_udelay(usec); \ 714 + spin_lock(chip->mutex); \ 715 + } while (0) 716 + 717 + #endif 572 718 573 719 static inline int do_read_onechip(struct map_info *map, struct flchip *chip, loff_t adr, size_t len, u_char *buf) 574 720 { ··· 773 535 /* Ensure cmd read/writes are aligned. */ 774 536 cmd_addr = adr & ~(map_bankwidth(map)-1); 775 537 776 - cfi_spin_lock(chip->mutex); 538 + spin_lock(chip->mutex); 777 539 ret = get_chip(map, chip, cmd_addr, FL_READY); 778 540 if (ret) { 779 - cfi_spin_unlock(chip->mutex); 541 + spin_unlock(chip->mutex); 780 542 return ret; 781 543 } 782 544 ··· 789 551 790 552 put_chip(map, chip, cmd_addr); 791 553 792 - cfi_spin_unlock(chip->mutex); 554 + spin_unlock(chip->mutex); 793 555 return 0; 794 556 } 795 557 ··· 843 605 struct cfi_private *cfi = map->fldrv_priv; 844 606 845 607 retry: 846 - cfi_spin_lock(chip->mutex); 608 + spin_lock(chip->mutex); 847 609 848 610 if (chip->state != FL_READY){ 849 611 #if 0 ··· 852 614 set_current_state(TASK_UNINTERRUPTIBLE); 853 615 add_wait_queue(&chip->wq, &wait); 854 616 855 - cfi_spin_unlock(chip->mutex); 617 + spin_unlock(chip->mutex); 856 618 857 619 schedule(); 858 620 remove_wait_queue(&chip->wq, &wait); ··· 881 643 cfi_send_gen_cmd(0x00, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 882 644 883 645 wake_up(&chip->wq); 884 - cfi_spin_unlock(chip->mutex); 646 + spin_unlock(chip->mutex); 885 647 886 648 return 0; 887 649 } ··· 930 692 } 931 693 932 694 933 - static int do_write_oneword(struct map_info *map, struct flchip *chip, unsigned long adr, map_word datum) 695 + static int __xipram do_write_oneword(struct map_info *map, struct flchip *chip, unsigned long adr, map_word datum) 934 696 { 935 697 struct cfi_private *cfi = map->fldrv_priv; 936 698 unsigned long timeo = jiffies + HZ; ··· 950 712 951 713 adr += chip->start; 952 714 953 - cfi_spin_lock(chip->mutex); 715 + spin_lock(chip->mutex); 954 716 ret = get_chip(map, chip, adr, FL_WRITING); 955 717 if (ret) { 956 - cfi_spin_unlock(chip->mutex); 718 + spin_unlock(chip->mutex); 957 719 return ret; 958 720 } 959 721 ··· 973 735 goto op_done; 974 736 } 975 737 738 + XIP_INVAL_CACHED_RANGE(map, adr, map_bankwidth(map)); 976 739 ENABLE_VPP(map); 740 + xip_disable(map, chip, adr); 977 741 retry: 978 742 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 979 743 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); ··· 983 743 map_write(map, datum, adr); 984 744 chip->state = FL_WRITING; 985 745 986 - cfi_spin_unlock(chip->mutex); 987 - cfi_udelay(chip->word_write_time); 988 - cfi_spin_lock(chip->mutex); 746 + INVALIDATE_CACHE_UDELAY(map, chip, 747 + adr, map_bankwidth(map), 748 + chip->word_write_time); 989 749 990 750 /* See comment above for timeout value. */ 991 751 timeo = jiffies + uWriteTimeout; ··· 996 756 997 757 set_current_state(TASK_UNINTERRUPTIBLE); 998 758 add_wait_queue(&chip->wq, &wait); 999 - cfi_spin_unlock(chip->mutex); 759 + spin_unlock(chip->mutex); 1000 760 schedule(); 1001 761 remove_wait_queue(&chip->wq, &wait); 1002 762 timeo = jiffies + (HZ / 2); /* FIXME */ 1003 - cfi_spin_lock(chip->mutex); 763 + spin_lock(chip->mutex); 1004 764 continue; 1005 765 } 1006 766 1007 767 if (chip_ready(map, adr)) 1008 - goto op_done; 768 + break; 1009 769 1010 - if (time_after(jiffies, timeo)) 770 + if (time_after(jiffies, timeo)) { 771 + xip_enable(map, chip, adr); 772 + printk(KERN_WARNING "MTD %s(): software timeout\n", __func__); 773 + xip_disable(map, chip, adr); 1011 774 break; 775 + } 1012 776 1013 777 /* Latency issues. Drop the lock, wait a while and retry */ 1014 - cfi_spin_unlock(chip->mutex); 1015 - cfi_udelay(1); 1016 - cfi_spin_lock(chip->mutex); 778 + UDELAY(map, chip, adr, 1); 1017 779 } 780 + /* Did we succeed? */ 781 + if (!chip_good(map, adr, datum)) { 782 + /* reset on all failures. */ 783 + map_write( map, CMD(0xF0), chip->start ); 784 + /* FIXME - should have reset delay before continuing */ 1018 785 1019 - printk(KERN_WARNING "MTD %s(): software timeout\n", __func__); 786 + if (++retry_cnt <= MAX_WORD_RETRIES) 787 + goto retry; 1020 788 1021 - /* reset on all failures. */ 1022 - map_write( map, CMD(0xF0), chip->start ); 1023 - /* FIXME - should have reset delay before continuing */ 1024 - if (++retry_cnt <= MAX_WORD_RETRIES) 1025 - goto retry; 1026 - 1027 - ret = -EIO; 789 + ret = -EIO; 790 + } 791 + xip_enable(map, chip, adr); 1028 792 op_done: 1029 793 chip->state = FL_READY; 1030 794 put_chip(map, chip, adr); 1031 - cfi_spin_unlock(chip->mutex); 795 + spin_unlock(chip->mutex); 1032 796 1033 797 return ret; 1034 798 } ··· 1064 820 map_word tmp_buf; 1065 821 1066 822 retry: 1067 - cfi_spin_lock(cfi->chips[chipnum].mutex); 823 + spin_lock(cfi->chips[chipnum].mutex); 1068 824 1069 825 if (cfi->chips[chipnum].state != FL_READY) { 1070 826 #if 0 ··· 1073 829 set_current_state(TASK_UNINTERRUPTIBLE); 1074 830 add_wait_queue(&cfi->chips[chipnum].wq, &wait); 1075 831 1076 - cfi_spin_unlock(cfi->chips[chipnum].mutex); 832 + spin_unlock(cfi->chips[chipnum].mutex); 1077 833 1078 834 schedule(); 1079 835 remove_wait_queue(&cfi->chips[chipnum].wq, &wait); ··· 1087 843 /* Load 'tmp_buf' with old contents of flash */ 1088 844 tmp_buf = map_read(map, bus_ofs+chipstart); 1089 845 1090 - cfi_spin_unlock(cfi->chips[chipnum].mutex); 846 + spin_unlock(cfi->chips[chipnum].mutex); 1091 847 1092 848 /* Number of bytes to copy from buffer */ 1093 849 n = min_t(int, len, map_bankwidth(map)-i); ··· 1142 898 map_word tmp_buf; 1143 899 1144 900 retry1: 1145 - cfi_spin_lock(cfi->chips[chipnum].mutex); 901 + spin_lock(cfi->chips[chipnum].mutex); 1146 902 1147 903 if (cfi->chips[chipnum].state != FL_READY) { 1148 904 #if 0 ··· 1151 907 set_current_state(TASK_UNINTERRUPTIBLE); 1152 908 add_wait_queue(&cfi->chips[chipnum].wq, &wait); 1153 909 1154 - cfi_spin_unlock(cfi->chips[chipnum].mutex); 910 + spin_unlock(cfi->chips[chipnum].mutex); 1155 911 1156 912 schedule(); 1157 913 remove_wait_queue(&cfi->chips[chipnum].wq, &wait); ··· 1164 920 1165 921 tmp_buf = map_read(map, ofs + chipstart); 1166 922 1167 - cfi_spin_unlock(cfi->chips[chipnum].mutex); 923 + spin_unlock(cfi->chips[chipnum].mutex); 1168 924 1169 925 tmp_buf = map_word_load_partial(map, tmp_buf, buf, 0, len); 1170 926 ··· 1183 939 /* 1184 940 * FIXME: interleaved mode not tested, and probably not supported! 1185 941 */ 1186 - static inline int do_write_buffer(struct map_info *map, struct flchip *chip, 1187 - unsigned long adr, const u_char *buf, int len) 942 + static int __xipram do_write_buffer(struct map_info *map, struct flchip *chip, 943 + unsigned long adr, const u_char *buf, 944 + int len) 1188 945 { 1189 946 struct cfi_private *cfi = map->fldrv_priv; 1190 947 unsigned long timeo = jiffies + HZ; ··· 1199 954 adr += chip->start; 1200 955 cmd_adr = adr; 1201 956 1202 - cfi_spin_lock(chip->mutex); 957 + spin_lock(chip->mutex); 1203 958 ret = get_chip(map, chip, adr, FL_WRITING); 1204 959 if (ret) { 1205 - cfi_spin_unlock(chip->mutex); 960 + spin_unlock(chip->mutex); 1206 961 return ret; 1207 962 } 1208 963 ··· 1211 966 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): WRITE 0x%.8lx(0x%.8lx)\n", 1212 967 __func__, adr, datum.x[0] ); 1213 968 969 + XIP_INVAL_CACHED_RANGE(map, adr, len); 1214 970 ENABLE_VPP(map); 971 + xip_disable(map, chip, cmd_adr); 972 + 1215 973 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 1216 974 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); 1217 975 //cfi_send_gen_cmd(0xA0, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); ··· 1244 996 map_write(map, CMD(0x29), cmd_adr); 1245 997 chip->state = FL_WRITING; 1246 998 1247 - cfi_spin_unlock(chip->mutex); 1248 - cfi_udelay(chip->buffer_write_time); 1249 - cfi_spin_lock(chip->mutex); 999 + INVALIDATE_CACHE_UDELAY(map, chip, 1000 + adr, map_bankwidth(map), 1001 + chip->word_write_time); 1250 1002 1251 1003 timeo = jiffies + uWriteTimeout; 1252 1004 ··· 1257 1009 1258 1010 set_current_state(TASK_UNINTERRUPTIBLE); 1259 1011 add_wait_queue(&chip->wq, &wait); 1260 - cfi_spin_unlock(chip->mutex); 1012 + spin_unlock(chip->mutex); 1261 1013 schedule(); 1262 1014 remove_wait_queue(&chip->wq, &wait); 1263 1015 timeo = jiffies + (HZ / 2); /* FIXME */ 1264 - cfi_spin_lock(chip->mutex); 1016 + spin_lock(chip->mutex); 1265 1017 continue; 1266 1018 } 1267 1019 1268 - if (chip_ready(map, adr)) 1020 + if (chip_ready(map, adr)) { 1021 + xip_enable(map, chip, adr); 1269 1022 goto op_done; 1023 + } 1270 1024 1271 1025 if( time_after(jiffies, timeo)) 1272 1026 break; 1273 1027 1274 1028 /* Latency issues. Drop the lock, wait a while and retry */ 1275 - cfi_spin_unlock(chip->mutex); 1276 - cfi_udelay(1); 1277 - cfi_spin_lock(chip->mutex); 1029 + UDELAY(map, chip, adr, 1); 1278 1030 } 1279 - 1280 - printk(KERN_WARNING "MTD %s(): software timeout\n", 1281 - __func__ ); 1282 1031 1283 1032 /* reset on all failures. */ 1284 1033 map_write( map, CMD(0xF0), chip->start ); 1034 + xip_enable(map, chip, adr); 1285 1035 /* FIXME - should have reset delay before continuing */ 1036 + 1037 + printk(KERN_WARNING "MTD %s(): software timeout\n", 1038 + __func__ ); 1286 1039 1287 1040 ret = -EIO; 1288 1041 op_done: 1289 1042 chip->state = FL_READY; 1290 1043 put_chip(map, chip, adr); 1291 - cfi_spin_unlock(chip->mutex); 1044 + spin_unlock(chip->mutex); 1292 1045 1293 1046 return ret; 1294 1047 } ··· 1379 1130 * Handle devices with one erase region, that only implement 1380 1131 * the chip erase command. 1381 1132 */ 1382 - static inline int do_erase_chip(struct map_info *map, struct flchip *chip) 1133 + static int __xipram do_erase_chip(struct map_info *map, struct flchip *chip) 1383 1134 { 1384 1135 struct cfi_private *cfi = map->fldrv_priv; 1385 1136 unsigned long timeo = jiffies + HZ; ··· 1389 1140 1390 1141 adr = cfi->addr_unlock1; 1391 1142 1392 - cfi_spin_lock(chip->mutex); 1143 + spin_lock(chip->mutex); 1393 1144 ret = get_chip(map, chip, adr, FL_WRITING); 1394 1145 if (ret) { 1395 - cfi_spin_unlock(chip->mutex); 1146 + spin_unlock(chip->mutex); 1396 1147 return ret; 1397 1148 } 1398 1149 1399 1150 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): ERASE 0x%.8lx\n", 1400 1151 __func__, chip->start ); 1401 1152 1153 + XIP_INVAL_CACHED_RANGE(map, adr, map->size); 1402 1154 ENABLE_VPP(map); 1155 + xip_disable(map, chip, adr); 1156 + 1403 1157 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 1404 1158 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); 1405 1159 cfi_send_gen_cmd(0x80, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); ··· 1414 1162 chip->erase_suspended = 0; 1415 1163 chip->in_progress_block_addr = adr; 1416 1164 1417 - cfi_spin_unlock(chip->mutex); 1418 - msleep(chip->erase_time/2); 1419 - cfi_spin_lock(chip->mutex); 1165 + INVALIDATE_CACHE_UDELAY(map, chip, 1166 + adr, map->size, 1167 + chip->erase_time*500); 1420 1168 1421 1169 timeo = jiffies + (HZ*20); 1422 1170 ··· 1425 1173 /* Someone's suspended the erase. Sleep */ 1426 1174 set_current_state(TASK_UNINTERRUPTIBLE); 1427 1175 add_wait_queue(&chip->wq, &wait); 1428 - cfi_spin_unlock(chip->mutex); 1176 + spin_unlock(chip->mutex); 1429 1177 schedule(); 1430 1178 remove_wait_queue(&chip->wq, &wait); 1431 - cfi_spin_lock(chip->mutex); 1179 + spin_lock(chip->mutex); 1432 1180 continue; 1433 1181 } 1434 1182 if (chip->erase_suspended) { ··· 1439 1187 } 1440 1188 1441 1189 if (chip_ready(map, adr)) 1442 - goto op_done; 1443 - 1444 - if (time_after(jiffies, timeo)) 1445 1190 break; 1446 1191 1192 + if (time_after(jiffies, timeo)) { 1193 + printk(KERN_WARNING "MTD %s(): software timeout\n", 1194 + __func__ ); 1195 + break; 1196 + } 1197 + 1447 1198 /* Latency issues. Drop the lock, wait a while and retry */ 1448 - cfi_spin_unlock(chip->mutex); 1449 - set_current_state(TASK_UNINTERRUPTIBLE); 1450 - schedule_timeout(1); 1451 - cfi_spin_lock(chip->mutex); 1199 + UDELAY(map, chip, adr, 1000000/HZ); 1200 + } 1201 + /* Did we succeed? */ 1202 + if (!chip_good(map, adr, map_word_ff(map))) { 1203 + /* reset on all failures. */ 1204 + map_write( map, CMD(0xF0), chip->start ); 1205 + /* FIXME - should have reset delay before continuing */ 1206 + 1207 + ret = -EIO; 1452 1208 } 1453 1209 1454 - printk(KERN_WARNING "MTD %s(): software timeout\n", 1455 - __func__ ); 1456 - 1457 - /* reset on all failures. */ 1458 - map_write( map, CMD(0xF0), chip->start ); 1459 - /* FIXME - should have reset delay before continuing */ 1460 - 1461 - ret = -EIO; 1462 - op_done: 1463 1210 chip->state = FL_READY; 1211 + xip_enable(map, chip, adr); 1464 1212 put_chip(map, chip, adr); 1465 - cfi_spin_unlock(chip->mutex); 1213 + spin_unlock(chip->mutex); 1466 1214 1467 1215 return ret; 1468 1216 } 1469 1217 1470 1218 1471 - static inline int do_erase_oneblock(struct map_info *map, struct flchip *chip, unsigned long adr, int len, void *thunk) 1219 + static int __xipram do_erase_oneblock(struct map_info *map, struct flchip *chip, unsigned long adr, int len, void *thunk) 1472 1220 { 1473 1221 struct cfi_private *cfi = map->fldrv_priv; 1474 1222 unsigned long timeo = jiffies + HZ; ··· 1477 1225 1478 1226 adr += chip->start; 1479 1227 1480 - cfi_spin_lock(chip->mutex); 1228 + spin_lock(chip->mutex); 1481 1229 ret = get_chip(map, chip, adr, FL_ERASING); 1482 1230 if (ret) { 1483 - cfi_spin_unlock(chip->mutex); 1231 + spin_unlock(chip->mutex); 1484 1232 return ret; 1485 1233 } 1486 1234 1487 1235 DEBUG( MTD_DEBUG_LEVEL3, "MTD %s(): ERASE 0x%.8lx\n", 1488 1236 __func__, adr ); 1489 1237 1238 + XIP_INVAL_CACHED_RANGE(map, adr, len); 1490 1239 ENABLE_VPP(map); 1240 + xip_disable(map, chip, adr); 1241 + 1491 1242 cfi_send_gen_cmd(0xAA, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); 1492 1243 cfi_send_gen_cmd(0x55, cfi->addr_unlock2, chip->start, map, cfi, cfi->device_type, NULL); 1493 1244 cfi_send_gen_cmd(0x80, cfi->addr_unlock1, chip->start, map, cfi, cfi->device_type, NULL); ··· 1501 1246 chip->state = FL_ERASING; 1502 1247 chip->erase_suspended = 0; 1503 1248 chip->in_progress_block_addr = adr; 1504 - 1505 - cfi_spin_unlock(chip->mutex); 1506 - msleep(chip->erase_time/2); 1507 - cfi_spin_lock(chip->mutex); 1249 + 1250 + INVALIDATE_CACHE_UDELAY(map, chip, 1251 + adr, len, 1252 + chip->erase_time*500); 1508 1253 1509 1254 timeo = jiffies + (HZ*20); 1510 1255 ··· 1513 1258 /* Someone's suspended the erase. Sleep */ 1514 1259 set_current_state(TASK_UNINTERRUPTIBLE); 1515 1260 add_wait_queue(&chip->wq, &wait); 1516 - cfi_spin_unlock(chip->mutex); 1261 + spin_unlock(chip->mutex); 1517 1262 schedule(); 1518 1263 remove_wait_queue(&chip->wq, &wait); 1519 - cfi_spin_lock(chip->mutex); 1264 + spin_lock(chip->mutex); 1520 1265 continue; 1521 1266 } 1522 1267 if (chip->erase_suspended) { ··· 1526 1271 chip->erase_suspended = 0; 1527 1272 } 1528 1273 1529 - if (chip_ready(map, adr)) 1530 - goto op_done; 1531 - 1532 - if (time_after(jiffies, timeo)) 1274 + if (chip_ready(map, adr)) { 1275 + xip_enable(map, chip, adr); 1533 1276 break; 1277 + } 1278 + 1279 + if (time_after(jiffies, timeo)) { 1280 + xip_enable(map, chip, adr); 1281 + printk(KERN_WARNING "MTD %s(): software timeout\n", 1282 + __func__ ); 1283 + break; 1284 + } 1534 1285 1535 1286 /* Latency issues. Drop the lock, wait a while and retry */ 1536 - cfi_spin_unlock(chip->mutex); 1537 - set_current_state(TASK_UNINTERRUPTIBLE); 1538 - schedule_timeout(1); 1539 - cfi_spin_lock(chip->mutex); 1287 + UDELAY(map, chip, adr, 1000000/HZ); 1540 1288 } 1541 - 1542 - printk(KERN_WARNING "MTD %s(): software timeout\n", 1543 - __func__ ); 1544 - 1545 - /* reset on all failures. */ 1546 - map_write( map, CMD(0xF0), chip->start ); 1547 - /* FIXME - should have reset delay before continuing */ 1289 + /* Did we succeed? */ 1290 + if (!chip_good(map, adr, map_word_ff(map))) { 1291 + /* reset on all failures. */ 1292 + map_write( map, CMD(0xF0), chip->start ); 1293 + /* FIXME - should have reset delay before continuing */ 1548 1294 1549 - ret = -EIO; 1550 - op_done: 1295 + ret = -EIO; 1296 + } 1297 + 1551 1298 chip->state = FL_READY; 1552 1299 put_chip(map, chip, adr); 1553 - cfi_spin_unlock(chip->mutex); 1300 + spin_unlock(chip->mutex); 1554 1301 return ret; 1555 1302 } 1556 1303 ··· 1612 1355 chip = &cfi->chips[i]; 1613 1356 1614 1357 retry: 1615 - cfi_spin_lock(chip->mutex); 1358 + spin_lock(chip->mutex); 1616 1359 1617 1360 switch(chip->state) { 1618 1361 case FL_READY: ··· 1626 1369 * with the chip now anyway. 1627 1370 */ 1628 1371 case FL_SYNCING: 1629 - cfi_spin_unlock(chip->mutex); 1372 + spin_unlock(chip->mutex); 1630 1373 break; 1631 1374 1632 1375 default: 1633 1376 /* Not an idle state */ 1634 1377 add_wait_queue(&chip->wq, &wait); 1635 1378 1636 - cfi_spin_unlock(chip->mutex); 1379 + spin_unlock(chip->mutex); 1637 1380 1638 1381 schedule(); 1639 1382 ··· 1648 1391 for (i--; i >=0; i--) { 1649 1392 chip = &cfi->chips[i]; 1650 1393 1651 - cfi_spin_lock(chip->mutex); 1394 + spin_lock(chip->mutex); 1652 1395 1653 1396 if (chip->state == FL_SYNCING) { 1654 1397 chip->state = chip->oldstate; 1655 1398 wake_up(&chip->wq); 1656 1399 } 1657 - cfi_spin_unlock(chip->mutex); 1400 + spin_unlock(chip->mutex); 1658 1401 } 1659 1402 } 1660 1403 ··· 1670 1413 for (i=0; !ret && i<cfi->numchips; i++) { 1671 1414 chip = &cfi->chips[i]; 1672 1415 1673 - cfi_spin_lock(chip->mutex); 1416 + spin_lock(chip->mutex); 1674 1417 1675 1418 switch(chip->state) { 1676 1419 case FL_READY: ··· 1690 1433 ret = -EAGAIN; 1691 1434 break; 1692 1435 } 1693 - cfi_spin_unlock(chip->mutex); 1436 + spin_unlock(chip->mutex); 1694 1437 } 1695 1438 1696 1439 /* Unlock the chips again */ ··· 1699 1442 for (i--; i >=0; i--) { 1700 1443 chip = &cfi->chips[i]; 1701 1444 1702 - cfi_spin_lock(chip->mutex); 1445 + spin_lock(chip->mutex); 1703 1446 1704 1447 if (chip->state == FL_PM_SUSPENDED) { 1705 1448 chip->state = chip->oldstate; 1706 1449 wake_up(&chip->wq); 1707 1450 } 1708 - cfi_spin_unlock(chip->mutex); 1451 + spin_unlock(chip->mutex); 1709 1452 } 1710 1453 } 1711 1454 ··· 1724 1467 1725 1468 chip = &cfi->chips[i]; 1726 1469 1727 - cfi_spin_lock(chip->mutex); 1470 + spin_lock(chip->mutex); 1728 1471 1729 1472 if (chip->state == FL_PM_SUSPENDED) { 1730 1473 chip->state = FL_READY; ··· 1734 1477 else 1735 1478 printk(KERN_ERR "Argh. Chip not in PM_SUSPENDED state upon resume()\n"); 1736 1479 1737 - cfi_spin_unlock(chip->mutex); 1480 + spin_unlock(chip->mutex); 1738 1481 } 1739 1482 } 1740 1483
+3 -3
drivers/mtd/chips/fwh_lock.h
··· 58 58 * to flash memory - that means that we don't have to check status 59 59 * and timeout. 60 60 */ 61 - cfi_spin_lock(chip->mutex); 61 + spin_lock(chip->mutex); 62 62 ret = get_chip(map, chip, adr, FL_LOCKING); 63 63 if (ret) { 64 - cfi_spin_unlock(chip->mutex); 64 + spin_unlock(chip->mutex); 65 65 return ret; 66 66 } 67 67 ··· 71 71 /* Done and happy. */ 72 72 chip->state = FL_READY; 73 73 put_chip(map, chip, adr); 74 - cfi_spin_unlock(chip->mutex); 74 + spin_unlock(chip->mutex); 75 75 return 0; 76 76 } 77 77
+2 -2
drivers/mtd/chips/gen_probe.c
··· 2 2 * Routines common to all CFI-type probes. 3 3 * (C) 2001-2003 Red Hat, Inc. 4 4 * GPL'd 5 - * $Id: gen_probe.c,v 1.21 2004/08/14 15:14:05 dwmw2 Exp $ 5 + * $Id: gen_probe.c,v 1.22 2005/01/24 23:49:50 rmk Exp $ 6 6 */ 7 7 8 8 #include <linux/kernel.h> ··· 162 162 int max_chips = map_bankwidth(map); /* And minimum 1 */ 163 163 int nr_chips, type; 164 164 165 - for (nr_chips = min_chips; nr_chips <= max_chips; nr_chips <<= 1) { 165 + for (nr_chips = max_chips; nr_chips >= min_chips; nr_chips >>= 1) { 166 166 167 167 if (!cfi_interleave_supported(nr_chips)) 168 168 continue;
+27 -1
drivers/mtd/chips/jedec_probe.c
··· 1 1 /* 2 2 Common Flash Interface probe code. 3 3 (C) 2000 Red Hat. GPL'd. 4 - $Id: jedec_probe.c,v 1.61 2004/11/19 20:52:16 thayne Exp $ 4 + $Id: jedec_probe.c,v 1.63 2005/02/14 16:30:32 bjd Exp $ 5 5 See JEDEC (http://www.jedec.org/) standard JESD21C (section 3.5) 6 6 for the standard this probe goes back to. 7 7 ··· 142 142 #define SST29LE512 0x003d 143 143 #define SST39LF800 0x2781 144 144 #define SST39LF160 0x2782 145 + #define SST39VF1601 0x234b 145 146 #define SST39LF512 0x00D4 146 147 #define SST39LF010 0x00D5 147 148 #define SST39LF020 0x00D6 ··· 1449 1448 ERASEINFO(0x1000,256), 1450 1449 ERASEINFO(0x1000,256) 1451 1450 } 1451 + }, { 1452 + .mfr_id = MANUFACTURER_SST, /* should be CFI */ 1453 + .dev_id = SST39VF1601, 1454 + .name = "SST 39VF1601", 1455 + .uaddr = { 1456 + [0] = MTD_UADDR_0x5555_0x2AAA, /* x8 */ 1457 + [1] = MTD_UADDR_0x5555_0x2AAA /* x16 */ 1458 + }, 1459 + .DevSize = SIZE_2MiB, 1460 + .CmdSet = P_ID_AMD_STD, 1461 + .NumEraseRegions= 2, 1462 + .regions = { 1463 + ERASEINFO(0x1000,256), 1464 + ERASEINFO(0x1000,256) 1465 + } 1452 1466 1453 1467 }, { 1454 1468 .mfr_id = MANUFACTURER_ST, /* FIXME - CFI device? */ ··· 1872 1856 case CFI_DEVICETYPE_X8: 1873 1857 mfr = (__u8)finfo->mfr_id; 1874 1858 id = (__u8)finfo->dev_id; 1859 + 1860 + /* bjd: it seems that if we do this, we can end up 1861 + * detecting 16bit flashes as an 8bit device, even though 1862 + * there aren't. 1863 + */ 1864 + if (finfo->dev_id > 0xff) { 1865 + DEBUG( MTD_DEBUG_LEVEL3, "%s(): ID is not 8bit\n", 1866 + __func__); 1867 + goto match_done; 1868 + } 1875 1869 break; 1876 1870 case CFI_DEVICETYPE_X16: 1877 1871 mfr = (__u16)finfo->mfr_id;
+6 -2
drivers/mtd/cmdlinepart.c
··· 1 1 /* 2 - * $Id: cmdlinepart.c,v 1.17 2004/11/26 11:18:47 lavinen Exp $ 2 + * $Id: cmdlinepart.c,v 1.18 2005/06/07 15:04:26 joern Exp $ 3 3 * 4 4 * Read flash partition table from command line 5 5 * ··· 239 239 &num_parts, /* out: number of parts */ 240 240 0, /* first partition */ 241 241 (unsigned char**)&this_mtd, /* out: extra mem */ 242 - mtd_id_len + 1 + sizeof(*this_mtd)); 242 + mtd_id_len + 1 + sizeof(*this_mtd) + 243 + sizeof(void*)-1 /*alignment*/); 243 244 if(!parts) 244 245 { 245 246 /* ··· 253 252 return 0; 254 253 } 255 254 255 + /* align this_mtd */ 256 + this_mtd = (struct cmdline_mtd_partition *) 257 + ALIGN((unsigned long)this_mtd, sizeof(void*)); 256 258 /* enter results */ 257 259 this_mtd->parts = parts; 258 260 this_mtd->num_parts = num_parts;
+9 -11
drivers/mtd/devices/block2mtd.c
··· 1 1 /* 2 - * $Id: block2mtd.c,v 1.23 2005/01/05 17:05:46 dwmw2 Exp $ 2 + * $Id: block2mtd.c,v 1.28 2005/03/19 22:40:44 gleixner Exp $ 3 3 * 4 4 * block2mtd.c - create an mtd from a block device 5 5 * 6 6 * Copyright (C) 2001,2002 Simon Evans <spse@secret.org.uk> 7 - * Copyright (C) 2004 Gareth Bult <Gareth@Encryptec.net> 8 7 * Copyright (C) 2004,2005 J�rn Engel <joern@wh.fh-wedel.de> 9 8 * 10 9 * Licence: GPL ··· 19 20 #include <linux/mtd/mtd.h> 20 21 #include <linux/buffer_head.h> 21 22 22 - #define VERSION "$Revision: 1.23 $" 23 + #define VERSION "$Revision: 1.28 $" 23 24 24 25 25 26 #define ERROR(fmt, args...) printk(KERN_ERR "block2mtd: " fmt "\n" , ## args) ··· 88 89 static struct page* page_readahead(struct address_space *mapping, int index) 89 90 { 90 91 filler_t *filler = (filler_t*)mapping->a_ops->readpage; 91 - //do_page_cache_readahead(mapping, index, XXX, 64); 92 92 cache_readahead(mapping, index); 93 93 return read_cache_page(mapping, index, filler, NULL); 94 94 } ··· 155 157 struct block2mtd_dev *dev = mtd->priv; 156 158 struct page *page; 157 159 int index = from >> PAGE_SHIFT; 158 - int offset = from & (PAGE_SHIFT-1); 160 + int offset = from & (PAGE_SIZE-1); 159 161 int cpylen; 160 162 161 163 if (from > mtd->size) ··· 368 370 } 369 371 370 372 371 - static int parse_num32(u32 *num32, const char *token) 373 + static int parse_num(size_t *num, const char *token) 372 374 { 373 375 char *endp; 374 - unsigned long n; 376 + size_t n; 375 377 376 - n = ustrtoul(token, &endp, 0); 378 + n = (size_t) ustrtoul(token, &endp, 0); 377 379 if (*endp) 378 380 return -EINVAL; 379 381 380 - *num32 = n; 382 + *num = n; 381 383 return 0; 382 384 } 383 385 ··· 420 422 char buf[80+12], *str=buf; /* 80 for device, 12 for erase size */ 421 423 char *token[2]; 422 424 char *name; 423 - u32 erase_size = PAGE_SIZE; 425 + size_t erase_size = PAGE_SIZE; 424 426 int i, ret; 425 427 426 428 if (strnlen(val, sizeof(buf)) >= sizeof(buf)) ··· 447 449 return 0; 448 450 449 451 if (token[1]) { 450 - ret = parse_num32(&erase_size, token[1]); 452 + ret = parse_num(&erase_size, token[1]); 451 453 if (ret) 452 454 parse_err("illegal erase size"); 453 455 }
+4 -4
drivers/mtd/devices/ms02-nv.c
··· 6 6 * as published by the Free Software Foundation; either version 7 7 * 2 of the License, or (at your option) any later version. 8 8 * 9 - * $Id: ms02-nv.c,v 1.8 2005/01/05 18:05:12 dwmw2 Exp $ 9 + * $Id: ms02-nv.c,v 1.10 2005/06/20 12:24:41 macro Exp $ 10 10 */ 11 11 12 12 #include <linux/init.h> ··· 99 99 * The firmware writes MS02NV_ID at MS02NV_MAGIC and also 100 100 * a diagnostic status at MS02NV_DIAG. 101 101 */ 102 - ms02nv_diagp = (ms02nv_uint *)(KSEG1ADDR(addr + MS02NV_DIAG)); 103 - ms02nv_magicp = (ms02nv_uint *)(KSEG1ADDR(addr + MS02NV_MAGIC)); 102 + ms02nv_diagp = (ms02nv_uint *)(CKSEG1ADDR(addr + MS02NV_DIAG)); 103 + ms02nv_magicp = (ms02nv_uint *)(CKSEG1ADDR(addr + MS02NV_MAGIC)); 104 104 err = get_dbe(ms02nv_magic, ms02nv_magicp); 105 105 if (err) 106 106 return 0; ··· 233 233 goto err_out_csr_res; 234 234 } 235 235 236 - printk(KERN_INFO "mtd%d: %s at 0x%08lx, size %uMiB.\n", 236 + printk(KERN_INFO "mtd%d: %s at 0x%08lx, size %zuMiB.\n", 237 237 mtd->index, ms02nv_name, addr, size >> 20); 238 238 239 239 mp->next = root_ms02nv_mtd;
+91 -164
drivers/mtd/devices/mtdram.c
··· 1 1 /* 2 2 * mtdram - a test mtd device 3 - * $Id: mtdram.c,v 1.35 2005/01/05 18:05:12 dwmw2 Exp $ 3 + * $Id: mtdram.c,v 1.37 2005/04/21 03:42:11 joern Exp $ 4 4 * Author: Alexander Larsson <alex@cendio.se> 5 5 * 6 6 * Copyright (c) 1999 Alexander Larsson <alex@cendio.se> 7 + * Copyright (c) 2005 Joern Engel <joern@wh.fh-wedel.de> 7 8 * 8 9 * This code is GPL 9 10 * ··· 19 18 #include <linux/mtd/compatmac.h> 20 19 #include <linux/mtd/mtd.h> 21 20 22 - #ifndef CONFIG_MTDRAM_ABS_POS 23 - #define CONFIG_MTDRAM_ABS_POS 0 24 - #endif 25 - 26 - #if CONFIG_MTDRAM_ABS_POS > 0 27 - #include <asm/io.h> 28 - #endif 29 - 30 - #ifdef MODULE 31 21 static unsigned long total_size = CONFIG_MTDRAM_TOTAL_SIZE; 32 22 static unsigned long erase_size = CONFIG_MTDRAM_ERASE_SIZE; 33 - module_param(total_size,ulong,0); 34 - MODULE_PARM_DESC(total_size, "Total device size in KiB"); 35 - module_param(erase_size,ulong,0); 36 - MODULE_PARM_DESC(erase_size, "Device erase block size in KiB"); 37 23 #define MTDRAM_TOTAL_SIZE (total_size * 1024) 38 24 #define MTDRAM_ERASE_SIZE (erase_size * 1024) 39 - #else 40 - #define MTDRAM_TOTAL_SIZE (CONFIG_MTDRAM_TOTAL_SIZE * 1024) 41 - #define MTDRAM_ERASE_SIZE (CONFIG_MTDRAM_ERASE_SIZE * 1024) 42 - #endif 43 25 26 + #ifdef MODULE 27 + module_param(total_size, ulong, 0); 28 + MODULE_PARM_DESC(total_size, "Total device size in KiB"); 29 + module_param(erase_size, ulong, 0); 30 + MODULE_PARM_DESC(erase_size, "Device erase block size in KiB"); 31 + #endif 44 32 45 33 // We could store these in the mtd structure, but we only support 1 device.. 46 34 static struct mtd_info *mtd_info; 47 35 48 - 49 - static int 50 - ram_erase(struct mtd_info *mtd, struct erase_info *instr) 36 + static int ram_erase(struct mtd_info *mtd, struct erase_info *instr) 51 37 { 52 - DEBUG(MTD_DEBUG_LEVEL2, "ram_erase(pos:%ld, len:%ld)\n", (long)instr->addr, (long)instr->len); 53 - if (instr->addr + instr->len > mtd->size) { 54 - DEBUG(MTD_DEBUG_LEVEL1, "ram_erase() out of bounds (%ld > %ld)\n", (long)(instr->addr + instr->len), (long)mtd->size); 55 - return -EINVAL; 56 - } 57 - 58 - memset((char *)mtd->priv + instr->addr, 0xff, instr->len); 59 - 60 - instr->state = MTD_ERASE_DONE; 61 - mtd_erase_callback(instr); 38 + if (instr->addr + instr->len > mtd->size) 39 + return -EINVAL; 62 40 63 - return 0; 41 + memset((char *)mtd->priv + instr->addr, 0xff, instr->len); 42 + 43 + instr->state = MTD_ERASE_DONE; 44 + mtd_erase_callback(instr); 45 + 46 + return 0; 64 47 } 65 48 66 - static int ram_point (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char **mtdbuf) 49 + static int ram_point(struct mtd_info *mtd, loff_t from, size_t len, 50 + size_t *retlen, u_char **mtdbuf) 67 51 { 68 - if (from + len > mtd->size) 69 - return -EINVAL; 70 - 71 - *mtdbuf = mtd->priv + from; 72 - *retlen = len; 73 - return 0; 52 + if (from + len > mtd->size) 53 + return -EINVAL; 54 + 55 + *mtdbuf = mtd->priv + from; 56 + *retlen = len; 57 + return 0; 74 58 } 75 59 76 - static void ram_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, 77 - size_t len) 60 + static void ram_unpoint(struct mtd_info *mtd, u_char * addr, loff_t from, 61 + size_t len) 78 62 { 79 - DEBUG(MTD_DEBUG_LEVEL2, "ram_unpoint\n"); 80 63 } 81 64 82 65 static int ram_read(struct mtd_info *mtd, loff_t from, size_t len, 83 - size_t *retlen, u_char *buf) 66 + size_t *retlen, u_char *buf) 84 67 { 85 - DEBUG(MTD_DEBUG_LEVEL2, "ram_read(pos:%ld, len:%ld)\n", (long)from, (long)len); 86 - if (from + len > mtd->size) { 87 - DEBUG(MTD_DEBUG_LEVEL1, "ram_read() out of bounds (%ld > %ld)\n", (long)(from + len), (long)mtd->size); 88 - return -EINVAL; 89 - } 68 + if (from + len > mtd->size) 69 + return -EINVAL; 90 70 91 - memcpy(buf, mtd->priv + from, len); 71 + memcpy(buf, mtd->priv + from, len); 92 72 93 - *retlen=len; 94 - return 0; 73 + *retlen = len; 74 + return 0; 95 75 } 96 76 97 77 static int ram_write(struct mtd_info *mtd, loff_t to, size_t len, 98 - size_t *retlen, const u_char *buf) 78 + size_t *retlen, const u_char *buf) 99 79 { 100 - DEBUG(MTD_DEBUG_LEVEL2, "ram_write(pos:%ld, len:%ld)\n", (long)to, (long)len); 101 - if (to + len > mtd->size) { 102 - DEBUG(MTD_DEBUG_LEVEL1, "ram_write() out of bounds (%ld > %ld)\n", (long)(to + len), (long)mtd->size); 103 - return -EINVAL; 104 - } 80 + if (to + len > mtd->size) 81 + return -EINVAL; 105 82 106 - memcpy ((char *)mtd->priv + to, buf, len); 83 + memcpy((char *)mtd->priv + to, buf, len); 107 84 108 - *retlen=len; 109 - return 0; 85 + *retlen = len; 86 + return 0; 110 87 } 111 88 112 89 static void __exit cleanup_mtdram(void) 113 90 { 114 - if (mtd_info) { 115 - del_mtd_device(mtd_info); 116 - #if CONFIG_MTDRAM_TOTAL_SIZE > 0 117 - if (mtd_info->priv) 118 - #if CONFIG_MTDRAM_ABS_POS > 0 119 - iounmap(mtd_info->priv); 120 - #else 121 - vfree(mtd_info->priv); 122 - #endif 123 - #endif 124 - kfree(mtd_info); 125 - } 91 + if (mtd_info) { 92 + del_mtd_device(mtd_info); 93 + if (mtd_info->priv) 94 + vfree(mtd_info->priv); 95 + kfree(mtd_info); 96 + } 126 97 } 127 98 128 - int mtdram_init_device(struct mtd_info *mtd, void *mapped_address, 129 - unsigned long size, char *name) 99 + int mtdram_init_device(struct mtd_info *mtd, void *mapped_address, 100 + unsigned long size, char *name) 130 101 { 131 - memset(mtd, 0, sizeof(*mtd)); 102 + memset(mtd, 0, sizeof(*mtd)); 132 103 133 - /* Setup the MTD structure */ 134 - mtd->name = name; 135 - mtd->type = MTD_RAM; 136 - mtd->flags = MTD_CAP_RAM; 137 - mtd->size = size; 138 - mtd->erasesize = MTDRAM_ERASE_SIZE; 139 - mtd->priv = mapped_address; 104 + /* Setup the MTD structure */ 105 + mtd->name = name; 106 + mtd->type = MTD_RAM; 107 + mtd->flags = MTD_CAP_RAM; 108 + mtd->size = size; 109 + mtd->erasesize = MTDRAM_ERASE_SIZE; 110 + mtd->priv = mapped_address; 140 111 141 - mtd->owner = THIS_MODULE; 142 - mtd->erase = ram_erase; 143 - mtd->point = ram_point; 144 - mtd->unpoint = ram_unpoint; 145 - mtd->read = ram_read; 146 - mtd->write = ram_write; 112 + mtd->owner = THIS_MODULE; 113 + mtd->erase = ram_erase; 114 + mtd->point = ram_point; 115 + mtd->unpoint = ram_unpoint; 116 + mtd->read = ram_read; 117 + mtd->write = ram_write; 147 118 148 - if (add_mtd_device(mtd)) { 149 - return -EIO; 150 - } 151 - 152 - return 0; 119 + if (add_mtd_device(mtd)) { 120 + return -EIO; 121 + } 122 + 123 + return 0; 153 124 } 154 - 155 - #if CONFIG_MTDRAM_TOTAL_SIZE > 0 156 - #if CONFIG_MTDRAM_ABS_POS > 0 157 - static int __init init_mtdram(void) 158 - { 159 - void *addr; 160 - int err; 161 - /* Allocate some memory */ 162 - mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL); 163 - if (!mtd_info) 164 - return -ENOMEM; 165 - 166 - addr = ioremap(CONFIG_MTDRAM_ABS_POS, MTDRAM_TOTAL_SIZE); 167 - if (!addr) { 168 - DEBUG(MTD_DEBUG_LEVEL1, 169 - "Failed to ioremap) memory region of size %ld at ABS_POS:%ld\n", 170 - (long)MTDRAM_TOTAL_SIZE, (long)CONFIG_MTDRAM_ABS_POS); 171 - kfree(mtd_info); 172 - mtd_info = NULL; 173 - return -ENOMEM; 174 - } 175 - err = mtdram_init_device(mtd_info, addr, 176 - MTDRAM_TOTAL_SIZE, "mtdram test device"); 177 - if (err) 178 - { 179 - iounmap(addr); 180 - kfree(mtd_info); 181 - mtd_info = NULL; 182 - return err; 183 - } 184 - memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE); 185 - return err; 186 - } 187 - 188 - #else /* CONFIG_MTDRAM_ABS_POS > 0 */ 189 125 190 126 static int __init init_mtdram(void) 191 127 { 192 - void *addr; 193 - int err; 194 - /* Allocate some memory */ 195 - mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL); 196 - if (!mtd_info) 197 - return -ENOMEM; 128 + void *addr; 129 + int err; 198 130 199 - addr = vmalloc(MTDRAM_TOTAL_SIZE); 200 - if (!addr) { 201 - DEBUG(MTD_DEBUG_LEVEL1, 202 - "Failed to vmalloc memory region of size %ld\n", 203 - (long)MTDRAM_TOTAL_SIZE); 204 - kfree(mtd_info); 205 - mtd_info = NULL; 206 - return -ENOMEM; 207 - } 208 - err = mtdram_init_device(mtd_info, addr, 209 - MTDRAM_TOTAL_SIZE, "mtdram test device"); 210 - if (err) 211 - { 212 - vfree(addr); 213 - kfree(mtd_info); 214 - mtd_info = NULL; 215 - return err; 216 - } 217 - memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE); 218 - return err; 131 + if (!total_size) 132 + return -EINVAL; 133 + 134 + /* Allocate some memory */ 135 + mtd_info = kmalloc(sizeof(struct mtd_info), GFP_KERNEL); 136 + if (!mtd_info) 137 + return -ENOMEM; 138 + 139 + addr = vmalloc(MTDRAM_TOTAL_SIZE); 140 + if (!addr) { 141 + kfree(mtd_info); 142 + mtd_info = NULL; 143 + return -ENOMEM; 144 + } 145 + err = mtdram_init_device(mtd_info, addr, MTDRAM_TOTAL_SIZE, "mtdram test device"); 146 + if (err) { 147 + vfree(addr); 148 + kfree(mtd_info); 149 + mtd_info = NULL; 150 + return err; 151 + } 152 + memset(mtd_info->priv, 0xff, MTDRAM_TOTAL_SIZE); 153 + return err; 219 154 } 220 - #endif /* !(CONFIG_MTDRAM_ABS_POS > 0) */ 221 - 222 - #else /* CONFIG_MTDRAM_TOTAL_SIZE > 0 */ 223 - 224 - static int __init init_mtdram(void) 225 - { 226 - return 0; 227 - } 228 - #endif /* !(CONFIG_MTDRAM_TOTAL_SIZE > 0) */ 229 155 230 156 module_init(init_mtdram); 231 157 module_exit(cleanup_mtdram); ··· 160 232 MODULE_LICENSE("GPL"); 161 233 MODULE_AUTHOR("Alexander Larsson <alexl@redhat.com>"); 162 234 MODULE_DESCRIPTION("Simulated MTD driver for testing"); 163 -
+24 -10
drivers/mtd/devices/phram.c
··· 1 1 /** 2 - * $Id: phram.c,v 1.11 2005/01/05 18:05:13 dwmw2 Exp $ 2 + * $Id: phram.c,v 1.14 2005/03/07 21:43:38 joern Exp $ 3 3 * 4 4 * Copyright (c) ???? Jochen Sch�uble <psionic@psionic.de> 5 5 * Copyright (c) 2003-2004 J�rn Engel <joern@wh.fh-wedel.de> ··· 15 15 * 16 16 * Example: 17 17 * phram=swap,64Mi,128Mi phram=test,900Mi,1Mi 18 - * 19 18 */ 20 - 21 19 #include <asm/io.h> 22 20 #include <linux/init.h> 23 21 #include <linux/kernel.h> ··· 32 34 }; 33 35 34 36 static LIST_HEAD(phram_list); 35 - 36 37 37 38 38 39 static int phram_erase(struct mtd_info *mtd, struct erase_info *instr) ··· 68 71 return 0; 69 72 } 70 73 71 - static void phram_unpoint(struct mtd_info *mtd, u_char *addr, loff_t from, size_t len) 74 + static void phram_unpoint(struct mtd_info *mtd, u_char *addr, loff_t from, 75 + size_t len) 72 76 { 73 77 } 74 78 ··· 78 80 { 79 81 u_char *start = mtd->priv; 80 82 81 - if (from + len > mtd->size) 83 + if (from >= mtd->size) 82 84 return -EINVAL; 85 + 86 + if (len > mtd->size - from) 87 + len = mtd->size - from; 83 88 84 89 memcpy(buf, start + from, len); 85 90 ··· 95 94 { 96 95 u_char *start = mtd->priv; 97 96 98 - if (to + len > mtd->size) 97 + if (to >= mtd->size) 99 98 return -EINVAL; 99 + 100 + if (len > mtd->size - to) 101 + len = mtd->size - to; 100 102 101 103 memcpy(start + to, buf, len); 102 104 ··· 111 107 112 108 static void unregister_devices(void) 113 109 { 114 - struct phram_mtd_list *this; 110 + struct phram_mtd_list *this, *safe; 115 111 116 - list_for_each_entry(this, &phram_list, list) { 112 + list_for_each_entry_safe(this, safe, &phram_list, list) { 117 113 del_mtd_device(&this->mtd); 118 114 iounmap(this->mtd.priv); 119 115 kfree(this); ··· 149 145 new->mtd.write = phram_write; 150 146 new->mtd.owner = THIS_MODULE; 151 147 new->mtd.type = MTD_RAM; 152 - new->mtd.erasesize = 0; 148 + new->mtd.erasesize = PAGE_SIZE; 153 149 154 150 ret = -EAGAIN; 155 151 if (add_mtd_device(&new->mtd)) { ··· 218 214 return 0; 219 215 } 220 216 217 + 218 + static inline void kill_final_newline(char *str) 219 + { 220 + char *newline = strrchr(str, '\n'); 221 + if (newline && !newline[1]) 222 + *newline = 0; 223 + } 224 + 225 + 221 226 #define parse_err(fmt, args...) do { \ 222 227 ERROR(fmt , ## args); \ 223 228 return 0; \ ··· 245 232 parse_err("parameter too long\n"); 246 233 247 234 strcpy(str, val); 235 + kill_final_newline(str); 248 236 249 237 for (i=0; i<3; i++) 250 238 token[i] = strsep(&str, ",");
+18 -5
drivers/mtd/devices/slram.c
··· 1 1 /*====================================================================== 2 2 3 - $Id: slram.c,v 1.33 2005/01/05 18:05:13 dwmw2 Exp $ 3 + $Id: slram.c,v 1.34 2005/01/06 21:16:42 jwboyer Exp $ 4 4 5 5 This driver provides a method to access memory not used by the kernel 6 6 itself (i.e. if the kernel commandline mem=xxx is used). To actually ··· 50 50 #include <linux/mtd/mtd.h> 51 51 52 52 #define SLRAM_MAX_DEVICES_PARAMS 6 /* 3 parameters / device */ 53 + #define SLRAM_BLK_SZ 0x4000 53 54 54 55 #define T(fmt, args...) printk(KERN_DEBUG fmt, ## args) 55 56 #define E(fmt, args...) printk(KERN_NOTICE fmt, ## args) ··· 109 108 { 110 109 slram_priv_t *priv = mtd->priv; 111 110 111 + if (from + len > mtd->size) 112 + return -EINVAL; 113 + 112 114 *mtdbuf = priv->start + from; 113 115 *retlen = len; 114 116 return(0); ··· 125 121 size_t *retlen, u_char *buf) 126 122 { 127 123 slram_priv_t *priv = mtd->priv; 128 - 124 + 125 + if (from > mtd->size) 126 + return -EINVAL; 127 + 128 + if (from + len > mtd->size) 129 + len = mtd->size - from; 130 + 129 131 memcpy(buf, priv->start + from, len); 130 132 131 133 *retlen = len; ··· 142 132 size_t *retlen, const u_char *buf) 143 133 { 144 134 slram_priv_t *priv = mtd->priv; 135 + 136 + if (to + len > mtd->size) 137 + return -EINVAL; 145 138 146 139 memcpy(priv->start + to, buf, len); 147 140 ··· 201 188 (*curmtd)->mtdinfo->name = name; 202 189 (*curmtd)->mtdinfo->size = length; 203 190 (*curmtd)->mtdinfo->flags = MTD_CLEAR_BITS | MTD_SET_BITS | 204 - MTD_WRITEB_WRITEABLE | MTD_VOLATILE; 191 + MTD_WRITEB_WRITEABLE | MTD_VOLATILE | MTD_CAP_RAM; 205 192 (*curmtd)->mtdinfo->erase = slram_erase; 206 193 (*curmtd)->mtdinfo->point = slram_point; 207 194 (*curmtd)->mtdinfo->unpoint = slram_unpoint; ··· 209 196 (*curmtd)->mtdinfo->write = slram_write; 210 197 (*curmtd)->mtdinfo->owner = THIS_MODULE; 211 198 (*curmtd)->mtdinfo->type = MTD_RAM; 212 - (*curmtd)->mtdinfo->erasesize = 0x0; 199 + (*curmtd)->mtdinfo->erasesize = SLRAM_BLK_SZ; 213 200 214 201 if (add_mtd_device((*curmtd)->mtdinfo)) { 215 202 E("slram: Failed to register new device\n"); ··· 274 261 } 275 262 T("slram: devname=%s, devstart=0x%lx, devlength=0x%lx\n", 276 263 devname, devstart, devlength); 277 - if ((devstart < 0) || (devlength < 0)) { 264 + if ((devstart < 0) || (devlength < 0) || (devlength % SLRAM_BLK_SZ != 0)) { 278 265 E("slram: Illegal start / length parameter.\n"); 279 266 return(-EINVAL); 280 267 }
+3 -2
drivers/mtd/ftl.c
··· 1 1 /* This version ported to the Linux-MTD system by dwmw2@infradead.org 2 - * $Id: ftl.c,v 1.54 2004/11/16 18:33:15 dwmw2 Exp $ 2 + * $Id: ftl.c,v 1.55 2005/01/17 13:47:21 hvr Exp $ 3 3 * 4 4 * Fixes: Arnaldo Carvalho de Melo <acme@conectiva.com.br> 5 5 * - fixes some leaks on failure in build_maps and ftl_notify_add, cleanups ··· 357 357 if (!erase) 358 358 return -ENOMEM; 359 359 360 + erase->mtd = part->mbd.mtd; 360 361 erase->callback = ftl_erase_callback; 361 362 erase->addr = xfer->Offset; 362 363 erase->len = 1 << part->header.EraseUnitSize; ··· 1097 1096 1098 1097 int init_ftl(void) 1099 1098 { 1100 - DEBUG(0, "$Id: ftl.c,v 1.54 2004/11/16 18:33:15 dwmw2 Exp $\n"); 1099 + DEBUG(0, "$Id: ftl.c,v 1.55 2005/01/17 13:47:21 hvr Exp $\n"); 1101 1100 1102 1101 return register_mtd_blktrans(&ftl_tr); 1103 1102 }
+36 -81
drivers/mtd/maps/Kconfig
··· 1 1 # drivers/mtd/maps/Kconfig 2 - # $Id: Kconfig,v 1.42 2005/01/05 16:59:50 dwmw2 Exp $ 2 + # $Id: Kconfig,v 1.55 2005/07/02 01:53:24 tpoynor Exp $ 3 3 4 4 menu "Mapping drivers for chip access" 5 5 depends on MTD!=n ··· 122 122 More info at 123 123 <http://www.arcomcontrols.com/products/icp/pc104/processors/SBC_GX1.htm>. 124 124 125 - config MTD_ELAN_104NC 126 - tristate "CFI Flash device mapped on Arcom ELAN-104NC" 127 - depends on X86 && MTD_CFI_INTELEXT && MTD_PARTITIONS && MTD_COMPLEX_MAPPINGS 128 - help 129 - This provides a driver for the on-board flash of the Arcom Control 130 - System's ELAN-104NC development board. By default the flash 131 - is split into 3 partitions which are accessed as separate MTD 132 - devices. This board utilizes Intel StrataFlash. More info at 133 - <http://www.arcomcontrols.com/products/icp/pc104/processors/ELAN104NC.htm>. 134 - 135 125 config MTD_LUBBOCK 136 126 tristate "CFI Flash device mapped on Intel Lubbock XScale eval board" 137 127 depends on ARCH_LUBBOCK && MTD_CFI_INTELEXT && MTD_PARTITIONS 138 128 help 139 129 This provides a driver for the on-board flash of the Intel 140 130 'Lubbock' XScale evaluation board. 131 + 132 + config MTD_MAINSTONE 133 + tristate "CFI Flash device mapped on Intel Mainstone XScale eval board" 134 + depends on MACH_MAINSTONE && MTD_CFI_INTELEXT 135 + select MTD_PARTITIONS 136 + help 137 + This provides a driver for the on-board flash of the Intel 138 + 'Mainstone PXA27x evaluation board. 141 139 142 140 config MTD_OCTAGON 143 141 tristate "JEDEC Flash device mapped on Octagon 5066 SBC" ··· 211 213 help 212 214 Support for flash chips on NETtel/SecureEdge/SnapGear boards. 213 215 214 - config MTD_PB1XXX 215 - tristate "Flash devices on Alchemy PB1xxx boards" 216 - depends on MIPS && ( MIPS_PB1000 || MIPS_PB1100 || MIPS_PB1500 ) 216 + config MTD_ALCHEMY 217 + tristate ' AMD Alchemy Pb1xxx/Db1xxx/RDK MTD support' 218 + depends on MIPS && SOC_AU1X00 217 219 help 218 - Flash memory access on Alchemy Pb1000/Pb1100/Pb1500 boards 219 - 220 - config MTD_PB1XXX_BOOT 221 - bool "PB1x00 boot flash device" 222 - depends on MTD_PB1XXX && ( MIPS_PB1100 || MIPS_PB1500 ) 223 - help 224 - Use the first of the two 32MiB flash banks on Pb1100/Pb1500 board. 225 - You can say 'Y' to both this and 'MTD_PB1XXX_USER' below, to use 226 - both banks. 227 - 228 - config MTD_PB1XXX_USER 229 - bool "PB1x00 user flash device" 230 - depends on MTD_PB1XXX && ( MIPS_PB1100 || MIPS_PB1500 ) 231 - default y if MTD_PB1XX_BOOT = n 232 - help 233 - Use the second of the two 32MiB flash banks on Pb1100/Pb1500 board. 234 - You can say 'Y' to both this and 'MTD_PB1XXX_BOOT' above, to use 235 - both banks. 236 - 237 - config MTD_PB1550 238 - tristate "Flash devices on Alchemy PB1550 board" 239 - depends on MIPS && MIPS_PB1550 240 - help 241 - Flash memory access on Alchemy Pb1550 board 242 - 243 - config MTD_PB1550_BOOT 244 - bool "PB1550 boot flash device" 245 - depends on MTD_PB1550 246 - help 247 - Use the first of the two 64MiB flash banks on Pb1550 board. 248 - You can say 'Y' to both this and 'MTD_PB1550_USER' below, to use 249 - both banks. 250 - 251 - config MTD_PB1550_USER 252 - bool "PB1550 user flash device" 253 - depends on MTD_PB1550 254 - default y if MTD_PB1550_BOOT = n 255 - help 256 - Use the second of the two 64MiB flash banks on Pb1550 board. 257 - You can say 'Y' to both this and 'MTD_PB1550_BOOT' above, to use 258 - both banks. 259 - 260 - config MTD_DB1550 261 - tristate "Flash devices on Alchemy DB1550 board" 262 - depends on MIPS && MIPS_DB1550 263 - help 264 - Flash memory access on Alchemy Db1550 board 265 - 266 - config MTD_DB1550_BOOT 267 - bool "DB1550 boot flash device" 268 - depends on MTD_DB1550 269 - help 270 - Use the first of the two 64MiB flash banks on Db1550 board. 271 - You can say 'Y' to both this and 'MTD_DB1550_USER' below, to use 272 - both banks. 273 - 274 - config MTD_DB1550_USER 275 - bool "DB1550 user flash device" 276 - depends on MTD_DB1550 277 - default y if MTD_DB1550_BOOT = n 278 - help 279 - Use the second of the two 64MiB flash banks on Db1550 board. 280 - You can say 'Y' to both this and 'MTD_DB1550_BOOT' above, to use 281 - both banks. 220 + Flash memory access on AMD Alchemy Pb/Db/RDK Reference Boards 282 221 283 222 config MTD_DILNETPC 284 223 tristate "CFI Flash device mapped on DIL/Net PC" ··· 523 588 This enables access to the flash chips on the Interface MPC-1211(CTP/PCI/MPC-SH02). 524 589 If you have such a board, say 'Y'. 525 590 591 + config MTD_OMAP_NOR 592 + tristate "TI OMAP board mappings" 593 + depends on MTD_CFI && ARCH_OMAP 594 + help 595 + This enables access to the NOR flash chips on TI OMAP-based 596 + boards defining flash platform devices and flash platform data. 597 + These boards include the Innovator, H2, H3, OSK, Perseus2, and 598 + more. If you have such a board, say 'Y'. 599 + 526 600 # This needs CFI or JEDEC, depending on the cards found. 527 601 config MTD_PCI 528 602 tristate "PCI MTD driver" ··· 591 647 Map driver for Dy-4 SVME/DMV-182 board. 592 648 593 649 config MTD_BAST 594 - tristate "Map driver for Simtec BAST (EB2410ITX)" 595 - depends on ARCH_BAST 650 + tristate "Map driver for Simtec BAST (EB2410ITX) or Thorcom VR1000" 651 + depends on ARCH_BAST || MACH_VR1000 596 652 select MTD_PARTITIONS 597 653 select MTD_MAP_BANK_WIDTH_16 598 654 select MTD_JEDECPROBE 599 655 help 600 - Map driver for NOR flash on the Simtec BAST (EB2410ITX). 656 + Map driver for NOR flash on the Simtec BAST (EB2410ITX), or the 657 + Thorcom VR1000 601 658 602 659 Note, this driver *cannot* over-ride the WP link on the 603 660 board, or currently detect the state of the link. ··· 613 668 depends on MTD && ARCH_PXA 614 669 help 615 670 This enables access to the flash chip on the Sharp SL Series of PDAs. 671 + 672 + config MTD_PLATRAM 673 + tristate "Map driver for platform device RAM (mtd-ram)" 674 + depends on MTD 675 + select MTD_RAM 676 + help 677 + Map driver for RAM areas described via the platform device 678 + system. 679 + 680 + This selection automatically selects the map_ram driver. 616 681 617 682 endmenu 618 683
+5 -6
drivers/mtd/maps/Makefile
··· 1 1 # 2 2 # linux/drivers/maps/Makefile 3 3 # 4 - # $Id: Makefile.common,v 1.23 2005/01/05 17:06:36 dwmw2 Exp $ 4 + # $Id: Makefile.common,v 1.30 2005/07/02 01:53:24 tpoynor Exp $ 5 5 6 6 ifeq ($(CONFIG_MTD_COMPLEX_MAPPINGS),y) 7 7 obj-$(CONFIG_MTD) += map_funcs.o ··· 15 15 obj-$(CONFIG_MTD_CSTM_MIPS_IXX) += cstm_mips_ixx.o 16 16 obj-$(CONFIG_MTD_DC21285) += dc21285.o 17 17 obj-$(CONFIG_MTD_DILNETPC) += dilnetpc.o 18 - obj-$(CONFIG_MTD_ELAN_104NC) += elan-104nc.o 19 18 obj-$(CONFIG_MTD_EPXA10DB) += epxa10db-flash.o 20 19 obj-$(CONFIG_MTD_IQ80310) += iq80310.o 21 20 obj-$(CONFIG_MTD_L440GX) += l440gx.o ··· 22 23 obj-$(CONFIG_MTD_ICHXROM) += ichxrom.o 23 24 obj-$(CONFIG_MTD_TSUNAMI) += tsunami_flash.o 24 25 obj-$(CONFIG_MTD_LUBBOCK) += lubbock-flash.o 26 + obj-$(CONFIG_MTD_MAINSTONE) += mainstone-flash.o 25 27 obj-$(CONFIG_MTD_MBX860) += mbx860.o 26 28 obj-$(CONFIG_MTD_CEIVA) += ceiva.o 27 29 obj-$(CONFIG_MTD_OCTAGON) += octagon-5066.o ··· 44 44 obj-$(CONFIG_MTD_OCELOT) += ocelot.o 45 45 obj-$(CONFIG_MTD_SOLUTIONENGINE)+= solutionengine.o 46 46 obj-$(CONFIG_MTD_PCI) += pci.o 47 - obj-$(CONFIG_MTD_PB1XXX) += pb1xxx-flash.o 48 - obj-$(CONFIG_MTD_DB1X00) += db1x00-flash.o 49 - obj-$(CONFIG_MTD_PB1550) += pb1550-flash.o 50 - obj-$(CONFIG_MTD_DB1550) += db1550-flash.o 47 + obj-$(CONFIG_MTD_ALCHEMY) += alchemy-flash.o 51 48 obj-$(CONFIG_MTD_LASAT) += lasat.o 52 49 obj-$(CONFIG_MTD_AUTCPU12) += autcpu12-nvram.o 53 50 obj-$(CONFIG_MTD_EDB7312) += edb7312.o ··· 68 71 obj-$(CONFIG_MTD_WRSBC8260) += wr_sbc82xx_flash.o 69 72 obj-$(CONFIG_MTD_DMV182) += dmv182.o 70 73 obj-$(CONFIG_MTD_SHARP_SL) += sharpsl-flash.o 74 + obj-$(CONFIG_MTD_PLATRAM) += plat-ram.o 75 + obj-$(CONFIG_MTD_OMAP_NOR) += omap_nor.o
+192
drivers/mtd/maps/alchemy-flash.c
··· 1 + /* 2 + * Flash memory access on AMD Alchemy evaluation boards 3 + * 4 + * $Id: alchemy-flash.c,v 1.1 2005/02/27 21:50:21 ppopov Exp $ 5 + * 6 + * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.com> 7 + * 8 + */ 9 + 10 + #include <linux/config.h> 11 + #include <linux/init.h> 12 + #include <linux/module.h> 13 + #include <linux/types.h> 14 + #include <linux/kernel.h> 15 + 16 + #include <linux/mtd/mtd.h> 17 + #include <linux/mtd/map.h> 18 + #include <linux/mtd/partitions.h> 19 + 20 + #include <asm/io.h> 21 + 22 + #ifdef DEBUG_RW 23 + #define DBG(x...) printk(x) 24 + #else 25 + #define DBG(x...) 26 + #endif 27 + 28 + #ifdef CONFIG_MIPS_PB1000 29 + #define BOARD_MAP_NAME "Pb1000 Flash" 30 + #define BOARD_FLASH_SIZE 0x00800000 /* 8MB */ 31 + #define BOARD_FLASH_WIDTH 4 /* 32-bits */ 32 + #endif 33 + 34 + #ifdef CONFIG_MIPS_PB1500 35 + #define BOARD_MAP_NAME "Pb1500 Flash" 36 + #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */ 37 + #define BOARD_FLASH_WIDTH 4 /* 32-bits */ 38 + #endif 39 + 40 + #ifdef CONFIG_MIPS_PB1100 41 + #define BOARD_MAP_NAME "Pb1100 Flash" 42 + #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */ 43 + #define BOARD_FLASH_WIDTH 4 /* 32-bits */ 44 + #endif 45 + 46 + #ifdef CONFIG_MIPS_PB1550 47 + #define BOARD_MAP_NAME "Pb1550 Flash" 48 + #define BOARD_FLASH_SIZE 0x08000000 /* 128MB */ 49 + #define BOARD_FLASH_WIDTH 4 /* 32-bits */ 50 + #endif 51 + 52 + #ifdef CONFIG_MIPS_PB1200 53 + #define BOARD_MAP_NAME "Pb1200 Flash" 54 + #define BOARD_FLASH_SIZE 0x08000000 /* 128MB */ 55 + #define BOARD_FLASH_WIDTH 2 /* 16-bits */ 56 + #endif 57 + 58 + #ifdef CONFIG_MIPS_DB1000 59 + #define BOARD_MAP_NAME "Db1000 Flash" 60 + #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */ 61 + #define BOARD_FLASH_WIDTH 4 /* 32-bits */ 62 + #endif 63 + 64 + #ifdef CONFIG_MIPS_DB1500 65 + #define BOARD_MAP_NAME "Db1500 Flash" 66 + #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */ 67 + #define BOARD_FLASH_WIDTH 4 /* 32-bits */ 68 + #endif 69 + 70 + #ifdef CONFIG_MIPS_DB1100 71 + #define BOARD_MAP_NAME "Db1100 Flash" 72 + #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */ 73 + #define BOARD_FLASH_WIDTH 4 /* 32-bits */ 74 + #endif 75 + 76 + #ifdef CONFIG_MIPS_DB1550 77 + #define BOARD_MAP_NAME "Db1550 Flash" 78 + #define BOARD_FLASH_SIZE 0x08000000 /* 128MB */ 79 + #define BOARD_FLASH_WIDTH 4 /* 32-bits */ 80 + #endif 81 + 82 + #ifdef CONFIG_MIPS_DB1200 83 + #define BOARD_MAP_NAME "Db1200 Flash" 84 + #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */ 85 + #define BOARD_FLASH_WIDTH 2 /* 16-bits */ 86 + #endif 87 + 88 + #ifdef CONFIG_MIPS_HYDROGEN3 89 + #define BOARD_MAP_NAME "Hydrogen3 Flash" 90 + #define BOARD_FLASH_SIZE 0x02000000 /* 32MB */ 91 + #define BOARD_FLASH_WIDTH 4 /* 32-bits */ 92 + #define USE_LOCAL_ACCESSORS /* why? */ 93 + #endif 94 + 95 + #ifdef CONFIG_MIPS_BOSPORUS 96 + #define BOARD_MAP_NAME "Bosporus Flash" 97 + #define BOARD_FLASH_SIZE 0x01000000 /* 16MB */ 98 + #define BOARD_FLASH_WIDTH 2 /* 16-bits */ 99 + #endif 100 + 101 + #ifdef CONFIG_MIPS_MIRAGE 102 + #define BOARD_MAP_NAME "Mirage Flash" 103 + #define BOARD_FLASH_SIZE 0x04000000 /* 64MB */ 104 + #define BOARD_FLASH_WIDTH 4 /* 32-bits */ 105 + #define USE_LOCAL_ACCESSORS /* why? */ 106 + #endif 107 + 108 + static struct map_info alchemy_map = { 109 + .name = BOARD_MAP_NAME, 110 + }; 111 + 112 + static struct mtd_partition alchemy_partitions[] = { 113 + { 114 + .name = "User FS", 115 + .size = BOARD_FLASH_SIZE - 0x00400000, 116 + .offset = 0x0000000 117 + },{ 118 + .name = "YAMON", 119 + .size = 0x0100000, 120 + .offset = MTDPART_OFS_APPEND, 121 + .mask_flags = MTD_WRITEABLE 122 + },{ 123 + .name = "raw kernel", 124 + .size = (0x300000 - 0x40000), /* last 256KB is yamon env */ 125 + .offset = MTDPART_OFS_APPEND, 126 + } 127 + }; 128 + 129 + #define NB_OF(x) (sizeof(x)/sizeof(x[0])) 130 + 131 + static struct mtd_info *mymtd; 132 + 133 + int __init alchemy_mtd_init(void) 134 + { 135 + struct mtd_partition *parts; 136 + int nb_parts = 0; 137 + unsigned long window_addr; 138 + unsigned long window_size; 139 + 140 + /* Default flash buswidth */ 141 + alchemy_map.bankwidth = BOARD_FLASH_WIDTH; 142 + 143 + window_addr = 0x20000000 - BOARD_FLASH_SIZE; 144 + window_size = BOARD_FLASH_SIZE; 145 + #ifdef CONFIG_MIPS_MIRAGE_WHY 146 + /* Boot ROM flash bank only; no user bank */ 147 + window_addr = 0x1C000000; 148 + window_size = 0x04000000; 149 + /* USERFS from 0x1C00 0000 to 0x1FC00000 */ 150 + alchemy_partitions[0].size = 0x03C00000; 151 + #endif 152 + 153 + /* 154 + * Static partition definition selection 155 + */ 156 + parts = alchemy_partitions; 157 + nb_parts = NB_OF(alchemy_partitions); 158 + alchemy_map.size = window_size; 159 + 160 + /* 161 + * Now let's probe for the actual flash. Do it here since 162 + * specific machine settings might have been set above. 163 + */ 164 + printk(KERN_NOTICE BOARD_MAP_NAME ": probing %d-bit flash bus\n", 165 + alchemy_map.bankwidth*8); 166 + alchemy_map.virt = ioremap(window_addr, window_size); 167 + mymtd = do_map_probe("cfi_probe", &alchemy_map); 168 + if (!mymtd) { 169 + iounmap(alchemy_map.virt); 170 + return -ENXIO; 171 + } 172 + mymtd->owner = THIS_MODULE; 173 + 174 + add_mtd_partitions(mymtd, parts, nb_parts); 175 + return 0; 176 + } 177 + 178 + static void __exit alchemy_mtd_cleanup(void) 179 + { 180 + if (mymtd) { 181 + del_mtd_partitions(mymtd); 182 + map_destroy(mymtd); 183 + iounmap(alchemy_map.virt); 184 + } 185 + } 186 + 187 + module_init(alchemy_mtd_init); 188 + module_exit(alchemy_mtd_cleanup); 189 + 190 + MODULE_AUTHOR("Embedded Alley Solutions, Inc"); 191 + MODULE_DESCRIPTION(BOARD_MAP_NAME " MTD driver"); 192 + MODULE_LICENSE("GPL");
+2 -2
drivers/mtd/maps/amd76xrom.c
··· 2 2 * amd76xrom.c 3 3 * 4 4 * Normal mappings of chips in physical memory 5 - * $Id: amd76xrom.c,v 1.19 2004/11/28 09:40:39 dwmw2 Exp $ 5 + * $Id: amd76xrom.c,v 1.20 2005/03/18 14:04:35 gleixner Exp $ 6 6 */ 7 7 8 8 #include <linux/module.h> ··· 314 314 } 315 315 return -ENXIO; 316 316 #if 0 317 - return pci_module_init(&amd76xrom_driver); 317 + return pci_register_driver(&amd76xrom_driver); 318 318 #endif 319 319 } 320 320
+8 -5
drivers/mtd/maps/bast-flash.c
··· 1 1 /* linux/drivers/mtd/maps/bast_flash.c 2 2 * 3 - * Copyright (c) 2004 Simtec Electronics 4 - * Ben Dooks <ben@simtec.co.uk> 3 + * Copyright (c) 2004-2005 Simtec Electronics 4 + * Ben Dooks <ben@simtec.co.uk> 5 5 * 6 6 * Simtec Bast (EB2410ITX) NOR MTD Mapping driver 7 7 * 8 8 * Changelog: 9 9 * 20-Sep-2004 BJD Initial version 10 + * 17-Jan-2005 BJD Add whole device if no partitions found 10 11 * 11 - * $Id: bast-flash.c,v 1.1 2004/09/21 14:29:04 bjd Exp $ 12 + * $Id: bast-flash.c,v 1.2 2005/01/18 11:13:47 bjd Exp $ 12 13 * 13 14 * This program is free software; you can redistribute it and/or modify 14 15 * it under the terms of the GNU General Public License as published by ··· 47 46 #include <asm/arch/bast-cpld.h> 48 47 49 48 #ifdef CONFIG_MTD_BAST_MAXSIZE 50 - #define AREA_MAXSIZE (CONFIG_MTD_BAST_MAXSIZE * (1024*1024)) 49 + #define AREA_MAXSIZE (CONFIG_MTD_BAST_MAXSIZE * SZ_1M) 51 50 #else 52 - #define AREA_MAXSIZE (32*1024*1024) 51 + #define AREA_MAXSIZE (32 * SZ_1M) 53 52 #endif 54 53 55 54 #define PFX "bast-flash: " ··· 190 189 err = add_mtd_partitions(info->mtd, info->partitions, err); 191 190 if (err) 192 191 printk(KERN_ERR PFX "cannot add/parse partitions\n"); 192 + } else { 193 + err = add_mtd_device(info->mtd); 193 194 } 194 195 195 196 if (err == 0)
-187
drivers/mtd/maps/db1550-flash.c
··· 1 - /* 2 - * Flash memory access on Alchemy Db1550 board 3 - * 4 - * $Id: db1550-flash.c,v 1.7 2004/11/04 13:24:14 gleixner Exp $ 5 - * 6 - * (C) 2004 Embedded Edge, LLC, based on db1550-flash.c: 7 - * (C) 2003, 2004 Pete Popov <ppopov@embeddedalley.com> 8 - * 9 - */ 10 - 11 - #include <linux/config.h> 12 - #include <linux/init.h> 13 - #include <linux/module.h> 14 - #include <linux/types.h> 15 - #include <linux/kernel.h> 16 - 17 - #include <linux/mtd/mtd.h> 18 - #include <linux/mtd/map.h> 19 - #include <linux/mtd/partitions.h> 20 - 21 - #include <asm/io.h> 22 - 23 - #ifdef DEBUG_RW 24 - #define DBG(x...) printk(x) 25 - #else 26 - #define DBG(x...) 27 - #endif 28 - 29 - static unsigned long window_addr; 30 - static unsigned long window_size; 31 - 32 - 33 - static struct map_info db1550_map = { 34 - .name = "Db1550 flash", 35 - }; 36 - 37 - static unsigned char flash_bankwidth = 4; 38 - 39 - /* 40 - * Support only 64MB NOR Flash parts 41 - */ 42 - 43 - #if defined(CONFIG_MTD_DB1550_BOOT) && defined(CONFIG_MTD_DB1550_USER) 44 - #define DB1550_BOTH_BANKS 45 - #elif defined(CONFIG_MTD_DB1550_BOOT) && !defined(CONFIG_MTD_DB1550_USER) 46 - #define DB1550_BOOT_ONLY 47 - #elif !defined(CONFIG_MTD_DB1550_BOOT) && defined(CONFIG_MTD_DB1550_USER) 48 - #define DB1550_USER_ONLY 49 - #endif 50 - 51 - #ifdef DB1550_BOTH_BANKS 52 - /* both banks will be used. Combine the first bank and the first 53 - * part of the second bank together into a single jffs/jffs2 54 - * partition. 55 - */ 56 - static struct mtd_partition db1550_partitions[] = { 57 - /* assume boot[2:0]:swap is '0000' or '1000', which translates to: 58 - * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash 59 - * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash 60 - */ 61 - { 62 - .name = "User FS", 63 - .size = (0x1FC00000 - 0x18000000), 64 - .offset = 0x0000000 65 - },{ 66 - .name = "yamon", 67 - .size = 0x0100000, 68 - .offset = MTDPART_OFS_APPEND, 69 - .mask_flags = MTD_WRITEABLE 70 - },{ 71 - .name = "raw kernel", 72 - .size = (0x300000 - 0x40000), /* last 256KB is yamon env */ 73 - .offset = MTDPART_OFS_APPEND, 74 - } 75 - }; 76 - #elif defined(DB1550_BOOT_ONLY) 77 - static struct mtd_partition db1550_partitions[] = { 78 - /* assume boot[2:0]:swap is '0000' or '1000', which translates to: 79 - * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash 80 - */ 81 - { 82 - .name = "User FS", 83 - .size = 0x03c00000, 84 - .offset = 0x0000000 85 - },{ 86 - .name = "yamon", 87 - .size = 0x0100000, 88 - .offset = MTDPART_OFS_APPEND, 89 - .mask_flags = MTD_WRITEABLE 90 - },{ 91 - .name = "raw kernel", 92 - .size = (0x300000-0x40000), /* last 256KB is yamon env */ 93 - .offset = MTDPART_OFS_APPEND, 94 - } 95 - }; 96 - #elif defined(DB1550_USER_ONLY) 97 - static struct mtd_partition db1550_partitions[] = { 98 - /* assume boot[2:0]:swap is '0000' or '1000', which translates to: 99 - * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash 100 - */ 101 - { 102 - .name = "User FS", 103 - .size = (0x4000000 - 0x200000), /* reserve 2MB for raw kernel */ 104 - .offset = 0x0000000 105 - },{ 106 - .name = "raw kernel", 107 - .size = MTDPART_SIZ_FULL, 108 - .offset = MTDPART_OFS_APPEND, 109 - } 110 - }; 111 - #else 112 - #error MTD_DB1550 define combo error /* should never happen */ 113 - #endif 114 - 115 - #define NB_OF(x) (sizeof(x)/sizeof(x[0])) 116 - 117 - static struct mtd_info *mymtd; 118 - 119 - /* 120 - * Probe the flash density and setup window address and size 121 - * based on user CONFIG options. There are times when we don't 122 - * want the MTD driver to be probing the boot or user flash, 123 - * so having the option to enable only one bank is important. 124 - */ 125 - int setup_flash_params(void) 126 - { 127 - #if defined(DB1550_BOTH_BANKS) 128 - window_addr = 0x18000000; 129 - window_size = 0x8000000; 130 - #elif defined(DB1550_BOOT_ONLY) 131 - window_addr = 0x1C000000; 132 - window_size = 0x4000000; 133 - #else /* USER ONLY */ 134 - window_addr = 0x18000000; 135 - window_size = 0x4000000; 136 - #endif 137 - return 0; 138 - } 139 - 140 - int __init db1550_mtd_init(void) 141 - { 142 - struct mtd_partition *parts; 143 - int nb_parts = 0; 144 - 145 - /* Default flash bankwidth */ 146 - db1550_map.bankwidth = flash_bankwidth; 147 - 148 - if (setup_flash_params()) 149 - return -ENXIO; 150 - 151 - /* 152 - * Static partition definition selection 153 - */ 154 - parts = db1550_partitions; 155 - nb_parts = NB_OF(db1550_partitions); 156 - db1550_map.size = window_size; 157 - 158 - /* 159 - * Now let's probe for the actual flash. Do it here since 160 - * specific machine settings might have been set above. 161 - */ 162 - printk(KERN_NOTICE "Db1550 flash: probing %d-bit flash bus\n", 163 - db1550_map.bankwidth*8); 164 - db1550_map.virt = ioremap(window_addr, window_size); 165 - mymtd = do_map_probe("cfi_probe", &db1550_map); 166 - if (!mymtd) return -ENXIO; 167 - mymtd->owner = THIS_MODULE; 168 - 169 - add_mtd_partitions(mymtd, parts, nb_parts); 170 - return 0; 171 - } 172 - 173 - static void __exit db1550_mtd_cleanup(void) 174 - { 175 - if (mymtd) { 176 - del_mtd_partitions(mymtd); 177 - map_destroy(mymtd); 178 - iounmap((void *) db1550_map.virt); 179 - } 180 - } 181 - 182 - module_init(db1550_mtd_init); 183 - module_exit(db1550_mtd_cleanup); 184 - 185 - MODULE_AUTHOR("Embedded Edge, LLC"); 186 - MODULE_DESCRIPTION("Db1550 mtd map driver"); 187 - MODULE_LICENSE("GPL");
-226
drivers/mtd/maps/db1x00-flash.c
··· 1 - /* 2 - * Flash memory access on Alchemy Db1xxx boards 3 - * 4 - * $Id: db1x00-flash.c,v 1.6 2004/11/04 13:24:14 gleixner Exp $ 5 - * 6 - * (C) 2003 Pete Popov <ppopov@embeddedalley.com> 7 - * 8 - */ 9 - 10 - #include <linux/config.h> 11 - #include <linux/module.h> 12 - #include <linux/types.h> 13 - #include <linux/init.h> 14 - #include <linux/kernel.h> 15 - 16 - #include <linux/mtd/mtd.h> 17 - #include <linux/mtd/map.h> 18 - #include <linux/mtd/partitions.h> 19 - 20 - #include <asm/io.h> 21 - 22 - #ifdef DEBUG_RW 23 - #define DBG(x...) printk(x) 24 - #else 25 - #define DBG(x...) 26 - #endif 27 - 28 - /* MTD CONFIG OPTIONS */ 29 - #if defined(CONFIG_MTD_DB1X00_BOOT) && defined(CONFIG_MTD_DB1X00_USER) 30 - #define DB1X00_BOTH_BANKS 31 - #elif defined(CONFIG_MTD_DB1X00_BOOT) && !defined(CONFIG_MTD_DB1X00_USER) 32 - #define DB1X00_BOOT_ONLY 33 - #elif !defined(CONFIG_MTD_DB1X00_BOOT) && defined(CONFIG_MTD_DB1X00_USER) 34 - #define DB1X00_USER_ONLY 35 - #endif 36 - 37 - static unsigned long window_addr; 38 - static unsigned long window_size; 39 - static unsigned long flash_size; 40 - 41 - static unsigned short *bcsr = (unsigned short *)0xAE000000; 42 - static unsigned char flash_bankwidth = 4; 43 - 44 - /* 45 - * The Db1x boards support different flash densities. We setup 46 - * the mtd_partition structures below for default of 64Mbit 47 - * flash densities, and override the partitions sizes, if 48 - * necessary, after we check the board status register. 49 - */ 50 - 51 - #ifdef DB1X00_BOTH_BANKS 52 - /* both banks will be used. Combine the first bank and the first 53 - * part of the second bank together into a single jffs/jffs2 54 - * partition. 55 - */ 56 - static struct mtd_partition db1x00_partitions[] = { 57 - { 58 - .name = "User FS", 59 - .size = 0x1c00000, 60 - .offset = 0x0000000 61 - },{ 62 - .name = "yamon", 63 - .size = 0x0100000, 64 - .offset = MTDPART_OFS_APPEND, 65 - .mask_flags = MTD_WRITEABLE 66 - },{ 67 - .name = "raw kernel", 68 - .size = (0x300000-0x40000), /* last 256KB is env */ 69 - .offset = MTDPART_OFS_APPEND, 70 - } 71 - }; 72 - #elif defined(DB1X00_BOOT_ONLY) 73 - static struct mtd_partition db1x00_partitions[] = { 74 - { 75 - .name = "User FS", 76 - .size = 0x00c00000, 77 - .offset = 0x0000000 78 - },{ 79 - .name = "yamon", 80 - .size = 0x0100000, 81 - .offset = MTDPART_OFS_APPEND, 82 - .mask_flags = MTD_WRITEABLE 83 - },{ 84 - .name = "raw kernel", 85 - .size = (0x300000-0x40000), /* last 256KB is env */ 86 - .offset = MTDPART_OFS_APPEND, 87 - } 88 - }; 89 - #elif defined(DB1X00_USER_ONLY) 90 - static struct mtd_partition db1x00_partitions[] = { 91 - { 92 - .name = "User FS", 93 - .size = 0x0e00000, 94 - .offset = 0x0000000 95 - },{ 96 - .name = "raw kernel", 97 - .size = MTDPART_SIZ_FULL, 98 - .offset = MTDPART_OFS_APPEND, 99 - } 100 - }; 101 - #else 102 - #error MTD_DB1X00 define combo error /* should never happen */ 103 - #endif 104 - #define NB_OF(x) (sizeof(x)/sizeof(x[0])) 105 - 106 - #define NAME "Db1x00 Linux Flash" 107 - 108 - static struct map_info db1xxx_mtd_map = { 109 - .name = NAME, 110 - }; 111 - 112 - static struct mtd_partition *parsed_parts; 113 - static struct mtd_info *db1xxx_mtd; 114 - 115 - /* 116 - * Probe the flash density and setup window address and size 117 - * based on user CONFIG options. There are times when we don't 118 - * want the MTD driver to be probing the boot or user flash, 119 - * so having the option to enable only one bank is important. 120 - */ 121 - int setup_flash_params(void) 122 - { 123 - switch ((bcsr[2] >> 14) & 0x3) { 124 - case 0: /* 64Mbit devices */ 125 - flash_size = 0x800000; /* 8MB per part */ 126 - #if defined(DB1X00_BOTH_BANKS) 127 - window_addr = 0x1E000000; 128 - window_size = 0x2000000; 129 - #elif defined(DB1X00_BOOT_ONLY) 130 - window_addr = 0x1F000000; 131 - window_size = 0x1000000; 132 - #else /* USER ONLY */ 133 - window_addr = 0x1E000000; 134 - window_size = 0x1000000; 135 - #endif 136 - break; 137 - case 1: 138 - /* 128 Mbit devices */ 139 - flash_size = 0x1000000; /* 16MB per part */ 140 - #if defined(DB1X00_BOTH_BANKS) 141 - window_addr = 0x1C000000; 142 - window_size = 0x4000000; 143 - /* USERFS from 0x1C00 0000 to 0x1FC0 0000 */ 144 - db1x00_partitions[0].size = 0x3C00000; 145 - #elif defined(DB1X00_BOOT_ONLY) 146 - window_addr = 0x1E000000; 147 - window_size = 0x2000000; 148 - /* USERFS from 0x1E00 0000 to 0x1FC0 0000 */ 149 - db1x00_partitions[0].size = 0x1C00000; 150 - #else /* USER ONLY */ 151 - window_addr = 0x1C000000; 152 - window_size = 0x2000000; 153 - /* USERFS from 0x1C00 0000 to 0x1DE00000 */ 154 - db1x00_partitions[0].size = 0x1DE0000; 155 - #endif 156 - break; 157 - case 2: 158 - /* 256 Mbit devices */ 159 - flash_size = 0x4000000; /* 64MB per part */ 160 - #if defined(DB1X00_BOTH_BANKS) 161 - return 1; 162 - #elif defined(DB1X00_BOOT_ONLY) 163 - /* Boot ROM flash bank only; no user bank */ 164 - window_addr = 0x1C000000; 165 - window_size = 0x4000000; 166 - /* USERFS from 0x1C00 0000 to 0x1FC00000 */ 167 - db1x00_partitions[0].size = 0x3C00000; 168 - #else /* USER ONLY */ 169 - return 1; 170 - #endif 171 - break; 172 - default: 173 - return 1; 174 - } 175 - db1xxx_mtd_map.size = window_size; 176 - db1xxx_mtd_map.bankwidth = flash_bankwidth; 177 - db1xxx_mtd_map.phys = window_addr; 178 - db1xxx_mtd_map.bankwidth = flash_bankwidth; 179 - return 0; 180 - } 181 - 182 - int __init db1x00_mtd_init(void) 183 - { 184 - struct mtd_partition *parts; 185 - int nb_parts = 0; 186 - 187 - if (setup_flash_params()) 188 - return -ENXIO; 189 - 190 - /* 191 - * Static partition definition selection 192 - */ 193 - parts = db1x00_partitions; 194 - nb_parts = NB_OF(db1x00_partitions); 195 - 196 - /* 197 - * Now let's probe for the actual flash. Do it here since 198 - * specific machine settings might have been set above. 199 - */ 200 - printk(KERN_NOTICE "Db1xxx flash: probing %d-bit flash bus\n", 201 - db1xxx_mtd_map.bankwidth*8); 202 - db1xxx_mtd_map.virt = ioremap(window_addr, window_size); 203 - db1xxx_mtd = do_map_probe("cfi_probe", &db1xxx_mtd_map); 204 - if (!db1xxx_mtd) return -ENXIO; 205 - db1xxx_mtd->owner = THIS_MODULE; 206 - 207 - add_mtd_partitions(db1xxx_mtd, parts, nb_parts); 208 - return 0; 209 - } 210 - 211 - static void __exit db1x00_mtd_cleanup(void) 212 - { 213 - if (db1xxx_mtd) { 214 - del_mtd_partitions(db1xxx_mtd); 215 - map_destroy(db1xxx_mtd); 216 - if (parsed_parts) 217 - kfree(parsed_parts); 218 - } 219 - } 220 - 221 - module_init(db1x00_mtd_init); 222 - module_exit(db1x00_mtd_cleanup); 223 - 224 - MODULE_AUTHOR("Pete Popov"); 225 - MODULE_DESCRIPTION("Db1x00 mtd map driver"); 226 - MODULE_LICENSE("GPL");
-228
drivers/mtd/maps/elan-104nc.c
··· 1 - /* elan-104nc.c -- MTD map driver for Arcom Control Systems ELAN-104NC 2 - 3 - Copyright (C) 2000 Arcom Control System Ltd 4 - 5 - This program is free software; you can redistribute it and/or modify 6 - it under the terms of the GNU General Public License as published by 7 - the Free Software Foundation; either version 2 of the License, or 8 - (at your option) any later version. 9 - 10 - This program is distributed in the hope that it will be useful, 11 - but WITHOUT ANY WARRANTY; without even the implied warranty of 12 - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 13 - GNU General Public License for more details. 14 - 15 - You should have received a copy of the GNU General Public License 16 - along with this program; if not, write to the Free Software 17 - Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA 18 - 19 - $Id: elan-104nc.c,v 1.25 2004/11/28 09:40:39 dwmw2 Exp $ 20 - 21 - The ELAN-104NC has up to 8 Mibyte of Intel StrataFlash (28F320/28F640) in x16 22 - mode. This drivers uses the CFI probe and Intel Extended Command Set drivers. 23 - 24 - The flash is accessed as follows: 25 - 26 - 32 kbyte memory window at 0xb0000-0xb7fff 27 - 28 - 16 bit I/O port (0x22) for some sort of paging. 29 - 30 - The single flash device is divided into 3 partition which appear as separate 31 - MTD devices. 32 - 33 - Linux thinks that the I/O port is used by the PIC and hence check_region() will 34 - always fail. So we don't do it. I just hope it doesn't break anything. 35 - */ 36 - #include <linux/module.h> 37 - #include <linux/slab.h> 38 - #include <linux/ioport.h> 39 - #include <linux/init.h> 40 - #include <asm/io.h> 41 - 42 - #include <linux/mtd/map.h> 43 - #include <linux/mtd/mtd.h> 44 - #include <linux/mtd/partitions.h> 45 - 46 - #define WINDOW_START 0xb0000 47 - /* Number of bits in offset. */ 48 - #define WINDOW_SHIFT 15 49 - #define WINDOW_LENGTH (1 << WINDOW_SHIFT) 50 - /* The bits for the offset into the window. */ 51 - #define WINDOW_MASK (WINDOW_LENGTH-1) 52 - #define PAGE_IO 0x22 53 - #define PAGE_IO_SIZE 2 54 - 55 - static volatile int page_in_window = -1; // Current page in window. 56 - static void __iomem *iomapadr; 57 - static DEFINE_SPINLOCK(elan_104nc_spin); 58 - 59 - /* partition_info gives details on the logical partitions that the split the 60 - * single flash device into. If the size if zero we use up to the end of the 61 - * device. */ 62 - static struct mtd_partition partition_info[]={ 63 - { .name = "ELAN-104NC flash boot partition", 64 - .offset = 0, 65 - .size = 640*1024 }, 66 - { .name = "ELAN-104NC flash partition 1", 67 - .offset = 640*1024, 68 - .size = 896*1024 }, 69 - { .name = "ELAN-104NC flash partition 2", 70 - .offset = (640+896)*1024 } 71 - }; 72 - #define NUM_PARTITIONS (sizeof(partition_info)/sizeof(partition_info[0])) 73 - 74 - /* 75 - * If no idea what is going on here. This is taken from the FlashFX stuff. 76 - */ 77 - #define ROMCS 1 78 - 79 - static inline void elan_104nc_setup(void) 80 - { 81 - u16 t; 82 - 83 - outw( 0x0023 + ROMCS*2, PAGE_IO ); 84 - t=inb( PAGE_IO+1 ); 85 - 86 - t=(t & 0xf9) | 0x04; 87 - 88 - outw( ((0x0023 + ROMCS*2) | (t << 8)), PAGE_IO ); 89 - } 90 - 91 - static inline void elan_104nc_page(struct map_info *map, unsigned long ofs) 92 - { 93 - unsigned long page = ofs >> WINDOW_SHIFT; 94 - 95 - if( page!=page_in_window ) { 96 - int cmd1; 97 - int cmd2; 98 - 99 - cmd1=(page & 0x700) + 0x0833 + ROMCS*0x4000; 100 - cmd2=((page & 0xff) << 8) + 0x0032; 101 - 102 - outw( cmd1, PAGE_IO ); 103 - outw( cmd2, PAGE_IO ); 104 - 105 - page_in_window = page; 106 - } 107 - } 108 - 109 - 110 - static map_word elan_104nc_read16(struct map_info *map, unsigned long ofs) 111 - { 112 - map_word ret; 113 - spin_lock(&elan_104nc_spin); 114 - elan_104nc_page(map, ofs); 115 - ret.x[0] = readw(iomapadr + (ofs & WINDOW_MASK)); 116 - spin_unlock(&elan_104nc_spin); 117 - return ret; 118 - } 119 - 120 - static void elan_104nc_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) 121 - { 122 - while (len) { 123 - unsigned long thislen = len; 124 - if (len > (WINDOW_LENGTH - (from & WINDOW_MASK))) 125 - thislen = WINDOW_LENGTH-(from & WINDOW_MASK); 126 - 127 - spin_lock(&elan_104nc_spin); 128 - elan_104nc_page(map, from); 129 - memcpy_fromio(to, iomapadr + (from & WINDOW_MASK), thislen); 130 - spin_unlock(&elan_104nc_spin); 131 - to += thislen; 132 - from += thislen; 133 - len -= thislen; 134 - } 135 - } 136 - 137 - static void elan_104nc_write16(struct map_info *map, map_word d, unsigned long adr) 138 - { 139 - spin_lock(&elan_104nc_spin); 140 - elan_104nc_page(map, adr); 141 - writew(d.x[0], iomapadr + (adr & WINDOW_MASK)); 142 - spin_unlock(&elan_104nc_spin); 143 - } 144 - 145 - static void elan_104nc_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len) 146 - { 147 - while(len) { 148 - unsigned long thislen = len; 149 - if (len > (WINDOW_LENGTH - (to & WINDOW_MASK))) 150 - thislen = WINDOW_LENGTH-(to & WINDOW_MASK); 151 - 152 - spin_lock(&elan_104nc_spin); 153 - elan_104nc_page(map, to); 154 - memcpy_toio(iomapadr + (to & WINDOW_MASK), from, thislen); 155 - spin_unlock(&elan_104nc_spin); 156 - to += thislen; 157 - from += thislen; 158 - len -= thislen; 159 - } 160 - } 161 - 162 - static struct map_info elan_104nc_map = { 163 - .name = "ELAN-104NC flash", 164 - .phys = NO_XIP, 165 - .size = 8*1024*1024, /* this must be set to a maximum possible amount 166 - of flash so the cfi probe routines find all 167 - the chips */ 168 - .bankwidth = 2, 169 - .read = elan_104nc_read16, 170 - .copy_from = elan_104nc_copy_from, 171 - .write = elan_104nc_write16, 172 - .copy_to = elan_104nc_copy_to 173 - }; 174 - 175 - /* MTD device for all of the flash. */ 176 - static struct mtd_info *all_mtd; 177 - 178 - static void cleanup_elan_104nc(void) 179 - { 180 - if( all_mtd ) { 181 - del_mtd_partitions( all_mtd ); 182 - map_destroy( all_mtd ); 183 - } 184 - 185 - iounmap(iomapadr); 186 - } 187 - 188 - static int __init init_elan_104nc(void) 189 - { 190 - /* Urg! We use I/O port 0x22 without request_region()ing it, 191 - because it's already allocated to the PIC. */ 192 - 193 - iomapadr = ioremap(WINDOW_START, WINDOW_LENGTH); 194 - if (!iomapadr) { 195 - printk( KERN_ERR"%s: failed to ioremap memory region\n", 196 - elan_104nc_map.name ); 197 - return -EIO; 198 - } 199 - 200 - printk( KERN_INFO"%s: IO:0x%x-0x%x MEM:0x%x-0x%x\n", 201 - elan_104nc_map.name, 202 - PAGE_IO, PAGE_IO+PAGE_IO_SIZE-1, 203 - WINDOW_START, WINDOW_START+WINDOW_LENGTH-1 ); 204 - 205 - elan_104nc_setup(); 206 - 207 - /* Probe for chip. */ 208 - all_mtd = do_map_probe("cfi_probe", &elan_104nc_map ); 209 - if( !all_mtd ) { 210 - cleanup_elan_104nc(); 211 - return -ENXIO; 212 - } 213 - 214 - all_mtd->owner = THIS_MODULE; 215 - 216 - /* Create MTD devices for each partition. */ 217 - add_mtd_partitions( all_mtd, partition_info, NUM_PARTITIONS ); 218 - 219 - return 0; 220 - } 221 - 222 - module_init(init_elan_104nc); 223 - module_exit(cleanup_elan_104nc); 224 - 225 - 226 - MODULE_LICENSE("GPL"); 227 - MODULE_AUTHOR("Arcom Control Systems Ltd."); 228 - MODULE_DESCRIPTION("MTD map driver for Arcom Control Systems ELAN-104NC");
+3 -3
drivers/mtd/maps/ichxrom.c
··· 2 2 * ichxrom.c 3 3 * 4 4 * Normal mappings of chips in physical memory 5 - * $Id: ichxrom.c,v 1.16 2004/11/28 09:40:39 dwmw2 Exp $ 5 + * $Id: ichxrom.c,v 1.18 2005/07/07 10:26:20 dwmw2 Exp $ 6 6 */ 7 7 8 8 #include <linux/module.h> ··· 338 338 { 0, }, 339 339 }; 340 340 341 + #if 0 341 342 MODULE_DEVICE_TABLE(pci, ichxrom_pci_tbl); 342 343 343 - #if 0 344 344 static struct pci_driver ichxrom_driver = { 345 345 .name = MOD_NAME, 346 346 .id_table = ichxrom_pci_tbl, ··· 366 366 } 367 367 return -ENXIO; 368 368 #if 0 369 - return pci_module_init(&ichxrom_driver); 369 + return pci_register_driver(&ichxrom_driver); 370 370 #endif 371 371 } 372 372
+1 -6
drivers/mtd/maps/ixp2000.c
··· 1 1 /* 2 - * $Id: ixp2000.c,v 1.5 2004/11/16 17:15:48 dsaxena Exp $ 2 + * $Id: ixp2000.c,v 1.6 2005/03/18 14:07:46 gleixner Exp $ 3 3 * 4 4 * drivers/mtd/maps/ixp2000.c 5 5 * ··· 215 215 err = -EIO; 216 216 goto Error; 217 217 } 218 - 219 - /* 220 - * Setup read mode for FLASH 221 - */ 222 - *IXP2000_SLOWPORT_FRM = 1; 223 218 224 219 #if defined(__ARMEB__) 225 220 /*
+178
drivers/mtd/maps/mainstone-flash.c
··· 1 + /* 2 + * $Id: $ 3 + * 4 + * Map driver for the Mainstone developer platform. 5 + * 6 + * Author: Nicolas Pitre 7 + * Copyright: (C) 2001 MontaVista Software Inc. 8 + * 9 + * This program is free software; you can redistribute it and/or modify 10 + * it under the terms of the GNU General Public License version 2 as 11 + * published by the Free Software Foundation. 12 + */ 13 + 14 + #include <linux/module.h> 15 + #include <linux/types.h> 16 + #include <linux/kernel.h> 17 + #include <linux/init.h> 18 + #include <linux/dma-mapping.h> 19 + #include <linux/mtd/mtd.h> 20 + #include <linux/mtd/map.h> 21 + #include <linux/mtd/partitions.h> 22 + #include <asm/io.h> 23 + #include <asm/hardware.h> 24 + #include <asm/arch/pxa-regs.h> 25 + #include <asm/arch/mainstone.h> 26 + 27 + 28 + #define ROM_ADDR 0x00000000 29 + #define FLASH_ADDR 0x04000000 30 + 31 + #define WINDOW_SIZE 0x04000000 32 + 33 + static void mainstone_map_inval_cache(struct map_info *map, unsigned long from, 34 + ssize_t len) 35 + { 36 + consistent_sync((char *)map->cached + from, len, DMA_FROM_DEVICE); 37 + } 38 + 39 + static struct map_info mainstone_maps[2] = { { 40 + .size = WINDOW_SIZE, 41 + .phys = PXA_CS0_PHYS, 42 + .inval_cache = mainstone_map_inval_cache, 43 + }, { 44 + .size = WINDOW_SIZE, 45 + .phys = PXA_CS1_PHYS, 46 + .inval_cache = mainstone_map_inval_cache, 47 + } }; 48 + 49 + static struct mtd_partition mainstone_partitions[] = { 50 + { 51 + .name = "Bootloader", 52 + .size = 0x00040000, 53 + .offset = 0, 54 + .mask_flags = MTD_WRITEABLE /* force read-only */ 55 + },{ 56 + .name = "Kernel", 57 + .size = 0x00400000, 58 + .offset = 0x00040000, 59 + },{ 60 + .name = "Filesystem", 61 + .size = MTDPART_SIZ_FULL, 62 + .offset = 0x00440000 63 + } 64 + }; 65 + 66 + static struct mtd_info *mymtds[2]; 67 + static struct mtd_partition *parsed_parts[2]; 68 + static int nr_parsed_parts[2]; 69 + 70 + static const char *probes[] = { "RedBoot", "cmdlinepart", NULL }; 71 + 72 + static int __init init_mainstone(void) 73 + { 74 + int SW7 = 0; /* FIXME: get from SCR (Mst doc section 3.2.1.1) */ 75 + int ret = 0, i; 76 + 77 + mainstone_maps[0].bankwidth = (BOOT_DEF & 1) ? 2 : 4; 78 + mainstone_maps[1].bankwidth = 4; 79 + 80 + /* Compensate for SW7 which swaps the flash banks */ 81 + mainstone_maps[SW7].name = "processor flash"; 82 + mainstone_maps[SW7 ^ 1].name = "main board flash"; 83 + 84 + printk(KERN_NOTICE "Mainstone configured to boot from %s\n", 85 + mainstone_maps[0].name); 86 + 87 + for (i = 0; i < 2; i++) { 88 + mainstone_maps[i].virt = ioremap(mainstone_maps[i].phys, 89 + WINDOW_SIZE); 90 + if (!mainstone_maps[i].virt) { 91 + printk(KERN_WARNING "Failed to ioremap %s\n", 92 + mainstone_maps[i].name); 93 + if (!ret) 94 + ret = -ENOMEM; 95 + continue; 96 + } 97 + mainstone_maps[i].cached = 98 + ioremap_cached(mainstone_maps[i].phys, WINDOW_SIZE); 99 + if (!mainstone_maps[i].cached) 100 + printk(KERN_WARNING "Failed to ioremap cached %s\n", 101 + mainstone_maps[i].name); 102 + simple_map_init(&mainstone_maps[i]); 103 + 104 + printk(KERN_NOTICE 105 + "Probing %s at physical address 0x%08lx" 106 + " (%d-bit bankwidth)\n", 107 + mainstone_maps[i].name, mainstone_maps[i].phys, 108 + mainstone_maps[i].bankwidth * 8); 109 + 110 + mymtds[i] = do_map_probe("cfi_probe", &mainstone_maps[i]); 111 + 112 + if (!mymtds[i]) { 113 + iounmap((void *)mainstone_maps[i].virt); 114 + if (mainstone_maps[i].cached) 115 + iounmap(mainstone_maps[i].cached); 116 + if (!ret) 117 + ret = -EIO; 118 + continue; 119 + } 120 + mymtds[i]->owner = THIS_MODULE; 121 + 122 + ret = parse_mtd_partitions(mymtds[i], probes, 123 + &parsed_parts[i], 0); 124 + 125 + if (ret > 0) 126 + nr_parsed_parts[i] = ret; 127 + } 128 + 129 + if (!mymtds[0] && !mymtds[1]) 130 + return ret; 131 + 132 + for (i = 0; i < 2; i++) { 133 + if (!mymtds[i]) { 134 + printk(KERN_WARNING "%s is absent. Skipping\n", 135 + mainstone_maps[i].name); 136 + } else if (nr_parsed_parts[i]) { 137 + add_mtd_partitions(mymtds[i], parsed_parts[i], 138 + nr_parsed_parts[i]); 139 + } else if (!i) { 140 + printk("Using static partitions on %s\n", 141 + mainstone_maps[i].name); 142 + add_mtd_partitions(mymtds[i], mainstone_partitions, 143 + ARRAY_SIZE(mainstone_partitions)); 144 + } else { 145 + printk("Registering %s as whole device\n", 146 + mainstone_maps[i].name); 147 + add_mtd_device(mymtds[i]); 148 + } 149 + } 150 + return 0; 151 + } 152 + 153 + static void __exit cleanup_mainstone(void) 154 + { 155 + int i; 156 + for (i = 0; i < 2; i++) { 157 + if (!mymtds[i]) 158 + continue; 159 + 160 + if (nr_parsed_parts[i] || !i) 161 + del_mtd_partitions(mymtds[i]); 162 + else 163 + del_mtd_device(mymtds[i]); 164 + 165 + map_destroy(mymtds[i]); 166 + iounmap((void *)mainstone_maps[i].virt); 167 + if (mainstone_maps[i].cached) 168 + iounmap(mainstone_maps[i].cached); 169 + kfree(parsed_parts[i]); 170 + } 171 + } 172 + 173 + module_init(init_mainstone); 174 + module_exit(cleanup_mainstone); 175 + 176 + MODULE_LICENSE("GPL"); 177 + MODULE_AUTHOR("Nicolas Pitre <nico@cam.org>"); 178 + MODULE_DESCRIPTION("MTD map driver for Intel Mainstone");
+6 -5
drivers/mtd/maps/map_funcs.c
··· 1 1 /* 2 - * $Id: map_funcs.c,v 1.9 2004/07/13 22:33:15 dwmw2 Exp $ 2 + * $Id: map_funcs.c,v 1.10 2005/06/06 23:04:36 tpoynor Exp $ 3 3 * 4 4 * Out-of-line map I/O functions for simple maps when CONFIG_COMPLEX_MAPPINGS 5 5 * is enabled. ··· 9 9 #include <linux/module.h> 10 10 11 11 #include <linux/mtd/map.h> 12 + #include <linux/mtd/xip.h> 12 13 13 - static map_word simple_map_read(struct map_info *map, unsigned long ofs) 14 + static map_word __xipram simple_map_read(struct map_info *map, unsigned long ofs) 14 15 { 15 16 return inline_map_read(map, ofs); 16 17 } 17 18 18 - static void simple_map_write(struct map_info *map, const map_word datum, unsigned long ofs) 19 + static void __xipram simple_map_write(struct map_info *map, const map_word datum, unsigned long ofs) 19 20 { 20 21 inline_map_write(map, datum, ofs); 21 22 } 22 23 23 - static void simple_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) 24 + static void __xipram simple_map_copy_from(struct map_info *map, void *to, unsigned long from, ssize_t len) 24 25 { 25 26 inline_map_copy_from(map, to, from, len); 26 27 } 27 28 28 - static void simple_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len) 29 + static void __xipram simple_map_copy_to(struct map_info *map, unsigned long to, const void *from, ssize_t len) 29 30 { 30 31 inline_map_copy_to(map, to, from, len); 31 32 }
+179
drivers/mtd/maps/omap_nor.c
··· 1 + /* 2 + * Flash memory support for various TI OMAP boards 3 + * 4 + * Copyright (C) 2001-2002 MontaVista Software Inc. 5 + * Copyright (C) 2003-2004 Texas Instruments 6 + * Copyright (C) 2004 Nokia Corporation 7 + * 8 + * Assembled using driver code copyright the companies above 9 + * and written by David Brownell, Jian Zhang <jzhang@ti.com>, 10 + * Tony Lindgren <tony@atomide.com> and others. 11 + * 12 + * This program is free software; you can redistribute it and/or modify it 13 + * under the terms of the GNU General Public License as published by the 14 + * Free Software Foundation; either version 2 of the License, or (at your 15 + * option) any later version. 16 + * 17 + * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED 18 + * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 19 + * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN 20 + * NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 21 + * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 22 + * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF 23 + * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON 24 + * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 25 + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 26 + * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 27 + * 28 + * You should have received a copy of the GNU General Public License along 29 + * with this program; if not, write to the Free Software Foundation, Inc., 30 + * 675 Mass Ave, Cambridge, MA 02139, USA. 31 + */ 32 + 33 + #include <linux/device.h> 34 + #include <linux/module.h> 35 + #include <linux/types.h> 36 + #include <linux/kernel.h> 37 + #include <linux/init.h> 38 + #include <linux/ioport.h> 39 + #include <linux/mtd/mtd.h> 40 + #include <linux/mtd/map.h> 41 + #include <linux/mtd/partitions.h> 42 + 43 + #include <asm/io.h> 44 + #include <asm/hardware.h> 45 + #include <asm/mach-types.h> 46 + #include <asm/mach/flash.h> 47 + #include <asm/arch/tc.h> 48 + 49 + #ifdef CONFIG_MTD_PARTITIONS 50 + static const char *part_probes[] = { /* "RedBoot", */ "cmdlinepart", NULL }; 51 + #endif 52 + 53 + struct omapflash_info { 54 + struct mtd_partition *parts; 55 + struct mtd_info *mtd; 56 + struct map_info map; 57 + }; 58 + 59 + static void omap_set_vpp(struct map_info *map, int enable) 60 + { 61 + static int count; 62 + 63 + if (enable) { 64 + if (count++ == 0) 65 + OMAP_EMIFS_CONFIG_REG |= OMAP_EMIFS_CONFIG_WP; 66 + } else { 67 + if (count && (--count == 0)) 68 + OMAP_EMIFS_CONFIG_REG &= ~OMAP_EMIFS_CONFIG_WP; 69 + } 70 + } 71 + 72 + static int __devinit omapflash_probe(struct device *dev) 73 + { 74 + int err; 75 + struct omapflash_info *info; 76 + struct platform_device *pdev = to_platform_device(dev); 77 + struct flash_platform_data *pdata = pdev->dev.platform_data; 78 + struct resource *res = pdev->resource; 79 + unsigned long size = res->end - res->start + 1; 80 + 81 + info = kmalloc(sizeof(struct omapflash_info), GFP_KERNEL); 82 + if (!info) 83 + return -ENOMEM; 84 + 85 + memset(info, 0, sizeof(struct omapflash_info)); 86 + 87 + if (!request_mem_region(res->start, size, "flash")) { 88 + err = -EBUSY; 89 + goto out_free_info; 90 + } 91 + 92 + info->map.virt = ioremap(res->start, size); 93 + if (!info->map.virt) { 94 + err = -ENOMEM; 95 + goto out_release_mem_region; 96 + } 97 + info->map.name = pdev->dev.bus_id; 98 + info->map.phys = res->start; 99 + info->map.size = size; 100 + info->map.bankwidth = pdata->width; 101 + info->map.set_vpp = omap_set_vpp; 102 + 103 + simple_map_init(&info->map); 104 + info->mtd = do_map_probe(pdata->map_name, &info->map); 105 + if (!info->mtd) { 106 + err = -EIO; 107 + goto out_iounmap; 108 + } 109 + info->mtd->owner = THIS_MODULE; 110 + 111 + #ifdef CONFIG_MTD_PARTITIONS 112 + err = parse_mtd_partitions(info->mtd, part_probes, &info->parts, 0); 113 + if (err > 0) 114 + add_mtd_partitions(info->mtd, info->parts, err); 115 + else if (err < 0 && pdata->parts) 116 + add_mtd_partitions(info->mtd, pdata->parts, pdata->nr_parts); 117 + else 118 + #endif 119 + add_mtd_device(info->mtd); 120 + 121 + dev_set_drvdata(&pdev->dev, info); 122 + 123 + return 0; 124 + 125 + out_iounmap: 126 + iounmap(info->map.virt); 127 + out_release_mem_region: 128 + release_mem_region(res->start, size); 129 + out_free_info: 130 + kfree(info); 131 + 132 + return err; 133 + } 134 + 135 + static int __devexit omapflash_remove(struct device *dev) 136 + { 137 + struct platform_device *pdev = to_platform_device(dev); 138 + struct omapflash_info *info = dev_get_drvdata(&pdev->dev); 139 + 140 + dev_set_drvdata(&pdev->dev, NULL); 141 + 142 + if (info) { 143 + if (info->parts) { 144 + del_mtd_partitions(info->mtd); 145 + kfree(info->parts); 146 + } else 147 + del_mtd_device(info->mtd); 148 + map_destroy(info->mtd); 149 + release_mem_region(info->map.phys, info->map.size); 150 + iounmap((void __iomem *) info->map.virt); 151 + kfree(info); 152 + } 153 + 154 + return 0; 155 + } 156 + 157 + static struct device_driver omapflash_driver = { 158 + .name = "omapflash", 159 + .bus = &platform_bus_type, 160 + .probe = omapflash_probe, 161 + .remove = __devexit_p(omapflash_remove), 162 + }; 163 + 164 + static int __init omapflash_init(void) 165 + { 166 + return driver_register(&omapflash_driver); 167 + } 168 + 169 + static void __exit omapflash_exit(void) 170 + { 171 + driver_unregister(&omapflash_driver); 172 + } 173 + 174 + module_init(omapflash_init); 175 + module_exit(omapflash_exit); 176 + 177 + MODULE_LICENSE("GPL"); 178 + MODULE_DESCRIPTION("MTD NOR map driver for TI OMAP boards"); 179 +
-203
drivers/mtd/maps/pb1550-flash.c
··· 1 - /* 2 - * Flash memory access on Alchemy Pb1550 board 3 - * 4 - * $Id: pb1550-flash.c,v 1.6 2004/11/04 13:24:15 gleixner Exp $ 5 - * 6 - * (C) 2004 Embedded Edge, LLC, based on pb1550-flash.c: 7 - * (C) 2003 Pete Popov <ppopov@pacbell.net> 8 - * 9 - */ 10 - 11 - #include <linux/config.h> 12 - #include <linux/init.h> 13 - #include <linux/module.h> 14 - #include <linux/types.h> 15 - #include <linux/kernel.h> 16 - 17 - #include <linux/mtd/mtd.h> 18 - #include <linux/mtd/map.h> 19 - #include <linux/mtd/partitions.h> 20 - 21 - #include <asm/io.h> 22 - #include <asm/au1000.h> 23 - #include <asm/pb1550.h> 24 - 25 - #ifdef DEBUG_RW 26 - #define DBG(x...) printk(x) 27 - #else 28 - #define DBG(x...) 29 - #endif 30 - 31 - static unsigned long window_addr; 32 - static unsigned long window_size; 33 - 34 - 35 - static struct map_info pb1550_map = { 36 - .name = "Pb1550 flash", 37 - }; 38 - 39 - static unsigned char flash_bankwidth = 4; 40 - 41 - /* 42 - * Support only 64MB NOR Flash parts 43 - */ 44 - 45 - #ifdef PB1550_BOTH_BANKS 46 - /* both banks will be used. Combine the first bank and the first 47 - * part of the second bank together into a single jffs/jffs2 48 - * partition. 49 - */ 50 - static struct mtd_partition pb1550_partitions[] = { 51 - /* assume boot[2:0]:swap is '0000' or '1000', which translates to: 52 - * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash 53 - * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash 54 - */ 55 - { 56 - .name = "User FS", 57 - .size = (0x1FC00000 - 0x18000000), 58 - .offset = 0x0000000 59 - },{ 60 - .name = "yamon", 61 - .size = 0x0100000, 62 - .offset = MTDPART_OFS_APPEND, 63 - .mask_flags = MTD_WRITEABLE 64 - },{ 65 - .name = "raw kernel", 66 - .size = (0x300000 - 0x40000), /* last 256KB is yamon env */ 67 - .offset = MTDPART_OFS_APPEND, 68 - } 69 - }; 70 - #elif defined(PB1550_BOOT_ONLY) 71 - static struct mtd_partition pb1550_partitions[] = { 72 - /* assume boot[2:0]:swap is '0000' or '1000', which translates to: 73 - * 1C00 0000 1FFF FFFF CE0 64MB Boot NOR Flash 74 - */ 75 - { 76 - .name = "User FS", 77 - .size = 0x03c00000, 78 - .offset = 0x0000000 79 - },{ 80 - .name = "yamon", 81 - .size = 0x0100000, 82 - .offset = MTDPART_OFS_APPEND, 83 - .mask_flags = MTD_WRITEABLE 84 - },{ 85 - .name = "raw kernel", 86 - .size = (0x300000-0x40000), /* last 256KB is yamon env */ 87 - .offset = MTDPART_OFS_APPEND, 88 - } 89 - }; 90 - #elif defined(PB1550_USER_ONLY) 91 - static struct mtd_partition pb1550_partitions[] = { 92 - /* assume boot[2:0]:swap is '0000' or '1000', which translates to: 93 - * 1800 0000 1BFF FFFF CE0 64MB Param NOR Flash 94 - */ 95 - { 96 - .name = "User FS", 97 - .size = (0x4000000 - 0x200000), /* reserve 2MB for raw kernel */ 98 - .offset = 0x0000000 99 - },{ 100 - .name = "raw kernel", 101 - .size = MTDPART_SIZ_FULL, 102 - .offset = MTDPART_OFS_APPEND, 103 - } 104 - }; 105 - #else 106 - #error MTD_PB1550 define combo error /* should never happen */ 107 - #endif 108 - 109 - #define NB_OF(x) (sizeof(x)/sizeof(x[0])) 110 - 111 - static struct mtd_info *mymtd; 112 - 113 - /* 114 - * Probe the flash density and setup window address and size 115 - * based on user CONFIG options. There are times when we don't 116 - * want the MTD driver to be probing the boot or user flash, 117 - * so having the option to enable only one bank is important. 118 - */ 119 - int setup_flash_params(void) 120 - { 121 - u16 boot_swapboot; 122 - boot_swapboot = (au_readl(MEM_STSTAT) & (0x7<<1)) | 123 - ((bcsr->status >> 6) & 0x1); 124 - printk("Pb1550 MTD: boot:swap %d\n", boot_swapboot); 125 - 126 - switch (boot_swapboot) { 127 - case 0: /* 512Mbit devices, both enabled */ 128 - case 1: 129 - case 8: 130 - case 9: 131 - #if defined(PB1550_BOTH_BANKS) 132 - window_addr = 0x18000000; 133 - window_size = 0x8000000; 134 - #elif defined(PB1550_BOOT_ONLY) 135 - window_addr = 0x1C000000; 136 - window_size = 0x4000000; 137 - #else /* USER ONLY */ 138 - window_addr = 0x1E000000; 139 - window_size = 0x4000000; 140 - #endif 141 - break; 142 - case 0xC: 143 - case 0xD: 144 - case 0xE: 145 - case 0xF: 146 - /* 64 MB Boot NOR Flash is disabled */ 147 - /* and the start address is moved to 0x0C00000 */ 148 - window_addr = 0x0C000000; 149 - window_size = 0x4000000; 150 - default: 151 - printk("Pb1550 MTD: unsupported boot:swap setting\n"); 152 - return 1; 153 - } 154 - return 0; 155 - } 156 - 157 - int __init pb1550_mtd_init(void) 158 - { 159 - struct mtd_partition *parts; 160 - int nb_parts = 0; 161 - 162 - /* Default flash bankwidth */ 163 - pb1550_map.bankwidth = flash_bankwidth; 164 - 165 - if (setup_flash_params()) 166 - return -ENXIO; 167 - 168 - /* 169 - * Static partition definition selection 170 - */ 171 - parts = pb1550_partitions; 172 - nb_parts = NB_OF(pb1550_partitions); 173 - pb1550_map.size = window_size; 174 - 175 - /* 176 - * Now let's probe for the actual flash. Do it here since 177 - * specific machine settings might have been set above. 178 - */ 179 - printk(KERN_NOTICE "Pb1550 flash: probing %d-bit flash bus\n", 180 - pb1550_map.bankwidth*8); 181 - pb1550_map.virt = ioremap(window_addr, window_size); 182 - mymtd = do_map_probe("cfi_probe", &pb1550_map); 183 - if (!mymtd) return -ENXIO; 184 - mymtd->owner = THIS_MODULE; 185 - 186 - add_mtd_partitions(mymtd, parts, nb_parts); 187 - return 0; 188 - } 189 - 190 - static void __exit pb1550_mtd_cleanup(void) 191 - { 192 - if (mymtd) { 193 - del_mtd_partitions(mymtd); 194 - map_destroy(mymtd); 195 - } 196 - } 197 - 198 - module_init(pb1550_mtd_init); 199 - module_exit(pb1550_mtd_cleanup); 200 - 201 - MODULE_AUTHOR("Embedded Edge, LLC"); 202 - MODULE_DESCRIPTION("Pb1550 mtd map driver"); 203 - MODULE_LICENSE("GPL");
-178
drivers/mtd/maps/pb1xxx-flash.c
··· 1 - /* 2 - * Flash memory access on Alchemy Pb1xxx boards 3 - * 4 - * (C) 2001 Pete Popov <ppopov@mvista.com> 5 - * 6 - * $Id: pb1xxx-flash.c,v 1.14 2004/11/04 13:24:15 gleixner Exp $ 7 - */ 8 - 9 - #include <linux/config.h> 10 - #include <linux/module.h> 11 - #include <linux/types.h> 12 - #include <linux/init.h> 13 - #include <linux/kernel.h> 14 - 15 - #include <linux/mtd/mtd.h> 16 - #include <linux/mtd/map.h> 17 - #include <linux/mtd/partitions.h> 18 - 19 - #include <asm/io.h> 20 - 21 - #ifdef DEBUG_RW 22 - #define DBG(x...) printk(x) 23 - #else 24 - #define DBG(x...) 25 - #endif 26 - 27 - #ifdef CONFIG_MIPS_PB1000 28 - 29 - #define WINDOW_ADDR 0x1F800000 30 - #define WINDOW_SIZE 0x800000 31 - 32 - static struct mtd_partition pb1xxx_partitions[] = { 33 - { 34 - .name = "yamon env", 35 - .size = 0x00020000, 36 - .offset = 0, 37 - .mask_flags = MTD_WRITEABLE}, 38 - { 39 - .name = "User FS", 40 - .size = 0x003e0000, 41 - .offset = 0x20000,}, 42 - { 43 - .name = "boot code", 44 - .size = 0x100000, 45 - .offset = 0x400000, 46 - .mask_flags = MTD_WRITEABLE}, 47 - { 48 - .name = "raw/kernel", 49 - .size = 0x300000, 50 - .offset = 0x500000} 51 - }; 52 - 53 - #elif defined(CONFIG_MIPS_PB1500) || defined(CONFIG_MIPS_PB1100) 54 - 55 - #if defined(CONFIG_MTD_PB1500_BOOT) && defined(CONFIG_MTD_PB1500_USER) 56 - /* both 32MB banks will be used. Combine the first 32MB bank and the 57 - * first 28MB of the second bank together into a single jffs/jffs2 58 - * partition. 59 - */ 60 - #define WINDOW_ADDR 0x1C000000 61 - #define WINDOW_SIZE 0x4000000 62 - static struct mtd_partition pb1xxx_partitions[] = { 63 - { 64 - .name = "User FS", 65 - .size = 0x3c00000, 66 - .offset = 0x0000000 67 - },{ 68 - .name = "yamon", 69 - .size = 0x0100000, 70 - .offset = 0x3c00000, 71 - .mask_flags = MTD_WRITEABLE 72 - },{ 73 - .name = "raw kernel", 74 - .size = 0x02c0000, 75 - .offset = 0x3d00000 76 - } 77 - }; 78 - #elif defined(CONFIG_MTD_PB1500_BOOT) && !defined(CONFIG_MTD_PB1500_USER) 79 - #define WINDOW_ADDR 0x1E000000 80 - #define WINDOW_SIZE 0x2000000 81 - static struct mtd_partition pb1xxx_partitions[] = { 82 - { 83 - .name = "User FS", 84 - .size = 0x1c00000, 85 - .offset = 0x0000000 86 - },{ 87 - .name = "yamon", 88 - .size = 0x0100000, 89 - .offset = 0x1c00000, 90 - .mask_flags = MTD_WRITEABLE 91 - },{ 92 - .name = "raw kernel", 93 - .size = 0x02c0000, 94 - .offset = 0x1d00000 95 - } 96 - }; 97 - #elif !defined(CONFIG_MTD_PB1500_BOOT) && defined(CONFIG_MTD_PB1500_USER) 98 - #define WINDOW_ADDR 0x1C000000 99 - #define WINDOW_SIZE 0x2000000 100 - static struct mtd_partition pb1xxx_partitions[] = { 101 - { 102 - .name = "User FS", 103 - .size = 0x1e00000, 104 - .offset = 0x0000000 105 - },{ 106 - .name = "raw kernel", 107 - .size = 0x0200000, 108 - .offset = 0x1e00000, 109 - } 110 - }; 111 - #else 112 - #error MTD_PB1500 define combo error /* should never happen */ 113 - #endif 114 - #else 115 - #error Unsupported board 116 - #endif 117 - 118 - #define NAME "Pb1x00 Linux Flash" 119 - #define PADDR WINDOW_ADDR 120 - #define BUSWIDTH 4 121 - #define SIZE WINDOW_SIZE 122 - #define PARTITIONS 4 123 - 124 - static struct map_info pb1xxx_mtd_map = { 125 - .name = NAME, 126 - .size = SIZE, 127 - .bankwidth = BUSWIDTH, 128 - .phys = PADDR, 129 - }; 130 - 131 - static struct mtd_info *pb1xxx_mtd; 132 - 133 - int __init pb1xxx_mtd_init(void) 134 - { 135 - struct mtd_partition *parts; 136 - int nb_parts = 0; 137 - char *part_type; 138 - 139 - /* 140 - * Static partition definition selection 141 - */ 142 - part_type = "static"; 143 - parts = pb1xxx_partitions; 144 - nb_parts = ARRAY_SIZE(pb1xxx_partitions); 145 - 146 - /* 147 - * Now let's probe for the actual flash. Do it here since 148 - * specific machine settings might have been set above. 149 - */ 150 - printk(KERN_NOTICE "Pb1xxx flash: probing %d-bit flash bus\n", 151 - BUSWIDTH*8); 152 - pb1xxx_mtd_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE); 153 - 154 - simple_map_init(&pb1xxx_mtd_map); 155 - 156 - pb1xxx_mtd = do_map_probe("cfi_probe", &pb1xxx_mtd_map); 157 - if (!pb1xxx_mtd) return -ENXIO; 158 - pb1xxx_mtd->owner = THIS_MODULE; 159 - 160 - add_mtd_partitions(pb1xxx_mtd, parts, nb_parts); 161 - return 0; 162 - } 163 - 164 - static void __exit pb1xxx_mtd_cleanup(void) 165 - { 166 - if (pb1xxx_mtd) { 167 - del_mtd_partitions(pb1xxx_mtd); 168 - map_destroy(pb1xxx_mtd); 169 - iounmap((void *) pb1xxx_mtd_map.virt); 170 - } 171 - } 172 - 173 - module_init(pb1xxx_mtd_init); 174 - module_exit(pb1xxx_mtd_cleanup); 175 - 176 - MODULE_AUTHOR("Pete Popov"); 177 - MODULE_DESCRIPTION("Pb1xxx CFI map driver"); 178 - MODULE_LICENSE("GPL");
+2 -2
drivers/mtd/maps/pci.c
··· 7 7 * it under the terms of the GNU General Public License version 2 as 8 8 * published by the Free Software Foundation. 9 9 * 10 - * $Id: pci.c,v 1.9 2004/11/28 09:40:40 dwmw2 Exp $ 10 + * $Id: pci.c,v 1.10 2005/03/18 14:04:35 gleixner Exp $ 11 11 * 12 12 * Generic PCI memory map driver. We support the following boards: 13 13 * - Intel IQ80310 ATU. ··· 370 370 371 371 static int __init mtd_pci_maps_init(void) 372 372 { 373 - return pci_module_init(&mtd_pci_driver); 373 + return pci_register_driver(&mtd_pci_driver); 374 374 } 375 375 376 376 static void __exit mtd_pci_maps_exit(void)
+278
drivers/mtd/maps/plat-ram.c
··· 1 + /* drivers/mtd/maps/plat-ram.c 2 + * 3 + * (c) 2004-2005 Simtec Electronics 4 + * http://www.simtec.co.uk/products/SWLINUX/ 5 + * Ben Dooks <ben@simtec.co.uk> 6 + * 7 + * Generic platfrom device based RAM map 8 + * 9 + * $Id: plat-ram.c,v 1.3 2005/03/19 22:41:27 gleixner Exp $ 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License as published by 13 + * the Free Software Foundation; either version 2 of the License, or 14 + * (at your option) any later version. 15 + * 16 + * This program is distributed in the hope that it will be useful, 17 + * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 + * GNU General Public License for more details. 20 + * 21 + * You should have received a copy of the GNU General Public License 22 + * along with this program; if not, write to the Free Software 23 + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 24 + */ 25 + 26 + #include <linux/module.h> 27 + #include <linux/types.h> 28 + #include <linux/init.h> 29 + #include <linux/kernel.h> 30 + #include <linux/string.h> 31 + #include <linux/ioport.h> 32 + #include <linux/device.h> 33 + 34 + #include <linux/mtd/mtd.h> 35 + #include <linux/mtd/map.h> 36 + #include <linux/mtd/partitions.h> 37 + #include <linux/mtd/plat-ram.h> 38 + 39 + #include <asm/io.h> 40 + 41 + /* private structure for each mtd platform ram device created */ 42 + 43 + struct platram_info { 44 + struct device *dev; 45 + struct mtd_info *mtd; 46 + struct map_info map; 47 + struct mtd_partition *partitions; 48 + struct resource *area; 49 + struct platdata_mtd_ram *pdata; 50 + }; 51 + 52 + /* to_platram_info() 53 + * 54 + * device private data to struct platram_info conversion 55 + */ 56 + 57 + static inline struct platram_info *to_platram_info(struct device *dev) 58 + { 59 + return (struct platram_info *)dev_get_drvdata(dev); 60 + } 61 + 62 + /* platram_setrw 63 + * 64 + * call the platform device's set rw/ro control 65 + * 66 + * to = 0 => read-only 67 + * = 1 => read-write 68 + */ 69 + 70 + static inline void platram_setrw(struct platram_info *info, int to) 71 + { 72 + if (info->pdata == NULL) 73 + return; 74 + 75 + if (info->pdata->set_rw != NULL) 76 + (info->pdata->set_rw)(info->dev, to); 77 + } 78 + 79 + /* platram_remove 80 + * 81 + * called to remove the device from the driver's control 82 + */ 83 + 84 + static int platram_remove(struct device *dev) 85 + { 86 + struct platram_info *info = to_platram_info(dev); 87 + 88 + dev_set_drvdata(dev, NULL); 89 + 90 + dev_dbg(dev, "removing device\n"); 91 + 92 + if (info == NULL) 93 + return 0; 94 + 95 + if (info->mtd) { 96 + #ifdef CONFIG_MTD_PARTITIONS 97 + if (info->partitions) { 98 + del_mtd_partitions(info->mtd); 99 + kfree(info->partitions); 100 + } 101 + #endif 102 + del_mtd_device(info->mtd); 103 + map_destroy(info->mtd); 104 + } 105 + 106 + /* ensure ram is left read-only */ 107 + 108 + platram_setrw(info, PLATRAM_RO); 109 + 110 + /* release resources */ 111 + 112 + if (info->area) { 113 + release_resource(info->area); 114 + kfree(info->area); 115 + } 116 + 117 + if (info->map.virt != NULL) 118 + iounmap(info->map.virt); 119 + 120 + kfree(info); 121 + 122 + return 0; 123 + } 124 + 125 + /* platram_probe 126 + * 127 + * called from device drive system when a device matching our 128 + * driver is found. 129 + */ 130 + 131 + static int platram_probe(struct device *dev) 132 + { 133 + struct platform_device *pd = to_platform_device(dev); 134 + struct platdata_mtd_ram *pdata; 135 + struct platram_info *info; 136 + struct resource *res; 137 + int err = 0; 138 + 139 + dev_dbg(dev, "probe entered\n"); 140 + 141 + if (dev->platform_data == NULL) { 142 + dev_err(dev, "no platform data supplied\n"); 143 + err = -ENOENT; 144 + goto exit_error; 145 + } 146 + 147 + pdata = dev->platform_data; 148 + 149 + info = kmalloc(sizeof(*info), GFP_KERNEL); 150 + if (info == NULL) { 151 + dev_err(dev, "no memory for flash info\n"); 152 + err = -ENOMEM; 153 + goto exit_error; 154 + } 155 + 156 + memset(info, 0, sizeof(*info)); 157 + dev_set_drvdata(dev, info); 158 + 159 + info->dev = dev; 160 + info->pdata = pdata; 161 + 162 + /* get the resource for the memory mapping */ 163 + 164 + res = platform_get_resource(pd, IORESOURCE_MEM, 0); 165 + 166 + if (res == NULL) { 167 + dev_err(dev, "no memory resource specified\n"); 168 + err = -ENOENT; 169 + goto exit_free; 170 + } 171 + 172 + dev_dbg(dev, "got platform resource %p (0x%lx)\n", res, res->start); 173 + 174 + /* setup map parameters */ 175 + 176 + info->map.phys = res->start; 177 + info->map.size = (res->end - res->start) + 1; 178 + info->map.name = pdata->mapname != NULL ? pdata->mapname : pd->name; 179 + info->map.bankwidth = pdata->bankwidth; 180 + 181 + /* register our usage of the memory area */ 182 + 183 + info->area = request_mem_region(res->start, info->map.size, pd->name); 184 + if (info->area == NULL) { 185 + dev_err(dev, "failed to request memory region\n"); 186 + err = -EIO; 187 + goto exit_free; 188 + } 189 + 190 + /* remap the memory area */ 191 + 192 + info->map.virt = ioremap(res->start, info->map.size); 193 + dev_dbg(dev, "virt %p, %lu bytes\n", info->map.virt, info->map.size); 194 + 195 + if (info->map.virt == NULL) { 196 + dev_err(dev, "failed to ioremap() region\n"); 197 + err = -EIO; 198 + goto exit_free; 199 + } 200 + 201 + simple_map_init(&info->map); 202 + 203 + dev_dbg(dev, "initialised map, probing for mtd\n"); 204 + 205 + /* probe for the right mtd map driver */ 206 + 207 + info->mtd = do_map_probe("map_ram" , &info->map); 208 + if (info->mtd == NULL) { 209 + dev_err(dev, "failed to probe for map_ram\n"); 210 + err = -ENOMEM; 211 + goto exit_free; 212 + } 213 + 214 + info->mtd->owner = THIS_MODULE; 215 + 216 + platram_setrw(info, PLATRAM_RW); 217 + 218 + /* check to see if there are any available partitions, or wether 219 + * to add this device whole */ 220 + 221 + #ifdef CONFIG_MTD_PARTITIONS 222 + if (pdata->nr_partitions > 0) { 223 + const char **probes = { NULL }; 224 + 225 + if (pdata->probes) 226 + probes = (const char **)pdata->probes; 227 + 228 + err = parse_mtd_partitions(info->mtd, probes, 229 + &info->partitions, 0); 230 + if (err > 0) { 231 + err = add_mtd_partitions(info->mtd, info->partitions, 232 + err); 233 + } 234 + } 235 + #endif /* CONFIG_MTD_PARTITIONS */ 236 + 237 + if (add_mtd_device(info->mtd)) { 238 + dev_err(dev, "add_mtd_device() failed\n"); 239 + err = -ENOMEM; 240 + } 241 + 242 + dev_info(dev, "registered mtd device\n"); 243 + return err; 244 + 245 + exit_free: 246 + platram_remove(dev); 247 + exit_error: 248 + return err; 249 + } 250 + 251 + /* device driver info */ 252 + 253 + static struct device_driver platram_driver = { 254 + .name = "mtd-ram", 255 + .bus = &platform_bus_type, 256 + .probe = platram_probe, 257 + .remove = platram_remove, 258 + }; 259 + 260 + /* module init/exit */ 261 + 262 + static int __init platram_init(void) 263 + { 264 + printk("Generic platform RAM MTD, (c) 2004 Simtec Electronics\n"); 265 + return driver_register(&platram_driver); 266 + } 267 + 268 + static void __exit platram_exit(void) 269 + { 270 + driver_unregister(&platram_driver); 271 + } 272 + 273 + module_init(platram_init); 274 + module_exit(platram_exit); 275 + 276 + MODULE_LICENSE("GPL"); 277 + MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); 278 + MODULE_DESCRIPTION("MTD platform RAM map driver");
+2 -2
drivers/mtd/maps/scb2_flash.c
··· 1 1 /* 2 2 * MTD map driver for BIOS Flash on Intel SCB2 boards 3 - * $Id: scb2_flash.c,v 1.11 2004/11/28 09:40:40 dwmw2 Exp $ 3 + * $Id: scb2_flash.c,v 1.12 2005/03/18 14:04:35 gleixner Exp $ 4 4 * Copyright (C) 2002 Sun Microsystems, Inc. 5 5 * Tim Hockin <thockin@sun.com> 6 6 * ··· 238 238 static int __init 239 239 scb2_flash_init(void) 240 240 { 241 - return pci_module_init(&scb2_flash_driver); 241 + return pci_register_driver(&scb2_flash_driver); 242 242 } 243 243 244 244 static void __exit
+26 -7
drivers/mtd/maps/sharpsl-flash.c
··· 4 4 * Copyright (C) 2001 Lineo Japan, Inc. 5 5 * Copyright (C) 2002 SHARP 6 6 * 7 - * $Id: sharpsl-flash.c,v 1.2 2004/11/24 20:38:06 rpurdie Exp $ 7 + * $Id: sharpsl-flash.c,v 1.5 2005/03/21 08:42:11 rpurdie Exp $ 8 8 * 9 9 * based on rpxlite.c,v 1.15 2001/10/02 15:05:14 dwmw2 Exp 10 10 * Handle mapping of the flash on the RPX Lite and CLLF boards ··· 24 24 #include <linux/module.h> 25 25 #include <linux/types.h> 26 26 #include <linux/kernel.h> 27 - #include <asm/io.h> 28 27 #include <linux/mtd/mtd.h> 29 28 #include <linux/mtd/map.h> 30 29 #include <linux/mtd/partitions.h> 30 + #include <asm/io.h> 31 + #include <asm/mach-types.h> 31 32 32 33 #define WINDOW_ADDR 0x00000000 33 - #define WINDOW_SIZE 0x01000000 34 + #define WINDOW_SIZE 0x00800000 34 35 #define BANK_WIDTH 2 35 36 36 37 static struct mtd_info *mymtd; ··· 45 44 46 45 static struct mtd_partition sharpsl_partitions[1] = { 47 46 { 48 - name: "Filesystem", 49 - size: 0x006d0000, 50 - offset: 0x00120000 47 + name: "Boot PROM Filesystem", 51 48 } 52 49 }; 53 50 ··· 57 58 int nb_parts = 0; 58 59 char *part_type = "static"; 59 60 60 - printk(KERN_NOTICE "Sharp SL series flash device: %x at %x\n", WINDOW_SIZE, WINDOW_ADDR); 61 + printk(KERN_NOTICE "Sharp SL series flash device: %x at %x\n", 62 + WINDOW_SIZE, WINDOW_ADDR); 61 63 sharpsl_map.virt = ioremap(WINDOW_ADDR, WINDOW_SIZE); 62 64 if (!sharpsl_map.virt) { 63 65 printk("Failed to ioremap\n"); 64 66 return -EIO; 65 67 } 68 + 69 + simple_map_init(&sharpsl_map); 70 + 66 71 mymtd = do_map_probe("map_rom", &sharpsl_map); 67 72 if (!mymtd) { 68 73 iounmap(sharpsl_map.virt); ··· 75 72 76 73 mymtd->owner = THIS_MODULE; 77 74 75 + if (machine_is_corgi() || machine_is_shepherd() || machine_is_husky() 76 + || machine_is_poodle()) { 77 + sharpsl_partitions[0].size=0x006d0000; 78 + sharpsl_partitions[0].offset=0x00120000; 79 + } else if (machine_is_tosa()) { 80 + sharpsl_partitions[0].size=0x006a0000; 81 + sharpsl_partitions[0].offset=0x00160000; 82 + } else if (machine_is_spitz()) { 83 + sharpsl_partitions[0].size=0x006b0000; 84 + sharpsl_partitions[0].offset=0x00140000; 85 + } else { 86 + map_destroy(mymtd); 87 + iounmap(sharpsl_map.virt); 88 + return -ENODEV; 89 + } 90 + 78 91 parts = sharpsl_partitions; 79 92 nb_parts = NB_OF(sharpsl_partitions); 80 93
+143 -33
drivers/mtd/mtdchar.c
··· 1 1 /* 2 - * $Id: mtdchar.c,v 1.66 2005/01/05 18:05:11 dwmw2 Exp $ 2 + * $Id: mtdchar.c,v 1.73 2005/07/04 17:36:41 gleixner Exp $ 3 3 * 4 4 * Character-device access to raw MTD devices. 5 5 * ··· 15 15 #include <linux/fs.h> 16 16 #include <asm/uaccess.h> 17 17 18 - #ifdef CONFIG_DEVFS_FS 19 - #include <linux/devfs_fs_kernel.h> 18 + #include <linux/device.h> 19 + 20 + static struct class *mtd_class; 20 21 21 22 static void mtd_notify_add(struct mtd_info* mtd) 22 23 { 23 24 if (!mtd) 24 25 return; 25 26 26 - devfs_mk_cdev(MKDEV(MTD_CHAR_MAJOR, mtd->index*2), 27 - S_IFCHR | S_IRUGO | S_IWUGO, "mtd/%d", mtd->index); 28 - 29 - devfs_mk_cdev(MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), 30 - S_IFCHR | S_IRUGO, "mtd/%dro", mtd->index); 27 + class_device_create(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2), 28 + NULL, "mtd%d", mtd->index); 29 + 30 + class_device_create(mtd_class, 31 + MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1), 32 + NULL, "mtd%dro", mtd->index); 31 33 } 32 34 33 35 static void mtd_notify_remove(struct mtd_info* mtd) 34 36 { 35 37 if (!mtd) 36 38 return; 37 - devfs_remove("mtd/%d", mtd->index); 38 - devfs_remove("mtd/%dro", mtd->index); 39 + 40 + class_device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2)); 41 + class_device_destroy(mtd_class, MKDEV(MTD_CHAR_MAJOR, mtd->index*2+1)); 39 42 } 40 43 41 44 static struct mtd_notifier notifier = { ··· 46 43 .remove = mtd_notify_remove, 47 44 }; 48 45 49 - static inline void mtdchar_devfs_init(void) 50 - { 51 - devfs_mk_dir("mtd"); 52 - register_mtd_user(&notifier); 53 - } 46 + /* 47 + * We use file->private_data to store a pointer to the MTDdevice. 48 + * Since alighment is at least 32 bits, we have 2 bits free for OTP 49 + * modes as well. 50 + */ 54 51 55 - static inline void mtdchar_devfs_exit(void) 56 - { 57 - unregister_mtd_user(&notifier); 58 - devfs_remove("mtd"); 59 - } 60 - #else /* !DEVFS */ 61 - #define mtdchar_devfs_init() do { } while(0) 62 - #define mtdchar_devfs_exit() do { } while(0) 63 - #endif 52 + #define TO_MTD(file) (struct mtd_info *)((long)((file)->private_data) & ~3L) 53 + 54 + #define MTD_MODE_OTP_FACT 1 55 + #define MTD_MODE_OTP_USER 2 56 + #define MTD_MODE(file) ((long)((file)->private_data) & 3) 57 + 58 + #define SET_MTD_MODE(file, mode) \ 59 + do { long __p = (long)((file)->private_data); \ 60 + (file)->private_data = (void *)((__p & ~3L) | mode); } while (0) 64 61 65 62 static loff_t mtd_lseek (struct file *file, loff_t offset, int orig) 66 63 { 67 - struct mtd_info *mtd = file->private_data; 64 + struct mtd_info *mtd = TO_MTD(file); 68 65 69 66 switch (orig) { 70 67 case 0: ··· 137 134 138 135 DEBUG(MTD_DEBUG_LEVEL0, "MTD_close\n"); 139 136 140 - mtd = file->private_data; 137 + mtd = TO_MTD(file); 141 138 142 139 if (mtd->sync) 143 140 mtd->sync(mtd); ··· 154 151 155 152 static ssize_t mtd_read(struct file *file, char __user *buf, size_t count,loff_t *ppos) 156 153 { 157 - struct mtd_info *mtd = file->private_data; 154 + struct mtd_info *mtd = TO_MTD(file); 158 155 size_t retlen=0; 159 156 size_t total_retlen=0; 160 157 int ret=0; ··· 181 178 if (!kbuf) 182 179 return -ENOMEM; 183 180 184 - ret = MTD_READ(mtd, *ppos, len, &retlen, kbuf); 181 + switch (MTD_MODE(file)) { 182 + case MTD_MODE_OTP_FACT: 183 + ret = mtd->read_fact_prot_reg(mtd, *ppos, len, &retlen, kbuf); 184 + break; 185 + case MTD_MODE_OTP_USER: 186 + ret = mtd->read_user_prot_reg(mtd, *ppos, len, &retlen, kbuf); 187 + break; 188 + default: 189 + ret = MTD_READ(mtd, *ppos, len, &retlen, kbuf); 190 + } 185 191 /* Nand returns -EBADMSG on ecc errors, but it returns 186 192 * the data. For our userspace tools it is important 187 193 * to dump areas with ecc errors ! ··· 208 196 209 197 count -= retlen; 210 198 buf += retlen; 199 + if (retlen == 0) 200 + count = 0; 211 201 } 212 202 else { 213 203 kfree(kbuf); ··· 224 210 225 211 static ssize_t mtd_write(struct file *file, const char __user *buf, size_t count,loff_t *ppos) 226 212 { 227 - struct mtd_info *mtd = file->private_data; 213 + struct mtd_info *mtd = TO_MTD(file); 228 214 char *kbuf; 229 215 size_t retlen; 230 216 size_t total_retlen=0; ··· 259 245 return -EFAULT; 260 246 } 261 247 262 - ret = (*(mtd->write))(mtd, *ppos, len, &retlen, kbuf); 248 + switch (MTD_MODE(file)) { 249 + case MTD_MODE_OTP_FACT: 250 + ret = -EROFS; 251 + break; 252 + case MTD_MODE_OTP_USER: 253 + if (!mtd->write_user_prot_reg) { 254 + ret = -EOPNOTSUPP; 255 + break; 256 + } 257 + ret = mtd->write_user_prot_reg(mtd, *ppos, len, &retlen, kbuf); 258 + break; 259 + default: 260 + ret = (*(mtd->write))(mtd, *ppos, len, &retlen, kbuf); 261 + } 263 262 if (!ret) { 264 263 *ppos += retlen; 265 264 total_retlen += retlen; ··· 303 276 static int mtd_ioctl(struct inode *inode, struct file *file, 304 277 u_int cmd, u_long arg) 305 278 { 306 - struct mtd_info *mtd = file->private_data; 279 + struct mtd_info *mtd = TO_MTD(file); 307 280 void __user *argp = (void __user *)arg; 308 281 int ret = 0; 309 282 u_long size; ··· 545 518 break; 546 519 } 547 520 521 + #ifdef CONFIG_MTD_OTP 522 + case OTPSELECT: 523 + { 524 + int mode; 525 + if (copy_from_user(&mode, argp, sizeof(int))) 526 + return -EFAULT; 527 + SET_MTD_MODE(file, 0); 528 + switch (mode) { 529 + case MTD_OTP_FACTORY: 530 + if (!mtd->read_fact_prot_reg) 531 + ret = -EOPNOTSUPP; 532 + else 533 + SET_MTD_MODE(file, MTD_MODE_OTP_FACT); 534 + break; 535 + case MTD_OTP_USER: 536 + if (!mtd->read_fact_prot_reg) 537 + ret = -EOPNOTSUPP; 538 + else 539 + SET_MTD_MODE(file, MTD_MODE_OTP_USER); 540 + break; 541 + default: 542 + ret = -EINVAL; 543 + case MTD_OTP_OFF: 544 + break; 545 + } 546 + file->f_pos = 0; 547 + break; 548 + } 549 + 550 + case OTPGETREGIONCOUNT: 551 + case OTPGETREGIONINFO: 552 + { 553 + struct otp_info *buf = kmalloc(4096, GFP_KERNEL); 554 + if (!buf) 555 + return -ENOMEM; 556 + ret = -EOPNOTSUPP; 557 + switch (MTD_MODE(file)) { 558 + case MTD_MODE_OTP_FACT: 559 + if (mtd->get_fact_prot_info) 560 + ret = mtd->get_fact_prot_info(mtd, buf, 4096); 561 + break; 562 + case MTD_MODE_OTP_USER: 563 + if (mtd->get_user_prot_info) 564 + ret = mtd->get_user_prot_info(mtd, buf, 4096); 565 + break; 566 + } 567 + if (ret >= 0) { 568 + if (cmd == OTPGETREGIONCOUNT) { 569 + int nbr = ret / sizeof(struct otp_info); 570 + ret = copy_to_user(argp, &nbr, sizeof(int)); 571 + } else 572 + ret = copy_to_user(argp, buf, ret); 573 + if (ret) 574 + ret = -EFAULT; 575 + } 576 + kfree(buf); 577 + break; 578 + } 579 + 580 + case OTPLOCK: 581 + { 582 + struct otp_info info; 583 + 584 + if (MTD_MODE(file) != MTD_MODE_OTP_USER) 585 + return -EINVAL; 586 + if (copy_from_user(&info, argp, sizeof(info))) 587 + return -EFAULT; 588 + if (!mtd->lock_user_prot_reg) 589 + return -EOPNOTSUPP; 590 + ret = mtd->lock_user_prot_reg(mtd, info.start, info.length); 591 + break; 592 + } 593 + #endif 594 + 548 595 default: 549 596 ret = -ENOTTY; 550 597 } ··· 644 543 return -EAGAIN; 645 544 } 646 545 647 - mtdchar_devfs_init(); 546 + mtd_class = class_create(THIS_MODULE, "mtd"); 547 + 548 + if (IS_ERR(mtd_class)) { 549 + printk(KERN_ERR "Error creating mtd class.\n"); 550 + unregister_chrdev(MTD_CHAR_MAJOR, "mtd"); 551 + return PTR_ERR(mtd_class); 552 + } 553 + 554 + register_mtd_user(&notifier); 648 555 return 0; 649 556 } 650 557 651 558 static void __exit cleanup_mtdchar(void) 652 559 { 653 - mtdchar_devfs_exit(); 560 + unregister_mtd_user(&notifier); 561 + class_destroy(mtd_class); 654 562 unregister_chrdev(MTD_CHAR_MAJOR, "mtd"); 655 563 } 656 564
+3 -3
drivers/mtd/mtdcore.c
··· 1 1 /* 2 - * $Id: mtdcore.c,v 1.44 2004/11/16 18:28:59 dwmw2 Exp $ 2 + * $Id: mtdcore.c,v 1.45 2005/02/18 14:34:50 dedekind Exp $ 3 3 * 4 4 * Core registration and callback routines for MTD 5 5 * drivers and users. ··· 149 149 } 150 150 151 151 /** 152 - * register_mtd_user - unregister a 'user' of MTD devices. 153 - * @new: pointer to notifier info structure 152 + * unregister_mtd_user - unregister a 'user' of MTD devices. 153 + * @old: pointer to notifier info structure 154 154 * 155 155 * Removes a callback function pair from the list of 'users' to be 156 156 * notified upon addition or removal of MTD devices. Causes the
+27 -1
drivers/mtd/mtdpart.c
··· 5 5 * 6 6 * This code is GPL 7 7 * 8 - * $Id: mtdpart.c,v 1.51 2004/11/16 18:28:59 dwmw2 Exp $ 8 + * $Id: mtdpart.c,v 1.53 2005/02/08 17:11:13 nico Exp $ 9 9 * 10 10 * 02-21-2002 Thomas Gleixner <gleixner@autronix.de> 11 11 * added support for read_oob, write_oob ··· 116 116 len, retlen, buf); 117 117 } 118 118 119 + static int part_get_user_prot_info (struct mtd_info *mtd, 120 + struct otp_info *buf, size_t len) 121 + { 122 + struct mtd_part *part = PART(mtd); 123 + return part->master->get_user_prot_info (part->master, buf, len); 124 + } 125 + 119 126 static int part_read_fact_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, 120 127 size_t *retlen, u_char *buf) 121 128 { 122 129 struct mtd_part *part = PART(mtd); 123 130 return part->master->read_fact_prot_reg (part->master, from, 124 131 len, retlen, buf); 132 + } 133 + 134 + static int part_get_fact_prot_info (struct mtd_info *mtd, 135 + struct otp_info *buf, size_t len) 136 + { 137 + struct mtd_part *part = PART(mtd); 138 + return part->master->get_fact_prot_info (part->master, buf, len); 125 139 } 126 140 127 141 static int part_write (struct mtd_info *mtd, loff_t to, size_t len, ··· 194 180 struct mtd_part *part = PART(mtd); 195 181 return part->master->write_user_prot_reg (part->master, from, 196 182 len, retlen, buf); 183 + } 184 + 185 + static int part_lock_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len) 186 + { 187 + struct mtd_part *part = PART(mtd); 188 + return part->master->lock_user_prot_reg (part->master, from, len); 197 189 } 198 190 199 191 static int part_writev (struct mtd_info *mtd, const struct kvec *vecs, ··· 429 409 slave->mtd.read_fact_prot_reg = part_read_fact_prot_reg; 430 410 if(master->write_user_prot_reg) 431 411 slave->mtd.write_user_prot_reg = part_write_user_prot_reg; 412 + if(master->lock_user_prot_reg) 413 + slave->mtd.lock_user_prot_reg = part_lock_user_prot_reg; 414 + if(master->get_user_prot_info) 415 + slave->mtd.get_user_prot_info = part_get_user_prot_info; 416 + if(master->get_fact_prot_info) 417 + slave->mtd.get_fact_prot_info = part_get_fact_prot_info; 432 418 if (master->sync) 433 419 slave->mtd.sync = part_sync; 434 420 if (!i && master->suspend && master->resume) {
+4 -17
drivers/mtd/nand/Kconfig
··· 1 1 # drivers/mtd/nand/Kconfig 2 - # $Id: Kconfig,v 1.26 2005/01/05 12:42:24 dwmw2 Exp $ 2 + # $Id: Kconfig,v 1.31 2005/06/20 12:03:21 bjd Exp $ 3 3 4 4 menu "NAND Flash Device Drivers" 5 5 depends on MTD!=n ··· 58 58 config MTD_NAND_IDS 59 59 tristate 60 60 61 - config MTD_NAND_TX4925NDFMC 62 - tristate "SmartMedia Card on Toshiba RBTX4925 reference board" 63 - depends on TOSHIBA_RBTX4925 && MTD_NAND && TOSHIBA_RBTX4925_MPLEX_NAND 64 - help 65 - This enables the driver for the NAND flash device found on the 66 - Toshiba RBTX4925 reference board, which is a SmartMediaCard. 67 - 68 - config MTD_NAND_TX4938NDFMC 69 - tristate "NAND Flash device on Toshiba RBTX4938 reference board" 70 - depends on TOSHIBA_RBTX4938 && MTD_NAND && TOSHIBA_RBTX4938_MPLEX_NAND 71 - help 72 - This enables the driver for the NAND flash device found on the 73 - Toshiba RBTX4938 reference board. 74 - 75 61 config MTD_NAND_AU1550 76 62 tristate "Au1550 NAND support" 77 63 depends on SOC_AU1550 && MTD_NAND ··· 81 95 This enables the NAND flash driver on the PPChameleon EVB Board. 82 96 83 97 config MTD_NAND_S3C2410 84 - tristate "NAND Flash support for S3C2410 SoC" 98 + tristate "NAND Flash support for S3C2410/S3C2440 SoC" 85 99 depends on ARCH_S3C2410 && MTD_NAND 86 100 help 87 - This enables the NAND flash controller on the S3C2410. 101 + This enables the NAND flash controller on the S3C2410 and S3C2440 102 + SoCs 88 103 89 104 No board specfic support is done by this driver, each board 90 105 must advertise a platform_device for the driver to attach.
-2
drivers/mtd/nand/Makefile
··· 10 10 obj-$(CONFIG_MTD_NAND_TOTO) += toto.o 11 11 obj-$(CONFIG_MTD_NAND_AUTCPU12) += autcpu12.o 12 12 obj-$(CONFIG_MTD_NAND_EDB7312) += edb7312.o 13 - obj-$(CONFIG_MTD_NAND_TX4925NDFMC) += tx4925ndfmc.o 14 - obj-$(CONFIG_MTD_NAND_TX4938NDFMC) += tx4938ndfmc.o 15 13 obj-$(CONFIG_MTD_NAND_AU1550) += au1550nd.o 16 14 obj-$(CONFIG_MTD_NAND_PPCHAMELEONEVB) += ppchameleonevb.o 17 15 obj-$(CONFIG_MTD_NAND_S3C2410) += s3c2410.o
+57 -45
drivers/mtd/nand/diskonchip.c
··· 16 16 * 17 17 * Interface to generic NAND code for M-Systems DiskOnChip devices 18 18 * 19 - * $Id: diskonchip.c,v 1.45 2005/01/05 18:05:14 dwmw2 Exp $ 19 + * $Id: diskonchip.c,v 1.54 2005/04/07 14:22:55 dbrown Exp $ 20 20 */ 21 21 22 22 #include <linux/kernel.h> ··· 35 35 #include <linux/mtd/inftl.h> 36 36 37 37 /* Where to look for the devices? */ 38 - #ifndef CONFIG_MTD_DISKONCHIP_PROBE_ADDRESS 39 - #define CONFIG_MTD_DISKONCHIP_PROBE_ADDRESS 0 38 + #ifndef CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS 39 + #define CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS 0 40 40 #endif 41 41 42 42 static unsigned long __initdata doc_locations[] = { 43 43 #if defined (__alpha__) || defined(__i386__) || defined(__x86_64__) 44 - #ifdef CONFIG_MTD_DISKONCHIP_PROBE_HIGH 44 + #ifdef CONFIG_MTD_NAND_DISKONCHIP_PROBE_HIGH 45 45 0xfffc8000, 0xfffca000, 0xfffcc000, 0xfffce000, 46 46 0xfffd0000, 0xfffd2000, 0xfffd4000, 0xfffd6000, 47 47 0xfffd8000, 0xfffda000, 0xfffdc000, 0xfffde000, ··· 81 81 struct mtd_info *nextdoc; 82 82 }; 83 83 84 - /* Max number of eraseblocks to scan (from start of device) for the (I)NFTL 85 - MediaHeader. The spec says to just keep going, I think, but that's just 86 - silly. */ 87 - #define MAX_MEDIAHEADER_SCAN 8 88 - 89 84 /* This is the syndrome computed by the HW ecc generator upon reading an empty 90 85 page, one with all 0xff for data and stored ecc code. */ 91 86 static u_char empty_read_syndrome[6] = { 0x26, 0xff, 0x6d, 0x47, 0x73, 0x7a }; ··· 106 111 static int no_ecc_failures=0; 107 112 module_param(no_ecc_failures, int, 0); 108 113 109 - #ifdef CONFIG_MTD_PARTITIONS 110 114 static int no_autopart=0; 111 115 module_param(no_autopart, int, 0); 112 - #endif 116 + 117 + static int show_firmware_partition=0; 118 + module_param(show_firmware_partition, int, 0); 113 119 114 120 #ifdef MTD_NAND_DISKONCHIP_BBTWRITE 115 121 static int inftl_bbt_write=1; ··· 119 123 #endif 120 124 module_param(inftl_bbt_write, int, 0); 121 125 122 - static unsigned long doc_config_location = CONFIG_MTD_DISKONCHIP_PROBE_ADDRESS; 126 + static unsigned long doc_config_location = CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS; 123 127 module_param(doc_config_location, ulong, 0); 124 128 MODULE_PARM_DESC(doc_config_location, "Physical memory address at which to probe for DiskOnChip"); 125 129 ··· 406 410 doc200x_hwcontrol(mtd, NAND_CTL_SETALE); 407 411 this->write_byte(mtd, 0); 408 412 doc200x_hwcontrol(mtd, NAND_CTL_CLRALE); 409 - 413 + 414 + /* We cant' use dev_ready here, but at least we wait for the 415 + * command to complete 416 + */ 417 + udelay(50); 418 + 410 419 ret = this->read_byte(mtd) << 8; 411 420 ret |= this->read_byte(mtd); 412 421 ··· 429 428 doc200x_hwcontrol(mtd, NAND_CTL_SETALE); 430 429 doc2000_write_byte(mtd, 0); 431 430 doc200x_hwcontrol(mtd, NAND_CTL_CLRALE); 431 + 432 + udelay(50); 432 433 433 434 ident.dword = readl(docptr + DoC_2k_CDSN_IO); 434 435 if (((ident.byte[0] << 8) | ident.byte[1]) == ret) { ··· 1049 1046 1050 1047 //u_char mydatabuf[528]; 1051 1048 1049 + /* The strange out-of-order .oobfree list below is a (possibly unneeded) 1050 + * attempt to retain compatibility. It used to read: 1051 + * .oobfree = { {8, 8} } 1052 + * Since that leaves two bytes unusable, it was changed. But the following 1053 + * scheme might affect existing jffs2 installs by moving the cleanmarker: 1054 + * .oobfree = { {6, 10} } 1055 + * jffs2 seems to handle the above gracefully, but the current scheme seems 1056 + * safer. The only problem with it is that any code that parses oobfree must 1057 + * be able to handle out-of-order segments. 1058 + */ 1052 1059 static struct nand_oobinfo doc200x_oobinfo = { 1053 1060 .useecc = MTD_NANDECC_AUTOPLACE, 1054 1061 .eccbytes = 6, 1055 1062 .eccpos = {0, 1, 2, 3, 4, 5}, 1056 - .oobfree = { {8, 8} } 1063 + .oobfree = { {8, 8}, {6, 2} } 1057 1064 }; 1058 1065 1059 1066 /* Find the (I)NFTL Media Header, and optionally also the mirror media header. ··· 1077 1064 { 1078 1065 struct nand_chip *this = mtd->priv; 1079 1066 struct doc_priv *doc = this->priv; 1080 - unsigned offs, end = (MAX_MEDIAHEADER_SCAN << this->phys_erase_shift); 1067 + unsigned offs; 1081 1068 int ret; 1082 1069 size_t retlen; 1083 1070 1084 - end = min(end, mtd->size); // paranoia 1085 - for (offs = 0; offs < end; offs += mtd->erasesize) { 1071 + for (offs = 0; offs < mtd->size; offs += mtd->erasesize) { 1086 1072 ret = mtd->read(mtd, offs, mtd->oobblock, &retlen, buf); 1087 1073 if (retlen != mtd->oobblock) continue; 1088 1074 if (ret) { ··· 1123 1111 u_char *buf; 1124 1112 struct NFTLMediaHeader *mh; 1125 1113 const unsigned psize = 1 << this->page_shift; 1114 + int numparts = 0; 1126 1115 unsigned blocks, maxblocks; 1127 1116 int offs, numheaders; 1128 1117 ··· 1135 1122 if (!(numheaders=find_media_headers(mtd, buf, "ANAND", 1))) goto out; 1136 1123 mh = (struct NFTLMediaHeader *) buf; 1137 1124 1138 - //#ifdef CONFIG_MTD_DEBUG_VERBOSE 1139 - // if (CONFIG_MTD_DEBUG_VERBOSE >= 2) 1125 + mh->NumEraseUnits = le16_to_cpu(mh->NumEraseUnits); 1126 + mh->FirstPhysicalEUN = le16_to_cpu(mh->FirstPhysicalEUN); 1127 + mh->FormattedSize = le32_to_cpu(mh->FormattedSize); 1128 + 1140 1129 printk(KERN_INFO " DataOrgID = %s\n" 1141 1130 " NumEraseUnits = %d\n" 1142 1131 " FirstPhysicalEUN = %d\n" ··· 1147 1132 mh->DataOrgID, mh->NumEraseUnits, 1148 1133 mh->FirstPhysicalEUN, mh->FormattedSize, 1149 1134 mh->UnitSizeFactor); 1150 - //#endif 1151 1135 1152 1136 blocks = mtd->size >> this->phys_erase_shift; 1153 1137 maxblocks = min(32768U, mtd->erasesize - psize); ··· 1189 1175 offs <<= this->page_shift; 1190 1176 offs += mtd->erasesize; 1191 1177 1192 - //parts[0].name = " DiskOnChip Boot / Media Header partition"; 1193 - //parts[0].offset = 0; 1194 - //parts[0].size = offs; 1195 - 1196 - parts[0].name = " DiskOnChip BDTL partition"; 1197 - parts[0].offset = offs; 1198 - parts[0].size = (mh->NumEraseUnits - numheaders) << this->bbt_erase_shift; 1199 - 1200 - offs += parts[0].size; 1201 - if (offs < mtd->size) { 1202 - parts[1].name = " DiskOnChip Remainder partition"; 1203 - parts[1].offset = offs; 1204 - parts[1].size = mtd->size - offs; 1205 - ret = 2; 1206 - goto out; 1178 + if (show_firmware_partition == 1) { 1179 + parts[0].name = " DiskOnChip Firmware / Media Header partition"; 1180 + parts[0].offset = 0; 1181 + parts[0].size = offs; 1182 + numparts = 1; 1207 1183 } 1208 - ret = 1; 1184 + 1185 + parts[numparts].name = " DiskOnChip BDTL partition"; 1186 + parts[numparts].offset = offs; 1187 + parts[numparts].size = (mh->NumEraseUnits - numheaders) << this->bbt_erase_shift; 1188 + 1189 + offs += parts[numparts].size; 1190 + numparts++; 1191 + 1192 + if (offs < mtd->size) { 1193 + parts[numparts].name = " DiskOnChip Remainder partition"; 1194 + parts[numparts].offset = offs; 1195 + parts[numparts].size = mtd->size - offs; 1196 + numparts++; 1197 + } 1198 + 1199 + ret = numparts; 1209 1200 out: 1210 1201 kfree(buf); 1211 1202 return ret; ··· 1252 1233 mh->FormatFlags = le32_to_cpu(mh->FormatFlags); 1253 1234 mh->PercentUsed = le32_to_cpu(mh->PercentUsed); 1254 1235 1255 - //#ifdef CONFIG_MTD_DEBUG_VERBOSE 1256 - // if (CONFIG_MTD_DEBUG_VERBOSE >= 2) 1257 1236 printk(KERN_INFO " bootRecordID = %s\n" 1258 1237 " NoOfBootImageBlocks = %d\n" 1259 1238 " NoOfBinaryPartitions = %d\n" ··· 1269 1252 ((unsigned char *) &mh->OsakVersion)[2] & 0xf, 1270 1253 ((unsigned char *) &mh->OsakVersion)[3] & 0xf, 1271 1254 mh->PercentUsed); 1272 - //#endif 1273 1255 1274 1256 vshift = this->phys_erase_shift + mh->BlockMultiplierBits; 1275 1257 ··· 1294 1278 ip->spareUnits = le32_to_cpu(ip->spareUnits); 1295 1279 ip->Reserved0 = le32_to_cpu(ip->Reserved0); 1296 1280 1297 - //#ifdef CONFIG_MTD_DEBUG_VERBOSE 1298 - // if (CONFIG_MTD_DEBUG_VERBOSE >= 2) 1299 1281 printk(KERN_INFO " PARTITION[%d] ->\n" 1300 1282 " virtualUnits = %d\n" 1301 1283 " firstUnit = %d\n" ··· 1303 1289 i, ip->virtualUnits, ip->firstUnit, 1304 1290 ip->lastUnit, ip->flags, 1305 1291 ip->spareUnits); 1306 - //#endif 1307 1292 1308 - /* 1309 - if ((i == 0) && (ip->firstUnit > 0)) { 1293 + if ((show_firmware_partition == 1) && 1294 + (i == 0) && (ip->firstUnit > 0)) { 1310 1295 parts[0].name = " DiskOnChip IPL / Media Header partition"; 1311 1296 parts[0].offset = 0; 1312 1297 parts[0].size = mtd->erasesize * ip->firstUnit; 1313 1298 numparts = 1; 1314 1299 } 1315 - */ 1316 1300 1317 1301 if (ip->flags & INFTL_BINARY) 1318 1302 parts[numparts].name = " DiskOnChip BDK partition";
+215 -84
drivers/mtd/nand/nand_base.c
··· 28 28 * among multiple independend devices. Suggestions and initial patch 29 29 * from Ben Dooks <ben-mtd@fluff.org> 30 30 * 31 + * 12-05-2004 dmarlin: add workaround for Renesas AG-AND chips "disturb" issue. 32 + * Basically, any block not rewritten may lose data when surrounding blocks 33 + * are rewritten many times. JFFS2 ensures this doesn't happen for blocks 34 + * it uses, but the Bad Block Table(s) may not be rewritten. To ensure they 35 + * do not lose data, force them to be rewritten when some of the surrounding 36 + * blocks are erased. Rather than tracking a specific nearby block (which 37 + * could itself go bad), use a page address 'mask' to select several blocks 38 + * in the same area, and rewrite the BBT when any of them are erased. 39 + * 40 + * 01-03-2005 dmarlin: added support for the device recovery command sequence for Renesas 41 + * AG-AND chips. If there was a sudden loss of power during an erase operation, 42 + * a "device recovery" operation must be performed when power is restored 43 + * to ensure correct operation. 44 + * 45 + * 01-20-2005 dmarlin: added support for optional hardware specific callback routine to 46 + * perform extra error status checks on erase and write failures. This required 47 + * adding a wrapper function for nand_read_ecc. 48 + * 31 49 * Credits: 32 50 * David Woodhouse for adding multichip support 33 51 * ··· 59 41 * The AG-AND chips have nice features for speed improvement, 60 42 * which are not supported yet. Read / program 4 pages in one go. 61 43 * 62 - * $Id: nand_base.c,v 1.126 2004/12/13 11:22:25 lavinen Exp $ 44 + * $Id: nand_base.c,v 1.146 2005/06/17 15:02:06 gleixner Exp $ 63 45 * 64 46 * This program is free software; you can redistribute it and/or modify 65 47 * it under the terms of the GNU General Public License version 2 as ··· 167 149 168 150 /* De-select the NAND device */ 169 151 this->select_chip(mtd, -1); 170 - /* Do we have a hardware controller ? */ 152 + 171 153 if (this->controller) { 154 + /* Release the controller and the chip */ 172 155 spin_lock(&this->controller->lock); 173 156 this->controller->active = NULL; 157 + this->state = FL_READY; 158 + wake_up(&this->controller->wq); 174 159 spin_unlock(&this->controller->lock); 160 + } else { 161 + /* Release the chip */ 162 + spin_lock(&this->chip_lock); 163 + this->state = FL_READY; 164 + wake_up(&this->wq); 165 + spin_unlock(&this->chip_lock); 175 166 } 176 - /* Release the chip */ 177 - spin_lock (&this->chip_lock); 178 - this->state = FL_READY; 179 - wake_up (&this->wq); 180 - spin_unlock (&this->chip_lock); 181 167 } 182 168 183 169 /** ··· 465 443 466 444 /* Get block number */ 467 445 block = ((int) ofs) >> this->bbt_erase_shift; 468 - this->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); 446 + if (this->bbt) 447 + this->bbt[block >> 2] |= 0x01 << ((block & 0x03) << 1); 469 448 470 449 /* Do we have a flash based bad block table ? */ 471 450 if (this->options & NAND_USE_FLASH_BBT) ··· 489 466 struct nand_chip *this = mtd->priv; 490 467 /* Check the WP bit */ 491 468 this->cmdfunc (mtd, NAND_CMD_STATUS, -1, -1); 492 - return (this->read_byte(mtd) & 0x80) ? 0 : 1; 469 + return (this->read_byte(mtd) & NAND_STATUS_WP) ? 0 : 1; 493 470 } 494 471 495 472 /** ··· 511 488 512 489 /* Return info from the table */ 513 490 return nand_isbad_bbt (mtd, ofs, allowbbt); 491 + } 492 + 493 + /* 494 + * Wait for the ready pin, after a command 495 + * The timeout is catched later. 496 + */ 497 + static void nand_wait_ready(struct mtd_info *mtd) 498 + { 499 + struct nand_chip *this = mtd->priv; 500 + unsigned long timeo = jiffies + 2; 501 + 502 + /* wait until command is processed or timeout occures */ 503 + do { 504 + if (this->dev_ready(mtd)) 505 + return; 506 + } while (time_before(jiffies, timeo)); 514 507 } 515 508 516 509 /** ··· 610 571 this->hwcontrol(mtd, NAND_CTL_SETCLE); 611 572 this->write_byte(mtd, NAND_CMD_STATUS); 612 573 this->hwcontrol(mtd, NAND_CTL_CLRCLE); 613 - while ( !(this->read_byte(mtd) & 0x40)); 574 + while ( !(this->read_byte(mtd) & NAND_STATUS_READY)); 614 575 return; 615 576 616 577 /* This applies to read commands */ ··· 624 585 return; 625 586 } 626 587 } 627 - 628 588 /* Apply this short delay always to ensure that we do wait tWB in 629 589 * any case on any machine. */ 630 590 ndelay (100); 631 - /* wait until command is processed */ 632 - while (!this->dev_ready(mtd)); 591 + 592 + nand_wait_ready(mtd); 633 593 } 634 594 635 595 /** ··· 657 619 /* Begin command latch cycle */ 658 620 this->hwcontrol(mtd, NAND_CTL_SETCLE); 659 621 /* Write out the command to the device. */ 660 - this->write_byte(mtd, command); 622 + this->write_byte(mtd, (command & 0xff)); 661 623 /* End command latch cycle */ 662 624 this->hwcontrol(mtd, NAND_CTL_CLRCLE); 663 625 ··· 685 647 686 648 /* 687 649 * program and erase have their own busy handlers 688 - * status and sequential in needs no delay 689 - */ 650 + * status, sequential in, and deplete1 need no delay 651 + */ 690 652 switch (command) { 691 653 692 654 case NAND_CMD_CACHEDPROG: ··· 695 657 case NAND_CMD_ERASE2: 696 658 case NAND_CMD_SEQIN: 697 659 case NAND_CMD_STATUS: 660 + case NAND_CMD_DEPLETE1: 698 661 return; 699 662 663 + /* 664 + * read error status commands require only a short delay 665 + */ 666 + case NAND_CMD_STATUS_ERROR: 667 + case NAND_CMD_STATUS_ERROR0: 668 + case NAND_CMD_STATUS_ERROR1: 669 + case NAND_CMD_STATUS_ERROR2: 670 + case NAND_CMD_STATUS_ERROR3: 671 + udelay(this->chip_delay); 672 + return; 700 673 701 674 case NAND_CMD_RESET: 702 675 if (this->dev_ready) ··· 716 667 this->hwcontrol(mtd, NAND_CTL_SETCLE); 717 668 this->write_byte(mtd, NAND_CMD_STATUS); 718 669 this->hwcontrol(mtd, NAND_CTL_CLRCLE); 719 - while ( !(this->read_byte(mtd) & 0x40)); 670 + while ( !(this->read_byte(mtd) & NAND_STATUS_READY)); 720 671 return; 721 672 722 673 case NAND_CMD_READ0: ··· 739 690 return; 740 691 } 741 692 } 742 - 693 + 743 694 /* Apply this short delay always to ensure that we do wait tWB in 744 695 * any case on any machine. */ 745 696 ndelay (100); 746 - /* wait until command is processed */ 747 - while (!this->dev_ready(mtd)); 697 + 698 + nand_wait_ready(mtd); 748 699 } 749 700 750 701 /** ··· 757 708 */ 758 709 static void nand_get_device (struct nand_chip *this, struct mtd_info *mtd, int new_state) 759 710 { 760 - struct nand_chip *active = this; 761 - 711 + struct nand_chip *active; 712 + spinlock_t *lock; 713 + wait_queue_head_t *wq; 762 714 DECLARE_WAITQUEUE (wait, current); 763 715 764 - /* 765 - * Grab the lock and see if the device is available 766 - */ 716 + lock = (this->controller) ? &this->controller->lock : &this->chip_lock; 717 + wq = (this->controller) ? &this->controller->wq : &this->wq; 767 718 retry: 719 + active = this; 720 + spin_lock(lock); 721 + 768 722 /* Hardware controller shared among independend devices */ 769 723 if (this->controller) { 770 - spin_lock (&this->controller->lock); 771 724 if (this->controller->active) 772 725 active = this->controller->active; 773 726 else 774 727 this->controller->active = this; 775 - spin_unlock (&this->controller->lock); 776 728 } 777 - 778 - if (active == this) { 779 - spin_lock (&this->chip_lock); 780 - if (this->state == FL_READY) { 781 - this->state = new_state; 782 - spin_unlock (&this->chip_lock); 783 - return; 784 - } 785 - } 786 - set_current_state (TASK_UNINTERRUPTIBLE); 787 - add_wait_queue (&active->wq, &wait); 788 - spin_unlock (&active->chip_lock); 789 - schedule (); 790 - remove_wait_queue (&active->wq, &wait); 729 + if (active == this && this->state == FL_READY) { 730 + this->state = new_state; 731 + spin_unlock(lock); 732 + return; 733 + } 734 + set_current_state(TASK_UNINTERRUPTIBLE); 735 + add_wait_queue(wq, &wait); 736 + spin_unlock(lock); 737 + schedule(); 738 + remove_wait_queue(wq, &wait); 791 739 goto retry; 792 740 } 793 741 ··· 831 785 if (this->read_byte(mtd) & NAND_STATUS_READY) 832 786 break; 833 787 } 834 - yield (); 788 + cond_resched(); 835 789 } 836 790 status = (int) this->read_byte(mtd); 837 791 return status; ··· 917 871 if (!cached) { 918 872 /* call wait ready function */ 919 873 status = this->waitfunc (mtd, this, FL_WRITING); 874 + 875 + /* See if operation failed and additional status checks are available */ 876 + if ((status & NAND_STATUS_FAIL) && (this->errstat)) { 877 + status = this->errstat(mtd, this, FL_WRITING, status, page); 878 + } 879 + 920 880 /* See if device thinks it succeeded */ 921 - if (status & 0x01) { 881 + if (status & NAND_STATUS_FAIL) { 922 882 DEBUG (MTD_DEBUG_LEVEL0, "%s: " "Failed write, page 0x%08x, ", __FUNCTION__, page); 923 883 return -EIO; 924 884 } ··· 1027 975 if (!this->dev_ready) 1028 976 udelay (this->chip_delay); 1029 977 else 1030 - while (!this->dev_ready(mtd)); 978 + nand_wait_ready(mtd); 1031 979 1032 980 /* All done, return happy */ 1033 981 if (!numpages) ··· 1049 997 #endif 1050 998 1051 999 /** 1052 - * nand_read - [MTD Interface] MTD compability function for nand_read_ecc 1000 + * nand_read - [MTD Interface] MTD compability function for nand_do_read_ecc 1053 1001 * @mtd: MTD device structure 1054 1002 * @from: offset to read from 1055 1003 * @len: number of bytes to read 1056 1004 * @retlen: pointer to variable to store the number of read bytes 1057 1005 * @buf: the databuffer to put data 1058 1006 * 1059 - * This function simply calls nand_read_ecc with oob buffer and oobsel = NULL 1060 - */ 1007 + * This function simply calls nand_do_read_ecc with oob buffer and oobsel = NULL 1008 + * and flags = 0xff 1009 + */ 1061 1010 static int nand_read (struct mtd_info *mtd, loff_t from, size_t len, size_t * retlen, u_char * buf) 1062 1011 { 1063 - return nand_read_ecc (mtd, from, len, retlen, buf, NULL, NULL); 1064 - } 1012 + return nand_do_read_ecc (mtd, from, len, retlen, buf, NULL, &mtd->oobinfo, 0xff); 1013 + } 1065 1014 1066 1015 1067 1016 /** 1068 - * nand_read_ecc - [MTD Interface] Read data with ECC 1017 + * nand_read_ecc - [MTD Interface] MTD compability function for nand_do_read_ecc 1069 1018 * @mtd: MTD device structure 1070 1019 * @from: offset to read from 1071 1020 * @len: number of bytes to read ··· 1075 1022 * @oob_buf: filesystem supplied oob data buffer 1076 1023 * @oobsel: oob selection structure 1077 1024 * 1078 - * NAND read with ECC 1025 + * This function simply calls nand_do_read_ecc with flags = 0xff 1079 1026 */ 1080 1027 static int nand_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, 1081 1028 size_t * retlen, u_char * buf, u_char * oob_buf, struct nand_oobinfo *oobsel) 1082 1029 { 1030 + /* use userspace supplied oobinfo, if zero */ 1031 + if (oobsel == NULL) 1032 + oobsel = &mtd->oobinfo; 1033 + return nand_do_read_ecc(mtd, from, len, retlen, buf, oob_buf, oobsel, 0xff); 1034 + } 1035 + 1036 + 1037 + /** 1038 + * nand_do_read_ecc - [MTD Interface] Read data with ECC 1039 + * @mtd: MTD device structure 1040 + * @from: offset to read from 1041 + * @len: number of bytes to read 1042 + * @retlen: pointer to variable to store the number of read bytes 1043 + * @buf: the databuffer to put data 1044 + * @oob_buf: filesystem supplied oob data buffer (can be NULL) 1045 + * @oobsel: oob selection structure 1046 + * @flags: flag to indicate if nand_get_device/nand_release_device should be preformed 1047 + * and how many corrected error bits are acceptable: 1048 + * bits 0..7 - number of tolerable errors 1049 + * bit 8 - 0 == do not get/release chip, 1 == get/release chip 1050 + * 1051 + * NAND read with ECC 1052 + */ 1053 + int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, 1054 + size_t * retlen, u_char * buf, u_char * oob_buf, 1055 + struct nand_oobinfo *oobsel, int flags) 1056 + { 1057 + 1083 1058 int i, j, col, realpage, page, end, ecc, chipnr, sndcmd = 1; 1084 1059 int read = 0, oob = 0, ecc_status = 0, ecc_failed = 0; 1085 1060 struct nand_chip *this = mtd->priv; ··· 1132 1051 } 1133 1052 1134 1053 /* Grab the lock and see if the device is available */ 1135 - nand_get_device (this, mtd ,FL_READING); 1054 + if (flags & NAND_GET_DEVICE) 1055 + nand_get_device (this, mtd, FL_READING); 1136 1056 1137 - /* use userspace supplied oobinfo, if zero */ 1138 - if (oobsel == NULL) 1139 - oobsel = &mtd->oobinfo; 1140 - 1141 1057 /* Autoplace of oob data ? Use the default placement scheme */ 1142 1058 if (oobsel->useecc == MTD_NANDECC_AUTOPLACE) 1143 1059 oobsel = this->autooob; ··· 1196 1118 } 1197 1119 1198 1120 /* get oob area, if we have no oob buffer from fs-driver */ 1199 - if (!oob_buf || oobsel->useecc == MTD_NANDECC_AUTOPLACE) 1121 + if (!oob_buf || oobsel->useecc == MTD_NANDECC_AUTOPLACE || 1122 + oobsel->useecc == MTD_NANDECC_AUTOPL_USR) 1200 1123 oob_data = &this->data_buf[end]; 1201 1124 1202 1125 eccsteps = this->eccsteps; ··· 1234 1155 /* We calc error correction directly, it checks the hw 1235 1156 * generator for an error, reads back the syndrome and 1236 1157 * does the error correction on the fly */ 1237 - if (this->correct_data(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]) == -1) { 1158 + ecc_status = this->correct_data(mtd, &data_poi[datidx], &oob_data[i], &ecc_code[i]); 1159 + if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { 1238 1160 DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " 1239 1161 "Failed ECC read, page 0x%08x on chip %d\n", page, chipnr); 1240 1162 ecc_failed++; ··· 1274 1194 p[i] = ecc_status; 1275 1195 } 1276 1196 1277 - if (ecc_status == -1) { 1197 + if ((ecc_status == -1) || (ecc_status > (flags && 0xff))) { 1278 1198 DEBUG (MTD_DEBUG_LEVEL0, "nand_read_ecc: " "Failed ECC read, page 0x%08x\n", page); 1279 1199 ecc_failed++; 1280 1200 } ··· 1286 1206 /* without autoplace. Legacy mode used by YAFFS1 */ 1287 1207 switch(oobsel->useecc) { 1288 1208 case MTD_NANDECC_AUTOPLACE: 1209 + case MTD_NANDECC_AUTOPL_USR: 1289 1210 /* Walk through the autoplace chunks */ 1290 - for (i = 0, j = 0; j < mtd->oobavail; i++) { 1211 + for (i = 0; oobsel->oobfree[i][1]; i++) { 1291 1212 int from = oobsel->oobfree[i][0]; 1292 1213 int num = oobsel->oobfree[i][1]; 1293 1214 memcpy(&oob_buf[oob], &oob_data[from], num); 1294 - j+= num; 1215 + oob += num; 1295 1216 } 1296 - oob += mtd->oobavail; 1297 1217 break; 1298 1218 case MTD_NANDECC_PLACE: 1299 1219 /* YAFFS1 legacy mode */ ··· 1319 1239 if (!this->dev_ready) 1320 1240 udelay (this->chip_delay); 1321 1241 else 1322 - while (!this->dev_ready(mtd)); 1242 + nand_wait_ready(mtd); 1323 1243 1324 1244 if (read == len) 1325 1245 break; ··· 1344 1264 } 1345 1265 1346 1266 /* Deselect and wake up anyone waiting on the device */ 1347 - nand_release_device(mtd); 1267 + if (flags & NAND_GET_DEVICE) 1268 + nand_release_device(mtd); 1348 1269 1349 1270 /* 1350 1271 * Return success, if no ECC failures, else -EBADMSG ··· 1418 1337 if (!this->dev_ready) 1419 1338 udelay (this->chip_delay); 1420 1339 else 1421 - while (!this->dev_ready(mtd)); 1340 + nand_wait_ready(mtd); 1422 1341 1423 1342 /* Read more ? */ 1424 1343 if (i < len) { ··· 1498 1417 if (!this->dev_ready) 1499 1418 udelay (this->chip_delay); 1500 1419 else 1501 - while (!this->dev_ready(mtd)); 1420 + nand_wait_ready(mtd); 1502 1421 1503 1422 /* Check, if the chip supports auto page increment */ 1504 1423 if (!NAND_CANAUTOINCR(this) || !(page & blockcheck)) ··· 1648 1567 oobsel = this->autooob; 1649 1568 autoplace = 1; 1650 1569 } 1570 + if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR) 1571 + autoplace = 1; 1651 1572 1652 1573 /* Setup variables and oob buffer */ 1653 1574 totalpages = len >> this->page_shift; ··· 1816 1733 status = this->waitfunc (mtd, this, FL_WRITING); 1817 1734 1818 1735 /* See if device thinks it succeeded */ 1819 - if (status & 0x01) { 1736 + if (status & NAND_STATUS_FAIL) { 1820 1737 DEBUG (MTD_DEBUG_LEVEL0, "nand_write_oob: " "Failed write, page 0x%08x\n", page); 1821 1738 ret = -EIO; 1822 1739 goto out; ··· 1924 1841 oobsel = this->autooob; 1925 1842 autoplace = 1; 1926 1843 } 1844 + if (oobsel->useecc == MTD_NANDECC_AUTOPL_USR) 1845 + autoplace = 1; 1927 1846 1928 1847 /* Setup start page */ 1929 1848 page = (int) (to >> this->page_shift); ··· 2072 1987 return nand_erase_nand (mtd, instr, 0); 2073 1988 } 2074 1989 1990 + #define BBT_PAGE_MASK 0xffffff3f 2075 1991 /** 2076 1992 * nand_erase_intern - [NAND Interface] erase block(s) 2077 1993 * @mtd: MTD device structure ··· 2085 1999 { 2086 2000 int page, len, status, pages_per_block, ret, chipnr; 2087 2001 struct nand_chip *this = mtd->priv; 2002 + int rewrite_bbt[NAND_MAX_CHIPS]={0}; /* flags to indicate the page, if bbt needs to be rewritten. */ 2003 + unsigned int bbt_masked_page; /* bbt mask to compare to page being erased. */ 2004 + /* It is used to see if the current page is in the same */ 2005 + /* 256 block group and the same bank as the bbt. */ 2088 2006 2089 2007 DEBUG (MTD_DEBUG_LEVEL3, 2090 2008 "nand_erase: start = 0x%08x, len = %i\n", (unsigned int) instr->addr, (unsigned int) instr->len); ··· 2134 2044 goto erase_exit; 2135 2045 } 2136 2046 2047 + /* if BBT requires refresh, set the BBT page mask to see if the BBT should be rewritten */ 2048 + if (this->options & BBT_AUTO_REFRESH) { 2049 + bbt_masked_page = this->bbt_td->pages[chipnr] & BBT_PAGE_MASK; 2050 + } else { 2051 + bbt_masked_page = 0xffffffff; /* should not match anything */ 2052 + } 2053 + 2137 2054 /* Loop through the pages */ 2138 2055 len = instr->len; 2139 2056 ··· 2163 2066 2164 2067 status = this->waitfunc (mtd, this, FL_ERASING); 2165 2068 2069 + /* See if operation failed and additional status checks are available */ 2070 + if ((status & NAND_STATUS_FAIL) && (this->errstat)) { 2071 + status = this->errstat(mtd, this, FL_ERASING, status, page); 2072 + } 2073 + 2166 2074 /* See if block erase succeeded */ 2167 - if (status & 0x01) { 2075 + if (status & NAND_STATUS_FAIL) { 2168 2076 DEBUG (MTD_DEBUG_LEVEL0, "nand_erase: " "Failed erase, page 0x%08x\n", page); 2169 2077 instr->state = MTD_ERASE_FAILED; 2170 2078 instr->fail_addr = (page << this->page_shift); 2171 2079 goto erase_exit; 2080 + } 2081 + 2082 + /* if BBT requires refresh, set the BBT rewrite flag to the page being erased */ 2083 + if (this->options & BBT_AUTO_REFRESH) { 2084 + if (((page & BBT_PAGE_MASK) == bbt_masked_page) && 2085 + (page != this->bbt_td->pages[chipnr])) { 2086 + rewrite_bbt[chipnr] = (page << this->page_shift); 2087 + } 2172 2088 } 2173 2089 2174 2090 /* Increment page address and decrement length */ ··· 2193 2083 chipnr++; 2194 2084 this->select_chip(mtd, -1); 2195 2085 this->select_chip(mtd, chipnr); 2086 + 2087 + /* if BBT requires refresh and BBT-PERCHIP, 2088 + * set the BBT page mask to see if this BBT should be rewritten */ 2089 + if ((this->options & BBT_AUTO_REFRESH) && (this->bbt_td->options & NAND_BBT_PERCHIP)) { 2090 + bbt_masked_page = this->bbt_td->pages[chipnr] & BBT_PAGE_MASK; 2091 + } 2092 + 2196 2093 } 2197 2094 } 2198 2095 instr->state = MTD_ERASE_DONE; ··· 2213 2096 2214 2097 /* Deselect and wake up anyone waiting on the device */ 2215 2098 nand_release_device(mtd); 2099 + 2100 + /* if BBT requires refresh and erase was successful, rewrite any selected bad block tables */ 2101 + if ((this->options & BBT_AUTO_REFRESH) && (!ret)) { 2102 + for (chipnr = 0; chipnr < this->numchips; chipnr++) { 2103 + if (rewrite_bbt[chipnr]) { 2104 + /* update the BBT for chip */ 2105 + DEBUG (MTD_DEBUG_LEVEL0, "nand_erase_nand: nand_update_bbt (%d:0x%0x 0x%0x)\n", 2106 + chipnr, rewrite_bbt[chipnr], this->bbt_td->pages[chipnr]); 2107 + nand_update_bbt (mtd, rewrite_bbt[chipnr]); 2108 + } 2109 + } 2110 + } 2216 2111 2217 2112 /* Return more or less happy */ 2218 2113 return ret; ··· 2297 2168 */ 2298 2169 int nand_scan (struct mtd_info *mtd, int maxchips) 2299 2170 { 2300 - int i, j, nand_maf_id, nand_dev_id, busw; 2171 + int i, nand_maf_id, nand_dev_id, busw, maf_id; 2301 2172 struct nand_chip *this = mtd->priv; 2302 2173 2303 2174 /* Get buswidth to select the correct functions*/ ··· 2385 2256 busw = nand_flash_ids[i].options & NAND_BUSWIDTH_16; 2386 2257 } 2387 2258 2259 + /* Try to identify manufacturer */ 2260 + for (maf_id = 0; nand_manuf_ids[maf_id].id != 0x0; maf_id++) { 2261 + if (nand_manuf_ids[maf_id].id == nand_maf_id) 2262 + break; 2263 + } 2264 + 2388 2265 /* Check, if buswidth is correct. Hardware drivers should set 2389 2266 * this correct ! */ 2390 2267 if (busw != (this->options & NAND_BUSWIDTH_16)) { 2391 2268 printk (KERN_INFO "NAND device: Manufacturer ID:" 2392 2269 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, 2393 - nand_manuf_ids[i].name , mtd->name); 2270 + nand_manuf_ids[maf_id].name , mtd->name); 2394 2271 printk (KERN_WARNING 2395 2272 "NAND bus width %d instead %d bit\n", 2396 2273 (this->options & NAND_BUSWIDTH_16) ? 16 : 8, ··· 2435 2300 if (mtd->oobblock > 512 && this->cmdfunc == nand_command) 2436 2301 this->cmdfunc = nand_command_lp; 2437 2302 2438 - /* Try to identify manufacturer */ 2439 - for (j = 0; nand_manuf_ids[j].id != 0x0; j++) { 2440 - if (nand_manuf_ids[j].id == nand_maf_id) 2441 - break; 2442 - } 2443 2303 printk (KERN_INFO "NAND device: Manufacturer ID:" 2444 2304 " 0x%02x, Chip ID: 0x%02x (%s %s)\n", nand_maf_id, nand_dev_id, 2445 - nand_manuf_ids[j].name , nand_flash_ids[i].name); 2305 + nand_manuf_ids[maf_id].name , nand_flash_ids[i].name); 2446 2306 break; 2447 2307 } 2448 2308 ··· 2518 2388 2519 2389 /* The number of bytes available for the filesystem to place fs dependend 2520 2390 * oob data */ 2521 - if (this->options & NAND_BUSWIDTH_16) { 2522 - mtd->oobavail = mtd->oobsize - (this->autooob->eccbytes + 2); 2523 - if (this->autooob->eccbytes & 0x01) 2524 - mtd->oobavail--; 2525 - } else 2526 - mtd->oobavail = mtd->oobsize - (this->autooob->eccbytes + 1); 2391 + mtd->oobavail = 0; 2392 + for (i = 0; this->autooob->oobfree[i][1]; i++) 2393 + mtd->oobavail += this->autooob->oobfree[i][1]; 2527 2394 2528 2395 /* 2529 2396 * check ECC mode, default to software ··· 2651 2524 memcpy(&mtd->oobinfo, this->autooob, sizeof(mtd->oobinfo)); 2652 2525 2653 2526 mtd->owner = THIS_MODULE; 2527 + 2528 + /* Check, if we should skip the bad block table scan */ 2529 + if (this->options & NAND_SKIP_BBTSCAN) 2530 + return 0; 2654 2531 2655 2532 /* Build bad block table */ 2656 2533 return this->scan_bbt (mtd); ··· 2686 2555 kfree (this->data_buf); 2687 2556 } 2688 2557 2689 - EXPORT_SYMBOL (nand_scan); 2690 - EXPORT_SYMBOL (nand_release); 2558 + EXPORT_SYMBOL_GPL (nand_scan); 2559 + EXPORT_SYMBOL_GPL (nand_release); 2691 2560 2692 2561 MODULE_LICENSE ("GPL"); 2693 2562 MODULE_AUTHOR ("Steven J. Hill <sjhill@realitydiluted.com>, Thomas Gleixner <tglx@linutronix.de>");
+86 -28
drivers/mtd/nand/nand_bbt.c
··· 6 6 * 7 7 * Copyright (C) 2004 Thomas Gleixner (tglx@linutronix.de) 8 8 * 9 - * $Id: nand_bbt.c,v 1.28 2004/11/13 10:19:09 gleixner Exp $ 9 + * $Id: nand_bbt.c,v 1.33 2005/06/14 15:47:56 gleixner Exp $ 10 10 * 11 11 * This program is free software; you can redistribute it and/or modify 12 12 * it under the terms of the GNU General Public License version 2 as ··· 77 77 */ 78 78 static int check_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) 79 79 { 80 - int i, end; 80 + int i, end = 0; 81 81 uint8_t *p = buf; 82 82 83 83 end = paglen + td->offs; ··· 95 95 return -1; 96 96 } 97 97 98 - p += td->len; 99 - end += td->len; 100 98 if (td->options & NAND_BBT_SCANEMPTY) { 99 + p += td->len; 100 + end += td->len; 101 101 for (i = end; i < len; i++) { 102 102 if (*p++ != 0xff) 103 103 return -1; 104 104 } 105 + } 106 + return 0; 107 + } 108 + 109 + /** 110 + * check_short_pattern - [GENERIC] check if a pattern is in the buffer 111 + * @buf: the buffer to search 112 + * @len: the length of buffer to search 113 + * @paglen: the pagelength 114 + * @td: search pattern descriptor 115 + * 116 + * Check for a pattern at the given place. Used to search bad block 117 + * tables and good / bad block identifiers. Same as check_pattern, but 118 + * no optional empty check and the pattern is expected to start 119 + * at offset 0. 120 + * 121 + */ 122 + static int check_short_pattern (uint8_t *buf, int len, int paglen, struct nand_bbt_descr *td) 123 + { 124 + int i; 125 + uint8_t *p = buf; 126 + 127 + /* Compare the pattern */ 128 + for (i = 0; i < td->len; i++) { 129 + if (p[i] != td->pattern[i]) 130 + return -1; 105 131 } 106 132 return 0; 107 133 } ··· 278 252 * Create a bad block table by scanning the device 279 253 * for the given good/bad block identify pattern 280 254 */ 281 - static void create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd, int chip) 255 + static int create_bbt (struct mtd_info *mtd, uint8_t *buf, struct nand_bbt_descr *bd, int chip) 282 256 { 283 257 struct nand_chip *this = mtd->priv; 284 258 int i, j, numblocks, len, scanlen; ··· 296 270 else 297 271 len = 1; 298 272 } 299 - scanlen = mtd->oobblock + mtd->oobsize; 300 - readlen = len * mtd->oobblock; 301 - ooblen = len * mtd->oobsize; 273 + 274 + if (!(bd->options & NAND_BBT_SCANEMPTY)) { 275 + /* We need only read few bytes from the OOB area */ 276 + scanlen = ooblen = 0; 277 + readlen = bd->len; 278 + } else { 279 + /* Full page content should be read */ 280 + scanlen = mtd->oobblock + mtd->oobsize; 281 + readlen = len * mtd->oobblock; 282 + ooblen = len * mtd->oobsize; 283 + } 302 284 303 285 if (chip == -1) { 304 286 /* Note that numblocks is 2 * (real numblocks) here, see i+=2 below as it ··· 318 284 if (chip >= this->numchips) { 319 285 printk (KERN_WARNING "create_bbt(): chipnr (%d) > available chips (%d)\n", 320 286 chip + 1, this->numchips); 321 - return; 287 + return -EINVAL; 322 288 } 323 289 numblocks = this->chipsize >> (this->bbt_erase_shift - 1); 324 290 startblock = chip * numblocks; ··· 327 293 } 328 294 329 295 for (i = startblock; i < numblocks;) { 330 - nand_read_raw (mtd, buf, from, readlen, ooblen); 296 + int ret; 297 + 298 + if (bd->options & NAND_BBT_SCANEMPTY) 299 + if ((ret = nand_read_raw (mtd, buf, from, readlen, ooblen))) 300 + return ret; 301 + 331 302 for (j = 0; j < len; j++) { 332 - if (check_pattern (&buf[j * scanlen], scanlen, mtd->oobblock, bd)) { 333 - this->bbt[i >> 3] |= 0x03 << (i & 0x6); 334 - printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n", 335 - i >> 1, (unsigned int) from); 336 - break; 303 + if (!(bd->options & NAND_BBT_SCANEMPTY)) { 304 + size_t retlen; 305 + 306 + /* No need to read pages fully, just read required OOB bytes */ 307 + ret = mtd->read_oob(mtd, from + j * mtd->oobblock + bd->offs, 308 + readlen, &retlen, &buf[0]); 309 + if (ret) 310 + return ret; 311 + 312 + if (check_short_pattern (&buf[j * scanlen], scanlen, mtd->oobblock, bd)) { 313 + this->bbt[i >> 3] |= 0x03 << (i & 0x6); 314 + printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n", 315 + i >> 1, (unsigned int) from); 316 + break; 317 + } 318 + } else { 319 + if (check_pattern (&buf[j * scanlen], scanlen, mtd->oobblock, bd)) { 320 + this->bbt[i >> 3] |= 0x03 << (i & 0x6); 321 + printk (KERN_WARNING "Bad eraseblock %d at 0x%08x\n", 322 + i >> 1, (unsigned int) from); 323 + break; 324 + } 337 325 } 338 326 } 339 327 i += 2; 340 328 from += (1 << this->bbt_erase_shift); 341 329 } 330 + return 0; 342 331 } 343 332 344 333 /** ··· 646 589 * The function creates a memory based bbt by scanning the device 647 590 * for manufacturer / software marked good / bad blocks 648 591 */ 649 - static int nand_memory_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd) 592 + static inline int nand_memory_bbt (struct mtd_info *mtd, struct nand_bbt_descr *bd) 650 593 { 651 594 struct nand_chip *this = mtd->priv; 652 595 653 - /* Ensure that we only scan for the pattern and nothing else */ 654 - bd->options = 0; 655 - create_bbt (mtd, this->data_buf, bd, -1); 656 - return 0; 596 + bd->options &= ~NAND_BBT_SCANEMPTY; 597 + return create_bbt (mtd, this->data_buf, bd, -1); 657 598 } 658 599 659 600 /** ··· 863 808 /* If no primary table decriptor is given, scan the device 864 809 * to build a memory based bad block table 865 810 */ 866 - if (!td) 867 - return nand_memory_bbt(mtd, bd); 811 + if (!td) { 812 + if ((res = nand_memory_bbt(mtd, bd))) { 813 + printk (KERN_ERR "nand_bbt: Can't scan flash and build the RAM-based BBT\n"); 814 + kfree (this->bbt); 815 + this->bbt = NULL; 816 + } 817 + return res; 818 + } 868 819 869 820 /* Allocate a temporary buffer for one eraseblock incl. oob */ 870 821 len = (1 << this->bbt_erase_shift); ··· 965 904 } 966 905 967 906 /* Define some generic bad / good block scan pattern which are used 968 - * while scanning a device for factory marked good / bad blocks 969 - * 970 - * The memory based patterns just 971 - */ 907 + * while scanning a device for factory marked good / bad blocks. */ 972 908 static uint8_t scan_ff_pattern[] = { 0xff, 0xff }; 973 909 974 910 static struct nand_bbt_descr smallpage_memorybased = { 975 - .options = 0, 911 + .options = NAND_BBT_SCAN2NDPAGE, 976 912 .offs = 5, 977 913 .len = 1, 978 914 .pattern = scan_ff_pattern ··· 1100 1042 res = (this->bbt[block >> 3] >> (block & 0x06)) & 0x03; 1101 1043 1102 1044 DEBUG (MTD_DEBUG_LEVEL2, "nand_isbad_bbt(): bbt info for offs 0x%08x: (block %d) 0x%02x\n", 1103 - (unsigned int)offs, res, block >> 1); 1045 + (unsigned int)offs, block >> 1, res); 1104 1046 1105 1047 switch ((int)res) { 1106 1048 case 0x00: return 0;
+13 -5
drivers/mtd/nand/nand_ids.c
··· 2 2 * drivers/mtd/nandids.c 3 3 * 4 4 * Copyright (C) 2002 Thomas Gleixner (tglx@linutronix.de) 5 - * 6 - * $Id: nand_ids.c,v 1.10 2004/05/26 13:40:12 gleixner Exp $ 5 + * 6 + * $Id: nand_ids.c,v 1.14 2005/06/23 09:38:50 gleixner Exp $ 7 7 * 8 8 * This program is free software; you can redistribute it and/or modify 9 9 * it under the terms of the GNU General Public License version 2 as ··· 56 56 {"NAND 64MiB 3,3V 16-bit", 0x56, 512, 64, 0x4000, NAND_BUSWIDTH_16}, 57 57 58 58 {"NAND 128MiB 1,8V 8-bit", 0x78, 512, 128, 0x4000, 0}, 59 + {"NAND 128MiB 1,8V 8-bit", 0x39, 512, 128, 0x4000, 0}, 59 60 {"NAND 128MiB 3,3V 8-bit", 0x79, 512, 128, 0x4000, 0}, 60 61 {"NAND 128MiB 1,8V 16-bit", 0x72, 512, 128, 0x4000, NAND_BUSWIDTH_16}, 62 + {"NAND 128MiB 1,8V 16-bit", 0x49, 512, 128, 0x4000, NAND_BUSWIDTH_16}, 61 63 {"NAND 128MiB 3,3V 16-bit", 0x74, 512, 128, 0x4000, NAND_BUSWIDTH_16}, 64 + {"NAND 128MiB 3,3V 16-bit", 0x59, 512, 128, 0x4000, NAND_BUSWIDTH_16}, 62 65 63 66 {"NAND 256MiB 3,3V 8-bit", 0x71, 512, 256, 0x4000, 0}, 64 67 65 - {"NAND 512MiB 3,3V 8-bit", 0xDC, 512, 512, 0x4000, 0}, 66 - 67 68 /* These are the new chips with large page size. The pagesize 68 69 * and the erasesize is determined from the extended id bytes 69 70 */ 71 + /*512 Megabit */ 72 + {"NAND 64MiB 1,8V 8-bit", 0xA2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, 73 + {"NAND 64MiB 3,3V 8-bit", 0xF2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, 74 + {"NAND 64MiB 1,8V 16-bit", 0xB2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR}, 75 + {"NAND 64MiB 3,3V 16-bit", 0xC2, 0, 64, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_BUSWIDTH_16 | NAND_NO_AUTOINCR}, 76 + 70 77 /* 1 Gigabit */ 71 78 {"NAND 128MiB 1,8V 8-bit", 0xA1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, 72 79 {"NAND 128MiB 3,3V 8-bit", 0xF1, 0, 128, 0, NAND_SAMSUNG_LP_OPTIONS | NAND_NO_AUTOINCR}, ··· 110 103 * Anyway JFFS2 would increase the eraseblock size so we chose a combined one which can be erased in one go 111 104 * There are more speed improvements for reads and writes possible, but not implemented now 112 105 */ 113 - {"AND 128MiB 3,3V 8-bit", 0x01, 2048, 128, 0x4000, NAND_IS_AND | NAND_NO_AUTOINCR | NAND_4PAGE_ARRAY}, 106 + {"AND 128MiB 3,3V 8-bit", 0x01, 2048, 128, 0x4000, NAND_IS_AND | NAND_NO_AUTOINCR | NAND_4PAGE_ARRAY | BBT_AUTO_REFRESH}, 114 107 115 108 {NULL,} 116 109 }; ··· 125 118 {NAND_MFR_NATIONAL, "National"}, 126 119 {NAND_MFR_RENESAS, "Renesas"}, 127 120 {NAND_MFR_STMICRO, "ST Micro"}, 121 + {NAND_MFR_HYNIX, "Hynix"}, 128 122 {0x0, "Unknown"} 129 123 }; 130 124
+12 -29
drivers/mtd/nand/nandsim.c
··· 22 22 * along with this program; if not, write to the Free Software 23 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA 24 24 * 25 - * $Id: nandsim.c,v 1.7 2004/12/06 11:53:06 dedekind Exp $ 25 + * $Id: nandsim.c,v 1.8 2005/03/19 15:33:56 dedekind Exp $ 26 26 */ 27 27 28 28 #include <linux/config.h> ··· 1484 1484 } 1485 1485 1486 1486 /* 1487 - * Having only NAND chip IDs we call nand_scan which detects NAND flash 1488 - * parameters and then calls scan_bbt in order to scan/find/build the 1489 - * NAND flash bad block table. But since at that moment the NAND flash 1490 - * image isn't allocated in the simulator, errors arise. To avoid this 1491 - * we redefine the scan_bbt callback and initialize the nandsim structure 1492 - * before the flash media scanning. 1493 - */ 1494 - int ns_scan_bbt(struct mtd_info *mtd) 1495 - { 1496 - struct nand_chip *chip = (struct nand_chip *)mtd->priv; 1497 - struct nandsim *ns = (struct nandsim *)(chip->priv); 1498 - int retval; 1499 - 1500 - if (!NS_IS_INITIALIZED(ns)) 1501 - if ((retval = init_nandsim(mtd)) != 0) { 1502 - NS_ERR("scan_bbt: can't initialize the nandsim structure\n"); 1503 - return retval; 1504 - } 1505 - if ((retval = nand_default_bbt(mtd)) != 0) { 1506 - free_nandsim(ns); 1507 - return retval; 1508 - } 1509 - 1510 - return 0; 1511 - } 1512 - 1513 - /* 1514 1487 * Module initialization function 1515 1488 */ 1516 1489 int __init ns_init_module(void) ··· 1517 1544 chip->hwcontrol = ns_hwcontrol; 1518 1545 chip->read_byte = ns_nand_read_byte; 1519 1546 chip->dev_ready = ns_device_ready; 1520 - chip->scan_bbt = ns_scan_bbt; 1521 1547 chip->write_byte = ns_nand_write_byte; 1522 1548 chip->write_buf = ns_nand_write_buf; 1523 1549 chip->read_buf = ns_nand_read_buf; ··· 1524 1552 chip->write_word = ns_nand_write_word; 1525 1553 chip->read_word = ns_nand_read_word; 1526 1554 chip->eccmode = NAND_ECC_SOFT; 1555 + chip->options |= NAND_SKIP_BBTSCAN; 1527 1556 1528 1557 /* 1529 1558 * Perform minimum nandsim structure initialization to handle ··· 1550 1577 NS_ERR("can't register NAND Simulator\n"); 1551 1578 if (retval > 0) 1552 1579 retval = -ENXIO; 1580 + goto error; 1581 + } 1582 + 1583 + if ((retval = init_nandsim(nsmtd)) != 0) { 1584 + NS_ERR("scan_bbt: can't initialize the nandsim structure\n"); 1585 + goto error; 1586 + } 1587 + 1588 + if ((retval = nand_default_bbt(nsmtd)) != 0) { 1589 + free_nandsim(nand); 1553 1590 goto error; 1554 1591 } 1555 1592
+132 -8
drivers/mtd/nand/rtc_from4.c
··· 6 6 * Derived from drivers/mtd/nand/spia.c 7 7 * Copyright (C) 2000 Steven J. Hill (sjhill@realitydiluted.com) 8 8 * 9 - * $Id: rtc_from4.c,v 1.7 2004/11/04 12:53:10 gleixner Exp $ 9 + * $Id: rtc_from4.c,v 1.9 2005/01/24 20:40:11 dmarlin Exp $ 10 10 * 11 11 * This program is free software; you can redistribute it and/or modify 12 12 * it under the terms of the GNU General Public License version 2 as ··· 83 83 #define RTC_FROM4_RS_ECC_CHK (RTC_FROM4_NAND_ADDR_FPGA | 0x00000070) 84 84 #define RTC_FROM4_RS_ECC_CHK_ERROR (1 << 7) 85 85 86 + #define ERR_STAT_ECC_AVAILABLE 0x20 87 + 86 88 /* Undefine for software ECC */ 87 89 #define RTC_FROM4_HWECC 1 90 + 91 + /* Define as 1 for no virtual erase blocks (in JFFS2) */ 92 + #define RTC_FROM4_NO_VIRTBLOCKS 0 88 93 89 94 /* 90 95 * Module stuff 91 96 */ 92 - static void __iomem *rtc_from4_fio_base = P2SEGADDR(RTC_FROM4_FIO_BASE); 97 + static void __iomem *rtc_from4_fio_base = (void *)P2SEGADDR(RTC_FROM4_FIO_BASE); 93 98 94 99 const static struct mtd_partition partition_info[] = { 95 100 { ··· 272 267 } 273 268 274 269 275 - 276 270 /* 277 271 * rtc_from4_nand_device_ready - hardware specific ready/busy check 278 272 * @mtd: MTD device structure ··· 289 285 return (status & RTC_FROM4_DEVICE_READY); 290 286 291 287 } 288 + 289 + 290 + /* 291 + * deplete - code to perform device recovery in case there was a power loss 292 + * @mtd: MTD device structure 293 + * @chip: Chip to select (0 == slot 3, 1 == slot 4) 294 + * 295 + * If there was a sudden loss of power during an erase operation, a 296 + * "device recovery" operation must be performed when power is restored 297 + * to ensure correct operation. This routine performs the required steps 298 + * for the requested chip. 299 + * 300 + * See page 86 of the data sheet for details. 301 + * 302 + */ 303 + static void deplete(struct mtd_info *mtd, int chip) 304 + { 305 + struct nand_chip *this = mtd->priv; 306 + 307 + /* wait until device is ready */ 308 + while (!this->dev_ready(mtd)); 309 + 310 + this->select_chip(mtd, chip); 311 + 312 + /* Send the commands for device recovery, phase 1 */ 313 + this->cmdfunc (mtd, NAND_CMD_DEPLETE1, 0x0000, 0x0000); 314 + this->cmdfunc (mtd, NAND_CMD_DEPLETE2, -1, -1); 315 + 316 + /* Send the commands for device recovery, phase 2 */ 317 + this->cmdfunc (mtd, NAND_CMD_DEPLETE1, 0x0000, 0x0004); 318 + this->cmdfunc (mtd, NAND_CMD_DEPLETE2, -1, -1); 319 + 320 + } 321 + 292 322 293 323 #ifdef RTC_FROM4_HWECC 294 324 /* ··· 367 329 368 330 } 369 331 332 + 370 333 /* 371 334 * rtc_from4_calculate_ecc - hardware specific code to read ECC code 372 335 * @mtd: MTD device structure ··· 395 356 ecc_code[7] |= 0x0f; /* set the last four bits (not used) */ 396 357 } 397 358 359 + 398 360 /* 399 361 * rtc_from4_correct_data - hardware specific code to correct data using ECC code 400 362 * @mtd: MTD device structure ··· 405 365 * 406 366 * The FPGA tells us fast, if there's an error or not. If no, we go back happy 407 367 * else we read the ecc results from the fpga and call the rs library to decode 408 - * and hopefully correct the error 368 + * and hopefully correct the error. 409 369 * 410 - * For now I use the code, which we read from the FLASH to use the RS lib, 411 - * as the syndrom conversion has a unresolved issue. 412 370 */ 413 371 static int rtc_from4_correct_data(struct mtd_info *mtd, const u_char *buf, u_char *ecc1, u_char *ecc2) 414 372 { 415 373 int i, j, res; 416 374 unsigned short status; 417 - uint16_t par[6], syn[6], tmp; 375 + uint16_t par[6], syn[6]; 418 376 uint8_t ecc[8]; 419 377 volatile unsigned short *rs_ecc; 420 378 ··· 454 416 } 455 417 456 418 /* Let the library code do its magic.*/ 457 - res = decode_rs8(rs_decoder, buf, par, 512, syn, 0, NULL, 0xff, NULL); 419 + res = decode_rs8(rs_decoder, (uint8_t *)buf, par, 512, syn, 0, NULL, 0xff, NULL); 458 420 if (res > 0) { 459 421 DEBUG (MTD_DEBUG_LEVEL0, "rtc_from4_correct_data: " 460 422 "ECC corrected %d errors on read\n", res); 461 423 } 462 424 return res; 463 425 } 426 + 427 + 428 + /** 429 + * rtc_from4_errstat - perform additional error status checks 430 + * @mtd: MTD device structure 431 + * @this: NAND chip structure 432 + * @state: state or the operation 433 + * @status: status code returned from read status 434 + * @page: startpage inside the chip, must be called with (page & this->pagemask) 435 + * 436 + * Perform additional error status checks on erase and write failures 437 + * to determine if errors are correctable. For this device, correctable 438 + * 1-bit errors on erase and write are considered acceptable. 439 + * 440 + * note: see pages 34..37 of data sheet for details. 441 + * 442 + */ 443 + static int rtc_from4_errstat(struct mtd_info *mtd, struct nand_chip *this, int state, int status, int page) 444 + { 445 + int er_stat=0; 446 + int rtn, retlen; 447 + size_t len; 448 + uint8_t *buf; 449 + int i; 450 + 451 + this->cmdfunc (mtd, NAND_CMD_STATUS_CLEAR, -1, -1); 452 + 453 + if (state == FL_ERASING) { 454 + for (i=0; i<4; i++) { 455 + if (status & 1<<(i+1)) { 456 + this->cmdfunc (mtd, (NAND_CMD_STATUS_ERROR + i + 1), -1, -1); 457 + rtn = this->read_byte(mtd); 458 + this->cmdfunc (mtd, NAND_CMD_STATUS_RESET, -1, -1); 459 + if (!(rtn & ERR_STAT_ECC_AVAILABLE)) { 460 + er_stat |= 1<<(i+1); /* err_ecc_not_avail */ 461 + } 462 + } 463 + } 464 + } else if (state == FL_WRITING) { 465 + /* single bank write logic */ 466 + this->cmdfunc (mtd, NAND_CMD_STATUS_ERROR, -1, -1); 467 + rtn = this->read_byte(mtd); 468 + this->cmdfunc (mtd, NAND_CMD_STATUS_RESET, -1, -1); 469 + if (!(rtn & ERR_STAT_ECC_AVAILABLE)) { 470 + er_stat |= 1<<1; /* err_ecc_not_avail */ 471 + } else { 472 + len = mtd->oobblock; 473 + buf = kmalloc (len, GFP_KERNEL); 474 + if (!buf) { 475 + printk (KERN_ERR "rtc_from4_errstat: Out of memory!\n"); 476 + er_stat = 1; /* if we can't check, assume failed */ 477 + } else { 478 + /* recovery read */ 479 + /* page read */ 480 + rtn = nand_do_read_ecc (mtd, page, len, &retlen, buf, NULL, this->autooob, 1); 481 + if (rtn) { /* if read failed or > 1-bit error corrected */ 482 + er_stat |= 1<<1; /* ECC read failed */ 483 + } 484 + kfree(buf); 485 + } 486 + } 487 + } 488 + 489 + rtn = status; 490 + if (er_stat == 0) { /* if ECC is available */ 491 + rtn = (status & ~NAND_STATUS_FAIL); /* clear the error bit */ 492 + } 493 + 494 + return rtn; 495 + } 464 496 #endif 497 + 465 498 466 499 /* 467 500 * Main initialization routine ··· 541 432 { 542 433 struct nand_chip *this; 543 434 unsigned short bcr1, bcr2, wcr2; 435 + int i; 544 436 545 437 /* Allocate memory for MTD device structure and private data */ 546 438 rtc_from4_mtd = kmalloc(sizeof(struct mtd_info) + sizeof (struct nand_chip), ··· 593 483 594 484 this->eccmode = NAND_ECC_HW8_512; 595 485 this->options |= NAND_HWECC_SYNDROME; 486 + /* return the status of extra status and ECC checks */ 487 + this->errstat = rtc_from4_errstat; 596 488 /* set the nand_oobinfo to support FPGA H/W error detection */ 597 489 this->autooob = &rtc_from4_nand_oobinfo; 598 490 this->enable_hwecc = rtc_from4_enable_hwecc; ··· 615 503 kfree(rtc_from4_mtd); 616 504 return -ENXIO; 617 505 } 506 + 507 + /* Perform 'device recovery' for each chip in case there was a power loss. */ 508 + for (i=0; i < this->numchips; i++) { 509 + deplete(rtc_from4_mtd, i); 510 + } 511 + 512 + #if RTC_FROM4_NO_VIRTBLOCKS 513 + /* use a smaller erase block to minimize wasted space when a block is bad */ 514 + /* note: this uses eight times as much RAM as using the default and makes */ 515 + /* mounts take four times as long. */ 516 + rtc_from4_mtd->flags |= MTD_NO_VIRTBLOCKS; 517 + #endif 618 518 619 519 /* Register the partitions */ 620 520 add_mtd_partitions(rtc_from4_mtd, partition_info, NUM_PARTITIONS);
+161 -136
drivers/mtd/nand/s3c2410.c
··· 1 1 /* linux/drivers/mtd/nand/s3c2410.c 2 2 * 3 - * Copyright (c) 2004 Simtec Electronics 4 - * Ben Dooks <ben@simtec.co.uk> 3 + * Copyright (c) 2004,2005 Simtec Electronics 4 + * http://www.simtec.co.uk/products/SWLINUX/ 5 + * Ben Dooks <ben@simtec.co.uk> 5 6 * 6 - * Samsung S3C2410 NAND driver 7 + * Samsung S3C2410/S3C240 NAND driver 7 8 * 8 9 * Changelog: 9 10 * 21-Sep-2004 BJD Initial version 10 11 * 23-Sep-2004 BJD Mulitple device support 11 12 * 28-Sep-2004 BJD Fixed ECC placement for Hardware mode 12 13 * 12-Oct-2004 BJD Fixed errors in use of platform data 14 + * 18-Feb-2005 BJD Fix sparse errors 15 + * 14-Mar-2005 BJD Applied tglx's code reduction patch 16 + * 02-May-2005 BJD Fixed s3c2440 support 17 + * 02-May-2005 BJD Reduced hwcontrol decode 18 + * 20-Jun-2005 BJD Updated s3c2440 support, fixed timing bug 19 + * 08-Jul-2005 BJD Fix OOPS when no platform data supplied 13 20 * 14 - * $Id: s3c2410.c,v 1.7 2005/01/05 18:05:14 dwmw2 Exp $ 21 + * $Id: s3c2410.c,v 1.14 2005/07/06 20:05:06 bjd Exp $ 15 22 * 16 23 * This program is free software; you can redistribute it and/or modify 17 24 * it under the terms of the GNU General Public License as published by ··· 76 69 */ 77 70 78 71 static struct nand_oobinfo nand_hw_eccoob = { 79 - .useecc = MTD_NANDECC_AUTOPLACE, 80 - .eccbytes = 3, 81 - .eccpos = {0, 1, 2 }, 82 - .oobfree = { {8, 8} } 72 + .useecc = MTD_NANDECC_AUTOPLACE, 73 + .eccbytes = 3, 74 + .eccpos = {0, 1, 2 }, 75 + .oobfree = { {8, 8} } 83 76 }; 84 77 85 78 /* controller and mtd information */ ··· 106 99 struct device *device; 107 100 struct resource *area; 108 101 struct clk *clk; 109 - void *regs; 102 + void __iomem *regs; 110 103 int mtd_count; 104 + 105 + unsigned char is_s3c2440; 111 106 }; 112 107 113 108 /* conversion functions */ ··· 174 165 /* calculate the timing information for the controller */ 175 166 176 167 if (plat != NULL) { 177 - tacls = s3c2410_nand_calc_rate(plat->tacls, clkrate, 8); 168 + tacls = s3c2410_nand_calc_rate(plat->tacls, clkrate, 4); 178 169 twrph0 = s3c2410_nand_calc_rate(plat->twrph0, clkrate, 8); 179 170 twrph1 = s3c2410_nand_calc_rate(plat->twrph1, clkrate, 8); 180 171 } else { 181 172 /* default timings */ 182 - tacls = 8; 173 + tacls = 4; 183 174 twrph0 = 8; 184 175 twrph1 = 8; 185 176 } ··· 194 185 to_ns(twrph0, clkrate), 195 186 to_ns(twrph1, clkrate)); 196 187 197 - cfg = S3C2410_NFCONF_EN; 198 - cfg |= S3C2410_NFCONF_TACLS(tacls-1); 199 - cfg |= S3C2410_NFCONF_TWRPH0(twrph0-1); 200 - cfg |= S3C2410_NFCONF_TWRPH1(twrph1-1); 188 + if (!info->is_s3c2440) { 189 + cfg = S3C2410_NFCONF_EN; 190 + cfg |= S3C2410_NFCONF_TACLS(tacls-1); 191 + cfg |= S3C2410_NFCONF_TWRPH0(twrph0-1); 192 + cfg |= S3C2410_NFCONF_TWRPH1(twrph1-1); 193 + } else { 194 + cfg = S3C2440_NFCONF_TACLS(tacls-1); 195 + cfg |= S3C2440_NFCONF_TWRPH0(twrph0-1); 196 + cfg |= S3C2440_NFCONF_TWRPH1(twrph1-1); 197 + } 201 198 202 199 pr_debug(PFX "NF_CONF is 0x%lx\n", cfg); 203 200 ··· 218 203 struct s3c2410_nand_info *info; 219 204 struct s3c2410_nand_mtd *nmtd; 220 205 struct nand_chip *this = mtd->priv; 206 + void __iomem *reg; 221 207 unsigned long cur; 208 + unsigned long bit; 222 209 223 210 nmtd = this->priv; 224 211 info = nmtd->info; 225 212 226 - cur = readl(info->regs + S3C2410_NFCONF); 213 + bit = (info->is_s3c2440) ? S3C2440_NFCONT_nFCE : S3C2410_NFCONF_nFCE; 214 + reg = info->regs+((info->is_s3c2440) ? S3C2440_NFCONT:S3C2410_NFCONF); 215 + 216 + cur = readl(reg); 227 217 228 218 if (chip == -1) { 229 - cur |= S3C2410_NFCONF_nFCE; 219 + cur |= bit; 230 220 } else { 231 - if (chip > nmtd->set->nr_chips) { 221 + if (nmtd->set != NULL && chip > nmtd->set->nr_chips) { 232 222 printk(KERN_ERR PFX "chip %d out of range\n", chip); 233 223 return; 234 224 } ··· 243 223 (info->platform->select_chip)(nmtd->set, chip); 244 224 } 245 225 246 - cur &= ~S3C2410_NFCONF_nFCE; 226 + cur &= ~bit; 247 227 } 248 228 249 - writel(cur, info->regs + S3C2410_NFCONF); 229 + writel(cur, reg); 250 230 } 251 231 252 - /* command and control functions */ 232 + /* command and control functions 233 + * 234 + * Note, these all use tglx's method of changing the IO_ADDR_W field 235 + * to make the code simpler, and use the nand layer's code to issue the 236 + * command and address sequences via the proper IO ports. 237 + * 238 + */ 253 239 254 240 static void s3c2410_nand_hwcontrol(struct mtd_info *mtd, int cmd) 255 241 { 256 242 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 257 - unsigned long cur; 243 + struct nand_chip *chip = mtd->priv; 258 244 259 245 switch (cmd) { 260 246 case NAND_CTL_SETNCE: 261 - cur = readl(info->regs + S3C2410_NFCONF); 262 - cur &= ~S3C2410_NFCONF_nFCE; 263 - writel(cur, info->regs + S3C2410_NFCONF); 264 - break; 265 - 266 247 case NAND_CTL_CLRNCE: 267 - cur = readl(info->regs + S3C2410_NFCONF); 268 - cur |= S3C2410_NFCONF_nFCE; 269 - writel(cur, info->regs + S3C2410_NFCONF); 248 + printk(KERN_ERR "%s: called for NCE\n", __FUNCTION__); 270 249 break; 271 250 272 - /* we don't need to implement these */ 273 251 case NAND_CTL_SETCLE: 274 - case NAND_CTL_CLRCLE: 252 + chip->IO_ADDR_W = info->regs + S3C2410_NFCMD; 253 + break; 254 + 275 255 case NAND_CTL_SETALE: 276 - case NAND_CTL_CLRALE: 277 - pr_debug(PFX "s3c2410_nand_hwcontrol(%d) unusedn", cmd); 256 + chip->IO_ADDR_W = info->regs + S3C2410_NFADDR; 257 + break; 258 + 259 + /* NAND_CTL_CLRCLE: */ 260 + /* NAND_CTL_CLRALE: */ 261 + default: 262 + chip->IO_ADDR_W = info->regs + S3C2410_NFDATA; 278 263 break; 279 264 } 280 265 } 281 266 282 - /* s3c2410_nand_command 283 - * 284 - * This function implements sending commands and the relevant address 285 - * information to the chip, via the hardware controller. Since the 286 - * S3C2410 generates the correct ALE/CLE signaling automatically, we 287 - * do not need to use hwcontrol. 288 - */ 267 + /* command and control functions */ 289 268 290 - static void s3c2410_nand_command (struct mtd_info *mtd, unsigned command, 291 - int column, int page_addr) 269 + static void s3c2440_nand_hwcontrol(struct mtd_info *mtd, int cmd) 292 270 { 293 - register struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 294 - register struct nand_chip *this = mtd->priv; 271 + struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 272 + struct nand_chip *chip = mtd->priv; 295 273 296 - /* 297 - * Write out the command to the device. 298 - */ 299 - if (command == NAND_CMD_SEQIN) { 300 - int readcmd; 274 + switch (cmd) { 275 + case NAND_CTL_SETNCE: 276 + case NAND_CTL_CLRNCE: 277 + printk(KERN_ERR "%s: called for NCE\n", __FUNCTION__); 278 + break; 301 279 302 - if (column >= mtd->oobblock) { 303 - /* OOB area */ 304 - column -= mtd->oobblock; 305 - readcmd = NAND_CMD_READOOB; 306 - } else if (column < 256) { 307 - /* First 256 bytes --> READ0 */ 308 - readcmd = NAND_CMD_READ0; 309 - } else { 310 - column -= 256; 311 - readcmd = NAND_CMD_READ1; 312 - } 313 - 314 - writeb(readcmd, info->regs + S3C2410_NFCMD); 315 - } 316 - writeb(command, info->regs + S3C2410_NFCMD); 280 + case NAND_CTL_SETCLE: 281 + chip->IO_ADDR_W = info->regs + S3C2440_NFCMD; 282 + break; 317 283 318 - /* Set ALE and clear CLE to start address cycle */ 284 + case NAND_CTL_SETALE: 285 + chip->IO_ADDR_W = info->regs + S3C2440_NFADDR; 286 + break; 319 287 320 - if (column != -1 || page_addr != -1) { 321 - 322 - /* Serially input address */ 323 - if (column != -1) { 324 - /* Adjust columns for 16 bit buswidth */ 325 - if (this->options & NAND_BUSWIDTH_16) 326 - column >>= 1; 327 - writeb(column, info->regs + S3C2410_NFADDR); 328 - } 329 - if (page_addr != -1) { 330 - writeb((unsigned char) (page_addr), info->regs + S3C2410_NFADDR); 331 - writeb((unsigned char) (page_addr >> 8), info->regs + S3C2410_NFADDR); 332 - /* One more address cycle for higher density devices */ 333 - if (this->chipsize & 0x0c000000) 334 - writeb((unsigned char) ((page_addr >> 16) & 0x0f), 335 - info->regs + S3C2410_NFADDR); 336 - } 337 - /* Latch in address */ 338 - } 339 - 340 - /* 341 - * program and erase have their own busy handlers 342 - * status and sequential in needs no delay 343 - */ 344 - switch (command) { 345 - 346 - case NAND_CMD_PAGEPROG: 347 - case NAND_CMD_ERASE1: 348 - case NAND_CMD_ERASE2: 349 - case NAND_CMD_SEQIN: 350 - case NAND_CMD_STATUS: 351 - return; 352 - 353 - case NAND_CMD_RESET: 354 - if (this->dev_ready) 355 - break; 356 - 357 - udelay(this->chip_delay); 358 - writeb(NAND_CMD_STATUS, info->regs + S3C2410_NFCMD); 359 - 360 - while ( !(this->read_byte(mtd) & 0x40)); 361 - return; 362 - 363 - /* This applies to read commands */ 288 + /* NAND_CTL_CLRCLE: */ 289 + /* NAND_CTL_CLRALE: */ 364 290 default: 365 - /* 366 - * If we don't have access to the busy pin, we apply the given 367 - * command delay 368 - */ 369 - if (!this->dev_ready) { 370 - udelay (this->chip_delay); 371 - return; 372 - } 291 + chip->IO_ADDR_W = info->regs + S3C2440_NFDATA; 292 + break; 373 293 } 374 - 375 - /* Apply this short delay always to ensure that we do wait tWB in 376 - * any case on any machine. */ 377 - ndelay (100); 378 - /* wait until command is processed */ 379 - while (!this->dev_ready(mtd)); 380 294 } 381 - 382 295 383 296 /* s3c2410_nand_devready() 384 297 * ··· 322 369 { 323 370 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 324 371 372 + if (info->is_s3c2440) 373 + return readb(info->regs + S3C2440_NFSTAT) & S3C2440_NFSTAT_READY; 325 374 return readb(info->regs + S3C2410_NFSTAT) & S3C2410_NFSTAT_BUSY; 326 375 } 376 + 327 377 328 378 /* ECC handling functions */ 329 379 ··· 350 394 return -1; 351 395 } 352 396 397 + /* ECC functions 398 + * 399 + * These allow the s3c2410 and s3c2440 to use the controller's ECC 400 + * generator block to ECC the data as it passes through] 401 + */ 402 + 353 403 static void s3c2410_nand_enable_hwecc(struct mtd_info *mtd, int mode) 354 404 { 355 405 struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); ··· 364 402 ctrl = readl(info->regs + S3C2410_NFCONF); 365 403 ctrl |= S3C2410_NFCONF_INITECC; 366 404 writel(ctrl, info->regs + S3C2410_NFCONF); 405 + } 406 + 407 + static void s3c2440_nand_enable_hwecc(struct mtd_info *mtd, int mode) 408 + { 409 + struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 410 + unsigned long ctrl; 411 + 412 + ctrl = readl(info->regs + S3C2440_NFCONT); 413 + writel(ctrl | S3C2440_NFCONT_INITECC, info->regs + S3C2440_NFCONT); 367 414 } 368 415 369 416 static int s3c2410_nand_calculate_ecc(struct mtd_info *mtd, ··· 391 420 } 392 421 393 422 394 - /* over-ride the standard functions for a little more speed? */ 423 + static int s3c2440_nand_calculate_ecc(struct mtd_info *mtd, 424 + const u_char *dat, u_char *ecc_code) 425 + { 426 + struct s3c2410_nand_info *info = s3c2410_nand_mtd_toinfo(mtd); 427 + unsigned long ecc = readl(info->regs + S3C2440_NFMECC0); 428 + 429 + ecc_code[0] = ecc; 430 + ecc_code[1] = ecc >> 8; 431 + ecc_code[2] = ecc >> 16; 432 + 433 + pr_debug("calculate_ecc: returning ecc %02x,%02x,%02x\n", 434 + ecc_code[0], ecc_code[1], ecc_code[2]); 435 + 436 + return 0; 437 + } 438 + 439 + 440 + /* over-ride the standard functions for a little more speed. We can 441 + * use read/write block to move the data buffers to/from the controller 442 + */ 395 443 396 444 static void s3c2410_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) 397 445 { ··· 513 523 { 514 524 struct nand_chip *chip = &nmtd->chip; 515 525 516 - chip->IO_ADDR_R = (char *)info->regs + S3C2410_NFDATA; 517 - chip->IO_ADDR_W = (char *)info->regs + S3C2410_NFDATA; 526 + chip->IO_ADDR_R = info->regs + S3C2410_NFDATA; 527 + chip->IO_ADDR_W = info->regs + S3C2410_NFDATA; 518 528 chip->hwcontrol = s3c2410_nand_hwcontrol; 519 529 chip->dev_ready = s3c2410_nand_devready; 520 - chip->cmdfunc = s3c2410_nand_command; 521 530 chip->write_buf = s3c2410_nand_write_buf; 522 531 chip->read_buf = s3c2410_nand_read_buf; 523 532 chip->select_chip = s3c2410_nand_select_chip; ··· 524 535 chip->priv = nmtd; 525 536 chip->options = 0; 526 537 chip->controller = &info->controller; 538 + 539 + if (info->is_s3c2440) { 540 + chip->IO_ADDR_R = info->regs + S3C2440_NFDATA; 541 + chip->IO_ADDR_W = info->regs + S3C2440_NFDATA; 542 + chip->hwcontrol = s3c2440_nand_hwcontrol; 543 + } 527 544 528 545 nmtd->info = info; 529 546 nmtd->mtd.priv = chip; ··· 541 546 chip->calculate_ecc = s3c2410_nand_calculate_ecc; 542 547 chip->eccmode = NAND_ECC_HW3_512; 543 548 chip->autooob = &nand_hw_eccoob; 549 + 550 + if (info->is_s3c2440) { 551 + chip->enable_hwecc = s3c2440_nand_enable_hwecc; 552 + chip->calculate_ecc = s3c2440_nand_calculate_ecc; 553 + } 544 554 } else { 545 555 chip->eccmode = NAND_ECC_SOFT; 546 556 } ··· 559 559 * nand layer to look for devices 560 560 */ 561 561 562 - static int s3c2410_nand_probe(struct device *dev) 562 + static int s3c24xx_nand_probe(struct device *dev, int is_s3c2440) 563 563 { 564 564 struct platform_device *pdev = to_platform_device(dev); 565 565 struct s3c2410_platform_nand *plat = to_nand_plat(dev); ··· 585 585 dev_set_drvdata(dev, info); 586 586 587 587 spin_lock_init(&info->controller.lock); 588 + init_waitqueue_head(&info->controller.wq); 588 589 589 590 /* get the clock source and enable it */ 590 591 ··· 601 600 602 601 /* allocate and map the resource */ 603 602 604 - res = pdev->resource; /* assume that the flash has one resource */ 603 + /* currently we assume we have the one resource */ 604 + res = pdev->resource; 605 605 size = res->end - res->start + 1; 606 606 607 607 info->area = request_mem_region(res->start, size, pdev->name); ··· 613 611 goto exit_error; 614 612 } 615 613 616 - info->device = dev; 617 - info->platform = plat; 618 - info->regs = ioremap(res->start, size); 614 + info->device = dev; 615 + info->platform = plat; 616 + info->regs = ioremap(res->start, size); 617 + info->is_s3c2440 = is_s3c2440; 619 618 620 619 if (info->regs == NULL) { 621 620 printk(KERN_ERR PFX "cannot reserve register region\n"); ··· 681 678 return err; 682 679 } 683 680 681 + /* driver device registration */ 682 + 683 + static int s3c2410_nand_probe(struct device *dev) 684 + { 685 + return s3c24xx_nand_probe(dev, 0); 686 + } 687 + 688 + static int s3c2440_nand_probe(struct device *dev) 689 + { 690 + return s3c24xx_nand_probe(dev, 1); 691 + } 692 + 684 693 static struct device_driver s3c2410_nand_driver = { 685 694 .name = "s3c2410-nand", 686 695 .bus = &platform_bus_type, ··· 700 685 .remove = s3c2410_nand_remove, 701 686 }; 702 687 688 + static struct device_driver s3c2440_nand_driver = { 689 + .name = "s3c2440-nand", 690 + .bus = &platform_bus_type, 691 + .probe = s3c2440_nand_probe, 692 + .remove = s3c2410_nand_remove, 693 + }; 694 + 703 695 static int __init s3c2410_nand_init(void) 704 696 { 705 - printk("S3C2410 NAND Driver, (c) 2004 Simtec Electronics\n"); 697 + printk("S3C24XX NAND Driver, (c) 2004 Simtec Electronics\n"); 698 + 699 + driver_register(&s3c2440_nand_driver); 706 700 return driver_register(&s3c2410_nand_driver); 707 701 } 708 702 709 703 static void __exit s3c2410_nand_exit(void) 710 704 { 705 + driver_unregister(&s3c2440_nand_driver); 711 706 driver_unregister(&s3c2410_nand_driver); 712 707 } 713 708 ··· 726 701 727 702 MODULE_LICENSE("GPL"); 728 703 MODULE_AUTHOR("Ben Dooks <ben@simtec.co.uk>"); 729 - MODULE_DESCRIPTION("S3C2410 MTD NAND driver"); 704 + MODULE_DESCRIPTION("S3C24XX MTD NAND driver");
+2 -2
drivers/mtd/nand/sharpsl.c
··· 3 3 * 4 4 * Copyright (C) 2004 Richard Purdie 5 5 * 6 - * $Id: sharpsl.c,v 1.3 2005/01/03 14:53:50 rpurdie Exp $ 6 + * $Id: sharpsl.c,v 1.4 2005/01/23 11:09:19 rpurdie Exp $ 7 7 * 8 8 * Based on Sharp's NAND driver sharp_sl.c 9 9 * ··· 216 216 nr_partitions = DEFAULT_NUM_PARTITIONS; 217 217 sharpsl_partition_info = sharpsl_nand_default_partition_info; 218 218 if (machine_is_poodle()) { 219 - sharpsl_partition_info[1].size=22 * 1024 * 1024; 219 + sharpsl_partition_info[1].size=30 * 1024 * 1024; 220 220 } else if (machine_is_corgi() || machine_is_shepherd()) { 221 221 sharpsl_partition_info[1].size=25 * 1024 * 1024; 222 222 } else if (machine_is_husky()) {
-416
drivers/mtd/nand/tx4925ndfmc.c
··· 1 - /* 2 - * drivers/mtd/tx4925ndfmc.c 3 - * 4 - * Overview: 5 - * This is a device driver for the NAND flash device found on the 6 - * Toshiba RBTX4925 reference board, which is a SmartMediaCard. It supports 7 - * 16MiB, 32MiB and 64MiB cards. 8 - * 9 - * Author: MontaVista Software, Inc. source@mvista.com 10 - * 11 - * Derived from drivers/mtd/autcpu12.c 12 - * Copyright (c) 2001 Thomas Gleixner (gleixner@autronix.de) 13 - * 14 - * $Id: tx4925ndfmc.c,v 1.5 2004/10/05 13:50:20 gleixner Exp $ 15 - * 16 - * Copyright (C) 2001 Toshiba Corporation 17 - * 18 - * 2003 (c) MontaVista Software, Inc. This file is licensed under 19 - * the terms of the GNU General Public License version 2. This program 20 - * is licensed "as is" without any warranty of any kind, whether express 21 - * or implied. 22 - * 23 - */ 24 - 25 - #include <linux/slab.h> 26 - #include <linux/init.h> 27 - #include <linux/module.h> 28 - #include <linux/mtd/mtd.h> 29 - #include <linux/mtd/nand.h> 30 - #include <linux/mtd/partitions.h> 31 - #include <linux/delay.h> 32 - #include <asm/io.h> 33 - #include <asm/tx4925/tx4925_nand.h> 34 - 35 - extern struct nand_oobinfo jffs2_oobinfo; 36 - 37 - /* 38 - * MTD structure for RBTX4925 board 39 - */ 40 - static struct mtd_info *tx4925ndfmc_mtd = NULL; 41 - 42 - /* 43 - * Define partitions for flash devices 44 - */ 45 - 46 - static struct mtd_partition partition_info16k[] = { 47 - { .name = "RBTX4925 flash partition 1", 48 - .offset = 0, 49 - .size = 8 * 0x00100000 }, 50 - { .name = "RBTX4925 flash partition 2", 51 - .offset = 8 * 0x00100000, 52 - .size = 8 * 0x00100000 }, 53 - }; 54 - 55 - static struct mtd_partition partition_info32k[] = { 56 - { .name = "RBTX4925 flash partition 1", 57 - .offset = 0, 58 - .size = 8 * 0x00100000 }, 59 - { .name = "RBTX4925 flash partition 2", 60 - .offset = 8 * 0x00100000, 61 - .size = 24 * 0x00100000 }, 62 - }; 63 - 64 - static struct mtd_partition partition_info64k[] = { 65 - { .name = "User FS", 66 - .offset = 0, 67 - .size = 16 * 0x00100000 }, 68 - { .name = "RBTX4925 flash partition 2", 69 - .offset = 16 * 0x00100000, 70 - .size = 48 * 0x00100000}, 71 - }; 72 - 73 - static struct mtd_partition partition_info128k[] = { 74 - { .name = "Skip bad section", 75 - .offset = 0, 76 - .size = 16 * 0x00100000 }, 77 - { .name = "User FS", 78 - .offset = 16 * 0x00100000, 79 - .size = 112 * 0x00100000 }, 80 - }; 81 - #define NUM_PARTITIONS16K 2 82 - #define NUM_PARTITIONS32K 2 83 - #define NUM_PARTITIONS64K 2 84 - #define NUM_PARTITIONS128K 2 85 - 86 - /* 87 - * hardware specific access to control-lines 88 - */ 89 - static void tx4925ndfmc_hwcontrol(struct mtd_info *mtd, int cmd) 90 - { 91 - 92 - switch(cmd){ 93 - 94 - case NAND_CTL_SETCLE: 95 - tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_CLE; 96 - break; 97 - case NAND_CTL_CLRCLE: 98 - tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_CLE; 99 - break; 100 - case NAND_CTL_SETALE: 101 - tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_ALE; 102 - break; 103 - case NAND_CTL_CLRALE: 104 - tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_ALE; 105 - break; 106 - case NAND_CTL_SETNCE: 107 - tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_CE; 108 - break; 109 - case NAND_CTL_CLRNCE: 110 - tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_CE; 111 - break; 112 - case NAND_CTL_SETWP: 113 - tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_WE; 114 - break; 115 - case NAND_CTL_CLRWP: 116 - tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_WE; 117 - break; 118 - } 119 - } 120 - 121 - /* 122 - * read device ready pin 123 - */ 124 - static int tx4925ndfmc_device_ready(struct mtd_info *mtd) 125 - { 126 - int ready; 127 - ready = (tx4925_ndfmcptr->sr & TX4925_NDSFR_BUSY) ? 0 : 1; 128 - return ready; 129 - } 130 - void tx4925ndfmc_enable_hwecc(struct mtd_info *mtd, int mode) 131 - { 132 - /* reset first */ 133 - tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_ECC_CNTL_MASK; 134 - tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_ECC_CNTL_MASK; 135 - tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_ECC_CNTL_ENAB; 136 - } 137 - static void tx4925ndfmc_disable_ecc(void) 138 - { 139 - tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_ECC_CNTL_MASK; 140 - } 141 - static void tx4925ndfmc_enable_read_ecc(void) 142 - { 143 - tx4925_ndfmcptr->mcr &= ~TX4925_NDFMCR_ECC_CNTL_MASK; 144 - tx4925_ndfmcptr->mcr |= TX4925_NDFMCR_ECC_CNTL_READ; 145 - } 146 - void tx4925ndfmc_readecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code){ 147 - int i; 148 - u_char *ecc = ecc_code; 149 - tx4925ndfmc_enable_read_ecc(); 150 - for (i = 0;i < 6;i++,ecc++) 151 - *ecc = tx4925_read_nfmc(&(tx4925_ndfmcptr->dtr)); 152 - tx4925ndfmc_disable_ecc(); 153 - } 154 - void tx4925ndfmc_device_setup(void) 155 - { 156 - 157 - *(unsigned char *)0xbb005000 &= ~0x08; 158 - 159 - /* reset NDFMC */ 160 - tx4925_ndfmcptr->rstr |= TX4925_NDFRSTR_RST; 161 - while (tx4925_ndfmcptr->rstr & TX4925_NDFRSTR_RST); 162 - 163 - /* setup BusSeparete, Hold Time, Strobe Pulse Width */ 164 - tx4925_ndfmcptr->mcr = TX4925_BSPRT ? TX4925_NDFMCR_BSPRT : 0; 165 - tx4925_ndfmcptr->spr = TX4925_HOLD << 4 | TX4925_SPW; 166 - } 167 - static u_char tx4925ndfmc_nand_read_byte(struct mtd_info *mtd) 168 - { 169 - struct nand_chip *this = mtd->priv; 170 - return tx4925_read_nfmc(this->IO_ADDR_R); 171 - } 172 - 173 - static void tx4925ndfmc_nand_write_byte(struct mtd_info *mtd, u_char byte) 174 - { 175 - struct nand_chip *this = mtd->priv; 176 - tx4925_write_nfmc(byte, this->IO_ADDR_W); 177 - } 178 - 179 - static void tx4925ndfmc_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len) 180 - { 181 - int i; 182 - struct nand_chip *this = mtd->priv; 183 - 184 - for (i=0; i<len; i++) 185 - tx4925_write_nfmc(buf[i], this->IO_ADDR_W); 186 - } 187 - 188 - static void tx4925ndfmc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) 189 - { 190 - int i; 191 - struct nand_chip *this = mtd->priv; 192 - 193 - for (i=0; i<len; i++) 194 - buf[i] = tx4925_read_nfmc(this->IO_ADDR_R); 195 - } 196 - 197 - static int tx4925ndfmc_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len) 198 - { 199 - int i; 200 - struct nand_chip *this = mtd->priv; 201 - 202 - for (i=0; i<len; i++) 203 - if (buf[i] != tx4925_read_nfmc(this->IO_ADDR_R)) 204 - return -EFAULT; 205 - 206 - return 0; 207 - } 208 - 209 - /* 210 - * Send command to NAND device 211 - */ 212 - static void tx4925ndfmc_nand_command (struct mtd_info *mtd, unsigned command, int column, int page_addr) 213 - { 214 - register struct nand_chip *this = mtd->priv; 215 - 216 - /* Begin command latch cycle */ 217 - this->hwcontrol(mtd, NAND_CTL_SETCLE); 218 - /* 219 - * Write out the command to the device. 220 - */ 221 - if (command == NAND_CMD_SEQIN) { 222 - int readcmd; 223 - 224 - if (column >= mtd->oobblock) { 225 - /* OOB area */ 226 - column -= mtd->oobblock; 227 - readcmd = NAND_CMD_READOOB; 228 - } else if (column < 256) { 229 - /* First 256 bytes --> READ0 */ 230 - readcmd = NAND_CMD_READ0; 231 - } else { 232 - column -= 256; 233 - readcmd = NAND_CMD_READ1; 234 - } 235 - this->write_byte(mtd, readcmd); 236 - } 237 - this->write_byte(mtd, command); 238 - 239 - /* Set ALE and clear CLE to start address cycle */ 240 - this->hwcontrol(mtd, NAND_CTL_CLRCLE); 241 - 242 - if (column != -1 || page_addr != -1) { 243 - this->hwcontrol(mtd, NAND_CTL_SETALE); 244 - 245 - /* Serially input address */ 246 - if (column != -1) 247 - this->write_byte(mtd, column); 248 - if (page_addr != -1) { 249 - this->write_byte(mtd, (unsigned char) (page_addr & 0xff)); 250 - this->write_byte(mtd, (unsigned char) ((page_addr >> 8) & 0xff)); 251 - /* One more address cycle for higher density devices */ 252 - if (mtd->size & 0x0c000000) 253 - this->write_byte(mtd, (unsigned char) ((page_addr >> 16) & 0x0f)); 254 - } 255 - /* Latch in address */ 256 - this->hwcontrol(mtd, NAND_CTL_CLRALE); 257 - } 258 - 259 - /* 260 - * program and erase have their own busy handlers 261 - * status and sequential in needs no delay 262 - */ 263 - switch (command) { 264 - 265 - case NAND_CMD_PAGEPROG: 266 - /* Turn off WE */ 267 - this->hwcontrol (mtd, NAND_CTL_CLRWP); 268 - return; 269 - 270 - case NAND_CMD_SEQIN: 271 - /* Turn on WE */ 272 - this->hwcontrol (mtd, NAND_CTL_SETWP); 273 - return; 274 - 275 - case NAND_CMD_ERASE1: 276 - case NAND_CMD_ERASE2: 277 - case NAND_CMD_STATUS: 278 - return; 279 - 280 - case NAND_CMD_RESET: 281 - if (this->dev_ready) 282 - break; 283 - this->hwcontrol(mtd, NAND_CTL_SETCLE); 284 - this->write_byte(mtd, NAND_CMD_STATUS); 285 - this->hwcontrol(mtd, NAND_CTL_CLRCLE); 286 - while ( !(this->read_byte(mtd) & 0x40)); 287 - return; 288 - 289 - /* This applies to read commands */ 290 - default: 291 - /* 292 - * If we don't have access to the busy pin, we apply the given 293 - * command delay 294 - */ 295 - if (!this->dev_ready) { 296 - udelay (this->chip_delay); 297 - return; 298 - } 299 - } 300 - 301 - /* wait until command is processed */ 302 - while (!this->dev_ready(mtd)); 303 - } 304 - 305 - #ifdef CONFIG_MTD_CMDLINE_PARTS 306 - extern int parse_cmdline_partitions(struct mtd_info *master, struct mtd_partitio 307 - n **pparts, char *); 308 - #endif 309 - 310 - /* 311 - * Main initialization routine 312 - */ 313 - extern int nand_correct_data(struct mtd_info *mtd, u_char *dat, u_char *read_ecc, u_char *calc_ecc); 314 - int __init tx4925ndfmc_init (void) 315 - { 316 - struct nand_chip *this; 317 - int err = 0; 318 - 319 - /* Allocate memory for MTD device structure and private data */ 320 - tx4925ndfmc_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip), 321 - GFP_KERNEL); 322 - if (!tx4925ndfmc_mtd) { 323 - printk ("Unable to allocate RBTX4925 NAND MTD device structure.\n"); 324 - err = -ENOMEM; 325 - goto out; 326 - } 327 - 328 - tx4925ndfmc_device_setup(); 329 - 330 - /* io is indirect via a register so don't need to ioremap address */ 331 - 332 - /* Get pointer to private data */ 333 - this = (struct nand_chip *) (&tx4925ndfmc_mtd[1]); 334 - 335 - /* Initialize structures */ 336 - memset((char *) tx4925ndfmc_mtd, 0, sizeof(struct mtd_info)); 337 - memset((char *) this, 0, sizeof(struct nand_chip)); 338 - 339 - /* Link the private data with the MTD structure */ 340 - tx4925ndfmc_mtd->priv = this; 341 - 342 - /* Set address of NAND IO lines */ 343 - this->IO_ADDR_R = (void __iomem *)&(tx4925_ndfmcptr->dtr); 344 - this->IO_ADDR_W = (void __iomem *)&(tx4925_ndfmcptr->dtr); 345 - this->hwcontrol = tx4925ndfmc_hwcontrol; 346 - this->enable_hwecc = tx4925ndfmc_enable_hwecc; 347 - this->calculate_ecc = tx4925ndfmc_readecc; 348 - this->correct_data = nand_correct_data; 349 - this->eccmode = NAND_ECC_HW6_512; 350 - this->dev_ready = tx4925ndfmc_device_ready; 351 - /* 20 us command delay time */ 352 - this->chip_delay = 20; 353 - this->read_byte = tx4925ndfmc_nand_read_byte; 354 - this->write_byte = tx4925ndfmc_nand_write_byte; 355 - this->cmdfunc = tx4925ndfmc_nand_command; 356 - this->write_buf = tx4925ndfmc_nand_write_buf; 357 - this->read_buf = tx4925ndfmc_nand_read_buf; 358 - this->verify_buf = tx4925ndfmc_nand_verify_buf; 359 - 360 - /* Scan to find existance of the device */ 361 - if (nand_scan (tx4925ndfmc_mtd, 1)) { 362 - err = -ENXIO; 363 - goto out_ior; 364 - } 365 - 366 - /* Register the partitions */ 367 - #ifdef CONFIG_MTD_CMDLINE_PARTS 368 - { 369 - int mtd_parts_nb = 0; 370 - struct mtd_partition *mtd_parts = 0; 371 - mtd_parts_nb = parse_cmdline_partitions(tx4925ndfmc_mtd, &mtd_parts, "tx4925ndfmc"); 372 - if (mtd_parts_nb > 0) 373 - add_mtd_partitions(tx4925ndfmc_mtd, mtd_parts, mtd_parts_nb); 374 - else 375 - add_mtd_device(tx4925ndfmc_mtd); 376 - } 377 - #else /* ifdef CONFIG_MTD_CMDLINE_PARTS */ 378 - switch(tx4925ndfmc_mtd->size){ 379 - case 0x01000000: add_mtd_partitions(tx4925ndfmc_mtd, partition_info16k, NUM_PARTITIONS16K); break; 380 - case 0x02000000: add_mtd_partitions(tx4925ndfmc_mtd, partition_info32k, NUM_PARTITIONS32K); break; 381 - case 0x04000000: add_mtd_partitions(tx4925ndfmc_mtd, partition_info64k, NUM_PARTITIONS64K); break; 382 - case 0x08000000: add_mtd_partitions(tx4925ndfmc_mtd, partition_info128k, NUM_PARTITIONS128K); break; 383 - default: { 384 - printk ("Unsupported SmartMedia device\n"); 385 - err = -ENXIO; 386 - goto out_ior; 387 - } 388 - } 389 - #endif /* ifdef CONFIG_MTD_CMDLINE_PARTS */ 390 - goto out; 391 - 392 - out_ior: 393 - out: 394 - return err; 395 - } 396 - 397 - module_init(tx4925ndfmc_init); 398 - 399 - /* 400 - * Clean up routine 401 - */ 402 - #ifdef MODULE 403 - static void __exit tx4925ndfmc_cleanup (void) 404 - { 405 - /* Release resources, unregister device */ 406 - nand_release (tx4925ndfmc_mtd); 407 - 408 - /* Free the MTD device structure */ 409 - kfree (tx4925ndfmc_mtd); 410 - } 411 - module_exit(tx4925ndfmc_cleanup); 412 - #endif 413 - 414 - MODULE_LICENSE("GPL"); 415 - MODULE_AUTHOR("Alice Hennessy <ahennessy@mvista.com>"); 416 - MODULE_DESCRIPTION("Glue layer for SmartMediaCard on Toshiba RBTX4925");
-406
drivers/mtd/nand/tx4938ndfmc.c
··· 1 - /* 2 - * drivers/mtd/nand/tx4938ndfmc.c 3 - * 4 - * Overview: 5 - * This is a device driver for the NAND flash device connected to 6 - * TX4938 internal NAND Memory Controller. 7 - * TX4938 NDFMC is almost same as TX4925 NDFMC, but register size are 64 bit. 8 - * 9 - * Author: source@mvista.com 10 - * 11 - * Based on spia.c by Steven J. Hill 12 - * 13 - * $Id: tx4938ndfmc.c,v 1.4 2004/10/05 13:50:20 gleixner Exp $ 14 - * 15 - * Copyright (C) 2000-2001 Toshiba Corporation 16 - * 17 - * 2003 (c) MontaVista Software, Inc. This file is licensed under the 18 - * terms of the GNU General Public License version 2. This program is 19 - * licensed "as is" without any warranty of any kind, whether express 20 - * or implied. 21 - */ 22 - #include <linux/config.h> 23 - #include <linux/slab.h> 24 - #include <linux/init.h> 25 - #include <linux/module.h> 26 - #include <linux/mtd/mtd.h> 27 - #include <linux/mtd/nand.h> 28 - #include <linux/mtd/nand_ecc.h> 29 - #include <linux/mtd/partitions.h> 30 - #include <asm/io.h> 31 - #include <asm/bootinfo.h> 32 - #include <linux/delay.h> 33 - #include <asm/tx4938/rbtx4938.h> 34 - 35 - extern struct nand_oobinfo jffs2_oobinfo; 36 - 37 - /* 38 - * MTD structure for TX4938 NDFMC 39 - */ 40 - static struct mtd_info *tx4938ndfmc_mtd; 41 - 42 - /* 43 - * Define partitions for flash device 44 - */ 45 - #define flush_wb() (void)tx4938_ndfmcptr->mcr; 46 - 47 - #define NUM_PARTITIONS 3 48 - #define NUMBER_OF_CIS_BLOCKS 24 49 - #define SIZE_OF_BLOCK 0x00004000 50 - #define NUMBER_OF_BLOCK_PER_ZONE 1024 51 - #define SIZE_OF_ZONE (NUMBER_OF_BLOCK_PER_ZONE * SIZE_OF_BLOCK) 52 - #ifndef CONFIG_MTD_CMDLINE_PARTS 53 - /* 54 - * You can use the following sample of MTD partitions 55 - * on the NAND Flash Memory 32MB or more. 56 - * 57 - * The following figure shows the image of the sample partition on 58 - * the 32MB NAND Flash Memory. 59 - * 60 - * Block No. 61 - * 0 +-----------------------------+ ------ 62 - * | CIS | ^ 63 - * 24 +-----------------------------+ | 64 - * | kernel image | | Zone 0 65 - * | | | 66 - * +-----------------------------+ | 67 - * 1023 | unused area | v 68 - * +-----------------------------+ ------ 69 - * 1024 | JFFS2 | ^ 70 - * | | | 71 - * | | | Zone 1 72 - * | | | 73 - * | | | 74 - * | | v 75 - * 2047 +-----------------------------+ ------ 76 - * 77 - */ 78 - static struct mtd_partition partition_info[NUM_PARTITIONS] = { 79 - { 80 - .name = "RBTX4938 CIS Area", 81 - .offset = 0, 82 - .size = (NUMBER_OF_CIS_BLOCKS * SIZE_OF_BLOCK), 83 - .mask_flags = MTD_WRITEABLE /* This partition is NOT writable */ 84 - }, 85 - { 86 - .name = "RBTX4938 kernel image", 87 - .offset = MTDPART_OFS_APPEND, 88 - .size = 8 * 0x00100000, /* 8MB (Depends on size of kernel image) */ 89 - .mask_flags = MTD_WRITEABLE /* This partition is NOT writable */ 90 - }, 91 - { 92 - .name = "Root FS (JFFS2)", 93 - .offset = (0 + SIZE_OF_ZONE), /* start address of next zone */ 94 - .size = MTDPART_SIZ_FULL 95 - }, 96 - }; 97 - #endif 98 - 99 - static void tx4938ndfmc_hwcontrol(struct mtd_info *mtd, int cmd) 100 - { 101 - switch (cmd) { 102 - case NAND_CTL_SETCLE: 103 - tx4938_ndfmcptr->mcr |= TX4938_NDFMCR_CLE; 104 - break; 105 - case NAND_CTL_CLRCLE: 106 - tx4938_ndfmcptr->mcr &= ~TX4938_NDFMCR_CLE; 107 - break; 108 - case NAND_CTL_SETALE: 109 - tx4938_ndfmcptr->mcr |= TX4938_NDFMCR_ALE; 110 - break; 111 - case NAND_CTL_CLRALE: 112 - tx4938_ndfmcptr->mcr &= ~TX4938_NDFMCR_ALE; 113 - break; 114 - /* TX4938_NDFMCR_CE bit is 0:high 1:low */ 115 - case NAND_CTL_SETNCE: 116 - tx4938_ndfmcptr->mcr |= TX4938_NDFMCR_CE; 117 - break; 118 - case NAND_CTL_CLRNCE: 119 - tx4938_ndfmcptr->mcr &= ~TX4938_NDFMCR_CE; 120 - break; 121 - case NAND_CTL_SETWP: 122 - tx4938_ndfmcptr->mcr |= TX4938_NDFMCR_WE; 123 - break; 124 - case NAND_CTL_CLRWP: 125 - tx4938_ndfmcptr->mcr &= ~TX4938_NDFMCR_WE; 126 - break; 127 - } 128 - } 129 - static int tx4938ndfmc_dev_ready(struct mtd_info *mtd) 130 - { 131 - flush_wb(); 132 - return !(tx4938_ndfmcptr->sr & TX4938_NDFSR_BUSY); 133 - } 134 - static void tx4938ndfmc_calculate_ecc(struct mtd_info *mtd, const u_char *dat, u_char *ecc_code) 135 - { 136 - u32 mcr = tx4938_ndfmcptr->mcr; 137 - mcr &= ~TX4938_NDFMCR_ECC_ALL; 138 - tx4938_ndfmcptr->mcr = mcr | TX4938_NDFMCR_ECC_OFF; 139 - tx4938_ndfmcptr->mcr = mcr | TX4938_NDFMCR_ECC_READ; 140 - ecc_code[1] = tx4938_ndfmcptr->dtr; 141 - ecc_code[0] = tx4938_ndfmcptr->dtr; 142 - ecc_code[2] = tx4938_ndfmcptr->dtr; 143 - tx4938_ndfmcptr->mcr = mcr | TX4938_NDFMCR_ECC_OFF; 144 - } 145 - static void tx4938ndfmc_enable_hwecc(struct mtd_info *mtd, int mode) 146 - { 147 - u32 mcr = tx4938_ndfmcptr->mcr; 148 - mcr &= ~TX4938_NDFMCR_ECC_ALL; 149 - tx4938_ndfmcptr->mcr = mcr | TX4938_NDFMCR_ECC_RESET; 150 - tx4938_ndfmcptr->mcr = mcr | TX4938_NDFMCR_ECC_OFF; 151 - tx4938_ndfmcptr->mcr = mcr | TX4938_NDFMCR_ECC_ON; 152 - } 153 - 154 - static u_char tx4938ndfmc_nand_read_byte(struct mtd_info *mtd) 155 - { 156 - struct nand_chip *this = mtd->priv; 157 - return tx4938_read_nfmc(this->IO_ADDR_R); 158 - } 159 - 160 - static void tx4938ndfmc_nand_write_byte(struct mtd_info *mtd, u_char byte) 161 - { 162 - struct nand_chip *this = mtd->priv; 163 - tx4938_write_nfmc(byte, this->IO_ADDR_W); 164 - } 165 - 166 - static void tx4938ndfmc_nand_write_buf(struct mtd_info *mtd, const u_char *buf, int len) 167 - { 168 - int i; 169 - struct nand_chip *this = mtd->priv; 170 - 171 - for (i=0; i<len; i++) 172 - tx4938_write_nfmc(buf[i], this->IO_ADDR_W); 173 - } 174 - 175 - static void tx4938ndfmc_nand_read_buf(struct mtd_info *mtd, u_char *buf, int len) 176 - { 177 - int i; 178 - struct nand_chip *this = mtd->priv; 179 - 180 - for (i=0; i<len; i++) 181 - buf[i] = tx4938_read_nfmc(this->IO_ADDR_R); 182 - } 183 - 184 - static int tx4938ndfmc_nand_verify_buf(struct mtd_info *mtd, const u_char *buf, int len) 185 - { 186 - int i; 187 - struct nand_chip *this = mtd->priv; 188 - 189 - for (i=0; i<len; i++) 190 - if (buf[i] != tx4938_read_nfmc(this->IO_ADDR_R)) 191 - return -EFAULT; 192 - 193 - return 0; 194 - } 195 - 196 - /* 197 - * Send command to NAND device 198 - */ 199 - static void tx4938ndfmc_nand_command (struct mtd_info *mtd, unsigned command, int column, int page_addr) 200 - { 201 - register struct nand_chip *this = mtd->priv; 202 - 203 - /* Begin command latch cycle */ 204 - this->hwcontrol(mtd, NAND_CTL_SETCLE); 205 - /* 206 - * Write out the command to the device. 207 - */ 208 - if (command == NAND_CMD_SEQIN) { 209 - int readcmd; 210 - 211 - if (column >= mtd->oobblock) { 212 - /* OOB area */ 213 - column -= mtd->oobblock; 214 - readcmd = NAND_CMD_READOOB; 215 - } else if (column < 256) { 216 - /* First 256 bytes --> READ0 */ 217 - readcmd = NAND_CMD_READ0; 218 - } else { 219 - column -= 256; 220 - readcmd = NAND_CMD_READ1; 221 - } 222 - this->write_byte(mtd, readcmd); 223 - } 224 - this->write_byte(mtd, command); 225 - 226 - /* Set ALE and clear CLE to start address cycle */ 227 - this->hwcontrol(mtd, NAND_CTL_CLRCLE); 228 - 229 - if (column != -1 || page_addr != -1) { 230 - this->hwcontrol(mtd, NAND_CTL_SETALE); 231 - 232 - /* Serially input address */ 233 - if (column != -1) 234 - this->write_byte(mtd, column); 235 - if (page_addr != -1) { 236 - this->write_byte(mtd, (unsigned char) (page_addr & 0xff)); 237 - this->write_byte(mtd, (unsigned char) ((page_addr >> 8) & 0xff)); 238 - /* One more address cycle for higher density devices */ 239 - if (mtd->size & 0x0c000000) 240 - this->write_byte(mtd, (unsigned char) ((page_addr >> 16) & 0x0f)); 241 - } 242 - /* Latch in address */ 243 - this->hwcontrol(mtd, NAND_CTL_CLRALE); 244 - } 245 - 246 - /* 247 - * program and erase have their own busy handlers 248 - * status and sequential in needs no delay 249 - */ 250 - switch (command) { 251 - 252 - case NAND_CMD_PAGEPROG: 253 - /* Turn off WE */ 254 - this->hwcontrol (mtd, NAND_CTL_CLRWP); 255 - return; 256 - 257 - case NAND_CMD_SEQIN: 258 - /* Turn on WE */ 259 - this->hwcontrol (mtd, NAND_CTL_SETWP); 260 - return; 261 - 262 - case NAND_CMD_ERASE1: 263 - case NAND_CMD_ERASE2: 264 - case NAND_CMD_STATUS: 265 - return; 266 - 267 - case NAND_CMD_RESET: 268 - if (this->dev_ready) 269 - break; 270 - this->hwcontrol(mtd, NAND_CTL_SETCLE); 271 - this->write_byte(mtd, NAND_CMD_STATUS); 272 - this->hwcontrol(mtd, NAND_CTL_CLRCLE); 273 - while ( !(this->read_byte(mtd) & 0x40)); 274 - return; 275 - 276 - /* This applies to read commands */ 277 - default: 278 - /* 279 - * If we don't have access to the busy pin, we apply the given 280 - * command delay 281 - */ 282 - if (!this->dev_ready) { 283 - udelay (this->chip_delay); 284 - return; 285 - } 286 - } 287 - 288 - /* wait until command is processed */ 289 - while (!this->dev_ready(mtd)); 290 - } 291 - 292 - #ifdef CONFIG_MTD_CMDLINE_PARTS 293 - extern int parse_cmdline_partitions(struct mtd_info *master, struct mtd_partition **pparts, char *); 294 - #endif 295 - /* 296 - * Main initialization routine 297 - */ 298 - int __init tx4938ndfmc_init (void) 299 - { 300 - struct nand_chip *this; 301 - int bsprt = 0, hold = 0xf, spw = 0xf; 302 - int protected = 0; 303 - 304 - if ((*rbtx4938_piosel_ptr & 0x0c) != 0x08) { 305 - printk("TX4938 NDFMC: disabled by IOC PIOSEL\n"); 306 - return -ENODEV; 307 - } 308 - bsprt = 1; 309 - hold = 2; 310 - spw = 9 - 1; /* 8 GBUSCLK = 80ns (@ GBUSCLK 100MHz) */ 311 - 312 - if ((tx4938_ccfgptr->pcfg & 313 - (TX4938_PCFG_ATA_SEL|TX4938_PCFG_ISA_SEL|TX4938_PCFG_NDF_SEL)) 314 - != TX4938_PCFG_NDF_SEL) { 315 - printk("TX4938 NDFMC: disabled by PCFG.\n"); 316 - return -ENODEV; 317 - } 318 - 319 - /* reset NDFMC */ 320 - tx4938_ndfmcptr->rstr |= TX4938_NDFRSTR_RST; 321 - while (tx4938_ndfmcptr->rstr & TX4938_NDFRSTR_RST) 322 - ; 323 - /* setup BusSeparete, Hold Time, Strobe Pulse Width */ 324 - tx4938_ndfmcptr->mcr = bsprt ? TX4938_NDFMCR_BSPRT : 0; 325 - tx4938_ndfmcptr->spr = hold << 4 | spw; 326 - 327 - /* Allocate memory for MTD device structure and private data */ 328 - tx4938ndfmc_mtd = kmalloc (sizeof(struct mtd_info) + sizeof (struct nand_chip), 329 - GFP_KERNEL); 330 - if (!tx4938ndfmc_mtd) { 331 - printk ("Unable to allocate TX4938 NDFMC MTD device structure.\n"); 332 - return -ENOMEM; 333 - } 334 - 335 - /* Get pointer to private data */ 336 - this = (struct nand_chip *) (&tx4938ndfmc_mtd[1]); 337 - 338 - /* Initialize structures */ 339 - memset((char *) tx4938ndfmc_mtd, 0, sizeof(struct mtd_info)); 340 - memset((char *) this, 0, sizeof(struct nand_chip)); 341 - 342 - /* Link the private data with the MTD structure */ 343 - tx4938ndfmc_mtd->priv = this; 344 - 345 - /* Set address of NAND IO lines */ 346 - this->IO_ADDR_R = (unsigned long)&tx4938_ndfmcptr->dtr; 347 - this->IO_ADDR_W = (unsigned long)&tx4938_ndfmcptr->dtr; 348 - this->hwcontrol = tx4938ndfmc_hwcontrol; 349 - this->dev_ready = tx4938ndfmc_dev_ready; 350 - this->calculate_ecc = tx4938ndfmc_calculate_ecc; 351 - this->correct_data = nand_correct_data; 352 - this->enable_hwecc = tx4938ndfmc_enable_hwecc; 353 - this->eccmode = NAND_ECC_HW3_256; 354 - this->chip_delay = 100; 355 - this->read_byte = tx4938ndfmc_nand_read_byte; 356 - this->write_byte = tx4938ndfmc_nand_write_byte; 357 - this->cmdfunc = tx4938ndfmc_nand_command; 358 - this->write_buf = tx4938ndfmc_nand_write_buf; 359 - this->read_buf = tx4938ndfmc_nand_read_buf; 360 - this->verify_buf = tx4938ndfmc_nand_verify_buf; 361 - 362 - /* Scan to find existance of the device */ 363 - if (nand_scan (tx4938ndfmc_mtd, 1)) { 364 - kfree (tx4938ndfmc_mtd); 365 - return -ENXIO; 366 - } 367 - 368 - if (protected) { 369 - printk(KERN_INFO "TX4938 NDFMC: write protected.\n"); 370 - tx4938ndfmc_mtd->flags &= ~(MTD_WRITEABLE | MTD_ERASEABLE); 371 - } 372 - 373 - #ifdef CONFIG_MTD_CMDLINE_PARTS 374 - { 375 - int mtd_parts_nb = 0; 376 - struct mtd_partition *mtd_parts = 0; 377 - mtd_parts_nb = parse_cmdline_partitions(tx4938ndfmc_mtd, &mtd_parts, "tx4938ndfmc"); 378 - if (mtd_parts_nb > 0) 379 - add_mtd_partitions(tx4938ndfmc_mtd, mtd_parts, mtd_parts_nb); 380 - else 381 - add_mtd_device(tx4938ndfmc_mtd); 382 - } 383 - #else 384 - add_mtd_partitions(tx4938ndfmc_mtd, partition_info, NUM_PARTITIONS ); 385 - #endif 386 - 387 - return 0; 388 - } 389 - module_init(tx4938ndfmc_init); 390 - 391 - /* 392 - * Clean up routine 393 - */ 394 - static void __exit tx4938ndfmc_cleanup (void) 395 - { 396 - /* Release resources, unregister device */ 397 - nand_release (tx4938ndfmc_mtd); 398 - 399 - /* Free the MTD device structure */ 400 - kfree (tx4938ndfmc_mtd); 401 - } 402 - module_exit(tx4938ndfmc_cleanup); 403 - 404 - MODULE_LICENSE("GPL"); 405 - MODULE_AUTHOR("Alice Hennessy <ahennessy@mvista.com>"); 406 - MODULE_DESCRIPTION("Board-specific glue layer for NAND flash on TX4938 NDFMC");
+9 -17
fs/Kconfig
··· 1039 1039 If reporting bugs, please try to have available a full dump of the 1040 1040 messages at debug level 1 while the misbehaviour was occurring. 1041 1041 1042 - config JFFS2_FS_NAND 1043 - bool "JFFS2 support for NAND flash" 1042 + config JFFS2_FS_WRITEBUFFER 1043 + bool "JFFS2 write-buffering support" 1044 1044 depends on JFFS2_FS 1045 - default n 1045 + default y 1046 1046 help 1047 - This enables the support for NAND flash in JFFS2. NAND is a newer 1048 - type of flash chip design than the traditional NOR flash, with 1049 - higher density but a handful of characteristics which make it more 1050 - interesting for the file system to use. 1047 + This enables the write-buffering support in JFFS2. 1051 1048 1052 - Say 'N' unless you have NAND flash. 1053 - 1054 - config JFFS2_FS_NOR_ECC 1055 - bool "JFFS2 support for ECC'd NOR flash (EXPERIMENTAL)" 1056 - depends on JFFS2_FS && EXPERIMENTAL 1057 - default n 1058 - help 1059 - This enables the experimental support for NOR flash with transparent 1060 - ECC for JFFS2. This type of flash chip is not common, however it is 1061 - available from ST Microelectronics. 1049 + This functionality is required to support JFFS2 on the following 1050 + types of flash devices: 1051 + - NAND flash 1052 + - NOR flash with transparent ECC 1053 + - DataFlash 1062 1054 1063 1055 config JFFS2_COMPRESSION_OPTIONS 1064 1056 bool "Advanced compression options for JFFS2"
+2 -3
fs/jffs2/Makefile
··· 1 1 # 2 2 # Makefile for the Linux Journalling Flash File System v2 (JFFS2) 3 3 # 4 - # $Id: Makefile.common,v 1.7 2004/11/03 12:57:38 jwboyer Exp $ 4 + # $Id: Makefile.common,v 1.9 2005/02/09 09:23:53 pavlov Exp $ 5 5 # 6 6 7 7 obj-$(CONFIG_JFFS2_FS) += jffs2.o ··· 11 11 jffs2-y += symlink.o build.o erase.o background.o fs.o writev.o 12 12 jffs2-y += super.o 13 13 14 - jffs2-$(CONFIG_JFFS2_FS_NAND) += wbuf.o 15 - jffs2-$(CONFIG_JFFS2_FS_NOR_ECC) += wbuf.o 14 + jffs2-$(CONFIG_JFFS2_FS_WRITEBUFFER) += wbuf.o 16 15 jffs2-$(CONFIG_JFFS2_RUBIN) += compr_rubin.o 17 16 jffs2-$(CONFIG_JFFS2_RTIME) += compr_rtime.o 18 17 jffs2-$(CONFIG_JFFS2_ZLIB) += compr_zlib.o
+5 -1
fs/jffs2/README.Locking
··· 1 - $Id: README.Locking,v 1.9 2004/11/20 10:35:40 dwmw2 Exp $ 1 + $Id: README.Locking,v 1.12 2005/04/13 13:22:35 dwmw2 Exp $ 2 2 3 3 JFFS2 LOCKING DOCUMENTATION 4 4 --------------------------- ··· 107 107 in-core jffs2_inode_cache objects (each inode in JFFS2 has the 108 108 correspondent jffs2_inode_cache object). So, the inocache_lock 109 109 has to be locked while walking the c->inocache_list hash buckets. 110 + 111 + This spinlock also covers allocation of new inode numbers, which is 112 + currently just '++->highest_ino++', but might one day get more complicated 113 + if we need to deal with wrapping after 4 milliard inode numbers are used. 110 114 111 115 Note, the f->sem guarantees that the correspondent jffs2_inode_cache 112 116 will not be removed. So, it is allowed to access it without locking
+8 -5
fs/jffs2/background.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: background.c,v 1.50 2004/11/16 20:36:10 dwmw2 Exp $ 10 + * $Id: background.c,v 1.54 2005/05/20 21:37:12 gleixner Exp $ 11 11 * 12 12 */ 13 13 ··· 37 37 if (c->gc_task) 38 38 BUG(); 39 39 40 - init_MUTEX_LOCKED(&c->gc_thread_start); 40 + init_completion(&c->gc_thread_start); 41 41 init_completion(&c->gc_thread_exit); 42 42 43 43 pid = kernel_thread(jffs2_garbage_collect_thread, c, CLONE_FS|CLONE_FILES); ··· 48 48 } else { 49 49 /* Wait for it... */ 50 50 D1(printk(KERN_DEBUG "JFFS2: Garbage collect thread is pid %d\n", pid)); 51 - down(&c->gc_thread_start); 51 + wait_for_completion(&c->gc_thread_start); 52 52 } 53 53 54 54 return ret; ··· 56 56 57 57 void jffs2_stop_garbage_collect_thread(struct jffs2_sb_info *c) 58 58 { 59 + int wait = 0; 59 60 spin_lock(&c->erase_completion_lock); 60 61 if (c->gc_task) { 61 62 D1(printk(KERN_DEBUG "jffs2: Killing GC task %d\n", c->gc_task->pid)); 62 63 send_sig(SIGKILL, c->gc_task, 1); 64 + wait = 1; 63 65 } 64 66 spin_unlock(&c->erase_completion_lock); 65 - wait_for_completion(&c->gc_thread_exit); 67 + if (wait) 68 + wait_for_completion(&c->gc_thread_exit); 66 69 } 67 70 68 71 static int jffs2_garbage_collect_thread(void *_c) ··· 78 75 allow_signal(SIGCONT); 79 76 80 77 c->gc_task = current; 81 - up(&c->gc_thread_start); 78 + complete(&c->gc_thread_start); 82 79 83 80 set_user_nice(current, 10); 84 81
+6 -3
fs/jffs2/build.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: build.c,v 1.69 2004/12/16 20:22:18 dmarlin Exp $ 10 + * $Id: build.c,v 1.70 2005/02/28 08:21:05 dedekind Exp $ 11 11 * 12 12 */ 13 13 ··· 97 97 /* First, scan the medium and build all the inode caches with 98 98 lists of physical nodes */ 99 99 100 - c->flags |= JFFS2_SB_FLAG_MOUNTING; 100 + c->flags |= JFFS2_SB_FLAG_SCANNING; 101 101 ret = jffs2_scan_medium(c); 102 + c->flags &= ~JFFS2_SB_FLAG_SCANNING; 102 103 if (ret) 103 104 goto exit; 104 105 105 106 D1(printk(KERN_DEBUG "Scanned flash completely\n")); 106 107 D2(jffs2_dump_block_lists(c)); 107 108 109 + c->flags |= JFFS2_SB_FLAG_BUILDING; 108 110 /* Now scan the directory tree, increasing nlink according to every dirent found. */ 109 111 for_each_inode(i, c, ic) { 110 112 D1(printk(KERN_DEBUG "Pass 1: ino #%u\n", ic->ino)); ··· 118 116 cond_resched(); 119 117 } 120 118 } 121 - c->flags &= ~JFFS2_SB_FLAG_MOUNTING; 122 119 123 120 D1(printk(KERN_DEBUG "Pass 1 complete\n")); 124 121 ··· 165 164 ic->scan_dents = NULL; 166 165 cond_resched(); 167 166 } 167 + c->flags &= ~JFFS2_SB_FLAG_BUILDING; 168 + 168 169 D1(printk(KERN_DEBUG "Pass 3 complete\n")); 169 170 D2(jffs2_dump_block_lists(c)); 170 171
+2 -2
fs/jffs2/compr_zlib.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: compr_zlib.c,v 1.29 2004/11/16 20:36:11 dwmw2 Exp $ 10 + * $Id: compr_zlib.c,v 1.31 2005/05/20 19:30:06 gleixner Exp $ 11 11 * 12 12 */ 13 13 ··· 17 17 18 18 #include <linux/config.h> 19 19 #include <linux/kernel.h> 20 + #include <linux/sched.h> 20 21 #include <linux/slab.h> 21 22 #include <linux/zlib.h> 22 23 #include <linux/zutil.h> 23 - #include <asm/semaphore.h> 24 24 #include "nodelist.h" 25 25 #include "compr.h" 26 26
+25 -21
fs/jffs2/dir.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: dir.c,v 1.84 2004/11/16 20:36:11 dwmw2 Exp $ 10 + * $Id: dir.c,v 1.86 2005/07/06 12:13:09 dwmw2 Exp $ 11 11 * 12 12 */ 13 13 ··· 22 22 #include <linux/time.h> 23 23 #include "nodelist.h" 24 24 25 - /* Urgh. Please tell me there's a nicer way of doing these. */ 26 - #include <linux/version.h> 27 - #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,48) 28 - typedef int mknod_arg_t; 29 - #define NAMEI_COMPAT(x) ((void *)x) 30 - #else 31 - typedef dev_t mknod_arg_t; 32 - #define NAMEI_COMPAT(x) (x) 33 - #endif 34 - 35 25 static int jffs2_readdir (struct file *, void *, filldir_t); 36 26 37 27 static int jffs2_create (struct inode *,struct dentry *,int, ··· 33 43 static int jffs2_symlink (struct inode *,struct dentry *,const char *); 34 44 static int jffs2_mkdir (struct inode *,struct dentry *,int); 35 45 static int jffs2_rmdir (struct inode *,struct dentry *); 36 - static int jffs2_mknod (struct inode *,struct dentry *,int,mknod_arg_t); 46 + static int jffs2_mknod (struct inode *,struct dentry *,int,dev_t); 37 47 static int jffs2_rename (struct inode *, struct dentry *, 38 48 struct inode *, struct dentry *); 39 49 ··· 48 58 49 59 struct inode_operations jffs2_dir_inode_operations = 50 60 { 51 - .create = NAMEI_COMPAT(jffs2_create), 52 - .lookup = NAMEI_COMPAT(jffs2_lookup), 61 + .create = jffs2_create, 62 + .lookup = jffs2_lookup, 53 63 .link = jffs2_link, 54 64 .unlink = jffs2_unlink, 55 65 .symlink = jffs2_symlink, ··· 286 296 struct jffs2_full_dirent *fd; 287 297 int namelen; 288 298 uint32_t alloclen, phys_ofs; 289 - int ret; 299 + int ret, targetlen = strlen(target); 290 300 291 301 /* FIXME: If you care. We'd need to use frags for the target 292 302 if it grows much more than this */ 293 - if (strlen(target) > 254) 303 + if (targetlen > 254) 294 304 return -EINVAL; 295 305 296 306 ri = jffs2_alloc_raw_inode(); ··· 304 314 * Just the node will do for now, though 305 315 */ 306 316 namelen = dentry->d_name.len; 307 - ret = jffs2_reserve_space(c, sizeof(*ri) + strlen(target), &phys_ofs, &alloclen, ALLOC_NORMAL); 317 + ret = jffs2_reserve_space(c, sizeof(*ri) + targetlen, &phys_ofs, &alloclen, ALLOC_NORMAL); 308 318 309 319 if (ret) { 310 320 jffs2_free_raw_inode(ri); ··· 323 333 324 334 f = JFFS2_INODE_INFO(inode); 325 335 326 - inode->i_size = strlen(target); 336 + inode->i_size = targetlen; 327 337 ri->isize = ri->dsize = ri->csize = cpu_to_je32(inode->i_size); 328 338 ri->totlen = cpu_to_je32(sizeof(*ri) + inode->i_size); 329 339 ri->hdr_crc = cpu_to_je32(crc32(0, ri, sizeof(struct jffs2_unknown_node)-4)); 330 340 331 341 ri->compr = JFFS2_COMPR_NONE; 332 - ri->data_crc = cpu_to_je32(crc32(0, target, strlen(target))); 342 + ri->data_crc = cpu_to_je32(crc32(0, target, targetlen)); 333 343 ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 334 344 335 - fn = jffs2_write_dnode(c, f, ri, target, strlen(target), phys_ofs, ALLOC_NORMAL); 345 + fn = jffs2_write_dnode(c, f, ri, target, targetlen, phys_ofs, ALLOC_NORMAL); 336 346 337 347 jffs2_free_raw_inode(ri); 338 348 ··· 343 353 jffs2_clear_inode(inode); 344 354 return PTR_ERR(fn); 345 355 } 356 + 357 + /* We use f->dents field to store the target path. */ 358 + f->dents = kmalloc(targetlen + 1, GFP_KERNEL); 359 + if (!f->dents) { 360 + printk(KERN_WARNING "Can't allocate %d bytes of memory\n", targetlen + 1); 361 + up(&f->sem); 362 + jffs2_complete_reservation(c); 363 + jffs2_clear_inode(inode); 364 + return -ENOMEM; 365 + } 366 + 367 + memcpy(f->dents, target, targetlen + 1); 368 + D1(printk(KERN_DEBUG "jffs2_symlink: symlink's target '%s' cached\n", (char *)f->dents)); 369 + 346 370 /* No data here. Only a metadata node, which will be 347 371 obsoleted by the first data write 348 372 */ ··· 568 564 return ret; 569 565 } 570 566 571 - static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, mknod_arg_t rdev) 567 + static int jffs2_mknod (struct inode *dir_i, struct dentry *dentry, int mode, dev_t rdev) 572 568 { 573 569 struct jffs2_inode_info *f, *dir_f; 574 570 struct jffs2_sb_info *c;
+15 -9
fs/jffs2/erase.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: erase.c,v 1.66 2004/11/16 20:36:11 dwmw2 Exp $ 10 + * $Id: erase.c,v 1.76 2005/05/03 15:11:40 dedekind Exp $ 11 11 * 12 12 */ 13 13 ··· 48 48 #else /* Linux */ 49 49 struct erase_info *instr; 50 50 51 + D1(printk(KERN_DEBUG "jffs2_erase_block(): erase block %#x (range %#x-%#x)\n", jeb->offset, jeb->offset, jeb->offset + c->sector_size)); 51 52 instr = kmalloc(sizeof(struct erase_info) + sizeof(struct erase_priv_struct), GFP_KERNEL); 52 53 if (!instr) { 53 54 printk(KERN_WARNING "kmalloc for struct erase_info in jffs2_erase_block failed. Refiling block for later\n"); ··· 234 233 continue; 235 234 } 236 235 237 - if (((*prev)->flash_offset & ~(c->sector_size -1)) == jeb->offset) { 236 + if (SECTOR_ADDR((*prev)->flash_offset) == jeb->offset) { 238 237 /* It's in the block we're erasing */ 239 238 struct jffs2_raw_node_ref *this; 240 239 ··· 278 277 printk("\n"); 279 278 }); 280 279 281 - if (ic->nodes == (void *)ic) { 282 - D1(printk(KERN_DEBUG "inocache for ino #%u is all gone now. Freeing\n", ic->ino)); 280 + if (ic->nodes == (void *)ic && ic->nlink == 0) 283 281 jffs2_del_ino_cache(c, ic); 284 - jffs2_free_inode_cache(ic); 285 - } 286 282 } 287 283 288 284 static void jffs2_free_all_node_refs(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) ··· 308 310 int ret; 309 311 uint32_t bad_offset; 310 312 311 - if (!jffs2_cleanmarker_oob(c)) { 313 + if ((!jffs2_cleanmarker_oob(c)) && (c->cleanmarker_size > 0)) { 312 314 marker_ref = jffs2_alloc_raw_node_ref(); 313 315 if (!marker_ref) { 314 316 printk(KERN_WARNING "Failed to allocate raw node ref for clean marker\n"); ··· 333 335 334 336 bad_offset = ofs; 335 337 336 - ret = jffs2_flash_read(c, ofs, readlen, &retlen, ebuf); 338 + ret = c->mtd->read(c->mtd, ofs, readlen, &retlen, ebuf); 339 + 337 340 if (ret) { 338 341 printk(KERN_WARNING "Read of newly-erased block at 0x%08x failed: %d. Putting on bad_list\n", ofs, ret); 339 342 goto bad; ··· 350 351 bad_offset += i; 351 352 printk(KERN_WARNING "Newly-erased block contained word 0x%lx at offset 0x%08x\n", datum, bad_offset); 352 353 bad: 353 - if (!jffs2_cleanmarker_oob(c)) 354 + if ((!jffs2_cleanmarker_oob(c)) && (c->cleanmarker_size > 0)) 354 355 jffs2_free_raw_node_ref(marker_ref); 355 356 kfree(ebuf); 356 357 bad2: ··· 380 381 if (jffs2_write_nand_cleanmarker(c, jeb)) 381 382 goto bad2; 382 383 384 + jeb->first_node = jeb->last_node = NULL; 385 + 386 + jeb->free_size = c->sector_size; 387 + jeb->used_size = 0; 388 + jeb->dirty_size = 0; 389 + jeb->wasted_size = 0; 390 + } else if (c->cleanmarker_size == 0) { 383 391 jeb->first_node = jeb->last_node = NULL; 384 392 385 393 jeb->free_size = c->sector_size;
+1 -4
fs/jffs2/file.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: file.c,v 1.99 2004/11/16 20:36:11 dwmw2 Exp $ 10 + * $Id: file.c,v 1.102 2005/07/06 12:13:09 dwmw2 Exp $ 11 11 * 12 12 */ 13 13 14 - #include <linux/version.h> 15 14 #include <linux/kernel.h> 16 15 #include <linux/slab.h> 17 16 #include <linux/fs.h> ··· 50 51 .ioctl = jffs2_ioctl, 51 52 .mmap = generic_file_readonly_mmap, 52 53 .fsync = jffs2_fsync, 53 - #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,29) 54 54 .sendfile = generic_file_sendfile 55 - #endif 56 55 }; 57 56 58 57 /* jffs2_file_inode_operations */
+19 -5
fs/jffs2/fs.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: fs.c,v 1.51 2004/11/28 12:19:37 dedekind Exp $ 10 + * $Id: fs.c,v 1.56 2005/07/06 12:13:09 dwmw2 Exp $ 11 11 * 12 12 */ 13 13 14 - #include <linux/version.h> 15 14 #include <linux/config.h> 16 15 #include <linux/kernel.h> 17 16 #include <linux/sched.h> ··· 449 450 450 451 c = JFFS2_SB_INFO(sb); 451 452 452 - #ifndef CONFIG_JFFS2_FS_NAND 453 + #ifndef CONFIG_JFFS2_FS_WRITEBUFFER 453 454 if (c->mtd->type == MTD_NANDFLASH) { 454 455 printk(KERN_ERR "jffs2: Cannot operate on NAND flash unless jffs2 NAND support is compiled in.\n"); 456 + return -EINVAL; 457 + } 458 + if (c->mtd->type == MTD_DATAFLASH) { 459 + printk(KERN_ERR "jffs2: Cannot operate on DataFlash unless jffs2 DataFlash support is compiled in.\n"); 455 460 return -EINVAL; 456 461 } 457 462 #endif ··· 525 522 if (!sb->s_root) 526 523 goto out_root_i; 527 524 528 - #if LINUX_VERSION_CODE >= 0x20403 529 525 sb->s_maxbytes = 0xFFFFFFFF; 530 - #endif 531 526 sb->s_blocksize = PAGE_CACHE_SIZE; 532 527 sb->s_blocksize_bits = PAGE_CACHE_SHIFT; 533 528 sb->s_magic = JFFS2_SUPER_MAGIC; ··· 662 661 if (ret) 663 662 return ret; 664 663 } 664 + 665 + /* and Dataflash */ 666 + if (jffs2_dataflash(c)) { 667 + ret = jffs2_dataflash_setup(c); 668 + if (ret) 669 + return ret; 670 + } 671 + 665 672 return ret; 666 673 } 667 674 ··· 682 673 /* add cleanups for other bizarre flashes here... */ 683 674 if (jffs2_nor_ecc(c)) { 684 675 jffs2_nor_ecc_flash_cleanup(c); 676 + } 677 + 678 + /* and DataFlash */ 679 + if (jffs2_dataflash(c)) { 680 + jffs2_dataflash_cleanup(c); 685 681 } 686 682 }
+33 -8
fs/jffs2/gc.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: gc.c,v 1.144 2004/12/21 11:18:50 dwmw2 Exp $ 10 + * $Id: gc.c,v 1.148 2005/04/09 10:47:00 dedekind Exp $ 11 11 * 12 12 */ 13 13 ··· 50 50 put the clever wear-levelling algorithms. Eventually. */ 51 51 /* We possibly want to favour the dirtier blocks more when the 52 52 number of free blocks is low. */ 53 + again: 53 54 if (!list_empty(&c->bad_used_list) && c->nr_free_blocks > c->resv_blocks_gcbad) { 54 55 D1(printk(KERN_DEBUG "Picking block from bad_used_list to GC next\n")); 55 56 nextlist = &c->bad_used_list; ··· 80 79 D1(printk(KERN_DEBUG "Picking block from erasable_list to GC next (clean_list and {very_,}dirty_list were empty)\n")); 81 80 82 81 nextlist = &c->erasable_list; 82 + } else if (!list_empty(&c->erasable_pending_wbuf_list)) { 83 + /* There are blocks are wating for the wbuf sync */ 84 + D1(printk(KERN_DEBUG "Synching wbuf in order to reuse erasable_pending_wbuf_list blocks\n")); 85 + spin_unlock(&c->erase_completion_lock); 86 + jffs2_flush_wbuf_pad(c); 87 + spin_lock(&c->erase_completion_lock); 88 + goto again; 83 89 } else { 84 90 /* Eep. All were empty */ 85 91 D1(printk(KERN_NOTICE "jffs2: No clean, dirty _or_ erasable blocks to GC from! Where are they all?\n")); ··· 669 661 { 670 662 struct jffs2_full_dnode *new_fn; 671 663 struct jffs2_raw_inode ri; 664 + struct jffs2_node_frag *last_frag; 672 665 jint16_t dev; 673 666 char *mdata = NULL, mdatalen = 0; 674 - uint32_t alloclen, phys_ofs; 667 + uint32_t alloclen, phys_ofs, ilen; 675 668 int ret; 676 669 677 670 if (S_ISBLK(JFFS2_F_I_MODE(f)) || ··· 708 699 goto out; 709 700 } 710 701 702 + last_frag = frag_last(&f->fragtree); 703 + if (last_frag) 704 + /* Fetch the inode length from the fragtree rather then 705 + * from i_size since i_size may have not been updated yet */ 706 + ilen = last_frag->ofs + last_frag->size; 707 + else 708 + ilen = JFFS2_F_I_SIZE(f); 709 + 711 710 memset(&ri, 0, sizeof(ri)); 712 711 ri.magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 713 712 ri.nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE); ··· 727 710 ri.mode = cpu_to_jemode(JFFS2_F_I_MODE(f)); 728 711 ri.uid = cpu_to_je16(JFFS2_F_I_UID(f)); 729 712 ri.gid = cpu_to_je16(JFFS2_F_I_GID(f)); 730 - ri.isize = cpu_to_je32(JFFS2_F_I_SIZE(f)); 713 + ri.isize = cpu_to_je32(ilen); 731 714 ri.atime = cpu_to_je32(JFFS2_F_I_ATIME(f)); 732 715 ri.ctime = cpu_to_je32(JFFS2_F_I_CTIME(f)); 733 716 ri.mtime = cpu_to_je32(JFFS2_F_I_MTIME(f)); ··· 833 816 834 817 /* Doesn't matter if there's one in the same erase block. We're going to 835 818 delete it too at the same time. */ 836 - if ((raw->flash_offset & ~(c->sector_size-1)) == 837 - (fd->raw->flash_offset & ~(c->sector_size-1))) 819 + if (SECTOR_ADDR(raw->flash_offset) == SECTOR_ADDR(fd->raw->flash_offset)) 838 820 continue; 839 821 840 822 D1(printk(KERN_DEBUG "Check potential deletion dirent at %08x\n", ref_offset(raw))); ··· 907 891 struct jffs2_raw_inode ri; 908 892 struct jffs2_node_frag *frag; 909 893 struct jffs2_full_dnode *new_fn; 910 - uint32_t alloclen, phys_ofs; 894 + uint32_t alloclen, phys_ofs, ilen; 911 895 int ret; 912 896 913 897 D1(printk(KERN_DEBUG "Writing replacement hole node for ino #%u from offset 0x%x to 0x%x\n", ··· 967 951 ri.csize = cpu_to_je32(0); 968 952 ri.compr = JFFS2_COMPR_ZERO; 969 953 } 954 + 955 + frag = frag_last(&f->fragtree); 956 + if (frag) 957 + /* Fetch the inode length from the fragtree rather then 958 + * from i_size since i_size may have not been updated yet */ 959 + ilen = frag->ofs + frag->size; 960 + else 961 + ilen = JFFS2_F_I_SIZE(f); 962 + 970 963 ri.mode = cpu_to_jemode(JFFS2_F_I_MODE(f)); 971 964 ri.uid = cpu_to_je16(JFFS2_F_I_UID(f)); 972 965 ri.gid = cpu_to_je16(JFFS2_F_I_GID(f)); 973 - ri.isize = cpu_to_je32(JFFS2_F_I_SIZE(f)); 966 + ri.isize = cpu_to_je32(ilen); 974 967 ri.atime = cpu_to_je32(JFFS2_F_I_ATIME(f)); 975 968 ri.ctime = cpu_to_je32(JFFS2_F_I_CTIME(f)); 976 969 ri.mtime = cpu_to_je32(JFFS2_F_I_MTIME(f)); ··· 1186 1161 D1(printk(KERN_DEBUG "Expanded dnode to write from (0x%x-0x%x) to (0x%x-0x%x)\n", 1187 1162 orig_start, orig_end, start, end)); 1188 1163 1189 - BUG_ON(end > JFFS2_F_I_SIZE(f)); 1164 + D1(BUG_ON(end > frag_last(&f->fragtree)->ofs + frag_last(&f->fragtree)->size)); 1190 1165 BUG_ON(end < orig_end); 1191 1166 BUG_ON(start > orig_start); 1192 1167 }
+69 -24
fs/jffs2/nodelist.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: nodelist.c,v 1.90 2004/12/08 17:59:20 dwmw2 Exp $ 10 + * $Id: nodelist.c,v 1.97 2005/07/06 15:18:41 dwmw2 Exp $ 11 11 * 12 12 */ 13 13 ··· 58 58 /* Put a new tmp_dnode_info into the list, keeping the list in 59 59 order of increasing version 60 60 */ 61 - static void jffs2_add_tn_to_list(struct jffs2_tmp_dnode_info *tn, struct jffs2_tmp_dnode_info **list) 61 + 62 + static void jffs2_add_tn_to_list(struct jffs2_tmp_dnode_info *tn, struct rb_root *list) 62 63 { 63 - struct jffs2_tmp_dnode_info **prev = list; 64 - 65 - while ((*prev) && (*prev)->version < tn->version) { 66 - prev = &((*prev)->next); 67 - } 68 - tn->next = (*prev); 69 - *prev = tn; 64 + struct rb_node **p = &list->rb_node; 65 + struct rb_node * parent = NULL; 66 + struct jffs2_tmp_dnode_info *this; 67 + 68 + while (*p) { 69 + parent = *p; 70 + this = rb_entry(parent, struct jffs2_tmp_dnode_info, rb); 71 + 72 + /* There may actually be a collision here, but it doesn't 73 + actually matter. As long as the two nodes with the same 74 + version are together, it's all fine. */ 75 + if (tn->version < this->version) 76 + p = &(*p)->rb_left; 77 + else 78 + p = &(*p)->rb_right; 79 + } 80 + 81 + rb_link_node(&tn->rb, parent, p); 82 + rb_insert_color(&tn->rb, list); 70 83 } 71 84 72 - static void jffs2_free_tmp_dnode_info_list(struct jffs2_tmp_dnode_info *tn) 85 + static void jffs2_free_tmp_dnode_info_list(struct rb_root *list) 73 86 { 74 - struct jffs2_tmp_dnode_info *next; 87 + struct rb_node *this; 88 + struct jffs2_tmp_dnode_info *tn; 75 89 76 - while (tn) { 77 - next = tn; 78 - tn = tn->next; 79 - jffs2_free_full_dnode(next->fn); 80 - jffs2_free_tmp_dnode_info(next); 90 + this = list->rb_node; 91 + 92 + /* Now at bottom of tree */ 93 + while (this) { 94 + if (this->rb_left) 95 + this = this->rb_left; 96 + else if (this->rb_right) 97 + this = this->rb_right; 98 + else { 99 + tn = rb_entry(this, struct jffs2_tmp_dnode_info, rb); 100 + jffs2_free_full_dnode(tn->fn); 101 + jffs2_free_tmp_dnode_info(tn); 102 + 103 + this = this->rb_parent; 104 + if (!this) 105 + break; 106 + 107 + if (this->rb_left == &tn->rb) 108 + this->rb_left = NULL; 109 + else if (this->rb_right == &tn->rb) 110 + this->rb_right = NULL; 111 + else BUG(); 112 + } 81 113 } 114 + list->rb_node = NULL; 82 115 } 83 116 84 117 static void jffs2_free_full_dirent_list(struct jffs2_full_dirent *fd) ··· 141 108 with this ino, returning the former in order of version */ 142 109 143 110 int jffs2_get_inode_nodes(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 144 - struct jffs2_tmp_dnode_info **tnp, struct jffs2_full_dirent **fdp, 111 + struct rb_root *tnp, struct jffs2_full_dirent **fdp, 145 112 uint32_t *highest_version, uint32_t *latest_mctime, 146 113 uint32_t *mctime_ver) 147 114 { 148 115 struct jffs2_raw_node_ref *ref, *valid_ref; 149 - struct jffs2_tmp_dnode_info *tn, *ret_tn = NULL; 116 + struct jffs2_tmp_dnode_info *tn; 117 + struct rb_root ret_tn = RB_ROOT; 150 118 struct jffs2_full_dirent *fd, *ret_fd = NULL; 151 119 union jffs2_node_union node; 152 120 size_t retlen; ··· 161 127 162 128 valid_ref = jffs2_first_valid_node(f->inocache->nodes); 163 129 164 - if (!valid_ref) 130 + if (!valid_ref && (f->inocache->ino != 1)) 165 131 printk(KERN_WARNING "Eep. No valid nodes for ino #%u\n", f->inocache->ino); 166 132 167 133 while (valid_ref) { ··· 484 450 return 0; 485 451 486 452 free_out: 487 - jffs2_free_tmp_dnode_info_list(ret_tn); 453 + jffs2_free_tmp_dnode_info_list(&ret_tn); 488 454 jffs2_free_full_dirent_list(ret_fd); 489 455 return err; 490 456 } ··· 523 489 void jffs2_add_ino_cache (struct jffs2_sb_info *c, struct jffs2_inode_cache *new) 524 490 { 525 491 struct jffs2_inode_cache **prev; 526 - D2(printk(KERN_DEBUG "jffs2_add_ino_cache: Add %p (ino #%u)\n", new, new->ino)); 492 + 527 493 spin_lock(&c->inocache_lock); 528 - 494 + if (!new->ino) 495 + new->ino = ++c->highest_ino; 496 + 497 + D2(printk(KERN_DEBUG "jffs2_add_ino_cache: Add %p (ino #%u)\n", new, new->ino)); 498 + 529 499 prev = &c->inocache_list[new->ino % INOCACHE_HASHSIZE]; 530 500 531 501 while ((*prev) && (*prev)->ino < new->ino) { ··· 544 506 void jffs2_del_ino_cache(struct jffs2_sb_info *c, struct jffs2_inode_cache *old) 545 507 { 546 508 struct jffs2_inode_cache **prev; 547 - D2(printk(KERN_DEBUG "jffs2_del_ino_cache: Del %p (ino #%u)\n", old, old->ino)); 509 + D1(printk(KERN_DEBUG "jffs2_del_ino_cache: Del %p (ino #%u)\n", old, old->ino)); 548 510 spin_lock(&c->inocache_lock); 549 511 550 512 prev = &c->inocache_list[old->ino % INOCACHE_HASHSIZE]; ··· 555 517 if ((*prev) == old) { 556 518 *prev = old->next; 557 519 } 520 + 521 + /* Free it now unless it's in READING or CLEARING state, which 522 + are the transitions upon read_inode() and clear_inode(). The 523 + rest of the time we know nobody else is looking at it, and 524 + if it's held by read_inode() or clear_inode() they'll free it 525 + for themselves. */ 526 + if (old->state != INO_STATE_READING && old->state != INO_STATE_CLEARING) 527 + jffs2_free_inode_cache(old); 558 528 559 529 spin_unlock(&c->inocache_lock); 560 530 } ··· 576 530 this = c->inocache_list[i]; 577 531 while (this) { 578 532 next = this->next; 579 - D2(printk(KERN_DEBUG "jffs2_free_ino_caches: Freeing ino #%u at %p\n", this->ino, this)); 580 533 jffs2_free_inode_cache(this); 581 534 this = next; 582 535 }
+17 -4
fs/jffs2/nodelist.h
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: nodelist.h,v 1.126 2004/11/19 15:06:29 dedekind Exp $ 10 + * $Id: nodelist.h,v 1.131 2005/07/05 21:03:07 dwmw2 Exp $ 11 11 * 12 12 */ 13 13 ··· 135 135 #define INO_STATE_CHECKEDABSENT 3 /* Checked, cleared again */ 136 136 #define INO_STATE_GC 4 /* GCing a 'pristine' node */ 137 137 #define INO_STATE_READING 5 /* In read_inode() */ 138 + #define INO_STATE_CLEARING 6 /* In clear_inode() */ 138 139 139 140 #define INOCACHE_HASHSIZE 128 140 141 ··· 161 160 */ 162 161 struct jffs2_tmp_dnode_info 163 162 { 164 - struct jffs2_tmp_dnode_info *next; 163 + struct rb_node rb; 165 164 struct jffs2_full_dnode *fn; 166 165 uint32_t version; 167 166 }; ··· 363 362 node = node->rb_left; 364 363 return rb_entry(node, struct jffs2_node_frag, rb); 365 364 } 365 + 366 + static inline struct jffs2_node_frag *frag_last(struct rb_root *root) 367 + { 368 + struct rb_node *node = root->rb_node; 369 + 370 + if (!node) 371 + return NULL; 372 + while(node->rb_right) 373 + node = node->rb_right; 374 + return rb_entry(node, struct jffs2_node_frag, rb); 375 + } 376 + 366 377 #define rb_parent(rb) ((rb)->rb_parent) 367 378 #define frag_next(frag) rb_entry(rb_next(&(frag)->rb), struct jffs2_node_frag, rb) 368 379 #define frag_prev(frag) rb_entry(rb_prev(&(frag)->rb), struct jffs2_node_frag, rb) ··· 387 374 D2(void jffs2_print_frag_list(struct jffs2_inode_info *f)); 388 375 void jffs2_add_fd_to_list(struct jffs2_sb_info *c, struct jffs2_full_dirent *new, struct jffs2_full_dirent **list); 389 376 int jffs2_get_inode_nodes(struct jffs2_sb_info *c, struct jffs2_inode_info *f, 390 - struct jffs2_tmp_dnode_info **tnp, struct jffs2_full_dirent **fdp, 377 + struct rb_root *tnp, struct jffs2_full_dirent **fdp, 391 378 uint32_t *highest_version, uint32_t *latest_mctime, 392 379 uint32_t *mctime_ver); 393 380 void jffs2_set_inocache_state(struct jffs2_sb_info *c, struct jffs2_inode_cache *ic, int state); ··· 475 462 /* erase.c */ 476 463 void jffs2_erase_pending_blocks(struct jffs2_sb_info *c, int count); 477 464 478 - #ifdef CONFIG_JFFS2_FS_NAND 465 + #ifdef CONFIG_JFFS2_FS_WRITEBUFFER 479 466 /* wbuf.c */ 480 467 int jffs2_flush_wbuf_gc(struct jffs2_sb_info *c, uint32_t ino); 481 468 int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c);
+16 -15
fs/jffs2/nodemgmt.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: nodemgmt.c,v 1.115 2004/11/22 11:07:21 dwmw2 Exp $ 10 + * $Id: nodemgmt.c,v 1.122 2005/05/06 09:30:27 dedekind Exp $ 11 11 * 12 12 */ 13 13 ··· 75 75 dirty = c->dirty_size + c->erasing_size - c->nr_erasing_blocks * c->sector_size + c->unchecked_size; 76 76 if (dirty < c->nospc_dirty_size) { 77 77 if (prio == ALLOC_DELETION && c->nr_free_blocks + c->nr_erasing_blocks >= c->resv_blocks_deletion) { 78 - printk(KERN_NOTICE "jffs2_reserve_space(): Low on dirty space to GC, but it's a deletion. Allowing...\n"); 78 + D1(printk(KERN_NOTICE "jffs2_reserve_space(): Low on dirty space to GC, but it's a deletion. Allowing...\n")); 79 79 break; 80 80 } 81 81 D1(printk(KERN_DEBUG "dirty size 0x%08x + unchecked_size 0x%08x < nospc_dirty_size 0x%08x, returning -ENOSPC\n", ··· 98 98 avail = c->free_size + c->dirty_size + c->erasing_size + c->unchecked_size; 99 99 if ( (avail / c->sector_size) <= blocksneeded) { 100 100 if (prio == ALLOC_DELETION && c->nr_free_blocks + c->nr_erasing_blocks >= c->resv_blocks_deletion) { 101 - printk(KERN_NOTICE "jffs2_reserve_space(): Low on possibly available space, but it's a deletion. Allowing...\n"); 101 + D1(printk(KERN_NOTICE "jffs2_reserve_space(): Low on possibly available space, but it's a deletion. Allowing...\n")); 102 102 break; 103 103 } 104 104 ··· 308 308 309 309 D1(printk(KERN_DEBUG "jffs2_add_physical_node_ref(): Node at 0x%x(%d), size 0x%x\n", ref_offset(new), ref_flags(new), len)); 310 310 #if 1 311 - if (jeb != c->nextblock || (ref_offset(new)) != jeb->offset + (c->sector_size - jeb->free_size)) { 311 + /* we could get some obsolete nodes after nextblock was refiled 312 + in wbuf.c */ 313 + if ((c->nextblock || !ref_obsolete(new)) 314 + &&(jeb != c->nextblock || ref_offset(new) != jeb->offset + (c->sector_size - jeb->free_size))) { 312 315 printk(KERN_WARNING "argh. node added in wrong place\n"); 313 316 jffs2_free_raw_node_ref(new); 314 317 return -EINVAL; ··· 335 332 c->used_size += len; 336 333 } 337 334 338 - if (!jeb->free_size && !jeb->dirty_size) { 335 + if (!jeb->free_size && !jeb->dirty_size && !ISDIRTY(jeb->wasted_size)) { 339 336 /* If it lives on the dirty_list, jffs2_reserve_space will put it there */ 340 337 D1(printk(KERN_DEBUG "Adding full erase block at 0x%08x to clean_list (free 0x%08x, dirty 0x%08x, used 0x%08x\n", 341 338 jeb->offset, jeb->free_size, jeb->dirty_size, jeb->used_size)); ··· 403 400 jeb = &c->blocks[blocknr]; 404 401 405 402 if (jffs2_can_mark_obsolete(c) && !jffs2_is_readonly(c) && 406 - !(c->flags & JFFS2_SB_FLAG_MOUNTING)) { 403 + !(c->flags & (JFFS2_SB_FLAG_SCANNING | JFFS2_SB_FLAG_BUILDING))) { 407 404 /* Hm. This may confuse static lock analysis. If any of the above 408 405 three conditions is false, we're going to return from this 409 406 function without actually obliterating any nodes or freeing ··· 437 434 438 435 // Take care, that wasted size is taken into concern 439 436 if ((jeb->dirty_size || ISDIRTY(jeb->wasted_size + ref_totlen(c, jeb, ref))) && jeb != c->nextblock) { 440 - D1(printk("Dirtying\n")); 437 + D1(printk(KERN_DEBUG "Dirtying\n")); 441 438 addedsize = ref_totlen(c, jeb, ref); 442 439 jeb->dirty_size += ref_totlen(c, jeb, ref); 443 440 c->dirty_size += ref_totlen(c, jeb, ref); ··· 459 456 } 460 457 } 461 458 } else { 462 - D1(printk("Wasting\n")); 459 + D1(printk(KERN_DEBUG "Wasting\n")); 463 460 addedsize = 0; 464 461 jeb->wasted_size += ref_totlen(c, jeb, ref); 465 462 c->wasted_size += ref_totlen(c, jeb, ref); ··· 470 467 471 468 D1(ACCT_PARANOIA_CHECK(jeb)); 472 469 473 - if (c->flags & JFFS2_SB_FLAG_MOUNTING) { 474 - /* Mount in progress. Don't muck about with the block 470 + if (c->flags & JFFS2_SB_FLAG_SCANNING) { 471 + /* Flash scanning is in progress. Don't muck about with the block 475 472 lists because they're not ready yet, and don't actually 476 473 obliterate nodes that look obsolete. If they weren't 477 474 marked obsolete on the flash at the time they _became_ ··· 530 527 531 528 spin_unlock(&c->erase_completion_lock); 532 529 533 - if (!jffs2_can_mark_obsolete(c) || jffs2_is_readonly(c)) { 530 + if (!jffs2_can_mark_obsolete(c) || jffs2_is_readonly(c) || 531 + (c->flags & JFFS2_SB_FLAG_BUILDING)) { 534 532 /* We didn't lock the erase_free_sem */ 535 533 return; 536 534 } ··· 594 590 *p = ref->next_in_ino; 595 591 ref->next_in_ino = NULL; 596 592 597 - if (ic->nodes == (void *)ic) { 598 - D1(printk(KERN_DEBUG "inocache for ino #%u is all gone now. Freeing\n", ic->ino)); 593 + if (ic->nodes == (void *)ic && ic->nlink == 0) 599 594 jffs2_del_ino_cache(c, ic); 600 - jffs2_free_inode_cache(ic); 601 - } 602 595 603 596 spin_unlock(&c->erase_completion_lock); 604 597 }
+15 -45
fs/jffs2/os-linux.h
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: os-linux.h,v 1.51 2004/11/16 20:36:11 dwmw2 Exp $ 10 + * $Id: os-linux.h,v 1.57 2005/07/06 12:13:09 dwmw2 Exp $ 11 11 * 12 12 */ 13 13 14 14 #ifndef __JFFS2_OS_LINUX_H__ 15 15 #define __JFFS2_OS_LINUX_H__ 16 - #include <linux/version.h> 17 16 18 17 /* JFFS2 uses Linux mode bits natively -- no need for conversion */ 19 18 #define os_to_jffs2_mode(x) (x) 20 19 #define jffs2_to_os_mode(x) (x) 21 20 22 - #if LINUX_VERSION_CODE < KERNEL_VERSION(2,5,73) 23 - #define kstatfs statfs 24 - #endif 25 - 26 21 struct kstatfs; 27 22 struct kvec; 28 23 29 - #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,2) 30 24 #define JFFS2_INODE_INFO(i) (list_entry(i, struct jffs2_inode_info, vfs_inode)) 31 25 #define OFNI_EDONI_2SFFJ(f) (&(f)->vfs_inode) 32 26 #define JFFS2_SB_INFO(sb) (sb->s_fs_info) 33 27 #define OFNI_BS_2SFFJ(c) ((struct super_block *)c->os_priv) 34 - #elif defined(JFFS2_OUT_OF_KERNEL) 35 - #define JFFS2_INODE_INFO(i) ((struct jffs2_inode_info *) &(i)->u) 36 - #define OFNI_EDONI_2SFFJ(f) ((struct inode *) ( ((char *)f) - ((char *)(&((struct inode *)NULL)->u)) ) ) 37 - #define JFFS2_SB_INFO(sb) ((struct jffs2_sb_info *) &(sb)->u) 38 - #define OFNI_BS_2SFFJ(c) ((struct super_block *) ( ((char *)c) - ((char *)(&((struct super_block *)NULL)->u)) ) ) 39 - #else 40 - #define JFFS2_INODE_INFO(i) (&i->u.jffs2_i) 41 - #define OFNI_EDONI_2SFFJ(f) ((struct inode *) ( ((char *)f) - ((char *)(&((struct inode *)NULL)->u)) ) ) 42 - #define JFFS2_SB_INFO(sb) (&sb->u.jffs2_sb) 43 - #define OFNI_BS_2SFFJ(c) ((struct super_block *) ( ((char *)c) - ((char *)(&((struct super_block *)NULL)->u)) ) ) 44 - #endif 45 28 46 29 47 30 #define JFFS2_F_I_SIZE(f) (OFNI_EDONI_2SFFJ(f)->i_size) ··· 32 49 #define JFFS2_F_I_UID(f) (OFNI_EDONI_2SFFJ(f)->i_uid) 33 50 #define JFFS2_F_I_GID(f) (OFNI_EDONI_2SFFJ(f)->i_gid) 34 51 35 - #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,1) 36 52 #define JFFS2_F_I_RDEV_MIN(f) (iminor(OFNI_EDONI_2SFFJ(f))) 37 53 #define JFFS2_F_I_RDEV_MAJ(f) (imajor(OFNI_EDONI_2SFFJ(f))) 38 - #else 39 - #define JFFS2_F_I_RDEV_MIN(f) (MINOR(to_kdev_t(OFNI_EDONI_2SFFJ(f)->i_rdev))) 40 - #define JFFS2_F_I_RDEV_MAJ(f) (MAJOR(to_kdev_t(OFNI_EDONI_2SFFJ(f)->i_rdev))) 41 - #endif 42 54 43 - /* Urgh. The things we do to keep the 2.4 build working */ 44 - #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,47) 45 55 #define ITIME(sec) ((struct timespec){sec, 0}) 46 56 #define I_SEC(tv) ((tv).tv_sec) 47 57 #define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime.tv_sec) 48 58 #define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime.tv_sec) 49 59 #define JFFS2_F_I_ATIME(f) (OFNI_EDONI_2SFFJ(f)->i_atime.tv_sec) 50 - #else 51 - #define ITIME(x) (x) 52 - #define I_SEC(x) (x) 53 - #define JFFS2_F_I_CTIME(f) (OFNI_EDONI_2SFFJ(f)->i_ctime) 54 - #define JFFS2_F_I_MTIME(f) (OFNI_EDONI_2SFFJ(f)->i_mtime) 55 - #define JFFS2_F_I_ATIME(f) (OFNI_EDONI_2SFFJ(f)->i_atime) 56 - #endif 57 60 58 61 #define sleep_on_spinunlock(wq, s) \ 59 62 do { \ ··· 53 84 54 85 static inline void jffs2_init_inode_info(struct jffs2_inode_info *f) 55 86 { 56 - #if LINUX_VERSION_CODE > KERNEL_VERSION(2,5,2) 57 87 f->highest_version = 0; 58 88 f->fragtree = RB_ROOT; 59 89 f->metadata = NULL; 60 90 f->dents = NULL; 61 91 f->flags = 0; 62 92 f->usercompr = 0; 63 - #else 64 - memset(f, 0, sizeof(*f)); 65 - init_MUTEX_LOCKED(&f->sem); 66 - #endif 67 93 } 94 + 68 95 69 96 #define jffs2_is_readonly(c) (OFNI_BS_2SFFJ(c)->s_flags & MS_RDONLY) 70 97 71 - #if (!defined CONFIG_JFFS2_FS_NAND && !defined CONFIG_JFFS2_FS_NOR_ECC) 98 + #ifndef CONFIG_JFFS2_FS_WRITEBUFFER 99 + #define SECTOR_ADDR(x) ( ((unsigned long)(x) & ~(c->sector_size-1)) ) 72 100 #define jffs2_can_mark_obsolete(c) (1) 101 + #define jffs2_is_writebuffered(c) (0) 73 102 #define jffs2_cleanmarker_oob(c) (0) 74 103 #define jffs2_write_nand_cleanmarker(c,jeb) (-EIO) 75 104 ··· 83 116 #define jffs2_wbuf_timeout NULL 84 117 #define jffs2_wbuf_process NULL 85 118 #define jffs2_nor_ecc(c) (0) 119 + #define jffs2_dataflash(c) (0) 86 120 #define jffs2_nor_ecc_flash_setup(c) (0) 87 121 #define jffs2_nor_ecc_flash_cleanup(c) do {} while (0) 88 122 89 123 #else /* NAND and/or ECC'd NOR support present */ 90 124 125 + #define jffs2_is_writebuffered(c) (c->wbuf != NULL) 126 + #define SECTOR_ADDR(x) ( ((unsigned long)(x) / (unsigned long)(c->sector_size)) * c->sector_size ) 91 127 #define jffs2_can_mark_obsolete(c) ((c->mtd->type == MTD_NORFLASH && !(c->mtd->flags & MTD_ECC)) || c->mtd->type == MTD_RAM) 92 128 #define jffs2_cleanmarker_oob(c) (c->mtd->type == MTD_NANDFLASH) 93 129 ··· 112 142 int jffs2_flush_wbuf_pad(struct jffs2_sb_info *c); 113 143 int jffs2_nand_flash_setup(struct jffs2_sb_info *c); 114 144 void jffs2_nand_flash_cleanup(struct jffs2_sb_info *c); 115 - #ifdef CONFIG_JFFS2_FS_NOR_ECC 145 + 116 146 #define jffs2_nor_ecc(c) (c->mtd->type == MTD_NORFLASH && (c->mtd->flags & MTD_ECC)) 117 147 int jffs2_nor_ecc_flash_setup(struct jffs2_sb_info *c); 118 148 void jffs2_nor_ecc_flash_cleanup(struct jffs2_sb_info *c); 119 - #else 120 - #define jffs2_nor_ecc(c) (0) 121 - #define jffs2_nor_ecc_flash_setup(c) (0) 122 - #define jffs2_nor_ecc_flash_cleanup(c) do {} while (0) 123 - #endif /* NOR ECC */ 124 - #endif /* NAND */ 149 + 150 + #define jffs2_dataflash(c) (c->mtd->type == MTD_DATAFLASH) 151 + int jffs2_dataflash_setup(struct jffs2_sb_info *c); 152 + void jffs2_dataflash_cleanup(struct jffs2_sb_info *c); 153 + 154 + #endif /* WRITEBUFFER */ 125 155 126 156 /* erase.c */ 127 157 static inline void jffs2_erase_pending_trigger(struct jffs2_sb_info *c)
+1 -31
fs/jffs2/read.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: read.c,v 1.38 2004/11/16 20:36:12 dwmw2 Exp $ 10 + * $Id: read.c,v 1.39 2005/03/01 10:34:03 dedekind Exp $ 11 11 * 12 12 */ 13 13 ··· 214 214 return 0; 215 215 } 216 216 217 - /* Core function to read symlink target. */ 218 - char *jffs2_getlink(struct jffs2_sb_info *c, struct jffs2_inode_info *f) 219 - { 220 - char *buf; 221 - int ret; 222 - 223 - down(&f->sem); 224 - 225 - if (!f->metadata) { 226 - printk(KERN_NOTICE "No metadata for symlink inode #%u\n", f->inocache->ino); 227 - up(&f->sem); 228 - return ERR_PTR(-EINVAL); 229 - } 230 - buf = kmalloc(f->metadata->size+1, GFP_USER); 231 - if (!buf) { 232 - up(&f->sem); 233 - return ERR_PTR(-ENOMEM); 234 - } 235 - buf[f->metadata->size]=0; 236 - 237 - ret = jffs2_read_dnode(c, f, f->metadata, buf, 0, f->metadata->size); 238 - 239 - up(&f->sem); 240 - 241 - if (ret) { 242 - kfree(buf); 243 - return ERR_PTR(ret); 244 - } 245 - return buf; 246 - }
+85 -11
fs/jffs2/readinode.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: readinode.c,v 1.117 2004/11/20 18:06:54 dwmw2 Exp $ 10 + * $Id: readinode.c,v 1.120 2005/07/05 21:03:07 dwmw2 Exp $ 11 11 * 12 12 */ 13 13 ··· 500 500 struct jffs2_inode_info *f, 501 501 struct jffs2_raw_inode *latest_node) 502 502 { 503 - struct jffs2_tmp_dnode_info *tn_list, *tn; 503 + struct jffs2_tmp_dnode_info *tn = NULL; 504 + struct rb_root tn_list; 505 + struct rb_node *rb, *repl_rb; 504 506 struct jffs2_full_dirent *fd_list; 505 507 struct jffs2_full_dnode *fn = NULL; 506 508 uint32_t crc; ··· 524 522 } 525 523 f->dents = fd_list; 526 524 527 - while (tn_list) { 528 - tn = tn_list; 525 + rb = rb_first(&tn_list); 529 526 527 + while (rb) { 528 + tn = rb_entry(rb, struct jffs2_tmp_dnode_info, rb); 530 529 fn = tn->fn; 531 530 532 531 if (f->metadata) { ··· 559 556 mdata_ver = tn->version; 560 557 } 561 558 next_tn: 562 - tn_list = tn->next; 559 + BUG_ON(rb->rb_left); 560 + repl_rb = NULL; 561 + if (rb->rb_parent && rb->rb_parent->rb_left == rb) { 562 + /* We were then left-hand child of our parent. We need 563 + to move our own right-hand child into our place. */ 564 + repl_rb = rb->rb_right; 565 + if (repl_rb) 566 + repl_rb->rb_parent = rb->rb_parent; 567 + } else 568 + repl_rb = NULL; 569 + 570 + rb = rb_next(rb); 571 + 572 + /* Remove the spent tn from the tree; don't bother rebalancing 573 + but put our right-hand child in our own place. */ 574 + if (tn->rb.rb_parent) { 575 + if (tn->rb.rb_parent->rb_left == &tn->rb) 576 + tn->rb.rb_parent->rb_left = repl_rb; 577 + else if (tn->rb.rb_parent->rb_right == &tn->rb) 578 + tn->rb.rb_parent->rb_right = repl_rb; 579 + else BUG(); 580 + } else if (tn->rb.rb_right) 581 + tn->rb.rb_right->rb_parent = NULL; 582 + 563 583 jffs2_free_tmp_dnode_info(tn); 564 584 } 565 585 D1(jffs2_sanitycheck_fragtree(f)); ··· 649 623 case. */ 650 624 if (!je32_to_cpu(latest_node->isize)) 651 625 latest_node->isize = latest_node->dsize; 626 + 627 + if (f->inocache->state != INO_STATE_CHECKING) { 628 + /* Symlink's inode data is the target path. Read it and 629 + * keep in RAM to facilitate quick follow symlink operation. 630 + * We use f->dents field to store the target path, which 631 + * is somewhat ugly. */ 632 + f->dents = kmalloc(je32_to_cpu(latest_node->csize) + 1, GFP_KERNEL); 633 + if (!f->dents) { 634 + printk(KERN_WARNING "Can't allocate %d bytes of memory " 635 + "for the symlink target path cache\n", 636 + je32_to_cpu(latest_node->csize)); 637 + up(&f->sem); 638 + jffs2_do_clear_inode(c, f); 639 + return -ENOMEM; 640 + } 641 + 642 + ret = jffs2_flash_read(c, ref_offset(fn->raw) + sizeof(*latest_node), 643 + je32_to_cpu(latest_node->csize), &retlen, (char *)f->dents); 644 + 645 + if (ret || retlen != je32_to_cpu(latest_node->csize)) { 646 + if (retlen != je32_to_cpu(latest_node->csize)) 647 + ret = -EIO; 648 + kfree(f->dents); 649 + f->dents = NULL; 650 + up(&f->sem); 651 + jffs2_do_clear_inode(c, f); 652 + return -ret; 653 + } 654 + 655 + ((char *)f->dents)[je32_to_cpu(latest_node->csize)] = '\0'; 656 + D1(printk(KERN_DEBUG "jffs2_do_read_inode(): symlink's target '%s' cached\n", 657 + (char *)f->dents)); 658 + } 659 + 652 660 /* fall through... */ 653 661 654 662 case S_IFBLK: ··· 732 672 down(&f->sem); 733 673 deleted = f->inocache && !f->inocache->nlink; 734 674 675 + if (f->inocache && f->inocache->state != INO_STATE_CHECKING) 676 + jffs2_set_inocache_state(c, f->inocache, INO_STATE_CLEARING); 677 + 735 678 if (f->metadata) { 736 679 if (deleted) 737 680 jffs2_mark_node_obsolete(c, f->metadata->raw); ··· 743 680 744 681 jffs2_kill_fragtree(&f->fragtree, deleted?c:NULL); 745 682 746 - fds = f->dents; 683 + /* For symlink inodes we us f->dents to store the target path name */ 684 + if (S_ISLNK(OFNI_EDONI_2SFFJ(f)->i_mode)) { 685 + if (f->dents) { 686 + kfree(f->dents); 687 + f->dents = NULL; 688 + } 689 + } else { 690 + fds = f->dents; 747 691 748 - while(fds) { 749 - fd = fds; 750 - fds = fd->next; 751 - jffs2_free_full_dirent(fd); 692 + while(fds) { 693 + fd = fds; 694 + fds = fd->next; 695 + jffs2_free_full_dirent(fd); 696 + } 752 697 } 753 698 754 - if (f->inocache && f->inocache->state != INO_STATE_CHECKING) 699 + if (f->inocache && f->inocache->state != INO_STATE_CHECKING) { 755 700 jffs2_set_inocache_state(c, f->inocache, INO_STATE_CHECKEDABSENT); 701 + if (f->inocache->nodes == (void *)f->inocache) 702 + jffs2_del_ino_cache(c, f->inocache); 703 + } 756 704 757 705 up(&f->sem); 758 706 }
+25 -14
fs/jffs2/scan.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: scan.c,v 1.115 2004/11/17 12:59:08 dedekind Exp $ 10 + * $Id: scan.c,v 1.119 2005/02/17 17:51:13 dedekind Exp $ 11 11 * 12 12 */ 13 13 #include <linux/kernel.h> ··· 19 19 #include <linux/compiler.h> 20 20 #include "nodelist.h" 21 21 22 - #define EMPTY_SCAN_SIZE 1024 22 + #define DEFAULT_EMPTY_SCAN_SIZE 1024 23 23 24 24 #define DIRTY_SPACE(x) do { typeof(x) _x = (x); \ 25 25 c->free_size -= _x; c->dirty_size += _x; \ ··· 68 68 static inline int min_free(struct jffs2_sb_info *c) 69 69 { 70 70 uint32_t min = 2 * sizeof(struct jffs2_raw_inode); 71 - #if defined CONFIG_JFFS2_FS_NAND || defined CONFIG_JFFS2_FS_NOR_ECC 71 + #ifdef CONFIG_JFFS2_FS_WRITEBUFFER 72 72 if (!jffs2_can_mark_obsolete(c) && min < c->wbuf_pagesize) 73 73 return c->wbuf_pagesize; 74 74 #endif 75 75 return min; 76 76 77 77 } 78 + 79 + static inline uint32_t EMPTY_SCAN_SIZE(uint32_t sector_size) { 80 + if (sector_size < DEFAULT_EMPTY_SCAN_SIZE) 81 + return sector_size; 82 + else 83 + return DEFAULT_EMPTY_SCAN_SIZE; 84 + } 85 + 78 86 int jffs2_scan_medium(struct jffs2_sb_info *c) 79 87 { 80 88 int i, ret; ··· 228 220 c->dirty_size -= c->nextblock->dirty_size; 229 221 c->nextblock->dirty_size = 0; 230 222 } 231 - #if defined CONFIG_JFFS2_FS_NAND || defined CONFIG_JFFS2_FS_NOR_ECC 223 + #ifdef CONFIG_JFFS2_FS_WRITEBUFFER 232 224 if (!jffs2_can_mark_obsolete(c) && c->nextblock && (c->nextblock->free_size & (c->wbuf_pagesize-1))) { 233 225 /* If we're going to start writing into a block which already 234 226 contains data, and the end of the data isn't page-aligned, ··· 294 286 uint32_t hdr_crc, buf_ofs, buf_len; 295 287 int err; 296 288 int noise = 0; 297 - #ifdef CONFIG_JFFS2_FS_NAND 289 + #ifdef CONFIG_JFFS2_FS_WRITEBUFFER 298 290 int cleanmarkerfound = 0; 299 291 #endif 300 292 ··· 303 295 304 296 D1(printk(KERN_DEBUG "jffs2_scan_eraseblock(): Scanning block at 0x%x\n", ofs)); 305 297 306 - #ifdef CONFIG_JFFS2_FS_NAND 298 + #ifdef CONFIG_JFFS2_FS_WRITEBUFFER 307 299 if (jffs2_cleanmarker_oob(c)) { 308 300 int ret = jffs2_check_nand_cleanmarker(c, jeb); 309 301 D2(printk(KERN_NOTICE "jffs_check_nand_cleanmarker returned %d\n",ret)); ··· 324 316 if (!buf_size) { 325 317 buf_len = c->sector_size; 326 318 } else { 327 - buf_len = EMPTY_SCAN_SIZE; 319 + buf_len = EMPTY_SCAN_SIZE(c->sector_size); 328 320 err = jffs2_fill_scan_buf(c, buf, buf_ofs, buf_len); 329 321 if (err) 330 322 return err; ··· 334 326 ofs = 0; 335 327 336 328 /* Scan only 4KiB of 0xFF before declaring it's empty */ 337 - while(ofs < EMPTY_SCAN_SIZE && *(uint32_t *)(&buf[ofs]) == 0xFFFFFFFF) 329 + while(ofs < EMPTY_SCAN_SIZE(c->sector_size) && *(uint32_t *)(&buf[ofs]) == 0xFFFFFFFF) 338 330 ofs += 4; 339 331 340 - if (ofs == EMPTY_SCAN_SIZE) { 341 - #ifdef CONFIG_JFFS2_FS_NAND 332 + if (ofs == EMPTY_SCAN_SIZE(c->sector_size)) { 333 + #ifdef CONFIG_JFFS2_FS_WRITEBUFFER 342 334 if (jffs2_cleanmarker_oob(c)) { 343 335 /* scan oob, take care of cleanmarker */ 344 336 int ret = jffs2_check_oob_empty(c, jeb, cleanmarkerfound); ··· 351 343 } 352 344 #endif 353 345 D1(printk(KERN_DEBUG "Block at 0x%08x is empty (erased)\n", jeb->offset)); 354 - return BLK_STATE_ALLFF; /* OK to erase if all blocks are like this */ 346 + if (c->cleanmarker_size == 0) 347 + return BLK_STATE_CLEANMARKER; /* don't bother with re-erase */ 348 + else 349 + return BLK_STATE_ALLFF; /* OK to erase if all blocks are like this */ 355 350 } 356 351 if (ofs) { 357 352 D1(printk(KERN_DEBUG "Free space at %08x ends at %08x\n", jeb->offset, ··· 433 422 /* If we're only checking the beginning of a block with a cleanmarker, 434 423 bail now */ 435 424 if (buf_ofs == jeb->offset && jeb->used_size == PAD(c->cleanmarker_size) && 436 - c->cleanmarker_size && !jeb->dirty_size && !jeb->first_node->next_in_ino) { 437 - D1(printk(KERN_DEBUG "%d bytes at start of block seems clean... assuming all clean\n", EMPTY_SCAN_SIZE)); 425 + c->cleanmarker_size && !jeb->dirty_size && !jeb->first_node->next_phys) { 426 + D1(printk(KERN_DEBUG "%d bytes at start of block seems clean... assuming all clean\n", EMPTY_SCAN_SIZE(c->sector_size))); 438 427 return BLK_STATE_CLEANMARKER; 439 428 } 440 429 ··· 629 618 } 630 619 631 620 if ((jeb->used_size + jeb->unchecked_size) == PAD(c->cleanmarker_size) && !jeb->dirty_size 632 - && (!jeb->first_node || !jeb->first_node->next_in_ino) ) 621 + && (!jeb->first_node || !jeb->first_node->next_phys) ) 633 622 return BLK_STATE_CLEANMARKER; 634 623 635 624 /* move blocks with max 4 byte dirty space to cleanlist */
+4 -4
fs/jffs2/super.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: super.c,v 1.104 2004/11/23 15:37:31 gleixner Exp $ 10 + * $Id: super.c,v 1.106 2005/05/18 11:37:25 dedekind Exp $ 11 11 * 12 12 */ 13 13 ··· 270 270 271 271 D2(printk(KERN_DEBUG "jffs2: jffs2_put_super()\n")); 272 272 273 - if (!(sb->s_flags & MS_RDONLY)) 274 - jffs2_stop_garbage_collect_thread(c); 275 273 down(&c->alloc_sem); 276 274 jffs2_flush_wbuf_pad(c); 277 275 up(&c->alloc_sem); ··· 290 292 static void jffs2_kill_sb(struct super_block *sb) 291 293 { 292 294 struct jffs2_sb_info *c = JFFS2_SB_INFO(sb); 295 + if (!(sb->s_flags & MS_RDONLY)) 296 + jffs2_stop_garbage_collect_thread(c); 293 297 generic_shutdown_super(sb); 294 298 put_mtd_device(c->mtd); 295 299 kfree(c); ··· 309 309 int ret; 310 310 311 311 printk(KERN_INFO "JFFS2 version 2.2." 312 - #ifdef CONFIG_JFFS2_FS_NAND 312 + #ifdef CONFIG_JFFS2_FS_WRITEBUFFER 313 313 " (NAND)" 314 314 #endif 315 315 " (C) 2001-2003 Red Hat, Inc.\n");
+30 -12
fs/jffs2/symlink.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: symlink.c,v 1.14 2004/11/16 20:36:12 dwmw2 Exp $ 10 + * $Id: symlink.c,v 1.16 2005/03/01 10:50:48 dedekind Exp $ 11 11 * 12 12 */ 13 13 ··· 19 19 #include "nodelist.h" 20 20 21 21 static int jffs2_follow_link(struct dentry *dentry, struct nameidata *nd); 22 - static void jffs2_put_link(struct dentry *dentry, struct nameidata *nd); 23 22 24 23 struct inode_operations jffs2_symlink_inode_operations = 25 24 { 26 25 .readlink = generic_readlink, 27 26 .follow_link = jffs2_follow_link, 28 - .put_link = jffs2_put_link, 29 27 .setattr = jffs2_setattr 30 28 }; 31 29 32 30 static int jffs2_follow_link(struct dentry *dentry, struct nameidata *nd) 33 31 { 34 - unsigned char *buf; 35 - buf = jffs2_getlink(JFFS2_SB_INFO(dentry->d_inode->i_sb), JFFS2_INODE_INFO(dentry->d_inode)); 36 - nd_set_link(nd, buf); 32 + struct jffs2_inode_info *f = JFFS2_INODE_INFO(dentry->d_inode); 33 + 34 + /* 35 + * We don't acquire the f->sem mutex here since the only data we 36 + * use is f->dents which in case of the symlink inode points to the 37 + * symlink's target path. 38 + * 39 + * 1. If we are here the inode has already built and f->dents has 40 + * to point to the target path. 41 + * 2. Nobody uses f->dents (if the inode is symlink's inode). The 42 + * exception is inode freeing function which frees f->dents. But 43 + * it can't be called while we are here and before VFS has 44 + * stopped using our f->dents string which we provide by means of 45 + * nd_set_link() call. 46 + */ 47 + 48 + if (!f->dents) { 49 + printk(KERN_ERR "jffs2_follow_link(): can't find symlink taerget\n"); 50 + return -EIO; 51 + } 52 + D1(printk(KERN_DEBUG "jffs2_follow_link(): target path is '%s'\n", (char *) f->dents)); 53 + 54 + nd_set_link(nd, (char *)f->dents); 55 + 56 + /* 57 + * We unlock the f->sem mutex but VFS will use the f->dents string. This is safe 58 + * since the only way that may cause f->dents to be changed is iput() operation. 59 + * But VFS will not use f->dents after iput() has been called. 60 + */ 37 61 return 0; 38 62 } 39 63 40 - static void jffs2_put_link(struct dentry *dentry, struct nameidata *nd) 41 - { 42 - char *s = nd_get_link(nd); 43 - if (!IS_ERR(s)) 44 - kfree(s); 45 - }
+108 -56
fs/jffs2/wbuf.c
··· 9 9 * 10 10 * For licensing information, see the file 'LICENCE' in this directory. 11 11 * 12 - * $Id: wbuf.c,v 1.82 2004/11/20 22:08:31 dwmw2 Exp $ 12 + * $Id: wbuf.c,v 1.92 2005/04/05 12:51:54 dedekind Exp $ 13 13 * 14 14 */ 15 15 ··· 83 83 struct jffs2_inodirty *new; 84 84 85 85 /* Mark the superblock dirty so that kupdated will flush... */ 86 - OFNI_BS_2SFFJ(c)->s_dirt = 1; 86 + jffs2_erase_pending_trigger(c); 87 87 88 88 if (jffs2_wbuf_pending_for_ino(c, ino)) 89 89 return; ··· 130 130 } 131 131 } 132 132 133 - static void jffs2_block_refile(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb) 133 + #define REFILE_NOTEMPTY 0 134 + #define REFILE_ANYWAY 1 135 + 136 + static void jffs2_block_refile(struct jffs2_sb_info *c, struct jffs2_eraseblock *jeb, int allow_empty) 134 137 { 135 138 D1(printk("About to refile bad block at %08x\n", jeb->offset)); 136 139 ··· 147 144 D1(printk("Refiling block at %08x to bad_used_list\n", jeb->offset)); 148 145 list_add(&jeb->list, &c->bad_used_list); 149 146 } else { 150 - BUG(); 147 + BUG_ON(allow_empty == REFILE_NOTEMPTY); 151 148 /* It has to have had some nodes or we couldn't be here */ 152 149 D1(printk("Refiling block at %08x to erase_pending_list\n", jeb->offset)); 153 150 list_add(&jeb->list, &c->erase_pending_list); ··· 182 179 183 180 jeb = &c->blocks[c->wbuf_ofs / c->sector_size]; 184 181 185 - jffs2_block_refile(c, jeb); 182 + jffs2_block_refile(c, jeb, REFILE_NOTEMPTY); 186 183 187 184 /* Find the first node to be recovered, by skipping over every 188 185 node which ends before the wbuf starts, or which is obsolete. */ ··· 267 264 ret = jffs2_reserve_space_gc(c, end-start, &ofs, &len); 268 265 if (ret) { 269 266 printk(KERN_WARNING "Failed to allocate space for wbuf recovery. Data loss ensues.\n"); 270 - if (buf) 271 - kfree(buf); 267 + kfree(buf); 272 268 return; 273 269 } 274 270 if (end-start >= c->wbuf_pagesize) { 275 - /* Need to do another write immediately. This, btw, 276 - means that we'll be writing from 'buf' and not from 277 - the wbuf. Since if we're writing from the wbuf there 278 - won't be more than a wbuf full of data, now will 279 - there? :) */ 280 - 271 + /* Need to do another write immediately, but it's possible 272 + that this is just because the wbuf itself is completely 273 + full, and there's nothing earlier read back from the 274 + flash. Hence 'buf' isn't necessarily what we're writing 275 + from. */ 276 + unsigned char *rewrite_buf = buf?:c->wbuf; 281 277 uint32_t towrite = (end-start) - ((end-start)%c->wbuf_pagesize); 282 278 283 279 D1(printk(KERN_DEBUG "Write 0x%x bytes at 0x%08x in wbuf recover\n", ··· 294 292 #endif 295 293 if (jffs2_cleanmarker_oob(c)) 296 294 ret = c->mtd->write_ecc(c->mtd, ofs, towrite, &retlen, 297 - buf, NULL, c->oobinfo); 295 + rewrite_buf, NULL, c->oobinfo); 298 296 else 299 - ret = c->mtd->write(c->mtd, ofs, towrite, &retlen, buf); 297 + ret = c->mtd->write(c->mtd, ofs, towrite, &retlen, rewrite_buf); 300 298 301 299 if (ret || retlen != towrite) { 302 300 /* Argh. We tried. Really we did. */ ··· 323 321 324 322 c->wbuf_len = (end - start) - towrite; 325 323 c->wbuf_ofs = ofs + towrite; 326 - memcpy(c->wbuf, buf + towrite, c->wbuf_len); 324 + memmove(c->wbuf, rewrite_buf + towrite, c->wbuf_len); 327 325 /* Don't muck about with c->wbuf_inodes. False positives are harmless. */ 328 - 329 - kfree(buf); 326 + if (buf) 327 + kfree(buf); 330 328 } else { 331 329 /* OK, now we're left with the dregs in whichever buffer we're using */ 332 330 if (buf) { ··· 415 413 int ret; 416 414 size_t retlen; 417 415 418 - /* Nothing to do if not NAND flash. In particular, we shouldn't 416 + /* Nothing to do if not write-buffering the flash. In particular, we shouldn't 419 417 del_timer() the timer we never initialised. */ 420 - if (jffs2_can_mark_obsolete(c)) 418 + if (!jffs2_is_writebuffered(c)) 421 419 return 0; 422 420 423 421 if (!down_trylock(&c->alloc_sem)) { ··· 426 424 BUG(); 427 425 } 428 426 429 - if(!c->wbuf || !c->wbuf_len) 427 + if (!c->wbuf_len) /* already checked c->wbuf above */ 430 428 return 0; 431 429 432 430 /* claim remaining space on the page ··· 435 433 if we have a switch to next page, we will not have 436 434 enough remaining space for this. 437 435 */ 438 - if (pad) { 436 + if (pad && !jffs2_dataflash(c)) { 439 437 c->wbuf_len = PAD(c->wbuf_len); 440 438 441 439 /* Pad with JFFS2_DIRTY_BITMASK initially. this helps out ECC'd NOR ··· 486 484 spin_lock(&c->erase_completion_lock); 487 485 488 486 /* Adjust free size of the block if we padded. */ 489 - if (pad) { 487 + if (pad && !jffs2_dataflash(c)) { 490 488 struct jffs2_eraseblock *jeb; 491 489 492 490 jeb = &c->blocks[c->wbuf_ofs / c->sector_size]; ··· 534 532 535 533 D1(printk(KERN_DEBUG "jffs2_flush_wbuf_gc() called for ino #%u...\n", ino)); 536 534 535 + if (!c->wbuf) 536 + return 0; 537 + 537 538 down(&c->alloc_sem); 538 539 if (!jffs2_wbuf_pending_for_ino(c, ino)) { 539 540 D1(printk(KERN_DEBUG "Ino #%d not pending in wbuf. Returning\n", ino)); ··· 552 547 D1(printk(KERN_DEBUG "jffs2_flush_wbuf_gc() padding. Not finished checking\n")); 553 548 down_write(&c->wbuf_sem); 554 549 ret = __jffs2_flush_wbuf(c, PAD_ACCOUNTING); 550 + /* retry flushing wbuf in case jffs2_wbuf_recover 551 + left some data in the wbuf */ 552 + if (ret) 553 + ret = __jffs2_flush_wbuf(c, PAD_ACCOUNTING); 555 554 up_write(&c->wbuf_sem); 556 555 } else while (old_wbuf_len && 557 556 old_wbuf_ofs == c->wbuf_ofs) { ··· 570 561 down(&c->alloc_sem); 571 562 down_write(&c->wbuf_sem); 572 563 ret = __jffs2_flush_wbuf(c, PAD_ACCOUNTING); 564 + /* retry flushing wbuf in case jffs2_wbuf_recover 565 + left some data in the wbuf */ 566 + if (ret) 567 + ret = __jffs2_flush_wbuf(c, PAD_ACCOUNTING); 573 568 up_write(&c->wbuf_sem); 574 569 break; 575 570 } ··· 591 578 { 592 579 int ret; 593 580 581 + if (!c->wbuf) 582 + return 0; 583 + 594 584 down_write(&c->wbuf_sem); 595 585 ret = __jffs2_flush_wbuf(c, PAD_NOACCOUNT); 586 + /* retry - maybe wbuf recover left some data in wbuf. */ 587 + if (ret) 588 + ret = __jffs2_flush_wbuf(c, PAD_NOACCOUNT); 596 589 up_write(&c->wbuf_sem); 597 590 598 591 return ret; 599 592 } 600 593 594 + #ifdef CONFIG_JFFS2_FS_WRITEBUFFER 595 + #define PAGE_DIV(x) ( ((unsigned long)(x) / (unsigned long)(c->wbuf_pagesize)) * (unsigned long)(c->wbuf_pagesize) ) 596 + #define PAGE_MOD(x) ( (unsigned long)(x) % (unsigned long)(c->wbuf_pagesize) ) 597 + #else 601 598 #define PAGE_DIV(x) ( (x) & (~(c->wbuf_pagesize - 1)) ) 602 599 #define PAGE_MOD(x) ( (x) & (c->wbuf_pagesize - 1) ) 600 + #endif 601 + 603 602 int jffs2_flash_writev(struct jffs2_sb_info *c, const struct kvec *invecs, unsigned long count, loff_t to, size_t *retlen, uint32_t ino) 604 603 { 605 604 struct kvec outvecs[3]; ··· 626 601 uint32_t outvec_to = to; 627 602 628 603 /* If not NAND flash, don't bother */ 629 - if (!c->wbuf) 604 + if (!jffs2_is_writebuffered(c)) 630 605 return jffs2_flash_direct_writev(c, invecs, count, to, retlen); 631 606 632 607 down_write(&c->wbuf_sem); ··· 655 630 erase block. Anything else, and you die. 656 631 New block starts at xxx000c (0-b = block header) 657 632 */ 658 - if ( (to & ~(c->sector_size-1)) != (c->wbuf_ofs & ~(c->sector_size-1)) ) { 633 + if (SECTOR_ADDR(to) != SECTOR_ADDR(c->wbuf_ofs)) { 659 634 /* It's a write to a new block */ 660 635 if (c->wbuf_len) { 661 636 D1(printk(KERN_DEBUG "jffs2_flash_writev() to 0x%lx causes flush of wbuf at 0x%08x\n", (unsigned long)to, c->wbuf_ofs)); ··· 787 762 788 763 if (ret < 0 || wbuf_retlen != PAGE_DIV(totlen)) { 789 764 /* At this point we have no problem, 790 - c->wbuf is empty. 765 + c->wbuf is empty. However refile nextblock to avoid 766 + writing again to same address. 791 767 */ 792 - *retlen = donelen; 768 + struct jffs2_eraseblock *jeb; 769 + 770 + spin_lock(&c->erase_completion_lock); 771 + 772 + jeb = &c->blocks[outvec_to / c->sector_size]; 773 + jffs2_block_refile(c, jeb, REFILE_ANYWAY); 774 + 775 + *retlen = 0; 776 + spin_unlock(&c->erase_completion_lock); 793 777 goto exit; 794 778 } 795 779 ··· 853 819 { 854 820 struct kvec vecs[1]; 855 821 856 - if (jffs2_can_mark_obsolete(c)) 822 + if (!jffs2_is_writebuffered(c)) 857 823 return c->mtd->write(c->mtd, ofs, len, retlen, buf); 858 824 859 825 vecs[0].iov_base = (unsigned char *) buf; ··· 869 835 loff_t orbf = 0, owbf = 0, lwbf = 0; 870 836 int ret; 871 837 872 - /* Read flash */ 873 - if (!jffs2_can_mark_obsolete(c)) { 874 - down_read(&c->wbuf_sem); 875 - 876 - if (jffs2_cleanmarker_oob(c)) 877 - ret = c->mtd->read_ecc(c->mtd, ofs, len, retlen, buf, NULL, c->oobinfo); 878 - else 879 - ret = c->mtd->read(c->mtd, ofs, len, retlen, buf); 880 - 881 - if ( (ret == -EBADMSG) && (*retlen == len) ) { 882 - printk(KERN_WARNING "mtd->read(0x%zx bytes from 0x%llx) returned ECC error\n", 883 - len, ofs); 884 - /* 885 - * We have the raw data without ECC correction in the buffer, maybe 886 - * we are lucky and all data or parts are correct. We check the node. 887 - * If data are corrupted node check will sort it out. 888 - * We keep this block, it will fail on write or erase and the we 889 - * mark it bad. Or should we do that now? But we should give him a chance. 890 - * Maybe we had a system crash or power loss before the ecc write or 891 - * a erase was completed. 892 - * So we return success. :) 893 - */ 894 - ret = 0; 895 - } 896 - } else 838 + if (!jffs2_is_writebuffered(c)) 897 839 return c->mtd->read(c->mtd, ofs, len, retlen, buf); 840 + 841 + /* Read flash */ 842 + down_read(&c->wbuf_sem); 843 + if (jffs2_cleanmarker_oob(c)) 844 + ret = c->mtd->read_ecc(c->mtd, ofs, len, retlen, buf, NULL, c->oobinfo); 845 + else 846 + ret = c->mtd->read(c->mtd, ofs, len, retlen, buf); 847 + 848 + if ( (ret == -EBADMSG) && (*retlen == len) ) { 849 + printk(KERN_WARNING "mtd->read(0x%zx bytes from 0x%llx) returned ECC error\n", 850 + len, ofs); 851 + /* 852 + * We have the raw data without ECC correction in the buffer, maybe 853 + * we are lucky and all data or parts are correct. We check the node. 854 + * If data are corrupted node check will sort it out. 855 + * We keep this block, it will fail on write or erase and the we 856 + * mark it bad. Or should we do that now? But we should give him a chance. 857 + * Maybe we had a system crash or power loss before the ecc write or 858 + * a erase was completed. 859 + * So we return success. :) 860 + */ 861 + ret = 0; 862 + } 898 863 899 864 /* if no writebuffer available or write buffer empty, return */ 900 865 if (!c->wbuf_pagesize || !c->wbuf_len) 901 866 goto exit; 902 867 903 868 /* if we read in a different block, return */ 904 - if ( (ofs & ~(c->sector_size-1)) != (c->wbuf_ofs & ~(c->sector_size-1)) ) 869 + if (SECTOR_ADDR(ofs) != SECTOR_ADDR(c->wbuf_ofs)) 905 870 goto exit; 906 871 907 872 if (ofs >= c->wbuf_ofs) { ··· 1194 1161 kfree(c->wbuf); 1195 1162 } 1196 1163 1197 - #ifdef CONFIG_JFFS2_FS_NOR_ECC 1164 + int jffs2_dataflash_setup(struct jffs2_sb_info *c) { 1165 + c->cleanmarker_size = 0; /* No cleanmarkers needed */ 1166 + 1167 + /* Initialize write buffer */ 1168 + init_rwsem(&c->wbuf_sem); 1169 + c->wbuf_pagesize = c->sector_size; 1170 + c->wbuf_ofs = 0xFFFFFFFF; 1171 + 1172 + c->wbuf = kmalloc(c->wbuf_pagesize, GFP_KERNEL); 1173 + if (!c->wbuf) 1174 + return -ENOMEM; 1175 + 1176 + printk(KERN_INFO "JFFS2 write-buffering enabled (%i)\n", c->wbuf_pagesize); 1177 + 1178 + return 0; 1179 + } 1180 + 1181 + void jffs2_dataflash_cleanup(struct jffs2_sb_info *c) { 1182 + kfree(c->wbuf); 1183 + } 1184 + 1198 1185 int jffs2_nor_ecc_flash_setup(struct jffs2_sb_info *c) { 1199 1186 /* Cleanmarker is actually larger on the flashes */ 1200 1187 c->cleanmarker_size = 16; ··· 1234 1181 void jffs2_nor_ecc_flash_cleanup(struct jffs2_sb_info *c) { 1235 1182 kfree(c->wbuf); 1236 1183 } 1237 - #endif
+38 -17
fs/jffs2/write.c
··· 7 7 * 8 8 * For licensing information, see the file 'LICENCE' in this directory. 9 9 * 10 - * $Id: write.c,v 1.87 2004/11/16 20:36:12 dwmw2 Exp $ 10 + * $Id: write.c,v 1.92 2005/04/13 13:22:35 dwmw2 Exp $ 11 11 * 12 12 */ 13 13 ··· 35 35 f->inocache = ic; 36 36 f->inocache->nlink = 1; 37 37 f->inocache->nodes = (struct jffs2_raw_node_ref *)f->inocache; 38 - f->inocache->ino = ++c->highest_ino; 39 38 f->inocache->state = INO_STATE_PRESENT; 40 39 41 - ri->ino = cpu_to_je32(f->inocache->ino); 42 40 43 - D1(printk(KERN_DEBUG "jffs2_do_new_inode(): Assigned ino# %d\n", f->inocache->ino)); 44 41 jffs2_add_ino_cache(c, f->inocache); 42 + D1(printk(KERN_DEBUG "jffs2_do_new_inode(): Assigned ino# %d\n", f->inocache->ino)); 43 + ri->ino = cpu_to_je32(f->inocache->ino); 45 44 46 45 ri->magic = cpu_to_je16(JFFS2_MAGIC_BITMASK); 47 46 ri->nodetype = cpu_to_je16(JFFS2_NODETYPE_INODE); ··· 134 135 raw->flash_offset = flash_ofs; 135 136 raw->__totlen = PAD(sizeof(*ri)+datalen); 136 137 raw->next_phys = NULL; 138 + 139 + if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(ri->version) < f->highest_version)) { 140 + BUG_ON(!retried); 141 + D1(printk(KERN_DEBUG "jffs2_write_dnode : dnode_version %d, " 142 + "highest version %d -> updating dnode\n", 143 + je32_to_cpu(ri->version), f->highest_version)); 144 + ri->version = cpu_to_je32(++f->highest_version); 145 + ri->node_crc = cpu_to_je32(crc32(0, ri, sizeof(*ri)-8)); 146 + } 137 147 138 148 ret = jffs2_flash_writev(c, vecs, cnt, flash_ofs, &retlen, 139 149 (alloc_mode==ALLOC_GC)?0:f->inocache->ino); ··· 287 279 raw->flash_offset = flash_ofs; 288 280 raw->__totlen = PAD(sizeof(*rd)+namelen); 289 281 raw->next_phys = NULL; 282 + 283 + if ((alloc_mode!=ALLOC_GC) && (je32_to_cpu(rd->version) < f->highest_version)) { 284 + BUG_ON(!retried); 285 + D1(printk(KERN_DEBUG "jffs2_write_dirent : dirent_version %d, " 286 + "highest version %d -> updating dirent\n", 287 + je32_to_cpu(rd->version), f->highest_version)); 288 + rd->version = cpu_to_je32(++f->highest_version); 289 + fd->version = je32_to_cpu(rd->version); 290 + rd->node_crc = cpu_to_je32(crc32(0, rd, sizeof(*rd)-8)); 291 + } 290 292 291 293 ret = jffs2_flash_writev(c, vecs, 2, flash_ofs, &retlen, 292 294 (alloc_mode==ALLOC_GC)?0:je32_to_cpu(rd->pino)); ··· 643 625 644 626 down(&dead_f->sem); 645 627 646 - while (dead_f->dents) { 647 - /* There can be only deleted ones */ 648 - fd = dead_f->dents; 649 - 650 - dead_f->dents = fd->next; 651 - 652 - if (fd->ino) { 653 - printk(KERN_WARNING "Deleting inode #%u with active dentry \"%s\"->ino #%u\n", 654 - dead_f->inocache->ino, fd->name, fd->ino); 655 - } else { 656 - D1(printk(KERN_DEBUG "Removing deletion dirent for \"%s\" from dir ino #%u\n", fd->name, dead_f->inocache->ino)); 628 + if (S_ISDIR(OFNI_EDONI_2SFFJ(dead_f)->i_mode)) { 629 + while (dead_f->dents) { 630 + /* There can be only deleted ones */ 631 + fd = dead_f->dents; 632 + 633 + dead_f->dents = fd->next; 634 + 635 + if (fd->ino) { 636 + printk(KERN_WARNING "Deleting inode #%u with active dentry \"%s\"->ino #%u\n", 637 + dead_f->inocache->ino, fd->name, fd->ino); 638 + } else { 639 + D1(printk(KERN_DEBUG "Removing deletion dirent for \"%s\" from dir ino #%u\n", 640 + fd->name, dead_f->inocache->ino)); 641 + } 642 + jffs2_mark_node_obsolete(c, fd->raw); 643 + jffs2_free_full_dirent(fd); 657 644 } 658 - jffs2_mark_node_obsolete(c, fd->raw); 659 - jffs2_free_full_dirent(fd); 660 645 } 661 646 662 647 dead_f->inocache->nlink--;
+37
include/asm-arm/arch-pxa/mtd-xip.h
··· 1 + /* 2 + * MTD primitives for XIP support. Architecture specific functions 3 + * 4 + * Do not include this file directly. It's included from linux/mtd/xip.h 5 + * 6 + * Author: Nicolas Pitre 7 + * Created: Nov 2, 2004 8 + * Copyright: (C) 2004 MontaVista Software, Inc. 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License version 2 as 12 + * published by the Free Software Foundation. 13 + * 14 + * $Id: xip.h,v 1.2 2004/12/01 15:49:10 nico Exp $ 15 + */ 16 + 17 + #ifndef __ARCH_PXA_MTD_XIP_H__ 18 + #define __ARCH_PXA_MTD_XIP_H__ 19 + 20 + #include <asm/arch/pxa-regs.h> 21 + 22 + #define xip_irqpending() (ICIP & ICMR) 23 + 24 + /* we sample OSCR and convert desired delta to usec (1/4 ~= 1000000/3686400) */ 25 + #define xip_currtime() (OSCR) 26 + #define xip_elapsed_since(x) (signed)((OSCR - (x)) / 4) 27 + 28 + /* 29 + * xip_cpu_idle() is used when waiting for a delay equal or larger than 30 + * the system timer tick period. This should put the CPU into idle mode 31 + * to save power and to be woken up only when some interrupts are pending. 32 + * As above, this should not rely upon standard kernel code. 33 + */ 34 + 35 + #define xip_cpu_idle() asm volatile ("mcr p14, 0, %0, c7, c0, 0" :: "r" (1)) 36 + 37 + #endif /* __ARCH_PXA_MTD_XIP_H__ */
+26
include/asm-arm/arch-sa1100/mtd-xip.h
··· 1 + /* 2 + * MTD primitives for XIP support. Architecture specific functions 3 + * 4 + * Do not include this file directly. It's included from linux/mtd/xip.h 5 + * 6 + * Author: Nicolas Pitre 7 + * Created: Nov 2, 2004 8 + * Copyright: (C) 2004 MontaVista Software, Inc. 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License version 2 as 12 + * published by the Free Software Foundation. 13 + * 14 + * $Id: xip.h,v 1.2 2004/12/01 15:49:10 nico Exp $ 15 + */ 16 + 17 + #ifndef __ARCH_SA1100_MTD_XIP_H__ 18 + #define __ARCH_SA1100_MTD_XIP_H__ 19 + 20 + #define xip_irqpending() (ICIP & ICMR) 21 + 22 + /* we sample OSCR and convert desired delta to usec (1/4 ~= 1000000/3686400) */ 23 + #define xip_currtime() (OSCR) 24 + #define xip_elapsed_since(x) (signed)((OSCR - (x)) / 4) 25 + 26 + #endif /* __ARCH_SA1100_MTD_XIP_H__ */
+26
include/asm-arm/mtd-xip.h
··· 1 + /* 2 + * MTD primitives for XIP support. Architecture specific functions 3 + * 4 + * Do not include this file directly. It's included from linux/mtd/xip.h 5 + * 6 + * Author: Nicolas Pitre 7 + * Created: Nov 2, 2004 8 + * Copyright: (C) 2004 MontaVista Software, Inc. 9 + * 10 + * This program is free software; you can redistribute it and/or modify 11 + * it under the terms of the GNU General Public License version 2 as 12 + * published by the Free Software Foundation. 13 + * 14 + * $Id: xip.h,v 1.2 2004/12/01 15:49:10 nico Exp $ 15 + */ 16 + 17 + #ifndef __ARM_MTD_XIP_H__ 18 + #define __ARM_MTD_XIP_H__ 19 + 20 + #include <asm/hardware.h> 21 + #include <asm/arch/mtd-xip.h> 22 + 23 + /* fill instruction prefetch */ 24 + #define xip_iprefetch() do { asm volatile (".rep 8; nop; .endr"); } while (0) 25 + 26 + #endif /* __ARM_MTD_XIP_H__ */
+5 -4
include/linux/jffs2_fs_sb.h
··· 1 - /* $Id: jffs2_fs_sb.h,v 1.48 2004/11/20 10:41:12 dwmw2 Exp $ */ 1 + /* $Id: jffs2_fs_sb.h,v 1.52 2005/05/19 16:12:17 gleixner Exp $ */ 2 2 3 3 #ifndef _JFFS2_FS_SB 4 4 #define _JFFS2_FS_SB ··· 14 14 #include <linux/rwsem.h> 15 15 16 16 #define JFFS2_SB_FLAG_RO 1 17 - #define JFFS2_SB_FLAG_MOUNTING 2 17 + #define JFFS2_SB_FLAG_SCANNING 2 /* Flash scanning is in progress */ 18 + #define JFFS2_SB_FLAG_BUILDING 4 /* File system building is in progress */ 18 19 19 20 struct jffs2_inodirty; 20 21 ··· 32 31 unsigned int flags; 33 32 34 33 struct task_struct *gc_task; /* GC task struct */ 35 - struct semaphore gc_thread_start; /* GC thread start mutex */ 34 + struct completion gc_thread_start; /* GC thread start completion */ 36 35 struct completion gc_thread_exit; /* GC thread exit completion port */ 37 36 38 37 struct semaphore alloc_sem; /* Used to protect all the following ··· 95 94 to an obsoleted node. I don't like this. Alternatives welcomed. */ 96 95 struct semaphore erase_free_sem; 97 96 98 - #if defined CONFIG_JFFS2_FS_NAND || defined CONFIG_JFFS2_FS_NOR_ECC 97 + #ifdef CONFIG_JFFS2_FS_WRITEBUFFER 99 98 /* Write-behind buffer for NAND flash */ 100 99 unsigned char *wbuf; 101 100 uint32_t wbuf_ofs;
+73 -12
include/linux/mtd/cfi.h
··· 1 1 2 2 /* Common Flash Interface structures 3 3 * See http://support.intel.com/design/flash/technote/index.htm 4 - * $Id: cfi.h,v 1.50 2004/11/20 12:46:51 dwmw2 Exp $ 4 + * $Id: cfi.h,v 1.54 2005/06/06 23:04:36 tpoynor Exp $ 5 5 */ 6 6 7 7 #ifndef __MTD_CFI_H__ ··· 148 148 uint8_t extra[0]; 149 149 } __attribute__((packed)); 150 150 151 + struct cfi_intelext_otpinfo { 152 + uint32_t ProtRegAddr; 153 + uint16_t FactGroups; 154 + uint8_t FactProtRegSize; 155 + uint16_t UserGroups; 156 + uint8_t UserProtRegSize; 157 + } __attribute__((packed)); 158 + 151 159 struct cfi_intelext_blockinfo { 152 160 uint16_t NumIdentBlocks; 153 161 uint16_t BlockSize; ··· 252 244 * It looks too long to be inline, but in the common case it should almost all 253 245 * get optimised away. 254 246 */ 255 - static inline map_word cfi_build_cmd(u_char cmd, struct map_info *map, struct cfi_private *cfi) 247 + static inline map_word cfi_build_cmd(u_long cmd, struct map_info *map, struct cfi_private *cfi) 256 248 { 257 249 map_word val = { {0} }; 258 250 int wordwidth, words_per_bus, chip_mode, chips_per_word; ··· 315 307 } 316 308 #define CMD(x) cfi_build_cmd((x), map, cfi) 317 309 310 + 311 + static inline unsigned char cfi_merge_status(map_word val, struct map_info *map, 312 + struct cfi_private *cfi) 313 + { 314 + int wordwidth, words_per_bus, chip_mode, chips_per_word; 315 + unsigned long onestat, res = 0; 316 + int i; 317 + 318 + /* We do it this way to give the compiler a fighting chance 319 + of optimising away all the crap for 'bankwidth' larger than 320 + an unsigned long, in the common case where that support is 321 + disabled */ 322 + if (map_bankwidth_is_large(map)) { 323 + wordwidth = sizeof(unsigned long); 324 + words_per_bus = (map_bankwidth(map)) / wordwidth; // i.e. normally 1 325 + } else { 326 + wordwidth = map_bankwidth(map); 327 + words_per_bus = 1; 328 + } 329 + 330 + chip_mode = map_bankwidth(map) / cfi_interleave(cfi); 331 + chips_per_word = wordwidth * cfi_interleave(cfi) / map_bankwidth(map); 332 + 333 + onestat = val.x[0]; 334 + /* Or all status words together */ 335 + for (i=1; i < words_per_bus; i++) { 336 + onestat |= val.x[i]; 337 + } 338 + 339 + res = onestat; 340 + switch(chips_per_word) { 341 + default: BUG(); 342 + #if BITS_PER_LONG >= 64 343 + case 8: 344 + res |= (onestat >> (chip_mode * 32)); 345 + #endif 346 + case 4: 347 + res |= (onestat >> (chip_mode * 16)); 348 + case 2: 349 + res |= (onestat >> (chip_mode * 8)); 350 + case 1: 351 + ; 352 + } 353 + 354 + /* Last, determine what the bit-pattern should be for a single 355 + device, according to chip mode and endianness... */ 356 + switch (chip_mode) { 357 + case 1: 358 + break; 359 + case 2: 360 + res = cfi16_to_cpu(res); 361 + break; 362 + case 4: 363 + res = cfi32_to_cpu(res); 364 + break; 365 + default: BUG(); 366 + } 367 + return res; 368 + } 369 + 370 + #define MERGESTATUS(x) cfi_merge_status((x), map, cfi) 371 + 372 + 318 373 /* 319 374 * Sends a CFI command to a bank of flash for the given geometry. 320 375 * ··· 426 355 udelay(us); 427 356 cond_resched(); 428 357 } 429 - } 430 - 431 - static inline void cfi_spin_lock(spinlock_t *mutex) 432 - { 433 - spin_lock_bh(mutex); 434 - } 435 - 436 - static inline void cfi_spin_unlock(spinlock_t *mutex) 437 - { 438 - spin_unlock_bh(mutex); 439 358 } 440 359 441 360 struct cfi_extquery *cfi_read_pri(struct map_info *map, uint16_t adr, uint16_t size,
+4 -3
include/linux/mtd/flashchip.h
··· 6 6 * 7 7 * (C) 2000 Red Hat. GPLd. 8 8 * 9 - * $Id: flashchip.h,v 1.15 2004/11/05 22:41:06 nico Exp $ 9 + * $Id: flashchip.h,v 1.17 2005/03/14 18:27:15 bjd Exp $ 10 10 * 11 11 */ 12 12 ··· 29 29 FL_ERASE_SUSPENDED, 30 30 FL_WRITING, 31 31 FL_WRITING_TO_BUFFER, 32 + FL_OTP_WRITE, 32 33 FL_WRITE_SUSPENDING, 33 34 FL_WRITE_SUSPENDED, 34 35 FL_PM_SUSPENDED, ··· 63 62 flstate_t state; 64 63 flstate_t oldstate; 65 64 66 - int write_suspended:1; 67 - int erase_suspended:1; 65 + unsigned int write_suspended:1; 66 + unsigned int erase_suspended:1; 68 67 unsigned long in_progress_block_addr; 69 68 70 69 spinlock_t *mutex;
+2 -2
include/linux/mtd/inftl.h
··· 3 3 * 4 4 * (C) Copyright 2002, Greg Ungerer (gerg@snapgear.com) 5 5 * 6 - * $Id: inftl.h,v 1.6 2004/06/30 14:49:00 dbrown Exp $ 6 + * $Id: inftl.h,v 1.7 2005/06/13 13:08:45 sean Exp $ 7 7 */ 8 8 9 9 #ifndef __MTD_INFTL_H__ ··· 20 20 #include <mtd/inftl-user.h> 21 21 22 22 #ifndef INFTL_MAJOR 23 - #define INFTL_MAJOR 94 23 + #define INFTL_MAJOR 96 24 24 #endif 25 25 #define INFTL_PARTN_BITS 4 26 26
+28 -5
include/linux/mtd/map.h
··· 1 1 2 2 /* Overhauled routines for dealing with different mmap regions of flash */ 3 - /* $Id: map.h,v 1.46 2005/01/05 17:09:44 dwmw2 Exp $ */ 3 + /* $Id: map.h,v 1.52 2005/05/25 10:29:41 gleixner Exp $ */ 4 4 5 5 #ifndef __LINUX_MTD_MAP_H__ 6 6 #define __LINUX_MTD_MAP_H__ ··· 263 263 return r; 264 264 } 265 265 266 + static inline map_word map_word_clr(struct map_info *map, map_word val1, map_word val2) 267 + { 268 + map_word r; 269 + int i; 270 + 271 + for (i=0; i<map_words(map); i++) { 272 + r.x[i] = val1.x[i] & ~val2.x[i]; 273 + } 274 + return r; 275 + } 276 + 266 277 static inline map_word map_word_or(struct map_info *map, map_word val1, map_word val2) 267 278 { 268 279 map_word r; ··· 284 273 } 285 274 return r; 286 275 } 276 + 287 277 #define map_word_andequal(m, a, b, z) map_word_equal(m, z, map_word_and(m, a, b)) 288 278 289 279 static inline int map_word_bitsset(struct map_info *map, map_word val1, map_word val2) ··· 340 328 return orig; 341 329 } 342 330 331 + #if BITS_PER_LONG < 64 332 + #define MAP_FF_LIMIT 4 333 + #else 334 + #define MAP_FF_LIMIT 8 335 + #endif 336 + 343 337 static inline map_word map_word_ff(struct map_info *map) 344 338 { 345 339 map_word r; 346 340 int i; 347 - 348 - for (i=0; i<map_words(map); i++) { 349 - r.x[i] = ~0UL; 341 + 342 + if (map_bankwidth(map) < MAP_FF_LIMIT) { 343 + int bw = 8 * map_bankwidth(map); 344 + r.x[0] = (1 << bw) - 1; 345 + } else { 346 + for (i=0; i<map_words(map); i++) 347 + r.x[i] = ~0UL; 350 348 } 351 349 return r; 352 350 } 351 + 353 352 static inline map_word inline_map_read(struct map_info *map, unsigned long ofs) 354 353 { 355 354 map_word r; ··· 428 405 429 406 430 407 #define simple_map_init(map) BUG_ON(!map_bankwidth_supported((map)->bankwidth)) 431 - #define map_is_linear(map) (1) 408 + #define map_is_linear(map) ({ (void)(map); 1; }) 432 409 433 410 #endif /* !CONFIG_MTD_COMPLEX_MAPPINGS */ 434 411
+9 -6
include/linux/mtd/mtd.h
··· 1 1 /* 2 - * $Id: mtd.h,v 1.56 2004/08/09 18:46:04 dmarlin Exp $ 2 + * $Id: mtd.h,v 1.59 2005/04/11 10:19:02 gleixner Exp $ 3 3 * 4 4 * Copyright (C) 1999-2003 David Woodhouse <dwmw2@infradead.org> et al. 5 5 * ··· 18 18 #include <linux/types.h> 19 19 #include <linux/module.h> 20 20 #include <linux/uio.h> 21 + #include <linux/notifier.h> 21 22 22 23 #include <linux/mtd/compatmac.h> 23 24 #include <mtd/mtd-abi.h> ··· 70 69 71 70 u_int32_t oobblock; // Size of OOB blocks (e.g. 512) 72 71 u_int32_t oobsize; // Amount of OOB data per block (e.g. 16) 73 - u_int32_t oobavail; // Number of bytes in OOB area available for fs 74 72 u_int32_t ecctype; 75 73 u_int32_t eccsize; 76 74 ··· 80 80 81 81 // oobinfo is a nand_oobinfo structure, which can be set by iotcl (MEMSETOOBINFO) 82 82 struct nand_oobinfo oobinfo; 83 + u_int32_t oobavail; // Number of bytes in OOB area available for fs 83 84 84 85 /* Data for variable erase regions. If numeraseregions is zero, 85 86 * it means that the whole device has erasesize as given above. ··· 114 113 * flash devices. The user data is one time programmable but the 115 114 * factory data is read only. 116 115 */ 117 - int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); 118 - 116 + int (*get_fact_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len); 119 117 int (*read_fact_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); 120 - 121 - /* This function is not yet implemented */ 118 + int (*get_user_prot_info) (struct mtd_info *mtd, struct otp_info *buf, size_t len); 119 + int (*read_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); 122 120 int (*write_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf); 121 + int (*lock_user_prot_reg) (struct mtd_info *mtd, loff_t from, size_t len); 123 122 124 123 /* kvec-based read/write methods. We need these especially for NAND flash, 125 124 with its limited number of write cycles per erase. ··· 147 146 /* Bad block management functions */ 148 147 int (*block_isbad) (struct mtd_info *mtd, loff_t ofs); 149 148 int (*block_markbad) (struct mtd_info *mtd, loff_t ofs); 149 + 150 + struct notifier_block reboot_notifier; /* default mode before reboot */ 150 151 151 152 void *priv; 152 153
+45 -3
include/linux/mtd/nand.h
··· 5 5 * Steven J. Hill <sjhill@realitydiluted.com> 6 6 * Thomas Gleixner <tglx@linutronix.de> 7 7 * 8 - * $Id: nand.h,v 1.68 2004/11/12 10:40:37 gleixner Exp $ 8 + * $Id: nand.h,v 1.73 2005/05/31 19:39:17 gleixner Exp $ 9 9 * 10 10 * This program is free software; you can redistribute it and/or modify 11 11 * it under the terms of the GNU General Public License version 2 as ··· 48 48 * 02-08-2004 tglx added option field to nand structure for chip anomalities 49 49 * 05-25-2004 tglx added bad block table support, ST-MICRO manufacturer id 50 50 * update of nand_chip structure description 51 + * 01-17-2005 dmarlin added extended commands for AG-AND device and added option 52 + * for BBT_AUTO_REFRESH. 53 + * 01-20-2005 dmarlin added optional pointer to hardware specific callback for 54 + * extra error status checks. 51 55 */ 52 56 #ifndef __LINUX_MTD_NAND_H 53 57 #define __LINUX_MTD_NAND_H ··· 119 115 #define NAND_CMD_READSTART 0x30 120 116 #define NAND_CMD_CACHEDPROG 0x15 121 117 118 + /* Extended commands for AG-AND device */ 119 + /* 120 + * Note: the command for NAND_CMD_DEPLETE1 is really 0x00 but 121 + * there is no way to distinguish that from NAND_CMD_READ0 122 + * until the remaining sequence of commands has been completed 123 + * so add a high order bit and mask it off in the command. 124 + */ 125 + #define NAND_CMD_DEPLETE1 0x100 126 + #define NAND_CMD_DEPLETE2 0x38 127 + #define NAND_CMD_STATUS_MULTI 0x71 128 + #define NAND_CMD_STATUS_ERROR 0x72 129 + /* multi-bank error status (banks 0-3) */ 130 + #define NAND_CMD_STATUS_ERROR0 0x73 131 + #define NAND_CMD_STATUS_ERROR1 0x74 132 + #define NAND_CMD_STATUS_ERROR2 0x75 133 + #define NAND_CMD_STATUS_ERROR3 0x76 134 + #define NAND_CMD_STATUS_RESET 0x7f 135 + #define NAND_CMD_STATUS_CLEAR 0xff 136 + 122 137 /* Status bits */ 123 138 #define NAND_STATUS_FAIL 0x01 124 139 #define NAND_STATUS_FAIL_N1 0x02 ··· 166 143 167 144 /* 168 145 * Constants for Hardware ECC 169 - */ 146 + */ 170 147 /* Reset Hardware ECC for read */ 171 148 #define NAND_ECC_READ 0 172 149 /* Reset Hardware ECC for write */ 173 150 #define NAND_ECC_WRITE 1 174 151 /* Enable Hardware ECC before syndrom is read back from flash */ 175 152 #define NAND_ECC_READSYN 2 153 + 154 + /* Bit mask for flags passed to do_nand_read_ecc */ 155 + #define NAND_GET_DEVICE 0x80 156 + 176 157 177 158 /* Option constants for bizarre disfunctionality and real 178 159 * features ··· 197 170 /* Chip has a array of 4 pages which can be read without 198 171 * additional ready /busy waits */ 199 172 #define NAND_4PAGE_ARRAY 0x00000040 173 + /* Chip requires that BBT is periodically rewritten to prevent 174 + * bits from adjacent blocks from 'leaking' in altering data. 175 + * This happens with the Renesas AG-AND chips, possibly others. */ 176 + #define BBT_AUTO_REFRESH 0x00000080 200 177 201 178 /* Options valid for Samsung large page devices */ 202 179 #define NAND_SAMSUNG_LP_OPTIONS \ ··· 223 192 * This can only work if we have the ecc bytes directly behind the 224 193 * data bytes. Applies for DOC and AG-AND Renesas HW Reed Solomon generators */ 225 194 #define NAND_HWECC_SYNDROME 0x00020000 226 - 195 + /* This option skips the bbt scan during initialization. */ 196 + #define NAND_SKIP_BBTSCAN 0x00040000 227 197 228 198 /* Options set by nand scan */ 229 199 /* Nand scan has allocated oob_buf */ ··· 253 221 * struct nand_hw_control - Control structure for hardware controller (e.g ECC generator) shared among independend devices 254 222 * @lock: protection lock 255 223 * @active: the mtd device which holds the controller currently 224 + * @wq: wait queue to sleep on if a NAND operation is in progress 225 + * used instead of the per chip wait queue when a hw controller is available 256 226 */ 257 227 struct nand_hw_control { 258 228 spinlock_t lock; 259 229 struct nand_chip *active; 230 + wait_queue_head_t wq; 260 231 }; 261 232 262 233 /** ··· 318 283 * @badblock_pattern: [REPLACEABLE] bad block scan pattern used for initial bad block scan 319 284 * @controller: [OPTIONAL] a pointer to a hardware controller structure which is shared among multiple independend devices 320 285 * @priv: [OPTIONAL] pointer to private chip date 286 + * @errstat: [OPTIONAL] hardware specific function to perform additional error status checks 287 + * (determine if errors are correctable) 321 288 */ 322 289 323 290 struct nand_chip { ··· 375 338 struct nand_bbt_descr *badblock_pattern; 376 339 struct nand_hw_control *controller; 377 340 void *priv; 341 + int (*errstat)(struct mtd_info *mtd, struct nand_chip *this, int state, int status, int page); 378 342 }; 379 343 380 344 /* ··· 387 349 #define NAND_MFR_NATIONAL 0x8f 388 350 #define NAND_MFR_RENESAS 0x07 389 351 #define NAND_MFR_STMICRO 0x20 352 + #define NAND_MFR_HYNIX 0xad 390 353 391 354 /** 392 355 * struct nand_flash_dev - NAND Flash Device ID Structure ··· 498 459 extern int nand_default_bbt (struct mtd_info *mtd); 499 460 extern int nand_isbad_bbt (struct mtd_info *mtd, loff_t offs, int allowbbt); 500 461 extern int nand_erase_nand (struct mtd_info *mtd, struct erase_info *instr, int allowbbt); 462 + extern int nand_do_read_ecc (struct mtd_info *mtd, loff_t from, size_t len, 463 + size_t * retlen, u_char * buf, u_char * oob_buf, 464 + struct nand_oobinfo *oobsel, int flags); 501 465 502 466 /* 503 467 * Constants for oob configuration
+35
include/linux/mtd/plat-ram.h
··· 1 + /* linux/include/mtd/plat-ram.h 2 + * 3 + * (c) 2004 Simtec Electronics 4 + * http://www.simtec.co.uk/products/SWLINUX/ 5 + * Ben Dooks <ben@simtec.co.uk> 6 + * 7 + * Generic platform device based RAM map 8 + * 9 + * $Id: plat-ram.h,v 1.2 2005/01/24 00:37:40 bjd Exp $ 10 + * 11 + * This program is free software; you can redistribute it and/or modify 12 + * it under the terms of the GNU General Public License version 2 as 13 + * published by the Free Software Foundation. 14 + * 15 + */ 16 + 17 + #ifndef __LINUX_MTD_PLATRAM_H 18 + #define __LINUX_MTD_PLATRAM_H __FILE__ 19 + 20 + #define PLATRAM_RO (0) 21 + #define PLATRAM_RW (1) 22 + 23 + struct platdata_mtd_ram { 24 + char *mapname; 25 + char **probes; 26 + struct mtd_partition *partitions; 27 + int nr_partitions; 28 + int bankwidth; 29 + 30 + /* control callbacks */ 31 + 32 + void (*set_rw)(struct device *dev, int to); 33 + }; 34 + 35 + #endif /* __LINUX_MTD_PLATRAM_H */
+13 -18
include/linux/mtd/xip.h
··· 58 58 * returned value is <= the real elapsed time. 59 59 * note 2: this should be able to cope with a few seconds without 60 60 * overflowing. 61 + * 62 + * xip_iprefetch() 63 + * 64 + * Macro to fill instruction prefetch 65 + * e.g. a series of nops: asm volatile (".rep 8; nop; .endr"); 61 66 */ 62 67 63 - #if defined(CONFIG_ARCH_SA1100) || defined(CONFIG_ARCH_PXA) 68 + #include <asm/mtd-xip.h> 64 69 65 - #include <asm/hardware.h> 66 - #ifdef CONFIG_ARCH_PXA 67 - #include <asm/arch/pxa-regs.h> 68 - #endif 69 - 70 - #define xip_irqpending() (ICIP & ICMR) 71 - 72 - /* we sample OSCR and convert desired delta to usec (1/4 ~= 1000000/3686400) */ 73 - #define xip_currtime() (OSCR) 74 - #define xip_elapsed_since(x) (signed)((OSCR - (x)) / 4) 75 - 76 - #else 70 + #ifndef xip_irqpending 77 71 78 72 #warning "missing IRQ and timer primitives for XIP MTD support" 79 73 #warning "some of the XIP MTD support code will be disabled" ··· 79 85 80 86 #endif 81 87 88 + #ifndef xip_iprefetch 89 + #define xip_iprefetch() do { } while (0) 90 + #endif 91 + 82 92 /* 83 93 * xip_cpu_idle() is used when waiting for a delay equal or larger than 84 94 * the system timer tick period. This should put the CPU into idle mode 85 95 * to save power and to be woken up only when some interrupts are pending. 86 - * As above, this should not rely upon standard kernel code. 96 + * This should not rely upon standard kernel code. 87 97 */ 88 - 89 - #if defined(CONFIG_CPU_XSCALE) 90 - #define xip_cpu_idle() asm volatile ("mcr p14, 0, %0, c7, c0, 0" :: "r" (1)) 91 - #else 98 + #ifndef xip_cpu_idle 92 99 #define xip_cpu_idle() do { } while (0) 93 100 #endif 94 101
+18 -1
include/mtd/mtd-abi.h
··· 1 1 /* 2 - * $Id: mtd-abi.h,v 1.7 2004/11/23 15:37:32 gleixner Exp $ 2 + * $Id: mtd-abi.h,v 1.11 2005/05/19 16:08:58 gleixner Exp $ 3 3 * 4 4 * Portions of MTD ABI definition which are shared by kernel and user space 5 5 */ ··· 29 29 #define MTD_NORFLASH 3 30 30 #define MTD_NANDFLASH 4 31 31 #define MTD_PEROM 5 32 + #define MTD_DATAFLASH 6 32 33 #define MTD_OTHER 14 33 34 #define MTD_UNKNOWN 15 34 35 ··· 61 60 #define MTD_NANDECC_PLACE 1 // Use the given placement in the structure (YAFFS1 legacy mode) 62 61 #define MTD_NANDECC_AUTOPLACE 2 // Use the default placement scheme 63 62 #define MTD_NANDECC_PLACEONLY 3 // Use the given placement in the structure (Do not store ecc result on read) 63 + #define MTD_NANDECC_AUTOPL_USR 4 // Use the given autoplacement scheme rather than using the default 64 + 65 + /* OTP mode selection */ 66 + #define MTD_OTP_OFF 0 67 + #define MTD_OTP_FACTORY 1 68 + #define MTD_OTP_USER 2 64 69 65 70 struct mtd_info_user { 66 71 uint8_t type; ··· 87 80 uint32_t regionindex; 88 81 }; 89 82 83 + struct otp_info { 84 + uint32_t start; 85 + uint32_t length; 86 + uint32_t locked; 87 + }; 88 + 90 89 #define MEMGETINFO _IOR('M', 1, struct mtd_info_user) 91 90 #define MEMERASE _IOW('M', 2, struct erase_info_user) 92 91 #define MEMWRITEOOB _IOWR('M', 3, struct mtd_oob_buf) ··· 105 92 #define MEMGETOOBSEL _IOR('M', 10, struct nand_oobinfo) 106 93 #define MEMGETBADBLOCK _IOW('M', 11, loff_t) 107 94 #define MEMSETBADBLOCK _IOW('M', 12, loff_t) 95 + #define OTPSELECT _IOR('M', 13, int) 96 + #define OTPGETREGIONCOUNT _IOW('M', 14, int) 97 + #define OTPGETREGIONINFO _IOW('M', 15, struct otp_info) 98 + #define OTPLOCK _IOR('M', 16, struct otp_info) 108 99 109 100 struct nand_oobinfo { 110 101 uint32_t useecc;