Skip to content

Commit e5fa3ab

Browse files
mripardpopcornmix
authored andcommitted
drm/vc4: hdmi: Adjust HSM clock rate depending on pixel rate
The HSM clock needs to be setup at around 110% of the pixel rate. This was done previously by setting the clock rate to 148.5MHz * 108% at probe time and only check in mode_valid whether the mode pixel clock was under 148.5MHz or not. However, with 4k we need to change that frequency to a higher frequency than 148.5MHz. Let's change that logic a bit by setting the clock rate of the HSM clock to the pixel rate at encoder_enable time. This would work for the BCM2711 that support 4k resolutions and has a clock that can provide it, but we still have to take care of a 4k panel plugged on a BCM283x SoCs that wouldn't be able to use those modes, so let's define the limit in the variant. Signed-off-by: Maxime Ripard <maxime@cerno.tech>
1 parent a2fb4d4 commit e5fa3ab

2 files changed

Lines changed: 29 additions & 29 deletions

File tree

‎drivers/gpu/drm/vc4/vc4_hdmi.c‎

Lines changed: 26 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,6 @@
5252
#include "vc4_hdmi_regs.h"
5353
#include "vc4_regs.h"
5454

55-
#define HSM_CLOCK_FREQ 163682864
5655
#define CEC_CLOCK_FREQ 40000
5756

5857
static int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
@@ -326,6 +325,7 @@ static void vc4_hdmi_encoder_disable(struct drm_encoder *encoder)
326325
HDMI_WRITE(HDMI_VID_CTL,
327326
HDMI_READ(HDMI_VID_CTL) & ~VC4_HD_VID_CTL_ENABLE);
328327

328+
clk_disable_unprepare(vc4_hdmi->hsm_clock);
329329
clk_disable_unprepare(vc4_hdmi->pixel_clock);
330330

331331
ret = pm_runtime_put(&vc4_hdmi->pdev->dev);
@@ -423,6 +423,7 @@ static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
423423
struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
424424
struct vc4_hdmi_encoder *vc4_encoder = to_vc4_hdmi_encoder(encoder);
425425
bool debug_dump_regs = false;
426+
unsigned long pixel_rate, hsm_rate;
426427
int ret;
427428

428429
ret = pm_runtime_get_sync(&vc4_hdmi->pdev->dev);
@@ -431,9 +432,8 @@ static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
431432
return;
432433
}
433434

434-
ret = clk_set_rate(vc4_hdmi->pixel_clock,
435-
mode->clock * 1000 *
436-
((mode->flags & DRM_MODE_FLAG_DBLCLK) ? 2 : 1));
435+
pixel_rate = mode->clock * 1000 * ((mode->flags & DRM_MODE_FLAG_DBLCLK) ? 2 : 1);
436+
ret = clk_set_rate(vc4_hdmi->pixel_clock, pixel_rate);
437437
if (ret) {
438438
DRM_ERROR("Failed to set pixel clock rate: %d\n", ret);
439439
return;
@@ -445,6 +445,24 @@ static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
445445
return;
446446
}
447447

448+
/*
449+
* The HSM rate needs to be at 108% of the pixel clock, with a
450+
* minimum of 108MHz.
451+
*/
452+
hsm_rate = max_t(unsigned long, 108000000, (pixel_rate / 100) * 108);
453+
ret = clk_set_rate(vc4_hdmi->hsm_clock, hsm_rate);
454+
if (ret) {
455+
DRM_ERROR("Failed to set HSM clock rate: %d\n", ret);
456+
return;
457+
}
458+
459+
ret = clk_prepare_enable(vc4_hdmi->hsm_clock);
460+
if (ret) {
461+
DRM_ERROR("Failed to turn on HSM clock: %d\n", ret);
462+
clk_disable_unprepare(vc4_hdmi->pixel_clock);
463+
return;
464+
}
465+
448466
if (vc4_hdmi->variant->reset)
449467
vc4_hdmi->variant->reset(vc4_hdmi);
450468

@@ -559,11 +577,9 @@ static enum drm_mode_status
559577
vc4_hdmi_encoder_mode_valid(struct drm_encoder *encoder,
560578
const struct drm_display_mode *mode)
561579
{
562-
/* HSM clock must be 108% of the pixel clock. Additionally,
563-
* the AXI clock needs to be at least 25% of pixel clock, but
564-
* HSM ends up being the limiting factor.
565-
*/
566-
if (mode->clock > HSM_CLOCK_FREQ / (1000 * 108 / 100))
580+
struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
581+
582+
if ((mode->clock * 1000) > vc4_hdmi->variant->max_pixel_clock)
567583
return MODE_CLOCK_HIGH;
568584

569585
return MODE_OK;
@@ -1338,23 +1354,6 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
13381354
return -EPROBE_DEFER;
13391355
}
13401356

1341-
/* This is the rate that is set by the firmware. The number
1342-
* needs to be a bit higher than the pixel clock rate
1343-
* (generally 148.5Mhz).
1344-
*/
1345-
ret = clk_set_rate(vc4_hdmi->hsm_clock, HSM_CLOCK_FREQ);
1346-
if (ret) {
1347-
DRM_ERROR("Failed to set HSM clock rate: %d\n", ret);
1348-
goto err_put_i2c;
1349-
}
1350-
1351-
ret = clk_prepare_enable(vc4_hdmi->hsm_clock);
1352-
if (ret) {
1353-
DRM_ERROR("Failed to turn on HDMI state machine clock: %d\n",
1354-
ret);
1355-
goto err_put_i2c;
1356-
}
1357-
13581357
/* Only use the GPIO HPD pin if present in the DT, otherwise
13591358
* we'll use the HDMI core's register.
13601359
*/
@@ -1412,9 +1411,7 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
14121411
err_destroy_encoder:
14131412
vc4_hdmi_encoder_destroy(encoder);
14141413
err_unprepare_hsm:
1415-
clk_disable_unprepare(vc4_hdmi->hsm_clock);
14161414
pm_runtime_disable(dev);
1417-
err_put_i2c:
14181415
put_device(&vc4_hdmi->ddc->dev);
14191416

14201417
return ret;
@@ -1437,7 +1434,6 @@ static void vc4_hdmi_unbind(struct device *dev, struct device *master,
14371434
vc4_hdmi_connector_destroy(&vc4_hdmi->connector);
14381435
vc4_hdmi_encoder_destroy(&vc4_hdmi->encoder.base.base);
14391436

1440-
clk_disable_unprepare(vc4_hdmi->hsm_clock);
14411437
pm_runtime_disable(dev);
14421438

14431439
put_device(&vc4_hdmi->ddc->dev);
@@ -1460,6 +1456,7 @@ static int vc4_hdmi_dev_remove(struct platform_device *pdev)
14601456
}
14611457

14621458
static const struct vc4_hdmi_variant bcm2835_variant = {
1459+
.max_pixel_clock = 148500000,
14631460
.audio_available = true,
14641461
.cec_available = true,
14651462
.registers = vc4_hdmi_fields,

‎drivers/gpu/drm/vc4/vc4_hdmi.h‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,9 @@ struct vc4_hdmi_variant {
3838
/* Set to true when the CEC support is available */
3939
bool cec_available;
4040

41+
/* Maximum pixel clock supported by the controller (in Hz) */
42+
unsigned long long max_pixel_clock;
43+
4144
/* List of the registers available on that variant */
4245
const struct vc4_hdmi_register *registers;
4346

0 commit comments

Comments
 (0)