From fdc250b90f8cffdb46f3745fb8086587f216cf1c Mon Sep 17 00:00:00 2001 From: Hong Guo Date: Sat, 7 Sep 2019 15:21:22 +0800 Subject: [PATCH] reboot: add reboot reason sys infterface [1/1] PD#TV-9896 Problem: provide sys interface to get last reboot reason Solution: add reboot reason sys infterface Verify: test pass on tl1_x301 Change-Id: I6c4046c892eff9f92506fadb0cddee7041c8f882 Signed-off-by: Hong Guo --- arch/arm/boot/dts/amlogic/mesontl1.dtsi | 1 + arch/arm64/boot/dts/amlogic/mesontl1.dtsi | 1 + drivers/amlogic/reboot/reboot.c | 26 +++++++++++++++++++++++ 3 files changed, 28 insertions(+) diff --git a/arch/arm/boot/dts/amlogic/mesontl1.dtsi b/arch/arm/boot/dts/amlogic/mesontl1.dtsi index ac996dd07dc9..bf1ce84b4f47 100644 --- a/arch/arm/boot/dts/amlogic/mesontl1.dtsi +++ b/arch/arm/boot/dts/amlogic/mesontl1.dtsi @@ -319,6 +319,7 @@ compatible = "amlogic,reboot"; sys_reset = <0x84000009>; sys_poweroff = <0x84000008>; + reboot_reason_addr = <0xff80023c>; }; ram-dump { diff --git a/arch/arm64/boot/dts/amlogic/mesontl1.dtsi b/arch/arm64/boot/dts/amlogic/mesontl1.dtsi index 07d59526eefc..e8b8aa4672e2 100644 --- a/arch/arm64/boot/dts/amlogic/mesontl1.dtsi +++ b/arch/arm64/boot/dts/amlogic/mesontl1.dtsi @@ -311,6 +311,7 @@ compatible = "amlogic,reboot"; sys_reset = <0x84000009>; sys_poweroff = <0x84000008>; + reboot_reason_addr = <0xff80023c>; }; ram-dump { diff --git a/drivers/amlogic/reboot/reboot.c b/drivers/amlogic/reboot/reboot.c index 80cf73760a48..c9b9f200196d 100644 --- a/drivers/amlogic/reboot/reboot.c +++ b/drivers/amlogic/reboot/reboot.c @@ -34,6 +34,7 @@ #include #include +static void __iomem *reboot_reason_vaddr; static u32 psci_function_id_restart; static u32 psci_function_id_poweroff; static char *kernel_panic; @@ -126,10 +127,27 @@ static struct notifier_block panic_notifier = { .notifier_call = panic_notify, }; +ssize_t reboot_reason_show(struct device *dev, + struct device_attribute *attr, char *buf) +{ + unsigned int value, len; + + if (!reboot_reason_vaddr) + return 0; + value = readl(reboot_reason_vaddr); + value = (value >> 12) & 0xf; + len = sprintf(buf, "%d\n", value); + + return len; +} + +DEVICE_ATTR(reboot_reason, 0444, reboot_reason_show, NULL); + static int aml_restart_probe(struct platform_device *pdev) { u32 id; int ret; + u32 paddr = 0; if (!of_property_read_u32(pdev->dev.of_node, "sys_reset", &id)) { psci_function_id_restart = id; @@ -141,6 +159,14 @@ static int aml_restart_probe(struct platform_device *pdev) pm_power_off = do_aml_poweroff; } + ret = of_property_read_u32(pdev->dev.of_node, + "reboot_reason_addr", &paddr); + if (!ret) { + pr_debug("reboot_reason paddr: 0x%x\n", paddr); + reboot_reason_vaddr = ioremap(paddr, 0x4); + device_create_file(&pdev->dev, &dev_attr_reboot_reason); + } + ret = register_die_notifier(&panic_notifier); if (ret != 0) { pr_err("%s,register die notifier failed,ret =%d!\n",