linux 2.6.16.38 w/ vs2.0.3-rc1
[linux-2.6.git] / sound / pci / hda / patch_sigmatel.c
index d862295..35c2823 100644 (file)
@@ -51,7 +51,6 @@ struct sigmatel_spec {
        unsigned int line_switch: 1;
        unsigned int mic_switch: 1;
        unsigned int alt_switch: 1;
-       unsigned int hp_detect: 1;
 
        /* playback */
        struct hda_multi_out multiout;
@@ -304,15 +303,6 @@ static struct hda_board_config stac922x_cfg_tbl[] = {
          .pci_subdevice = 0x0101,
          .config = STAC_D945GTP3 },    /* Intel D945GTP - 3 Stack */
        { .pci_subvendor = PCI_VENDOR_ID_INTEL,
-         .pci_subdevice = 0x0202,
-         .config = STAC_D945GTP3 },    /* Intel D945GNT - 3 Stack, 9221 A1 */
-       { .pci_subvendor = PCI_VENDOR_ID_INTEL,
-         .pci_subdevice = 0x0b0b,
-         .config = STAC_D945GTP3 },    /* Intel D945PSN - 3 Stack, 9221 A1 */
-       { .pci_subvendor = PCI_VENDOR_ID_INTEL,
-         .pci_subdevice = 0x0707,
-         .config = STAC_D945GTP5 },    /* Intel D945PSV - 5 Stack */
-       { .pci_subvendor = PCI_VENDOR_ID_INTEL,
          .pci_subdevice = 0x0404,
          .config = STAC_D945GTP5 },    /* Intel D945GTP - 5 Stack */
        { .pci_subvendor = PCI_VENDOR_ID_INTEL,
@@ -537,22 +527,6 @@ static int stac92xx_build_pcms(struct hda_codec *codec)
        return 0;
 }
 
-static unsigned int stac92xx_get_vref(struct hda_codec *codec, hda_nid_t nid)
-{
-       unsigned int pincap = snd_hda_param_read(codec, nid,
-                                                AC_PAR_PIN_CAP);
-       pincap = (pincap & AC_PINCAP_VREF) >> AC_PINCAP_VREF_SHIFT;
-       if (pincap & AC_PINCAP_VREF_100)
-               return AC_PINCTL_VREF_100;
-       if (pincap & AC_PINCAP_VREF_80)
-               return AC_PINCTL_VREF_80;
-       if (pincap & AC_PINCAP_VREF_50)
-               return AC_PINCTL_VREF_50;
-       if (pincap & AC_PINCAP_VREF_GRD)
-               return AC_PINCTL_VREF_GRD;
-       return 0;
-}
-
 static void stac92xx_auto_set_pinctl(struct hda_codec *codec, hda_nid_t nid, int pin_type)
 
 {
@@ -590,12 +564,9 @@ static int stac92xx_io_switch_put(struct snd_kcontrol *kcontrol, struct snd_ctl_
 
        if (val)
                stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_OUT_EN);
-       else {
-               unsigned int pinctl = AC_PINCTL_IN_EN;
-               if (io_idx) /* set VREF for mic */
-                       pinctl |= stac92xx_get_vref(codec, nid);
-               stac92xx_auto_set_pinctl(codec, nid, pinctl);
-       }
+       else
+               stac92xx_auto_set_pinctl(codec, nid, AC_PINCTL_IN_EN);
+
         return 1;
 }
 
@@ -720,7 +691,13 @@ static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct aut
                                        AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
        }
 
-       spec->multiout.num_dacs = cfg->line_outs;
+       if (cfg->line_outs)
+               spec->multiout.num_dacs = cfg->line_outs;
+       else if (cfg->hp_pin) {
+               spec->multiout.dac_nids[0] = snd_hda_codec_read(codec, cfg->hp_pin, 0,
+                                       AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
+               spec->multiout.num_dacs = 1;
+       }
 
        return 0;
 }
@@ -790,7 +767,10 @@ static int stac92xx_auto_create_hp_ctls(struct hda_codec *codec, struct auto_pin
 
        wid_caps = get_wcaps(codec, pin);
        if (wid_caps & AC_WCAP_UNSOL_CAP)
-               spec->hp_detect = 1;
+               /* Enable unsolicited responses on the HP widget */
+               snd_hda_codec_write(codec, pin, 0,
+                               AC_VERB_SET_UNSOLICITED_ENABLE,
+                               STAC_UNSOL_ENABLE);
 
        nid = snd_hda_codec_read(codec, pin, 0, AC_VERB_GET_CONNECT_LIST, 0) & 0xff;
        for (i = 0; i < cfg->line_outs; i++) {
@@ -824,6 +804,9 @@ static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const
        for (i = 0; i < AUTO_PIN_LAST; i++) {
                int index = -1;
                if (cfg->input_pins[i]) {
+                       /* Enable active pin widget as an input */
+                       stac92xx_auto_set_pinctl(codec, cfg->input_pins[i], AC_PINCTL_IN_EN);
+
                        imux->items[imux->num_items].label = auto_pin_cfg_labels[i];
 
                        for (j=0; j<spec->num_muxes; j++) {
@@ -872,8 +855,10 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
 
        if ((err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, NULL)) < 0)
                return err;
-       if (! spec->autocfg.line_outs)
+       if (! spec->autocfg.line_outs && ! spec->autocfg.hp_pin)
                return 0; /* can't find valid pin config */
+       stac92xx_auto_init_multi_out(codec);
+       stac92xx_auto_init_hp_out(codec);
        if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
                return err;
        if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
@@ -888,10 +873,14 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
        if (spec->multiout.max_channels > 2)
                spec->surr_switch = 1;
 
-       if (spec->autocfg.dig_out_pin)
+       if (spec->autocfg.dig_out_pin) {
                spec->multiout.dig_out_nid = dig_out;
-       if (spec->autocfg.dig_in_pin)
+               stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
+       }
+       if (spec->autocfg.dig_in_pin) {
                spec->dig_in_nid = dig_in;
+               stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
+       }
 
        if (spec->kctl_alloc)
                spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
@@ -901,24 +890,6 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
        return 1;
 }
 
-/* add playback controls for HP output */
-static int stac9200_auto_create_hp_ctls(struct hda_codec *codec,
-                                       struct auto_pin_cfg *cfg)
-{
-       struct sigmatel_spec *spec = codec->spec;
-       hda_nid_t pin = cfg->hp_pin;
-       unsigned int wid_caps;
-
-       if (! pin)
-               return 0;
-
-       wid_caps = get_wcaps(codec, pin);
-       if (wid_caps & AC_WCAP_UNSOL_CAP)
-               spec->hp_detect = 1;
-
-       return 0;
-}
-
 static int stac9200_parse_auto_config(struct hda_codec *codec)
 {
        struct sigmatel_spec *spec = codec->spec;
@@ -930,13 +901,14 @@ static int stac9200_parse_auto_config(struct hda_codec *codec)
        if ((err = stac92xx_auto_create_analog_input_ctls(codec, &spec->autocfg)) < 0)
                return err;
 
-       if ((err = stac9200_auto_create_hp_ctls(codec, &spec->autocfg)) < 0)
-               return err;
-
-       if (spec->autocfg.dig_out_pin)
+       if (spec->autocfg.dig_out_pin) {
                spec->multiout.dig_out_nid = 0x05;
-       if (spec->autocfg.dig_in_pin)
+               stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_out_pin, AC_PINCTL_OUT_EN);
+       }
+       if (spec->autocfg.dig_in_pin) {
                spec->dig_in_nid = 0x04;
+               stac92xx_auto_set_pinctl(codec, spec->autocfg.dig_in_pin, AC_PINCTL_IN_EN);
+       }
 
        if (spec->kctl_alloc)
                spec->mixers[spec->num_mixers++] = spec->kctl_alloc;
@@ -949,39 +921,9 @@ static int stac9200_parse_auto_config(struct hda_codec *codec)
 static int stac92xx_init(struct hda_codec *codec)
 {
        struct sigmatel_spec *spec = codec->spec;
-       struct auto_pin_cfg *cfg = &spec->autocfg;
-       int i;
 
        snd_hda_sequence_write(codec, spec->init);
 
-       /* set up pins */
-       if (spec->hp_detect) {
-               /* Enable unsolicited responses on the HP widget */
-               snd_hda_codec_write(codec, cfg->hp_pin, 0,
-                               AC_VERB_SET_UNSOLICITED_ENABLE,
-                               STAC_UNSOL_ENABLE);
-               /* fake event to set up pins */
-               codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
-       } else {
-               stac92xx_auto_init_multi_out(codec);
-               stac92xx_auto_init_hp_out(codec);
-       }
-       for (i = 0; i < AUTO_PIN_LAST; i++) {
-               hda_nid_t nid = cfg->input_pins[i];
-               if (nid) {
-                       unsigned int pinctl = AC_PINCTL_IN_EN;
-                       if (i == AUTO_PIN_MIC || i == AUTO_PIN_FRONT_MIC)
-                               pinctl |= stac92xx_get_vref(codec, nid);
-                       stac92xx_auto_set_pinctl(codec, nid, pinctl);
-               }
-       }
-       if (cfg->dig_out_pin)
-               stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
-                                        AC_PINCTL_OUT_EN);
-       if (cfg->dig_in_pin)
-               stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
-                                        AC_PINCTL_IN_EN);
-
        return 0;
 }
 
@@ -1199,166 +1141,6 @@ static int patch_stac927x(struct hda_codec *codec)
        return 0;
 }
 
-/*
- * STAC 7661(?) hack
- */
-
-/* static config for Sony VAIO FE550G */
-static hda_nid_t vaio_dacs[] = { 0x2 };
-#define VAIO_HP_DAC    0x5
-static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
-static hda_nid_t vaio_mux_nids[] = { 0x15 };
-
-static struct hda_input_mux vaio_mux = {
-       .num_items = 2,
-       .items = {
-               /* { "HP", 0x0 }, */
-               { "Line", 0x1 },
-               { "Mic", 0x2 },
-               { "PCM", 0x3 },
-       }
-};
-
-static struct hda_verb vaio_init[] = {
-       {0x0a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP <- 0x2 */
-       {0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Speaker <- 0x5 */
-       {0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? (<- 0x2) */
-       {0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD */
-       {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Mic? */
-       {0x15, AC_VERB_SET_CONNECT_SEL, 0x2}, /* mic-sel: 0a,0d,14,02 */
-       {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* HP */
-       {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE}, /* Speaker */
-       {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, /* capture sw/vol -> 0x8 */
-       {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)}, /* CD-in -> 0x6 */
-       {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, /* Mic-in -> 0x9 */
-       {}
-};
-
-/* bind volumes of both NID 0x02 and 0x05 */
-static int vaio_master_vol_put(struct snd_kcontrol *kcontrol,
-                              struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       long *valp = ucontrol->value.integer.value;
-       int change;
-
-       change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
-                                         0x7f, valp[0] & 0x7f);
-       change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
-                                          0x7f, valp[1] & 0x7f);
-       snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
-                                0x7f, valp[0] & 0x7f);
-       snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
-                                0x7f, valp[1] & 0x7f);
-       return change;
-}
-
-/* bind volumes of both NID 0x02 and 0x05 */
-static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
-                             struct snd_ctl_elem_value *ucontrol)
-{
-       struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
-       long *valp = ucontrol->value.integer.value;
-       int change;
-
-       change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
-                                         0x80, (valp[0] ? 0 : 0x80));
-       change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
-                                          0x80, (valp[1] ? 0 : 0x80));
-       snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
-                                0x80, (valp[0] ? 0 : 0x80));
-       snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
-                                0x80, (valp[1] ? 0 : 0x80));
-       return change;
-}
-
-static struct snd_kcontrol_new vaio_mixer[] = {
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Volume",
-               .info = snd_hda_mixer_amp_volume_info,
-               .get = snd_hda_mixer_amp_volume_get,
-               .put = vaio_master_vol_put,
-               .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
-       },
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Master Playback Switch",
-               .info = snd_hda_mixer_amp_switch_info,
-               .get = snd_hda_mixer_amp_switch_get,
-               .put = vaio_master_sw_put,
-               .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
-       },
-       /* HDA_CODEC_VOLUME("CD Capture Volume", 0x07, 0, HDA_INPUT), */
-       HDA_CODEC_VOLUME("Capture Volume", 0x09, 0, HDA_INPUT),
-       HDA_CODEC_MUTE("Capture Switch", 0x09, 0, HDA_INPUT),
-       {
-               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
-               .name = "Capture Source",
-               .count = 1,
-               .info = stac92xx_mux_enum_info,
-               .get = stac92xx_mux_enum_get,
-               .put = stac92xx_mux_enum_put,
-       },
-       {}
-};
-
-static struct hda_codec_ops stac7661_patch_ops = {
-       .build_controls = stac92xx_build_controls,
-       .build_pcms = stac92xx_build_pcms,
-       .init = stac92xx_init,
-       .free = stac92xx_free,
-#ifdef CONFIG_PM
-       .resume = stac92xx_resume,
-#endif
-};
-
-enum { STAC7661_VAIO };
-
-static struct hda_board_config stac7661_cfg_tbl[] = {
-       { .modelname = "vaio", .config = STAC7661_VAIO },
-       { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
-         .config = STAC7661_VAIO },
-       { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
-         .config = STAC7661_VAIO },
-       {}
-};
-
-static int patch_stac7661(struct hda_codec *codec)
-{
-       struct sigmatel_spec *spec;
-       int board_config;
-
-       board_config = snd_hda_check_board_config(codec, stac7661_cfg_tbl);
-       if (board_config < 0)
-               /* unknown config, let generic-parser do its job... */
-               return snd_hda_parse_generic_codec(codec);
-       
-       spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
-       if (spec == NULL)
-               return -ENOMEM;
-
-       codec->spec = spec;
-       switch (board_config) {
-       case STAC7661_VAIO:
-               spec->mixer = vaio_mixer;
-               spec->init = vaio_init;
-               spec->multiout.max_channels = 2;
-               spec->multiout.num_dacs = ARRAY_SIZE(vaio_dacs);
-               spec->multiout.dac_nids = vaio_dacs;
-               spec->multiout.hp_nid = VAIO_HP_DAC;
-               spec->num_adcs = ARRAY_SIZE(vaio_adcs);
-               spec->adc_nids = vaio_adcs;
-               spec->input_mux = &vaio_mux;
-               spec->mux_nids = vaio_mux_nids;
-               break;
-       }
-
-       codec->patch_ops = stac7661_patch_ops;
-       return 0;
-}
-
-
 /*
  * patch entries
  */
@@ -1380,6 +1162,5 @@ struct hda_codec_preset snd_hda_preset_sigmatel[] = {
        { .id = 0x83847627, .name = "STAC9271D", .patch = patch_stac927x },
        { .id = 0x83847628, .name = "STAC9274X5NH", .patch = patch_stac927x },
        { .id = 0x83847629, .name = "STAC9274D5NH", .patch = patch_stac927x },
-       { .id = 0x83847661, .name = "STAC7661", .patch = patch_stac7661 },
        {} /* terminator */
 };