|
| 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