Skip to content

Commit 6e89b84

Browse files
author
Boris Brezillon
committed
Merge tag 'nand/for-4.18' of git://git.infradead.org/linux-mtd into mtd/next
Core changes: - Add Miquel as a NAND maintainer - Add access mode to the nand_page_io_req struct - Fix kernel-doc in rawnand.h - Support bit-wise majority to recover from corrupted ONFI parameter pages - Stop checking FAIL bit after a SET_FEATURES, as documented in the ONFI spec Raw NAND Driver changes: - Fix and cleanup the error path of many NAND controller drivers - GPMI: * Cleanup/simplification of a few aspects in the driver * Take ECC setup specified in the DT into account - sunxi: remove support for GPIO-based R/B polling - MTK: * Use of_device_get_match_data() instead of of_match_device() * Add an entry in MAINTAINERS for this driver * Fix nand-ecc-step-size and nand-ecc-strength description in the DT bindings doc - fsl_ifc: fix ->cmdfunc() to read more than one ONFI parameter page OneNAND driver changes: - samsung: use dev_get_drvdata() instead of platform_get_drvdata()
2 parents c64d441 + f567c71 commit 6e89b84

22 files changed

Lines changed: 328 additions & 416 deletions

‎Documentation/devicetree/bindings/mtd/gpmi-nand.txt‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,11 @@ Optional properties:
4747
partitions written from Linux with this feature
4848
turned on may not be accessible by the BootROM
4949
code.
50+
- nand-ecc-strength: integer representing the number of bits to correct
51+
per ECC step. Needs to be a multiple of 2.
52+
- nand-ecc-step-size: integer representing the number of data bytes
53+
that are covered by a single ECC step. The driver
54+
supports 512 and 1024.
5055

5156
The device tree may optionally contain sub-nodes describing partitions of the
5257
address space. See partition.txt for more detail.

‎Documentation/devicetree/bindings/mtd/mtk-nand.txt‎

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,19 @@ Optional:
5050
- nand-on-flash-bbt: Store BBT on NAND Flash.
5151
- nand-ecc-mode: the NAND ecc mode (check driver for supported modes)
5252
- nand-ecc-step-size: Number of data bytes covered by a single ECC step.
53-
valid values: 512 and 1024.
53+
valid values:
54+
512 and 1024 on mt2701 and mt2712.
55+
512 only on mt7622.
5456
1024 is recommended for large page NANDs.
5557
- nand-ecc-strength: Number of bits to correct per ECC step.
56-
The valid values that the controller supports are: 4, 6,
57-
8, 10, 12, 14, 16, 18, 20, 22, 24, 28, 32, 36, 40, 44,
58-
48, 52, 56, 60.
58+
The valid values that each controller supports:
59+
mt2701: 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28,
60+
32, 36, 40, 44, 48, 52, 56, 60.
61+
mt2712: 4, 6, 8, 10, 12, 14, 16, 18, 20, 22, 24, 28,
62+
32, 36, 40, 44, 48, 52, 56, 60, 68, 72, 80.
63+
mt7622: 4, 6, 8, 10, 12, 14, 16.
5964
The strength should be calculated as follows:
60-
E = (S - F) * 8 / 14
65+
E = (S - F) * 8 / B
6166
S = O / (P / Q)
6267
E : nand-ecc-strength.
6368
S : spare size per sector.
@@ -66,6 +71,15 @@ Optional:
6671
O : oob size.
6772
P : page size.
6873
Q : nand-ecc-step-size.
74+
B : number of parity bits needed to correct
75+
1 bitflip.
76+
According to MTK NAND controller design,
77+
this number depends on max ecc step size
78+
that MTK NAND controller supports.
79+
If max ecc step size supported is 1024,
80+
then it should be always 14. And if max
81+
ecc step size is 512, then it should be
82+
always 13.
6983
If the result does not match any one of the listed
7084
choices above, please select the smaller valid value from
7185
the list.

‎Documentation/devicetree/bindings/mtd/sunxi-nand.txt‎

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,6 @@ Optional properties:
2222
- reset : phandle + reset specifier pair
2323
- reset-names : must contain "ahb"
2424
- allwinner,rb : shall contain the native Ready/Busy ids.
25-
or
26-
- rb-gpios : shall contain the gpios used as R/B pins.
2725
- nand-ecc-mode : one of the supported ECC modes ("hw", "soft", "soft_bch" or
2826
"none")
2927

‎MAINTAINERS‎

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8941,6 +8941,13 @@ L: linux-wireless@vger.kernel.org
89418941
S: Maintained
89428942
F: drivers/net/wireless/mediatek/mt7601u/
89438943

8944+
MEDIATEK NAND CONTROLLER DRIVER
8945+
M: Xiaolei Li <xiaolei.li@mediatek.com>
8946+
L: linux-mtd@lists.infradead.org
8947+
S: Maintained
8948+
F: drivers/mtd/nand/raw/mtk_*
8949+
F: Documentation/devicetree/bindings/mtd/mtk-nand.txt
8950+
89448951
MEDIATEK RANDOM NUMBER GENERATOR SUPPORT
89458952
M: Sean Wang <sean.wang@mediatek.com>
89468953
S: Maintained
@@ -9574,6 +9581,7 @@ F: drivers/net/ethernet/myricom/myri10ge/
95749581

95759582
NAND FLASH SUBSYSTEM
95769583
M: Boris Brezillon <boris.brezillon@bootlin.com>
9584+
M: Miquel Raynal <miquel.raynal@bootlin.com>
95779585
R: Richard Weinberger <richard@nod.at>
95789586
L: linux-mtd@lists.infradead.org
95799587
W: http://www.linux-mtd.infradead.org/

‎drivers/mtd/nand/onenand/samsung.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -958,8 +958,7 @@ static int s3c_onenand_remove(struct platform_device *pdev)
958958

959959
static int s3c_pm_ops_suspend(struct device *dev)
960960
{
961-
struct platform_device *pdev = to_platform_device(dev);
962-
struct mtd_info *mtd = platform_get_drvdata(pdev);
961+
struct mtd_info *mtd = dev_get_drvdata(dev);
963962
struct onenand_chip *this = mtd->priv;
964963

965964
this->wait(mtd, FL_PM_SUSPENDED);
@@ -968,8 +967,7 @@ static int s3c_pm_ops_suspend(struct device *dev)
968967

969968
static int s3c_pm_ops_resume(struct device *dev)
970969
{
971-
struct platform_device *pdev = to_platform_device(dev);
972-
struct mtd_info *mtd = platform_get_drvdata(pdev);
970+
struct mtd_info *mtd = dev_get_drvdata(dev);
973971
struct onenand_chip *this = mtd->priv;
974972

975973
this->unlock_all(mtd);

‎drivers/mtd/nand/raw/davinci_nand.c‎

Lines changed: 1 addition & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
#include <linux/module.h>
2828
#include <linux/platform_device.h>
2929
#include <linux/err.h>
30-
#include <linux/clk.h>
3130
#include <linux/io.h>
3231
#include <linux/mtd/rawnand.h>
3332
#include <linux/mtd/partitions.h>
@@ -55,7 +54,6 @@ struct davinci_nand_info {
5554
struct nand_chip chip;
5655

5756
struct device *dev;
58-
struct clk *clk;
5957

6058
bool is_readmode;
6159

@@ -703,22 +701,6 @@ static int nand_davinci_probe(struct platform_device *pdev)
703701
/* Use board-specific ECC config */
704702
info->chip.ecc.mode = pdata->ecc_mode;
705703

706-
ret = -EINVAL;
707-
708-
info->clk = devm_clk_get(&pdev->dev, "aemif");
709-
if (IS_ERR(info->clk)) {
710-
ret = PTR_ERR(info->clk);
711-
dev_dbg(&pdev->dev, "unable to get AEMIF clock, err %d\n", ret);
712-
return ret;
713-
}
714-
715-
ret = clk_prepare_enable(info->clk);
716-
if (ret < 0) {
717-
dev_dbg(&pdev->dev, "unable to enable AEMIF clock, err %d\n",
718-
ret);
719-
goto err_clk_enable;
720-
}
721-
722704
spin_lock_irq(&davinci_nand_lock);
723705

724706
/* put CSxNAND into NAND mode */
@@ -732,7 +714,7 @@ static int nand_davinci_probe(struct platform_device *pdev)
732714
ret = nand_scan_ident(mtd, pdata->mask_chipsel ? 2 : 1, NULL);
733715
if (ret < 0) {
734716
dev_dbg(&pdev->dev, "no NAND chip(s) found\n");
735-
goto err;
717+
return ret;
736718
}
737719

738720
switch (info->chip.ecc.mode) {
@@ -838,9 +820,6 @@ static int nand_davinci_probe(struct platform_device *pdev)
838820
nand_cleanup(&info->chip);
839821

840822
err:
841-
clk_disable_unprepare(info->clk);
842-
843-
err_clk_enable:
844823
spin_lock_irq(&davinci_nand_lock);
845824
if (info->chip.ecc.mode == NAND_ECC_HW_SYNDROME)
846825
ecc4_busy = false;
@@ -859,8 +838,6 @@ static int nand_davinci_remove(struct platform_device *pdev)
859838

860839
nand_release(nand_to_mtd(&info->chip));
861840

862-
clk_disable_unprepare(info->clk);
863-
864841
return 0;
865842
}
866843

‎drivers/mtd/nand/raw/diskonchip.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1481,12 +1481,12 @@ static int __init doc_probe(unsigned long physadr)
14811481
WriteDOC(tmp, virtadr, Mplus_DOCControl);
14821482
WriteDOC(~tmp, virtadr, Mplus_CtrlConfirm);
14831483

1484-
mdelay(1);
1484+
usleep_range(1000, 2000);
14851485
/* Enable the Millennium Plus ASIC */
14861486
tmp = DOC_MODE_NORMAL | DOC_MODE_MDWREN | DOC_MODE_RST_LAT | DOC_MODE_BDECT;
14871487
WriteDOC(tmp, virtadr, Mplus_DOCControl);
14881488
WriteDOC(~tmp, virtadr, Mplus_CtrlConfirm);
1489-
mdelay(1);
1489+
usleep_range(1000, 2000);
14901490

14911491
ChipID = ReadDOC(virtadr, ChipID);
14921492

‎drivers/mtd/nand/raw/fsl_elbc_nand.c‎

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -813,8 +813,6 @@ static int fsl_elbc_chip_remove(struct fsl_elbc_mtd *priv)
813813
struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = priv->ctrl->nand;
814814
struct mtd_info *mtd = nand_to_mtd(&priv->chip);
815815

816-
nand_release(mtd);
817-
818816
kfree(mtd->name);
819817

820818
if (priv->vbase)
@@ -926,23 +924,30 @@ static int fsl_elbc_nand_probe(struct platform_device *pdev)
926924

927925
/* First look for RedBoot table or partitions on the command
928926
* line, these take precedence over device tree information */
929-
mtd_device_parse_register(mtd, part_probe_types, NULL,
930-
NULL, 0);
927+
ret = mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0);
928+
if (ret)
929+
goto cleanup_nand;
931930

932931
pr_info("eLBC NAND device at 0x%llx, bank %d\n",
933932
(unsigned long long)res.start, priv->bank);
933+
934934
return 0;
935935

936+
cleanup_nand:
937+
nand_cleanup(&priv->chip);
936938
err:
937939
fsl_elbc_chip_remove(priv);
940+
938941
return ret;
939942
}
940943

941944
static int fsl_elbc_nand_remove(struct platform_device *pdev)
942945
{
943946
struct fsl_elbc_fcm_ctrl *elbc_fcm_ctrl = fsl_lbc_ctrl_dev->nand;
944947
struct fsl_elbc_mtd *priv = dev_get_drvdata(&pdev->dev);
948+
struct mtd_info *mtd = nand_to_mtd(&priv->chip);
945949

950+
nand_release(mtd);
946951
fsl_elbc_chip_remove(priv);
947952

948953
mutex_lock(&fsl_elbc_nand_mutex);

‎drivers/mtd/nand/raw/fsl_ifc_nand.c‎

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -342,9 +342,16 @@ static void fsl_ifc_cmdfunc(struct mtd_info *mtd, unsigned int command,
342342

343343
case NAND_CMD_READID:
344344
case NAND_CMD_PARAM: {
345+
/*
346+
* For READID, read 8 bytes that are currently used.
347+
* For PARAM, read all 3 copies of 256-bytes pages.
348+
*/
349+
int len = 8;
345350
int timing = IFC_FIR_OP_RB;
346-
if (command == NAND_CMD_PARAM)
351+
if (command == NAND_CMD_PARAM) {
347352
timing = IFC_FIR_OP_RBCD;
353+
len = 256 * 3;
354+
}
348355

349356
ifc_out32((IFC_FIR_OP_CW0 << IFC_NAND_FIR0_OP0_SHIFT) |
350357
(IFC_FIR_OP_UA << IFC_NAND_FIR0_OP1_SHIFT) |
@@ -354,12 +361,8 @@ static void fsl_ifc_cmdfunc(struct mtd_info *mtd, unsigned int command,
354361
&ifc->ifc_nand.nand_fcr0);
355362
ifc_out32(column, &ifc->ifc_nand.row3);
356363

357-
/*
358-
* although currently it's 8 bytes for READID, we always read
359-
* the maximum 256 bytes(for PARAM)
360-
*/
361-
ifc_out32(256, &ifc->ifc_nand.nand_fbcr);
362-
ifc_nand_ctrl->read_bytes = 256;
364+
ifc_out32(len, &ifc->ifc_nand.nand_fbcr);
365+
ifc_nand_ctrl->read_bytes = len;
363366

364367
set_addr(mtd, 0, 0, 0);
365368
fsl_ifc_run_command(mtd);
@@ -924,8 +927,6 @@ static int fsl_ifc_chip_remove(struct fsl_ifc_mtd *priv)
924927
{
925928
struct mtd_info *mtd = nand_to_mtd(&priv->chip);
926929

927-
nand_release(mtd);
928-
929930
kfree(mtd->name);
930931

931932
if (priv->vbase)
@@ -1059,21 +1060,29 @@ static int fsl_ifc_nand_probe(struct platform_device *dev)
10591060

10601061
/* First look for RedBoot table or partitions on the command
10611062
* line, these take precedence over device tree information */
1062-
mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0);
1063+
ret = mtd_device_parse_register(mtd, part_probe_types, NULL, NULL, 0);
1064+
if (ret)
1065+
goto cleanup_nand;
10631066

10641067
dev_info(priv->dev, "IFC NAND device at 0x%llx, bank %d\n",
10651068
(unsigned long long)res.start, priv->bank);
1069+
10661070
return 0;
10671071

1072+
cleanup_nand:
1073+
nand_cleanup(&priv->chip);
10681074
err:
10691075
fsl_ifc_chip_remove(priv);
1076+
10701077
return ret;
10711078
}
10721079

10731080
static int fsl_ifc_nand_remove(struct platform_device *dev)
10741081
{
10751082
struct fsl_ifc_mtd *priv = dev_get_drvdata(&dev->dev);
1083+
struct mtd_info *mtd = nand_to_mtd(&priv->chip);
10761084

1085+
nand_release(mtd);
10771086
fsl_ifc_chip_remove(priv);
10781087

10791088
mutex_lock(&fsl_ifc_nand_mutex);

‎drivers/mtd/nand/raw/fsmc_nand.c‎

Lines changed: 15 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1022,12 +1022,12 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
10221022
host->read_dma_chan = dma_request_channel(mask, filter, NULL);
10231023
if (!host->read_dma_chan) {
10241024
dev_err(&pdev->dev, "Unable to get read dma channel\n");
1025-
goto err_req_read_chnl;
1025+
goto disable_clk;
10261026
}
10271027
host->write_dma_chan = dma_request_channel(mask, filter, NULL);
10281028
if (!host->write_dma_chan) {
10291029
dev_err(&pdev->dev, "Unable to get write dma channel\n");
1030-
goto err_req_write_chnl;
1030+
goto release_dma_read_chan;
10311031
}
10321032
}
10331033

@@ -1050,7 +1050,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
10501050
ret = nand_scan_ident(mtd, 1, NULL);
10511051
if (ret) {
10521052
dev_err(&pdev->dev, "No NAND Device found!\n");
1053-
goto err_scan_ident;
1053+
goto release_dma_write_chan;
10541054
}
10551055

10561056
if (AMBA_REV_BITS(host->pid) >= 8) {
@@ -1065,7 +1065,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
10651065
dev_warn(&pdev->dev, "No oob scheme defined for oobsize %d\n",
10661066
mtd->oobsize);
10671067
ret = -EINVAL;
1068-
goto err_probe;
1068+
goto release_dma_write_chan;
10691069
}
10701070

10711071
mtd_set_ooblayout(mtd, &fsmc_ecc4_ooblayout_ops);
@@ -1090,7 +1090,7 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
10901090

10911091
default:
10921092
dev_err(&pdev->dev, "Unsupported ECC mode!\n");
1093-
goto err_probe;
1093+
goto release_dma_write_chan;
10941094
}
10951095

10961096
/*
@@ -1110,34 +1110,37 @@ static int __init fsmc_nand_probe(struct platform_device *pdev)
11101110
"No oob scheme defined for oobsize %d\n",
11111111
mtd->oobsize);
11121112
ret = -EINVAL;
1113-
goto err_probe;
1113+
goto release_dma_write_chan;
11141114
}
11151115
}
11161116
}
11171117

11181118
/* Second stage of scan to fill MTD data-structures */
11191119
ret = nand_scan_tail(mtd);
11201120
if (ret)
1121-
goto err_probe;
1121+
goto release_dma_write_chan;
11221122

11231123
mtd->name = "nand";
11241124
ret = mtd_device_register(mtd, NULL, 0);
11251125
if (ret)
1126-
goto err_probe;
1126+
goto cleanup_nand;
11271127

11281128
platform_set_drvdata(pdev, host);
11291129
dev_info(&pdev->dev, "FSMC NAND driver registration successful\n");
1130+
11301131
return 0;
11311132

1132-
err_probe:
1133-
err_scan_ident:
1133+
cleanup_nand:
1134+
nand_cleanup(nand);
1135+
release_dma_write_chan:
11341136
if (host->mode == USE_DMA_ACCESS)
11351137
dma_release_channel(host->write_dma_chan);
1136-
err_req_write_chnl:
1138+
release_dma_read_chan:
11371139
if (host->mode == USE_DMA_ACCESS)
11381140
dma_release_channel(host->read_dma_chan);
1139-
err_req_read_chnl:
1141+
disable_clk:
11401142
clk_disable_unprepare(host->clk);
1143+
11411144
return ret;
11421145
}
11431146

0 commit comments

Comments
 (0)