2 * Copyright (C) 2013 ROCKCHIP, Inc.
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
9 #include <linux/delay.h>
10 #include <linux/spinlock.h>
11 #include <linux/rockchip/iomap.h>
12 #include <linux/kobject.h>
15 #define efuse_readl(offset) readl_relaxed(RK_EFUSE_VIRT + offset)
16 #define efuse_writel(val, offset) writel_relaxed(val, RK_EFUSE_VIRT + offset)
18 static u8 efuse_buf[32 + 1] = {0, 0};
20 static int efuse_readregs(u32 addr, u32 length, u8 *buf)
26 static DEFINE_SPINLOCK(efuse_lock);
32 spin_lock_irqsave(&efuse_lock, flags);
34 efuse_writel(EFUSE_CSB, REG_EFUSE_CTRL);
35 efuse_writel(EFUSE_LOAD | EFUSE_PGENB, REG_EFUSE_CTRL);
38 efuse_writel(efuse_readl(REG_EFUSE_CTRL) &
39 (~(EFUSE_A_MASK << EFUSE_A_SHIFT)), REG_EFUSE_CTRL);
40 efuse_writel(efuse_readl(REG_EFUSE_CTRL) |
41 ((addr & EFUSE_A_MASK) << EFUSE_A_SHIFT),
44 efuse_writel(efuse_readl(REG_EFUSE_CTRL) |
45 EFUSE_STROBE, REG_EFUSE_CTRL);
47 *buf = efuse_readl(REG_EFUSE_DOUT);
48 efuse_writel(efuse_readl(REG_EFUSE_CTRL) &
49 (~EFUSE_STROBE), REG_EFUSE_CTRL);
55 efuse_writel(efuse_readl(REG_EFUSE_CTRL) | EFUSE_CSB, REG_EFUSE_CTRL);
58 spin_unlock_irqrestore(&efuse_lock, flags);
64 static int efuse_writeregs(u32 addr, u32 length, u8 *buf)
68 static DEFINE_SPINLOCK(efuse_lock);
69 spin_lock_irqsave(&efuse_lock, flags);
71 efuse_writel(EFUSE_CSB|EFUSE_LOAD|EFUSE_PGENB,REG_EFUSE_CTRL);
73 efuse_writel((~EFUSE_PGENB)&(efuse_readl(REG_EFUSE_CTRL)),
76 efuse_writel((~(EFUSE_LOAD | EFUSE_CSB))&(efuse_readl(REG_EFUSE_CTRL)),
83 efuse_writel(efuse_readl(REG_EFUSE_CTRL) &
84 (~(EFUSE_A_MASK << EFUSE_A_SHIFT)),
86 efuse_writel(efuse_readl(REG_EFUSE_CTRL) |
87 (((addr + (j<<5))&EFUSE_A_MASK) << EFUSE_A_SHIFT),
90 efuse_writel(efuse_readl(REG_EFUSE_CTRL) |
91 EFUSE_STROBE, REG_EFUSE_CTRL);
93 efuse_writel(efuse_readl(REG_EFUSE_CTRL) &
94 (~EFUSE_STROBE), REG_EFUSE_CTRL);
103 efuse_writel(efuse_readl(REG_EFUSE_CTRL) |
104 EFUSE_CSB | EFUSE_LOAD, REG_EFUSE_CTRL);
106 efuse_writel(efuse_readl(REG_EFUSE_CTRL)|EFUSE_PGENB, REG_EFUSE_CTRL);
109 spin_unlock_irqrestore(&efuse_lock, flags);
114 int rockchip_efuse_version(void)
116 int ret = efuse_buf[4] & (~(0x1 << 3));
120 int rockchip_get_leakage(int ch)
122 if ((ch < 0) || (ch > 2))
125 return efuse_buf[23+ch];
128 static int efuse_init(void)
130 efuse_readregs(0, 32, efuse_buf);
135 core_initcall(efuse_init);