Comment 52 for bug 893210

Revision history for this message
Raymond (superquad-vortex2) wrote :

diff --git a/include/sound/ac97_codec.h b/include/sound/ac97_codec.h
index 0e9d75b..9e659e2 100644
--- a/include/sound/ac97_codec.h
+++ b/include/sound/ac97_codec.h
@@ -31,6 +31,7 @@
 #include <sound/pcm.h>
 #include <sound/control.h>
 #include <sound/info.h>
+#include <sound/jack.h>

 /* maximum number of devices on the AC97 bus */
 #define AC97_BUS_MAX_DEVICES 4
@@ -531,6 +532,10 @@ struct snd_ac97 {
  struct device dev;

  struct snd_pcm_chmap *chmaps[2]; /* channel-maps (optional) */
+
+ struct snd_jack *hp_jack;
+ struct snd_jack *lo_jack;
+ struct snd_jack *sp_jack;
 };

 #define to_ac97_t(d) container_of(d, struct snd_ac97, dev)
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index f4234ed..581000c 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -1886,6 +1886,23 @@ static int patch_ad1981a(struct snd_ac97 *ac97)
 static const struct snd_kcontrol_new snd_ac97_ad198x_2cmic =
 AC97_SINGLE("Stereo Mic", AC97_AD_MISC, 6, 1, 0);

+#define AD198X_JS1_ST 0x08
+#define AD198X_JS0_ST 0x04
+
+void ad198x_handle_hp_jack(struct snd_ac97 *ac97)
+{
+ bool hp_plugged = (snd_ac97_read(ac97, AC97_AD_JACK_SPDIF) &
+ AD198X_JS1_ST) == AD198X_JS1_ST;
+ snd_jack_report(ac97->hp_jack, hp_plugged ? SND_JACK_HEADPHONE : 0);
+}
+
+void ad198x_handle_lo_jack(struct snd_ac97 *ac97)
+{
+ bool lo_plugged = (snd_ac97_read(ac97, AC97_AD_JACK_SPDIF) &
+ AD198X_JS0_ST) == AD198X_JS0_ST;
+ snd_jack_report(ac97->lo_jack, lo_plugged ? SND_JACK_LINEOUT : 0);
+}
+
 static int patch_ad1981b_specific(struct snd_ac97 *ac97)
 {
  int err;
@@ -1894,8 +1911,23 @@ static int patch_ad1981b_specific(struct snd_ac97 *ac97)
   return err;
  if (check_list(ac97, ad1981_jacks_blacklist))
   return 0;
- return patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
+ err = patch_build_controls(ac97, snd_ac97_ad1981x_jack_sense,
         ARRAY_SIZE(snd_ac97_ad1981x_jack_sense));
+ if (err < 0)
+ return err;
+ if (( err = snd_jack_new(ac97->bus->card, "Headphone", SND_JACK_HEADPHONE,
+ &ac97->hp_jack, true, false)) < 0)
+ return err;
+ ad198x_handle_hp_jack(ac97);
+ if (( err = snd_jack_new(ac97->bus->card, "Line Out", SND_JACK_LINEOUT,
+ &ac97->lo_jack, true, false)) < 0)
+ return err;
+ ad198x_handle_lo_jack(ac97);
+ if (( err = snd_jack_new(ac97->bus->card, "Internal Speaker", SND_JACK_LINEOUT,
+ &ac97->sp_jack, true, true)) < 0)
+ return err;
+ snd_jack_report(ac97->sp_jack, SND_JACK_LINEOUT);
+ return 0;
 }

 static const struct snd_ac97_build_ops patch_ad1981b_build_ops = {