ALSA: hda - Merge input-jack helpers to hda_jack.c
authorTakashi Iwai <tiwai@suse.de>
Wed, 2 Nov 2011 07:54:51 +0000 (08:54 +0100)
committerTakashi Iwai <tiwai@suse.de>
Wed, 16 Nov 2011 10:14:04 +0000 (11:14 +0100)
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>
sound/pci/hda/hda_codec.c
sound/pci/hda/hda_jack.c
sound/pci/hda/hda_jack.h
sound/pci/hda/hda_local.h
sound/pci/hda/patch_conexant.c
sound/pci/hda/patch_hdmi.c
sound/pci/hda/patch_realtek.c
sound/pci/hda/patch_sigmatel.c

index 8217ff7ff7b58755bfaf96147f7ff38d30fc2181..e57698f611aba854a89771d893e68604deb1ed4b 100644 (file)
@@ -5275,113 +5275,5 @@ void snd_print_pcm_bits(int pcm, char *buf, int buflen)
 }
 EXPORT_SYMBOL_HDA(snd_print_pcm_bits);
 
-#ifdef CONFIG_SND_HDA_INPUT_JACK
-/*
- * Input-jack notification support
- */
-struct hda_jack_item {
-       hda_nid_t nid;
-       int type;
-       struct snd_jack *jack;
-};
-
-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_item *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_item *jack;
-       int err;
-
-       snd_array_init(&codec->jacks, sizeof(*jack), 32);
-       jack = snd_array_new(&codec->jacks);
-       if (!jack)
-               return -ENOMEM;
-
-       jack->nid = nid;
-       jack->type = type;
-       if (!name)
-               name = get_jack_default_name(codec, nid, type);
-       err = snd_jack_new(codec->bus->card, name, type, &jack->jack);
-       if (err < 0) {
-               jack->nid = 0;
-               return err;
-       }
-       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_item *jacks = codec->jacks.list;
-       int i;
-
-       if (!jacks)
-               return;
-
-       for (i = 0; i < codec->jacks.used; i++, jacks++) {
-               unsigned int pin_ctl;
-               unsigned int present;
-               int type;
-
-               if (jacks->nid != nid)
-                       continue;
-               present = snd_hda_jack_detect(codec, nid);
-               type = jacks->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(jacks->jack, present ? type : 0);
-       }
-}
-EXPORT_SYMBOL_HDA(snd_hda_input_jack_report);
-
-/* free jack instances manually when clearing/reconfiguring */
-void snd_hda_input_jack_free(struct hda_codec *codec)
-{
-       if (!codec->bus->shutdown && codec->jacks.list) {
-               struct hda_jack_item *jacks = codec->jacks.list;
-               int i;
-               for (i = 0; i < codec->jacks.used; i++, jacks++) {
-                       if (jacks->jack)
-                               snd_device_free(codec->bus->card, jacks->jack);
-               }
-       }
-       snd_array_free(&codec->jacks);
-}
-EXPORT_SYMBOL_HDA(snd_hda_input_jack_free);
-#endif /* CONFIG_SND_HDA_INPUT_JACK */
-
 MODULE_DESCRIPTION("HDA codec core");
 MODULE_LICENSE("GPL");
index a2ab52b2726596e1ab500b47b1469409a3761eeb..1389958b201d1f20bde2fe94000c86219f52c72c 100644 (file)
@@ -13,6 +13,7 @@
 #include <linux/slab.h>
 #include <sound/core.h>
 #include <sound/control.h>
+#include <sound/jack.h>
 #include "hda_codec.h"
 #include "hda_local.h"
 #include "hda_jack.h"
@@ -87,8 +88,15 @@ snd_hda_jack_tbl_new(struct hda_codec *codec, hda_nid_t nid)
        return jack;
 }
 
+#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);
        snd_array_free(&codec->jacktbl);
 }
 
@@ -186,7 +194,7 @@ void snd_hda_jack_report_sync(struct hda_codec *codec)
                if (jack->nid) {
                        jack_detect_update(codec, jack);
                        state = get_jack_plug_state(jack->pin_sense);
-                       snd_kctl_jack_notify(codec->bus->card, jack->kctl, state);
+                       snd_kctl_jack_report(codec->bus->card, jack->kctl, state);
                }
 }
 EXPORT_SYMBOL_HDA(snd_hda_jack_report_sync);
@@ -287,3 +295,90 @@ 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->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)
+               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 */
index 4bb75ee16b56ef8746b7ee6c4686d824a5c774c2..f8f97c71c9c1a05fc8016187228f77aca71256d7 100644 (file)
@@ -22,6 +22,10 @@ struct hda_jack_tbl {
        unsigned int jack_detect:1;     /* capable of jack-detection? */
        unsigned int jack_dirty:1;      /* needs to update? */
        struct snd_kcontrol *kctl;      /* assigned kctl for jack-detection */
+#ifdef CONFIG_SND_HDA_INPUT_JACK
+       int type;
+       struct snd_jack *jack;
+#endif
 };
 
 struct hda_jack_tbl *
index 08e88b826d271b93d381bb1dfa8b72ea8e562f43..13f681480a3837a17e064da29865efedde78d479 100644 (file)
@@ -680,7 +680,6 @@ void snd_print_channel_allocation(int spk_alloc, char *buf, int buflen);
 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);
-void snd_hda_input_jack_free(struct hda_codec *codec);
 #else /* CONFIG_SND_HDA_INPUT_JACK */
 static inline int snd_hda_input_jack_add(struct hda_codec *codec,
                                         hda_nid_t nid, int type,
@@ -692,9 +691,6 @@ static inline void snd_hda_input_jack_report(struct hda_codec *codec,
                                             hda_nid_t nid)
 {
 }
-static inline void snd_hda_input_jack_free(struct hda_codec *codec)
-{
-}
 #endif /* CONFIG_SND_HDA_INPUT_JACK */
 
 #endif /* __SOUND_HDA_LOCAL_H */
index 40bd75b293bab7de83ff9c86c8fde43cff59da99..ae9c028d8254e7127e6962445e3a76a7edfece1a 100644 (file)
@@ -475,7 +475,6 @@ static int conexant_init(struct hda_codec *codec)
 
 static void conexant_free(struct hda_codec *codec)
 {
-       snd_hda_input_jack_free(codec);
        snd_hda_detach_beep_device(codec);
        kfree(codec->spec);
 }
index ea30bf4a4f50ac15936419a3177f2ceaf9d497b9..bb8cfc68cd73235ce45830fd9236c923f4f3812d 100644 (file)
@@ -1318,7 +1318,6 @@ static void generic_hdmi_free(struct hda_codec *codec)
                cancel_delayed_work(&per_pin->work);
                snd_hda_eld_proc_free(codec, eld);
        }
-       snd_hda_input_jack_free(codec);
 
        flush_workqueue(codec->bus->workq);
        kfree(spec);
index 9a90cdac78f48db70844a662133256c6dd2e1585..933c8cf23b270cc5881fec1adb4c2a6ad2d475d0 100644 (file)
@@ -2474,7 +2474,6 @@ static void alc_free(struct hda_codec *codec)
                return;
 
        alc_shutup(codec);
-       snd_hda_input_jack_free(codec);
        alc_free_kctls(codec);
        alc_free_bind_ctls(codec);
        kfree(spec);
index dd6569ffcff8d8d305a4cf0c8600ac4cfc2ef5d3..73bf7cd0a6e4266f73582618e68676e15f0a64f2 100644 (file)
@@ -4489,7 +4489,6 @@ static void stac92xx_free(struct hda_codec *codec)
                return;
 
        stac92xx_shutup(codec);
-       snd_hda_input_jack_free(codec);
 
        kfree(spec);
        snd_hda_detach_beep_device(codec);