Skip to content

Commit 51106b8

Browse files
committed
spi: spi-qpic-snand: enable 8 bits ECC strength
Merge series from Gabor Juhos <[email protected]>: This small patch set adds support for 8 bits ECC strength, which widens the range of the usable SPI NAND chips with the driver. The first one is a preparatory patch which adds some defines which allows to avoid using magic values, and the second patch implements the actual support. The series should be integrated via the SPI tree, as that contains prerequisite changes.
2 parents 7105fdd + 913bf8d commit 51106b8

File tree

3 files changed

+21
-8
lines changed

3 files changed

+21
-8
lines changed

drivers/mtd/nand/raw/qcom_nandc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1379,7 +1379,7 @@ static int qcom_nand_attach_chip(struct nand_chip *chip)
13791379
struct qcom_nand_controller *nandc = get_qcom_nand_controller(chip);
13801380
int cwperpage, bad_block_byte, ret;
13811381
bool wide_bus;
1382-
int ecc_mode = 1;
1382+
int ecc_mode = ECC_MODE_8BIT;
13831383

13841384
/* controller only supports 512 bytes data steps */
13851385
ecc->size = NANDC_STEP_SIZE;
@@ -1400,7 +1400,7 @@ static int qcom_nand_attach_chip(struct nand_chip *chip)
14001400
if (ecc->strength >= 8) {
14011401
/* 8 bit ECC defaults to BCH ECC on all platforms */
14021402
host->bch_enabled = true;
1403-
ecc_mode = 1;
1403+
ecc_mode = ECC_MODE_8BIT;
14041404

14051405
if (wide_bus) {
14061406
host->ecc_bytes_hw = 14;
@@ -1420,7 +1420,7 @@ static int qcom_nand_attach_chip(struct nand_chip *chip)
14201420
if (nandc->props->ecc_modes & ECC_BCH_4BIT) {
14211421
/* BCH */
14221422
host->bch_enabled = true;
1423-
ecc_mode = 0;
1423+
ecc_mode = ECC_MODE_4BIT;
14241424

14251425
if (wide_bus) {
14261426
host->ecc_bytes_hw = 8;

drivers/spi/spi-qpic-snand.c

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,22 @@ static int qcom_spi_ecc_init_ctx_pipelined(struct nand_device *nand)
277277
goto err_free_ecc_cfg;
278278
}
279279

280-
if (ecc_cfg->strength != 4) {
280+
switch (ecc_cfg->strength) {
281+
case 4:
282+
ecc_cfg->ecc_mode = ECC_MODE_4BIT;
283+
ecc_cfg->ecc_bytes_hw = 7;
284+
ecc_cfg->spare_bytes = 4;
285+
break;
286+
287+
case 8:
288+
ecc_cfg->ecc_mode = ECC_MODE_8BIT;
289+
ecc_cfg->ecc_bytes_hw = 13;
290+
ecc_cfg->spare_bytes = 2;
291+
break;
292+
293+
default:
281294
dev_err(snandc->dev,
282-
"only 4 bits ECC strength is supported\n");
295+
"only 4 or 8 bits ECC strength is supported\n");
283296
ret = -EOPNOTSUPP;
284297
goto err_free_ecc_cfg;
285298
}
@@ -296,8 +309,6 @@ static int qcom_spi_ecc_init_ctx_pipelined(struct nand_device *nand)
296309
nand->ecc.ctx.priv = ecc_cfg;
297310
snandc->qspi->mtd = mtd;
298311

299-
ecc_cfg->ecc_bytes_hw = 7;
300-
ecc_cfg->spare_bytes = 4;
301312
ecc_cfg->bbm_size = 1;
302313
ecc_cfg->bch_enabled = true;
303314
ecc_cfg->bytes = ecc_cfg->ecc_bytes_hw + ecc_cfg->spare_bytes + ecc_cfg->bbm_size;
@@ -343,7 +354,7 @@ static int qcom_spi_ecc_init_ctx_pipelined(struct nand_device *nand)
343354
FIELD_PREP(ECC_SW_RESET, 0) |
344355
FIELD_PREP(ECC_NUM_DATA_BYTES_MASK, ecc_cfg->cw_data) |
345356
FIELD_PREP(ECC_FORCE_CLK_OPEN, 1) |
346-
FIELD_PREP(ECC_MODE_MASK, 0) |
357+
FIELD_PREP(ECC_MODE_MASK, ecc_cfg->ecc_mode) |
347358
FIELD_PREP(ECC_PARITY_SIZE_BYTES_BCH_MASK, ecc_cfg->ecc_bytes_hw);
348359

349360
ecc_cfg->ecc_buf_cfg = FIELD_PREP(NUM_STEPS_MASK, 0x203);

include/linux/mtd/nand-qpic-common.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,8 @@
101101
#define ECC_SW_RESET BIT(1)
102102
#define ECC_MODE 4
103103
#define ECC_MODE_MASK GENMASK(5, 4)
104+
#define ECC_MODE_4BIT 0
105+
#define ECC_MODE_8BIT 1
104106
#define ECC_PARITY_SIZE_BYTES_BCH 8
105107
#define ECC_PARITY_SIZE_BYTES_BCH_MASK GENMASK(12, 8)
106108
#define ECC_NUM_DATA_BYTES 16

0 commit comments

Comments
 (0)