]> pilppa.org Git - linux-2.6-omap-h63xx.git/blobdiff - sound/pci/hda/patch_sigmatel.c
[ALSA] hda-codec - Add support of AD1883/1884A/1984A/1984B
[linux-2.6-omap-h63xx.git] / sound / pci / hda / patch_sigmatel.c
index b8152efbfc8cba2d2e9ac4f754a94967627d289f..7901e76f269066753b5eec6b6cd7012b8a22c326 100644 (file)
@@ -39,6 +39,7 @@
 
 enum {
        STAC_REF,
+       STAC_9200_OQO,
        STAC_9200_DELL_D21,
        STAC_9200_DELL_D22,
        STAC_9200_DELL_D23,
@@ -122,13 +123,20 @@ struct sigmatel_spec {
        unsigned int alt_switch: 1;
        unsigned int hp_detect: 1;
 
-       unsigned int gpio_mask, gpio_data;
+       /* gpio lines */
+       unsigned int gpio_mask;
+       unsigned int gpio_dir;
+       unsigned int gpio_data;
+       unsigned int gpio_mute;
+
+       /* analog loopback */
        unsigned char aloopback_mask;
        unsigned char aloopback_shift;
 
        /* power management */
        unsigned int num_pwrs;
        hda_nid_t *pwr_nids;
+       hda_nid_t *dac_list;
 
        /* playback */
        struct hda_input_mux *mono_mux;
@@ -284,6 +292,10 @@ static hda_nid_t stac927x_mux_nids[3] = {
         0x15, 0x16, 0x17
 };
 
+static hda_nid_t stac927x_dac_nids[6] = {
+       0x02, 0x03, 0x04, 0x05, 0x06, 0
+};
+
 static hda_nid_t stac927x_dmux_nids[1] = {
        0x1b,
 };
@@ -873,6 +885,7 @@ static const char *slave_sws[] = {
        "Speaker Playback Switch",
        "External Speaker Playback Switch",
        "Speaker2 Playback Switch",
+       "IEC958 Playback Switch",
        NULL
 };
 
@@ -903,6 +916,11 @@ static int stac92xx_build_controls(struct hda_codec *codec)
                err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
                if (err < 0)
                        return err;
+               err = snd_hda_create_spdif_share_sw(codec,
+                                                   &spec->multiout);
+               if (err < 0)
+                       return err;
+               spec->multiout.share_spdif = 1;
        }
        if (spec->dig_in_nid) {
                err = snd_hda_create_spdif_in_ctls(codec, spec->dig_in_nid);
@@ -1045,9 +1063,15 @@ static unsigned int dell9200_m27_pin_configs[8] = {
        0x90170310, 0x04a11020, 0x90170310, 0x40f003fc,
 };
 
+static unsigned int oqo9200_pin_configs[8] = {
+       0x40c000f0, 0x404000f1, 0x0221121f, 0x02211210,
+       0x90170111, 0x90a70120, 0x400000f2, 0x400000f3,
+};
+
 
 static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
        [STAC_REF] = ref9200_pin_configs,
+       [STAC_9200_OQO] = oqo9200_pin_configs,
        [STAC_9200_DELL_D21] = dell9200_d21_pin_configs,
        [STAC_9200_DELL_D22] = dell9200_d22_pin_configs,
        [STAC_9200_DELL_D23] = dell9200_d23_pin_configs,
@@ -1062,6 +1086,7 @@ static unsigned int *stac9200_brd_tbl[STAC_9200_MODELS] = {
 
 static const char *stac9200_models[STAC_9200_MODELS] = {
        [STAC_REF] = "ref",
+       [STAC_9200_OQO] = "oqo",
        [STAC_9200_DELL_D21] = "dell-d21",
        [STAC_9200_DELL_D22] = "dell-d22",
        [STAC_9200_DELL_D23] = "dell-d23",
@@ -1146,6 +1171,8 @@ static struct snd_pci_quirk stac9200_cfg_tbl[] = {
                      STAC_9200_GATEWAY),
        SND_PCI_QUIRK(0x107b, 0x0318, "Gateway ML3019, MT3707",
                      STAC_9200_GATEWAY),
+       /* OQO Mobile */
+       SND_PCI_QUIRK(0x1106, 0x3288, "OQO Model 2", STAC_9200_OQO),
        {} /* terminator */
 };
 
@@ -1726,7 +1753,8 @@ static int stac92xx_playback_pcm_open(struct hda_pcm_stream *hinfo,
                                      struct snd_pcm_substream *substream)
 {
        struct sigmatel_spec *spec = codec->spec;
-       return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream);
+       return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
+                                            hinfo);
 }
 
 static int stac92xx_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -1882,6 +1910,7 @@ static int stac92xx_build_pcms(struct hda_codec *codec)
                codec->num_pcms++;
                info++;
                info->name = "STAC92xx Digital";
+               info->pcm_type = HDA_PCM_TYPE_SPDIF;
                if (spec->multiout.dig_out_nid) {
                        info->stream[SNDRV_PCM_STREAM_PLAYBACK] = stac92xx_pcm_digital_playback;
                        info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = spec->multiout.dig_out_nid;
@@ -2226,7 +2255,7 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
        int i, err;
 
        struct sigmatel_spec *spec = codec->spec;
-       unsigned int wid_caps;
+       unsigned int wid_caps, pincap;
 
 
        for (i = 0; i < cfg->line_outs; i++) {
@@ -2262,13 +2291,39 @@ static int stac92xx_auto_create_multi_out_ctls(struct hda_codec *codec,
                }
        }
 
-       if (spec->line_switch)
-               if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Line In as Output Switch", cfg->input_pins[AUTO_PIN_LINE] << 8)) < 0)
-                       return err;
+       if (spec->line_switch) {
+               nid = cfg->input_pins[AUTO_PIN_LINE];
+               pincap = snd_hda_param_read(codec, nid,
+                                               AC_PAR_PIN_CAP);
+               if (pincap & AC_PINCAP_OUT) {
+                       err = stac92xx_add_control(spec,
+                               STAC_CTL_WIDGET_IO_SWITCH,
+                               "Line In as Output Switch", nid << 8);
+                       if (err < 0)
+                               return err;
+               }
+       }
 
-       if (spec->mic_switch)
-               if ((err = stac92xx_add_control(spec, STAC_CTL_WIDGET_IO_SWITCH, "Mic as Output Switch", (cfg->input_pins[AUTO_PIN_MIC] << 8) | 1)) < 0)
-                       return err;
+       if (spec->mic_switch) {
+               unsigned int def_conf;
+               nid = cfg->input_pins[AUTO_PIN_MIC];
+               def_conf = snd_hda_codec_read(codec, nid, 0,
+                                               AC_VERB_GET_CONFIG_DEFAULT, 0);
+
+               /* some laptops have an internal analog microphone
+                * which can't be used as a output */
+               if (get_defcfg_connect(def_conf) != AC_JACK_PORT_FIXED) {
+                       pincap = snd_hda_param_read(codec, nid,
+                                                       AC_PAR_PIN_CAP);
+                       if (pincap & AC_PINCAP_OUT) {
+                               err = stac92xx_add_control(spec,
+                                       STAC_CTL_WIDGET_IO_SWITCH,
+                                       "Mic as Output Switch", (nid << 8) | 1);
+                               if (err < 0)
+                                       return err;
+                       }
+               }
+       }
 
        return 0;
 }
@@ -2784,13 +2839,13 @@ static int stac9200_parse_auto_config(struct hda_codec *codec)
  */
 
 static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
-                         unsigned int data)
+                         unsigned int dir_mask, unsigned int data)
 {
        unsigned int gpiostate, gpiomask, gpiodir;
 
        gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
                                       AC_VERB_GET_GPIO_DATA, 0);
-       gpiostate = (gpiostate & ~mask) | (data & mask);
+       gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
 
        gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
                                      AC_VERB_GET_GPIO_MASK, 0);
@@ -2798,7 +2853,7 @@ static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
 
        gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
                                     AC_VERB_GET_GPIO_DIRECTION, 0);
-       gpiodir |= mask;
+       gpiodir |= dir_mask;
 
        /* Configure GPIOx as CMOS */
        snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
@@ -2833,6 +2888,18 @@ static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
        return 0; /* nid is not a HP-Out */
 };
 
+static void stac92xx_power_down(struct hda_codec *codec)
+{
+       struct sigmatel_spec *spec = codec->spec;
+
+       /* power down inactive DACs */
+       hda_nid_t *dac;
+       for (dac = spec->dac_list; *dac; dac++)
+               if (!is_in_dac_nids(spec, *dac))
+                       snd_hda_codec_write_cache(codec, *dac, 0,
+                                       AC_VERB_SET_POWER_STATE, AC_PWRST_D3);
+}
+
 static int stac92xx_init(struct hda_codec *codec)
 {
        struct sigmatel_spec *spec = codec->spec;
@@ -2885,7 +2952,8 @@ static int stac92xx_init(struct hda_codec *codec)
                enable_pin_detect(codec, spec->pwr_nids[i], event | i);
                codec->patch_ops.unsol_event(codec, (event | i) << 26);
        }
-
+       if (spec->dac_list)
+               stac92xx_power_down(codec);
        if (cfg->dig_out_pin)
                stac92xx_auto_set_pinctl(codec, cfg->dig_out_pin,
                                         AC_PINCTL_OUT_EN);
@@ -2893,7 +2961,8 @@ static int stac92xx_init(struct hda_codec *codec)
                stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
                                         AC_PINCTL_IN_EN);
 
-       stac_gpio_set(codec, spec->gpio_mask, spec->gpio_data);
+       stac_gpio_set(codec, spec->gpio_mask,
+                                       spec->gpio_dir, spec->gpio_data);
 
        return 0;
 }
@@ -2983,10 +3052,14 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
        int i, presence;
 
        presence = 0;
+       if (spec->gpio_mute)
+               presence = !(snd_hda_codec_read(codec, codec->afg, 0,
+                       AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
+
        for (i = 0; i < cfg->hp_outs; i++) {
-               presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
                if (presence)
                        break;
+               presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
        }
 
        if (presence) {
@@ -3049,9 +3122,13 @@ static int stac92xx_resume(struct hda_codec *codec)
 
        stac92xx_set_config_regs(codec);
        snd_hda_sequence_write(codec, spec->init);
-       stac_gpio_set(codec, spec->gpio_mask, spec->gpio_data);
+       stac_gpio_set(codec, spec->gpio_mask,
+               spec->gpio_dir, spec->gpio_data);
        snd_hda_codec_resume_amp(codec);
        snd_hda_codec_resume_cache(codec);
+       /* power down inactive DACs */
+       if (spec->dac_list)
+               stac92xx_power_down(codec);
        /* invoke unsolicited event to reset the HP state */
        if (spec->hp_detect)
                codec->patch_ops.unsol_event(codec, STAC_HP_EVENT << 26);
@@ -3108,7 +3185,8 @@ static int patch_stac9200(struct hda_codec *codec)
        spec->num_adcs = 1;
        spec->num_pwrs = 0;
 
-       if (spec->board_config == STAC_9200_GATEWAY)
+       if (spec->board_config == STAC_9200_GATEWAY ||
+           spec->board_config == STAC_9200_OQO)
                spec->init = stac9200_eapd_init;
        else
                spec->init = stac9200_core_init;
@@ -3283,7 +3361,8 @@ again:
        spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
        spec->dinput_mux = &stac92hd73xx_dmux;
        /* GPIO0 High = Enable EAPD */
-       spec->gpio_mask = spec->gpio_data = 0x000001;
+       spec->gpio_mask = spec->gpio_dir = 0x1;
+       spec->gpio_data = 0x01;
 
        spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
        spec->pwr_nids = stac92hd73xx_pwr_nids;
@@ -3357,7 +3436,8 @@ again:
        spec->aloopback_mask = 0x20;
        spec->aloopback_shift = 0;
 
-       spec->gpio_mask = spec->gpio_data = 0x00000001; /* GPIO0 High = EAPD */
+       /* GPIO0 High = EAPD */
+       spec->gpio_mask = spec->gpio_dir = spec->gpio_data = 0x1;
 
        spec->mux_nids = stac92hd71bxx_mux_nids;
        spec->adc_nids = stac92hd71bxx_adc_nids;
@@ -3413,7 +3493,8 @@ static int patch_stac922x(struct hda_codec *codec)
                                                        stac922x_models,
                                                        stac922x_cfg_tbl);
        if (spec->board_config == STAC_INTEL_MAC_V3) {
-               spec->gpio_mask = spec->gpio_data = 0x03;
+               spec->gpio_mask = spec->gpio_dir = 0x03;
+               spec->gpio_data = 0x03;
                /* Intel Macs have all same PCI SSID, so we need to check
                 * codec SSID to distinguish the exact models
                 */
@@ -3535,13 +3616,15 @@ static int patch_stac927x(struct hda_codec *codec)
        spec->num_adcs = ARRAY_SIZE(stac927x_adc_nids);
        spec->mux_nids = stac927x_mux_nids;
        spec->num_muxes = ARRAY_SIZE(stac927x_mux_nids);
+       spec->dac_list = stac927x_dac_nids;
        spec->multiout.dac_nids = spec->dac_nids;
 
        switch (spec->board_config) {
        case STAC_D965_3ST:
        case STAC_D965_5ST:
                /* GPIO0 High = Enable EAPD */
-               spec->gpio_mask = spec->gpio_data = 0x00000001;
+               spec->gpio_mask = spec->gpio_dir = 0x01;
+               spec->gpio_data = 0x01;
                spec->num_dmics = 0;
 
                spec->init = d965_core_init;
@@ -3555,7 +3638,8 @@ static int patch_stac927x(struct hda_codec *codec)
                /* fallthru */
        case STAC_DELL_3ST:
                /* GPIO2 High = Enable EAPD */
-               spec->gpio_mask = spec->gpio_data = 0x00000004;
+               spec->gpio_mask = spec->gpio_dir = 0x04;
+               spec->gpio_data = 0x04;
                spec->dmic_nids = stac927x_dmic_nids;
                spec->num_dmics = STAC927X_NUM_DMICS;
 
@@ -3566,7 +3650,8 @@ static int patch_stac927x(struct hda_codec *codec)
                break;
        default:
                /* GPIO0 High = Enable EAPD */
-               spec->gpio_mask = spec->gpio_data = 0x00000001;
+               spec->gpio_mask = spec->gpio_dir = 0x1;
+               spec->gpio_data = 0x01;
                spec->num_dmics = 0;
 
                spec->init = stac927x_core_init;
@@ -3661,15 +3746,25 @@ static int patch_stac9205(struct hda_codec *codec)
                stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
                stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
 
-               spec->gpio_mask = 0x00000007; /* GPIO0-2 */
-               /* GPIO0 High = EAPD, GPIO1 Low = DRM,
-                * GPIO2 High = Headphone Mute
+               /* Enable unsol response for GPIO4/Dock HP connection */
+               snd_hda_codec_write(codec, codec->afg, 0,
+                       AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
+               snd_hda_codec_write_cache(codec, codec->afg, 0,
+                                         AC_VERB_SET_UNSOLICITED_ENABLE,
+                                         (AC_USRSP_EN | STAC_HP_EVENT));
+
+               spec->gpio_dir = 0x0b;
+               spec->gpio_mask = 0x1b;
+               spec->gpio_mute = 0x10;
+               /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
+                * GPIO3 Low = DRM
                 */
-               spec->gpio_data = 0x00000005;
+               spec->gpio_data = 0x01;
                break;
        default:
                /* GPIO0 High = EAPD */
-               spec->gpio_mask = spec->gpio_data = 0x00000001;
+               spec->gpio_mask = spec->gpio_dir = 0x1;
+               spec->gpio_data = 0x01;
                break;
        }