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: 9243555 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 A9BC0607D3 for ; Fri, 22 Jul 2016 13:23:09 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9AB4227D76 for ; Fri, 22 Jul 2016 13:23:09 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8EFDD27FA3; Fri, 22 Jul 2016 13:23:09 +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=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2A5EC27D76 for ; Fri, 22 Jul 2016 13:23:09 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 131C66EB6E; Fri, 22 Jul 2016 13:22:46 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pa0-f65.google.com (mail-pa0-f65.google.com [209.85.220.65]) by gabe.freedesktop.org (Postfix) with ESMTPS id 547116EAFD for ; Fri, 22 Jul 2016 09:08:05 +0000 (UTC) Received: by mail-pa0-f65.google.com with SMTP id ez1so6664925pab.3 for ; Fri, 22 Jul 2016 02:08:05 -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=MQI3R3uPb4I5czft0CG4X0ni6LTlILpph207HbP6T16LU1P0l3m6HxAIG1GNuWtvjI DjUlpPDMiknK3n/V99SYSfFb0YhEGfERVkKtSFOTT8vh/OmFBUIe8SsVVACvEqwQm0O5 udQJJ8/DIVjA8nbC+2Obp0upxwjgyexCNf0QFmB/t9pxHLXXK/cnAHrZ4wssxyGtoj/g ROwdO5qnUx6hygcpK90g7Bjl/3FCk4Z3bJGVNk9MaDxhLLYmTWDnvwueIFBUndxeQypA cjJUDlhqvs680G7P4swcIi4j9eMYNZL2i4DbR49XfBkGTscHeaElQk/YiS82mGwSqXrj hxVA== X-Gm-Message-State: AEkoousJaX0GM8Em6WbV2jFcvymy83bYchlWMmE6o/JNkRn9+k4nVy/QAZu1mEnOCKlFmA== 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-Mailman-Approved-At: Fri, 22 Jul 2016 13:22:35 +0000 Cc: tixy@linaro.org, typ@rock-chips.com, Lin Huang , linux-rockchip@lists.infradead.org, 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 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" 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;