Skip to content

Commit 2dd33fc

Browse files
committed
Merge tag 'nand/for-6.15' into mtd/next
* Raw NAND changes: i.MX8 and i.MX31 now have their own compatible, the Qcom driver got cleaned, the Broadcom driver got fixed. * SPI NAND changes: Two main features have been added: - OTP support has been brought, and ESMT and Micron manufacturer drivers implement it. - Read retry, and Macronix manufacturer driver implement it. There is as well a bunch of minor improvements and fixes in drivers and bindings.
2 parents 59ee921 + b0e63a0 commit 2dd33fc

File tree

15 files changed

+893
-57
lines changed

15 files changed

+893
-57
lines changed

Documentation/devicetree/bindings/mtd/arasan,nand-controller.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ required:
4242
- clock-names
4343
- interrupts
4444

45-
unevaluatedProperties: true
45+
unevaluatedProperties: false
4646

4747
examples:
4848
- |

Documentation/devicetree/bindings/mtd/gpmi-nand.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,14 @@ properties:
2929
- enum:
3030
- fsl,imx8mm-gpmi-nand
3131
- fsl,imx8mn-gpmi-nand
32+
- fsl,imx8mp-gpmi-nand
33+
- fsl,imx8mq-gpmi-nand
3234
- const: fsl,imx7d-gpmi-nand
35+
- items:
36+
- enum:
37+
- fsl,imx8dxl-gpmi-nand
38+
- fsl,imx8qm-gpmi-nand
39+
- const: fsl,imx8qxp-gpmi-nand
3340

3441
reg:
3542
items:

Documentation/devicetree/bindings/mtd/mxc-nand.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,12 @@ allOf:
1414

1515
properties:
1616
compatible:
17-
const: fsl,imx27-nand
18-
17+
oneOf:
18+
- const: fsl,imx27-nand
19+
- items:
20+
- enum:
21+
- fsl,imx31-nand
22+
- const: fsl,imx27-nand
1923
reg:
2024
maxItems: 1
2125

drivers/mtd/nand/raw/brcmnand/brcmnand.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3008,7 +3008,7 @@ static int brcmnand_resume(struct device *dev)
30083008
brcmnand_save_restore_cs_config(host, 1);
30093009

30103010
/* Reset the chip, required by some chips after power-up */
3011-
nand_reset_op(chip);
3011+
nand_reset(chip, 0);
30123012
}
30133013

30143014
return 0;

drivers/mtd/nand/raw/nand_base.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,7 +1833,7 @@ int nand_readid_op(struct nand_chip *chip, u8 addr, void *buf,
18331833

18341834
/* READ_ID data bytes are received twice in NV-DDR mode */
18351835
if (len && nand_interface_is_nvddr(conf)) {
1836-
ddrbuf = kzalloc(len * 2, GFP_KERNEL);
1836+
ddrbuf = kcalloc(2, len, GFP_KERNEL);
18371837
if (!ddrbuf)
18381838
return -ENOMEM;
18391839

@@ -2203,7 +2203,7 @@ int nand_read_data_op(struct nand_chip *chip, void *buf, unsigned int len,
22032203
* twice.
22042204
*/
22052205
if (force_8bit && nand_interface_is_nvddr(conf)) {
2206-
ddrbuf = kzalloc(len * 2, GFP_KERNEL);
2206+
ddrbuf = kcalloc(2, len, GFP_KERNEL);
22072207
if (!ddrbuf)
22082208
return -ENOMEM;
22092209

drivers/mtd/nand/raw/qcom_nandc.c

Lines changed: 18 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -165,9 +165,9 @@ static void nandc_set_read_loc_first(struct nand_chip *chip,
165165
{
166166
struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
167167
__le32 locreg_val;
168-
u32 val = (((cw_offset) << READ_LOCATION_OFFSET) |
169-
((read_size) << READ_LOCATION_SIZE) |
170-
((is_last_read_loc) << READ_LOCATION_LAST));
168+
u32 val = FIELD_PREP(READ_LOCATION_OFFSET_MASK, cw_offset) |
169+
FIELD_PREP(READ_LOCATION_SIZE_MASK, read_size) |
170+
FIELD_PREP(READ_LOCATION_LAST_MASK, is_last_read_loc);
171171

172172
locreg_val = cpu_to_le32(val);
173173

@@ -197,9 +197,9 @@ static void nandc_set_read_loc_last(struct nand_chip *chip,
197197
{
198198
struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
199199
__le32 locreg_val;
200-
u32 val = (((cw_offset) << READ_LOCATION_OFFSET) |
201-
((read_size) << READ_LOCATION_SIZE) |
202-
((is_last_read_loc) << READ_LOCATION_LAST));
200+
u32 val = FIELD_PREP(READ_LOCATION_OFFSET_MASK, cw_offset) |
201+
FIELD_PREP(READ_LOCATION_SIZE_MASK, read_size) |
202+
FIELD_PREP(READ_LOCATION_LAST_MASK, is_last_read_loc);
203203

204204
locreg_val = cpu_to_le32(val);
205205

@@ -271,14 +271,14 @@ static void update_rw_regs(struct qcom_nand_host *host, int num_cw, bool read, i
271271
}
272272

273273
if (host->use_ecc) {
274-
cfg0 = cpu_to_le32((host->cfg0 & ~(7U << CW_PER_PAGE)) |
275-
(num_cw - 1) << CW_PER_PAGE);
274+
cfg0 = cpu_to_le32((host->cfg0 & ~CW_PER_PAGE_MASK) |
275+
FIELD_PREP(CW_PER_PAGE_MASK, (num_cw - 1)));
276276

277277
cfg1 = cpu_to_le32(host->cfg1);
278278
ecc_bch_cfg = cpu_to_le32(host->ecc_bch_cfg);
279279
} else {
280-
cfg0 = cpu_to_le32((host->cfg0_raw & ~(7U << CW_PER_PAGE)) |
281-
(num_cw - 1) << CW_PER_PAGE);
280+
cfg0 = cpu_to_le32((host->cfg0_raw & ~CW_PER_PAGE_MASK) |
281+
FIELD_PREP(CW_PER_PAGE_MASK, (num_cw - 1)));
282282

283283
cfg1 = cpu_to_le32(host->cfg1_raw);
284284
ecc_bch_cfg = cpu_to_le32(ECC_CFG_ECC_DISABLE);
@@ -882,12 +882,12 @@ static void qcom_nandc_codeword_fixup(struct qcom_nand_host *host, int page)
882882
host->bbm_size - host->cw_data;
883883

884884
host->cfg0 &= ~(SPARE_SIZE_BYTES_MASK | UD_SIZE_BYTES_MASK);
885-
host->cfg0 |= host->spare_bytes << SPARE_SIZE_BYTES |
886-
host->cw_data << UD_SIZE_BYTES;
885+
host->cfg0 |= FIELD_PREP(SPARE_SIZE_BYTES_MASK, host->spare_bytes) |
886+
FIELD_PREP(UD_SIZE_BYTES_MASK, host->cw_data);
887887

888888
host->ecc_bch_cfg &= ~ECC_NUM_DATA_BYTES_MASK;
889-
host->ecc_bch_cfg |= host->cw_data << ECC_NUM_DATA_BYTES;
890-
host->ecc_buf_cfg = (host->cw_data - 1) << NUM_STEPS;
889+
host->ecc_bch_cfg |= FIELD_PREP(ECC_NUM_DATA_BYTES_MASK, host->cw_data);
890+
host->ecc_buf_cfg = FIELD_PREP(NUM_STEPS_MASK, host->cw_data - 1);
891891
}
892892

893893
/* implements ecc->read_page() */
@@ -1531,7 +1531,7 @@ static int qcom_nand_attach_chip(struct nand_chip *chip)
15311531
FIELD_PREP(ECC_PARITY_SIZE_BYTES_BCH_MASK, host->ecc_bytes_hw);
15321532

15331533
if (!nandc->props->qpic_version2)
1534-
host->ecc_buf_cfg = 0x203 << NUM_STEPS;
1534+
host->ecc_buf_cfg = FIELD_PREP(NUM_STEPS_MASK, 0x203);
15351535

15361536
host->clrflashstatus = FS_READY_BSY_N;
15371537
host->clrreadstatus = 0xc0;
@@ -1817,7 +1817,7 @@ static int qcom_misc_cmd_type_exec(struct nand_chip *chip, const struct nand_sub
18171817
q_op.cmd_reg |= cpu_to_le32(PAGE_ACC | LAST_PAGE);
18181818
nandc->regs->addr0 = q_op.addr1_reg;
18191819
nandc->regs->addr1 = q_op.addr2_reg;
1820-
nandc->regs->cfg0 = cpu_to_le32(host->cfg0_raw & ~(7 << CW_PER_PAGE));
1820+
nandc->regs->cfg0 = cpu_to_le32(host->cfg0_raw & ~CW_PER_PAGE_MASK);
18211821
nandc->regs->cfg1 = cpu_to_le32(host->cfg1_raw);
18221822
instrs = 3;
18231823
} else if (q_op.cmd_reg != cpu_to_le32(OP_RESET_DEVICE)) {
@@ -1900,8 +1900,8 @@ static int qcom_param_page_type_exec(struct nand_chip *chip, const struct nand_
19001900
/* configure CMD1 and VLD for ONFI param probing in QPIC v1 */
19011901
if (!nandc->props->qpic_version2) {
19021902
nandc->regs->vld = cpu_to_le32((nandc->vld & ~READ_START_VLD));
1903-
nandc->regs->cmd1 = cpu_to_le32((nandc->cmd1 & ~(0xFF << READ_ADDR))
1904-
| NAND_CMD_PARAM << READ_ADDR);
1903+
nandc->regs->cmd1 = cpu_to_le32((nandc->cmd1 & ~READ_ADDR_MASK) |
1904+
FIELD_PREP(READ_ADDR_MASK, NAND_CMD_PARAM));
19051905
}
19061906

19071907
nandc->regs->exec = cpu_to_le32(1);

drivers/mtd/nand/spi/Makefile

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# SPDX-License-Identifier: GPL-2.0
2-
spinand-objs := core.o alliancememory.o ato.o esmt.o foresee.o gigadevice.o macronix.o
2+
spinand-objs := core.o otp.o
3+
spinand-objs += alliancememory.o ato.o esmt.o foresee.o gigadevice.o macronix.o
34
spinand-objs += micron.o paragon.o skyhigh.o toshiba.o winbond.o xtx.o
45
obj-$(CONFIG_MTD_SPI_NAND) += spinand.o

drivers/mtd/nand/spi/core.c

Lines changed: 75 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -534,10 +534,20 @@ static int spinand_erase_op(struct spinand_device *spinand,
534534
return spi_mem_exec_op(spinand->spimem, &op);
535535
}
536536

537-
static int spinand_wait(struct spinand_device *spinand,
538-
unsigned long initial_delay_us,
539-
unsigned long poll_delay_us,
540-
u8 *s)
537+
/**
538+
* spinand_wait() - Poll memory device status
539+
* @spinand: the spinand device
540+
* @initial_delay_us: delay in us before starting to poll
541+
* @poll_delay_us: time to sleep between reads in us
542+
* @s: the pointer to variable to store the value of REG_STATUS
543+
*
544+
* This function polls a status register (REG_STATUS) and returns when
545+
* the STATUS_READY bit is 0 or when the timeout has expired.
546+
*
547+
* Return: 0 on success, a negative error code otherwise.
548+
*/
549+
int spinand_wait(struct spinand_device *spinand, unsigned long initial_delay_us,
550+
unsigned long poll_delay_us, u8 *s)
541551
{
542552
struct spi_mem_op op = SPINAND_GET_FEATURE_OP(REG_STATUS,
543553
spinand->scratchbuf);
@@ -604,8 +614,16 @@ static int spinand_lock_block(struct spinand_device *spinand, u8 lock)
604614
return spinand_write_reg_op(spinand, REG_BLOCK_LOCK, lock);
605615
}
606616

607-
static int spinand_read_page(struct spinand_device *spinand,
608-
const struct nand_page_io_req *req)
617+
/**
618+
* spinand_read_page() - Read a page
619+
* @spinand: the spinand device
620+
* @req: the I/O request
621+
*
622+
* Return: 0 or a positive number of bitflips corrected on success.
623+
* A negative error code otherwise.
624+
*/
625+
int spinand_read_page(struct spinand_device *spinand,
626+
const struct nand_page_io_req *req)
609627
{
610628
struct nand_device *nand = spinand_to_nand(spinand);
611629
u8 status;
@@ -635,8 +653,16 @@ static int spinand_read_page(struct spinand_device *spinand,
635653
return nand_ecc_finish_io_req(nand, (struct nand_page_io_req *)req);
636654
}
637655

638-
static int spinand_write_page(struct spinand_device *spinand,
639-
const struct nand_page_io_req *req)
656+
/**
657+
* spinand_write_page() - Write a page
658+
* @spinand: the spinand device
659+
* @req: the I/O request
660+
*
661+
* Return: 0 or a positive number of bitflips corrected on success.
662+
* A negative error code otherwise.
663+
*/
664+
int spinand_write_page(struct spinand_device *spinand,
665+
const struct nand_page_io_req *req)
640666
{
641667
struct nand_device *nand = spinand_to_nand(spinand);
642668
u8 status;
@@ -674,11 +700,15 @@ static int spinand_mtd_regular_page_read(struct mtd_info *mtd, loff_t from,
674700
{
675701
struct spinand_device *spinand = mtd_to_spinand(mtd);
676702
struct nand_device *nand = mtd_to_nanddev(mtd);
703+
struct mtd_ecc_stats old_stats;
677704
struct nand_io_iter iter;
678705
bool disable_ecc = false;
679706
bool ecc_failed = false;
707+
unsigned int retry_mode = 0;
680708
int ret;
681709

710+
old_stats = mtd->ecc_stats;
711+
682712
if (ops->mode == MTD_OPS_RAW || !mtd->ooblayout)
683713
disable_ecc = true;
684714

@@ -690,18 +720,43 @@ static int spinand_mtd_regular_page_read(struct mtd_info *mtd, loff_t from,
690720
if (ret)
691721
break;
692722

723+
read_retry:
693724
ret = spinand_read_page(spinand, &iter.req);
694725
if (ret < 0 && ret != -EBADMSG)
695726
break;
696727

697-
if (ret == -EBADMSG)
728+
if (ret == -EBADMSG && spinand->set_read_retry) {
729+
if (spinand->read_retries && (++retry_mode <= spinand->read_retries)) {
730+
ret = spinand->set_read_retry(spinand, retry_mode);
731+
if (ret < 0) {
732+
spinand->set_read_retry(spinand, 0);
733+
return ret;
734+
}
735+
736+
/* Reset ecc_stats; retry */
737+
mtd->ecc_stats = old_stats;
738+
goto read_retry;
739+
} else {
740+
/* No more retry modes; real failure */
741+
ecc_failed = true;
742+
}
743+
} else if (ret == -EBADMSG) {
698744
ecc_failed = true;
699-
else
745+
} else {
700746
*max_bitflips = max_t(unsigned int, *max_bitflips, ret);
747+
}
701748

702749
ret = 0;
703750
ops->retlen += iter.req.datalen;
704751
ops->oobretlen += iter.req.ooblen;
752+
753+
/* Reset to retry mode 0 */
754+
if (retry_mode) {
755+
retry_mode = 0;
756+
ret = spinand->set_read_retry(spinand, retry_mode);
757+
if (ret < 0)
758+
return ret;
759+
}
705760
}
706761

707762
if (ecc_failed && !ret)
@@ -1292,6 +1347,10 @@ int spinand_match_and_init(struct spinand_device *spinand,
12921347
spinand->id.len = 1 + table[i].devid.len;
12931348
spinand->select_target = table[i].select_target;
12941349
spinand->set_cont_read = table[i].set_cont_read;
1350+
spinand->fact_otp = &table[i].fact_otp;
1351+
spinand->user_otp = &table[i].user_otp;
1352+
spinand->read_retries = table[i].read_retries;
1353+
spinand->set_read_retry = table[i].set_read_retry;
12951354

12961355
op = spinand_select_op_variant(spinand,
12971356
info->op_variants.read_cache);
@@ -1478,6 +1537,12 @@ static int spinand_init(struct spinand_device *spinand)
14781537
mtd->_max_bad_blocks = nanddev_mtd_max_bad_blocks;
14791538
mtd->_resume = spinand_mtd_resume;
14801539

1540+
if (spinand_user_otp_size(spinand) || spinand_fact_otp_size(spinand)) {
1541+
ret = spinand_set_mtd_otp_ops(spinand);
1542+
if (ret)
1543+
goto err_cleanup_ecc_engine;
1544+
}
1545+
14811546
if (nand->ecc.engine) {
14821547
ret = mtd_ooblayout_count_freebytes(mtd);
14831548
if (ret < 0)

0 commit comments

Comments
 (0)