Commit 35ab6cfb authored by Yannick Fertré's avatar Yannick Fertré Committed by Benjamin Gaignard

drm/stm: support runtime power management

This patch enables runtime power management (runtime PM) support for
the display controller. pm_runtime_enable() and pm_runtime_disable()
are added during ltdc load and unload respectively.
pm_runtime_get_sync() and pm_runtime_put_sync() are added for ltdc
register access.
Signed-off-by: default avatarYannick Fertré <yannick.fertre@st.com>
Acked-by: default avatarPhilippe Cornu <philippe.cornu@st.com>
Signed-off-by: default avatarBenjamin Gaignard <benjamin.gaignard@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/1559550722-14091-1-git-send-email-yannick.fertre@st.com
parent 630bec0c
...@@ -12,6 +12,7 @@ ...@@ -12,6 +12,7 @@
#include <linux/dma-mapping.h> #include <linux/dma-mapping.h>
#include <linux/module.h> #include <linux/module.h>
#include <linux/of_platform.h> #include <linux/of_platform.h>
#include <linux/pm_runtime.h>
#include <drm/drm_atomic.h> #include <drm/drm_atomic.h>
#include <drm/drm_atomic_helper.h> #include <drm/drm_atomic_helper.h>
...@@ -135,14 +136,15 @@ static __maybe_unused int drv_suspend(struct device *dev) ...@@ -135,14 +136,15 @@ static __maybe_unused int drv_suspend(struct device *dev)
struct ltdc_device *ldev = ddev->dev_private; struct ltdc_device *ldev = ddev->dev_private;
struct drm_atomic_state *state; struct drm_atomic_state *state;
drm_kms_helper_poll_disable(ddev); if (WARN_ON(!ldev->suspend_state))
return -ENOENT;
state = drm_atomic_helper_suspend(ddev); state = drm_atomic_helper_suspend(ddev);
if (IS_ERR(state)) { if (IS_ERR(state))
drm_kms_helper_poll_enable(ddev);
return PTR_ERR(state); return PTR_ERR(state);
}
ldev->suspend_state = state; ldev->suspend_state = state;
ltdc_suspend(ddev); pm_runtime_force_suspend(dev);
return 0; return 0;
} }
...@@ -151,16 +153,41 @@ static __maybe_unused int drv_resume(struct device *dev) ...@@ -151,16 +153,41 @@ static __maybe_unused int drv_resume(struct device *dev)
{ {
struct drm_device *ddev = dev_get_drvdata(dev); struct drm_device *ddev = dev_get_drvdata(dev);
struct ltdc_device *ldev = ddev->dev_private; struct ltdc_device *ldev = ddev->dev_private;
int ret;
ltdc_resume(ddev); pm_runtime_force_resume(dev);
drm_atomic_helper_resume(ddev, ldev->suspend_state); ret = drm_atomic_helper_resume(ddev, ldev->suspend_state);
drm_kms_helper_poll_enable(ddev); if (ret) {
pm_runtime_force_suspend(dev);
ldev->suspend_state = NULL;
return ret;
}
return 0; return 0;
} }
static __maybe_unused int drv_runtime_suspend(struct device *dev)
{
struct drm_device *ddev = dev_get_drvdata(dev);
DRM_DEBUG_DRIVER("\n");
ltdc_suspend(ddev);
return 0;
}
static __maybe_unused int drv_runtime_resume(struct device *dev)
{
struct drm_device *ddev = dev_get_drvdata(dev);
DRM_DEBUG_DRIVER("\n");
return ltdc_resume(ddev);
}
static const struct dev_pm_ops drv_pm_ops = { static const struct dev_pm_ops drv_pm_ops = {
SET_SYSTEM_SLEEP_PM_OPS(drv_suspend, drv_resume) SET_SYSTEM_SLEEP_PM_OPS(drv_suspend, drv_resume)
SET_RUNTIME_PM_OPS(drv_runtime_suspend,
drv_runtime_resume, NULL)
}; };
static int stm_drm_platform_probe(struct platform_device *pdev) static int stm_drm_platform_probe(struct platform_device *pdev)
......
...@@ -16,6 +16,7 @@ ...@@ -16,6 +16,7 @@
#include <linux/of_address.h> #include <linux/of_address.h>
#include <linux/of_graph.h> #include <linux/of_graph.h>
#include <linux/platform_device.h> #include <linux/platform_device.h>
#include <linux/pm_runtime.h>
#include <linux/reset.h> #include <linux/reset.h>
#include <drm/drm_atomic.h> #include <drm/drm_atomic.h>
...@@ -444,6 +445,7 @@ static void ltdc_crtc_atomic_disable(struct drm_crtc *crtc, ...@@ -444,6 +445,7 @@ static void ltdc_crtc_atomic_disable(struct drm_crtc *crtc,
struct drm_crtc_state *old_state) struct drm_crtc_state *old_state)
{ {
struct ltdc_device *ldev = crtc_to_ltdc(crtc); struct ltdc_device *ldev = crtc_to_ltdc(crtc);
struct drm_device *ddev = crtc->dev;
DRM_DEBUG_DRIVER("\n"); DRM_DEBUG_DRIVER("\n");
...@@ -457,6 +459,8 @@ static void ltdc_crtc_atomic_disable(struct drm_crtc *crtc, ...@@ -457,6 +459,8 @@ static void ltdc_crtc_atomic_disable(struct drm_crtc *crtc,
/* immediately commit disable of layers before switching off LTDC */ /* immediately commit disable of layers before switching off LTDC */
reg_set(ldev->regs, LTDC_SRCR, SRCR_IMR); reg_set(ldev->regs, LTDC_SRCR, SRCR_IMR);
pm_runtime_put_sync(ddev->dev);
} }
#define CLK_TOLERANCE_HZ 50 #define CLK_TOLERANCE_HZ 50
...@@ -505,17 +509,31 @@ static bool ltdc_crtc_mode_fixup(struct drm_crtc *crtc, ...@@ -505,17 +509,31 @@ static bool ltdc_crtc_mode_fixup(struct drm_crtc *crtc,
struct drm_display_mode *adjusted_mode) struct drm_display_mode *adjusted_mode)
{ {
struct ltdc_device *ldev = crtc_to_ltdc(crtc); struct ltdc_device *ldev = crtc_to_ltdc(crtc);
struct drm_device *ddev = crtc->dev;
int rate = mode->clock * 1000; int rate = mode->clock * 1000;
bool runtime_active;
int ret;
runtime_active = pm_runtime_active(ddev->dev);
if (runtime_active)
pm_runtime_put_sync(ddev->dev);
clk_disable(ldev->pixel_clk);
if (clk_set_rate(ldev->pixel_clk, rate) < 0) { if (clk_set_rate(ldev->pixel_clk, rate) < 0) {
DRM_ERROR("Cannot set rate (%dHz) for pixel clk\n", rate); DRM_ERROR("Cannot set rate (%dHz) for pixel clk\n", rate);
return false; return false;
} }
clk_enable(ldev->pixel_clk);
adjusted_mode->clock = clk_get_rate(ldev->pixel_clk) / 1000; adjusted_mode->clock = clk_get_rate(ldev->pixel_clk) / 1000;
if (runtime_active) {
ret = pm_runtime_get_sync(ddev->dev);
if (ret) {
DRM_ERROR("Failed to fixup mode, cannot get sync\n");
return false;
}
}
DRM_DEBUG_DRIVER("requested clock %dkHz, adjusted clock %dkHz\n", DRM_DEBUG_DRIVER("requested clock %dkHz, adjusted clock %dkHz\n",
mode->clock, adjusted_mode->clock); mode->clock, adjusted_mode->clock);
...@@ -525,11 +543,21 @@ static bool ltdc_crtc_mode_fixup(struct drm_crtc *crtc, ...@@ -525,11 +543,21 @@ static bool ltdc_crtc_mode_fixup(struct drm_crtc *crtc,
static void ltdc_crtc_mode_set_nofb(struct drm_crtc *crtc) static void ltdc_crtc_mode_set_nofb(struct drm_crtc *crtc)
{ {
struct ltdc_device *ldev = crtc_to_ltdc(crtc); struct ltdc_device *ldev = crtc_to_ltdc(crtc);
struct drm_device *ddev = crtc->dev;
struct drm_display_mode *mode = &crtc->state->adjusted_mode; struct drm_display_mode *mode = &crtc->state->adjusted_mode;
struct videomode vm; struct videomode vm;
u32 hsync, vsync, accum_hbp, accum_vbp, accum_act_w, accum_act_h; u32 hsync, vsync, accum_hbp, accum_vbp, accum_act_w, accum_act_h;
u32 total_width, total_height; u32 total_width, total_height;
u32 val; u32 val;
int ret;
if (!pm_runtime_active(ddev->dev)) {
ret = pm_runtime_get_sync(ddev->dev);
if (ret) {
DRM_ERROR("Failed to set mode, cannot get sync\n");
return;
}
}
drm_display_mode_to_videomode(mode, &vm); drm_display_mode_to_videomode(mode, &vm);
...@@ -590,6 +618,7 @@ static void ltdc_crtc_atomic_flush(struct drm_crtc *crtc, ...@@ -590,6 +618,7 @@ static void ltdc_crtc_atomic_flush(struct drm_crtc *crtc,
struct drm_crtc_state *old_crtc_state) struct drm_crtc_state *old_crtc_state)
{ {
struct ltdc_device *ldev = crtc_to_ltdc(crtc); struct ltdc_device *ldev = crtc_to_ltdc(crtc);
struct drm_device *ddev = crtc->dev;
struct drm_pending_vblank_event *event = crtc->state->event; struct drm_pending_vblank_event *event = crtc->state->event;
DRM_DEBUG_ATOMIC("\n"); DRM_DEBUG_ATOMIC("\n");
...@@ -602,12 +631,12 @@ static void ltdc_crtc_atomic_flush(struct drm_crtc *crtc, ...@@ -602,12 +631,12 @@ static void ltdc_crtc_atomic_flush(struct drm_crtc *crtc,
if (event) { if (event) {
crtc->state->event = NULL; crtc->state->event = NULL;
spin_lock_irq(&crtc->dev->event_lock); spin_lock_irq(&ddev->event_lock);
if (drm_crtc_vblank_get(crtc) == 0) if (drm_crtc_vblank_get(crtc) == 0)
drm_crtc_arm_vblank_event(crtc, event); drm_crtc_arm_vblank_event(crtc, event);
else else
drm_crtc_send_vblank_event(crtc, event); drm_crtc_send_vblank_event(crtc, event);
spin_unlock_irq(&crtc->dev->event_lock); spin_unlock_irq(&ddev->event_lock);
} }
} }
...@@ -663,15 +692,19 @@ bool ltdc_crtc_scanoutpos(struct drm_device *ddev, unsigned int pipe, ...@@ -663,15 +692,19 @@ bool ltdc_crtc_scanoutpos(struct drm_device *ddev, unsigned int pipe,
* Computation for the two first cases are identical so we can * Computation for the two first cases are identical so we can
* simplify the code and only test if line > vactive_end * simplify the code and only test if line > vactive_end
*/ */
line = reg_read(ldev->regs, LTDC_CPSR) & CPSR_CYPOS; if (pm_runtime_active(ddev->dev)) {
vactive_start = reg_read(ldev->regs, LTDC_BPCR) & BPCR_AVBP; line = reg_read(ldev->regs, LTDC_CPSR) & CPSR_CYPOS;
vactive_end = reg_read(ldev->regs, LTDC_AWCR) & AWCR_AAH; vactive_start = reg_read(ldev->regs, LTDC_BPCR) & BPCR_AVBP;
vtotal = reg_read(ldev->regs, LTDC_TWCR) & TWCR_TOTALH; vactive_end = reg_read(ldev->regs, LTDC_AWCR) & AWCR_AAH;
vtotal = reg_read(ldev->regs, LTDC_TWCR) & TWCR_TOTALH;
if (line > vactive_end)
*vpos = line - vtotal - vactive_start; if (line > vactive_end)
else *vpos = line - vtotal - vactive_start;
*vpos = line - vactive_start; else
*vpos = line - vactive_start;
} else {
*vpos = 0;
}
*hpos = 0; *hpos = 0;
...@@ -1243,8 +1276,11 @@ int ltdc_load(struct drm_device *ddev) ...@@ -1243,8 +1276,11 @@ int ltdc_load(struct drm_device *ddev)
/* Allow usage of vblank without having to call drm_irq_install */ /* Allow usage of vblank without having to call drm_irq_install */
ddev->irq_enabled = 1; ddev->irq_enabled = 1;
return 0; clk_disable_unprepare(ldev->pixel_clk);
pm_runtime_enable(ddev->dev);
return 0;
err: err:
for (i = 0; i < MAX_ENDPOINTS; i++) for (i = 0; i < MAX_ENDPOINTS; i++)
drm_panel_bridge_remove(bridge[i]); drm_panel_bridge_remove(bridge[i]);
...@@ -1256,7 +1292,6 @@ int ltdc_load(struct drm_device *ddev) ...@@ -1256,7 +1292,6 @@ int ltdc_load(struct drm_device *ddev)
void ltdc_unload(struct drm_device *ddev) void ltdc_unload(struct drm_device *ddev)
{ {
struct ltdc_device *ldev = ddev->dev_private;
int i; int i;
DRM_DEBUG_DRIVER("\n"); DRM_DEBUG_DRIVER("\n");
...@@ -1264,7 +1299,7 @@ void ltdc_unload(struct drm_device *ddev) ...@@ -1264,7 +1299,7 @@ void ltdc_unload(struct drm_device *ddev)
for (i = 0; i < MAX_ENDPOINTS; i++) for (i = 0; i < MAX_ENDPOINTS; i++)
drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i); drm_of_panel_bridge_remove(ddev->dev->of_node, 0, i);
clk_disable_unprepare(ldev->pixel_clk); pm_runtime_disable(ddev->dev);
} }
MODULE_AUTHOR("Philippe Cornu <philippe.cornu@st.com>"); MODULE_AUTHOR("Philippe Cornu <philippe.cornu@st.com>");
......
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