Skip to content

Commit d21b433

Browse files
richard-bootlinmiquelraynal
authored andcommitted
mtd: rawnand: sunxi: introduce ecc_mode_mask in sunxi_nfc_caps
The H6/H616 ECC_MODE field is not at the same offset, and has not the same size. So move the mask into sunxi_nfc_caps. Also, introduce a non compile-time field_prep() because FIELD_PREP() doesn't work with non compile-time constant. No functional change. Link: https://lore.kernel.org/all/cover.1761588465.git.geert+renesas@glider.be Signed-off-by: Richard Genoud <richard.genoud@bootlin.com> Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
1 parent 8c1b28a commit d21b433

1 file changed

Lines changed: 9 additions & 4 deletions

File tree

drivers/mtd/nand/raw/sunxi_nand.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,8 +29,9 @@
2929
#include <linux/iopoll.h>
3030
#include <linux/reset.h>
3131

32-
/* non compile-time field get */
32+
/* non compile-time field get/prep */
3333
#define field_get(_mask, _reg) (((_reg) & (_mask)) >> (ffs(_mask) - 1))
34+
#define field_prep(_mask, _val) (((_val) << (ffs(_mask) - 1)) & (_mask))
3435

3536
#define NFC_REG_CTL 0x0000
3637
#define NFC_REG_ST 0x0004
@@ -145,8 +146,8 @@
145146
#define NFC_ECC_BLOCK_512 BIT(5)
146147
#define NFC_RANDOM_EN BIT(9)
147148
#define NFC_RANDOM_DIRECTION BIT(10)
148-
#define NFC_ECC_MODE_MSK GENMASK(15, 12)
149-
#define NFC_ECC_MODE(x) ((x) << 12)
149+
#define NFC_ECC_MODE_MSK(nfc) (nfc->caps->ecc_mode_mask)
150+
#define NFC_ECC_MODE(nfc, x) field_prep(NFC_ECC_MODE_MSK(nfc), (x))
150151
#define NFC_RANDOM_SEED_MSK GENMASK(30, 16)
151152
#define NFC_RANDOM_SEED(x) ((x) << 16)
152153

@@ -238,6 +239,7 @@ static inline struct sunxi_nand_chip *to_sunxi_nand(struct nand_chip *nand)
238239
* @reg_ecc_err_cnt: ECC error counter register
239240
* @reg_user_data: User data register
240241
* @reg_pat_found: Data Pattern Status Register
242+
* @ecc_mode_mask: ECC_MODE mask in NFC_ECC_CTL register
241243
* @pat_found_mask: ECC_PAT_FOUND mask in NFC_REG_PAT_FOUND register
242244
* @dma_maxburst: DMA maxburst
243245
* @ecc_strengths: Available ECC strengths array
@@ -250,6 +252,7 @@ struct sunxi_nfc_caps {
250252
unsigned int reg_ecc_err_cnt;
251253
unsigned int reg_user_data;
252254
unsigned int reg_pat_found;
255+
unsigned int ecc_mode_mask;
253256
unsigned int pat_found_mask;
254257
unsigned int dma_maxburst;
255258
const u8 *ecc_strengths;
@@ -1757,7 +1760,7 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand,
17571760
ecc->read_oob_raw = nand_read_oob_std;
17581761
ecc->write_oob_raw = nand_write_oob_std;
17591762

1760-
sunxi_nand->ecc.ecc_ctl = NFC_ECC_MODE(i) | NFC_ECC_EXCEPTION |
1763+
sunxi_nand->ecc.ecc_ctl = NFC_ECC_MODE(nfc, i) | NFC_ECC_EXCEPTION |
17611764
NFC_ECC_PIPELINE | NFC_ECC_EN;
17621765

17631766
if (ecc->size == 512) {
@@ -2227,6 +2230,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a10_caps = {
22272230
.reg_ecc_err_cnt = NFC_REG_A10_ECC_ERR_CNT,
22282231
.reg_user_data = NFC_REG_A10_USER_DATA,
22292232
.reg_pat_found = NFC_REG_ECC_ST,
2233+
.ecc_mode_mask = GENMASK(15, 12),
22302234
.pat_found_mask = GENMASK(31, 16),
22312235
.dma_maxburst = 4,
22322236
.ecc_strengths = sunxi_ecc_strengths_a10,
@@ -2240,6 +2244,7 @@ static const struct sunxi_nfc_caps sunxi_nfc_a23_caps = {
22402244
.reg_ecc_err_cnt = NFC_REG_A10_ECC_ERR_CNT,
22412245
.reg_user_data = NFC_REG_A10_USER_DATA,
22422246
.reg_pat_found = NFC_REG_ECC_ST,
2247+
.ecc_mode_mask = GENMASK(15, 12),
22432248
.pat_found_mask = GENMASK(31, 16),
22442249
.dma_maxburst = 8,
22452250
.ecc_strengths = sunxi_ecc_strengths_a10,

0 commit comments

Comments
 (0)