Skip to content

Commit

Permalink
ALSA: hda - Integrate input-jack stuff into kctl-jack
Browse files Browse the repository at this point in the history
Instead of managing input-jack stuff separately, call all stuff inside
the kctl-jack creation, deletion and report.  The caller no longer needs
to care about input-jack.

The better integration between input-jack and kctl-jack should be done
in the upper layer in near future, but for now, it's implemented locally
for more tests.

Signed-off-by: Takashi Iwai <tiwai@suse.de>
  • Loading branch information
Takashi Iwai committed Dec 1, 2011
1 parent 358b6e6 commit 31ef225
Show file tree
Hide file tree
Showing 6 changed files with 74 additions and 277 deletions.
159 changes: 60 additions & 99 deletions sound/pci/hda/hda_jack.c
Original file line number Diff line number Diff line change
Expand Up @@ -90,15 +90,19 @@ snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid)
}
EXPORT_SYMBOL_HDA(snd_hda_jack_tbl_new);

#ifdef CONFIG_SND_HDA_INPUT_JACK
static void snd_hda_input_jack_free(struct hda_codec *codec);
#else
#define snd_hda_input_jack_free(codec)
#endif

void snd_hda_jack_tbl_clear(struct hda_codec *codec)
{
snd_hda_input_jack_free(codec);
#ifdef CONFIG_SND_HDA_INPUT_JACK
/* free jack instances manually when clearing/reconfiguring */
if (!codec->bus->shutdown && codec->jacktbl.list) {
struct hda_jack_tbl *jack = codec->jacktbl.list;
int i;
for (i = 0; i < codec->jacktbl.used; i++, jack++) {
if (jack->jack)
snd_device_free(codec->bus->card, jack->jack);
}
}
#endif
snd_array_free(&codec->jacktbl);
}

Expand Down Expand Up @@ -199,10 +203,44 @@ void snd_hda_jack_report_sync(struct hda_codec *codec)
continue;
state = get_jack_plug_state(jack->pin_sense);
snd_kctl_jack_report(codec->bus->card, jack->kctl, state);
#ifdef CONFIG_SND_HDA_INPUT_JACK
if (jack->jack)
snd_jack_report(jack->jack,
state ? jack->type : 0);
#endif
}
}
EXPORT_SYMBOL_HDA(snd_hda_jack_report_sync);

#ifdef CONFIG_SND_HDA_INPUT_JACK
/* guess the jack type from the pin-config */
static int get_input_jack_type(struct hda_codec *codec, hda_nid_t nid)
{
unsigned int def_conf = snd_hda_codec_get_pincfg(codec, nid);
switch (get_defcfg_device(def_conf)) {
case AC_JACK_LINE_OUT:
case AC_JACK_SPEAKER:
return SND_JACK_LINEOUT;
case AC_JACK_HP_OUT:
return SND_JACK_HEADPHONE;
case AC_JACK_SPDIF_OUT:
case AC_JACK_DIG_OTHER_OUT:
return SND_JACK_AVOUT;
case AC_JACK_MIC_IN:
return SND_JACK_MICROPHONE;
default:
return SND_JACK_LINEIN;
}
}

static void hda_free_jack_priv(struct snd_jack *jack)
{
struct hda_jack_tbl *jacks = jack->private_data;
jacks->nid = 0;
jacks->jack = NULL;
}
#endif

/**
* snd_hda_jack_add_kctl - Add a kctl for the given pin
*
Expand All @@ -214,6 +252,7 @@ int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
{
struct hda_jack_tbl *jack;
struct snd_kcontrol *kctl;
int err, state;

jack = snd_hda_jack_tbl_new(codec, nid);
if (!jack)
Expand All @@ -223,11 +262,21 @@ int snd_hda_jack_add_kctl(struct hda_codec *codec, hda_nid_t nid,
kctl = snd_kctl_jack_new(name, idx, codec);
if (!kctl)
return -ENOMEM;
if (snd_hda_ctl_add(codec, nid, kctl) < 0)
return -ENOMEM;
err = snd_hda_ctl_add(codec, nid, kctl);
if (err < 0)
return err;
jack->kctl = kctl;
snd_kctl_jack_report(codec->bus->card, kctl,
snd_hda_jack_detect(codec, nid));
state = snd_hda_jack_detect(codec, nid);
snd_kctl_jack_report(codec->bus->card, kctl, state);
#ifdef CONFIG_SND_HDA_INPUT_JACK
jack->type = get_input_jack_type(codec, nid);
err = snd_jack_new(codec->bus->card, name, jack->type, &jack->jack);
if (err < 0)
return err;
jack->jack->private_data = jack;
jack->jack->private_free = hda_free_jack_priv;
snd_jack_report(jack->jack, state ? jack->type : 0);
#endif
return 0;
}
EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctl);
Expand Down Expand Up @@ -302,91 +351,3 @@ int snd_hda_jack_add_kctls(struct hda_codec *codec,
return 0;
}
EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctls);

#ifdef CONFIG_SND_HDA_INPUT_JACK
/*
* Input-jack notification support
*/
static const char *get_jack_default_name(struct hda_codec *codec, hda_nid_t nid,
int type)
{
switch (type) {
case SND_JACK_HEADPHONE:
return "Headphone";
case SND_JACK_MICROPHONE:
return "Mic";
case SND_JACK_LINEOUT:
return "Line-out";
case SND_JACK_LINEIN:
return "Line-in";
case SND_JACK_HEADSET:
return "Headset";
case SND_JACK_VIDEOOUT:
return "HDMI/DP";
default:
return "Misc";
}
}

static void hda_free_jack_priv(struct snd_jack *jack)
{
struct hda_jack_tbl *jacks = jack->private_data;
jacks->nid = 0;
jacks->jack = NULL;
}

int snd_hda_input_jack_add(struct hda_codec *codec, hda_nid_t nid, int type,
const char *name)
{
struct hda_jack_tbl *jack = snd_hda_jack_tbl_new(codec, nid);
int err;

if (!jack)
return -ENOMEM;
if (!name)
name = get_jack_default_name(codec, nid, type);
err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
if (err < 0)
return err;
jack->type = type;
jack->jack->private_data = jack;
jack->jack->private_free = hda_free_jack_priv;
return 0;
}
EXPORT_SYMBOL_HDA(snd_hda_input_jack_add);

void snd_hda_input_jack_report(struct hda_codec *codec, hda_nid_t nid)
{
struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid);
unsigned int pin_ctl;
unsigned int present;
int type;

if (!jack || !jack->jack)
return;

present = snd_hda_jack_detect(codec, nid);
type = jack->type;
if (type == (SND_JACK_HEADPHONE | SND_JACK_LINEOUT)) {
pin_ctl = snd_hda_codec_read(codec, nid, 0,
AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
type = (pin_ctl & AC_PINCTL_HP_EN) ?
SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
}
snd_jack_report(jack->jack, present ? type : 0);
}
EXPORT_SYMBOL_HDA(snd_hda_input_jack_report);

/* free jack instances manually when clearing/reconfiguring */
static void snd_hda_input_jack_free(struct hda_codec *codec)
{
if (!codec->bus->shutdown && codec->jacktbl.list) {
struct hda_jack_tbl *jack = codec->jacktbl.list;
int i;
for (i = 0; i < codec->jacktbl.used; i++, jack++) {
if (jack->jack)
snd_device_free(codec->bus->card, jack->jack);
}
}
}
#endif /* CONFIG_SND_HDA_INPUT_JACK */
20 changes: 0 additions & 20 deletions sound/pci/hda/hda_local.h
Original file line number Diff line number Diff line change
Expand Up @@ -674,24 +674,4 @@ static inline void snd_hda_eld_proc_free(struct hda_codec *codec,
#define SND_PRINT_CHANNEL_ALLOCATION_ADVISED_BUFSIZE 80
void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);

/*
* Input-jack notification support
*/
#ifdef CONFIG_SND_HDA_INPUT_JACK
int snd_hda_input_jack_add(struct hda_codec *codec, hda_nid_t nid, int type,
const char *name);
void snd_hda_input_jack_report(struct hda_codec *codec, hda_nid_t nid);
#else /* CONFIG_SND_HDA_INPUT_JACK */
static inline int snd_hda_input_jack_add(struct hda_codec *codec,
hda_nid_t nid, int type,
const char *name)
{
return 0;
}
static inline void snd_hda_input_jack_report(struct hda_codec *codec,
hda_nid_t nid)
{
}
#endif /* CONFIG_SND_HDA_INPUT_JACK */

#endif /* __SOUND_HDA_LOCAL_H */
52 changes: 8 additions & 44 deletions sound/pci/hda/patch_conexant.c
Original file line number Diff line number Diff line change
Expand Up @@ -416,40 +416,6 @@ static int conexant_mux_enum_put(struct snd_kcontrol *kcontrol,
&spec->cur_mux[adc_idx]);
}

static int conexant_init_jacks(struct hda_codec *codec)
{
#ifdef CONFIG_SND_HDA_INPUT_JACK
struct conexant_spec *spec = codec->spec;
int i;

for (i = 0; i < spec->num_init_verbs; i++) {
const struct hda_verb *hv;

hv = spec->init_verbs[i];
while (hv->nid) {
int err = 0;
switch (hv->param ^ AC_USRSP_EN) {
case CONEXANT_HP_EVENT:
err = snd_hda_input_jack_add(codec, hv->nid,
SND_JACK_HEADPHONE, NULL);
snd_hda_input_jack_report(codec, hv->nid);
break;
case CXT5051_PORTC_EVENT:
case CONEXANT_MIC_EVENT:
err = snd_hda_input_jack_add(codec, hv->nid,
SND_JACK_MICROPHONE, NULL);
snd_hda_input_jack_report(codec, hv->nid);
break;
}
if (err < 0)
return err;
++hv;
}
}
#endif /* CONFIG_SND_HDA_INPUT_JACK */
return 0;
}

static void conexant_set_power(struct hda_codec *codec, hda_nid_t fg,
unsigned int power_state)
{
Expand Down Expand Up @@ -1750,7 +1716,6 @@ static void cxt5051_hp_automute(struct hda_codec *codec)
static void cxt5051_hp_unsol_event(struct hda_codec *codec,
unsigned int res)
{
int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;
switch (res >> 26) {
case CONEXANT_HP_EVENT:
cxt5051_hp_automute(codec);
Expand All @@ -1762,7 +1727,6 @@ static void cxt5051_hp_unsol_event(struct hda_codec *codec,
cxt5051_portc_automic(codec);
break;
}
snd_hda_input_jack_report(codec, nid);
}

static const struct snd_kcontrol_new cxt5051_playback_mixers[] = {
Expand Down Expand Up @@ -1901,8 +1865,6 @@ static void cxt5051_init_mic_port(struct hda_codec *codec, hda_nid_t nid,
snd_hda_codec_write(codec, nid, 0,
AC_VERB_SET_UNSOLICITED_ENABLE,
AC_USRSP_EN | event);
snd_hda_input_jack_add(codec, nid, SND_JACK_MICROPHONE, NULL);
snd_hda_input_jack_report(codec, nid);
}

static const struct hda_verb cxt5051_ideapad_init_verbs[] = {
Expand All @@ -1918,7 +1880,6 @@ static int cxt5051_init(struct hda_codec *codec)
struct conexant_spec *spec = codec->spec;

conexant_init(codec);
conexant_init_jacks(codec);

if (spec->auto_mic & AUTO_MIC_PORTB)
cxt5051_init_mic_port(codec, 0x17, CXT5051_PORTB_EVENT);
Expand Down Expand Up @@ -3450,7 +3411,6 @@ static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
hda_nid_t nid = pins[i];
if (!nid || !is_jack_detectable(codec, nid))
break;
snd_hda_input_jack_report(codec, nid);
present |= snd_hda_jack_detect(codec, nid);
}
return present;
Expand Down Expand Up @@ -3755,8 +3715,6 @@ static void cx_auto_automic(struct hda_codec *codec)

static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
{
int nid = (res & AC_UNSOL_RES_SUBTAG) >> 20;

switch (snd_hda_jack_get_action(codec, res >> 26)) {
case CONEXANT_HP_EVENT:
cx_auto_hp_automute(codec);
Expand All @@ -3766,7 +3724,6 @@ static void cx_auto_unsol_event(struct hda_codec *codec, unsigned int res)
break;
case CONEXANT_MIC_EVENT:
cx_auto_automic(codec);
snd_hda_input_jack_report(codec, nid);
break;
}
snd_hda_jack_report_sync(codec);
Expand Down Expand Up @@ -4325,6 +4282,7 @@ static int cx_auto_build_input_controls(struct hda_codec *codec)

static int cx_auto_build_controls(struct hda_codec *codec)
{
struct conexant_spec *spec = codec->spec;
int err;

err = cx_auto_build_output_controls(codec);
Expand All @@ -4333,7 +4291,13 @@ static int cx_auto_build_controls(struct hda_codec *codec)
err = cx_auto_build_input_controls(codec);
if (err < 0)
return err;
return conexant_build_controls(codec);
err = conexant_build_controls(codec);
if (err < 0)
return err;
err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
if (err < 0)
return err;
return 0;
}

static int cx_auto_search_adcs(struct hda_codec *codec)
Expand Down
22 changes: 6 additions & 16 deletions sound/pci/hda/patch_hdmi.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,8 +1005,6 @@ static void hdmi_present_sense(struct hdmi_spec_per_pin *per_pin, bool retry)
msecs_to_jiffies(300));
}
}

snd_hda_input_jack_report(codec, pin_nid);
}

static void hdmi_repoll_eld(struct work_struct *work)
Expand Down Expand Up @@ -1232,21 +1230,15 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec)

static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
{
int err;
char hdmi_str[32];
char hdmi_str[32] = "HDMI/DP";
struct hdmi_spec *spec = codec->spec;
struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
int pcmdev = spec->pcm_rec[pin_idx].device;

snprintf(hdmi_str, sizeof(hdmi_str), "HDMI/DP,pcm=%d", pcmdev);

err = snd_hda_input_jack_add(codec, per_pin->pin_nid,
SND_JACK_VIDEOOUT, pcmdev > 0 ? hdmi_str : NULL);
if (err < 0)
return err;
if (pcmdev > 0)
sprintf(hdmi_str + strlen(hdmi_str), ",pcm=%d", pcmdev);

hdmi_present_sense(per_pin, false);
return 0;
return snd_hda_jack_add_kctl(codec, per_pin->pin_nid, hdmi_str, 0);
}

static int generic_hdmi_build_controls(struct hda_codec *codec)
Expand Down Expand Up @@ -1276,10 +1268,8 @@ static int generic_hdmi_build_controls(struct hda_codec *codec)

if (err < 0)
return err;
err = snd_hda_jack_add_kctl(codec, per_pin->pin_nid,
"HDMI", pin_idx);
if (err < 0)
return err;

hdmi_present_sense(per_pin, false);
}

return 0;
Expand Down
Loading

0 comments on commit 31ef225

Please sign in to comment.