<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>i.MX Processors中的主题 Re: iMX8QXP SPDIF problem &amp;quot;cannot set hw params: Invalid argument&amp;quot;</title>
    <link>https://community.nxp.com/t5/i-MX-Processors/iMX8QXP-SPDIF-problem-quot-cannot-set-hw-params-Invalid-argument/m-p/1234028#M169791</link>
    <description>&lt;P&gt;Dear&amp;nbsp;&lt;SPAN&gt;igor:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Do you mean the S/PDIF can only be used in "simple-audio-card" framework? Currently I am using the&amp;nbsp;custom machine driver to create audio card.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I may posted the wrong information that the codec of the sound card is&lt;STRONG&gt; dummy audio codec&lt;/STRONG&gt; which is refer to the&amp;nbsp;&lt;A href="https://community.nxp.com/t5/i-MX-Processors-Knowledge-Base/Dummy-audio-codec-play-record-on-i-MX8MM/ta-p/1112577" target="_self"&gt;Dummy audio codec - play &amp;amp; record on i.MX8MM&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And if I just use the S/PDIF driver at kernel/sound/soc/fsl/imx-spdif.c (block the imx-dummy.c) refer to the &lt;A href="https://www.nxp.com/docs/en/reference-manual/IMX_REFERENCE_MANUAL.pdf" target="_self"&gt;i.MX Linux Reference Manual&lt;/A&gt; in capter 7.4.2~7.4.5, the dts:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;sound-spdif {
	compatible = "fsl,imx-audio-spdif";
	model = "imx-spdif";
	spdif-controller = &amp;lt;&amp;amp;spdif0&amp;gt;;
	spdif-in;
	spdif-out;
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then I will get the same problem in the main post.&amp;nbsp;Except the S/PDIF, the SAI/ESAI has already worked with dummy codec.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Mon, 22 Feb 2021 08:59:23 GMT</pubDate>
    <dc:creator>Buridan</dc:creator>
    <dc:date>2021-02-22T08:59:23Z</dc:date>
    <item>
      <title>iMX8QXP SPDIF problem "cannot set hw params: Invalid argument"</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/iMX8QXP-SPDIF-problem-quot-cannot-set-hw-params-Invalid-argument/m-p/1223912#M168728</link>
      <description>&lt;P&gt;Dear NXP experts:&lt;/P&gt;&lt;P&gt;Now I'm using SPDIF as the primary audio card of Android 10 on iMX8QXP mek board. I don't need the codec code and just output the SPDIF signal form&amp;nbsp;SPDIF0_TX pin. The SDK version is&amp;nbsp;imx8_10_2.2.0 .&lt;/P&gt;&lt;P&gt;My DTS config like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// imx8x-mek.dtsi
&amp;amp;spdif0 {
	compatible = "fsl,imx8qm-spdif";
	pinctrl-names = "default";
	pinctrl-0 = &amp;lt;&amp;amp;pinctrl_spdif0&amp;gt;;
	assigned-clocks = &amp;lt;&amp;amp;acm IMX_ADMA_ACM_SPDIF0_TX_CLK_SEL&amp;gt;,
			&amp;lt;&amp;amp;clk IMX_SC_R_AUDIO_PLL_0 IMX_SC_PM_CLK_PLL&amp;gt;,
			&amp;lt;&amp;amp;clk IMX_SC_R_AUDIO_PLL_0 IMX_SC_PM_CLK_SLV_BUS&amp;gt;,
			&amp;lt;&amp;amp;clk IMX_SC_R_AUDIO_PLL_0 IMX_SC_PM_CLK_MST_BUS&amp;gt;,
			&amp;lt;&amp;amp;spdif0_lpcg 0&amp;gt;;
	assigned-clock-parents = &amp;lt;&amp;amp;aud_pll_div0_lpcg 0&amp;gt;;
	assigned-clock-rates = &amp;lt;0&amp;gt;, &amp;lt;786432000&amp;gt;, &amp;lt;49152000&amp;gt;, &amp;lt;24576000&amp;gt;, &amp;lt;49152000&amp;gt;;
	status = "okay";
};

pinctrl_spdif0: spdif0grp {
	fsl,pins = &amp;lt;
		IMX8QXP_SPDIF0_TX_ADMA_SPDIF0_TX        0xc6000040
		IMX8QXP_SPDIF0_RX_ADMA_SPDIF0_RX        0xc6000040
	&amp;gt;;
};

// imxqxp-mek.dts
sound-dummy {
	compatible = "fsl,imx-audio-dummy";
	model = "imx-dummy";
	dai-controller = &amp;lt;&amp;amp;sai0&amp;gt;, &amp;lt;&amp;amp;sai1&amp;gt;, &amp;lt;&amp;amp;esai0&amp;gt;, &amp;lt;&amp;amp;spdif0&amp;gt;;
	dai-codec = &amp;lt;&amp;amp;codec_dummy&amp;gt;;
	status = "okay";
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;The driver modified from NXP dummy codec example, and the part of SPDIF copy from kernel/sound/soc/fsl/imx-spdif.c like this:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;// imx-dummy.c
static int imx_dummy_spdif_hw_params(struct snd_pcm_substream *substream,
									 struct snd_pcm_hw_params *params)
{
	struct snd_soc_pcm_runtime *rtd = substream-&amp;gt;private_data;
	struct device *dev = rtd-&amp;gt;card-&amp;gt;dev;
	int ret = 0;
	unsigned int freq;

	printk("run in %s\n", __func__);

	if (substream-&amp;gt;stream == SNDRV_PCM_STREAM_PLAYBACK) {
		u64 rate = params_rate(params);

		freq = do_div(rate, 8000) ? CLK_11K_FREQ : CLK_8K_FREQ;
		ret = snd_soc_dai_set_sysclk(rtd-&amp;gt;cpu_dai, STC_TXCLK_SPDIF_ROOT,
									 freq, SND_SOC_CLOCK_OUT);
		if (ret)
			dev_err(dev, "failed to set cpu sysclk: %d\n", ret);
	}

	return ret;
}
static struct snd_soc_ops imx_aif_spdif_ops = {
	.hw_params = imx_dummy_spdif_hw_params,
};

static int imx_dummy_probe(struct platform_device *pdev)
{
	...
	for (i = 0; i &amp;lt; num_dai; i++) {
		...
		priv-&amp;gt;dai[i].stream_name = "SAI S/PDIF PCM";
		priv-&amp;gt;dai[i].codecs-&amp;gt;dai_name = "snd-soc-dummy-dai";
		priv-&amp;gt;dai[i].codecs-&amp;gt;name = "snd-soc-dummy";
		...
		if (strstr(cpu_np-&amp;gt;name, "spdif")) {
			priv-&amp;gt;dai[i].ops = &amp;amp;imx_aif_spdif_ops;
		} else {
		...
	...
}&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;But it seems not work when I use tinyplay to play wav files:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="c"&gt;mek_8q:/sdcard/Music # cat /proc/asound/cards
 0 [imxdummy       ]: imx-dummy - imx-dummy
                      imx-dummy
mek_8q:/sdcard/Music # ls /dev/snd/
controlC0 pcmC0D0p pcmC0D1p pcmC0D2p pcmC0D3p
pcmC0D0c  pcmC0D1c pcmC0D2c pcmC0D3c timer
mek_8q:/sdcard/Music # tinyplay ./1khz-16000-16-1.wav -D 0 -d 3 -p 1024 -n 3
Sample is 1 channels, device only supports &amp;gt;= 2 channels
Bitrate is 16 bits, device only supports &amp;gt;= 32 bits
mek_8q:/sdcard/Music # tinyplay ./1khz-16000-32-2.wav -D 0 -d 3 -p 1024 -n 3
Sample rate is 16000Hz, device only supports &amp;gt;= 32000Hz
mek_8q:/sdcard/Music # tinyplay ./1khz-48000-32-2.wav -D 0 -d 3 -p 1024 -n 3
Unable to open PCM device 3 (cannot set hw params: Invalid argument)
mek_8q:/sdcard/Music # tinymix
Mixer name: 'imx-dummy'
Number of controls: 9
ctl     type    num     name                                     value

0       IEC958  1       IEC958 Playback Default                  unknown
1       IEC958  1       IEC958 Capture Default                   unknown
2       IEC958  1       IEC958 Subcode Capture Default           unknown
Failed to mixer_ctl_get_array
3       BYTE    12      IEC958 Q-subcode Capture Default         4      BOOL    1       IEC958 Rx V-Bit Errors                   Off
5       BOOL    1       IEC958 Tx V-Bit                          Off
6       INT     1       RX Sample Rate                           0
7       BOOL    1       IEC958 USyncMode CDText                  Off
8       BOOL    1       IEC958 Rx Raw Capture Mode Bit           Off&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;After configured the SPDIF(/dev/snd/pcmC0D3x, port = 3) as the primary card in&amp;nbsp;vendor/nxp-opensource/imx/alsa/tinyalsa_hal.cpp, the logcat like this when playing audio in app:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;02-01 07:15:14.972   371  2137 I audio_hw_primary: start_output_stream: out: 0xe8f47600, device: 2, address: , mode: 0, flags 0x2
02-01 07:15:14.972   371  2137 I audio_hw_primary: select_output_device(), headphone 0 ,headset 0 ,speaker 2
02-01 07:15:14.972   371  2137 I audio_hw_primary: start_output_stream: set to pcm_config_mm_out, rate 48000, chn 2, format 0x0
02-01 07:15:14.972   371  2137 D audio_hw_primary: start_output_stream: pcm_open: card: 0, rate: 48000, channel: 2, format: 0, period_size: 0x400, flag: 8
02-01 07:15:14.980   371  2137 E audio_hw_primary: start_output_stream: pcm_open error: cannot set hw params: Invalid argument
02-01 07:15:14.981   371  2137 V audio_hw_primary: write error, sleep few ms&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;Is there anything else I need to do for this problem? Thank you!&lt;/P&gt;</description>
      <pubDate>Tue, 02 Feb 2021 07:22:50 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/iMX8QXP-SPDIF-problem-quot-cannot-set-hw-params-Invalid-argument/m-p/1223912#M168728</guid>
      <dc:creator>Buridan</dc:creator>
      <dc:date>2021-02-02T07:22:50Z</dc:date>
    </item>
    <item>
      <title>Re: iMX8QXP SPDIF problem "cannot set hw params: Invalid argument"</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/iMX8QXP-SPDIF-problem-quot-cannot-set-hw-params-Invalid-argument/m-p/1225099#M168835</link>
      <description>&lt;P&gt;I opend the DEBUG macro and the printf output:&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;mek_8q:/ # dmesg | grep dai
[    5.169054] fsl-spdif-dai 59020000.spdif: use rxtx1 as tx clock source for 32000Hz sample rate
[    5.169066] fsl-spdif-dai 59020000.spdif: use txclk df 24 for 32000Hz sample rate
[    5.169072] fsl-spdif-dai 59020000.spdif: the best rate for 32000Hz sample rate is 32000Hz
[    5.176404] fsl-spdif-dai 59020000.spdif: use rxtx5 as tx clock source for 44100Hz sample rate
[    5.176411] fsl-spdif-dai 59020000.spdif: use txclk df 19 for 44100Hz sample rate
[    5.176419] fsl-spdif-dai 59020000.spdif: use sysclk df 3 for 44100Hz sample rate
[    5.176426] fsl-spdif-dai 59020000.spdif: the best rate for 44100Hz sample rate is 43859Hz
[    5.176438] fsl-spdif-dai 59020000.spdif: use rxtx1 as tx clock source for 48000Hz sample rate
[    5.176444] fsl-spdif-dai 59020000.spdif: use txclk df 16 for 48000Hz sample rate
[    5.176451] fsl-spdif-dai 59020000.spdif: the best rate for 48000Hz sample rate is 48000Hz
[    5.176460] fsl-spdif-dai 59020000.spdif: use rxtx1 as tx clock source for 96000Hz sample rate
[    5.176466] fsl-spdif-dai 59020000.spdif: use txclk df 8 for 96000Hz sample rate
[    5.176474] fsl-spdif-dai 59020000.spdif: the best rate for 96000Hz sample rate is 96000Hz
[    5.176482] fsl-spdif-dai 59020000.spdif: use rxtx1 as tx clock source for 192000Hz sample rate
[    5.176489] fsl-spdif-dai 59020000.spdif: use txclk df 4 for 192000Hz sample rate
[    5.176497] fsl-spdif-dai 59020000.spdif: the best rate for 192000Hz sample rate is 192000Hz
[    5.188105] imx-dummy sound-dummy: snd-soc-dummy-dai &amp;lt;-&amp;gt; 59040000.sai mapping ok
[    5.198172] imx-dummy sound-dummy: snd-soc-dummy-dai &amp;lt;-&amp;gt; 59050000.sai mapping ok
[    5.208096] imx-dummy sound-dummy: snd-soc-dummy-dai &amp;lt;-&amp;gt; 59010000.esai mapping ok
[    5.222350] imx-dummy sound-dummy: snd-soc-dummy-dai &amp;lt;-&amp;gt; 59020000.spdif mapping ok
mek_8q:/ # tinyplay /sdcard/Music/1
1khz-16000-16-1.wav       1khz-32000-32-2.wav       1khz-8000-8-2.wav
1khz-16000-32-2.wav       1khz-48000-32-2.wav
mek_8q:/ # tinyplay /sdcard/Music/1khz-48000-32-2.wav -D 0 -d 3 -p 1024 -n 3
Unable to open PCM device 3 (cannot set hw params: Invalid argument)&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Wed, 03 Feb 2021 02:28:57 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/iMX8QXP-SPDIF-problem-quot-cannot-set-hw-params-Invalid-argument/m-p/1225099#M168835</guid>
      <dc:creator>Buridan</dc:creator>
      <dc:date>2021-02-03T02:28:57Z</dc:date>
    </item>
    <item>
      <title>Re: iMX8QXP SPDIF problem "cannot set hw params: Invalid argument"</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/iMX8QXP-SPDIF-problem-quot-cannot-set-hw-params-Invalid-argument/m-p/1227606#M169100</link>
      <description>&lt;P&gt;Hi Buridan&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;such configuration (without codec) is not supported in nxp bsps, in general one&lt;/P&gt;
&lt;P&gt;can try to follow similar example with "simple-audio-card "&lt;/P&gt;
&lt;P&gt;&lt;A href="https://source.codeaurora.org/external/imx/linux-imx/tree/arch/arm64/boot/dts/freescale/imx8qm-mek-sof-cs42888.dts?h=imx_5.4.70_2.3.0" target="_blank" rel="noopener"&gt;https://source.codeaurora.org/external/imx/linux-imx/tree/arch/arm64/boot/dts/freescale/imx8qxp-mek-sof-cs42888.dts?h=imx_5.4.70_2.3.0&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;&lt;A href="https://source.codeaurora.org/external/imx/linux-imx/tree/Documentation/devicetree/bindings/sound/simple-card.txt?h=imx_5.4.70_2.3.0" target="_blank"&gt;https://source.codeaurora.org/external/imx/linux-imx/tree/Documentation/devicetree/bindings/sound/simple-card.txt?h=imx_5.4.70_2.3.0&lt;/A&gt;&lt;/P&gt;
&lt;P&gt;Use Chapter 7 Audio&amp;nbsp;&amp;nbsp; &lt;A style="box-sizing: border-box; background-color: transparent; color: #215bd6; text-decoration: none; cursor: pointer;" href="https://www.nxp.com/docs/en/reference-manual/IMX_REFERENCE_MANUAL.pdf" target="_blank" rel="noopener"&gt;i.MX Linux Reference Manual​&amp;nbsp;&amp;nbsp;&lt;/A&gt; describing all linux ALSA software layers&lt;/P&gt;
&lt;P&gt;&amp;nbsp;&lt;/P&gt;
&lt;P&gt;Best regards&lt;BR /&gt;igor&lt;/P&gt;</description>
      <pubDate>Sun, 07 Feb 2021 23:31:34 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/iMX8QXP-SPDIF-problem-quot-cannot-set-hw-params-Invalid-argument/m-p/1227606#M169100</guid>
      <dc:creator>igorpadykov</dc:creator>
      <dc:date>2021-02-07T23:31:34Z</dc:date>
    </item>
    <item>
      <title>Re: iMX8QXP SPDIF problem "cannot set hw params: Invalid argument"</title>
      <link>https://community.nxp.com/t5/i-MX-Processors/iMX8QXP-SPDIF-problem-quot-cannot-set-hw-params-Invalid-argument/m-p/1234028#M169791</link>
      <description>&lt;P&gt;Dear&amp;nbsp;&lt;SPAN&gt;igor:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Do you mean the S/PDIF can only be used in "simple-audio-card" framework? Currently I am using the&amp;nbsp;custom machine driver to create audio card.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;I may posted the wrong information that the codec of the sound card is&lt;STRONG&gt; dummy audio codec&lt;/STRONG&gt; which is refer to the&amp;nbsp;&lt;A href="https://community.nxp.com/t5/i-MX-Processors-Knowledge-Base/Dummy-audio-codec-play-record-on-i-MX8MM/ta-p/1112577" target="_self"&gt;Dummy audio codec - play &amp;amp; record on i.MX8MM&lt;/A&gt;.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;And if I just use the S/PDIF driver at kernel/sound/soc/fsl/imx-spdif.c (block the imx-dummy.c) refer to the &lt;A href="https://www.nxp.com/docs/en/reference-manual/IMX_REFERENCE_MANUAL.pdf" target="_self"&gt;i.MX Linux Reference Manual&lt;/A&gt; in capter 7.4.2~7.4.5, the dts:&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;LI-CODE lang="markup"&gt;sound-spdif {
	compatible = "fsl,imx-audio-spdif";
	model = "imx-spdif";
	spdif-controller = &amp;lt;&amp;amp;spdif0&amp;gt;;
	spdif-in;
	spdif-out;
};&lt;/LI-CODE&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;&lt;P&gt;&lt;SPAN&gt;Then I will get the same problem in the main post.&amp;nbsp;Except the S/PDIF, the SAI/ESAI has already worked with dummy codec.&lt;/SPAN&gt;&lt;/P&gt;&lt;P&gt;&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Mon, 22 Feb 2021 08:59:23 GMT</pubDate>
      <guid>https://community.nxp.com/t5/i-MX-Processors/iMX8QXP-SPDIF-problem-quot-cannot-set-hw-params-Invalid-argument/m-p/1234028#M169791</guid>
      <dc:creator>Buridan</dc:creator>
      <dc:date>2021-02-22T08:59:23Z</dc:date>
    </item>
  </channel>
</rss>

