From patchwork Fri Sep 21 15:09:07 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ville Syrjala X-Patchwork-Id: 10610231 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id B44CA15A6 for ; Fri, 21 Sep 2018 15:09:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A41912E421 for ; Fri, 21 Sep 2018 15:09:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 983932E429; Fri, 21 Sep 2018 15:09:13 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DFB992E421 for ; Fri, 21 Sep 2018 15:09:12 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 541DC6E816; Fri, 21 Sep 2018 15:09:12 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga02.intel.com (mga02.intel.com [134.134.136.20]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7BBC66E816; Fri, 21 Sep 2018 15:09:11 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga003.fm.intel.com ([10.253.24.29]) by orsmga101.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Sep 2018 08:09:11 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,285,1534834800"; d="scan'208";a="82270746" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.174]) by FMSMGA003.fm.intel.com with SMTP; 21 Sep 2018 08:09:08 -0700 Received: by stinkbox (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:09:07 +0300 From: Ville Syrjala To: dri-devel@lists.freedesktop.org Date: Fri, 21 Sep 2018 18:09:07 +0300 Message-Id: <20180921150907.12290-1-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180920185145.1912-7-ville.syrjala@linux.intel.com> References: <20180920185145.1912-7-ville.syrjala@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v2 06/18] video/hdmi: Handle the MPEG Source infoframe X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org, Hans Verkuil , linux-media@vger.kernel.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Ville Syrjälä Add the code to deal with the MPEG source infoframe. Blindly typed from the spec, and totally untested. v2: Rebase Cc: Thierry Reding Cc: Hans Verkuil Cc: linux-media@vger.kernel.org Signed-off-by: Ville Syrjälä --- drivers/video/hdmi.c | 229 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/hdmi.h | 27 ++++++ 2 files changed, 256 insertions(+) diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c index 08d94ab00467..6f39b9ae56b9 100644 --- a/drivers/video/hdmi.c +++ b/drivers/video/hdmi.c @@ -706,6 +706,131 @@ hdmi_vendor_any_infoframe_pack(union hdmi_vendor_any_infoframe *frame, return hdmi_vendor_any_infoframe_pack_only(frame, buffer, size); } +/** + * hdmi_mpeg_source_infoframe_init() - initialize an HDMI MPEG Source infoframe + * @frame: HDMI MPEG Source infoframe + * + * Returns 0 on success or a negative error code on failure. + */ +int hdmi_mpeg_source_infoframe_init(struct hdmi_mpeg_source_infoframe *frame) +{ + memset(frame, 0, sizeof(*frame)); + + frame->type = HDMI_INFOFRAME_TYPE_MPEG_SOURCE; + frame->version = 1; + frame->length = HDMI_MPEG_SOURCE_INFOFRAME_SIZE; + + return 0; +} +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_init); + +static int hdmi_mpeg_source_infoframe_check_only(const struct hdmi_mpeg_source_infoframe *frame) +{ + if (frame->type != HDMI_INFOFRAME_TYPE_MPEG_SOURCE || + frame->version != 1 || + frame->length != HDMI_MPEG_SOURCE_INFOFRAME_SIZE) + return -EINVAL; + + return 0; +} + +/** + * hdmi_mpeg_source_infoframe_check() - check a HDMI MPEG Source infoframe + * @frame: HDMI MPEG Source infoframe + * + * Validates that the infoframe is consistent and updates derived fields + * (eg. length) based on other fields. + * + * Returns 0 on success or a negative error code on failure. + */ +int hdmi_mpeg_source_infoframe_check(struct hdmi_mpeg_source_infoframe *frame) +{ + return hdmi_mpeg_source_infoframe_check_only(frame); +} +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_check); + +/** + * hdmi_mpeg_source_infoframe_pack_only() - write HDMI MPEG Source infoframe to binary buffer + * @frame: HDMI MPEG Source infoframe + * @buffer: destination buffer + * @size: size of buffer + * + * Packs the information contained in the @frame structure into a binary + * representation that can be written into the corresponding controller + * registers. Also computes the checksum as required by section 5.3.5 of + * the HDMI 1.4 specification. + * + * Returns the number of bytes packed into the binary buffer or a negative + * error code on failure. + */ +ssize_t hdmi_mpeg_source_infoframe_pack_only(const struct hdmi_mpeg_source_infoframe *frame, + void *buffer, size_t size) +{ + u8 *ptr = buffer; + size_t length; + int ret; + + ret = hdmi_mpeg_source_infoframe_check_only(frame); + if (ret) + return ret; + + length = HDMI_INFOFRAME_HEADER_SIZE + frame->length; + + if (size < length) + return -ENOSPC; + + memset(buffer, 0, size); + + ptr[0] = frame->type; + ptr[1] = frame->version; + ptr[2] = frame->length; + ptr[3] = 0; /* checksum */ + + /* start infoframe payload */ + ptr += HDMI_INFOFRAME_HEADER_SIZE; + + ptr[0] = frame->mpeg_bit_rate >> 0; + ptr[1] = frame->mpeg_bit_rate >> 8; + ptr[2] = frame->mpeg_bit_rate >> 16; + ptr[3] = frame->mpeg_bit_rate >> 24; + ptr[4] = (frame->field_repeat << 4) | frame->mpeg_frame; + + hdmi_infoframe_set_checksum(buffer, length); + + return length; +} +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_pack_only); + +/** + * hdmi_mpeg_source_infoframe_pack() - check a HDMI MPEG Source infoframe, + * and write it to binary buffer + * @frame: HDMI MPEG Source infoframe + * @buffer: destination buffer + * @size: size of buffer + * + * Validates that the infoframe is consistent and updates derived fields + * (eg. length) based on other fields, after which packs the information + * contained in the @frame structure into a binary representation that + * can be written into the corresponding controller registers. This function + * also computes the checksum as required by section 5.3.5 of the HDMI 1.4 + * specification. + * + * Returns the number of bytes packed into the binary buffer or a negative + * error code on failure. + */ +ssize_t hdmi_mpeg_source_infoframe_pack(struct hdmi_mpeg_source_infoframe *frame, + void *buffer, size_t size) +{ + int ret; + + ret = hdmi_mpeg_source_infoframe_check(frame); + if (ret) + return ret; + + return hdmi_mpeg_source_infoframe_pack_only(frame, buffer, size); +} +EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_pack); + /** * hdmi_infoframe_check() - check a HDMI infoframe * @frame: HDMI infoframe @@ -727,6 +852,8 @@ hdmi_infoframe_check(union hdmi_infoframe *frame) return hdmi_audio_infoframe_check(&frame->audio); case HDMI_INFOFRAME_TYPE_VENDOR: return hdmi_vendor_any_infoframe_check(&frame->vendor); + case HDMI_INFOFRAME_TYPE_MPEG_SOURCE: + return hdmi_mpeg_source_infoframe_check(&frame->mpeg_source); default: WARN(1, "Bad infoframe type %d\n", frame->any.type); return -EINVAL; @@ -770,6 +897,10 @@ hdmi_infoframe_pack_only(const union hdmi_infoframe *frame, void *buffer, size_t length = hdmi_vendor_any_infoframe_pack_only(&frame->vendor, buffer, size); break; + case HDMI_INFOFRAME_TYPE_MPEG_SOURCE: + length = hdmi_mpeg_source_infoframe_pack_only(&frame->mpeg_source, + buffer, size); + break; default: WARN(1, "Bad infoframe type %d\n", frame->any.type); length = -EINVAL; @@ -816,6 +947,10 @@ hdmi_infoframe_pack(union hdmi_infoframe *frame, length = hdmi_vendor_any_infoframe_pack(&frame->vendor, buffer, size); break; + case HDMI_INFOFRAME_TYPE_MPEG_SOURCE: + length = hdmi_mpeg_source_infoframe_pack(&frame->mpeg_source, + buffer, size); + break; default: WARN(1, "Bad infoframe type %d\n", frame->any.type); length = -EINVAL; @@ -838,6 +973,8 @@ static const char *hdmi_infoframe_type_get_name(enum hdmi_infoframe_type type) return "Source Product Description (SPD)"; case HDMI_INFOFRAME_TYPE_AUDIO: return "Audio"; + case HDMI_INFOFRAME_TYPE_MPEG_SOURCE: + return "MPEG Source"; } return "Reserved"; } @@ -1349,6 +1486,46 @@ hdmi_vendor_any_infoframe_log(const char *level, } } +static const char * +hdmi_mpeg_frame_get_name(enum hdmi_mpeg_frame frame) +{ + if (frame < 0 || frame > 3) + return "invalid"; + + switch (frame) { + case HDMI_MPEG_FRAME_UNKNOWN: + return "Unknown"; + case HDMI_MPEG_FRAME_I_PICTURE: + return "I Picture"; + case HDMI_MPEG_FRAME_B_PICTURE: + return "B Picture"; + case HDMI_MPEG_FRAME_P_PICTURE: + return "P Picture"; + } + return "Reserved"; +} + +/** + * hdmi_mpeg_source_infoframe_log() - log info of HDMI MPEG Source infoframe + * @level: logging level + * @dev: device + * @frame: HDMI MPEG Source infoframe + */ +static void hdmi_mpeg_source_infoframe_log(const char *level, + struct device *dev, + const struct hdmi_mpeg_source_infoframe *frame) +{ + hdmi_infoframe_log_header(level, dev, + (const struct hdmi_any_infoframe *)frame); + + hdmi_log(" MPEG bit rate: %d Hz\n", + frame->mpeg_bit_rate); + hdmi_log(" MPEG frame: %s\n", + hdmi_mpeg_frame_get_name(frame->mpeg_frame)); + hdmi_log(" field repeat: %s\n", + frame->field_repeat ? "Yes" : "No"); +} + /** * hdmi_infoframe_log() - log info of HDMI infoframe * @level: logging level @@ -1372,6 +1549,9 @@ void hdmi_infoframe_log(const char *level, case HDMI_INFOFRAME_TYPE_VENDOR: hdmi_vendor_any_infoframe_log(level, dev, &frame->vendor); break; + case HDMI_INFOFRAME_TYPE_MPEG_SOURCE: + hdmi_mpeg_source_infoframe_log(level, dev, &frame->mpeg_source); + break; } } EXPORT_SYMBOL(hdmi_infoframe_log); @@ -1614,6 +1794,52 @@ hdmi_vendor_any_infoframe_unpack(union hdmi_vendor_any_infoframe *frame, return 0; } +/** + * hdmi_mpeg_source_infoframe_unpack() - unpack binary buffer to a HDMI MPEG Source infoframe + * @frame: HDMI MPEG Source infoframe + * @buffer: source buffer + * @size: size of buffer + * + * Unpacks the information contained in binary @buffer into a structured + * @frame of the HDMI MPEG Source information frame. + * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4 + * specification. + * + * Returns 0 on success or a negative error code on failure. + */ +static int hdmi_mpeg_source_infoframe_unpack(struct hdmi_mpeg_source_infoframe *frame, + const void *buffer, size_t size) +{ + const u8 *ptr = buffer; + int ret; + + if (size < HDMI_INFOFRAME_SIZE(MPEG_SOURCE)) + return -EINVAL; + + if (ptr[0] != HDMI_INFOFRAME_TYPE_MPEG_SOURCE || + ptr[1] != 1 || + ptr[2] != HDMI_MPEG_SOURCE_INFOFRAME_SIZE) { + return -EINVAL; + } + + if (hdmi_infoframe_checksum(buffer, HDMI_INFOFRAME_SIZE(MPEG_SOURCE)) != 0) + return -EINVAL; + + ret = hdmi_mpeg_source_infoframe_init(frame); + if (ret) + return ret; + + ptr += HDMI_INFOFRAME_HEADER_SIZE; + + frame->mpeg_bit_rate = + (ptr[0] << 0) | (ptr[1] << 8) | + (ptr[2] << 16) | (ptr[3] << 24); + frame->mpeg_frame = ptr[4] & 0x3; + frame->field_repeat = ptr[4] & 0x10; + + return 0; +} + /** * hdmi_infoframe_unpack() - unpack binary buffer to a HDMI infoframe * @frame: HDMI infoframe @@ -1649,6 +1875,9 @@ int hdmi_infoframe_unpack(union hdmi_infoframe *frame, case HDMI_INFOFRAME_TYPE_VENDOR: ret = hdmi_vendor_any_infoframe_unpack(&frame->vendor, buffer, size); break; + case HDMI_INFOFRAME_TYPE_MPEG_SOURCE: + ret = hdmi_mpeg_source_infoframe_unpack(&frame->mpeg_source, buffer, size); + break; default: ret = -EINVAL; break; diff --git a/include/linux/hdmi.h b/include/linux/hdmi.h index 80521d9591a1..2c9322f7538d 100644 --- a/include/linux/hdmi.h +++ b/include/linux/hdmi.h @@ -47,6 +47,7 @@ enum hdmi_infoframe_type { HDMI_INFOFRAME_TYPE_AVI = 0x82, HDMI_INFOFRAME_TYPE_SPD = 0x83, HDMI_INFOFRAME_TYPE_AUDIO = 0x84, + HDMI_INFOFRAME_TYPE_MPEG_SOURCE = 0x85, }; #define HDMI_IEEE_OUI 0x000c03 @@ -55,6 +56,7 @@ enum hdmi_infoframe_type { #define HDMI_AVI_INFOFRAME_SIZE 13 #define HDMI_SPD_INFOFRAME_SIZE 25 #define HDMI_AUDIO_INFOFRAME_SIZE 10 +#define HDMI_MPEG_SOURCE_INFOFRAME_SIZE 10 #define HDMI_INFOFRAME_SIZE(type) \ (HDMI_INFOFRAME_HEADER_SIZE + HDMI_ ## type ## _INFOFRAME_SIZE) @@ -337,6 +339,29 @@ union hdmi_vendor_any_infoframe { struct hdmi_vendor_infoframe hdmi; }; +enum hdmi_mpeg_frame { + HDMI_MPEG_FRAME_UNKNOWN, + HDMI_MPEG_FRAME_I_PICTURE, + HDMI_MPEG_FRAME_B_PICTURE, + HDMI_MPEG_FRAME_P_PICTURE, +}; + +struct hdmi_mpeg_source_infoframe { + enum hdmi_infoframe_type type; + unsigned char version; + unsigned char length; + unsigned int mpeg_bit_rate; + enum hdmi_mpeg_frame mpeg_frame; + bool field_repeat; +}; + +int hdmi_mpeg_source_infoframe_init(struct hdmi_mpeg_source_infoframe *frame); +ssize_t hdmi_mpeg_source_infoframe_pack(struct hdmi_mpeg_source_infoframe *frame, + void *buffer, size_t size); +ssize_t hdmi_mpeg_source_infoframe_pack_only(const struct hdmi_mpeg_source_infoframe *frame, + void *buffer, size_t size); +int hdmi_mpeg_source_infoframe_check(struct hdmi_mpeg_source_infoframe *frame); + /** * union hdmi_infoframe - overall union of all abstract infoframe representations * @any: generic infoframe @@ -344,6 +369,7 @@ union hdmi_vendor_any_infoframe { * @spd: spd infoframe * @vendor: union of all vendor infoframes * @audio: audio infoframe + * @mpeg_source: mpeg source infoframe * * This is used by the generic pack function. This works since all infoframes * have the same header which also indicates which type of infoframe should be @@ -355,6 +381,7 @@ union hdmi_infoframe { struct hdmi_spd_infoframe spd; union hdmi_vendor_any_infoframe vendor; struct hdmi_audio_infoframe audio; + struct hdmi_mpeg_source_infoframe mpeg_source; }; ssize_t hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer, From patchwork Fri Sep 21 15:10:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Ville Syrjala X-Patchwork-Id: 10610273 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 42F2C15E8 for ; Fri, 21 Sep 2018 15:10:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 2E1DB2E4BE for ; Fri, 21 Sep 2018 15:10:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 2C0222E4CB; Fri, 21 Sep 2018 15:10:25 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-5.2 required=2.0 tests=BAYES_00,MAILING_LIST_MULTI, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 48DA12E4D8 for ; Fri, 21 Sep 2018 15:10:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9D5436E81F; Fri, 21 Sep 2018 15:10:23 +0000 (UTC) X-Original-To: intel-gfx@lists.freedesktop.org Delivered-To: intel-gfx@lists.freedesktop.org Received: from mga09.intel.com (mga09.intel.com [134.134.136.24]) by gabe.freedesktop.org (Postfix) with ESMTPS id CC33B6E81F; Fri, 21 Sep 2018 15:10:22 +0000 (UTC) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from orsmga001.jf.intel.com ([10.7.209.18]) by orsmga102.jf.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 21 Sep 2018 08:10:22 -0700 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.54,285,1534834800"; d="scan'208";a="92572031" Received: from stinkbox.fi.intel.com (HELO stinkbox) ([10.237.72.174]) by orsmga001.jf.intel.com with SMTP; 21 Sep 2018 08:10:18 -0700 Received: by stinkbox (sSMTP sendmail emulation); Fri, 21 Sep 2018 18:10:17 +0300 From: Ville Syrjala To: dri-devel@lists.freedesktop.org Date: Fri, 21 Sep 2018 18:10:17 +0300 Message-Id: <20180921151017.13133-1-ville.syrjala@linux.intel.com> X-Mailer: git-send-email 2.16.4 In-Reply-To: <20180920185145.1912-8-ville.syrjala@linux.intel.com> References: <20180920185145.1912-8-ville.syrjala@linux.intel.com> MIME-Version: 1.0 Subject: [Intel-gfx] [PATCH v2 07/18] video/hdmi: Handle the NTSC VBI infoframe X-BeenThere: intel-gfx@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Intel graphics driver community testing & development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: intel-gfx@lists.freedesktop.org, Hans Verkuil , linux-media@vger.kernel.org Errors-To: intel-gfx-bounces@lists.freedesktop.org Sender: "Intel-gfx" X-Virus-Scanned: ClamAV using ClamSMTP From: Ville Syrjälä Add the code to deal with the NTSC VBI infoframe. I decided against parsing the PES_data_field and just leave it as an opaque blob, just dumping it out as hex in the log. Blindly typed from the spec, and totally untested. v2: Rebase Cc: Thierry Reding Cc: Hans Verkuil Cc: linux-media@vger.kernel.org Signed-off-by: Ville Syrjälä --- drivers/video/hdmi.c | 208 +++++++++++++++++++++++++++++++++++++++++++++++++++ include/linux/hdmi.h | 18 +++++ 2 files changed, 226 insertions(+) diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c index 6f39b9ae56b9..b14202fc5854 100644 --- a/drivers/video/hdmi.c +++ b/drivers/video/hdmi.c @@ -831,6 +831,139 @@ ssize_t hdmi_mpeg_source_infoframe_pack(struct hdmi_mpeg_source_infoframe *frame } EXPORT_SYMBOL(hdmi_mpeg_source_infoframe_pack); +/** + * hdmi_ntsc_vbi_infoframe_init() - initialize an HDMI NTSC VBI infoframe + * @frame: HDMI NTSC VBI infoframe + * @pes_data_field: ANSI/SCTE 127 PES_data_field + * @length: ANSI/SCTE 127 PES_data_field length + * + * Returns 0 on success or a negative error code on failure. + */ +int hdmi_ntsc_vbi_infoframe_init(struct hdmi_ntsc_vbi_infoframe *frame, + const void *pes_data_field, + size_t length) +{ + if (length < 1 || length > 27) + return -EINVAL; + + memset(frame, 0, sizeof(*frame)); + + frame->type = HDMI_INFOFRAME_TYPE_NTSC_VBI; + frame->version = 1; + frame->length = length; + + memcpy(frame->pes_data_field, pes_data_field, length); + + return 0; +} +EXPORT_SYMBOL(hdmi_ntsc_vbi_infoframe_init); + +static int hdmi_ntsc_vbi_infoframe_check_only(const struct hdmi_ntsc_vbi_infoframe *frame) +{ + if (frame->type != HDMI_INFOFRAME_TYPE_NTSC_VBI || + frame->version != 1 || + frame->length < 1 || frame->length > 27) + return -EINVAL; + + if (frame->pes_data_field[0] != 0x99) + return -EINVAL; + + return 0; +} + +/** + * hdmi_ntsc_vbi_infoframe_check() - Check and check a HDMI NTSC VBI infoframe + * @frame: HDMI NTSC VBI infoframe + * + * Validates that the infoframe is consistent and updates derived fields + * (eg. length) based on other fields. + * + * Returns 0 on success or a negative error code on failure. + */ +int hdmi_ntsc_vbi_infoframe_check(struct hdmi_ntsc_vbi_infoframe *frame) +{ + return hdmi_ntsc_vbi_infoframe_check_only(frame); +} +EXPORT_SYMBOL(hdmi_ntsc_vbi_infoframe_check); + +/** + * hdmi_ntsc_vbi_infoframe_pack_only() - write HDMI NTSC VBI infoframe to binary buffer + * @frame: HDMI NTSC VBI infoframe + * @buffer: destination buffer + * @size: size of buffer + * + * Packs the information contained in the @frame structure into a binary + * representation that can be written into the corresponding controller + * registers. Also computes the checksum as required by section 5.3.5 of + * the HDMI 1.4 specification. + * + * Returns the number of bytes packed into the binary buffer or a negative + * error code on failure. + */ +ssize_t hdmi_ntsc_vbi_infoframe_pack_only(const struct hdmi_ntsc_vbi_infoframe *frame, + void *buffer, size_t size) +{ + u8 *ptr = buffer; + size_t length; + int ret; + + ret = hdmi_ntsc_vbi_infoframe_check_only(frame); + if (ret) + return ret; + + length = HDMI_INFOFRAME_HEADER_SIZE + frame->length; + + if (size < length) + return -ENOSPC; + + memset(buffer, 0, size); + + ptr[0] = frame->type; + ptr[1] = frame->version; + ptr[2] = frame->length; + ptr[3] = 0; /* checksum */ + + /* start infoframe payload */ + ptr += HDMI_INFOFRAME_HEADER_SIZE; + + memcpy(ptr, frame->pes_data_field, frame->length); + + hdmi_infoframe_set_checksum(buffer, length); + + return length; +} +EXPORT_SYMBOL(hdmi_ntsc_vbi_infoframe_pack_only); + +/** + * hdmi_ntsc_vbi_infoframe_pack() - check a HDMI NTSC VBI infoframe, + * and write it to binary buffer + * @frame: HDMI NTSC VBI infoframe + * @buffer: destination buffer + * @size: size of buffer + * + * Validates that the infoframe is consistent and updates derived fields + * (eg. length) based on other fields, after which packs the information + * contained in the @frame structure into a binary representation that + * can be written into the corresponding controller registers. This function + * also computes the checksum as required by section 5.3.5 of the HDMI 1.4 + * specification. + * + * Returns the number of bytes packed into the binary buffer or a negative + * error code on failure. + */ +ssize_t hdmi_ntsc_vbi_infoframe_pack(struct hdmi_ntsc_vbi_infoframe *frame, + void *buffer, size_t size) +{ + int ret; + + ret = hdmi_ntsc_vbi_infoframe_check(frame); + if (ret) + return ret; + + return hdmi_ntsc_vbi_infoframe_pack_only(frame, buffer, size); +} +EXPORT_SYMBOL(hdmi_ntsc_vbi_infoframe_pack); + /** * hdmi_infoframe_check() - check a HDMI infoframe * @frame: HDMI infoframe @@ -854,6 +987,8 @@ hdmi_infoframe_check(union hdmi_infoframe *frame) return hdmi_vendor_any_infoframe_check(&frame->vendor); case HDMI_INFOFRAME_TYPE_MPEG_SOURCE: return hdmi_mpeg_source_infoframe_check(&frame->mpeg_source); + case HDMI_INFOFRAME_TYPE_NTSC_VBI: + return hdmi_ntsc_vbi_infoframe_check(&frame->ntsc_vbi); default: WARN(1, "Bad infoframe type %d\n", frame->any.type); return -EINVAL; @@ -901,6 +1036,10 @@ hdmi_infoframe_pack_only(const union hdmi_infoframe *frame, void *buffer, size_t length = hdmi_mpeg_source_infoframe_pack_only(&frame->mpeg_source, buffer, size); break; + case HDMI_INFOFRAME_TYPE_NTSC_VBI: + length = hdmi_ntsc_vbi_infoframe_pack_only(&frame->ntsc_vbi, + buffer, size); + break; default: WARN(1, "Bad infoframe type %d\n", frame->any.type); length = -EINVAL; @@ -951,6 +1090,10 @@ hdmi_infoframe_pack(union hdmi_infoframe *frame, length = hdmi_mpeg_source_infoframe_pack(&frame->mpeg_source, buffer, size); break; + case HDMI_INFOFRAME_TYPE_NTSC_VBI: + length = hdmi_ntsc_vbi_infoframe_pack(&frame->ntsc_vbi, + buffer, size); + break; default: WARN(1, "Bad infoframe type %d\n", frame->any.type); length = -EINVAL; @@ -975,6 +1118,8 @@ static const char *hdmi_infoframe_type_get_name(enum hdmi_infoframe_type type) return "Audio"; case HDMI_INFOFRAME_TYPE_MPEG_SOURCE: return "MPEG Source"; + case HDMI_INFOFRAME_TYPE_NTSC_VBI: + return "NTSC VBI"; } return "Reserved"; } @@ -1526,6 +1671,22 @@ static void hdmi_mpeg_source_infoframe_log(const char *level, frame->field_repeat ? "Yes" : "No"); } +/** + * hdmi_ntsc_vbi_infoframe_log() - log info of HDMI NTSC VBI infoframe + * @level: logging level + * @dev: device + * @frame: HDMI NTSC VBI infoframe + */ +static void hdmi_ntsc_vbi_infoframe_log(const char *level, + struct device *dev, + const struct hdmi_ntsc_vbi_infoframe *frame) +{ + hdmi_infoframe_log_header(level, dev, + (const struct hdmi_any_infoframe *)frame); + + hdmi_log(" %*ph\n", frame->length, frame->pes_data_field); +} + /** * hdmi_infoframe_log() - log info of HDMI infoframe * @level: logging level @@ -1552,6 +1713,9 @@ void hdmi_infoframe_log(const char *level, case HDMI_INFOFRAME_TYPE_MPEG_SOURCE: hdmi_mpeg_source_infoframe_log(level, dev, &frame->mpeg_source); break; + case HDMI_INFOFRAME_TYPE_NTSC_VBI: + hdmi_ntsc_vbi_infoframe_log(level, dev, &frame->ntsc_vbi); + break; } } EXPORT_SYMBOL(hdmi_infoframe_log); @@ -1840,6 +2004,47 @@ static int hdmi_mpeg_source_infoframe_unpack(struct hdmi_mpeg_source_infoframe * return 0; } +/** + * hdmi_ntsc_vbi_infoframe_unpack() - unpack binary buffer to a HDMI MPEG Source infoframe + * @frame: HDMI MPEG Source infoframe + * @buffer: source buffer + * @size: size of buffer + * + * Unpacks the information contained in binary @buffer into a structured + * @frame of the HDMI MPEG Source information frame. + * Also verifies the checksum as required by section 5.3.5 of the HDMI 1.4 + * specification. + * + * Returns 0 on success or a negative error code on failure. + */ +static int hdmi_ntsc_vbi_infoframe_unpack(struct hdmi_ntsc_vbi_infoframe *frame, + const void *buffer, size_t size) +{ + const u8 *ptr = buffer; + size_t length; + + if (size < HDMI_INFOFRAME_HEADER_SIZE) + return -EINVAL; + + if (ptr[0] != HDMI_INFOFRAME_TYPE_NTSC_VBI || + ptr[1] != 1 || + ptr[2] < 1 || ptr[2] > 27) + return -EINVAL; + + length = ptr[2]; + + if (size < HDMI_INFOFRAME_HEADER_SIZE + length) + return -EINVAL; + + if (hdmi_infoframe_checksum(buffer, + HDMI_INFOFRAME_HEADER_SIZE + length) != 0) + return -EINVAL; + + ptr += HDMI_INFOFRAME_HEADER_SIZE; + + return hdmi_ntsc_vbi_infoframe_init(frame, ptr, length); +} + /** * hdmi_infoframe_unpack() - unpack binary buffer to a HDMI infoframe * @frame: HDMI infoframe @@ -1878,6 +2083,9 @@ int hdmi_infoframe_unpack(union hdmi_infoframe *frame, case HDMI_INFOFRAME_TYPE_MPEG_SOURCE: ret = hdmi_mpeg_source_infoframe_unpack(&frame->mpeg_source, buffer, size); break; + case HDMI_INFOFRAME_TYPE_NTSC_VBI: + ret = hdmi_ntsc_vbi_infoframe_unpack(&frame->ntsc_vbi, buffer, size); + break; default: ret = -EINVAL; break; diff --git a/include/linux/hdmi.h b/include/linux/hdmi.h index 2c9322f7538d..3821516b336c 100644 --- a/include/linux/hdmi.h +++ b/include/linux/hdmi.h @@ -48,6 +48,7 @@ enum hdmi_infoframe_type { HDMI_INFOFRAME_TYPE_SPD = 0x83, HDMI_INFOFRAME_TYPE_AUDIO = 0x84, HDMI_INFOFRAME_TYPE_MPEG_SOURCE = 0x85, + HDMI_INFOFRAME_TYPE_NTSC_VBI = 0x86, }; #define HDMI_IEEE_OUI 0x000c03 @@ -362,6 +363,21 @@ ssize_t hdmi_mpeg_source_infoframe_pack_only(const struct hdmi_mpeg_source_infof void *buffer, size_t size); int hdmi_mpeg_source_infoframe_check(struct hdmi_mpeg_source_infoframe *frame); +struct hdmi_ntsc_vbi_infoframe { + enum hdmi_infoframe_type type; + unsigned char version; + unsigned char length; + unsigned char pes_data_field[27]; +}; + +int hdmi_ntsc_vbi_infoframe_init(struct hdmi_ntsc_vbi_infoframe *frame, + const void *pes_data_field, size_t length); +ssize_t hdmi_ntsc_vbi_infoframe_pack(struct hdmi_ntsc_vbi_infoframe *frame, + void *buffer, size_t size); +ssize_t hdmi_ntsc_vbi_infoframe_pack_only(const struct hdmi_ntsc_vbi_infoframe *frame, + void *buffer, size_t size); +int hdmi_ntsc_vbi_infoframe_check(struct hdmi_ntsc_vbi_infoframe *frame); + /** * union hdmi_infoframe - overall union of all abstract infoframe representations * @any: generic infoframe @@ -370,6 +386,7 @@ int hdmi_mpeg_source_infoframe_check(struct hdmi_mpeg_source_infoframe *frame); * @vendor: union of all vendor infoframes * @audio: audio infoframe * @mpeg_source: mpeg source infoframe + * @ntsc_vbi: ntsc vbi infoframe * * This is used by the generic pack function. This works since all infoframes * have the same header which also indicates which type of infoframe should be @@ -382,6 +399,7 @@ union hdmi_infoframe { union hdmi_vendor_any_infoframe vendor; struct hdmi_audio_infoframe audio; struct hdmi_mpeg_source_infoframe mpeg_source; + struct hdmi_ntsc_vbi_infoframe ntsc_vbi; }; ssize_t hdmi_infoframe_pack(union hdmi_infoframe *frame, void *buffer,