Skip to content

Commit 3166df0

Browse files
Bastian HechtDavid Woodhouse
authored andcommitted
mtd: sh_flctl: Use user oob data in hardware ECC mode
In hardware ecc mode, the flctl now writes and reads the oob data provided by the user. Additionally the ECC is now returned in normal page reads, not only when using the explicit NAND_CMD_READOOB command. Signed-off-by: Bastian Hecht <hechtb@gmail.com> Acked-by: Brian Norris <computersforpeace@gmail.com> Signed-off-by: Artem Bityutskiy <artem.bityutskiy@linux.intel.com> Signed-off-by: David Woodhouse <David.Woodhouse@intel.com>
1 parent 6667a6d commit 3166df0

1 file changed

Lines changed: 17 additions & 8 deletions

File tree

‎drivers/mtd/nand/sh_flctl.c‎

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -275,13 +275,12 @@ static void read_fiforeg(struct sh_flctl *flctl, int rlen, int offset)
275275
{
276276
int i, len_4align;
277277
unsigned long *buf = (unsigned long *)&flctl->done_buff[offset];
278-
void *fifo_addr = (void *)FLDTFIFO(flctl);
279278

280279
len_4align = (rlen + 3) / 4;
281280

282281
for (i = 0; i < len_4align; i++) {
283282
wait_rfifo_ready(flctl);
284-
buf[i] = readl(fifo_addr);
283+
buf[i] = readl(FLDTFIFO(flctl));
285284
buf[i] = be32_to_cpu(buf[i]);
286285
}
287286
}
@@ -318,6 +317,18 @@ static void write_fiforeg(struct sh_flctl *flctl, int rlen, int offset)
318317
}
319318
}
320319

320+
static void write_ec_fiforeg(struct sh_flctl *flctl, int rlen, int offset)
321+
{
322+
int i, len_4align;
323+
unsigned long *data = (unsigned long *)&flctl->done_buff[offset];
324+
325+
len_4align = (rlen + 3) / 4;
326+
for (i = 0; i < len_4align; i++) {
327+
wait_wecfifo_ready(flctl);
328+
writel(cpu_to_be32(data[i]), FLECFIFO(flctl));
329+
}
330+
}
331+
321332
static void set_cmd_regs(struct mtd_info *mtd, uint32_t cmd, uint32_t flcmcdr_val)
322333
{
323334
struct sh_flctl *flctl = mtd_to_flctl(mtd);
@@ -384,13 +395,15 @@ static int flctl_read_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
384395
uint8_t *buf, int oob_required, int page)
385396
{
386397
chip->read_buf(mtd, buf, mtd->writesize);
398+
chip->read_buf(mtd, chip->oob_poi, mtd->oobsize);
387399
return 0;
388400
}
389401

390402
static void flctl_write_page_hwecc(struct mtd_info *mtd, struct nand_chip *chip,
391403
const uint8_t *buf, int oob_required)
392404
{
393405
chip->write_buf(mtd, buf, mtd->writesize);
406+
chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
394407
}
395408

396409
static void execmd_read_page_sector(struct mtd_info *mtd, int page_addr)
@@ -466,7 +479,7 @@ static void execmd_read_oob(struct mtd_info *mtd, int page_addr)
466479
static void execmd_write_page_sector(struct mtd_info *mtd)
467480
{
468481
struct sh_flctl *flctl = mtd_to_flctl(mtd);
469-
int i, page_addr = flctl->seqin_page_addr;
482+
int page_addr = flctl->seqin_page_addr;
470483
int sector, page_sectors;
471484

472485
page_sectors = flctl->page_size ? 4 : 1;
@@ -482,11 +495,7 @@ static void execmd_write_page_sector(struct mtd_info *mtd)
482495

483496
for (sector = 0; sector < page_sectors; sector++) {
484497
write_fiforeg(flctl, 512, 512 * sector);
485-
486-
for (i = 0; i < 4; i++) {
487-
wait_wecfifo_ready(flctl); /* wait for write ready */
488-
writel(0xFFFFFFFF, FLECFIFO(flctl));
489-
}
498+
write_ec_fiforeg(flctl, 16, mtd->writesize + 16 * sector);
490499
}
491500

492501
wait_completion(flctl);

0 commit comments

Comments
 (0)