<div dir="ltr">laurent,<br>
<br>
Please review or give some feedback.</div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, Aug 25, 2020 at 7:57 PM Vinay Simha B N <<a href="mailto:simhavcs@gmail.com">simhavcs@gmail.com</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">laurent,<br>
<br>
Please review or give some feedback.<br>
<br>
On Thu, Aug 13, 2020 at 9:09 PM Vinay Simha B N <<a href="mailto:simhavcs@gmail.com" target="_blank">simhavcs@gmail.com</a>> wrote:<br>
><br>
> laurent,<br>
><br>
> The code sequence was a problem. *num_inputs_fmts =<br>
> ARRAY_SIZE(tc_lvds_in_bus_fmts); should come first and then allocate<br>
> the kcalloc.<br>
><br>
> input_fmts = kcalloc(*num_input_fmts, ARRAY_SIZE(tc_lvds_in_bus_fmts),<br>
> GFP_KERNEL);<br>
> ..<br>
> for (i = 0; i < ARRAY_SIZE(tc_lvds_in_bus_fmts); ++i)<br>
> input_fmts[i] = tc_lvds_in_bus_fmts[i];<br>
><br>
> *num_inputs_fmts = ARRAY_SIZE(tc_lvds_in_bus_fmts);<br>
><br>
> So, internally in the drm pipeline get set the input format based on<br>
> the output formats?<br>
><br>
> On Wed, Aug 12, 2020 at 10:45 PM Vinay Simha B N <<a href="mailto:simhavcs@gmail.com" target="_blank">simhavcs@gmail.com</a>> wrote:<br>
> ><br>
> > laurent,<br>
> ><br>
> > if i add the .atomic_get_input_bus_fmts =<br>
> > tc_bridge_get_input_bus_fmts, with the implementation suggested,<br>
> > system does not boot fully, the reason is, we capture all the<br>
> > supported input formats, but not sure where to set the final input<br>
> > format. Please suggest.<br>
> ><br>
> > for (i = 0; i < ARRAY_SIZE(tc_lvds_in_bus_fmts); ++i)<br>
> > input_fmts[i] = tc_lvds_in_bus_fmts[i];<br>
> ><br>
> > *num_input_fmts = ARRAY_SIZE(tc_lvds_in_bus_fmts);<br>
> ><br>
> > On Wed, Aug 12, 2020 at 8:25 PM Vinay Simha B N <<a href="mailto:simhavcs@gmail.com" target="_blank">simhavcs@gmail.com</a>> wrote:<br>
> > ><br>
> > > laurent,<br>
> > ><br>
> > > Video data input format : RGB666 loosely packed 24 bits per pixel<br>
> > > Can we use MEDIA_BUS_FMT_RGB666_1X24_CPADHI? There was no information<br>
> > > wrt CPADHI or for loosely packed<br>
> > ><br>
> > > static const u32 tc_lvds_in_bus_fmts[] = {<br>
> > > MEDIA_BUS_FMT_RGB565_1X16,<br>
> > > MEDIA_BUS_FMT_RGB666_1X18,<br>
> > > MEDIA_BUS_FMT_RGB666_1X24_CPADHI,<br>
> > > MEDIA_BUS_FMT_RBG888_1X24,<br>
> > > };<br>
> > ><br>
> > > for (i = 0; i < ARRAY_SIZE(tc_lvds_in_bus_fmts); ++i)<br>
> > > input_fmts[i] = tc_lvds_in_bus_fmts[i];<br>
> > > >> This will have all the available input formats, but finally which video data input format chosen?<br>
> > > Since dsi->format = MIPI_DSI_FMT_RGB888 is used does it chooses<br>
> > > MEDIA_BUS_FMT_RBG888_1X24 by the drm pipeline<br>
> > ><br>
> > > On Wed, Aug 12, 2020 at 6:48 PM Laurent Pinchart<br>
> > > <<a href="mailto:laurent.pinchart@ideasonboard.com" target="_blank">laurent.pinchart@ideasonboard.com</a>> wrote:<br>
> > > ><br>
> > > > Hi Vinay,<br>
> > > ><br>
> > > > On Wed, Aug 12, 2020 at 06:07:52PM +0530, Vinay Simha B N wrote:<br>
> > > > > On Wed, Aug 12, 2020 at 3:24 PM Laurent Pinchart wrote:<br>
> > > > > > On Wed, Aug 12, 2020 at 12:55:50PM +0530, Vinay Simha BN wrote:<br>
> > > > > > > - bus formats read from drm_bridge_state.output_bus_cfg.format<br>
> > > > > > > and .atomic_get_input_bus_fmts() instead of connector<br>
> > > > > > ><br>
> > > > > > > Signed-off-by: Vinay Simha BN <<a href="mailto:simhavcs@gmail.com" target="_blank">simhavcs@gmail.com</a>><br>
> > > > > > ><br>
> > > > > > > ---<br>
> > > > > > > v1:<br>
> > > > > > > * Laurent Pinchart review comments incorporated<br>
> > > > > > > drm_bridge_state.output_bus_cfg.format<br>
> > > > > > > instead of connector<br>
> > > > > > > ---<br>
> > > > > > > drivers/gpu/drm/bridge/tc358775.c | 76 ++++++++++++++++++++++++++++++---------<br>
> > > > > > > 1 file changed, 59 insertions(+), 17 deletions(-)<br>
> > > > > > ><br>
> > > > > > > diff --git a/drivers/gpu/drm/bridge/tc358775.c b/drivers/gpu/drm/bridge/tc358775.c<br>
> > > > > > > index 7da15cd..5d8714a 100644<br>
> > > > > > > --- a/drivers/gpu/drm/bridge/tc358775.c<br>
> > > > > > > +++ b/drivers/gpu/drm/bridge/tc358775.c<br>
> > > > > > > @@ -271,6 +271,13 @@ struct tc_data {<br>
> > > > > > > struct gpio_desc *stby_gpio;<br>
> > > > > > > u8 lvds_link; /* single-link or dual-link */<br>
> > > > > > > u8 bpc;<br>
> > > > > > > + u32 output_bus_fmt;<br>
> > > > > > > +};<br>
> > > > > > > +<br>
> > > > > > > +static const u32 tc_lvds_out_bus_fmts[] = {<br>
> > > > > > > + MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA,<br>
> > > > > > > + MEDIA_BUS_FMT_RGB888_1X7X4_SPWG,<br>
> > > > > > > + MEDIA_BUS_FMT_RGB666_1X7X3_SPWG,<br>
> > > > > > > };<br>
> > > > > > ><br>
> > > > > > > static inline struct tc_data *bridge_to_tc(struct drm_bridge *b)<br>
> > > > > > > @@ -359,19 +366,6 @@ static void d2l_write(struct i2c_client *i2c, u16 addr, u32 val)<br>
> > > > > > > ret, addr);<br>
> > > > > > > }<br>
> > > > > > ><br>
> > > > > > > -/* helper function to access bus_formats */<br>
> > > > > > > -static struct drm_connector *get_connector(struct drm_encoder *encoder)<br>
> > > > > > > -{<br>
> > > > > > > - struct drm_device *dev = encoder->dev;<br>
> > > > > > > - struct drm_connector *connector;<br>
> > > > > > > -<br>
> > > > > > > - list_for_each_entry(connector, &dev->mode_config.connector_list, head)<br>
> > > > > > > - if (connector->encoder == encoder)<br>
> > > > > > > - return connector;<br>
> > > > > > > -<br>
> > > > > > > - return NULL;<br>
> > > > > > > -}<br>
> > > > > > > -<br>
> > > > > > > static void tc_bridge_enable(struct drm_bridge *bridge)<br>
> > > > > > > {<br>
> > > > > > > struct tc_data *tc = bridge_to_tc(bridge);<br>
> > > > > > > @@ -380,7 +374,6 @@ static void tc_bridge_enable(struct drm_bridge *bridge)<br>
> > > > > > > u32 val = 0;<br>
> > > > > > > u16 dsiclk, clkdiv, byteclk, t1, t2, t3, vsdelay;<br>
> > > > > > > struct drm_display_mode *mode;<br>
> > > > > > > - struct drm_connector *connector = get_connector(bridge->encoder);<br>
> > > > > > ><br>
> > > > > > > mode = &bridge->encoder->crtc->state->adjusted_mode;<br>
> > > > > > ><br>
> > > > > > > @@ -451,14 +444,13 @@ static void tc_bridge_enable(struct drm_bridge *bridge)<br>
> > > > > > > d2l_write(tc->i2c, LVPHY0, LV_PHY0_PRBS_ON(4) | LV_PHY0_ND(6));<br>
> > > > > > ><br>
> > > > > > > dev_dbg(tc->dev, "bus_formats %04x bpc %d\n",<br>
> > > > > > > - connector->display_info.bus_formats[0],<br>
> > > > > > > + tc->output_bus_fmt,<br>
> > > > > > > tc->bpc);<br>
> > > > > > > /*<br>
> > > > > > > * Default hardware register settings of tc358775 configured<br>
> > > > > > > * with MEDIA_BUS_FMT_RGB888_1X7X4_JEIDA jeida-24 format<br>
> > > > > > > */<br>
> > > > > > > - if (connector->display_info.bus_formats[0] ==<br>
> > > > > > > - MEDIA_BUS_FMT_RGB888_1X7X4_SPWG) {<br>
> > > > > > > + if (tc->output_bus_fmt == MEDIA_BUS_FMT_RGB888_1X7X4_SPWG) {<br>
> > > > > > > /* VESA-24 */<br>
> > > > > > > d2l_write(tc->i2c, LV_MX0003, LV_MX(LVI_R0, LVI_R1, LVI_R2, LVI_R3));<br>
> > > > > > > d2l_write(tc->i2c, LV_MX0407, LV_MX(LVI_R4, LVI_R7, LVI_R5, LVI_G0));<br>
> > > > > > > @@ -590,6 +582,51 @@ static int tc358775_parse_dt(struct device_node *np, struct tc_data *tc)<br>
> > > > > > > return 0;<br>
> > > > > > > }<br>
> > > > > > ><br>
> > > > > > > +static int tc_bridge_atomic_check(struct drm_bridge *bridge,<br>
> > > > > > > + struct drm_bridge_state *bridge_state,<br>
> > > > > > > + struct drm_crtc_state *crtc_state,<br>
> > > > > > > + struct drm_connector_state *conn_state)<br>
> > > > > > > +{<br>
> > > > > > > + struct tc_data *tc = bridge_to_tc(bridge);<br>
> > > > > > > +<br>
> > > > > > > + tc->output_bus_fmt = bridge_state->output_bus_cfg.format;<br>
> > > > > ><br>
> > > > > > .atomic_check() isn't allowed to modify the device state, neither the<br>
> > > > > > hardware state nor the software state in drm_bridge or tc_data. You can<br>
> > > > > > instead access the bridge state directly in tc_bridge_enable(), with<br>
> > > > > ><br>
> > > > > > struct drm_bridge_state *state =<br>
> > > > > > drm_priv_to_bridge_state(bridge->base.state);<br>
> > > > ><br>
> > > > > Currently the driver is picking up from the dts panel<br>
> > > > > (data-mapping = "vesa-24";) or jeida-24 or jeida-18.<br>
> > > > ><br>
> > > > > Does state->output_bus_cfg.format get set from the data-mapping?<br>
> > > ><br>
> > > > It should. The drm_panel should take care of that. In<br>
> > > > panel_simple_get_non_edid_modes(), it calls<br>
> > > ><br>
> > > > if (panel->desc->bus_format)<br>
> > > > drm_display_info_set_bus_formats(&connector->display_info,<br>
> > > > &panel->desc->bus_format, 1);<br>
> > > ><br>
> > > > to initialize the bus format in display_info. Then, the DRM bridge<br>
> > > > helper drm_atomic_bridge_chain_select_bus_fmts() retrieves the output<br>
> > > > format by calling .atomic_get_output_bus_fmts() if implemented by the<br>
> > > > last bridge in the chain, or directly from the connector display_info.<br>
> > > > The last bridge in the chain is a DRM panel bridge, and doesn't<br>
> > > > implement .atomic_get_output_bus_fmts(), so the format from display_info<br>
> > > > is used, and is stored in the output_bus_cfg.format field of this bridge<br>
> > > > in select_bus_fmt_recursive().<br>
> > > ><br>
> > > > If something doesn't work according to the plan, I can help you<br>
> > > > debugging.<br>
> > > ><br>
> > > > > > > +<br>
> > > > > > > + dev_dbg(tc->dev, "output_bus_fmt %04x\n", tc->output_bus_fmt);<br>
> > > > > > > +<br>
> > > > > > > + return 0;<br>
> > > > > > > +}<br>
> > > > > > > +<br>
> > > > > > > +static u32 *<br>
> > > > > > > +tc_bridge_get_input_bus_fmts(struct drm_bridge *bridge,<br>
> > > > > > > + struct drm_bridge_state *bridge_state,<br>
> > > > > > > + struct drm_crtc_state *crtc_state,<br>
> > > > > > > + struct drm_connector_state *conn_state,<br>
> > > > > > > + u32 output_fmt,<br>
> > > > > > > + unsigned int *num_input_fmts)<br>
> > > > > > > +{<br>
> > > > > > > + u32 *input_fmts = NULL;<br>
> > > > > > > + int i;<br>
> > > > > ><br>
> > > > > > i only takes positive values, so it can be an unsigned int.<br>
> > > > > ><br>
> > > > > > > +<br>
> > > > > > > + *num_input_fmts = 0;<br>
> > > > > > > +<br>
> > > > > > > + for (i = 0 ; i < ARRAY_SIZE(tc_lvds_out_bus_fmts) ; ++i) {<br>
> > > > > > > + if (output_fmt == tc_lvds_out_bus_fmts[i]) {<br>
> > > > > > > + *num_input_fmts = 1;<br>
> > > > > > > + input_fmts = kcalloc(*num_input_fmts,<br>
> > > > > > > + sizeof(*input_fmts),<br>
> > > > > > > + GFP_KERNEL);<br>
> > > > > > > + if (!input_fmts)<br>
> > > > > > > + return NULL;<br>
> > > > > > > +<br>
> > > > > > > + input_fmts[0] = output_fmt;<br>
> > > > > ><br>
> > > > > > I don't think this is right, the input of the bridge isn't LVDS, is it ?<br>
> > > > ><br>
> > > > > Input to the bridge is DSI, format is already set<br>
> > > > ><br>
> > > > > dsi->format = MIPI_DSI_FMT_RGB888;<br>
> > > > ><br>
> > > > > enum mipi_dsi_pixel_format {<br>
> > > > > MIPI_DSI_FMT_RGB888,<br>
> > > > > MIPI_DSI_FMT_RGB666,<br>
> > > > > MIPI_DSI_FMT_RGB666_PACKED,<br>
> > > > > MIPI_DSI_FMT_RGB565,<br>
> > > > > };<br>
> > > > > include/drm/drm_mipi_dsi.h<br>
> > > > ><br>
> > > > > Why do we require this atomic_get_input_bus_fmts?<br>
> > > > ><br>
> > > > > Do i need to implement both atomic_get_input_bus_fmts and<br>
> > > > > atomic_get_output_bus_fmts?<br>
> > > ><br>
> > > > .atomic_get_output_bus_fmts() is only need for the last bridge in the<br>
> > > > chain, and is not mandatory when that bridge supports a single format.<br>
> > > > As this bridge can't be last (if the output is connect to a panel, there<br>
> > > > will be a drm_bridge wrapping the drm_panel), you don't have to<br>
> > > > implement that operation.<br>
> > > ><br>
> > > > .atomic_get_input_bus_fmts() is used to negotiate formats along the<br>
> > > > pipeline. The helps the DRM bridge helpers figure out what formats are<br>
> > > > possible, with the help of bridges that must report what input formats<br>
> > > > are compatible with a given output format. The DRM bridge helpers will<br>
> > > > take care of the rest.<br>
> > > ><br>
> > > > So, for this bridge, the input and output formats are decoupled. The<br>
> > > > bridge can output any of the three supported LVDS formats, regardless of<br>
> > > > what format it gets at its input. You should thus verify that the output<br>
> > > > format you receive in this function is supported (and return NULL if it<br>
> > > > isn't), and then return the list of supported input formats. If you<br>
> > > > don't implement .atomic_get_input_bus_fmts(), then the DRM bridge<br>
> > > > helpers will consider that the input and output formats are the same,<br>
> > > > and will set the output format of the previous bridge to, for example,<br>
> > > > MEDIA_BUS_FMT_RGB666_1X7X3_SPWG. It may work if the previous bridge<br>
> > > > doesn't care about its output format, but if it does, then it will be<br>
> > > > puzzled, as the previous bridge outputs DSI, not LVDS.<br>
> > > ><br>
> > > > > > As far as I can tell, the hardware support transcoding any of the<br>
> > > > > > supported input formats (RGB565, RGB666 or RGB888) to any of the<br>
> > > > > > supported output formats. How about the following ?<br>
> > > > > ><br>
> > > > > > static const u32 tc_lvds_in_bus_fmts[] = {<br>
> > > > > > MEDIA_BUS_FMT_RGB565_1X16,<br>
> > > > > > MEDIA_BUS_FMT_RGB666_1X18,<br>
> > > > > > MEDIA_BUS_FMT_RBG888_1X24,<br>
> > > > > > };<br>
> > > > > ><br>
> > > > > > ...<br>
> > > > > ><br>
> > > > > > u32 *input_fmts;<br>
> > > > > > unsigned int i;<br>
> > > > > ><br>
> > > > > > *num_input_fmts = 0;<br>
> > > > > ><br>
> > > > > > for (i = 0 ; i < ARRAY_SIZE(tc_lvds_out_bus_fmts) ; ++i) {<br>
> > > > > > if (output_fmt == tc_lvds_out_bus_fmts[i])<br>
> > > > > > break;<br>
> > > > > > }<br>
> > > > > ><br>
> > > > > > if (i == ARRAY_SIZE(tc_lvds_out_bus_fmts))<br>
> > > > > > return NULL;<br>
> > > > > ><br>
> > > > > > input_fmts = kcalloc(*num_input_fmts, ARRAY_SIZE(tc_lvds_in_bus_fmts),<br>
> > > > > > GFP_KERNEL);<br>
> > > > > > if (!input_fmts)<br>
> > > > > > return NULL;<br>
> > > > > ><br>
> > > > > > for (i = 0; i < ARRAY_SIZE(tc_lvds_in_bus_fmts); ++i)<br>
> > > > > > input_fmts[i] = tc_lvds_in_bus_fmts[i];<br>
> > > > > ><br>
> > > > > > *num_inputs_fmts = ARRAY_SIZE(tc_lvds_in_bus_fmts);<br>
> > > > > > return input_fmts;<br>
> > > > > ><br>
> > > > > > > +<br>
> > > > > > > + break;<br>
> > > > > > > + }<br>
> > > > > > > + }<br>
> > > > > > > +<br>
> > > > > > > + return input_fmts;<br>
> > > > > > > +}<br>
> > > > > > > +<br>
> > > > > > > static int tc_bridge_attach(struct drm_bridge *bridge,<br>
> > > > > > > enum drm_bridge_attach_flags flags)<br>
> > > > > > > {<br>
> > > > > > > @@ -639,6 +676,11 @@ static int tc_bridge_attach(struct drm_bridge *bridge,<br>
> > > > > > > }<br>
> > > > > > ><br>
> > > > > > > static const struct drm_bridge_funcs tc_bridge_funcs = {<br>
> > > > > > > + .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state,<br>
> > > > > > > + .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,<br>
> > > > > > > + .atomic_reset = drm_atomic_helper_bridge_reset,<br>
> > > > > > > + .atomic_get_input_bus_fmts = tc_bridge_get_input_bus_fmts,<br>
> > > > > > > + .atomic_check = tc_bridge_atomic_check,<br>
> > > > > > > .attach = tc_bridge_attach,<br>
> > > > > > > .pre_enable = tc_bridge_pre_enable,<br>
> > > > > > > .enable = tc_bridge_enable,<br>
> > > ><br>
> > > > --<br>
> > > > Regards,<br>
> > > ><br>
> > > > Laurent Pinchart<br>
> > ><br>
> > ><br>
> > ><br>
> > > --<br>
> > > regards,<br>
> > > vinaysimha<br>
> ><br>
> ><br>
> ><br>
> > --<br>
> > regards,<br>
> > vinaysimha<br>
><br>
><br>
><br>
> --<br>
> regards,<br>
> vinaysimha<br>
<br>
<br>
<br>
-- <br>
regards,<br>
vinaysimha<br>
</blockquote></div><br clear="all"><br>-- <br><div dir="ltr" class="gmail_signature">regards,<br>vinaysimha</div>