diff options
author | Rouven Czerwinski <r.czerwinski@pengutronix.de> | 2020-07-15 07:56:06 +0200 |
---|---|---|
committer | Sascha Hauer <s.hauer@pengutronix.de> | 2020-08-10 21:52:34 +0200 |
commit | 27f06072e2d4a190540fe8b1f5b450462430f5e0 (patch) | |
tree | 233e307e3d0dc3ae249b7873702dee4fc07711c5 | |
parent | 18a6de26661ce945d9a27d856bdffa638247b69b (diff) | |
download | barebox-27f06072e2d4a190540fe8b1f5b450462430f5e0.tar.gz barebox-27f06072e2d4a190540fe8b1f5b450462430f5e0.tar.xz |
nvmem: ocotp: add new timing function for i.MX7
Ported from the linux kernel.
Signed-off-by: Rouven Czerwinski <r.czerwinski@pengutronix.de>
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
-rw-r--r-- | drivers/nvmem/ocotp.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/drivers/nvmem/ocotp.c b/drivers/nvmem/ocotp.c index 71f1ced2b1..54e916bea0 100644 --- a/drivers/nvmem/ocotp.c +++ b/drivers/nvmem/ocotp.c @@ -48,6 +48,9 @@ #define OCOTP_READ_CTRL 0x30 #define OCOTP_READ_FUSE_DATA 0x40 +#define DEF_FSOURCE 1001 /* > 1000 ns */ +#define DEF_STROBE_PROG 10000 /* IPG clocks */ + /* OCOTP Registers bits and masks */ #define OCOTP_CTRL_WR_UNLOCK 16 #define OCOTP_CTRL_WR_UNLOCK_KEY 0x3E77 @@ -171,6 +174,27 @@ static int imx6_ocotp_set_timing(struct ocotp_priv *priv) return 0; } +static int imx7_ocotp_set_timing(struct ocotp_priv *priv) +{ + unsigned long clk_rate; + u64 fsource, strobe_prog; + u32 timing; + + clk_rate = clk_get_rate(priv->clk); + + fsource = DIV_ROUND_UP_ULL((u64)clk_rate * DEF_FSOURCE, + NSEC_PER_SEC) + 1; + strobe_prog = DIV_ROUND_CLOSEST_ULL((u64)clk_rate * DEF_STROBE_PROG, + NSEC_PER_SEC) + 1; + + timing = strobe_prog & 0x00000FFF; + timing |= (fsource << 12) & 0x000FF000; + + writel(timing, priv->base + OCOTP_TIMING); + + return 0; +} + static int imx6_ocotp_wait_busy(struct ocotp_priv *priv, u32 flags) { uint64_t start = get_time_ns(); |