Skip to content

Commit 3bb80f2

Browse files
Laurent Pinchartboddob
authored andcommitted
drm: bridge: Link encoder and bridge in core code
Instead of linking encoders and bridges in every driver (and getting it wrong half of the time, as many drivers forget to set the drm_bridge encoder pointer), do so in core code. The drm_bridge_attach() function needs the encoder and optional previous bridge to perform that task, update all the callers. Signed-off-by: Laurent Pinchart <laurent.pinchart+renesas@ideasonboard.com> Acked-by: Stefan Agner <stefan@agner.ch> # For DCU Acked-by: Boris Brezillon <boris.brezillon@free-electrons.com> # For atmel-hlcdc Acked-by: Vincent Abriou <vincent.abriou@st.com> # For STI Acked-by: Maxime Ripard <maxime.ripard@free-electrons.com> # For sun4i Acked-by: Xinliang Liu <z.liuxinliang@hisilicon.com> # For hisilicon Acked-by: Jyri Sarha <jsarha@ti.com> # For tilcdc Reviewed-by: Daniel Vetter <daniel.vetter@ffwll.ch> Signed-off-by: Archit Taneja <architt@codeaurora.org> Link: http://patchwork.freedesktop.org/patch/msgid/1481709550-29226-4-git-send-email-laurent.pinchart+renesas@ideasonboard.com
1 parent 2407d1d commit 3bb80f2

25 files changed

Lines changed: 85 additions & 110 deletions

‎drivers/gpu/drm/arc/arcpgu_hdmi.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,7 @@ int arcpgu_drm_hdmi_init(struct drm_device *drm, struct device_node *np)
4747
return ret;
4848

4949
/* Link drm_bridge to encoder */
50-
bridge->encoder = encoder;
51-
encoder->bridge = bridge;
52-
53-
ret = drm_bridge_attach(drm, bridge);
50+
ret = drm_bridge_attach(encoder, bridge, NULL);
5451
if (ret)
5552
drm_encoder_cleanup(encoder);
5653

‎drivers/gpu/drm/atmel-hlcdc/atmel_hlcdc_output.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -230,9 +230,7 @@ static int atmel_hlcdc_attach_endpoint(struct drm_device *dev,
230230
of_node_put(np);
231231

232232
if (bridge) {
233-
output->encoder.bridge = bridge;
234-
bridge->encoder = &output->encoder;
235-
ret = drm_bridge_attach(dev, bridge);
233+
ret = drm_bridge_attach(&output->encoder, bridge, NULL);
236234
if (!ret)
237235
return 0;
238236
}

‎drivers/gpu/drm/bridge/analogix/analogix_dp_core.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1232,12 +1232,10 @@ static int analogix_dp_create_bridge(struct drm_device *drm_dev,
12321232

12331233
dp->bridge = bridge;
12341234

1235-
dp->encoder->bridge = bridge;
12361235
bridge->driver_private = dp;
1237-
bridge->encoder = dp->encoder;
12381236
bridge->funcs = &analogix_dp_bridge_funcs;
12391237

1240-
ret = drm_bridge_attach(drm_dev, bridge);
1238+
ret = drm_bridge_attach(dp->encoder, bridge, NULL);
12411239
if (ret) {
12421240
DRM_ERROR("failed to attach drm bridge\n");
12431241
return -EINVAL;

‎drivers/gpu/drm/bridge/dw-hdmi.c‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1841,13 +1841,12 @@ static int dw_hdmi_register(struct drm_device *drm, struct dw_hdmi *hdmi)
18411841
hdmi->bridge = bridge;
18421842
bridge->driver_private = hdmi;
18431843
bridge->funcs = &dw_hdmi_bridge_funcs;
1844-
ret = drm_bridge_attach(drm, bridge);
1844+
ret = drm_bridge_attach(encoder, bridge, NULL);
18451845
if (ret) {
18461846
DRM_ERROR("Failed to initialize bridge with drm\n");
18471847
return -EINVAL;
18481848
}
18491849

1850-
encoder->bridge = bridge;
18511850
hdmi->connector.polled = DRM_CONNECTOR_POLL_HPD;
18521851

18531852
drm_connector_helper_add(&hdmi->connector,

‎drivers/gpu/drm/drm_bridge.c‎

Lines changed: 34 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
#include <linux/mutex.h>
2727

2828
#include <drm/drm_bridge.h>
29+
#include <drm/drm_encoder.h>
2930

3031
/**
3132
* DOC: overview
@@ -92,32 +93,53 @@ void drm_bridge_remove(struct drm_bridge *bridge)
9293
EXPORT_SYMBOL(drm_bridge_remove);
9394

9495
/**
95-
* drm_bridge_attach - associate given bridge to our DRM device
96+
* drm_bridge_attach - attach the bridge to an encoder's chain
9697
*
97-
* @dev: DRM device
98-
* @bridge: bridge control structure
98+
* @encoder: DRM encoder
99+
* @bridge: bridge to attach
100+
* @previous: previous bridge in the chain (optional)
99101
*
100-
* Called by a kms driver to link one of our encoder/bridge to the given
101-
* bridge.
102+
* Called by a kms driver to link the bridge to an encoder's chain. The previous
103+
* argument specifies the previous bridge in the chain. If NULL, the bridge is
104+
* linked directly at the encoder's output. Otherwise it is linked at the
105+
* previous bridge's output.
102106
*
103-
* Note that setting up links between the bridge and our encoder/bridge
104-
* objects needs to be handled by the kms driver itself.
107+
* If non-NULL the previous bridge must be already attached by a call to this
108+
* function.
105109
*
106110
* RETURNS:
107111
* Zero on success, error code on failure
108112
*/
109-
int drm_bridge_attach(struct drm_device *dev, struct drm_bridge *bridge)
113+
int drm_bridge_attach(struct drm_encoder *encoder, struct drm_bridge *bridge,
114+
struct drm_bridge *previous)
110115
{
111-
if (!dev || !bridge)
116+
int ret;
117+
118+
if (!encoder || !bridge)
119+
return -EINVAL;
120+
121+
if (previous && (!previous->dev || previous->encoder != encoder))
112122
return -EINVAL;
113123

114124
if (bridge->dev)
115125
return -EBUSY;
116126

117-
bridge->dev = dev;
127+
bridge->dev = encoder->dev;
128+
bridge->encoder = encoder;
129+
130+
if (bridge->funcs->attach) {
131+
ret = bridge->funcs->attach(bridge);
132+
if (ret < 0) {
133+
bridge->dev = NULL;
134+
bridge->encoder = NULL;
135+
return ret;
136+
}
137+
}
118138

119-
if (bridge->funcs->attach)
120-
return bridge->funcs->attach(bridge);
139+
if (previous)
140+
previous->next = bridge;
141+
else
142+
encoder->bridge = bridge;
121143

122144
return 0;
123145
}

‎drivers/gpu/drm/drm_simple_kms_helper.c‎

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -182,9 +182,7 @@ static const struct drm_plane_funcs drm_simple_kms_plane_funcs = {
182182
int drm_simple_display_pipe_attach_bridge(struct drm_simple_display_pipe *pipe,
183183
struct drm_bridge *bridge)
184184
{
185-
bridge->encoder = &pipe->encoder;
186-
pipe->encoder.bridge = bridge;
187-
return drm_bridge_attach(pipe->encoder.dev, bridge);
185+
return drm_bridge_attach(&pipe->encoder, bridge, NULL);
188186
}
189187
EXPORT_SYMBOL(drm_simple_display_pipe_attach_bridge);
190188

‎drivers/gpu/drm/exynos/exynos_dp.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,17 +99,14 @@ static int exynos_dp_bridge_attach(struct analogix_dp_plat_data *plat_data,
9999
struct drm_connector *connector)
100100
{
101101
struct exynos_dp_device *dp = to_dp(plat_data);
102-
struct drm_encoder *encoder = &dp->encoder;
103102
int ret;
104103

105104
drm_connector_register(connector);
106105
dp->connector = connector;
107106

108107
/* Pre-empt DP connector creation if there's a bridge */
109108
if (dp->ptn_bridge) {
110-
bridge->next = dp->ptn_bridge;
111-
dp->ptn_bridge->encoder = encoder;
112-
ret = drm_bridge_attach(encoder->dev, dp->ptn_bridge);
109+
ret = drm_bridge_attach(&dp->encoder, dp->ptn_bridge, bridge);
113110
if (ret) {
114111
DRM_ERROR("Failed to attach bridge to drm\n");
115112
bridge->next = NULL;

‎drivers/gpu/drm/exynos/exynos_drm_dsi.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1718,10 +1718,8 @@ static int exynos_dsi_bind(struct device *dev, struct device *master,
17181718
}
17191719

17201720
bridge = of_drm_find_bridge(dsi->bridge_node);
1721-
if (bridge) {
1722-
encoder->bridge = bridge;
1723-
drm_bridge_attach(drm_dev, bridge);
1724-
}
1721+
if (bridge)
1722+
drm_bridge_attach(encoder, bridge, NULL);
17251723

17261724
return mipi_dsi_host_register(&dsi->dsi_host);
17271725
}

‎drivers/gpu/drm/fsl-dcu/fsl_dcu_drm_rgb.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -160,10 +160,7 @@ static int fsl_dcu_attach_endpoint(struct fsl_dcu_drm_device *fsl_dev,
160160
if (!bridge)
161161
return -ENODEV;
162162

163-
fsl_dev->encoder.bridge = bridge;
164-
bridge->encoder = &fsl_dev->encoder;
165-
166-
return drm_bridge_attach(fsl_dev->drm, bridge);
163+
return drm_bridge_attach(&fsl_dev->encoder, bridge, NULL);
167164
}
168165

169166
int fsl_dcu_create_outputs(struct fsl_dcu_drm_device *fsl_dev)

‎drivers/gpu/drm/hisilicon/kirin/dw_drm_dsi.c‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -709,10 +709,7 @@ static int dsi_bridge_init(struct drm_device *dev, struct dw_dsi *dsi)
709709
int ret;
710710

711711
/* associate the bridge to dsi encoder */
712-
encoder->bridge = bridge;
713-
bridge->encoder = encoder;
714-
715-
ret = drm_bridge_attach(dev, bridge);
712+
ret = drm_bridge_attach(encoder, bridge, NULL);
716713
if (ret) {
717714
DRM_ERROR("failed to attach external bridge\n");
718715
return ret;

0 commit comments

Comments
 (0)