block: move down direct IO plugging
[linux/fpc-iii.git] / arch / arm / mach-mxs / ocotp.c
blob54add60f94c98c5d8d15c119e996395a13b6fc86
1 /*
2 * Copyright 2010 Freescale Semiconductor, Inc. All Rights Reserved.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 2 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
15 #include <linux/delay.h>
16 #include <linux/err.h>
17 #include <linux/mutex.h>
19 #include <asm/processor.h> /* for cpu_relax() */
21 #include <mach/mxs.h>
23 #define OCOTP_WORD_OFFSET 0x20
24 #define OCOTP_WORD_COUNT 0x20
26 #define BM_OCOTP_CTRL_BUSY (1 << 8)
27 #define BM_OCOTP_CTRL_ERROR (1 << 9)
28 #define BM_OCOTP_CTRL_RD_BANK_OPEN (1 << 12)
30 static DEFINE_MUTEX(ocotp_mutex);
31 static u32 ocotp_words[OCOTP_WORD_COUNT];
33 const u32 *mxs_get_ocotp(void)
35 void __iomem *ocotp_base = MXS_IO_ADDRESS(MXS_OCOTP_BASE_ADDR);
36 int timeout = 0x400;
37 size_t i;
38 static int once = 0;
40 if (once)
41 return ocotp_words;
43 mutex_lock(&ocotp_mutex);
46 * clk_enable(hbus_clk) for ocotp can be skipped
47 * as it must be on when system is running.
50 /* try to clear ERROR bit */
51 __mxs_clrl(BM_OCOTP_CTRL_ERROR, ocotp_base);
53 /* check both BUSY and ERROR cleared */
54 while ((__raw_readl(ocotp_base) &
55 (BM_OCOTP_CTRL_BUSY | BM_OCOTP_CTRL_ERROR)) && --timeout)
56 cpu_relax();
58 if (unlikely(!timeout))
59 goto error_unlock;
61 /* open OCOTP banks for read */
62 __mxs_setl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);
64 /* approximately wait 32 hclk cycles */
65 udelay(1);
67 /* poll BUSY bit becoming cleared */
68 timeout = 0x400;
69 while ((__raw_readl(ocotp_base) & BM_OCOTP_CTRL_BUSY) && --timeout)
70 cpu_relax();
72 if (unlikely(!timeout))
73 goto error_unlock;
75 for (i = 0; i < OCOTP_WORD_COUNT; i++)
76 ocotp_words[i] = __raw_readl(ocotp_base + OCOTP_WORD_OFFSET +
77 i * 0x10);
79 /* close banks for power saving */
80 __mxs_clrl(BM_OCOTP_CTRL_RD_BANK_OPEN, ocotp_base);
82 once = 1;
84 mutex_unlock(&ocotp_mutex);
86 return ocotp_words;
88 error_unlock:
89 mutex_unlock(&ocotp_mutex);
90 pr_err("%s: timeout in reading OCOTP\n", __func__);
91 return NULL;