Skip to content

Commit cd4cb49

Browse files
committed
drm/vc4: hdmi: Adjust HSM clock rate depending on pixel rate
The HSM clock needs to be setup at around 101% of the pixel rate. This was done previously by setting the clock rate to 163.7MHz at probe time and only check in mode_valid whether the mode pixel clock was under the pixel clock +1% or not. However, with 4k we need to change that frequency to a higher frequency than 163.7MHz, and yet want to have the lowest clock as possible to have a decent power saving. 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 <[email protected]> Tested-by: Chanwoo Choi <[email protected]> Tested-by: Hoegeun Kwon <[email protected]> Tested-by: Stefan Wahren <[email protected]> Reviewed-by: Dave Stevenson <[email protected]> Link: https://patchwork.freedesktop.org/patch/msgid/7e692ddc231d33dd671e70ea04dd1dcf56c1ecb3.1599120059.git-series.maxime@cerno.tech
1 parent 11a1731 commit cd4cb49

File tree

2 files changed

+41
-41
lines changed

2 files changed

+41
-41
lines changed

drivers/gpu/drm/vc4/vc4_hdmi.c

Lines changed: 38 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,6 @@
5353
#include "vc4_hdmi_regs.h"
5454
#include "vc4_regs.h"
5555

56-
#define HSM_CLOCK_FREQ 163682864
5756
#define CEC_CLOCK_FREQ 40000
5857

5958
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,36 @@ static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
445445
return;
446446
}
447447

448+
/*
449+
* As stated in RPi's vc4 firmware "HDMI state machine (HSM) clock must
450+
* be faster than pixel clock, infinitesimally faster, tested in
451+
* simulation. Otherwise, exact value is unimportant for HDMI
452+
* operation." This conflicts with bcm2835's vc4 documentation, which
453+
* states HSM's clock has to be at least 108% of the pixel clock.
454+
*
455+
* Real life tests reveal that vc4's firmware statement holds up, and
456+
* users are able to use pixel clocks closer to HSM's, namely for
457+
* 1920x1200@60Hz. So it was decided to have leave a 1% margin between
458+
* both clocks. Which, for RPi0-3 implies a maximum pixel clock of
459+
* 162MHz.
460+
*
461+
* Additionally, the AXI clock needs to be at least 25% of
462+
* pixel clock, but HSM ends up being the limiting factor.
463+
*/
464+
hsm_rate = max_t(unsigned long, 120000000, (pixel_rate / 100) * 101);
465+
ret = clk_set_rate(vc4_hdmi->hsm_clock, hsm_rate);
466+
if (ret) {
467+
DRM_ERROR("Failed to set HSM clock rate: %d\n", ret);
468+
return;
469+
}
470+
471+
ret = clk_prepare_enable(vc4_hdmi->hsm_clock);
472+
if (ret) {
473+
DRM_ERROR("Failed to turn on HSM clock: %d\n", ret);
474+
clk_disable_unprepare(vc4_hdmi->pixel_clock);
475+
return;
476+
}
477+
448478
if (vc4_hdmi->variant->reset)
449479
vc4_hdmi->variant->reset(vc4_hdmi);
450480

@@ -559,23 +589,9 @@ static enum drm_mode_status
559589
vc4_hdmi_encoder_mode_valid(struct drm_encoder *encoder,
560590
const struct drm_display_mode *mode)
561591
{
562-
/*
563-
* As stated in RPi's vc4 firmware "HDMI state machine (HSM) clock must
564-
* be faster than pixel clock, infinitesimally faster, tested in
565-
* simulation. Otherwise, exact value is unimportant for HDMI
566-
* operation." This conflicts with bcm2835's vc4 documentation, which
567-
* states HSM's clock has to be at least 108% of the pixel clock.
568-
*
569-
* Real life tests reveal that vc4's firmware statement holds up, and
570-
* users are able to use pixel clocks closer to HSM's, namely for
571-
* 1920x1200@60Hz. So it was decided to have leave a 1% margin between
572-
* both clocks. Which, for RPi0-3 implies a maximum pixel clock of
573-
* 162MHz.
574-
*
575-
* Additionally, the AXI clock needs to be at least 25% of
576-
* pixel clock, but HSM ends up being the limiting factor.
577-
*/
578-
if (mode->clock > HSM_CLOCK_FREQ / (1000 * 101 / 100))
592+
struct vc4_hdmi *vc4_hdmi = encoder_to_vc4_hdmi(encoder);
593+
594+
if ((mode->clock * 1000) > vc4_hdmi->variant->max_pixel_clock)
579595
return MODE_CLOCK_HIGH;
580596

581597
return MODE_OK;
@@ -1348,23 +1364,6 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
13481364
return -EPROBE_DEFER;
13491365
}
13501366

1351-
/* This is the rate that is set by the firmware. The number
1352-
* needs to be a bit higher than the pixel clock rate
1353-
* (generally 148.5Mhz).
1354-
*/
1355-
ret = clk_set_rate(vc4_hdmi->hsm_clock, HSM_CLOCK_FREQ);
1356-
if (ret) {
1357-
DRM_ERROR("Failed to set HSM clock rate: %d\n", ret);
1358-
goto err_put_i2c;
1359-
}
1360-
1361-
ret = clk_prepare_enable(vc4_hdmi->hsm_clock);
1362-
if (ret) {
1363-
DRM_ERROR("Failed to turn on HDMI state machine clock: %d\n",
1364-
ret);
1365-
goto err_put_i2c;
1366-
}
1367-
13681367
/* Only use the GPIO HPD pin if present in the DT, otherwise
13691368
* we'll use the HDMI core's register.
13701369
*/
@@ -1412,9 +1411,7 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
14121411
err_destroy_encoder:
14131412
drm_encoder_cleanup(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;
@@ -1453,7 +1450,6 @@ static void vc4_hdmi_unbind(struct device *dev, struct device *master,
14531450
vc4_hdmi_connector_destroy(&vc4_hdmi->connector);
14541451
drm_encoder_cleanup(&vc4_hdmi->encoder.base.base);
14551452

1456-
clk_disable_unprepare(vc4_hdmi->hsm_clock);
14571453
pm_runtime_disable(dev);
14581454

14591455
put_device(&vc4_hdmi->ddc->dev);
@@ -1478,6 +1474,7 @@ static int vc4_hdmi_dev_remove(struct platform_device *pdev)
14781474
static const struct vc4_hdmi_variant bcm2835_variant = {
14791475
.encoder_type = VC4_ENCODER_TYPE_HDMI0,
14801476
.debugfs_name = "hdmi_regs",
1477+
.max_pixel_clock = 162000000,
14811478
.cec_available = true,
14821479
.registers = vc4_hdmi_fields,
14831480
.num_registers = ARRAY_SIZE(vc4_hdmi_fields),

drivers/gpu/drm/vc4/vc4_hdmi.h

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

39+
/* Maximum pixel clock supported by the controller (in Hz) */
40+
unsigned long long max_pixel_clock;
41+
3942
/* List of the registers available on that variant */
4043
const struct vc4_hdmi_register *registers;
4144

0 commit comments

Comments
 (0)