~ubuntu-branches/ubuntu/trusty/linux-armadaxp/trusty

« back to all changes in this revision

Viewing changes to sound/pci/hda/patch_sigmatel.c

  • Committer: Package Import Robot
  • Author(s): Michael Casadevall, Bryan Wu, Dann Frazier, Michael Casadeall
  • Date: 2012-03-10 15:00:54 UTC
  • mfrom: (1.1.1)
  • Revision ID: package-import@ubuntu.com-20120310150054-flugb39zon8vvgwe
Tags: 3.2.0-1600.1
[ Bryan Wu ]
* UBUNTU: import debian/debian.env and debian.armadaxp

[ Dann Frazier ]
* ARM: Armada XP: remove trailing '/' in dirnames in mvRules.mk

[ Michael Casadeall ]
* tools: add some tools for Marvell Armada XP processor
* kernel: timer tick hacking from Marvell
* kernel: Sheeva Errata: add delay on Sheeva when powering down
* net: add Marvell NFP netfilter
* net: socket and skb modifications made by Marvell
* miscdevice: add minor IDs for some Marvell Armada drivers
* fs: introduce memory pool for splice()
* video: EDID detection updates from Marvell Armada XP patchset
* video: backlight: add Marvell Dove LCD backlight driver
* video: display: add THS8200 display driver
* video: framebuffer: add Marvell Dove and Armada XP processor onchip LCD controller driver
* usbtest: add Interrupt transfer testing by Marvell Armada XP code
* usb: ehci: add support for Marvell EHCI controler
* tty/serial: 8250: add support for Marvell Armada XP processor and DeviceTree work
* rtc: add support for Marvell Armada XP onchip RTC controller
* net: pppoe: add Marvell ethernet NFP hook in PPPoE networking driver
* mtd: nand: add support for Marvell Armada XP Nand Flash Controller
* mtd: maps: add Marvell Armada XP specific map driver
* mmc: add support for Marvell Armada XP MMC/SD host controller
* i2c: add support for Marvell Armada XP onchip i2c bus controller
* hwmon: add Kconfig option for Armada XP onchip thermal sensor driver
* dmaengine: add Net DMA support for splice and update Marvell XOR DMA engine driver
* ata: add support for Marvell Armada XP SATA controller and update some quirks
* ARM: add Marvell Armada XP machine to mach-types
* ARM: oprofile: add support for Marvell PJ4B core
* ARM: mm: more ARMv6 switches for Marvell Armada XP
* ARM: remove static declaration to allow compilation
* ARM: alignment access fault trick
* ARM: mm: skip some fault fixing when run on NONE SMP ARMv6 mode during early abort event
* ARM: mm: add Marvell Sheeva CPU Architecture for PJ4B
* ARM: introduce optimized copy operation for Marvell Armada XP
* ARM: SAUCE: hardware breakpoint trick for Marvell Armada XP
* ARM: big endian and little endian tricks for Marvell Armada XP
* ARM: SAUCE: Add Marvell Armada XP build rules to arch/arm/kernel/Makefile
* ARM: vfp: add special handling for Marvell Armada XP
* ARM: add support for Marvell U-Boot
* ARM: add mv_controller_num for ARM PCI drivers
* ARM: add support for local PMUs, general SMP tweaks and cache flushing
* ARM: add Marvell device identifies in glue-proc.h
* ARM: add IPC driver support for Marvell platforms
* ARM: add DMA mapping for Marvell platforms
* ARM: add Sheeva errata and PJ4B code for booting
* ARM: update Kconfig and Makefile to include Marvell Armada XP platforms
* ARM: Armada XP: import LSP from Marvell for Armada XP 3.2 kernel enablement

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
#include <linux/slab.h>
30
30
#include <linux/pci.h>
31
31
#include <linux/dmi.h>
 
32
#include <linux/module.h>
32
33
#include <sound/core.h>
33
34
#include <sound/asoundef.h>
34
35
#include <sound/jack.h>
36
37
#include "hda_codec.h"
37
38
#include "hda_local.h"
38
39
#include "hda_beep.h"
 
40
#include "hda_jack.h"
39
41
 
40
42
enum {
41
43
        STAC_VREF_EVENT = 1,
94
96
        STAC_92HD83XXX_REF,
95
97
        STAC_92HD83XXX_PWR_REF,
96
98
        STAC_DELL_S14,
 
99
        STAC_DELL_VOSTRO_3500,
97
100
        STAC_92HD83XXX_HP,
 
101
        STAC_92HD83XXX_HP_cNB11_INTQUAD,
98
102
        STAC_HP_DV7_4000,
99
103
        STAC_92HD83XXX_MODELS
100
104
};
173
177
        STAC_9872_MODELS
174
178
};
175
179
 
176
 
struct sigmatel_event {
177
 
        hda_nid_t nid;
178
 
        unsigned char type;
179
 
        unsigned char tag;
180
 
        int data;
181
 
};
182
 
 
183
180
struct sigmatel_mic_route {
184
181
        hda_nid_t pin;
185
182
        signed char mux_idx;
212
209
        unsigned int gpio_mute;
213
210
        unsigned int gpio_led;
214
211
        unsigned int gpio_led_polarity;
 
212
        unsigned int vref_mute_led_nid; /* pin NID for mute-LED vref control */
 
213
        unsigned int vref_led;
215
214
 
216
215
        /* stream */
217
216
        unsigned int stream_delay;
223
222
 
224
223
        /* power management */
225
224
        unsigned int num_pwrs;
226
 
        const unsigned int *pwr_mapping;
227
225
        const hda_nid_t *pwr_nids;
228
226
        const hda_nid_t *dac_list;
229
227
 
230
 
        /* events */
231
 
        struct snd_array events;
232
 
 
233
228
        /* playback */
234
229
        struct hda_input_mux *mono_mux;
235
230
        unsigned int cur_mmux;
370
365
 
371
366
#define STAC92HD83_DAC_COUNT 3
372
367
 
373
 
static const hda_nid_t stac92hd83xxx_pwr_nids[4] = {
374
 
        0xa, 0xb, 0xd, 0xe,
 
368
static const hda_nid_t stac92hd83xxx_pwr_nids[7] = {
 
369
        0x0a, 0x0b, 0x0c, 0xd, 0x0e,
 
370
        0x0f, 0x10
375
371
};
376
372
 
377
373
static const hda_nid_t stac92hd83xxx_slave_dig_outs[2] = {
378
374
        0x1e, 0,
379
375
};
380
376
 
381
 
static const unsigned int stac92hd83xxx_pwr_mapping[4] = {
382
 
        0x03, 0x0c, 0x20, 0x40,
383
 
};
384
 
 
385
377
static const hda_nid_t stac92hd83xxx_dmic_nids[] = {
386
378
                0x11, 0x20,
387
379
};
671
663
        return 0;
672
664
}
673
665
 
 
666
#ifdef CONFIG_SND_HDA_POWER_SAVE
 
667
static int stac_vrefout_set(struct hda_codec *codec,
 
668
                                        hda_nid_t nid, unsigned int new_vref)
 
669
{
 
670
        int error, pinctl;
 
671
 
 
672
        snd_printdd("%s, nid %x ctl %x\n", __func__, nid, new_vref);
 
673
        pinctl = snd_hda_codec_read(codec, nid, 0,
 
674
                                AC_VERB_GET_PIN_WIDGET_CONTROL, 0);
 
675
 
 
676
        if (pinctl < 0)
 
677
                return pinctl;
 
678
 
 
679
        pinctl &= 0xff;
 
680
        pinctl &= ~AC_PINCTL_VREFEN;
 
681
        pinctl |= (new_vref & AC_PINCTL_VREFEN);
 
682
 
 
683
        error = snd_hda_codec_write_cache(codec, nid, 0,
 
684
                                        AC_VERB_SET_PIN_WIDGET_CONTROL, pinctl);
 
685
        if (error < 0)
 
686
                return error;
 
687
 
 
688
        return 1;
 
689
}
 
690
#endif
 
691
 
674
692
static unsigned int stac92xx_vref_set(struct hda_codec *codec,
675
693
                                        hda_nid_t nid, unsigned int new_vref)
676
694
{
1067
1085
};
1068
1086
 
1069
1087
static void stac92xx_free_kctls(struct hda_codec *codec);
1070
 
static int stac92xx_add_jack(struct hda_codec *codec, hda_nid_t nid, int type);
1071
1088
 
1072
1089
static int stac92xx_build_controls(struct hda_codec *codec)
1073
1090
{
1074
1091
        struct sigmatel_spec *spec = codec->spec;
1075
 
        struct auto_pin_cfg *cfg = &spec->autocfg;
1076
 
        hda_nid_t nid;
1077
1092
        int err;
1078
1093
        int i;
1079
1094
 
1112
1127
        }
1113
1128
 
1114
1129
        if (spec->multiout.dig_out_nid) {
1115
 
                err = snd_hda_create_spdif_out_ctls(codec, spec->multiout.dig_out_nid);
 
1130
                err = snd_hda_create_spdif_out_ctls(codec,
 
1131
                                                    spec->multiout.dig_out_nid,
 
1132
                                                    spec->multiout.dig_out_nid);
1116
1133
                if (err < 0)
1117
1134
                        return err;
1118
1135
                err = snd_hda_create_spdif_share_sw(codec,
1157
1174
 
1158
1175
        stac92xx_free_kctls(codec); /* no longer needed */
1159
1176
 
1160
 
        /* create jack input elements */
1161
 
        if (spec->hp_detect) {
1162
 
                for (i = 0; i < cfg->hp_outs; i++) {
1163
 
                        int type = SND_JACK_HEADPHONE;
1164
 
                        nid = cfg->hp_pins[i];
1165
 
                        /* jack detection */
1166
 
                        if (cfg->hp_outs == i)
1167
 
                                type |= SND_JACK_LINEOUT;
1168
 
                        err = stac92xx_add_jack(codec, nid, type);
1169
 
                        if (err < 0)
1170
 
                                return err;
1171
 
                }
1172
 
        }
1173
 
        for (i = 0; i < cfg->line_outs; i++) {
1174
 
                err = stac92xx_add_jack(codec, cfg->line_out_pins[i],
1175
 
                                        SND_JACK_LINEOUT);
1176
 
                if (err < 0)
1177
 
                        return err;
1178
 
        }
1179
 
        for (i = 0; i < cfg->num_inputs; i++) {
1180
 
                nid = cfg->inputs[i].pin;
1181
 
                err = stac92xx_add_jack(codec, nid, SND_JACK_MICROPHONE);
1182
 
                if (err < 0)
1183
 
                        return err;
1184
 
        }
 
1177
        err = snd_hda_jack_add_kctls(codec, &spec->autocfg);
 
1178
        if (err < 0)
 
1179
                return err;
1185
1180
 
1186
1181
        return 0;       
1187
1182
}
1602
1597
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02bd,
1603
1598
                                "Dell Studio 1557", STAC_DELL_M6_DMIC),
1604
1599
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02fe,
1605
 
                                "Dell Studio XPS 1645", STAC_DELL_M6_BOTH),
 
1600
                                "Dell Studio XPS 1645", STAC_DELL_M6_DMIC),
1606
1601
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0413,
1607
1602
                                "Dell Studio 1558", STAC_DELL_M6_DMIC),
1608
1603
        {} /* terminator */
1613
1608
                      "Alienware M17x", STAC_ALIENWARE_M17X),
1614
1609
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x043a,
1615
1610
                      "Alienware M17x", STAC_ALIENWARE_M17X),
 
1611
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x0490,
 
1612
                      "Alienware M17x", STAC_ALIENWARE_M17X),
1616
1613
        {} /* terminator */
1617
1614
};
1618
1615
 
1628
1625
        0x40f000f0, 0x40f000f0,
1629
1626
};
1630
1627
 
 
1628
static const unsigned int dell_vostro_3500_pin_configs[10] = {
 
1629
        0x02a11020, 0x0221101f, 0x400000f0, 0x90170110,
 
1630
        0x400000f1, 0x400000f2, 0x400000f3, 0x90a60160,
 
1631
        0x400000f4, 0x400000f5,
 
1632
};
 
1633
 
1631
1634
static const unsigned int hp_dv7_4000_pin_configs[10] = {
1632
1635
        0x03a12050, 0x0321201f, 0x40f000f0, 0x90170110,
1633
1636
        0x40f000f0, 0x40f000f0, 0x90170110, 0xd5a30140,
1634
1637
        0x40f000f0, 0x40f000f0,
1635
1638
};
1636
1639
 
 
1640
static const unsigned int hp_cNB11_intquad_pin_configs[10] = {
 
1641
        0x40f000f0, 0x0221101f, 0x02a11020, 0x92170110,
 
1642
        0x40f000f0, 0x92170110, 0x40f000f0, 0xd5a30130,
 
1643
        0x40f000f0, 0x40f000f0,
 
1644
};
 
1645
 
1637
1646
static const unsigned int *stac92hd83xxx_brd_tbl[STAC_92HD83XXX_MODELS] = {
1638
1647
        [STAC_92HD83XXX_REF] = ref92hd83xxx_pin_configs,
1639
1648
        [STAC_92HD83XXX_PWR_REF] = ref92hd83xxx_pin_configs,
1640
1649
        [STAC_DELL_S14] = dell_s14_pin_configs,
 
1650
        [STAC_DELL_VOSTRO_3500] = dell_vostro_3500_pin_configs,
 
1651
        [STAC_92HD83XXX_HP_cNB11_INTQUAD] = hp_cNB11_intquad_pin_configs,
1641
1652
        [STAC_HP_DV7_4000] = hp_dv7_4000_pin_configs,
1642
1653
};
1643
1654
 
1646
1657
        [STAC_92HD83XXX_REF] = "ref",
1647
1658
        [STAC_92HD83XXX_PWR_REF] = "mic-ref",
1648
1659
        [STAC_DELL_S14] = "dell-s14",
 
1660
        [STAC_DELL_VOSTRO_3500] = "dell-vostro-3500",
1649
1661
        [STAC_92HD83XXX_HP] = "hp",
 
1662
        [STAC_92HD83XXX_HP_cNB11_INTQUAD] = "hp_cNB11_intquad",
1650
1663
        [STAC_HP_DV7_4000] = "hp-dv7-4000",
1651
1664
};
1652
1665
 
1658
1671
                      "DFI LanParty", STAC_92HD83XXX_REF),
1659
1672
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x02ba,
1660
1673
                      "unknown Dell", STAC_DELL_S14),
 
1674
        SND_PCI_QUIRK(PCI_VENDOR_ID_DELL, 0x1028,
 
1675
                      "Dell Vostro 3500", STAC_DELL_VOSTRO_3500),
1661
1676
        SND_PCI_QUIRK_MASK(PCI_VENDOR_ID_HP, 0xff00, 0x3600,
1662
 
                      "HP", STAC_92HD83XXX_HP),
 
1677
                          "HP", STAC_92HD83XXX_HP),
 
1678
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1656,
 
1679
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1680
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1657,
 
1681
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1682
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1658,
 
1683
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1684
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x1659,
 
1685
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1686
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165A,
 
1687
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1688
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x165B,
 
1689
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1690
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3388,
 
1691
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1692
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3389,
 
1693
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1694
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355B,
 
1695
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1696
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355C,
 
1697
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1698
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355D,
 
1699
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1700
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355E,
 
1701
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1702
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x355F,
 
1703
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1704
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3560,
 
1705
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1706
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358B,
 
1707
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1708
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358C,
 
1709
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1710
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x358D,
 
1711
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1712
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3591,
 
1713
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1714
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3592,
 
1715
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
 
1716
        SND_PCI_QUIRK(PCI_VENDOR_ID_HP, 0x3593,
 
1717
                          "HP", STAC_92HD83XXX_HP_cNB11_INTQUAD),
1663
1718
        {} /* terminator */
1664
1719
};
1665
1720
 
2786
2841
        }
2787
2842
 
2788
2843
        if (control) {
2789
 
                strcpy(name, hda_get_input_pin_label(codec, nid, 1));
 
2844
                snd_hda_get_pin_label(codec, nid, &spec->autocfg,
 
2845
                                      name, sizeof(name), NULL);
2790
2846
                return stac92xx_add_control(codec->spec, control,
2791
2847
                                        strcat(name, " Jack Mode"), nid);
2792
2848
        }
2894
2950
static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2895
2951
{
2896
2952
        struct sigmatel_spec *spec = codec->spec;
 
2953
        struct auto_pin_cfg *cfg = &spec->autocfg;
2897
2954
        int j, conn_len;
2898
 
        hda_nid_t conn[HDA_MAX_CONNECTIONS];
 
2955
        hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
2899
2956
        unsigned int wcaps, wtype;
2900
2957
 
2901
2958
        conn_len = snd_hda_get_connections(codec, nid, conn,
2923
2980
                        return conn[j];
2924
2981
                }
2925
2982
        }
2926
 
        /* if all DACs are already assigned, connect to the primary DAC */
 
2983
 
 
2984
        /* if all DACs are already assigned, connect to the primary DAC,
 
2985
           unless we're assigning a secondary headphone */
 
2986
        fallback_dac = spec->multiout.dac_nids[0];
 
2987
        if (spec->multiout.hp_nid) {
 
2988
                for (j = 0; j < cfg->hp_outs; j++)
 
2989
                        if (cfg->hp_pins[j] == nid) {
 
2990
                                fallback_dac = spec->multiout.hp_nid;
 
2991
                                break;
 
2992
                        }
 
2993
        }
 
2994
 
2927
2995
        if (conn_len > 1) {
2928
2996
                for (j = 0; j < conn_len; j++) {
2929
 
                        if (conn[j] == spec->multiout.dac_nids[0]) {
 
2997
                        if (conn[j] == fallback_dac) {
2930
2998
                                snd_hda_codec_write_cache(codec, nid, 0,
2931
2999
                                                  AC_VERB_SET_CONNECT_SEL, j);
2932
3000
                                break;
3406
3474
        return 0;
3407
3475
}
3408
3476
 
3409
 
static int get_connection_index(struct hda_codec *codec, hda_nid_t mux,
3410
 
                                hda_nid_t nid)
3411
 
{
3412
 
        hda_nid_t conn[HDA_MAX_NUM_INPUTS];
3413
 
        int i, nums;
3414
 
 
3415
 
        if (!(get_wcaps(codec, mux) & AC_WCAP_CONN_LIST))
3416
 
                return -1;
3417
 
 
3418
 
        nums = snd_hda_get_connections(codec, mux, conn, ARRAY_SIZE(conn));
3419
 
        for (i = 0; i < nums; i++)
3420
 
                if (conn[i] == nid)
3421
 
                        return i;
3422
 
 
3423
 
        for (i = 0; i < nums; i++) {
3424
 
                unsigned int wid_caps = get_wcaps(codec, conn[i]);
3425
 
                unsigned int wid_type = get_wcaps_type(wid_caps);
3426
 
 
3427
 
                if (wid_type != AC_WID_PIN && wid_type != AC_WID_AUD_MIX)
3428
 
                        if (get_connection_index(codec, conn[i], nid) >= 0)
3429
 
                                return i;
3430
 
        }
3431
 
        return -1;
3432
 
}
 
3477
/* look for NID recursively */
 
3478
#define get_connection_index(codec, mux, nid) \
 
3479
        snd_hda_get_conn_index(codec, mux, nid, 1)
3433
3480
 
3434
3481
/* create a volume assigned to the given pin (only if supported) */
3435
3482
/* return 1 if the volume control is created */
3473
3520
        for (i = 0; i < spec->num_dmics; i++) {
3474
3521
                hda_nid_t nid;
3475
3522
                int index, type_idx;
3476
 
                const char *label;
 
3523
                char label[32];
3477
3524
 
3478
3525
                nid = spec->dmic_nids[i];
3479
3526
                if (get_wcaps_type(get_wcaps(codec, nid)) != AC_WID_PIN)
3486
3533
                if (index < 0)
3487
3534
                        continue;
3488
3535
 
3489
 
                label = hda_get_input_pin_label(codec, nid, 1);
 
3536
                snd_hda_get_pin_label(codec, nid, &spec->autocfg,
 
3537
                                      label, sizeof(label), NULL);
3490
3538
                snd_hda_add_imux_item(dimux, label, index, &type_idx);
3491
3539
                if (snd_hda_get_bool_hint(codec, "separate_dmux") != 1)
3492
3540
                        snd_hda_add_imux_item(imux, label, index, &type_idx);
3722
3770
}
3723
3771
 
3724
3772
 
3725
 
static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in)
 
3773
static int stac92xx_parse_auto_config(struct hda_codec *codec)
3726
3774
{
3727
3775
        struct sigmatel_spec *spec = codec->spec;
 
3776
        hda_nid_t dig_out = 0, dig_in = 0;
3728
3777
        int hp_swap = 0;
3729
3778
        int i, err;
3730
3779
 
3907
3956
        if (spec->multiout.max_channels > 2)
3908
3957
                spec->surr_switch = 1;
3909
3958
 
 
3959
        /* find digital out and in converters */
 
3960
        for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
 
3961
                unsigned int wid_caps = get_wcaps(codec, i);
 
3962
                if (wid_caps & AC_WCAP_DIGITAL) {
 
3963
                        switch (get_wcaps_type(wid_caps)) {
 
3964
                        case AC_WID_AUD_OUT:
 
3965
                                if (!dig_out)
 
3966
                                        dig_out = i;
 
3967
                                break;
 
3968
                        case AC_WID_AUD_IN:
 
3969
                                if (!dig_in)
 
3970
                                        dig_in = i;
 
3971
                                break;
 
3972
                        }
 
3973
                }
 
3974
        }
3910
3975
        if (spec->autocfg.dig_outs)
3911
3976
                spec->multiout.dig_out_nid = dig_out;
3912
3977
        if (dig_in && spec->autocfg.dig_in_pin)
4039
4104
{
4040
4105
        unsigned int gpiostate, gpiomask, gpiodir;
4041
4106
 
 
4107
        snd_printdd("%s msk %x dir %x gpio %x\n", __func__, mask, dir_mask, data);
 
4108
 
4042
4109
        gpiostate = snd_hda_codec_read(codec, codec->afg, 0,
4043
4110
                                       AC_VERB_GET_GPIO_DATA, 0);
4044
4111
        gpiostate = (gpiostate & ~dir_mask) | (data & dir_mask);
4065
4132
                           AC_VERB_SET_GPIO_DATA, gpiostate); /* sync */
4066
4133
}
4067
4134
 
4068
 
static int stac92xx_add_jack(struct hda_codec *codec,
4069
 
                hda_nid_t nid, int type)
4070
 
{
4071
 
#ifdef CONFIG_SND_HDA_INPUT_JACK
4072
 
        int def_conf = snd_hda_codec_get_pincfg(codec, nid);
4073
 
        int connectivity = get_defcfg_connect(def_conf);
4074
 
        char name[32];
4075
 
        int err;
4076
 
 
4077
 
        if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4078
 
                return 0;
4079
 
 
4080
 
        snprintf(name, sizeof(name), "%s at %s %s Jack",
4081
 
                snd_hda_get_jack_type(def_conf),
4082
 
                snd_hda_get_jack_connectivity(def_conf),
4083
 
                snd_hda_get_jack_location(def_conf));
4084
 
 
4085
 
        err = snd_hda_input_jack_add(codec, nid, type, name);
4086
 
        if (err < 0)
4087
 
                return err;
4088
 
#endif /* CONFIG_SND_HDA_INPUT_JACK */
4089
 
        return 0;
4090
 
}
4091
 
 
4092
 
static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
 
4135
static int stac_add_event(struct hda_codec *codec, hda_nid_t nid,
4093
4136
                          unsigned char type, int data)
4094
4137
{
4095
 
        struct sigmatel_event *event;
 
4138
        struct hda_jack_tbl *event;
4096
4139
 
4097
 
        snd_array_init(&spec->events, sizeof(*event), 32);
4098
 
        event = snd_array_new(&spec->events);
 
4140
        event = snd_hda_jack_tbl_new(codec, nid);
4099
4141
        if (!event)
4100
4142
                return -ENOMEM;
4101
 
        event->nid = nid;
4102
 
        event->type = type;
4103
 
        event->tag = spec->events.used;
4104
 
        event->data = data;
4105
 
 
4106
 
        return event->tag;
4107
 
}
4108
 
 
4109
 
static struct sigmatel_event *stac_get_event(struct hda_codec *codec,
4110
 
                                             hda_nid_t nid)
4111
 
{
4112
 
        struct sigmatel_spec *spec = codec->spec;
4113
 
        struct sigmatel_event *event = spec->events.list;
4114
 
        int i;
4115
 
 
4116
 
        for (i = 0; i < spec->events.used; i++, event++) {
4117
 
                if (event->nid == nid)
4118
 
                        return event;
4119
 
        }
4120
 
        return NULL;
4121
 
}
4122
 
 
4123
 
static struct sigmatel_event *stac_get_event_from_tag(struct hda_codec *codec,
4124
 
                                                      unsigned char tag)
4125
 
{
4126
 
        struct sigmatel_spec *spec = codec->spec;
4127
 
        struct sigmatel_event *event = spec->events.list;
4128
 
        int i;
4129
 
 
4130
 
        for (i = 0; i < spec->events.used; i++, event++) {
4131
 
                if (event->tag == tag)
4132
 
                        return event;
4133
 
        }
4134
 
        return NULL;
 
4143
        event->action = type;
 
4144
        event->private_data = data;
 
4145
 
 
4146
        return 0;
4135
4147
}
4136
4148
 
4137
4149
/* check if given nid is a valid pin and no other events are assigned
4141
4153
static int enable_pin_detect(struct hda_codec *codec, hda_nid_t nid,
4142
4154
                             unsigned int type)
4143
4155
{
4144
 
        struct sigmatel_event *event;
4145
 
        int tag;
 
4156
        struct hda_jack_tbl *event;
4146
4157
 
4147
4158
        if (!is_jack_detectable(codec, nid))
4148
4159
                return 0;
4149
 
        event = stac_get_event(codec, nid);
4150
 
        if (event) {
4151
 
                if (event->type != type)
4152
 
                        return 0;
4153
 
                tag = event->tag;
4154
 
        } else {
4155
 
                tag = stac_add_event(codec->spec, nid, type, 0);
4156
 
                if (tag < 0)
4157
 
                        return 0;
4158
 
        }
4159
 
        snd_hda_codec_write_cache(codec, nid, 0,
4160
 
                                  AC_VERB_SET_UNSOLICITED_ENABLE,
4161
 
                                  AC_USRSP_EN | tag);
 
4160
        event = snd_hda_jack_tbl_new(codec, nid);
 
4161
        if (!event)
 
4162
                return -ENOMEM;
 
4163
        if (event->action && event->action != type)
 
4164
                return 0;
 
4165
        event->action = type;
 
4166
        snd_hda_jack_detect_enable(codec, nid, 0);
4162
4167
        return 1;
4163
4168
}
4164
4169
 
4165
 
static int is_nid_hp_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
 
4170
static int is_nid_out_jack_pin(struct auto_pin_cfg *cfg, hda_nid_t nid)
4166
4171
{
4167
4172
        int i;
4168
4173
        for (i = 0; i < cfg->hp_outs; i++)
4169
4174
                if (cfg->hp_pins[i] == nid)
4170
4175
                        return 1; /* nid is a HP-Out */
4171
 
 
 
4176
        for (i = 0; i < cfg->line_outs; i++)
 
4177
                if (cfg->line_out_pins[i] == nid)
 
4178
                        return 1; /* nid is a line-Out */
4172
4179
        return 0; /* nid is not a HP-Out */
4173
4180
};
4174
4181
 
4235
4242
        }
4236
4243
}
4237
4244
 
 
4245
static void stac_issue_unsol_events(struct hda_codec *codec, int num_pins,
 
4246
                                    const hda_nid_t *pins)
 
4247
{
 
4248
        while (num_pins--)
 
4249
                stac_issue_unsol_event(codec, *pins++);
 
4250
}
 
4251
 
 
4252
/* fake event to set up pins */
 
4253
static void stac_fake_hp_events(struct hda_codec *codec)
 
4254
{
 
4255
        struct sigmatel_spec *spec = codec->spec;
 
4256
 
 
4257
        if (spec->autocfg.hp_outs)
 
4258
                stac_issue_unsol_events(codec, spec->autocfg.hp_outs,
 
4259
                                        spec->autocfg.hp_pins);
 
4260
        if (spec->autocfg.line_outs &&
 
4261
            spec->autocfg.line_out_pins[0] != spec->autocfg.hp_pins[0])
 
4262
                stac_issue_unsol_events(codec, spec->autocfg.line_outs,
 
4263
                                        spec->autocfg.line_out_pins);
 
4264
}
 
4265
 
4238
4266
static int stac92xx_init(struct hda_codec *codec)
4239
4267
{
4240
4268
        struct sigmatel_spec *spec = codec->spec;
4285
4313
                stac92xx_auto_set_pinctl(codec, spec->autocfg.line_out_pins[0],
4286
4314
                                AC_PINCTL_OUT_EN);
4287
4315
                /* fake event to set up pins */
4288
 
                if (cfg->hp_pins[0])
4289
 
                        stac_issue_unsol_event(codec, cfg->hp_pins[0]);
4290
 
                else if (cfg->line_out_pins[0])
4291
 
                        stac_issue_unsol_event(codec, cfg->line_out_pins[0]);
 
4316
                stac_fake_hp_events(codec);
4292
4317
        } else {
4293
4318
                stac92xx_auto_init_multi_out(codec);
4294
4319
                stac92xx_auto_init_hp_out(codec);
4349
4374
                int pinctl, def_conf;
4350
4375
 
4351
4376
                /* power on when no jack detection is available */
4352
 
                if (!spec->hp_detect) {
 
4377
                /* or when the VREF is used for controlling LED */
 
4378
                if (!spec->hp_detect ||
 
4379
                    spec->vref_mute_led_nid == nid) {
4353
4380
                        stac_toggle_power_map(codec, nid, 1);
4354
4381
                        continue;
4355
4382
                }
4356
4383
 
4357
 
                if (is_nid_hp_pin(cfg, nid))
 
4384
                if (is_nid_out_jack_pin(cfg, nid))
4358
4385
                        continue; /* already has an unsol event */
4359
4386
 
4360
4387
                pinctl = snd_hda_codec_read(codec, nid, 0,
4376
4403
                                stac_toggle_power_map(codec, nid, 1);
4377
4404
                        continue;
4378
4405
                }
4379
 
                if (enable_pin_detect(codec, nid, STAC_PWR_EVENT))
 
4406
                if (enable_pin_detect(codec, nid, STAC_PWR_EVENT)) {
4380
4407
                        stac_issue_unsol_event(codec, nid);
 
4408
                        continue;
 
4409
                }
 
4410
                /* none of the above, turn the port OFF */
 
4411
                stac_toggle_power_map(codec, nid, 0);
4381
4412
        }
4382
4413
 
 
4414
        snd_hda_jack_report_sync(codec);
 
4415
 
4383
4416
        /* sync mute LED */
4384
4417
        if (spec->gpio_led)
4385
4418
                hda_call_check_power_status(codec, 0x01);
4401
4434
        snd_array_free(&spec->kctls);
4402
4435
}
4403
4436
 
 
4437
static void stac92xx_shutup_pins(struct hda_codec *codec)
 
4438
{
 
4439
        unsigned int i, def_conf;
 
4440
 
 
4441
        if (codec->bus->shutdown)
 
4442
                return;
 
4443
        for (i = 0; i < codec->init_pins.used; i++) {
 
4444
                struct hda_pincfg *pin = snd_array_elem(&codec->init_pins, i);
 
4445
                def_conf = snd_hda_codec_get_pincfg(codec, pin->nid);
 
4446
                if (get_defcfg_connect(def_conf) != AC_JACK_PORT_NONE)
 
4447
                        snd_hda_codec_write(codec, pin->nid, 0,
 
4448
                                    AC_VERB_SET_PIN_WIDGET_CONTROL, 0);
 
4449
        }
 
4450
}
 
4451
 
4404
4452
static void stac92xx_shutup(struct hda_codec *codec)
4405
4453
{
4406
4454
        struct sigmatel_spec *spec = codec->spec;
4407
4455
 
4408
 
        snd_hda_shutup_pins(codec);
 
4456
        stac92xx_shutup_pins(codec);
4409
4457
 
4410
4458
        if (spec->eapd_mask)
4411
4459
                stac_gpio_set(codec, spec->gpio_mask,
4421
4469
                return;
4422
4470
 
4423
4471
        stac92xx_shutup(codec);
4424
 
        snd_hda_input_jack_free(codec);
4425
 
        snd_array_free(&spec->events);
4426
4472
 
4427
4473
        kfree(spec);
4428
4474
        snd_hda_detach_beep_device(codec);
4618
4664
        if (idx >= spec->num_pwrs)
4619
4665
                return;
4620
4666
 
4621
 
        /* several codecs have two power down bits */
4622
 
        if (spec->pwr_mapping)
4623
 
                idx = spec->pwr_mapping[idx];
4624
 
        else
4625
 
                idx = 1 << idx;
 
4667
        idx = 1 << idx;
4626
4668
 
4627
4669
        val = snd_hda_codec_read(codec, codec->afg, 0, 0x0fec, 0x0) & 0xff;
4628
4670
        if (enable)
4690
4732
                                          mic->mux_idx);
4691
4733
}
4692
4734
 
4693
 
static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
4694
 
{
4695
 
        struct sigmatel_event *event = stac_get_event(codec, nid);
4696
 
        if (!event)
4697
 
                return;
4698
 
        codec->patch_ops.unsol_event(codec, (unsigned)event->tag << 26);
4699
 
}
4700
 
 
4701
 
static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
 
4735
static void handle_unsol_event(struct hda_codec *codec,
 
4736
                               struct hda_jack_tbl *event)
4702
4737
{
4703
4738
        struct sigmatel_spec *spec = codec->spec;
4704
 
        struct sigmatel_event *event;
4705
 
        int tag, data;
4706
 
 
4707
 
        tag = (res >> 26) & 0x7f;
4708
 
        event = stac_get_event_from_tag(codec, tag);
4709
 
        if (!event)
4710
 
                return;
4711
 
 
4712
 
        switch (event->type) {
 
4739
        int data;
 
4740
 
 
4741
        switch (event->action) {
4713
4742
        case STAC_HP_EVENT:
4714
4743
        case STAC_LO_EVENT:
4715
4744
                stac92xx_hp_detect(codec);
4719
4748
                break;
4720
4749
        }
4721
4750
 
4722
 
        switch (event->type) {
 
4751
        switch (event->action) {
4723
4752
        case STAC_HP_EVENT:
4724
4753
        case STAC_LO_EVENT:
4725
4754
        case STAC_MIC_EVENT:
4727
4756
        case STAC_PWR_EVENT:
4728
4757
                if (spec->num_pwrs > 0)
4729
4758
                        stac92xx_pin_sense(codec, event->nid);
4730
 
                snd_hda_input_jack_report(codec, event->nid);
4731
4759
 
4732
4760
                switch (codec->subsystem_id) {
4733
4761
                case 0x103c308f:
4752
4780
                                          AC_VERB_GET_GPIO_DATA, 0);
4753
4781
                /* toggle VREF state based on GPIOx status */
4754
4782
                snd_hda_codec_write(codec, codec->afg, 0, 0x7e0,
4755
 
                                    !!(data & (1 << event->data)));
 
4783
                                    !!(data & (1 << event->private_data)));
4756
4784
                break;
4757
4785
        }
4758
4786
}
4759
4787
 
 
4788
static void stac_issue_unsol_event(struct hda_codec *codec, hda_nid_t nid)
 
4789
{
 
4790
        struct hda_jack_tbl *event = snd_hda_jack_tbl_get(codec, nid);
 
4791
        if (!event)
 
4792
                return;
 
4793
        handle_unsol_event(codec, event);
 
4794
}
 
4795
 
 
4796
static void stac92xx_unsol_event(struct hda_codec *codec, unsigned int res)
 
4797
{
 
4798
        struct hda_jack_tbl *event;
 
4799
        int tag;
 
4800
 
 
4801
        tag = (res >> 26) & 0x7f;
 
4802
        event = snd_hda_jack_tbl_get_from_tag(codec, tag);
 
4803
        if (!event)
 
4804
                return;
 
4805
        event->jack_dirty = 1;
 
4806
        handle_unsol_event(codec, event);
 
4807
        snd_hda_jack_report_sync(codec);
 
4808
}
 
4809
 
4760
4810
static int hp_blike_system(u32 subsystem_id);
4761
4811
 
4762
4812
static void set_hp_led_gpio(struct hda_codec *codec)
4803
4853
        if ((codec->subsystem_id >> 16) == PCI_VENDOR_ID_HP) {
4804
4854
                while ((dev = dmi_find_device(DMI_DEV_TYPE_OEM_STRING,
4805
4855
                                                                NULL, dev))) {
4806
 
                        if (sscanf(dev->name, "HP_Mute_LED_%d_%d",
 
4856
                        if (sscanf(dev->name, "HP_Mute_LED_%d_%x",
4807
4857
                                  &spec->gpio_led_polarity,
4808
4858
                                  &spec->gpio_led) == 2) {
4809
 
                                spec->gpio_led = 1 << spec->gpio_led;
 
4859
                                unsigned int max_gpio;
 
4860
                                max_gpio = snd_hda_param_read(codec, codec->afg,
 
4861
                                                              AC_PAR_GPIO_CAP);
 
4862
                                max_gpio &= AC_GPIO_IO_COUNT;
 
4863
                                if (spec->gpio_led < max_gpio)
 
4864
                                        spec->gpio_led = 1 << spec->gpio_led;
 
4865
                                else
 
4866
                                        spec->vref_mute_led_nid = spec->gpio_led;
4810
4867
                                return 1;
4811
4868
                        }
4812
4869
                        if (sscanf(dev->name, "HP_Mute_LED_%d",
4814
4871
                                set_hp_led_gpio(codec);
4815
4872
                                return 1;
4816
4873
                        }
 
4874
                        /* BIOS bug: unfilled OEM string */
 
4875
                        if (strstr(dev->name, "HP_Mute_LED_P_G")) {
 
4876
                                set_hp_led_gpio(codec);
 
4877
                                switch (codec->subsystem_id) {
 
4878
                                case 0x103c148a:
 
4879
                                        spec->gpio_led_polarity = 0;
 
4880
                                        break;
 
4881
                                default:
 
4882
                                        spec->gpio_led_polarity = 1;
 
4883
                                        break;
 
4884
                                }
 
4885
                                return 1;
 
4886
                        }
4817
4887
                }
4818
4888
 
4819
4889
                /*
4904
4974
#define stac927x_proc_hook      NULL
4905
4975
#endif
4906
4976
 
4907
 
#ifdef SND_HDA_NEEDS_RESUME
 
4977
#ifdef CONFIG_PM
4908
4978
static int stac92xx_resume(struct hda_codec *codec)
4909
4979
{
4910
 
        struct sigmatel_spec *spec = codec->spec;
4911
 
 
4912
4980
        stac92xx_init(codec);
4913
4981
        snd_hda_codec_resume_amp(codec);
4914
4982
        snd_hda_codec_resume_cache(codec);
4915
4983
        /* fake event to set up pins again to override cached values */
4916
 
        if (spec->hp_detect) {
4917
 
                if (spec->autocfg.hp_pins[0])
4918
 
                        stac_issue_unsol_event(codec, spec->autocfg.hp_pins[0]);
4919
 
                else if (spec->autocfg.line_out_pins[0])
4920
 
                        stac_issue_unsol_event(codec,
4921
 
                                               spec->autocfg.line_out_pins[0]);
 
4984
        stac_fake_hp_events(codec);
 
4985
        return 0;
 
4986
}
 
4987
 
 
4988
static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
 
4989
{
 
4990
        stac92xx_shutup(codec);
 
4991
        return 0;
 
4992
}
 
4993
 
 
4994
#ifdef CONFIG_SND_HDA_POWER_SAVE
 
4995
static int stac92xx_pre_resume(struct hda_codec *codec)
 
4996
{
 
4997
        struct sigmatel_spec *spec = codec->spec;
 
4998
 
 
4999
        /* sync mute LED */
 
5000
        if (spec->vref_mute_led_nid)
 
5001
                stac_vrefout_set(codec, spec->vref_mute_led_nid,
 
5002
                                 spec->vref_led);
 
5003
        else if (spec->gpio_led)
 
5004
                stac_gpio_set(codec, spec->gpio_mask,
 
5005
                              spec->gpio_dir, spec->gpio_data);
 
5006
        return 0;
 
5007
}
 
5008
 
 
5009
static void stac92xx_set_power_state(struct hda_codec *codec, hda_nid_t fg,
 
5010
                                unsigned int power_state)
 
5011
{
 
5012
        unsigned int afg_power_state = power_state;
 
5013
        struct sigmatel_spec *spec = codec->spec;
 
5014
 
 
5015
        if (power_state == AC_PWRST_D3) {
 
5016
                if (spec->vref_mute_led_nid) {
 
5017
                        /* with vref-out pin used for mute led control
 
5018
                         * codec AFG is prevented from D3 state
 
5019
                         */
 
5020
                        afg_power_state = AC_PWRST_D1;
 
5021
                }
 
5022
                /* this delay seems necessary to avoid click noise at power-down */
 
5023
                msleep(100);
4922
5024
        }
4923
 
        /* sync mute LED */
4924
 
        if (spec->gpio_led)
4925
 
                hda_call_check_power_status(codec, 0x01);
4926
 
        return 0;
 
5025
        snd_hda_codec_read(codec, fg, 0, AC_VERB_SET_POWER_STATE,
 
5026
                        afg_power_state);
 
5027
        snd_hda_codec_set_power_to_all(codec, fg, power_state, true);
4927
5028
}
4928
5029
 
4929
5030
/*
4930
 
 * using power check for controlling mute led of HP notebooks
4931
 
 * check for mute state only on Speakers (nid = 0x10)
4932
 
 *
4933
 
 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed, otherwise
4934
 
 * the LED is NOT working properly !
4935
 
 *
4936
 
 * Changed name to reflect that it now works for any designated
4937
 
 * model, not just HP HDX.
 
5031
 * For this feature CONFIG_SND_HDA_POWER_SAVE is needed
 
5032
 * as mute LED state is updated in check_power_status hook
4938
5033
 */
4939
 
 
4940
 
#ifdef CONFIG_SND_HDA_POWER_SAVE
4941
 
static int stac92xx_hp_check_power_status(struct hda_codec *codec,
4942
 
                                              hda_nid_t nid)
 
5034
static int stac92xx_update_led_status(struct hda_codec *codec)
4943
5035
{
4944
5036
        struct sigmatel_spec *spec = codec->spec;
4945
 
        int i, muted = 1;
 
5037
        int i, num_ext_dacs, muted = 1;
 
5038
        unsigned int muted_lvl, notmtd_lvl;
 
5039
        hda_nid_t nid;
 
5040
 
 
5041
        if (!spec->gpio_led)
 
5042
                return 0;
4946
5043
 
4947
5044
        for (i = 0; i < spec->multiout.num_dacs; i++) {
4948
5045
                nid = spec->multiout.dac_nids[i];
4952
5049
                        break;
4953
5050
                }
4954
5051
        }
4955
 
        if (muted)
4956
 
                spec->gpio_data &= ~spec->gpio_led; /* orange */
4957
 
        else
4958
 
                spec->gpio_data |= spec->gpio_led; /* white */
4959
 
 
4960
 
        if (!spec->gpio_led_polarity) {
4961
 
                /* LED state is inverted on these systems */
4962
 
                spec->gpio_data ^= spec->gpio_led;
4963
 
        }
4964
 
 
4965
 
        stac_gpio_set(codec, spec->gpio_mask, spec->gpio_dir, spec->gpio_data);
 
5052
        if (muted && spec->multiout.hp_nid)
 
5053
                if (!(snd_hda_codec_amp_read(codec,
 
5054
                                spec->multiout.hp_nid, 0, HDA_OUTPUT, 0) &
 
5055
                                        HDA_AMP_MUTE)) {
 
5056
                        muted = 0; /* HP is not muted */
 
5057
                }
 
5058
        num_ext_dacs = ARRAY_SIZE(spec->multiout.extra_out_nid);
 
5059
        for (i = 0; muted && i < num_ext_dacs; i++) {
 
5060
                nid = spec->multiout.extra_out_nid[i];
 
5061
                if (nid == 0)
 
5062
                        break;
 
5063
                if (!(snd_hda_codec_amp_read(codec, nid, 0, HDA_OUTPUT, 0) &
 
5064
                      HDA_AMP_MUTE)) {
 
5065
                        muted = 0; /* extra output is not muted */
 
5066
                }
 
5067
        }
 
5068
        /*polarity defines *not* muted state level*/
 
5069
        if (!spec->vref_mute_led_nid) {
 
5070
                if (muted)
 
5071
                        spec->gpio_data &= ~spec->gpio_led; /* orange */
 
5072
                else
 
5073
                        spec->gpio_data |= spec->gpio_led; /* white */
 
5074
 
 
5075
                if (!spec->gpio_led_polarity) {
 
5076
                        /* LED state is inverted on these systems */
 
5077
                        spec->gpio_data ^= spec->gpio_led;
 
5078
                }
 
5079
                stac_gpio_set(codec, spec->gpio_mask,
 
5080
                                spec->gpio_dir, spec->gpio_data);
 
5081
        } else {
 
5082
                notmtd_lvl = spec->gpio_led_polarity ?
 
5083
                                AC_PINCTL_VREF_HIZ : AC_PINCTL_VREF_GRD;
 
5084
                muted_lvl = spec->gpio_led_polarity ?
 
5085
                                AC_PINCTL_VREF_GRD : AC_PINCTL_VREF_HIZ;
 
5086
                spec->vref_led = muted ? muted_lvl : notmtd_lvl;
 
5087
                stac_vrefout_set(codec, spec->vref_mute_led_nid,
 
5088
                                 spec->vref_led);
 
5089
        }
4966
5090
        return 0;
4967
5091
}
4968
 
#endif
4969
5092
 
4970
 
static int stac92xx_suspend(struct hda_codec *codec, pm_message_t state)
 
5093
/*
 
5094
 * use power check for controlling mute led of HP notebooks
 
5095
 */
 
5096
static int stac92xx_check_power_status(struct hda_codec *codec,
 
5097
                                              hda_nid_t nid)
4971
5098
{
4972
 
        stac92xx_shutup(codec);
 
5099
        stac92xx_update_led_status(codec);
 
5100
 
4973
5101
        return 0;
4974
5102
}
4975
 
#endif
 
5103
#endif /* CONFIG_SND_HDA_POWER_SAVE */
 
5104
#endif /* CONFIG_PM */
4976
5105
 
4977
5106
static const struct hda_codec_ops stac92xx_patch_ops = {
4978
5107
        .build_controls = stac92xx_build_controls,
4980
5109
        .init = stac92xx_init,
4981
5110
        .free = stac92xx_free,
4982
5111
        .unsol_event = stac92xx_unsol_event,
4983
 
#ifdef SND_HDA_NEEDS_RESUME
 
5112
#ifdef CONFIG_PM
4984
5113
        .suspend = stac92xx_suspend,
4985
5114
        .resume = stac92xx_resume,
4986
5115
#endif
5115
5244
        spec->capvols = stac925x_capvols;
5116
5245
        spec->capsws = stac925x_capsws;
5117
5246
 
5118
 
        err = stac92xx_parse_auto_config(codec, 0x8, 0x7);
 
5247
        err = stac92xx_parse_auto_config(codec);
5119
5248
        if (!err) {
5120
5249
                if (spec->board_config < 0) {
5121
5250
                        printk(KERN_WARNING "hda_codec: No auto-config is "
5256
5385
        spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5257
5386
        spec->pwr_nids = stac92hd73xx_pwr_nids;
5258
5387
 
5259
 
        err = stac92xx_parse_auto_config(codec, 0x25, 0x27);
 
5388
        err = stac92xx_parse_auto_config(codec);
5260
5389
 
5261
5390
        if (!err) {
5262
5391
                if (spec->board_config < 0) {
5436
5565
                snd_hda_codec_set_pincfg(codec, 0xf, 0x2181205e);
5437
5566
        }
5438
5567
 
5439
 
        /* reset pin power-down; Windows may leave these bits after reboot */
5440
 
        snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7EC, 0);
5441
 
        snd_hda_codec_write_cache(codec, codec->afg, 0, 0x7ED, 0);
5442
5568
        codec->no_trigger_sense = 1;
5443
5569
        codec->spec = spec;
5444
5570
 
5448
5574
        codec->slave_dig_outs = stac92hd83xxx_slave_dig_outs;
5449
5575
        spec->digbeep_nid = 0x21;
5450
5576
        spec->pwr_nids = stac92hd83xxx_pwr_nids;
5451
 
        spec->pwr_mapping = stac92hd83xxx_pwr_mapping;
5452
5577
        spec->num_pwrs = ARRAY_SIZE(stac92hd83xxx_pwr_nids);
5453
5578
        spec->multiout.dac_nids = spec->dac_nids;
5454
5579
        spec->init = stac92hd83xxx_core_init;
5465
5590
                stac92xx_set_config_regs(codec,
5466
5591
                                stac92hd83xxx_brd_tbl[spec->board_config]);
5467
5592
 
5468
 
        if (spec->board_config != STAC_92HD83XXX_PWR_REF)
5469
 
                spec->num_pwrs = 0;
5470
 
 
5471
5593
        codec->patch_ops = stac92xx_patch_ops;
5472
5594
 
5473
5595
        if (find_mute_led_gpio(codec, 0))
5477
5599
 
5478
5600
#ifdef CONFIG_SND_HDA_POWER_SAVE
5479
5601
        if (spec->gpio_led) {
5480
 
                spec->gpio_mask |= spec->gpio_led;
5481
 
                spec->gpio_dir |= spec->gpio_led;
5482
 
                spec->gpio_data |= spec->gpio_led;
5483
 
                /* register check_power_status callback. */
 
5602
                if (!spec->vref_mute_led_nid) {
 
5603
                        spec->gpio_mask |= spec->gpio_led;
 
5604
                        spec->gpio_dir |= spec->gpio_led;
 
5605
                        spec->gpio_data |= spec->gpio_led;
 
5606
                } else {
 
5607
                        codec->patch_ops.set_power_state =
 
5608
                                        stac92xx_set_power_state;
 
5609
                }
 
5610
                codec->patch_ops.pre_resume = stac92xx_pre_resume;
5484
5611
                codec->patch_ops.check_power_status =
5485
 
                        stac92xx_hp_check_power_status;
 
5612
                        stac92xx_check_power_status;
5486
5613
        }
5487
5614
#endif  
5488
5615
 
5489
 
        /* 92HD65/66 series has S/PDIF-IN */
5490
 
        if (codec->vendor_id >= 0x111d76e8 && codec->vendor_id <= 0x111d76f3)
5491
 
                err = stac92xx_parse_auto_config(codec, 0x1d, 0x22);
5492
 
        else
5493
 
                err = stac92xx_parse_auto_config(codec, 0x1d, 0);
 
5616
        err = stac92xx_parse_auto_config(codec);
5494
5617
        if (!err) {
5495
5618
                if (spec->board_config < 0) {
5496
5619
                        printk(KERN_WARNING "hda_codec: No auto-config is "
5657
5780
                switch (spec->board_config) {
5658
5781
                case STAC_HP_M4:
5659
5782
                        /* Enable VREF power saving on GPIO1 detect */
5660
 
                        err = stac_add_event(spec, codec->afg,
 
5783
                        err = stac_add_event(codec, codec->afg,
5661
5784
                                             STAC_VREF_EVENT, 0x02);
5662
5785
                        if (err < 0)
5663
5786
                                return err;
5664
5787
                        snd_hda_codec_write_cache(codec, codec->afg, 0,
5665
5788
                                AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x02);
5666
 
                        snd_hda_codec_write_cache(codec, codec->afg, 0,
5667
 
                                AC_VERB_SET_UNSOLICITED_ENABLE,
5668
 
                                AC_USRSP_EN | err);
 
5789
                        snd_hda_jack_detect_enable(codec, codec->afg, 0);
5669
5790
                        spec->gpio_mask |= 0x02;
5670
5791
                        break;
5671
5792
                }
5673
5794
                    (codec->revision_id & 0xf) == 1)
5674
5795
                        spec->stream_delay = 40; /* 40 milliseconds */
5675
5796
 
5676
 
                /* no output amps */
5677
 
                spec->num_pwrs = 0;
5678
5797
                /* disable VSW */
5679
5798
                spec->init = stac92hd71bxx_core_init;
5680
5799
                unmute_init++;
5689
5808
                if ((codec->revision_id & 0xf) == 1)
5690
5809
                        spec->stream_delay = 40; /* 40 milliseconds */
5691
5810
 
5692
 
                /* no output amps */
5693
 
                spec->num_pwrs = 0;
5694
5811
                /* fallthru */
5695
5812
        default:
5696
5813
                spec->init = stac92hd71bxx_core_init;
5793
5910
 
5794
5911
#ifdef CONFIG_SND_HDA_POWER_SAVE
5795
5912
        if (spec->gpio_led) {
5796
 
                spec->gpio_mask |= spec->gpio_led;
5797
 
                spec->gpio_dir |= spec->gpio_led;
5798
 
                spec->gpio_data |= spec->gpio_led;
5799
 
                /* register check_power_status callback. */
 
5913
                if (!spec->vref_mute_led_nid) {
 
5914
                        spec->gpio_mask |= spec->gpio_led;
 
5915
                        spec->gpio_dir |= spec->gpio_led;
 
5916
                        spec->gpio_data |= spec->gpio_led;
 
5917
                } else {
 
5918
                        codec->patch_ops.set_power_state =
 
5919
                                        stac92xx_set_power_state;
 
5920
                }
 
5921
                codec->patch_ops.pre_resume = stac92xx_pre_resume;
5800
5922
                codec->patch_ops.check_power_status =
5801
 
                        stac92xx_hp_check_power_status;
 
5923
                        stac92xx_check_power_status;
5802
5924
        }
5803
5925
#endif  
5804
5926
 
5805
5927
        spec->multiout.dac_nids = spec->dac_nids;
5806
5928
 
5807
 
        err = stac92xx_parse_auto_config(codec, 0x21, 0);
 
5929
        err = stac92xx_parse_auto_config(codec);
5808
5930
        if (!err) {
5809
5931
                if (spec->board_config < 0) {
5810
5932
                        printk(KERN_WARNING "hda_codec: No auto-config is "
5913
6035
 
5914
6036
        spec->multiout.dac_nids = spec->dac_nids;
5915
6037
        
5916
 
        err = stac92xx_parse_auto_config(codec, 0x08, 0x09);
 
6038
        err = stac92xx_parse_auto_config(codec);
5917
6039
        if (!err) {
5918
6040
                if (spec->board_config < 0) {
5919
6041
                        printk(KERN_WARNING "hda_codec: No auto-config is "
6038
6160
        spec->aloopback_shift = 0;
6039
6161
        spec->eapd_switch = 1;
6040
6162
 
6041
 
        err = stac92xx_parse_auto_config(codec, 0x1e, 0x20);
 
6163
        err = stac92xx_parse_auto_config(codec);
6042
6164
        if (!err) {
6043
6165
                if (spec->board_config < 0) {
6044
6166
                        printk(KERN_WARNING "hda_codec: No auto-config is "
6135
6257
                snd_hda_codec_set_pincfg(codec, 0x20, 0x1c410030);
6136
6258
 
6137
6259
                /* Enable unsol response for GPIO4/Dock HP connection */
6138
 
                err = stac_add_event(spec, codec->afg, STAC_VREF_EVENT, 0x01);
 
6260
                err = stac_add_event(codec, codec->afg, STAC_VREF_EVENT, 0x01);
6139
6261
                if (err < 0)
6140
6262
                        return err;
6141
6263
                snd_hda_codec_write_cache(codec, codec->afg, 0,
6142
6264
                        AC_VERB_SET_GPIO_UNSOLICITED_RSP_MASK, 0x10);
6143
 
                snd_hda_codec_write_cache(codec, codec->afg, 0,
6144
 
                                          AC_VERB_SET_UNSOLICITED_ENABLE,
6145
 
                                          AC_USRSP_EN | err);
 
6265
                snd_hda_jack_detect_enable(codec, codec->afg, 0);
6146
6266
 
6147
6267
                spec->gpio_dir = 0x0b;
6148
6268
                spec->eapd_mask = 0x01;
6163
6283
                break;
6164
6284
        }
6165
6285
 
6166
 
        err = stac92xx_parse_auto_config(codec, 0x1f, 0x20);
 
6286
        err = stac92xx_parse_auto_config(codec);
6167
6287
        if (!err) {
6168
6288
                if (spec->board_config < 0) {
6169
6289
                        printk(KERN_WARNING "hda_codec: No auto-config is "
6268
6388
        spec->capvols = stac9872_capvols;
6269
6389
        spec->capsws = stac9872_capsws;
6270
6390
 
6271
 
        err = stac92xx_parse_auto_config(codec, 0x10, 0x12);
 
6391
        err = stac92xx_parse_auto_config(codec);
6272
6392
        if (err < 0) {
6273
6393
                stac92xx_free(codec);
6274
6394
                return -EINVAL;