ALSA: hda/hdmi: Fix the converter allocation for the silent stream

Track the converters handling the silent stream using a new
variable to avoid mixing of the open/close and silent stream
use. This change ensures the proper allocation of the converters.

Fixes: 5f80d6bd2b ("ALSA: hda/hdmi: Fix the converter reuse for the silent stream")

Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Reviewed-by: Kai Vehmanen <kai.vehmanen@linux.intel.com>
Link: https://lore.kernel.org/r/20220919135444.3554982-1-perex@perex.cz
Signed-off-by: Takashi Iwai <tiwai@suse.de>
This commit is contained in:
Jaroslav Kysela 2022-09-19 15:54:44 +02:00 committed by Takashi Iwai
parent bfbbfb2693
commit fc6f923ecf

View File

@ -54,6 +54,7 @@ MODULE_PARM_DESC(enable_all_pins, "Forcibly enable all pins");
struct hdmi_spec_per_cvt { struct hdmi_spec_per_cvt {
hda_nid_t cvt_nid; hda_nid_t cvt_nid;
bool assigned; /* the stream has been assigned */ bool assigned; /* the stream has been assigned */
bool silent_stream; /* silent stream activated */
unsigned int channels_min; unsigned int channels_min;
unsigned int channels_max; unsigned int channels_max;
u32 rates; u32 rates;
@ -988,7 +989,8 @@ static int hdmi_setup_stream(struct hda_codec *codec, hda_nid_t cvt_nid,
* of the pin. * of the pin.
*/ */
static int hdmi_choose_cvt(struct hda_codec *codec, static int hdmi_choose_cvt(struct hda_codec *codec,
int pin_idx, int *cvt_id) int pin_idx, int *cvt_id,
bool silent)
{ {
struct hdmi_spec *spec = codec->spec; struct hdmi_spec *spec = codec->spec;
struct hdmi_spec_per_pin *per_pin; struct hdmi_spec_per_pin *per_pin;
@ -1003,6 +1005,9 @@ static int hdmi_choose_cvt(struct hda_codec *codec,
if (per_pin && per_pin->silent_stream) { if (per_pin && per_pin->silent_stream) {
cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid); cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid);
per_cvt = get_cvt(spec, cvt_idx);
if (per_cvt->assigned && !silent)
return -EBUSY;
if (cvt_id) if (cvt_id)
*cvt_id = cvt_idx; *cvt_id = cvt_idx;
return 0; return 0;
@ -1013,7 +1018,7 @@ static int hdmi_choose_cvt(struct hda_codec *codec,
per_cvt = get_cvt(spec, cvt_idx); per_cvt = get_cvt(spec, cvt_idx);
/* Must not already be assigned */ /* Must not already be assigned */
if (per_cvt->assigned) if (per_cvt->assigned || per_cvt->silent_stream)
continue; continue;
if (per_pin == NULL) if (per_pin == NULL)
break; break;
@ -1199,7 +1204,7 @@ static int hdmi_pcm_open_no_pin(struct hda_pcm_stream *hinfo,
if (pcm_idx < 0) if (pcm_idx < 0)
return -EINVAL; return -EINVAL;
err = hdmi_choose_cvt(codec, -1, &cvt_idx); err = hdmi_choose_cvt(codec, -1, &cvt_idx, false);
if (err) if (err)
return err; return err;
@ -1267,7 +1272,7 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
} }
} }
err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx); err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, false);
if (err < 0) if (err < 0)
goto unlock; goto unlock;
@ -1278,7 +1283,6 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo,
set_bit(pcm_idx, &spec->pcm_in_use); set_bit(pcm_idx, &spec->pcm_in_use);
per_pin = get_pin(spec, pin_idx); per_pin = get_pin(spec, pin_idx);
per_pin->cvt_nid = per_cvt->cvt_nid; per_pin->cvt_nid = per_cvt->cvt_nid;
per_pin->silent_stream = false;
hinfo->nid = per_cvt->cvt_nid; hinfo->nid = per_cvt->cvt_nid;
/* flip stripe flag for the assigned stream if supported */ /* flip stripe flag for the assigned stream if supported */
@ -1760,14 +1764,14 @@ static void silent_stream_enable(struct hda_codec *codec,
} }
pin_idx = pin_id_to_pin_index(codec, per_pin->pin_nid, per_pin->dev_id); pin_idx = pin_id_to_pin_index(codec, per_pin->pin_nid, per_pin->dev_id);
err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx); err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, true);
if (err) { if (err) {
codec_err(codec, "hdmi: no free converter to enable silent mode\n"); codec_err(codec, "hdmi: no free converter to enable silent mode\n");
goto unlock_out; goto unlock_out;
} }
per_cvt = get_cvt(spec, cvt_idx); per_cvt = get_cvt(spec, cvt_idx);
per_cvt->assigned = true; per_cvt->silent_stream = true;
per_pin->cvt_nid = per_cvt->cvt_nid; per_pin->cvt_nid = per_cvt->cvt_nid;
per_pin->silent_stream = true; per_pin->silent_stream = true;
@ -1827,7 +1831,7 @@ static void silent_stream_disable(struct hda_codec *codec,
cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid); cvt_idx = cvt_nid_to_cvt_index(codec, per_pin->cvt_nid);
if (cvt_idx >= 0 && cvt_idx < spec->num_cvts) { if (cvt_idx >= 0 && cvt_idx < spec->num_cvts) {
per_cvt = get_cvt(spec, cvt_idx); per_cvt = get_cvt(spec, cvt_idx);
per_cvt->assigned = false; per_cvt->silent_stream = false;
} }
if (spec->silent_stream_type == SILENT_STREAM_I915) { if (spec->silent_stream_type == SILENT_STREAM_I915) {