Skip to content

Commit e2adc14

Browse files
yihsin-hungasus-leslieyu
authored andcommitted
Assign the Serial and Revision vaule of CPU from efuse
Change-Id: Ibfced548e03103912533f95dd0ec9818b8e6be47 Signed-off-by: yi-hsin_hung <yi-hsin_hung@asus.com>
1 parent 21df26c commit e2adc14

2 files changed

Lines changed: 68 additions & 0 deletions

File tree

drivers/cpufreq/cpufreq-dt.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include <linux/regulator/consumer.h>
3030
#include <linux/slab.h>
3131
#include <linux/thermal.h>
32+
#include <asm/system_info.h>
3233

3334
#define MAX_PROP_NAME_LEN 6
3435
#define VERSION_ELEMENTS 1
@@ -119,6 +120,9 @@ static int set_opp_info(struct device *dev)
119120
chip_vesion = 0;
120121
apll_safefreq = SAFE_FREQ;
121122
}
123+
124+
system_rev = (unsigned int)(package_info & 0xf0);
125+
122126
snprintf(name, MAX_PROP_NAME_LEN, "v%d", chip_vesion);
123127
ret = dev_pm_opp_set_prop_name(dev, name);
124128
if (ret) {

drivers/nvmem/rockchip-efuse.c

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
#include <linux/slab.h>
2424
#include <linux/of.h>
2525
#include <linux/platform_device.h>
26+
#include <asm/system_info.h>
27+
#include <linux/crc32.h>
2628

2729
#define EFUSE_A_SHIFT 6
2830
#define EFUSE_A_MASK 0x3ff
@@ -94,6 +96,64 @@ static const struct of_device_id rockchip_efuse_match[] = {
9496
};
9597
MODULE_DEVICE_TABLE(of, rockchip_efuse_match);
9698

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+
97157
static int __init rockchip_efuse_probe(struct platform_device *pdev)
98158
{
99159
struct resource *res;
@@ -125,6 +185,10 @@ static int __init rockchip_efuse_probe(struct platform_device *pdev)
125185

126186
platform_set_drvdata(pdev, nvmem);
127187

188+
rockchip_efuse_serial_number(efuse, efuse_buf);
189+
190+
rockchip_efuse_set_system_serial();
191+
128192
return 0;
129193
}
130194

0 commit comments

Comments
 (0)