kernel: bump 5.15 to 5.15.100
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.15 / 950-0868-drm-vc4-hdmi-Rework-hdmi_enable_4kp60-detection.patch
1 From 62dd8774e71d9af9b0f3cabdeacbb80d24313504 Mon Sep 17 00:00:00 2001
2 From: Maxime Ripard <maxime@cerno.tech>
3 Date: Thu, 24 Mar 2022 11:57:57 +0100
4 Subject: [PATCH] drm/vc4: hdmi: Rework hdmi_enable_4kp60 detection
5
6 In order to support higher HDMI frequencies, users have to set the
7 hdmi_enable_4kp60 parameter in their config.txt file.
8
9 We were detecting this so far by calling clk_round_rate on the core
10 clock with the frequency we're supposed to run at when one of those
11 modes is enabled. Whether or not the parameter was enabled could then be
12 inferred by the returned rate since the maximum clock rate reported by
13 the firmware was one of the side effect of setting that parameter.
14
15 However, the recent clock rework we did changed what clk_round_rate was
16 returning to always return the minimum allowed, and thus this test
17 wasn't reliable anymore.
18
19 Let's instead try to set a minimum on that clock for the rate we'd like
20 to reach. If the maximum reported by the firmware is below the minimum
21 we're trying to set, the clock framework will return an error which we
22 then can use to infer whether the parameter is set or not.
23
24 Signed-off-by: Maxime Ripard <maxime@cerno.tech>
25 ---
26 drivers/gpu/drm/vc4/vc4_drv.h | 8 ++++++++
27 drivers/gpu/drm/vc4/vc4_hdmi.c | 14 ++++----------
28 drivers/gpu/drm/vc4/vc4_hdmi.h | 8 --------
29 drivers/gpu/drm/vc4/vc4_hvs.c | 6 ++++++
30 4 files changed, 18 insertions(+), 18 deletions(-)
31
32 --- a/drivers/gpu/drm/vc4/vc4_drv.h
33 +++ b/drivers/gpu/drm/vc4/vc4_drv.h
34 @@ -341,6 +341,14 @@ struct vc4_hvs {
35
36 /* HVS version 5 flag, therefore requires updated dlist structures */
37 bool hvs5;
38 +
39 + /*
40 + * Even if HDMI0 on the RPi4 can output modes requiring a pixel
41 + * rate higher than 297MHz, it needs some adjustments in the
42 + * config.txt file to be able to do so and thus won't always be
43 + * available.
44 + */
45 + bool vc5_hdmi_enable_scrambling;
46 };
47
48 struct vc4_plane {
49 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
50 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
51 @@ -292,6 +292,7 @@ static int vc4_hdmi_connector_get_modes(
52 {
53 struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
54 struct vc4_hdmi_encoder *vc4_encoder = &vc4_hdmi->encoder;
55 + struct vc4_dev *vc4 = to_vc4_dev(connector->dev);
56 int ret = 0;
57 struct edid *edid;
58
59 @@ -310,7 +311,7 @@ static int vc4_hdmi_connector_get_modes(
60 ret = drm_add_edid_modes(connector, edid);
61 kfree(edid);
62
63 - if (vc4_hdmi->disable_4kp60) {
64 + if (!vc4->hvs->vc5_hdmi_enable_scrambling) {
65 struct drm_device *drm = connector->dev;
66 struct drm_display_mode *mode;
67
68 @@ -1673,11 +1674,12 @@ vc4_hdmi_encoder_clock_valid(const struc
69 {
70 const struct drm_connector *connector = &vc4_hdmi->connector;
71 const struct drm_display_info *info = &connector->display_info;
72 + struct vc4_dev *vc4 = to_vc4_dev(connector->dev);
73
74 if (clock > vc4_hdmi->variant->max_pixel_clock)
75 return MODE_CLOCK_HIGH;
76
77 - if (vc4_hdmi->disable_4kp60 && clock > HDMI_14_MAX_TMDS_CLK)
78 + if (!vc4->hvs->vc5_hdmi_enable_scrambling && clock > HDMI_14_MAX_TMDS_CLK)
79 return MODE_CLOCK_HIGH;
80
81 if (info->max_tmds_clock && clock > (info->max_tmds_clock * 1000))
82 @@ -3158,14 +3160,6 @@ static int vc4_hdmi_bind(struct device *
83 vc4_hdmi->disable_wifi_frequencies =
84 of_property_read_bool(dev->of_node, "wifi-2.4ghz-coexistence");
85
86 - if (variant->max_pixel_clock == 600000000) {
87 - struct vc4_dev *vc4 = to_vc4_dev(drm);
88 - long max_rate = clk_round_rate(vc4->hvs->core_clk, 550000000);
89 -
90 - if (max_rate < 550000000)
91 - vc4_hdmi->disable_4kp60 = true;
92 - }
93 -
94 /*
95 * If we boot without any cable connected to the HDMI connector,
96 * the firmware will skip the HSM initialization and leave it
97 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h
98 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h
99 @@ -169,14 +169,6 @@ struct vc4_hdmi {
100 */
101 bool disable_wifi_frequencies;
102
103 - /*
104 - * Even if HDMI0 on the RPi4 can output modes requiring a pixel
105 - * rate higher than 297MHz, it needs some adjustments in the
106 - * config.txt file to be able to do so and thus won't always be
107 - * available.
108 - */
109 - bool disable_4kp60;
110 -
111 struct cec_adapter *cec_adap;
112 struct cec_msg cec_rx_msg;
113 bool cec_tx_ok;
114 --- a/drivers/gpu/drm/vc4/vc4_hvs.c
115 +++ b/drivers/gpu/drm/vc4/vc4_hvs.c
116 @@ -897,12 +897,18 @@ static int vc4_hvs_bind(struct device *d
117 hvs->regset.nregs = ARRAY_SIZE(hvs_regs);
118
119 if (hvs->hvs5) {
120 + unsigned long max_rate;
121 +
122 hvs->core_clk = devm_clk_get(&pdev->dev, NULL);
123 if (IS_ERR(hvs->core_clk)) {
124 dev_err(&pdev->dev, "Couldn't get core clock\n");
125 return PTR_ERR(hvs->core_clk);
126 }
127
128 + max_rate = clk_get_max_rate(hvs->core_clk);
129 + if (max_rate >= 550000000)
130 + hvs->vc5_hdmi_enable_scrambling = true;
131 +
132 ret = clk_prepare_enable(hvs->core_clk);
133 if (ret) {
134 dev_err(&pdev->dev, "Couldn't enable the core clock\n");