📄 cfi_cmdset_0001.c
字号:
return -EINVAL; /* can not point this region */ *retlen = 0; /* Now lock the chip(s) to POINT state */ /* ofs: offset within the first chip that the first read should start */ chipnum = (from >> cfi->chipshift); ofs = from - (chipnum << cfi->chipshift); while (len) { unsigned long thislen; if (chipnum >= cfi->numchips) break; if ((len + ofs -1) >> cfi->chipshift) thislen = (1<<cfi->chipshift) - ofs; else thislen = len; ret = do_point_onechip(map, &cfi->chips[chipnum], ofs, thislen); if (ret) break; *retlen += thislen; len -= thislen; ofs = 0; chipnum++; } return 0;}static void do_unpoint (struct mtd_info *mtd, u_char *addr, loff_t from, size_t len){ struct map_info *map = mtd->priv; struct cfi_private *cfi = map->fldrv_priv; unsigned long ofs; int chipnum; map->unpoint(map, addr, from, len); /* Now unlock the chip(s) POINT state */ /* ofs: offset within the first chip that the first read should start */ chipnum = (from >> cfi->chipshift); ofs = from - (chipnum << cfi->chipshift); while (len) { unsigned long thislen; struct flchip *chip; chip = &cfi->chips[chipnum]; if (chipnum >= cfi->numchips) break; if ((len + ofs -1) >> cfi->chipshift) thislen = (1<<cfi->chipshift) - ofs; else thislen = len; spin_lock(chip->mutex); if(chip->state == FL_POINT){ chip->ref_point_counter--; if(chip->ref_point_counter == 0) chip->state = FL_READY; } else printk("Warning: unpoint called on non pointed region\n"); /* Should this give an error? */ wake_up(&chip->wq); spin_unlock(chip->mutex); len -= thislen; ofs = 0; chipnum++; }}static inline int do_read_onechip(struct map_info *map, struct flchip *chip, loff_t adr, size_t len, u_char *buf){ cfi_word status, status_OK; unsigned long timeo; DECLARE_WAITQUEUE(wait, current); int suspended = 0; unsigned long cmd_addr; struct cfi_private *cfi = map->fldrv_priv; adr += chip->start; /* Ensure cmd read/writes are aligned. */ cmd_addr = adr & ~(CFIDEV_BUSWIDTH-1); /* Let's determine this according to the interleave only once */ status_OK = CMD(0x80); timeo = jiffies + HZ; retry: spin_lock(chip->mutex); /* Check that the chip's ready to talk to us. * If it's in FL_ERASING state, suspend it and make it talk now. */ switch (chip->state) { case FL_ERASING: if (!cfi->cmdset_priv || !(((struct cfi_pri_intelext *)cfi->cmdset_priv)->FeatureSupport & 2)) goto sleep; /* We don't support erase suspend */ cfi_write (map, CMD(0xb0), cmd_addr); /* If the flash has finished erasing, then 'erase suspend' * appears to make some (28F320) flash devices switch to * 'read' mode. Make sure that we switch to 'read status' * mode so we get the right data. --rmk */ cfi_write(map, CMD(0x70), cmd_addr); chip->oldstate = FL_ERASING; chip->state = FL_ERASE_SUSPENDING; // printk("Erase suspending at 0x%lx\n", cmd_addr); for (;;) { status = cfi_read(map, cmd_addr); if ((status & status_OK) == status_OK) break; if (time_after(jiffies, timeo)) { /* Urgh */ cfi_write(map, CMD(0xd0), cmd_addr); /* make sure we're in 'read status' mode */ cfi_write(map, CMD(0x70), cmd_addr); chip->state = FL_ERASING; spin_unlock(chip->mutex); printk(KERN_ERR "Chip not ready after erase " "suspended: status = 0x%llx\n", (__u64)status); return -EIO; } spin_unlock(chip->mutex); cfi_udelay(1); spin_lock(chip->mutex); } suspended = 1; cfi_write(map, CMD(0xff), cmd_addr); chip->state = FL_READY; break; #if 0 case FL_WRITING: /* Not quite yet */#endif case FL_READY: case FL_POINT: break; case FL_CFI_QUERY: case FL_JEDEC_QUERY: cfi_write(map, CMD(0x70), cmd_addr); chip->state = FL_STATUS; case FL_STATUS: status = cfi_read(map, cmd_addr); if ((status & status_OK) == status_OK) { cfi_write(map, CMD(0xff), cmd_addr); chip->state = FL_READY; break; } /* Urgh. Chip not yet ready to talk to us. */ if (time_after(jiffies, timeo)) { spin_unlock(chip->mutex); printk(KERN_ERR "waiting for chip to be ready timed out in read. WSM status = %llx\n", (__u64)status); return -EIO; } /* Latency issues. Drop the lock, wait a while and retry */ spin_unlock(chip->mutex); cfi_udelay(1); goto retry; default: sleep: /* Stick ourselves on a wait queue to be woken when someone changes the status */ set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&chip->wq, &wait); spin_unlock(chip->mutex); schedule(); remove_wait_queue(&chip->wq, &wait); timeo = jiffies + HZ; goto retry; } map->copy_from(map, buf, adr, len); if (suspended) { chip->state = chip->oldstate; /* What if one interleaved chip has finished and the other hasn't? The old code would leave the finished one in READY mode. That's bad, and caused -EROFS errors to be returned from do_erase_oneblock because that's the only bit it checked for at the time. As the state machine appears to explicitly allow sending the 0x70 (Read Status) command to an erasing chip and expecting it to be ignored, that's what we do. */ cfi_write(map, CMD(0xd0), cmd_addr); cfi_write(map, CMD(0x70), cmd_addr); } wake_up(&chip->wq); spin_unlock(chip->mutex); return 0;}static int cfi_intelext_read (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf){ struct map_info *map = mtd->priv; struct cfi_private *cfi = map->fldrv_priv; unsigned long ofs; int chipnum; int ret = 0; /* ofs: offset within the first chip that the first read should start */ chipnum = (from >> cfi->chipshift); ofs = from - (chipnum << cfi->chipshift); *retlen = 0; while (len) { unsigned long thislen; if (chipnum >= cfi->numchips) break; if ((len + ofs -1) >> cfi->chipshift) thislen = (1<<cfi->chipshift) - ofs; else thislen = len; ret = do_read_onechip(map, &cfi->chips[chipnum], ofs, thislen, buf); if (ret) break; *retlen += thislen; len -= thislen; buf += thislen; ofs = 0; chipnum++; } return ret;}static int cfi_intelext_read_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf, int base_offst, int reg_sz){ struct map_info *map = mtd->priv; struct cfi_private *cfi = map->fldrv_priv; struct cfi_pri_intelext *extp=cfi->cmdset_priv; int ofs_factor = cfi->interleave * cfi->device_type; int count=len; struct flchip *chip; int chip_num,offst; unsigned long timeo; DECLARE_WAITQUEUE(wait, current); chip=0; /* Calculate which chip & protection register offset we need */ chip_num=((unsigned int)from/reg_sz); offst=from-(reg_sz*chip_num)+base_offst; while(count){ if(chip_num>=cfi->numchips) goto out; /* Make sure that the chip is in the right state */ timeo = jiffies + HZ; chip=&cfi->chips[chip_num]; retry: spin_lock(chip->mutex); switch (chip->state) { case FL_READY: case FL_STATUS: case FL_CFI_QUERY: case FL_JEDEC_QUERY: break; default: /* Stick ourselves on a wait queue to be woken when someone changes the status */ set_current_state(TASK_UNINTERRUPTIBLE); add_wait_queue(&chip->wq, &wait); spin_unlock(chip->mutex); schedule(); remove_wait_queue(&chip->wq, &wait); timeo = jiffies + HZ; goto retry; } /* Now read the data required from this flash */ cfi_send_gen_cmd(0x90, 0x55,chip->start, map, cfi, cfi->device_type, NULL); while(count && ((offst-base_offst)<reg_sz)){ *buf=map->read8(map,(chip->start+((extp->ProtRegAddr+1)*ofs_factor)+offst)); buf++; offst++; count--; } chip->state=FL_CFI_QUERY; spin_unlock(chip->mutex); /* Move on to the next chip */ chip_num++; offst=base_offst; } out: wake_up(&chip->wq); return len-count;} static int cfi_intelext_read_user_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf){ struct map_info *map = mtd->priv; struct cfi_private *cfi = map->fldrv_priv; struct cfi_pri_intelext *extp=cfi->cmdset_priv; int base_offst,reg_sz; /* Check that we actually have some protection registers */ if(!(extp->FeatureSupport&64)){ printk(KERN_WARNING "%s: This flash device has no protection data to read!\n",map->name); return 0; } base_offst=(1<<extp->FactProtRegSize); reg_sz=(1<<extp->UserProtRegSize); return cfi_intelext_read_prot_reg(mtd, from, len, retlen, buf, base_offst, reg_sz);}static int cfi_intelext_read_fact_prot_reg (struct mtd_info *mtd, loff_t from, size_t len, size_t *retlen, u_char *buf){ struct map_info *map = mtd->priv; struct cfi_private *cfi = map->fldrv_priv; struct cfi_pri_intelext *extp=cfi->cmdset_priv; int base_offst,reg_sz; /* Check that we actually have some protection registers */ if(!(extp->FeatureSupport&64)){ printk(KERN_WARNING "%s: This flash device has no protection data to read!\n",map->name); return 0; } base_offst=0; reg_sz=(1<<extp->FactProtRegSize); return cfi_intelext_read_prot_reg(mtd, from, len, retlen, buf, base_offst, reg_sz);}static int do_write_oneword(struct map_info *map, struct flchip *chip, unsigned long adr, cfi_word datum){ struct cfi_private *cfi = map->fldrv_priv; struct cfi_pri_intelext *extp = cfi->cmdset_priv; cfi_word status, status_OK; unsigned long timeo; DECLARE_WAITQUEUE(wait, current); int z, suspended=0, ret=0; adr += chip->start; /* Let's determine this according to the interleave only once */ status_OK = CMD(0x80); timeo = jiffies + HZ; retry: spin_lock(chip->mutex); /* Check that the chip's ready to talk to us. * Later, we can actually think about interrupting it * if it's in FL_ERASING state. * Not just yet, though. */ switch (chip->state) { case FL_READY: break;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -