soc: rockchip: cpuinfo: read cpu version from eFuse
authorLiang Chen <cl@rock-chips.com>
Thu, 1 Jun 2017 03:11:11 +0000 (11:11 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Fri, 2 Jun 2017 08:40:04 +0000 (16:40 +0800)
Change-Id: Ia18ff4e745f09fa04690bb7bc6d95169c389b9d2
Signed-off-by: Liang Chen <cl@rock-chips.com>
drivers/soc/rockchip/Kconfig
drivers/soc/rockchip/rockchip-cpuinfo.c
include/linux/rockchip/cpu.h

index 60496713ebce69b0d1cfa79a2e0de4b37a9acead..aacbd43613b222662415584e4abe77a2796e9ee6 100644 (file)
@@ -4,8 +4,9 @@ if ARCH_ROCKCHIP || COMPILE_TEST
 # Rockchip Soc drivers
 #
 config ROCKCHIP_CPUINFO
-       tristate "Rockchip cpuinfo support"
+       bool "Rockchip cpuinfo support"
        depends on ROCKCHIP_EFUSE && (ARM64 || ARM)
+       default y
        help
          Say y here to enable Rockchip cpuinfo support.
          Set system_serial_low/high from eFuse ID.
index 5c8e9f2022be751f7951cefe63703cbb083191dd..64a59bbc876808682a185d92542b5e8830ed4c4d 100644 (file)
 #include <linux/platform_device.h>
 #include <linux/slab.h>
 #include <asm/system_info.h>
+#include <linux/rockchip/cpu.h>
+
+unsigned long rockchip_soc_id;
+EXPORT_SYMBOL(rockchip_soc_id);
 
 static int rockchip_cpuinfo_probe(struct platform_device *pdev)
 {
@@ -27,6 +31,16 @@ static int rockchip_cpuinfo_probe(struct platform_device *pdev)
        size_t len;
        int i;
 
+       cell = nvmem_cell_get(dev, "cpu-version");
+       if (!IS_ERR(cell)) {
+               efuse_buf = nvmem_cell_read(cell, &len);
+               nvmem_cell_put(cell);
+
+               if (len == 1)
+                       rockchip_set_cpu_version(efuse_buf[0]);
+               kfree(efuse_buf);
+       }
+
        cell = nvmem_cell_get(dev, "id");
        if (IS_ERR(cell)) {
                dev_err(dev, "failed to get id cell: %ld\n", PTR_ERR(cell));
@@ -72,4 +86,9 @@ static struct platform_driver rockchip_cpuinfo_driver = {
                .of_match_table = rockchip_cpuinfo_of_match,
        },
 };
-module_platform_driver(rockchip_cpuinfo_driver);
+
+static int __init rockchip_cpuinfo_init(void)
+{
+       return platform_driver_register(&rockchip_cpuinfo_driver);
+}
+subsys_initcall_sync(rockchip_cpuinfo_init);
index edc145550f556d3db44f4eee0d6206cfdc15ef09..ad6cdc40fd879a25a67706e50cf8aa56fe927b42 100644 (file)
@@ -1,6 +1,8 @@
 #ifndef __MACH_ROCKCHIP_CPU_H
 #define __MACH_ROCKCHIP_CPU_H
 
+#ifdef CONFIG_ROCKCHIP_CPUINFO
+
 extern unsigned long rockchip_soc_id;
 
 static inline bool cpu_is_rockchip(void)
@@ -24,6 +26,24 @@ static inline void rockchip_set_cpu_version(unsigned long ver)
                (ver << ROCKCHIP_CPU_VERION_SHIFT) & ROCKCHIP_CPU_VERION_MASK;
 }
 
+#else
+
+static inline bool cpu_is_rockchip(void)
+{
+       return true;
+}
+
+static inline unsigned long rockchip_get_cpu_version(void)
+{
+       return 0;
+}
+
+static inline void rockchip_set_cpu_version(unsigned long ver)
+{
+}
+
+#endif
+
 #define ROCKCHIP_CPU_MASK       0xffff0000
 #define ROCKCHIP_CPU_RK2928     0x29280000
 #define ROCKCHIP_CPU_RK3026     0x30260000
@@ -36,7 +56,7 @@ static inline void rockchip_set_cpu_version(unsigned long ver)
 #define ROCKCHIP_CPU_RK3288     0x32880000
 #define ROCKCHIP_CPU_RK3228     0x32280000
 
-#ifdef CONFIG_ARM
+#ifdef CONFIG_ROCKCHIP_CPUINFO
 #define ROCKCHIP_CPU(id, ID) \
 static inline bool cpu_is_rk##id(void) \
 { \
@@ -80,7 +100,7 @@ ROCKCHIP_CPU(3228, 3228)
 #define ROCKCHIP_SOC_RK3288     (ROCKCHIP_CPU_RK3288 | 0x00)
 #define ROCKCHIP_SOC_RK3228     (ROCKCHIP_CPU_RK3228 | 0x00)
 
-#ifdef CONFIG_ARM
+#ifdef CONFIG_ROCKCHIP_CPUINFO
 #define ROCKCHIP_SOC(id, ID) \
 static inline bool soc_is_rk##id(void) \
 { \