53
53
#include "vc4_hdmi_regs.h"
54
54
#include "vc4_regs.h"
55
55
56
- #define HSM_CLOCK_FREQ 163682864
57
56
#define CEC_CLOCK_FREQ 40000
58
57
59
58
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)
326
325
HDMI_WRITE (HDMI_VID_CTL ,
327
326
HDMI_READ (HDMI_VID_CTL ) & ~VC4_HD_VID_CTL_ENABLE );
328
327
328
+ clk_disable_unprepare (vc4_hdmi -> hsm_clock );
329
329
clk_disable_unprepare (vc4_hdmi -> pixel_clock );
330
330
331
331
ret = pm_runtime_put (& vc4_hdmi -> pdev -> dev );
@@ -423,6 +423,7 @@ static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
423
423
struct vc4_hdmi * vc4_hdmi = encoder_to_vc4_hdmi (encoder );
424
424
struct vc4_hdmi_encoder * vc4_encoder = to_vc4_hdmi_encoder (encoder );
425
425
bool debug_dump_regs = false;
426
+ unsigned long pixel_rate , hsm_rate ;
426
427
int ret ;
427
428
428
429
ret = pm_runtime_get_sync (& vc4_hdmi -> pdev -> dev );
@@ -431,9 +432,8 @@ static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
431
432
return ;
432
433
}
433
434
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 );
437
437
if (ret ) {
438
438
DRM_ERROR ("Failed to set pixel clock rate: %d\n" , ret );
439
439
return ;
@@ -445,6 +445,36 @@ static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
445
445
return ;
446
446
}
447
447
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
+
448
478
if (vc4_hdmi -> variant -> reset )
449
479
vc4_hdmi -> variant -> reset (vc4_hdmi );
450
480
@@ -559,23 +589,9 @@ static enum drm_mode_status
559
589
vc4_hdmi_encoder_mode_valid (struct drm_encoder * encoder ,
560
590
const struct drm_display_mode * mode )
561
591
{
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 )
579
595
return MODE_CLOCK_HIGH ;
580
596
581
597
return MODE_OK ;
@@ -1348,23 +1364,6 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
1348
1364
return - EPROBE_DEFER ;
1349
1365
}
1350
1366
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
-
1368
1367
/* Only use the GPIO HPD pin if present in the DT, otherwise
1369
1368
* we'll use the HDMI core's register.
1370
1369
*/
@@ -1412,9 +1411,7 @@ static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
1412
1411
err_destroy_encoder :
1413
1412
drm_encoder_cleanup (encoder );
1414
1413
err_unprepare_hsm :
1415
- clk_disable_unprepare (vc4_hdmi -> hsm_clock );
1416
1414
pm_runtime_disable (dev );
1417
- err_put_i2c :
1418
1415
put_device (& vc4_hdmi -> ddc -> dev );
1419
1416
1420
1417
return ret ;
@@ -1453,7 +1450,6 @@ static void vc4_hdmi_unbind(struct device *dev, struct device *master,
1453
1450
vc4_hdmi_connector_destroy (& vc4_hdmi -> connector );
1454
1451
drm_encoder_cleanup (& vc4_hdmi -> encoder .base .base );
1455
1452
1456
- clk_disable_unprepare (vc4_hdmi -> hsm_clock );
1457
1453
pm_runtime_disable (dev );
1458
1454
1459
1455
put_device (& vc4_hdmi -> ddc -> dev );
@@ -1478,6 +1474,7 @@ static int vc4_hdmi_dev_remove(struct platform_device *pdev)
1478
1474
static const struct vc4_hdmi_variant bcm2835_variant = {
1479
1475
.encoder_type = VC4_ENCODER_TYPE_HDMI0 ,
1480
1476
.debugfs_name = "hdmi_regs" ,
1477
+ .max_pixel_clock = 162000000 ,
1481
1478
.cec_available = true,
1482
1479
.registers = vc4_hdmi_fields ,
1483
1480
.num_registers = ARRAY_SIZE (vc4_hdmi_fields ),
0 commit comments