ramdump: add ramdump support for TL1 [4/4]
authorTao Zeng <tao.zeng@amlogic.com>
Fri, 4 Jan 2019 09:04:45 +0000 (17:04 +0800)
committerJianxin Pan <jianxin.pan@amlogic.com>
Wed, 9 Jan 2019 07:03:46 +0000 (23:03 -0800)
PD#TV-1924

Problem:
On TL1, ramdump is not enabled.

Solution:
Add ramdump support for TL1 chips in kernel.
Also add sticky register config for other chips

Verify:
tl1_x301_v1

Change-Id: I67a11d128343ff9e615377b19914a3fc77b7acef
Signed-off-by: Tao Zeng <tao.zeng@amlogic.com>
16 files changed:
arch/arm/boot/dts/amlogic/mesonaxg.dtsi
arch/arm/boot/dts/amlogic/mesong12a.dtsi
arch/arm/boot/dts/amlogic/mesongxl.dtsi
arch/arm/boot/dts/amlogic/mesongxm.dtsi
arch/arm/boot/dts/amlogic/mesontl1.dtsi
arch/arm/boot/dts/amlogic/mesontxl.dtsi
arch/arm/boot/dts/amlogic/mesontxlx.dtsi
arch/arm64/boot/dts/amlogic/mesonaxg.dtsi
arch/arm64/boot/dts/amlogic/mesong12a.dtsi
arch/arm64/boot/dts/amlogic/mesongxl.dtsi
arch/arm64/boot/dts/amlogic/mesongxm.dtsi
arch/arm64/boot/dts/amlogic/mesontl1.dtsi
arch/arm64/boot/dts/amlogic/mesontxl.dtsi
arch/arm64/boot/dts/amlogic/mesontxlx.dtsi
drivers/amlogic/memory_ext/ram_dump.c
include/linux/amlogic/ramdump.h

index 3d3fa50..0aa846d 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0xFF6345E0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        pinctrl_aobus: pinctrl@ff800014{
index c0e8fce..7282425 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0xFF6345E0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        jtag {
index a220ea1..982bae2 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0xC88345E0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        jtag {
index 91a1e26..0a0fb44 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0xC88345E0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        jtag {
index 2e47699..dbc3187 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0xFF6345E0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        securitykey {
index 0327f80..ed9fd92 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0xC88345E0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        securitykey {
index d45d4d9..8228a79 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0xFF6345E0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        amlogic-jtag {
index 111ad4c..318bb4d 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0x0 0xFF6345E0 0x0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        pinctrl_aobus: pinctrl@ff800014{
index d5cecef..9d7bf37 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0x0 0xFF6345E0 0x0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        jtag {
index 643a922..af7117d 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0x0 0xC88345E0 0x0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        jtag {
index 22cbefd..177907c 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0x0 0xC88345E0 0x0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        jtag {
index f7ab9b2..cdb3509 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0x0 0xFF6345E0 0x0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        securitykey {
index 92ad567..9d90ba8 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0x0 0xC88345E0 0x0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        securitykey {
index 502e5e3..9f19b46 100644 (file)
        ram-dump {
                compatible = "amlogic, ram_dump";
                status = "okay";
+               reg = <0x0 0xFF6345E0 0x0 4>;
+               reg-names = "PREG_STICKY_REG8";
        };
 
        amlogic-jtag {
index 3634ad4..c188088 100644 (file)
@@ -31,6 +31,7 @@
 #include <linux/amlogic/ramdump.h>
 #include <linux/amlogic/reboot.h>
 #include <linux/arm-smccc.h>
+#include <linux/of.h>
 #include <linux/highmem.h>
 #include <asm/cacheflush.h>
 
@@ -282,6 +283,46 @@ void ramdump_sync_data(void)
 static int __init ramdump_probe(struct platform_device *pdev)
 {
        void __iomem *p = NULL;
+       struct device_node *np;
+       unsigned long dts_memory[2] = {0}, total_mem;
+       struct resource *res;
+       unsigned int dump_set;
+       int ret;
+       void __iomem *base;
+
+       np = of_find_node_by_name(NULL, "memory");
+       if (!np)
+               return -EINVAL;
+
+#ifdef CONFIG_64BIT
+       ret = of_property_read_u64_array(np, "linux,usable-memory",
+                                        (u64 *)&dts_memory, 2);
+       if (ret)
+               ret = of_property_read_u64_array(np, "reg",
+                                                (u64 *)&dts_memory, 2);
+#else
+       ret = of_property_read_u32_array(np, "linux,usable-memory",
+                                        (u32 *)&dts_memory, 2);
+       if (ret)
+               ret = of_property_read_u32_array(np, "reg",
+                                                (u32 *)&dts_memory, 2);
+#endif
+       if (ret)
+               pr_info("can't get dts memory\n");
+       else
+               pr_info("MEMORY:[%lx+%lx]\n", dts_memory[0], dts_memory[1]);
+       of_node_put(np);
+
+       /*
+        * memory in dts is [start_addr size] patten. For amlogic soc,
+        * ddr address range is started from 0x0, usually start_addr in
+        * dts should be started with 0x0, but some soc must reserve a
+        * small framgment of memory at 0x0 for start up code. So start_addr
+        * can be 0x100000/0x1000000. But we always using 0x0 to get real
+        * DDR size for ramdump. So we using following formula to get total
+        * DDR size.
+        */
+       total_mem = dts_memory[0] + dts_memory[1];
 
        ram = kzalloc(sizeof(struct ramdump), GFP_KERNEL);
        if (!ram)
@@ -320,6 +361,21 @@ static int __init ramdump_probe(struct platform_device *pdev)
                INIT_WORK(&ram->clear_work, lazy_clear_work);
                schedule_work(&ram->clear_work);
        }
+       res = platform_get_resource_byname(pdev, IORESOURCE_MEM,
+                                          "PREG_STICKY_REG8");
+       if (res) {
+               base = devm_ioremap(&pdev->dev, res->start,
+                                               res->end - res->start);
+               if (!base) {
+                       pr_err("%s, map reg failed\n", __func__);
+                       goto err;
+               }
+               dump_set = readl(base);
+               dump_set &= ~RAMDUMP_STICKY_DATA_MASK;
+               dump_set |= ((total_mem >> 20) | AMLOGIC_KERNEL_BOOTED);
+               writel(dump_set, base);
+               pr_info("%s, set sticky to %x\n", __func__, dump_set);
+       }
        return 0;
 
 err1:
index 5dc0c42..7944e65 100644 (file)
@@ -20,6 +20,9 @@
 
 #define SET_REBOOT_REASON              0x82000049
 
+#define AMLOGIC_KERNEL_BOOTED          0x8000
+#define RAMDUMP_STICKY_DATA_MASK       0xFFFF
+
 extern int ramdump_disabled(void);
 extern void ramdump_sync_data(void);