aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMiquel Raynal <miquel.raynal@bootlin.com>2018-02-28 20:51:47 +0100
committerMaxime Ripard <maxime.ripard@bootlin.com>2018-04-03 12:11:04 +0200
commit28f7a9d375c8bc7a30563b8d995b9baa355c7e41 (patch)
treeec067ee6f0c326340ad1070a53067c18d54253f2
parent802f766994ded5afc9d89e93556011063a430e0d (diff)
downloadu-boot-28f7a9d375c8bc7a30563b8d995b9baa355c7e41.zip
u-boot-28f7a9d375c8bc7a30563b8d995b9baa355c7e41.tar.gz
u-boot-28f7a9d375c8bc7a30563b8d995b9baa355c7e41.tar.bz2
spl: nand: sunxi: introduce the nand_wait_int() helper
The pattern of polling on a status register until a bit is set or a timeout occurs is repeated multiple times in the driver. Mutualize the code by introducing the nand_wait_int() helper that does wait for the bit to flip or returns an error in case of timeout. Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com> Acked-by: Boris Brezillon <boris.brezillon@bootlin.com> Signed-off-by: Maxime Ripard <maxime.ripard@bootlin.com>
-rw-r--r--drivers/mtd/nand/sunxi_nand_spl.c34
1 files changed, 14 insertions, 20 deletions
diff --git a/drivers/mtd/nand/sunxi_nand_spl.c b/drivers/mtd/nand/sunxi_nand_spl.c
index 608cc99..c2f4f2c 100644
--- a/drivers/mtd/nand/sunxi_nand_spl.c
+++ b/drivers/mtd/nand/sunxi_nand_spl.c
@@ -155,6 +155,17 @@ static inline int check_value_negated(int offset, int unexpected_bits,
return check_value_inner(offset, unexpected_bits, timeout_us, 1);
}
+static int nand_wait_int(void)
+{
+ if (!check_value(SUNXI_NFC_BASE + NFC_ST, NFC_ST_CMD_INT_FLAG,
+ DEFAULT_TIMEOUT_US)) {
+ printf("nand: timeout waiting for interruption\n");
+ return -ETIMEDOUT;
+ }
+
+ return 0;
+}
+
void nand_init(void)
{
uint32_t val;
@@ -176,12 +187,7 @@ void nand_init(void)
writel(NFC_SEND_CMD1 | NFC_WAIT_FLAG | NAND_CMD_RESET,
SUNXI_NFC_BASE + NFC_CMD);
- if (!check_value(SUNXI_NFC_BASE + NFC_ST, NFC_ST_CMD_INT_FLAG,
- DEFAULT_TIMEOUT_US)) {
- printf("Error timeout waiting for nand reset\n");
- return;
- }
- writel(NFC_ST_CMD_INT_FLAG, SUNXI_NFC_BASE + NFC_ST);
+ nand_wait_int();
}
static void nand_apply_config(const struct nfc_config *conf)
@@ -211,13 +217,7 @@ static int nand_load_page(const struct nfc_config *conf, u32 offs)
((conf->addr_cycles - 1) << NFC_ADDR_NUM_OFFSET) | NFC_SEND_ADDR,
SUNXI_NFC_BASE + NFC_CMD);
- if (!check_value(SUNXI_NFC_BASE + NFC_ST, NFC_ST_CMD_INT_FLAG,
- DEFAULT_TIMEOUT_US)) {
- printf("Error while initializing dma interrupt\n");
- return -EIO;
- }
-
- return 0;
+ return nand_wait_int();
}
static int nand_reset_column(void)
@@ -231,13 +231,7 @@ static int nand_reset_column(void)
(1 << NFC_ADDR_NUM_OFFSET) | NFC_SEND_ADDR | NFC_CMD_RNDOUT,
SUNXI_NFC_BASE + NFC_CMD);
- if (!check_value(SUNXI_NFC_BASE + NFC_ST, NFC_ST_CMD_INT_FLAG,
- DEFAULT_TIMEOUT_US)) {
- printf("Error while initializing dma interrupt\n");
- return -1;
- }
-
- return 0;
+ return nand_wait_int();
}
static int nand_read_page(const struct nfc_config *conf, u32 offs,