Skip to contentSkip to conversation

ASoC: codec: hdac_hdmi: no checking monitor in hw_params

RFC PATCH In review [email protected] 5 participants 18 messages May 6, 2019 – May 7, 2019

Subsystems (2)
lore
Share & tools
lore
#0 lore raw

RFC PATCH 1/1 ASoC: codec: hdac_hdmi: no checking monitor in hw_params

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is OK.

However, pulseaudio will check the pcm devices when kernel is booting up. It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting up. Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

---
 sound/soc/codecs/hdac_hdmi.c | 44 +++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)
sound/soc/codecs/hdac_hdmi.c +31 -13
index 4de1fbf..f482e09 100644
@@ -455,24 +455,11 @@ static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)
 {
 	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
-	struct hdac_device *hdev = hdmi->hdev;
 	struct hdac_hdmi_dai_port_map *dai_map;
-	struct hdac_hdmi_port *port;
 	struct hdac_hdmi_pcm *pcm;
 	int format;
 
 	dai_map = &hdmi->dai_map[dai->id];
-	port = dai_map->port;
-
-	if (!port)
-		return -ENODEV;
-
-	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
-		dev_err(&hdev->dev,
-			"device is not configured for this pin:port%d:%d\n",
-					port->pin->nid, port->id);
-		return -ENODEV;
-	}
 
 	format = snd_hdac_calc_stream_format(params_rate(hparams),
 			params_channels(hparams), params_format(hparams),
@@ -630,6 +617,36 @@ static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,
 		dai_map->port = NULL;
 }
 
+static int hdac_hdmi_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
+				 struct snd_soc_dai *dai)
+{
+	struct hdac_hdmi_port *port;
+	struct hdac_hdmi_dai_port_map *dai_map;
+	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
+	struct hdac_device *hdev = hdmi->hdev;
+
+	/*
+	 * When start, if there is no monitor,
+	 * It should not start audio.
+	 */
+	if (cmd == SNDRV_PCM_TRIGGER_START) {
+		dai_map = &hdmi->dai_map[dai->id];
+		port = dai_map->port;
+
+		if (!port)
+			return -ENODEV;
+
+		if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
+			dev_err(&hdev->dev,
+				"device is not configured for this pin:port%d:%d\n",
+				port->pin->nid, port->id);
+			return -ENODEV;
+		}
+	}
+
+	return 0;
+}
+
 static int
 hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct hdac_hdmi_cvt *cvt)
 {
@@ -1389,6 +1406,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {
 	.startup = hdac_hdmi_pcm_open,
 	.shutdown = hdac_hdmi_pcm_close,
 	.hw_params = hdac_hdmi_set_hw_params,
+	.trigger = hdac_hdmi_pcm_trigger,
 	.set_tdm_slot = hdac_hdmi_set_tdm_slot,
 };
 
Signature · 1 line
2.7.4
maintainer
#1 lore raw

Dne 06. 05. 19 v 8:59 [email protected] napsal(a):

Quoted 15 lines

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is OK.

However, pulseaudio will check the pcm devices when kernel is booting up. It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting up. Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

Quoted 7 lines

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

I don't like this solution much. PA should use the Jack control to add the devices dynamically and avoid probing when the Jack control is false.

Jaroslav

Quoted 81 lines
---
 sound/soc/codecs/hdac_hdmi.c | 44 +++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)
sound/soc/codecs/hdac_hdmi.c +31 -13
index 4de1fbf..f482e09 100644
@@ -455,24 +455,11 @@ static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)
 {
 	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
-	struct hdac_device *hdev = hdmi->hdev;
 	struct hdac_hdmi_dai_port_map *dai_map;
-	struct hdac_hdmi_port *port;
 	struct hdac_hdmi_pcm *pcm;
 	int format;
 
 	dai_map = &hdmi->dai_map[dai->id];
-	port = dai_map->port;
-
-	if (!port)
-		return -ENODEV;
-
-	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
-		dev_err(&hdev->dev,
-			"device is not configured for this pin:port%d:%d\n",
-					port->pin->nid, port->id);
-		return -ENODEV;
-	}
 
 	format = snd_hdac_calc_stream_format(params_rate(hparams),
 			params_channels(hparams), params_format(hparams),
@@ -630,6 +617,36 @@ static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,
 		dai_map->port = NULL;
 }
 
+static int hdac_hdmi_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
+				 struct snd_soc_dai *dai)
+{
+	struct hdac_hdmi_port *port;
+	struct hdac_hdmi_dai_port_map *dai_map;
+	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
+	struct hdac_device *hdev = hdmi->hdev;
+
+	/*
+	 * When start, if there is no monitor,
+	 * It should not start audio.
+	 */
+	if (cmd == SNDRV_PCM_TRIGGER_START) {
+		dai_map = &hdmi->dai_map[dai->id];
+		port = dai_map->port;
+
+		if (!port)
+			return -ENODEV;
+
+		if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
+			dev_err(&hdev->dev,
+				"device is not configured for this pin:port%d:%d\n",
+				port->pin->nid, port->id);
+			return -ENODEV;
+		}
+	}
+
+	return 0;
+}
+
 static int
 hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct hdac_hdmi_cvt *cvt)
 {
@@ -1389,6 +1406,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {
 	.startup = hdac_hdmi_pcm_open,
 	.shutdown = hdac_hdmi_pcm_close,
 	.hw_params = hdac_hdmi_set_hw_params,
+	.trigger = hdac_hdmi_pcm_trigger,
 	.set_tdm_slot = hdac_hdmi_set_tdm_slot,
 };
 
Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
#2 lore raw
Quoted 20 lines · Jaroslav Kysela

Dne 06. 05. 19 v 8:59 [email protected] napsal(a):

Quoted 18 lines

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is OK.

However, pulseaudio will check the pcm devices when kernel is booting up. It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting up. Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

Quoted 7 lines
Quoted 4 lines

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

I don't like this solution much. PA should use the Jack control to add the devices dynamically and avoid probing when the Jack control is false.

Ideally, yes, but this isn't going to happen soon, I'm afraid. And we're still responsible for fixing for the existing platforms. So I find the proposed patch OK although it's hackish. The added code in the trigger has almost no overhead, and it won't break stuff.

thanks,

Takashi

Quoted 90 lines

Jaroslav

Quoted 81 lines
---
 sound/soc/codecs/hdac_hdmi.c | 44 +++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)
sound/soc/codecs/hdac_hdmi.c +31 -13
index 4de1fbf..f482e09 100644
@@ -455,24 +455,11 @@ static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,
 	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)
 {
 	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
-	struct hdac_device *hdev = hdmi->hdev;
 	struct hdac_hdmi_dai_port_map *dai_map;
-	struct hdac_hdmi_port *port;
 	struct hdac_hdmi_pcm *pcm;
 	int format;
 
 	dai_map = &hdmi->dai_map[dai->id];
-	port = dai_map->port;
-
-	if (!port)
-		return -ENODEV;
-
-	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
-		dev_err(&hdev->dev,
-			"device is not configured for this pin:port%d:%d\n",
-					port->pin->nid, port->id);
-		return -ENODEV;
-	}
 
 	format = snd_hdac_calc_stream_format(params_rate(hparams),
 			params_channels(hparams), params_format(hparams),
@@ -630,6 +617,36 @@ static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,
 		dai_map->port = NULL;
 }
 
+static int hdac_hdmi_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
+				 struct snd_soc_dai *dai)
+{
+	struct hdac_hdmi_port *port;
+	struct hdac_hdmi_dai_port_map *dai_map;
+	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
+	struct hdac_device *hdev = hdmi->hdev;
+
+	/*
+	 * When start, if there is no monitor,
+	 * It should not start audio.
+	 */
+	if (cmd == SNDRV_PCM_TRIGGER_START) {
+		dai_map = &hdmi->dai_map[dai->id];
+		port = dai_map->port;
+
+		if (!port)
+			return -ENODEV;
+
+		if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
+			dev_err(&hdev->dev,
+				"device is not configured for this pin:port%d:%d\n",
+				port->pin->nid, port->id);
+			return -ENODEV;
+		}
+	}
+
+	return 0;
+}
+
 static int
 hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct hdac_hdmi_cvt *cvt)
 {
@@ -1389,6 +1406,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {
 	.startup = hdac_hdmi_pcm_open,
 	.shutdown = hdac_hdmi_pcm_close,
 	.hw_params = hdac_hdmi_set_hw_params,
+	.trigger = hdac_hdmi_pcm_trigger,
 	.set_tdm_slot = hdac_hdmi_set_tdm_slot,
 };
 
Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
#3 lore raw

Hi Takashi,

Quoted 39 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Monday, May 6, 2019 4:40 PM
To: Jaroslav Kysela <[email protected]>
Cc: Yang, Libin <[email protected]>; [email protected]; pierre- [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Quoted 8 lines · Jaroslav Kysela

Dne 06. 05. 19 v 8:59 [email protected] napsal(a):

Quoted 6 lines

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is

OK.

Quoted 4 lines
Quoted 4 lines

However, pulseaudio will check the pcm devices when kernel is booting up. It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting

up.

Quoted 13 lines
Quoted 12 lines

Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

Quoted 7 lines
Quoted 2 lines

I don't like this solution much. PA should use the Jack control to add the devices dynamically and avoid probing when the Jack control is false.

Ideally, yes, but this isn't going to happen soon, I'm afraid. And we're still responsible for fixing for the existing platforms. So I find the proposed patch OK although it's hackish. The added code in the trigger has almost no overhead, and it won't break stuff.

Yes, this is why we want to use UCM. We need more changes in the driver to use Jack control.

I have another question:
Is it possible that we remove the monitor detection? I mean just returning ok even there are no monitors?

There is one case: playback -> disconnect monitor -> S3.
As it will trigger start after S3, my patch will cause playback to exit as it will check the monitors.
The original code will not break playback in this case.

Regards,
Libin

Quoted 100 lines

thanks,

Takashi

Quoted 10 lines

Jaroslav

Quoted 7 lines
---
 sound/soc/codecs/hdac_hdmi.c | 44
+++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)
Quoted 5 lines

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct

Quoted 5 lines
(quoted diff) +0 -0

b/sound/soc/codecs/hdac_hdmi.c index 4de1fbf..f482e09 100644

sound/soc/codecs/hdac_hdmi.c +0 -0
@@ -455,24 +455,11 @@ static int hdac_hdmi_set_hw_params(struct

snd_pcm_substream *substream,

Quoted 21 lines
Quoted 21 lines
sound/soc/codecs/hdac_hdmi.c +0 -13
 	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)  {
 	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
-	struct hdac_device *hdev = hdmi->hdev;
 	struct hdac_hdmi_dai_port_map *dai_map;
-	struct hdac_hdmi_port *port;
 	struct hdac_hdmi_pcm *pcm;
 	int format;
 
 	dai_map = &hdmi->dai_map[dai->id];
-	port = dai_map->port;
-
-	if (!port)
-		return -ENODEV;
-
-	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
-		dev_err(&hdev->dev,
-			"device is not configured for this pin:port%d:%d\n",
-					port->pin->nid, port->id);
-		return -ENODEV;
-	}
 
Quoted 2 lines

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct · line 464

Quoted 2 lines
sound/soc/codecs/hdac_hdmi.c +0 -0
 	format = snd_hdac_calc_stream_format(params_rate(hparams),
 			params_channels(hparams),

params_format(hparams), @@ -630,6

Quoted 1 line

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct · line 465

Quoted 1 line
sound/soc/codecs/hdac_hdmi.c +1 -0
+617,36 @@ static void hdac_hdmi_pcm_close(struct snd_pcm_substream

*substream,

Quoted 4 lines

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 4 lines
sound/soc/codecs/hdac_hdmi.c +1 -0
 		dai_map->port = NULL;
 }
 
+static int hdac_hdmi_pcm_trigger(struct snd_pcm_substream *substream,

int cmd,

Quoted 13 lines
Quoted 13 lines
sound/soc/codecs/hdac_hdmi.c +13 -0
+				 struct snd_soc_dai *dai)
+{
+	struct hdac_hdmi_port *port;
+	struct hdac_hdmi_dai_port_map *dai_map;
+	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
+	struct hdac_device *hdev = hdmi->hdev;
+
+	/*
+	 * When start, if there is no monitor,
+	 * It should not start audio.
+	 */
+	if (cmd == SNDRV_PCM_TRIGGER_START) {
+		dai_map = &hdmi->dai_map[dai->id];
Quoted 8 lines

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 8 lines
sound/soc/codecs/hdac_hdmi.c +8 -0
+		port = dai_map->port;
+
+		if (!port)
+			return -ENODEV;
+
+		if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
+			dev_err(&hdev->dev,
+				"device is not configured for this

pin:port%d:%d\n",

Quoted 25 lines
Quoted 14 lines
sound/soc/codecs/hdac_hdmi.c +8 -0
+				port->pin->nid, port->id);
+			return -ENODEV;
+		}
+	}
+
+	return 0;
+}
+
 static int
 hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct

hdac_hdmi_cvt *cvt) { @@ -1389,6 +1406,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {

sound/soc/codecs/hdac_hdmi.c static const struct snd_soc_dai_ops hdmi_dai_ops = {

Quoted 5 lines
sound/soc/codecs/hdac_hdmi.c +1 -0
 	.startup = hdac_hdmi_pcm_open,
 	.shutdown = hdac_hdmi_pcm_close,
 	.hw_params = hdac_hdmi_set_hw_params,
+	.trigger = hdac_hdmi_pcm_trigger,
 	.set_tdm_slot = hdac_hdmi_set_tdm_slot,  };

--
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

#4 lore raw
Quoted 54 lines · Libin

Hi Takashi,

Quoted 39 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Monday, May 6, 2019 4:40 PM
To: Jaroslav Kysela <[email protected]>
Cc: Yang, Libin <[email protected]>; [email protected]; pierre- [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Quoted 8 lines · Jaroslav Kysela

Dne 06. 05. 19 v 8:59 [email protected] napsal(a):

Quoted 6 lines

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is

OK.

Quoted 4 lines
Quoted 4 lines

However, pulseaudio will check the pcm devices when kernel is booting up. It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting

up.

Quoted 13 lines
Quoted 12 lines

Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

Quoted 7 lines
Quoted 2 lines

I don't like this solution much. PA should use the Jack control to add the devices dynamically and avoid probing when the Jack control is false.

Ideally, yes, but this isn't going to happen soon, I'm afraid. And we're still responsible for fixing for the existing platforms. So I find the proposed patch OK although it's hackish. The added code in the trigger has almost no overhead, and it won't break stuff.

Yes, this is why we want to use UCM. We need more changes in the driver to use Jack control.

Quoted 8 lines

I have another question:
Is it possible that we remove the monitor detection? I mean just returning ok even there are no monitors?

There is one case: playback -> disconnect monitor -> S3.
As it will trigger start after S3, my patch will cause playback to exit as it will check the monitors.
The original code will not break playback in this case.

This pretty much depends on the driver; the legacy HD-audio has no such check. If it were no monitor connection and a stream is played back, it'll be passed to the hardware as-is.

I don't know why ASoC HD-audio driver has the check, maybe otherwise something gets screwed up? If removing the monitor detection "works" (i.e. doesn't give any hiccup in the driver side), it's OK to remove that, of course.

thanks,

Takashi

Quoted 105 lines

Regards,
Libin

Quoted 100 lines

thanks,

Takashi

Quoted 10 lines

Jaroslav

Quoted 7 lines
---
 sound/soc/codecs/hdac_hdmi.c | 44
+++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)
Quoted 5 lines

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct

Quoted 5 lines
(quoted diff) +0 -0

b/sound/soc/codecs/hdac_hdmi.c index 4de1fbf..f482e09 100644

sound/soc/codecs/hdac_hdmi.c +0 -0
@@ -455,24 +455,11 @@ static int hdac_hdmi_set_hw_params(struct

snd_pcm_substream *substream,

Quoted 21 lines
Quoted 21 lines
sound/soc/codecs/hdac_hdmi.c +0 -13
 	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)  {
 	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
-	struct hdac_device *hdev = hdmi->hdev;
 	struct hdac_hdmi_dai_port_map *dai_map;
-	struct hdac_hdmi_port *port;
 	struct hdac_hdmi_pcm *pcm;
 	int format;
 
 	dai_map = &hdmi->dai_map[dai->id];
-	port = dai_map->port;
-
-	if (!port)
-		return -ENODEV;
-
-	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
-		dev_err(&hdev->dev,
-			"device is not configured for this pin:port%d:%d\n",
-					port->pin->nid, port->id);
-		return -ENODEV;
-	}
 
Quoted 2 lines

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct · line 464

Quoted 2 lines
sound/soc/codecs/hdac_hdmi.c +0 -0
 	format = snd_hdac_calc_stream_format(params_rate(hparams),
 			params_channels(hparams),

params_format(hparams), @@ -630,6

Quoted 1 line

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct · line 465

Quoted 1 line
sound/soc/codecs/hdac_hdmi.c +1 -0
+617,36 @@ static void hdac_hdmi_pcm_close(struct snd_pcm_substream

*substream,

Quoted 4 lines

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 4 lines
sound/soc/codecs/hdac_hdmi.c +1 -0
 		dai_map->port = NULL;
 }
 
+static int hdac_hdmi_pcm_trigger(struct snd_pcm_substream *substream,

int cmd,

Quoted 13 lines
Quoted 13 lines
sound/soc/codecs/hdac_hdmi.c +13 -0
+				 struct snd_soc_dai *dai)
+{
+	struct hdac_hdmi_port *port;
+	struct hdac_hdmi_dai_port_map *dai_map;
+	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
+	struct hdac_device *hdev = hdmi->hdev;
+
+	/*
+	 * When start, if there is no monitor,
+	 * It should not start audio.
+	 */
+	if (cmd == SNDRV_PCM_TRIGGER_START) {
+		dai_map = &hdmi->dai_map[dai->id];
Quoted 8 lines

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 8 lines
sound/soc/codecs/hdac_hdmi.c +8 -0
+		port = dai_map->port;
+
+		if (!port)
+			return -ENODEV;
+
+		if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
+			dev_err(&hdev->dev,
+				"device is not configured for this

pin:port%d:%d\n",

Quoted 25 lines
Quoted 14 lines
sound/soc/codecs/hdac_hdmi.c +8 -0
+				port->pin->nid, port->id);
+			return -ENODEV;
+		}
+	}
+
+	return 0;
+}
+
 static int
 hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct

hdac_hdmi_cvt *cvt) { @@ -1389,6 +1406,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {

sound/soc/codecs/hdac_hdmi.c static const struct snd_soc_dai_ops hdmi_dai_ops = {

Quoted 5 lines
sound/soc/codecs/hdac_hdmi.c +1 -0
 	.startup = hdac_hdmi_pcm_open,
 	.shutdown = hdac_hdmi_pcm_close,
 	.hw_params = hdac_hdmi_set_hw_params,
+	.trigger = hdac_hdmi_pcm_trigger,
 	.set_tdm_slot = hdac_hdmi_set_tdm_slot,  };

--
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

#5 lore raw

Hi Takashi,

Quoted 76 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Monday, May 6, 2019 5:02 PM
To: Yang, Libin <[email protected]>
Cc: Jaroslav Kysela <[email protected]>; [email protected]; pierre- [email protected]; [email protected]; Lin, Mengdong <[email protected]>; Wang, Rander <[email protected]>; [email protected]
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Quoted 21 lines · Libin

Hi Takashi,

Quoted 17 lines

-----Original Message-----
From: Takashi Iwai [mailto:[email protected]]
Sent: Monday, May 6, 2019 4:40 PM
To: Jaroslav Kysela <[email protected]>
Cc: Yang, Libin <[email protected]>; [email protected]; pierre- [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Quoted 5 lines · Jaroslav Kysela

Dne 06. 05. 19 v 8:59 [email protected] napsal(a):

Quoted 3 lines

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger

callback.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines
Quoted 4 lines

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is

OK.

Quoted 2 lines
Quoted 2 lines

However, pulseaudio will check the pcm devices when kernel is booting

up.

Quoted 12 lines
Quoted 12 lines
Quoted 3 lines
Quoted 3 lines

It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting

up.

Quoted 8 lines
Quoted 8 lines

Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

Quoted 7 lines
Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

I don't like this solution much. PA should use the Jack control to add the devices dynamically and avoid probing when the Jack control is

false.

Quoted 13 lines
Quoted 5 lines

Ideally, yes, but this isn't going to happen soon, I'm afraid. And we're still responsible for fixing for the existing platforms. So I find the proposed patch OK although it's hackish. The added code in the trigger has almost no overhead, and it won't break stuff.

Yes, this is why we want to use UCM. We need more changes in the driver to use Jack control.

I have another question:
Is it possible that we remove the monitor detection? I mean just returning ok even there are no monitors?

Quoted 8 lines
Quoted 4 lines

There is one case: playback -> disconnect monitor -> S3. As it will trigger start after S3, my patch will cause playback to exit as it will check the monitors.
The original code will not break playback in this case.

This pretty much depends on the driver; the legacy HD-audio has no such check. If it were no monitor connection and a stream is played back, it'll be passed to the hardware as-is.

Yes, I refer to legacy HDA driver and wonder if we can remove the check. :)

Quoted 5 lines

I don't know why ASoC HD-audio driver has the check, maybe otherwise something gets screwed up? If removing the monitor detection "works" (i.e. doesn't give any hiccup in the driver side), it's OK to remove that, of course.

I did some test with removing the monitor check, it works well so far. I will do more tests on removing monitor check tomorrow.

My understanding for the monitor check is that if there is no monitors, we should not send audio infoframe as there is no sink. But the experiences show it is OK the audio driver setup the audio infoframe. I believe the gfx driver or the HW has already handled such situation smoothly.

Regards,
Libin

Quoted 113 lines

thanks,

Takashi

Quoted 107 lines

Regards,
Libin

Quoted 102 lines

thanks,

Takashi

Quoted 10 lines

Jaroslav

Quoted 7 lines
---
 sound/soc/codecs/hdac_hdmi.c | 44
+++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)
Quoted 5 lines

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct

Quoted 5 lines
(quoted diff) +0 -0

b/sound/soc/codecs/hdac_hdmi.c index 4de1fbf..f482e09 100644

sound/soc/codecs/hdac_hdmi.c +0 -0
@@ -455,24 +455,11 @@ static int hdac_hdmi_set_hw_params(struct

snd_pcm_substream *substream,

Quoted 21 lines
Quoted 21 lines
sound/soc/codecs/hdac_hdmi.c +0 -13
 	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)  {
 	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
-	struct hdac_device *hdev = hdmi->hdev;
 	struct hdac_hdmi_dai_port_map *dai_map;
-	struct hdac_hdmi_port *port;
 	struct hdac_hdmi_pcm *pcm;
 	int format;
 
 	dai_map = &hdmi->dai_map[dai->id];
-	port = dai_map->port;
-
-	if (!port)
-		return -ENODEV;
-
-	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
-		dev_err(&hdev->dev,
-			"device is not configured for this pin:port%d:%d\n",
-					port->pin->nid, port->id);
-		return -ENODEV;
-	}
 
Quoted 2 lines

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct · line 464

Quoted 2 lines
sound/soc/codecs/hdac_hdmi.c +0 -0
 	format = snd_hdac_calc_stream_format(params_rate(hparams),
 			params_channels(hparams),

params_format(hparams), @@ -630,6

Quoted 2 lines

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct

Quoted 2 lines
sound/soc/codecs/hdac_hdmi.c +2 -0
+617,36 @@ static void hdac_hdmi_pcm_close(struct
+snd_pcm_substream

*substream,

Quoted 5 lines

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 5 lines
sound/soc/codecs/hdac_hdmi.c +2 -0
 		dai_map->port = NULL;
 }
 
+static int hdac_hdmi_pcm_trigger(struct snd_pcm_substream
+*substream,

int cmd,

Quoted 13 lines
Quoted 13 lines
sound/soc/codecs/hdac_hdmi.c +13 -0
+				 struct snd_soc_dai *dai)
+{
+	struct hdac_hdmi_port *port;
+	struct hdac_hdmi_dai_port_map *dai_map;
+	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
+	struct hdac_device *hdev = hdmi->hdev;
+
+	/*
+	 * When start, if there is no monitor,
+	 * It should not start audio.
+	 */
+	if (cmd == SNDRV_PCM_TRIGGER_START) {
+		dai_map = &hdmi->dai_map[dai->id];
Quoted 8 lines

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 8 lines
sound/soc/codecs/hdac_hdmi.c +8 -0
+		port = dai_map->port;
+
+		if (!port)
+			return -ENODEV;
+
+		if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
+			dev_err(&hdev->dev,
+				"device is not configured for this

pin:port%d:%d\n",

Quoted 25 lines
Quoted 14 lines
sound/soc/codecs/hdac_hdmi.c +8 -0
+				port->pin->nid, port->id);
+			return -ENODEV;
+		}
+	}
+
+	return 0;
+}
+
 static int
 hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct

hdac_hdmi_cvt *cvt) { @@ -1389,6 +1406,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {

sound/soc/codecs/hdac_hdmi.c static const struct snd_soc_dai_ops hdmi_dai_ops = {

Quoted 5 lines
sound/soc/codecs/hdac_hdmi.c +1 -0
 	.startup = hdac_hdmi_pcm_open,
 	.shutdown = hdac_hdmi_pcm_close,
 	.hw_params = hdac_hdmi_set_hw_params,
+	.trigger = hdac_hdmi_pcm_trigger,
 	.set_tdm_slot = hdac_hdmi_set_tdm_slot,  };

--
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

#6 lore raw
In reply to Jaroslav Kysela

Add Mengdong, Hui, Rander

Hi Jaroslav,

Quoted 28 lines

-----Original Message-----
From: Jaroslav Kysela [mailto:[email protected]]
Sent: Monday, May 6, 2019 4:20 PM
To: Yang, Libin <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Dne 06. 05. 19 v 8:59 [email protected] napsal(a):

Quoted 18 lines

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is OK.

However, pulseaudio will check the pcm devices when kernel is booting up. It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting up. Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

Quoted 7 lines
Quoted 4 lines

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

I don't like this solution much. PA should use the Jack control to add the devices dynamically and avoid probing when the Jack control is false.

Before we decided to use UCM, we did some investigation on Jack controls. And we found we need do much more changes in driver to support Jack Controls.

Regards,
Libin

Quoted 93 lines

Jaroslav

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct

Quoted 12 lines
---
 sound/soc/codecs/hdac_hdmi.c | 44
+++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)
(quoted diff) +0 -0

b/sound/soc/codecs/hdac_hdmi.c index 4de1fbf..f482e09 100644

sound/soc/codecs/hdac_hdmi.c +0 -0
@@ -455,24 +455,11 @@ static int hdac_hdmi_set_hw_params(struct

snd_pcm_substream *substream,

Quoted 13 lines
sound/soc/codecs/hdac_hdmi.c +0 -6
 	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)  {
 	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
-	struct hdac_device *hdev = hdmi->hdev;
 	struct hdac_hdmi_dai_port_map *dai_map;
-	struct hdac_hdmi_port *port;
 	struct hdac_hdmi_pcm *pcm;
 	int format;
 
 	dai_map = &hdmi->dai_map[dai->id];
-	port = dai_map->port;
-
-	if (!port)
-		return -ENODEV;

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,

Quoted 10 lines
sound/soc/codecs/hdac_hdmi.c +0 -7
-
-	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
-		dev_err(&hdev->dev,
-			"device is not configured for this pin:port%d:%d\n",
-					port->pin->nid, port->id);
-		return -ENODEV;
-	}
 
 	format = snd_hdac_calc_stream_format(params_rate(hparams),
 			params_channels(hparams),

params_format(hparams), @@ -630,6

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct · line 465

Quoted 1 line
sound/soc/codecs/hdac_hdmi.c +1 -0
+617,36 @@ static void hdac_hdmi_pcm_close(struct snd_pcm_substream

*substream,

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 4 lines
sound/soc/codecs/hdac_hdmi.c +1 -0
 		dai_map->port = NULL;
 }
 
+static int hdac_hdmi_pcm_trigger(struct snd_pcm_substream *substream,

int cmd,

Quoted 11 lines
sound/soc/codecs/hdac_hdmi.c +11 -0
+				 struct snd_soc_dai *dai)
+{
+	struct hdac_hdmi_port *port;
+	struct hdac_hdmi_dai_port_map *dai_map;
+	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
+	struct hdac_device *hdev = hdmi->hdev;
+
+	/*
+	 * When start, if there is no monitor,
+	 * It should not start audio.
+	 */

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 10 lines
sound/soc/codecs/hdac_hdmi.c +10 -0
+	if (cmd == SNDRV_PCM_TRIGGER_START) {
+		dai_map = &hdmi->dai_map[dai->id];
+		port = dai_map->port;
+
+		if (!port)
+			return -ENODEV;
+
+		if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
+			dev_err(&hdev->dev,
+				"device is not configured for this

pin:port%d:%d\n",

Quoted 14 lines
sound/soc/codecs/hdac_hdmi.c +8 -0
+				port->pin->nid, port->id);
+			return -ENODEV;
+		}
+	}
+
+	return 0;
+}
+
 static int
 hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct

hdac_hdmi_cvt *cvt) { @@ -1389,6 +1406,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {

sound/soc/codecs/hdac_hdmi.c static const struct snd_soc_dai_ops hdmi_dai_ops = {

Quoted 5 lines
sound/soc/codecs/hdac_hdmi.c +1 -0
 	.startup = hdac_hdmi_pcm_open,
 	.shutdown = hdac_hdmi_pcm_close,
 	.hw_params = hdac_hdmi_set_hw_params,
+	.trigger = hdac_hdmi_pcm_trigger,
 	.set_tdm_slot = hdac_hdmi_set_tdm_slot,  };

--
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

maintainer
#7 lore raw

Dne 06. 05. 19 v 10:46 Yang, Libin napsal(a):

Quoted 37 lines

Add Mengdong, Hui, Rander

Hi Jaroslav,

Quoted 33 lines

-----Original Message-----
From: Jaroslav Kysela [mailto:[email protected]]
Sent: Monday, May 6, 2019 4:20 PM
To: Yang, Libin <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Dne 06. 05. 19 v 8:59 [email protected] napsal(a):

Quoted 22 lines

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is OK.

However, pulseaudio will check the pcm devices when kernel is booting up. It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting up. Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

Quoted 6 lines
Quoted 2 lines

I don't like this solution much. PA should use the Jack control to add the devices dynamically and avoid probing when the Jack control is false.

Before we decided to use UCM, we did some investigation on Jack controls. And we found we need do much more changes in driver to support Jack Controls.

How do you handle the dynamic monitor configuration (like when user disconnects the monitor on-the-fly) then? The control interface can notify the state change through the Jack controls. The PCM interface does not handle this.

Jaroslav

Quoted 97 lines

Regards,
Libin

Quoted 93 lines

Jaroslav

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct

Quoted 12 lines
---
 sound/soc/codecs/hdac_hdmi.c | 44
+++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)
(quoted diff) +0 -0

b/sound/soc/codecs/hdac_hdmi.c index 4de1fbf..f482e09 100644

sound/soc/codecs/hdac_hdmi.c +0 -0
@@ -455,24 +455,11 @@ static int hdac_hdmi_set_hw_params(struct

snd_pcm_substream *substream,

Quoted 13 lines
sound/soc/codecs/hdac_hdmi.c +0 -6
 	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)  {
 	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
-	struct hdac_device *hdev = hdmi->hdev;
 	struct hdac_hdmi_dai_port_map *dai_map;
-	struct hdac_hdmi_port *port;
 	struct hdac_hdmi_pcm *pcm;
 	int format;
 
 	dai_map = &hdmi->dai_map[dai->id];
-	port = dai_map->port;
-
-	if (!port)
-		return -ENODEV;

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,

Quoted 10 lines
sound/soc/codecs/hdac_hdmi.c +0 -7
-
-	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
-		dev_err(&hdev->dev,
-			"device is not configured for this pin:port%d:%d\n",
-					port->pin->nid, port->id);
-		return -ENODEV;
-	}
 
 	format = snd_hdac_calc_stream_format(params_rate(hparams),
 			params_channels(hparams),

params_format(hparams), @@ -630,6

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct · line 465

Quoted 1 line
sound/soc/codecs/hdac_hdmi.c +1 -0
+617,36 @@ static void hdac_hdmi_pcm_close(struct snd_pcm_substream

*substream,

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 4 lines
sound/soc/codecs/hdac_hdmi.c +1 -0
 		dai_map->port = NULL;
 }
 
+static int hdac_hdmi_pcm_trigger(struct snd_pcm_substream *substream,

int cmd,

Quoted 11 lines
sound/soc/codecs/hdac_hdmi.c +11 -0
+				 struct snd_soc_dai *dai)
+{
+	struct hdac_hdmi_port *port;
+	struct hdac_hdmi_dai_port_map *dai_map;
+	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
+	struct hdac_device *hdev = hdmi->hdev;
+
+	/*
+	 * When start, if there is no monitor,
+	 * It should not start audio.
+	 */

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 10 lines
sound/soc/codecs/hdac_hdmi.c +10 -0
+	if (cmd == SNDRV_PCM_TRIGGER_START) {
+		dai_map = &hdmi->dai_map[dai->id];
+		port = dai_map->port;
+
+		if (!port)
+			return -ENODEV;
+
+		if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
+			dev_err(&hdev->dev,
+				"device is not configured for this

pin:port%d:%d\n",

Quoted 14 lines
sound/soc/codecs/hdac_hdmi.c +8 -0
+				port->pin->nid, port->id);
+			return -ENODEV;
+		}
+	}
+
+	return 0;
+}
+
 static int
 hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct

hdac_hdmi_cvt *cvt) { @@ -1389,6 +1406,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {

sound/soc/codecs/hdac_hdmi.c static const struct snd_soc_dai_ops hdmi_dai_ops = {

Quoted 5 lines
sound/soc/codecs/hdac_hdmi.c +1 -0
 	.startup = hdac_hdmi_pcm_open,
 	.shutdown = hdac_hdmi_pcm_close,
 	.hw_params = hdac_hdmi_set_hw_params,
+	.trigger = hdac_hdmi_pcm_trigger,
 	.set_tdm_slot = hdac_hdmi_set_tdm_slot,  };

--
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
#8 lore raw

Hi Jaroslav,

Quoted 56 lines

-----Original Message-----
From: Jaroslav Kysela [mailto:[email protected]]
Sent: Monday, May 6, 2019 5:04 PM
To: Yang, Libin <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Hui Wang <[email protected]>; Lin, Mengdong <[email protected]>; Wang, Rander <[email protected]>
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Dne 06. 05. 19 v 10:46 Yang, Libin napsal(a):

Quoted 21 lines

Add Mengdong, Hui, Rander

Hi Jaroslav,

Quoted 17 lines

-----Original Message-----
From: Jaroslav Kysela [mailto:[email protected]]
Sent: Monday, May 6, 2019 4:20 PM
To: Yang, Libin <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Dne 06. 05. 19 v 8:59 [email protected] napsal(a):

Quoted 6 lines

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is

OK.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

However, pulseaudio will check the pcm devices when kernel is booting

up.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting

up.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

I don't like this solution much. PA should use the Jack control to add the devices dynamically and avoid probing when the Jack control is

false.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

Before we decided to use UCM, we did some investigation on Jack controls. And we found we need do much more changes in driver to support Jack Controls.

How do you handle the dynamic monitor configuration (like when user disconnects the monitor on-the-fly) then? The control interface can notify the state change through the Jack controls. The PCM interface does not handle this.

We may still need Jack control for this case. This is my second plan to enable Jack control. But even we enable Jack control, it seems it is still easy to use UCM. This is because ASoC control names don't follow legacy HDA rule. This means we may need to change other controls name besides HDMI in the driver or we may need to add more configures in pulseaudio/alsa-mixer/paths.

Hi Mengdong & Hui,

Do you have more comments for Jack control or UCM?

Regards,
Libin

Quoted 107 lines

Jaroslav

Quoted 45 lines

Regards,
Libin

Quoted 41 lines

Jaroslav

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct

Quoted 12 lines
---
 sound/soc/codecs/hdac_hdmi.c | 44
+++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)
(quoted diff) +0 -0

b/sound/soc/codecs/hdac_hdmi.c index 4de1fbf..f482e09 100644

sound/soc/codecs/hdac_hdmi.c +0 -0
@@ -455,24 +455,11 @@ static int hdac_hdmi_set_hw_params(struct

snd_pcm_substream *substream,

Quoted 13 lines
sound/soc/codecs/hdac_hdmi.c +0 -6
 	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)  {
 	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
-	struct hdac_device *hdev = hdmi->hdev;
 	struct hdac_hdmi_dai_port_map *dai_map;
-	struct hdac_hdmi_port *port;
 	struct hdac_hdmi_pcm *pcm;
 	int format;
 
 	dai_map = &hdmi->dai_map[dai->id];
-	port = dai_map->port;
-
-	if (!port)
-		return -ENODEV;

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,

Quoted 10 lines
sound/soc/codecs/hdac_hdmi.c +0 -7
-
-	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
-		dev_err(&hdev->dev,
-			"device is not configured for this pin:port%d:%d\n",
-					port->pin->nid, port->id);
-		return -ENODEV;
-	}
 
 	format = snd_hdac_calc_stream_format(params_rate(hparams),
 			params_channels(hparams),

params_format(hparams), @@ -630,6

Quoted 1 line
sound/soc/codecs/hdac_hdmi.c +1 -0
+617,36 @@ static void hdac_hdmi_pcm_close(struct

snd_pcm_substream

Quoted 45 lines
Quoted 45 lines

*substream,

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 5 lines
sound/soc/codecs/hdac_hdmi.c +2 -0
 		dai_map->port = NULL;
 }
 
+static int hdac_hdmi_pcm_trigger(struct snd_pcm_substream
+*substream,

int cmd,

Quoted 11 lines
sound/soc/codecs/hdac_hdmi.c +11 -0
+				 struct snd_soc_dai *dai)
+{
+	struct hdac_hdmi_port *port;
+	struct hdac_hdmi_dai_port_map *dai_map;
+	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
+	struct hdac_device *hdev = hdmi->hdev;
+
+	/*
+	 * When start, if there is no monitor,
+	 * It should not start audio.
+	 */

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 10 lines
sound/soc/codecs/hdac_hdmi.c +10 -0
+	if (cmd == SNDRV_PCM_TRIGGER_START) {
+		dai_map = &hdmi->dai_map[dai->id];
+		port = dai_map->port;
+
+		if (!port)
+			return -ENODEV;
+
+		if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
+			dev_err(&hdev->dev,
+				"device is not configured for this

pin:port%d:%d\n",

Quoted 16 lines
sound/soc/codecs/hdac_hdmi.c +8 -0
+				port->pin->nid, port->id);
+			return -ENODEV;
+		}
+	}
+
+	return 0;
+}
+
 static int
 hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct

hdac_hdmi_cvt *cvt) { @@ -1389,6 +1406,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {

sound/soc/codecs/hdac_hdmi.c +1 -0
 	.startup = hdac_hdmi_pcm_open,
 	.shutdown = hdac_hdmi_pcm_close,
 	.hw_params = hdac_hdmi_set_hw_params,
+	.trigger = hdac_hdmi_pcm_trigger,
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

.set_tdm_slot = hdac_hdmi_set_tdm_slot, };

--
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

--
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

#9 lore raw
Quoted 68 lines · Libin

Hi Jaroslav,

Quoted 56 lines

-----Original Message-----
From: Jaroslav Kysela [mailto:[email protected]]
Sent: Monday, May 6, 2019 5:04 PM
To: Yang, Libin <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Hui Wang <[email protected]>; Lin, Mengdong <[email protected]>; Wang, Rander <[email protected]>
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Dne 06. 05. 19 v 10:46 Yang, Libin napsal(a):

Quoted 21 lines

Add Mengdong, Hui, Rander

Hi Jaroslav,

Quoted 17 lines

-----Original Message-----
From: Jaroslav Kysela [mailto:[email protected]]
Sent: Monday, May 6, 2019 4:20 PM
To: Yang, Libin <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Dne 06. 05. 19 v 8:59 [email protected] napsal(a):

Quoted 6 lines

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is

OK.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

However, pulseaudio will check the pcm devices when kernel is booting

up.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting

up.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

I don't like this solution much. PA should use the Jack control to add the devices dynamically and avoid probing when the Jack control is

false.

Quoted 1 line
Quoted 8 lines
Quoted 3 lines

Before we decided to use UCM, we did some investigation on Jack controls. And we found we need do much more changes in driver to support Jack Controls.

How do you handle the dynamic monitor configuration (like when user disconnects the monitor on-the-fly) then? The control interface can notify the state change through the Jack controls. The PCM interface does not handle this.

Quoted 5 lines

We may still need Jack control for this case. This is my second plan to enable Jack control. But even we enable Jack control, it seems it is still easy to use UCM. This is because ASoC control names don't follow legacy HDA rule. This means we may need to change other controls name besides HDMI in the driver or we may need to add more configures in pulseaudio/alsa-mixer/paths.

Ah, I overlooked that hdac_hdmi chose the own jack control names. That's basically useless, yeah.

Quoted 3 lines

Hi Mengdong & Hui,

Do you have more comments for Jack control or UCM?

I guess a UCM profile would handle the jack detection as well, by specifying the right kcontrol names, right?

thanks,

Takashi

Quoted 111 lines

Regards,
Libin

Quoted 107 lines

Jaroslav

Quoted 45 lines

Regards,
Libin

Quoted 41 lines

Jaroslav

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct

Quoted 12 lines
---
 sound/soc/codecs/hdac_hdmi.c | 44
+++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)
(quoted diff) +0 -0

b/sound/soc/codecs/hdac_hdmi.c index 4de1fbf..f482e09 100644

sound/soc/codecs/hdac_hdmi.c +0 -0
@@ -455,24 +455,11 @@ static int hdac_hdmi_set_hw_params(struct

snd_pcm_substream *substream,

Quoted 13 lines
sound/soc/codecs/hdac_hdmi.c +0 -6
 	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)  {
 	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
-	struct hdac_device *hdev = hdmi->hdev;
 	struct hdac_hdmi_dai_port_map *dai_map;
-	struct hdac_hdmi_port *port;
 	struct hdac_hdmi_pcm *pcm;
 	int format;
 
 	dai_map = &hdmi->dai_map[dai->id];
-	port = dai_map->port;
-
-	if (!port)
-		return -ENODEV;

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,

Quoted 10 lines
sound/soc/codecs/hdac_hdmi.c +0 -7
-
-	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
-		dev_err(&hdev->dev,
-			"device is not configured for this pin:port%d:%d\n",
-					port->pin->nid, port->id);
-		return -ENODEV;
-	}
 
 	format = snd_hdac_calc_stream_format(params_rate(hparams),
 			params_channels(hparams),

params_format(hparams), @@ -630,6

Quoted 1 line
sound/soc/codecs/hdac_hdmi.c +1 -0
+617,36 @@ static void hdac_hdmi_pcm_close(struct

snd_pcm_substream

Quoted 45 lines
Quoted 45 lines

*substream,

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 5 lines
sound/soc/codecs/hdac_hdmi.c +2 -0
 		dai_map->port = NULL;
 }
 
+static int hdac_hdmi_pcm_trigger(struct snd_pcm_substream
+*substream,

int cmd,

Quoted 11 lines
sound/soc/codecs/hdac_hdmi.c +11 -0
+				 struct snd_soc_dai *dai)
+{
+	struct hdac_hdmi_port *port;
+	struct hdac_hdmi_dai_port_map *dai_map;
+	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
+	struct hdac_device *hdev = hdmi->hdev;
+
+	/*
+	 * When start, if there is no monitor,
+	 * It should not start audio.
+	 */

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 10 lines
sound/soc/codecs/hdac_hdmi.c +10 -0
+	if (cmd == SNDRV_PCM_TRIGGER_START) {
+		dai_map = &hdmi->dai_map[dai->id];
+		port = dai_map->port;
+
+		if (!port)
+			return -ENODEV;
+
+		if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
+			dev_err(&hdev->dev,
+				"device is not configured for this

pin:port%d:%d\n",

Quoted 16 lines
sound/soc/codecs/hdac_hdmi.c +8 -0
+				port->pin->nid, port->id);
+			return -ENODEV;
+		}
+	}
+
+	return 0;
+}
+
 static int
 hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct

hdac_hdmi_cvt *cvt) { @@ -1389,6 +1406,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {

sound/soc/codecs/hdac_hdmi.c +1 -0
 	.startup = hdac_hdmi_pcm_open,
 	.shutdown = hdac_hdmi_pcm_close,
 	.hw_params = hdac_hdmi_set_hw_params,
+	.trigger = hdac_hdmi_pcm_trigger,
Quoted 8 lines
Quoted 8 lines
Quoted 3 lines

.set_tdm_slot = hdac_hdmi_set_tdm_slot, };

--
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

--
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

#10 lore raw
Quoted 69 lines · Takashi Iwai
Quoted 62 lines · Libin

Hi Jaroslav,

Quoted 52 lines

-----Original Message-----
From: Jaroslav Kysela [mailto:[email protected]]
Sent: Monday, May 6, 2019 5:04 PM
To: Yang, Libin <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; Hui Wang <[email protected]>; Lin, Mengdong <[email protected]>; Wang, Rander <[email protected]>
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Dne 06. 05. 19 v 10:46 Yang, Libin napsal(a):

Quoted 21 lines

Add Mengdong, Hui, Rander

Hi Jaroslav,

Quoted 17 lines

-----Original Message-----
From: Jaroslav Kysela [mailto:[email protected]]
Sent: Monday, May 6, 2019 4:20 PM
To: Yang, Libin <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Dne 06. 05. 19 v 8:59 [email protected] napsal(a):

Quoted 6 lines

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is

OK.

Quoted 1 line
Quoted 1 line
Quoted 1 line

However, pulseaudio will check the pcm devices when kernel is booting

up.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting

up.

Quoted 8 lines
Quoted 8 lines
Quoted 8 lines

Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

Quoted 6 lines
Quoted 6 lines
Quoted 4 lines

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

I don't like this solution much. PA should use the Jack control to add the devices dynamically and avoid probing when the Jack control is

Quoted 8 lines

false.

Quoted 3 lines

Before we decided to use UCM, we did some investigation on Jack controls. And we found we need do much more changes in driver to support Jack Controls.

How do you handle the dynamic monitor configuration (like when user disconnects the monitor on-the-fly) then? The control interface can notify the state change through the Jack controls. The PCM interface does not handle this.

Quoted 5 lines

We may still need Jack control for this case. This is my second plan to enable Jack control. But even we enable Jack control, it seems it is still easy to use UCM. This is because ASoC control names don't follow legacy HDA rule. This means we may need to change other controls name besides HDMI in the driver or we may need to add more configures in pulseaudio/alsa-mixer/paths.

Quoted 8 lines

Ah, I overlooked that hdac_hdmi chose the own jack control names. That's basically useless, yeah.

Quoted 3 lines

Hi Mengdong & Hui,

Do you have more comments for Jack control or UCM?

I guess a UCM profile would handle the jack detection as well, by specifying the right kcontrol names, right?

Yes, probably it can work. set a HD-Audio Jack name in the SectionDevice, and monitor the ASoC jack name via JackControl. like below:

SectionDevice."Jack HDMI/DP,pcm=3" {
        Comment "HDMI/DP Audio #0"

        Value {
                CaptureChannels "2"
                CapturePCM "hw:${card_name},#{subdev}" JackControl "${ASoC_HDMI_Jack_Name} Jack" }

...
Thanks,

Hui.

Quoted 106 lines

thanks,

Takashi

Quoted 101 lines

Regards,
Libin

Quoted 98 lines

Jaroslav

Quoted 42 lines

Regards,
Libin

Quoted 39 lines

Jaroslav

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct

Quoted 11 lines
---
  sound/soc/codecs/hdac_hdmi.c | 44
+++++++++++++++++++++++++++++++-------------
  1 file changed, 31 insertions(+), 13 deletions(-)
(quoted diff) +0 -0

b/sound/soc/codecs/hdac_hdmi.c index 4de1fbf..f482e09 100644

sound/soc/codecs/hdac_hdmi.c +0 -0
@@ -455,24 +455,11 @@ static int hdac_hdmi_set_hw_params(struct

snd_pcm_substream *substream,

Quoted 13 lines
sound/soc/codecs/hdac_hdmi.c +0 -6
  	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)  {
  	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
-	struct hdac_device *hdev = hdmi->hdev;
  	struct hdac_hdmi_dai_port_map *dai_map;
-	struct hdac_hdmi_port *port;
  	struct hdac_hdmi_pcm *pcm;
  	int format;
 
  	dai_map = &hdmi->dai_map[dai->id];
-	port = dai_map->port;
-
-	if (!port)
-		return -ENODEV;

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,

Quoted 10 lines
sound/soc/codecs/hdac_hdmi.c +0 -7
-
-	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
-		dev_err(&hdev->dev,
-			"device is not configured for this pin:port%d:%d\n",
-					port->pin->nid, port->id);
-		return -ENODEV;
-	}
 
  	format = snd_hdac_calc_stream_format(params_rate(hparams),
  			params_channels(hparams),

params_format(hparams), @@ -630,6

Quoted 1 line
sound/soc/codecs/hdac_hdmi.c +1 -0
+617,36 @@ static void hdac_hdmi_pcm_close(struct

snd_pcm_substream

Quoted 52 lines
Quoted 52 lines

*substream,

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 5 lines
sound/soc/codecs/hdac_hdmi.c +2 -0
  		dai_map->port = NULL;
  }
 
+static int hdac_hdmi_pcm_trigger(struct snd_pcm_substream
+*substream,

int cmd,

Quoted 11 lines
sound/soc/codecs/hdac_hdmi.c +11 -0
+				 struct snd_soc_dai *dai)
+{
+	struct hdac_hdmi_port *port;
+	struct hdac_hdmi_dai_port_map *dai_map;
+	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
+	struct hdac_device *hdev = hdmi->hdev;
+
+	/*
+	 * When start, if there is no monitor,
+	 * It should not start audio.
+	 */

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 10 lines
sound/soc/codecs/hdac_hdmi.c +10 -0
+	if (cmd == SNDRV_PCM_TRIGGER_START) {
+		dai_map = &hdmi->dai_map[dai->id];
+		port = dai_map->port;
+
+		if (!port)
+			return -ENODEV;
+
+		if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
+			dev_err(&hdev->dev,
+				"device is not configured for this

pin:port%d:%d\n",

Quoted 17 lines
sound/soc/codecs/hdac_hdmi.c +8 -0
+				port->pin->nid, port->id);
+			return -ENODEV;
+		}
+	}
+
+	return 0;
+}
+
  static int
  hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct

hdac_hdmi_cvt *cvt) { @@ -1389,6 +1406,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {
.startup = hdac_hdmi_pcm_open,
.shutdown = hdac_hdmi_pcm_close,
.hw_params = hdac_hdmi_set_hw_params,

sound/soc/codecs/hdac_hdmi.c

Quoted 2 lines
sound/soc/codecs/hdac_hdmi.c +1 -0
+	.trigger = hdac_hdmi_pcm_trigger,
  	.set_tdm_slot = hdac_hdmi_set_tdm_slot,  };

--
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

Quoted 8 lines
Quoted 3 lines
Quoted 3 lines

--
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

_______________________________________________
Alsa-devel mailing list
[email protected]
https://mailman.alsa-project.org/mailman/listinfo/alsa-devel

#11 lore raw
In reply to Jaroslav Kysela
Quoted 42 lines · Jaroslav Kysela

Dne 06. 05. 19 v 10:46 Yang, Libin napsal(a):

Quoted 40 lines

Add Mengdong, Hui, Rander

Hi Jaroslav,

Quoted 35 lines

-----Original Message-----
From: Jaroslav Kysela [mailto:[email protected]]
Sent: Monday, May 6, 2019 4:20 PM
To: Yang, Libin <[email protected]>; [email protected]
Cc: [email protected]; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Dne 06. 05. 19 v 8:59 [email protected] napsal(a):

Quoted 15 lines

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is OK.

However, pulseaudio will check the pcm devices when kernel is booting up. It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting up. Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

Quoted 7 lines

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

I don't like this solution much. PA should use the Jack control to add the devices dynamically and avoid probing when the Jack control is false.

Quoted 7 lines
Quoted 3 lines

Before we decided to use UCM, we did some investigation on Jack controls. And we found we need do much more changes in driver to support Jack Controls.

How do you handle the dynamic monitor configuration (like when user disconnects the monitor on-the-fly) then? The control interface can notify the state change through the Jack controls. The PCM interface does not handle this.

PA watches the Jack control change and switch the stream appropriately. So, the simplest "solution" would be just to remove the monitor check in the PCM side, as Libin mentioned.

thanks,

Takashi

Quoted 106 lines

Jaroslav

Quoted 97 lines

Regards,
Libin

Quoted 93 lines

Jaroslav

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct

Quoted 12 lines
---
 sound/soc/codecs/hdac_hdmi.c | 44
+++++++++++++++++++++++++++++++-------------
 1 file changed, 31 insertions(+), 13 deletions(-)
(quoted diff) +0 -0

b/sound/soc/codecs/hdac_hdmi.c index 4de1fbf..f482e09 100644

sound/soc/codecs/hdac_hdmi.c +0 -0
@@ -455,24 +455,11 @@ static int hdac_hdmi_set_hw_params(struct

snd_pcm_substream *substream,

Quoted 13 lines
sound/soc/codecs/hdac_hdmi.c +0 -6
 	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)  {
 	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
-	struct hdac_device *hdev = hdmi->hdev;
 	struct hdac_hdmi_dai_port_map *dai_map;
-	struct hdac_hdmi_port *port;
 	struct hdac_hdmi_pcm *pcm;
 	int format;
 
 	dai_map = &hdmi->dai_map[dai->id];
-	port = dai_map->port;
-
-	if (!port)
-		return -ENODEV;

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,

Quoted 10 lines
sound/soc/codecs/hdac_hdmi.c +0 -7
-
-	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
-		dev_err(&hdev->dev,
-			"device is not configured for this pin:port%d:%d\n",
-					port->pin->nid, port->id);
-		return -ENODEV;
-	}
 
 	format = snd_hdac_calc_stream_format(params_rate(hparams),
 			params_channels(hparams),

params_format(hparams), @@ -630,6

sound/soc/codecs/hdac_hdmi.c static int hdac_hdmi_set_hw_params(struct · line 465

Quoted 1 line
sound/soc/codecs/hdac_hdmi.c +1 -0
+617,36 @@ static void hdac_hdmi_pcm_close(struct snd_pcm_substream

*substream,

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 4 lines
sound/soc/codecs/hdac_hdmi.c +1 -0
 		dai_map->port = NULL;
 }
 
+static int hdac_hdmi_pcm_trigger(struct snd_pcm_substream *substream,

int cmd,

Quoted 11 lines
sound/soc/codecs/hdac_hdmi.c +11 -0
+				 struct snd_soc_dai *dai)
+{
+	struct hdac_hdmi_port *port;
+	struct hdac_hdmi_dai_port_map *dai_map;
+	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
+	struct hdac_device *hdev = hdmi->hdev;
+
+	/*
+	 * When start, if there is no monitor,
+	 * It should not start audio.
+	 */

sound/soc/codecs/hdac_hdmi.c static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,

Quoted 10 lines
sound/soc/codecs/hdac_hdmi.c +10 -0
+	if (cmd == SNDRV_PCM_TRIGGER_START) {
+		dai_map = &hdmi->dai_map[dai->id];
+		port = dai_map->port;
+
+		if (!port)
+			return -ENODEV;
+
+		if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
+			dev_err(&hdev->dev,
+				"device is not configured for this

pin:port%d:%d\n",

Quoted 14 lines
sound/soc/codecs/hdac_hdmi.c +8 -0
+				port->pin->nid, port->id);
+			return -ENODEV;
+		}
+	}
+
+	return 0;
+}
+
 static int
 hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct

hdac_hdmi_cvt *cvt) { @@ -1389,6 +1406,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {

sound/soc/codecs/hdac_hdmi.c static const struct snd_soc_dai_ops hdmi_dai_ops = {

Quoted 5 lines
sound/soc/codecs/hdac_hdmi.c +1 -0
 	.startup = hdac_hdmi_pcm_open,
 	.shutdown = hdac_hdmi_pcm_close,
 	.hw_params = hdac_hdmi_set_hw_params,
+	.trigger = hdac_hdmi_pcm_trigger,
 	.set_tdm_slot = hdac_hdmi_set_tdm_slot,  };

--
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.

Signature · 2 lines
Jaroslav Kysela <[email protected]>
Linux Sound Maintainer; ALSA Project; Red Hat, Inc.
#12 lore raw
In reply to [email protected]
Quoted 15 lines · On 5/6/19 1:59 AM, [email protected] wrote:

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is OK.

However, pulseaudio will check the pcm devices when kernel is booting up. It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting up. Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

Quoted 7 lines

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

Out of curiosity, how is this handled in the legacy driver? I haven't done this for a long time but I remember very clearly being able to play on the HDMI:3,7, etc devices without any monitors connected. You'd get of course no sound but there was no error reported to userspace. The hardware is perfectly capable of pushing samples into the display controller using the HDAudio/iDisp link.

Quoted 81 lines
---
  sound/soc/codecs/hdac_hdmi.c | 44 +++++++++++++++++++++++++++++++-------------
  1 file changed, 31 insertions(+), 13 deletions(-)
sound/soc/codecs/hdac_hdmi.c +31 -13
index 4de1fbf..f482e09 100644
@@ -455,24 +455,11 @@ static int hdac_hdmi_set_hw_params(struct snd_pcm_substream *substream,
  	struct snd_pcm_hw_params *hparams, struct snd_soc_dai *dai)
  {
  	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
-	struct hdac_device *hdev = hdmi->hdev;
  	struct hdac_hdmi_dai_port_map *dai_map;
-	struct hdac_hdmi_port *port;
  	struct hdac_hdmi_pcm *pcm;
  	int format;
 
  	dai_map = &hdmi->dai_map[dai->id];
-	port = dai_map->port;
-
-	if (!port)
-		return -ENODEV;
-
-	if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
-		dev_err(&hdev->dev,
-			"device is not configured for this pin:port%d:%d\n",
-					port->pin->nid, port->id);
-		return -ENODEV;
-	}
 
  	format = snd_hdac_calc_stream_format(params_rate(hparams),
  			params_channels(hparams), params_format(hparams),
@@ -630,6 +617,36 @@ static void hdac_hdmi_pcm_close(struct snd_pcm_substream *substream,
  		dai_map->port = NULL;
  }
 
+static int hdac_hdmi_pcm_trigger(struct snd_pcm_substream *substream, int cmd,
+				 struct snd_soc_dai *dai)
+{
+	struct hdac_hdmi_port *port;
+	struct hdac_hdmi_dai_port_map *dai_map;
+	struct hdac_hdmi_priv *hdmi = snd_soc_dai_get_drvdata(dai);
+	struct hdac_device *hdev = hdmi->hdev;
+
+	/*
+	 * When start, if there is no monitor,
+	 * It should not start audio.
+	 */
+	if (cmd == SNDRV_PCM_TRIGGER_START) {
+		dai_map = &hdmi->dai_map[dai->id];
+		port = dai_map->port;
+
+		if (!port)
+			return -ENODEV;
+
+		if ((!port->eld.monitor_present) || (!port->eld.eld_valid)) {
+			dev_err(&hdev->dev,
+				"device is not configured for this pin:port%d:%d\n",
+				port->pin->nid, port->id);
+			return -ENODEV;
+		}
+	}
+
+	return 0;
+}
+
  static int
  hdac_hdmi_query_cvt_params(struct hdac_device *hdev, struct hdac_hdmi_cvt *cvt)
  {
@@ -1389,6 +1406,7 @@ static const struct snd_soc_dai_ops hdmi_dai_ops = {
  	.startup = hdac_hdmi_pcm_open,
  	.shutdown = hdac_hdmi_pcm_close,
  	.hw_params = hdac_hdmi_set_hw_params,
+	.trigger = hdac_hdmi_pcm_trigger,
  	.set_tdm_slot = hdac_hdmi_set_tdm_slot,
  };
 
#13 lore raw
Quoted 25 lines · Pierre-Louis Bossart
Quoted 15 lines · On 5/6/19 1:59 AM, [email protected] wrote:

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is OK.

However, pulseaudio will check the pcm devices when kernel is booting up. It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting up. Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

Quoted 7 lines

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

Quoted 6 lines

Out of curiosity, how is this handled in the legacy driver? I haven't done this for a long time but I remember very clearly being able to play on the HDMI:3,7, etc devices without any monitors connected. You'd get of course no sound but there was no error reported to userspace. The hardware is perfectly capable of pushing samples into the display controller using the HDAudio/iDisp link.

As mentioned in the thread, PA just picks up the stream that is connected via a monitor by checking / notified by the corresponding Jack control. On hdac_hdmi driver, the jack control has different base name that is irrelevant with the output pins, so PA doesn't know how to interpret it, hence it's ignored.

thanks,

Takashi

#14 lore raw
Quoted 34 lines · Takashi Iwai
Quoted 25 lines · Pierre-Louis Bossart
Quoted 15 lines · On 5/6/19 1:59 AM, [email protected] wrote:

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is OK.

However, pulseaudio will check the pcm devices when kernel is booting up. It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting up. Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

Quoted 7 lines

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

Quoted 6 lines

Out of curiosity, how is this handled in the legacy driver? I haven't done this for a long time but I remember very clearly being able to play on the HDMI:3,7, etc devices without any monitors connected. You'd get of course no sound but there was no error reported to userspace. The hardware is perfectly capable of pushing samples into the display controller using the HDAudio/iDisp link.

Quoted 5 lines

As mentioned in the thread, PA just picks up the stream that is connected via a monitor by checking / notified by the corresponding Jack control. On hdac_hdmi driver, the jack control has different base name that is irrelevant with the output pins, so PA doesn't know how to interpret it, hence it's ignored.

Yes, but do we have any error checks in the hw_params or trigger cases with the legacy driver?

#15 lore raw
Quoted 36 lines · Pierre-Louis Bossart
Quoted 34 lines · Takashi Iwai
Quoted 31 lines · Pierre-Louis Bossart
Quoted 15 lines · On 5/6/19 1:59 AM, [email protected] wrote:

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is OK.

However, pulseaudio will check the pcm devices when kernel is booting up. It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting up. Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

Quoted 7 lines

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

Out of curiosity, how is this handled in the legacy driver? I haven't done this for a long time but I remember very clearly being able to play on the HDMI:3,7, etc devices without any monitors connected. You'd get of course no sound but there was no error reported to userspace. The hardware is perfectly capable of pushing samples into the display controller using the HDAudio/iDisp link.

Quoted 8 lines
Quoted 5 lines

As mentioned in the thread, PA just picks up the stream that is connected via a monitor by checking / notified by the corresponding Jack control. On hdac_hdmi driver, the jack control has different base name that is irrelevant with the output pins, so PA doesn't know how to interpret it, hence it's ignored.

Yes, but do we have any error checks in the hw_params or trigger cases with the legacy driver?

No, it just continues playing without the actual output.

Takashi

#16 lore raw
Quoted 44 lines · Takashi Iwai
Quoted 42 lines · Pierre-Louis Bossart
Quoted 39 lines · Takashi Iwai
Quoted 25 lines · Pierre-Louis Bossart
Quoted 15 lines · On 5/6/19 1:59 AM, [email protected] wrote:

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger callback.

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this is OK.

However, pulseaudio will check the pcm devices when kernel is booting up. It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is booting up. Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

Quoted 7 lines

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

Quoted 6 lines

Out of curiosity, how is this handled in the legacy driver? I haven't done this for a long time but I remember very clearly being able to play on the HDMI:3,7, etc devices without any monitors connected. You'd get of course no sound but there was no error reported to userspace. The hardware is perfectly capable of pushing samples into the display controller using the HDAudio/iDisp link.

As mentioned in the thread, PA just picks up the stream that is connected via a monitor by checking / notified by the corresponding Jack control. On hdac_hdmi driver, the jack control has different base name that is irrelevant with the output pins, so PA doesn't know how to interpret it, hence it's ignored.

Quoted 4 lines
Quoted 2 lines

Yes, but do we have any error checks in the hw_params or trigger cases with the legacy driver?

No, it just continues playing without the actual output.

ok, so could we remove all these error checks then for hdac_hdmi? The problem is really the output selection on jack detect/monitor reconfigurations, those checks don't add much value, do they?

#17 lore raw

Hi Pierre,

Quoted 59 lines

-----Original Message-----
From: Pierre-Louis Bossart [mailto:[email protected]]
Sent: Monday, May 6, 2019 11:54 PM
To: Takashi Iwai <[email protected]>
Cc: Yang, Libin <[email protected]>; [email protected]; [email protected]; [email protected]; [email protected]
Subject: Re: [alsa-devel] [RFC PATCH] ASoC: codec: hdac_hdmi: no checking monitor in hw_params

Quoted 11 lines · Takashi Iwai
Quoted 9 lines · Pierre-Louis Bossart
Quoted 7 lines · Takashi Iwai
Quoted 5 lines · Pierre-Louis Bossart
Quoted 3 lines · On 5/6/19 1:59 AM, [email protected] wrote:

From: Libin Yang <[email protected]>

This patch move the check of monitor from hw_params to trigger

callback.

Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines
Quoted 3 lines

The original code will check the monitor presence in hw_params. If the monitor doesn't exist, hw_params will return -ENODEV. Mostly this

is OK.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

However, pulseaudio will check the pcm devices when kernel is booting

up.

Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines
Quoted 2 lines

It will try to open, set hw_params, prepare such pcm devices. We can't guarantee that the monitor will be connected when kernel is

booting up.

Quoted 26 lines
Quoted 26 lines
Quoted 25 lines
Quoted 13 lines
Quoted 5 lines

Especially, hdac_hdmi will export 3 pcms at most. It's hard to say users will connect 3 monitors to the HDMI/DP ports. This will cause pulseaudio fail in parsing the pcm devices because the driver will return -ENODEV in hw_params.

Quoted 7 lines

This patch tries to move the check of monitor presence into trigger callback. This can "trick" the pulseaudio the pcm is ready.

This bug is found when we try to enable HDMI detection in gnome-sound-setting for ASoC hdac_hdmi. After we enable the hdmi in UCM, pulseaudio will try to parse the hdmi pcm devices. It will cause failure if there are no monitors connected.

Quoted 6 lines

Out of curiosity, how is this handled in the legacy driver? I haven't done this for a long time but I remember very clearly being able to play on the HDMI:3,7, etc devices without any monitors connected. You'd get of course no sound but there was no error reported to userspace. The hardware is perfectly capable of pushing samples into the display controller using the HDAudio/iDisp link.

As mentioned in the thread, PA just picks up the stream that is connected via a monitor by checking / notified by the corresponding Jack control. On hdac_hdmi driver, the jack control has different base name that is irrelevant with the output pins, so PA doesn't know how to interpret it, hence it's ignored.

Quoted 8 lines
Quoted 4 lines
Quoted 2 lines

Yes, but do we have any error checks in the hw_params or trigger cases with the legacy driver?

No, it just continues playing without the actual output.

ok, so could we remove all these error checks then for hdac_hdmi? The problem is really the output selection on jack detect/monitor reconfigurations, those checks don't add much value, do they?

Yes, I'm planning to remove the checks in hdac_hdmi. Before that, I will do some tests on it.

The monitor check in hw_params only impacts on the playback flow.

Regards,
Libin