[PATCH] drm/komeda: Adds output-color format/depth support

From: Lowry Li (Arm Technology China)
Date: Wed Jun 19 2019 - 05:31:54 EST


Sets color_depth according to connector->bpc.
Adds a new optional DT attribute "color-format" to represent a
preferred color formats for a specific pipeline, and the select order
is:
YCRCB420 > YCRCB422 > YCRCB444 > RGB444
The color-format can be anyone of these 4 format, one color-format not
only represent one format, but also include the lower formats, like

color-format preferred_color_formats
YCRCB420 YCRCB420 > YCRCB422 > YCRCB444 > RGB444
YCRCB422 YCRCB422 > YCRCB444 > RGB444
YCRCB444 YCRCB444 > RGB444
RGB444 RGB444

Then the final color_format is calculated by 3 steps:
1. calculate HW available formats.
avail_formats = connector_color_formats & improc->color_formats;
2. filter out un-preferred format.
avail_formats &= preferred_color_formats;
3. select the final format according to the preferred order.
color_format = BIT(__fls(aval_formats));

Signed-off-by: Lowry Li (Arm Technology China) <lowry.li@xxxxxxx>
---
.../gpu/drm/arm/display/komeda/d71/d71_component.c | 14 ++++++++--
drivers/gpu/drm/arm/display/komeda/komeda_crtc.c | 27 ++++++++++++++++++
drivers/gpu/drm/arm/display/komeda/komeda_dev.c | 32 +++++++++++++++++++++-
drivers/gpu/drm/arm/display/komeda/komeda_kms.h | 2 ++
.../gpu/drm/arm/display/komeda/komeda_pipeline.h | 3 ++
.../drm/arm/display/komeda/komeda_pipeline_state.c | 31 +++++++++++++++++++++
.../drm/arm/display/komeda/komeda_wb_connector.c | 5 ++++
7 files changed, 111 insertions(+), 3 deletions(-)

diff --git a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
index 01dd426..5135577 100644
--- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
+++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c
@@ -955,6 +955,7 @@ static void d71_improc_update(struct komeda_component *c,
to_d71_input_id(state, index));

malidp_write32(reg, BLK_SIZE, HV_SIZE(st->hsize, st->vsize));
+ malidp_write32(reg, IPS_DEPTH, st->color_depth);

if (crtc_st->color_mgmt_changed) {
mask |= IPS_CTRL_FT | IPS_CTRL_RGB;
@@ -974,8 +975,17 @@ static void d71_improc_update(struct komeda_component *c,
}
}

- if (mask)
- malidp_write32_mask(reg, BLK_CONTROL, mask, ctrl);
+ mask |= IPS_CTRL_YUV | IPS_CTRL_CHD422 | IPS_CTRL_CHD420;
+
+ /* config color format */
+ if (st->color_format == DRM_COLOR_FORMAT_YCRCB420)
+ ctrl |= IPS_CTRL_YUV | IPS_CTRL_CHD422 | IPS_CTRL_CHD420;
+ else if (st->color_format == DRM_COLOR_FORMAT_YCRCB422)
+ ctrl |= IPS_CTRL_YUV | IPS_CTRL_CHD422;
+ else if (st->color_format == DRM_COLOR_FORMAT_YCRCB444)
+ ctrl |= IPS_CTRL_YUV;
+
+ malidp_write32_mask(reg, BLK_CONTROL, mask, ctrl);
}

static void d71_improc_dump(struct komeda_component *c, struct seq_file *sf)
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
index cc6582f..ae67894 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_crtc.c
@@ -18,6 +18,33 @@
#include "komeda_dev.h"
#include "komeda_kms.h"

+void komeda_crtc_get_color_config(struct drm_crtc_state *crtc_st,
+ u32 *color_depths, u32 *color_formats)
+{
+ struct drm_connector *conn;
+ struct drm_connector_state *conn_st;
+ u32 conn_color_formats = ~0u;
+ int i, min_bpc = 31, conn_bpc = 0;
+
+ for_each_new_connector_in_state(crtc_st->state, conn, conn_st, i) {
+ if (conn_st->crtc != crtc_st->crtc)
+ continue;
+
+ conn_bpc = conn->display_info.bpc ? conn->display_info.bpc : 8;
+ conn_color_formats &= conn->display_info.color_formats;
+
+ if (conn_bpc < min_bpc)
+ min_bpc = conn_bpc;
+ }
+
+ /* connector doesn't config any color_format, use RGB444 as default */
+ if (conn_color_formats == 0)
+ conn_color_formats = DRM_COLOR_FORMAT_RGB444;
+
+ *color_depths = GENMASK(conn_bpc, 0);
+ *color_formats = conn_color_formats;
+}
+
static void komeda_crtc_update_clock_ratio(struct komeda_crtc_state *kcrtc_st)
{
u64 pxlclk, aclk;
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_dev.c b/drivers/gpu/drm/arm/display/komeda/komeda_dev.c
index 591da1e..a09de45 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_dev.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_dev.c
@@ -102,12 +102,34 @@ static void komeda_debugfs_init(struct komeda_dev *mdev)
.attrs = komeda_sysfs_entries,
};

+static int to_color_format(const char *str)
+{
+ int format;
+
+ if (!strncmp(str, "RGB444", 7)) {
+ format = DRM_COLOR_FORMAT_RGB444;
+ } else if (!strncmp(str, "YCRCB444", 9)) {
+ format = DRM_COLOR_FORMAT_YCRCB444;
+ } else if (!strncmp(str, "YCRCB422", 9)) {
+ format = DRM_COLOR_FORMAT_YCRCB422;
+ } else if (!strncmp(str, "YCRCB420", 9)) {
+ format = DRM_COLOR_FORMAT_YCRCB420;
+ } else {
+ DRM_WARN("invalid color_format: %s, please set it to RGB444, YCRCB444, YCRCB422 or YCRCB420\n",
+ str);
+ format = DRM_COLOR_FORMAT_RGB444;
+ }
+
+ return format;
+}
+
static int komeda_parse_pipe_dt(struct komeda_dev *mdev, struct device_node *np)
{
struct komeda_pipeline *pipe;
struct clk *clk;
u32 pipe_id;
- int ret = 0;
+ int ret = 0, color_format;
+ const char *str;

ret = of_property_read_u32(np, "reg", &pipe_id);
if (ret != 0 || pipe_id >= mdev->n_pipelines)
@@ -122,6 +144,14 @@ static int komeda_parse_pipe_dt(struct komeda_dev *mdev, struct device_node *np)
}
pipe->pxlclk = clk;

+ /* fetch DT configured color-format, if not set, use RGB444 */
+ if (!of_property_read_string(np, "color-format", &str))
+ color_format = to_color_format(str);
+ else
+ color_format = DRM_COLOR_FORMAT_RGB444;
+
+ pipe->improc->preferred_color_formats = (color_format << 1) - 1;
+
/* enum ports */
pipe->of_output_links[0] =
of_graph_get_remote_node(np, KOMEDA_OF_PORT_OUTPUT, 0);
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_kms.h b/drivers/gpu/drm/arm/display/komeda/komeda_kms.h
index cf2122b..dc1d436 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_kms.h
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_kms.h
@@ -180,6 +180,8 @@ static inline bool has_flip_h(u32 rot)
return !!(rotation & DRM_MODE_REFLECT_X);
}

+void komeda_crtc_get_color_config(struct drm_crtc_state *crtc_st,
+ u32 *color_depths, u32 *color_formats);
unsigned long komeda_crtc_get_aclk(struct komeda_crtc_state *kcrtc_st);

int komeda_kms_setup_crtcs(struct komeda_kms_dev *kms, struct komeda_dev *mdev);
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h
index 9a5fc35..9e84232 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h
@@ -317,6 +317,8 @@ struct komeda_splitter_state {
struct komeda_improc {
struct komeda_component base;
u32 supported_color_formats; /* DRM_RGB/YUV444/YUV420*/
+ /* the preferred order is from MSB to LSB YUV420 --> RGB444 */
+ u32 preferred_color_formats;
u32 supported_color_depths; /* BIT(8) | BIT(10)*/
u8 supports_degamma : 1;
u8 supports_csc : 1;
@@ -325,6 +327,7 @@ struct komeda_improc {

struct komeda_improc_state {
struct komeda_component_state base;
+ u8 color_format, color_depth;
u16 hsize, vsize;
u32 fgamma_coeffs[KOMEDA_N_GAMMA_COEFFS];
u32 ctm_coeffs[KOMEDA_N_CTM_COEFFS];
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c
index 796cae6..4523d28 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline_state.c
@@ -743,6 +743,7 @@ void pipeline_composition_size(struct komeda_crtc_state *kcrtc_st,
struct komeda_data_flow_cfg *dflow)
{
struct drm_crtc *crtc = kcrtc_st->base.crtc;
+ struct drm_crtc_state *crtc_st = &kcrtc_st->base;
struct komeda_component_state *c_st;
struct komeda_improc_state *st;

@@ -756,6 +757,36 @@ void pipeline_composition_size(struct komeda_crtc_state *kcrtc_st,
st->hsize = dflow->in_w;
st->vsize = dflow->in_h;

+ if (drm_atomic_crtc_needs_modeset(crtc_st)) {
+ u32 output_depths, output_formats;
+ u32 avail_depths, avail_formats;
+
+ komeda_crtc_get_color_config(crtc_st, &output_depths,
+ &output_formats);
+
+ avail_depths = output_depths & improc->supported_color_depths;
+ if (avail_depths == 0) {
+ DRM_DEBUG_ATOMIC("No available color depths, conn depths: 0x%x & display: 0x%x\n",
+ output_depths,
+ improc->supported_color_depths);
+ return -EINVAL;
+ }
+
+ avail_formats = output_formats &
+ improc->supported_color_formats &
+ improc->preferred_color_formats;
+ if (avail_formats == 0) {
+ DRM_DEBUG_ATOMIC("No available color_formats, conn formats 0x%x & display: 0x%x & preferred: 0x%x\n",
+ output_formats,
+ improc->supported_color_formats,
+ improc->preferred_color_formats);
+ return -EINVAL;
+ }
+
+ st->color_depth = __fls(avail_depths);
+ st->color_format = BIT(__fls(avail_formats));
+ }
+
if (kcrtc_st->base.color_mgmt_changed) {
drm_lut_to_fgamma_coeffs(kcrtc_st->base.gamma_lut,
st->fgamma_coeffs);
diff --git a/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c b/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c
index 4e26b27..6c43462 100644
--- a/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c
+++ b/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c
@@ -149,6 +149,7 @@ static int komeda_wb_connector_add(struct komeda_kms_dev *kms,
struct komeda_dev *mdev = kms->base.dev_private;
struct komeda_wb_connector *kwb_conn;
struct drm_writeback_connector *wb_conn;
+ struct drm_display_info *info;
u32 *formats, n_formats = 0;
int err;

@@ -178,6 +179,10 @@ static int komeda_wb_connector_add(struct komeda_kms_dev *kms,

drm_connector_helper_add(&wb_conn->base, &komeda_wb_conn_helper_funcs);

+ info = &kwb_conn->base.base.display_info;
+ info->bpc = __fls(kcrtc->master->improc->supported_color_depths);
+ info->color_formats = kcrtc->master->improc->supported_color_formats;
+
kcrtc->wb_conn = kwb_conn;

return 0;
--
1.9.1