drm/bridge: cdns-dsi: Fix the color-shift issue
Subsystems (3)
v3 cover drm/bridge: cdns-dsi: Fix the color-shift issue
Hello all,
This series provides some crucial fixes and improvements for the Cadence's DSI TX (cdns-dsi) controller found commonly in Texas Instruments' J7 family of SoCs as well as in AM62P.
Along with that, this series aims to fix the color-shift issue that has been going on with the DSI controller. This controller requires to be enabled before the previous entity enables its stream[0]. It's a strict requirement which, if not followed, causes the colors to "shift" on the display. The fix happens in 2 steps.
1. The bridge pre_enable calls have been shifted before the crtc_enable and the bridge post_disable calls have been shifted after the crtc_disable. This has been done as per the definition of bridge pre_enable.
"The display pipe (i.e. clocks and timing signals) feeding this bridge will not yet be running when this callback is called".
Since CRTC is also a source feeding the bridge, it should not be enabled before the bridges in the pipeline are pre_enabled.
The sequence of enable after this patch will look like:
bridge[n]_pre_enable
...
bridge[1]_pre_enable
crtc_enable
encoder_enable
bridge[1]_enable
...
bridge[n]_enable
and vice-versa for the bridge chain disable sequence.
2. The cdns-dsi enable / disable sequences have now been moved to pre_enable and post_disable sequences. This is the only way to have cdns-dsi drivers be up and ready before the previous entity is enables its streaming.
The DSI also spec requires the Clock and Data Lanes be ready before the DSI TX enables its stream[0]. A patch has been added to make the code wait for that to happen. Going ahead with further DSI (and DSS configuration), while the lanes are not ready, has been found to be another reason for shift in colors.
All these patches have been tested on TI's vendor tree kernel with more devices, but for the mainline, these patches have been tested with J721E based BeagleboneAI64 along with a RaspberryPi 7" DSI panel. The extra patches can be found in the "next_dsi-v2-tests" branch of my github fork[1] for anyone who would like to test them.
Thanks,
Aradhya
[0]: Section 12.6.5.7.3: "Start-up Procedure" [For DSI TX controller]
in TDA4VM Technical Reference Manual https://www.ti.com/lit/zip/spruil1
[1]: https://github.com/aradhya07/linux-ab/tree/next_dsi-v3-finals-test
Change Log:
- Changes in v3:
- Reword the commit message for patch "drm/bridge: cdns-dsi: Fix OF node pointer".
- Add a new helper API to figure out DSI host input pixel format in patch "drm/mipi-dsi: Add helper to find input format".
- Use a common function for bridge pre-enable and enable, and bridge disable and post-disable, to avoid code duplication.
- Add T-b tag from Dominik Haller in patch 5/10. (Missed to add it in v2).
- Add R-b tag from Dmitry Baryshkov for patch 8/10.
- Changes in v2:
- Drop patch "drm/tidss: Add CRTC mode_fixup"
- Split patch "drm/bridge: cdns-dsi: Fix minor bugs" into 4 separate ones
- Drop support for early_enable/late_disable APIs and instead re-order the pre_enable / post_disable APIs to be called before / after crtc_enable / crtc_disable.
- Drop support for early_enable/late_disable in cdns-dsi and use pre_enable/post_disable APIs instead to do bridge enable/disable.
Previous versions:
v1: https://lore.kernel.org/all/[email protected]/
v2: https://lore.kernel.org/all/[email protected]/
Aradhya Bhatia (10):
drm/bridge: cdns-dsi: Fix OF node pointer
drm/bridge: cdns-dsi: Fix the phy_initialized variable drm/bridge: cdns-dsi: Fix the link and phy init order drm/bridge: cdns-dsi: Fix the clock variable for mode_valid() drm/bridge: cdns-dsi: Wait for Clk and Data Lanes to be ready drm/bridge: cdns-dsi: Reset the DCS write FIFO drm/mipi-dsi: Add helper to find input format
drm/bridge: cdns-dsi: Support atomic bridge APIs drm/atomic-helper: Re-order bridge chain pre-enable and post-disable drm/bridge: cdns-dsi: Use pre_enable/post_disable to enable/disable
.../gpu/drm/bridge/cadence/cdns-dsi-core.c | 72 +++++--- drivers/gpu/drm/drm_atomic_helper.c | 165 ++++++++++++------ drivers/gpu/drm/drm_mipi_dsi.c | 37 ++++ include/drm/drm_atomic_helper.h | 7 + include/drm/drm_mipi_dsi.h | 1 + 5 files changed, 201 insertions(+), 81 deletions(-)
base-commit: 6906a84c482f098d31486df8dc98cead21cce2d0
Signature · 1 line
2.34.1
PATCH v3 1/10 drm/bridge: cdns-dsi: Fix OF node pointer
Fix the OF node pointer passed to the of_drm_find_bridge() call to find the next bridge in the display chain.
To find the next bridge in the pipeline, we need to pass "np" - the OF node pointer of the next entity in the devicetree chain. Passing "of_node" to of_drm_find_bridge will make the function try to fetch the bridge for the cdns-dsi which is not what's required.
Fix that.
--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +1 -1
@@ -952,7 +952,7 @@ static int cdns_dsi_attach(struct mipi_dsi_host *host, bridge =drm_panel_bridge_add_typed (panel,DRM_MODE_CONNECTOR_DSI ); }else { - bridge =of_drm_find_bridge (dev->dev.of_node); + bridge =of_drm_find_bridge (np);if (!bridge) bridge =ERR_PTR (-EINVAL ); }
Signature · 1 line
2.34.1
Re: [PATCH v3 01/10] drm/bridge: cdns-dsi: Fix OF node pointer
Quoted 8 lines · Aradhya Bhatia
Fix the OF node pointer passed to the
of_drm_find_bridge()call to find the next bridge in the display chain.To find the next bridge in the pipeline, we need to pass "np" - the OF node pointer of the next entity in the devicetree chain. Passing "
of_node" toof_drm_find_bridgewill make the function try to fetch the bridge for the cdns-dsi which is not what's required.
Quoted 7 lines
Fix that.
Fixes e19233955d9e ("drm/bridge: Add Cadence DSI driver")Signed-off-by Aradhya Bhatia <[email protected]>--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Nit: consider switching to devm_drm_of_get_bridge(), which does the same.
Signature · 2 lines
With best wishes Dmitry
PATCH v3 2/10 drm/bridge: cdns-dsi: Fix the phy_initialized variable
In reply to Aradhya BhatiaUpdate the Phy initialized state to "not initialized" when the driver (and the hardware by extension) gets suspended. This will allow the Phy to get initialized again after resume.
--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 1 + 1 file changed, 1 insertion(+)
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +1 -0
@@ -1153,6 +1153,7 @@ static int __maybe_unused cdns_dsi_suspend(struct device *dev)clk_disable_unprepare (dsi->dsi_p_clk);reset_control_assert (dsi->dsi_p_rst); dsi->link_initialized = false; + dsi->phy_initialized = false;return 0 ; }
Signature · 1 line
2.34.1
Re: [PATCH v3 02/10] drm/bridge: cdns-dsi: Fix the phy_initialized variable
Quoted 15 lines · Aradhya Bhatia
Update the Phy initialized state to "not initialized" when the driver (and the hardware by extension) gets suspended. This will allow the Phy to get initialized again after resume.
Fixes e19233955d9e ("drm/bridge: Add Cadence DSI driver")Signed-off-by Aradhya Bhatia <[email protected]>--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +0
-0
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c static int __maybe_unused cdns_dsi_suspend(struct device *dev) · line 1155
Quoted 3 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +0
-0@@ -1153,6 +1153,7 @@ static int __maybe_unused cdns_dsi_suspend(struct device *dev)clk_disable_unprepare (dsi->dsi_p_clk);reset_control_assert (dsi->dsi_p_rst); dsi->link_initialized = false;
Most likely you should also call phy_exit() here. And in _remove() too.
Quoted 7 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +1
-0+ dsi->phy_initialized = false;return 0 ; }Signature · 1 line
2.34.1
Signature · 2 lines
With best wishes Dmitry
Re: [PATCH v3 02/10] drm/bridge: cdns-dsi: Fix the phy_initialized variable
Hi Dmitry,
Thanks for reviewing the patches!
Quoted 11 lines · Dmitry Baryshkov
Quoted 10 lines · Aradhya Bhatia
Update the Phy initialized state to "not initialized" when the driver (and the hardware by extension) gets suspended. This will allow the Phy to get initialized again after resume.
Fixes e19233955d9e ("drm/bridge: Add Cadence DSI driver")Signed-off-by Aradhya Bhatia <[email protected]>--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 1 + 1 file changed, 1 insertion(+)
Quoted 10 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c static int __maybe_unused cdns_dsi_suspend(struct device *dev) · line 1155
Quoted 8 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +0
-0@@ -1153,6 +1153,7 @@ static int __maybe_unused cdns_dsi_suspend(struct device *dev)clk_disable_unprepare (dsi->dsi_p_clk);reset_control_assert (dsi->dsi_p_rst); dsi->link_initialized = false;Most likely you should also call
phy_exit()here. And in_remove()too.
I agree that phy_exit should be called here. But why in _remove()? Wouldn't having phy_exit in 2 places mess up the internal ref count?
Quoted 9 lines
Quoted 8 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +1
-0+ dsi->phy_initialized = false;return 0 ; }Signature · 1 line
2.34.1
--
Regards
Aradhya
Re: [PATCH v3 02/10] drm/bridge: cdns-dsi: Fix the phy_initialized variable
Quoted 28 lines · Aradhya Bhatia
Hi Dmitry,
Thanks for reviewing the patches!
Quoted 11 lines · Dmitry Baryshkov
Quoted 10 lines · Aradhya Bhatia
Update the Phy initialized state to "not initialized" when the driver (and the hardware by extension) gets suspended. This will allow the Phy to get initialized again after resume.
Fixes e19233955d9e ("drm/bridge: Add Cadence DSI driver")Signed-off-by Aradhya Bhatia <[email protected]>--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 1 + 1 file changed, 1 insertion(+)Quoted 10 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c static int __maybe_unused cdns_dsi_suspend(struct device *dev) · line 1155
Quoted 8 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +0
-0@@ -1153,6 +1153,7 @@ static int __maybe_unused cdns_dsi_suspend(struct device *dev)clk_disable_unprepare (dsi->dsi_p_clk);reset_control_assert (dsi->dsi_p_rst); dsi->link_initialized = false;Most likely you should also call
phy_exit()here. And in_remove()too.
Quoted 2 lines
I agree that
phy_exitshould be called here. But why in_remove()? Wouldn't havingphy_exitin 2 places mess up the internal ref count?
If suspend() is going to be called in the teardown path, then it's fine to have just one call here. Otherwise you might add one guarded with if (phy_initialized) to _remove() too.
Quoted 13 lines
Quoted 10 lines
Quoted 9 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +1
-1+ dsi->phy_initialized = false;return 0 ; } --2.34.1
--
Regards
Aradhya
Signature · 2 lines
With best wishes Dmitry
Re: [PATCH v3 02/10] drm/bridge: cdns-dsi: Fix the phy_initialized variable
Quoted 29 lines · Dmitry Baryshkov
Quoted 28 lines · Aradhya Bhatia
Hi Dmitry,
Thanks for reviewing the patches!
Quoted 21 lines · Dmitry Baryshkov
Quoted 15 lines · Aradhya Bhatia
Update the Phy initialized state to "not initialized" when the driver (and the hardware by extension) gets suspended. This will allow the Phy to get initialized again after resume.
Fixes e19233955d9e ("drm/bridge: Add Cadence DSI driver")Signed-off-by Aradhya Bhatia <[email protected]>--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 1 + 1 file changed, 1 insertion(+)drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +0
-0drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c static int __maybe_unused cdns_dsi_suspend(struct device *dev) · line 1155
Quoted 3 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +0
-0@@ -1153,6 +1153,7 @@ static int __maybe_unused cdns_dsi_suspend(struct device *dev)clk_disable_unprepare (dsi->dsi_p_clk);reset_control_assert (dsi->dsi_p_rst); dsi->link_initialized = false;Most likely you should also call
phy_exit()here. And in_remove()too.
Quoted 6 lines
Quoted 2 lines
I agree that
phy_exitshould be called here. But why in_remove()? Wouldn't havingphy_exitin 2 places mess up the internal ref count?If
suspend()is going to be called in the teardown path, then it's fine to have just one call here. Otherwise you might add one guarded with if (phy_initialized) to_remove()too.
Since the _suspend() and _resume() hooks are registered for both, system sleep PM and runtime PM, the _suspend() hook does get called when I remove the cdns_dsi module using modprobe. Tested that on my setup.
I believe having phy_exit() only in _suspend() would suffice for now.
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +1
-0+ dsi->phy_initialized = false;return 0 ; }
Quoted 10 lines
Quoted 7 lines
Quoted 4 lines
Quoted 3 lines
--
2.34.1--
Regards
Aradhya
--
Regards
Aradhya
PATCH v3 3/10 drm/bridge: cdns-dsi: Fix the link and phy init order
In reply to Aradhya BhatiaThe order of init of DSI link and DSI phy is wrong. The DSI link needs to be configured before the DSI phy is getting configured. Otherwise, the D-Phy is unable to lock in on the incoming PLL Reference clock[0].
Fix the order of inits.
[0]: See section 12.6.5.7.3 "Start-up Procedure" in J721E SoC TRM
TRM Link: http://www.ti.com/lit/pdf/spruil1
--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +1 -1
@@ -775,8 +775,8 @@ static void cdns_dsi_bridge_enable(struct drm_bridge *bridge)WARN_ON_ONCE (cdns_dsi_check_conf (dsi, mode, &dsi_cfg, false)); -cdns_dsi_hs_init (dsi);cdns_dsi_init_link (dsi); +cdns_dsi_hs_init (dsi);writel (HBP_LEN (dsi_cfg.hbp) |HSA_LEN (dsi_cfg.hsa), dsi->regs +VID_HSIZE1 );
Signature · 1 line
2.34.1
PATCH v3 4/10 drm/bridge: cdns-dsi: Fix the clock variable for mode_valid()
In reply to Aradhya BhatiaAllow the D-Phy config checks to use mode->clock instead of mode->crtc_clock during mode_valid checks, like everywhere else in the driver.
--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +1 -1
@@ -574,7 +574,7 @@ static int cdns_dsi_check_conf(struct cdns_dsi *dsi,if (ret)return ret; -phy_mipi_dphy_get_default_config (mode->crtc_clock *1000 , +phy_mipi_dphy_get_default_config ((mode_valid_check ? mode->clock : mode->crtc_clock) *1000 ,mipi_dsi_pixel_format_to_bpp (output->dev->format), nlanes, phy_cfg);
Signature · 1 line
2.34.1
PATCH v3 5/10 drm/bridge: cdns-dsi: Wait for Clk and Data Lanes to be ready
In reply to Aradhya BhatiaOnce the DSI Link and DSI Phy are initialized, the code needs to wait for Clk and Data Lanes to be ready, before continuing configuration. This is in accordance with the DSI Start-up procedure, found in the Technical Reference Manual of Texas Instrument's J721E SoC[0] which houses this DSI TX controller.
If the previous bridge (or crtc/encoder) are configured pre-maturely, the input signal FIFO gets corrupt. This introduces a color-shift on the display.
Allow the driver to wait for the clk and data lanes to get ready during DSI enable.
[0]: See section 12.6.5.7.3 "Start-up Procedure" in J721E SoC TRM
TRM Link: http://www.ti.com/lit/pdf/spruil1
--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-)
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +12 -1
@@ -761,7 +761,7 @@ static void cdns_dsi_bridge_enable(struct drm_bridge *bridge)struct phy_configure_opts_mipi_dphy *phy_cfg = &output->phy_opts.mipi_dphy;unsigned long tx_byte_period;struct cdns_dsi_cfg dsi_cfg; -u32 tmp, reg_wakeup, div; +u32 tmp, reg_wakeup, div, status;int nlanes;if (WARN_ON (pm_runtime_get_sync (dsi->base.dev) <0 ))
@@ -778,6 +778,17 @@ static void cdns_dsi_bridge_enable(struct drm_bridge *bridge)cdns_dsi_init_link (dsi);cdns_dsi_hs_init (dsi); +/* +* Now that the DSI Link and DSI Phy are initialized, +* wait for the CLK and Data Lanes to be ready. +*/ + tmp =CLK_LANE_RDY ; +for (int i =0 ; i < nlanes; i++) + tmp |=DATA_LANE_RDY (i); + +WARN_ON_ONCE (readl_poll_timeout (dsi->regs +MCTL_MAIN_STS , status, + status & tmp,100 ,0 )); +writel (HBP_LEN (dsi_cfg.hbp) |HSA_LEN (dsi_cfg.hsa), dsi->regs +VID_HSIZE1 ); writel(HFP_LEN(dsi_cfg.hfp) | HACT_LEN(dsi_cfg.hact),
Signature · 1 line
2.34.1
PATCH v3 6/10 drm/bridge: cdns-dsi: Reset the DCS write FIFO
In reply to Aradhya BhatiaAllow the DCS Write FIFO in the cdns-dsi controller to reset before any DCS packet is transmitted to the DSI sink device.
The DCS FIFO reset is optional. Not all panels require it. But at least one of the DSI based panel that uses Ilitek ILI9881C (DSI to DPI bridge) doesn't work with without this reset.
--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 3 +++ 1 file changed, 3 insertions(+)
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +3 -0
@@ -1037,6 +1037,9 @@ static ssize_t cdns_dsi_transfer(struct mipi_dsi_host *host,cdns_dsi_init_link (dsi); +/* Reset the DCS Write FIFO */ +writel (0x00 , dsi->regs +DIRECT_CMD_FIFO_RST ); + ret =mipi_dsi_create_packet (&packet, msg);if (ret) goto out;
Signature · 1 line
2.34.1
Re: [PATCH v3 06/10] drm/bridge: cdns-dsi: Reset the DCS write FIFO
Quoted 6 lines · Aradhya Bhatia
Allow the DCS Write FIFO in the cdns-dsi controller to reset before any DCS packet is transmitted to the DSI sink device.
The DCS FIFO reset is optional. Not all panels require it. But at least one of the DSI based panel that uses Ilitek ILI9881C (DSI to DPI bridge) doesn't work with without this reset.
Could you please be more specific, why doesn't it work. Are there any leftover bytes in the FIFO? Is there any additional delay?
Quoted 23 lines
Signed-off-by Aradhya Bhatia <[email protected]>--- drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c | 3 +++ 1 file changed, 3 insertions(+)drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +3
-0@@ -1037,6 +1037,9 @@ static ssize_t cdns_dsi_transfer(struct mipi_dsi_host *host,cdns_dsi_init_link (dsi); +/* Reset the DCS Write FIFO */ +writel (0x00 , dsi->regs +DIRECT_CMD_FIFO_RST ); + ret =mipi_dsi_create_packet (&packet, msg);if (ret) goto out;Signature · 1 line
2.34.1
Signature · 2 lines
With best wishes Dmitry
PATCH v3 7/10 drm/mipi-dsi: Add helper to find input format
In reply to Aradhya BhatiaAdd a helper API that can be used by the DSI hosts to find the required input bus format for the given output dsi pixel format.
--- drivers/gpu/drm/drm_mipi_dsi.c | 37 ++++++++++++++++++++++++++++++++++ include/drm/drm_mipi_dsi.h | 1 + 2 files changed, 38 insertions(+)
drivers/gpu/drm/drm_mipi_dsi.c +37 -0
@@ -36,6 +36,8 @@#include <drm/drm_mipi_dsi.h> #include <drm/drm_print.h> +#include <linux/media-bus-format.h> +#include <video/mipi_display.h> /**
@@ -810,6 +812,41 @@ ssize_t mipi_dsi_generic_read(struct mipi_dsi_device *dsi, const void *params, }EXPORT_SYMBOL (mipi_dsi_generic_read); +/** +* drm_mipi_dsi_get_input_bus_fmt() - Get the required MEDIA_BUS_FMT_* based +* input pixel format for a given DSI output +* pixel format +* @dsi_format: pixel format that a DSI host needs to output +* +* Various DSI hosts can use this function during their +* &drm_bridge_funcs.atomic_get_input_bus_fmts operation to ascertain +* the MEDIA_BUS_FMT_* pixel format required as input. +* +* RETURNS: +* a 32-bit MEDIA_BUS_FMT_* value on success or 0 in case of failure. +*/ +u32 drm_mipi_dsi_get_input_bus_fmt (enum mipi_dsi_pixel_format dsi_format) +{ +switch (dsi_format) { +case MIPI_DSI_FMT_RGB888 : +return MEDIA_BUS_FMT_RGB888_1X24 ; + +case MIPI_DSI_FMT_RGB666 : +return MEDIA_BUS_FMT_RGB666_1X24_CPADHI ; + +case MIPI_DSI_FMT_RGB666_PACKED : +return MEDIA_BUS_FMT_RGB666_1X18 ; + +case MIPI_DSI_FMT_RGB565 : +return MEDIA_BUS_FMT_RGB565_1X16 ; + +default : +/* Unsupported DSI Format */ +return 0 ; + } +} +EXPORT_SYMBOL (drm_mipi_dsi_get_input_bus_fmt); +/** * mipi_dsi_dcs_write_buffer() - transmit a DCS command with payload * @dsi: DSI peripheral device
include/drm/drm_mipi_dsi.h +1 -0
@@ -258,6 +258,7 @@ ssize_t mipi_dsi_generic_write(struct mipi_dsi_device *dsi, const void *payload, size_t size);ssize_t mipi_dsi_generic_read (struct mipi_dsi_device *dsi,const void *params,size_t num_params,void *data,size_t size); +u32 drm_mipi_dsi_get_input_bus_fmt (enum mipi_dsi_pixel_format dsi_format);/** * enum mipi_dsi_dcs_tear_mode - Tearing Effect Output Line mode
Signature · 1 line
2.34.1
Re: [PATCH v3 07/10] drm/mipi-dsi: Add helper to find input format
Quoted 9 lines · Aradhya Bhatia
Add a helper API that can be used by the DSI hosts to find the required input bus format for the given output dsi pixel format.
Signed-off-by Aradhya Bhatia <[email protected]>--- drivers/gpu/drm/drm_mipi_dsi.c | 37 ++++++++++++++++++++++++++++++++++ include/drm/drm_mipi_dsi.h | 1 + 2 files changed, 38 insertions(+)
Signature · 2 lines
With best wishes Dmitry
PATCH v3 8/10 drm/bridge: cdns-dsi: Support atomic bridge APIs
In reply to Aradhya BhatiaChange the existing (and deprecated) bridge hooks, to the bridge atomic APIs.
Add drm helpers for duplicate_state, destroy_state, and bridge_reset bridge hooks.
Further add support for the input format negotiation hook.
--- .../gpu/drm/bridge/cadence/cdns-dsi-core.c | 51 ++++++++++++++++--- 1 file changed, 43 insertions(+), 8 deletions(-)
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +43 -8
@@ -655,7 +655,8 @@ cdns_dsi_bridge_mode_valid(struct drm_bridge *bridge,return MODE_OK ; } -static void cdns_dsi_bridge_disable (struct drm_bridge *bridge) +static void cdns_dsi_bridge_atomic_disable (struct drm_bridge *bridge, +struct drm_bridge_state *old_bridge_state) {struct cdns_dsi_input *input =bridge_to_cdns_dsi_input (bridge);struct cdns_dsi *dsi =input_to_dsi (input);
@@ -675,7 +676,8 @@ static void cdns_dsi_bridge_disable(struct drm_bridge *bridge)pm_runtime_put (dsi->base.dev); } -static void cdns_dsi_bridge_post_disable (struct drm_bridge *bridge) +static void cdns_dsi_bridge_atomic_post_disable (struct drm_bridge *bridge, +struct drm_bridge_state *old_bridge_state) {struct cdns_dsi_input *input =bridge_to_cdns_dsi_input (bridge);struct cdns_dsi *dsi =input_to_dsi (input);
@@ -752,7 +754,8 @@ static void cdns_dsi_init_link(struct cdns_dsi *dsi) dsi->link_initialized = true; } -static void cdns_dsi_bridge_enable (struct drm_bridge *bridge) +static void cdns_dsi_bridge_atomic_enable (struct drm_bridge *bridge, +struct drm_bridge_state *old_bridge_state) {struct cdns_dsi_input *input =bridge_to_cdns_dsi_input (bridge);struct cdns_dsi *dsi =input_to_dsi (input);
@@ -903,7 +906,8 @@ static void cdns_dsi_bridge_enable(struct drm_bridge *bridge)writel (tmp, dsi->regs +MCTL_MAIN_EN ); } -static void cdns_dsi_bridge_pre_enable (struct drm_bridge *bridge) +static void cdns_dsi_bridge_atomic_pre_enable (struct drm_bridge *bridge, +struct drm_bridge_state *old_bridge_state) {struct cdns_dsi_input *input =bridge_to_cdns_dsi_input (bridge);struct cdns_dsi *dsi =input_to_dsi (input);
@@ -915,13 +919,44 @@ static void cdns_dsi_bridge_pre_enable(struct drm_bridge *bridge)cdns_dsi_hs_init (dsi); } +static u32 *cdns_dsi_bridge_get_input_bus_fmts (struct drm_bridge *bridge, +struct drm_bridge_state *bridge_state, +struct drm_crtc_state *crtc_state, +struct drm_connector_state *conn_state, +u32 output_fmt, +unsigned int *num_input_fmts) +{ +struct cdns_dsi_input *input =bridge_to_cdns_dsi_input (bridge); +struct cdns_dsi *dsi =input_to_dsi (input); +struct cdns_dsi_output *output = &dsi->output; +u32 *input_fmts; + + *num_input_fmts =0 ; + + input_fmts =kzalloc (sizeof (*input_fmts),GFP_KERNEL ); +if (!input_fmts) +return NULL ; + + input_fmts[0 ] =drm_mipi_dsi_get_input_bus_fmt (output->dev->format); +if (!input_fmts[0 ]) +return NULL ; + + *num_input_fmts =1 ; + +return input_fmts; +} +static const struct drm_bridge_funcs cdns_dsi_bridge_funcs = { .attach = cdns_dsi_bridge_attach, .mode_valid = cdns_dsi_bridge_mode_valid, - .disable = cdns_dsi_bridge_disable, - .pre_enable = cdns_dsi_bridge_pre_enable, - .enable = cdns_dsi_bridge_enable, - .post_disable = cdns_dsi_bridge_post_disable, + .atomic_disable = cdns_dsi_bridge_atomic_disable, + .atomic_pre_enable = cdns_dsi_bridge_atomic_pre_enable, + .atomic_enable = cdns_dsi_bridge_atomic_enable, + .atomic_post_disable = cdns_dsi_bridge_atomic_post_disable, + .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, + .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state, + .atomic_reset = drm_atomic_helper_bridge_reset, + .atomic_get_input_bus_fmts = cdns_dsi_bridge_get_input_bus_fmts, }; static int cdns_dsi_attach(struct mipi_dsi_host *host,
Signature · 1 line
2.34.1
PATCH v3 9/10 drm/atomic-helper: Re-order bridge chain pre-enable and post-disable
In reply to Aradhya BhatiaMove the bridge pre_enable call before crtc enable, and the bridge post_disable call after the crtc disable.
The sequence of enable after this patch will look like:
bridge[n]_pre_enable ... bridge[1]_pre_enable crtc_enable encoder_enable bridge[1]_enable ... bridge[n]__enable
and vice-versa for the bridge chain disable sequence.
The definition of bridge pre_enable hook says that,
"The display pipe (i.e. clocks and timing signals) feeding this bridge will not yet be running when this callback is called".
Since CRTC is also a source feeding the bridge, it should not be enabled before the bridges in the pipeline are pre_enabled. Fix that by re-ordering the sequence of bridge pre_enable and bridge post_disable.
--- drivers/gpu/drm/drm_atomic_helper.c | 165 ++++++++++++++++++---------- include/drm/drm_atomic_helper.h | 7 ++ 2 files changed, 114 insertions(+), 58 deletions(-)
drivers/gpu/drm/drm_atomic_helper.c +107 -58
@@ -74,6 +74,7 @@* also shares the &struct drm_plane_helper_funcs function table with the plane * helpers. */ + static void drm_atomic_helper_plane_changed(struct drm_atomic_state *state, struct drm_plane_state *old_plane_state,
@@ -1122,11 +1123,11 @@ crtc_needs_disable(struct drm_crtc_state *old_state, }static void -disable_outputs (struct drm_device *dev,struct drm_atomic_state *old_state) +disable_encoder_brige_chain (struct drm_device *dev,struct drm_atomic_state *old_state, +enum bridge_chain_operation_type op_type) {struct drm_connector *connector;struct drm_connector_state *old_conn_state, *new_conn_state; -struct drm_crtc *crtc;struct drm_crtc_state *old_crtc_state, *new_crtc_state;int i;
@@ -1163,32 +1164,55 @@ disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)if (WARN_ON (!encoder))continue ; - funcs = encoder->helper_private; - -drm_dbg_atomic (dev,"disabling [ENCODER:%d:%s]\n" , - encoder->base.id, encoder->name); -/* * Each encoder has at most one connector (since we always steal * it away), so we won't call disable hooks twice. */ bridge =drm_bridge_chain_get_first_bridge (encoder); -drm_atomic_bridge_chain_disable (bridge, old_state); -/* Right function depends upon target state. */ -if (funcs) { -if (funcs->atomic_disable) - funcs->atomic_disable (encoder, old_state); -else if (new_conn_state->crtc && funcs->prepare) - funcs->prepare (encoder); -else if (funcs->disable) - funcs->disable (encoder); -else if (funcs->dpms) - funcs->dpms (encoder,DRM_MODE_DPMS_OFF ); - } +switch (op_type) { +case DRM_ENCODER_BRIDGE_DISABLE : + funcs = encoder->helper_private; + +drm_dbg_atomic (dev,"disabling [ENCODER:%d:%s]\n" , + encoder->base.id, encoder->name); + +drm_atomic_bridge_chain_disable (bridge, old_state); + +/* Right function depends upon target state. */ +if (funcs) { +if (funcs->atomic_disable) + funcs->atomic_disable (encoder, old_state); +else if (new_conn_state->crtc && funcs->prepare) + funcs->prepare (encoder); +else if (funcs->disable) + funcs->disable (encoder); +else if (funcs->dpms) + funcs->dpms (encoder,DRM_MODE_DPMS_OFF ); + } + +break ; + +case DRM_BRIDGE_POST_DISABLE : +drm_atomic_bridge_chain_post_disable (bridge, old_state); -drm_atomic_bridge_chain_post_disable (bridge, old_state); +break ; + +default : +drm_err (dev,"Unrecognized Encoder/Bridge Operation (%d).\n" , op_type); +break ; + } } +} + +static void +disable_outputs (struct drm_device *dev,struct drm_atomic_state *old_state) +{ +struct drm_crtc *crtc; +struct drm_crtc_state *old_crtc_state, *new_crtc_state; +int i; + +disable_encoder_brige_chain (dev, old_state,DRM_ENCODER_BRIDGE_DISABLE );for_each_oldnew_crtc_in_state (old_state, crtc, old_crtc_state, new_crtc_state, i) {const struct drm_crtc_helper_funcs *funcs;
@@ -1234,6 +1258,8 @@ disable_outputs(struct drm_device *dev, struct drm_atomic_state *old_state)if (ret ==0 )drm_crtc_vblank_put (crtc); } + +disable_encoder_brige_chain (dev, old_state,DRM_BRIDGE_POST_DISABLE ); }/**
@@ -1445,6 +1471,64 @@ static void drm_atomic_helper_commit_writebacks(struct drm_device *dev, } } +static void +enable_encoder_brige_chain (struct drm_device *dev,struct drm_atomic_state *old_state, +enum bridge_chain_operation_type op_type) +{ +struct drm_connector *connector; +struct drm_connector_state *new_conn_state; +int i; + +for_each_new_connector_in_state (old_state, connector, new_conn_state, i) { +const struct drm_encoder_helper_funcs *funcs; +struct drm_encoder *encoder; +struct drm_bridge *bridge; + +if (!new_conn_state->best_encoder) +continue ; + +if (!new_conn_state->crtc->state->active || + !drm_atomic_crtc_needs_modeset (new_conn_state->crtc->state)) +continue ; + + encoder = new_conn_state->best_encoder; + +/* +* Each encoder has at most one connector (since we always steal +* it away), so we won't call enable hooks twice. +*/ + bridge =drm_bridge_chain_get_first_bridge (encoder); + +switch (op_type) { +case DRM_BRIDGE_PRE_ENABLE : +drm_atomic_bridge_chain_pre_enable (bridge, old_state); +break ; + +case DRM_ENCODER_BRIDGE_ENABLE : + funcs = encoder->helper_private; + +drm_dbg_atomic (dev,"enabling [ENCODER:%d:%s]\n" , + encoder->base.id, encoder->name); + +if (funcs) { +if (funcs->atomic_enable) + funcs->atomic_enable (encoder, old_state); +else if (funcs->enable) + funcs->enable (encoder); +else if (funcs->commit) + funcs->commit (encoder); + } + +drm_atomic_bridge_chain_enable (bridge, old_state); +break ; + +default : +drm_err (dev,"Unrecognized Encoder/Bridge Operation (%d).\n" , op_type); +break ; + } + } +} +/** * drm_atomic_helper_commit_modeset_enables - modeset commit to enable outputs * @dev: DRM device
@@ -1465,10 +1549,10 @@ void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev,struct drm_crtc *crtc;struct drm_crtc_state *old_crtc_state;struct drm_crtc_state *new_crtc_state; -struct drm_connector *connector; -struct drm_connector_state *new_conn_state;int i; +enable_encoder_brige_chain (dev, old_state,DRM_BRIDGE_PRE_ENABLE ); +for_each_oldnew_crtc_in_state (old_state, crtc, old_crtc_state, new_crtc_state, i) {const struct drm_crtc_helper_funcs *funcs;
@@ -1491,42 +1575,7 @@ void drm_atomic_helper_commit_modeset_enables(struct drm_device *dev, } } -for_each_new_connector_in_state (old_state, connector, new_conn_state, i) { -const struct drm_encoder_helper_funcs *funcs; -struct drm_encoder *encoder; -struct drm_bridge *bridge; - -if (!new_conn_state->best_encoder) -continue ; - -if (!new_conn_state->crtc->state->active || - !drm_atomic_crtc_needs_modeset (new_conn_state->crtc->state)) -continue ; - - encoder = new_conn_state->best_encoder; - funcs = encoder->helper_private; - -drm_dbg_atomic (dev,"enabling [ENCODER:%d:%s]\n" , - encoder->base.id, encoder->name); - -/* -* Each encoder has at most one connector (since we always steal -* it away), so we won't call enable hooks twice. -*/ - bridge =drm_bridge_chain_get_first_bridge (encoder); -drm_atomic_bridge_chain_pre_enable (bridge, old_state); - -if (funcs) { -if (funcs->atomic_enable) - funcs->atomic_enable (encoder, old_state); -else if (funcs->enable) - funcs->enable (encoder); -else if (funcs->commit) - funcs->commit (encoder); - } - -drm_atomic_bridge_chain_enable (bridge, old_state); - } +enable_encoder_brige_chain (dev, old_state,DRM_ENCODER_BRIDGE_ENABLE );drm_atomic_helper_commit_writebacks (dev, old_state); }
include/drm/drm_atomic_helper.h +7 -0
@@ -43,6 +43,13 @@*/ #define DRM_PLANE_NO_SCALING (1<<16) +enum bridge_chain_operation_type { +DRM_BRIDGE_PRE_ENABLE , +DRM_BRIDGE_POST_DISABLE , +DRM_ENCODER_BRIDGE_ENABLE , +DRM_ENCODER_BRIDGE_DISABLE , +}; +struct drm_atomic_state ;struct drm_private_obj ;struct drm_private_state ;
Signature · 1 line
2.34.1
PATCH v3 10/10 drm/bridge: cdns-dsi: Use pre_enable/post_disable to enable/disable
In reply to Aradhya BhatiaThe cdns-dsi controller requires that it be turned on completely before the input DPI's source has begun streaming[0]. Not having that, allows for a small window before cdns-dsi enable and after cdns-dsi disable where the previous entity (in this case tidss's videoport) to continue streaming DPI video signals. This small window where cdns-dsi is disabled but is still receiving signals causes the input FIFO of cdns-dsi to get corrupted. This causes the colors to shift on the output display. The colors can either shift by one color component (R->G, G->B, B->R), or by two color components (R->B, G->R, B->G).
Since tidss's videoport starts streaming via crtc enable hooks, we need cdns-dsi to be up and running before that. Now that the bridges are pre_enabled before crtc is enabled, and post_disabled after crtc is disabled, use the pre_enable and post_disable hooks to get cdns-dsi ready and running before the tidss videoport to get pass the color shift issues.
[0]: See section 12.6.5.7.3 "Start-up Procedure" in J721E SoC TRM
TRM Link: http://www.ti.com/lit/pdf/spruil1
--- .../gpu/drm/bridge/cadence/cdns-dsi-core.c | 32 +++---------------- 1 file changed, 4 insertions(+), 28 deletions(-)
drivers/gpu/drm/bridge/cadence/cdns-dsi-core.c +4 -28
@@ -655,8 +655,8 @@ cdns_dsi_bridge_mode_valid(struct drm_bridge *bridge,return MODE_OK ; } -static void cdns_dsi_bridge_atomic_disable (struct drm_bridge *bridge, -struct drm_bridge_state *old_bridge_state) +static void cdns_dsi_bridge_atomic_post_disable (struct drm_bridge *bridge, +struct drm_bridge_state *old_bridge_state) {struct cdns_dsi_input *input =bridge_to_cdns_dsi_input (bridge);struct cdns_dsi *dsi =input_to_dsi (input);
@@ -676,15 +676,6 @@ static void cdns_dsi_bridge_atomic_disable(struct drm_bridge *bridge,pm_runtime_put (dsi->base.dev); } -static void cdns_dsi_bridge_atomic_post_disable (struct drm_bridge *bridge, -struct drm_bridge_state *old_bridge_state) -{ -struct cdns_dsi_input *input =bridge_to_cdns_dsi_input (bridge); -struct cdns_dsi *dsi =input_to_dsi (input); - -pm_runtime_put (dsi->base.dev); -} -static void cdns_dsi_hs_init (struct cdns_dsi *dsi) {struct cdns_dsi_output *output = &dsi->output;
@@ -754,8 +745,8 @@ static void cdns_dsi_init_link(struct cdns_dsi *dsi) dsi->link_initialized = true; } -static void cdns_dsi_bridge_atomic_enable (struct drm_bridge *bridge, -struct drm_bridge_state *old_bridge_state) +static void cdns_dsi_bridge_atomic_pre_enable (struct drm_bridge *bridge, +struct drm_bridge_state *old_bridge_state) {struct cdns_dsi_input *input =bridge_to_cdns_dsi_input (bridge);struct cdns_dsi *dsi =input_to_dsi (input);
@@ -906,19 +897,6 @@ static void cdns_dsi_bridge_atomic_enable(struct drm_bridge *bridge,writel (tmp, dsi->regs +MCTL_MAIN_EN ); } -static void cdns_dsi_bridge_atomic_pre_enable (struct drm_bridge *bridge, -struct drm_bridge_state *old_bridge_state) -{ -struct cdns_dsi_input *input =bridge_to_cdns_dsi_input (bridge); -struct cdns_dsi *dsi =input_to_dsi (input); - -if (WARN_ON (pm_runtime_get_sync (dsi->base.dev) <0 )) -return ; - -cdns_dsi_init_link (dsi); -cdns_dsi_hs_init (dsi); -} - static u32 *cdns_dsi_bridge_get_input_bus_fmts(struct drm_bridge *bridge, struct drm_bridge_state *bridge_state, struct drm_crtc_state *crtc_state,
@@ -949,9 +927,7 @@ static u32 *cdns_dsi_bridge_get_input_bus_fmts(struct drm_bridge *bridge,static const struct drm_bridge_funcs cdns_dsi_bridge_funcs = { .attach = cdns_dsi_bridge_attach, .mode_valid = cdns_dsi_bridge_mode_valid, - .atomic_disable = cdns_dsi_bridge_atomic_disable, .atomic_pre_enable = cdns_dsi_bridge_atomic_pre_enable, - .atomic_enable = cdns_dsi_bridge_atomic_enable, .atomic_post_disable = cdns_dsi_bridge_atomic_post_disable, .atomic_duplicate_state = drm_atomic_helper_bridge_duplicate_state, .atomic_destroy_state = drm_atomic_helper_bridge_destroy_state,
Signature · 1 line
2.34.1