Received: by 2002:ac0:8845:0:0:0:0:0 with SMTP id g63csp631983img; Thu, 28 Feb 2019 05:28:31 -0800 (PST) X-Google-Smtp-Source: AHgI3IaVT7hKl+qbshyD2K9axYRRfl+g2tGhKh65oJMwyRymHe6WL1Q37HShL3pATm413E8GoE7j X-Received: by 2002:a62:5e46:: with SMTP id s67mr7450855pfb.126.1551360511332; Thu, 28 Feb 2019 05:28:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1551360511; cv=none; d=google.com; s=arc-20160816; b=sxLxFT2z/LwNHyk1xJNHryn5lgSRKiCrw9+zWe5F5GnoUoBL75nH7CezJCBWR1TRjZ uTLLEbPNGsN75+fNZDZmqrR5XO9WiE5frGkTpnN1KSRZLfrjQlIBp+TaXMoWMHWTcUtJ 9hZL5SVEgqdSIJHEM06Vll0NgJfSHeUHCaGpnYIRmrNvhquxAuKdZ+oy9mHn1AUsgYe7 eREa8sUUIHfRpmsbLuNZJ7csIW+ttcLNLfInC6+8nr8rv+iWrAOLjotQeK2eHhtbMSeD isqg5Q+JY1mvsEbc1ZtvJ0gVdmXphh6P8uXDQ68jZ6GnifTqCDMPloXQt0Yan7mfb1Om XDfQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date:dkim-signature; bh=1dCsrev92yUWlX4d+Ar1uRdwfi+4D5obO9jb8ZJ/b+U=; b=n1oHUc2bMUW2xzuHjcoCJnCm3L7BuuQUZinbFMe1QN1yNRMJxGD9OpkpKi7hWF16R/ 5oaAO7iQJiaJ/37kjMgH5OjxFuMDBZ9K2iLen8aagXfAfNdcgm50sJGYJcIyjH1k2bmt 0Fl+B2EWoxrjOZVIuwhEow/A2gRTKg+IgDmAAW/jfwDGVe4ap9Uyht71D8EMYoltW9tG KVndAD/KGWyXFB+hnQZZ0Za4Ci506Ewgl6bHF9+gHw6/N3H/NnEvzxThTzL1Xls+9+9+ zaXhZbT6TTlTXklIXook+DTwnJ2TxzyWicFsdU/+1fcZohDXMEZbycKtNzPhU6mIB2Sd Luow== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=eFp1quFw; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id k86si18383342pfj.145.2019.02.28.05.28.15; Thu, 28 Feb 2019 05:28:31 -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=fail (test mode) header.i=@armlinux.org.uk header.s=pandora-2019 header.b=eFp1quFw; 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=fail (p=NONE sp=NONE dis=NONE) header.from=armlinux.org.uk Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732004AbfB1NLP (ORCPT + 99 others); Thu, 28 Feb 2019 08:11:15 -0500 Received: from pandora.armlinux.org.uk ([78.32.30.218]:47952 "EHLO pandora.armlinux.org.uk" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727717AbfB1NLO (ORCPT ); Thu, 28 Feb 2019 08:11:14 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=armlinux.org.uk; s=pandora-2019; h=Sender:In-Reply-To:Content-Type: MIME-Version:References:Message-ID:Subject:Cc:To:From:Date:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Id: List-Help:List-Unsubscribe:List-Subscribe:List-Post:List-Owner:List-Archive; bh=1dCsrev92yUWlX4d+Ar1uRdwfi+4D5obO9jb8ZJ/b+U=; b=eFp1quFw5OgV4mP9xZ5WPursg peLdyjIrJzawQ6eUs188NJ9RykVtb+UT9TYFA9Ew/TDUEkZmdJIWyJ12pAbRKcLRGHsvqxnxS5DWf 2BCF7r/VVPnEIcWy74d2bz0sewEFC0QsX4mWmA/zNeXYUvsB2OLY/8HTSH8Hrx1y5s+5/mfQ3Sjqf cp+1gQdd3U3wD5eGrlWFFOFFhEkdg0x1EWToMQnnwVdRozv2gJKcSbFPbJJ+PufcFCABUqhro7SPJ yk0pgx899ZnsAaZjtHBjYIHLbVX6HBLEnoLeLi0oATG+FEPjm1VRvleWfxsTz/YMjl9FElDsK+2WQ 2UsPe3KFg==; Received: from shell.armlinux.org.uk ([2001:4d48:ad52:3201:5054:ff:fe00:4ec]:54870) by pandora.armlinux.org.uk with esmtpsa (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1gzLSn-0000VK-Ue; Thu, 28 Feb 2019 13:11:02 +0000 Received: from linux by shell.armlinux.org.uk with local (Exim 4.89) (envelope-from ) id 1gzLSl-0007QC-8b; Thu, 28 Feb 2019 13:10:59 +0000 Date: Thu, 28 Feb 2019 13:10:59 +0000 From: Russell King - ARM Linux admin To: Jyri Sarha Cc: Liam Girdwood , Mark Brown , alsa-devel@alsa-project.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org Subject: Re: hdmi-codec: modifying params in hw_params() callback Message-ID: <20190228131059.i4nffuylja5p6tjv@shell.armlinux.org.uk> References: <20190228121516.swd3vweisgcxlvld@shell.armlinux.org.uk> <421c1217-6ff6-6ca2-8169-db026284fb29@ti.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <421c1217-6ff6-6ca2-8169-db026284fb29@ti.com> User-Agent: NeoMutt/20170113 (1.7.2) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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. Thanks. -- RMK's Patch system: https://www.armlinux.org.uk/developer/patches/ FTTC broadband for 0.8mile line in suburbia: sync at 12.1Mbps down 622kbps up According to speedtest.net: 11.9Mbps down 500kbps up