aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/patch_realtek.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2011-03-03 08:40:14 -0500
committerTakashi Iwai <tiwai@suse.de>2011-03-03 08:40:14 -0500
commitcd372fb3befde3bceef3fdcbc550dde50c894e36 (patch)
tree300fec172522d11408ccd8086f7789cdcd2a8509 /sound/pci/hda/patch_realtek.c
parentd207df2df064c19a2cf4eac8f887351fe5ce526e (diff)
ALSA: hda - Make common input-jack helper functions
Since multiple codec drivers already use the input-jack stuff, let's make common helper functions to reduce the duplicated codes. Signed-off-by: Takashi Iwai <tiwai@suse.de>
Diffstat (limited to 'sound/pci/hda/patch_realtek.c')
-rw-r--r--sound/pci/hda/patch_realtek.c94
1 files changed, 12 insertions, 82 deletions
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 96cb442dc1d..f6c344126b8 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -282,12 +282,6 @@ struct alc_mic_route {
282 unsigned char amix_idx; 282 unsigned char amix_idx;
283}; 283};
284 284
285struct alc_jack {
286 hda_nid_t nid;
287 int type;
288 struct snd_jack *jack;
289};
290
291#define MUX_IDX_UNDEF ((unsigned char)-1) 285#define MUX_IDX_UNDEF ((unsigned char)-1)
292 286
293struct alc_customize_define { 287struct alc_customize_define {
@@ -366,9 +360,6 @@ struct alc_spec {
366 /* PCM information */ 360 /* PCM information */
367 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */ 361 struct hda_pcm pcm_rec[3]; /* used in alc_build_pcms() */
368 362
369 /* jack detection */
370 struct snd_array jacks;
371
372 /* dynamic controls, init_verbs and input_mux */ 363 /* dynamic controls, init_verbs and input_mux */
373 struct auto_pin_cfg autocfg; 364 struct auto_pin_cfg autocfg;
374 struct alc_customize_define cdefine; 365 struct alc_customize_define cdefine;
@@ -1032,94 +1023,32 @@ static void alc_fix_pll_init(struct hda_codec *codec, hda_nid_t nid,
1032 alc_fix_pll(codec); 1023 alc_fix_pll(codec);
1033} 1024}
1034 1025
1035#ifdef CONFIG_SND_HDA_INPUT_JACK
1036static void alc_free_jack_priv(struct snd_jack *jack)
1037{
1038 struct alc_jack *jacks = jack->private_data;
1039 jacks->nid = 0;
1040 jacks->jack = NULL;
1041}
1042
1043static int alc_add_jack(struct hda_codec *codec,
1044 hda_nid_t nid, int type)
1045{
1046 struct alc_spec *spec;
1047 struct alc_jack *jack;
1048 const char *name;
1049 int err;
1050
1051 spec = codec->spec;
1052 snd_array_init(&spec->jacks, sizeof(*jack), 32);
1053 jack = snd_array_new(&spec->jacks);
1054 if (!jack)
1055 return -ENOMEM;
1056
1057 jack->nid = nid;
1058 jack->type = type;
1059 name = (type == SND_JACK_HEADPHONE) ? "Headphone" : "Mic" ;
1060
1061 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
1062 if (err < 0)
1063 return err;
1064 jack->jack->private_data = jack;
1065 jack->jack->private_free = alc_free_jack_priv;
1066 return 0;
1067}
1068
1069static void alc_report_jack(struct hda_codec *codec, hda_nid_t nid)
1070{
1071 struct alc_spec *spec = codec->spec;
1072 struct alc_jack *jacks = spec->jacks.list;
1073
1074 if (jacks) {
1075 int i;
1076 for (i = 0; i < spec->jacks.used; i++) {
1077 if (jacks->nid == nid) {
1078 unsigned int present;
1079 present = snd_hda_jack_detect(codec, nid);
1080
1081 present = (present) ? jacks->type : 0;
1082
1083 snd_jack_report(jacks->jack, present);
1084 }
1085 jacks++;
1086 }
1087 }
1088}
1089
1090static int alc_init_jacks(struct hda_codec *codec) 1026static int alc_init_jacks(struct hda_codec *codec)
1091{ 1027{
1028#ifdef CONFIG_SND_HDA_INPUT_JACK
1092 struct alc_spec *spec = codec->spec; 1029 struct alc_spec *spec = codec->spec;
1093 int err; 1030 int err;
1094 unsigned int hp_nid = spec->autocfg.hp_pins[0]; 1031 unsigned int hp_nid = spec->autocfg.hp_pins[0];
1095 unsigned int mic_nid = spec->ext_mic.pin; 1032 unsigned int mic_nid = spec->ext_mic.pin;
1096 1033
1097 if (hp_nid) { 1034 if (hp_nid) {
1098 err = alc_add_jack(codec, hp_nid, SND_JACK_HEADPHONE); 1035 err = snd_hda_input_jack_add(codec, hp_nid,
1036 SND_JACK_HEADPHONE, NULL);
1099 if (err < 0) 1037 if (err < 0)
1100 return err; 1038 return err;
1101 alc_report_jack(codec, hp_nid); 1039 snd_hda_input_jack_report(codec, hp_nid);
1102 } 1040 }
1103 1041
1104 if (mic_nid) { 1042 if (mic_nid) {
1105 err = alc_add_jack(codec, mic_nid, SND_JACK_MICROPHONE); 1043 err = snd_hda_input_jack_add(codec, mic_nid,
1044 SND_JACK_MICROPHONE, NULL);
1106 if (err < 0) 1045 if (err < 0)
1107 return err; 1046 return err;
1108 alc_report_jack(codec, mic_nid); 1047 snd_hda_input_jack_report(codec, mic_nid);
1109 } 1048 }
1110 1049#endif /* CONFIG_SND_HDA_INPUT_JACK */
1111 return 0;
1112}
1113#else
1114static inline void alc_report_jack(struct hda_codec *codec, hda_nid_t nid)
1115{
1116}
1117
1118static inline int alc_init_jacks(struct hda_codec *codec)
1119{
1120 return 0; 1050 return 0;
1121} 1051}
1122#endif
1123 1052
1124static void alc_automute_speaker(struct hda_codec *codec, int pinctl) 1053static void alc_automute_speaker(struct hda_codec *codec, int pinctl)
1125{ 1054{
@@ -1133,7 +1062,7 @@ static void alc_automute_speaker(struct hda_codec *codec, int pinctl)
1133 nid = spec->autocfg.hp_pins[i]; 1062 nid = spec->autocfg.hp_pins[i];
1134 if (!nid) 1063 if (!nid)
1135 break; 1064 break;
1136 alc_report_jack(codec, nid); 1065 snd_hda_input_jack_report(codec, nid);
1137 spec->jack_present |= snd_hda_jack_detect(codec, nid); 1066 spec->jack_present |= snd_hda_jack_detect(codec, nid);
1138 } 1067 }
1139 1068
@@ -1240,7 +1169,7 @@ static void alc_mic_automute(struct hda_codec *codec)
1240 AC_VERB_SET_CONNECT_SEL, 1169 AC_VERB_SET_CONNECT_SEL,
1241 alive->mux_idx); 1170 alive->mux_idx);
1242 } 1171 }
1243 alc_report_jack(codec, spec->ext_mic.pin); 1172 snd_hda_input_jack_report(codec, spec->ext_mic.pin);
1244 1173
1245 /* FIXME: analog mixer */ 1174 /* FIXME: analog mixer */
1246} 1175}
@@ -4283,6 +4212,7 @@ static void alc_free(struct hda_codec *codec)
4283 return; 4212 return;
4284 4213
4285 alc_shutup(codec); 4214 alc_shutup(codec);
4215 snd_hda_input_jack_free(codec);
4286 alc_free_kctls(codec); 4216 alc_free_kctls(codec);
4287 kfree(spec); 4217 kfree(spec);
4288 snd_hda_detach_beep_device(codec); 4218 snd_hda_detach_beep_device(codec);
@@ -14494,7 +14424,7 @@ static void alc269_speaker_automute(struct hda_codec *codec)
14494 HDA_AMP_MUTE, bits); 14424 HDA_AMP_MUTE, bits);
14495 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1, 14425 snd_hda_codec_amp_stereo(codec, 0x0c, HDA_INPUT, 1,
14496 HDA_AMP_MUTE, bits); 14426 HDA_AMP_MUTE, bits);
14497 alc_report_jack(codec, nid); 14427 snd_hda_input_jack_report(codec, nid);
14498} 14428}
14499 14429
14500/* unsolicited event for HP jack sensing */ 14430/* unsolicited event for HP jack sensing */