819e983e6e6d6746d36cd5f3ef32cc06c919cf25
[openwrt/openwrt.git] /
1 From b6cf78ca0773f54074da8dc3401b9f52aec2e27e Mon Sep 17 00:00:00 2001
2 From: Dave Stevenson <dave.stevenson@raspberrypi.com>
3 Date: Wed, 8 Apr 2020 16:12:02 +0100
4 Subject: [PATCH] drm/vc4_hdmi: Add Broadcast RGB property to allow
5 override of RGB range
6
7 Copy Intel's "Broadcast RGB" property semantics to add manual override
8 of the HDMI pixel range for monitors that don't abide by the content
9 of the AVI Infoframe.
10
11 Signed-off-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
12 ---
13 drivers/gpu/drm/vc4/vc4_hdmi.c | 103 +++++++++++++++++++++++++++++++++
14 drivers/gpu/drm/vc4/vc4_hdmi.h | 15 +++++
15 2 files changed, 118 insertions(+)
16
17 --- a/drivers/gpu/drm/vc4/vc4_hdmi.c
18 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.c
19 @@ -56,6 +56,14 @@
20 #include "vc4_hdmi_regs.h"
21 #include "vc4_regs.h"
22
23 +/*
24 + * "Broadcast RGB" property.
25 + * Allows overriding of HDMI full or limited range RGB
26 + */
27 +#define VC4_BROADCAST_RGB_AUTO 0
28 +#define VC4_BROADCAST_RGB_FULL 1
29 +#define VC4_BROADCAST_RGB_LIMITED 2
30 +
31 #define VC5_HDMI_HORZA_HFP_SHIFT 16
32 #define VC5_HDMI_HORZA_HFP_MASK VC4_MASK(28, 16)
33 #define VC5_HDMI_HORZA_VPOS BIT(15)
34 @@ -135,6 +143,10 @@ static bool vc4_hdmi_is_full_range_rgb(s
35 {
36 struct vc4_hdmi_encoder *vc4_encoder = &vc4_hdmi->encoder;
37
38 + if (vc4_hdmi->broadcast_rgb == VC4_BROADCAST_RGB_LIMITED)
39 + return false;
40 + else if (vc4_hdmi->broadcast_rgb == VC4_BROADCAST_RGB_FULL)
41 + return true;
42 return !vc4_encoder->hdmi_monitor ||
43 drm_default_rgb_quant_range(mode) == HDMI_QUANTIZATION_RANGE_FULL;
44 }
45 @@ -341,6 +353,65 @@ static int vc4_hdmi_connector_atomic_che
46 return 0;
47 }
48
49 +/**
50 + * vc4_hdmi_connector_atomic_get_property - hook for
51 + * connector->atomic_get_property.
52 + * @connector: Connector to get the property for.
53 + * @state: Connector state to retrieve the property from.
54 + * @property: Property to retrieve.
55 + * @val: Return value for the property.
56 + *
57 + * Returns the atomic property value for a digital connector.
58 + */
59 +int vc4_hdmi_connector_get_property(struct drm_connector *connector,
60 + const struct drm_connector_state *state,
61 + struct drm_property *property,
62 + uint64_t *val)
63 +{
64 + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
65 + const struct vc4_hdmi_connector_state *vc4_conn_state =
66 + const_conn_state_to_vc4_hdmi_conn_state(state);
67 +
68 + if (property == vc4_hdmi->broadcast_rgb_property) {
69 + *val = vc4_conn_state->broadcast_rgb;
70 + } else {
71 + DRM_DEBUG_ATOMIC("Unknown property [PROP:%d:%s]\n",
72 + property->base.id, property->name);
73 + return -EINVAL;
74 + }
75 +
76 + return 0;
77 +}
78 +
79 +/**
80 + * vc4_hdmi_connector_atomic_set_property - hook for
81 + * connector->atomic_set_property.
82 + * @connector: Connector to set the property for.
83 + * @state: Connector state to set the property on.
84 + * @property: Property to set.
85 + * @val: New value for the property.
86 + *
87 + * Sets the atomic property value for a digital connector.
88 + */
89 +int vc4_hdmi_connector_set_property(struct drm_connector *connector,
90 + struct drm_connector_state *state,
91 + struct drm_property *property,
92 + uint64_t val)
93 +{
94 + struct vc4_hdmi *vc4_hdmi = connector_to_vc4_hdmi(connector);
95 + struct vc4_hdmi_connector_state *vc4_conn_state =
96 + conn_state_to_vc4_hdmi_conn_state(state);
97 +
98 + if (property == vc4_hdmi->broadcast_rgb_property) {
99 + vc4_conn_state->broadcast_rgb = val;
100 + return 0;
101 + }
102 +
103 + DRM_DEBUG_ATOMIC("Unknown property [PROP:%d:%s]\n",
104 + property->base.id, property->name);
105 + return -EINVAL;
106 +}
107 +
108 static void vc4_hdmi_connector_reset(struct drm_connector *connector)
109 {
110 struct vc4_hdmi_connector_state *old_state =
111 @@ -377,6 +448,7 @@ vc4_hdmi_connector_duplicate_state(struc
112 new_state->pixel_rate = vc4_state->pixel_rate;
113 new_state->output_bpc = vc4_state->output_bpc;
114 new_state->output_format = vc4_state->output_format;
115 + new_state->broadcast_rgb = vc4_state->broadcast_rgb;
116 __drm_atomic_helper_connector_duplicate_state(connector, &new_state->base);
117
118 return &new_state->base;
119 @@ -389,6 +461,8 @@ static const struct drm_connector_funcs
120 .reset = vc4_hdmi_connector_reset,
121 .atomic_duplicate_state = vc4_hdmi_connector_duplicate_state,
122 .atomic_destroy_state = drm_atomic_helper_connector_destroy_state,
123 + .atomic_get_property = vc4_hdmi_connector_get_property,
124 + .atomic_set_property = vc4_hdmi_connector_set_property,
125 };
126
127 static const struct drm_connector_helper_funcs vc4_hdmi_connector_helper_funcs = {
128 @@ -396,6 +470,32 @@ static const struct drm_connector_helper
129 .atomic_check = vc4_hdmi_connector_atomic_check,
130 };
131
132 +static const struct drm_prop_enum_list broadcast_rgb_names[] = {
133 + { VC4_BROADCAST_RGB_AUTO, "Automatic" },
134 + { VC4_BROADCAST_RGB_FULL, "Full" },
135 + { VC4_BROADCAST_RGB_LIMITED, "Limited 16:235" },
136 +};
137 +
138 +static void
139 +vc4_hdmi_attach_broadcast_rgb_property(struct drm_device *dev,
140 + struct vc4_hdmi *vc4_hdmi)
141 +{
142 + struct drm_property *prop = vc4_hdmi->broadcast_rgb_property;
143 +
144 + if (!prop) {
145 + prop = drm_property_create_enum(dev, DRM_MODE_PROP_ENUM,
146 + "Broadcast RGB",
147 + broadcast_rgb_names,
148 + ARRAY_SIZE(broadcast_rgb_names));
149 + if (!prop)
150 + return;
151 +
152 + vc4_hdmi->broadcast_rgb_property = prop;
153 + }
154 +
155 + drm_object_attach_property(&vc4_hdmi->connector.base, prop, 0);
156 +}
157 +
158 static int vc4_hdmi_connector_init(struct drm_device *dev,
159 struct vc4_hdmi *vc4_hdmi)
160 {
161 @@ -439,6 +539,8 @@ static int vc4_hdmi_connector_init(struc
162 if (vc4_hdmi->variant->supports_hdr)
163 drm_connector_attach_hdr_output_metadata_property(connector);
164
165 + vc4_hdmi_attach_broadcast_rgb_property(dev, vc4_hdmi);
166 +
167 drm_connector_attach_encoder(connector, encoder);
168
169 return 0;
170 @@ -1384,6 +1486,7 @@ static void vc4_hdmi_encoder_atomic_mode
171 mutex_lock(&vc4_hdmi->mutex);
172 vc4_hdmi->output_bpc = vc4_state->output_bpc;
173 vc4_hdmi->output_format = vc4_state->output_format;
174 + vc4_hdmi->broadcast_rgb = vc4_state->broadcast_rgb;
175 memcpy(&vc4_hdmi->saved_adjusted_mode,
176 &crtc_state->adjusted_mode,
177 sizeof(vc4_hdmi->saved_adjusted_mode));
178 --- a/drivers/gpu/drm/vc4/vc4_hdmi.h
179 +++ b/drivers/gpu/drm/vc4/vc4_hdmi.h
180 @@ -140,6 +140,8 @@ struct vc4_hdmi {
181
182 struct delayed_work scrambling_work;
183
184 + struct drm_property *broadcast_rgb_property;
185 +
186 struct i2c_adapter *ddc;
187 void __iomem *hdmicore_regs;
188 void __iomem *hd_regs;
189 @@ -240,6 +242,12 @@ struct vc4_hdmi {
190 */
191 enum vc4_hdmi_output_format output_format;
192
193 + /**
194 + * @broadcast_rgb: Copy of @vc4_connector_state.broadcast_rgb
195 + * for use outside of KMS hooks. Protected by @mutex.
196 + */
197 + int broadcast_rgb;
198 +
199 /* VC5 debugfs regset */
200 struct debugfs_regset32 cec_regset;
201 struct debugfs_regset32 csc_regset;
202 @@ -268,6 +276,7 @@ struct vc4_hdmi_connector_state {
203 unsigned long long pixel_rate;
204 unsigned int output_bpc;
205 enum vc4_hdmi_output_format output_format;
206 + int broadcast_rgb;
207 };
208
209 static inline struct vc4_hdmi_connector_state *
210 @@ -275,6 +284,12 @@ conn_state_to_vc4_hdmi_conn_state(struct
211 {
212 return container_of(conn_state, struct vc4_hdmi_connector_state, base);
213 }
214 +
215 +static inline const struct vc4_hdmi_connector_state *
216 +const_conn_state_to_vc4_hdmi_conn_state(const struct drm_connector_state *conn_state)
217 +{
218 + return container_of(conn_state, struct vc4_hdmi_connector_state, base);
219 +}
220
221 void vc4_hdmi_phy_init(struct vc4_hdmi *vc4_hdmi,
222 struct vc4_hdmi_connector_state *vc4_conn_state);