Skip to content

Commit ef3e632

Browse files
smaeulmiquelraynal
authored andcommitted
mtd: rawnand: sunxi: Precompute the ECC_CTL register value
The value computed by this function never changes for a given chip. Compute the whole register value once up front, instead of every time the ECC engine is enabled. Signed-off-by: Samuel Holland <[email protected]> Signed-off-by: Miquel Raynal <[email protected]> Link: https://lore.kernel.org/linux-mtd/[email protected]
1 parent ac1c707 commit ef3e632

File tree

1 file changed

+10
-17
lines changed

1 file changed

+10
-17
lines changed

drivers/mtd/nand/raw/sunxi_nand.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,10 @@ struct sunxi_nand_chip_sel {
172172
/**
173173
* struct sunxi_nand_hw_ecc - stores information related to HW ECC support
174174
*
175-
* @mode: the sunxi ECC mode field deduced from ECC requirements
175+
* @ecc_ctl: ECC_CTL register value for this NAND chip
176176
*/
177177
struct sunxi_nand_hw_ecc {
178-
int mode;
178+
u32 ecc_ctl;
179179
};
180180

181181
/**
@@ -689,26 +689,15 @@ static void sunxi_nfc_hw_ecc_enable(struct nand_chip *nand)
689689
{
690690
struct sunxi_nand_chip *sunxi_nand = to_sunxi_nand(nand);
691691
struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
692-
u32 ecc_ctl;
693-
694-
ecc_ctl = readl(nfc->regs + NFC_REG_ECC_CTL);
695-
ecc_ctl &= ~(NFC_ECC_MODE_MSK | NFC_ECC_PIPELINE |
696-
NFC_ECC_BLOCK_SIZE_MSK);
697-
ecc_ctl |= NFC_ECC_EN | NFC_ECC_MODE(sunxi_nand->ecc.mode) |
698-
NFC_ECC_EXCEPTION | NFC_ECC_PIPELINE;
699-
700-
if (nand->ecc.size == 512)
701-
ecc_ctl |= NFC_ECC_BLOCK_512;
702692

703-
writel(ecc_ctl, nfc->regs + NFC_REG_ECC_CTL);
693+
writel(sunxi_nand->ecc.ecc_ctl, nfc->regs + NFC_REG_ECC_CTL);
704694
}
705695

706696
static void sunxi_nfc_hw_ecc_disable(struct nand_chip *nand)
707697
{
708698
struct sunxi_nfc *nfc = to_sunxi_nfc(nand->controller);
709699

710-
writel(readl(nfc->regs + NFC_REG_ECC_CTL) & ~NFC_ECC_EN,
711-
nfc->regs + NFC_REG_ECC_CTL);
700+
writel(0, nfc->regs + NFC_REG_ECC_CTL);
712701
}
713702

714703
static inline void sunxi_nfc_user_data_to_buf(u32 user_data, u8 *buf)
@@ -1693,8 +1682,6 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand,
16931682
return -ENOTSUPP;
16941683
}
16951684

1696-
sunxi_nand->ecc.mode = i;
1697-
16981685
/* HW ECC always request ECC bytes for 1024 bytes blocks */
16991686
ecc->bytes = DIV_ROUND_UP(ecc->strength * fls(8 * 1024), 8);
17001687

@@ -1726,6 +1713,12 @@ static int sunxi_nand_hw_ecc_ctrl_init(struct nand_chip *nand,
17261713
ecc->read_oob_raw = nand_read_oob_std;
17271714
ecc->write_oob_raw = nand_write_oob_std;
17281715

1716+
sunxi_nand->ecc.ecc_ctl = NFC_ECC_MODE(i) | NFC_ECC_EXCEPTION |
1717+
NFC_ECC_PIPELINE | NFC_ECC_EN;
1718+
1719+
if (ecc->size == 512)
1720+
sunxi_nand->ecc.ecc_ctl |= NFC_ECC_BLOCK_512;
1721+
17291722
return 0;
17301723
}
17311724

0 commit comments

Comments
 (0)