From patchwork Thu Jan 3 14:23:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Thierry Reding X-Patchwork-Id: 10747417 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 525CA1575 for ; Thu, 3 Jan 2019 14:23:25 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 41149287B4 for ; Thu, 3 Jan 2019 14:23:25 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 3F4BA287F4; Thu, 3 Jan 2019 14:23: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,DKIM_ADSP_CUSTOM_MED, FREEMAIL_FROM,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 D9E2D287DC for ; Thu, 3 Jan 2019 14:23:24 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 8AB4089A60; Thu, 3 Jan 2019 14:23:22 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wr1-x443.google.com (mail-wr1-x443.google.com [IPv6:2a00:1450:4864:20::443]) by gabe.freedesktop.org (Postfix) with ESMTPS id A51CB89A60 for ; Thu, 3 Jan 2019 14:23:20 +0000 (UTC) Received: by mail-wr1-x443.google.com with SMTP id 96so33766663wrb.2 for ; Thu, 03 Jan 2019 06:23:20 -0800 (PST) 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:mime-version :content-transfer-encoding; bh=RVL2wFflv+zmfSz5gHNj0ozT4I2eh2hqgvb0nPbItDg=; b=W/ffe2VcxoOBd2oF6Sct5w/wzle/wgFa/GL5z51gXI0PWwsNV6u+sfdwlUN29KFLIa SW9PGw2kbGS12Lyxbcn8gLth9VzI1RZ08WiLwyGypZ3+IE6cJuP7DslszV9FPQDL+FSG 2QVBP9Ym6GJbt60z1Sn6u//zV2ipNlrqPjqpcZqAiGDnCRHslLLIkTD654QDbTZWc7DV +At+yigsTxyKM91/pPyBglwbkI6cL32nz3bIDViDHC/hSGNXxuTMb0AeJgNnJh9tHRLR D6c/vj6ROtRE6ZTiPHJgD4j8CRogTHr33cZmtkk/cPxMSthBmBnYXczlAu2T9Jkp3HEW Rstw== X-Gm-Message-State: AJcUukdtNhxaaHq/f3IEvYv9HH4Rw+Z5FNy+pp4QWhvaH1odxj86rQPf E3y3awgCMG8Q8sxtOuxWTPqxi0+s X-Google-Smtp-Source: ALg8bN57I+gTwIQCFp7ToTPddrOwnypwNXg3qYgeiCvsJIQ8ao1KgqTj85yL0yt99KQDUaQdVvTtZA== X-Received: by 2002:a5d:6684:: with SMTP id l4mr3577561wru.154.1546525399002; Thu, 03 Jan 2019 06:23:19 -0800 (PST) Received: from localhost (pD9E51040.dip0.t-ipconnect.de. [217.229.16.64]) by smtp.gmail.com with ESMTPSA id v133sm41446375wmf.19.2019.01.03.06.23.18 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 03 Jan 2019 06:23:18 -0800 (PST) From: Thierry Reding To: Thierry Reding Subject: [PATCH 1/3] drm/tegra: sor: Parse more data from HDA format Date: Thu, 3 Jan 2019 15:23:15 +0100 Message-Id: <20190103142317.26124-1-thierry.reding@gmail.com> X-Mailer: git-send-email 2.19.1 MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: dri-devel@lists.freedesktop.org, linux-tegra@vger.kernel.org, Sameer Pujar , Mohan Kumar , Ujwal Patel Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Thierry Reding The HDA format data passed to the SOR from the HDA codec contains more information than just the rate and number of channels. Parse all the fields and store them in an internal structure for subsequent use. While at it, also fix an off-by-one error in the number of channels. Signed-off-by: Thierry Reding --- drivers/gpu/drm/tegra/sor.c | 69 ++++++++++++++++++++++++++++--------- 1 file changed, 53 insertions(+), 16 deletions(-) diff --git a/drivers/gpu/drm/tegra/sor.c b/drivers/gpu/drm/tegra/sor.c index ef8692b7075a..7839223aa040 100644 --- a/drivers/gpu/drm/tegra/sor.c +++ b/drivers/gpu/drm/tegra/sor.c @@ -393,6 +393,13 @@ struct tegra_sor_ops { int (*remove)(struct tegra_sor *sor); }; +struct tegra_sor_audio { + unsigned int sample_rate; + unsigned int channels; + unsigned int bits; + bool pcm; +}; + struct tegra_sor { struct host1x_client client; struct tegra_output output; @@ -429,10 +436,7 @@ struct tegra_sor { struct delayed_work scdc; bool scdc_enabled; - struct { - unsigned int sample_rate; - unsigned int channels; - } audio; + struct tegra_sor_audio audio; }; struct tegra_sor_state { @@ -3195,22 +3199,58 @@ static int tegra_sor_parse_dt(struct tegra_sor *sor) return 0; } -static void tegra_hda_parse_format(unsigned int format, unsigned int *rate, - unsigned int *channels) +static void tegra_hda_parse_format(unsigned int format, + struct tegra_sor_audio *audio) { - unsigned int mul, div; + unsigned int mul, div, bits, channels; + + if (format & AC_FMT_TYPE_NON_PCM) + audio->pcm = false; + else + audio->pcm = true; if (format & AC_FMT_BASE_44K) - *rate = 44100; + audio->sample_rate = 44100; else - *rate = 48000; + audio->sample_rate = 48000; mul = (format & AC_FMT_MULT_MASK) >> AC_FMT_MULT_SHIFT; div = (format & AC_FMT_DIV_MASK) >> AC_FMT_DIV_SHIFT; - *rate = *rate * (mul + 1) / (div + 1); + audio->sample_rate = audio->sample_rate * (mul + 1) / (div + 1); + + switch (format & AC_FMT_BITS_MASK) { + case AC_FMT_BITS_8: + audio->bits = 8; + break; + + case AC_FMT_BITS_16: + audio->bits = 16; + break; + + case AC_FMT_BITS_20: + audio->bits = 20; + break; + + case AC_FMT_BITS_24: + audio->bits = 24; + break; + + case AC_FMT_BITS_32: + audio->bits = 32; + break; + + default: + bits = (format & AC_FMT_BITS_MASK) >> AC_FMT_BITS_SHIFT; + WARN(1, "invalid number of bits: %#x\n", bits); + audio->bits = 8; + break; + } - *channels = (format & AC_FMT_CHAN_MASK) >> AC_FMT_CHAN_SHIFT; + channels = (format & AC_FMT_CHAN_MASK) >> AC_FMT_CHAN_SHIFT; + + /* channels are encoded as n - 1 */ + audio->channels = channels + 1; } static irqreturn_t tegra_sor_irq(int irq, void *data) @@ -3225,14 +3265,11 @@ static irqreturn_t tegra_sor_irq(int irq, void *data) value = tegra_sor_readl(sor, SOR_AUDIO_HDA_CODEC_SCRATCH0); if (value & SOR_AUDIO_HDA_CODEC_SCRATCH0_VALID) { - unsigned int format, sample_rate, channels; + unsigned int format; format = value & SOR_AUDIO_HDA_CODEC_SCRATCH0_FMT_MASK; - tegra_hda_parse_format(format, &sample_rate, &channels); - - sor->audio.sample_rate = sample_rate; - sor->audio.channels = channels; + tegra_hda_parse_format(format, &sor->audio); tegra_sor_hdmi_audio_enable(sor); } else {