|
23 | 23 | #include <linux/slab.h> |
24 | 24 | #include <linux/of.h> |
25 | 25 | #include <linux/platform_device.h> |
| 26 | +#include <asm/system_info.h> |
| 27 | +#include <linux/crc32.h> |
26 | 28 |
|
27 | 29 | #define EFUSE_A_SHIFT 6 |
28 | 30 | #define EFUSE_A_MASK 0x3ff |
@@ -94,6 +96,64 @@ static const struct of_device_id rockchip_efuse_match[] = { |
94 | 96 | }; |
95 | 97 | MODULE_DEVICE_TABLE(of, rockchip_efuse_match); |
96 | 98 |
|
| 99 | +static u8 efuse_buf[32] = {}; |
| 100 | +static int rockchip_efuse_serial_number(struct rockchip_efuse_chip *efuse, u8 *efuse_buf) |
| 101 | +{ |
| 102 | + u8 *buf = efuse_buf; |
| 103 | + int ret; |
| 104 | + size_t bytes = 32; |
| 105 | + unsigned int offset = 0; |
| 106 | + |
| 107 | + ret = clk_prepare_enable(efuse->clk); |
| 108 | + if (ret < 0) { |
| 109 | + dev_err(efuse->dev, "failed to prepare/enable efuse clk\n"); |
| 110 | + return ret; |
| 111 | + } |
| 112 | + |
| 113 | + dump_stack(); |
| 114 | + |
| 115 | + writel(EFUSE_LOAD | EFUSE_PGENB, efuse->base + REG_EFUSE_CTRL); |
| 116 | + udelay(1); |
| 117 | + while (bytes--) { |
| 118 | + writel(readl(efuse->base + REG_EFUSE_CTRL) & |
| 119 | + (~(EFUSE_A_MASK << EFUSE_A_SHIFT)), |
| 120 | + efuse->base + REG_EFUSE_CTRL); |
| 121 | + writel(readl(efuse->base + REG_EFUSE_CTRL) | |
| 122 | + ((offset++ & EFUSE_A_MASK) << EFUSE_A_SHIFT), |
| 123 | + efuse->base + REG_EFUSE_CTRL); |
| 124 | + udelay(1); |
| 125 | + writel(readl(efuse->base + REG_EFUSE_CTRL) | |
| 126 | + EFUSE_STROBE, efuse->base + REG_EFUSE_CTRL); |
| 127 | + udelay(1); |
| 128 | + *buf++ = readb(efuse->base + REG_EFUSE_DOUT); |
| 129 | + writel(readl(efuse->base + REG_EFUSE_CTRL) & |
| 130 | + (~EFUSE_STROBE), efuse->base + REG_EFUSE_CTRL); |
| 131 | + udelay(1); |
| 132 | + } |
| 133 | + |
| 134 | + |
| 135 | + writel(EFUSE_PGENB | EFUSE_CSB, efuse->base + REG_EFUSE_CTRL); |
| 136 | + |
| 137 | + clk_disable_unprepare(efuse->clk); |
| 138 | + |
| 139 | + return 0; |
| 140 | +} |
| 141 | + |
| 142 | +static void __init rockchip_efuse_set_system_serial(void) |
| 143 | +{ |
| 144 | + int i; |
| 145 | + u8 buf[16]; |
| 146 | + |
| 147 | + for (i = 0; i < 8; i++) { |
| 148 | + buf[i] = efuse_buf[8 + (i << 1)]; |
| 149 | + buf[i + 8] = efuse_buf[7 + (i << 1)]; |
| 150 | + } |
| 151 | + |
| 152 | + system_serial_low = crc32(0, buf, 8); |
| 153 | + system_serial_high = crc32(system_serial_low, buf + 8, 8); |
| 154 | +} |
| 155 | + |
| 156 | + |
97 | 157 | static int __init rockchip_efuse_probe(struct platform_device *pdev) |
98 | 158 | { |
99 | 159 | struct resource *res; |
@@ -125,6 +185,10 @@ static int __init rockchip_efuse_probe(struct platform_device *pdev) |
125 | 185 |
|
126 | 186 | platform_set_drvdata(pdev, nvmem); |
127 | 187 |
|
| 188 | + rockchip_efuse_serial_number(efuse, efuse_buf); |
| 189 | + |
| 190 | + rockchip_efuse_set_system_serial(); |
| 191 | + |
128 | 192 | return 0; |
129 | 193 | } |
130 | 194 |
|
|
0 commit comments