Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

drm/display: hdmi: Add HDMI compute clock helper

A lot of HDMI drivers have some variation of the formula to calculate
the TMDS character rate from a mode, but few of them actually take all
parameters into account.

Let's create a helper to provide that rate taking all parameters into
account.

Reviewed-by: Dave Stevenson <dave.stevenson@raspberrypi.com>
Reviewed-by: Dmitry Baryshkov <dmitry.baryshkov@linaro.org>
Link: https://patchwork.freedesktop.org/patch/msgid/20240527-kms-hdmi-connector-state-v15-9-c5af16c3aae2@kernel.org
Signed-off-by: Maxime Ripard <mripard@kernel.org>

+65
+61
drivers/gpu/drm/display/drm_hdmi_helper.c
··· 195 195 frame->itc = conn_state->content_type != DRM_MODE_CONTENT_TYPE_NO_DATA; 196 196 } 197 197 EXPORT_SYMBOL(drm_hdmi_avi_infoframe_content_type); 198 + 199 + /** 200 + * drm_hdmi_compute_mode_clock() - Computes the TMDS Character Rate 201 + * @mode: Display mode to compute the clock for 202 + * @bpc: Bits per character 203 + * @fmt: Output Pixel Format used 204 + * 205 + * Returns the TMDS Character Rate for a given mode, bpc count and output format. 206 + * 207 + * RETURNS: 208 + * The TMDS Character Rate, in Hertz, or 0 on error. 209 + */ 210 + unsigned long long 211 + drm_hdmi_compute_mode_clock(const struct drm_display_mode *mode, 212 + unsigned int bpc, enum hdmi_colorspace fmt) 213 + { 214 + unsigned long long clock = mode->clock * 1000ULL; 215 + unsigned int vic = drm_match_cea_mode(mode); 216 + 217 + /* 218 + * CTA-861-G Spec, section 5.4 - Color Coding and Quantization 219 + * mandates that VIC 1 always uses 8 bpc. 220 + */ 221 + if (vic == 1 && bpc != 8) 222 + return 0; 223 + 224 + if (fmt == HDMI_COLORSPACE_YUV422) { 225 + /* 226 + * HDMI 1.0 Spec, section 6.5 - Pixel Encoding states that 227 + * YUV422 sends 24 bits over three channels, with Cb and Cr 228 + * components being sent on odd and even pixels, respectively. 229 + * 230 + * If fewer than 12 bpc are sent, data are left justified. 231 + */ 232 + if (bpc > 12) 233 + return 0; 234 + 235 + /* 236 + * HDMI 1.0 Spec, section 6.5 - Pixel Encoding 237 + * specifies that YUV422 sends two 12-bits components over 238 + * three TMDS channels per pixel clock, which is equivalent to 239 + * three 8-bits components over three channels used by RGB as 240 + * far as the clock rate goes. 241 + */ 242 + bpc = 8; 243 + } 244 + 245 + /* 246 + * HDMI 2.0 Spec, Section 7.1 - YCbCr 4:2:0 Pixel Encoding 247 + * specifies that YUV420 encoding is carried at a TMDS Character Rate 248 + * equal to half the pixel clock rate. 249 + */ 250 + if (fmt == HDMI_COLORSPACE_YUV420) 251 + clock = clock / 2; 252 + 253 + if (mode->flags & DRM_MODE_FLAG_DBLCLK) 254 + clock = clock * 2; 255 + 256 + return DIV_ROUND_CLOSEST_ULL(clock * bpc, 8); 257 + } 258 + EXPORT_SYMBOL(drm_hdmi_compute_mode_clock);
+4
include/drm/display/drm_hdmi_helper.h
··· 24 24 void drm_hdmi_avi_infoframe_content_type(struct hdmi_avi_infoframe *frame, 25 25 const struct drm_connector_state *conn_state); 26 26 27 + unsigned long long 28 + drm_hdmi_compute_mode_clock(const struct drm_display_mode *mode, 29 + unsigned int bpc, enum hdmi_colorspace fmt); 30 + 27 31 #endif