From patchwork Fri Sep 23 08:15:23 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrzej Hajda X-Patchwork-Id: 9347695 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id D6FD5601C2 for ; Fri, 23 Sep 2016 08:15:53 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id C8DA129F34 for ; Fri, 23 Sep 2016 08:15:53 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id BDA8C29F56; Fri, 23 Sep 2016 08:15:53 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-6.9 required=2.0 tests=BAYES_00,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 23BB529F3A for ; Fri, 23 Sep 2016 08:15:53 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S965418AbcIWIPu (ORCPT ); Fri, 23 Sep 2016 04:15:50 -0400 Received: from mailout4.w1.samsung.com ([210.118.77.14]:53476 "EHLO mailout4.w1.samsung.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S965414AbcIWIPp (ORCPT ); Fri, 23 Sep 2016 04:15:45 -0400 Received: from eucas1p1.samsung.com (unknown [182.198.249.206]) by mailout4.w1.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTP id <0ODY00EG36Y69020@mailout4.w1.samsung.com> for linux-samsung-soc@vger.kernel.org; Fri, 23 Sep 2016 09:15:42 +0100 (BST) Received: from eusmges4.samsung.com (unknown [203.254.199.244]) by eucas1p1.samsung.com (KnoxPortal) with ESMTP id 20160923081542eucas1p1a2cb4575d1c65d5a30f6a928ec7db7e9~25cBQjzyy0827808278eucas1p1N; Fri, 23 Sep 2016 08:15:42 +0000 (GMT) Received: from eucas1p2.samsung.com ( [182.198.249.207]) by eusmges4.samsung.com (EUCPMTA) with SMTP id 31.DB.28332.DA4E4E75; Fri, 23 Sep 2016 09:15:41 +0100 (BST) Received: from eusmgms2.samsung.com (unknown [182.198.249.180]) by eucas1p2.samsung.com (KnoxPortal) with ESMTP id 20160923081541eucas1p277bce738f62966250216ae1da9accc81~25cAfjTdM0226102261eucas1p27; Fri, 23 Sep 2016 08:15:41 +0000 (GMT) X-AuditID: cbfec7f4-f791c6d000006eac-d0-57e4e4ad54f4 Received: from eusync3.samsung.com ( [203.254.199.213]) by eusmgms2.samsung.com (EUCPMTA) with SMTP id 82.65.10494.084E4E75; Fri, 23 Sep 2016 09:14:56 +0100 (BST) Received: from AMDC2768.digital.local ([106.116.147.88]) by eusync3.samsung.com (Oracle Communications Messaging Server 7.0.5.31.0 64bit (built May 5 2014)) with ESMTPA id <0ODY00KL06XWOSA0@eusync3.samsung.com>; Fri, 23 Sep 2016 09:15:41 +0100 (BST) From: Andrzej Hajda To: Inki Dae Cc: Andrzej Hajda , Bartlomiej Zolnierkiewicz , Marek Szyprowski , dri-devel@lists.freedesktop.org, linux-samsung-soc@vger.kernel.org, Daniel Vetter , Tobias Jakobi Subject: [PATCH 1/2] drm/exynos/vidi: use timer for vblanks instead of sleeping worker Date: Fri, 23 Sep 2016 10:15:23 +0200 Message-id: <1474618524-8916-2-git-send-email-a.hajda@samsung.com> X-Mailer: git-send-email 2.7.4 In-reply-to: <1474618524-8916-1-git-send-email-a.hajda@samsung.com> X-Brightmail-Tracker: H4sIAAAAAAAAA+NgFrrAIsWRmVeSWpSXmKPExsWy7djP87prnzwJN5j43czi1rpzrBYbZ6xn tVj48C6zxZWv79ksJt2fwGIx4/w+Jou1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ICJhLPdt5hhrDFJC7cW8/WxcjF ISSwhFHi9uzfLBBOE5PEzvn72UGq2AQ0Jf5uvskGYosIKEus2tfODlLELLCWSWJWywtGkISw QITEq9dvwRpYBFQldvxZygJi8wo4STx8do4dYp2cxM1znWCrOQWcJbZ0fALrFQKqOXvtMfME Rt4FjAyrGEVSS4tz03OLjfSKE3OLS/PS9ZLzczcxAsN627GfW3Ywdr0LPsQowMGoxMP74PHj cCHWxLLiytxDjBIczEoivLMePgkX4k1JrKxKLcqPLyrNSS0+xGgKdNREZinR5HxgzOWVxBua GJpbGhoZW1iYGxkpifNO/XAlXEggPbEkNTs1tSC1CKaPiYNTqoHRR/rRV2bdhC/V7Mw8W55q FF14OX1d4aHzb9vnqXuoep+7wZ788YfS/3bxVQcnzFXXlZ7i+d3gy4TGq0nnszqnLG6oUUk/ 5uvs8G5F6+bmwMLCuT3u/3jW7vM49mLzZpaXfh/dFz+XE1G89eGH7JbgzPKvTxmvLNjqIq+3 Unay3NytvxSdan6dUmIpzkg01GIuKk4EALBV1WeBAgAA X-MTR: 20000000000000000@CPGS X-CMS-MailID: 20160923081541eucas1p277bce738f62966250216ae1da9accc81 X-Msg-Generator: CA X-Sender-IP: 182.198.249.180 X-Local-Sender: =?UTF-8?B?QW5kcnplaiBIYWpkYRtTUlBPTC1LZXJuZWwgKFRQKRvsgrw=?= =?UTF-8?B?7ISx7KCE7J6QG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Global-Sender: =?UTF-8?B?QW5kcnplaiBIYWpkYRtTUlBPTC1LZXJuZWwgKFRQKRtTYW1z?= =?UTF-8?B?dW5nIEVsZWN0cm9uaWNzG1NlbmlvciBTb2Z0d2FyZSBFbmdpbmVlcg==?= X-Sender-Code: =?UTF-8?B?QzEwG0VIURtDMTBDRDAyQ0QwMjczOTI=?= CMS-TYPE: 201P X-HopCount: 7 X-CMS-RootMailID: 20160923081541eucas1p277bce738f62966250216ae1da9accc81 X-RootMTR: 20160923081541eucas1p277bce738f62966250216ae1da9accc81 References: <1474618524-8916-1-git-send-email-a.hajda@samsung.com> Sender: linux-samsung-soc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-samsung-soc@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP VIDI driver uses fake vblank handler to generate vblank events. It was implemented using worker which slept for vblank time, additionally it did not work if there were no page flips. The patch replaces it with timer, uses drm_crtc_vblank_(on|off) helpers to manage it and fixes behavior for non-page-flip cases. This change allows further improvements of vblank in exynos-drm framework. Signed-off-by: Andrzej Hajda Reviewed-by: Gustavo Padovan --- drivers/gpu/drm/exynos/exynos_drm_vidi.c | 66 ++++++++++---------------------- 1 file changed, 20 insertions(+), 46 deletions(-) diff --git a/drivers/gpu/drm/exynos/exynos_drm_vidi.c b/drivers/gpu/drm/exynos/exynos_drm_vidi.c index e8f6c92..a91dad6 100644 --- a/drivers/gpu/drm/exynos/exynos_drm_vidi.c +++ b/drivers/gpu/drm/exynos/exynos_drm_vidi.c @@ -15,6 +15,7 @@ #include #include #include +#include #include @@ -28,6 +29,9 @@ #include "exynos_drm_plane.h" #include "exynos_drm_vidi.h" +/* VIDI uses fixed refresh rate of 50Hz */ +#define VIDI_REFRESH_TIME (1000 / 50) + /* vidi has totally three virtual windows. */ #define WINDOWS_NR 3 @@ -43,12 +47,9 @@ struct vidi_context { struct exynos_drm_plane planes[WINDOWS_NR]; struct edid *raw_edid; unsigned int clkdiv; - unsigned long irq_flags; unsigned int connected; - bool vblank_on; bool suspended; - bool direct_vblank; - struct work_struct work; + struct timer_list timer; struct mutex lock; int pipe; }; @@ -102,30 +103,14 @@ static int vidi_enable_vblank(struct exynos_drm_crtc *crtc) if (ctx->suspended) return -EPERM; - if (!test_and_set_bit(0, &ctx->irq_flags)) - ctx->vblank_on = true; - - ctx->direct_vblank = true; - - /* - * in case of page flip request, vidi_finish_pageflip function - * will not be called because direct_vblank is true and then - * that function will be called by crtc_ops->update_plane callback - */ - schedule_work(&ctx->work); + mod_timer(&ctx->timer, + jiffies + msecs_to_jiffies(VIDI_REFRESH_TIME) - 1); return 0; } static void vidi_disable_vblank(struct exynos_drm_crtc *crtc) { - struct vidi_context *ctx = crtc->ctx; - - if (ctx->suspended) - return; - - if (test_and_clear_bit(0, &ctx->irq_flags)) - ctx->vblank_on = false; } static void vidi_update_plane(struct exynos_drm_crtc *crtc, @@ -140,9 +125,6 @@ static void vidi_update_plane(struct exynos_drm_crtc *crtc, addr = exynos_drm_fb_dma_addr(state->fb, 0); DRM_DEBUG_KMS("dma_addr = %pad\n", &addr); - - if (ctx->vblank_on) - schedule_work(&ctx->work); } static void vidi_enable(struct exynos_drm_crtc *crtc) @@ -153,17 +135,17 @@ static void vidi_enable(struct exynos_drm_crtc *crtc) ctx->suspended = false; - /* if vblank was enabled status, enable it again. */ - if (test_and_clear_bit(0, &ctx->irq_flags)) - vidi_enable_vblank(ctx->crtc); - mutex_unlock(&ctx->lock); + + drm_crtc_vblank_on(&crtc->base); } static void vidi_disable(struct exynos_drm_crtc *crtc) { struct vidi_context *ctx = crtc->ctx; + drm_crtc_vblank_off(&crtc->base); + mutex_lock(&ctx->lock); ctx->suspended = true; @@ -190,28 +172,17 @@ static const struct exynos_drm_crtc_ops vidi_crtc_ops = { .update_plane = vidi_update_plane, }; -static void vidi_fake_vblank_handler(struct work_struct *work) +static void vidi_fake_vblank_timer(unsigned long arg) { - struct vidi_context *ctx = container_of(work, struct vidi_context, - work); + struct vidi_context *ctx = (void *)arg; int win; if (ctx->pipe < 0) return; - /* refresh rate is about 50Hz. */ - usleep_range(16000, 20000); - - mutex_lock(&ctx->lock); - - if (ctx->direct_vblank) { - drm_crtc_handle_vblank(&ctx->crtc->base); - ctx->direct_vblank = false; - mutex_unlock(&ctx->lock); - return; - } - - mutex_unlock(&ctx->lock); + if (drm_crtc_handle_vblank(&ctx->crtc->base)) + mod_timer(&ctx->timer, + jiffies + msecs_to_jiffies(VIDI_REFRESH_TIME) - 1); for (win = 0 ; win < WINDOWS_NR ; win++) { struct exynos_drm_plane *plane = &ctx->planes[win]; @@ -489,6 +460,9 @@ static int vidi_bind(struct device *dev, struct device *master, void *data) static void vidi_unbind(struct device *dev, struct device *master, void *data) { + struct vidi_context *ctx = dev_get_drvdata(dev); + + del_timer_sync(&ctx->timer); } static const struct component_ops vidi_component_ops = { @@ -507,7 +481,7 @@ static int vidi_probe(struct platform_device *pdev) ctx->pdev = pdev; - INIT_WORK(&ctx->work, vidi_fake_vblank_handler); + setup_timer(&ctx->timer, vidi_fake_vblank_timer, (unsigned long)ctx); mutex_init(&ctx->lock);