From patchwork Wed Aug 17 01:11:15 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 9285065 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 6E9AF600CB for ; Wed, 17 Aug 2016 01:11:35 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 6095B287C7 for ; Wed, 17 Aug 2016 01:11:35 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 5592C287CC; Wed, 17 Aug 2016 01:11:35 +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.1 required=2.0 tests=BAYES_00,DKIM_SIGNED, RCVD_IN_DNSWL_MED,T_DKIM_INVALID autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 0B5CC287C7 for ; Wed, 17 Aug 2016 01:11:35 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 578156E785; Wed, 17 Aug 2016 01:11:33 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-pa0-x236.google.com (mail-pa0-x236.google.com [IPv6:2607:f8b0:400e:c03::236]) by gabe.freedesktop.org (Postfix) with ESMTPS id 571326E781 for ; Wed, 17 Aug 2016 01:11:30 +0000 (UTC) Received: by mail-pa0-x236.google.com with SMTP id i5so31330725pat.2 for ; Tue, 16 Aug 2016 18:11:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=chromium.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=6G8LkUyl6pRhHi5rs7WZHVmnTanSJb+XGoNgNpUoUjo=; b=I5ury0xuPDxL5lOvMB6oRxmLdWFHv/om+0CQCVIN2me6Oz0DX7FNOdVwFK04s/zYWh UFbOuaFKZV+SSJgH44byK1BdqJvFXisOYniaVO+h3KDx0mcGh2enM80Dr+4wsequFCd0 o0zQQQmMeFYr7DbcJItNM5G0PjxmcpUyVdw6Y= 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=6G8LkUyl6pRhHi5rs7WZHVmnTanSJb+XGoNgNpUoUjo=; b=Bj9E+9I3mOY93O2XVZusWhspNXh4TpM+38v+BCG4nO18i0N9mgsKoEOhkCOSwhdXZN LHiuUo12saXSVEhmOsrCg0kRdI48ou3wKITBo/BA7Dk1CO4tMMWlP/L35pRIgOfDPn42 ytP/oIUGtsnJpCFX540+q1s87bA4ymmDJqv0/02JdW3Pr94gGkCW84sKHfYADQGIykgj dcUmaD2CMyH+Yi1ZwXfas7id3L2OWu/qIibwFc0TAhuz/NYjVdtPsMmfnTACPiwXDWRu yQuIY56Rw4n6mvShzy7D5sMjtP9CAnHG3YB7zvK8+kg1s/+uzaZ+lE7OXEoF7ks8KYC+ TRng== X-Gm-Message-State: AEkoouv3Ub/Dp4D4mlHruB/hW6h06K6LuHhImYRNqgGku7g355jKTNniDsGI+LnMtR7ywyok X-Received: by 10.66.10.168 with SMTP id j8mr69295497pab.3.1471396289966; Tue, 16 Aug 2016 18:11:29 -0700 (PDT) Received: from seanpaul0.corp.google.com ([172.22.162.59]) by smtp.gmail.com with ESMTPSA id f6sm42170827pfa.17.2016.08.16.18.11.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 16 Aug 2016 18:11:29 -0700 (PDT) From: Sean Paul To: mark.yao@rock-chips.com, dri-devel@lists.freedesktop.org, ykk@rock-chips.com Subject: [PATCH v2 5/6] drm/rockchip: Improve analogix-dp psr handling Date: Tue, 16 Aug 2016 18:11:15 -0700 Message-Id: <1471396276-8222-6-git-send-email-seanpaul@chromium.org> X-Mailer: git-send-email 2.8.0.rc3.226.g39d4020 In-Reply-To: <1471396276-8222-1-git-send-email-seanpaul@chromium.org> References: <1471396276-8222-1-git-send-email-seanpaul@chromium.org> Cc: marcheu@chromium.org, dianders@chromium.org, linux-rockchip@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 Remove the delayed worker, opting instead for the non-delayed variety. Also introduce a lock to ensure we don't have races with the worker and psr_state. Finally, cancel and wait for the worker to finish when disabling the bridge. Signed-off-by: Sean Paul Reviewed-by: Yakir Yang --- Changes in v2: - Rebased on https://cgit.freedesktop.org/~seanpaul/dogwood/log/?h=for-next drivers/gpu/drm/rockchip/analogix_dp-rockchip.c | 19 ++++++++++++++----- 1 file changed, 14 insertions(+), 5 deletions(-) diff --git a/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c b/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c index d6d0751..439b933 100644 --- a/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c +++ b/drivers/gpu/drm/rockchip/analogix_dp-rockchip.c @@ -42,7 +42,6 @@ #define HIWORD_UPDATE(val, mask) (val | (mask) << 16) -#define PSR_SET_DELAY_TIME msecs_to_jiffies(10) #define PSR_WAIT_LINE_FLAG_TIMEOUT_MS 100 #define to_dp(nm) container_of(nm, struct rockchip_dp_device, nm) @@ -72,7 +71,8 @@ struct rockchip_dp_device { struct regmap *grf; struct reset_control *rst; - struct delayed_work psr_work; + struct work_struct psr_work; + spinlock_t psr_lock; unsigned int psr_state; const struct rockchip_dp_chip_data *data; @@ -83,25 +83,29 @@ struct rockchip_dp_device { static void analogix_dp_psr_set(struct drm_encoder *encoder, bool enabled) { struct rockchip_dp_device *dp = to_dp(encoder); + unsigned long flags; dev_dbg(dp->dev, "%s PSR...\n", enabled ? "Entry" : "Exit"); + spin_lock_irqsave(&dp->psr_lock, flags); if (enabled) dp->psr_state = EDP_VSC_PSR_STATE_ACTIVE; else dp->psr_state = ~EDP_VSC_PSR_STATE_ACTIVE; - schedule_delayed_work(&dp->psr_work, PSR_SET_DELAY_TIME); + schedule_work(&dp->psr_work); + spin_unlock_irqrestore(&dp->psr_lock, flags); } static void analogix_dp_psr_work(struct work_struct *work) { struct rockchip_dp_device *dp = - container_of(work, typeof(*dp), psr_work.work); + container_of(work, typeof(*dp), psr_work); struct drm_crtc *crtc = dp->encoder.crtc; int psr_state = dp->psr_state; int vact_end; int ret; + unsigned long flags; if (!crtc) return; @@ -115,10 +119,12 @@ static void analogix_dp_psr_work(struct work_struct *work) return; } + spin_lock_irqsave(&dp->psr_lock, flags); if (psr_state == EDP_VSC_PSR_STATE_ACTIVE) analogix_dp_enable_psr(dp->dev); else analogix_dp_disable_psr(dp->dev); + spin_unlock_irqrestore(&dp->psr_lock, flags); } static int rockchip_dp_pre_init(struct rockchip_dp_device *dp) @@ -135,6 +141,8 @@ static int rockchip_dp_poweron(struct analogix_dp_plat_data *plat_data) struct rockchip_dp_device *dp = to_dp(plat_data); int ret; + cancel_work_sync(&dp->psr_work); + ret = clk_prepare_enable(dp->pclk); if (ret < 0) { dev_err(dp->dev, "failed to enable pclk %d\n", ret); @@ -390,8 +398,9 @@ static int rockchip_dp_bind(struct device *dev, struct device *master, dp->plat_data.power_off = rockchip_dp_powerdown; dp->plat_data.get_modes = rockchip_dp_get_modes; + spin_lock_init(&dp->psr_lock); dp->psr_state = ~EDP_VSC_PSR_STATE_ACTIVE; - INIT_DELAYED_WORK(&dp->psr_work, analogix_dp_psr_work); + INIT_WORK(&dp->psr_work, analogix_dp_psr_work); rockchip_drm_psr_register(&dp->encoder, analogix_dp_psr_set);