Skip to content

Commit

Permalink
mtd: atmel_nand: add NFC status error check
Browse files Browse the repository at this point in the history
Add a new function to read the NFC status. Meantime, this function will
check if there is any errors in NFC.

Signed-off-by: Josh Wu <josh.wu@atmel.com>
Tested-by: Matthieu Crapet <Matthieu.Crapet@ingenico.com>
Signed-off-by: Brian Norris <computersforpeace@gmail.com>
  • Loading branch information
Wu, Josh authored and Brian Norris committed Jul 22, 2014
1 parent b385766 commit 50e04e2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
24 changes: 23 additions & 1 deletion drivers/mtd/nand/atmel_nand.c
Original file line number Diff line number Diff line change
Expand Up @@ -1572,14 +1572,33 @@ static int atmel_hw_nand_init_params(struct platform_device *pdev,
return 0;
}

static inline u32 nfc_read_status(struct atmel_nand_host *host)
{
u32 err_flags = NFC_SR_DTOE | NFC_SR_UNDEF | NFC_SR_AWB | NFC_SR_ASE;
u32 nfc_status = nfc_readl(host->nfc->hsmc_regs, SR);

if (unlikely(nfc_status & err_flags)) {
if (nfc_status & NFC_SR_DTOE)
dev_err(host->dev, "NFC: Waiting Nand R/B Timeout Error\n");
else if (nfc_status & NFC_SR_UNDEF)
dev_err(host->dev, "NFC: Access Undefined Area Error\n");
else if (nfc_status & NFC_SR_AWB)
dev_err(host->dev, "NFC: Access memory While NFC is busy\n");
else if (nfc_status & NFC_SR_ASE)
dev_err(host->dev, "NFC: Access memory Size Error\n");
}

return nfc_status;
}

/* SMC interrupt service routine */
static irqreturn_t hsmc_interrupt(int irq, void *dev_id)
{
struct atmel_nand_host *host = dev_id;
u32 status, mask, pending;
irqreturn_t ret = IRQ_HANDLED;

status = nfc_readl(host->nfc->hsmc_regs, SR);
status = nfc_read_status(host);
mask = nfc_readl(host->nfc->hsmc_regs, IMR);
pending = status & mask;

Expand Down Expand Up @@ -2209,6 +2228,9 @@ static int atmel_nand_nfc_probe(struct platform_device *pdev)
}
}

nfc_writel(nfc->hsmc_regs, IDR, 0xffffffff);
nfc_readl(nfc->hsmc_regs, SR); /* clear the NFC_SR */

nfc->is_initialized = true;
dev_info(&pdev->dev, "NFC is probed.\n");
return 0;
Expand Down
4 changes: 4 additions & 0 deletions drivers/mtd/nand/atmel_nand_nfc.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#define ATMEL_HSMC_NFC_SR 0x08 /* NFC Status Register */
#define NFC_SR_XFR_DONE (1 << 16)
#define NFC_SR_CMD_DONE (1 << 17)
#define NFC_SR_DTOE (1 << 20)
#define NFC_SR_UNDEF (1 << 21)
#define NFC_SR_AWB (1 << 22)
#define NFC_SR_ASE (1 << 23)
#define NFC_SR_RB_EDGE (1 << 24)

#define ATMEL_HSMC_NFC_IER 0x0c
Expand Down

0 comments on commit 50e04e2

Please sign in to comment.