Commit 033bfe75 authored by Boris Brezillon's avatar Boris Brezillon

drm/vc4: dsi: Fix bridge chain handling

Commit 05193dc3 ("drm/bridge: Make the bridge chain a double-linked
list") patched the bridge chain logic to use a double-linked list instead
of a single-linked list. This change induced changes to the VC4 driver
which was manually resetting the encoder->bridge element to NULL to
control the enable/disable sequence of the bridge chain. During this
conversion, 2 bugs were introduced:

1/ list_splice() was used to move chain elements to our own internal
   chain, but list_splice() does not reset the source list to an empty
   state, leading to unexpected bridge hook calls when
   drm_bridge_chain_xxx() helpers were called by the core. Replacing
   those list_splice() calls by list_splice_init() ones fixes this
   problem.

2/ drm_bridge_chain_xxx() helpers operate on the
   bridge->encoder->bridge_chain list, which is now empty. When the
   helper uses list_for_each_entry_reverse() we end up with no operation
   done which is not what we want. But that's even worse when the helper
   uses list_for_each_entry_from(), because in that case we end up in
   an infinite loop searching for the list head element which is no
   longer encoder->bridge_chain but vc4_dsi->bridge_chain. To address
   that problem we stop using the bridge chain helpers and call the
   hooks directly.
Reported-by: default avatarMarek Szyprowski <m.szyprowski@samsung.com>
Cc: Eric Anholt <eric@anholt.net>
Fixes: 05193dc3 ("drm/bridge: Make the bridge chain a double-linked list")
Signed-off-by: default avatarBoris Brezillon <boris.brezillon@collabora.com>
Reviewed-by: default avatarAndrzej Hajda <a.hajda@samsung.com>
Acked-by: default avatarEric Anholt <eric@anholt.net>
Link: https://patchwork.freedesktop.org/patch/msgid/20191227144124.210294-2-boris.brezillon@collabora.com
parent 2ec1431f
...@@ -753,10 +753,19 @@ static void vc4_dsi_encoder_disable(struct drm_encoder *encoder) ...@@ -753,10 +753,19 @@ static void vc4_dsi_encoder_disable(struct drm_encoder *encoder)
struct vc4_dsi_encoder *vc4_encoder = to_vc4_dsi_encoder(encoder); struct vc4_dsi_encoder *vc4_encoder = to_vc4_dsi_encoder(encoder);
struct vc4_dsi *dsi = vc4_encoder->dsi; struct vc4_dsi *dsi = vc4_encoder->dsi;
struct device *dev = &dsi->pdev->dev; struct device *dev = &dsi->pdev->dev;
struct drm_bridge *iter;
list_for_each_entry_reverse(iter, &dsi->bridge_chain, chain_node) {
if (iter->funcs->disable)
iter->funcs->disable(iter);
}
drm_bridge_chain_disable(dsi->bridge);
vc4_dsi_ulps(dsi, true); vc4_dsi_ulps(dsi, true);
drm_bridge_chain_post_disable(dsi->bridge);
list_for_each_entry_from(iter, &dsi->bridge_chain, chain_node) {
if (iter->funcs->post_disable)
iter->funcs->post_disable(iter);
}
clk_disable_unprepare(dsi->pll_phy_clock); clk_disable_unprepare(dsi->pll_phy_clock);
clk_disable_unprepare(dsi->escape_clock); clk_disable_unprepare(dsi->escape_clock);
...@@ -824,6 +833,7 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder) ...@@ -824,6 +833,7 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
struct vc4_dsi *dsi = vc4_encoder->dsi; struct vc4_dsi *dsi = vc4_encoder->dsi;
struct device *dev = &dsi->pdev->dev; struct device *dev = &dsi->pdev->dev;
bool debug_dump_regs = false; bool debug_dump_regs = false;
struct drm_bridge *iter;
unsigned long hs_clock; unsigned long hs_clock;
u32 ui_ns; u32 ui_ns;
/* Minimum LP state duration in escape clock cycles. */ /* Minimum LP state duration in escape clock cycles. */
...@@ -1056,7 +1066,10 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder) ...@@ -1056,7 +1066,10 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
vc4_dsi_ulps(dsi, false); vc4_dsi_ulps(dsi, false);
drm_bridge_chain_pre_enable(dsi->bridge); list_for_each_entry_reverse(iter, &dsi->bridge_chain, chain_node) {
if (iter->funcs->pre_enable)
iter->funcs->pre_enable(iter);
}
if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) { if (dsi->mode_flags & MIPI_DSI_MODE_VIDEO) {
DSI_PORT_WRITE(DISP0_CTRL, DSI_PORT_WRITE(DISP0_CTRL,
...@@ -1073,7 +1086,10 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder) ...@@ -1073,7 +1086,10 @@ static void vc4_dsi_encoder_enable(struct drm_encoder *encoder)
DSI_DISP0_ENABLE); DSI_DISP0_ENABLE);
} }
drm_bridge_chain_enable(dsi->bridge); list_for_each_entry(iter, &dsi->bridge_chain, chain_node) {
if (iter->funcs->enable)
iter->funcs->enable(iter);
}
if (debug_dump_regs) { if (debug_dump_regs) {
struct drm_printer p = drm_info_printer(&dsi->pdev->dev); struct drm_printer p = drm_info_printer(&dsi->pdev->dev);
...@@ -1613,7 +1629,7 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data) ...@@ -1613,7 +1629,7 @@ static int vc4_dsi_bind(struct device *dev, struct device *master, void *data)
* from our driver, since we need to sequence them within the * from our driver, since we need to sequence them within the
* encoder's enable/disable paths. * encoder's enable/disable paths.
*/ */
list_splice(&dsi->encoder->bridge_chain, &dsi->bridge_chain); list_splice_init(&dsi->encoder->bridge_chain, &dsi->bridge_chain);
if (dsi->port == 0) if (dsi->port == 0)
vc4_debugfs_add_regset32(drm, "dsi0_regs", &dsi->regset); vc4_debugfs_add_regset32(drm, "dsi0_regs", &dsi->regset);
...@@ -1639,7 +1655,7 @@ static void vc4_dsi_unbind(struct device *dev, struct device *master, ...@@ -1639,7 +1655,7 @@ static void vc4_dsi_unbind(struct device *dev, struct device *master,
* Restore the bridge_chain so the bridge detach procedure can happen * Restore the bridge_chain so the bridge detach procedure can happen
* normally. * normally.
*/ */
list_splice(&dsi->bridge_chain, &dsi->encoder->bridge_chain); list_splice_init(&dsi->bridge_chain, &dsi->encoder->bridge_chain);
vc4_dsi_encoder_destroy(dsi->encoder); vc4_dsi_encoder_destroy(dsi->encoder);
if (dsi->port == 1) if (dsi->port == 1)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment