Received: by 2002:a05:7412:b995:b0:f9:9502:5bb8 with SMTP id it21csp4293750rdb; Thu, 28 Dec 2023 17:46:51 -0800 (PST) X-Google-Smtp-Source: AGHT+IHIyN2rcPBHfhZBn+xtmpW4Q8kzJ9ozTWVr632fALfyXlW3W0ZT2KUvGiQ/1HErtTCqweK+ X-Received: by 2002:a17:906:c2c9:b0:a23:dffc:8366 with SMTP id ch9-20020a170906c2c900b00a23dffc8366mr5444242ejb.88.1703814410940; Thu, 28 Dec 2023 17:46:50 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1703814410; cv=none; d=google.com; s=arc-20160816; b=zEwmKqauYIvrGRpaw02linemvDlrnOY17URUN98dM8wE/9QpBeVqT7ApHl49bc4x6a jZ/W3FJ8XNiIGWDnNRmogjdfqbxVAQKYfrBMqjdvgYk3upzXYGFD5WjDDpw+D0mkVg3/ K7dOeEKrucPGwy3KfoFAjU0Fm+DNBQjWoOxwoYhp7flulEM8RHaF49f0sfwhTCfiaMJ+ Xqj8wLbNZzZ3W4VRk0Oikpk4cO+d6pZl+KMMOIOJK67xTuOtXXBvNBveIr4yN6oDsxkK DMXMR98Z7gOrC/2sqD9v0qoAujiM4YPr7dRDrt3Ua2MvySltpDdajbOZF3hUqUW7HIut bu2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=mime-version:list-unsubscribe:list-subscribe:list-id:precedence :references:in-reply-to:message-id:date:subject:cc:to:from; bh=13xCSmM/SJN6wyq4jmQam8qVqv5vNRTpn5JFB2YtlaU=; fh=LPiWBm6ez1s62qjfX1mCP8Bw9lbBkf+R8zBitlrM48g=; b=CWNWVn0QivRMNx9kYeknF5CCNKUn556rlZOB/4taV+/K92L6Z4oSugt7MQ+x62mU1m ouN3QZEumtfQMGkgZO5helm5TS64LFyC+NIgsgA0S2gA8qTkaLQDgo766vME37z3Amok zrBTsUxHwmJ5H3B/a0BjeeyuekcVtWHjXHdOlHbQc/XKbQXnO88W5SOopkCL5vlN2cmV YwxWhHwozK2TMT693qSZmzmyrp+jw8fPkJFAAGEMHGXlFD4bbzaYzyz7SRQsz/b5kqWJ ITiG2bD6rBB2/5acxo7NzSNekjSkyEdUI33DEqEsdbAhK9OMlqb+QC0l+E1Mt0cAz48y xR5g== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-12907-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12907-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [147.75.80.249]) by mx.google.com with ESMTPS id r26-20020a1709067fda00b00a2357304edesi7178967ejs.770.2023.12.28.17.46.50 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Dec 2023 17:46:50 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-12907-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) client-ip=147.75.80.249; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel+bounces-12907-linux.lists.archive=gmail.com@vger.kernel.org designates 147.75.80.249 as permitted sender) smtp.mailfrom="linux-kernel+bounces-12907-linux.lists.archive=gmail.com@vger.kernel.org" Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 88B4F1F21287 for ; Fri, 29 Dec 2023 01:46:50 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 222FF46A9; Fri, 29 Dec 2023 01:46:32 +0000 (UTC) X-Original-To: linux-kernel@vger.kernel.org Received: from mg.richtek.com (mg.richtek.com [220.130.44.152]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C9B523B3 for ; Fri, 29 Dec 2023 01:46:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=richtek.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=richtek.com X-MailGates: (SIP:2,PASS,NONE)(compute_score:DELIVER,40,3) Received: from 192.168.10.46 by mg.richtek.com with MailGates ESMTPS Server V6.0(636823:0:AUTH_RELAY) (envelope-from ) (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256/256); Fri, 29 Dec 2023 09:46:03 +0800 (CST) Received: from ex3.rt.l (192.168.10.46) by ex3.rt.l (192.168.10.46) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.2.1258.27; Fri, 29 Dec 2023 09:46:03 +0800 Received: from linuxcarl2.richtek.com (192.168.10.154) by ex3.rt.l (192.168.10.45) with Microsoft SMTP Server id 15.2.1258.27 via Frontend Transport; Fri, 29 Dec 2023 09:46:03 +0800 From: To: Mark Brown CC: Liam Girdwood , Jaroslav Kysela , Takashi Iwai , ChiYuan Huang , , Subject: [PATCH 2/2] ASoC: codecs: rtq9128: Fix TDM enable and DAI format control flow Date: Fri, 29 Dec 2023 09:46:02 +0800 Message-ID: X-Mailer: git-send-email 1.8.3.1 In-Reply-To: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain From: ChiYuan Huang To enable TDM mode, the current control flow limits the function calling order should be 'set_tdm_slot->set_dai_fmt'. But not all platform sound card like as simeple card to follow this design. To bypass this limit, adjust the DAI format setting in runtime 'hw_param' callback. Signed-off-by: ChiYuan Huang --- sound/soc/codecs/rtq9128.c | 67 ++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 31 deletions(-) diff --git a/sound/soc/codecs/rtq9128.c b/sound/soc/codecs/rtq9128.c index bda64f9eeb62..aa3eadecd974 100644 --- a/sound/soc/codecs/rtq9128.c +++ b/sound/soc/codecs/rtq9128.c @@ -59,6 +59,7 @@ struct rtq9128_data { struct gpio_desc *enable; + unsigned int daifmt; int tdm_slots; int tdm_slot_width; bool tdm_input_data2_select; @@ -441,10 +442,7 @@ static const struct snd_soc_component_driver rtq9128_comp_driver = { static int rtq9128_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) { struct rtq9128_data *data = snd_soc_dai_get_drvdata(dai); - struct snd_soc_component *comp = dai->component; struct device *dev = dai->dev; - unsigned int audfmt, fmtval; - int ret; dev_dbg(dev, "%s: fmt 0x%8x\n", __func__, fmt); @@ -454,35 +452,10 @@ static int rtq9128_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) return -EINVAL; } - fmtval = fmt & SND_SOC_DAIFMT_FORMAT_MASK; - if (data->tdm_slots && fmtval != SND_SOC_DAIFMT_DSP_A && fmtval != SND_SOC_DAIFMT_DSP_B) { - dev_err(dev, "TDM is used, format only support DSP_A or DSP_B\n"); - return -EINVAL; - } + /* Store here and will be used in runtime hw_params for DAI format setting */ + data->daifmt = fmt; - switch (fmtval) { - case SND_SOC_DAIFMT_I2S: - audfmt = 8; - break; - case SND_SOC_DAIFMT_LEFT_J: - audfmt = 9; - break; - case SND_SOC_DAIFMT_RIGHT_J: - audfmt = 10; - break; - case SND_SOC_DAIFMT_DSP_A: - audfmt = data->tdm_slots ? 12 : 11; - break; - case SND_SOC_DAIFMT_DSP_B: - audfmt = data->tdm_slots ? 4 : 3; - break; - default: - dev_err(dev, "Unsupported format 0x%8x\n", fmt); - return -EINVAL; - } - - ret = snd_soc_component_write_field(comp, RTQ9128_REG_I2S_OPT, RTQ9128_AUDFMT_MASK, audfmt); - return ret < 0 ? ret : 0; + return 0; } static int rtq9128_dai_set_tdm_slot(struct snd_soc_dai *dai, unsigned int tx_mask, @@ -558,10 +531,38 @@ static int rtq9128_dai_hw_params(struct snd_pcm_substream *stream, struct snd_pc unsigned int width, slot_width, bitrate, audbit, dolen; struct snd_soc_component *comp = dai->component; struct device *dev = dai->dev; + unsigned int fmtval, audfmt; int ret; dev_dbg(dev, "%s: width %d\n", __func__, params_width(param)); + fmtval = FIELD_GET(SND_SOC_DAIFMT_FORMAT_MASK, data->daifmt); + if (data->tdm_slots && fmtval != SND_SOC_DAIFMT_DSP_A && fmtval != SND_SOC_DAIFMT_DSP_B) { + dev_err(dev, "TDM is used, format only support DSP_A or DSP_B\n"); + return -EINVAL; + } + + switch (fmtval) { + case SND_SOC_DAIFMT_I2S: + audfmt = 8; + break; + case SND_SOC_DAIFMT_LEFT_J: + audfmt = 9; + break; + case SND_SOC_DAIFMT_RIGHT_J: + audfmt = 10; + break; + case SND_SOC_DAIFMT_DSP_A: + audfmt = data->tdm_slots ? 12 : 11; + break; + case SND_SOC_DAIFMT_DSP_B: + audfmt = data->tdm_slots ? 4 : 3; + break; + default: + dev_err(dev, "Unsupported format 0x%8x\n", fmtval); + return -EINVAL; + } + switch (width = params_width(param)) { case 16: audbit = 0; @@ -615,6 +616,10 @@ static int rtq9128_dai_hw_params(struct snd_pcm_substream *stream, struct snd_pc return -EINVAL; } + ret = snd_soc_component_write_field(comp, RTQ9128_REG_I2S_OPT, RTQ9128_AUDFMT_MASK, audfmt); + if (ret < 0) + return ret; + ret = snd_soc_component_write_field(comp, RTQ9128_REG_I2S_OPT, RTQ9128_AUDBIT_MASK, audbit); if (ret < 0) return ret; -- 2.34.1