2019-06-01 16:08:57 +08:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-only
|
2016-03-07 18:00:53 +08:00
|
|
|
/*
|
|
|
|
* (C) COPYRIGHT 2016 ARM Limited. All rights reserved.
|
|
|
|
* Author: Liviu Dudau <Liviu.Dudau@arm.com>
|
|
|
|
*
|
|
|
|
* ARM Mali DP500/DP550/DP650 driver (crtc operations)
|
|
|
|
*/
|
|
|
|
|
2019-08-04 17:41:32 +08:00
|
|
|
#include <linux/clk.h>
|
|
|
|
#include <linux/pm_runtime.h>
|
|
|
|
|
|
|
|
#include <video/videomode.h>
|
|
|
|
|
2016-03-07 18:00:53 +08:00
|
|
|
#include <drm/drm_atomic.h>
|
|
|
|
#include <drm/drm_atomic_helper.h>
|
|
|
|
#include <drm/drm_crtc.h>
|
2019-08-04 17:41:32 +08:00
|
|
|
#include <drm/drm_print.h>
|
2019-01-18 05:03:34 +08:00
|
|
|
#include <drm/drm_probe_helper.h>
|
2019-08-04 17:41:32 +08:00
|
|
|
#include <drm/drm_vblank.h>
|
2016-03-07 18:00:53 +08:00
|
|
|
|
|
|
|
#include "malidp_drv.h"
|
|
|
|
#include "malidp_hw.h"
|
|
|
|
|
2017-05-19 08:52:17 +08:00
|
|
|
static enum drm_mode_status malidp_crtc_mode_valid(struct drm_crtc *crtc,
|
|
|
|
const struct drm_display_mode *mode)
|
2016-03-07 18:00:53 +08:00
|
|
|
{
|
|
|
|
struct malidp_drm *malidp = crtc_to_malidp_device(crtc);
|
|
|
|
struct malidp_hw_device *hwdev = malidp->dev;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* check that the hardware can drive the required clock rate,
|
|
|
|
* but skip the check if the clock is meant to be disabled (req_rate = 0)
|
|
|
|
*/
|
|
|
|
long rate, req_rate = mode->crtc_clock * 1000;
|
|
|
|
|
|
|
|
if (req_rate) {
|
|
|
|
rate = clk_round_rate(hwdev->pxlclk, req_rate);
|
|
|
|
if (rate != req_rate) {
|
|
|
|
DRM_DEBUG_DRIVER("pxlclk doesn't support %ld Hz\n",
|
|
|
|
req_rate);
|
2017-05-19 08:52:17 +08:00
|
|
|
return MODE_NOCLOCK;
|
2016-03-07 18:00:53 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-05-19 08:52:17 +08:00
|
|
|
return MODE_OK;
|
2016-03-07 18:00:53 +08:00
|
|
|
}
|
|
|
|
|
2017-06-30 17:36:44 +08:00
|
|
|
static void malidp_crtc_atomic_enable(struct drm_crtc *crtc,
|
drm/atomic: Pass the full state to CRTC atomic enable/disable
If the CRTC driver ever needs to access the full DRM state, it can't do so
at atomic_enable / atomic_disable time since drm_atomic_helper_swap_state
will have cleared the pointer from the struct drm_crtc_state to the struct
drm_atomic_state before calling those hooks.
In order to allow that, let's pass the full DRM state to atomic_enable and
atomic_disable. The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
disable_outputs(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_disable(crtc, crtc_state);
+ FUNCS->atomic_disable(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_enable(crtc, crtc_state);
+ FUNCS->atomic_enable(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_enable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_enable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_disable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_disable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_enable = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/845aa10ef171fc0ea060495efef142a0c13f7870.1602161031.git-series.maxime@cerno.tech
2020-10-08 20:44:08 +08:00
|
|
|
struct drm_atomic_state *state)
|
2016-03-07 18:00:53 +08:00
|
|
|
{
|
|
|
|
struct malidp_drm *malidp = crtc_to_malidp_device(crtc);
|
|
|
|
struct malidp_hw_device *hwdev = malidp->dev;
|
|
|
|
struct videomode vm;
|
2017-03-22 18:44:57 +08:00
|
|
|
int err = pm_runtime_get_sync(crtc->dev->dev);
|
2016-03-07 18:00:53 +08:00
|
|
|
|
2017-03-22 18:44:57 +08:00
|
|
|
if (err < 0) {
|
|
|
|
DRM_DEBUG_DRIVER("Failed to enable runtime power management: %d\n", err);
|
|
|
|
return;
|
|
|
|
}
|
2016-03-07 18:00:53 +08:00
|
|
|
|
2017-03-22 18:44:57 +08:00
|
|
|
drm_display_mode_to_videomode(&crtc->state->adjusted_mode, &vm);
|
2016-03-07 18:00:53 +08:00
|
|
|
clk_prepare_enable(hwdev->pxlclk);
|
|
|
|
|
2017-02-15 22:00:15 +08:00
|
|
|
/* We rely on firmware to set mclk to a sensible level. */
|
2016-03-07 18:00:53 +08:00
|
|
|
clk_set_rate(hwdev->pxlclk, crtc->state->adjusted_mode.crtc_clock * 1000);
|
|
|
|
|
2017-08-31 22:48:43 +08:00
|
|
|
hwdev->hw->modeset(hwdev, &vm);
|
|
|
|
hwdev->hw->leave_config_mode(hwdev);
|
2016-03-07 18:00:53 +08:00
|
|
|
drm_crtc_vblank_on(crtc);
|
|
|
|
}
|
|
|
|
|
2017-06-30 17:36:45 +08:00
|
|
|
static void malidp_crtc_atomic_disable(struct drm_crtc *crtc,
|
drm/atomic: Pass the full state to CRTC atomic enable/disable
If the CRTC driver ever needs to access the full DRM state, it can't do so
at atomic_enable / atomic_disable time since drm_atomic_helper_swap_state
will have cleared the pointer from the struct drm_crtc_state to the struct
drm_atomic_state before calling those hooks.
In order to allow that, let's pass the full DRM state to atomic_enable and
atomic_disable. The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
disable_outputs(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_disable(crtc, crtc_state);
+ FUNCS->atomic_disable(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_enable(crtc, crtc_state);
+ FUNCS->atomic_enable(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_enable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_enable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_disable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_disable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_enable = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/845aa10ef171fc0ea060495efef142a0c13f7870.1602161031.git-series.maxime@cerno.tech
2020-10-08 20:44:08 +08:00
|
|
|
struct drm_atomic_state *state)
|
2016-03-07 18:00:53 +08:00
|
|
|
{
|
drm/atomic: Pass the full state to CRTC atomic enable/disable
If the CRTC driver ever needs to access the full DRM state, it can't do so
at atomic_enable / atomic_disable time since drm_atomic_helper_swap_state
will have cleared the pointer from the struct drm_crtc_state to the struct
drm_atomic_state before calling those hooks.
In order to allow that, let's pass the full DRM state to atomic_enable and
atomic_disable. The conversion was done using the coccinelle script below,
built tested on all the drivers and actually tested on vc4.
virtual report
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
disable_outputs(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_disable(crtc, crtc_state);
+ FUNCS->atomic_disable(crtc, state);
...>
}
@@
struct drm_crtc_helper_funcs *FUNCS;
identifier dev, state;
identifier crtc, crtc_state;
@@
drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, struct drm_atomic_state *state)
{
<...
- FUNCS->atomic_enable(crtc, crtc_state);
+ FUNCS->atomic_enable(crtc, state);
...>
}
@@
identifier crtc, old_state;
@@
struct drm_crtc_helper_funcs {
...
- void (*atomic_enable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_enable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
- void (*atomic_disable)(struct drm_crtc *crtc, struct drm_crtc_state *old_state);
+ void (*atomic_disable)(struct drm_crtc *crtc, struct drm_atomic_state *state);
...
}
@ crtc_atomic_func @
identifier helpers;
identifier func;
@@
(
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_enable = func,
...,
};
|
static struct drm_crtc_helper_funcs helpers = {
...,
.atomic_disable = func,
...,
};
)
@ ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc,
struct drm_crtc_state *old_state)
{
... when != old_state
}
@ adds_old_state depends on crtc_atomic_func && !ignores_old_state @
identifier crtc_atomic_func.func;
identifier crtc, old_state;
@@
void func(struct drm_crtc *crtc, struct drm_crtc_state *old_state)
{
+ struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state, crtc);
...
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
expression E;
type T;
@@
void func(...)
{
...
- T state = E;
+ T crtc_state = E;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
type T;
@@
void func(...)
{
...
- T state;
+ T crtc_state;
<+...
- state
+ crtc_state
...+>
}
@ depends on crtc_atomic_func @
identifier crtc_atomic_func.func;
identifier old_state;
identifier crtc;
@@
void func(struct drm_crtc *crtc,
- struct drm_crtc_state *old_state
+ struct drm_atomic_state *state
)
{ ... }
@ include depends on adds_old_state @
@@
#include <drm/drm_atomic.h>
@ no_include depends on !include && adds_old_state @
@@
+ #include <drm/drm_atomic.h>
#include <drm/...>
Signed-off-by: Maxime Ripard <maxime@cerno.tech>
Acked-by: Daniel Vetter <daniel.vetter@ffwll.ch>
Link: https://patchwork.freedesktop.org/patch/msgid/845aa10ef171fc0ea060495efef142a0c13f7870.1602161031.git-series.maxime@cerno.tech
2020-10-08 20:44:08 +08:00
|
|
|
struct drm_crtc_state *old_state = drm_atomic_get_old_crtc_state(state,
|
|
|
|
crtc);
|
2016-03-07 18:00:53 +08:00
|
|
|
struct malidp_drm *malidp = crtc_to_malidp_device(crtc);
|
|
|
|
struct malidp_hw_device *hwdev = malidp->dev;
|
2017-03-22 18:44:57 +08:00
|
|
|
int err;
|
2016-03-07 18:00:53 +08:00
|
|
|
|
2017-09-01 00:39:24 +08:00
|
|
|
/* always disable planes on the CRTC that is being turned off */
|
|
|
|
drm_atomic_helper_disable_planes_on_crtc(old_state, false);
|
|
|
|
|
2016-03-07 18:00:53 +08:00
|
|
|
drm_crtc_vblank_off(crtc);
|
2017-08-31 22:48:43 +08:00
|
|
|
hwdev->hw->enter_config_mode(hwdev);
|
|
|
|
|
2016-03-07 18:00:53 +08:00
|
|
|
clk_disable_unprepare(hwdev->pxlclk);
|
2017-03-22 18:44:57 +08:00
|
|
|
|
|
|
|
err = pm_runtime_put(crtc->dev->dev);
|
|
|
|
if (err < 0) {
|
|
|
|
DRM_DEBUG_DRIVER("Failed to disable runtime power management: %d\n", err);
|
|
|
|
}
|
2016-03-07 18:00:53 +08:00
|
|
|
}
|
|
|
|
|
2017-02-01 22:48:50 +08:00
|
|
|
static const struct gamma_curve_segment {
|
|
|
|
u16 start;
|
|
|
|
u16 end;
|
|
|
|
} segments[MALIDP_COEFFTAB_NUM_COEFFS] = {
|
|
|
|
/* sector 0 */
|
|
|
|
{ 0, 0 }, { 1, 1 }, { 2, 2 }, { 3, 3 },
|
|
|
|
{ 4, 4 }, { 5, 5 }, { 6, 6 }, { 7, 7 },
|
|
|
|
{ 8, 8 }, { 9, 9 }, { 10, 10 }, { 11, 11 },
|
|
|
|
{ 12, 12 }, { 13, 13 }, { 14, 14 }, { 15, 15 },
|
|
|
|
/* sector 1 */
|
|
|
|
{ 16, 19 }, { 20, 23 }, { 24, 27 }, { 28, 31 },
|
|
|
|
/* sector 2 */
|
|
|
|
{ 32, 39 }, { 40, 47 }, { 48, 55 }, { 56, 63 },
|
|
|
|
/* sector 3 */
|
|
|
|
{ 64, 79 }, { 80, 95 }, { 96, 111 }, { 112, 127 },
|
|
|
|
/* sector 4 */
|
|
|
|
{ 128, 159 }, { 160, 191 }, { 192, 223 }, { 224, 255 },
|
|
|
|
/* sector 5 */
|
|
|
|
{ 256, 319 }, { 320, 383 }, { 384, 447 }, { 448, 511 },
|
|
|
|
/* sector 6 */
|
|
|
|
{ 512, 639 }, { 640, 767 }, { 768, 895 }, { 896, 1023 },
|
|
|
|
{ 1024, 1151 }, { 1152, 1279 }, { 1280, 1407 }, { 1408, 1535 },
|
|
|
|
{ 1536, 1663 }, { 1664, 1791 }, { 1792, 1919 }, { 1920, 2047 },
|
|
|
|
{ 2048, 2175 }, { 2176, 2303 }, { 2304, 2431 }, { 2432, 2559 },
|
|
|
|
{ 2560, 2687 }, { 2688, 2815 }, { 2816, 2943 }, { 2944, 3071 },
|
|
|
|
{ 3072, 3199 }, { 3200, 3327 }, { 3328, 3455 }, { 3456, 3583 },
|
|
|
|
{ 3584, 3711 }, { 3712, 3839 }, { 3840, 3967 }, { 3968, 4095 },
|
|
|
|
};
|
|
|
|
|
|
|
|
#define DE_COEFTAB_DATA(a, b) ((((a) & 0xfff) << 16) | (((b) & 0xfff)))
|
|
|
|
|
|
|
|
static void malidp_generate_gamma_table(struct drm_property_blob *lut_blob,
|
|
|
|
u32 coeffs[MALIDP_COEFFTAB_NUM_COEFFS])
|
|
|
|
{
|
|
|
|
struct drm_color_lut *lut = (struct drm_color_lut *)lut_blob->data;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
for (i = 0; i < MALIDP_COEFFTAB_NUM_COEFFS; ++i) {
|
|
|
|
u32 a, b, delta_in, out_start, out_end;
|
|
|
|
|
|
|
|
delta_in = segments[i].end - segments[i].start;
|
|
|
|
/* DP has 12-bit internal precision for its LUTs. */
|
|
|
|
out_start = drm_color_lut_extract(lut[segments[i].start].green,
|
|
|
|
12);
|
|
|
|
out_end = drm_color_lut_extract(lut[segments[i].end].green, 12);
|
|
|
|
a = (delta_in == 0) ? 0 : ((out_end - out_start) * 256) / delta_in;
|
|
|
|
b = out_start;
|
|
|
|
coeffs[i] = DE_COEFTAB_DATA(a, b);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check if there is a new gamma LUT and if it is of an acceptable size. Also,
|
|
|
|
* reject any LUTs that use distinct red, green, and blue curves.
|
|
|
|
*/
|
|
|
|
static int malidp_crtc_atomic_check_gamma(struct drm_crtc *crtc,
|
|
|
|
struct drm_crtc_state *state)
|
|
|
|
{
|
|
|
|
struct malidp_crtc_state *mc = to_malidp_crtc_state(state);
|
|
|
|
struct drm_color_lut *lut;
|
|
|
|
size_t lut_size;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!state->color_mgmt_changed || !state->gamma_lut)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (crtc->state->gamma_lut &&
|
|
|
|
(crtc->state->gamma_lut->base.id == state->gamma_lut->base.id))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (state->gamma_lut->length % sizeof(struct drm_color_lut))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
lut_size = state->gamma_lut->length / sizeof(struct drm_color_lut);
|
|
|
|
if (lut_size != MALIDP_GAMMA_LUT_SIZE)
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
lut = (struct drm_color_lut *)state->gamma_lut->data;
|
|
|
|
for (i = 0; i < lut_size; ++i)
|
|
|
|
if (!((lut[i].red == lut[i].green) &&
|
|
|
|
(lut[i].red == lut[i].blue)))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
if (!state->mode_changed) {
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
state->mode_changed = true;
|
|
|
|
/*
|
|
|
|
* Kerneldoc for drm_atomic_helper_check_modeset mandates that
|
|
|
|
* it be invoked when the driver sets ->mode_changed. Since
|
|
|
|
* changing the gamma LUT doesn't depend on any external
|
|
|
|
* resources, it is safe to call it only once.
|
|
|
|
*/
|
|
|
|
ret = drm_atomic_helper_check_modeset(crtc->dev, state->state);
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
malidp_generate_gamma_table(state->gamma_lut, mc->gamma_coeffs);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-13 20:49:03 +08:00
|
|
|
/*
|
|
|
|
* Check if there is a new CTM and if it contains valid input. Valid here means
|
|
|
|
* that the number is inside the representable range for a Q3.12 number,
|
|
|
|
* excluding truncating the fractional part of the input data.
|
|
|
|
*
|
|
|
|
* The COLORADJ registers can be changed atomically.
|
|
|
|
*/
|
|
|
|
static int malidp_crtc_atomic_check_ctm(struct drm_crtc *crtc,
|
|
|
|
struct drm_crtc_state *state)
|
|
|
|
{
|
|
|
|
struct malidp_crtc_state *mc = to_malidp_crtc_state(state);
|
|
|
|
struct drm_color_ctm *ctm;
|
|
|
|
int i;
|
|
|
|
|
|
|
|
if (!state->color_mgmt_changed)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (!state->ctm)
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
if (crtc->state->ctm && (crtc->state->ctm->base.id ==
|
|
|
|
state->ctm->base.id))
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* The size of the ctm is checked in
|
|
|
|
* drm_atomic_replace_property_blob_from_id.
|
|
|
|
*/
|
|
|
|
ctm = (struct drm_color_ctm *)state->ctm->data;
|
|
|
|
for (i = 0; i < ARRAY_SIZE(ctm->matrix); ++i) {
|
|
|
|
/* Convert from S31.32 to Q3.12. */
|
|
|
|
s64 val = ctm->matrix[i];
|
|
|
|
u32 mag = ((((u64)val) & ~BIT_ULL(63)) >> 20) &
|
|
|
|
GENMASK_ULL(14, 0);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert to 2s complement and check the destination's top bit
|
|
|
|
* for overflow. NB: Can't check before converting or it'd
|
|
|
|
* incorrectly reject the case:
|
|
|
|
* sign == 1
|
|
|
|
* mag == 0x2000
|
|
|
|
*/
|
|
|
|
if (val & BIT_ULL(63))
|
|
|
|
mag = ~mag + 1;
|
|
|
|
if (!!(val & BIT_ULL(63)) != !!(mag & BIT(14)))
|
|
|
|
return -EINVAL;
|
|
|
|
mc->coloradj_coeffs[i] = mag;
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2017-02-13 23:14:05 +08:00
|
|
|
static int malidp_crtc_atomic_check_scaling(struct drm_crtc *crtc,
|
|
|
|
struct drm_crtc_state *state)
|
|
|
|
{
|
2017-02-13 23:09:01 +08:00
|
|
|
struct malidp_drm *malidp = crtc_to_malidp_device(crtc);
|
|
|
|
struct malidp_hw_device *hwdev = malidp->dev;
|
2017-02-13 23:14:05 +08:00
|
|
|
struct malidp_crtc_state *cs = to_malidp_crtc_state(state);
|
|
|
|
struct malidp_se_config *s = &cs->scaler_config;
|
|
|
|
struct drm_plane *plane;
|
2017-02-13 23:09:01 +08:00
|
|
|
struct videomode vm;
|
2017-02-13 23:14:05 +08:00
|
|
|
const struct drm_plane_state *pstate;
|
|
|
|
u32 h_upscale_factor = 0; /* U16.16 */
|
|
|
|
u32 v_upscale_factor = 0; /* U16.16 */
|
|
|
|
u8 scaling = cs->scaled_planes_mask;
|
2017-02-13 23:09:01 +08:00
|
|
|
int ret;
|
2017-02-13 23:14:05 +08:00
|
|
|
|
|
|
|
if (!scaling) {
|
|
|
|
s->scale_enable = false;
|
2017-02-13 23:09:01 +08:00
|
|
|
goto mclk_calc;
|
2017-02-13 23:14:05 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/* The scaling engine can only handle one plane at a time. */
|
|
|
|
if (scaling & (scaling - 1))
|
|
|
|
return -EINVAL;
|
|
|
|
|
|
|
|
drm_atomic_crtc_state_for_each_plane_state(plane, pstate, state) {
|
|
|
|
struct malidp_plane *mp = to_malidp_plane(plane);
|
|
|
|
u32 phase;
|
|
|
|
|
|
|
|
if (!(mp->layer->id & scaling))
|
|
|
|
continue;
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert crtc_[w|h] to U32.32, then divide by U16.16 src_[w|h]
|
|
|
|
* to get the U16.16 result.
|
|
|
|
*/
|
2017-04-26 03:56:53 +08:00
|
|
|
h_upscale_factor = div_u64((u64)pstate->crtc_w << 32,
|
|
|
|
pstate->src_w);
|
|
|
|
v_upscale_factor = div_u64((u64)pstate->crtc_h << 32,
|
|
|
|
pstate->src_h);
|
2017-02-13 23:14:05 +08:00
|
|
|
|
2017-02-06 20:20:56 +08:00
|
|
|
s->enhancer_enable = ((h_upscale_factor >> 16) >= 2 ||
|
|
|
|
(v_upscale_factor >> 16) >= 2);
|
|
|
|
|
2017-12-20 00:20:16 +08:00
|
|
|
if (pstate->rotation & MALIDP_ROTATED_MASK) {
|
|
|
|
s->input_w = pstate->src_h >> 16;
|
|
|
|
s->input_h = pstate->src_w >> 16;
|
|
|
|
} else {
|
|
|
|
s->input_w = pstate->src_w >> 16;
|
|
|
|
s->input_h = pstate->src_h >> 16;
|
|
|
|
}
|
|
|
|
|
2017-02-13 23:14:05 +08:00
|
|
|
s->output_w = pstate->crtc_w;
|
|
|
|
s->output_h = pstate->crtc_h;
|
|
|
|
|
|
|
|
#define SE_N_PHASE 4
|
|
|
|
#define SE_SHIFT_N_PHASE 12
|
|
|
|
/* Calculate initial_phase and delta_phase for horizontal. */
|
|
|
|
phase = s->input_w;
|
|
|
|
s->h_init_phase =
|
|
|
|
((phase << SE_N_PHASE) / s->output_w + 1) / 2;
|
|
|
|
|
|
|
|
phase = s->input_w;
|
|
|
|
phase <<= (SE_SHIFT_N_PHASE + SE_N_PHASE);
|
|
|
|
s->h_delta_phase = phase / s->output_w;
|
|
|
|
|
|
|
|
/* Same for vertical. */
|
|
|
|
phase = s->input_h;
|
|
|
|
s->v_init_phase =
|
|
|
|
((phase << SE_N_PHASE) / s->output_h + 1) / 2;
|
|
|
|
|
|
|
|
phase = s->input_h;
|
|
|
|
phase <<= (SE_SHIFT_N_PHASE + SE_N_PHASE);
|
|
|
|
s->v_delta_phase = phase / s->output_h;
|
|
|
|
#undef SE_N_PHASE
|
|
|
|
#undef SE_SHIFT_N_PHASE
|
|
|
|
s->plane_src_id = mp->layer->id;
|
|
|
|
}
|
|
|
|
|
|
|
|
s->scale_enable = true;
|
|
|
|
s->hcoeff = malidp_se_select_coeffs(h_upscale_factor);
|
|
|
|
s->vcoeff = malidp_se_select_coeffs(v_upscale_factor);
|
2017-02-13 23:09:01 +08:00
|
|
|
|
|
|
|
mclk_calc:
|
|
|
|
drm_display_mode_to_videomode(&state->adjusted_mode, &vm);
|
2017-08-31 22:48:43 +08:00
|
|
|
ret = hwdev->hw->se_calc_mclk(hwdev, s, &vm);
|
2017-02-13 23:09:01 +08:00
|
|
|
if (ret < 0)
|
|
|
|
return -EINVAL;
|
2017-02-13 23:14:05 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2016-03-07 18:00:53 +08:00
|
|
|
static int malidp_crtc_atomic_check(struct drm_crtc *crtc,
|
|
|
|
struct drm_crtc_state *state)
|
|
|
|
{
|
|
|
|
struct malidp_drm *malidp = crtc_to_malidp_device(crtc);
|
|
|
|
struct malidp_hw_device *hwdev = malidp->dev;
|
|
|
|
struct drm_plane *plane;
|
|
|
|
const struct drm_plane_state *pstate;
|
|
|
|
u32 rot_mem_free, rot_mem_usable;
|
|
|
|
int rotated_planes = 0;
|
2017-02-13 20:49:03 +08:00
|
|
|
int ret;
|
2016-03-07 18:00:53 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* check if there is enough rotation memory available for planes
|
2018-10-02 19:11:00 +08:00
|
|
|
* that need 90° and 270° rotion or planes that are compressed.
|
|
|
|
* Each plane has set its required memory size in the ->plane_check()
|
|
|
|
* callback, here we only make sure that the sums are less that the
|
|
|
|
* total usable memory.
|
2016-03-07 18:00:53 +08:00
|
|
|
*
|
|
|
|
* The rotation memory allocation algorithm (for each plane):
|
2018-10-02 19:11:00 +08:00
|
|
|
* a. If no more rotated or compressed planes exist, all remaining
|
|
|
|
* rotate memory in the bank is available for use by the plane.
|
|
|
|
* b. If other rotated or compressed planes exist, and plane's
|
|
|
|
* layer ID is DE_VIDEO1, it can use all the memory from first bank
|
|
|
|
* if secondary rotation memory bank is available, otherwise it can
|
2016-03-07 18:00:53 +08:00
|
|
|
* use up to half the bank's memory.
|
2018-10-02 19:11:00 +08:00
|
|
|
* c. If other rotated or compressed planes exist, and plane's layer ID
|
|
|
|
* is not DE_VIDEO1, it can use half of the available memory.
|
2016-03-07 18:00:53 +08:00
|
|
|
*
|
|
|
|
* Note: this algorithm assumes that the order in which the planes are
|
|
|
|
* checked always has DE_VIDEO1 plane first in the list if it is
|
|
|
|
* rotated. Because that is how we create the planes in the first
|
|
|
|
* place, under current DRM version things work, but if ever the order
|
|
|
|
* in which drm_atomic_crtc_state_for_each_plane() iterates over planes
|
|
|
|
* changes, we need to pre-sort the planes before validation.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/* first count the number of rotated planes */
|
|
|
|
drm_atomic_crtc_state_for_each_plane_state(plane, pstate, state) {
|
2018-10-02 19:11:00 +08:00
|
|
|
struct drm_framebuffer *fb = pstate->fb;
|
|
|
|
|
|
|
|
if ((pstate->rotation & MALIDP_ROTATED_MASK) || fb->modifier)
|
2016-03-07 18:00:53 +08:00
|
|
|
rotated_planes++;
|
|
|
|
}
|
|
|
|
|
|
|
|
rot_mem_free = hwdev->rotation_memory[0];
|
|
|
|
/*
|
|
|
|
* if we have more than 1 plane using rotation memory, use the second
|
|
|
|
* block of rotation memory as well
|
|
|
|
*/
|
|
|
|
if (rotated_planes > 1)
|
|
|
|
rot_mem_free += hwdev->rotation_memory[1];
|
|
|
|
|
|
|
|
/* now validate the rotation memory requirements */
|
|
|
|
drm_atomic_crtc_state_for_each_plane_state(plane, pstate, state) {
|
|
|
|
struct malidp_plane *mp = to_malidp_plane(plane);
|
|
|
|
struct malidp_plane_state *ms = to_malidp_plane_state(pstate);
|
2018-10-02 19:11:00 +08:00
|
|
|
struct drm_framebuffer *fb = pstate->fb;
|
2016-03-07 18:00:53 +08:00
|
|
|
|
2018-10-02 19:11:00 +08:00
|
|
|
if ((pstate->rotation & MALIDP_ROTATED_MASK) || fb->modifier) {
|
2016-03-07 18:00:53 +08:00
|
|
|
/* process current plane */
|
|
|
|
rotated_planes--;
|
|
|
|
|
|
|
|
if (!rotated_planes) {
|
|
|
|
/* no more rotated planes, we can use what's left */
|
|
|
|
rot_mem_usable = rot_mem_free;
|
|
|
|
} else {
|
|
|
|
if ((mp->layer->id != DE_VIDEO1) ||
|
|
|
|
(hwdev->rotation_memory[1] == 0))
|
|
|
|
rot_mem_usable = rot_mem_free / 2;
|
|
|
|
else
|
|
|
|
rot_mem_usable = hwdev->rotation_memory[0];
|
|
|
|
}
|
|
|
|
|
|
|
|
rot_mem_free -= rot_mem_usable;
|
|
|
|
|
|
|
|
if (ms->rotmem_size > rot_mem_usable)
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2017-11-03 00:49:51 +08:00
|
|
|
/* If only the writeback routing has changed, we don't need a modeset */
|
|
|
|
if (state->connectors_changed) {
|
|
|
|
u32 old_mask = crtc->state->connector_mask;
|
|
|
|
u32 new_mask = state->connector_mask;
|
|
|
|
|
|
|
|
if ((old_mask ^ new_mask) ==
|
|
|
|
(1 << drm_connector_index(&malidp->mw_connector.base)))
|
|
|
|
state->connectors_changed = false;
|
|
|
|
}
|
|
|
|
|
2017-02-13 20:49:03 +08:00
|
|
|
ret = malidp_crtc_atomic_check_gamma(crtc, state);
|
|
|
|
ret = ret ? ret : malidp_crtc_atomic_check_ctm(crtc, state);
|
2017-02-13 23:14:05 +08:00
|
|
|
ret = ret ? ret : malidp_crtc_atomic_check_scaling(crtc, state);
|
2017-02-13 20:49:03 +08:00
|
|
|
|
|
|
|
return ret;
|
2016-03-07 18:00:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
static const struct drm_crtc_helper_funcs malidp_crtc_helper_funcs = {
|
2017-05-19 08:52:17 +08:00
|
|
|
.mode_valid = malidp_crtc_mode_valid,
|
2016-03-07 18:00:53 +08:00
|
|
|
.atomic_check = malidp_crtc_atomic_check,
|
2017-06-30 17:36:44 +08:00
|
|
|
.atomic_enable = malidp_crtc_atomic_enable,
|
2017-06-30 17:36:45 +08:00
|
|
|
.atomic_disable = malidp_crtc_atomic_disable,
|
2016-03-07 18:00:53 +08:00
|
|
|
};
|
|
|
|
|
2017-02-01 22:48:49 +08:00
|
|
|
static struct drm_crtc_state *malidp_crtc_duplicate_state(struct drm_crtc *crtc)
|
|
|
|
{
|
2017-02-01 22:48:50 +08:00
|
|
|
struct malidp_crtc_state *state, *old_state;
|
2017-02-01 22:48:49 +08:00
|
|
|
|
|
|
|
if (WARN_ON(!crtc->state))
|
|
|
|
return NULL;
|
|
|
|
|
2017-02-01 22:48:50 +08:00
|
|
|
old_state = to_malidp_crtc_state(crtc->state);
|
2017-02-01 22:48:49 +08:00
|
|
|
state = kmalloc(sizeof(*state), GFP_KERNEL);
|
|
|
|
if (!state)
|
|
|
|
return NULL;
|
|
|
|
|
|
|
|
__drm_atomic_helper_crtc_duplicate_state(crtc, &state->base);
|
2017-02-01 22:48:50 +08:00
|
|
|
memcpy(state->gamma_coeffs, old_state->gamma_coeffs,
|
|
|
|
sizeof(state->gamma_coeffs));
|
2017-02-13 20:49:03 +08:00
|
|
|
memcpy(state->coloradj_coeffs, old_state->coloradj_coeffs,
|
|
|
|
sizeof(state->coloradj_coeffs));
|
2017-02-13 23:14:05 +08:00
|
|
|
memcpy(&state->scaler_config, &old_state->scaler_config,
|
|
|
|
sizeof(state->scaler_config));
|
|
|
|
state->scaled_planes_mask = 0;
|
2017-02-01 22:48:49 +08:00
|
|
|
|
|
|
|
return &state->base;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void malidp_crtc_destroy_state(struct drm_crtc *crtc,
|
|
|
|
struct drm_crtc_state *state)
|
|
|
|
{
|
|
|
|
struct malidp_crtc_state *mali_state = NULL;
|
|
|
|
|
|
|
|
if (state) {
|
|
|
|
mali_state = to_malidp_crtc_state(state);
|
|
|
|
__drm_atomic_helper_crtc_destroy_state(state);
|
|
|
|
}
|
|
|
|
|
|
|
|
kfree(mali_state);
|
|
|
|
}
|
|
|
|
|
2019-03-01 20:56:15 +08:00
|
|
|
static void malidp_crtc_reset(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct malidp_crtc_state *state =
|
|
|
|
kzalloc(sizeof(*state), GFP_KERNEL);
|
|
|
|
|
|
|
|
if (crtc->state)
|
|
|
|
malidp_crtc_destroy_state(crtc, crtc->state);
|
|
|
|
|
|
|
|
__drm_atomic_helper_crtc_reset(crtc, &state->base);
|
|
|
|
}
|
|
|
|
|
2017-02-07 17:16:17 +08:00
|
|
|
static int malidp_crtc_enable_vblank(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct malidp_drm *malidp = crtc_to_malidp_device(crtc);
|
|
|
|
struct malidp_hw_device *hwdev = malidp->dev;
|
|
|
|
|
|
|
|
malidp_hw_enable_irq(hwdev, MALIDP_DE_BLOCK,
|
2017-08-31 22:48:43 +08:00
|
|
|
hwdev->hw->map.de_irq_map.vsync_irq);
|
2017-02-07 17:16:17 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static void malidp_crtc_disable_vblank(struct drm_crtc *crtc)
|
|
|
|
{
|
|
|
|
struct malidp_drm *malidp = crtc_to_malidp_device(crtc);
|
|
|
|
struct malidp_hw_device *hwdev = malidp->dev;
|
|
|
|
|
|
|
|
malidp_hw_disable_irq(hwdev, MALIDP_DE_BLOCK,
|
2017-08-31 22:48:43 +08:00
|
|
|
hwdev->hw->map.de_irq_map.vsync_irq);
|
2017-02-07 17:16:17 +08:00
|
|
|
}
|
|
|
|
|
2016-03-07 18:00:53 +08:00
|
|
|
static const struct drm_crtc_funcs malidp_crtc_funcs = {
|
2017-02-01 22:48:50 +08:00
|
|
|
.gamma_set = drm_atomic_helper_legacy_gamma_set,
|
2016-03-07 18:00:53 +08:00
|
|
|
.destroy = drm_crtc_cleanup,
|
|
|
|
.set_config = drm_atomic_helper_set_config,
|
|
|
|
.page_flip = drm_atomic_helper_page_flip,
|
2017-02-01 22:48:49 +08:00
|
|
|
.reset = malidp_crtc_reset,
|
|
|
|
.atomic_duplicate_state = malidp_crtc_duplicate_state,
|
|
|
|
.atomic_destroy_state = malidp_crtc_destroy_state,
|
2017-02-07 17:16:17 +08:00
|
|
|
.enable_vblank = malidp_crtc_enable_vblank,
|
|
|
|
.disable_vblank = malidp_crtc_disable_vblank,
|
2016-03-07 18:00:53 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
int malidp_crtc_init(struct drm_device *drm)
|
|
|
|
{
|
|
|
|
struct malidp_drm *malidp = drm->dev_private;
|
|
|
|
struct drm_plane *primary = NULL, *plane;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = malidp_de_planes_init(drm);
|
|
|
|
if (ret < 0) {
|
|
|
|
DRM_ERROR("Failed to initialise planes\n");
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
drm_for_each_plane(plane, drm) {
|
|
|
|
if (plane->type == DRM_PLANE_TYPE_PRIMARY) {
|
|
|
|
primary = plane;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!primary) {
|
|
|
|
DRM_ERROR("no primary plane found\n");
|
2018-01-18 05:55:29 +08:00
|
|
|
return -EINVAL;
|
2016-03-07 18:00:53 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
ret = drm_crtc_init_with_planes(drm, &malidp->crtc, primary, NULL,
|
|
|
|
&malidp_crtc_funcs, NULL);
|
2017-02-01 22:48:50 +08:00
|
|
|
if (ret)
|
2018-01-18 05:55:29 +08:00
|
|
|
return ret;
|
2016-03-07 18:00:53 +08:00
|
|
|
|
2017-02-01 22:48:50 +08:00
|
|
|
drm_crtc_helper_add(&malidp->crtc, &malidp_crtc_helper_funcs);
|
|
|
|
drm_mode_crtc_set_gamma_size(&malidp->crtc, MALIDP_GAMMA_LUT_SIZE);
|
2017-02-06 20:20:56 +08:00
|
|
|
/* No inverse-gamma: it is per-plane. */
|
2017-02-13 20:49:03 +08:00
|
|
|
drm_crtc_enable_color_mgmt(&malidp->crtc, 0, true, MALIDP_GAMMA_LUT_SIZE);
|
2017-02-01 22:48:50 +08:00
|
|
|
|
2017-02-06 20:20:56 +08:00
|
|
|
malidp_se_set_enh_coeffs(malidp->dev);
|
|
|
|
|
2017-02-01 22:48:50 +08:00
|
|
|
return 0;
|
2016-03-07 18:00:53 +08:00
|
|
|
}
|