aboutsummaryrefslogtreecommitdiffstats
path: root/sound/pci/hda/patch_sigmatel.c
diff options
context:
space:
mode:
authorTakashi Iwai <tiwai@suse.de>2008-01-15 05:39:08 -0500
committerJaroslav Kysela <perex@perex.cz>2008-01-31 11:29:58 -0500
commit76e1ddfbdae590dd4580141b49c4b01f6fb12dab (patch)
tree68f5452f718133d5fdf25a9e5f1e280e4696c86f /sound/pci/hda/patch_sigmatel.c
parentbcd7200394bde40e3735054fc660b6f5012638b3 (diff)
[ALSA] hda-code - Clean up STAC GPIO enablement code
There are two similar GPIO-enablement codes in patch_sigmatel.c. Let's clean up. Signed-off-by: Takashi Iwai <tiwai@suse.de> Signed-off-by: Jaroslav Kysela <perex@perex.cz>
Diffstat (limited to 'sound/pci/hda/patch_sigmatel.c')
-rw-r--r--sound/pci/hda/patch_sigmatel.c56
1 files changed, 13 insertions, 43 deletions
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index c3496de387c5..1d643b9771a0 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -121,7 +121,6 @@ struct sigmatel_spec {
121 unsigned int mic_switch: 1; 121 unsigned int mic_switch: 1;
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 unsigned int gpio_mute: 1;
125 124
126 unsigned int gpio_mask, gpio_data; 125 unsigned int gpio_mask, gpio_data;
127 unsigned char aloopback_mask; 126 unsigned char aloopback_mask;
@@ -1681,22 +1680,6 @@ static void stac92xx_set_config_regs(struct hda_codec *codec)
1681 spec->pin_configs[i]); 1680 spec->pin_configs[i]);
1682} 1681}
1683 1682
1684static void stac92xx_enable_gpio_mask(struct hda_codec *codec)
1685{
1686 struct sigmatel_spec *spec = codec->spec;
1687 /* Configure GPIOx as output */
1688 snd_hda_codec_write_cache(codec, codec->afg, 0,
1689 AC_VERB_SET_GPIO_DIRECTION, spec->gpio_mask);
1690 /* Configure GPIOx as CMOS */
1691 snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7e7, 0x00000000);
1692 /* Assert GPIOx */
1693 snd_hda_codec_write_cache(codec, codec->afg, 0,
1694 AC_VERB_SET_GPIO_DATA, spec->gpio_data);
1695 /* Enable GPIOx */
1696 snd_hda_codec_write_cache(codec, codec->afg, 0,
1697 AC_VERB_SET_GPIO_MASK, spec->gpio_mask);
1698}
1699
1700/* 1683/*
1701 * Analog playback callbacks 1684 * Analog playback callbacks
1702 */ 1685 */
@@ -2678,38 +2661,35 @@ static int stac9200_parse_auto_config(struct hda_codec *codec)
2678 * funky external mute control using GPIO pins. 2661 * funky external mute control using GPIO pins.
2679 */ 2662 */
2680 2663
2681static void stac922x_gpio_mute(struct hda_codec *codec, int pin, int muted) 2664static void stac_gpio_set(struct hda_codec *codec, unsigned int mask,
2665 unsigned int data)
2682{ 2666{
2683 unsigned int gpiostate, gpiomask, gpiodir; 2667 unsigned int gpiostate, gpiomask, gpiodir;
2684 2668
2685 gpiostate = snd_hda_codec_read(codec, codec->afg, 0, 2669 gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
2686 AC_VERB_GET_GPIO_DATA, 0); 2670 AC_VERB_GET_GPIO_DATA, 0);
2687 2671 gpiostate = (gpiostate & ~mask) | (data & mask);
2688 if (!muted)
2689 gpiostate |= (1 << pin);
2690 else
2691 gpiostate &= ~(1 << pin);
2692 2672
2693 gpiomask = snd_hda_codec_read(codec, codec->afg, 0, 2673 gpiomask = snd_hda_codec_read(codec, codec->afg, 0,
2694 AC_VERB_GET_GPIO_MASK, 0); 2674 AC_VERB_GET_GPIO_MASK, 0);
2695 gpiomask |= (1 << pin); 2675 gpiomask |= mask;
2696 2676
2697 gpiodir = snd_hda_codec_read(codec, codec->afg, 0, 2677 gpiodir = snd_hda_codec_read(codec, codec->afg, 0,
2698 AC_VERB_GET_GPIO_DIRECTION, 0); 2678 AC_VERB_GET_GPIO_DIRECTION, 0);
2699 gpiodir |= (1 << pin); 2679 gpiodir |= mask;
2700 2680
2701 /* AppleHDA seems to do this -- WTF is this verb?? */ 2681 /* Configure GPIOx as CMOS */
2702 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0); 2682 snd_hda_codec_write(codec, codec->afg, 0, 0x7e7, 0);
2703 2683
2704 snd_hda_codec_write(codec, codec->afg, 0, 2684 snd_hda_codec_write(codec, codec->afg, 0,
2705 AC_VERB_SET_GPIO_MASK, gpiomask); 2685 AC_VERB_SET_GPIO_MASK, gpiomask);
2706 snd_hda_codec_write(codec, codec->afg, 0, 2686 snd_hda_codec_read(codec, codec->afg, 0,
2707 AC_VERB_SET_GPIO_DIRECTION, gpiodir); 2687 AC_VERB_SET_GPIO_DIRECTION, gpiodir); /* sync */
2708 2688
2709 msleep(1); 2689 msleep(1);
2710 2690
2711 snd_hda_codec_write(codec, codec->afg, 0, 2691 snd_hda_codec_read(codec, codec->afg, 0,
2712 AC_VERB_SET_GPIO_DATA, gpiostate); 2692 AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
2713} 2693}
2714 2694
2715static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid, 2695static void enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
@@ -2791,10 +2771,7 @@ static int stac92xx_init(struct hda_codec *codec)
2791 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin, 2771 stac92xx_auto_set_pinctl(codec, cfg->dig_in_pin,
2792 AC_PINCTL_IN_EN); 2772 AC_PINCTL_IN_EN);
2793 2773
2794 if (spec->gpio_mute) { 2774 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_data);
2795 stac922x_gpio_mute(codec, 0, 0);
2796 stac922x_gpio_mute(codec, 1, 0);
2797 }
2798 2775
2799 return 0; 2776 return 0;
2800} 2777}
@@ -2950,10 +2927,7 @@ static int stac92xx_resume(struct hda_codec *codec)
2950 2927
2951 stac92xx_set_config_regs(codec); 2928 stac92xx_set_config_regs(codec);
2952 snd_hda_sequence_write(codec, spec->init); 2929 snd_hda_sequence_write(codec, spec->init);
2953 if (spec->gpio_mute) { 2930 stac_gpio_set(codec, spec->gpio_mask, spec->gpio_data);
2954 stac922x_gpio_mute(codec, 0, 0);
2955 stac922x_gpio_mute(codec, 1, 0);
2956 }
2957 snd_hda_codec_resume_amp(codec); 2931 snd_hda_codec_resume_amp(codec);
2958 snd_hda_codec_resume_cache(codec); 2932 snd_hda_codec_resume_cache(codec);
2959 /* invoke unsolicited event to reset the HP state */ 2933 /* invoke unsolicited event to reset the HP state */
@@ -3188,7 +3162,6 @@ again:
3188 spec->dinput_mux = &stac92hd73xx_dmux; 3162 spec->dinput_mux = &stac92hd73xx_dmux;
3189 /* GPIO0 High = Enable EAPD */ 3163 /* GPIO0 High = Enable EAPD */
3190 spec->gpio_mask = spec->gpio_data = 0x000001; 3164 spec->gpio_mask = spec->gpio_data = 0x000001;
3191 stac92xx_enable_gpio_mask(codec);
3192 3165
3193 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids); 3166 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
3194 spec->pwr_nids = stac92hd73xx_pwr_nids; 3167 spec->pwr_nids = stac92hd73xx_pwr_nids;
@@ -3263,7 +3236,6 @@ again:
3263 spec->aloopback_shift = 0; 3236 spec->aloopback_shift = 0;
3264 3237
3265 spec->gpio_mask = spec->gpio_data = 0x00000001; /* GPIO0 High = EAPD */ 3238 spec->gpio_mask = spec->gpio_data = 0x00000001; /* GPIO0 High = EAPD */
3266 stac92xx_enable_gpio_mask(codec);
3267 3239
3268 spec->mux_nids = stac92hd71bxx_mux_nids; 3240 spec->mux_nids = stac92hd71bxx_mux_nids;
3269 spec->adc_nids = stac92hd71bxx_adc_nids; 3241 spec->adc_nids = stac92hd71bxx_adc_nids;
@@ -3319,7 +3291,7 @@ static int patch_stac922x(struct hda_codec *codec)
3319 stac922x_models, 3291 stac922x_models,
3320 stac922x_cfg_tbl); 3292 stac922x_cfg_tbl);
3321 if (spec->board_config == STAC_INTEL_MAC_V3) { 3293 if (spec->board_config == STAC_INTEL_MAC_V3) {
3322 spec->gpio_mute = 1; 3294 spec->gpio_mask = spec->gpio_data = 0x03;
3323 /* Intel Macs have all same PCI SSID, so we need to check 3295 /* Intel Macs have all same PCI SSID, so we need to check
3324 * codec SSID to distinguish the exact models 3296 * codec SSID to distinguish the exact models
3325 */ 3297 */
@@ -3483,7 +3455,6 @@ static int patch_stac927x(struct hda_codec *codec)
3483 spec->aloopback_mask = 0x40; 3455 spec->aloopback_mask = 0x40;
3484 spec->aloopback_shift = 0; 3456 spec->aloopback_shift = 0;
3485 3457
3486 stac92xx_enable_gpio_mask(codec);
3487 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20); 3458 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
3488 if (!err) { 3459 if (!err) {
3489 if (spec->board_config < 0) { 3460 if (spec->board_config < 0) {
@@ -3568,7 +3539,6 @@ static int patch_stac9205(struct hda_codec *codec)
3568 break; 3539 break;
3569 } 3540 }
3570 3541
3571 stac92xx_enable_gpio_mask(codec);
3572 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20); 3542 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
3573 if (!err) { 3543 if (!err) {
3574 if (spec->board_config < 0) { 3544 if (spec->board_config < 0) {