From patchwork Thu Sep 1 22:31:25 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: huang lin X-Patchwork-Id: 9310079 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 40245607D6 for ; Thu, 1 Sep 2016 22:42:07 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id EB80329551 for ; Thu, 1 Sep 2016 22:42:06 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id DFF2E29564; Thu, 1 Sep 2016 22:42:06 +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 676BF29551 for ; Thu, 1 Sep 2016 22:42:06 +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 1bfaer-00073q-7R; Thu, 01 Sep 2016 22:40:29 +0000 Received: from mail-pa0-f67.google.com ([209.85.220.67]) by bombadil.infradead.org with esmtps (Exim 4.85_2 #1 (Red Hat Linux)) id 1bfaWZ-0005zO-3M; Thu, 01 Sep 2016 22:32:13 +0000 Received: by mail-pa0-f67.google.com with SMTP id ez1so4708962pab.3; Thu, 01 Sep 2016 15:31:36 -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=bBQ6gHnfxTKUh/4VAMnwY8tBNrNU0wh9qpHG0/Wn4Ms=; b=WVgpWGzldoa6khUwWIOJPzrtti767S6S7URO9l8F+mUKX1zkWp+BiFBmZAHW0QgfmQ 5koiSSLwADrlbRQFgwYrR3+XZUiXzgRl6n6jLSrx+C+Tpz2JOF4ysjOz7Bp4yJDuLszc kpsJ2CZyAcwlESKupm3g2Eq7nEWJxEZzdFd+jlOclhRED/rlq8dLSK+h+HlK2rbrQCl1 Wfkw4TrQl6BdAQ6jVUZ45Rld9T+KNFuN0IDepXfH3Ip9euRO2/AK+EmSkIQgEpo8VBCF 4TlwXdunhS6BoGQAXAJeba1XAeI2KbaXiGIbdlzqiTQj7SaEA3snwn6jVRGXQDznEra8 kduQ== X-Gm-Message-State: AE9vXwMMmdXFQzDxI5DVQKoBwxNyrzNRMWrll7grWbHWWOpDnXQ630HsC2I+FzHvP5SIdQ== X-Received: by 10.66.50.164 with SMTP id d4mr30542871pao.96.1472769095557; Thu, 01 Sep 2016 15:31:35 -0700 (PDT) Received: from hl-ThinkPad-X240.corp.google.com ([172.22.52.196]) by smtp.gmail.com with ESMTPSA id k9sm9897400pfj.63.2016.09.01.15.31.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 01 Sep 2016 15:31:35 -0700 (PDT) From: Lin Huang To: heiko@sntech.de Subject: [PATCH 5/5] drm/rockchip: Add dmc notifier in vop driver Date: Fri, 2 Sep 2016 06:31:25 +0800 Message-Id: <1472769085-20715-6-git-send-email-hl@rock-chips.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1472769085-20715-1-git-send-email-hl@rock-chips.com> References: <1472769085-20715-1-git-send-email-hl@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20160901_153155_769098_A7C57F3B X-CRM114-Status: GOOD ( 20.28 ) 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, mark.rutland@arm.com, devicetree@vger.kernel.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, cw00.choi@samsung.com, kyungmin.park@samsung.com, myungjoo.ham@samsung.com, sudeep.holla@arm.com, linux-pm@vger.kernel.org, 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 operation, since in dcf we check vop clock to see whether vop work. If vop work, dcf do ddr frequency scaling when vop in vblank status, and we need to read vop register to check whether vop go into vblank status. If vop not work, dcf can do ddr frequency any time. So when do ddr frequency scaling, you disabled or enable vop, there may two bad thing happen: 1, the panel flicker(when vop from disable status change to enable). 2, kernel hang (when vop from enable status change to disable, dcf need to read vblank status, but if you disable vop clock, it can not get the status, it will lead soc dead) So we need register to devfreq notifier, and we can get the dmc status. Also, when there have two vop enabled, we need to disable dmc, since dcf only base on one vop vblank time, so the other panel will flicker when do ddr frequency scaling. Signed-off-by: Lin Huang Reviewed-by: Chanwoo Choi --- Changes in v8: - None Changes in v7: - None Changes in v6: - fix a build error Changes in v5: - improve some nits Changes in v4: - register notifier to devfreq_register_notifier - use DEVFREQ_PRECHANGE and DEVFREQ_POSTCHANGE to get dmc status - when two vop enable, disable dmc - when two vop back to one vop, enable dmc 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 | 116 ++++++++++++++++++++++++++++ 1 file changed, 116 insertions(+) diff --git a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c index efbc41a..a73f3aa 100644 --- a/drivers/gpu/drm/rockchip/rockchip_drm_vop.c +++ b/drivers/gpu/drm/rockchip/rockchip_drm_vop.c @@ -19,6 +19,8 @@ #include #include +#include +#include #include #include #include @@ -118,6 +120,13 @@ struct vop { const struct vop_data *data; + struct devfreq *devfreq; + struct devfreq_event_dev *devfreq_event_dev; + 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; @@ -428,11 +437,47 @@ 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 == DEVFREQ_PRECHANGE) { + /* + * check if vop in enable or disable process, + * if yes, wait until it finishes, use 200ms as + * timeout. + */ + if (!wait_event_timeout(vop->wait_vop_switch_queue, + !vop->vop_switch_status, HZ / 5)) + dev_warn(vop->dev, + "Timeout waiting for vop swtich status\n"); + vop->dmc_in_process = 1; + } else if (event == DEVFREQ_POSTCHANGE) { + vop->dmc_in_process = 0; + wake_up(&vop->wait_dmc_queue); + } + + return NOTIFY_OK; +} + static int vop_enable(struct drm_crtc *crtc) { struct vop *vop = to_vop(crtc); + int num_enabled_crtc = 0; int ret; + /* + * if in dmc scaling frequency process, wait until it finishes + * use 200ms as timeout time. + */ + if (!wait_event_timeout(vop->wait_dmc_queue, + !vop->dmc_in_process, HZ / 5)) + dev_warn(vop->dev, + "Timeout waiting for dmc when vop enable\n"); + + 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); @@ -479,6 +524,21 @@ static int vop_enable(struct drm_crtc *crtc) drm_crtc_vblank_on(crtc); + vop->vop_switch_status = 0; + wake_up(&vop->wait_vop_switch_queue); + + /* check how many VOPs in use now */ + drm_for_each_crtc(crtc, vop->drm_dev) { + if (crtc->state->enable) + num_enabled_crtc++; + } + + /* if enable two vop, need to disable dmc */ + if ((num_enabled_crtc > 1) && vop->devfreq) { + if (vop->devfreq_event_dev) + devfreq_event_disable_edev(vop->devfreq_event_dev); + devfreq_suspend_device(vop->devfreq); + } return 0; err_disable_aclk: @@ -489,17 +549,31 @@ err_disable_hclk: clk_disable(vop->hclk); err_put_pm_runtime: pm_runtime_put_sync(vop->dev); + vop->vop_switch_status = 0; + wake_up(&vop->wait_vop_switch_queue); return ret; } static void vop_crtc_disable(struct drm_crtc *crtc) { struct vop *vop = to_vop(crtc); + int num_enabled_crtc = 0; int i; WARN_ON(vop->event); /* + * if in dmc scaling frequency process, wait until it finish + * use 200ms as timeout time. + */ + if (!wait_event_timeout(vop->wait_dmc_queue, + !vop->dmc_in_process, HZ / 5)) + dev_warn(vop->dev, + "Timeout waiting for dmc when vop disable\n"); + + 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. @@ -555,6 +629,24 @@ static void vop_crtc_disable(struct drm_crtc *crtc) spin_unlock_irq(&crtc->dev->event_lock); crtc->state->event = NULL; + + vop->vop_switch_status = 0; + wake_up(&vop->wait_vop_switch_queue); + + /* check how many VOPs in use now */ + drm_for_each_crtc(crtc, vop->drm_dev) { + if (crtc->state->enable) + num_enabled_crtc++; + } + + /* + * if num_enabled_crtc = 1 now, it means 2 vop enabled + * change to 1 vop enabled need to enable dmc again. + */ + if ((num_enabled_crtc == 1) && vop->devfreq) { + if (vop->devfreq_event_dev) + devfreq_event_enable_edev(vop->devfreq_event_dev); + devfreq_resume_device(vop->devfreq); } } @@ -1413,6 +1505,8 @@ static int vop_bind(struct device *dev, struct device *master, void *data) struct drm_device *drm_dev = data; struct vop *vop; struct resource *res; + struct devfreq *devfreq; + struct devfreq_event_dev *event_dev; size_t alloc_size; int ret, irq; @@ -1474,6 +1568,28 @@ static int vop_bind(struct device *dev, struct device *master, void *data) return ret; pm_runtime_enable(&pdev->dev); + + 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; + + devfreq = devfreq_get_devfreq_by_phandle(dev, 0); + if (IS_ERR(devfreq)) + goto out; + + vop->devfreq = devfreq; + vop->dmc_nb.notifier_call = dmc_notify; + devfreq_register_notifier(vop->devfreq, &vop->dmc_nb, + DEVFREQ_TRANSITION_NOTIFIER); + + event_dev = devfreq_event_get_edev_by_phandle(vop->devfreq->dev.parent, + 0); + if (IS_ERR(event_dev)) + goto out; + + vop->devfreq_event_dev = event_dev; +out: return 0; }