hc
2024-12-19 9370bb92b2d16684ee45cf24e879c93c509162da
kernel/drivers/mtd/nand/raw/omap2.c
....@@ -1,11 +1,8 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /*
23 * Copyright © 2004 Texas Instruments, Jian Zhang <jzhang@ti.com>
34 * Copyright © 2004 Micron Technology Inc.
45 * Copyright © 2004 David Brownell
5
- *
6
- * This program is free software; you can redistribute it and/or modify
7
- * it under the terms of the GNU General Public License version 2 as
8
- * published by the Free Software Foundation.
96 */
107
118 #include <linux/platform_device.h>
....@@ -240,7 +237,7 @@
240237
241238 /**
242239 * omap_hwcontrol - hardware specific access to control-lines
243
- * @mtd: MTD device structure
240
+ * @chip: NAND chip object
244241 * @cmd: command to device
245242 * @ctrl:
246243 * NAND_NCE: bit 0 -> don't care
....@@ -249,9 +246,9 @@
249246 *
250247 * NOTE: boards may use different bits for these!!
251248 */
252
-static void omap_hwcontrol(struct mtd_info *mtd, int cmd, unsigned int ctrl)
249
+static void omap_hwcontrol(struct nand_chip *chip, int cmd, unsigned int ctrl)
253250 {
254
- struct omap_nand_info *info = mtd_to_omap(mtd);
251
+ struct omap_nand_info *info = mtd_to_omap(nand_to_mtd(chip));
255252
256253 if (cmd != NAND_CMD_NONE) {
257254 if (ctrl & NAND_CLE)
....@@ -275,7 +272,7 @@
275272 {
276273 struct nand_chip *nand = mtd_to_nand(mtd);
277274
278
- ioread8_rep(nand->IO_ADDR_R, buf, len);
275
+ ioread8_rep(nand->legacy.IO_ADDR_R, buf, len);
279276 }
280277
281278 /**
....@@ -291,7 +288,7 @@
291288 bool status;
292289
293290 while (len--) {
294
- iowrite8(*p++, info->nand.IO_ADDR_W);
291
+ iowrite8(*p++, info->nand.legacy.IO_ADDR_W);
295292 /* wait until buffer is available for write */
296293 do {
297294 status = info->ops->nand_writebuffer_empty();
....@@ -309,7 +306,7 @@
309306 {
310307 struct nand_chip *nand = mtd_to_nand(mtd);
311308
312
- ioread16_rep(nand->IO_ADDR_R, buf, len / 2);
309
+ ioread16_rep(nand->legacy.IO_ADDR_R, buf, len / 2);
313310 }
314311
315312 /**
....@@ -327,7 +324,7 @@
327324 len >>= 1;
328325
329326 while (len--) {
330
- iowrite16(*p++, info->nand.IO_ADDR_W);
327
+ iowrite16(*p++, info->nand.legacy.IO_ADDR_W);
331328 /* wait until buffer is available for write */
332329 do {
333330 status = info->ops->nand_writebuffer_empty();
....@@ -337,12 +334,13 @@
337334
338335 /**
339336 * omap_read_buf_pref - read data from NAND controller into buffer
340
- * @mtd: MTD device structure
337
+ * @chip: NAND chip object
341338 * @buf: buffer to store date
342339 * @len: number of bytes to read
343340 */
344
-static void omap_read_buf_pref(struct mtd_info *mtd, u_char *buf, int len)
341
+static void omap_read_buf_pref(struct nand_chip *chip, u_char *buf, int len)
345342 {
343
+ struct mtd_info *mtd = nand_to_mtd(chip);
346344 struct omap_nand_info *info = mtd_to_omap(mtd);
347345 uint32_t r_count = 0;
348346 int ret = 0;
....@@ -372,7 +370,7 @@
372370 r_count = readl(info->reg.gpmc_prefetch_status);
373371 r_count = PREFETCH_STATUS_FIFO_CNT(r_count);
374372 r_count = r_count >> 2;
375
- ioread32_rep(info->nand.IO_ADDR_R, p, r_count);
373
+ ioread32_rep(info->nand.legacy.IO_ADDR_R, p, r_count);
376374 p += r_count;
377375 len -= r_count << 2;
378376 } while (len);
....@@ -383,13 +381,14 @@
383381
384382 /**
385383 * omap_write_buf_pref - write buffer to NAND controller
386
- * @mtd: MTD device structure
384
+ * @chip: NAND chip object
387385 * @buf: data buffer
388386 * @len: number of bytes to write
389387 */
390
-static void omap_write_buf_pref(struct mtd_info *mtd,
391
- const u_char *buf, int len)
388
+static void omap_write_buf_pref(struct nand_chip *chip, const u_char *buf,
389
+ int len)
392390 {
391
+ struct mtd_info *mtd = nand_to_mtd(chip);
393392 struct omap_nand_info *info = mtd_to_omap(mtd);
394393 uint32_t w_count = 0;
395394 int i = 0, ret = 0;
....@@ -399,7 +398,7 @@
399398
400399 /* take care of subpage writes */
401400 if (len % 2 != 0) {
402
- writeb(*buf, info->nand.IO_ADDR_W);
401
+ writeb(*buf, info->nand.legacy.IO_ADDR_W);
403402 p = (u16 *)(buf + 1);
404403 len--;
405404 }
....@@ -419,7 +418,7 @@
419418 w_count = PREFETCH_STATUS_FIFO_CNT(w_count);
420419 w_count = w_count >> 1;
421420 for (i = 0; (i < w_count) && len; i++, len -= 2)
422
- iowrite16(*p++, info->nand.IO_ADDR_W);
421
+ iowrite16(*p++, info->nand.legacy.IO_ADDR_W);
423422 }
424423 /* wait for data to flushed-out before reset the prefetch */
425424 tim = 0;
....@@ -528,14 +527,17 @@
528527
529528 /**
530529 * omap_read_buf_dma_pref - read data from NAND controller into buffer
531
- * @mtd: MTD device structure
530
+ * @chip: NAND chip object
532531 * @buf: buffer to store date
533532 * @len: number of bytes to read
534533 */
535
-static void omap_read_buf_dma_pref(struct mtd_info *mtd, u_char *buf, int len)
534
+static void omap_read_buf_dma_pref(struct nand_chip *chip, u_char *buf,
535
+ int len)
536536 {
537
+ struct mtd_info *mtd = nand_to_mtd(chip);
538
+
537539 if (len <= mtd->oobsize)
538
- omap_read_buf_pref(mtd, buf, len);
540
+ omap_read_buf_pref(chip, buf, len);
539541 else
540542 /* start transfer in DMA mode */
541543 omap_nand_dma_transfer(mtd, buf, len, 0x0);
....@@ -543,18 +545,20 @@
543545
544546 /**
545547 * omap_write_buf_dma_pref - write buffer to NAND controller
546
- * @mtd: MTD device structure
548
+ * @chip: NAND chip object
547549 * @buf: data buffer
548550 * @len: number of bytes to write
549551 */
550
-static void omap_write_buf_dma_pref(struct mtd_info *mtd,
551
- const u_char *buf, int len)
552
+static void omap_write_buf_dma_pref(struct nand_chip *chip, const u_char *buf,
553
+ int len)
552554 {
555
+ struct mtd_info *mtd = nand_to_mtd(chip);
556
+
553557 if (len <= mtd->oobsize)
554
- omap_write_buf_pref(mtd, buf, len);
558
+ omap_write_buf_pref(chip, buf, len);
555559 else
556560 /* start transfer in DMA mode */
557
- omap_nand_dma_transfer(mtd, (u_char *) buf, len, 0x1);
561
+ omap_nand_dma_transfer(mtd, (u_char *)buf, len, 0x1);
558562 }
559563
560564 /*
....@@ -578,14 +582,14 @@
578582 bytes = info->buf_len;
579583 else if (!info->buf_len)
580584 bytes = 0;
581
- iowrite32_rep(info->nand.IO_ADDR_W,
582
- (u32 *)info->buf, bytes >> 2);
585
+ iowrite32_rep(info->nand.legacy.IO_ADDR_W, (u32 *)info->buf,
586
+ bytes >> 2);
583587 info->buf = info->buf + bytes;
584588 info->buf_len -= bytes;
585589
586590 } else {
587
- ioread32_rep(info->nand.IO_ADDR_R,
588
- (u32 *)info->buf, bytes >> 2);
591
+ ioread32_rep(info->nand.legacy.IO_ADDR_R, (u32 *)info->buf,
592
+ bytes >> 2);
589593 info->buf = info->buf + bytes;
590594
591595 if (this_irq == info->gpmc_irq_count)
....@@ -605,17 +609,19 @@
605609
606610 /*
607611 * omap_read_buf_irq_pref - read data from NAND controller into buffer
608
- * @mtd: MTD device structure
612
+ * @chip: NAND chip object
609613 * @buf: buffer to store date
610614 * @len: number of bytes to read
611615 */
612
-static void omap_read_buf_irq_pref(struct mtd_info *mtd, u_char *buf, int len)
616
+static void omap_read_buf_irq_pref(struct nand_chip *chip, u_char *buf,
617
+ int len)
613618 {
619
+ struct mtd_info *mtd = nand_to_mtd(chip);
614620 struct omap_nand_info *info = mtd_to_omap(mtd);
615621 int ret = 0;
616622
617623 if (len <= mtd->oobsize) {
618
- omap_read_buf_pref(mtd, buf, len);
624
+ omap_read_buf_pref(chip, buf, len);
619625 return;
620626 }
621627
....@@ -651,20 +657,21 @@
651657
652658 /*
653659 * omap_write_buf_irq_pref - write buffer to NAND controller
654
- * @mtd: MTD device structure
660
+ * @chip: NAND chip object
655661 * @buf: data buffer
656662 * @len: number of bytes to write
657663 */
658
-static void omap_write_buf_irq_pref(struct mtd_info *mtd,
659
- const u_char *buf, int len)
664
+static void omap_write_buf_irq_pref(struct nand_chip *chip, const u_char *buf,
665
+ int len)
660666 {
667
+ struct mtd_info *mtd = nand_to_mtd(chip);
661668 struct omap_nand_info *info = mtd_to_omap(mtd);
662669 int ret = 0;
663670 unsigned long tim, limit;
664671 u32 val;
665672
666673 if (len <= mtd->oobsize) {
667
- omap_write_buf_pref(mtd, buf, len);
674
+ omap_write_buf_pref(chip, buf, len);
668675 return;
669676 }
670677
....@@ -857,7 +864,7 @@
857864
858865 /**
859866 * omap_correct_data - Compares the ECC read with HW generated ECC
860
- * @mtd: MTD device structure
867
+ * @chip: NAND chip object
861868 * @dat: page data
862869 * @read_ecc: ecc read from nand flash
863870 * @calc_ecc: ecc read from HW ECC registers
....@@ -869,16 +876,16 @@
869876 * corrected errors is returned. If uncorrectable errors exist, %-1 is
870877 * returned.
871878 */
872
-static int omap_correct_data(struct mtd_info *mtd, u_char *dat,
873
- u_char *read_ecc, u_char *calc_ecc)
879
+static int omap_correct_data(struct nand_chip *chip, u_char *dat,
880
+ u_char *read_ecc, u_char *calc_ecc)
874881 {
875
- struct omap_nand_info *info = mtd_to_omap(mtd);
882
+ struct omap_nand_info *info = mtd_to_omap(nand_to_mtd(chip));
876883 int blockCnt = 0, i = 0, ret = 0;
877884 int stat = 0;
878885
879886 /* Ex NAND_ECC_HW12_2048 */
880
- if ((info->nand.ecc.mode == NAND_ECC_HW) &&
881
- (info->nand.ecc.size == 2048))
887
+ if (info->nand.ecc.engine_type == NAND_ECC_ENGINE_TYPE_ON_HOST &&
888
+ info->nand.ecc.size == 2048)
882889 blockCnt = 4;
883890 else
884891 blockCnt = 1;
....@@ -900,7 +907,7 @@
900907
901908 /**
902909 * omap_calcuate_ecc - Generate non-inverted ECC bytes.
903
- * @mtd: MTD device structure
910
+ * @chip: NAND chip object
904911 * @dat: The pointer to data on which ecc is computed
905912 * @ecc_code: The ecc_code buffer
906913 *
....@@ -910,10 +917,10 @@
910917 * an erased page will produce an ECC mismatch between generated and read
911918 * ECC bytes that has to be dealt with separately.
912919 */
913
-static int omap_calculate_ecc(struct mtd_info *mtd, const u_char *dat,
914
- u_char *ecc_code)
920
+static int omap_calculate_ecc(struct nand_chip *chip, const u_char *dat,
921
+ u_char *ecc_code)
915922 {
916
- struct omap_nand_info *info = mtd_to_omap(mtd);
923
+ struct omap_nand_info *info = mtd_to_omap(nand_to_mtd(chip));
917924 u32 val;
918925
919926 val = readl(info->reg.gpmc_ecc_config);
....@@ -935,10 +942,9 @@
935942 * @mtd: MTD device structure
936943 * @mode: Read/Write mode
937944 */
938
-static void omap_enable_hwecc(struct mtd_info *mtd, int mode)
945
+static void omap_enable_hwecc(struct nand_chip *chip, int mode)
939946 {
940
- struct omap_nand_info *info = mtd_to_omap(mtd);
941
- struct nand_chip *chip = mtd_to_nand(mtd);
947
+ struct omap_nand_info *info = mtd_to_omap(nand_to_mtd(chip));
942948 unsigned int dev_width = (chip->options & NAND_BUSWIDTH_16) ? 1 : 0;
943949 u32 val;
944950
....@@ -972,8 +978,7 @@
972978
973979 /**
974980 * omap_wait - wait until the command is done
975
- * @mtd: MTD device structure
976
- * @chip: NAND Chip structure
981
+ * @this: NAND Chip structure
977982 *
978983 * Wait function is called during Program and erase operations and
979984 * the way it is called from MTD layer, we should wait till the NAND
....@@ -982,17 +987,13 @@
982987 * Erase can take up to 400ms and program up to 20ms according to
983988 * general NAND and SmartMedia specs
984989 */
985
-static int omap_wait(struct mtd_info *mtd, struct nand_chip *chip)
990
+static int omap_wait(struct nand_chip *this)
986991 {
987
- struct nand_chip *this = mtd_to_nand(mtd);
988
- struct omap_nand_info *info = mtd_to_omap(mtd);
992
+ struct omap_nand_info *info = mtd_to_omap(nand_to_mtd(this));
989993 unsigned long timeo = jiffies;
990
- int status, state = this->state;
994
+ int status;
991995
992
- if (state == FL_ERASING)
993
- timeo += msecs_to_jiffies(400);
994
- else
995
- timeo += msecs_to_jiffies(20);
996
+ timeo += msecs_to_jiffies(400);
996997
997998 writeb(NAND_CMD_STATUS & 0xFF, info->reg.gpmc_nand_command);
998999 while (time_before(jiffies, timeo)) {
....@@ -1012,9 +1013,9 @@
10121013 *
10131014 * Returns true if ready and false if busy.
10141015 */
1015
-static int omap_dev_ready(struct mtd_info *mtd)
1016
+static int omap_dev_ready(struct nand_chip *chip)
10161017 {
1017
- struct omap_nand_info *info = mtd_to_omap(mtd);
1018
+ struct omap_nand_info *info = mtd_to_omap(nand_to_mtd(chip));
10181019
10191020 return gpiod_get_value(info->ready_gpiod);
10201021 }
....@@ -1030,13 +1031,13 @@
10301031 * eccsize0 = 0 (no additional protected byte in spare area)
10311032 * eccsize1 = 32 (skip 32 nibbles = 16 bytes per sector in spare area)
10321033 */
1033
-static void __maybe_unused omap_enable_hwecc_bch(struct mtd_info *mtd, int mode)
1034
+static void __maybe_unused omap_enable_hwecc_bch(struct nand_chip *chip,
1035
+ int mode)
10341036 {
10351037 unsigned int bch_type;
10361038 unsigned int dev_width, nsectors;
1037
- struct omap_nand_info *info = mtd_to_omap(mtd);
1039
+ struct omap_nand_info *info = mtd_to_omap(nand_to_mtd(chip));
10381040 enum omap_ecc ecc_opt = info->ecc_opt;
1039
- struct nand_chip *chip = mtd_to_nand(mtd);
10401041 u32 val, wr_mode;
10411042 unsigned int ecc_size1, ecc_size0;
10421043
....@@ -1256,7 +1257,7 @@
12561257
12571258 /**
12581259 * omap_calculate_ecc_bch_sw - ECC generator for sector for SW based correction
1259
- * @mtd: MTD device structure
1260
+ * @chip: NAND chip object
12601261 * @dat: The pointer to data on which ecc is computed
12611262 * @ecc_code: The ecc_code buffer
12621263 *
....@@ -1264,10 +1265,10 @@
12641265 * when SW based correction is required as ECC is required for one sector
12651266 * at a time.
12661267 */
1267
-static int omap_calculate_ecc_bch_sw(struct mtd_info *mtd,
1268
+static int omap_calculate_ecc_bch_sw(struct nand_chip *chip,
12681269 const u_char *dat, u_char *ecc_calc)
12691270 {
1270
- return _omap_calculate_ecc_bch(mtd, dat, ecc_calc, 0);
1271
+ return _omap_calculate_ecc_bch(nand_to_mtd(chip), dat, ecc_calc, 0);
12711272 }
12721273
12731274 /**
....@@ -1339,7 +1340,7 @@
13391340
13401341 /**
13411342 * omap_elm_correct_data - corrects page data area in case error reported
1342
- * @mtd: MTD device structure
1343
+ * @chip: NAND chip object
13431344 * @data: page data
13441345 * @read_ecc: ecc read from nand flash
13451346 * @calc_ecc: ecc read from HW ECC registers
....@@ -1348,10 +1349,10 @@
13481349 * In case of non-zero ecc vector, first filter out erased-pages, and
13491350 * then process data via ELM to detect bit-flips.
13501351 */
1351
-static int omap_elm_correct_data(struct mtd_info *mtd, u_char *data,
1352
- u_char *read_ecc, u_char *calc_ecc)
1352
+static int omap_elm_correct_data(struct nand_chip *chip, u_char *data,
1353
+ u_char *read_ecc, u_char *calc_ecc)
13531354 {
1354
- struct omap_nand_info *info = mtd_to_omap(mtd);
1355
+ struct omap_nand_info *info = mtd_to_omap(nand_to_mtd(chip));
13551356 struct nand_ecc_ctrl *ecc = &info->nand.ecc;
13561357 int eccsteps = info->nand.ecc.steps;
13571358 int i , j, stat = 0;
....@@ -1500,7 +1501,7 @@
15001501 }
15011502
15021503 /* Update number of correctable errors */
1503
- stat += err_vec[i].error_count;
1504
+ stat = max_t(unsigned int, stat, err_vec[i].error_count);
15041505
15051506 /* Update page data with sector size */
15061507 data += ecc->size;
....@@ -1512,7 +1513,6 @@
15121513
15131514 /**
15141515 * omap_write_page_bch - BCH ecc based write page function for entire page
1515
- * @mtd: mtd info structure
15161516 * @chip: nand chip info structure
15171517 * @buf: data buffer
15181518 * @oob_required: must write chip->oob_poi to OOB
....@@ -1520,19 +1520,20 @@
15201520 *
15211521 * Custom write page method evolved to support multi sector writing in one shot
15221522 */
1523
-static int omap_write_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
1524
- const uint8_t *buf, int oob_required, int page)
1523
+static int omap_write_page_bch(struct nand_chip *chip, const uint8_t *buf,
1524
+ int oob_required, int page)
15251525 {
1526
+ struct mtd_info *mtd = nand_to_mtd(chip);
15261527 int ret;
15271528 uint8_t *ecc_calc = chip->ecc.calc_buf;
15281529
15291530 nand_prog_page_begin_op(chip, page, 0, NULL, 0);
15301531
15311532 /* Enable GPMC ecc engine */
1532
- chip->ecc.hwctl(mtd, NAND_ECC_WRITE);
1533
+ chip->ecc.hwctl(chip, NAND_ECC_WRITE);
15331534
15341535 /* Write data */
1535
- chip->write_buf(mtd, buf, mtd->writesize);
1536
+ chip->legacy.write_buf(chip, buf, mtd->writesize);
15361537
15371538 /* Update ecc vector from GPMC result registers */
15381539 omap_calculate_ecc_bch_multi(mtd, buf, &ecc_calc[0]);
....@@ -1543,14 +1544,13 @@
15431544 return ret;
15441545
15451546 /* Write ecc vector to OOB area */
1546
- chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
1547
+ chip->legacy.write_buf(chip, chip->oob_poi, mtd->oobsize);
15471548
15481549 return nand_prog_page_end_op(chip);
15491550 }
15501551
15511552 /**
15521553 * omap_write_subpage_bch - BCH hardware ECC based subpage write
1553
- * @mtd: mtd info structure
15541554 * @chip: nand chip info structure
15551555 * @offset: column address of subpage within the page
15561556 * @data_len: data length
....@@ -1560,11 +1560,11 @@
15601560 *
15611561 * OMAP optimized subpage write method.
15621562 */
1563
-static int omap_write_subpage_bch(struct mtd_info *mtd,
1564
- struct nand_chip *chip, u32 offset,
1563
+static int omap_write_subpage_bch(struct nand_chip *chip, u32 offset,
15651564 u32 data_len, const u8 *buf,
15661565 int oob_required, int page)
15671566 {
1567
+ struct mtd_info *mtd = nand_to_mtd(chip);
15681568 u8 *ecc_calc = chip->ecc.calc_buf;
15691569 int ecc_size = chip->ecc.size;
15701570 int ecc_bytes = chip->ecc.bytes;
....@@ -1582,10 +1582,10 @@
15821582 nand_prog_page_begin_op(chip, page, 0, NULL, 0);
15831583
15841584 /* Enable GPMC ECC engine */
1585
- chip->ecc.hwctl(mtd, NAND_ECC_WRITE);
1585
+ chip->ecc.hwctl(chip, NAND_ECC_WRITE);
15861586
15871587 /* Write data */
1588
- chip->write_buf(mtd, buf, mtd->writesize);
1588
+ chip->legacy.write_buf(chip, buf, mtd->writesize);
15891589
15901590 for (step = 0; step < ecc_steps; step++) {
15911591 /* mask ECC of un-touched subpages by padding 0xFF */
....@@ -1610,14 +1610,13 @@
16101610 return ret;
16111611
16121612 /* write OOB buffer to NAND device */
1613
- chip->write_buf(mtd, chip->oob_poi, mtd->oobsize);
1613
+ chip->legacy.write_buf(chip, chip->oob_poi, mtd->oobsize);
16141614
16151615 return nand_prog_page_end_op(chip);
16161616 }
16171617
16181618 /**
16191619 * omap_read_page_bch - BCH ecc based page read function for entire page
1620
- * @mtd: mtd info structure
16211620 * @chip: nand chip info structure
16221621 * @buf: buffer to store read data
16231622 * @oob_required: caller requires OOB data read to chip->oob_poi
....@@ -1630,9 +1629,10 @@
16301629 * ecc engine enabled. ecc vector updated after read of OOB data.
16311630 * For non error pages ecc vector reported as zero.
16321631 */
1633
-static int omap_read_page_bch(struct mtd_info *mtd, struct nand_chip *chip,
1634
- uint8_t *buf, int oob_required, int page)
1632
+static int omap_read_page_bch(struct nand_chip *chip, uint8_t *buf,
1633
+ int oob_required, int page)
16351634 {
1635
+ struct mtd_info *mtd = nand_to_mtd(chip);
16361636 uint8_t *ecc_calc = chip->ecc.calc_buf;
16371637 uint8_t *ecc_code = chip->ecc.code_buf;
16381638 int stat, ret;
....@@ -1641,10 +1641,10 @@
16411641 nand_read_page_op(chip, page, 0, NULL, 0);
16421642
16431643 /* Enable GPMC ecc engine */
1644
- chip->ecc.hwctl(mtd, NAND_ECC_READ);
1644
+ chip->ecc.hwctl(chip, NAND_ECC_READ);
16451645
16461646 /* Read data */
1647
- chip->read_buf(mtd, buf, mtd->writesize);
1647
+ chip->legacy.read_buf(chip, buf, mtd->writesize);
16481648
16491649 /* Read oob bytes */
16501650 nand_change_read_column_op(chip,
....@@ -1660,7 +1660,7 @@
16601660 if (ret)
16611661 return ret;
16621662
1663
- stat = chip->ecc.correct(mtd, buf, ecc_code, ecc_calc);
1663
+ stat = chip->ecc.correct(chip, buf, ecc_code, ecc_calc);
16641664
16651665 if (stat < 0) {
16661666 mtd->ecc_stats.failed++;
....@@ -1722,9 +1722,9 @@
17221722 break;
17231723 }
17241724
1725
- if (ecc_needs_bch && !IS_ENABLED(CONFIG_MTD_NAND_ECC_BCH)) {
1725
+ if (ecc_needs_bch && !IS_ENABLED(CONFIG_MTD_NAND_ECC_SW_BCH)) {
17261726 dev_err(&info->pdev->dev,
1727
- "CONFIG_MTD_NAND_ECC_BCH not enabled\n");
1727
+ "CONFIG_MTD_NAND_ECC_SW_BCH not enabled\n");
17281728 return false;
17291729 }
17301730 if (ecc_needs_omap_bch && !IS_ENABLED(CONFIG_MTD_NAND_OMAP_BCH)) {
....@@ -1927,8 +1927,8 @@
19271927 /* Re-populate low-level callbacks based on xfer modes */
19281928 switch (info->xfer_type) {
19291929 case NAND_OMAP_PREFETCH_POLLED:
1930
- chip->read_buf = omap_read_buf_pref;
1931
- chip->write_buf = omap_write_buf_pref;
1930
+ chip->legacy.read_buf = omap_read_buf_pref;
1931
+ chip->legacy.write_buf = omap_write_buf_pref;
19321932 break;
19331933
19341934 case NAND_OMAP_POLLED:
....@@ -1960,17 +1960,15 @@
19601960 err);
19611961 return err;
19621962 }
1963
- chip->read_buf = omap_read_buf_dma_pref;
1964
- chip->write_buf = omap_write_buf_dma_pref;
1963
+ chip->legacy.read_buf = omap_read_buf_dma_pref;
1964
+ chip->legacy.write_buf = omap_write_buf_dma_pref;
19651965 }
19661966 break;
19671967
19681968 case NAND_OMAP_PREFETCH_IRQ:
19691969 info->gpmc_irq_fifo = platform_get_irq(info->pdev, 0);
1970
- if (info->gpmc_irq_fifo <= 0) {
1971
- dev_err(dev, "Error getting fifo IRQ\n");
1970
+ if (info->gpmc_irq_fifo <= 0)
19721971 return -ENODEV;
1973
- }
19741972 err = devm_request_irq(dev, info->gpmc_irq_fifo,
19751973 omap_nand_irq, IRQF_SHARED,
19761974 "gpmc-nand-fifo", info);
....@@ -1982,10 +1980,8 @@
19821980 }
19831981
19841982 info->gpmc_irq_count = platform_get_irq(info->pdev, 1);
1985
- if (info->gpmc_irq_count <= 0) {
1986
- dev_err(dev, "Error getting IRQ count\n");
1983
+ if (info->gpmc_irq_count <= 0)
19871984 return -ENODEV;
1988
- }
19891985 err = devm_request_irq(dev, info->gpmc_irq_count,
19901986 omap_nand_irq, IRQF_SHARED,
19911987 "gpmc-nand-count", info);
....@@ -1996,8 +1992,8 @@
19961992 return err;
19971993 }
19981994
1999
- chip->read_buf = omap_read_buf_irq_pref;
2000
- chip->write_buf = omap_write_buf_irq_pref;
1995
+ chip->legacy.read_buf = omap_read_buf_irq_pref;
1996
+ chip->legacy.write_buf = omap_write_buf_irq_pref;
20011997
20021998 break;
20031999
....@@ -2010,12 +2006,12 @@
20102006 return -EINVAL;
20112007
20122008 /*
2013
- * Bail out earlier to let NAND_ECC_SOFT code create its own
2009
+ * Bail out earlier to let NAND_ECC_ENGINE_TYPE_SOFT code create its own
20142010 * ooblayout instead of using ours.
20152011 */
20162012 if (info->ecc_opt == OMAP_ECC_HAM1_CODE_SW) {
2017
- chip->ecc.mode = NAND_ECC_SOFT;
2018
- chip->ecc.algo = NAND_ECC_HAMMING;
2013
+ chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_SOFT;
2014
+ chip->ecc.algo = NAND_ECC_ALGO_HAMMING;
20192015 return 0;
20202016 }
20212017
....@@ -2023,7 +2019,7 @@
20232019 switch (info->ecc_opt) {
20242020 case OMAP_ECC_HAM1_CODE_HW:
20252021 dev_info(dev, "nand: using OMAP_ECC_HAM1_CODE_HW\n");
2026
- chip->ecc.mode = NAND_ECC_HW;
2022
+ chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
20272023 chip->ecc.bytes = 3;
20282024 chip->ecc.size = 512;
20292025 chip->ecc.strength = 1;
....@@ -2040,7 +2036,7 @@
20402036
20412037 case OMAP_ECC_BCH4_CODE_HW_DETECTION_SW:
20422038 pr_info("nand: using OMAP_ECC_BCH4_CODE_HW_DETECTION_SW\n");
2043
- chip->ecc.mode = NAND_ECC_HW;
2039
+ chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
20442040 chip->ecc.size = 512;
20452041 chip->ecc.bytes = 7;
20462042 chip->ecc.strength = 4;
....@@ -2060,7 +2056,7 @@
20602056
20612057 case OMAP_ECC_BCH4_CODE_HW:
20622058 pr_info("nand: using OMAP_ECC_BCH4_CODE_HW ECC scheme\n");
2063
- chip->ecc.mode = NAND_ECC_HW;
2059
+ chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
20642060 chip->ecc.size = 512;
20652061 /* 14th bit is kept reserved for ROM-code compatibility */
20662062 chip->ecc.bytes = 7 + 1;
....@@ -2082,7 +2078,7 @@
20822078
20832079 case OMAP_ECC_BCH8_CODE_HW_DETECTION_SW:
20842080 pr_info("nand: using OMAP_ECC_BCH8_CODE_HW_DETECTION_SW\n");
2085
- chip->ecc.mode = NAND_ECC_HW;
2081
+ chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
20862082 chip->ecc.size = 512;
20872083 chip->ecc.bytes = 13;
20882084 chip->ecc.strength = 8;
....@@ -2102,7 +2098,7 @@
21022098
21032099 case OMAP_ECC_BCH8_CODE_HW:
21042100 pr_info("nand: using OMAP_ECC_BCH8_CODE_HW ECC scheme\n");
2105
- chip->ecc.mode = NAND_ECC_HW;
2101
+ chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
21062102 chip->ecc.size = 512;
21072103 /* 14th bit is kept reserved for ROM-code compatibility */
21082104 chip->ecc.bytes = 13 + 1;
....@@ -2125,7 +2121,7 @@
21252121
21262122 case OMAP_ECC_BCH16_CODE_HW:
21272123 pr_info("Using OMAP_ECC_BCH16_CODE_HW ECC scheme\n");
2128
- chip->ecc.mode = NAND_ECC_HW;
2124
+ chip->ecc.engine_type = NAND_ECC_ENGINE_TYPE_ON_HOST;
21292125 chip->ecc.size = 512;
21302126 chip->ecc.bytes = 26;
21312127 chip->ecc.strength = 16;
....@@ -2167,11 +2163,8 @@
21672163 };
21682164
21692165 /* Shared among all NAND instances to synchronize access to the ECC Engine */
2170
-static struct nand_controller omap_gpmc_controller = {
2171
- .lock = __SPIN_LOCK_UNLOCKED(omap_gpmc_controller.lock),
2172
- .wq = __WAIT_QUEUE_HEAD_INITIALIZER(omap_gpmc_controller.wq),
2173
- .ops = &omap_nand_controller_ops,
2174
-};
2166
+static struct nand_controller omap_gpmc_controller;
2167
+static bool omap_gpmc_controller_initialized;
21752168
21762169 static int omap_nand_probe(struct platform_device *pdev)
21772170 {
....@@ -2215,16 +2208,22 @@
22152208 }
22162209
22172210 res = platform_get_resource(pdev, IORESOURCE_MEM, 0);
2218
- nand_chip->IO_ADDR_R = devm_ioremap_resource(&pdev->dev, res);
2219
- if (IS_ERR(nand_chip->IO_ADDR_R))
2220
- return PTR_ERR(nand_chip->IO_ADDR_R);
2211
+ nand_chip->legacy.IO_ADDR_R = devm_ioremap_resource(&pdev->dev, res);
2212
+ if (IS_ERR(nand_chip->legacy.IO_ADDR_R))
2213
+ return PTR_ERR(nand_chip->legacy.IO_ADDR_R);
22212214
22222215 info->phys_base = res->start;
22232216
2217
+ if (!omap_gpmc_controller_initialized) {
2218
+ omap_gpmc_controller.ops = &omap_nand_controller_ops;
2219
+ nand_controller_init(&omap_gpmc_controller);
2220
+ omap_gpmc_controller_initialized = true;
2221
+ }
2222
+
22242223 nand_chip->controller = &omap_gpmc_controller;
22252224
2226
- nand_chip->IO_ADDR_W = nand_chip->IO_ADDR_R;
2227
- nand_chip->cmd_ctrl = omap_hwcontrol;
2225
+ nand_chip->legacy.IO_ADDR_W = nand_chip->legacy.IO_ADDR_R;
2226
+ nand_chip->legacy.cmd_ctrl = omap_hwcontrol;
22282227
22292228 info->ready_gpiod = devm_gpiod_get_optional(&pdev->dev, "rb",
22302229 GPIOD_IN);
....@@ -2241,11 +2240,11 @@
22412240 * device and read status register until you get a failure or success
22422241 */
22432242 if (info->ready_gpiod) {
2244
- nand_chip->dev_ready = omap_dev_ready;
2245
- nand_chip->chip_delay = 0;
2243
+ nand_chip->legacy.dev_ready = omap_dev_ready;
2244
+ nand_chip->legacy.chip_delay = 0;
22462245 } else {
2247
- nand_chip->waitfunc = omap_wait;
2248
- nand_chip->chip_delay = 50;
2246
+ nand_chip->legacy.waitfunc = omap_wait;
2247
+ nand_chip->legacy.chip_delay = 50;
22492248 }
22502249
22512250 if (info->flash_bbt)
....@@ -2284,14 +2283,18 @@
22842283 struct mtd_info *mtd = platform_get_drvdata(pdev);
22852284 struct nand_chip *nand_chip = mtd_to_nand(mtd);
22862285 struct omap_nand_info *info = mtd_to_omap(mtd);
2286
+ int ret;
2287
+
22872288 if (nand_chip->ecc.priv) {
22882289 nand_bch_free(nand_chip->ecc.priv);
22892290 nand_chip->ecc.priv = NULL;
22902291 }
22912292 if (info->dma)
22922293 dma_release_channel(info->dma);
2293
- nand_release(nand_chip);
2294
- return 0;
2294
+ ret = mtd_device_unregister(mtd);
2295
+ WARN_ON(ret);
2296
+ nand_cleanup(nand_chip);
2297
+ return ret;
22952298 }
22962299
22972300 static const struct of_device_id omap_nand_ids[] = {