From patchwork Tue Jul 18 11:20:41 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Zhong X-Patchwork-Id: 9848031 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 0536A602C8 for ; Tue, 18 Jul 2017 11:21:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id ED82928573 for ; Tue, 18 Jul 2017 11:21:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id E207428577; Tue, 18 Jul 2017 11:21:00 +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 573B228573 for ; Tue, 18 Jul 2017 11:21:00 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751533AbdGRLU7 (ORCPT ); Tue, 18 Jul 2017 07:20:59 -0400 Received: from mail-pf0-f193.google.com ([209.85.192.193]:34016 "EHLO mail-pf0-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751515AbdGRLU6 (ORCPT ); Tue, 18 Jul 2017 07:20:58 -0400 Received: by mail-pf0-f193.google.com with SMTP id o88so2351564pfk.1; Tue, 18 Jul 2017 04:20:58 -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=e8fhWYPpCo5STSj/bJJNW+mX0iU1PWkad9FGBLLmKLA=; b=HvRp5oS7JStUPZLTWBFqER6rpS70VTRJNN0nN58IsK6/stLWgBXx2zhSSefjPE4Fqi w6YM1BAwbd+4FZGcbV4ZszrcsT++x2OFfYTK0DrZfkJVDaztIXJ+HeAKtmFX5dzume0b mxJzj0hMPB0XF8J/9tmJe4D1ivxScAWsjv9yfmeupggi04KOl63TvFCecdOgQNgMz1iK 2dFFwDCwu1Uyl9kOITdLvcDF3IcFLw8zwAe66loUGgKYW+fdCnRhsjH2zSIyRYRYUSQm unaR6GeTnETEY8OcvcaRl7djVRd4cEso4s7Mc5tvr4/OaXRtI/9tYnN+zl36VUYbRo09 nnLg== X-Gm-Message-State: AIVw111v388OfrcyfJVP2BX78WFPp73a4nGzYxy2Tl51kF+xNR+Xl212 G+NWW18dGDhecQ== X-Received: by 10.98.11.4 with SMTP id t4mr1185841pfi.104.1500376858197; Tue, 18 Jul 2017 04:20:58 -0700 (PDT) Received: from chris-X240.lan ([103.29.142.67]) by smtp.gmail.com with ESMTPSA id s11sm4299713pgr.53.2017.07.18.04.20.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 18 Jul 2017 04:20:57 -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 , Shashank Sharma , Jose Abreu , Jani Nikula , Thierry Reding , linux-fbdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH v2 1/2] video/hdmi: Introduce helpers for the HDMI audio infoframe payload Date: Tue, 18 Jul 2017 19:20:41 +0800 Message-Id: <1500376842-6739-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 v2: None drivers/video/hdmi.c | 66 ++++++++++++++++++++++++++++++++++++++-------------- include/linux/hdmi.h | 3 ++- 2 files changed, 50 insertions(+), 19 deletions(-) diff --git a/drivers/video/hdmi.c b/drivers/video/hdmi.c index 1cf907e..e0b041e 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) + 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..d93c709 100644 --- a/include/linux/hdmi.h +++ b/include/linux/hdmi.h @@ -272,7 +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, HDMI_3D_STRUCTURE_FRAME_PACKING = 0,