diff options
Diffstat (limited to 'sound/hda/codecs/hdmi/hdmi.c')
-rw-r--r-- | sound/hda/codecs/hdmi/hdmi.c | 199 |
1 files changed, 72 insertions, 127 deletions
diff --git a/sound/hda/codecs/hdmi/hdmi.c b/sound/hda/codecs/hdmi/hdmi.c index 44576b30f699..dc38bfd9dba5 100644 --- a/sound/hda/codecs/hdmi/hdmi.c +++ b/sound/hda/codecs/hdmi/hdmi.c @@ -145,18 +145,15 @@ static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol, uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES; pcm_idx = kcontrol->private_value; - mutex_lock(&spec->pcm_lock); + guard(mutex)(&spec->pcm_lock); per_pin = pcm_idx_to_pin(spec, pcm_idx); if (!per_pin) { /* no pin is bound to the pcm */ uinfo->count = 0; - goto unlock; + return 0; } eld = &per_pin->sink_eld; uinfo->count = eld->eld_valid ? eld->eld_size : 0; - - unlock: - mutex_unlock(&spec->pcm_lock); return 0; } @@ -168,24 +165,22 @@ static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol, struct hdmi_spec_per_pin *per_pin; struct hdmi_eld *eld; int pcm_idx; - int err = 0; pcm_idx = kcontrol->private_value; - mutex_lock(&spec->pcm_lock); + guard(mutex)(&spec->pcm_lock); per_pin = pcm_idx_to_pin(spec, pcm_idx); if (!per_pin) { /* no pin is bound to the pcm */ memset(ucontrol->value.bytes.data, 0, ARRAY_SIZE(ucontrol->value.bytes.data)); - goto unlock; + return 0; } eld = &per_pin->sink_eld; if (eld->eld_size > ARRAY_SIZE(ucontrol->value.bytes.data) || eld->eld_size > ELD_MAX_SIZE) { snd_BUG(); - err = -EINVAL; - goto unlock; + return -EINVAL; } memset(ucontrol->value.bytes.data, 0, @@ -193,10 +188,7 @@ static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol, if (eld->eld_valid) memcpy(ucontrol->value.bytes.data, eld->eld_buffer, eld->eld_size); - - unlock: - mutex_unlock(&spec->pcm_lock); - return err; + return 0; } static const struct snd_kcontrol_new eld_bytes_ctl = { @@ -295,10 +287,9 @@ static void print_eld_info(struct snd_info_entry *entry, { struct hdmi_spec_per_pin *per_pin = entry->private_data; - mutex_lock(&per_pin->lock); + guard(mutex)(&per_pin->lock); snd_hdmi_print_eld_info(&per_pin->sink_eld, buffer, per_pin->pin_nid, per_pin->dev_id, per_pin->cvt_nid); - mutex_unlock(&per_pin->lock); } static void write_eld_info(struct snd_info_entry *entry, @@ -306,9 +297,8 @@ static void write_eld_info(struct snd_info_entry *entry, { struct hdmi_spec_per_pin *per_pin = entry->private_data; - mutex_lock(&per_pin->lock); + guard(mutex)(&per_pin->lock); snd_hdmi_write_eld_info(&per_pin->sink_eld, buffer); - mutex_unlock(&per_pin->lock); } static int eld_proc_new(struct hdmi_spec_per_pin *per_pin, int index) @@ -599,9 +589,8 @@ void snd_hda_hdmi_check_presence_and_report(struct hda_codec *codec, if (pin_idx < 0) return; - mutex_lock(&spec->pcm_lock); + guard(mutex)(&spec->pcm_lock); hdmi_present_sense(get_pin(spec, pin_idx), 1); - mutex_unlock(&spec->pcm_lock); } EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_check_presence_and_report, "SND_HDA_CODEC_HDMI"); @@ -907,19 +896,17 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, if (pcm_idx < 0) return -EINVAL; - mutex_lock(&spec->pcm_lock); + guard(mutex)(&spec->pcm_lock); pin_idx = hinfo_to_pin_index(codec, hinfo); /* no pin is assigned to the PCM * PA need pcm open successfully when probe */ - if (pin_idx < 0) { - err = hdmi_pcm_open_no_pin(hinfo, codec, substream); - goto unlock; - } + if (pin_idx < 0) + return hdmi_pcm_open_no_pin(hinfo, codec, substream); err = hdmi_choose_cvt(codec, pin_idx, &cvt_idx, false); if (err < 0) - goto unlock; + return err; per_cvt = get_cvt(spec, cvt_idx); /* Claim converter */ @@ -960,8 +947,7 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, per_cvt->assigned = false; hinfo->nid = 0; snd_hda_spdif_ctls_unassign(codec, pcm_idx); - err = -ENODEV; - goto unlock; + return -ENODEV; } } @@ -973,9 +959,7 @@ static int hdmi_pcm_open(struct hda_pcm_stream *hinfo, snd_pcm_hw_constraint_step(substream->runtime, 0, SNDRV_PCM_HW_PARAM_CHANNELS, 2); - unlock: - mutex_unlock(&spec->pcm_lock); - return err; + return 0; } /* @@ -1270,20 +1254,19 @@ static void hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin, * the unsolicited response to avoid custom WARs. */ int present; - int ret; #ifdef CONFIG_PM if (dev->power.runtime_status == RPM_SUSPENDING) return; #endif - ret = snd_hda_power_up_pm(codec); - if (ret < 0 && pm_runtime_suspended(dev)) - goto out; + CLASS(snd_hda_power_pm, pm)(codec); + if (pm.err < 0 && pm_runtime_suspended(dev)) + return; present = snd_hda_jack_pin_sense(codec, pin_nid, dev_id); - mutex_lock(&per_pin->lock); + guard(mutex)(&per_pin->lock); eld->monitor_present = !!(present & AC_PINSENSE_PRESENCE); if (eld->monitor_present) eld->eld_valid = !!(present & AC_PINSENSE_ELDV); @@ -1301,9 +1284,6 @@ static void hdmi_present_sense_via_verbs(struct hdmi_spec_per_pin *per_pin, } update_eld(codec, per_pin, eld, repoll); - mutex_unlock(&per_pin->lock); - out: - snd_hda_power_down_pm(codec); } static void silent_stream_enable(struct hda_codec *codec, @@ -1318,27 +1298,25 @@ static void silent_stream_enable(struct hda_codec *codec, * have to be done without mutex held. */ - err = snd_hda_power_up_pm(codec); - if (err < 0 && err != -EACCES) { + CLASS(snd_hda_power_pm, pm)(codec); + if (pm.err < 0 && pm.err != -EACCES) { codec_err(codec, - "Failed to power up codec for silent stream enable ret=[%d]\n", err); - snd_hda_power_down_pm(codec); + "Failed to power up codec for silent stream enable ret=[%d]\n", pm.err); return; } - mutex_lock(&per_pin->lock); + guard(mutex)(&per_pin->lock); if (per_pin->setup) { codec_dbg(codec, "hdmi: PCM already open, no silent stream\n"); - err = -EBUSY; - goto unlock_out; + return; } 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, true); if (err) { codec_err(codec, "hdmi: no free converter to enable silent mode\n"); - goto unlock_out; + return; } per_cvt = get_cvt(spec, cvt_idx); @@ -1358,11 +1336,6 @@ static void silent_stream_enable(struct hda_codec *codec, pin_cvt_fixup(codec, per_pin, 0); spec->ops.silent_stream(codec, per_pin, true); - - unlock_out: - mutex_unlock(&per_pin->lock); - - snd_hda_power_down_pm(codec); } static void silent_stream_disable(struct hda_codec *codec, @@ -1370,20 +1343,19 @@ static void silent_stream_disable(struct hda_codec *codec, { struct hdmi_spec *spec = codec->spec; struct hdmi_spec_per_cvt *per_cvt; - int cvt_idx, err; + int cvt_idx; - err = snd_hda_power_up_pm(codec); - if (err < 0 && err != -EACCES) { + CLASS(snd_hda_power_pm, pm)(codec); + if (pm.err < 0 && pm.err != -EACCES) { codec_err(codec, "Failed to power up codec for silent stream disable ret=[%d]\n", - err); - snd_hda_power_down_pm(codec); + pm.err); return; } - mutex_lock(&per_pin->lock); + guard(mutex)(&per_pin->lock); if (!per_pin->silent_stream) - goto unlock_out; + return; codec_dbg(codec, "HDMI: disable silent stream on pin-NID=0x%x cvt-NID=0x%x\n", per_pin->pin_nid, per_pin->cvt_nid); @@ -1398,11 +1370,6 @@ static void silent_stream_disable(struct hda_codec *codec, per_pin->cvt_nid = 0; per_pin->silent_stream = false; - - unlock_out: - mutex_unlock(&per_pin->lock); - - snd_hda_power_down_pm(codec); } /* update ELD and jack state via audio component */ @@ -1413,16 +1380,16 @@ static void sync_eld_via_acomp(struct hda_codec *codec, struct hdmi_eld *eld = &spec->temp_eld; bool monitor_prev, monitor_next; - mutex_lock(&per_pin->lock); - eld->monitor_present = false; - monitor_prev = per_pin->sink_eld.monitor_present; - eld->eld_size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid, - per_pin->dev_id, &eld->monitor_present, - eld->eld_buffer, ELD_MAX_SIZE); - eld->eld_valid = (eld->eld_size > 0); - update_eld(codec, per_pin, eld, 0); - monitor_next = per_pin->sink_eld.monitor_present; - mutex_unlock(&per_pin->lock); + scoped_guard(mutex, &per_pin->lock) { + eld->monitor_present = false; + monitor_prev = per_pin->sink_eld.monitor_present; + eld->eld_size = snd_hdac_acomp_get_eld(&codec->core, per_pin->pin_nid, + per_pin->dev_id, &eld->monitor_present, + eld->eld_buffer, ELD_MAX_SIZE); + eld->eld_valid = (eld->eld_size > 0); + update_eld(codec, per_pin, eld, 0); + monitor_next = per_pin->sink_eld.monitor_present; + } if (spec->silent_stream_type) { if (!monitor_prev && monitor_next) @@ -1458,9 +1425,8 @@ static void hdmi_repoll_eld(struct work_struct *work) if (per_pin->repoll_count++ > 6) per_pin->repoll_count = 0; - mutex_lock(&spec->pcm_lock); + guard(mutex)(&spec->pcm_lock); hdmi_present_sense(per_pin, per_pin->repoll_count); - mutex_unlock(&spec->pcm_lock); } static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid) @@ -1655,20 +1621,15 @@ EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_parse_codec, "SND_HDA_CODEC_HDMI"); static bool check_non_pcm_per_cvt(struct hda_codec *codec, hda_nid_t cvt_nid) { struct hda_spdif_out *spdif; - bool non_pcm; - mutex_lock(&codec->spdif_mutex); + guard(mutex)(&codec->spdif_mutex); spdif = snd_hda_spdif_out_of_nid(codec, cvt_nid); /* Add sanity check to pass klockwork check. * This should never happen. */ - if (WARN_ON(spdif == NULL)) { - mutex_unlock(&codec->spdif_mutex); + if (WARN_ON(spdif == NULL)) return true; - } - non_pcm = !!(spdif->status & IEC958_AES0_NONAUDIO); - mutex_unlock(&codec->spdif_mutex); - return non_pcm; + return !!(spdif->status & IEC958_AES0_NONAUDIO); } /* @@ -1688,9 +1649,8 @@ int snd_hda_hdmi_generic_pcm_prepare(struct hda_pcm_stream *hinfo, struct snd_pcm_runtime *runtime = substream->runtime; bool non_pcm; int pinctl, stripe; - int err = 0; - mutex_lock(&spec->pcm_lock); + guard(mutex)(&spec->pcm_lock); pin_idx = hinfo_to_pin_index(codec, hinfo); if (pin_idx < 0) { /* when pcm is not bound to a pin skip pin setup and return 0 @@ -1699,7 +1659,7 @@ int snd_hda_hdmi_generic_pcm_prepare(struct hda_pcm_stream *hinfo, pin_cvt_fixup(codec, NULL, cvt_nid); snd_hda_codec_setup_stream(codec, cvt_nid, stream_tag, 0, format); - goto unlock; + return 0; } per_pin = get_pin(spec, pin_idx); @@ -1721,20 +1681,20 @@ int snd_hda_hdmi_generic_pcm_prepare(struct hda_pcm_stream *hinfo, per_pin->dev_id, runtime->rate); non_pcm = check_non_pcm_per_cvt(codec, cvt_nid); - mutex_lock(&per_pin->lock); - per_pin->channels = substream->runtime->channels; - per_pin->setup = true; + scoped_guard(mutex, &per_pin->lock) { + per_pin->channels = substream->runtime->channels; + per_pin->setup = true; + + if (get_wcaps(codec, cvt_nid) & AC_WCAP_STRIPE) { + stripe = snd_hdac_get_stream_stripe_ctl(&codec->bus->core, + substream); + snd_hda_codec_write(codec, cvt_nid, 0, + AC_VERB_SET_STRIPE_CONTROL, + stripe); + } - if (get_wcaps(codec, cvt_nid) & AC_WCAP_STRIPE) { - stripe = snd_hdac_get_stream_stripe_ctl(&codec->bus->core, - substream); - snd_hda_codec_write(codec, cvt_nid, 0, - AC_VERB_SET_STRIPE_CONTROL, - stripe); + snd_hda_hdmi_setup_audio_infoframe(codec, per_pin, non_pcm); } - - snd_hda_hdmi_setup_audio_infoframe(codec, per_pin, non_pcm); - mutex_unlock(&per_pin->lock); if (spec->dyn_pin_out) { snd_hda_set_dev_select(codec, per_pin->pin_nid, per_pin->dev_id); @@ -1746,11 +1706,8 @@ int snd_hda_hdmi_generic_pcm_prepare(struct hda_pcm_stream *hinfo, } /* snd_hda_set_dev_select() has been called before */ - err = spec->ops.setup_stream(codec, cvt_nid, per_pin->pin_nid, - per_pin->dev_id, stream_tag, format); - unlock: - mutex_unlock(&spec->pcm_lock); - return err; + return spec->ops.setup_stream(codec, cvt_nid, per_pin->pin_nid, + per_pin->dev_id, stream_tag, format); } EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_pcm_prepare, "SND_HDA_CODEC_HDMI"); @@ -1772,20 +1729,15 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo, struct hdmi_spec_per_cvt *per_cvt; struct hdmi_spec_per_pin *per_pin; int pinctl; - int err = 0; - mutex_lock(&spec->pcm_lock); + guard(mutex)(&spec->pcm_lock); if (hinfo->nid) { pcm_idx = hinfo_to_pcm_index(codec, hinfo); - if (snd_BUG_ON(pcm_idx < 0)) { - err = -EINVAL; - goto unlock; - } + if (snd_BUG_ON(pcm_idx < 0)) + return -EINVAL; cvt_idx = cvt_nid_to_cvt_index(codec, hinfo->nid); - if (snd_BUG_ON(cvt_idx < 0)) { - err = -EINVAL; - goto unlock; - } + if (snd_BUG_ON(cvt_idx < 0)) + return -EINVAL; per_cvt = get_cvt(spec, cvt_idx); per_cvt->assigned = false; hinfo->nid = 0; @@ -1800,7 +1752,7 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo, * hdmi_pcm_open() */ if (pin_idx < 0) - goto unlock; + return 0; per_pin = get_pin(spec, pin_idx); @@ -1814,19 +1766,15 @@ static int hdmi_pcm_close(struct hda_pcm_stream *hinfo, pinctl & ~PIN_OUT); } - mutex_lock(&per_pin->lock); + guard(mutex)(&per_pin->lock); per_pin->chmap_set = false; memset(per_pin->chmap, 0, sizeof(per_pin->chmap)); per_pin->setup = false; per_pin->channels = 0; - mutex_unlock(&per_pin->lock); } -unlock: - mutex_unlock(&spec->pcm_lock); - - return err; + return 0; } static const struct hda_pcm_ops generic_ops = { @@ -1871,12 +1819,11 @@ static void hdmi_set_chmap(struct hdac_device *hdac, int pcm_idx, if (!per_pin) return; - mutex_lock(&per_pin->lock); + guard(mutex)(&per_pin->lock); per_pin->chmap_set = true; memcpy(per_pin->chmap, chmap, ARRAY_SIZE(per_pin->chmap)); if (prepared) snd_hda_hdmi_setup_audio_infoframe(codec, per_pin, per_pin->non_pcm); - mutex_unlock(&per_pin->lock); } static bool is_hdmi_pcm_attached(struct hdac_device *hdac, int pcm_idx) @@ -2045,7 +1992,7 @@ int snd_hda_hdmi_generic_init(struct hda_codec *codec) struct hdmi_spec *spec = codec->spec; int pin_idx; - mutex_lock(&spec->bind_lock); + guard(mutex)(&spec->bind_lock); for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { struct hdmi_spec_per_pin *per_pin = get_pin(spec, pin_idx); hda_nid_t pin_nid = per_pin->pin_nid; @@ -2058,7 +2005,6 @@ int snd_hda_hdmi_generic_init(struct hda_codec *codec) snd_hda_jack_detect_enable_callback_mst(codec, pin_nid, dev_id, jack_callback); } - mutex_unlock(&spec->bind_lock); return 0; } EXPORT_SYMBOL_NS_GPL(snd_hda_hdmi_generic_init, "SND_HDA_CODEC_HDMI"); @@ -2229,7 +2175,7 @@ static void generic_acomp_notifier_set(struct drm_audio_component *acomp, int i; spec = container_of(acomp->audio_ops, struct hdmi_spec, drm_audio_ops); - mutex_lock(&spec->bind_lock); + guard(mutex)(&spec->bind_lock); spec->use_acomp_notifier = use_acomp; spec->codec->relaxed_resume = use_acomp; spec->codec->bus->keep_power = 0; @@ -2239,7 +2185,6 @@ static void generic_acomp_notifier_set(struct drm_audio_component *acomp, get_pin(spec, i)->pin_nid, get_pin(spec, i)->dev_id, use_acomp); - mutex_unlock(&spec->bind_lock); } /* enable / disable the notifier via master bind / unbind */ |