aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2011-11-02 03:54:51 -0400
committerTakashi Iwai <tiwai@suse.de>2011-11-16 05:14:04 -0500
commitaad37dbd563010252e1bedb6dad6cddb867b9235 (patch)
tree4417a480e21dcd2f6bbbd6f6ff3b20fb10364f9b
parent35be544af367170a9c6bf63adcf9d0cb2d569dbb (diff)
ALSA: hda - Merge input-jack helpers to hda_jack.c
We can use the very same table in hda_jack.c for managing the list for input-jack elements, too. Signed-off-by: Takashi Iwai <tiwai@suse.de>
-rw-r--r--sound/pci/hda/hda_codec.c108
-rw-r--r--sound/pci/hda/hda_jack.c97
-rw-r--r--sound/pci/hda/hda_jack.h4
-rw-r--r--sound/pci/hda/hda_local.h4
-rw-r--r--sound/pci/hda/patch_conexant.c1
-rw-r--r--sound/pci/hda/patch_hdmi.c1
-rw-r--r--sound/pci/hda/patch_realtek.c1
-rw-r--r--sound/pci/hda/patch_sigmatel.c1
8 files changed, 100 insertions, 117 deletions
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 8217ff7ff7b5..e57698f611ab 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -5275,113 +5275,5 @@ void snd_print_pcm_bits(int pcm, char *buf, int buflen)
5275} 5275}
5276EXPORT_SYMBOL_HDA(snd_print_pcm_bits); 5276EXPORT_SYMBOL_HDA(snd_print_pcm_bits);
5277 5277
5278#ifdef CONFIG_SND_HDA_INPUT_JACK
5279/*
5280 * Input-jack notification support
5281 */
5282struct hda_jack_item {
5283 hda_nid_t nid;
5284 int type;
5285 struct snd_jack *jack;
5286};
5287
5288static const char *get_jack_default_name(struct hda_codec *codec, hda_nid_t nid,
5289 int type)
5290{
5291 switch (type) {
5292 case SND_JACK_HEADPHONE:
5293 return "Headphone";
5294 case SND_JACK_MICROPHONE:
5295 return "Mic";
5296 case SND_JACK_LINEOUT:
5297 return "Line-out";
5298 case SND_JACK_LINEIN:
5299 return "Line-in";
5300 case SND_JACK_HEADSET:
5301 return "Headset";
5302 case SND_JACK_VIDEOOUT:
5303 return "HDMI/DP";
5304 default:
5305 return "Misc";
5306 }
5307}
5308
5309static void hda_free_jack_priv(struct snd_jack *jack)
5310{
5311 struct hda_jack_item *jacks = jack->private_data;
5312 jacks->nid = 0;
5313 jacks->jack = NULL;
5314}
5315
5316int snd_hda_input_jack_add(struct hda_codec *codec, hda_nid_t nid, int type,
5317 const char *name)
5318{
5319 struct hda_jack_item *jack;
5320 int err;
5321
5322 snd_array_init(&codec->jacks, sizeof(*jack), 32);
5323 jack = snd_array_new(&codec->jacks);
5324 if (!jack)
5325 return -ENOMEM;
5326
5327 jack->nid = nid;
5328 jack->type = type;
5329 if (!name)
5330 name = get_jack_default_name(codec, nid, type);
5331 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
5332 if (err < 0) {
5333 jack->nid = 0;
5334 return err;
5335 }
5336 jack->jack->private_data = jack;
5337 jack->jack->private_free = hda_free_jack_priv;
5338 return 0;
5339}
5340EXPORT_SYMBOL_HDA(snd_hda_input_jack_add);
5341
5342void snd_hda_input_jack_report(struct hda_codec *codec, hda_nid_t nid)
5343{
5344 struct hda_jack_item *jacks = codec->jacks.list;
5345 int i;
5346
5347 if (!jacks)
5348 return;
5349
5350 for (i = 0; i < codec->jacks.used; i++, jacks++) {
5351 unsigned int pin_ctl;
5352 unsigned int present;
5353 int type;
5354
5355 if (jacks->nid != nid)
5356 continue;
5357 present = snd_hda_jack_detect(codec, nid);
5358 type = jacks->type;
5359 if (type == (SND_JACK_HEADPHONE | SND_JACK_LINEOUT)) {
5360 pin_ctl = snd_hda_codec_read(codec, nid, 0,
5361 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
5362 type = (pin_ctl & AC_PINCTL_HP_EN) ?
5363 SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
5364 }
5365 snd_jack_report(jacks->jack, present ? type : 0);
5366 }
5367}
5368EXPORT_SYMBOL_HDA(snd_hda_input_jack_report);
5369
5370/* free jack instances manually when clearing/reconfiguring */
5371void snd_hda_input_jack_free(struct hda_codec *codec)
5372{
5373 if (!codec->bus->shutdown && codec->jacks.list) {
5374 struct hda_jack_item *jacks = codec->jacks.list;
5375 int i;
5376 for (i = 0; i < codec->jacks.used; i++, jacks++) {
5377 if (jacks->jack)
5378 snd_device_free(codec->bus->card, jacks->jack);
5379 }
5380 }
5381 snd_array_free(&codec->jacks);
5382}
5383EXPORT_SYMBOL_HDA(snd_hda_input_jack_free);
5384#endif /* CONFIG_SND_HDA_INPUT_JACK */
5385
5386MODULE_DESCRIPTION("HDA codec core"); 5278MODULE_DESCRIPTION("HDA codec core");
5387MODULE_LICENSE("GPL"); 5279MODULE_LICENSE("GPL");
diff --git a/sound/pci/hda/hda_jack.c b/sound/pci/hda/hda_jack.c
index a2ab52b27265..1389958b201d 100644
--- a/sound/pci/hda/hda_jack.c
+++ b/sound/pci/hda/hda_jack.c
@@ -13,6 +13,7 @@
13#include <linux/slab.h> 13#include <linux/slab.h>
14#include <sound/core.h> 14#include <sound/core.h>
15#include <sound/control.h> 15#include <sound/control.h>
16#include <sound/jack.h>
16#include "hda_codec.h" 17#include "hda_codec.h"
17#include "hda_local.h" 18#include "hda_local.h"
18#include "hda_jack.h" 19#include "hda_jack.h"
@@ -87,8 +88,15 @@ snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid)
87 return jack; 88 return jack;
88} 89}
89 90
91#ifdef CONFIG_SND_HDA_INPUT_JACK
92static void snd_hda_input_jack_free(struct hda_codec *codec);
93#else
94#define snd_hda_input_jack_free(codec)
95#endif
96
90void snd_hda_jack_tbl_clear(struct hda_codec *codec) 97void snd_hda_jack_tbl_clear(struct hda_codec *codec)
91{ 98{
99 snd_hda_input_jack_free(codec);
92 snd_array_free(&codec->jacktbl); 100 snd_array_free(&codec->jacktbl);
93} 101}
94 102
@@ -186,7 +194,7 @@ void snd_hda_jack_report_sync(struct hda_codec *codec)
186 if (jack->nid) { 194 if (jack->nid) {
187 jack_detect_update(codec, jack); 195 jack_detect_update(codec, jack);
188 state = get_jack_plug_state(jack->pin_sense); 196 state = get_jack_plug_state(jack->pin_sense);
189 snd_kctl_jack_notify(codec->bus->card, jack->kctl, state); 197 snd_kctl_jack_report(codec->bus->card, jack->kctl, state);
190 } 198 }
191} 199}
192EXPORT_SYMBOL_HDA(snd_hda_jack_report_sync); 200EXPORT_SYMBOL_HDA(snd_hda_jack_report_sync);
@@ -287,3 +295,90 @@ int snd_hda_jack_add_kctls(struct hda_codec *codec,
287 return 0; 295 return 0;
288} 296}
289EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctls); 297EXPORT_SYMBOL_HDA(snd_hda_jack_add_kctls);
298
299#ifdef CONFIG_SND_HDA_INPUT_JACK
300/*
301 * Input-jack notification support
302 */
303static const char *get_jack_default_name(struct hda_codec *codec, hda_nid_t nid,
304 int type)
305{
306 switch (type) {
307 case SND_JACK_HEADPHONE:
308 return "Headphone";
309 case SND_JACK_MICROPHONE:
310 return "Mic";
311 case SND_JACK_LINEOUT:
312 return "Line-out";
313 case SND_JACK_LINEIN:
314 return "Line-in";
315 case SND_JACK_HEADSET:
316 return "Headset";
317 case SND_JACK_VIDEOOUT:
318 return "HDMI/DP";
319 default:
320 return "Misc";
321 }
322}
323
324static void hda_free_jack_priv(struct snd_jack *jack)
325{
326 struct hda_jack_tbl *jacks = jack->private_data;
327 jacks->nid = 0;
328 jacks->jack = NULL;
329}
330
331int snd_hda_input_jack_add(struct hda_codec *codec, hda_nid_t nid, int type,
332 const char *name)
333{
334 struct hda_jack_tbl *jack = snd_hda_jack_tbl_new(codec, nid);
335 int err;
336
337 if (!jack)
338 return -ENOMEM;
339 if (!name)
340 name = get_jack_default_name(codec, nid, type);
341 err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
342 if (err < 0)
343 return err;
344 jack->jack->private_data = jack;
345 jack->jack->private_free = hda_free_jack_priv;
346 return 0;
347}
348EXPORT_SYMBOL_HDA(snd_hda_input_jack_add);
349
350void snd_hda_input_jack_report(struct hda_codec *codec, hda_nid_t nid)
351{
352 struct hda_jack_tbl *jack = snd_hda_jack_tbl_get(codec, nid);
353 unsigned int pin_ctl;
354 unsigned int present;
355 int type;
356
357 if (!jack)
358 return;
359
360 present = snd_hda_jack_detect(codec, nid);
361 type = jack->type;
362 if (type == (SND_JACK_HEADPHONE | SND_JACK_LINEOUT)) {
363 pin_ctl = snd_hda_codec_read(codec, nid, 0,
364 AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
365 type = (pin_ctl & AC_PINCTL_HP_EN) ?
366 SND_JACK_HEADPHONE : SND_JACK_LINEOUT;
367 }
368 snd_jack_report(jack->jack, present ? type : 0);
369}
370EXPORT_SYMBOL_HDA(snd_hda_input_jack_report);
371
372/* free jack instances manually when clearing/reconfiguring */
373static void snd_hda_input_jack_free(struct hda_codec *codec)
374{
375 if (!codec->bus->shutdown && codec->jacktbl.list) {
376 struct hda_jack_tbl *jack = codec->jacktbl.list;
377 int i;
378 for (i = 0; i < codec->jacktbl.used; i++, jack++) {
379 if (jack->jack)
380 snd_device_free(codec->bus->card, jack->jack);
381 }
382 }
383}
384#endif /* CONFIG_SND_HDA_INPUT_JACK */
diff --git a/sound/pci/hda/hda_jack.h b/sound/pci/hda/hda_jack.h
index 4bb75ee16b56..f8f97c71c9c1 100644
--- a/sound/pci/hda/hda_jack.h
+++ b/sound/pci/hda/hda_jack.h
@@ -22,6 +22,10 @@ struct hda_jack_tbl {
22 unsigned int jack_detect:1; /* capable of jack-detection? */ 22 unsigned int jack_detect:1; /* capable of jack-detection? */
23 unsigned int jack_dirty:1; /* needs to update? */ 23 unsigned int jack_dirty:1; /* needs to update? */
24 struct snd_kcontrol *kctl; /* assigned kctl for jack-detection */ 24 struct snd_kcontrol *kctl; /* assigned kctl for jack-detection */
25#ifdef CONFIG_SND_HDA_INPUT_JACK
26 int type;
27 struct snd_jack *jack;
28#endif
25}; 29};
26 30
27struct hda_jack_tbl * 31struct hda_jack_tbl *
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 08e88b826d27..13f681480a38 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -680,7 +680,6 @@ void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
680int snd_hda_input_jack_add(struct hda_codec *codec, hda_nid_t nid, int type, 680int snd_hda_input_jack_add(struct hda_codec *codec, hda_nid_t nid, int type,
681 const char *name); 681 const char *name);
682void snd_hda_input_jack_report(struct hda_codec *codec, hda_nid_t nid); 682void snd_hda_input_jack_report(struct hda_codec *codec, hda_nid_t nid);
683void snd_hda_input_jack_free(struct hda_codec *codec);
684#else /* CONFIG_SND_HDA_INPUT_JACK */ 683#else /* CONFIG_SND_HDA_INPUT_JACK */
685static inline int snd_hda_input_jack_add(struct hda_codec *codec, 684static inline int snd_hda_input_jack_add(struct hda_codec *codec,
686 hda_nid_t nid, int type, 685 hda_nid_t nid, int type,
@@ -692,9 +691,6 @@ static inline void snd_hda_input_jack_report(struct hda_codec *codec,
692 hda_nid_t nid) 691 hda_nid_t nid)
693{ 692{
694} 693}
695static inline void snd_hda_input_jack_free(struct hda_codec *codec)
696{
697}
698#endif /* CONFIG_SND_HDA_INPUT_JACK */ 694#endif /* CONFIG_SND_HDA_INPUT_JACK */
699 695
700#endif /* __SOUND_HDA_LOCAL_H */ 696#endif /* __SOUND_HDA_LOCAL_H */
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 40bd75b293ba..ae9c028d8254 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -475,7 +475,6 @@ static int conexant_init(struct hda_codec *codec)
475 475
476static void conexant_free(struct hda_codec *codec) 476static void conexant_free(struct hda_codec *codec)
477{ 477{
478 snd_hda_input_jack_free(codec);
479 snd_hda_detach_beep_device(codec); 478 snd_hda_detach_beep_device(codec);
480 kfree(codec->spec); 479 kfree(codec->spec);
481} 480}
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index ea30bf4a4f50..bb8cfc68cd73 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -1318,7 +1318,6 @@ static void generic_hdmi_free(struct hda_codec *codec)
1318 cancel_delayed_work(&per_pin->work); 1318 cancel_delayed_work(&per_pin->work);
1319 snd_hda_eld_proc_free(codec, eld); 1319 snd_hda_eld_proc_free(codec, eld);
1320 } 1320 }
1321 snd_hda_input_jack_free(codec);
1322 1321
1323 flush_workqueue(codec->bus->workq); 1322 flush_workqueue(codec->bus->workq);
1324 kfree(spec); 1323 kfree(spec);
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index 9a90cdac78f4..933c8cf23b27 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -2474,7 +2474,6 @@ static void alc_free(struct hda_codec *codec)
2474 return; 2474 return;
2475 2475
2476 alc_shutup(codec); 2476 alc_shutup(codec);
2477 snd_hda_input_jack_free(codec);
2478 alc_free_kctls(codec); 2477 alc_free_kctls(codec);
2479 alc_free_bind_ctls(codec); 2478 alc_free_bind_ctls(codec);
2480 kfree(spec); 2479 kfree(spec);
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index dd6569ffcff8..73bf7cd0a6e4 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -4489,7 +4489,6 @@ static void stac92xx_free(struct hda_codec *codec)
4489 return; 4489 return;
4490 4490
4491 stac92xx_shutup(codec); 4491 stac92xx_shutup(codec);
4492 snd_hda_input_jack_free(codec);
4493 4492
4494 kfree(spec); 4493 kfree(spec);
4495 snd_hda_detach_beep_device(codec); 4494 snd_hda_detach_beep_device(codec);