Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp5214601ybl; Tue, 27 Aug 2019 00:55:24 -0700 (PDT) X-Google-Smtp-Source: APXvYqz2xdvYaDUT2wijUkEfKOKikzsBhXe7TiukuwYwkXf6Ii/6tvDaaY8PAGj9rS/YKsE6Vos/ X-Received: by 2002:a17:90a:3082:: with SMTP id h2mr24260560pjb.53.1566892524600; Tue, 27 Aug 2019 00:55:24 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566892524; cv=none; d=google.com; s=arc-20160816; b=SeLv8NZg7mI19SpG24oFZtzvyvvGUfqg/c3h2qpWvx+7CJGHLvwOPYgK5JpNNllWpR uGR1l2slShmNhxB2Jf+WDy/flMhgtIDubA63jsbWb6nJ05ZDhSOmgMl709gddCNz1VRz W2HzDbWxYIYiNJvH/pZ8swRmvKtYbg7qcoaQdJs3Byx5jHyd9Pt4GWeAtfFlbh0DSxf6 /UvSfHsG/xbDD5i5AiY1TYgaNM16N+TgqNWLyyVYuDkeDraJo7StBwPZrEOgH1qNsD0u pmvxW0fHzDwHBL5StOIhshVdYoiliOJdL+o4T8GFYQgpeCTVNKb0CVx46qMQXo86wChT 5pDA== 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:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=csYdGUCGkuZ6dSxQppukESmsrDJ5XTx67DCIC6Z0yqM=; b=wS4Sc0Gq+qc5Fs9Vkq3ywcZ8URQb1s4UnQuDcVXccwbQtf0bsoSoYsRkFI0JqbMiHX GVo/Wo7Vi6F8u/D2s7G8wOC+4Pyy2L580VDqEqFh8b5Q3iTH53tpAIYpSsZRWpxWlq7V oOgOal7kOYdFmuzh6oq3olWZRxNWErymkNFniUU9JC4So/JxHF9k8RaOLio+uep3gXk+ vQcf9SJ4uBR13BqSbDy1RzBDqdLv2FFKJHxLUiE9l1RSPLG6FOtLNRtYS3PS6qI8paHH MBhCJQbNLeaNi87J8j8fQkTizH+8MCOMtyr6rcPzeMrx7ud653sB3rU8lnHtvnqbLZby IERA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=dCH5SA0i; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id s3si11268567pgn.467.2019.08.27.00.55.09; Tue, 27 Aug 2019 00:55:24 -0700 (PDT) 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=@kernel.org header.s=default header.b=dCH5SA0i; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729250AbfH0Hxk (ORCPT + 99 others); Tue, 27 Aug 2019 03:53:40 -0400 Received: from mail.kernel.org ([198.145.29.99]:45184 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729128AbfH0Hxi (ORCPT ); Tue, 27 Aug 2019 03:53:38 -0400 Received: from localhost (83-86-89-107.cable.dynamic.v4.ziggo.nl [83.86.89.107]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 3AB0822CED; Tue, 27 Aug 2019 07:53:36 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566892416; bh=EF70cvt9s7OlLybKyQL8sZAeFzv3QTBh4dxWHZqbsbI=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=dCH5SA0i81zwcb/84Q7eH6Kw1+JvoZ2RrQ7zRHkJQTe/SE4b5VRo+rtJ6KL5MHBVE YeQnCX0gI1raEbjl3jXuQqJ0PT98J9IAxFaEu32lZTI4j/rjYwGn8NRshh0lvxpzFj kb9TaVfqa8f83Vsuaam4jES3sYHWI9M1L16IXZhQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Peter Ujfalusi , Mark Brown , Sasha Levin Subject: [PATCH 4.14 11/62] ASoC: ti: davinci-mcasp: Correct slot_width posed constraint Date: Tue, 27 Aug 2019 09:50:16 +0200 Message-Id: <20190827072701.023825678@linuxfoundation.org> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20190827072659.803647352@linuxfoundation.org> References: <20190827072659.803647352@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org [ Upstream commit 1e112c35e3c96db7c8ca6ddaa96574f00c06e7db ] The slot_width is a property for the bus while the constraint for SNDRV_PCM_HW_PARAM_SAMPLE_BITS is for the in memory format. Applying slot_width constraint to sample_bits works most of the time, but it will blacklist valid formats in some cases. With slot_width 24 we can support S24_3LE and S24_LE formats as they both look the same on the bus, but a a 24 constraint on sample_bits would not allow S24_LE as it is stored in 32bits in memory. Implement a simple hw_rule function to allow all formats which require less or equal number of bits on the bus as slot_width (if configured). Signed-off-by: Peter Ujfalusi Link: https://lore.kernel.org/r/20190726064244.3762-2-peter.ujfalusi@ti.com Signed-off-by: Mark Brown Signed-off-by: Sasha Levin --- sound/soc/davinci/davinci-mcasp.c | 43 ++++++++++++++++++++++++------- 1 file changed, 34 insertions(+), 9 deletions(-) diff --git a/sound/soc/davinci/davinci-mcasp.c b/sound/soc/davinci/davinci-mcasp.c index 9aa741d272798..0480ec4c80354 100644 --- a/sound/soc/davinci/davinci-mcasp.c +++ b/sound/soc/davinci/davinci-mcasp.c @@ -1158,6 +1158,28 @@ static int davinci_mcasp_trigger(struct snd_pcm_substream *substream, return ret; } +static int davinci_mcasp_hw_rule_slot_width(struct snd_pcm_hw_params *params, + struct snd_pcm_hw_rule *rule) +{ + struct davinci_mcasp_ruledata *rd = rule->private; + struct snd_mask *fmt = hw_param_mask(params, SNDRV_PCM_HW_PARAM_FORMAT); + struct snd_mask nfmt; + int i, slot_width; + + snd_mask_none(&nfmt); + slot_width = rd->mcasp->slot_width; + + for (i = 0; i <= SNDRV_PCM_FORMAT_LAST; i++) { + if (snd_mask_test(fmt, i)) { + if (snd_pcm_format_width(i) <= slot_width) { + snd_mask_set(&nfmt, i); + } + } + } + + return snd_mask_refine(fmt, &nfmt); +} + static const unsigned int davinci_mcasp_dai_rates[] = { 8000, 11025, 16000, 22050, 32000, 44100, 48000, 64000, 88200, 96000, 176400, 192000, @@ -1251,7 +1273,7 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream, struct davinci_mcasp_ruledata *ruledata = &mcasp->ruledata[substream->stream]; u32 max_channels = 0; - int i, dir; + int i, dir, ret; int tdm_slots = mcasp->tdm_slots; /* Do not allow more then one stream per direction */ @@ -1280,6 +1302,7 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream, max_channels++; } ruledata->serializers = max_channels; + ruledata->mcasp = mcasp; max_channels *= tdm_slots; /* * If the already active stream has less channels than the calculated @@ -1305,20 +1328,22 @@ static int davinci_mcasp_startup(struct snd_pcm_substream *substream, 0, SNDRV_PCM_HW_PARAM_CHANNELS, &mcasp->chconstr[substream->stream]); - if (mcasp->slot_width) - snd_pcm_hw_constraint_minmax(substream->runtime, - SNDRV_PCM_HW_PARAM_SAMPLE_BITS, - 8, mcasp->slot_width); + if (mcasp->slot_width) { + /* Only allow formats require <= slot_width bits on the bus */ + ret = snd_pcm_hw_rule_add(substream->runtime, 0, + SNDRV_PCM_HW_PARAM_FORMAT, + davinci_mcasp_hw_rule_slot_width, + ruledata, + SNDRV_PCM_HW_PARAM_FORMAT, -1); + if (ret) + return ret; + } /* * If we rely on implicit BCLK divider setting we should * set constraints based on what we can provide. */ if (mcasp->bclk_master && mcasp->bclk_div == 0 && mcasp->sysclk_freq) { - int ret; - - ruledata->mcasp = mcasp; - ret = snd_pcm_hw_rule_add(substream->runtime, 0, SNDRV_PCM_HW_PARAM_RATE, davinci_mcasp_hw_rule_rate, -- 2.20.1