From patchwork Tue May 26 18:59:08 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jyri Sarha X-Patchwork-Id: 6485181 Return-Path: X-Original-To: patchwork-linux-omap@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork2.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork2.web.kernel.org (Postfix) with ESMTP id E0429C0434 for ; Tue, 26 May 2015 19:00:08 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 041F820673 for ; Tue, 26 May 2015 19:00:08 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id F28DC20678 for ; Tue, 26 May 2015 19:00:06 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751774AbbEZTAG (ORCPT ); Tue, 26 May 2015 15:00:06 -0400 Received: from arroyo.ext.ti.com ([192.94.94.40]:59020 "EHLO arroyo.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751786AbbEZTAD (ORCPT ); Tue, 26 May 2015 15:00:03 -0400 Received: from dflxv15.itg.ti.com ([128.247.5.124]) by arroyo.ext.ti.com (8.13.7/8.13.7) with ESMTP id t4QIxiDe001754; Tue, 26 May 2015 13:59:44 -0500 Received: from DFLE72.ent.ti.com (dfle72.ent.ti.com [128.247.5.109]) by dflxv15.itg.ti.com (8.14.3/8.13.8) with ESMTP id t4QIxiRG019210; Tue, 26 May 2015 13:59:44 -0500 Received: from dflp33.itg.ti.com (10.64.6.16) by DFLE72.ent.ti.com (128.247.5.109) with Microsoft SMTP Server id 14.3.224.2; Tue, 26 May 2015 13:59:44 -0500 Received: from imryr.ti.com (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp33.itg.ti.com (8.14.3/8.13.8) with ESMTP id t4QIxUKq032651; Tue, 26 May 2015 13:59:42 -0500 From: Jyri Sarha To: , , , CC: , , , , , , Jyri Sarha Subject: [PATCH RFC v2 4/7] ASoC: hdmi-codec: Add ELD based audio pcm rules DO NOT MERGE Date: Tue, 26 May 2015 21:59:08 +0300 Message-ID: <1432666751-24794-5-git-send-email-jsarha@ti.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1432666751-24794-1-git-send-email-jsarha@ti.com> References: <1432666751-24794-1-git-send-email-jsarha@ti.com> MIME-Version: 1.0 Sender: linux-omap-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-omap@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP This patch is mostly just a copy paste from Russel King's generic patchs[1] for the same thing. The patche is included only for testing purposes. Do not merge! [1] http://lists.freedesktop.org/archives/dri-devel/2015-April/080525.html Signed-off-by: Jyri Sarha --- sound/soc/codecs/hdmi-codec.c | 104 +++++++++++++++++++++++++++++++++++++++++- 1 file changed, 103 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/hdmi-codec.c b/sound/soc/codecs/hdmi-codec.c index c208cef..2d26ce8 100644 --- a/sound/soc/codecs/hdmi-codec.c +++ b/sound/soc/codecs/hdmi-codec.c @@ -78,6 +78,103 @@ static int hdmi_codec_new_stream(struct snd_pcm_substream *substream, return ret; } +static const uint8_t *eld_sad(const uint8_t *eld) +{ + unsigned int ver, mnl; + + ver = (eld[DRM_ELD_VER] & DRM_ELD_VER_MASK) >> DRM_ELD_VER_SHIFT; + if (ver != 2 && ver != 31) + return NULL; + + mnl = drm_eld_mnl(eld); + if (mnl > 16) + return NULL; + + return eld + DRM_ELD_CEA_SAD(mnl, 0); +} + +static const unsigned int eld_rates[] = { + 32000, + 44100, + 48000, + 88200, + 96000, + 176400, + 192000, +}; + +static int eld_limit_rates(struct snd_pcm_hw_params *params, + struct snd_pcm_hw_rule *rule) +{ + struct snd_interval *r = hw_param_interval(params, rule->var); + unsigned int rate_mask = 7, i; + const u8 *sad, *eld = rule->private; + + sad = eld_sad(eld); + if (sad) { + for (i = drm_eld_sad_count(eld); i > 0; i--, sad += 3) { + unsigned channels = 1 + (sad[0] & 7); + + /* + * Exclude SADs which do not include the + * requested number of channels. + */ + if (params_channels(params) == channels) + rate_mask |= sad[1]; + } + } + + return snd_interval_list(r, ARRAY_SIZE(eld_rates), eld_rates, + rate_mask); +} + +static int eld_limit_channels(struct snd_pcm_hw_params *params, + struct snd_pcm_hw_rule *rule) +{ + struct snd_interval *var = hw_param_interval(params, rule->var); + struct snd_interval t = { .min = 1, .max = 2, .integer = 1, }; + unsigned int i, j; + const u8 *sad, *eld = rule->private; + int rate = params_rate(params); + + sad = eld_sad(eld); + if (!sad) + return 0; + + for (i = drm_eld_sad_count(eld); i > 0; i--, sad += 3) { + for (j = 0; j < ARRAY_SIZE(eld_rates); j++) { + if ((sad[1] & (1<hcd.ops->get_eld) { hcp->eld = hcp->hcd.ops->get_eld(hcp->hcd.dev); - /* Call snd_pcm_hw_constraint_eld here */ + if (hcp->eld) { + ret = hdmi_codec_constraint_eld(substream->runtime, + hcp->eld); + if (ret) + return ret; + } } return 0; }