⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 mtd.patch

📁 patches for linux-2.6.
💻 PATCH
📖 第 1 页 / 共 5 页
字号:
 		 		/* Latency issues. Drop the lock, wait a while and retry */-		spin_unlock(chip->mutex); 		UDELAY(map, chip, adr, 1000000/HZ);-		spin_lock(chip->mutex); 	}  	/* We've broken this before. It doesn't hurt to be safe */@@ -1778,53 +1793,40 @@ 	chip->state = FL_STATUS; 	status = map_read(map, adr); -	/* check for lock bit */+	/* check for errors */ 	if (map_word_bitsset(map, status, CMD(0x3a))) {-		unsigned char chipstatus;+		unsigned long chipstatus = MERGESTATUS(status);  		/* Reset the error bits */ 		map_write(map, CMD(0x50), adr); 		map_write(map, CMD(0x70), adr); 		xip_enable(map, chip, adr); -		chipstatus = status.x[0];-		if (!map_word_equal(map, status, CMD(chipstatus))) {-			int i, w;-			for (w=0; w<map_words(map); w++) {-				for (i = 0; i<cfi_interleave(cfi); i++) {-					chipstatus |= status.x[w] >> (cfi->device_type * 8);-				}-			}-			printk(KERN_WARNING "Status is not identical for all chips: 0x%lx. Merging to give 0x%02x\n",-			       status.x[0], chipstatus);-		}- 		if ((chipstatus & 0x30) == 0x30) {-			printk(KERN_NOTICE "Chip reports improper command sequence: status 0x%x\n", chipstatus);-			ret = -EIO;+			printk(KERN_ERR "%s: block erase error: (bad command sequence, status 0x%lx)\n", map->name, chipstatus);+			ret = -EINVAL; 		} else if (chipstatus & 0x02) { 			/* Protection bit set */ 			ret = -EROFS; 		} else if (chipstatus & 0x8) { 			/* Voltage */-			printk(KERN_WARNING "Chip reports voltage low on erase: status 0x%x\n", chipstatus);+			printk(KERN_ERR "%s: block erase error: (bad VPP)\n", map->name); 			ret = -EIO;-		} else if (chipstatus & 0x20) {-			if (retries--) {-				printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%x. Retrying...\n", adr, chipstatus);-				timeo = jiffies + HZ;-				put_chip(map, chip, adr);-				spin_unlock(chip->mutex);-				goto retry;-			}-			printk(KERN_DEBUG "Chip erase failed at 0x%08lx: status 0x%x\n", adr, chipstatus);+		} else if (chipstatus & 0x20 && retries--) {+			printk(KERN_DEBUG "block erase failed at 0x%08lx: status 0x%lx. Retrying...\n", adr, chipstatus);+			timeo = jiffies + HZ;+			put_chip(map, chip, adr);+			spin_unlock(chip->mutex);+			goto retry;+		} else {+			printk(KERN_ERR "%s: block erase failed at 0x%08lx (status 0x%lx)\n", map->name, adr, chipstatus); 			ret = -EIO; 		}-	} else {-		xip_enable(map, chip, adr);-		ret = 0;++		goto out; 	} +	xip_enable(map, chip, adr);  out:	put_chip(map, chip, adr); 	spin_unlock(chip->mutex); 	return ret;@@ -1882,6 +1884,7 @@ 		 		if (chip->state == FL_SYNCING) { 			chip->state = chip->oldstate;+			chip->oldstate = FL_READY; 			wake_up(&chip->wq); 		} 		spin_unlock(chip->mutex);@@ -1897,8 +1900,9 @@ 	struct cfi_private *cfi = map->fldrv_priv; 	int status, ofs_factor = cfi->interleave * cfi->device_type; +	adr += chip->start; 	xip_disable(map, chip, adr+(2*ofs_factor));-	cfi_send_gen_cmd(0x90, 0x55, 0, map, cfi, cfi->device_type, NULL);+	map_write(map, CMD(0x90), adr+(2*ofs_factor)); 	chip->state = FL_JEDEC_QUERY; 	status = cfi_read_query(map, adr+(2*ofs_factor)); 	xip_enable(map, chip, 0);@@ -1915,6 +1919,7 @@ 				       unsigned long adr, int len, void *thunk) { 	struct cfi_private *cfi = map->fldrv_priv;+	struct cfi_pri_intelext *extp = cfi->cmdset_priv; 	map_word status, status_OK; 	unsigned long timeo = jiffies + HZ; 	int ret;@@ -1944,9 +1949,13 @@ 	} else 		BUG(); -	spin_unlock(chip->mutex);-	UDELAY(map, chip, adr, 1000000/HZ);-	spin_lock(chip->mutex);+	/*+	 * If Instant Individual Block Locking supported then no need+	 * to delay.+	 */++	if (!extp || !(extp->FeatureSupport & (1 << 5)))+		UDELAY(map, chip, adr, 1000000/HZ);  	/* FIXME. Use a timer to check this, and return immediately. */ 	/* Once the state machine's known to be working I'll do that */@@ -1960,22 +1969,17 @@ 		 		/* OK Still waiting */ 		if (time_after(jiffies, timeo)) {-			map_word Xstatus; 			map_write(map, CMD(0x70), adr); 			chip->state = FL_STATUS;-			Xstatus = map_read(map, adr); 			xip_enable(map, chip, adr);-			printk(KERN_ERR "waiting for unlock to complete timed out. status = %lx, Xstatus = %lx.\n",-			       status.x[0], Xstatus.x[0]);+			printk(KERN_ERR "%s: block unlock error: (status timeout)\n", map->name); 			put_chip(map, chip, adr); 			spin_unlock(chip->mutex); 			return -EIO; 		} 		 		/* Latency issues. Drop the lock, wait a while and retry */-		spin_unlock(chip->mutex); 		UDELAY(map, chip, adr, 1);-		spin_lock(chip->mutex); 	} 	 	/* Done and happy. */@@ -2034,6 +2038,274 @@ 	return ret; } +#ifdef CONFIG_MTD_OTP++typedef int (*otp_op_t)(struct map_info *map, struct flchip *chip, +			u_long data_offset, u_char *buf, u_int size,+			u_long prot_offset, u_int groupno, u_int groupsize);++static int __xipram+do_otp_read(struct map_info *map, struct flchip *chip, u_long offset,+	    u_char *buf, u_int size, u_long prot, u_int grpno, u_int grpsz)+{+	struct cfi_private *cfi = map->fldrv_priv;+	int ret;++	spin_lock(chip->mutex);+	ret = get_chip(map, chip, chip->start, FL_JEDEC_QUERY);+	if (ret) {+		spin_unlock(chip->mutex);+		return ret;+	}++	/* let's ensure we're not reading back cached data from array mode */+	INVALIDATE_CACHED_RANGE(map, chip->start + offset, size);++	xip_disable(map, chip, chip->start);+	if (chip->state != FL_JEDEC_QUERY) {+		map_write(map, CMD(0x90), chip->start);+		chip->state = FL_JEDEC_QUERY;+	}+	map_copy_from(map, buf, chip->start + offset, size);+	xip_enable(map, chip, chip->start);++	/* then ensure we don't keep OTP data in the cache */+	INVALIDATE_CACHED_RANGE(map, chip->start + offset, size);++	put_chip(map, chip, chip->start);+	spin_unlock(chip->mutex);+	return 0;+}++static int+do_otp_write(struct map_info *map, struct flchip *chip, u_long offset,+	     u_char *buf, u_int size, u_long prot, u_int grpno, u_int grpsz)+{+	int ret;++	while (size) {+		unsigned long bus_ofs = offset & ~(map_bankwidth(map)-1);+		int gap = offset - bus_ofs;+		int n = min_t(int, size, map_bankwidth(map)-gap);+		map_word datum = map_word_ff(map);++		datum = map_word_load_partial(map, datum, buf, gap, n);+		ret = do_write_oneword(map, chip, bus_ofs, datum, FL_OTP_WRITE);+		if (ret) +			return ret;++		offset += n;+		buf += n;+		size -= n;+	}++	return 0;+}++static int+do_otp_lock(struct map_info *map, struct flchip *chip, u_long offset,+	    u_char *buf, u_int size, u_long prot, u_int grpno, u_int grpsz)+{+	struct cfi_private *cfi = map->fldrv_priv;+	map_word datum;++	/* make sure area matches group boundaries */+	if (size != grpsz)+		return -EXDEV;++	datum = map_word_ff(map);+	datum = map_word_clr(map, datum, CMD(1 << grpno));+	return do_write_oneword(map, chip, prot, datum, FL_OTP_WRITE);+}++static int cfi_intelext_otp_walk(struct mtd_info *mtd, loff_t from, size_t len,+				 size_t *retlen, u_char *buf,+				 otp_op_t action, int user_regs)+{+	struct map_info *map = mtd->priv;+	struct cfi_private *cfi = map->fldrv_priv;+	struct cfi_pri_intelext *extp = cfi->cmdset_priv;+	struct flchip *chip;+	struct cfi_intelext_otpinfo *otp;+	u_long devsize, reg_prot_offset, data_offset;+	u_int chip_num, chip_step, field, reg_fact_size, reg_user_size;+	u_int groups, groupno, groupsize, reg_fact_groups, reg_user_groups;+	int ret;++	*retlen = 0;++	/* Check that we actually have some OTP registers */+	if (!extp || !(extp->FeatureSupport & 64) || !extp->NumProtectionFields)+		return -ENODATA;++	/* we need real chips here not virtual ones */+	devsize = (1 << cfi->cfiq->DevSize) * cfi->interleave;+	chip_step = devsize >> cfi->chipshift;+	chip_num = 0;++	/* Some chips have OTP located in the _top_ partition only.+	   For example: Intel 28F256L18T (T means top-parameter device) */+	if (cfi->mfr == MANUFACTURER_INTEL) {+		switch (cfi->id) {+		case 0x880b:+		case 0x880c:+		case 0x880d:+			chip_num = chip_step - 1;+		}+	}++	for ( ; chip_num < cfi->numchips; chip_num += chip_step) {+		chip = &cfi->chips[chip_num];+		otp = (struct cfi_intelext_otpinfo *)&extp->extra[0];++		/* first OTP region */+		field = 0;+		reg_prot_offset = extp->ProtRegAddr;+		reg_fact_groups = 1;+		reg_fact_size = 1 << extp->FactProtRegSize;+		reg_user_groups = 1;+		reg_user_size = 1 << extp->UserProtRegSize;++		while (len > 0) {+			/* flash geometry fixup */+			data_offset = reg_prot_offset + 1;+			data_offset *= cfi->interleave * cfi->device_type;+			reg_prot_offset *= cfi->interleave * cfi->device_type;+			reg_fact_size *= cfi->interleave;+			reg_user_size *= cfi->interleave;++			if (user_regs) {+				groups = reg_user_groups;+				groupsize = reg_user_size;+				/* skip over factory reg area */+				groupno = reg_fact_groups;+				data_offset += reg_fact_groups * reg_fact_size;+			} else {+				groups = reg_fact_groups;+				groupsize = reg_fact_size;+				groupno = 0;+			}++			while (len > 0 && groups > 0) {+				if (!action) {+					/*+					 * Special case: if action is NULL+					 * we fill buf with otp_info records.+					 */+					struct otp_info *otpinfo;+					map_word lockword;+					len -= sizeof(struct otp_info);+					if (len <= 0)+						return -ENOSPC;+					ret = do_otp_read(map, chip,+							  reg_prot_offset,+							  (u_char *)&lockword,+							  map_bankwidth(map),+							  0, 0,  0);+					if (ret)+						return ret;+					otpinfo = (struct otp_info *)buf;+					otpinfo->start = from;+					otpinfo->length = groupsize;+					otpinfo->locked =+					   !map_word_bitsset(map, lockword,+							     CMD(1 << groupno));+					from += groupsize;+					buf += sizeof(*otpinfo);+					*retlen += sizeof(*otpinfo);+				} else if (from >= groupsize) {+					from -= groupsize;+					data_offset += groupsize;+				} else {+					int size = groupsize;+					data_offset += from;+					size -= from;+					from = 0;+					if (size > len)+						size = len;+					ret = action(map, chip, data_offset,+						     buf, size, reg_prot_offset,+						     groupno, groupsize);+					if (ret < 0)+						return ret;+					buf += size;+					len -= size;+					*retlen += size;+					data_offset += size;+				}+				groupno++;+				groups--;+			}++			/* next OTP region */+			if (++field == extp->NumProtectionFields)+				break;+			reg_prot_offset = otp->ProtRegAddr;+			reg_fact_groups = otp->FactGroups;+			reg_fact_size = 1 << otp->FactProtRegSize;+			reg_user_groups = otp->UserGroups;+			reg_user_size = 1 << otp->UserProtRegSize;+			otp++;+		}+	}++	return 0;+}++static int cfi_intelext_read_fact_prot_reg(struct mtd_info *mtd, loff_t from,+					   size_t len, size_t *retlen,+					    u_char *buf)+{+	return cfi_intelext_otp_walk(mtd, from, len, retlen,+				     buf, do_otp_read, 0);+}++static int cfi_intelext_read_user_prot_reg(struct mtd_info *mtd, loff_t from,+					   size_t len, size_t *retlen,+					    u_char *buf)+{+	return cfi_intelext_otp_walk(mtd, from, len, retlen,+				     buf, do_otp_read, 1);+}++static int cfi_intelext_write_user_prot_reg(struct mtd_info *mtd, loff_t from,+					    size_t len, size_t *retlen,+					     u_char *buf)+{+	return cfi_intelext_otp_walk(mtd, from, len, retlen,+				     buf, do_otp_write, 1);+}++static int cfi_intelext_lock_user_prot_reg(struct mtd_info *mtd,+					   loff_t from, size_t len)+{+	size_t retlen;+	return cfi_intelext_otp_walk(mtd, from, len, &retlen,+				     NULL, do_otp_lock, 1);+}++static int cfi_intelext_get_fact_prot_info(struct mtd_info *mtd, +					   struct otp_info *buf, size_t len)+{+	size_t retlen;+	int ret;++	ret = cfi_intelext_otp_walk(mtd, 0, len, &retlen, (u_char *)buf, NULL, 0);+	return ret ? : retlen;+}++static int cfi_intelext_get_user_prot_info(struct mtd_info *mtd,+					   struct otp_info *buf, size_t len)+{+	size_t retlen;+	int ret;++	ret = cfi_intelext_otp_walk(mtd, 0, len, &retlen, (u_char *)buf, NULL, 1);+	return ret ? : retlen;+}++#endif+

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -