* [PATCH 1/2] media: mtk-vpu: VPU should be in idle state before system is suspended @ 2020-10-29 1:17 Irui Wang 2020-10-29 1:17 ` [PATCH 2/2] media: mtk-vpu: dump VPU status when IPI times out Irui Wang 2020-11-25 2:46 ` [PATCH 1/2] media: mtk-vpu: VPU should be in idle state before system is suspended Alexandre Courbot 0 siblings, 2 replies; 4+ messages in thread From: Irui Wang @ 2020-10-29 1:17 UTC (permalink / raw) To: hverkuil, acourbot, mchehab, matthias.bgg Cc: Andrew-CT.Chen, Maoguang.Meng, srv_heupstream, irui.wang, Yunfei.Dong, erin.lo, Longfei.Wang, linux-kernel, houlong.wei, linux-mediatek, PoChun.Lin, hsinyi, linux-arm-kernel, linux-media VPU should be in idle state before system is suspended or it will work abnormally like VPU program counter not in a correct address or VPU reset Signed-off-by: Irui Wang <irui.wang@mediatek.com> --- drivers/media/platform/mtk-vpu/mtk_vpu.c | 68 ++++++++++++++++++++++++ 1 file changed, 68 insertions(+) diff --git a/drivers/media/platform/mtk-vpu/mtk_vpu.c b/drivers/media/platform/mtk-vpu/mtk_vpu.c index 36cb9b6131f7..86ab808ba877 100644 --- a/drivers/media/platform/mtk-vpu/mtk_vpu.c +++ b/drivers/media/platform/mtk-vpu/mtk_vpu.c @@ -27,6 +27,7 @@ #define INIT_TIMEOUT_MS 2000U #define IPI_TIMEOUT_MS 2000U +#define VPU_IDLE_TIMEOUT_MS 1000U #define VPU_FW_VER_LEN 16 /* maximum program/data TCM (Tightly-Coupled Memory) size */ @@ -57,11 +58,15 @@ #define VPU_DMEM_EXT0_ADDR 0x0014 #define VPU_DMEM_EXT1_ADDR 0x0018 #define HOST_TO_VPU 0x0024 +#define VPU_IDLE_REG 0x002C +#define VPU_INT_STATUS 0x0034 #define VPU_PC_REG 0x0060 #define VPU_WDT_REG 0x0084 /* vpu inter-processor communication interrupt */ #define VPU_IPC_INT BIT(8) +/* vpu idle state */ +#define VPU_IDLE_STATE BIT(23) /** * enum vpu_fw_type - VPU firmware type @@ -945,11 +950,74 @@ static int mtk_vpu_remove(struct platform_device *pdev) return 0; } +static int mtk_vpu_suspend(struct device *dev) +{ + struct mtk_vpu *vpu = dev_get_drvdata(dev); + unsigned long timeout; + int ret; + + ret = vpu_clock_enable(vpu); + if (ret) { + dev_err(dev, "failed to enable vpu clock\n"); + return ret; + } + + mutex_lock(&vpu->vpu_mutex); + /* disable vpu timer interrupt */ + vpu_cfg_writel(vpu, vpu_cfg_readl(vpu, VPU_INT_STATUS) | VPU_IDLE_STATE, + VPU_INT_STATUS); + /* check if vpu is idle for system suspend */ + timeout = jiffies + msecs_to_jiffies(VPU_IDLE_TIMEOUT_MS); + do { + if (time_after(jiffies, timeout)) { + dev_err(dev, "vpu idle timeout\n"); + mutex_unlock(&vpu->vpu_mutex); + vpu_clock_disable(vpu); + return -EIO; + } + } while (!vpu_cfg_readl(vpu, VPU_IDLE_REG)); + + mutex_unlock(&vpu->vpu_mutex); + vpu_clock_disable(vpu); + clk_unprepare(vpu->clk); + + return 0; +} + +static int mtk_vpu_resume(struct device *dev) +{ + struct mtk_vpu *vpu = dev_get_drvdata(dev); + int ret; + + clk_prepare(vpu->clk); + ret = vpu_clock_enable(vpu); + if (ret) { + dev_err(dev, "failed to enable vpu clock\n"); + return ret; + } + + mutex_lock(&vpu->vpu_mutex); + /* enable vpu timer interrupt */ + vpu_cfg_writel(vpu, + vpu_cfg_readl(vpu, VPU_INT_STATUS) & ~(VPU_IDLE_STATE), + VPU_INT_STATUS); + mutex_unlock(&vpu->vpu_mutex); + vpu_clock_disable(vpu); + + return 0; +} + +static const struct dev_pm_ops mtk_vpu_pm = { + .suspend = mtk_vpu_suspend, + .resume = mtk_vpu_resume, +}; + static struct platform_driver mtk_vpu_driver = { .probe = mtk_vpu_probe, .remove = mtk_vpu_remove, .driver = { .name = "mtk_vpu", + .pm = &mtk_vpu_pm, .of_match_table = mtk_vpu_match, }, }; -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 2/2] media: mtk-vpu: dump VPU status when IPI times out 2020-10-29 1:17 [PATCH 1/2] media: mtk-vpu: VPU should be in idle state before system is suspended Irui Wang @ 2020-10-29 1:17 ` Irui Wang 2020-11-25 2:46 ` Alexandre Courbot 2020-11-25 2:46 ` [PATCH 1/2] media: mtk-vpu: VPU should be in idle state before system is suspended Alexandre Courbot 1 sibling, 1 reply; 4+ messages in thread From: Irui Wang @ 2020-10-29 1:17 UTC (permalink / raw) To: hverkuil, acourbot, mchehab, matthias.bgg Cc: Andrew-CT.Chen, Maoguang.Meng, srv_heupstream, irui.wang, Yunfei.Dong, erin.lo, Longfei.Wang, linux-kernel, houlong.wei, linux-mediatek, PoChun.Lin, hsinyi, linux-arm-kernel, linux-media when IPI time out, dump VPU status to get more debug information Signed-off-by: Irui Wang <irui.wang@mediatek.com> --- drivers/media/platform/mtk-vpu/mtk_vpu.c | 33 +++++++++++++++++++++--- 1 file changed, 29 insertions(+), 4 deletions(-) diff --git a/drivers/media/platform/mtk-vpu/mtk_vpu.c b/drivers/media/platform/mtk-vpu/mtk_vpu.c index 86ab808ba877..043894f7188c 100644 --- a/drivers/media/platform/mtk-vpu/mtk_vpu.c +++ b/drivers/media/platform/mtk-vpu/mtk_vpu.c @@ -61,6 +61,8 @@ #define VPU_IDLE_REG 0x002C #define VPU_INT_STATUS 0x0034 #define VPU_PC_REG 0x0060 +#define VPU_SP_REG 0x0064 +#define VPU_RA_REG 0x0068 #define VPU_WDT_REG 0x0084 /* vpu inter-processor communication interrupt */ @@ -268,6 +270,20 @@ static int vpu_clock_enable(struct mtk_vpu *vpu) return ret; } +static void vpu_dump_status(struct mtk_vpu *vpu) +{ + dev_info(vpu->dev, + "vpu: run %x, pc = 0x%x, ra = 0x%x, sp = 0x%x, idle = 0x%x\n" + "vpu: int %x, hv = 0x%x, vh = 0x%x, wdt = 0x%x\n", + vpu_running(vpu), vpu_cfg_readl(vpu, VPU_PC_REG), + vpu_cfg_readl(vpu, VPU_RA_REG), vpu_cfg_readl(vpu, VPU_SP_REG), + vpu_cfg_readl(vpu, VPU_IDLE_REG), + vpu_cfg_readl(vpu, VPU_INT_STATUS), + vpu_cfg_readl(vpu, HOST_TO_VPU), + vpu_cfg_readl(vpu, VPU_TO_HOST), + vpu_cfg_readl(vpu, VPU_WDT_REG)); +} + int vpu_ipi_register(struct platform_device *pdev, enum ipi_id id, ipi_handler_t handler, const char *name, void *priv) @@ -328,6 +344,7 @@ int vpu_ipi_send(struct platform_device *pdev, if (time_after(jiffies, timeout)) { dev_err(vpu->dev, "vpu_ipi_send: IPI timeout!\n"); ret = -EIO; + vpu_dump_status(vpu); goto mut_unlock; } } while (vpu_cfg_readl(vpu, HOST_TO_VPU)); @@ -347,8 +364,9 @@ int vpu_ipi_send(struct platform_device *pdev, ret = wait_event_timeout(vpu->ack_wq, vpu->ipi_id_ack[id], timeout); vpu->ipi_id_ack[id] = false; if (ret == 0) { - dev_err(vpu->dev, "vpu ipi %d ack time out !", id); + dev_err(vpu->dev, "vpu ipi %d ack time out !\n", id); ret = -EIO; + vpu_dump_status(vpu); goto clock_disable; } vpu_clock_disable(vpu); @@ -633,7 +651,7 @@ static ssize_t vpu_debug_read(struct file *file, char __user *user_buf, { char buf[256]; unsigned int len; - unsigned int running, pc, vpu_to_host, host_to_vpu, wdt; + unsigned int running, pc, vpu_to_host, host_to_vpu, wdt, idle, ra, sp; int ret; struct device *dev = file->private_data; struct mtk_vpu *vpu = dev_get_drvdata(dev); @@ -650,6 +668,10 @@ static ssize_t vpu_debug_read(struct file *file, char __user *user_buf, wdt = vpu_cfg_readl(vpu, VPU_WDT_REG); host_to_vpu = vpu_cfg_readl(vpu, HOST_TO_VPU); vpu_to_host = vpu_cfg_readl(vpu, VPU_TO_HOST); + ra = vpu_cfg_readl(vpu, VPU_RA_REG); + sp = vpu_cfg_readl(vpu, VPU_SP_REG); + idle = vpu_cfg_readl(vpu, VPU_IDLE_REG); + vpu_clock_disable(vpu); if (running) { @@ -658,9 +680,12 @@ static ssize_t vpu_debug_read(struct file *file, char __user *user_buf, "PC: 0x%x\n" "WDT: 0x%x\n" "Host to VPU: 0x%x\n" - "VPU to Host: 0x%x\n", + "VPU to Host: 0x%x\n" + "SP: 0x%x\n" + "RA: 0x%x\n" + "idle: 0x%x\n", vpu->run.fw_ver, pc, wdt, - host_to_vpu, vpu_to_host); + host_to_vpu, vpu_to_host, sp, ra, idle); } else { len = snprintf(buf, sizeof(buf), "VPU not running\n"); } -- 2.25.1 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 2/2] media: mtk-vpu: dump VPU status when IPI times out 2020-10-29 1:17 ` [PATCH 2/2] media: mtk-vpu: dump VPU status when IPI times out Irui Wang @ 2020-11-25 2:46 ` Alexandre Courbot 0 siblings, 0 replies; 4+ messages in thread From: Alexandre Courbot @ 2020-11-25 2:46 UTC (permalink / raw) To: Irui Wang Cc: Andrew-CT.Chen, Maoguang.Meng, srv_heupstream, Yunfei.Dong, erin.lo, Longfei.Wang, linux-kernel, houlong.wei, hverkuil, linux-mediatek, PoChun.Lin, matthias.bgg, hsinyi, mchehab, linux-arm-kernel, linux-media On Thu, Oct 29, 2020 at 10:17 AM Irui Wang <irui.wang@mediatek.com> wrote: > > when IPI time out, dump VPU status to get more debug information > > Signed-off-by: Irui Wang <irui.wang@mediatek.com> Reviewed-by: Alexandre Courbot <acourbot@chromium.org> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH 1/2] media: mtk-vpu: VPU should be in idle state before system is suspended 2020-10-29 1:17 [PATCH 1/2] media: mtk-vpu: VPU should be in idle state before system is suspended Irui Wang 2020-10-29 1:17 ` [PATCH 2/2] media: mtk-vpu: dump VPU status when IPI times out Irui Wang @ 2020-11-25 2:46 ` Alexandre Courbot 1 sibling, 0 replies; 4+ messages in thread From: Alexandre Courbot @ 2020-11-25 2:46 UTC (permalink / raw) To: Irui Wang Cc: Andrew-CT.Chen, Maoguang.Meng, srv_heupstream, Yunfei.Dong, erin.lo, Longfei.Wang, linux-kernel, houlong.wei, hverkuil, linux-mediatek, PoChun.Lin, matthias.bgg, hsinyi, mchehab, linux-arm-kernel, linux-media On Thu, Oct 29, 2020 at 10:17 AM Irui Wang <irui.wang@mediatek.com> wrote: > > VPU should be in idle state before system is suspended > or it will work abnormally like VPU program counter not > in a correct address or VPU reset > > Signed-off-by: Irui Wang <irui.wang@mediatek.com> FWIW, Reviewed-by: Alexandre Courbot <acourbot@chromium.org> _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-11-25 2:54 UTC | newest] Thread overview: 4+ messages (download: mbox.gz follow: Atom feed -- links below jump to the message on this page -- 2020-10-29 1:17 [PATCH 1/2] media: mtk-vpu: VPU should be in idle state before system is suspended Irui Wang 2020-10-29 1:17 ` [PATCH 2/2] media: mtk-vpu: dump VPU status when IPI times out Irui Wang 2020-11-25 2:46 ` Alexandre Courbot 2020-11-25 2:46 ` [PATCH 1/2] media: mtk-vpu: VPU should be in idle state before system is suspended Alexandre Courbot
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).