All of lore.kernel.org
 help / color / mirror / Atom feed
From: Sean Paul <seanpaul@chromium.org>
To: mark.yao@rock-chips.com, dri-devel@lists.freedesktop.org,
	ykk@rock-chips.com
Cc: marcheu@chromium.org, dianders@chromium.org,
	linux-rockchip@lists.infradead.org
Subject: [PATCH v2 5/6] drm/rockchip: Improve analogix-dp psr handling
Date: Tue, 16 Aug 2016 18:11:15 -0700	[thread overview]
Message-ID: <1471396276-8222-6-git-send-email-seanpaul@chromium.org> (raw)
In-Reply-To: <1471396276-8222-1-git-send-email-seanpaul@chromium.org>

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 <seanpaul@chromium.org>
---

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);
 
-- 
2.8.0.rc3.226.g39d4020

_______________________________________________
dri-devel mailing list
dri-devel@lists.freedesktop.org
https://lists.freedesktop.org/mailman/listinfo/dri-devel

  parent reply	other threads:[~2016-08-17  1:11 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-08-17  1:11 [PATCH v2 0/6] drm/rockchip: Some patches to update the PSR series Sean Paul
2016-08-17  1:11 ` [PATCH v2 1/6] drm/rockchip: Convert psr_list_mutex to spinlock and use it Sean Paul
2016-08-17  2:29   ` Yakir Yang
2016-08-17  1:11 ` [PATCH v2 2/6] drm/rockchip: Don't use a delayed worker for psr state changes Sean Paul
2016-08-17  2:31   ` Yakir Yang
2016-08-17  1:11 ` [PATCH v2 3/6] drm/rockchip: Use a spinlock to protect psr state Sean Paul
2016-08-17  2:33   ` Yakir Yang
2016-08-17  1:11 ` [PATCH v2 4/6] drm/rockchip: A couple small fixes to psr Sean Paul
2016-08-17  2:34   ` Yakir Yang
2016-08-17  1:11 ` Sean Paul [this message]
2016-08-17  2:35   ` [PATCH v2 5/6] drm/rockchip: Improve analogix-dp psr handling Yakir Yang
2016-08-17  1:11 ` [PATCH v2 6/6] drm/rockchip: Enable vblank without event Sean Paul
2016-08-17  3:27   ` Yakir Yang
2016-08-17  2:41 ` [PATCH v2 0/6] drm/rockchip: Some patches to update the PSR series Yakir Yang
2016-08-17  2:45   ` Sean Paul
2016-08-17  3:20     ` Yakir Yang
2016-08-17  2:45   ` Yakir Yang

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1471396276-8222-6-git-send-email-seanpaul@chromium.org \
    --to=seanpaul@chromium.org \
    --cc=dianders@chromium.org \
    --cc=dri-devel@lists.freedesktop.org \
    --cc=linux-rockchip@lists.infradead.org \
    --cc=marcheu@chromium.org \
    --cc=mark.yao@rock-chips.com \
    --cc=ykk@rock-chips.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.