Commit 187d333e authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda - Fix jack-detection control of VT1708

VT1708 has no support for unsolicited events per jack-plug, the driver
implements the workq for polling the jack-detection.  The mixer element
"Jack Detect" was supposed to control this behavior on/off, but this
doesn't work properly as is now.  The workq is always started and the
HP automute is always enabled.

This patch fixes the jack-detect control behavior by triggering / stopping
the work appropriately at the state change.  Also the work checks the
internal state to continue scheduling or not.

Cc: <stable@kernel.org> [v3.1]
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 92bb43e6
...@@ -208,6 +208,7 @@ struct via_spec { ...@@ -208,6 +208,7 @@ struct via_spec {
/* work to check hp jack state */ /* work to check hp jack state */
struct hda_codec *codec; struct hda_codec *codec;
struct delayed_work vt1708_hp_work; struct delayed_work vt1708_hp_work;
int hp_work_active;
int vt1708_jack_detect; int vt1708_jack_detect;
int vt1708_hp_present; int vt1708_hp_present;
...@@ -305,27 +306,35 @@ enum { ...@@ -305,27 +306,35 @@ enum {
static void analog_low_current_mode(struct hda_codec *codec); static void analog_low_current_mode(struct hda_codec *codec);
static bool is_aa_path_mute(struct hda_codec *codec); static bool is_aa_path_mute(struct hda_codec *codec);
static void vt1708_start_hp_work(struct via_spec *spec) #define hp_detect_with_aa(codec) \
(snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1 && \
!is_aa_path_mute(codec))
static void vt1708_stop_hp_work(struct via_spec *spec)
{ {
if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
return; return;
snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, if (spec->hp_work_active) {
!spec->vt1708_jack_detect); snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 1);
if (!delayed_work_pending(&spec->vt1708_hp_work)) cancel_delayed_work_sync(&spec->vt1708_hp_work);
schedule_delayed_work(&spec->vt1708_hp_work, spec->hp_work_active = 0;
msecs_to_jiffies(100)); }
} }
static void vt1708_stop_hp_work(struct via_spec *spec) static void vt1708_update_hp_work(struct via_spec *spec)
{ {
if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0) if (spec->codec_type != VT1708 || spec->autocfg.hp_pins[0] == 0)
return; return;
if (snd_hda_get_bool_hint(spec->codec, "analog_loopback_hp_detect") == 1 if (spec->vt1708_jack_detect &&
&& !is_aa_path_mute(spec->codec)) (spec->active_streams || hp_detect_with_aa(spec->codec))) {
return; if (!spec->hp_work_active) {
snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, snd_hda_codec_write(spec->codec, 0x1, 0, 0xf81, 0);
!spec->vt1708_jack_detect); schedule_delayed_work(&spec->vt1708_hp_work,
cancel_delayed_work_sync(&spec->vt1708_hp_work); msecs_to_jiffies(100));
spec->hp_work_active = 1;
}
} else if (!hp_detect_with_aa(spec->codec))
vt1708_stop_hp_work(spec);
} }
static void set_widgets_power_state(struct hda_codec *codec) static void set_widgets_power_state(struct hda_codec *codec)
...@@ -343,12 +352,7 @@ static int analog_input_switch_put(struct snd_kcontrol *kcontrol, ...@@ -343,12 +352,7 @@ static int analog_input_switch_put(struct snd_kcontrol *kcontrol,
set_widgets_power_state(codec); set_widgets_power_state(codec);
analog_low_current_mode(snd_kcontrol_chip(kcontrol)); analog_low_current_mode(snd_kcontrol_chip(kcontrol));
if (snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") == 1) { vt1708_update_hp_work(codec->spec);
if (is_aa_path_mute(codec))
vt1708_start_hp_work(codec->spec);
else
vt1708_stop_hp_work(codec->spec);
}
return change; return change;
} }
...@@ -1154,7 +1158,7 @@ static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo, ...@@ -1154,7 +1158,7 @@ static int via_playback_multi_pcm_prepare(struct hda_pcm_stream *hinfo,
spec->cur_dac_stream_tag = stream_tag; spec->cur_dac_stream_tag = stream_tag;
spec->cur_dac_format = format; spec->cur_dac_format = format;
mutex_unlock(&spec->config_mutex); mutex_unlock(&spec->config_mutex);
vt1708_start_hp_work(spec); vt1708_update_hp_work(spec);
return 0; return 0;
} }
...@@ -1174,7 +1178,7 @@ static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo, ...@@ -1174,7 +1178,7 @@ static int via_playback_hp_pcm_prepare(struct hda_pcm_stream *hinfo,
spec->cur_hp_stream_tag = stream_tag; spec->cur_hp_stream_tag = stream_tag;
spec->cur_hp_format = format; spec->cur_hp_format = format;
mutex_unlock(&spec->config_mutex); mutex_unlock(&spec->config_mutex);
vt1708_start_hp_work(spec); vt1708_update_hp_work(spec);
return 0; return 0;
} }
...@@ -1188,7 +1192,7 @@ static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo, ...@@ -1188,7 +1192,7 @@ static int via_playback_multi_pcm_cleanup(struct hda_pcm_stream *hinfo,
snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
spec->active_streams &= ~STREAM_MULTI_OUT; spec->active_streams &= ~STREAM_MULTI_OUT;
mutex_unlock(&spec->config_mutex); mutex_unlock(&spec->config_mutex);
vt1708_stop_hp_work(spec); vt1708_update_hp_work(spec);
return 0; return 0;
} }
...@@ -1203,7 +1207,7 @@ static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo, ...@@ -1203,7 +1207,7 @@ static int via_playback_hp_pcm_cleanup(struct hda_pcm_stream *hinfo,
snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0); snd_hda_codec_setup_stream(codec, spec->hp_dac_nid, 0, 0, 0);
spec->active_streams &= ~STREAM_INDEP_HP; spec->active_streams &= ~STREAM_INDEP_HP;
mutex_unlock(&spec->config_mutex); mutex_unlock(&spec->config_mutex);
vt1708_stop_hp_work(spec); vt1708_update_hp_work(spec);
return 0; return 0;
} }
...@@ -1645,7 +1649,8 @@ static void via_hp_automute(struct hda_codec *codec) ...@@ -1645,7 +1649,8 @@ static void via_hp_automute(struct hda_codec *codec)
int nums; int nums;
struct via_spec *spec = codec->spec; struct via_spec *spec = codec->spec;
if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0]) if (!spec->hp_independent_mode && spec->autocfg.hp_pins[0] &&
(spec->codec_type != VT1708 || spec->vt1708_jack_detect))
present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]); present = snd_hda_jack_detect(codec, spec->autocfg.hp_pins[0]);
if (spec->smart51_enabled) if (spec->smart51_enabled)
...@@ -2612,8 +2617,6 @@ static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol, ...@@ -2612,8 +2617,6 @@ static int vt1708_jack_detect_get(struct snd_kcontrol *kcontrol,
if (spec->codec_type != VT1708) if (spec->codec_type != VT1708)
return 0; return 0;
spec->vt1708_jack_detect =
!((snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8) & 0x1);
ucontrol->value.integer.value[0] = spec->vt1708_jack_detect; ucontrol->value.integer.value[0] = spec->vt1708_jack_detect;
return 0; return 0;
} }
...@@ -2623,18 +2626,22 @@ static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol, ...@@ -2623,18 +2626,22 @@ static int vt1708_jack_detect_put(struct snd_kcontrol *kcontrol,
{ {
struct hda_codec *codec = snd_kcontrol_chip(kcontrol); struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
struct via_spec *spec = codec->spec; struct via_spec *spec = codec->spec;
int change; int val;
if (spec->codec_type != VT1708) if (spec->codec_type != VT1708)
return 0; return 0;
spec->vt1708_jack_detect = ucontrol->value.integer.value[0]; val = !!ucontrol->value.integer.value[0];
change = (0x1 & (snd_hda_codec_read(codec, 0x1, 0, 0xf84, 0) >> 8)) if (spec->vt1708_jack_detect == val)
== !spec->vt1708_jack_detect; return 0;
if (spec->vt1708_jack_detect) { spec->vt1708_jack_detect = val;
if (spec->vt1708_jack_detect &&
snd_hda_get_bool_hint(codec, "analog_loopback_hp_detect") != 1) {
mute_aa_path(codec, 1); mute_aa_path(codec, 1);
notify_aa_path_ctls(codec); notify_aa_path_ctls(codec);
} }
return change; via_hp_automute(codec);
vt1708_update_hp_work(spec);
return 1;
} }
static const struct snd_kcontrol_new vt1708_jack_detect_ctl = { static const struct snd_kcontrol_new vt1708_jack_detect_ctl = {
...@@ -2771,6 +2778,7 @@ static int via_init(struct hda_codec *codec) ...@@ -2771,6 +2778,7 @@ static int via_init(struct hda_codec *codec)
via_auto_init_unsol_event(codec); via_auto_init_unsol_event(codec);
via_hp_automute(codec); via_hp_automute(codec);
vt1708_update_hp_work(spec);
return 0; return 0;
} }
...@@ -2787,7 +2795,9 @@ static void vt1708_update_hp_jack_state(struct work_struct *work) ...@@ -2787,7 +2795,9 @@ static void vt1708_update_hp_jack_state(struct work_struct *work)
spec->vt1708_hp_present ^= 1; spec->vt1708_hp_present ^= 1;
via_hp_automute(spec->codec); via_hp_automute(spec->codec);
} }
vt1708_start_hp_work(spec); if (spec->vt1708_jack_detect)
schedule_delayed_work(&spec->vt1708_hp_work,
msecs_to_jiffies(100));
} }
static int get_mux_nids(struct hda_codec *codec) static int get_mux_nids(struct hda_codec *codec)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment