From patchwork Fri Jul 22 09:07:20 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: huang lin X-Patchwork-Id: 9243307 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 35FBA602F0 for ; Fri, 22 Jul 2016 09:11:28 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 221A6223A4 for ; Fri, 22 Jul 2016 09:11:28 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 16CCA27F93; Fri, 22 Jul 2016 09:11:28 +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=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=unavailable version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.9]) (using TLSv1.2 with cipher AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id B04A4223A4 for ; Fri, 22 Jul 2016 09:11:27 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.85_2 #1 (Red Hat Linux)) id 1bQWT2-00078a-T6; Fri, 22 Jul 2016 09:10:00 +0000 Received: from mail-pa0-f65.google.com ([209.85.220.65]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bQWRT-0005co-LI; Fri, 22 Jul 2016 09:08:25 +0000 Received: by mail-pa0-f65.google.com with SMTP id q2so6686083pap.0; Fri, 22 Jul 2016 02:08:03 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=YrXDjWYzGoEOecaUUnaEPzZOFVrsdtMPlChFJkgHayo=; b=KKignX6Gy8eD5n5SFkl2PIz05iZVVdz5oz0sCsmSXUVQAGIs+sClIiK314nOhSdXGo JiMnf+pV01wMvMuY1dF4IgbKOkt94313xpawbq5ZNgPA//WVTXpslEZ4hVzURM5tgRU4 zJaJEyRMInalMtoIKKVoptNBEBOm3M6tB4ZQ1ofqZMgS1Dq2ojc9st4aO83lfdmmq57m n2embVt8vcdZwy+OoUfDgubVd/aDFSzi8diIrBU1cbwfbLkAs5bMesd6PRzdk9g6owv+ UfKXeTst6qqIS9Mim7uxGshHU51dxJRc1ZpFTxELNF1DFxsQTbRJdmcYg/3xZv2F4ZZ/ F8zQ== X-Gm-Message-State: AEkoouvFaTPRdSIrjBxwCboxoJutpCrHW32EmwpqDMPDkMOtLVJEqv0VHrF0RGGkD3m1oA== X-Received: by 10.67.7.98 with SMTP id db2mr4551741pad.156.1469178483515; Fri, 22 Jul 2016 02:08:03 -0700 (PDT) Received: from localhost.localdomain ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id i137sm18130320pfe.64.2016.07.22.02.07.59 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 22 Jul 2016 02:08:02 -0700 (PDT) From: Lin Huang To: heiko@sntech.de Subject: [PATCH v3 7/7] drm/rockchip: Add dmc notifier in vop driver Date: Fri, 22 Jul 2016 17:07:20 +0800 Message-Id: <1469178440-4668-8-git-send-email-hl@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1469178440-4668-1-git-send-email-hl@rock-chips.com> References: <1469178440-4668-1-git-send-email-hl@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160722_020823_892598_EDFBF538 X-CRM114-Status: GOOD ( 16.36 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: tixy@linaro.org, typ@rock-chips.com, Lin Huang , linux-rockchip@lists.infradead.org, airlied@linux.ie, mturquette@baylibre.com, dbasehore@chromium.org, sboyd@codeaurora.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, dianders@chromium.org, xsf@rock-chips.com, cw00.choi@samsung.com, kyungmin.park@samsung.com, myungjoo.ham@samsung.com, linux-arm-kernel@lists.infradead.org, mark.yao@rock-chips.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP when in ddr frequency scaling process, vop can not do enable or disable operate, since dcf will base on vop vblank time to do frequency scaling and need to get vop irq if there have vop enabled. So need register to dmc notifier, and we can get the dmc status. Signed-off-by: Lin Huang --- Changes in v3: - when do vop eanble/disable, dmc will wait until it finish Changes in v2: - None Changes in v1: - use wait_event instead usleep drivers/gpu/drm/rockchip/rockchip_drm_vop.c | 75 ++++++++++++++++++++++++++--- 1 file changed, 69 insertions(+), 6 deletions(-) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index 6255e5b..4220629 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -31,6 +31,8 @@ #include #include +#include + #include "rockchip_drm_drv.h" #include "rockchip_drm_gem.h" #include "rockchip_drm_fb.h" @@ -120,6 +122,11 @@ struct vop { const struct vop_data *data; + struct notifier_block dmc_nb; + int dmc_in_process; + int vop_switch_status; + wait_queue_head_t wait_dmc_queue; + wait_queue_head_t wait_vop_switch_queue; uint32_t *regsbak; void __iomem *regs; @@ -430,21 +437,56 @@ static void vop_dsp_hold_valid_irq_disable(struct vop *vop) spin_unlock_irqrestore(&vop->irq_lock, flags); } +static int dmc_notify(struct notifier_block *nb, unsigned long event, + void *data) +{ + struct vop *vop = container_of(nb, struct vop, dmc_nb); + + if (event == DMCFREQ_ADJUST) { + + /* + * check if vop in enable or disable process, + * if yes, wait until it finish, use 200ms as + * timeout. + */ + wait_event_timeout(vop->wait_vop_switch_queue, + !vop->vop_switch_status, HZ / 5); + vop->dmc_in_process = 1; + } else if (event == DMCFREQ_FINISH) { + vop->dmc_in_process = 0; + wake_up(&vop->wait_dmc_queue); + } + + return NOTIFY_OK; +} + static void vop_enable(struct drm_crtc *crtc) { struct vop *vop = to_vop(crtc); int ret; + if (vop->is_enabled) + return; + + /* + * if in dmc scaling frequency process, wait until it finish + * use 100ms as timeout time. + */ + wait_event_timeout(vop->wait_dmc_queue, + !vop->dmc_in_process, HZ / 5); + + vop->vop_switch_status = 1; + ret = pm_runtime_get_sync(vop->dev); if (ret < 0) { dev_err(vop->dev, "failed to get pm runtime: %d\n", ret); - return; + goto err; } ret = clk_enable(vop->hclk); if (ret < 0) { dev_err(vop->dev, "failed to enable hclk - %d\n", ret); - return; + goto err; } ret = clk_enable(vop->dclk); @@ -458,7 +500,6 @@ static void vop_enable(struct drm_crtc *crtc) dev_err(vop->dev, "failed to enable aclk - %d\n", ret); goto err_disable_dclk; } - /* * Slave iommu shares power, irq and clock with vop. It was associated * automatically with this master device via common driver code. @@ -486,7 +527,9 @@ static void vop_enable(struct drm_crtc *crtc) enable_irq(vop->irq); drm_crtc_vblank_on(crtc); - + vop->vop_switch_status = 0; + wake_up(&vop->wait_vop_switch_queue); + rockchip_dmc_get(&vop->dmc_nb); return; err_disable_aclk: @@ -495,6 +538,10 @@ err_disable_dclk: clk_disable(vop->dclk); err_disable_hclk: clk_disable(vop->hclk); +err: + vop->vop_switch_status = 0; + wake_up(&vop->wait_vop_switch_queue); + return; } static void vop_crtc_disable(struct drm_crtc *crtc) @@ -505,6 +552,15 @@ static void vop_crtc_disable(struct drm_crtc *crtc) WARN_ON(vop->event); /* + * if in dmc scaling frequency process, wait until it finish + * use 100ms as timeout time. + */ + wait_event_timeout(vop->wait_dmc_queue, + !vop->dmc_in_process, HZ / 5); + + vop->vop_switch_status = 1; + + /* * We need to make sure that all windows are disabled before we * disable that crtc. Otherwise we might try to scan from a destroyed * buffer later. @@ -517,7 +573,6 @@ static void vop_crtc_disable(struct drm_crtc *crtc) VOP_WIN_SET(vop, win, enable, 0); spin_unlock(&vop->reg_lock); } - drm_crtc_vblank_off(crtc); /* @@ -548,7 +603,6 @@ static void vop_crtc_disable(struct drm_crtc *crtc) * vop standby complete, so iommu detach is safe. */ rockchip_drm_dma_detach_device(vop->drm_dev, vop->dev); - clk_disable(vop->dclk); clk_disable(vop->aclk); clk_disable(vop->hclk); @@ -561,6 +615,9 @@ static void vop_crtc_disable(struct drm_crtc *crtc) crtc->state->event = NULL; } + vop->vop_switch_status = 0; + wake_up(&vop->wait_vop_switch_queue); + rockchip_dmc_put(&vop->dmc_nb); } static void vop_plane_destroy(struct drm_plane *plane) @@ -1247,6 +1304,7 @@ static int vop_create_crtc(struct vop *vop) goto err_cleanup_crtc; } + vop->dmc_nb.notifier_call = dmc_notify; init_completion(&vop->dsp_hold_completion); init_completion(&vop->wait_update_complete); crtc->port = port; @@ -1468,6 +1526,11 @@ static int vop_bind(struct device *dev, struct device *master, void *data) /* IRQ is initially disabled; it gets enabled in power_on */ disable_irq(vop->irq); + init_waitqueue_head(&vop->wait_vop_switch_queue); + vop->vop_switch_status = 0; + init_waitqueue_head(&vop->wait_dmc_queue); + vop->dmc_in_process = 0; + ret = vop_create_crtc(vop); if (ret) return ret;