summaryrefslogtreecommitdiffstats
path: root/arch
diff options
context:
space:
mode:
authorWolfram Sang <w.sang@pengutronix.de>2012-06-14 15:21:03 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-06-30 22:37:41 +0200
commit51f4b6926a5c794cc51052f46df5208bd6a17f99 (patch)
tree3626d167e743d8de32eab79a139354f587a451cc /arch
parent27b1a89e272688c9aee951aca942535837287778 (diff)
downloadbarebox-51f4b6926a5c794cc51052f46df5208bd6a17f99.tar.gz
barebox-51f4b6926a5c794cc51052f46df5208bd6a17f99.tar.xz
arm: mxs: refactor timeout routine for ocotp
Let's keep the timeout routine in a central place. We will need it more often when we add write support. Signed-off-by: Wolfram Sang <w.sang@pengutronix.de> Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'arch')
-rw-r--r--arch/arm/mach-mxs/ocotp.c26
1 files changed, 16 insertions, 10 deletions
diff --git a/arch/arm/mach-mxs/ocotp.c b/arch/arm/mach-mxs/ocotp.c
index 38f9ffde16..7f9107a239 100644
--- a/arch/arm/mach-mxs/ocotp.c
+++ b/arch/arm/mach-mxs/ocotp.c
@@ -39,13 +39,24 @@ struct ocotp_priv {
void __iomem *base;
};
+static int mxs_ocotp_wait_busy(struct ocotp_priv *priv)
+{
+ uint64_t start = get_time_ns();
+
+ /* check both BUSY and ERROR cleared */
+ while (readl(priv->base) & (BM_OCOTP_CTRL_BUSY | BM_OCOTP_CTRL_ERROR))
+ if (is_timeout(start, MSECOND))
+ return -ETIMEDOUT;
+
+ return 0;
+}
+
static ssize_t mxs_ocotp_cdev_read(struct cdev *cdev, void *buf, size_t count,
ulong offset, ulong flags)
{
struct ocotp_priv *priv = cdev->priv;
void __iomem *base = priv->base;
size_t size = min((ulong)count, cdev->size - offset);
- uint64_t start;
int i;
/*
@@ -56,11 +67,8 @@ static ssize_t mxs_ocotp_cdev_read(struct cdev *cdev, void *buf, size_t count,
/* try to clear ERROR bit */
writel(BM_OCOTP_CTRL_ERROR, base + BIT_CLR);
- /* check both BUSY and ERROR cleared */
- start = get_time_ns();
- while (readl(base) & (BM_OCOTP_CTRL_BUSY | BM_OCOTP_CTRL_ERROR))
- if (is_timeout(start, MSECOND))
- return -ETIMEDOUT;
+ if (mxs_ocotp_wait_busy(priv))
+ return -ETIMEDOUT;
/* open OCOTP banks for read */
writel(BM_OCOTP_CTRL_RD_BANK_OPEN, base + BIT_SET);
@@ -69,10 +77,8 @@ static ssize_t mxs_ocotp_cdev_read(struct cdev *cdev, void *buf, size_t count,
udelay(1);
/* poll BUSY bit becoming cleared */
- start = get_time_ns();
- while (readl(base) & BM_OCOTP_CTRL_BUSY)
- if (is_timeout(start, MSECOND))
- return -ETIMEDOUT;
+ if (mxs_ocotp_wait_busy(priv))
+ return -ETIMEDOUT;
for (i = 0; i < size; i++)
/* When reading bytewise, we need to hop over the SET/CLR/TGL regs */