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

video/hdmi: Add audio_infoframe packing for DP

Similar to HDMI, DP uses audio infoframes as well which are structured
very similar to the HDMI ones.

This patch adds a helper function to pack the HDMI audio infoframe for
DP, called hdmi_audio_infoframe_pack_for_dp().
hdmi_audio_infoframe_pack_only() is split into two parts. One of them
packs the payload only and can be used for HDMI and DP.

Also constify the frame parameter in hdmi_audio_infoframe_check() as
it is passed to hdmi_audio_infoframe_check_only() which expects a const.

Signed-off-by: Markus Schneider-Pargmann <msp@baylibre.com>
Signed-off-by: Guillaume Ranquet <granquet@baylibre.com>
Signed-off-by: Bo-Chen Chen <rex-bc.chen@mediatek.com>
Reviewed-by: AngeloGioacchino Del Regno <angelogioacchino.delregno@collabora.com>
Signed-off-by: Dmitry Osipenko <dmitry.osipenko@collabora.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20220901044149.16782-3-rex-bc.chen@mediatek.com

authored by

Markus Schneider-Pargmann and committed by
Dmitry Osipenko
f89aa0b6 a2ce58e8

+71 -20
+63 -19
drivers/video/hdmi.c
··· 21 21 * DEALINGS IN THE SOFTWARE. 22 22 */ 23 23 24 + #include <drm/display/drm_dp.h> 24 25 #include <linux/bitops.h> 25 26 #include <linux/bug.h> 26 27 #include <linux/errno.h> ··· 382 381 * 383 382 * Returns 0 on success or a negative error code on failure. 384 383 */ 385 - int hdmi_audio_infoframe_check(struct hdmi_audio_infoframe *frame) 384 + int hdmi_audio_infoframe_check(const struct hdmi_audio_infoframe *frame) 386 385 { 387 386 return hdmi_audio_infoframe_check_only(frame); 388 387 } 389 388 EXPORT_SYMBOL(hdmi_audio_infoframe_check); 389 + 390 + static void 391 + hdmi_audio_infoframe_pack_payload(const struct hdmi_audio_infoframe *frame, 392 + u8 *buffer) 393 + { 394 + u8 channels; 395 + 396 + if (frame->channels >= 2) 397 + channels = frame->channels - 1; 398 + else 399 + channels = 0; 400 + 401 + buffer[0] = ((frame->coding_type & 0xf) << 4) | (channels & 0x7); 402 + buffer[1] = ((frame->sample_frequency & 0x7) << 2) | 403 + (frame->sample_size & 0x3); 404 + buffer[2] = frame->coding_type_ext & 0x1f; 405 + buffer[3] = frame->channel_allocation; 406 + buffer[4] = (frame->level_shift_value & 0xf) << 3; 407 + 408 + if (frame->downmix_inhibit) 409 + buffer[4] |= BIT(7); 410 + } 390 411 391 412 /** 392 413 * hdmi_audio_infoframe_pack_only() - write HDMI audio infoframe to binary buffer ··· 427 404 ssize_t hdmi_audio_infoframe_pack_only(const struct hdmi_audio_infoframe *frame, 428 405 void *buffer, size_t size) 429 406 { 430 - unsigned char channels; 431 407 u8 *ptr = buffer; 432 408 size_t length; 433 409 int ret; ··· 442 420 443 421 memset(buffer, 0, size); 444 422 445 - if (frame->channels >= 2) 446 - channels = frame->channels - 1; 447 - else 448 - channels = 0; 449 - 450 423 ptr[0] = frame->type; 451 424 ptr[1] = frame->version; 452 425 ptr[2] = frame->length; 453 426 ptr[3] = 0; /* checksum */ 454 427 455 - /* start infoframe payload */ 456 - ptr += HDMI_INFOFRAME_HEADER_SIZE; 457 - 458 - ptr[0] = ((frame->coding_type & 0xf) << 4) | (channels & 0x7); 459 - ptr[1] = ((frame->sample_frequency & 0x7) << 2) | 460 - (frame->sample_size & 0x3); 461 - ptr[2] = frame->coding_type_ext & 0x1f; 462 - ptr[3] = frame->channel_allocation; 463 - ptr[4] = (frame->level_shift_value & 0xf) << 3; 464 - 465 - if (frame->downmix_inhibit) 466 - ptr[4] |= BIT(7); 428 + hdmi_audio_infoframe_pack_payload(frame, 429 + ptr + HDMI_INFOFRAME_HEADER_SIZE); 467 430 468 431 hdmi_infoframe_set_checksum(buffer, length); 469 432 ··· 485 478 return hdmi_audio_infoframe_pack_only(frame, buffer, size); 486 479 } 487 480 EXPORT_SYMBOL(hdmi_audio_infoframe_pack); 481 + 482 + /** 483 + * hdmi_audio_infoframe_pack_for_dp - Pack a HDMI Audio infoframe for DisplayPort 484 + * 485 + * @frame: HDMI Audio infoframe 486 + * @sdp: Secondary data packet for DisplayPort. 487 + * @dp_version: DisplayPort version to be encoded in the header 488 + * 489 + * Packs a HDMI Audio Infoframe to be sent over DisplayPort. This function 490 + * fills the secondary data packet to be used for DisplayPort. 491 + * 492 + * Return: Number of total written bytes or a negative errno on failure. 493 + */ 494 + ssize_t 495 + hdmi_audio_infoframe_pack_for_dp(const struct hdmi_audio_infoframe *frame, 496 + struct dp_sdp *sdp, u8 dp_version) 497 + { 498 + int ret; 499 + 500 + ret = hdmi_audio_infoframe_check(frame); 501 + if (ret) 502 + return ret; 503 + 504 + memset(sdp->db, 0, sizeof(sdp->db)); 505 + 506 + /* Secondary-data packet header */ 507 + sdp->sdp_header.HB0 = 0; 508 + sdp->sdp_header.HB1 = frame->type; 509 + sdp->sdp_header.HB2 = DP_SDP_AUDIO_INFOFRAME_HB2; 510 + sdp->sdp_header.HB3 = (dp_version & 0x3f) << 2; 511 + 512 + hdmi_audio_infoframe_pack_payload(frame, sdp->db); 513 + 514 + /* Return size = frame length + four HB for sdp_header */ 515 + return frame->length + 4; 516 + } 517 + EXPORT_SYMBOL(hdmi_audio_infoframe_pack_for_dp); 488 518 489 519 /** 490 520 * hdmi_vendor_infoframe_init() - initialize an HDMI vendor infoframe
+2
include/drm/display/drm_dp.h
··· 1536 1536 #define DP_SDP_VSC_EXT_CEA 0x21 /* DP 1.4 */ 1537 1537 /* 0x80+ CEA-861 infoframe types */ 1538 1538 1539 + #define DP_SDP_AUDIO_INFOFRAME_HB2 0x1b 1540 + 1539 1541 /** 1540 1542 * struct dp_sdp_header - DP secondary data packet header 1541 1543 * @HB0: Secondary Data Packet ID
+6 -1
include/linux/hdmi.h
··· 336 336 void *buffer, size_t size); 337 337 ssize_t hdmi_audio_infoframe_pack_only(const struct hdmi_audio_infoframe *frame, 338 338 void *buffer, size_t size); 339 - int hdmi_audio_infoframe_check(struct hdmi_audio_infoframe *frame); 339 + int hdmi_audio_infoframe_check(const struct hdmi_audio_infoframe *frame); 340 + 341 + struct dp_sdp; 342 + ssize_t 343 + hdmi_audio_infoframe_pack_for_dp(const struct hdmi_audio_infoframe *frame, 344 + struct dp_sdp *sdp, u8 dp_version); 340 345 341 346 enum hdmi_3d_structure { 342 347 HDMI_3D_STRUCTURE_INVALID = -1,