Skip to content

Commit eea034a

Browse files
jernejskmripard
authored andcommitted
drm/bridge/synopsys: dw-hdmi: don't clobber drvdata
dw_hdmi shouldn't set drvdata since some drivers might need to store it's own data there. Rework dw_hdmi in a way to return struct dw_hdmi instead to store it in drvdata. This way drivers are responsible to store and pass structure when needed. Idea was taken from the following commit: 8242ecb ("drm/bridge/synopsys: stop clobbering drvdata") Cc: [email protected] Cc: [email protected] Cc: [email protected] Acked-by: Heiko Stuebner <[email protected]> Acked-by: Neil Armstrong <[email protected]> Reviewed-by: Archit Taneja <[email protected]> Tested-by: Heiko Stuebner <[email protected]> Signed-off-by: Jernej Skrabec <[email protected]> Signed-off-by: Maxime Ripard <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 5765916 commit eea034a

File tree

6 files changed

+60
-36
lines changed

6 files changed

+60
-36
lines changed

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

Lines changed: 13 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2543,8 +2543,6 @@ __dw_hdmi_probe(struct platform_device *pdev,
25432543
if (hdmi->i2c)
25442544
dw_hdmi_i2c_init(hdmi);
25452545

2546-
platform_set_drvdata(pdev, hdmi);
2547-
25482546
return hdmi;
25492547

25502548
err_iahb:
@@ -2594,25 +2592,23 @@ static void __dw_hdmi_remove(struct dw_hdmi *hdmi)
25942592
/* -----------------------------------------------------------------------------
25952593
* Probe/remove API, used from platforms based on the DRM bridge API.
25962594
*/
2597-
int dw_hdmi_probe(struct platform_device *pdev,
2598-
const struct dw_hdmi_plat_data *plat_data)
2595+
struct dw_hdmi *dw_hdmi_probe(struct platform_device *pdev,
2596+
const struct dw_hdmi_plat_data *plat_data)
25992597
{
26002598
struct dw_hdmi *hdmi;
26012599

26022600
hdmi = __dw_hdmi_probe(pdev, plat_data);
26032601
if (IS_ERR(hdmi))
2604-
return PTR_ERR(hdmi);
2602+
return hdmi;
26052603

26062604
drm_bridge_add(&hdmi->bridge);
26072605

2608-
return 0;
2606+
return hdmi;
26092607
}
26102608
EXPORT_SYMBOL_GPL(dw_hdmi_probe);
26112609

2612-
void dw_hdmi_remove(struct platform_device *pdev)
2610+
void dw_hdmi_remove(struct dw_hdmi *hdmi)
26132611
{
2614-
struct dw_hdmi *hdmi = platform_get_drvdata(pdev);
2615-
26162612
drm_bridge_remove(&hdmi->bridge);
26172613

26182614
__dw_hdmi_remove(hdmi);
@@ -2622,31 +2618,30 @@ EXPORT_SYMBOL_GPL(dw_hdmi_remove);
26222618
/* -----------------------------------------------------------------------------
26232619
* Bind/unbind API, used from platforms based on the component framework.
26242620
*/
2625-
int dw_hdmi_bind(struct platform_device *pdev, struct drm_encoder *encoder,
2626-
const struct dw_hdmi_plat_data *plat_data)
2621+
struct dw_hdmi *dw_hdmi_bind(struct platform_device *pdev,
2622+
struct drm_encoder *encoder,
2623+
const struct dw_hdmi_plat_data *plat_data)
26272624
{
26282625
struct dw_hdmi *hdmi;
26292626
int ret;
26302627

26312628
hdmi = __dw_hdmi_probe(pdev, plat_data);
26322629
if (IS_ERR(hdmi))
2633-
return PTR_ERR(hdmi);
2630+
return hdmi;
26342631

26352632
ret = drm_bridge_attach(encoder, &hdmi->bridge, NULL);
26362633
if (ret) {
2637-
dw_hdmi_remove(pdev);
2634+
dw_hdmi_remove(hdmi);
26382635
DRM_ERROR("Failed to initialize bridge with drm\n");
2639-
return ret;
2636+
return ERR_PTR(ret);
26402637
}
26412638

2642-
return 0;
2639+
return hdmi;
26432640
}
26442641
EXPORT_SYMBOL_GPL(dw_hdmi_bind);
26452642

2646-
void dw_hdmi_unbind(struct device *dev)
2643+
void dw_hdmi_unbind(struct dw_hdmi *hdmi)
26472644
{
2648-
struct dw_hdmi *hdmi = dev_get_drvdata(dev);
2649-
26502645
__dw_hdmi_remove(hdmi);
26512646
}
26522647
EXPORT_SYMBOL_GPL(dw_hdmi_unbind);

drivers/gpu/drm/imx/dw_hdmi-imx.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
struct imx_hdmi {
2626
struct device *dev;
2727
struct drm_encoder encoder;
28+
struct dw_hdmi *hdmi;
2829
struct regmap *regmap;
2930
};
3031

@@ -239,22 +240,28 @@ static int dw_hdmi_imx_bind(struct device *dev, struct device *master,
239240
drm_encoder_init(drm, encoder, &dw_hdmi_imx_encoder_funcs,
240241
DRM_MODE_ENCODER_TMDS, NULL);
241242

242-
ret = dw_hdmi_bind(pdev, encoder, plat_data);
243+
platform_set_drvdata(pdev, hdmi);
244+
245+
hdmi->hdmi = dw_hdmi_bind(pdev, encoder, plat_data);
243246

244247
/*
245248
* If dw_hdmi_bind() fails we'll never call dw_hdmi_unbind(),
246249
* which would have called the encoder cleanup. Do it manually.
247250
*/
248-
if (ret)
251+
if (IS_ERR(hdmi->hdmi)) {
252+
ret = PTR_ERR(hdmi->hdmi);
249253
drm_encoder_cleanup(encoder);
254+
}
250255

251256
return ret;
252257
}
253258

254259
static void dw_hdmi_imx_unbind(struct device *dev, struct device *master,
255260
void *data)
256261
{
257-
return dw_hdmi_unbind(dev);
262+
struct imx_hdmi *hdmi = dev_get_drvdata(dev);
263+
264+
dw_hdmi_unbind(hdmi->hdmi);
258265
}
259266

260267
static const struct component_ops dw_hdmi_imx_ops = {

drivers/gpu/drm/meson/meson_dw_hdmi.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ struct meson_dw_hdmi {
140140
struct clk *venci_clk;
141141
struct regulator *hdmi_supply;
142142
u32 irq_stat;
143+
struct dw_hdmi *hdmi;
143144
};
144145
#define encoder_to_meson_dw_hdmi(x) \
145146
container_of(x, struct meson_dw_hdmi, encoder)
@@ -878,9 +879,12 @@ static int meson_dw_hdmi_bind(struct device *dev, struct device *master,
878879
dw_plat_data->input_bus_format = MEDIA_BUS_FMT_YUV8_1X24;
879880
dw_plat_data->input_bus_encoding = V4L2_YCBCR_ENC_709;
880881

881-
ret = dw_hdmi_bind(pdev, encoder, &meson_dw_hdmi->dw_plat_data);
882-
if (ret)
883-
return ret;
882+
platform_set_drvdata(pdev, meson_dw_hdmi);
883+
884+
meson_dw_hdmi->hdmi = dw_hdmi_bind(pdev, encoder,
885+
&meson_dw_hdmi->dw_plat_data);
886+
if (IS_ERR(meson_dw_hdmi->hdmi))
887+
return PTR_ERR(meson_dw_hdmi->hdmi);
884888

885889
DRM_DEBUG_DRIVER("HDMI controller initialized\n");
886890

@@ -890,7 +894,9 @@ static int meson_dw_hdmi_bind(struct device *dev, struct device *master,
890894
static void meson_dw_hdmi_unbind(struct device *dev, struct device *master,
891895
void *data)
892896
{
893-
dw_hdmi_unbind(dev);
897+
struct meson_dw_hdmi *meson_dw_hdmi = dev_get_drvdata(dev);
898+
899+
dw_hdmi_unbind(meson_dw_hdmi->hdmi);
894900
}
895901

896902
static const struct component_ops meson_dw_hdmi_ops = {

drivers/gpu/drm/rcar-du/rcar_dw_hdmi.c

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,20 @@ static const struct dw_hdmi_plat_data rcar_dw_hdmi_plat_data = {
6868

6969
static int rcar_dw_hdmi_probe(struct platform_device *pdev)
7070
{
71-
return dw_hdmi_probe(pdev, &rcar_dw_hdmi_plat_data);
71+
struct dw_hdmi *hdmi;
72+
73+
hdmi = dw_hdmi_probe(pdev, &rcar_dw_hdmi_plat_data);
74+
if (IS_ERR(hdmi))
75+
return PTR_ERR(hdmi);
76+
77+
platform_set_drvdata(pdev, hdmi);
7278
}
7379

7480
static int rcar_dw_hdmi_remove(struct platform_device *pdev)
7581
{
76-
dw_hdmi_remove(pdev);
82+
struct dw_hdmi *hdmi = platform_get_drvdata(dev);
83+
84+
dw_hdmi_remove(hdmi);
7785

7886
return 0;
7987
}

drivers/gpu/drm/rockchip/dw_hdmi-rockchip.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ struct rockchip_hdmi {
4848
const struct rockchip_hdmi_chip_data *chip_data;
4949
struct clk *vpll_clk;
5050
struct clk *grf_clk;
51+
struct dw_hdmi *hdmi;
5152
};
5253

5354
#define to_rockchip_hdmi(x) container_of(x, struct rockchip_hdmi, x)
@@ -377,22 +378,28 @@ static int dw_hdmi_rockchip_bind(struct device *dev, struct device *master,
377378
drm_encoder_init(drm, encoder, &dw_hdmi_rockchip_encoder_funcs,
378379
DRM_MODE_ENCODER_TMDS, NULL);
379380

380-
ret = dw_hdmi_bind(pdev, encoder, plat_data);
381+
platform_set_drvdata(pdev, hdmi);
382+
383+
hdmi->hdmi = dw_hdmi_bind(pdev, encoder, plat_data);
381384

382385
/*
383386
* If dw_hdmi_bind() fails we'll never call dw_hdmi_unbind(),
384387
* which would have called the encoder cleanup. Do it manually.
385388
*/
386-
if (ret)
389+
if (IS_ERR(hdmi->hdmi)) {
390+
ret = PTR_ERR(hdmi->hdmi);
387391
drm_encoder_cleanup(encoder);
392+
}
388393

389394
return ret;
390395
}
391396

392397
static void dw_hdmi_rockchip_unbind(struct device *dev, struct device *master,
393398
void *data)
394399
{
395-
return dw_hdmi_unbind(dev);
400+
struct rockchip_hdmi *hdmi = dev_get_drvdata(dev);
401+
402+
dw_hdmi_unbind(hdmi->hdmi);
396403
}
397404

398405
static const struct component_ops dw_hdmi_rockchip_ops = {

include/drm/bridge/dw_hdmi.h

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -143,12 +143,13 @@ struct dw_hdmi_plat_data {
143143
unsigned long mpixelclock);
144144
};
145145

146-
int dw_hdmi_probe(struct platform_device *pdev,
147-
const struct dw_hdmi_plat_data *plat_data);
148-
void dw_hdmi_remove(struct platform_device *pdev);
149-
void dw_hdmi_unbind(struct device *dev);
150-
int dw_hdmi_bind(struct platform_device *pdev, struct drm_encoder *encoder,
151-
const struct dw_hdmi_plat_data *plat_data);
146+
struct dw_hdmi *dw_hdmi_probe(struct platform_device *pdev,
147+
const struct dw_hdmi_plat_data *plat_data);
148+
void dw_hdmi_remove(struct dw_hdmi *hdmi);
149+
void dw_hdmi_unbind(struct dw_hdmi *hdmi);
150+
struct dw_hdmi *dw_hdmi_bind(struct platform_device *pdev,
151+
struct drm_encoder *encoder,
152+
const struct dw_hdmi_plat_data *plat_data);
152153

153154
void dw_hdmi_setup_rx_sense(struct device *dev, bool hpd, bool rx_sense);
154155

0 commit comments

Comments
 (0)