From patchwork Wed Jul 26 12:37:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Zhong X-Patchwork-Id: 9864711 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id 5D209602B1 for ; Wed, 26 Jul 2017 12:37:42 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4D6FB28723 for ; Wed, 26 Jul 2017 12:37:42 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 4213D2874C; Wed, 26 Jul 2017 12:37:42 +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=-6.4 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, RCVD_IN_SORBS_SPAM autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 5175928723 for ; Wed, 26 Jul 2017 12:37:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751592AbdGZMhk (ORCPT ); Wed, 26 Jul 2017 08:37:40 -0400 Received: from mail-pg0-f66.google.com ([74.125.83.66]:38095 "EHLO mail-pg0-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751522AbdGZMhj (ORCPT ); Wed, 26 Jul 2017 08:37:39 -0400 Received: by mail-pg0-f66.google.com with SMTP id 125so3818123pgi.5; Wed, 26 Jul 2017 05:37:39 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=tRReJ+xeBweZBpZoOsyecZghj8M0eHc3v5btZjJ03yI=; b=JoxfInm3dWtJZBJ7OY6YNBwZfyRoFLFAoa/m5tnovH1i7l09kYIVDo/GqtvHmiqjD3 DgaAoDGkLNlG4T2GogQdaoT/6vj+J6CsCms0khDgObtcWINclnjg7JoH4nGVDMwFAXcC 8p/bXl8cK6/rapLapNn8N/TwObajHyfnva3RNqQn2/b+UA+ZxOIaAXMJs2J4cTTt2YUi OQbS49EcCNELjZFJnqSiV2ATyjmmW+glC1SjR3oCJ+47L1bten682Xk50fnT+UU8Frvh wTng4QuWGgfjfuu/9iW+jcEG3NquBMZDCXaf592CksdCRtFdY5Fkiy6cbg+3A0z6iluU abMw== X-Gm-Message-State: AIVw1130fZwQj15zp05zygfRg/1t54KkxB8+SHZLSUFk3P8v+a3qjEhZ Lfh1ujYPW1vBOg== X-Received: by 10.99.124.5 with SMTP id x5mr768269pgc.280.1501072659266; Wed, 26 Jul 2017 05:37:39 -0700 (PDT) Received: from chris-X240.lan ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id k4sm20884767pgr.74.2017.07.26.05.37.34 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Jul 2017 05:37:37 -0700 (PDT) From: Chris Zhong To: seanpaul@chromium.org, dianders@chromium.org, briannorris@chromium.org Cc: linux-rockchip@lists.infradead.org, mark.yao@rock-chips.com, heiko@sntech.de, Chris Zhong , Bartlomiej Zolnierkiewicz , Jose Abreu , Shashank Sharma , Daniel Vetter , Thierry Reding , linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v3 1/2] video/hdmi: Introduce helpers for the HDMI audio infoframe payload Date: Wed, 26 Jul 2017 20:37:29 +0800 Message-Id: <1501072650-32653-1-git-send-email-zyw@rock-chips.com> X-Mailer: git-send-email 2.7.4 Sender: linux-fbdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-fbdev@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP The DP is using the same audio infoframe payload as hdmi, per DP 1.3 spec, but it has a different header. Provide a new interface here, it just packs the payload. Signed-off-by: Chris Zhong --- Changes in v3: - add size < HDMI_AUDIO_INFOFRAME_SIZE check according to Doug's advice Changes in v2: None drivers/video/hdmi.c | 66 ++++++++++++++++++++++++++++++++++++++-------------- include/linux/hdmi.h | 2 ++ 2 files changed, 50 insertions(+), 18 deletions(-) diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c index 1cf907e..9868050 100644 --- a/drivers/video/hdmi.c +++ b/drivers/video/hdmi.c @@ -240,6 +240,49 @@ int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame) EXPORT_SYMBOL(hdmi_audio_infoframe_init); /** + * hdmi_audio_infoframe_pack_payload() - write HDMI audio infoframe payload to + * binary buffer + * @frame: HDMI audio 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. + * + * Returns 0 on success or a negative error code on failure. + */ +ssize_t hdmi_audio_infoframe_pack_payload(struct hdmi_audio_infoframe *frame, + void *buffer, size_t size) +{ + unsigned char channels; + u8 *ptr = buffer; + + if (size < frame->length || size < HDMI_AUDIO_INFOFRAME_SIZE) + return -ENOSPC; + + memset(buffer, 0, size); + + if (frame->channels >= 2) + channels = frame->channels - 1; + else + channels = 0; + + ptr[0] = ((frame->coding_type & 0xf) << 4) | (channels & 0x7); + ptr[1] = ((frame->sample_frequency & 0x7) << 2) | + (frame->sample_size & 0x3); + ptr[2] = frame->coding_type_ext & 0x1f; + ptr[3] = frame->channel_allocation; + ptr[4] = (frame->level_shift_value & 0xf) << 3; + + if (frame->downmix_inhibit) + ptr[4] |= BIT(7); + + return 0; +} +EXPORT_SYMBOL(hdmi_audio_infoframe_pack_payload); + +/** * hdmi_audio_infoframe_pack() - write HDMI audio infoframe to binary buffer * @frame: HDMI audio infoframe * @buffer: destination buffer @@ -256,22 +299,15 @@ EXPORT_SYMBOL(hdmi_audio_infoframe_init); ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, void *buffer, size_t size) { - unsigned char channels; u8 *ptr = buffer; size_t length; + int ret; length = HDMI_INFOFRAME_HEADER_SIZE + frame->length; if (size < length) return -ENOSPC; - memset(buffer, 0, size); - - if (frame->channels >= 2) - channels = frame->channels - 1; - else - channels = 0; - ptr[0] = frame->type; ptr[1] = frame->version; ptr[2] = frame->length; @@ -279,16 +315,10 @@ ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, /* start infoframe payload */ ptr += HDMI_INFOFRAME_HEADER_SIZE; - - ptr[0] = ((frame->coding_type & 0xf) << 4) | (channels & 0x7); - ptr[1] = ((frame->sample_frequency & 0x7) << 2) | - (frame->sample_size & 0x3); - ptr[2] = frame->coding_type_ext & 0x1f; - ptr[3] = frame->channel_allocation; - ptr[4] = (frame->level_shift_value & 0xf) << 3; - - if (frame->downmix_inhibit) - ptr[4] |= BIT(7); + ret = hdmi_audio_infoframe_pack_payload(frame, ptr, + size - HDMI_INFOFRAME_HEADER_SIZE); + if (ret) + return ret; hdmi_infoframe_set_checksum(buffer, length); diff --git a/include/linux/hdmi.h b/include/linux/hdmi.h index d271ff2..a4be132 100644 --- a/include/linux/hdmi.h +++ b/include/linux/hdmi.h @@ -272,6 +272,8 @@ struct hdmi_audio_infoframe { int hdmi_audio_infoframe_init(struct hdmi_audio_infoframe *frame); ssize_t hdmi_audio_infoframe_pack(struct hdmi_audio_infoframe *frame, void *buffer, size_t size); +ssize_t hdmi_audio_infoframe_pack_payload(struct hdmi_audio_infoframe *frame, + void *buffer, size_t size); enum hdmi_3d_structure { HDMI_3D_STRUCTURE_INVALID = -1,