Commit 3c7c1e45 authored by Kamal Dasu's avatar Kamal Dasu Committed by Miquel Raynal

mtd: rawnand: brcmnand: Refactored code to introduce helper functions

Refactored NAND ECC and CMD address configuration code to use helper
functions.
Signed-off-by: default avatarKamal Dasu <kdasu.kdev@gmail.com>
Signed-off-by: default avatarMiquel Raynal <miquel.raynal@bootlin.com>
parent c1ac2dc3
...@@ -581,6 +581,54 @@ static inline void brcmnand_write_fc(struct brcmnand_controller *ctrl, ...@@ -581,6 +581,54 @@ static inline void brcmnand_write_fc(struct brcmnand_controller *ctrl,
__raw_writel(val, ctrl->nand_fc + word * 4); __raw_writel(val, ctrl->nand_fc + word * 4);
} }
static void brcmnand_clear_ecc_addr(struct brcmnand_controller *ctrl)
{
/* Clear error addresses */
brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_ADDR, 0);
brcmnand_write_reg(ctrl, BRCMNAND_CORR_ADDR, 0);
brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_EXT_ADDR, 0);
brcmnand_write_reg(ctrl, BRCMNAND_CORR_EXT_ADDR, 0);
}
static u64 brcmnand_get_uncorrecc_addr(struct brcmnand_controller *ctrl)
{
u64 err_addr;
err_addr = brcmnand_read_reg(ctrl, BRCMNAND_UNCORR_ADDR);
err_addr |= ((u64)(brcmnand_read_reg(ctrl,
BRCMNAND_UNCORR_EXT_ADDR)
& 0xffff) << 32);
return err_addr;
}
static u64 brcmnand_get_correcc_addr(struct brcmnand_controller *ctrl)
{
u64 err_addr;
err_addr = brcmnand_read_reg(ctrl, BRCMNAND_CORR_ADDR);
err_addr |= ((u64)(brcmnand_read_reg(ctrl,
BRCMNAND_CORR_EXT_ADDR)
& 0xffff) << 32);
return err_addr;
}
static void brcmnand_set_cmd_addr(struct mtd_info *mtd, u64 addr)
{
struct nand_chip *chip = mtd_to_nand(mtd);
struct brcmnand_host *host = nand_get_controller_data(chip);
struct brcmnand_controller *ctrl = host->ctrl;
brcmnand_write_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS,
(host->cs << 16) | ((addr >> 32) & 0xffff));
(void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS);
brcmnand_write_reg(ctrl, BRCMNAND_CMD_ADDRESS,
lower_32_bits(addr));
(void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
}
static inline u16 brcmnand_cs_offset(struct brcmnand_controller *ctrl, int cs, static inline u16 brcmnand_cs_offset(struct brcmnand_controller *ctrl, int cs,
enum brcmnand_cs_reg reg) enum brcmnand_cs_reg reg)
{ {
...@@ -1220,9 +1268,12 @@ static void brcmnand_send_cmd(struct brcmnand_host *host, int cmd) ...@@ -1220,9 +1268,12 @@ static void brcmnand_send_cmd(struct brcmnand_host *host, int cmd)
{ {
struct brcmnand_controller *ctrl = host->ctrl; struct brcmnand_controller *ctrl = host->ctrl;
int ret; int ret;
u64 cmd_addr;
cmd_addr = brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
dev_dbg(ctrl->dev, "send native cmd %d addr 0x%llx\n", cmd, cmd_addr);
dev_dbg(ctrl->dev, "send native cmd %d addr_lo 0x%x\n", cmd,
brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS));
BUG_ON(ctrl->cmd_pending != 0); BUG_ON(ctrl->cmd_pending != 0);
ctrl->cmd_pending = cmd; ctrl->cmd_pending = cmd;
...@@ -1408,12 +1459,7 @@ static void brcmnand_cmdfunc(struct nand_chip *chip, unsigned command, ...@@ -1408,12 +1459,7 @@ static void brcmnand_cmdfunc(struct nand_chip *chip, unsigned command,
if (!native_cmd) if (!native_cmd)
return; return;
brcmnand_write_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS, brcmnand_set_cmd_addr(mtd, addr);
(host->cs << 16) | ((addr >> 32) & 0xffff));
(void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS);
brcmnand_write_reg(ctrl, BRCMNAND_CMD_ADDRESS, lower_32_bits(addr));
(void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
brcmnand_send_cmd(host, native_cmd); brcmnand_send_cmd(host, native_cmd);
brcmnand_waitfunc(chip); brcmnand_waitfunc(chip);
...@@ -1631,20 +1677,10 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1631,20 +1677,10 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip,
struct brcmnand_controller *ctrl = host->ctrl; struct brcmnand_controller *ctrl = host->ctrl;
int i, j, ret = 0; int i, j, ret = 0;
/* Clear error addresses */ brcmnand_clear_ecc_addr(ctrl);
brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_ADDR, 0);
brcmnand_write_reg(ctrl, BRCMNAND_CORR_ADDR, 0);
brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_EXT_ADDR, 0);
brcmnand_write_reg(ctrl, BRCMNAND_CORR_EXT_ADDR, 0);
brcmnand_write_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS,
(host->cs << 16) | ((addr >> 32) & 0xffff));
(void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS);
for (i = 0; i < trans; i++, addr += FC_BYTES) { for (i = 0; i < trans; i++, addr += FC_BYTES) {
brcmnand_write_reg(ctrl, BRCMNAND_CMD_ADDRESS, brcmnand_set_cmd_addr(mtd, addr);
lower_32_bits(addr));
(void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
/* SPARE_AREA_READ does not use ECC, so just use PAGE_READ */ /* SPARE_AREA_READ does not use ECC, so just use PAGE_READ */
brcmnand_send_cmd(host, CMD_PAGE_READ); brcmnand_send_cmd(host, CMD_PAGE_READ);
brcmnand_waitfunc(chip); brcmnand_waitfunc(chip);
...@@ -1664,21 +1700,15 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1664,21 +1700,15 @@ static int brcmnand_read_by_pio(struct mtd_info *mtd, struct nand_chip *chip,
host->hwcfg.sector_size_1k); host->hwcfg.sector_size_1k);
if (!ret) { if (!ret) {
*err_addr = brcmnand_read_reg(ctrl, *err_addr = brcmnand_get_uncorrecc_addr(ctrl);
BRCMNAND_UNCORR_ADDR) |
((u64)(brcmnand_read_reg(ctrl,
BRCMNAND_UNCORR_EXT_ADDR)
& 0xffff) << 32);
if (*err_addr) if (*err_addr)
ret = -EBADMSG; ret = -EBADMSG;
} }
if (!ret) { if (!ret) {
*err_addr = brcmnand_read_reg(ctrl, *err_addr = brcmnand_get_correcc_addr(ctrl);
BRCMNAND_CORR_ADDR) |
((u64)(brcmnand_read_reg(ctrl,
BRCMNAND_CORR_EXT_ADDR)
& 0xffff) << 32);
if (*err_addr) if (*err_addr)
ret = -EUCLEAN; ret = -EUCLEAN;
} }
...@@ -1745,7 +1775,7 @@ static int brcmnand_read(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1745,7 +1775,7 @@ static int brcmnand_read(struct mtd_info *mtd, struct nand_chip *chip,
dev_dbg(ctrl->dev, "read %llx -> %p\n", (unsigned long long)addr, buf); dev_dbg(ctrl->dev, "read %llx -> %p\n", (unsigned long long)addr, buf);
try_dmaread: try_dmaread:
brcmnand_write_reg(ctrl, BRCMNAND_UNCORR_COUNT, 0); brcmnand_clear_ecc_addr(ctrl);
if (has_flash_dma(ctrl) && !oob && flash_dma_buf_ok(buf)) { if (has_flash_dma(ctrl) && !oob && flash_dma_buf_ok(buf)) {
err = brcmnand_dma_trans(host, addr, buf, trans * FC_BYTES, err = brcmnand_dma_trans(host, addr, buf, trans * FC_BYTES,
...@@ -1892,15 +1922,9 @@ static int brcmnand_write(struct mtd_info *mtd, struct nand_chip *chip, ...@@ -1892,15 +1922,9 @@ static int brcmnand_write(struct mtd_info *mtd, struct nand_chip *chip,
goto out; goto out;
} }
brcmnand_write_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS,
(host->cs << 16) | ((addr >> 32) & 0xffff));
(void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_EXT_ADDRESS);
for (i = 0; i < trans; i++, addr += FC_BYTES) { for (i = 0; i < trans; i++, addr += FC_BYTES) {
/* full address MUST be set before populating FC */ /* full address MUST be set before populating FC */
brcmnand_write_reg(ctrl, BRCMNAND_CMD_ADDRESS, brcmnand_set_cmd_addr(mtd, addr);
lower_32_bits(addr));
(void)brcmnand_read_reg(ctrl, BRCMNAND_CMD_ADDRESS);
if (buf) { if (buf) {
brcmnand_soc_data_bus_prepare(ctrl->soc, false); brcmnand_soc_data_bus_prepare(ctrl->soc, false);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment