/* NOTE: boards don't need to use these address bits * for ALE/CLE unless they support booting from NAND. * They're used unless platform data overrides them.
*/ #define MASK_ALE 0x08 #define MASK_CLE 0x10
#define MAX_TSU_PS 3000 /* Input setup time in ps */ #define MAX_TH_PS 1600 /* Input hold time in ps */
/* * 0-indexed chip-select number of the asynchronous * interface to which the NAND device has been connected. * * So, if you have NAND connected to CS3 of DA850, you * will pass '1' here. Since the asynchronous interface * on DA850 starts from CS2.
*/
uint32_t core_chipsel;
/* for packages using two chipselects */
uint32_t mask_chipsel;
/* none == NAND_ECC_ENGINE_TYPE_NONE (strongly *not* advised!!) * soft == NAND_ECC_ENGINE_TYPE_SOFT * on-die == NAND_ECC_ENGINE_TYPE_ON_DIE * else == NAND_ECC_ENGINE_TYPE_ON_HOST, according to ecc_bits * * All DaVinci-family chips support 1-bit hardware ECC. * Newer ones also support 4-bit ECC, but are awkward * using it with large page chips.
*/ enum nand_ecc_engine_type engine_type; enum nand_ecc_placement ecc_placement;
u8 ecc_bits;
/* e.g. NAND_BUSWIDTH_16 */ unsignedint options; /* e.g. NAND_BBT_USE_FLASH */ unsignedint bbt_options;
/* Main and mirror bbt descriptor overrides */ struct nand_bbt_descr *bbt_td; struct nand_bbt_descr *bbt_md;
};
/* * This is a device driver for the NAND flash controller found on the * various DaVinci family chips. It handles up to four SoC chipselects, * and some flavors of secondary chipselect (e.g. based on A12) as used * with multichip packages. * * The 1-bit ECC hardware is supported, as well as the newer 4-bit ECC * available on chips like the DM355 and OMAP-L137 and needed with the * more error-prone MLC NAND chips. * * This driver assumes EM_WAIT connects all the NAND devices' RDY/nBUSY * outputs in a "wire-AND" configuration, with no per-chip signals.
*/ struct davinci_nand_info { struct nand_controller controller; struct nand_chip chip;
/* * 4-bit hardware ECC ... context maintained over entire AEMIF * * This is a syndrome engine, but we avoid NAND_ECC_PLACEMENT_INTERLEAVED * since that forces use of a problematic "infix OOB" layout. * Among other things, it trashes manufacturer bad block markers. * Also, and specific to this hardware, it ECC-protects the "prepad" * in the OOB ... while having ECC protection for parts of OOB would * seem useful, the current MTD stack sometimes wants to update the * OOB without recomputing ECC.
*/
/* Terminate read ECC; or return ECC (as bytes) of data written to NAND. */ staticint nand_davinci_calculate_4bit(struct nand_chip *chip, const u_char *dat, u_char *ecc_code)
{ struct davinci_nand_info *info = to_davinci_nand(nand_to_mtd(chip));
u32 raw_ecc[4], *p; unsigned i;
/* After a read, terminate ECC calculation by a dummy read * of some 4-bit ECC register. ECC covers everything that * was read; correct() just uses the hardware state, so * ecc_code is not needed.
*/ if (info->is_readmode) {
davinci_nand_readl(info, NAND_4BIT_ECC1_OFFSET); return 0;
}
/* Pack eight raw 10-bit ecc values into ten bytes, making * two passes which each convert four values (in upper and * lower halves of two 32-bit words) into five bytes. The * ROM boot loader uses this same packing scheme.
*/
nand_davinci_readecc_4bit(info, raw_ecc); for (i = 0, p = raw_ecc; i < 2; i++, p += 2) {
*ecc_code++ = p[0] & 0xff;
*ecc_code++ = ((p[0] >> 8) & 0x03) | ((p[0] >> 14) & 0xfc);
*ecc_code++ = ((p[0] >> 22) & 0x0f) | ((p[1] << 4) & 0xf0);
*ecc_code++ = ((p[1] >> 4) & 0x3f) | ((p[1] >> 10) & 0xc0);
*ecc_code++ = (p[1] >> 18) & 0xff;
}
return 0;
}
/* Correct up to 4 bits in data we just read, using state left in the * hardware plus the ecc_code computed when it was first written.
*/ staticint nand_davinci_correct_4bit(struct nand_chip *chip, u_char *data,
u_char *ecc_code, u_char *null)
{ int i; struct davinci_nand_info *info = to_davinci_nand(nand_to_mtd(chip)); unsignedshort ecc10[8]; unsignedshort *ecc16;
u32 syndrome[4];
u32 ecc_state; unsigned num_errors, corrected; unsignedlong timeo;
/* Unpack ten bytes into eight 10 bit values. We know we're * little-endian, and use type punning for less shifting/masking.
*/ if (WARN_ON(0x01 & (uintptr_t)ecc_code)) return -EINVAL;
ecc16 = (unsignedshort *)ecc_code;
/* Tell ECC controller about the expected ECC codes. */ for (i = 7; i >= 0; i--)
davinci_nand_writel(info, NAND_4BIT_ECC_LOAD_OFFSET, ecc10[i]);
/* Allow time for syndrome calculation ... then read it. * A syndrome of all zeroes 0 means no detected errors.
*/
davinci_nand_readl(info, NANDFSR_OFFSET);
nand_davinci_readecc_4bit(info, syndrome); if (!(syndrome[0] | syndrome[1] | syndrome[2] | syndrome[3])) return 0;
/* * Clear any previous address calculation by doing a dummy read of an * error address register.
*/
davinci_nand_readl(info, NAND_ERR_ADD1_OFFSET);
/* Start address calculation, and wait for it to complete. * We _could_ start reading more data while this is working, * to speed up the overall page read.
*/
davinci_nand_writel(info, NANDFCR_OFFSET,
davinci_nand_readl(info, NANDFCR_OFFSET) | BIT(13));
/* * ECC_STATE field reads 0x3 (Error correction complete) immediately * after setting the 4BITECC_ADD_CALC_START bit. So if you immediately * begin trying to poll for the state, you may fall right out of your * loop without any of the correction calculations having taken place. * The recommendation from the hardware team is to initially delay as * long as ECC_STATE reads less than 4. After that, ECC HW has entered * correction state.
*/
timeo = jiffies + usecs_to_jiffies(100); do {
ecc_state = (davinci_nand_readl(info,
NANDFSR_OFFSET) >> 8) & 0x0f;
cpu_relax();
} while ((ecc_state < 4) && time_before(jiffies, timeo));
for (;;) {
u32 fsr = davinci_nand_readl(info, NANDFSR_OFFSET);
switch ((fsr >> 8) & 0x0f) { case 0: /* no error, should not happen */
davinci_nand_readl(info, NAND_ERR_ERRVAL1_OFFSET); return 0; case 1: /* five or more errors detected */
davinci_nand_readl(info, NAND_ERR_ERRVAL1_OFFSET); return -EBADMSG; case 2: /* error addresses computed */ case 3:
num_errors = 1 + ((fsr >> 16) & 0x03); goto correct; default: /* still working on it */
cpu_relax(); continue;
}
}
correct: /* correct each error */ for (i = 0, corrected = 0; i < num_errors; i++) { int error_address, error_value;
/* An ECC layout for using 4-bit ECC with small-page flash, storing * ten ECC bytes plus the manufacturer's bad block marker byte, and * and not overlapping the default BBT markers.
*/ staticint hwecc4_ooblayout_small_ecc(struct mtd_info *mtd, int section, struct mtd_oob_region *oobregion)
{ if (section > 2) return -ERANGE;
if (device_property_read_bool(&pdev->dev, "ti,davinci-nand-use-bbt"))
pdata->bbt_options = NAND_BBT_USE_FLASH;
/* * Since kernel v4.8, this driver has been fixed to enable * use of 4-bit hardware ECC with subpages and verified on * TI's keystone EVMs (K2L, K2HK and K2E). * However, in the interest of not breaking systems using * existing UBI partitions, sub-page writes are not being * (re)enabled. If you want to use subpage writes on Keystone * platforms (i.e. do not have any existing UBI partitions), * then use "ti,davinci-nand" as the compatible in your * device-tree file.
*/ if (device_is_compatible(&pdev->dev, "ti,keystone-nand"))
pdata->options |= NAND_NO_SUBPAGE_WRITE;
}
switch (chip->ecc.engine_type) { case NAND_ECC_ENGINE_TYPE_NONE: case NAND_ECC_ENGINE_TYPE_ON_DIE:
pdata->ecc_bits = 0; break; case NAND_ECC_ENGINE_TYPE_SOFT:
pdata->ecc_bits = 0; /* * This driver expects Hamming based ECC when engine_type is set * to NAND_ECC_ENGINE_TYPE_SOFT. Force ecc.algo to * NAND_ECC_ALGO_HAMMING to avoid adding an extra ->ecc_algo * field to davinci_nand_pdata.
*/
chip->ecc.algo = NAND_ECC_ALGO_HAMMING; break; case NAND_ECC_ENGINE_TYPE_ON_HOST: if (pdata->ecc_bits == 4) { int chunks = mtd->writesize / 512;
/* * No sanity checks: CPUs must support this, * and the chips may not use NAND_BUSWIDTH_16.
*/
/* No sharing 4-bit hardware between chipselects yet */
spin_lock_irq(&davinci_nand_lock); if (ecc4_busy)
ret = -EBUSY; else
ecc4_busy = true;
spin_unlock_irq(&davinci_nand_lock);
/* * Update ECC layout if needed ... for 1-bit HW ECC, the * default is OK, but it allocates 6 bytes when only 3 * are needed (for each 512 bytes). For 4-bit HW ECC, * the default is not usable: 10 bytes needed, not 6. * * For small page chips, preserve the manufacturer's * badblock marking data ... and make sure a flash BBT * table marker fits in the free bytes.
*/ if (chunks == 1) {
mtd_set_ooblayout(mtd,
&hwecc4_small_ooblayout_ops);
} elseif (chunks == 4 || chunks == 8) {
chip->ecc.read_page = nand_read_page_hwecc_oob_first;
if (force_8bit || (alignment & 1))
iowrite8_rep(info->current_cs, buf, len); elseif (alignment & 3)
iowrite16_rep(info->current_cs, buf, len >> 1); else
iowrite32_rep(info->current_cs, buf, len >> 2);
}
staticint davinci_nand_exec_instr(struct davinci_nand_info *info, conststruct nand_op_instr *instr)
{ unsignedint i, timeout_us;
u32 status; int ret;
switch (instr->type) { case NAND_OP_CMD_INSTR:
iowrite8(instr->ctx.cmd.opcode,
info->current_cs + info->mask_cle); break;
case NAND_OP_ADDR_INSTR: for (i = 0; i < instr->ctx.addr.naddrs; i++) {
iowrite8(instr->ctx.addr.addrs[i],
info->current_cs + info->mask_ale);
} break;
case NAND_OP_DATA_IN_INSTR:
nand_davinci_data_in(info, instr->ctx.data.buf.in,
instr->ctx.data.len,
instr->ctx.data.force_8bit); break;
case NAND_OP_DATA_OUT_INSTR:
nand_davinci_data_out(info, instr->ctx.data.buf.out,
instr->ctx.data.len,
instr->ctx.data.force_8bit); break;
case NAND_OP_WAITRDY_INSTR:
timeout_us = instr->ctx.waitrdy.timeout_ms * 1000;
ret = readl_relaxed_poll_timeout(info->base + NANDFSR_OFFSET,
status, status & BIT(0), 5,
timeout_us); if (ret) return ret;
break;
}
if (instr->delay_ns) { /* Dummy read to be sure that command is sent before ndelay starts */
davinci_nand_readl(info, 0);
ndelay(instr->delay_ns);
}
vaddr = devm_ioremap_resource(&pdev->dev, res1); if (IS_ERR(vaddr)) return PTR_ERR(vaddr);
/* * This registers range is used to setup NAND settings. In case with * TI AEMIF driver, the same memory address range is requested already * by AEMIF, so we cannot request it twice, just ioremap. * The AEMIF and NAND drivers not use the same registers in this range.
*/
base = devm_ioremap(&pdev->dev, res2->start, resource_size(res2)); if (!base) {
dev_err(&pdev->dev, "ioremap failed for resource %pR\n", res2); return -EADDRNOTAVAIL;
}
info->clk = devm_clk_get_enabled(&pdev->dev, "aemif"); if (IS_ERR(info->clk)) return dev_err_probe(&pdev->dev, PTR_ERR(info->clk), "failed to get clock");
/* use nandboot-capable ALE/CLE masks by default */
info->mask_ale = pdata->mask_ale ? : MASK_ALE;
info->mask_cle = pdata->mask_cle ? : MASK_CLE;
spin_lock_irq(&davinci_nand_lock);
/* put CSxNAND into NAND mode */
val = davinci_nand_readl(info, NANDFCR_OFFSET);
val |= BIT(info->core_chipsel);
davinci_nand_writel(info, NANDFCR_OFFSET, val);
spin_unlock_irq(&davinci_nand_lock);
/* Scan to find existence of the device(s) */
nand_controller_init(&info->controller);
info->controller.ops = &davinci_nand_controller_ops;
info->chip.controller = &info->controller;
ret = nand_scan(&info->chip, pdata->mask_chipsel ? 2 : 1); if (ret < 0) {
dev_dbg(&pdev->dev, "no NAND chip(s) found\n"); return ret;
}
if (pdata->parts)
ret = mtd_device_register(mtd, pdata->parts, pdata->nr_parts); else
ret = mtd_device_register(mtd, NULL, 0); if (ret < 0) goto err_cleanup_nand;
val = davinci_nand_readl(info, NRCSR_OFFSET);
dev_info(&pdev->dev, "controller rev. %d.%d\n",
(val >> 8) & 0xff, val & 0xff);
¤ Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.0.18Bemerkung:
(vorverarbeitet)
¤
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.