Skip to content

Commit 128abd0

Browse files
mripardpopcornmix
authored andcommitted
drm/vc4: hdmi: Support the BCM2711 HDMI controllers
Now that the driver is ready for it, let's bring in the HDMI controllers variants for the BCM2711. Signed-off-by: Maxime Ripard <maxime@cerno.tech>
1 parent e5fa3ab commit 128abd0

4 files changed

Lines changed: 959 additions & 0 deletions

File tree

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

Lines changed: 254 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@
4242
#include <linux/of_platform.h>
4343
#include <linux/pm_runtime.h>
4444
#include <linux/rational.h>
45+
#include <linux/reset.h>
4546
#include <sound/dmaengine_pcm.h>
4647
#include <sound/pcm_drm_eld.h>
4748
#include <sound/pcm_params.h>
@@ -52,6 +53,31 @@
5253
#include "vc4_hdmi_regs.h"
5354
#include "vc4_regs.h"
5455

56+
#define VC5_HDMI_HORZA_HFP_SHIFT 16
57+
#define VC5_HDMI_HORZA_HFP_MASK VC4_MASK(28, 16)
58+
#define VC5_HDMI_HORZA_VPOS BIT(15)
59+
#define VC5_HDMI_HORZA_HPOS BIT(14)
60+
#define VC5_HDMI_HORZA_HAP_SHIFT 0
61+
#define VC5_HDMI_HORZA_HAP_MASK VC4_MASK(13, 0)
62+
63+
#define VC5_HDMI_HORZB_HBP_SHIFT 16
64+
#define VC5_HDMI_HORZB_HBP_MASK VC4_MASK(26, 16)
65+
#define VC5_HDMI_HORZB_HSP_SHIFT 0
66+
#define VC5_HDMI_HORZB_HSP_MASK VC4_MASK(10, 0)
67+
68+
#define VC5_HDMI_VERTA_VSP_SHIFT 24
69+
#define VC5_HDMI_VERTA_VSP_MASK VC4_MASK(28, 24)
70+
#define VC5_HDMI_VERTA_VFP_SHIFT 16
71+
#define VC5_HDMI_VERTA_VFP_MASK VC4_MASK(22, 16)
72+
#define VC5_HDMI_VERTA_VAL_SHIFT 0
73+
#define VC5_HDMI_VERTA_VAL_MASK VC4_MASK(12, 0)
74+
75+
#define VC5_HDMI_VERTB_VSPO_SHIFT 16
76+
#define VC5_HDMI_VERTB_VSPO_MASK VC4_MASK(29, 16)
77+
78+
# define VC4_HD_M_SW_RST BIT(2)
79+
# define VC4_HD_M_ENABLE BIT(0)
80+
5581
#define CEC_CLOCK_FREQ 40000
5682

5783
static int vc4_hdmi_debugfs_regs(struct seq_file *m, void *unused)
@@ -75,6 +101,13 @@ static void vc4_hdmi_reset(struct vc4_hdmi *vc4_hdmi)
75101
HDMI_WRITE(HDMI_SW_RESET_CONTROL, 0);
76102
}
77103

104+
static void vc5_hdmi_reset(struct vc4_hdmi *vc4_hdmi)
105+
{
106+
reset_control_reset(vc4_hdmi->reset);
107+
108+
HDMI_WRITE(HDMI_DVP_CTL, 0);
109+
}
110+
78111
static enum drm_connector_status
79112
vc4_hdmi_connector_detect(struct drm_connector *connector, bool force)
80113
{
@@ -368,6 +401,45 @@ static void vc4_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi, bool enable)
368401
HDMI_WRITE(HDMI_CSC_CTL, csc_ctl);
369402
}
370403

404+
static void vc5_hdmi_csc_setup(struct vc4_hdmi *vc4_hdmi, bool enable)
405+
{
406+
u32 csc_ctl;
407+
408+
csc_ctl = 0x07; /* RGB_CONVERT_MODE = custom matrix, || USE_RGB_TO_YCBCR */
409+
410+
if (enable) {
411+
/* CEA VICs other than #1 requre limited range RGB
412+
* output unless overridden by an AVI infoframe.
413+
* Apply a colorspace conversion to squash 0-255 down
414+
* to 16-235. The matrix here is:
415+
*
416+
* [ 0.8594 0 0 16]
417+
* [ 0 0.8594 0 16]
418+
* [ 0 0 0.8594 16]
419+
* [ 0 0 0 1]
420+
* Matrix is signed 2p13 fixed point, with signed 9p6 offsets
421+
*/
422+
HDMI_WRITE(HDMI_CSC_12_11, (0x0000 << 16) | 0x1b80);
423+
HDMI_WRITE(HDMI_CSC_14_13, (0x0400 << 16) | 0x0000);
424+
HDMI_WRITE(HDMI_CSC_22_21, (0x1b80 << 16) | 0x0000);
425+
HDMI_WRITE(HDMI_CSC_24_23, (0x0400 << 16) | 0x0000);
426+
HDMI_WRITE(HDMI_CSC_32_31, (0x0000 << 16) | 0x0000);
427+
HDMI_WRITE(HDMI_CSC_34_33, (0x0400 << 16) | 0x1b80);
428+
} else {
429+
/* Still use the matrix for full range, but make it unity.
430+
* Matrix is signed 2p13 fixed point, with signed 9p6 offsets
431+
*/
432+
HDMI_WRITE(HDMI_CSC_12_11, (0x0000 << 16) | 0x2000);
433+
HDMI_WRITE(HDMI_CSC_14_13, (0x0000 << 16) | 0x0000);
434+
HDMI_WRITE(HDMI_CSC_22_21, (0x2000 << 16) | 0x0000);
435+
HDMI_WRITE(HDMI_CSC_24_23, (0x0000 << 16) | 0x0000);
436+
HDMI_WRITE(HDMI_CSC_32_31, (0x0000 << 16) | 0x0000);
437+
HDMI_WRITE(HDMI_CSC_34_33, (0x0000 << 16) | 0x2000);
438+
}
439+
440+
HDMI_WRITE(HDMI_CSC_CTL, csc_ctl);
441+
}
442+
371443
static void vc4_hdmi_set_timings(struct vc4_hdmi *vc4_hdmi,
372444
struct drm_display_mode *mode)
373445
{
@@ -417,6 +489,58 @@ static void vc4_hdmi_set_timings(struct vc4_hdmi *vc4_hdmi,
417489
(hsync_pos ? 0 : VC4_HD_VID_CTL_HSYNC_LOW));
418490
}
419491

492+
static void vc5_hdmi_set_timings(struct vc4_hdmi *vc4_hdmi,
493+
struct drm_display_mode *mode)
494+
{
495+
bool hsync_pos = mode->flags & DRM_MODE_FLAG_PHSYNC;
496+
bool vsync_pos = mode->flags & DRM_MODE_FLAG_PVSYNC;
497+
bool interlaced = mode->flags & DRM_MODE_FLAG_INTERLACE;
498+
u32 pixel_rep = (mode->flags & DRM_MODE_FLAG_DBLCLK) ? 2 : 1;
499+
u32 verta = (VC4_SET_FIELD(mode->crtc_vsync_end - mode->crtc_vsync_start,
500+
VC5_HDMI_VERTA_VSP) |
501+
VC4_SET_FIELD(mode->crtc_vsync_start - mode->crtc_vdisplay,
502+
VC5_HDMI_VERTA_VFP) |
503+
VC4_SET_FIELD(mode->crtc_vdisplay, VC5_HDMI_VERTA_VAL));
504+
u32 vertb = (VC4_SET_FIELD(0, VC5_HDMI_VERTB_VSPO) |
505+
VC4_SET_FIELD(mode->crtc_vtotal - mode->crtc_vsync_end,
506+
VC4_HDMI_VERTB_VBP));
507+
u32 vertb_even = (VC4_SET_FIELD(0, VC5_HDMI_VERTB_VSPO) |
508+
VC4_SET_FIELD(mode->crtc_vtotal -
509+
mode->crtc_vsync_end -
510+
interlaced,
511+
VC4_HDMI_VERTB_VBP));
512+
513+
HDMI_WRITE(HDMI_VEC_INTERFACE_XBAR, 0x354021);
514+
HDMI_WRITE(HDMI_HORZA,
515+
(vsync_pos ? VC5_HDMI_HORZA_VPOS : 0) |
516+
(hsync_pos ? VC5_HDMI_HORZA_HPOS : 0) |
517+
VC4_SET_FIELD(mode->hdisplay * pixel_rep,
518+
VC5_HDMI_HORZA_HAP) |
519+
VC4_SET_FIELD((mode->hsync_start -
520+
mode->hdisplay) * pixel_rep,
521+
VC5_HDMI_HORZA_HFP));
522+
523+
HDMI_WRITE(HDMI_HORZB,
524+
VC4_SET_FIELD((mode->htotal -
525+
mode->hsync_end) * pixel_rep,
526+
VC5_HDMI_HORZB_HBP) |
527+
VC4_SET_FIELD((mode->hsync_end -
528+
mode->hsync_start) * pixel_rep,
529+
VC5_HDMI_HORZB_HSP));
530+
531+
HDMI_WRITE(HDMI_VERTA0, verta);
532+
HDMI_WRITE(HDMI_VERTA1, verta);
533+
534+
HDMI_WRITE(HDMI_VERTB0, vertb_even);
535+
HDMI_WRITE(HDMI_VERTB1, vertb);
536+
537+
HDMI_WRITE(HDMI_VID_CTL,
538+
(vsync_pos ? 0 : VC4_HD_VID_CTL_VSYNC_LOW) |
539+
(hsync_pos ? 0 : VC4_HD_VID_CTL_HSYNC_LOW));
540+
541+
HDMI_WRITE(HDMI_CLOCK_STOP, 0);
542+
}
543+
420544
static void vc4_hdmi_encoder_enable(struct drm_encoder *encoder)
421545
{
422546
struct drm_display_mode *mode = &encoder->crtc->state->adjusted_mode;
@@ -1317,6 +1441,92 @@ static int vc4_hdmi_init_resources(struct vc4_hdmi *vc4_hdmi)
13171441
return 0;
13181442
}
13191443

1444+
static int vc5_hdmi_init_resources(struct vc4_hdmi *vc4_hdmi)
1445+
{
1446+
struct platform_device *pdev = vc4_hdmi->pdev;
1447+
struct device *dev = &pdev->dev;
1448+
struct resource *res;
1449+
1450+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hdmi");
1451+
if (!res)
1452+
return -ENODEV;
1453+
1454+
vc4_hdmi->hdmicore_regs = devm_ioremap(dev, res->start,
1455+
resource_size(res));
1456+
if (IS_ERR(vc4_hdmi->hdmicore_regs))
1457+
return PTR_ERR(vc4_hdmi->hdmicore_regs);
1458+
1459+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "hd");
1460+
if (!res)
1461+
return -ENODEV;
1462+
1463+
vc4_hdmi->hd_regs = devm_ioremap(dev, res->start, resource_size(res));
1464+
if (IS_ERR(vc4_hdmi->hd_regs))
1465+
return PTR_ERR(vc4_hdmi->hd_regs);
1466+
1467+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "cec");
1468+
if (!res)
1469+
return -ENODEV;
1470+
1471+
vc4_hdmi->cec_regs = devm_ioremap(dev, res->start, resource_size(res));
1472+
if (IS_ERR(vc4_hdmi->cec_regs))
1473+
return PTR_ERR(vc4_hdmi->cec_regs);
1474+
1475+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "csc");
1476+
if (!res)
1477+
return -ENODEV;
1478+
1479+
vc4_hdmi->csc_regs = devm_ioremap(dev, res->start, resource_size(res));
1480+
if (IS_ERR(vc4_hdmi->csc_regs))
1481+
return PTR_ERR(vc4_hdmi->csc_regs);
1482+
1483+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "dvp");
1484+
if (!res)
1485+
return -ENODEV;
1486+
1487+
vc4_hdmi->dvp_regs = devm_ioremap(dev, res->start, resource_size(res));
1488+
if (IS_ERR(vc4_hdmi->dvp_regs))
1489+
return PTR_ERR(vc4_hdmi->dvp_regs);
1490+
1491+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "phy");
1492+
if (!res)
1493+
return -ENODEV;
1494+
1495+
vc4_hdmi->phy_regs = devm_ioremap(dev, res->start, resource_size(res));
1496+
if (IS_ERR(vc4_hdmi->phy_regs))
1497+
return PTR_ERR(vc4_hdmi->phy_regs);
1498+
1499+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "packet");
1500+
if (!res)
1501+
return -ENODEV;
1502+
1503+
vc4_hdmi->ram_regs = devm_ioremap(dev, res->start, resource_size(res));
1504+
if (IS_ERR(vc4_hdmi->ram_regs))
1505+
return PTR_ERR(vc4_hdmi->ram_regs);
1506+
1507+
res = platform_get_resource_byname(pdev, IORESOURCE_MEM, "rm");
1508+
if (!res)
1509+
return -ENODEV;
1510+
1511+
vc4_hdmi->rm_regs = devm_ioremap(dev, res->start, resource_size(res));
1512+
if (IS_ERR(vc4_hdmi->rm_regs))
1513+
return PTR_ERR(vc4_hdmi->rm_regs);
1514+
1515+
vc4_hdmi->hsm_clock = devm_clk_get(dev, "hdmi");
1516+
if (IS_ERR(vc4_hdmi->hsm_clock)) {
1517+
DRM_ERROR("Failed to get HDMI state machine clock\n");
1518+
return PTR_ERR(vc4_hdmi->hsm_clock);
1519+
}
1520+
1521+
vc4_hdmi->reset = devm_reset_control_get(dev, NULL);
1522+
if (IS_ERR(vc4_hdmi->reset)) {
1523+
DRM_ERROR("Failed to get HDMI reset line\n");
1524+
return PTR_ERR(vc4_hdmi->reset);
1525+
}
1526+
1527+
return 0;
1528+
}
1529+
13201530
static int vc4_hdmi_bind(struct device *dev, struct device *master, void *data)
13211531
{
13221532
struct platform_device *pdev = to_platform_device(dev);
@@ -1472,8 +1682,52 @@ static const struct vc4_hdmi_variant bcm2835_variant = {
14721682
.phy_rng_disable = vc4_hdmi_phy_rng_disable,
14731683
};
14741684

1685+
static const struct vc4_hdmi_variant bcm2711_hdmi0_variant = {
1686+
.id = 0,
1687+
.max_pixel_clock = 297000000,
1688+
.registers = vc5_hdmi_hdmi0_fields,
1689+
.num_registers = ARRAY_SIZE(vc5_hdmi_hdmi0_fields),
1690+
.phy_lane_mapping = {
1691+
PHY_LANE_0,
1692+
PHY_LANE_1,
1693+
PHY_LANE_2,
1694+
PHY_LANE_CK,
1695+
},
1696+
1697+
.init_resources = vc5_hdmi_init_resources,
1698+
.csc_setup = vc5_hdmi_csc_setup,
1699+
.reset = vc5_hdmi_reset,
1700+
.set_timings = vc5_hdmi_set_timings,
1701+
.phy_init = vc5_hdmi_phy_init,
1702+
.phy_rng_enable = vc5_hdmi_phy_rng_enable,
1703+
.phy_rng_disable = vc5_hdmi_phy_rng_disable,
1704+
};
1705+
1706+
static const struct vc4_hdmi_variant bcm2711_hdmi1_variant = {
1707+
.id = 1,
1708+
.max_pixel_clock = 297000000,
1709+
.registers = vc5_hdmi_hdmi1_fields,
1710+
.num_registers = ARRAY_SIZE(vc5_hdmi_hdmi1_fields),
1711+
.phy_lane_mapping = {
1712+
PHY_LANE_1,
1713+
PHY_LANE_0,
1714+
PHY_LANE_CK,
1715+
PHY_LANE_2,
1716+
},
1717+
1718+
.init_resources = vc5_hdmi_init_resources,
1719+
.csc_setup = vc5_hdmi_csc_setup,
1720+
.reset = vc5_hdmi_reset,
1721+
.set_timings = vc5_hdmi_set_timings,
1722+
.phy_init = vc5_hdmi_phy_init,
1723+
.phy_rng_enable = vc5_hdmi_phy_rng_enable,
1724+
.phy_rng_disable = vc5_hdmi_phy_rng_disable,
1725+
};
1726+
14751727
static const struct of_device_id vc4_hdmi_dt_match[] = {
14761728
{ .compatible = "brcm,bcm2835-hdmi", .data = &bcm2835_variant },
1729+
{ .compatible = "brcm,bcm2711-hdmi0", .data = &bcm2711_hdmi0_variant },
1730+
{ .compatible = "brcm,bcm2711-hdmi1", .data = &bcm2711_hdmi1_variant },
14771731
{}
14781732
};
14791733

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

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,13 @@ struct drm_display_mode;
2626
struct vc4_hdmi;
2727
struct vc4_hdmi_register;
2828

29+
enum vc4_hdmi_phy_channel {
30+
PHY_LANE_0 = 0,
31+
PHY_LANE_1,
32+
PHY_LANE_2,
33+
PHY_LANE_CK,
34+
};
35+
2936
struct vc4_hdmi_variant {
3037
/* On devices that have multiple, different instances (like
3138
* the BCM2711), which instance is that variant useful for.
@@ -47,6 +54,13 @@ struct vc4_hdmi_variant {
4754
/* Number of registers on that variant */
4855
unsigned int num_registers;
4956

57+
/* BCM2711 Only.
58+
* The variants don't map the lane in the same order in the
59+
* PHY, so this is an array mapping the HDMI channel (index)
60+
* to the PHY lane (value).
61+
*/
62+
enum vc4_hdmi_phy_channel phy_lane_mapping[4];
63+
5064
/* Callback to get the resources (memory region, interrupts,
5165
* clocks, etc) for that variant.
5266
*/
@@ -102,6 +116,20 @@ struct vc4_hdmi {
102116
struct i2c_adapter *ddc;
103117
void __iomem *hdmicore_regs;
104118
void __iomem *hd_regs;
119+
120+
/* VC5 Only */
121+
void __iomem *cec_regs;
122+
/* VC5 Only */
123+
void __iomem *csc_regs;
124+
/* VC5 Only */
125+
void __iomem *dvp_regs;
126+
/* VC5 Only */
127+
void __iomem *phy_regs;
128+
/* VC5 Only */
129+
void __iomem *ram_regs;
130+
/* VC5 Only */
131+
void __iomem *rm_regs;
132+
105133
int hpd_gpio;
106134
bool hpd_active_low;
107135

@@ -113,6 +141,8 @@ struct vc4_hdmi {
113141
struct clk *pixel_clock;
114142
struct clk *hsm_clock;
115143

144+
struct reset_control *reset;
145+
116146
struct debugfs_regset32 hdmi_regset;
117147
struct debugfs_regset32 hd_regset;
118148
};
@@ -137,4 +167,9 @@ void vc4_hdmi_phy_disable(struct vc4_hdmi *vc4_hdmi);
137167
void vc4_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi);
138168
void vc4_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi);
139169

170+
void vc5_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
171+
struct drm_display_mode *mode);
172+
void vc5_hdmi_phy_rng_enable(struct vc4_hdmi *vc4_hdmi);
173+
void vc5_hdmi_phy_rng_disable(struct vc4_hdmi *vc4_hdmi);
174+
140175
#endif /* _VC4_HDMI_H_ */

0 commit comments

Comments
 (0)