Skip to content

Commit

Permalink
soc: amlogic: add cpuinfo support
Browse files Browse the repository at this point in the history
  • Loading branch information
scpcom committed Jun 27, 2020
1 parent ddf4dc8 commit e7bfce8
Show file tree
Hide file tree
Showing 3 changed files with 82 additions and 0 deletions.
9 changes: 9 additions & 0 deletions drivers/soc/amlogic/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,15 @@ config MESON_CLK_MEASURE
Say yes to support of Measuring a set of internal SoC clocks
from the debugfs interface.

config MESON_GX_CPUINFO
tristate "Amlogic Meson GX cpuinfo support"
depends on MESON_EFUSE && (ARM64 || ARM)
default MESON_EFUSE
help
Say y here to enable Amlogic Meson GX cpuinfo support.
Set system_serial from eFuse SN.
Serial can read from /proc/cpuinfo.

config MESON_GX_SOCINFO
bool "Amlogic Meson GX SoC Information driver"
depends on ARCH_MESON || COMPILE_TEST
Expand Down
1 change: 1 addition & 0 deletions drivers/soc/amlogic/Makefile
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# SPDX-License-Identifier: GPL-2.0-only
obj-$(CONFIG_MESON_CANVAS) += meson-canvas.o
obj-$(CONFIG_MESON_CLK_MEASURE) += meson-clk-measure.o
obj-$(CONFIG_MESON_GX_CPUINFO) += meson-gx-cpuinfo.o
obj-$(CONFIG_MESON_GX_SOCINFO) += meson-gx-socinfo.o
obj-$(CONFIG_MESON_GX_PM_DOMAINS) += meson-gx-pwrc-vpu.o
obj-$(CONFIG_MESON_MX_SOCINFO) += meson-mx-socinfo.o
Expand Down
72 changes: 72 additions & 0 deletions drivers/soc/amlogic/meson-gx-cpuinfo.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
/*
* This program is free software; you can redistribute it and/or modify it
* under the terms of version 2 of the GNU General Public License as
* published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*/

#include <linux/crc32.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/nvmem-consumer.h>
#include <linux/platform_device.h>
#include <linux/of_platform.h>
#include <linux/slab.h>
#include <asm/system_info.h>

static int meson_gx_cpuinfo_probe(struct platform_device *pdev)
{
struct device *dev = &pdev->dev;
struct nvmem_cell *cell;
unsigned char *efuse_buf, buf[17];
size_t len;
int i;

cell = nvmem_cell_get(dev, "sn");
if (IS_ERR(cell)) {
dev_err(dev, "failed to get sn cell: %ld\n", PTR_ERR(cell));
if (PTR_ERR(cell) == -EPROBE_DEFER)
return PTR_ERR(cell);
return PTR_ERR(cell);
}
efuse_buf = nvmem_cell_read(cell, &len);
nvmem_cell_put(cell);

if (len != 16) {
kfree(efuse_buf);
dev_err(dev, "invalid sn len: %zu\n", len);
return -EINVAL;
}

for (i = 0; i < 16; i++) {
buf[i] = efuse_buf[i];
}
buf[16] = 0;

kfree(efuse_buf);

system_serial = kasprintf(GFP_KERNEL, "%s", buf);

dev_info(dev, "Serial\t\t: %s\n", system_serial);

return 0;
}

static const struct of_device_id meson_gx_cpuinfo_of_match[] = {
{ .compatible = "amlogic,meson-gx-cpuinfo", },
{ },
};
MODULE_DEVICE_TABLE(of, meson_gx_cpuinfo_of_match);

static struct platform_driver meson_gx_cpuinfo_driver = {
.probe = meson_gx_cpuinfo_probe,
.driver = {
.name = "meson-gx-cpuinfo",
.of_match_table = meson_gx_cpuinfo_of_match,
},
};
module_platform_driver(meson_gx_cpuinfo_driver);

0 comments on commit e7bfce8

Please sign in to comment.