Commit 6c836d96 authored by Sean Paul's avatar Sean Paul

drm/rockchip: Use the helpers for PSR

Instead of rolling our own implementation for tracking when PSR should
be [in]active, use the new self refresh helpers to do the heavy lifting.

Changes in v2:
- updated to reflect changes made in the helpers
Changes in v3:
- use the new atomic hooks to inspect crtc state instead of needing conn state (Daniel)
Changes in v4:
- Use Laurent's get_new_connector_for_encoder helper (Daniel)
- Exit vop disable early if it's already off
Changes in v5:
- Rebase on latest drm-misc-next
- Resolve conflict with s/edp_vsc_psr/dp_sdp/ rename
- Resolve conflict with drm_atomic.h header inclusion

Link to v1: https://patchwork.freedesktop.org/patch/msgid/20190228210939.83386-4-sean@poorly.run
Link to v2: https://patchwork.freedesktop.org/patch/msgid/20190326204509.96515-3-sean@poorly.run
Link to v3: https://patchwork.freedesktop.org/patch/msgid/20190502194956.218441-9-sean@poorly.run
Link to v4: https://patchwork.freedesktop.org/patch/msgid/20190508160920.144739-9-sean@poorly.run

Cc: Zain Wang <wzz@rock-chips.com>
Cc: Tomasz Figa <tfiga@chromium.org>
Cc: Daniel Vetter <daniel@ffwll.ch>
Cc: Laurent Pinchart <laurent.pinchart@ideasonboard.com>
Tested-by: default avatarHeiko Stuebner <heiko@sntech.de>
Reviewed-by: default avatarHeiko Stuebner <heiko@sntech.de>
[seanpaul resolved some conflicts with drmP.h work and Helen's async fixes]
Signed-off-by: default avatarSean Paul <seanpaul@chromium.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20190611160844.257498-9-sean@poorly.run
parent ad309284
...@@ -171,8 +171,8 @@ struct analogix_dp_device { ...@@ -171,8 +171,8 @@ struct analogix_dp_device {
int dpms_mode; int dpms_mode;
struct gpio_desc *hpd_gpiod; struct gpio_desc *hpd_gpiod;
bool force_hpd; bool force_hpd;
bool psr_enable;
bool fast_train_enable; bool fast_train_enable;
bool psr_supported;
struct mutex panel_lock; struct mutex panel_lock;
bool panel_is_modeset; bool panel_is_modeset;
......
...@@ -4,8 +4,7 @@ ...@@ -4,8 +4,7 @@
# Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher. # Direct Rendering Infrastructure (DRI) in XFree86 4.1.0 and higher.
rockchipdrm-y := rockchip_drm_drv.o rockchip_drm_fb.o \ rockchipdrm-y := rockchip_drm_drv.o rockchip_drm_fb.o \
rockchip_drm_gem.o rockchip_drm_psr.o \ rockchip_drm_gem.o rockchip_drm_vop.o rockchip_vop_reg.o
rockchip_drm_vop.o rockchip_vop_reg.o
rockchipdrm-$(CONFIG_DRM_FBDEV_EMULATION) += rockchip_drm_fbdev.o rockchipdrm-$(CONFIG_DRM_FBDEV_EMULATION) += rockchip_drm_fbdev.o
rockchipdrm-$(CONFIG_ROCKCHIP_ANALOGIX_DP) += analogix_dp-rockchip.o rockchipdrm-$(CONFIG_ROCKCHIP_ANALOGIX_DP) += analogix_dp-rockchip.o
......
...@@ -19,6 +19,8 @@ ...@@ -19,6 +19,8 @@
#include <video/of_videomode.h> #include <video/of_videomode.h>
#include <video/videomode.h> #include <video/videomode.h>
#include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h>
#include <drm/bridge/analogix_dp.h> #include <drm/bridge/analogix_dp.h>
#include <drm/drm_dp_helper.h> #include <drm/drm_dp_helper.h>
#include <drm/drm_of.h> #include <drm/drm_of.h>
...@@ -26,7 +28,6 @@ ...@@ -26,7 +28,6 @@
#include <drm/drm_probe_helper.h> #include <drm/drm_probe_helper.h>
#include "rockchip_drm_drv.h" #include "rockchip_drm_drv.h"
#include "rockchip_drm_psr.h"
#include "rockchip_drm_vop.h" #include "rockchip_drm_vop.h"
#define RK3288_GRF_SOC_CON6 0x25c #define RK3288_GRF_SOC_CON6 0x25c
...@@ -71,29 +72,6 @@ struct rockchip_dp_device { ...@@ -71,29 +72,6 @@ struct rockchip_dp_device {
struct analogix_dp_plat_data plat_data; struct analogix_dp_plat_data plat_data;
}; };
static int analogix_dp_psr_set(struct drm_encoder *encoder, bool enabled)
{
struct rockchip_dp_device *dp = to_dp(encoder);
int ret;
if (!analogix_dp_psr_enabled(dp->adp))
return 0;
DRM_DEV_DEBUG(dp->dev, "%s PSR...\n", enabled ? "Entry" : "Exit");
ret = rockchip_drm_wait_vact_end(dp->encoder.crtc,
PSR_WAIT_LINE_FLAG_TIMEOUT_MS);
if (ret) {
DRM_DEV_ERROR(dp->dev, "line flag interrupt did not arrive\n");
return -ETIMEDOUT;
}
if (enabled)
return analogix_dp_enable_psr(dp->adp);
else
return analogix_dp_disable_psr(dp->adp);
}
static int rockchip_dp_pre_init(struct rockchip_dp_device *dp) static int rockchip_dp_pre_init(struct rockchip_dp_device *dp)
{ {
reset_control_assert(dp->rst); reset_control_assert(dp->rst);
...@@ -124,21 +102,9 @@ static int rockchip_dp_poweron_start(struct analogix_dp_plat_data *plat_data) ...@@ -124,21 +102,9 @@ static int rockchip_dp_poweron_start(struct analogix_dp_plat_data *plat_data)
return ret; return ret;
} }
static int rockchip_dp_poweron_end(struct analogix_dp_plat_data *plat_data)
{
struct rockchip_dp_device *dp = to_dp(plat_data);
return rockchip_drm_psr_inhibit_put(&dp->encoder);
}
static int rockchip_dp_powerdown(struct analogix_dp_plat_data *plat_data) static int rockchip_dp_powerdown(struct analogix_dp_plat_data *plat_data)
{ {
struct rockchip_dp_device *dp = to_dp(plat_data); struct rockchip_dp_device *dp = to_dp(plat_data);
int ret;
ret = rockchip_drm_psr_inhibit_get(&dp->encoder);
if (ret != 0)
return ret;
clk_disable_unprepare(dp->pclk); clk_disable_unprepare(dp->pclk);
...@@ -178,12 +144,42 @@ static void rockchip_dp_drm_encoder_mode_set(struct drm_encoder *encoder, ...@@ -178,12 +144,42 @@ static void rockchip_dp_drm_encoder_mode_set(struct drm_encoder *encoder,
/* do nothing */ /* do nothing */
} }
static void rockchip_dp_drm_encoder_enable(struct drm_encoder *encoder) static
struct drm_crtc *rockchip_dp_drm_get_new_crtc(struct drm_encoder *encoder,
struct drm_atomic_state *state)
{
struct drm_connector *connector;
struct drm_connector_state *conn_state;
connector = drm_atomic_get_new_connector_for_encoder(state, encoder);
if (!connector)
return NULL;
conn_state = drm_atomic_get_new_connector_state(state, connector);
if (!conn_state)
return NULL;
return conn_state->crtc;
}
static void rockchip_dp_drm_encoder_enable(struct drm_encoder *encoder,
struct drm_atomic_state *state)
{ {
struct rockchip_dp_device *dp = to_dp(encoder); struct rockchip_dp_device *dp = to_dp(encoder);
struct drm_crtc *crtc;
struct drm_crtc_state *old_crtc_state;
int ret; int ret;
u32 val; u32 val;
crtc = rockchip_dp_drm_get_new_crtc(encoder, state);
if (!crtc)
return;
old_crtc_state = drm_atomic_get_old_crtc_state(state, crtc);
/* Coming back from self refresh, nothing to do */
if (old_crtc_state && old_crtc_state->self_refresh_active)
return;
ret = drm_of_encoder_active_endpoint_id(dp->dev->of_node, encoder); ret = drm_of_encoder_active_endpoint_id(dp->dev->of_node, encoder);
if (ret < 0) if (ret < 0)
return; return;
...@@ -208,9 +204,27 @@ static void rockchip_dp_drm_encoder_enable(struct drm_encoder *encoder) ...@@ -208,9 +204,27 @@ static void rockchip_dp_drm_encoder_enable(struct drm_encoder *encoder)
clk_disable_unprepare(dp->grfclk); clk_disable_unprepare(dp->grfclk);
} }
static void rockchip_dp_drm_encoder_nop(struct drm_encoder *encoder) static void rockchip_dp_drm_encoder_disable(struct drm_encoder *encoder,
struct drm_atomic_state *state)
{ {
/* do nothing */ struct rockchip_dp_device *dp = to_dp(encoder);
struct drm_crtc *crtc;
struct drm_crtc_state *new_crtc_state = NULL;
int ret;
crtc = rockchip_dp_drm_get_new_crtc(encoder, state);
/* No crtc means we're doing a full shutdown */
if (!crtc)
return;
new_crtc_state = drm_atomic_get_new_crtc_state(state, crtc);
/* If we're not entering self-refresh, no need to wait for vact */
if (!new_crtc_state || !new_crtc_state->self_refresh_active)
return;
ret = rockchip_drm_wait_vact_end(crtc, PSR_WAIT_LINE_FLAG_TIMEOUT_MS);
if (ret)
DRM_DEV_ERROR(dp->dev, "line flag irq timed out\n");
} }
static int static int
...@@ -239,8 +253,8 @@ rockchip_dp_drm_encoder_atomic_check(struct drm_encoder *encoder, ...@@ -239,8 +253,8 @@ rockchip_dp_drm_encoder_atomic_check(struct drm_encoder *encoder,
static struct drm_encoder_helper_funcs rockchip_dp_encoder_helper_funcs = { static struct drm_encoder_helper_funcs rockchip_dp_encoder_helper_funcs = {
.mode_fixup = rockchip_dp_drm_encoder_mode_fixup, .mode_fixup = rockchip_dp_drm_encoder_mode_fixup,
.mode_set = rockchip_dp_drm_encoder_mode_set, .mode_set = rockchip_dp_drm_encoder_mode_set,
.enable = rockchip_dp_drm_encoder_enable, .atomic_enable = rockchip_dp_drm_encoder_enable,
.disable = rockchip_dp_drm_encoder_nop, .atomic_disable = rockchip_dp_drm_encoder_disable,
.atomic_check = rockchip_dp_drm_encoder_atomic_check, .atomic_check = rockchip_dp_drm_encoder_atomic_check,
}; };
...@@ -332,23 +346,16 @@ static int rockchip_dp_bind(struct device *dev, struct device *master, ...@@ -332,23 +346,16 @@ static int rockchip_dp_bind(struct device *dev, struct device *master,
dp->plat_data.dev_type = dp->data->chip_type; dp->plat_data.dev_type = dp->data->chip_type;
dp->plat_data.power_on_start = rockchip_dp_poweron_start; dp->plat_data.power_on_start = rockchip_dp_poweron_start;
dp->plat_data.power_on_end = rockchip_dp_poweron_end;
dp->plat_data.power_off = rockchip_dp_powerdown; dp->plat_data.power_off = rockchip_dp_powerdown;
dp->plat_data.get_modes = rockchip_dp_get_modes; dp->plat_data.get_modes = rockchip_dp_get_modes;
ret = rockchip_drm_psr_register(&dp->encoder, analogix_dp_psr_set);
if (ret < 0)
goto err_cleanup_encoder;
dp->adp = analogix_dp_bind(dev, dp->drm_dev, &dp->plat_data); dp->adp = analogix_dp_bind(dev, dp->drm_dev, &dp->plat_data);
if (IS_ERR(dp->adp)) { if (IS_ERR(dp->adp)) {
ret = PTR_ERR(dp->adp); ret = PTR_ERR(dp->adp);
goto err_unreg_psr; goto err_cleanup_encoder;
} }
return 0; return 0;
err_unreg_psr:
rockchip_drm_psr_unregister(&dp->encoder);
err_cleanup_encoder: err_cleanup_encoder:
dp->encoder.funcs->destroy(&dp->encoder); dp->encoder.funcs->destroy(&dp->encoder);
return ret; return ret;
...@@ -360,7 +367,6 @@ static void rockchip_dp_unbind(struct device *dev, struct device *master, ...@@ -360,7 +367,6 @@ static void rockchip_dp_unbind(struct device *dev, struct device *master,
struct rockchip_dp_device *dp = dev_get_drvdata(dev); struct rockchip_dp_device *dp = dev_get_drvdata(dev);
analogix_dp_unbind(dp->adp); analogix_dp_unbind(dp->adp);
rockchip_drm_psr_unregister(&dp->encoder);
dp->encoder.funcs->destroy(&dp->encoder); dp->encoder.funcs->destroy(&dp->encoder);
dp->adp = ERR_PTR(-ENODEV); dp->adp = ERR_PTR(-ENODEV);
......
...@@ -17,7 +17,6 @@ ...@@ -17,7 +17,6 @@
#include "rockchip_drm_drv.h" #include "rockchip_drm_drv.h"
#include "rockchip_drm_fb.h" #include "rockchip_drm_fb.h"
#include "rockchip_drm_gem.h" #include "rockchip_drm_gem.h"
#include "rockchip_drm_psr.h"
static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = { static const struct drm_framebuffer_funcs rockchip_drm_fb_funcs = {
.destroy = drm_gem_fb_destroy, .destroy = drm_gem_fb_destroy,
...@@ -111,8 +110,6 @@ rockchip_atomic_helper_commit_tail_rpm(struct drm_atomic_state *old_state) ...@@ -111,8 +110,6 @@ rockchip_atomic_helper_commit_tail_rpm(struct drm_atomic_state *old_state)
{ {
struct drm_device *dev = old_state->dev; struct drm_device *dev = old_state->dev;
rockchip_drm_psr_inhibit_get_state(old_state);
drm_atomic_helper_commit_modeset_disables(dev, old_state); drm_atomic_helper_commit_modeset_disables(dev, old_state);
drm_atomic_helper_commit_modeset_enables(dev, old_state); drm_atomic_helper_commit_modeset_enables(dev, old_state);
...@@ -120,8 +117,6 @@ rockchip_atomic_helper_commit_tail_rpm(struct drm_atomic_state *old_state) ...@@ -120,8 +117,6 @@ rockchip_atomic_helper_commit_tail_rpm(struct drm_atomic_state *old_state)
drm_atomic_helper_commit_planes(dev, old_state, drm_atomic_helper_commit_planes(dev, old_state,
DRM_PLANE_COMMIT_ACTIVE_ONLY); DRM_PLANE_COMMIT_ACTIVE_ONLY);
rockchip_drm_psr_inhibit_put_state(old_state);
drm_atomic_helper_commit_hw_done(old_state); drm_atomic_helper_commit_hw_done(old_state);
drm_atomic_helper_wait_for_vblanks(dev, old_state); drm_atomic_helper_wait_for_vblanks(dev, old_state);
......
// SPDX-License-Identifier: GPL-2.0-only
/*
* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
* Author: Yakir Yang <ykk@rock-chips.com>
*/
#include <drm/drm_atomic.h>
#include <drm/drm_probe_helper.h>
#include "rockchip_drm_drv.h"
#include "rockchip_drm_psr.h"
#define PSR_FLUSH_TIMEOUT_MS 100
struct psr_drv {
struct list_head list;
struct drm_encoder *encoder;
struct mutex lock;
int inhibit_count;
bool enabled;
struct delayed_work flush_work;
int (*set)(struct drm_encoder *encoder, bool enable);
};
static struct psr_drv *find_psr_by_encoder(struct drm_encoder *encoder)
{
struct rockchip_drm_private *drm_drv = encoder->dev->dev_private;
struct psr_drv *psr;
mutex_lock(&drm_drv->psr_list_lock);
list_for_each_entry(psr, &drm_drv->psr_list, list) {
if (psr->encoder == encoder)
goto out;
}
psr = ERR_PTR(-ENODEV);
out:
mutex_unlock(&drm_drv->psr_list_lock);
return psr;
}
static int psr_set_state_locked(struct psr_drv *psr, bool enable)
{
int ret;
if (psr->inhibit_count > 0)
return -EINVAL;
if (enable == psr->enabled)
return 0;
ret = psr->set(psr->encoder, enable);
if (ret)
return ret;
psr->enabled = enable;
return 0;
}
static void psr_flush_handler(struct work_struct *work)
{
struct psr_drv *psr = container_of(to_delayed_work(work),
struct psr_drv, flush_work);
mutex_lock(&psr->lock);
psr_set_state_locked(psr, true);
mutex_unlock(&psr->lock);
}
/**
* rockchip_drm_psr_inhibit_put - release PSR inhibit on given encoder
* @encoder: encoder to obtain the PSR encoder
*
* Decrements PSR inhibit count on given encoder. Should be called only
* for a PSR inhibit count increment done before. If PSR inhibit counter
* reaches zero, PSR flush work is scheduled to make the hardware enter
* PSR mode in PSR_FLUSH_TIMEOUT_MS.
*
* Returns:
* Zero on success, negative errno on failure.
*/
int rockchip_drm_psr_inhibit_put(struct drm_encoder *encoder)
{
struct psr_drv *psr = find_psr_by_encoder(encoder);
if (IS_ERR(psr))
return PTR_ERR(psr);
mutex_lock(&psr->lock);
--psr->inhibit_count;
WARN_ON(psr->inhibit_count < 0);
if (!psr->inhibit_count)
mod_delayed_work(system_wq, &psr->flush_work,
PSR_FLUSH_TIMEOUT_MS);
mutex_unlock(&psr->lock);
return 0;
}
EXPORT_SYMBOL(rockchip_drm_psr_inhibit_put);
void rockchip_drm_psr_inhibit_get_state(struct drm_atomic_state *state)
{
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
struct drm_encoder *encoder;
u32 encoder_mask = 0;
int i;
for_each_old_crtc_in_state(state, crtc, crtc_state, i) {
encoder_mask |= crtc_state->encoder_mask;
encoder_mask |= crtc->state->encoder_mask;
}
drm_for_each_encoder_mask(encoder, state->dev, encoder_mask)
rockchip_drm_psr_inhibit_get(encoder);
}
EXPORT_SYMBOL(rockchip_drm_psr_inhibit_get_state);
void rockchip_drm_psr_inhibit_put_state(struct drm_atomic_state *state)
{
struct drm_crtc *crtc;
struct drm_crtc_state *crtc_state;
struct drm_encoder *encoder;
u32 encoder_mask = 0;
int i;
for_each_old_crtc_in_state(state, crtc, crtc_state, i) {
encoder_mask |= crtc_state->encoder_mask;
encoder_mask |= crtc->state->encoder_mask;
}
drm_for_each_encoder_mask(encoder, state->dev, encoder_mask)
rockchip_drm_psr_inhibit_put(encoder);
}
EXPORT_SYMBOL(rockchip_drm_psr_inhibit_put_state);
/**
* rockchip_drm_psr_inhibit_get - acquire PSR inhibit on given encoder
* @encoder: encoder to obtain the PSR encoder
*
* Increments PSR inhibit count on given encoder. This function guarantees
* that after it returns PSR is turned off on given encoder and no PSR-related
* hardware state change occurs at least until a matching call to
* rockchip_drm_psr_inhibit_put() is done.
*
* Returns:
* Zero on success, negative errno on failure.
*/
int rockchip_drm_psr_inhibit_get(struct drm_encoder *encoder)
{
struct psr_drv *psr = find_psr_by_encoder(encoder);
if (IS_ERR(psr))
return PTR_ERR(psr);
mutex_lock(&psr->lock);
psr_set_state_locked(psr, false);
++psr->inhibit_count;
mutex_unlock(&psr->lock);
cancel_delayed_work_sync(&psr->flush_work);
return 0;
}
EXPORT_SYMBOL(rockchip_drm_psr_inhibit_get);
static void rockchip_drm_do_flush(struct psr_drv *psr)
{
cancel_delayed_work_sync(&psr->flush_work);
mutex_lock(&psr->lock);
if (!psr_set_state_locked(psr, false))
mod_delayed_work(system_wq, &psr->flush_work,
PSR_FLUSH_TIMEOUT_MS);
mutex_unlock(&psr->lock);
}
/**
* rockchip_drm_psr_flush_all - force to flush all registered PSR encoders
* @dev: drm device
*
* Disable the PSR function for all registered encoders, and then enable the
* PSR function back after PSR_FLUSH_TIMEOUT. If encoder PSR state have been
* changed during flush time, then keep the state no change after flush
* timeout.
*
* Returns:
* Zero on success, negative errno on failure.
*/
void rockchip_drm_psr_flush_all(struct drm_device *dev)
{
struct rockchip_drm_private *drm_drv = dev->dev_private;
struct psr_drv *psr;
mutex_lock(&drm_drv->psr_list_lock);
list_for_each_entry(psr, &drm_drv->psr_list, list)
rockchip_drm_do_flush(psr);
mutex_unlock(&drm_drv->psr_list_lock);
}
EXPORT_SYMBOL(rockchip_drm_psr_flush_all);
/**
* rockchip_drm_psr_register - register encoder to psr driver
* @encoder: encoder that obtain the PSR function
* @psr_set: call back to set PSR state
*
* The function returns with PSR inhibit counter initialized with one
* and the caller (typically encoder driver) needs to call
* rockchip_drm_psr_inhibit_put() when it becomes ready to accept PSR
* enable request.
*
* Returns:
* Zero on success, negative errno on failure.
*/
int rockchip_drm_psr_register(struct drm_encoder *encoder,
int (*psr_set)(struct drm_encoder *, bool enable))
{
struct rockchip_drm_private *drm_drv;
struct psr_drv *psr;
if (!encoder || !psr_set)
return -EINVAL;
drm_drv = encoder->dev->dev_private;
psr = kzalloc(sizeof(struct psr_drv), GFP_KERNEL);
if (!psr)
return -ENOMEM;
INIT_DELAYED_WORK(&psr->flush_work, psr_flush_handler);
mutex_init(&psr->lock);
psr->inhibit_count = 1;
psr->enabled = false;
psr->encoder = encoder;
psr->set = psr_set;
mutex_lock(&drm_drv->psr_list_lock);
list_add_tail(&psr->list, &drm_drv->psr_list);
mutex_unlock(&drm_drv->psr_list_lock);
return 0;
}
EXPORT_SYMBOL(rockchip_drm_psr_register);
/**
* rockchip_drm_psr_unregister - unregister encoder to psr driver
* @encoder: encoder that obtain the PSR function
* @psr_set: call back to set PSR state
*
* It is expected that the PSR inhibit counter is 1 when this function is
* called, which corresponds to a state when related encoder has been
* disconnected from any CRTCs and its driver called
* rockchip_drm_psr_inhibit_get() to stop the PSR logic.
*
* Returns:
* Zero on success, negative errno on failure.
*/
void rockchip_drm_psr_unregister(struct drm_encoder *encoder)
{
struct rockchip_drm_private *drm_drv = encoder->dev->dev_private;
struct psr_drv *psr, *n;
mutex_lock(&drm_drv->psr_list_lock);
list_for_each_entry_safe(psr, n, &drm_drv->psr_list, list) {
if (psr->encoder == encoder) {
/*
* Any other value would mean that the encoder
* is still in use.
*/
WARN_ON(psr->inhibit_count != 1);
list_del(&psr->list);
kfree(psr);
}
}
mutex_unlock(&drm_drv->psr_list_lock);
}
EXPORT_SYMBOL(rockchip_drm_psr_unregister);
/* SPDX-License-Identifier: GPL-2.0-only */
/*
* Copyright (C) Fuzhou Rockchip Electronics Co.Ltd
* Author: Yakir Yang <ykk@rock-chips.com>
*/
#ifndef __ROCKCHIP_DRM_PSR___
#define __ROCKCHIP_DRM_PSR___
void rockchip_drm_psr_flush_all(struct drm_device *dev);
int rockchip_drm_psr_inhibit_put(struct drm_encoder *encoder);
int rockchip_drm_psr_inhibit_get(struct drm_encoder *encoder);
void rockchip_drm_psr_inhibit_get_state(struct drm_atomic_state *state);
void rockchip_drm_psr_inhibit_put_state(struct drm_atomic_state *state);
int rockchip_drm_psr_register(struct drm_encoder *encoder,
int (*psr_set)(struct drm_encoder *, bool enable));
void rockchip_drm_psr_unregister(struct drm_encoder *encoder);
#endif /* __ROCKCHIP_DRM_PSR__ */
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <drm/drm_gem_framebuffer_helper.h> #include <drm/drm_gem_framebuffer_helper.h>
#include <drm/drm_plane_helper.h> #include <drm/drm_plane_helper.h>
#include <drm/drm_probe_helper.h> #include <drm/drm_probe_helper.h>
#include <drm/drm_self_refresh_helper.h>
#include <drm/drm_vblank.h> #include <drm/drm_vblank.h>
#ifdef CONFIG_DRM_ANALOGIX_DP #ifdef CONFIG_DRM_ANALOGIX_DP
...@@ -35,10 +36,11 @@ ...@@ -35,10 +36,11 @@
#include "rockchip_drm_drv.h" #include "rockchip_drm_drv.h"
#include "rockchip_drm_gem.h" #include "rockchip_drm_gem.h"
#include "rockchip_drm_fb.h" #include "rockchip_drm_fb.h"
#include "rockchip_drm_psr.h"
#include "rockchip_drm_vop.h" #include "rockchip_drm_vop.h"
#include "rockchip_rgb.h" #include "rockchip_rgb.h"
#define VOP_SELF_REFRESH_ENTRY_DELAY_MS 100
#define VOP_WIN_SET(vop, win, name, v) \ #define VOP_WIN_SET(vop, win, name, v) \
vop_reg_set(vop, &win->phy->name, win->base, ~0, v, #name) vop_reg_set(vop, &win->phy->name, win->base, ~0, v, #name)
#define VOP_SCL_SET(vop, win, name, v) \ #define VOP_SCL_SET(vop, win, name, v) \
...@@ -541,7 +543,7 @@ static void vop_win_disable(struct vop *vop, const struct vop_win_data *win) ...@@ -541,7 +543,7 @@ static void vop_win_disable(struct vop *vop, const struct vop_win_data *win)
VOP_WIN_SET(vop, win, enable, 0); VOP_WIN_SET(vop, win, enable, 0);
} }
static int vop_enable(struct drm_crtc *crtc) static int vop_enable(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{ {
struct vop *vop = to_vop(crtc); struct vop *vop = to_vop(crtc);
int ret, i; int ret, i;
...@@ -581,12 +583,18 @@ static int vop_enable(struct drm_crtc *crtc) ...@@ -581,12 +583,18 @@ static int vop_enable(struct drm_crtc *crtc)
* We need to make sure that all windows are disabled before we * We need to make sure that all windows are disabled before we
* enable the crtc. Otherwise we might try to scan from a destroyed * enable the crtc. Otherwise we might try to scan from a destroyed
* buffer later. * buffer later.
*
* In the case of enable-after-PSR, we don't need to worry about this
* case since the buffer is guaranteed to be valid and disabling the
* window will result in screen glitches on PSR exit.
*/ */
for (i = 0; i < vop->data->win_size; i++) { if (!old_state || !old_state->self_refresh_active) {
struct vop_win *vop_win = &vop->win[i]; for (i = 0; i < vop->data->win_size; i++) {
const struct vop_win_data *win = vop_win->data; struct vop_win *vop_win = &vop->win[i];
const struct vop_win_data *win = vop_win->data;
vop_win_disable(vop, win); vop_win_disable(vop, win);
}
} }
spin_unlock(&vop->reg_lock); spin_unlock(&vop->reg_lock);
...@@ -624,6 +632,12 @@ static void vop_crtc_atomic_disable(struct drm_crtc *crtc, ...@@ -624,6 +632,12 @@ static void vop_crtc_atomic_disable(struct drm_crtc *crtc,
WARN_ON(vop->event); WARN_ON(vop->event);
mutex_lock(&vop->vop_lock); mutex_lock(&vop->vop_lock);
if (!vop->is_enabled) {
mutex_unlock(&vop->vop_lock);
return;
}
drm_crtc_vblank_off(crtc); drm_crtc_vblank_off(crtc);
/* /*
...@@ -925,12 +939,10 @@ static void vop_plane_atomic_async_update(struct drm_plane *plane, ...@@ -925,12 +939,10 @@ static void vop_plane_atomic_async_update(struct drm_plane *plane,
swap(plane->state->fb, new_state->fb); swap(plane->state->fb, new_state->fb);
if (vop->is_enabled) { if (vop->is_enabled) {
rockchip_drm_psr_inhibit_get_state(new_state->state);
vop_plane_atomic_update(plane, plane->state); vop_plane_atomic_update(plane, plane->state);
spin_lock(&vop->reg_lock); spin_lock(&vop->reg_lock);
vop_cfg_done(vop); vop_cfg_done(vop);
spin_unlock(&vop->reg_lock); spin_unlock(&vop->reg_lock);
rockchip_drm_psr_inhibit_put_state(new_state->state);
/* /*
* A scanout can still be occurring, so we can't drop the * A scanout can still be occurring, so we can't drop the
...@@ -1038,7 +1050,7 @@ static void vop_crtc_atomic_enable(struct drm_crtc *crtc, ...@@ -1038,7 +1050,7 @@ static void vop_crtc_atomic_enable(struct drm_crtc *crtc,
WARN_ON(vop->event); WARN_ON(vop->event);
ret = vop_enable(crtc); ret = vop_enable(crtc, old_state);
if (ret) { if (ret) {
mutex_unlock(&vop->vop_lock); mutex_unlock(&vop->vop_lock);
DRM_DEV_ERROR(vop->dev, "Failed to enable vop (%d)\n", ret); DRM_DEV_ERROR(vop->dev, "Failed to enable vop (%d)\n", ret);
...@@ -1520,6 +1532,13 @@ static int vop_create_crtc(struct vop *vop) ...@@ -1520,6 +1532,13 @@ static int vop_create_crtc(struct vop *vop)
init_completion(&vop->line_flag_completion); init_completion(&vop->line_flag_completion);
crtc->port = port; crtc->port = port;
ret = drm_self_refresh_helper_init(crtc,
VOP_SELF_REFRESH_ENTRY_DELAY_MS);
if (ret)
DRM_DEV_DEBUG_KMS(vop->dev,
"Failed to init %s with SR helpers %d, ignoring\n",
crtc->name, ret);
return 0; return 0;
err_cleanup_crtc: err_cleanup_crtc:
...@@ -1537,6 +1556,8 @@ static void vop_destroy_crtc(struct vop *vop) ...@@ -1537,6 +1556,8 @@ static void vop_destroy_crtc(struct vop *vop)
struct drm_device *drm_dev = vop->drm_dev; struct drm_device *drm_dev = vop->drm_dev;
struct drm_plane *plane, *tmp; struct drm_plane *plane, *tmp;
drm_self_refresh_helper_cleanup(crtc);
of_node_put(crtc->port); of_node_put(crtc->port);
/* /*
......
...@@ -38,10 +38,6 @@ struct analogix_dp_plat_data { ...@@ -38,10 +38,6 @@ struct analogix_dp_plat_data {
struct drm_connector *); struct drm_connector *);
}; };
int analogix_dp_psr_enabled(struct analogix_dp_device *dp);
int analogix_dp_enable_psr(struct analogix_dp_device *dp);
int analogix_dp_disable_psr(struct analogix_dp_device *dp);
int analogix_dp_resume(struct analogix_dp_device *dp); int analogix_dp_resume(struct analogix_dp_device *dp);
int analogix_dp_suspend(struct analogix_dp_device *dp); int analogix_dp_suspend(struct analogix_dp_device *dp);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment