Skip to content

Commit e7bfce8

Browse files
committed
soc: amlogic: add cpuinfo support
1 parent ddf4dc8 commit e7bfce8

File tree

3 files changed

+82
-0
lines changed

3 files changed

+82
-0
lines changed

drivers/soc/amlogic/Kconfig

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,15 @@ config MESON_CLK_MEASURE
1717
Say yes to support of Measuring a set of internal SoC clocks
1818
from the debugfs interface.
1919

20+
config MESON_GX_CPUINFO
21+
tristate "Amlogic Meson GX cpuinfo support"
22+
depends on MESON_EFUSE && (ARM64 || ARM)
23+
default MESON_EFUSE
24+
help
25+
Say y here to enable Amlogic Meson GX cpuinfo support.
26+
Set system_serial from eFuse SN.
27+
Serial can read from /proc/cpuinfo.
28+
2029
config MESON_GX_SOCINFO
2130
bool "Amlogic Meson GX SoC Information driver"
2231
depends on ARCH_MESON || COMPILE_TEST

drivers/soc/amlogic/Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# SPDX-License-Identifier: GPL-2.0-only
22
obj-$(CONFIG_MESON_CANVAS) += meson-canvas.o
33
obj-$(CONFIG_MESON_CLK_MEASURE) += meson-clk-measure.o
4+
obj-$(CONFIG_MESON_GX_CPUINFO) += meson-gx-cpuinfo.o
45
obj-$(CONFIG_MESON_GX_SOCINFO) += meson-gx-socinfo.o
56
obj-$(CONFIG_MESON_GX_PM_DOMAINS) += meson-gx-pwrc-vpu.o
67
obj-$(CONFIG_MESON_MX_SOCINFO) += meson-mx-socinfo.o
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/*
2+
* This program is free software; you can redistribute it and/or modify it
3+
* under the terms of version 2 of the GNU General Public License as
4+
* published by the Free Software Foundation.
5+
*
6+
* This program is distributed in the hope that it will be useful, but WITHOUT
7+
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
8+
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
9+
* more details.
10+
*/
11+
12+
#include <linux/crc32.h>
13+
#include <linux/kernel.h>
14+
#include <linux/module.h>
15+
#include <linux/nvmem-consumer.h>
16+
#include <linux/platform_device.h>
17+
#include <linux/of_platform.h>
18+
#include <linux/slab.h>
19+
#include <asm/system_info.h>
20+
21+
static int meson_gx_cpuinfo_probe(struct platform_device *pdev)
22+
{
23+
struct device *dev = &pdev->dev;
24+
struct nvmem_cell *cell;
25+
unsigned char *efuse_buf, buf[17];
26+
size_t len;
27+
int i;
28+
29+
cell = nvmem_cell_get(dev, "sn");
30+
if (IS_ERR(cell)) {
31+
dev_err(dev, "failed to get sn cell: %ld\n", PTR_ERR(cell));
32+
if (PTR_ERR(cell) == -EPROBE_DEFER)
33+
return PTR_ERR(cell);
34+
return PTR_ERR(cell);
35+
}
36+
efuse_buf = nvmem_cell_read(cell, &len);
37+
nvmem_cell_put(cell);
38+
39+
if (len != 16) {
40+
kfree(efuse_buf);
41+
dev_err(dev, "invalid sn len: %zu\n", len);
42+
return -EINVAL;
43+
}
44+
45+
for (i = 0; i < 16; i++) {
46+
buf[i] = efuse_buf[i];
47+
}
48+
buf[16] = 0;
49+
50+
kfree(efuse_buf);
51+
52+
system_serial = kasprintf(GFP_KERNEL, "%s", buf);
53+
54+
dev_info(dev, "Serial\t\t: %s\n", system_serial);
55+
56+
return 0;
57+
}
58+
59+
static const struct of_device_id meson_gx_cpuinfo_of_match[] = {
60+
{ .compatible = "amlogic,meson-gx-cpuinfo", },
61+
{ },
62+
};
63+
MODULE_DEVICE_TABLE(of, meson_gx_cpuinfo_of_match);
64+
65+
static struct platform_driver meson_gx_cpuinfo_driver = {
66+
.probe = meson_gx_cpuinfo_probe,
67+
.driver = {
68+
.name = "meson-gx-cpuinfo",
69+
.of_match_table = meson_gx_cpuinfo_of_match,
70+
},
71+
};
72+
module_platform_driver(meson_gx_cpuinfo_driver);

0 commit comments

Comments
 (0)