From: Darren Etheridge Date: Fri, 19 Sep 2014 01:42:57 +0000 (+0000) Subject: drm/tilcdc: fix kernel panic on suspend when no hdmi monitor connected X-Git-Url: https://git.karo-electronics.de/?a=commitdiff_plain;h=85fd27f80b3641c9af9f04cde1b712c8c20916d8;p=linux-beck.git drm/tilcdc: fix kernel panic on suspend when no hdmi monitor connected On BeagleBone Black if no HDMI monitor is connected and suspend is requested a kernel panic will result: root@am335x-evm:~# echo mem > /sys/power/state [ 65.548710] PM: Syncing filesystems ... done. [ 65.631311] Freezing user space processes ... (elapsed 0.006 seconds) done. [ 65.648619] Freezing remaining freezable tasks ... (elapsed 0.005 seconds) done. [ 65.833500] Unhandled fault: external abort on non-linefetch (0x1028) at 0xfa30e004 [ 65.841692] Internal error: : 1028 [#1] SMP ARM [ 66.105287] [] (platform_pm_suspend) from [] (dpm_run_callback+0x34/0x70) [ 66.114370] [] (dpm_run_callback) from [] (__device_suspend+0x10c/0x2f4) [ 66.123357] [] (__device_suspend) from [] (dpm_suspend+0x58/0x218) [ 66.131796] [] (dpm_suspend) from [] (suspend_devices_and_enter+0x9c/0x3c0) [ 66.141055] [] (suspend_devices_and_enter) from [] (pm_suspend+0x210/0x24c) [ 66.150312] [] (pm_suspend) from [] (state_store+0x68/0xb8) [ 66.158103] [] (state_store) from [] (kobj_attr_store+0x14/0x20) [ 66.166355] [] (kobj_attr_store) from [] (sysfs_kf_write+0x4c/0x50) [ 66.174883] [] (sysfs_kf_write) from [] (kernfs_fop_write+0xb4/0x150) [ 66.183598] [] (kernfs_fop_write) from [] (vfs_write+0xa8/0x180) [ 66.191846] [] (vfs_write) from [] (SyS_write+0x40/0x8c) [ 66.199365] [] (SyS_write) from [] (ret_fast_syscall+0x0/0x48) [ 66.207426] Code: e595c210 e5932000 e59cc000 e08c2002 (e592c000) This is because the lcdc module is not enabled when no monitor is detected to save power. However the suspend handler just blindly tries to save the lcdc state by copying out the pertinent registers. However module is off so no good things happen when you try and access it. This patch only saves off the registers if the module is enabled, and then only restores the registers on resume if they were saved off during suspend. Signed-off-by: Darren Etheridge Tested-by: Dave Gerlach Acked-by: Felipe Balbi Signed-off-by: Jyri Sarha Reviewed-by: Tomi Valkeinen --- diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.c b/drivers/gpu/drm/tilcdc/tilcdc_drv.c index 420a237a99fc..67ed9f7fe197 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.c +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.c @@ -582,13 +582,20 @@ static int tilcdc_pm_suspend(struct device *dev) drm_kms_helper_poll_disable(ddev); + /* Select sleep pin state */ + pinctrl_pm_select_sleep_state(dev); + + if (pm_runtime_suspended(dev)) { + priv->ctx_valid = false; + return 0; + } + /* Save register state: */ for (i = 0; i < ARRAY_SIZE(registers); i++) if (registers[i].save && (priv->rev >= registers[i].rev)) priv->saved_register[n++] = tilcdc_read(ddev, registers[i].reg); - /* Select sleep pin state */ - pinctrl_pm_select_sleep_state(dev); + priv->ctx_valid = true; return 0; } @@ -602,10 +609,14 @@ static int tilcdc_pm_resume(struct device *dev) /* Select default pin state */ pinctrl_pm_select_default_state(dev); - /* Restore register state: */ - for (i = 0; i < ARRAY_SIZE(registers); i++) - if (registers[i].save && (priv->rev >= registers[i].rev)) - tilcdc_write(ddev, registers[i].reg, priv->saved_register[n++]); + if (priv->ctx_valid == true) { + /* Restore register state: */ + for (i = 0; i < ARRAY_SIZE(registers); i++) + if (registers[i].save && + (priv->rev >= registers[i].rev)) + tilcdc_write(ddev, registers[i].reg, + priv->saved_register[n++]); + } drm_kms_helper_poll_enable(ddev); diff --git a/drivers/gpu/drm/tilcdc/tilcdc_drv.h b/drivers/gpu/drm/tilcdc/tilcdc_drv.h index 62a1d688e6b3..55d17b3466c4 100644 --- a/drivers/gpu/drm/tilcdc/tilcdc_drv.h +++ b/drivers/gpu/drm/tilcdc/tilcdc_drv.h @@ -67,6 +67,7 @@ struct tilcdc_drm_private { /* register contents saved across suspend/resume: */ u32 saved_register[12]; + bool ctx_valid; #ifdef CONFIG_CPU_FREQ struct notifier_block freq_transition;