Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp733611img; Thu, 28 Feb 2019 07:04:34 -0800 (PST) X-Google-Smtp-Source: AHgI3IYpZm2fKl99Z6u6jmqqk3h1509p0Fm+8Tl8N57Bwnb9GLZc9Jzmi+q9sWBappheGc/w8WW3 X-Received: by 2002:a17:902:b7c9:: with SMTP id v9mr8224492plz.68.1551366274021; Thu, 28 Feb 2019 07:04:34 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551366274; cv=none; d=google.com; s=arc-20160816; b=p2rtlFy7An7McAUMA1WDoaZFU+v6WTx4LgU8G6JmyVreGvIzxzcPQ+43w7W5xKkR9i ZFRnYXEO2tZ6mlgOQyHg3VnyNSEV6UHutLesrshFSDi8RMkt1hG7EdTmzHXYkOFbHV4a Fa15lJ1EfLAm8o85qhqmxxoz2JZqvt77VDyWB5Zcyr0PuWzqqwf0G4ci2ncNvt5ichwy DSQp/4gYkys9OfRehEkdF808LCQ53ts2Vo2Jf6Ft8KIOn4b+JNl+VOPeMuYrqUZO2Fey N/GOc3sEt3r3maqD6EnglVXDGFJEUtjtHcA6ViPbF2k+Z9bgcNTeW5q7ovVFys8kEcRq 07OQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding :content-language:in-reply-to:mime-version:user-agent:date :message-id:autocrypt:openpgp:from:references:cc:to:subject :dkim-signature; bh=PrJaCcs2AbICKqJIKvTvH4NOxph+19+zP5+iWZOmDjY=; b=vuRfjHTLSfUdn+UvsKDAxP4Q+5fAZ9HLgIuMKCYziE81h7iunhWJ8MZdArTer9ZuV5 x3cew5V3+6yjBmAoBSmGY62cNhnzIX+vvPei74uOu762ihxuzTJ2Rvq703+XelLp3gax 8FLVh39/x90gRasaa51VBPUfH+AEBuF5fzQltNcUKwsqn8wuCgNyS9jvtJv4MZWUcFe3 MN0pcOnrYT31N7+j9ycv8byD0glXevmNdWRxv8k4xmHKjVrIuGU5D9CtcYgLh+kwbpRL SHCw/XCC+aAiK50nrN7nj+MEIPP3NuXLdsZ2cW/00anHNYemj74M5w5sKzXi5gMDId9r 3dmA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="zODHxJ0/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 1si16247740ply.232.2019.02.28.07.04.16; Thu, 28 Feb 2019 07:04:33 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@ti.com header.s=ti-com-17Q1 header.b="zODHxJ0/"; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=NONE dis=NONE) header.from=ti.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732663AbfB1Ols (ORCPT + 99 others); Thu, 28 Feb 2019 09:41:48 -0500 Received: from lelv0143.ext.ti.com ([198.47.23.248]:37440 "EHLO lelv0143.ext.ti.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725896AbfB1Olr (ORCPT ); Thu, 28 Feb 2019 09:41:47 -0500 Received: from fllv0034.itg.ti.com ([10.64.40.246]) by lelv0143.ext.ti.com (8.15.2/8.15.2) with ESMTP id x1SEfTWM115140; Thu, 28 Feb 2019 08:41:29 -0600 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ti.com; s=ti-com-17Q1; t=1551364889; bh=PrJaCcs2AbICKqJIKvTvH4NOxph+19+zP5+iWZOmDjY=; h=Subject:To:CC:References:From:Date:In-Reply-To; b=zODHxJ0/r7eruppnOEBErq3FiGoHDJWfUeszP9ViuXhi8DoaVMqzIaF8SvN38rdOe WzpJIlPzjnogMD6UaS+OUZi/Wa8DxP15aMlY7SoBUojnyTjpQtwEPDJi6mLWMXIxDb i4xOyIEuhGDI2ZIOvaKBIugWkZM22lxGr11ajVn8= Received: from DFLE104.ent.ti.com (dfle104.ent.ti.com [10.64.6.25]) by fllv0034.itg.ti.com (8.15.2/8.15.2) with ESMTPS id x1SEfThp090575 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=FAIL); Thu, 28 Feb 2019 08:41:29 -0600 Received: from DFLE115.ent.ti.com (10.64.6.36) by DFLE104.ent.ti.com (10.64.6.25) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.1591.10; Thu, 28 Feb 2019 08:41:28 -0600 Received: from dflp32.itg.ti.com (10.64.6.15) by DFLE115.ent.ti.com (10.64.6.36) with Microsoft SMTP Server (version=TLS1_0, cipher=TLS_RSA_WITH_AES_256_CBC_SHA) id 15.1.1591.10 via Frontend Transport; Thu, 28 Feb 2019 08:41:27 -0600 Received: from [10.1.3.6] (ileax41-snat.itg.ti.com [10.172.224.153]) by dflp32.itg.ti.com (8.14.3/8.13.8) with ESMTP id x1SEfQdf026300; Thu, 28 Feb 2019 08:41:26 -0600 Subject: Re: hdmi-codec: modifying params in hw_params() callback To: Russell King - ARM Linux admin CC: Liam Girdwood , Mark Brown , , , References: <20190228121516.swd3vweisgcxlvld@shell.armlinux.org.uk> <421c1217-6ff6-6ca2-8169-db026284fb29@ti.com> <20190228131059.i4nffuylja5p6tjv@shell.armlinux.org.uk> <20190228143912.imjsc2ynnltydeny@shell.armlinux.org.uk> From: Jyri Sarha Openpgp: preference=signencrypt Autocrypt: addr=jsarha@ti.com; prefer-encrypt=mutual; keydata= mQINBFbd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38Cl4P9PK1JX 8VK661BG8GXsXJ3uZbPSu6K0+FiJy09N4IW7CPJNABEBAAGJAh8EGAECAAkFAlbdWt8CGwwA CgkQkDazUNfWGUFOfRAA5K/z9DXVEl2kkuMuIWkgtuuLQ7ZwqgxGP3dMA5z3Iv/N+VNRGbaw oxf+ZkTbJHEE/dWclj1TDtpET/t6BJNLaldLtJ1PborQH+0jTmGbsquemKPgaHeSU8vYLCdc GV/Rz+3FN0/fRdmoq2+bIHght4T6KZJ6jsrnBhm7y6gzjMOiftH6M5GXPjU0/FsU09qsk/af jbwLETaea0mlWMrLd9FC2KfVITA/f/YG2gqtUUF9WlizidyctWJqSTZn08MdzaoPItIkRUTv 6Bv6rmFn0daWkHt23BLd0ZP7e7pON1rqNVljWjWQ/b/E/SzeETrehgiyDr8pP+CLlC+vSQxi XtjhWjt1ItFLXxb4/HLZbb/L4gYX7zbZ3NwkON6Ifn3VU7UwqxGLmKfUwu/mFV+DXif1cKSS v6vWkVQ6Go9jPsSMFxMXPA5317sZZk/v18TAkIiwFqda3/SSjwc3e8Y76/DwPvUQd36lEbva uBrUXDDhCoiZnjQaNz/J+o9iYjuMTpY1Wp+igjIretYr9+kLvGsoPo/kTPWyiuh/WiFU2d6J PMCGFGhodTS5qmQA6IOuazek1qSZIl475u3E2uG98AEX/kRhSzgpsbvADPEUPaz75uvlmOCX tv+Sye9QT4Z1QCh3lV/Zh4GlY5lt4MwYnqFCxroK/1LpkLgdyQ4rRVw= Message-ID: <5b8aa94b-934a-380c-33d2-c381c6673279@ti.com> Date: Thu, 28 Feb 2019 16:41:25 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.4.0 MIME-Version: 1.0 In-Reply-To: <20190228143912.imjsc2ynnltydeny@shell.armlinux.org.uk> Content-Type: text/plain; charset="utf-8" Content-Language: en-GB Content-Transfer-Encoding: 7bit X-EXCLAIMER-MD-CONFIG: e1e8a2fd-e40a-4ac6-ac9b-f7e9cc9ee180 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 28/02/2019 16:39, Russell King - ARM Linux admin wrote: > On Thu, Feb 28, 2019 at 04:35:29PM +0200, Jyri Sarha wrote: >> On 28/02/2019 15:10, Russell King - ARM Linux admin wrote: >>> On Thu, Feb 28, 2019 at 02:54:29PM +0200, Jyri Sarha wrote: >>>> On 28/02/2019 14:15, Russell King - ARM Linux admin wrote: >>>>> Hi all, >>>>> >>>>> While looking at hdmi-codec issues, I spotted this code: >>>>> >>>>> static int hdmi_codec_hw_params(struct snd_pcm_substream *substream, >>>>> struct snd_pcm_hw_params *params, >>>>> struct snd_soc_dai *dai) >>>>> { >>>>> ... >>>>> if (params_width(params) > 24) >>>>> params->msbits = 24; >>>>> >>>>> params->msbits is a parameter that is negotiated and refined by >>>>> libasound, and is part of the ALSA constraint system. The "Writing an >>>>> ALSA driver" documentation says about the hw_params callback: >>>>> >>>>> "This is called when the hardware parameter (``hw_params``) is set up >>>>> by the application, that is, once when the buffer size, the period >>>>> size, the format, etc. are defined for the pcm substream." >>>>> >>>>> which suggests we should only be reading the parameters, not writing >>>>> to them. >>>>> >>>>> What's more is that the msbits is a parameter that is refined with >>>>> userspace, so surely the above should be a declared constraint? >>>>> >>>> >>>> Certainly not a constraint. While HDMI can only pass up to 24-bit per >>>> sample audio the most (or at least the two I have worked with) encoders >>>> can take 32-bit wide (and probably wider) samples trough i2s. So the >>>> system can play 32-bit samples, just the 4 LSB is ignored. >>> >>> You have not explained why "not a constraint". From the explanation >>> that Mark gave me on IRC, msbits is the number of bits that the codec >>> respects, whereas the sample bits is the number of bits in the sample. >>> If sample bits - msbits != 0, then that is the number of bits ignored. >>> Mark basically described it as "feel free to send me more than 24 bits >>> but I'm ignoring the LSBs". >>> >>> If the msbits is limited to 24, then userspace gets to know about that >>> limitation when negotiating with ALSA if it is a constraint. If it >>> isn't a constraint, userspace has no way to know. >>> >>>> Actually there is very little difference between the case of playing >>>> 32-bit stereo audio with matching i2s bclk ratio, and playing 24-bit >>>> stereo audio with 64-bit bclk ratio. Especially when the 4 LSB is anyway >>>> ignored like in HDMI audio case. >>> >>> You mean 8 LSB throughout the above two paragraphs. >>> >>>>> Digging a bit deeper, ASoC passes a private copy of the params to each >>>>> codec - a copy is made, then fixups for TDM slots are applied, followed >>>>> by any topology fixups by the DAI link (be_hw_params_fixup) before the >>>>> codec driver's hw_params() callback is made. Afterwards, ASoC reads >>>>> back the rate, channels and physical (memory) width and stores them >>>>> in the codec's DAI structure. The msbits are not read. >>>>> >>>>> hdmi-codec also seems to do nothing with the msbits parameter other >>>>> than the above code. >>>>> >>>>> So, all in all, it seems that the above code limiting msbits is >>>>> redundant - nothing will read this modified value. Can we kill it? >>>>> >>>> >>>> It certainly looks that way, so yes. In any case struct >>>> snd_soc_dai_driver .playback.sig_bits = 24 should be all that is needed. >>> >>> This sets a constraint to limit msbits to 24 for any sample width >>> in core ASoC code, doing exactly what you said "certainly not" to >>> above. >>> >>> It also means that the quoted code in hdmi-codec's hw_params() is >>> redundant for another reason. >>> >>> See the description of: >>> snd_pcm_hw_constraint_msbits() in sound/core/pcm_lib.c, >>> soc_pcm_set_msb() and soc_pcm_apply_msb() in sound/soc/soc-pcm.c. >>> >>> Can you please clarify, because there seems to be some confusion. >>> >> >> If I understand right, the only confusion here is around the term >> "constraint". I did not follow that you meant in strictly alsa-term. Yes >> we should set msbits pcm_lib constraint to 24 (as hdmi-codec aready >> does), because HDMI interface can not deliver more than 24 bits per >> sample, and any extra LSB bit will be ignored. > > Right, so we can remove the above code then? > Yes, you correctly pointed out that this piece of code does nothing and is conceptually wrong: if (params_width(params) > 24) params->msbits = 24; Yes. It can be removed. -- Texas Instruments Finland Oy, Porkkalankatu 22, 00180 Helsinki. Y-tunnus/Business ID: 0615521-4. Kotipaikka/Domicile: Helsinki