thermal: rockchip: add temperature dump when panic
authorRocky Hao <rocky.hao@rock-chips.com>
Wed, 17 Aug 2016 10:44:12 +0000 (18:44 +0800)
committerHuang, Tao <huangtao@rock-chips.com>
Fri, 26 Aug 2016 09:26:48 +0000 (17:26 +0800)
Change-Id: I8cf3bbaea76d379dcfd1c89482254854df62cfea
Signed-off-by: Rocky Hao <rocky.hao@rock-chips.com>
drivers/thermal/rockchip_thermal.c

index 43f3371360b2905d5947379ed7d03f7d761207c3..357d967fc71fa4c679ebaddf49926d543827a062 100644 (file)
@@ -1010,6 +1010,48 @@ static void rockchip_thermal_reset_controller(struct reset_control *reset)
        reset_control_deassert(reset);
 }
 
+static struct platform_device *thermal_device;
+
+void rockchip_dump_temperature(void)
+{
+       struct rockchip_thermal_data *thermal;
+       struct platform_device *pdev;
+       int i;
+
+       if (!thermal_device)
+               return;
+
+       pdev = thermal_device;
+       thermal = platform_get_drvdata(pdev);
+
+       for (i = 0; i < thermal->chip->chn_num; i++) {
+               struct rockchip_thermal_sensor *sensor = &thermal->sensors[i];
+               struct thermal_zone_device *tz = sensor->tzd;
+
+               if (tz->temperature != THERMAL_TEMP_INVALID)
+                       dev_warn(&pdev->dev, "channal %d: temperature(%d C)\n",
+                                i, tz->temperature / 1000);
+       }
+
+       if (thermal->regs) {
+               pr_warn("THERMAL REGS:\n");
+               print_hex_dump(KERN_WARNING, "", DUMP_PREFIX_OFFSET,
+                              32, 4, thermal->regs, 0x88, false);
+       }
+}
+EXPORT_SYMBOL_GPL(rockchip_dump_temperature);
+
+static int rockchip_thermal_panic(struct notifier_block *this,
+                                 unsigned long ev, void *ptr)
+{
+       rockchip_dump_temperature();
+       return NOTIFY_DONE;
+}
+
+static struct notifier_block rockchip_thermal_panic_block = {
+       .notifier_call = rockchip_thermal_panic,
+};
+
 static int rockchip_thermal_probe(struct platform_device *pdev)
 {
        struct device_node *np = pdev->dev.of_node;
@@ -1122,6 +1164,11 @@ static int rockchip_thermal_probe(struct platform_device *pdev)
 
        platform_set_drvdata(pdev, thermal);
 
+       thermal_device = pdev;
+
+       atomic_notifier_chain_register(&panic_notifier_list,
+                                      &rockchip_thermal_panic_block);
+
        return 0;
 
 err_disable_pclk: