aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMatthew Ranostay <mranostay@embeddedalley.com>2008-01-29 09:28:44 -0500
committerJaroslav Kysela <perex@perex.cz>2008-01-31 11:30:22 -0500
commit4fe5195c46f4303ca295f7e4350fb45a2aa6cff2 (patch)
tree7d3a5537dc5f6ee2b134f14e055690ee21f9d976
parent0aaa22e554c0934625faf79deea42bfecbdbc23d (diff)
[ALSA] hda: Add GPIO mute support to STAC9205
Support added for detecting HP jack presence via GPIO on several laptop docks. Signed-off-by: Matthew Ranostay <mranostay@embeddedalley.com> Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
-rw-r--r--sound/pci/hda/patch_sigmatel.c62
1 files changed, 45 insertions, 17 deletions
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index 46c237b0e694..7c8cd59852ec 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -122,7 +122,13 @@ struct sigmatel_spec {
122 unsigned int alt_switch: 1; 122 unsigned int alt_switch: 1;
123 unsigned int hp_detect: 1; 123 unsigned int hp_detect: 1;
124 124
125 unsigned int gpio_mask, gpio_data; 125 /* gpio lines */
126 unsigned int gpio_mask;
127 unsigned int gpio_dir;
128 unsigned int gpio_data;
129 unsigned int gpio_mute;
130
131 /* analog loopback */
126 unsigned char aloopback_mask; 132 unsigned char aloopback_mask;
127 unsigned char aloopback_shift; 133 unsigned char aloopback_shift;
128 134
@@ -2803,13 +2809,13 @@ static int stac9200_parse_auto_config(struct hda_codec *codec)
2803 */ 2809 */
2804 2810
2805static void stac_gpio_set(struct hda_codec *codec, unsigned int mask, 2811static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
2806 unsigned int data) 2812 unsigned int dir_mask, unsigned int data)
2807{ 2813{
2808 unsigned int gpiostate, gpiomask, gpiodir; 2814 unsigned int gpiostate, gpiomask, gpiodir;
2809 2815
2810 gpiostate = snd_hda_codec_read(codec, codec->afg, 0, 2816 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2811 AC_VERB_GET_GPIO_DATA, 0); 2817 AC_VERB_GET_GPIO_DATA, 0);
2812 gpiostate = (gpiostate & ~mask) | (data & mask); 2818 gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
2813 2819
2814 gpiomask = snd_hda_codec_read(codec, codec->afg, 0, 2820 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2815 AC_VERB_GET_GPIO_MASK, 0); 2821 AC_VERB_GET_GPIO_MASK, 0);
@@ -2817,7 +2823,7 @@ static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
2817 2823
2818 gpiodir = snd_hda_codec_read(codec, codec->afg, 0, 2824 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2819 AC_VERB_GET_GPIO_DIRECTION, 0); 2825 AC_VERB_GET_GPIO_DIRECTION, 0);
2820 gpiodir |= mask; 2826 gpiodir |= dir_mask;
2821 2827
2822 /* Configure GPIOx as CMOS */ 2828 /* Configure GPIOx as CMOS */
2823 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0); 2829 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
@@ -2912,7 +2918,8 @@ static int stac92xx_init(struct hda_codec *codec)
2912 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin, 2918 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
2913 AC_PINCTL_IN_EN); 2919 AC_PINCTL_IN_EN);
2914 2920
2915 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_data); 2921 stac_gpio_set(codec, spec->gpio_mask,
2922 spec->gpio_dir, spec->gpio_data);
2916 2923
2917 return 0; 2924 return 0;
2918} 2925}
@@ -3002,10 +3009,14 @@ static void stac92xx_hp_detect(struct hda_codec *codec, unsigned int res)
3002 int i, presence; 3009 int i, presence;
3003 3010
3004 presence = 0; 3011 presence = 0;
3012 if (spec->gpio_mute)
3013 presence = !(snd_hda_codec_read(codec, codec->afg, 0,
3014 AC_VERB_GET_GPIO_DATA, 0) & spec->gpio_mute);
3015
3005 for (i = 0; i < cfg->hp_outs; i++) { 3016 for (i = 0; i < cfg->hp_outs; i++) {
3006 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
3007 if (presence) 3017 if (presence)
3008 break; 3018 break;
3019 presence = get_hp_pin_presence(codec, cfg->hp_pins[i]);
3009 } 3020 }
3010 3021
3011 if (presence) { 3022 if (presence) {
@@ -3068,7 +3079,8 @@ static int stac92xx_resume(struct hda_codec *codec)
3068 3079
3069 stac92xx_set_config_regs(codec); 3080 stac92xx_set_config_regs(codec);
3070 snd_hda_sequence_write(codec, spec->init); 3081 snd_hda_sequence_write(codec, spec->init);
3071 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_data); 3082 stac_gpio_set(codec, spec->gpio_mask,
3083 spec->gpio_dir, spec->gpio_data);
3072 snd_hda_codec_resume_amp(codec); 3084 snd_hda_codec_resume_amp(codec);
3073 snd_hda_codec_resume_cache(codec); 3085 snd_hda_codec_resume_cache(codec);
3074 /* invoke unsolicited event to reset the HP state */ 3086 /* invoke unsolicited event to reset the HP state */
@@ -3302,7 +3314,8 @@ again:
3302 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids); 3314 spec->num_dmuxes = ARRAY_SIZE(stac92hd73xx_dmux_nids);
3303 spec->dinput_mux = &stac92hd73xx_dmux; 3315 spec->dinput_mux = &stac92hd73xx_dmux;
3304 /* GPIO0 High = Enable EAPD */ 3316 /* GPIO0 High = Enable EAPD */
3305 spec->gpio_mask = spec->gpio_data = 0x000001; 3317 spec->gpio_mask = spec->gpio_dir = 0x1;
3318 spec->gpio_data = 0x01;
3306 3319
3307 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids); 3320 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
3308 spec->pwr_nids = stac92hd73xx_pwr_nids; 3321 spec->pwr_nids = stac92hd73xx_pwr_nids;
@@ -3376,7 +3389,8 @@ again:
3376 spec->aloopback_mask = 0x20; 3389 spec->aloopback_mask = 0x20;
3377 spec->aloopback_shift = 0; 3390 spec->aloopback_shift = 0;
3378 3391
3379 spec->gpio_mask = spec->gpio_data = 0x00000001; /* GPIO0 High = EAPD */ 3392 /* GPIO0 High = EAPD */
3393 spec->gpio_mask = spec->gpio_dir = spec->gpio_data = 0x1;
3380 3394
3381 spec->mux_nids = stac92hd71bxx_mux_nids; 3395 spec->mux_nids = stac92hd71bxx_mux_nids;
3382 spec->adc_nids = stac92hd71bxx_adc_nids; 3396 spec->adc_nids = stac92hd71bxx_adc_nids;
@@ -3432,7 +3446,8 @@ static int patch_stac922x(struct hda_codec *codec)
3432 stac922x_models, 3446 stac922x_models,
3433 stac922x_cfg_tbl); 3447 stac922x_cfg_tbl);
3434 if (spec->board_config == STAC_INTEL_MAC_V3) { 3448 if (spec->board_config == STAC_INTEL_MAC_V3) {
3435 spec->gpio_mask = spec->gpio_data = 0x03; 3449 spec->gpio_mask = spec->gpio_dir = 0x03;
3450 spec->gpio_data = 0x03;
3436 /* Intel Macs have all same PCI SSID, so we need to check 3451 /* Intel Macs have all same PCI SSID, so we need to check
3437 * codec SSID to distinguish the exact models 3452 * codec SSID to distinguish the exact models
3438 */ 3453 */
@@ -3560,7 +3575,8 @@ static int patch_stac927x(struct hda_codec *codec)
3560 case STAC_D965_3ST: 3575 case STAC_D965_3ST:
3561 case STAC_D965_5ST: 3576 case STAC_D965_5ST:
3562 /* GPIO0 High = Enable EAPD */ 3577 /* GPIO0 High = Enable EAPD */
3563 spec->gpio_mask = spec->gpio_data = 0x00000001; 3578 spec->gpio_mask = spec->gpio_dir = 0x01;
3579 spec->gpio_data = 0x01;
3564 spec->num_dmics = 0; 3580 spec->num_dmics = 0;
3565 3581
3566 spec->init = d965_core_init; 3582 spec->init = d965_core_init;
@@ -3574,7 +3590,8 @@ static int patch_stac927x(struct hda_codec *codec)
3574 /* fallthru */ 3590 /* fallthru */
3575 case STAC_DELL_3ST: 3591 case STAC_DELL_3ST:
3576 /* GPIO2 High = Enable EAPD */ 3592 /* GPIO2 High = Enable EAPD */
3577 spec->gpio_mask = spec->gpio_data = 0x00000004; 3593 spec->gpio_mask = spec->gpio_dir = 0x04;
3594 spec->gpio_data = 0x04;
3578 spec->dmic_nids = stac927x_dmic_nids; 3595 spec->dmic_nids = stac927x_dmic_nids;
3579 spec->num_dmics = STAC927X_NUM_DMICS; 3596 spec->num_dmics = STAC927X_NUM_DMICS;
3580 3597
@@ -3585,7 +3602,8 @@ static int patch_stac927x(struct hda_codec *codec)
3585 break; 3602 break;
3586 default: 3603 default:
3587 /* GPIO0 High = Enable EAPD */ 3604 /* GPIO0 High = Enable EAPD */
3588 spec->gpio_mask = spec->gpio_data = 0x00000001; 3605 spec->gpio_mask = spec->gpio_dir = 0x1;
3606 spec->gpio_data = 0x01;
3589 spec->num_dmics = 0; 3607 spec->num_dmics = 0;
3590 3608
3591 spec->init = stac927x_core_init; 3609 spec->init = stac927x_core_init;
@@ -3680,15 +3698,25 @@ static int patch_stac9205(struct hda_codec *codec)
3680 stac92xx_set_config_reg(codec, 0x1f, 0x01441030); 3698 stac92xx_set_config_reg(codec, 0x1f, 0x01441030);
3681 stac92xx_set_config_reg(codec, 0x20, 0x1c410030); 3699 stac92xx_set_config_reg(codec, 0x20, 0x1c410030);
3682 3700
3683 spec->gpio_mask = 0x0000000b; 3701 /* Enable unsol response for GPIO4/Dock HP connection */
3702 snd_hda_codec_write(codec, codec->afg, 0,
3703 AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
3704 snd_hda_codec_write_cache(codec, codec->afg, 0,
3705 AC_VERB_SET_UNSOLICITED_ENABLE,
3706 (AC_USRSP_EN | STAC_HP_EVENT));
3707
3708 spec->gpio_dir = 0x0b;
3709 spec->gpio_mask = 0x1b;
3710 spec->gpio_mute = 0x10;
3684 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute, 3711 /* GPIO0 High = EAPD, GPIO1 Low = Headphone Mute,
3685 * GPIO3 High = DRM 3712 * GPIO3 Low = DRM
3686 */ 3713 */
3687 spec->gpio_data = 0x00000009; 3714 spec->gpio_data = 0x01;
3688 break; 3715 break;
3689 default: 3716 default:
3690 /* GPIO0 High = EAPD */ 3717 /* GPIO0 High = EAPD */
3691 spec->gpio_mask = spec->gpio_data = 0x00000001; 3718 spec->gpio_mask = spec->gpio_dir = 0x1;
3719 spec->gpio_data = 0x01;
3692 break; 3720 break;
3693 } 3721 }
3694 3722