From patchwork Wed Jul 26 12:37:30 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Chris Zhong X-Patchwork-Id: 9864725 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 5F63F602B1 for ; Wed, 26 Jul 2017 12:38:13 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 4F35C28723 for ; Wed, 26 Jul 2017 12:38:13 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 441142874C; Wed, 26 Jul 2017 12:38: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=-1.4 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, RCVD_IN_DNSWL_NONE, RCVD_IN_SORBS_SPAM autolearn=no version=3.3.1 Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id DCB1128723 for ; Wed, 26 Jul 2017 12:38:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:References: In-Reply-To:Message-Id:Date:Subject:To:From:Reply-To:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:List-Owner; bh=LNYxopAT99FClKldebWjWag441aKOYJl/JKuiSyd9PI=; b=fjoIzqd3qvGGxreZKHY/lN5Y/B TCdiQoIbzMaXrqVbrXRICI/UJTIcn5tINhT38nJFvtno3tJ12Ji9taYEjTVEA28jix3zSsNo7Fp1M xC9+sYNXv4n1+CO2UoHcJ+uVz2R5ZfH6r8KK+pIyvvtDumzUAwbnY+2h55WiFs/7xyfHynbNED1Hf 5rqhqyUgQ8obxfJNGMUdQQPZGHExfGXo8ORYb8eB5TI1n6OwthCsKDETL+ZDc6kAtCu14SD1WTzpO ZJqlkRo6PqPpmllGOfTrZJ/MZNm52zA/wJ74O+XooNCYMKacF9b1qqg/XHZP7N8EfRPBAVfRJddlM Qj1xoKJw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1daLZo-0004oT-PK; Wed, 26 Jul 2017 12:38:08 +0000 Received: from mail-pg0-f67.google.com ([74.125.83.67]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1daLZj-0004jy-LS; Wed, 26 Jul 2017 12:38:05 +0000 Received: by mail-pg0-f67.google.com with SMTP id 123so6687627pgj.0; Wed, 26 Jul 2017 05:37:43 -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:in-reply-to :references; bh=9Jv7MjiXvnBKrDvqJhIKOuq6BqWHm3RlIlWd90kgGXw=; b=kthOzQKNVD3ig8g1O64vKcWFAbPNjurc4vDtTvfLs5AtsvFPIwkRzPC4mJppzPtl1r tHvIk0yEA1M/LpP0KDUDbp/XAek1VWG0CATDgoL7g+dScITysr4DAzI8fIGMT1uClgGB iNqOGTMy6gVtdEMG0iaA8WyoBL90/cXPatQsVpFc5YkZ4W9raz6QALjvYiIFWIKOLn/p 6W+IwSCifMZ6E308sl0Zxaaxjkx6xQGvzJVxlHb6m4ZUqS+PyEVNGTBTzu+cbv1rXud9 wkH6NGhSgfQAdENXVt697V/QOxmteK0sIsFWIdS9bVx+odahdt78r8KI55ovxbq3xwBI O/7w== X-Gm-Message-State: AIVw110BynsIxpNhocOdJjQ6n/Fvh74k5Hdp0p8Vt9RSLER3yGKTPRcw o/LCCxsh2c2N+g== X-Received: by 10.84.210.79 with SMTP id z73mr801513plh.151.1501072662793; Wed, 26 Jul 2017 05:37:42 -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.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 26 Jul 2017 05:37:42 -0700 (PDT) From: Chris Zhong To: seanpaul@chromium.org, dianders@chromium.org, briannorris@chromium.org Subject: [PATCH v3 2/2] drm/rockchip: cdn-dp: send audio infoframe to sink Date: Wed, 26 Jul 2017 20:37:30 +0800 Message-Id: <1501072650-32653-2-git-send-email-zyw@rock-chips.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1501072650-32653-1-git-send-email-zyw@rock-chips.com> References: <1501072650-32653-1-git-send-email-zyw@rock-chips.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20170726_053803_756134_261E5FF9 X-CRM114-Status: GOOD ( 12.98 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: heiko@sntech.de, David Airlie , linux-kernel@vger.kernel.org, Jani Nikula , linux-rockchip@lists.infradead.org, dri-devel@lists.freedesktop.org, Chris Zhong , Daniel Vetter , linux-arm-kernel@lists.infradead.org, mark.yao@rock-chips.com MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org X-Virus-Scanned: ClamAV using ClamSMTP Some DP/HDMI sink need to receive the audio infoframe to play sound, especially some multi-channel AV receiver, they need the channel_allocation from infoframe to config the speakers. Send the audio infoframe via SDP will make them work properly. Signed-off-by: Chris Zhong --- Changes in v3: None Changes in v2: - According to the advice of Sean Paul and Doug use hdmi_audio_infoframe_pack_payload to pack the buffer define a SDP_HEADER_SIZE drivers/gpu/drm/rockchip/cdn-dp-core.c | 20 ++++++++++++++++++++ drivers/gpu/drm/rockchip/cdn-dp-reg.c | 27 +++++++++++++++++++++++++++ drivers/gpu/drm/rockchip/cdn-dp-reg.h | 6 ++++++ include/drm/drm_dp_helper.h | 1 + 4 files changed, 54 insertions(+) diff --git a/drivers/gpu/drm/rockchip/cdn-dp-core.c b/drivers/gpu/drm/rockchip/cdn-dp-core.c index 9b0b058..6a4fc66 100644 --- a/drivers/gpu/drm/rockchip/cdn-dp-core.c +++ b/drivers/gpu/drm/rockchip/cdn-dp-core.c @@ -802,6 +802,7 @@ static int cdn_dp_audio_hw_params(struct device *dev, void *data, .sample_rate = params->sample_rate, .channels = params->channels, }; + u8 buffer[HDMI_AUDIO_INFOFRAME_SIZE + EDP_SDP_HEADER_SIZE] = { 0 }; int ret; mutex_lock(&dp->lock); @@ -823,6 +824,25 @@ static int cdn_dp_audio_hw_params(struct device *dev, void *data, goto out; } + /* + * Prepare the infoframe header to SDP header per DP 1.3 spec, Table + * 2-98. + */ + buffer[0] = 0; + buffer[1] = HDMI_INFOFRAME_TYPE_AUDIO; + buffer[2] = 0x1b; + buffer[3] = 0x48; + + ret = hdmi_audio_infoframe_pack_payload(¶ms->cea, + &buffer[EDP_SDP_HEADER_SIZE], + HDMI_AUDIO_INFOFRAME_SIZE); + if (ret < 0) { + DRM_DEV_ERROR(dev, "Failed to pack audio infoframe: %d\n", ret); + goto out; + } + + cdn_dp_sdp_write(dp, 0, buffer, sizeof(buffer)); + ret = cdn_dp_audio_config(dp, &audio); if (!ret) dp->audio_info = audio; diff --git a/drivers/gpu/drm/rockchip/cdn-dp-reg.c b/drivers/gpu/drm/rockchip/cdn-dp-reg.c index b14d211..4a818e4 100644 --- a/drivers/gpu/drm/rockchip/cdn-dp-reg.c +++ b/drivers/gpu/drm/rockchip/cdn-dp-reg.c @@ -286,6 +286,33 @@ int cdn_dp_dpcd_write(struct cdn_dp_device *dp, u32 addr, u8 value) return ret; } +void cdn_dp_sdp_write(struct cdn_dp_device *dp, int entry_id, u8 *buf, + u32 buf_len) +{ + int idx; + u32 *packet = (u32 *)buf; + u32 num_packets = buf_len / 4; + u8 type; + + if (buf_len < EDP_SDP_HEADER_SIZE) { + DRM_DEV_ERROR(dp->dev, "sdp buffer length: %d\n", buf_len); + return; + } + + type = buf[1]; + + for (idx = 0; idx < num_packets; idx++) + writel(cpu_to_le32(*packet++), dp->regs + SOURCE_PIF_DATA_WR); + + writel(entry_id, dp->regs + SOURCE_PIF_WR_ADDR); + + writel(F_HOST_WR, dp->regs + SOURCE_PIF_WR_REQ); + + writel(PIF_PKT_TYPE_VALID | F_PACKET_TYPE(type) | entry_id, + dp->regs + SOURCE_PIF_PKT_ALLOC_REG); + writel(PIF_PKT_ALLOC_WR_EN, dp->regs + SOURCE_PIF_PKT_ALLOC_WR_EN); +} + int cdn_dp_load_firmware(struct cdn_dp_device *dp, const u32 *i_mem, u32 i_size, const u32 *d_mem, u32 d_size) { diff --git a/drivers/gpu/drm/rockchip/cdn-dp-reg.h b/drivers/gpu/drm/rockchip/cdn-dp-reg.h index c4bbb4a83..6ec0e81 100644 --- a/drivers/gpu/drm/rockchip/cdn-dp-reg.h +++ b/drivers/gpu/drm/rockchip/cdn-dp-reg.h @@ -424,6 +424,11 @@ /* Reference cycles when using lane clock as reference */ #define LANE_REF_CYC 0x8000 +#define F_HOST_WR BIT(0) +#define PIF_PKT_ALLOC_WR_EN BIT(0) +#define PIF_PKT_TYPE_VALID (3 << 16) +#define F_PACKET_TYPE(x) (((x) & 0xff) << 8) + enum voltage_swing_level { VOLTAGE_LEVEL_0, VOLTAGE_LEVEL_1, @@ -478,5 +483,6 @@ int cdn_dp_set_video_status(struct cdn_dp_device *dp, int active); int cdn_dp_config_video(struct cdn_dp_device *dp); int cdn_dp_audio_stop(struct cdn_dp_device *dp, struct audio_info *audio); int cdn_dp_audio_mute(struct cdn_dp_device *dp, bool enable); +void cdn_dp_sdp_write(struct cdn_dp_device *dp, int entry_id, u8 *buf, u32 len); int cdn_dp_audio_config(struct cdn_dp_device *dp, struct audio_info *audio); #endif /* _CDN_DP_REG_H */ diff --git a/include/drm/drm_dp_helper.h b/include/drm/drm_dp_helper.h index b17476a..5d5dd07 100644 --- a/include/drm/drm_dp_helper.h +++ b/include/drm/drm_dp_helper.h @@ -878,6 +878,7 @@ struct edp_sdp_header { u8 HB3; /* 7:5 reserved, 4:0 number of valid data bytes */ } __packed; +#define EDP_SDP_HEADER_SIZE 4 #define EDP_SDP_HEADER_REVISION_MASK 0x1F #define EDP_SDP_HEADER_VALID_PAYLOAD_BYTES 0x1F