[ALSA] Add missing TLV callbacks for HD-audio codecs
[pandora-kernel.git] / sound / pci / hda / patch_sigmatel.c
index 8c440fb..887b52e 100644 (file)
 #define STAC_REF               0
 #define STAC_D945GTP3          1
 #define STAC_D945GTP5          2
+#define STAC_MACMINI           3
+#define STAC_D965_2112         4
+#define STAC_D965_284B         5
+#define STAC_922X_MODELS       6       /* number of 922x models */
 
 struct sigmatel_spec {
        struct snd_kcontrol_new *mixers[4];
@@ -52,6 +56,7 @@ struct sigmatel_spec {
        unsigned int mic_switch: 1;
        unsigned int alt_switch: 1;
        unsigned int hp_detect: 1;
+       unsigned int gpio_mute: 1;
 
        /* playback */
        struct hda_multi_out multiout;
@@ -105,10 +110,24 @@ static hda_nid_t stac922x_adc_nids[2] = {
         0x06, 0x07,
 };
 
+static hda_nid_t stac9227_adc_nids[2] = {
+        0x07, 0x08,
+};
+
+#if 0
+static hda_nid_t d965_2112_dac_nids[3] = {
+        0x02, 0x03, 0x05,
+};
+#endif
+
 static hda_nid_t stac922x_mux_nids[2] = {
         0x12, 0x13,
 };
 
+static hda_nid_t stac9227_mux_nids[2] = {
+        0x15, 0x16,
+};
+
 static hda_nid_t stac927x_adc_nids[3] = {
         0x07, 0x08, 0x09
 };
@@ -117,6 +136,14 @@ static hda_nid_t stac927x_mux_nids[3] = {
         0x15, 0x16, 0x17
 };
 
+static hda_nid_t stac9205_adc_nids[2] = {
+        0x12, 0x13
+};
+
+static hda_nid_t stac9205_mux_nids[2] = {
+        0x19, 0x1a
+};
+
 static hda_nid_t stac9200_pin_nids[8] = {
        0x08, 0x09, 0x0d, 0x0e, 0x0f, 0x10, 0x11, 0x12,
 };
@@ -132,6 +159,13 @@ static hda_nid_t stac927x_pin_nids[14] = {
        0x14, 0x21, 0x22, 0x23,
 };
 
+static hda_nid_t stac9205_pin_nids[12] = {
+       0x0a, 0x0b, 0x0c, 0x0d, 0x0e,
+       0x0f, 0x14, 0x16, 0x17, 0x18,
+       0x21, 0x22,
+       
+};
+
 static int stac92xx_mux_enum_info(struct snd_kcontrol *kcontrol, struct snd_ctl_elem_info *uinfo)
 {
        struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
@@ -171,12 +205,36 @@ static struct hda_verb stac922x_core_init[] = {
        {}
 };
 
+static struct hda_verb stac9227_core_init[] = {
+       /* set master volume and direct control */      
+       { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
+       /* unmute node 0x1b */
+       { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
+       {}
+};
+
+static struct hda_verb d965_2112_core_init[] = {
+       /* set master volume and direct control */      
+       { 0x16, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
+       /* unmute node 0x1b */
+       { 0x1b, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
+       /* select node 0x03 as DAC */   
+       { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x01},
+       {}
+};
+
 static struct hda_verb stac927x_core_init[] = {
        /* set master volume and direct control */      
        { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
        {}
 };
 
+static struct hda_verb stac9205_core_init[] = {
+       /* set master volume and direct control */      
+       { 0x24, AC_VERB_SET_VOLUME_KNOB_CONTROL, 0xff},
+       {}
+};
+
 static struct snd_kcontrol_new stac9200_mixer[] = {
        HDA_CODEC_VOLUME("Master Playback Volume", 0xb, 0, HDA_OUTPUT),
        HDA_CODEC_MUTE("Master Playback Switch", 0xb, 0, HDA_OUTPUT),
@@ -210,6 +268,21 @@ static struct snd_kcontrol_new stac922x_mixer[] = {
        { } /* end */
 };
 
+/* This needs to be generated dynamically based on sequence */
+static struct snd_kcontrol_new stac9227_mixer[] = {
+       {
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .name = "Input Source",
+               .count = 1,
+               .info = stac92xx_mux_enum_info,
+               .get = stac92xx_mux_enum_get,
+               .put = stac92xx_mux_enum_put,
+       },
+       HDA_CODEC_VOLUME("Capture Volume", 0x15, 0x0, HDA_OUTPUT),
+       HDA_CODEC_MUTE("Capture Switch", 0x1b, 0x0, HDA_OUTPUT),
+       { } /* end */
+};
+
 static snd_kcontrol_new_t stac927x_mixer[] = {
        {
                .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
@@ -225,6 +298,21 @@ static snd_kcontrol_new_t stac927x_mixer[] = {
        { } /* end */
 };
 
+static snd_kcontrol_new_t stac9205_mixer[] = {
+       {
+               .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
+               .name = "Input Source",
+               .count = 1,
+               .info = stac92xx_mux_enum_info,
+               .get = stac92xx_mux_enum_get,
+               .put = stac92xx_mux_enum_put,
+       },
+       HDA_CODEC_VOLUME("InMux Capture Volume", 0x19, 0x0, HDA_OUTPUT),
+       HDA_CODEC_VOLUME("InVol Capture Volume", 0x1b, 0x0, HDA_INPUT),
+       HDA_CODEC_MUTE("ADCMux Capture Switch", 0x1d, 0x0, HDA_OUTPUT),
+       { } /* end */
+};
+
 static int stac92xx_build_controls(struct hda_codec *codec)
 {
        struct sigmatel_spec *spec = codec->spec;
@@ -289,10 +377,18 @@ static unsigned int d945gtp5_pin_configs[10] = {
        0x02a19320, 0x40000100,
 };
 
-static unsigned int *stac922x_brd_tbl[] = {
-       ref922x_pin_configs,
-       d945gtp3_pin_configs,
-       d945gtp5_pin_configs,
+static unsigned int d965_2112_pin_configs[10] = {
+       0x0221401f, 0x40000100, 0x40000100, 0x01014011,
+       0x01a19021, 0x01813024, 0x01452130, 0x40000100,
+       0x02a19320, 0x40000100,
+};
+
+static unsigned int *stac922x_brd_tbl[STAC_922X_MODELS] = {
+       [STAC_REF] =    ref922x_pin_configs,
+       [STAC_D945GTP3] = d945gtp3_pin_configs,
+       [STAC_D945GTP5] = d945gtp5_pin_configs,
+       [STAC_MACMINI] = d945gtp5_pin_configs,
+       [STAC_D965_2112] = d965_2112_pin_configs,
 };
 
 static struct hda_board_config stac922x_cfg_tbl[] = {
@@ -324,6 +420,15 @@ static struct hda_board_config stac922x_cfg_tbl[] = {
        { .pci_subvendor = PCI_VENDOR_ID_INTEL,
          .pci_subdevice = 0x0417,
          .config = STAC_D945GTP5 },    /* Intel D975XBK - 5 Stack */
+       { .pci_subvendor = 0x8384,
+         .pci_subdevice = 0x7680,
+         .config = STAC_MACMINI },     /* Apple Mac Mini (early 2006) */
+       { .pci_subvendor = PCI_VENDOR_ID_INTEL,
+         .pci_subdevice = 0x2112,
+         .config = STAC_D965_2112 },
+       { .pci_subvendor = PCI_VENDOR_ID_INTEL,
+         .pci_subdevice = 0x284b,
+         .config = STAC_D965_284B },
        {} /* terminator */
 };
 
@@ -346,6 +451,24 @@ static struct hda_board_config stac927x_cfg_tbl[] = {
        {} /* terminator */
 };
 
+static unsigned int ref9205_pin_configs[12] = {
+       0x40000100, 0x40000100, 0x01016011, 0x01014010,
+       0x01813122, 0x01a19021, 0x40000100, 0x40000100, 
+       0x40000100, 0x40000100, 0x01441030, 0x01c41030
+};
+
+static unsigned int *stac9205_brd_tbl[] = {
+       ref9205_pin_configs,
+};
+
+static struct hda_board_config stac9205_cfg_tbl[] = {
+       { .modelname = "ref",
+         .pci_subvendor = PCI_VENDOR_ID_INTEL,
+         .pci_subdevice = 0x2668,      /* DFI LanParty */
+         .config = STAC_REF },         /* SigmaTel reference board */
+       {} /* terminator */
+};
+
 static void stac92xx_set_config_regs(struct hda_codec *codec)
 {
        int i;
@@ -707,7 +830,8 @@ static int stac92xx_add_dyn_out_pins(struct hda_codec *codec, struct auto_pin_cf
  * A and B is not supported.
  */
 /* fill in the dac_nids table from the parsed pin configuration */
-static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct auto_pin_cfg *cfg)
+static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec,
+                                      const struct auto_pin_cfg *cfg)
 {
        struct sigmatel_spec *spec = codec->spec;
        hda_nid_t nid;
@@ -726,10 +850,13 @@ static int stac92xx_auto_fill_dac_nids(struct hda_codec *codec, const struct aut
 }
 
 /* add playback controls from the parsed DAC table */
-static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec, const struct auto_pin_cfg *cfg)
+static int stac92xx_auto_create_multi_out_ctls(struct sigmatel_spec *spec,
+                                              const struct auto_pin_cfg *cfg)
 {
        char name[32];
-       static const char *chname[4] = { "Front", "Surround", NULL /*CLFE*/, "Side" };
+       static const char *chname[4] = {
+               "Front", "Surround", NULL /*CLFE*/, "Side"
+       };
        hda_nid_t nid;
        int i, err;
 
@@ -841,6 +968,19 @@ static int stac92xx_auto_create_analog_input_ctls(struct hda_codec *codec, const
                }
        }
 
+       if (imux->num_items == 1) {
+               /*
+                * Set the current input for the muxes.
+                * The STAC9221 has two input muxes with identical source
+                * NID lists.  Hopefully this won't get confused.
+                */
+               for (i = 0; i < spec->num_muxes; i++) {
+                       snd_hda_codec_write(codec, spec->mux_nids[i], 0,
+                                           AC_VERB_SET_CONNECT_SEL,
+                                           imux->items[0].index);
+               }
+       }
+
        return 0;
 }
 
@@ -874,10 +1014,12 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
                return err;
        if (! spec->autocfg.line_outs)
                return 0; /* can't find valid pin config */
+
        if ((err = stac92xx_add_dyn_out_pins(codec, &spec->autocfg)) < 0)
                return err;
-       if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
-               return err;
+       if (spec->multiout.num_dacs == 0)
+               if ((err = stac92xx_auto_fill_dac_nids(codec, &spec->autocfg)) < 0)
+                       return err;
 
        if ((err = stac92xx_auto_create_multi_out_ctls(spec, &spec->autocfg)) < 0 ||
            (err = stac92xx_auto_create_hp_ctls(codec, &spec->autocfg)) < 0 ||
@@ -946,6 +1088,45 @@ static int stac9200_parse_auto_config(struct hda_codec *codec)
        return 1;
 }
 
+/*
+ * Early 2006 Intel Macintoshes with STAC9220X5 codecs seem to have a
+ * funky external mute control using GPIO pins.
+ */
+
+static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted)
+{
+       unsigned int gpiostate, gpiomask, gpiodir;
+
+       gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
+                                      AC_VERB_GET_GPIO_DATA, 0);
+
+       if (!muted)
+               gpiostate |= (1 << pin);
+       else
+               gpiostate &= ~(1 << pin);
+
+       gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
+                                     AC_VERB_GET_GPIO_MASK, 0);
+       gpiomask |= (1 << pin);
+
+       gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
+                                    AC_VERB_GET_GPIO_DIRECTION, 0);
+       gpiodir |= (1 << pin);
+
+       /* AppleHDA seems to do this -- WTF is this verb?? */
+       snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
+
+       snd_hda_codec_write(codec, codec->afg, 0,
+                           AC_VERB_SET_GPIO_MASK, gpiomask);
+       snd_hda_codec_write(codec, codec->afg, 0,
+                           AC_VERB_SET_GPIO_DIRECTION, gpiodir);
+
+       msleep(1);
+
+       snd_hda_codec_write(codec, codec->afg, 0,
+                           AC_VERB_SET_GPIO_DATA, gpiostate);
+}
+
 static int stac92xx_init(struct hda_codec *codec)
 {
        struct sigmatel_spec *spec = codec->spec;
@@ -982,6 +1163,11 @@ static int stac92xx_init(struct hda_codec *codec)
                stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
                                         AC_PINCTL_IN_EN);
 
+       if (spec->gpio_mute) {
+               stac922x_gpio_mute(codec, 0, 0);
+               stac922x_gpio_mute(codec, 1, 0);
+       }
+
        return 0;
 }
 
@@ -1131,8 +1317,9 @@ static int patch_stac922x(struct hda_codec *codec)
        codec->spec = spec;
        spec->board_config = snd_hda_check_board_config(codec, stac922x_cfg_tbl);
        if (spec->board_config < 0)
-                snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, using BIOS defaults\n");
-       else {
+                snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC922x, "
+                           "using BIOS defaults\n");
+       else if (stac922x_brd_tbl[spec->board_config] != NULL) {
                spec->num_pins = 10;
                spec->pin_nids = stac922x_pin_nids;
                spec->pin_configs = stac922x_brd_tbl[spec->board_config];
@@ -1147,6 +1334,25 @@ static int patch_stac922x(struct hda_codec *codec)
        spec->mixer = stac922x_mixer;
 
        spec->multiout.dac_nids = spec->dac_nids;
+       
+       switch (spec->board_config) {
+       case STAC_D965_2112:
+               spec->adc_nids = stac9227_adc_nids;
+               spec->mux_nids = stac9227_mux_nids;
+#if 0
+               spec->multiout.dac_nids = d965_2112_dac_nids;
+               spec->multiout.num_dacs = ARRAY_SIZE(d965_2112_dac_nids);
+#endif
+               spec->init = d965_2112_core_init;
+               spec->mixer = stac9227_mixer;
+               break;
+       case STAC_D965_284B:
+               spec->adc_nids = stac9227_adc_nids;
+               spec->mux_nids = stac9227_mux_nids;
+               spec->init = stac9227_core_init;
+               spec->mixer = stac9227_mixer;
+               break;
+       }
 
        err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
        if (err < 0) {
@@ -1154,6 +1360,9 @@ static int patch_stac922x(struct hda_codec *codec)
                return err;
        }
 
+       if (spec->board_config == STAC_MACMINI)
+               spec->gpio_mute = 1;
+
        codec->patch_ops = stac92xx_patch_ops;
 
        return 0;
@@ -1199,11 +1408,51 @@ static int patch_stac927x(struct hda_codec *codec)
        return 0;
 }
 
+static int patch_stac9205(struct hda_codec *codec)
+{
+       struct sigmatel_spec *spec;
+       int err;
+
+       spec  = kzalloc(sizeof(*spec), GFP_KERNEL);
+       if (spec == NULL)
+               return -ENOMEM;
+
+       codec->spec = spec;
+       spec->board_config = snd_hda_check_board_config(codec, stac9205_cfg_tbl);
+       if (spec->board_config < 0)
+                snd_printdd(KERN_INFO "hda_codec: Unknown model for STAC9205, using BIOS defaults\n");
+       else {
+               spec->num_pins = 14;
+               spec->pin_nids = stac9205_pin_nids;
+               spec->pin_configs = stac9205_brd_tbl[spec->board_config];
+               stac92xx_set_config_regs(codec);
+       }
+
+       spec->adc_nids = stac9205_adc_nids;
+       spec->mux_nids = stac9205_mux_nids;
+       spec->num_muxes = 3;
+
+       spec->init = stac9205_core_init;
+       spec->mixer = stac9205_mixer;
+
+       spec->multiout.dac_nids = spec->dac_nids;
+
+       err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
+       if (err < 0) {
+               stac92xx_free(codec);
+               return err;
+       }
+
+       codec->patch_ops = stac92xx_patch_ops;
+
+       return 0;
+}
+
 /*
- * STAC 7661(?) hack
+ * STAC 7661(?) and 7664 hack
  */
 
-/* static config for Sony VAIO FE550G */
+/* static config for Sony VAIO FE550G and Sony VAIO AR */
 static hda_nid_t vaio_dacs[] = { 0x2 };
 #define VAIO_HP_DAC    0x5
 static hda_nid_t vaio_adcs[] = { 0x8 /*,0x6*/ };
@@ -1262,13 +1511,13 @@ static int vaio_master_sw_put(struct snd_kcontrol *kcontrol,
        int change;
 
        change = snd_hda_codec_amp_update(codec, 0x02, 0, HDA_OUTPUT, 0,
-                                         0x80, valp[0] & 0x80);
+                                         0x80, (valp[0] ? 0 : 0x80));
        change |= snd_hda_codec_amp_update(codec, 0x02, 1, HDA_OUTPUT, 0,
-                                          0x80, valp[1] & 0x80);
+                                          0x80, (valp[1] ? 0 : 0x80));
        snd_hda_codec_amp_update(codec, 0x05, 0, HDA_OUTPUT, 0,
-                                0x80, valp[0] & 0x80);
+                                0x80, (valp[0] ? 0 : 0x80));
        snd_hda_codec_amp_update(codec, 0x05, 1, HDA_OUTPUT, 0,
-                                0x80, valp[1] & 0x80);
+                                0x80, (valp[1] ? 0 : 0x80));
        return change;
 }
 
@@ -1279,6 +1528,7 @@ static struct snd_kcontrol_new vaio_mixer[] = {
                .info = snd_hda_mixer_amp_volume_info,
                .get = snd_hda_mixer_amp_volume_get,
                .put = vaio_master_vol_put,
+               .tlv = { .c = snd_hda_mixer_amp_tlv },
                .private_value = HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
        },
        {
@@ -1303,7 +1553,7 @@ static struct snd_kcontrol_new vaio_mixer[] = {
        {}
 };
 
-static struct hda_codec_ops stac7661_patch_ops = {
+static struct hda_codec_ops stac766x_patch_ops = {
        .build_controls = stac92xx_build_controls,
        .build_pcms = stac92xx_build_pcms,
        .init = stac92xx_init,
@@ -1313,23 +1563,25 @@ static struct hda_codec_ops stac7661_patch_ops = {
 #endif
 };
 
-enum { STAC7661_VAIO };
+enum { STAC766x_VAIO };
 
-static struct hda_board_config stac7661_cfg_tbl[] = {
-       { .modelname = "vaio", .config = STAC7661_VAIO },
+static struct hda_board_config stac766x_cfg_tbl[] = {
+       { .modelname = "vaio", .config = STAC766x_VAIO },
        { .pci_subvendor = 0x104d, .pci_subdevice = 0x81e6,
-         .config = STAC7661_VAIO },
+         .config = STAC766x_VAIO },
        { .pci_subvendor = 0x104d, .pci_subdevice = 0x81ef,
-         .config = STAC7661_VAIO },
+         .config = STAC766x_VAIO },
+       { .pci_subvendor = 0x104d, .pci_subdevice = 0x81fd,
+         .config = STAC766x_VAIO },
        {}
 };
 
-static int patch_stac7661(struct hda_codec *codec)
+static int patch_stac766x(struct hda_codec *codec)
 {
        struct sigmatel_spec *spec;
        int board_config;
 
-       board_config = snd_hda_check_board_config(codec, stac7661_cfg_tbl);
+       board_config = snd_hda_check_board_config(codec, stac766x_cfg_tbl);
        if (board_config < 0)
                /* unknown config, let generic-parser do its job... */
                return snd_hda_parse_generic_codec(codec);
@@ -1340,7 +1592,7 @@ static int patch_stac7661(struct hda_codec *codec)
 
        codec->spec = spec;
        switch (board_config) {
-       case STAC7661_VAIO:
+       case STAC766x_VAIO:
                spec->mixer = vaio_mixer;
                spec->init = vaio_init;
                spec->multiout.max_channels = 2;
@@ -1354,7 +1606,7 @@ static int patch_stac7661(struct hda_codec *codec)
                break;
        }
 
-       codec->patch_ops = stac7661_patch_ops;
+       codec->patch_ops = stac766x_patch_ops;
        return 0;
 }
 
@@ -1370,6 +1622,12 @@ struct hda_codec_preset snd_hda_preset_sigmatel[] = {
        { .id = 0x83847681, .name = "STAC9220D/9223D A2", .patch = patch_stac922x },
        { .id = 0x83847682, .name = "STAC9221 A2", .patch = patch_stac922x },
        { .id = 0x83847683, .name = "STAC9221D A2", .patch = patch_stac922x },
+       { .id = 0x83847618, .name = "STAC9227", .patch = patch_stac927x },
+       { .id = 0x83847619, .name = "STAC9227", .patch = patch_stac927x },
+       { .id = 0x83847616, .name = "STAC9228", .patch = patch_stac927x },
+       { .id = 0x83847617, .name = "STAC9228", .patch = patch_stac927x },
+       { .id = 0x83847614, .name = "STAC9229", .patch = patch_stac927x },
+       { .id = 0x83847615, .name = "STAC9229", .patch = patch_stac927x },
        { .id = 0x83847620, .name = "STAC9274", .patch = patch_stac927x },
        { .id = 0x83847621, .name = "STAC9274D", .patch = patch_stac927x },
        { .id = 0x83847622, .name = "STAC9273X", .patch = patch_stac927x },
@@ -1380,6 +1638,15 @@ 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 },
+       { .id = 0x83847661, .name = "STAC7661", .patch = patch_stac766x },
+       { .id = 0x838476a0, .name = "STAC9205", .patch = patch_stac9205 },
+       { .id = 0x838476a1, .name = "STAC9205D", .patch = patch_stac9205 },
+       { .id = 0x838476a2, .name = "STAC9204", .patch = patch_stac9205 },
+       { .id = 0x838476a3, .name = "STAC9204D", .patch = patch_stac9205 },
+       { .id = 0x838476a4, .name = "STAC9255", .patch = patch_stac9205 },
+       { .id = 0x838476a5, .name = "STAC9255D", .patch = patch_stac9205 },
+       { .id = 0x838476a6, .name = "STAC9254", .patch = patch_stac9205 },
+       { .id = 0x838476a7, .name = "STAC9254D", .patch = patch_stac9205 },
+       { .id = 0x83847664, .name = "STAC7664", .patch = patch_stac766x },
        {} /* terminator */
 };