Skip to content

Commit 10ee275

Browse files
Hans Verkuilanholt
authored andcommitted
drm/vc4: prepare for CEC support
In order to support CEC the hsm clock needs to be enabled in vc4_hdmi_bind(), not in vc4_hdmi_encoder_enable(). Otherwise you wouldn't be able to support CEC when there is no hotplug detect signal, which is required by some monitors that turn off the HPD when in standby, but keep the CEC bus alive so they can be woken up. The HDMI core also has to be enabled in vc4_hdmi_bind() for the same reason. Signed-off-by: Hans Verkuil <[email protected]> Signed-off-by: Eric Anholt <[email protected]> Reviewed-by: Eric Anholt <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/[email protected]
1 parent 89a15e6 commit 10ee275

File tree

1 file changed

+29
-30
lines changed

1 file changed

+29
-30
lines changed

drivers/gpu/drm/vc4/vc4_hdmi.c

Lines changed: 29 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -463,11 +463,6 @@ static void vc4_hdmi_encoder_disable(struct drm_encoder *encoder)
463463
HD_WRITE(VC4_HD_VID_CTL,
464464
HD_READ(VC4_HD_VID_CTL) & ~VC4_HD_VID_CTL_ENABLE);
465465

466-
HD_WRITE(VC4_HD_M_CTL, VC4_HD_M_SW_RST);
467-
udelay(1);
468-
HD_WRITE(VC4_HD_M_CTL, 0);
469-
470-
clk_disable_unprepare(hdmi->hsm_clock);
471466
clk_disable_unprepare(hdmi->pixel_clock);
472467

473468
ret = pm_runtime_put(&hdmi->pdev->dev);
@@ -509,16 +504,6 @@ static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
509504
return;
510505
}
511506

512-
/* This is the rate that is set by the firmware. The number
513-
* needs to be a bit higher than the pixel clock rate
514-
* (generally 148.5Mhz).
515-
*/
516-
ret = clk_set_rate(hdmi->hsm_clock, 163682864);
517-
if (ret) {
518-
DRM_ERROR("Failed to set HSM clock rate: %d\n", ret);
519-
return;
520-
}
521-
522507
ret = clk_set_rate(hdmi->pixel_clock,
523508
mode->clock * 1000 *
524509
((mode->flags & DRM_MODE_FLAG_DBLCLK) ? 2 : 1));
@@ -533,20 +518,6 @@ static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
533518
return;
534519
}
535520

536-
ret = clk_prepare_enable(hdmi->hsm_clock);
537-
if (ret) {
538-
DRM_ERROR("Failed to turn on HDMI state machine clock: %d\n",
539-
ret);
540-
clk_disable_unprepare(hdmi->pixel_clock);
541-
return;
542-
}
543-
544-
HD_WRITE(VC4_HD_M_CTL, VC4_HD_M_SW_RST);
545-
udelay(1);
546-
HD_WRITE(VC4_HD_M_CTL, 0);
547-
548-
HD_WRITE(VC4_HD_M_CTL, VC4_HD_M_ENABLE);
549-
550521
HDMI_WRITE(VC4_HDMI_SW_RESET_CONTROL,
551522
VC4_HDMI_SW_RESET_HDMI |
552523
VC4_HDMI_SW_RESET_FORMAT_DETECT);
@@ -1205,6 +1176,23 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
12051176
return -EPROBE_DEFER;
12061177
}
12071178

1179+
/* This is the rate that is set by the firmware. The number
1180+
* needs to be a bit higher than the pixel clock rate
1181+
* (generally 148.5Mhz).
1182+
*/
1183+
ret = clk_set_rate(hdmi->hsm_clock, 163682864);
1184+
if (ret) {
1185+
DRM_ERROR("Failed to set HSM clock rate: %d\n", ret);
1186+
goto err_put_i2c;
1187+
}
1188+
1189+
ret = clk_prepare_enable(hdmi->hsm_clock);
1190+
if (ret) {
1191+
DRM_ERROR("Failed to turn on HDMI state machine clock: %d\n",
1192+
ret);
1193+
goto err_put_i2c;
1194+
}
1195+
12081196
/* Only use the GPIO HPD pin if present in the DT, otherwise
12091197
* we'll use the HDMI core's register.
12101198
*/
@@ -1216,14 +1204,22 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
12161204
&hpd_gpio_flags);
12171205
if (hdmi->hpd_gpio < 0) {
12181206
ret = hdmi->hpd_gpio;
1219-
goto err_put_i2c;
1207+
goto err_unprepare_hsm;
12201208
}
12211209

12221210
hdmi->hpd_active_low = hpd_gpio_flags & OF_GPIO_ACTIVE_LOW;
12231211
}
12241212

12251213
vc4->hdmi = hdmi;
12261214

1215+
/* HDMI core must be enabled. */
1216+
if (!(HD_READ(VC4_HD_M_CTL) & VC4_HD_M_ENABLE)) {
1217+
HD_WRITE(VC4_HD_M_CTL, VC4_HD_M_SW_RST);
1218+
udelay(1);
1219+
HD_WRITE(VC4_HD_M_CTL, 0);
1220+
1221+
HD_WRITE(VC4_HD_M_CTL, VC4_HD_M_ENABLE);
1222+
}
12271223
pm_runtime_enable(dev);
12281224

12291225
drm_encoder_init(drm, hdmi->encoder, &vc4_hdmi_encoder_funcs,
@@ -1244,6 +1240,8 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
12441240

12451241
err_destroy_encoder:
12461242
vc4_hdmi_encoder_destroy(hdmi->encoder);
1243+
err_unprepare_hsm:
1244+
clk_disable_unprepare(hdmi->hsm_clock);
12471245
pm_runtime_disable(dev);
12481246
err_put_i2c:
12491247
put_device(&hdmi->ddc->dev);
@@ -1263,6 +1261,7 @@ static void vc4_hdmi_unbind(struct device *dev, struct device *master,
12631261
vc4_hdmi_connector_destroy(hdmi->connector);
12641262
vc4_hdmi_encoder_destroy(hdmi->encoder);
12651263

1264+
clk_disable_unprepare(hdmi->hsm_clock);
12661265
pm_runtime_disable(dev);
12671266

12681267
put_device(&hdmi->ddc->dev);

0 commit comments

Comments
 (0)