Hi Lowry, On Fri, Sep 20, 2019 at 09:43:47AM +0000, Lowry Li (Arm Technology China) wrote: > From: "Lowry Li (Arm Technology China)" <lowry...@arm.com> > > 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));
Is there a specific use-case for the DT property for selecting color format? I think in general the color format should be determined according to the rules in the CEA spec. There's also the drm_mode_is_420_only() helper we can use to determine if YCBCR420 must be used. For the cases where it's optional, I think we can default to RGB444. Thanks, -Brian > > Changes since v1: > Rebased to the drm-misc-next branch. > > Signed-off-by: Lowry Li (Arm Technology China) <lowry...@arm.com> > --- > .../arm/display/komeda/d71/d71_component.c | 15 ++++++++- > .../gpu/drm/arm/display/komeda/komeda_crtc.c | 27 ++++++++++++++++ > .../gpu/drm/arm/display/komeda/komeda_dev.c | 32 ++++++++++++++++++- > .../gpu/drm/arm/display/komeda/komeda_kms.h | 2 ++ > .../drm/arm/display/komeda/komeda_pipeline.h | 3 ++ > .../display/komeda/komeda_pipeline_state.c | 31 ++++++++++++++++++ > .../arm/display/komeda/komeda_wb_connector.c | 5 +++ > 7 files changed, 113 insertions(+), 2 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 c3d29c0b051b..7b374a3b911e 100644 > --- a/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c > +++ b/drivers/gpu/drm/arm/display/komeda/d71/d71_component.c > @@ -944,13 +944,26 @@ static void d71_improc_update(struct komeda_component > *c, > { > struct komeda_improc_state *st = to_improc_st(state); > u32 __iomem *reg = c->reg; > - u32 index; > + u32 index, mask = 0, ctrl = 0; > > for_each_changed_input(state, index) > malidp_write32(reg, BLK_INPUT_ID0 + index * 4, > 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); > + > + 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 624d257da20f..38d5cb20e908 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 9cbcd56e54cd..bee4633cdd9f 100644 > --- a/drivers/gpu/drm/arm/display/komeda/komeda_dev.c > +++ b/drivers/gpu/drm/arm/display/komeda/komeda_dev.c > @@ -113,12 +113,34 @@ static struct attribute_group komeda_sysfs_attr_group = > { > .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) > @@ -133,6 +155,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 45c498e15e7a..456f3c435719 100644 > --- a/drivers/gpu/drm/arm/display/komeda/komeda_kms.h > +++ b/drivers/gpu/drm/arm/display/komeda/komeda_kms.h > @@ -166,6 +166,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 a7a84e66549d..910d279ae48d 100644 > --- a/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h > +++ b/drivers/gpu/drm/arm/display/komeda/komeda_pipeline.h > @@ -315,6 +315,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; > @@ -323,6 +325,7 @@ struct komeda_improc { > > struct komeda_improc_state { > struct komeda_component_state base; > + u8 color_format, color_depth; > u16 hsize, vsize; > }; > > 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 ea26bc9c2d00..5526731f5a33 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 @@ komeda_improc_validate(struct komeda_improc *improc, > 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 @@ komeda_improc_validate(struct komeda_improc *improc, > 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)); > + } > + > komeda_component_add_input(&st->base, &dflow->input, 0); > komeda_component_set_output(&dflow->input, &improc->base, 0); > > 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 617e1f7b8472..49e5469ba48e 100644 > --- a/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c > +++ b/drivers/gpu/drm/arm/display/komeda/komeda_wb_connector.c > @@ -142,6 +142,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; > > @@ -171,6 +172,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; > -- > 2.17.1 > _______________________________________________ dri-devel mailing list dri-devel@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/dri-devel