Commit 1835a0f9 authored by Takashi Iwai's avatar Takashi Iwai

ALSA: hda - Cache the jack-detection value

Introduce a table containing the pins and their jack-detection states
for avoiding the unnecessary verbs to check the pin status at each time.

When the unsol event is enabled via snd_hda_jack_detect_enable(), it
automatically adds the given NID to the table.  Then the driver supposes
that the codec driver will set the dirty flag appropariately when an
unsolicited event is invoked for that pin.

The behavior for reading other pins that aren't registered in the table
doesn't change.  Only the pins assigned to the table are cached, so far.

In near futre, this table can be extended to use the central place for
the unsolicited events of all pins, etc, and eventually include the
jack-detect kcontrols that replace the current input-jack stuff.
Signed-off-by: default avatarTakashi Iwai <tiwai@suse.de>
parent 04f5ade6
snd-hda-intel-objs := hda_intel.o snd-hda-intel-objs := hda_intel.o
snd-hda-codec-y := hda_codec.o snd-hda-codec-y := hda_codec.o hda_jack.o
snd-hda-codec-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o snd-hda-codec-$(CONFIG_SND_HDA_GENERIC) += hda_generic.o
snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o
snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include <sound/jack.h> #include <sound/jack.h>
#include "hda_local.h" #include "hda_local.h"
#include "hda_beep.h" #include "hda_beep.h"
#include "hda_jack.h"
#include <sound/hda_hwdep.h> #include <sound/hda_hwdep.h>
#define CREATE_TRACE_POINTS #define CREATE_TRACE_POINTS
...@@ -1723,43 +1724,6 @@ int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, ...@@ -1723,43 +1724,6 @@ int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
} }
EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps); EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps);
/**
* snd_hda_pin_sense - execute pin sense measurement
* @codec: the CODEC to sense
* @nid: the pin NID to sense
*
* Execute necessary pin sense measurement and return its Presence Detect,
* Impedance, ELD Valid etc. status bits.
*/
u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
{
u32 pincap;
if (!codec->no_trigger_sense) {
pincap = snd_hda_query_pin_caps(codec, nid);
if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
snd_hda_codec_read(codec, nid, 0,
AC_VERB_SET_PIN_SENSE, 0);
}
return snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_PIN_SENSE, 0);
}
EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
/**
* snd_hda_jack_detect - query pin Presence Detect status
* @codec: the CODEC to sense
* @nid: the pin NID to sense
*
* Query and return the pin's Presence Detect status.
*/
int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
{
u32 sense = snd_hda_pin_sense(codec, nid);
return !!(sense & AC_PINSENSE_PRESENCE);
}
EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
/* /*
* read the current volume to info * read the current volume to info
* if the cache exists, read the cache value. * if the cache exists, read the cache value.
...@@ -2308,6 +2272,7 @@ int snd_hda_codec_reset(struct hda_codec *codec) ...@@ -2308,6 +2272,7 @@ int snd_hda_codec_reset(struct hda_codec *codec)
} }
if (codec->patch_ops.free) if (codec->patch_ops.free)
codec->patch_ops.free(codec); codec->patch_ops.free(codec);
snd_hda_jack_tbl_clear(codec);
codec->proc_widget_hook = NULL; codec->proc_widget_hook = NULL;
codec->spec = NULL; codec->spec = NULL;
free_hda_cache(&codec->amp_cache); free_hda_cache(&codec->amp_cache);
...@@ -3364,6 +3329,7 @@ static void hda_call_codec_resume(struct hda_codec *codec) ...@@ -3364,6 +3329,7 @@ static void hda_call_codec_resume(struct hda_codec *codec)
restore_pincfgs(codec); /* restore all current pin configs */ restore_pincfgs(codec); /* restore all current pin configs */
restore_shutup_pins(codec); restore_shutup_pins(codec);
hda_exec_init_verbs(codec); hda_exec_init_verbs(codec);
snd_hda_jack_set_dirty_all(codec);
if (codec->patch_ops.resume) if (codec->patch_ops.resume)
codec->patch_ops.resume(codec); codec->patch_ops.resume(codec);
else { else {
......
...@@ -869,6 +869,9 @@ struct hda_codec { ...@@ -869,6 +869,9 @@ struct hda_codec {
void (*proc_widget_hook)(struct snd_info_buffer *buffer, void (*proc_widget_hook)(struct snd_info_buffer *buffer,
struct hda_codec *codec, hda_nid_t nid); struct hda_codec *codec, hda_nid_t nid);
/* jack detection */
struct snd_array jacktbl;
#ifdef CONFIG_SND_HDA_INPUT_JACK #ifdef CONFIG_SND_HDA_INPUT_JACK
/* jack detection */ /* jack detection */
struct snd_array jacks; struct snd_array jacks;
......
/*
* Jack-detection handling for HD-audio
*
* Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
*
* This driver is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#include <linux/init.h>
#include <linux/slab.h>
#include <sound/core.h>
#include "hda_codec.h"
#include "hda_local.h"
#include "hda_jack.h"
/* execute pin sense measurement */
static u32 read_pin_sense(struct hda_codec *codec, hda_nid_t nid)
{
u32 pincap;
if (!codec->no_trigger_sense) {
pincap = snd_hda_query_pin_caps(codec, nid);
if (pincap & AC_PINCAP_TRIG_REQ) /* need trigger? */
snd_hda_codec_read(codec, nid, 0,
AC_VERB_SET_PIN_SENSE, 0);
}
return snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_PIN_SENSE, 0);
}
/**
* snd_hda_jack_tbl_get - query the jack-table entry for the given NID
*/
struct hda_jack_tbl *
snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid)
{
struct hda_jack_tbl *jack = codec->jacktbl.list;
int i;
if (!nid || !jack)
return NULL;
for (i = 0; i < codec->jacktbl.used; i++, jack++)
if (jack->nid == nid)
return jack;
return NULL;
}
EXPORT_SYMBOL_HDA(snd_hda_jack_tbl_get);
/**
* snd_hda_jack_tbl_new - create a jack-table entry for the given NID
*/
struct hda_jack_tbl *
snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid)
{
struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid);
if (jack)
return jack;
snd_array_init(&codec->jacktbl, sizeof(*jack), 16);
jack = snd_array_new(&codec->jacktbl);
if (!jack)
return NULL;
jack->nid = nid;
jack->jack_dirty = 1;
return jack;
}
void snd_hda_jack_tbl_clear(struct hda_codec *codec)
{
snd_array_free(&codec->jacktbl);
}
/* update the cached value and notification flag if needed */
static void jack_detect_update(struct hda_codec *codec,
struct hda_jack_tbl *jack)
{
if (jack->jack_dirty) {
jack->pin_sense = read_pin_sense(codec, jack->nid);
jack->jack_dirty = 0;
}
}
/**
* snd_hda_set_dirty_all - Mark all the cached as dirty
*
* This function sets the dirty flag to all entries of jack table.
* It's called from the resume path in hda_codec.c.
*/
void snd_hda_jack_set_dirty_all(struct hda_codec *codec)
{
struct hda_jack_tbl *jack = codec->jacktbl.list;
int i;
for (i = 0; i < codec->jacktbl.used; i++, jack++)
if (jack->nid)
jack->jack_dirty = 1;
}
EXPORT_SYMBOL_HDA(snd_hda_jack_set_dirty_all);
/**
* snd_hda_pin_sense - execute pin sense measurement
* @codec: the CODEC to sense
* @nid: the pin NID to sense
*
* Execute necessary pin sense measurement and return its Presence Detect,
* Impedance, ELD Valid etc. status bits.
*/
u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid)
{
struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid);
if (jack) {
jack_detect_update(codec, jack);
return jack->pin_sense;
}
return read_pin_sense(codec, nid);
}
EXPORT_SYMBOL_HDA(snd_hda_pin_sense);
/**
* snd_hda_jack_detect - query pin Presence Detect status
* @codec: the CODEC to sense
* @nid: the pin NID to sense
*
* Query and return the pin's Presence Detect status.
*/
int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid)
{
u32 sense = snd_hda_pin_sense(codec, nid);
return !!(sense & AC_PINSENSE_PRESENCE);
}
EXPORT_SYMBOL_HDA(snd_hda_jack_detect);
/**
* snd_hda_jack_detect_enable - enable the jack-detection
*/
int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
unsigned int tag)
{
struct hda_jack_tbl *jack = snd_hda_jack_tbl_new(codec, nid);
if (!jack)
return -ENOMEM;
return snd_hda_codec_write_cache(codec, nid, 0,
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | tag);
}
EXPORT_SYMBOL_HDA(snd_hda_jack_detect_enable);
/*
* Jack-detection handling for HD-audio
*
* Copyright (c) 2011 Takashi Iwai <tiwai@suse.de>
*
* This driver is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*/
#ifndef __SOUND_HDA_JACK_H
#define __SOUND_HDA_JACK_H
struct hda_jack_tbl {
hda_nid_t nid;
unsigned int pin_sense; /* cached pin-sense value */
unsigned int jack_dirty:1; /* needs to update? */
};
struct hda_jack_tbl *
snd_hda_jack_tbl_get(struct hda_codec *codec, hda_nid_t nid);
struct hda_jack_tbl *
snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid);
void snd_hda_jack_tbl_clear(struct hda_codec *codec);
/**
* snd_hda_jack_set_dirty - set the dirty flag for the given jack-entry
*
* Call this function when a pin-state may change, e.g. when the hardware
* notifies via an unsolicited event.
*/
static inline void snd_hda_jack_set_dirty(struct hda_codec *codec,
hda_nid_t nid)
{
struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid);
if (jack)
jack->jack_dirty = 1;
}
void snd_hda_jack_set_dirty_all(struct hda_codec *codec);
int snd_hda_jack_detect_enable(struct hda_codec *codec, hda_nid_t nid,
unsigned int tag);
u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
static inline bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
{
if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_PRES_DETECT))
return false;
if (!codec->ignore_misc_bit &&
(get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) &
AC_DEFCFG_MISC_NO_PRESENCE))
return false;
if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
return false;
return true;
}
#endif /* __SOUND_HDA_JACK_H */
...@@ -505,21 +505,6 @@ int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, ...@@ -505,21 +505,6 @@ int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid); u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid, int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
unsigned int caps); unsigned int caps);
u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
static inline bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
{
if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_PRES_DETECT))
return false;
if (!codec->ignore_misc_bit &&
(get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid)) &
AC_DEFCFG_MISC_NO_PRESENCE))
return false;
if (!(get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP))
return false;
return true;
}
/* flags for hda_nid_item */ /* flags for hda_nid_item */
#define HDA_NID_ITEM_AMP (1<<0) #define HDA_NID_ITEM_AMP (1<<0)
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
#include "hda_codec.h" #include "hda_codec.h"
#include "hda_local.h" #include "hda_local.h"
#include "hda_beep.h" #include "hda_beep.h"
#include "hda_jack.h"
struct ad198x_spec { struct ad198x_spec {
const struct snd_kcontrol_new *mixers[6]; const struct snd_kcontrol_new *mixers[6];
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#include <sound/core.h> #include <sound/core.h>
#include "hda_codec.h" #include "hda_codec.h"
#include "hda_local.h" #include "hda_local.h"
#include "hda_jack.h"
#include <sound/tlv.h> #include <sound/tlv.h>
/* /*
...@@ -1020,9 +1021,7 @@ static void init_output(struct hda_codec *codec) ...@@ -1020,9 +1021,7 @@ static void init_output(struct hda_codec *codec)
if (!cfg->speaker_outs) if (!cfg->speaker_outs)
continue; continue;
if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
snd_hda_codec_write(codec, nid, 0, snd_hda_jack_detect_enable(codec, nid, HP_EVENT);
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | HP_EVENT);
spec->hp_detect = 1; spec->hp_detect = 1;
} }
} }
...@@ -1063,9 +1062,7 @@ static void init_input(struct hda_codec *codec) ...@@ -1063,9 +1062,7 @@ static void init_input(struct hda_codec *codec)
AC_VERB_SET_AMP_GAIN_MUTE, AC_VERB_SET_AMP_GAIN_MUTE,
AMP_IN_MUTE(spec->adc_idx[i])); AMP_IN_MUTE(spec->adc_idx[i]));
if (spec->mic_detect && spec->automic_idx == i) if (spec->mic_detect && spec->automic_idx == i)
snd_hda_codec_write(codec, pin, 0, snd_hda_jack_detect_enable(codec, pin, MIC_EVENT);
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | MIC_EVENT);
} }
/* specific to CS421x */ /* specific to CS421x */
if (spec->vendor_nid == CS421X_VENDOR_NID) { if (spec->vendor_nid == CS421X_VENDOR_NID) {
...@@ -1227,6 +1224,8 @@ static void cs_free(struct hda_codec *codec) ...@@ -1227,6 +1224,8 @@ static void cs_free(struct hda_codec *codec)
static void cs_unsol_event(struct hda_codec *codec, unsigned int res) static void cs_unsol_event(struct hda_codec *codec, unsigned int res)
{ {
snd_hda_jack_set_dirty_all(codec); /* FIXME: to be more fine-grained */
switch ((res >> 26) & 0x7f) { switch ((res >> 26) & 0x7f) {
case HP_EVENT: case HP_EVENT:
cs_automute(codec); cs_automute(codec);
...@@ -1585,10 +1584,7 @@ static void init_cs421x_digital(struct hda_codec *codec) ...@@ -1585,10 +1584,7 @@ static void init_cs421x_digital(struct hda_codec *codec)
if (!cfg->speaker_outs) if (!cfg->speaker_outs)
continue; continue;
if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) { if (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP) {
snd_hda_jack_detect_enable(codec, nid, SPDIF_EVENT);
snd_hda_codec_write(codec, nid, 0,
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | SPDIF_EVENT);
spec->spdif_detect = 1; spec->spdif_detect = 1;
} }
} }
...@@ -1806,6 +1802,8 @@ static int cs421x_build_controls(struct hda_codec *codec) ...@@ -1806,6 +1802,8 @@ static int cs421x_build_controls(struct hda_codec *codec)
static void cs421x_unsol_event(struct hda_codec *codec, unsigned int res) static void cs421x_unsol_event(struct hda_codec *codec, unsigned int res)
{ {
snd_hda_jack_set_dirty_all(codec); /* FIXME: to be more fine-grained */
switch ((res >> 26) & 0x3f) { switch ((res >> 26) & 0x3f) {
case HP_EVENT: case HP_EVENT:
case SPDIF_EVENT: case SPDIF_EVENT:
......
...@@ -31,6 +31,7 @@ ...@@ -31,6 +31,7 @@
#include "hda_codec.h" #include "hda_codec.h"
#include "hda_local.h" #include "hda_local.h"
#include "hda_beep.h" #include "hda_beep.h"
#include "hda_jack.h"
#define CXT_PIN_DIR_IN 0x00 #define CXT_PIN_DIR_IN 0x00
#define CXT_PIN_DIR_OUT 0x01 #define CXT_PIN_DIR_OUT 0x01
...@@ -3756,6 +3757,7 @@ static void cx_auto_automic(struct hda_codec *codec) ...@@ -3756,6 +3757,7 @@ static void cx_auto_automic(struct hda_codec *codec)
static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res) static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
{ {
int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20; int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
snd_hda_jack_set_dirty(codec, nid);
switch (res >> 26) { switch (res >> 26) {
case CONEXANT_HP_EVENT: case CONEXANT_HP_EVENT:
cx_auto_hp_automute(codec); cx_auto_hp_automute(codec);
...@@ -3983,9 +3985,7 @@ static void enable_unsol_pins(struct hda_codec *codec, int num_pins, ...@@ -3983,9 +3985,7 @@ static void enable_unsol_pins(struct hda_codec *codec, int num_pins,
{ {
int i; int i;
for (i = 0; i < num_pins; i++) for (i = 0; i < num_pins; i++)
snd_hda_codec_write(codec, pins[i], 0, snd_hda_jack_detect_enable(codec, pins[i], tag);
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | tag);
} }
static void cx_auto_init_output(struct hda_codec *codec) static void cx_auto_init_output(struct hda_codec *codec)
...@@ -4060,16 +4060,14 @@ static void cx_auto_init_input(struct hda_codec *codec) ...@@ -4060,16 +4060,14 @@ static void cx_auto_init_input(struct hda_codec *codec)
if (spec->auto_mic) { if (spec->auto_mic) {
if (spec->auto_mic_ext >= 0) { if (spec->auto_mic_ext >= 0) {
snd_hda_codec_write(codec, snd_hda_jack_detect_enable(codec,
cfg->inputs[spec->auto_mic_ext].pin, 0, cfg->inputs[spec->auto_mic_ext].pin,
AC_VERB_SET_UNSOLICITED_ENABLE, CONEXANT_MIC_EVENT);
AC_USRSP_EN | CONEXANT_MIC_EVENT);
} }
if (spec->auto_mic_dock >= 0) { if (spec->auto_mic_dock >= 0) {
snd_hda_codec_write(codec, snd_hda_jack_detect_enable(codec,
cfg->inputs[spec->auto_mic_dock].pin, 0, cfg->inputs[spec->auto_mic_dock].pin,
AC_VERB_SET_UNSOLICITED_ENABLE, CONEXANT_MIC_EVENT);
AC_USRSP_EN | CONEXANT_MIC_EVENT);
} }
cx_auto_automic(codec); cx_auto_automic(codec);
} else { } else {
......
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
#include <sound/jack.h> #include <sound/jack.h>
#include "hda_codec.h" #include "hda_codec.h"
#include "hda_local.h" #include "hda_local.h"
#include "hda_jack.h"
static bool static_hdmi_pcm; static bool static_hdmi_pcm;
module_param(static_hdmi_pcm, bool, 0644); module_param(static_hdmi_pcm, bool, 0644);
...@@ -766,6 +767,7 @@ static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res) ...@@ -766,6 +767,7 @@ static void hdmi_intrinsic_event(struct hda_codec *codec, unsigned int res)
if (pin_idx < 0) if (pin_idx < 0)
return; return;
snd_hda_jack_set_dirty(codec, pin_nid);
hdmi_present_sense(&spec->pins[pin_idx], true); hdmi_present_sense(&spec->pins[pin_idx], true);
} }
...@@ -1282,9 +1284,7 @@ static int generic_hdmi_init(struct hda_codec *codec) ...@@ -1282,9 +1284,7 @@ static int generic_hdmi_init(struct hda_codec *codec)
struct hdmi_eld *eld = &per_pin->sink_eld; struct hdmi_eld *eld = &per_pin->sink_eld;
hdmi_init_pin(codec, pin_nid); hdmi_init_pin(codec, pin_nid);
snd_hda_codec_write(codec, pin_nid, 0, snd_hda_jack_detect_enable(codec, pin_nid, pin_nid);
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | pin_nid);
per_pin->codec = codec; per_pin->codec = codec;
INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld); INIT_DELAYED_WORK(&per_pin->work, hdmi_repoll_eld);
......
...@@ -33,6 +33,7 @@ ...@@ -33,6 +33,7 @@
#include "hda_codec.h" #include "hda_codec.h"
#include "hda_local.h" #include "hda_local.h"
#include "hda_beep.h" #include "hda_beep.h"
#include "hda_jack.h"
/* unsol event tags */ /* unsol event tags */
#define ALC_FRONT_EVENT 0x01 #define ALC_FRONT_EVENT 0x01
...@@ -664,6 +665,7 @@ static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res) ...@@ -664,6 +665,7 @@ static void alc_sku_unsol_event(struct hda_codec *codec, unsigned int res)
res >>= 28; res >>= 28;
else else
res >>= 26; res >>= 26;
snd_hda_jack_set_dirty_all(codec); /* FIXME: to be more fine-grained */
switch (res) { switch (res) {
case ALC_HP_EVENT: case ALC_HP_EVENT:
alc_hp_automute(codec); alc_hp_automute(codec);
...@@ -964,9 +966,7 @@ static void alc_init_automute(struct hda_codec *codec) ...@@ -964,9 +966,7 @@ static void alc_init_automute(struct hda_codec *codec)
continue; continue;
snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n", snd_printdd("realtek: Enable HP auto-muting on NID 0x%x\n",
nid); nid);
snd_hda_codec_write_cache(codec, nid, 0, snd_hda_jack_detect_enable(codec, nid, ALC_HP_EVENT);
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | ALC_HP_EVENT);
spec->detect_hp = 1; spec->detect_hp = 1;
} }
...@@ -978,9 +978,8 @@ static void alc_init_automute(struct hda_codec *codec) ...@@ -978,9 +978,8 @@ static void alc_init_automute(struct hda_codec *codec)
continue; continue;
snd_printdd("realtek: Enable Line-Out " snd_printdd("realtek: Enable Line-Out "
"auto-muting on NID 0x%x\n", nid); "auto-muting on NID 0x%x\n", nid);
snd_hda_codec_write_cache(codec, nid, 0, snd_hda_jack_detect_enable(codec, nid,
AC_VERB_SET_UNSOLICITED_ENABLE, ALC_FRONT_EVENT);
AC_USRSP_EN | ALC_FRONT_EVENT);
spec->detect_lo = 1; spec->detect_lo = 1;
} }
spec->automute_lo_possible = spec->detect_hp; spec->automute_lo_possible = spec->detect_hp;
...@@ -1108,13 +1107,10 @@ static bool alc_auto_mic_check_imux(struct hda_codec *codec) ...@@ -1108,13 +1107,10 @@ static bool alc_auto_mic_check_imux(struct hda_codec *codec)
return false; /* no corresponding imux */ return false; /* no corresponding imux */
} }
snd_hda_codec_write_cache(codec, spec->ext_mic_pin, 0, snd_hda_jack_detect_enable(codec, spec->ext_mic_pin, ALC_MIC_EVENT);
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | ALC_MIC_EVENT);
if (spec->dock_mic_pin) if (spec->dock_mic_pin)
snd_hda_codec_write_cache(codec, spec->dock_mic_pin, 0, snd_hda_jack_detect_enable(codec, spec->dock_mic_pin,
AC_VERB_SET_UNSOLICITED_ENABLE, ALC_MIC_EVENT);
AC_USRSP_EN | ALC_MIC_EVENT);
spec->auto_mic_valid_imux = 1; spec->auto_mic_valid_imux = 1;
spec->auto_mic = 1; spec->auto_mic = 1;
......
...@@ -37,6 +37,7 @@ ...@@ -37,6 +37,7 @@
#include "hda_codec.h" #include "hda_codec.h"
#include "hda_local.h" #include "hda_local.h"
#include "hda_beep.h" #include "hda_beep.h"
#include "hda_jack.h"
enum { enum {
STAC_VREF_EVENT = 1, STAC_VREF_EVENT = 1,
...@@ -4244,9 +4245,7 @@ static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid, ...@@ -4244,9 +4245,7 @@ static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
if (tag < 0) if (tag < 0)
return 0; return 0;
} }
snd_hda_codec_write_cache(codec, nid, 0, snd_hda_jack_detect_enable(codec, nid, tag);
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | tag);
return 1; return 1;
} }
...@@ -4795,24 +4794,11 @@ static void stac92xx_mic_detect(struct hda_codec *codec) ...@@ -4795,24 +4794,11 @@ static void stac92xx_mic_detect(struct hda_codec *codec)
mic->mux_idx); mic->mux_idx);
} }
static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid) static void handle_unsol_event(struct hda_codec *codec,
{ struct sigmatel_event *event)
struct sigmatel_event *event = stac_get_event(codec, nid);
if (!event)
return;
codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
}
static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
{ {
struct sigmatel_spec *spec = codec->spec; struct sigmatel_spec *spec = codec->spec;
struct sigmatel_event *event; int data;
int tag, data;
tag = (res >> 26) & 0x7f;
event = stac_get_event_from_tag(codec, tag);
if (!event)
return;
switch (event->type) { switch (event->type) {
case STAC_HP_EVENT: case STAC_HP_EVENT:
...@@ -4862,6 +4848,28 @@ static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res) ...@@ -4862,6 +4848,28 @@ static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
} }
} }
static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
{
struct sigmatel_event *event = stac_get_event(codec, nid);
if (!event)
return;
handle_unsol_event(codec, event);
}
static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
{
struct sigmatel_spec *spec = codec->spec;
struct sigmatel_event *event;
int tag;
tag = (res >> 26) & 0x7f;
event = stac_get_event_from_tag(codec, tag);
if (!event)
return;
snd_hda_jack_set_dirty(codec, event->nid);
handle_unsol_event(codec, event);
}
static int hp_blike_system(u32 subsystem_id); static int hp_blike_system(u32 subsystem_id);
static void set_hp_led_gpio(struct hda_codec *codec) static void set_hp_led_gpio(struct hda_codec *codec)
......
...@@ -54,6 +54,7 @@ ...@@ -54,6 +54,7 @@
#include <sound/asoundef.h> #include <sound/asoundef.h>
#include "hda_codec.h" #include "hda_codec.h"
#include "hda_local.h" #include "hda_local.h"
#include "hda_jack.h"
/* Pin Widget NID */ /* Pin Widget NID */
#define VT1708_HP_PIN_NID 0x20 #define VT1708_HP_PIN_NID 0x20
...@@ -1708,6 +1709,8 @@ static void via_gpio_control(struct hda_codec *codec) ...@@ -1708,6 +1709,8 @@ static void via_gpio_control(struct hda_codec *codec)
static void via_unsol_event(struct hda_codec *codec, static void via_unsol_event(struct hda_codec *codec,
unsigned int res) unsigned int res)
{ {
snd_hda_jack_set_dirty_all(codec); /* FIXME: to be more fine-grained */
res >>= 26; res >>= 26;
if (res & VIA_JACK_EVENT) if (res & VIA_JACK_EVENT)
...@@ -2729,9 +2732,8 @@ static void via_auto_init_unsol_event(struct hda_codec *codec) ...@@ -2729,9 +2732,8 @@ static void via_auto_init_unsol_event(struct hda_codec *codec)
int i; int i;
if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0])) if (cfg->hp_pins[0] && is_jack_detectable(codec, cfg->hp_pins[0]))
snd_hda_codec_write(codec, cfg->hp_pins[0], 0, snd_hda_jack_detect_enable(codec, cfg->hp_pins[0],
AC_VERB_SET_UNSOLICITED_ENABLE, VIA_HP_EVENT | VIA_JACK_EVENT);
AC_USRSP_EN | VIA_HP_EVENT | VIA_JACK_EVENT);
if (cfg->speaker_pins[0]) if (cfg->speaker_pins[0])
ev = VIA_LINE_EVENT; ev = VIA_LINE_EVENT;
...@@ -2740,16 +2742,14 @@ static void via_auto_init_unsol_event(struct hda_codec *codec) ...@@ -2740,16 +2742,14 @@ static void via_auto_init_unsol_event(struct hda_codec *codec)
for (i = 0; i < cfg->line_outs; i++) { for (i = 0; i < cfg->line_outs; i++) {
if (cfg->line_out_pins[i] && if (cfg->line_out_pins[i] &&
is_jack_detectable(codec, cfg->line_out_pins[i])) is_jack_detectable(codec, cfg->line_out_pins[i]))
snd_hda_codec_write(codec, cfg->line_out_pins[i], 0, snd_hda_jack_detect_enable(codec, cfg->line_out_pins[i],
AC_VERB_SET_UNSOLICITED_ENABLE, ev | VIA_JACK_EVENT);
AC_USRSP_EN | ev | VIA_JACK_EVENT);
} }
for (i = 0; i < cfg->num_inputs; i++) { for (i = 0; i < cfg->num_inputs; i++) {
if (is_jack_detectable(codec, cfg->inputs[i].pin)) if (is_jack_detectable(codec, cfg->inputs[i].pin))
snd_hda_codec_write(codec, cfg->inputs[i].pin, 0, snd_hda_jack_detect_enable(codec, cfg->inputs[i].pin,
AC_VERB_SET_UNSOLICITED_ENABLE, VIA_JACK_EVENT);
AC_USRSP_EN | VIA_JACK_EVENT);
} }
} }
...@@ -2781,6 +2781,7 @@ static void vt1708_update_hp_jack_state(struct work_struct *work) ...@@ -2781,6 +2781,7 @@ static void vt1708_update_hp_jack_state(struct work_struct *work)
vt1708_hp_work.work); vt1708_hp_work.work);
if (spec->codec_type != VT1708) if (spec->codec_type != VT1708)
return; return;
snd_hda_jack_set_dirty_all(spec->codec);
/* if jack state toggled */ /* if jack state toggled */
if (spec->vt1708_hp_present if (spec->vt1708_hp_present
!= snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) { != snd_hda_jack_detect(spec->codec, spec->autocfg.hp_pins[0])) {
......
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