From nobody Fri Dec 26 21:47:52 2025 Received: from mg.richtek.com (mg.richtek.com [220.130.44.152]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 1C9DD23B4 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.47 by mg.richtek.com with MailGates ESMTPS Server V6.0(636808: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 ex4.rt.l (192.168.10.47) 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 1/2] ASoC: codecs: rtq9128: Fix PM_RUNTIME usage Date: Fri, 29 Dec 2023 09:46:01 +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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" From: ChiYuan Huang If 'pm_runtime_resume_and_get' is used, must check the return value to prevent the active count not matched problem. Signed-off-by: ChiYuan Huang --- sound/soc/codecs/rtq9128.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/sound/soc/codecs/rtq9128.c b/sound/soc/codecs/rtq9128.c index c22b047115cc..bda64f9eeb62 100644 --- a/sound/soc/codecs/rtq9128.c +++ b/sound/soc/codecs/rtq9128.c @@ -391,7 +391,11 @@ static int rtq9128_component_probe(struct snd_soc_comp= onent *comp) unsigned int val; int i, ret; =20 - pm_runtime_resume_and_get(comp->dev); + ret =3D pm_runtime_resume_and_get(comp->dev); + if (ret < 0) { + dev_err(comp->dev, "Failed to resume device (%d)\n", ret); + return ret; + } =20 val =3D snd_soc_component_read(comp, RTQ9128_REG_EFUSE_DATA); =20 --=20 2.34.1 From nobody Fri Dec 26 21:47:52 2025 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-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" 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 @@ =20 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_c= omp_driver =3D { static int rtq9128_dai_set_fmt(struct snd_soc_dai *dai, unsigned int fmt) { struct rtq9128_data *data =3D snd_soc_dai_get_drvdata(dai); - struct snd_soc_component *comp =3D dai->component; struct device *dev =3D dai->dev; - unsigned int audfmt, fmtval; - int ret; =20 dev_dbg(dev, "%s: fmt 0x%8x\n", __func__, fmt); =20 @@ -454,35 +452,10 @@ static int rtq9128_dai_set_fmt(struct snd_soc_dai *da= i, unsigned int fmt) return -EINVAL; } =20 - fmtval =3D fmt & SND_SOC_DAIFMT_FORMAT_MASK; - if (data->tdm_slots && fmtval !=3D SND_SOC_DAIFMT_DSP_A && fmtval !=3D SN= D_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 settin= g */ + data->daifmt =3D fmt; =20 - switch (fmtval) { - case SND_SOC_DAIFMT_I2S: - audfmt =3D 8; - break; - case SND_SOC_DAIFMT_LEFT_J: - audfmt =3D 9; - break; - case SND_SOC_DAIFMT_RIGHT_J: - audfmt =3D 10; - break; - case SND_SOC_DAIFMT_DSP_A: - audfmt =3D data->tdm_slots ? 12 : 11; - break; - case SND_SOC_DAIFMT_DSP_B: - audfmt =3D data->tdm_slots ? 4 : 3; - break; - default: - dev_err(dev, "Unsupported format 0x%8x\n", fmt); - return -EINVAL; - } - - ret =3D snd_soc_component_write_field(comp, RTQ9128_REG_I2S_OPT, RTQ9128_= AUDFMT_MASK, audfmt); - return ret < 0 ? ret : 0; + return 0; } =20 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_subst= ream *stream, struct snd_pc unsigned int width, slot_width, bitrate, audbit, dolen; struct snd_soc_component *comp =3D dai->component; struct device *dev =3D dai->dev; + unsigned int fmtval, audfmt; int ret; =20 dev_dbg(dev, "%s: width %d\n", __func__, params_width(param)); =20 + fmtval =3D FIELD_GET(SND_SOC_DAIFMT_FORMAT_MASK, data->daifmt); + if (data->tdm_slots && fmtval !=3D SND_SOC_DAIFMT_DSP_A && fmtval !=3D SN= D_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 =3D 8; + break; + case SND_SOC_DAIFMT_LEFT_J: + audfmt =3D 9; + break; + case SND_SOC_DAIFMT_RIGHT_J: + audfmt =3D 10; + break; + case SND_SOC_DAIFMT_DSP_A: + audfmt =3D data->tdm_slots ? 12 : 11; + break; + case SND_SOC_DAIFMT_DSP_B: + audfmt =3D data->tdm_slots ? 4 : 3; + break; + default: + dev_err(dev, "Unsupported format 0x%8x\n", fmtval); + return -EINVAL; + } + switch (width =3D params_width(param)) { case 16: audbit =3D 0; @@ -615,6 +616,10 @@ static int rtq9128_dai_hw_params(struct snd_pcm_substr= eam *stream, struct snd_pc return -EINVAL; } =20 + ret =3D snd_soc_component_write_field(comp, RTQ9128_REG_I2S_OPT, RTQ9128_= AUDFMT_MASK, audfmt); + if (ret < 0) + return ret; + ret =3D snd_soc_component_write_field(comp, RTQ9128_REG_I2S_OPT, RTQ9128_= AUDBIT_MASK, audbit); if (ret < 0) return ret; --=20 2.34.1