aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Documentation/DocBook/writing-an-alsa-driver.tmpl36
-rw-r--r--Documentation/sound/alsa/ALSA-Configuration.txt6
-rw-r--r--Documentation/sound/alsa/HD-Audio-Controls.txt16
-rw-r--r--Documentation/sound/alsa/HD-Audio-Models.txt67
-rw-r--r--Documentation/sound/alsa/HD-Audio.txt55
-rw-r--r--MAINTAINERS2
-rw-r--r--include/linux/input.h1
-rw-r--r--include/linux/usb/ch9.h17
-rw-r--r--include/sound/asound.h4
-rw-r--r--include/sound/initval.h2
-rw-r--r--include/sound/jack.h1
-rw-r--r--include/sound/mpu401.h7
-rw-r--r--include/sound/pcm.h4
-rw-r--r--sound/aoa/codecs/onyx.c4
-rw-r--r--sound/aoa/fabrics/layout.c2
-rw-r--r--sound/arm/aaci.c2
-rw-r--r--sound/arm/pxa2xx-ac97-lib.c2
-rw-r--r--sound/core/control.c84
-rw-r--r--sound/core/control_compat.c4
-rw-r--r--sound/core/hwdep.c9
-rw-r--r--sound/core/jack.c1
-rw-r--r--sound/core/oss/mixer_oss.c2
-rw-r--r--sound/core/pcm_lib.c59
-rw-r--r--sound/core/pcm_native.c19
-rw-r--r--sound/core/timer.c5
-rw-r--r--sound/drivers/aloop.c13
-rw-r--r--sound/drivers/ml403-ac97cr.c4
-rw-r--r--sound/drivers/mpu401/mpu401.c3
-rw-r--r--sound/drivers/mpu401/mpu401_uart.c20
-rw-r--r--sound/drivers/mtpav.c2
-rw-r--r--sound/drivers/serial-u16550.c2
-rw-r--r--sound/firewire/isight.c1
-rw-r--r--sound/firewire/speakers.c5
-rw-r--r--sound/isa/ad1816a/ad1816a.c2
-rw-r--r--sound/isa/ad1816a/ad1816a_lib.c2
-rw-r--r--sound/isa/als100.c1
-rw-r--r--sound/isa/azt2320.c3
-rw-r--r--sound/isa/cmi8330.c2
-rw-r--r--sound/isa/cs423x/cs4231.c1
-rw-r--r--sound/isa/cs423x/cs4236.c3
-rw-r--r--sound/isa/es1688/es1688.c2
-rw-r--r--sound/isa/es1688/es1688_lib.c2
-rw-r--r--sound/isa/es18xx.c6
-rw-r--r--sound/isa/galaxy/galaxy.c3
-rw-r--r--sound/isa/gus/gus_main.c2
-rw-r--r--sound/isa/gus/gusextreme.c3
-rw-r--r--sound/isa/gus/gusmax.c2
-rw-r--r--sound/isa/gus/interwave.c2
-rw-r--r--sound/isa/msnd/msnd_pinnacle.c2
-rw-r--r--sound/isa/opl3sa2.c7
-rw-r--r--sound/isa/opti9xx/miro.c3
-rw-r--r--sound/isa/opti9xx/opti92x-ad1848.c4
-rw-r--r--sound/isa/sb/jazz16.c1
-rw-r--r--sound/isa/sb/sb16.c5
-rw-r--r--sound/isa/sb/sb_common.c2
-rw-r--r--sound/isa/sc6000.c3
-rw-r--r--sound/isa/sscape.c3
-rw-r--r--sound/isa/wavefront/wavefront.c5
-rw-r--r--sound/isa/wss/wss_lib.c2
-rw-r--r--sound/mips/au1x00.c4
-rw-r--r--sound/oss/pas2_pcm.c8
-rw-r--r--sound/oss/pss.c6
-rw-r--r--sound/oss/sound_timer.c2
-rw-r--r--sound/pci/Kconfig10
-rw-r--r--sound/pci/ac97/ac97_patch.c1
-rw-r--r--sound/pci/als4000.c5
-rw-r--r--sound/pci/asihpi/hpicmn.c5
-rw-r--r--sound/pci/au88x0/au88x0_mpu401.c6
-rw-r--r--sound/pci/azt3328.c16
-rw-r--r--sound/pci/cmipci.c5
-rw-r--r--sound/pci/ctxfi/ctpcm.c2
-rw-r--r--sound/pci/ctxfi/ctsrc.c2
-rw-r--r--sound/pci/ctxfi/ctvmem.h2
-rw-r--r--sound/pci/emu10k1/emupcm.c5
-rw-r--r--sound/pci/es1938.c5
-rw-r--r--sound/pci/es1968.c5
-rw-r--r--sound/pci/fm801.c29
-rw-r--r--sound/pci/hda/Makefile3
-rw-r--r--sound/pci/hda/alc260_quirks.c304
-rw-r--r--sound/pci/hda/alc262_quirks.c530
-rw-r--r--sound/pci/hda/alc268_quirks.c636
-rw-r--r--sound/pci/hda/alc269_quirks.c681
-rw-r--r--sound/pci/hda/alc662_quirks.c1408
-rw-r--r--sound/pci/hda/alc680_quirks.c222
-rw-r--r--sound/pci/hda/alc861_quirks.c725
-rw-r--r--sound/pci/hda/alc861vd_quirks.c605
-rw-r--r--sound/pci/hda/alc880_quirks.c17
-rw-r--r--sound/pci/hda/alc882_quirks.c85
-rw-r--r--sound/pci/hda/alc_quirks.c13
-rw-r--r--sound/pci/hda/hda_codec.c149
-rw-r--r--sound/pci/hda/hda_eld.c72
-rw-r--r--sound/pci/hda/hda_hwdep.c8
-rw-r--r--sound/pci/hda/hda_intel.c235
-rw-r--r--sound/pci/hda/hda_local.h36
-rw-r--r--sound/pci/hda/hda_proc.c12
-rw-r--r--sound/pci/hda/hda_trace.h117
-rw-r--r--sound/pci/hda/patch_analog.c176
-rw-r--r--sound/pci/hda/patch_cirrus.c10
-rw-r--r--sound/pci/hda/patch_conexant.c223
-rw-r--r--sound/pci/hda/patch_hdmi.c104
-rw-r--r--sound/pci/hda/patch_realtek.c1466
-rw-r--r--sound/pci/hda/patch_sigmatel.c119
-rw-r--r--sound/pci/hda/patch_via.c75
-rw-r--r--sound/pci/ice1712/ice1712.c10
-rw-r--r--sound/pci/intel8x0.c29
-rw-r--r--sound/pci/maestro3.c4
-rw-r--r--sound/pci/oxygen/oxygen_lib.c6
-rw-r--r--sound/pci/oxygen/xonar_pcm179x.c1
-rw-r--r--sound/pci/riptide/riptide.c2
-rw-r--r--sound/pci/rme9652/hdsp.c2
-rw-r--r--sound/pci/rme9652/hdspm.c214
-rw-r--r--sound/pci/sis7019.c4
-rw-r--r--sound/pci/sonicvibes.c7
-rw-r--r--sound/pci/trident/trident.c5
-rw-r--r--sound/pci/via82xx.c13
-rw-r--r--sound/pci/ymfpci/ymfpci.c5
-rw-r--r--sound/pci/ymfpci/ymfpci_main.c32
-rw-r--r--sound/ppc/keywest.c1
-rw-r--r--sound/ppc/snd_ps3.c2
-rw-r--r--sound/soc/au1x/dma.c2
-rw-r--r--sound/soc/codecs/tlv320dac33.c2
-rw-r--r--sound/soc/nuc900/nuc900-pcm.c2
-rw-r--r--sound/soc/samsung/ac97.c2
-rw-r--r--sound/soc/sh/fsi.c2
-rw-r--r--sound/soc/txx9/txx9aclc-ac97.c2
-rw-r--r--sound/sparc/amd7930.c2
-rw-r--r--sound/usb/6fire/firmware.c25
-rw-r--r--sound/usb/Kconfig2
-rw-r--r--sound/usb/Makefile12
-rw-r--r--sound/usb/caiaq/audio.c37
-rw-r--r--sound/usb/caiaq/device.c8
-rw-r--r--sound/usb/caiaq/device.h2
-rw-r--r--sound/usb/caiaq/input.c157
-rw-r--r--sound/usb/card.c11
-rw-r--r--sound/usb/card.h2
-rw-r--r--sound/usb/clock.c12
-rw-r--r--sound/usb/endpoint.c1199
-rw-r--r--sound/usb/endpoint.h20
-rw-r--r--sound/usb/format.c4
-rw-r--r--sound/usb/helper.c4
-rw-r--r--sound/usb/helper.h2
-rw-r--r--sound/usb/midi.c27
-rw-r--r--sound/usb/mixer.c49
-rw-r--r--sound/usb/mixer.h1
-rw-r--r--sound/usb/mixer_quirks.c10
-rw-r--r--sound/usb/pcm.c34
-rw-r--r--sound/usb/pcm.h3
-rw-r--r--sound/usb/quirks-table.h65
-rw-r--r--sound/usb/quirks.c18
-rw-r--r--sound/usb/stream.c452
-rw-r--r--sound/usb/stream.h12
-rw-r--r--sound/usb/urb.c941
-rw-r--r--sound/usb/urb.h21
-rw-r--r--sound/usb/usbaudio.h1
154 files changed, 4369 insertions, 7796 deletions
diff --git a/Documentation/DocBook/writing-an-alsa-driver.tmpl b/Documentation/DocBook/writing-an-alsa-driver.tmpl
index 598c22f3b3ac..5de23c007078 100644
--- a/Documentation/DocBook/writing-an-alsa-driver.tmpl
+++ b/Documentation/DocBook/writing-an-alsa-driver.tmpl
@@ -4288,7 +4288,7 @@ struct _snd_pcm_runtime {
4288<![CDATA[ 4288<![CDATA[
4289 struct snd_rawmidi *rmidi; 4289 struct snd_rawmidi *rmidi;
4290 snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port, info_flags, 4290 snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port, info_flags,
4291 irq, irq_flags, &rmidi); 4291 irq, &rmidi);
4292]]> 4292]]>
4293 </programlisting> 4293 </programlisting>
4294 </informalexample> 4294 </informalexample>
@@ -4343,6 +4343,13 @@ struct _snd_pcm_runtime {
4343 by itself to start processing the output stream in the irq handler. 4343 by itself to start processing the output stream in the irq handler.
4344 </para> 4344 </para>
4345 4345
4346 <para>
4347 If the MPU-401 interface shares its interrupt with the other logical
4348 devices on the card, set <constant>MPU401_INFO_IRQ_HOOK</constant>
4349 (see <link linkend="midi-interface-interrupt-handler"><citetitle>
4350 below</citetitle></link>).
4351 </para>
4352
4346 <para> 4353 <para>
4347 Usually, the port address corresponds to the command port and 4354 Usually, the port address corresponds to the command port and
4348 port + 1 corresponds to the data port. If not, you may change 4355 port + 1 corresponds to the data port. If not, you may change
@@ -4375,14 +4382,12 @@ struct _snd_pcm_runtime {
4375 </para> 4382 </para>
4376 4383
4377 <para> 4384 <para>
4378 The 6th argument specifies the irq number for UART. If the irq 4385 The 6th argument specifies the ISA irq number that will be
4379 is already allocated, pass 0 to the 7th argument 4386 allocated. If no interrupt is to be allocated (because your
4380 (<parameter>irq_flags</parameter>). Otherwise, pass the flags 4387 code is already allocating a shared interrupt, or because the
4381 for irq allocation 4388 device does not use interrupts), pass -1 instead.
4382 (<constant>SA_XXX</constant> bits) to it, and the irq will be 4389 For a MPU-401 device without an interrupt, a polling timer
4383 reserved by the mpu401-uart layer. If the card doesn't generate 4390 will be used instead.
4384 UART interrupts, pass -1 as the irq number. Then a timer
4385 interrupt will be invoked for polling.
4386 </para> 4391 </para>
4387 </section> 4392 </section>
4388 4393
@@ -4390,12 +4395,13 @@ struct _snd_pcm_runtime {
4390 <title>Interrupt Handler</title> 4395 <title>Interrupt Handler</title>
4391 <para> 4396 <para>
4392 When the interrupt is allocated in 4397 When the interrupt is allocated in
4393 <function>snd_mpu401_uart_new()</function>, the private 4398 <function>snd_mpu401_uart_new()</function>, an exclusive ISA
4394 interrupt handler is used, hence you don't have anything else to do 4399 interrupt handler is automatically used, hence you don't have
4395 than creating the mpu401 stuff. Otherwise, you have to call 4400 anything else to do than creating the mpu401 stuff. Otherwise, you
4396 <function>snd_mpu401_uart_interrupt()</function> explicitly when 4401 have to set <constant>MPU401_INFO_IRQ_HOOK</constant>, and call
4397 a UART interrupt is invoked and checked in your own interrupt 4402 <function>snd_mpu401_uart_interrupt()</function> explicitly from your
4398 handler. 4403 own interrupt handler when it has determined that a UART interrupt
4404 has occurred.
4399 </para> 4405 </para>
4400 4406
4401 <para> 4407 <para>
diff --git a/Documentation/sound/alsa/ALSA-Configuration.txt b/Documentation/sound/alsa/ALSA-Configuration.txt
index 89757012c7ff..936699e4f04b 100644
--- a/Documentation/sound/alsa/ALSA-Configuration.txt
+++ b/Documentation/sound/alsa/ALSA-Configuration.txt
@@ -886,6 +886,12 @@ Prior to version 0.9.0rc4 options had a 'snd_' prefix. This was removed.
886 disable) 886 disable)
887 power_save_controller - Reset HD-audio controller in power-saving mode 887 power_save_controller - Reset HD-audio controller in power-saving mode
888 (default = on) 888 (default = on)
889 align_buffer_size - Force rounding of buffer/period sizes to multiples
890 of 128 bytes. This is more efficient in terms of memory
891 access but isn't required by the HDA spec and prevents
892 users from specifying exact period/buffer sizes.
893 (default = on)
894 snoop - Enable/disable snooping (default = on)
889 895
890 This module supports multiple cards and autoprobe. 896 This module supports multiple cards and autoprobe.
891 897
diff --git a/Documentation/sound/alsa/HD-Audio-Controls.txt b/Documentation/sound/alsa/HD-Audio-Controls.txt
index 1482035243e6..e9621e349e17 100644
--- a/Documentation/sound/alsa/HD-Audio-Controls.txt
+++ b/Documentation/sound/alsa/HD-Audio-Controls.txt
@@ -98,3 +98,19 @@ Conexant codecs
98 98
99* Auto-Mute Mode 99* Auto-Mute Mode
100 See Reatek codecs. 100 See Reatek codecs.
101
102
103Analog codecs
104--------------
105
106* Channel Mode
107 This is an enum control to change the surround-channel setup,
108 appears only when the surround channels are available.
109 It gives the number of channels to be used, "2ch", "4ch" and "6ch".
110 According to the configuration, this also controls the
111 jack-retasking of multi-I/O jacks.
112
113* Independent HP
114 When this enum control is enabled, the headphone output is routed
115 from an individual stream (the third PCM such as hw:0,2) instead of
116 the primary stream.
diff --git a/Documentation/sound/alsa/HD-Audio-Models.txt b/Documentation/sound/alsa/HD-Audio-Models.txt
index d70c93bdcadf..4f3443230d89 100644
--- a/Documentation/sound/alsa/HD-Audio-Models.txt
+++ b/Documentation/sound/alsa/HD-Audio-Models.txt
@@ -29,9 +29,6 @@ ALC880
29 29
30ALC260 30ALC260
31====== 31======
32 hp HP machines
33 hp-3013 HP machines (3013-variant)
34 hp-dc7600 HP DC7600
35 fujitsu Fujitsu S7020 32 fujitsu Fujitsu S7020
36 acer Acer TravelMate 33 acer Acer TravelMate
37 will Will laptops (PB V7900) 34 will Will laptops (PB V7900)
@@ -46,15 +43,10 @@ ALC260
46ALC262 43ALC262
47====== 44======
48 fujitsu Fujitsu Laptop 45 fujitsu Fujitsu Laptop
49 hp-bpc HP xw4400/6400/8400/9400 laptops
50 hp-bpc-d7000 HP BPC D7000
51 hp-tc-t5735 HP Thin Client T5735
52 hp-rp5700 HP RP5700
53 benq Benq ED8 46 benq Benq ED8
54 benq-t31 Benq T31 47 benq-t31 Benq T31
55 hippo Hippo (ATI) with jack detection, Sony UX-90s 48 hippo Hippo (ATI) with jack detection, Sony UX-90s
56 hippo_1 Hippo (Benq) with jack detection 49 hippo_1 Hippo (Benq) with jack detection
57 sony-assamd Sony ASSAMD
58 toshiba-s06 Toshiba S06 50 toshiba-s06 Toshiba S06
59 toshiba-rx1 Toshiba RX1 51 toshiba-rx1 Toshiba RX1
60 tyan Tyan Thunder n6650W (S2915-E) 52 tyan Tyan Thunder n6650W (S2915-E)
@@ -66,43 +58,15 @@ ALC262
66 58
67ALC267/268 59ALC267/268
68========== 60==========
69 quanta-il1 Quanta IL1 mini-notebook 61 N/A
70 3stack 3-stack model
71 toshiba Toshiba A205
72 acer Acer laptops
73 acer-dmic Acer laptops with digital-mic
74 acer-aspire Acer Aspire One
75 dell Dell OEM laptops (Vostro 1200)
76 zepto Zepto laptops
77 test for testing/debugging purpose, almost all controls can
78 adjusted. Appearing only when compiled with
79 $CONFIG_SND_DEBUG=y
80 auto auto-config reading BIOS (default)
81 62
82ALC269 63ALC269
83====== 64======
84 basic Basic preset
85 quanta Quanta FL1
86 laptop-amic Laptops with analog-mic input 65 laptop-amic Laptops with analog-mic input
87 laptop-dmic Laptops with digital-mic input 66 laptop-dmic Laptops with digital-mic input
88 fujitsu FSC Amilo
89 lifebook Fujitsu Lifebook S6420
90 auto auto-config reading BIOS (default)
91 67
92ALC662/663/272 68ALC662/663/272
93============== 69==============
94 3stack-dig 3-stack (2-channel) with SPDIF
95 3stack-6ch 3-stack (6-channel)
96 3stack-6ch-dig 3-stack (6-channel) with SPDIF
97 5stack-dig 5-stack with SPDIF
98 lenovo-101e Lenovo laptop
99 eeepc-p701 ASUS Eeepc P701
100 eeepc-ep20 ASUS Eeepc EP20
101 ecs ECS/Foxconn mobo
102 m51va ASUS M51VA
103 g71v ASUS G71V
104 h13 ASUS H13
105 g50v ASUS G50V
106 asus-mode1 ASUS 70 asus-mode1 ASUS
107 asus-mode2 ASUS 71 asus-mode2 ASUS
108 asus-mode3 ASUS 72 asus-mode3 ASUS
@@ -111,15 +75,10 @@ ALC662/663/272
111 asus-mode6 ASUS 75 asus-mode6 ASUS
112 asus-mode7 ASUS 76 asus-mode7 ASUS
113 asus-mode8 ASUS 77 asus-mode8 ASUS
114 dell Dell with ALC272
115 dell-zm1 Dell ZM1 with ALC272
116 samsung-nc10 Samsung NC10 mini notebook
117 auto auto-config reading BIOS (default)
118 78
119ALC680 79ALC680
120====== 80======
121 base Base model (ASUS NX90) 81 N/A
122 auto auto-config reading BIOS (default)
123 82
124ALC882/883/885/888/889 83ALC882/883/885/888/889
125====================== 84======================
@@ -175,28 +134,11 @@ ALC882/883/885/888/889
175 134
176ALC861/660 135ALC861/660
177========== 136==========
178 3stack 3-jack 137 N/A
179 3stack-dig 3-jack with SPDIF I/O
180 6stack-dig 6-jack with SPDIF I/O
181 3stack-660 3-jack (for ALC660)
182 uniwill-m31 Uniwill M31 laptop
183 toshiba Toshiba laptop support
184 asus Asus laptop support
185 asus-laptop ASUS F2/F3 laptops
186 auto auto-config reading BIOS (default)
187 138
188ALC861VD/660VD 139ALC861VD/660VD
189============== 140==============
190 3stack 3-jack 141 N/A
191 3stack-dig 3-jack with SPDIF OUT
192 6stack-dig 6-jack with SPDIF OUT
193 3stack-660 3-jack (for ALC660VD)
194 3stack-660-digout 3-jack with SPDIF OUT (for ALC660VD)
195 lenovo Lenovo 3000 C200
196 dallas Dallas laptops
197 hp HP TX1000
198 asus-v1s ASUS V1Sn
199 auto auto-config reading BIOS (default)
200 142
201CMI9880 143CMI9880
202======= 144=======
@@ -289,7 +231,6 @@ Conexant 5051
289 hp-dv6736 HP dv6736 231 hp-dv6736 HP dv6736
290 hp-f700 HP Compaq Presario F700 232 hp-f700 HP Compaq Presario F700
291 ideapad Lenovo IdeaPad laptop 233 ideapad Lenovo IdeaPad laptop
292 lenovo-x200 Lenovo X200 laptop
293 toshiba Toshiba Satellite M300 234 toshiba Toshiba Satellite M300
294 235
295Conexant 5066 236Conexant 5066
diff --git a/Documentation/sound/alsa/HD-Audio.txt b/Documentation/sound/alsa/HD-Audio.txt
index c82beb007634..03e2771ddeef 100644
--- a/Documentation/sound/alsa/HD-Audio.txt
+++ b/Documentation/sound/alsa/HD-Audio.txt
@@ -447,7 +447,10 @@ The file needs to have a line `[codec]`. The next line should contain
447three numbers indicating the codec vendor-id (0x12345678 in the 447three numbers indicating the codec vendor-id (0x12345678 in the
448example), the codec subsystem-id (0xabcd1234) and the address (2) of 448example), the codec subsystem-id (0xabcd1234) and the address (2) of
449the codec. The rest patch entries are applied to this specified codec 449the codec. The rest patch entries are applied to this specified codec
450until another codec entry is given. 450until another codec entry is given. Passing 0 or a negative number to
451the first or the second value will make the check of the corresponding
452field be skipped. It'll be useful for really broken devices that don't
453initialize SSID properly.
451 454
452The `[model]` line allows to change the model name of the each codec. 455The `[model]` line allows to change the model name of the each codec.
453In the example above, it will be changed to model=auto. 456In the example above, it will be changed to model=auto.
@@ -491,7 +494,7 @@ Also, the codec chip name can be rewritten via `[chip_name]` line.
491The hd-audio driver reads the file via request_firmware(). Thus, 494The hd-audio driver reads the file via request_firmware(). Thus,
492a patch file has to be located on the appropriate firmware path, 495a patch file has to be located on the appropriate firmware path,
493typically, /lib/firmware. For example, when you pass the option 496typically, /lib/firmware. For example, when you pass the option
494`patch=hda-init.fw`, the file /lib/firmware/hda-init-fw must be 497`patch=hda-init.fw`, the file /lib/firmware/hda-init.fw must be
495present. 498present.
496 499
497The patch module option is specific to each card instance, and you 500The patch module option is specific to each card instance, and you
@@ -524,6 +527,54 @@ power-saving. See /sys/module/snd_hda_intel/parameters/power_save to
524check the current value. If it's non-zero, the feature is turned on. 527check the current value. If it's non-zero, the feature is turned on.
525 528
526 529
530Tracepoints
531~~~~~~~~~~~
532The hd-audio driver gives a few basic tracepoints.
533`hda:hda_send_cmd` traces each CORB write while `hda:hda_get_response`
534traces the response from RIRB (only when read from the codec driver).
535`hda:hda_bus_reset` traces the bus-reset due to fatal error, etc,
536`hda:hda_unsol_event` traces the unsolicited events, and
537`hda:hda_power_down` and `hda:hda_power_up` trace the power down/up
538via power-saving behavior.
539
540Enabling all tracepoints can be done like
541------------------------------------------------------------------------
542 # echo 1 > /sys/kernel/debug/tracing/events/hda/enable
543------------------------------------------------------------------------
544then after some commands, you can traces from
545/sys/kernel/debug/tracing/trace file. For example, when you want to
546trace what codec command is sent, enable the tracepoint like:
547------------------------------------------------------------------------
548 # cat /sys/kernel/debug/tracing/trace
549 # tracer: nop
550 #
551 # TASK-PID CPU# TIMESTAMP FUNCTION
552 # | | | | |
553 <...>-7807 [002] 105147.774889: hda_send_cmd: [0:0] val=e3a019
554 <...>-7807 [002] 105147.774893: hda_send_cmd: [0:0] val=e39019
555 <...>-7807 [002] 105147.999542: hda_send_cmd: [0:0] val=e3a01a
556 <...>-7807 [002] 105147.999543: hda_send_cmd: [0:0] val=e3901a
557 <...>-26764 [001] 349222.837143: hda_send_cmd: [0:0] val=e3a019
558 <...>-26764 [001] 349222.837148: hda_send_cmd: [0:0] val=e39019
559 <...>-26764 [001] 349223.058539: hda_send_cmd: [0:0] val=e3a01a
560 <...>-26764 [001] 349223.058541: hda_send_cmd: [0:0] val=e3901a
561------------------------------------------------------------------------
562Here `[0:0]` indicates the card number and the codec address, and
563`val` shows the value sent to the codec, respectively. The value is
564a packed value, and you can decode it via hda-decode-verb program
565included in hda-emu package below. For example, the value e3a019 is
566to set the left output-amp value to 25.
567------------------------------------------------------------------------
568 % hda-decode-verb 0xe3a019
569 raw value = 0x00e3a019
570 cid = 0, nid = 0x0e, verb = 0x3a0, parm = 0x19
571 raw value: verb = 0x3a0, parm = 0x19
572 verbname = set_amp_gain_mute
573 amp raw val = 0xa019
574 output, left, idx=0, mute=0, val=25
575------------------------------------------------------------------------
576
577
527Development Tree 578Development Tree
528~~~~~~~~~~~~~~~~ 579~~~~~~~~~~~~~~~~
529The latest development codes for HD-audio are found on sound git tree: 580The latest development codes for HD-audio are found on sound git tree:
diff --git a/MAINTAINERS b/MAINTAINERS
index bbf42cd74e2a..1dbbb278d218 100644
--- a/MAINTAINERS
+++ b/MAINTAINERS
@@ -5991,7 +5991,7 @@ M: Jaroslav Kysela <perex@perex.cz>
5991M: Takashi Iwai <tiwai@suse.de> 5991M: Takashi Iwai <tiwai@suse.de>
5992L: alsa-devel@alsa-project.org (moderated for non-subscribers) 5992L: alsa-devel@alsa-project.org (moderated for non-subscribers)
5993W: http://www.alsa-project.org/ 5993W: http://www.alsa-project.org/
5994T: git git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound-2.6.git 5994T: git git://git.kernel.org/pub/scm/linux/kernel/git/tiwai/sound.git
5995T: git git://git.alsa-project.org/alsa-kernel.git 5995T: git git://git.alsa-project.org/alsa-kernel.git
5996S: Maintained 5996S: Maintained
5997F: Documentation/sound/ 5997F: Documentation/sound/
diff --git a/include/linux/input.h b/include/linux/input.h
index a637e7814334..a514fb8faea3 100644
--- a/include/linux/input.h
+++ b/include/linux/input.h
@@ -814,6 +814,7 @@ struct input_keymap_entry {
814#define SW_KEYPAD_SLIDE 0x0a /* set = keypad slide out */ 814#define SW_KEYPAD_SLIDE 0x0a /* set = keypad slide out */
815#define SW_FRONT_PROXIMITY 0x0b /* set = front proximity sensor active */ 815#define SW_FRONT_PROXIMITY 0x0b /* set = front proximity sensor active */
816#define SW_ROTATE_LOCK 0x0c /* set = rotate locked/disabled */ 816#define SW_ROTATE_LOCK 0x0c /* set = rotate locked/disabled */
817#define SW_LINEIN_INSERT 0x0d /* set = inserted */
817#define SW_MAX 0x0f 818#define SW_MAX 0x0f
818#define SW_CNT (SW_MAX+1) 819#define SW_CNT (SW_MAX+1)
819 820
diff --git a/include/linux/usb/ch9.h b/include/linux/usb/ch9.h
index 0fd3fbdd8283..f30253599501 100644
--- a/include/linux/usb/ch9.h
+++ b/include/linux/usb/ch9.h
@@ -377,12 +377,6 @@ struct usb_endpoint_descriptor {
377#define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */ 377#define USB_ENDPOINT_NUMBER_MASK 0x0f /* in bEndpointAddress */
378#define USB_ENDPOINT_DIR_MASK 0x80 378#define USB_ENDPOINT_DIR_MASK 0x80
379 379
380#define USB_ENDPOINT_SYNCTYPE 0x0c
381#define USB_ENDPOINT_SYNC_NONE (0 << 2)
382#define USB_ENDPOINT_SYNC_ASYNC (1 << 2)
383#define USB_ENDPOINT_SYNC_ADAPTIVE (2 << 2)
384#define USB_ENDPOINT_SYNC_SYNC (3 << 2)
385
386#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */ 380#define USB_ENDPOINT_XFERTYPE_MASK 0x03 /* in bmAttributes */
387#define USB_ENDPOINT_XFER_CONTROL 0 381#define USB_ENDPOINT_XFER_CONTROL 0
388#define USB_ENDPOINT_XFER_ISOC 1 382#define USB_ENDPOINT_XFER_ISOC 1
@@ -390,6 +384,17 @@ struct usb_endpoint_descriptor {
390#define USB_ENDPOINT_XFER_INT 3 384#define USB_ENDPOINT_XFER_INT 3
391#define USB_ENDPOINT_MAX_ADJUSTABLE 0x80 385#define USB_ENDPOINT_MAX_ADJUSTABLE 0x80
392 386
387#define USB_ENDPOINT_SYNCTYPE 0x0c
388#define USB_ENDPOINT_SYNC_NONE (0 << 2)
389#define USB_ENDPOINT_SYNC_ASYNC (1 << 2)
390#define USB_ENDPOINT_SYNC_ADAPTIVE (2 << 2)
391#define USB_ENDPOINT_SYNC_SYNC (3 << 2)
392
393#define USB_ENDPOINT_USAGE_MASK 0x30
394#define USB_ENDPOINT_USAGE_DATA 0x00
395#define USB_ENDPOINT_USAGE_FEEDBACK 0x10
396#define USB_ENDPOINT_USAGE_IMPLICIT_FB 0x20 /* Implicit feedback Data endpoint */
397
393/*-------------------------------------------------------------------------*/ 398/*-------------------------------------------------------------------------*/
394 399
395/** 400/**
diff --git a/include/sound/asound.h b/include/sound/asound.h
index 5d6074faa279..a2e4ff5ba9e9 100644
--- a/include/sound/asound.h
+++ b/include/sound/asound.h
@@ -706,7 +706,7 @@ struct snd_timer_tread {
706 * * 706 * *
707 ****************************************************************************/ 707 ****************************************************************************/
708 708
709#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 6) 709#define SNDRV_CTL_VERSION SNDRV_PROTOCOL_VERSION(2, 0, 7)
710 710
711struct snd_ctl_card_info { 711struct snd_ctl_card_info {
712 int card; /* card number */ 712 int card; /* card number */
@@ -803,6 +803,8 @@ struct snd_ctl_elem_info {
803 unsigned int items; /* R: number of items */ 803 unsigned int items; /* R: number of items */
804 unsigned int item; /* W: item number */ 804 unsigned int item; /* W: item number */
805 char name[64]; /* R: value name */ 805 char name[64]; /* R: value name */
806 __u64 names_ptr; /* W: names list (ELEM_ADD only) */
807 unsigned int names_length;
806 } enumerated; 808 } enumerated;
807 unsigned char reserved[128]; 809 unsigned char reserved[128];
808 } value; 810 } value;
diff --git a/include/sound/initval.h b/include/sound/initval.h
index 1daa6dff8297..f99a0d2ddfe7 100644
--- a/include/sound/initval.h
+++ b/include/sound/initval.h
@@ -62,7 +62,7 @@ static int snd_legacy_find_free_irq(int *irq_table)
62{ 62{
63 while (*irq_table != -1) { 63 while (*irq_table != -1) {
64 if (!request_irq(*irq_table, snd_legacy_empty_irq_handler, 64 if (!request_irq(*irq_table, snd_legacy_empty_irq_handler,
65 IRQF_DISABLED | IRQF_PROBE_SHARED, "ALSA Test IRQ", 65 IRQF_PROBE_SHARED, "ALSA Test IRQ",
66 (void *) irq_table)) { 66 (void *) irq_table)) {
67 free_irq(*irq_table, (void *) irq_table); 67 free_irq(*irq_table, (void *) irq_table);
68 return *irq_table; 68 return *irq_table;
diff --git a/include/sound/jack.h b/include/sound/jack.h
index c140fc7cbd3f..63c790742db4 100644
--- a/include/sound/jack.h
+++ b/include/sound/jack.h
@@ -42,6 +42,7 @@ enum snd_jack_types {
42 SND_JACK_MECHANICAL = 0x0008, /* If detected separately */ 42 SND_JACK_MECHANICAL = 0x0008, /* If detected separately */
43 SND_JACK_VIDEOOUT = 0x0010, 43 SND_JACK_VIDEOOUT = 0x0010,
44 SND_JACK_AVOUT = SND_JACK_LINEOUT | SND_JACK_VIDEOOUT, 44 SND_JACK_AVOUT = SND_JACK_LINEOUT | SND_JACK_VIDEOOUT,
45 SND_JACK_LINEIN = 0x0020,
45 46
46 /* Kept separate from switches to facilitate implementation */ 47 /* Kept separate from switches to facilitate implementation */
47 SND_JACK_BTN_0 = 0x4000, 48 SND_JACK_BTN_0 = 0x4000,
diff --git a/include/sound/mpu401.h b/include/sound/mpu401.h
index 1f1d53f8830b..20230db00ef1 100644
--- a/include/sound/mpu401.h
+++ b/include/sound/mpu401.h
@@ -50,7 +50,10 @@
50#define MPU401_INFO_INTEGRATED (1 << 2) /* integrated h/w port */ 50#define MPU401_INFO_INTEGRATED (1 << 2) /* integrated h/w port */
51#define MPU401_INFO_MMIO (1 << 3) /* MMIO access */ 51#define MPU401_INFO_MMIO (1 << 3) /* MMIO access */
52#define MPU401_INFO_TX_IRQ (1 << 4) /* independent TX irq */ 52#define MPU401_INFO_TX_IRQ (1 << 4) /* independent TX irq */
53#define MPU401_INFO_IRQ_HOOK (1 << 5) /* mpu401 irq handler is called
54 from driver irq handler */
53#define MPU401_INFO_NO_ACK (1 << 6) /* No ACK cmd needed */ 55#define MPU401_INFO_NO_ACK (1 << 6) /* No ACK cmd needed */
56#define MPU401_INFO_USE_TIMER (1 << 15) /* internal */
54 57
55#define MPU401_MODE_BIT_INPUT 0 58#define MPU401_MODE_BIT_INPUT 0
56#define MPU401_MODE_BIT_OUTPUT 1 59#define MPU401_MODE_BIT_OUTPUT 1
@@ -73,8 +76,7 @@ struct snd_mpu401 {
73 unsigned long port; /* base port of MPU-401 chip */ 76 unsigned long port; /* base port of MPU-401 chip */
74 unsigned long cport; /* port + 1 (usually) */ 77 unsigned long cport; /* port + 1 (usually) */
75 struct resource *res; /* port resource */ 78 struct resource *res; /* port resource */
76 int irq; /* IRQ number of MPU-401 chip (-1 = poll) */ 79 int irq; /* IRQ number of MPU-401 chip */
77 int irq_flags;
78 80
79 unsigned long mode; /* MPU401_MODE_XXXX */ 81 unsigned long mode; /* MPU401_MODE_XXXX */
80 int timer_invoked; 82 int timer_invoked;
@@ -131,7 +133,6 @@ int snd_mpu401_uart_new(struct snd_card *card,
131 unsigned long port, 133 unsigned long port,
132 unsigned int info_flags, 134 unsigned int info_flags,
133 int irq, 135 int irq,
134 int irq_flags,
135 struct snd_rawmidi ** rrawmidi); 136 struct snd_rawmidi ** rrawmidi);
136 137
137#endif /* __SOUND_MPU401_H */ 138#endif /* __SOUND_MPU401_H */
diff --git a/include/sound/pcm.h b/include/sound/pcm.h
index 57e71fa33f7c..3e7fda6e8164 100644
--- a/include/sound/pcm.h
+++ b/include/sound/pcm.h
@@ -825,6 +825,8 @@ int snd_pcm_hw_constraint_step(struct snd_pcm_runtime *runtime,
825int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime, 825int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
826 unsigned int cond, 826 unsigned int cond,
827 snd_pcm_hw_param_t var); 827 snd_pcm_hw_param_t var);
828int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
829 unsigned int base_rate);
828int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime, 830int snd_pcm_hw_rule_add(struct snd_pcm_runtime *runtime,
829 unsigned int cond, 831 unsigned int cond,
830 int var, 832 int var,
@@ -1035,6 +1037,8 @@ static inline void snd_pcm_mmap_data_close(struct vm_area_struct *area)
1035 atomic_dec(&substream->mmap_count); 1037 atomic_dec(&substream->mmap_count);
1036} 1038}
1037 1039
1040int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
1041 struct vm_area_struct *area);
1038/* mmap for io-memory area */ 1042/* mmap for io-memory area */
1039#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA) 1043#if defined(CONFIG_X86) || defined(CONFIG_PPC) || defined(CONFIG_ALPHA)
1040#define SNDRV_PCM_INFO_MMAP_IOMEM SNDRV_PCM_INFO_MMAP 1044#define SNDRV_PCM_INFO_MMAP_IOMEM SNDRV_PCM_INFO_MMAP
diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
index 3687a6cc9881..762af68c8996 100644
--- a/sound/aoa/codecs/onyx.c
+++ b/sound/aoa/codecs/onyx.c
@@ -1067,7 +1067,6 @@ static int onyx_i2c_probe(struct i2c_client *client,
1067 printk(KERN_DEBUG PFX "created and attached onyx instance\n"); 1067 printk(KERN_DEBUG PFX "created and attached onyx instance\n");
1068 return 0; 1068 return 0;
1069 fail: 1069 fail:
1070 i2c_set_clientdata(client, NULL);
1071 kfree(onyx); 1070 kfree(onyx);
1072 return -ENODEV; 1071 return -ENODEV;
1073} 1072}
@@ -1112,8 +1111,7 @@ static int onyx_i2c_remove(struct i2c_client *client)
1112 1111
1113 aoa_codec_unregister(&onyx->codec); 1112 aoa_codec_unregister(&onyx->codec);
1114 of_node_put(onyx->codec.node); 1113 of_node_put(onyx->codec.node);
1115 if (onyx->codec_info) 1114 kfree(onyx->codec_info);
1116 kfree(onyx->codec_info);
1117 kfree(onyx); 1115 kfree(onyx);
1118 return 0; 1116 return 0;
1119} 1117}
diff --git a/sound/aoa/fabrics/layout.c b/sound/aoa/fabrics/layout.c
index 3fd1a7e24928..552b97afbca5 100644
--- a/sound/aoa/fabrics/layout.c
+++ b/sound/aoa/fabrics/layout.c
@@ -1073,10 +1073,10 @@ static int aoa_fabric_layout_probe(struct soundbus_dev *sdev)
1073 sdev->pcmid = -1; 1073 sdev->pcmid = -1;
1074 list_del(&ldev->list); 1074 list_del(&ldev->list);
1075 layouts_list_items--; 1075 layouts_list_items--;
1076 kfree(ldev);
1076 outnodev: 1077 outnodev:
1077 of_node_put(sound); 1078 of_node_put(sound);
1078 layout_device = NULL; 1079 layout_device = NULL;
1079 kfree(ldev);
1080 return -ENODEV; 1080 return -ENODEV;
1081} 1081}
1082 1082
diff --git a/sound/arm/aaci.c b/sound/arm/aaci.c
index d0cead38d5fb..e518d38b1c74 100644
--- a/sound/arm/aaci.c
+++ b/sound/arm/aaci.c
@@ -443,7 +443,7 @@ static int aaci_pcm_open(struct snd_pcm_substream *substream)
443 mutex_lock(&aaci->irq_lock); 443 mutex_lock(&aaci->irq_lock);
444 if (!aaci->users++) { 444 if (!aaci->users++) {
445 ret = request_irq(aaci->dev->irq[0], aaci_irq, 445 ret = request_irq(aaci->dev->irq[0], aaci_irq,
446 IRQF_SHARED | IRQF_DISABLED, DRIVER_NAME, aaci); 446 IRQF_SHARED, DRIVER_NAME, aaci);
447 if (ret != 0) 447 if (ret != 0)
448 aaci->users--; 448 aaci->users--;
449 } 449 }
diff --git a/sound/arm/pxa2xx-ac97-lib.c b/sound/arm/pxa2xx-ac97-lib.c
index 88eec3847df2..8ad65352bf91 100644
--- a/sound/arm/pxa2xx-ac97-lib.c
+++ b/sound/arm/pxa2xx-ac97-lib.c
@@ -359,7 +359,7 @@ int __devinit pxa2xx_ac97_hw_probe(struct platform_device *dev)
359 if (ret) 359 if (ret)
360 goto err_clk2; 360 goto err_clk2;
361 361
362 ret = request_irq(IRQ_AC97, pxa2xx_ac97_irq, IRQF_DISABLED, "AC97", NULL); 362 ret = request_irq(IRQ_AC97, pxa2xx_ac97_irq, 0, "AC97", NULL);
363 if (ret < 0) 363 if (ret < 0)
364 goto err_irq; 364 goto err_irq;
365 365
diff --git a/sound/core/control.c b/sound/core/control.c
index f8c5be464510..978fe1a8e9f0 100644
--- a/sound/core/control.c
+++ b/sound/core/control.c
@@ -989,7 +989,6 @@ struct user_element {
989 void *tlv_data; /* TLV data */ 989 void *tlv_data; /* TLV data */
990 unsigned long tlv_data_size; /* TLV data size */ 990 unsigned long tlv_data_size; /* TLV data size */
991 void *priv_data; /* private data (like strings for enumerated type) */ 991 void *priv_data; /* private data (like strings for enumerated type) */
992 unsigned long priv_data_size; /* size of private data in bytes */
993}; 992};
994 993
995static int snd_ctl_elem_user_info(struct snd_kcontrol *kcontrol, 994static int snd_ctl_elem_user_info(struct snd_kcontrol *kcontrol,
@@ -1001,6 +1000,28 @@ static int snd_ctl_elem_user_info(struct snd_kcontrol *kcontrol,
1001 return 0; 1000 return 0;
1002} 1001}
1003 1002
1003static int snd_ctl_elem_user_enum_info(struct snd_kcontrol *kcontrol,
1004 struct snd_ctl_elem_info *uinfo)
1005{
1006 struct user_element *ue = kcontrol->private_data;
1007 const char *names;
1008 unsigned int item;
1009
1010 item = uinfo->value.enumerated.item;
1011
1012 *uinfo = ue->info;
1013
1014 item = min(item, uinfo->value.enumerated.items - 1);
1015 uinfo->value.enumerated.item = item;
1016
1017 names = ue->priv_data;
1018 for (; item > 0; --item)
1019 names += strlen(names) + 1;
1020 strcpy(uinfo->value.enumerated.name, names);
1021
1022 return 0;
1023}
1024
1004static int snd_ctl_elem_user_get(struct snd_kcontrol *kcontrol, 1025static int snd_ctl_elem_user_get(struct snd_kcontrol *kcontrol,
1005 struct snd_ctl_elem_value *ucontrol) 1026 struct snd_ctl_elem_value *ucontrol)
1006{ 1027{
@@ -1055,11 +1076,46 @@ static int snd_ctl_elem_user_tlv(struct snd_kcontrol *kcontrol,
1055 return change; 1076 return change;
1056} 1077}
1057 1078
1079static int snd_ctl_elem_init_enum_names(struct user_element *ue)
1080{
1081 char *names, *p;
1082 size_t buf_len, name_len;
1083 unsigned int i;
1084
1085 if (ue->info.value.enumerated.names_length > 64 * 1024)
1086 return -EINVAL;
1087
1088 names = memdup_user(
1089 (const void __user *)ue->info.value.enumerated.names_ptr,
1090 ue->info.value.enumerated.names_length);
1091 if (IS_ERR(names))
1092 return PTR_ERR(names);
1093
1094 /* check that there are enough valid names */
1095 buf_len = ue->info.value.enumerated.names_length;
1096 p = names;
1097 for (i = 0; i < ue->info.value.enumerated.items; ++i) {
1098 name_len = strnlen(p, buf_len);
1099 if (name_len == 0 || name_len >= 64 || name_len == buf_len) {
1100 kfree(names);
1101 return -EINVAL;
1102 }
1103 p += name_len + 1;
1104 buf_len -= name_len + 1;
1105 }
1106
1107 ue->priv_data = names;
1108 ue->info.value.enumerated.names_ptr = 0;
1109
1110 return 0;
1111}
1112
1058static void snd_ctl_elem_user_free(struct snd_kcontrol *kcontrol) 1113static void snd_ctl_elem_user_free(struct snd_kcontrol *kcontrol)
1059{ 1114{
1060 struct user_element *ue = kcontrol->private_data; 1115 struct user_element *ue = kcontrol->private_data;
1061 if (ue->tlv_data) 1116
1062 kfree(ue->tlv_data); 1117 kfree(ue->tlv_data);
1118 kfree(ue->priv_data);
1063 kfree(ue); 1119 kfree(ue);
1064} 1120}
1065 1121
@@ -1072,8 +1128,8 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
1072 long private_size; 1128 long private_size;
1073 struct user_element *ue; 1129 struct user_element *ue;
1074 int idx, err; 1130 int idx, err;
1075 1131
1076 if (card->user_ctl_count >= MAX_USER_CONTROLS) 1132 if (!replace && card->user_ctl_count >= MAX_USER_CONTROLS)
1077 return -ENOMEM; 1133 return -ENOMEM;
1078 if (info->count < 1) 1134 if (info->count < 1)
1079 return -EINVAL; 1135 return -EINVAL;
@@ -1101,7 +1157,10 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
1101 memcpy(&kctl.id, &info->id, sizeof(info->id)); 1157 memcpy(&kctl.id, &info->id, sizeof(info->id));
1102 kctl.count = info->owner ? info->owner : 1; 1158 kctl.count = info->owner ? info->owner : 1;
1103 access |= SNDRV_CTL_ELEM_ACCESS_USER; 1159 access |= SNDRV_CTL_ELEM_ACCESS_USER;
1104 kctl.info = snd_ctl_elem_user_info; 1160 if (info->type == SNDRV_CTL_ELEM_TYPE_ENUMERATED)
1161 kctl.info = snd_ctl_elem_user_enum_info;
1162 else
1163 kctl.info = snd_ctl_elem_user_info;
1105 if (access & SNDRV_CTL_ELEM_ACCESS_READ) 1164 if (access & SNDRV_CTL_ELEM_ACCESS_READ)
1106 kctl.get = snd_ctl_elem_user_get; 1165 kctl.get = snd_ctl_elem_user_get;
1107 if (access & SNDRV_CTL_ELEM_ACCESS_WRITE) 1166 if (access & SNDRV_CTL_ELEM_ACCESS_WRITE)
@@ -1122,6 +1181,11 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
1122 if (info->count > 64) 1181 if (info->count > 64)
1123 return -EINVAL; 1182 return -EINVAL;
1124 break; 1183 break;
1184 case SNDRV_CTL_ELEM_TYPE_ENUMERATED:
1185 private_size = sizeof(unsigned int);
1186 if (info->count > 128 || info->value.enumerated.items == 0)
1187 return -EINVAL;
1188 break;
1125 case SNDRV_CTL_ELEM_TYPE_BYTES: 1189 case SNDRV_CTL_ELEM_TYPE_BYTES:
1126 private_size = sizeof(unsigned char); 1190 private_size = sizeof(unsigned char);
1127 if (info->count > 512) 1191 if (info->count > 512)
@@ -1143,9 +1207,17 @@ static int snd_ctl_elem_add(struct snd_ctl_file *file,
1143 ue->info.access = 0; 1207 ue->info.access = 0;
1144 ue->elem_data = (char *)ue + sizeof(*ue); 1208 ue->elem_data = (char *)ue + sizeof(*ue);
1145 ue->elem_data_size = private_size; 1209 ue->elem_data_size = private_size;
1210 if (ue->info.type == SNDRV_CTL_ELEM_TYPE_ENUMERATED) {
1211 err = snd_ctl_elem_init_enum_names(ue);
1212 if (err < 0) {
1213 kfree(ue);
1214 return err;
1215 }
1216 }
1146 kctl.private_free = snd_ctl_elem_user_free; 1217 kctl.private_free = snd_ctl_elem_user_free;
1147 _kctl = snd_ctl_new(&kctl, access); 1218 _kctl = snd_ctl_new(&kctl, access);
1148 if (_kctl == NULL) { 1219 if (_kctl == NULL) {
1220 kfree(ue->priv_data);
1149 kfree(ue); 1221 kfree(ue);
1150 return -ENOMEM; 1222 return -ENOMEM;
1151 } 1223 }
diff --git a/sound/core/control_compat.c b/sound/core/control_compat.c
index 426874429a5e..2bb95a7a8809 100644
--- a/sound/core/control_compat.c
+++ b/sound/core/control_compat.c
@@ -83,6 +83,8 @@ struct snd_ctl_elem_info32 {
83 u32 items; 83 u32 items;
84 u32 item; 84 u32 item;
85 char name[64]; 85 char name[64];
86 u64 names_ptr;
87 u32 names_length;
86 } enumerated; 88 } enumerated;
87 unsigned char reserved[128]; 89 unsigned char reserved[128];
88 } value; 90 } value;
@@ -372,6 +374,8 @@ static int snd_ctl_elem_add_compat(struct snd_ctl_file *file,
372 &data32->value.enumerated, 374 &data32->value.enumerated,
373 sizeof(data->value.enumerated))) 375 sizeof(data->value.enumerated)))
374 goto error; 376 goto error;
377 data->value.enumerated.names_ptr =
378 (uintptr_t)compat_ptr(data->value.enumerated.names_ptr);
375 break; 379 break;
376 default: 380 default:
377 break; 381 break;
diff --git a/sound/core/hwdep.c b/sound/core/hwdep.c
index a70ee7f1ed98..031e215b6dde 100644
--- a/sound/core/hwdep.c
+++ b/sound/core/hwdep.c
@@ -272,7 +272,14 @@ static int snd_hwdep_control_ioctl(struct snd_card *card,
272 if (get_user(device, (int __user *)arg)) 272 if (get_user(device, (int __user *)arg))
273 return -EFAULT; 273 return -EFAULT;
274 mutex_lock(&register_mutex); 274 mutex_lock(&register_mutex);
275 device = device < 0 ? 0 : device + 1; 275
276 if (device < 0)
277 device = 0;
278 else if (device < SNDRV_MINOR_HWDEPS)
279 device++;
280 else
281 device = SNDRV_MINOR_HWDEPS;
282
276 while (device < SNDRV_MINOR_HWDEPS) { 283 while (device < SNDRV_MINOR_HWDEPS) {
277 if (snd_hwdep_search(card, device)) 284 if (snd_hwdep_search(card, device))
278 break; 285 break;
diff --git a/sound/core/jack.c b/sound/core/jack.c
index 53b53e97c896..240a3e13470d 100644
--- a/sound/core/jack.c
+++ b/sound/core/jack.c
@@ -30,6 +30,7 @@ static int jack_switch_types[] = {
30 SW_LINEOUT_INSERT, 30 SW_LINEOUT_INSERT,
31 SW_JACK_PHYSICAL_INSERT, 31 SW_JACK_PHYSICAL_INSERT,
32 SW_VIDEOOUT_INSERT, 32 SW_VIDEOOUT_INSERT,
33 SW_LINEIN_INSERT,
33}; 34};
34 35
35static int snd_jack_dev_free(struct snd_device *device) 36static int snd_jack_dev_free(struct snd_device *device)
diff --git a/sound/core/oss/mixer_oss.c b/sound/core/oss/mixer_oss.c
index d8359cfeca15..1b5e0c49a0ad 100644
--- a/sound/core/oss/mixer_oss.c
+++ b/sound/core/oss/mixer_oss.c
@@ -499,7 +499,7 @@ static struct snd_kcontrol *snd_mixer_oss_test_id(struct snd_mixer_oss *mixer, c
499 499
500 memset(&id, 0, sizeof(id)); 500 memset(&id, 0, sizeof(id));
501 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER; 501 id.iface = SNDRV_CTL_ELEM_IFACE_MIXER;
502 strcpy(id.name, name); 502 strlcpy(id.name, name, sizeof(id.name));
503 id.index = index; 503 id.index = index;
504 return snd_ctl_find_id(card, &id); 504 return snd_ctl_find_id(card, &id);
505} 505}
diff --git a/sound/core/pcm_lib.c b/sound/core/pcm_lib.c
index 86d0caf91b35..95d1e789715f 100644
--- a/sound/core/pcm_lib.c
+++ b/sound/core/pcm_lib.c
@@ -1399,6 +1399,32 @@ int snd_pcm_hw_constraint_pow2(struct snd_pcm_runtime *runtime,
1399 1399
1400EXPORT_SYMBOL(snd_pcm_hw_constraint_pow2); 1400EXPORT_SYMBOL(snd_pcm_hw_constraint_pow2);
1401 1401
1402static int snd_pcm_hw_rule_noresample_func(struct snd_pcm_hw_params *params,
1403 struct snd_pcm_hw_rule *rule)
1404{
1405 unsigned int base_rate = (unsigned int)(uintptr_t)rule->private;
1406 struct snd_interval *rate;
1407
1408 rate = hw_param_interval(params, SNDRV_PCM_HW_PARAM_RATE);
1409 return snd_interval_list(rate, 1, &base_rate, 0);
1410}
1411
1412/**
1413 * snd_pcm_hw_rule_noresample - add a rule to allow disabling hw resampling
1414 * @runtime: PCM runtime instance
1415 * @base_rate: the rate at which the hardware does not resample
1416 */
1417int snd_pcm_hw_rule_noresample(struct snd_pcm_runtime *runtime,
1418 unsigned int base_rate)
1419{
1420 return snd_pcm_hw_rule_add(runtime, SNDRV_PCM_HW_PARAMS_NORESAMPLE,
1421 SNDRV_PCM_HW_PARAM_RATE,
1422 snd_pcm_hw_rule_noresample_func,
1423 (void *)(uintptr_t)base_rate,
1424 SNDRV_PCM_HW_PARAM_RATE, -1);
1425}
1426EXPORT_SYMBOL(snd_pcm_hw_rule_noresample);
1427
1402static void _snd_pcm_hw_param_any(struct snd_pcm_hw_params *params, 1428static void _snd_pcm_hw_param_any(struct snd_pcm_hw_params *params,
1403 snd_pcm_hw_param_t var) 1429 snd_pcm_hw_param_t var)
1404{ 1430{
@@ -1761,6 +1787,10 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
1761 snd_pcm_uframes_t avail = 0; 1787 snd_pcm_uframes_t avail = 0;
1762 long wait_time, tout; 1788 long wait_time, tout;
1763 1789
1790 init_waitqueue_entry(&wait, current);
1791 set_current_state(TASK_INTERRUPTIBLE);
1792 add_wait_queue(&runtime->tsleep, &wait);
1793
1764 if (runtime->no_period_wakeup) 1794 if (runtime->no_period_wakeup)
1765 wait_time = MAX_SCHEDULE_TIMEOUT; 1795 wait_time = MAX_SCHEDULE_TIMEOUT;
1766 else { 1796 else {
@@ -1771,16 +1801,32 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
1771 } 1801 }
1772 wait_time = msecs_to_jiffies(wait_time * 1000); 1802 wait_time = msecs_to_jiffies(wait_time * 1000);
1773 } 1803 }
1774 init_waitqueue_entry(&wait, current); 1804
1775 add_wait_queue(&runtime->tsleep, &wait);
1776 for (;;) { 1805 for (;;) {
1777 if (signal_pending(current)) { 1806 if (signal_pending(current)) {
1778 err = -ERESTARTSYS; 1807 err = -ERESTARTSYS;
1779 break; 1808 break;
1780 } 1809 }
1810
1811 /*
1812 * We need to check if space became available already
1813 * (and thus the wakeup happened already) first to close
1814 * the race of space already having become available.
1815 * This check must happen after been added to the waitqueue
1816 * and having current state be INTERRUPTIBLE.
1817 */
1818 if (is_playback)
1819 avail = snd_pcm_playback_avail(runtime);
1820 else
1821 avail = snd_pcm_capture_avail(runtime);
1822 if (avail >= runtime->twake)
1823 break;
1781 snd_pcm_stream_unlock_irq(substream); 1824 snd_pcm_stream_unlock_irq(substream);
1782 tout = schedule_timeout_interruptible(wait_time); 1825
1826 tout = schedule_timeout(wait_time);
1827
1783 snd_pcm_stream_lock_irq(substream); 1828 snd_pcm_stream_lock_irq(substream);
1829 set_current_state(TASK_INTERRUPTIBLE);
1784 switch (runtime->status->state) { 1830 switch (runtime->status->state) {
1785 case SNDRV_PCM_STATE_SUSPENDED: 1831 case SNDRV_PCM_STATE_SUSPENDED:
1786 err = -ESTRPIPE; 1832 err = -ESTRPIPE;
@@ -1806,14 +1852,9 @@ static int wait_for_avail(struct snd_pcm_substream *substream,
1806 err = -EIO; 1852 err = -EIO;
1807 break; 1853 break;
1808 } 1854 }
1809 if (is_playback)
1810 avail = snd_pcm_playback_avail(runtime);
1811 else
1812 avail = snd_pcm_capture_avail(runtime);
1813 if (avail >= runtime->twake)
1814 break;
1815 } 1855 }
1816 _endloop: 1856 _endloop:
1857 set_current_state(TASK_RUNNING);
1817 remove_wait_queue(&runtime->tsleep, &wait); 1858 remove_wait_queue(&runtime->tsleep, &wait);
1818 *availp = avail; 1859 *availp = avail;
1819 return err; 1860 return err;
diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
index 1c6be91dfb98..77d7df22e7c8 100644
--- a/sound/core/pcm_native.c
+++ b/sound/core/pcm_native.c
@@ -2058,16 +2058,12 @@ EXPORT_SYMBOL(snd_pcm_open_substream);
2058 2058
2059static int snd_pcm_open_file(struct file *file, 2059static int snd_pcm_open_file(struct file *file,
2060 struct snd_pcm *pcm, 2060 struct snd_pcm *pcm,
2061 int stream, 2061 int stream)
2062 struct snd_pcm_file **rpcm_file)
2063{ 2062{
2064 struct snd_pcm_file *pcm_file; 2063 struct snd_pcm_file *pcm_file;
2065 struct snd_pcm_substream *substream; 2064 struct snd_pcm_substream *substream;
2066 int err; 2065 int err;
2067 2066
2068 if (rpcm_file)
2069 *rpcm_file = NULL;
2070
2071 err = snd_pcm_open_substream(pcm, stream, file, &substream); 2067 err = snd_pcm_open_substream(pcm, stream, file, &substream);
2072 if (err < 0) 2068 if (err < 0)
2073 return err; 2069 return err;
@@ -2083,8 +2079,7 @@ static int snd_pcm_open_file(struct file *file,
2083 substream->pcm_release = pcm_release_private; 2079 substream->pcm_release = pcm_release_private;
2084 } 2080 }
2085 file->private_data = pcm_file; 2081 file->private_data = pcm_file;
2086 if (rpcm_file) 2082
2087 *rpcm_file = pcm_file;
2088 return 0; 2083 return 0;
2089} 2084}
2090 2085
@@ -2113,7 +2108,6 @@ static int snd_pcm_capture_open(struct inode *inode, struct file *file)
2113static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream) 2108static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream)
2114{ 2109{
2115 int err; 2110 int err;
2116 struct snd_pcm_file *pcm_file;
2117 wait_queue_t wait; 2111 wait_queue_t wait;
2118 2112
2119 if (pcm == NULL) { 2113 if (pcm == NULL) {
@@ -2131,7 +2125,7 @@ static int snd_pcm_open(struct file *file, struct snd_pcm *pcm, int stream)
2131 add_wait_queue(&pcm->open_wait, &wait); 2125 add_wait_queue(&pcm->open_wait, &wait);
2132 mutex_lock(&pcm->open_mutex); 2126 mutex_lock(&pcm->open_mutex);
2133 while (1) { 2127 while (1) {
2134 err = snd_pcm_open_file(file, pcm, stream, &pcm_file); 2128 err = snd_pcm_open_file(file, pcm, stream);
2135 if (err >= 0) 2129 if (err >= 0)
2136 break; 2130 break;
2137 if (err == -EAGAIN) { 2131 if (err == -EAGAIN) {
@@ -3156,8 +3150,8 @@ static const struct vm_operations_struct snd_pcm_vm_ops_data_fault = {
3156/* 3150/*
3157 * mmap the DMA buffer on RAM 3151 * mmap the DMA buffer on RAM
3158 */ 3152 */
3159static int snd_pcm_default_mmap(struct snd_pcm_substream *substream, 3153int snd_pcm_lib_default_mmap(struct snd_pcm_substream *substream,
3160 struct vm_area_struct *area) 3154 struct vm_area_struct *area)
3161{ 3155{
3162 area->vm_flags |= VM_RESERVED; 3156 area->vm_flags |= VM_RESERVED;
3163#ifdef ARCH_HAS_DMA_MMAP_COHERENT 3157#ifdef ARCH_HAS_DMA_MMAP_COHERENT
@@ -3177,6 +3171,7 @@ static int snd_pcm_default_mmap(struct snd_pcm_substream *substream,
3177 area->vm_ops = &snd_pcm_vm_ops_data_fault; 3171 area->vm_ops = &snd_pcm_vm_ops_data_fault;
3178 return 0; 3172 return 0;
3179} 3173}
3174EXPORT_SYMBOL_GPL(snd_pcm_lib_default_mmap);
3180 3175
3181/* 3176/*
3182 * mmap the DMA buffer on I/O memory area 3177 * mmap the DMA buffer on I/O memory area
@@ -3242,7 +3237,7 @@ int snd_pcm_mmap_data(struct snd_pcm_substream *substream, struct file *file,
3242 if (substream->ops->mmap) 3237 if (substream->ops->mmap)
3243 err = substream->ops->mmap(substream, area); 3238 err = substream->ops->mmap(substream, area);
3244 else 3239 else
3245 err = snd_pcm_default_mmap(substream, area); 3240 err = snd_pcm_lib_default_mmap(substream, area);
3246 if (!err) 3241 if (!err)
3247 atomic_inc(&substream->mmap_count); 3242 atomic_inc(&substream->mmap_count);
3248 return err; 3243 return err;
diff --git a/sound/core/timer.c b/sound/core/timer.c
index 7c1cbf0a0dc4..67ebf1c21c04 100644
--- a/sound/core/timer.c
+++ b/sound/core/timer.c
@@ -328,6 +328,8 @@ int snd_timer_close(struct snd_timer_instance *timeri)
328 mutex_unlock(&register_mutex); 328 mutex_unlock(&register_mutex);
329 } else { 329 } else {
330 timer = timeri->timer; 330 timer = timeri->timer;
331 if (snd_BUG_ON(!timer))
332 goto out;
331 /* wait, until the active callback is finished */ 333 /* wait, until the active callback is finished */
332 spin_lock_irq(&timer->lock); 334 spin_lock_irq(&timer->lock);
333 while (timeri->flags & SNDRV_TIMER_IFLG_CALLBACK) { 335 while (timeri->flags & SNDRV_TIMER_IFLG_CALLBACK) {
@@ -353,6 +355,7 @@ int snd_timer_close(struct snd_timer_instance *timeri)
353 } 355 }
354 mutex_unlock(&register_mutex); 356 mutex_unlock(&register_mutex);
355 } 357 }
358 out:
356 if (timeri->private_free) 359 if (timeri->private_free)
357 timeri->private_free(timeri); 360 timeri->private_free(timeri);
358 kfree(timeri->owner); 361 kfree(timeri->owner);
@@ -531,6 +534,8 @@ int snd_timer_stop(struct snd_timer_instance *timeri)
531 if (err < 0) 534 if (err < 0)
532 return err; 535 return err;
533 timer = timeri->timer; 536 timer = timeri->timer;
537 if (!timer)
538 return -EINVAL;
534 spin_lock_irqsave(&timer->lock, flags); 539 spin_lock_irqsave(&timer->lock, flags);
535 timeri->cticks = timeri->ticks; 540 timeri->cticks = timeri->ticks;
536 timeri->pticks = 0; 541 timeri->pticks = 0;
diff --git a/sound/drivers/aloop.c b/sound/drivers/aloop.c
index a0da7755fcea..4067f1548949 100644
--- a/sound/drivers/aloop.c
+++ b/sound/drivers/aloop.c
@@ -575,7 +575,8 @@ static void loopback_runtime_free(struct snd_pcm_runtime *runtime)
575static int loopback_hw_params(struct snd_pcm_substream *substream, 575static int loopback_hw_params(struct snd_pcm_substream *substream,
576 struct snd_pcm_hw_params *params) 576 struct snd_pcm_hw_params *params)
577{ 577{
578 return snd_pcm_lib_malloc_pages(substream, params_buffer_bytes(params)); 578 return snd_pcm_lib_alloc_vmalloc_buffer(substream,
579 params_buffer_bytes(params));
579} 580}
580 581
581static int loopback_hw_free(struct snd_pcm_substream *substream) 582static int loopback_hw_free(struct snd_pcm_substream *substream)
@@ -587,7 +588,7 @@ static int loopback_hw_free(struct snd_pcm_substream *substream)
587 mutex_lock(&dpcm->loopback->cable_lock); 588 mutex_lock(&dpcm->loopback->cable_lock);
588 cable->valid &= ~(1 << substream->stream); 589 cable->valid &= ~(1 << substream->stream);
589 mutex_unlock(&dpcm->loopback->cable_lock); 590 mutex_unlock(&dpcm->loopback->cable_lock);
590 return snd_pcm_lib_free_pages(substream); 591 return snd_pcm_lib_free_vmalloc_buffer(substream);
591} 592}
592 593
593static unsigned int get_cable_index(struct snd_pcm_substream *substream) 594static unsigned int get_cable_index(struct snd_pcm_substream *substream)
@@ -740,6 +741,8 @@ static struct snd_pcm_ops loopback_playback_ops = {
740 .prepare = loopback_prepare, 741 .prepare = loopback_prepare,
741 .trigger = loopback_trigger, 742 .trigger = loopback_trigger,
742 .pointer = loopback_pointer, 743 .pointer = loopback_pointer,
744 .page = snd_pcm_lib_get_vmalloc_page,
745 .mmap = snd_pcm_lib_mmap_vmalloc,
743}; 746};
744 747
745static struct snd_pcm_ops loopback_capture_ops = { 748static struct snd_pcm_ops loopback_capture_ops = {
@@ -751,6 +754,8 @@ static struct snd_pcm_ops loopback_capture_ops = {
751 .prepare = loopback_prepare, 754 .prepare = loopback_prepare,
752 .trigger = loopback_trigger, 755 .trigger = loopback_trigger,
753 .pointer = loopback_pointer, 756 .pointer = loopback_pointer,
757 .page = snd_pcm_lib_get_vmalloc_page,
758 .mmap = snd_pcm_lib_mmap_vmalloc,
754}; 759};
755 760
756static int __devinit loopback_pcm_new(struct loopback *loopback, 761static int __devinit loopback_pcm_new(struct loopback *loopback,
@@ -771,10 +776,6 @@ static int __devinit loopback_pcm_new(struct loopback *loopback,
771 strcpy(pcm->name, "Loopback PCM"); 776 strcpy(pcm->name, "Loopback PCM");
772 777
773 loopback->pcm[device] = pcm; 778 loopback->pcm[device] = pcm;
774
775 snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_CONTINUOUS,
776 snd_dma_continuous_data(GFP_KERNEL),
777 0, 2 * 1024 * 1024);
778 return 0; 779 return 0;
779} 780}
780 781
diff --git a/sound/drivers/ml403-ac97cr.c b/sound/drivers/ml403-ac97cr.c
index 5cfcb908c430..2c7a7636f472 100644
--- a/sound/drivers/ml403-ac97cr.c
+++ b/sound/drivers/ml403-ac97cr.c
@@ -1153,7 +1153,7 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
1153 "0x%x done\n", (unsigned int)ml403_ac97cr->port); 1153 "0x%x done\n", (unsigned int)ml403_ac97cr->port);
1154 /* get irq */ 1154 /* get irq */
1155 irq = platform_get_irq(pfdev, 0); 1155 irq = platform_get_irq(pfdev, 0);
1156 if (request_irq(irq, snd_ml403_ac97cr_irq, IRQF_DISABLED, 1156 if (request_irq(irq, snd_ml403_ac97cr_irq, 0,
1157 dev_name(&pfdev->dev), (void *)ml403_ac97cr)) { 1157 dev_name(&pfdev->dev), (void *)ml403_ac97cr)) {
1158 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": " 1158 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": "
1159 "unable to grab IRQ %d\n", 1159 "unable to grab IRQ %d\n",
@@ -1166,7 +1166,7 @@ snd_ml403_ac97cr_create(struct snd_card *card, struct platform_device *pfdev,
1166 "request (playback) irq %d done\n", 1166 "request (playback) irq %d done\n",
1167 ml403_ac97cr->irq); 1167 ml403_ac97cr->irq);
1168 irq = platform_get_irq(pfdev, 1); 1168 irq = platform_get_irq(pfdev, 1);
1169 if (request_irq(irq, snd_ml403_ac97cr_irq, IRQF_DISABLED, 1169 if (request_irq(irq, snd_ml403_ac97cr_irq, 0,
1170 dev_name(&pfdev->dev), (void *)ml403_ac97cr)) { 1170 dev_name(&pfdev->dev), (void *)ml403_ac97cr)) {
1171 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": " 1171 snd_printk(KERN_ERR SND_ML403_AC97CR_DRIVER ": "
1172 "unable to grab IRQ %d\n", 1172 "unable to grab IRQ %d\n",
diff --git a/sound/drivers/mpu401/mpu401.c b/sound/drivers/mpu401/mpu401.c
index 149d05a8202d..1c02852aceea 100644
--- a/sound/drivers/mpu401/mpu401.c
+++ b/sound/drivers/mpu401/mpu401.c
@@ -86,8 +86,7 @@ static int snd_mpu401_create(int dev, struct snd_card **rcard)
86 } 86 }
87 87
88 err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port[dev], 0, 88 err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, port[dev], 0,
89 irq[dev], irq[dev] >= 0 ? IRQF_DISABLED : 0, 89 irq[dev], NULL);
90 NULL);
91 if (err < 0) { 90 if (err < 0) {
92 printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]); 91 printk(KERN_ERR "MPU401 not detected at 0x%lx\n", port[dev]);
93 goto _err; 92 goto _err;
diff --git a/sound/drivers/mpu401/mpu401_uart.c b/sound/drivers/mpu401/mpu401_uart.c
index 2af09996a3d0..e91698a634b2 100644
--- a/sound/drivers/mpu401/mpu401_uart.c
+++ b/sound/drivers/mpu401/mpu401_uart.c
@@ -3,7 +3,7 @@
3 * Routines for control of MPU-401 in UART mode 3 * Routines for control of MPU-401 in UART mode
4 * 4 *
5 * MPU-401 supports UART mode which is not capable generate transmit 5 * MPU-401 supports UART mode which is not capable generate transmit
6 * interrupts thus output is done via polling. Also, if irq < 0, then 6 * interrupts thus output is done via polling. Without interrupt,
7 * input is done also via polling. Do not expect good performance. 7 * input is done also via polling. Do not expect good performance.
8 * 8 *
9 * 9 *
@@ -374,7 +374,7 @@ snd_mpu401_uart_input_trigger(struct snd_rawmidi_substream *substream, int up)
374 /* first time - flush FIFO */ 374 /* first time - flush FIFO */
375 while (max-- > 0) 375 while (max-- > 0)
376 mpu->read(mpu, MPU401D(mpu)); 376 mpu->read(mpu, MPU401D(mpu));
377 if (mpu->irq < 0) 377 if (mpu->info_flags & MPU401_INFO_USE_TIMER)
378 snd_mpu401_uart_add_timer(mpu, 1); 378 snd_mpu401_uart_add_timer(mpu, 1);
379 } 379 }
380 380
@@ -383,7 +383,7 @@ snd_mpu401_uart_input_trigger(struct snd_rawmidi_substream *substream, int up)
383 snd_mpu401_uart_input_read(mpu); 383 snd_mpu401_uart_input_read(mpu);
384 spin_unlock_irqrestore(&mpu->input_lock, flags); 384 spin_unlock_irqrestore(&mpu->input_lock, flags);
385 } else { 385 } else {
386 if (mpu->irq < 0) 386 if (mpu->info_flags & MPU401_INFO_USE_TIMER)
387 snd_mpu401_uart_remove_timer(mpu, 1); 387 snd_mpu401_uart_remove_timer(mpu, 1);
388 clear_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode); 388 clear_bit(MPU401_MODE_BIT_INPUT_TRIGGER, &mpu->mode);
389 } 389 }
@@ -496,7 +496,7 @@ static struct snd_rawmidi_ops snd_mpu401_uart_input =
496static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi) 496static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi)
497{ 497{
498 struct snd_mpu401 *mpu = rmidi->private_data; 498 struct snd_mpu401 *mpu = rmidi->private_data;
499 if (mpu->irq_flags && mpu->irq >= 0) 499 if (mpu->irq >= 0)
500 free_irq(mpu->irq, (void *) mpu); 500 free_irq(mpu->irq, (void *) mpu);
501 release_and_free_resource(mpu->res); 501 release_and_free_resource(mpu->res);
502 kfree(mpu); 502 kfree(mpu);
@@ -509,8 +509,7 @@ static void snd_mpu401_uart_free(struct snd_rawmidi *rmidi)
509 * @hardware: the hardware type, MPU401_HW_XXXX 509 * @hardware: the hardware type, MPU401_HW_XXXX
510 * @port: the base address of MPU401 port 510 * @port: the base address of MPU401 port
511 * @info_flags: bitflags MPU401_INFO_XXX 511 * @info_flags: bitflags MPU401_INFO_XXX
512 * @irq: the irq number, -1 if no interrupt for mpu 512 * @irq: the ISA irq number, -1 if not to be allocated
513 * @irq_flags: the irq request flags (SA_XXX), 0 if irq was already reserved.
514 * @rrawmidi: the pointer to store the new rawmidi instance 513 * @rrawmidi: the pointer to store the new rawmidi instance
515 * 514 *
516 * Creates a new MPU-401 instance. 515 * Creates a new MPU-401 instance.
@@ -525,7 +524,7 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
525 unsigned short hardware, 524 unsigned short hardware,
526 unsigned long port, 525 unsigned long port,
527 unsigned int info_flags, 526 unsigned int info_flags,
528 int irq, int irq_flags, 527 int irq,
529 struct snd_rawmidi ** rrawmidi) 528 struct snd_rawmidi ** rrawmidi)
530{ 529{
531 struct snd_mpu401 *mpu; 530 struct snd_mpu401 *mpu;
@@ -577,8 +576,8 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
577 mpu->cport = port + 2; 576 mpu->cport = port + 2;
578 else 577 else
579 mpu->cport = port + 1; 578 mpu->cport = port + 1;
580 if (irq >= 0 && irq_flags) { 579 if (irq >= 0) {
581 if (request_irq(irq, snd_mpu401_uart_interrupt, irq_flags, 580 if (request_irq(irq, snd_mpu401_uart_interrupt, 0,
582 "MPU401 UART", (void *) mpu)) { 581 "MPU401 UART", (void *) mpu)) {
583 snd_printk(KERN_ERR "mpu401_uart: " 582 snd_printk(KERN_ERR "mpu401_uart: "
584 "unable to grab IRQ %d\n", irq); 583 "unable to grab IRQ %d\n", irq);
@@ -586,9 +585,10 @@ int snd_mpu401_uart_new(struct snd_card *card, int device,
586 return -EBUSY; 585 return -EBUSY;
587 } 586 }
588 } 587 }
588 if (irq < 0 && !(info_flags & MPU401_INFO_IRQ_HOOK))
589 info_flags |= MPU401_INFO_USE_TIMER;
589 mpu->info_flags = info_flags; 590 mpu->info_flags = info_flags;
590 mpu->irq = irq; 591 mpu->irq = irq;
591 mpu->irq_flags = irq_flags;
592 if (card->shortname[0]) 592 if (card->shortname[0])
593 snprintf(rmidi->name, sizeof(rmidi->name), "%s MIDI", 593 snprintf(rmidi->name, sizeof(rmidi->name), "%s MIDI",
594 card->shortname); 594 card->shortname);
diff --git a/sound/drivers/mtpav.c b/sound/drivers/mtpav.c
index 5c426df87678..1eef4ccebe4b 100644
--- a/sound/drivers/mtpav.c
+++ b/sound/drivers/mtpav.c
@@ -589,7 +589,7 @@ static int __devinit snd_mtpav_get_ISA(struct mtpav * mcard)
589 return -EBUSY; 589 return -EBUSY;
590 } 590 }
591 mcard->port = port; 591 mcard->port = port;
592 if (request_irq(irq, snd_mtpav_irqh, IRQF_DISABLED, "MOTU MTPAV", mcard)) { 592 if (request_irq(irq, snd_mtpav_irqh, 0, "MOTU MTPAV", mcard)) {
593 snd_printk(KERN_ERR "MTVAP IRQ %d busy\n", irq); 593 snd_printk(KERN_ERR "MTVAP IRQ %d busy\n", irq);
594 return -EBUSY; 594 return -EBUSY;
595 } 595 }
diff --git a/sound/drivers/serial-u16550.c b/sound/drivers/serial-u16550.c
index a25fb7b1f441..fc1d822802c3 100644
--- a/sound/drivers/serial-u16550.c
+++ b/sound/drivers/serial-u16550.c
@@ -816,7 +816,7 @@ static int __devinit snd_uart16550_create(struct snd_card *card,
816 816
817 if (irq >= 0 && irq != SNDRV_AUTO_IRQ) { 817 if (irq >= 0 && irq != SNDRV_AUTO_IRQ) {
818 if (request_irq(irq, snd_uart16550_interrupt, 818 if (request_irq(irq, snd_uart16550_interrupt,
819 IRQF_DISABLED, "Serial MIDI", uart)) { 819 0, "Serial MIDI", uart)) {
820 snd_printk(KERN_WARNING 820 snd_printk(KERN_WARNING
821 "irq %d busy. Using Polling.\n", irq); 821 "irq %d busy. Using Polling.\n", irq);
822 } else { 822 } else {
diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
index 440030818db7..cd094ecaca3b 100644
--- a/sound/firewire/isight.c
+++ b/sound/firewire/isight.c
@@ -51,7 +51,6 @@ struct isight {
51 struct fw_unit *unit; 51 struct fw_unit *unit;
52 struct fw_device *device; 52 struct fw_device *device;
53 u64 audio_base; 53 u64 audio_base;
54 struct fw_address_handler iris_handler;
55 struct snd_pcm_substream *pcm; 54 struct snd_pcm_substream *pcm;
56 struct mutex mutex; 55 struct mutex mutex;
57 struct iso_packets_buffer buffer; 56 struct iso_packets_buffer buffer;
diff --git a/sound/firewire/speakers.c b/sound/firewire/speakers.c
index 3fc257da180c..cbe6bb9e53b6 100644
--- a/sound/firewire/speakers.c
+++ b/sound/firewire/speakers.c
@@ -778,9 +778,10 @@ static int __devexit fwspk_remove(struct device *dev)
778{ 778{
779 struct fwspk *fwspk = dev_get_drvdata(dev); 779 struct fwspk *fwspk = dev_get_drvdata(dev);
780 780
781 mutex_lock(&fwspk->mutex);
782 amdtp_out_stream_pcm_abort(&fwspk->stream); 781 amdtp_out_stream_pcm_abort(&fwspk->stream);
783 snd_card_disconnect(fwspk->card); 782 snd_card_disconnect(fwspk->card);
783
784 mutex_lock(&fwspk->mutex);
784 fwspk_stop_stream(fwspk); 785 fwspk_stop_stream(fwspk);
785 mutex_unlock(&fwspk->mutex); 786 mutex_unlock(&fwspk->mutex);
786 787
@@ -796,8 +797,8 @@ static void fwspk_bus_reset(struct fw_unit *unit)
796 fcp_bus_reset(fwspk->unit); 797 fcp_bus_reset(fwspk->unit);
797 798
798 if (cmp_connection_update(&fwspk->connection) < 0) { 799 if (cmp_connection_update(&fwspk->connection) < 0) {
799 mutex_lock(&fwspk->mutex);
800 amdtp_out_stream_pcm_abort(&fwspk->stream); 800 amdtp_out_stream_pcm_abort(&fwspk->stream);
801 mutex_lock(&fwspk->mutex);
801 fwspk_stop_stream(fwspk); 802 fwspk_stop_stream(fwspk);
802 mutex_unlock(&fwspk->mutex); 803 mutex_unlock(&fwspk->mutex);
803 return; 804 return;
diff --git a/sound/isa/ad1816a/ad1816a.c b/sound/isa/ad1816a/ad1816a.c
index 3cb75bc97699..a87a2b566e19 100644
--- a/sound/isa/ad1816a/ad1816a.c
+++ b/sound/isa/ad1816a/ad1816a.c
@@ -204,7 +204,7 @@ static int __devinit snd_card_ad1816a_probe(int dev, struct pnp_card_link *pcard
204 204
205 if (mpu_port[dev] > 0) { 205 if (mpu_port[dev] > 0) {
206 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 206 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
207 mpu_port[dev], 0, mpu_irq[dev], IRQF_DISABLED, 207 mpu_port[dev], 0, mpu_irq[dev],
208 NULL) < 0) 208 NULL) < 0)
209 printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]); 209 printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", mpu_port[dev]);
210 } 210 }
diff --git a/sound/isa/ad1816a/ad1816a_lib.c b/sound/isa/ad1816a/ad1816a_lib.c
index 05aef8b97e96..177eed3271bc 100644
--- a/sound/isa/ad1816a/ad1816a_lib.c
+++ b/sound/isa/ad1816a/ad1816a_lib.c
@@ -595,7 +595,7 @@ int __devinit snd_ad1816a_create(struct snd_card *card,
595 snd_ad1816a_free(chip); 595 snd_ad1816a_free(chip);
596 return -EBUSY; 596 return -EBUSY;
597 } 597 }
598 if (request_irq(irq, snd_ad1816a_interrupt, IRQF_DISABLED, "AD1816A", (void *) chip)) { 598 if (request_irq(irq, snd_ad1816a_interrupt, 0, "AD1816A", (void *) chip)) {
599 snd_printk(KERN_ERR "ad1816a: can't grab IRQ %d\n", irq); 599 snd_printk(KERN_ERR "ad1816a: can't grab IRQ %d\n", irq);
600 snd_ad1816a_free(chip); 600 snd_ad1816a_free(chip);
601 return -EBUSY; 601 return -EBUSY;
diff --git a/sound/isa/als100.c b/sound/isa/als100.c
index 20becc89f6f6..706effd6b3cd 100644
--- a/sound/isa/als100.c
+++ b/sound/isa/als100.c
@@ -256,7 +256,6 @@ static int __devinit snd_card_als100_probe(int dev,
256 mpu_type, 256 mpu_type,
257 mpu_port[dev], 0, 257 mpu_port[dev], 0,
258 mpu_irq[dev], 258 mpu_irq[dev],
259 mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0,
260 NULL) < 0) 259 NULL) < 0)
261 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]); 260 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
262 } 261 }
diff --git a/sound/isa/azt2320.c b/sound/isa/azt2320.c
index aac8dc15c2fe..b7bdbf307740 100644
--- a/sound/isa/azt2320.c
+++ b/sound/isa/azt2320.c
@@ -234,8 +234,7 @@ static int __devinit snd_card_azt2320_probe(int dev,
234 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { 234 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
235 if (snd_mpu401_uart_new(card, 0, MPU401_HW_AZT2320, 235 if (snd_mpu401_uart_new(card, 0, MPU401_HW_AZT2320,
236 mpu_port[dev], 0, 236 mpu_port[dev], 0,
237 mpu_irq[dev], IRQF_DISABLED, 237 mpu_irq[dev], NULL) < 0)
238 NULL) < 0)
239 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]); 238 snd_printk(KERN_ERR PFX "no MPU-401 device at 0x%lx\n", mpu_port[dev]);
240 } 239 }
241 240
diff --git a/sound/isa/cmi8330.c b/sound/isa/cmi8330.c
index fe79a169acb5..dca69f80305f 100644
--- a/sound/isa/cmi8330.c
+++ b/sound/isa/cmi8330.c
@@ -597,7 +597,7 @@ static int __devinit snd_cmi8330_probe(struct snd_card *card, int dev)
597 if (mpuport[dev] != SNDRV_AUTO_PORT) { 597 if (mpuport[dev] != SNDRV_AUTO_PORT) {
598 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 598 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
599 mpuport[dev], 0, mpuirq[dev], 599 mpuport[dev], 0, mpuirq[dev],
600 IRQF_DISABLED, NULL) < 0) 600 NULL) < 0)
601 printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n", 601 printk(KERN_ERR PFX "no MPU-401 device at 0x%lx.\n",
602 mpuport[dev]); 602 mpuport[dev]);
603 } 603 }
diff --git a/sound/isa/cs423x/cs4231.c b/sound/isa/cs423x/cs4231.c
index cb9153e75b82..409fa0ad7843 100644
--- a/sound/isa/cs423x/cs4231.c
+++ b/sound/isa/cs423x/cs4231.c
@@ -131,7 +131,6 @@ static int __devinit snd_cs4231_probe(struct device *dev, unsigned int n)
131 mpu_irq[n] = -1; 131 mpu_irq[n] = -1;
132 if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232, 132 if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
133 mpu_port[n], 0, mpu_irq[n], 133 mpu_port[n], 0, mpu_irq[n],
134 mpu_irq[n] >= 0 ? IRQF_DISABLED : 0,
135 NULL) < 0) 134 NULL) < 0)
136 dev_warn(dev, "MPU401 not detected\n"); 135 dev_warn(dev, "MPU401 not detected\n");
137 } 136 }
diff --git a/sound/isa/cs423x/cs4236.c b/sound/isa/cs423x/cs4236.c
index 999dc1e0fdbd..0dbde461e6c1 100644
--- a/sound/isa/cs423x/cs4236.c
+++ b/sound/isa/cs423x/cs4236.c
@@ -449,8 +449,7 @@ static int __devinit snd_cs423x_probe(struct snd_card *card, int dev)
449 mpu_irq[dev] = -1; 449 mpu_irq[dev] = -1;
450 if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232, 450 if (snd_mpu401_uart_new(card, 0, MPU401_HW_CS4232,
451 mpu_port[dev], 0, 451 mpu_port[dev], 0,
452 mpu_irq[dev], 452 mpu_irq[dev], NULL) < 0)
453 mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0, NULL) < 0)
454 printk(KERN_WARNING IDENT ": MPU401 not detected\n"); 453 printk(KERN_WARNING IDENT ": MPU401 not detected\n");
455 } 454 }
456 455
diff --git a/sound/isa/es1688/es1688.c b/sound/isa/es1688/es1688.c
index 0cde8131a575..5493e9e4bcd5 100644
--- a/sound/isa/es1688/es1688.c
+++ b/sound/isa/es1688/es1688.c
@@ -174,7 +174,7 @@ static int __devinit snd_es1688_probe(struct snd_card *card, unsigned int n)
174 chip->mpu_port > 0) { 174 chip->mpu_port > 0) {
175 error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, 175 error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
176 chip->mpu_port, 0, 176 chip->mpu_port, 0,
177 mpu_irq[n], IRQF_DISABLED, NULL); 177 mpu_irq[n], NULL);
178 if (error < 0) 178 if (error < 0)
179 return error; 179 return error;
180 } 180 }
diff --git a/sound/isa/es1688/es1688_lib.c b/sound/isa/es1688/es1688_lib.c
index 07676200496a..d3eab6fb0866 100644
--- a/sound/isa/es1688/es1688_lib.c
+++ b/sound/isa/es1688/es1688_lib.c
@@ -661,7 +661,7 @@ int snd_es1688_create(struct snd_card *card,
661 snd_printk(KERN_ERR "es1688: can't grab port 0x%lx\n", port + 4); 661 snd_printk(KERN_ERR "es1688: can't grab port 0x%lx\n", port + 4);
662 return -EBUSY; 662 return -EBUSY;
663 } 663 }
664 if (request_irq(irq, snd_es1688_interrupt, IRQF_DISABLED, "ES1688", (void *) chip)) { 664 if (request_irq(irq, snd_es1688_interrupt, 0, "ES1688", (void *) chip)) {
665 snd_printk(KERN_ERR "es1688: can't grab IRQ %d\n", irq); 665 snd_printk(KERN_ERR "es1688: can't grab IRQ %d\n", irq);
666 return -EBUSY; 666 return -EBUSY;
667 } 667 }
diff --git a/sound/isa/es18xx.c b/sound/isa/es18xx.c
index fb4d6b34bbca..bf6ad0bf51c6 100644
--- a/sound/isa/es18xx.c
+++ b/sound/isa/es18xx.c
@@ -1805,7 +1805,7 @@ static int __devinit snd_es18xx_new_device(struct snd_card *card,
1805 return -EBUSY; 1805 return -EBUSY;
1806 } 1806 }
1807 1807
1808 if (request_irq(irq, snd_es18xx_interrupt, IRQF_DISABLED, "ES18xx", 1808 if (request_irq(irq, snd_es18xx_interrupt, 0, "ES18xx",
1809 (void *) card)) { 1809 (void *) card)) {
1810 snd_es18xx_free(card); 1810 snd_es18xx_free(card);
1811 snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq); 1811 snd_printk(KERN_ERR PFX "unable to grap IRQ %d\n", irq);
@@ -2160,8 +2160,8 @@ static int __devinit snd_audiodrive_probe(struct snd_card *card, int dev)
2160 2160
2161 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) { 2161 if (mpu_port[dev] > 0 && mpu_port[dev] != SNDRV_AUTO_PORT) {
2162 err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX, 2162 err = snd_mpu401_uart_new(card, 0, MPU401_HW_ES18XX,
2163 mpu_port[dev], 0, 2163 mpu_port[dev], MPU401_INFO_IRQ_HOOK,
2164 irq[dev], 0, &chip->rmidi); 2164 -1, &chip->rmidi);
2165 if (err < 0) 2165 if (err < 0)
2166 return err; 2166 return err;
2167 } 2167 }
diff --git a/sound/isa/galaxy/galaxy.c b/sound/isa/galaxy/galaxy.c
index ee54df082b9c..e51d3244742a 100644
--- a/sound/isa/galaxy/galaxy.c
+++ b/sound/isa/galaxy/galaxy.c
@@ -585,8 +585,7 @@ static int __devinit snd_galaxy_probe(struct device *dev, unsigned int n)
585 585
586 if (mpu_port[n] >= 0) { 586 if (mpu_port[n] >= 0) {
587 err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 587 err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
588 mpu_port[n], 0, mpu_irq[n], 588 mpu_port[n], 0, mpu_irq[n], NULL);
589 IRQF_DISABLED, NULL);
590 if (err < 0) 589 if (err < 0)
591 goto error; 590 goto error;
592 } 591 }
diff --git a/sound/isa/gus/gus_main.c b/sound/isa/gus/gus_main.c
index 12eb98f2f931..3167e5ac3699 100644
--- a/sound/isa/gus/gus_main.c
+++ b/sound/isa/gus/gus_main.c
@@ -180,7 +180,7 @@ int snd_gus_create(struct snd_card *card,
180 snd_gus_free(gus); 180 snd_gus_free(gus);
181 return -EBUSY; 181 return -EBUSY;
182 } 182 }
183 if (irq >= 0 && request_irq(irq, snd_gus_interrupt, IRQF_DISABLED, "GUS GF1", (void *) gus)) { 183 if (irq >= 0 && request_irq(irq, snd_gus_interrupt, 0, "GUS GF1", (void *) gus)) {
184 snd_printk(KERN_ERR "gus: can't grab irq %d\n", irq); 184 snd_printk(KERN_ERR "gus: can't grab irq %d\n", irq);
185 snd_gus_free(gus); 185 snd_gus_free(gus);
186 return -EBUSY; 186 return -EBUSY;
diff --git a/sound/isa/gus/gusextreme.c b/sound/isa/gus/gusextreme.c
index 008e8e5bfa37..c4733c08b60b 100644
--- a/sound/isa/gus/gusextreme.c
+++ b/sound/isa/gus/gusextreme.c
@@ -317,8 +317,7 @@ static int __devinit snd_gusextreme_probe(struct device *dev, unsigned int n)
317 317
318 if (es1688->mpu_port >= 0x300) { 318 if (es1688->mpu_port >= 0x300) {
319 error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688, 319 error = snd_mpu401_uart_new(card, 0, MPU401_HW_ES1688,
320 es1688->mpu_port, 0, 320 es1688->mpu_port, 0, mpu_irq[n], NULL);
321 mpu_irq[n], IRQF_DISABLED, NULL);
322 if (error < 0) 321 if (error < 0)
323 goto out; 322 goto out;
324 } 323 }
diff --git a/sound/isa/gus/gusmax.c b/sound/isa/gus/gusmax.c
index 3e4a58b72913..c43faa057ff6 100644
--- a/sound/isa/gus/gusmax.c
+++ b/sound/isa/gus/gusmax.c
@@ -291,7 +291,7 @@ static int __devinit snd_gusmax_probe(struct device *pdev, unsigned int dev)
291 goto _err; 291 goto _err;
292 } 292 }
293 293
294 if (request_irq(xirq, snd_gusmax_interrupt, IRQF_DISABLED, "GUS MAX", (void *)maxcard)) { 294 if (request_irq(xirq, snd_gusmax_interrupt, 0, "GUS MAX", (void *)maxcard)) {
295 snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq); 295 snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq);
296 err = -EBUSY; 296 err = -EBUSY;
297 goto _err; 297 goto _err;
diff --git a/sound/isa/gus/interwave.c b/sound/isa/gus/interwave.c
index c7b80e4730fc..5f869a32b48c 100644
--- a/sound/isa/gus/interwave.c
+++ b/sound/isa/gus/interwave.c
@@ -684,7 +684,7 @@ static int __devinit snd_interwave_probe(struct snd_card *card, int dev)
684 if ((err = snd_gus_initialize(gus)) < 0) 684 if ((err = snd_gus_initialize(gus)) < 0)
685 return err; 685 return err;
686 686
687 if (request_irq(xirq, snd_interwave_interrupt, IRQF_DISABLED, 687 if (request_irq(xirq, snd_interwave_interrupt, 0,
688 "InterWave", iwcard)) { 688 "InterWave", iwcard)) {
689 snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq); 689 snd_printk(KERN_ERR PFX "unable to grab IRQ %d\n", xirq);
690 return -EBUSY; 690 return -EBUSY;
diff --git a/sound/isa/msnd/msnd_pinnacle.c b/sound/isa/msnd/msnd_pinnacle.c
index 91d6023a63e5..0961e2cf20ca 100644
--- a/sound/isa/msnd/msnd_pinnacle.c
+++ b/sound/isa/msnd/msnd_pinnacle.c
@@ -600,7 +600,7 @@ static int __devinit snd_msnd_attach(struct snd_card *card)
600 mpu_io[0], 600 mpu_io[0],
601 MPU401_MODE_INPUT | 601 MPU401_MODE_INPUT |
602 MPU401_MODE_OUTPUT, 602 MPU401_MODE_OUTPUT,
603 mpu_irq[0], IRQF_DISABLED, 603 mpu_irq[0],
604 &chip->rmidi); 604 &chip->rmidi);
605 if (err < 0) { 605 if (err < 0) {
606 printk(KERN_ERR LOGNAME 606 printk(KERN_ERR LOGNAME
diff --git a/sound/isa/opl3sa2.c b/sound/isa/opl3sa2.c
index 9b915e27b5bd..bbafb0b543ea 100644
--- a/sound/isa/opl3sa2.c
+++ b/sound/isa/opl3sa2.c
@@ -667,7 +667,7 @@ static int __devinit snd_opl3sa2_probe(struct snd_card *card, int dev)
667 err = snd_opl3sa2_detect(card); 667 err = snd_opl3sa2_detect(card);
668 if (err < 0) 668 if (err < 0)
669 return err; 669 return err;
670 err = request_irq(xirq, snd_opl3sa2_interrupt, IRQF_DISABLED, 670 err = request_irq(xirq, snd_opl3sa2_interrupt, 0,
671 "OPL3-SA2", card); 671 "OPL3-SA2", card);
672 if (err) { 672 if (err) {
673 snd_printk(KERN_ERR PFX "can't grab IRQ %d\n", xirq); 673 snd_printk(KERN_ERR PFX "can't grab IRQ %d\n", xirq);
@@ -707,8 +707,9 @@ static int __devinit snd_opl3sa2_probe(struct snd_card *card, int dev)
707 } 707 }
708 if (midi_port[dev] >= 0x300 && midi_port[dev] < 0x340) { 708 if (midi_port[dev] >= 0x300 && midi_port[dev] < 0x340) {
709 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_OPL3SA2, 709 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_OPL3SA2,
710 midi_port[dev], 0, 710 midi_port[dev],
711 xirq, 0, &chip->rmidi)) < 0) 711 MPU401_INFO_IRQ_HOOK, -1,
712 &chip->rmidi)) < 0)
712 return err; 713 return err;
713 } 714 }
714 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d", 715 sprintf(card->longname, "%s at 0x%lx, irq %d, dma %d",
diff --git a/sound/isa/opti9xx/miro.c b/sound/isa/opti9xx/miro.c
index 8c24102d0d93..d94d0f35cb76 100644
--- a/sound/isa/opti9xx/miro.c
+++ b/sound/isa/opti9xx/miro.c
@@ -1377,8 +1377,7 @@ static int __devinit snd_miro_probe(struct snd_card *card)
1377 rmidi = NULL; 1377 rmidi = NULL;
1378 else { 1378 else {
1379 error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 1379 error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
1380 mpu_port, 0, miro->mpu_irq, IRQF_DISABLED, 1380 mpu_port, 0, miro->mpu_irq, &rmidi);
1381 &rmidi);
1382 if (error < 0) 1381 if (error < 0)
1383 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", 1382 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
1384 mpu_port); 1383 mpu_port);
diff --git a/sound/isa/opti9xx/opti92x-ad1848.c b/sound/isa/opti9xx/opti92x-ad1848.c
index c35dc68930dc..6dbbfa76b440 100644
--- a/sound/isa/opti9xx/opti92x-ad1848.c
+++ b/sound/isa/opti9xx/opti92x-ad1848.c
@@ -892,7 +892,7 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
892#endif 892#endif
893#ifdef OPTi93X 893#ifdef OPTi93X
894 error = request_irq(irq, snd_opti93x_interrupt, 894 error = request_irq(irq, snd_opti93x_interrupt,
895 IRQF_DISABLED, DEV_NAME" - WSS", chip); 895 0, DEV_NAME" - WSS", chip);
896 if (error < 0) { 896 if (error < 0) {
897 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq); 897 snd_printk(KERN_ERR "opti9xx: can't grab IRQ %d\n", irq);
898 return error; 898 return error;
@@ -914,7 +914,7 @@ static int __devinit snd_opti9xx_probe(struct snd_card *card)
914 rmidi = NULL; 914 rmidi = NULL;
915 else { 915 else {
916 error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 916 error = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
917 mpu_port, 0, mpu_irq, IRQF_DISABLED, &rmidi); 917 mpu_port, 0, mpu_irq, &rmidi);
918 if (error) 918 if (error)
919 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n", 919 snd_printk(KERN_WARNING "no MPU-401 device at 0x%lx?\n",
920 mpu_port); 920 mpu_port);
diff --git a/sound/isa/sb/jazz16.c b/sound/isa/sb/jazz16.c
index 8ccbcddf08e1..54e3c2c18060 100644
--- a/sound/isa/sb/jazz16.c
+++ b/sound/isa/sb/jazz16.c
@@ -322,7 +322,6 @@ static int __devinit snd_jazz16_probe(struct device *devptr, unsigned int dev)
322 MPU401_HW_MPU401, 322 MPU401_HW_MPU401,
323 mpu_port[dev], 0, 323 mpu_port[dev], 0,
324 mpu_irq[dev], 324 mpu_irq[dev],
325 mpu_irq[dev] >= 0 ? IRQF_DISABLED : 0,
326 NULL) < 0) 325 NULL) < 0)
327 snd_printk(KERN_ERR "no MPU-401 device at 0x%lx\n", 326 snd_printk(KERN_ERR "no MPU-401 device at 0x%lx\n",
328 mpu_port[dev]); 327 mpu_port[dev]);
diff --git a/sound/isa/sb/sb16.c b/sound/isa/sb/sb16.c
index 4d1c5a300ff8..237f8bd7fbe4 100644
--- a/sound/isa/sb/sb16.c
+++ b/sound/isa/sb/sb16.c
@@ -394,8 +394,9 @@ static int __devinit snd_sb16_probe(struct snd_card *card, int dev)
394 394
395 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) { 395 if (chip->mpu_port > 0 && chip->mpu_port != SNDRV_AUTO_PORT) {
396 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SB, 396 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SB,
397 chip->mpu_port, 0, 397 chip->mpu_port,
398 xirq, 0, &chip->rmidi)) < 0) 398 MPU401_INFO_IRQ_HOOK, -1,
399 &chip->rmidi)) < 0)
399 return err; 400 return err;
400 chip->rmidi_callback = snd_mpu401_uart_interrupt; 401 chip->rmidi_callback = snd_mpu401_uart_interrupt;
401 } 402 }
diff --git a/sound/isa/sb/sb_common.c b/sound/isa/sb/sb_common.c
index eae6c1c0eff9..d2e19215813e 100644
--- a/sound/isa/sb/sb_common.c
+++ b/sound/isa/sb/sb_common.c
@@ -240,7 +240,7 @@ int snd_sbdsp_create(struct snd_card *card,
240 if (request_irq(irq, irq_handler, 240 if (request_irq(irq, irq_handler,
241 (hardware == SB_HW_ALS4000 || 241 (hardware == SB_HW_ALS4000 ||
242 hardware == SB_HW_CS5530) ? 242 hardware == SB_HW_CS5530) ?
243 IRQF_SHARED : IRQF_DISABLED, 243 IRQF_SHARED : 0,
244 "SoundBlaster", (void *) chip)) { 244 "SoundBlaster", (void *) chip)) {
245 snd_printk(KERN_ERR "sb: can't grab irq %d\n", irq); 245 snd_printk(KERN_ERR "sb: can't grab irq %d\n", irq);
246 snd_sbdsp_free(chip); 246 snd_sbdsp_free(chip);
diff --git a/sound/isa/sc6000.c b/sound/isa/sc6000.c
index 9a8bbf6dd62a..207c161f100c 100644
--- a/sound/isa/sc6000.c
+++ b/sound/isa/sc6000.c
@@ -658,8 +658,7 @@ static int __devinit snd_sc6000_probe(struct device *devptr, unsigned int dev)
658 if (snd_mpu401_uart_new(card, 0, 658 if (snd_mpu401_uart_new(card, 0,
659 MPU401_HW_MPU401, 659 MPU401_HW_MPU401,
660 mpu_port[dev], 0, 660 mpu_port[dev], 0,
661 mpu_irq[dev], IRQF_DISABLED, 661 mpu_irq[dev], NULL) < 0)
662 NULL) < 0)
663 snd_printk(KERN_ERR "no MPU-401 device at 0x%lx ?\n", 662 snd_printk(KERN_ERR "no MPU-401 device at 0x%lx ?\n",
664 mpu_port[dev]); 663 mpu_port[dev]);
665 } 664 }
diff --git a/sound/isa/sscape.c b/sound/isa/sscape.c
index e2d5d2d3ed96..f2379e102b63 100644
--- a/sound/isa/sscape.c
+++ b/sound/isa/sscape.c
@@ -825,8 +825,7 @@ static int __devinit create_mpu401(struct snd_card *card, int devnum,
825 int err; 825 int err;
826 826
827 err = snd_mpu401_uart_new(card, devnum, MPU401_HW_MPU401, port, 827 err = snd_mpu401_uart_new(card, devnum, MPU401_HW_MPU401, port,
828 MPU401_INFO_INTEGRATED, irq, IRQF_DISABLED, 828 MPU401_INFO_INTEGRATED, irq, &rawmidi);
829 &rawmidi);
830 if (err == 0) { 829 if (err == 0) {
831 struct snd_mpu401 *mpu = rawmidi->private_data; 830 struct snd_mpu401 *mpu = rawmidi->private_data;
832 mpu->open_input = mpu401_open; 831 mpu->open_input = mpu401_open;
diff --git a/sound/isa/wavefront/wavefront.c b/sound/isa/wavefront/wavefront.c
index 711670e4a425..87142977335a 100644
--- a/sound/isa/wavefront/wavefront.c
+++ b/sound/isa/wavefront/wavefront.c
@@ -418,7 +418,7 @@ snd_wavefront_probe (struct snd_card *card, int dev)
418 return -EBUSY; 418 return -EBUSY;
419 } 419 }
420 if (request_irq(ics2115_irq[dev], snd_wavefront_ics2115_interrupt, 420 if (request_irq(ics2115_irq[dev], snd_wavefront_ics2115_interrupt,
421 IRQF_DISABLED, "ICS2115", acard)) { 421 0, "ICS2115", acard)) {
422 snd_printk(KERN_ERR "unable to use ICS2115 IRQ %d\n", ics2115_irq[dev]); 422 snd_printk(KERN_ERR "unable to use ICS2115 IRQ %d\n", ics2115_irq[dev]);
423 return -EBUSY; 423 return -EBUSY;
424 } 424 }
@@ -449,8 +449,7 @@ snd_wavefront_probe (struct snd_card *card, int dev)
449 if (cs4232_mpu_port[dev] > 0 && cs4232_mpu_port[dev] != SNDRV_AUTO_PORT) { 449 if (cs4232_mpu_port[dev] > 0 && cs4232_mpu_port[dev] != SNDRV_AUTO_PORT) {
450 err = snd_mpu401_uart_new(card, midi_dev, MPU401_HW_CS4232, 450 err = snd_mpu401_uart_new(card, midi_dev, MPU401_HW_CS4232,
451 cs4232_mpu_port[dev], 0, 451 cs4232_mpu_port[dev], 0,
452 cs4232_mpu_irq[dev], IRQF_DISABLED, 452 cs4232_mpu_irq[dev], NULL);
453 NULL);
454 if (err < 0) { 453 if (err < 0) {
455 snd_printk (KERN_ERR "can't allocate CS4232 MPU-401 device\n"); 454 snd_printk (KERN_ERR "can't allocate CS4232 MPU-401 device\n");
456 return err; 455 return err;
diff --git a/sound/isa/wss/wss_lib.c b/sound/isa/wss/wss_lib.c
index 2a42cc377957..7277c5b7df6c 100644
--- a/sound/isa/wss/wss_lib.c
+++ b/sound/isa/wss/wss_lib.c
@@ -1833,7 +1833,7 @@ int snd_wss_create(struct snd_card *card,
1833 } 1833 }
1834 chip->cport = cport; 1834 chip->cport = cport;
1835 if (!(hwshare & WSS_HWSHARE_IRQ)) 1835 if (!(hwshare & WSS_HWSHARE_IRQ))
1836 if (request_irq(irq, snd_wss_interrupt, IRQF_DISABLED, 1836 if (request_irq(irq, snd_wss_interrupt, 0,
1837 "WSS", (void *) chip)) { 1837 "WSS", (void *) chip)) {
1838 snd_printk(KERN_ERR "wss: can't grab IRQ %d\n", irq); 1838 snd_printk(KERN_ERR "wss: can't grab IRQ %d\n", irq);
1839 snd_wss_free(chip); 1839 snd_wss_free(chip);
diff --git a/sound/mips/au1x00.c b/sound/mips/au1x00.c
index 446cf9748664..7567ebd71913 100644
--- a/sound/mips/au1x00.c
+++ b/sound/mips/au1x00.c
@@ -465,13 +465,13 @@ snd_au1000_pcm_new(struct snd_au1000 *au1000)
465 465
466 flags = claim_dma_lock(); 466 flags = claim_dma_lock();
467 if ((au1000->stream[PLAYBACK]->dma = request_au1000_dma(DMA_ID_AC97C_TX, 467 if ((au1000->stream[PLAYBACK]->dma = request_au1000_dma(DMA_ID_AC97C_TX,
468 "AC97 TX", au1000_dma_interrupt, IRQF_DISABLED, 468 "AC97 TX", au1000_dma_interrupt, 0,
469 au1000->stream[PLAYBACK])) < 0) { 469 au1000->stream[PLAYBACK])) < 0) {
470 release_dma_lock(flags); 470 release_dma_lock(flags);
471 return -EBUSY; 471 return -EBUSY;
472 } 472 }
473 if ((au1000->stream[CAPTURE]->dma = request_au1000_dma(DMA_ID_AC97C_RX, 473 if ((au1000->stream[CAPTURE]->dma = request_au1000_dma(DMA_ID_AC97C_RX,
474 "AC97 RX", au1000_dma_interrupt, IRQF_DISABLED, 474 "AC97 RX", au1000_dma_interrupt, 0,
475 au1000->stream[CAPTURE])) < 0){ 475 au1000->stream[CAPTURE])) < 0){
476 release_dma_lock(flags); 476 release_dma_lock(flags);
477 return -EBUSY; 477 return -EBUSY;
diff --git a/sound/oss/pas2_pcm.c b/sound/oss/pas2_pcm.c
index 8f7d175767a2..6f13ab4afc6b 100644
--- a/sound/oss/pas2_pcm.c
+++ b/sound/oss/pas2_pcm.c
@@ -63,13 +63,13 @@ static int pcm_set_speed(int arg)
63 63
64 if (pcm_channels & 2) 64 if (pcm_channels & 2)
65 { 65 {
66 foo = ((CLOCK_TICK_RATE / 2) + (arg / 2)) / arg; 66 foo = ((PIT_TICK_RATE / 2) + (arg / 2)) / arg;
67 arg = ((CLOCK_TICK_RATE / 2) + (foo / 2)) / foo; 67 arg = ((PIT_TICK_RATE / 2) + (foo / 2)) / foo;
68 } 68 }
69 else 69 else
70 { 70 {
71 foo = (CLOCK_TICK_RATE + (arg / 2)) / arg; 71 foo = (PIT_TICK_RATE + (arg / 2)) / arg;
72 arg = (CLOCK_TICK_RATE + (foo / 2)) / foo; 72 arg = (PIT_TICK_RATE + (foo / 2)) / foo;
73 } 73 }
74 74
75 pcm_speed = arg; 75 pcm_speed = arg;
diff --git a/sound/oss/pss.c b/sound/oss/pss.c
index 9b800ce5100e..2fc0624024b5 100644
--- a/sound/oss/pss.c
+++ b/sound/oss/pss.c
@@ -673,7 +673,8 @@ static void configure_nonsound_components(void)
673 673
674 if (pss_cdrom_port == -1) { /* If cdrom port enablation wasn't requested */ 674 if (pss_cdrom_port == -1) { /* If cdrom port enablation wasn't requested */
675 printk(KERN_INFO "PSS: CDROM port not enabled.\n"); 675 printk(KERN_INFO "PSS: CDROM port not enabled.\n");
676 } else if (check_region(pss_cdrom_port, 2)) { 676 } else if (!request_region(pss_cdrom_port, 2, "PSS CDROM")) {
677 pss_cdrom_port = -1;
677 printk(KERN_ERR "PSS: CDROM I/O port conflict.\n"); 678 printk(KERN_ERR "PSS: CDROM I/O port conflict.\n");
678 } else { 679 } else {
679 set_io_base(devc, CONF_CDROM, pss_cdrom_port); 680 set_io_base(devc, CONF_CDROM, pss_cdrom_port);
@@ -1232,7 +1233,8 @@ static void __exit cleanup_pss(void)
1232 if(pssmpu) 1233 if(pssmpu)
1233 unload_pss_mpu(&cfg_mpu); 1234 unload_pss_mpu(&cfg_mpu);
1234 unload_pss(&cfg); 1235 unload_pss(&cfg);
1235 } 1236 } else if (pss_cdrom_port != -1)
1237 release_region(pss_cdrom_port, 2);
1236 1238
1237 if(!pss_keep_settings) /* Keep hardware settings if asked */ 1239 if(!pss_keep_settings) /* Keep hardware settings if asked */
1238 { 1240 {
diff --git a/sound/oss/sound_timer.c b/sound/oss/sound_timer.c
index 48cda6c4c257..8021c85f076d 100644
--- a/sound/oss/sound_timer.c
+++ b/sound/oss/sound_timer.c
@@ -320,7 +320,7 @@ void sound_timer_init(struct sound_lowlev_timer *t, char *name)
320 n = sound_alloc_timerdev(); 320 n = sound_alloc_timerdev();
321 if (n == -1) 321 if (n == -1)
322 n = 0; /* Overwrite the system timer */ 322 n = 0; /* Overwrite the system timer */
323 strcpy(sound_timer.info.name, name); 323 strlcpy(sound_timer.info.name, name, sizeof(sound_timer.info.name));
324 sound_timer_devs[n] = &sound_timer; 324 sound_timer_devs[n] = &sound_timer;
325} 325}
326EXPORT_SYMBOL(sound_timer_init); 326EXPORT_SYMBOL(sound_timer_init);
diff --git a/sound/pci/Kconfig b/sound/pci/Kconfig
index 50abf5bf8e09..88168044375f 100644
--- a/sound/pci/Kconfig
+++ b/sound/pci/Kconfig
@@ -1,5 +1,10 @@
1# ALSA PCI drivers 1# ALSA PCI drivers
2 2
3config SND_TEA575X
4 tristate
5 depends on SND_FM801_TEA575X_BOOL || SND_ES1968_RADIO || RADIO_SF16FMR2
6 default SND_FM801 || SND_ES1968 || RADIO_SF16FMR2
7
3menuconfig SND_PCI 8menuconfig SND_PCI
4 bool "PCI sound devices" 9 bool "PCI sound devices"
5 depends on PCI 10 depends on PCI
@@ -563,11 +568,6 @@ config SND_FM801_TEA575X_BOOL
563 FM801 chip with a TEA5757 tuner (MediaForte SF256-PCS, SF256-PCP and 568 FM801 chip with a TEA5757 tuner (MediaForte SF256-PCS, SF256-PCP and
564 SF64-PCR) into the snd-fm801 driver. 569 SF64-PCR) into the snd-fm801 driver.
565 570
566config SND_TEA575X
567 tristate
568 depends on SND_FM801_TEA575X_BOOL || SND_ES1968_RADIO || RADIO_SF16FMR2
569 default SND_FM801 || SND_ES1968 || RADIO_SF16FMR2
570
571source "sound/pci/hda/Kconfig" 571source "sound/pci/hda/Kconfig"
572 572
573config SND_HDSP 573config SND_HDSP
diff --git a/sound/pci/ac97/ac97_patch.c b/sound/pci/ac97/ac97_patch.c
index 200c9a1d48b7..a872d0a82976 100644
--- a/sound/pci/ac97/ac97_patch.c
+++ b/sound/pci/ac97/ac97_patch.c
@@ -1909,6 +1909,7 @@ static unsigned int ad1981_jacks_whitelist[] = {
1909 0x103c0944, /* HP nc6220 */ 1909 0x103c0944, /* HP nc6220 */
1910 0x103c0934, /* HP nc8220 */ 1910 0x103c0934, /* HP nc8220 */
1911 0x103c006d, /* HP nx9105 */ 1911 0x103c006d, /* HP nx9105 */
1912 0x103c300d, /* HP Compaq dc5100 SFF(PT003AW) */
1912 0x17340088, /* FSC Scenic-W */ 1913 0x17340088, /* FSC Scenic-W */
1913 0 /* end */ 1914 0 /* end */
1914}; 1915};
diff --git a/sound/pci/als4000.c b/sound/pci/als4000.c
index a9c1af33f276..04628696eb08 100644
--- a/sound/pci/als4000.c
+++ b/sound/pci/als4000.c
@@ -931,8 +931,9 @@ static int __devinit snd_card_als4000_probe(struct pci_dev *pci,
931 931
932 if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000, 932 if ((err = snd_mpu401_uart_new( card, 0, MPU401_HW_ALS4000,
933 iobase + ALS4K_IOB_30_MIDI_DATA, 933 iobase + ALS4K_IOB_30_MIDI_DATA,
934 MPU401_INFO_INTEGRATED, 934 MPU401_INFO_INTEGRATED |
935 pci->irq, 0, &chip->rmidi)) < 0) { 935 MPU401_INFO_IRQ_HOOK,
936 -1, &chip->rmidi)) < 0) {
936 printk(KERN_ERR "als4000: no MPU-401 device at 0x%lx?\n", 937 printk(KERN_ERR "als4000: no MPU-401 device at 0x%lx?\n",
937 iobase + ALS4K_IOB_30_MIDI_DATA); 938 iobase + ALS4K_IOB_30_MIDI_DATA);
938 goto out_err; 939 goto out_err;
diff --git a/sound/pci/asihpi/hpicmn.c b/sound/pci/asihpi/hpicmn.c
index 65b7ca13115b..bd47521b24ec 100644
--- a/sound/pci/asihpi/hpicmn.c
+++ b/sound/pci/asihpi/hpicmn.c
@@ -631,13 +631,12 @@ struct hpi_control_cache *hpi_alloc_control_cache(const u32 control_count,
631 if (!p_cache) 631 if (!p_cache)
632 return NULL; 632 return NULL;
633 633
634 p_cache->p_info = 634 p_cache->p_info = kzalloc(sizeof(*p_cache->p_info) * control_count,
635 kmalloc(sizeof(*p_cache->p_info) * control_count, GFP_KERNEL); 635 GFP_KERNEL);
636 if (!p_cache->p_info) { 636 if (!p_cache->p_info) {
637 kfree(p_cache); 637 kfree(p_cache);
638 return NULL; 638 return NULL;
639 } 639 }
640 memset(p_cache->p_info, 0, sizeof(*p_cache->p_info) * control_count);
641 p_cache->cache_size_in_bytes = size_in_bytes; 640 p_cache->cache_size_in_bytes = size_in_bytes;
642 p_cache->control_count = control_count; 641 p_cache->control_count = control_count;
643 p_cache->p_cache = p_dsp_control_buffer; 642 p_cache->p_cache = p_dsp_control_buffer;
diff --git a/sound/pci/au88x0/au88x0_mpu401.c b/sound/pci/au88x0/au88x0_mpu401.c
index 0dc8d259d1ed..e6c6a0febb75 100644
--- a/sound/pci/au88x0/au88x0_mpu401.c
+++ b/sound/pci/au88x0/au88x0_mpu401.c
@@ -84,7 +84,7 @@ static int __devinit snd_vortex_midi(vortex_t * vortex)
84#ifdef VORTEX_MPU401_LEGACY 84#ifdef VORTEX_MPU401_LEGACY
85 if ((temp = 85 if ((temp =
86 snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_MPU401, 0x330, 86 snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_MPU401, 0x330,
87 0, 0, 0, &rmidi)) != 0) { 87 MPU401_INFO_IRQ_HOOK, -1, &rmidi)) != 0) {
88 hwwrite(vortex->mmio, VORTEX_CTRL, 88 hwwrite(vortex->mmio, VORTEX_CTRL,
89 (hwread(vortex->mmio, VORTEX_CTRL) & 89 (hwread(vortex->mmio, VORTEX_CTRL) &
90 ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN); 90 ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN);
@@ -94,8 +94,8 @@ static int __devinit snd_vortex_midi(vortex_t * vortex)
94 port = (unsigned long)(vortex->mmio + VORTEX_MIDI_DATA); 94 port = (unsigned long)(vortex->mmio + VORTEX_MIDI_DATA);
95 if ((temp = 95 if ((temp =
96 snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_AUREAL, port, 96 snd_mpu401_uart_new(vortex->card, 0, MPU401_HW_AUREAL, port,
97 MPU401_INFO_INTEGRATED | MPU401_INFO_MMIO, 97 MPU401_INFO_INTEGRATED | MPU401_INFO_MMIO |
98 0, 0, &rmidi)) != 0) { 98 MPU401_INFO_IRQ_HOOK, -1, &rmidi)) != 0) {
99 hwwrite(vortex->mmio, VORTEX_CTRL, 99 hwwrite(vortex->mmio, VORTEX_CTRL,
100 (hwread(vortex->mmio, VORTEX_CTRL) & 100 (hwread(vortex->mmio, VORTEX_CTRL) &
101 ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN); 101 ~CTRL_MIDI_PORT) & ~CTRL_MIDI_EN);
diff --git a/sound/pci/azt3328.c b/sound/pci/azt3328.c
index e4d76a270c9f..d24fe425e87f 100644
--- a/sound/pci/azt3328.c
+++ b/sound/pci/azt3328.c
@@ -2625,16 +2625,19 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2625 int err; 2625 int err;
2626 2626
2627 snd_azf3328_dbgcallenter(); 2627 snd_azf3328_dbgcallenter();
2628 if (dev >= SNDRV_CARDS) 2628 if (dev >= SNDRV_CARDS) {
2629 return -ENODEV; 2629 err = -ENODEV;
2630 goto out;
2631 }
2630 if (!enable[dev]) { 2632 if (!enable[dev]) {
2631 dev++; 2633 dev++;
2632 return -ENOENT; 2634 err = -ENOENT;
2635 goto out;
2633 } 2636 }
2634 2637
2635 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card); 2638 err = snd_card_create(index[dev], id[dev], THIS_MODULE, 0, &card);
2636 if (err < 0) 2639 if (err < 0)
2637 return err; 2640 goto out;
2638 2641
2639 strcpy(card->driver, "AZF3328"); 2642 strcpy(card->driver, "AZF3328");
2640 strcpy(card->shortname, "Aztech AZF3328 (PCI168)"); 2643 strcpy(card->shortname, "Aztech AZF3328 (PCI168)");
@@ -2649,8 +2652,9 @@ snd_azf3328_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2649 since our hardware ought to be similar, thus use same ID. */ 2652 since our hardware ought to be similar, thus use same ID. */
2650 err = snd_mpu401_uart_new( 2653 err = snd_mpu401_uart_new(
2651 card, 0, 2654 card, 0,
2652 MPU401_HW_AZT2320, chip->mpu_io, MPU401_INFO_INTEGRATED, 2655 MPU401_HW_AZT2320, chip->mpu_io,
2653 pci->irq, 0, &chip->rmidi 2656 MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
2657 -1, &chip->rmidi
2654 ); 2658 );
2655 if (err < 0) { 2659 if (err < 0) {
2656 snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n", 2660 snd_printk(KERN_ERR "azf3328: no MPU-401 device at 0x%lx?\n",
diff --git a/sound/pci/cmipci.c b/sound/pci/cmipci.c
index 9cf99fb7eb9c..da9c73211eca 100644
--- a/sound/pci/cmipci.c
+++ b/sound/pci/cmipci.c
@@ -3228,8 +3228,9 @@ static int __devinit snd_cmipci_create(struct snd_card *card, struct pci_dev *pc
3228 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI, 3228 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI,
3229 iomidi, 3229 iomidi,
3230 (integrated_midi ? 3230 (integrated_midi ?
3231 MPU401_INFO_INTEGRATED : 0), 3231 MPU401_INFO_INTEGRATED : 0) |
3232 cm->irq, 0, &cm->rmidi)) < 0) { 3232 MPU401_INFO_IRQ_HOOK,
3233 -1, &cm->rmidi)) < 0) {
3233 printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi); 3234 printk(KERN_ERR "cmipci: no UART401 device at 0x%lx\n", iomidi);
3234 } 3235 }
3235 } 3236 }
diff --git a/sound/pci/ctxfi/ctpcm.c b/sound/pci/ctxfi/ctpcm.c
index 457d21189b0d..2c8622617c8c 100644
--- a/sound/pci/ctxfi/ctpcm.c
+++ b/sound/pci/ctxfi/ctpcm.c
@@ -404,7 +404,7 @@ int ct_alsa_pcm_create(struct ct_atc *atc,
404 int err; 404 int err;
405 int playback_count, capture_count; 405 int playback_count, capture_count;
406 406
407 playback_count = (IEC958 == device) ? 1 : 8; 407 playback_count = (IEC958 == device) ? 1 : 256;
408 capture_count = (FRONT == device) ? 1 : 0; 408 capture_count = (FRONT == device) ? 1 : 0;
409 err = snd_pcm_new(atc->card, "ctxfi", device, 409 err = snd_pcm_new(atc->card, "ctxfi", device,
410 playback_count, capture_count, &pcm); 410 playback_count, capture_count, &pcm);
diff --git a/sound/pci/ctxfi/ctsrc.c b/sound/pci/ctxfi/ctsrc.c
index c749fa720889..e134b3a5780d 100644
--- a/sound/pci/ctxfi/ctsrc.c
+++ b/sound/pci/ctxfi/ctsrc.c
@@ -20,7 +20,7 @@
20#include "cthardware.h" 20#include "cthardware.h"
21#include <linux/slab.h> 21#include <linux/slab.h>
22 22
23#define SRC_RESOURCE_NUM 64 23#define SRC_RESOURCE_NUM 256
24#define SRCIMP_RESOURCE_NUM 256 24#define SRCIMP_RESOURCE_NUM 256
25 25
26static unsigned int conj_mask; 26static unsigned int conj_mask;
diff --git a/sound/pci/ctxfi/ctvmem.h b/sound/pci/ctxfi/ctvmem.h
index b23adfca4de6..e6da60eb19ce 100644
--- a/sound/pci/ctxfi/ctvmem.h
+++ b/sound/pci/ctxfi/ctvmem.h
@@ -18,7 +18,7 @@
18#ifndef CTVMEM_H 18#ifndef CTVMEM_H
19#define CTVMEM_H 19#define CTVMEM_H
20 20
21#define CT_PTP_NUM 1 /* num of device page table pages */ 21#define CT_PTP_NUM 4 /* num of device page table pages */
22 22
23#include <linux/mutex.h> 23#include <linux/mutex.h>
24#include <linux/list.h> 24#include <linux/list.h>
diff --git a/sound/pci/emu10k1/emupcm.c b/sound/pci/emu10k1/emupcm.c
index 622bace148e3..e22b8e2bbd88 100644
--- a/sound/pci/emu10k1/emupcm.c
+++ b/sound/pci/emu10k1/emupcm.c
@@ -1146,6 +1146,11 @@ static int snd_emu10k1_playback_open(struct snd_pcm_substream *substream)
1146 kfree(epcm); 1146 kfree(epcm);
1147 return err; 1147 return err;
1148 } 1148 }
1149 err = snd_pcm_hw_rule_noresample(runtime, 48000);
1150 if (err < 0) {
1151 kfree(epcm);
1152 return err;
1153 }
1149 mix = &emu->pcm_mixer[substream->number]; 1154 mix = &emu->pcm_mixer[substream->number];
1150 for (i = 0; i < 4; i++) 1155 for (i = 0; i < 4; i++)
1151 mix->send_routing[0][i] = mix->send_routing[1][i] = mix->send_routing[2][i] = i; 1156 mix->send_routing[0][i] = mix->send_routing[1][i] = mix->send_routing[2][i] = i;
diff --git a/sound/pci/es1938.c b/sound/pci/es1938.c
index 26a5a2f25d4b..718a2643474e 100644
--- a/sound/pci/es1938.c
+++ b/sound/pci/es1938.c
@@ -1854,8 +1854,9 @@ static int __devinit snd_es1938_probe(struct pci_dev *pci,
1854 } 1854 }
1855 } 1855 }
1856 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 1856 if (snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
1857 chip->mpu_port, MPU401_INFO_INTEGRATED, 1857 chip->mpu_port,
1858 chip->irq, 0, &chip->rmidi) < 0) { 1858 MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
1859 -1, &chip->rmidi) < 0) {
1859 printk(KERN_ERR "es1938: unable to initialize MPU-401\n"); 1860 printk(KERN_ERR "es1938: unable to initialize MPU-401\n");
1860 } else { 1861 } else {
1861 // this line is vital for MIDI interrupt handling on ess-solo1 1862 // this line is vital for MIDI interrupt handling on ess-solo1
diff --git a/sound/pci/es1968.c b/sound/pci/es1968.c
index 99ea9320c6b5..407e4abc4356 100644
--- a/sound/pci/es1968.c
+++ b/sound/pci/es1968.c
@@ -2843,8 +2843,9 @@ static int __devinit snd_es1968_probe(struct pci_dev *pci,
2843 if (enable_mpu[dev]) { 2843 if (enable_mpu[dev]) {
2844 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401, 2844 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_MPU401,
2845 chip->io_port + ESM_MPU401_PORT, 2845 chip->io_port + ESM_MPU401_PORT,
2846 MPU401_INFO_INTEGRATED, 2846 MPU401_INFO_INTEGRATED |
2847 chip->irq, 0, &chip->rmidi)) < 0) { 2847 MPU401_INFO_IRQ_HOOK,
2848 -1, &chip->rmidi)) < 0) {
2848 printk(KERN_WARNING "es1968: skipping MPU-401 MIDI support..\n"); 2849 printk(KERN_WARNING "es1968: skipping MPU-401 MIDI support..\n");
2849 } 2850 }
2850 } 2851 }
diff --git a/sound/pci/fm801.c b/sound/pci/fm801.c
index f9123f09e83e..136f7232bb7c 100644
--- a/sound/pci/fm801.c
+++ b/sound/pci/fm801.c
@@ -68,6 +68,7 @@ MODULE_PARM_DESC(enable, "Enable FM801 soundcard.");
68module_param_array(tea575x_tuner, int, NULL, 0444); 68module_param_array(tea575x_tuner, int, NULL, 0444);
69MODULE_PARM_DESC(tea575x_tuner, "TEA575x tuner access method (0 = auto, 1 = SF256-PCS, 2=SF256-PCP, 3=SF64-PCR, 8=disable, +16=tuner-only)."); 69MODULE_PARM_DESC(tea575x_tuner, "TEA575x tuner access method (0 = auto, 1 = SF256-PCS, 2=SF256-PCP, 3=SF64-PCR, 8=disable, +16=tuner-only).");
70 70
71#define TUNER_DISABLED (1<<3)
71#define TUNER_ONLY (1<<4) 72#define TUNER_ONLY (1<<4)
72#define TUNER_TYPE_MASK (~TUNER_ONLY & 0xFFFF) 73#define TUNER_TYPE_MASK (~TUNER_ONLY & 0xFFFF)
73 74
@@ -728,11 +729,14 @@ static struct snd_fm801_tea575x_gpio snd_fm801_tea575x_gpios[] = {
728 { .data = 2, .clk = 0, .wren = 1, .most = 3, .name = "SF64-PCR" }, 729 { .data = 2, .clk = 0, .wren = 1, .most = 3, .name = "SF64-PCR" },
729}; 730};
730 731
732#define get_tea575x_gpio(chip) \
733 (&snd_fm801_tea575x_gpios[((chip)->tea575x_tuner & TUNER_TYPE_MASK) - 1])
734
731static void snd_fm801_tea575x_set_pins(struct snd_tea575x *tea, u8 pins) 735static void snd_fm801_tea575x_set_pins(struct snd_tea575x *tea, u8 pins)
732{ 736{
733 struct fm801 *chip = tea->private_data; 737 struct fm801 *chip = tea->private_data;
734 unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL)); 738 unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL));
735 struct snd_fm801_tea575x_gpio gpio = snd_fm801_tea575x_gpios[(chip->tea575x_tuner & TUNER_TYPE_MASK) - 1]; 739 struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
736 740
737 reg &= ~(FM801_GPIO_GP(gpio.data) | 741 reg &= ~(FM801_GPIO_GP(gpio.data) |
738 FM801_GPIO_GP(gpio.clk) | 742 FM801_GPIO_GP(gpio.clk) |
@@ -750,7 +754,7 @@ static u8 snd_fm801_tea575x_get_pins(struct snd_tea575x *tea)
750{ 754{
751 struct fm801 *chip = tea->private_data; 755 struct fm801 *chip = tea->private_data;
752 unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL)); 756 unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL));
753 struct snd_fm801_tea575x_gpio gpio = snd_fm801_tea575x_gpios[(chip->tea575x_tuner & TUNER_TYPE_MASK) - 1]; 757 struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
754 758
755 return (reg & FM801_GPIO_GP(gpio.data)) ? TEA575X_DATA : 0 | 759 return (reg & FM801_GPIO_GP(gpio.data)) ? TEA575X_DATA : 0 |
756 (reg & FM801_GPIO_GP(gpio.most)) ? TEA575X_MOST : 0; 760 (reg & FM801_GPIO_GP(gpio.most)) ? TEA575X_MOST : 0;
@@ -760,7 +764,7 @@ static void snd_fm801_tea575x_set_direction(struct snd_tea575x *tea, bool output
760{ 764{
761 struct fm801 *chip = tea->private_data; 765 struct fm801 *chip = tea->private_data;
762 unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL)); 766 unsigned short reg = inw(FM801_REG(chip, GPIO_CTRL));
763 struct snd_fm801_tea575x_gpio gpio = snd_fm801_tea575x_gpios[(chip->tea575x_tuner & TUNER_TYPE_MASK) - 1]; 767 struct snd_fm801_tea575x_gpio gpio = *get_tea575x_gpio(chip);
764 768
765 /* use GPIO lines and set write enable bit */ 769 /* use GPIO lines and set write enable bit */
766 reg |= FM801_GPIO_GS(gpio.data) | 770 reg |= FM801_GPIO_GS(gpio.data) |
@@ -1150,7 +1154,8 @@ static int snd_fm801_free(struct fm801 *chip)
1150 1154
1151 __end_hw: 1155 __end_hw:
1152#ifdef CONFIG_SND_FM801_TEA575X_BOOL 1156#ifdef CONFIG_SND_FM801_TEA575X_BOOL
1153 snd_tea575x_exit(&chip->tea); 1157 if (!(chip->tea575x_tuner & TUNER_DISABLED))
1158 snd_tea575x_exit(&chip->tea);
1154#endif 1159#endif
1155 if (chip->irq >= 0) 1160 if (chip->irq >= 0)
1156 free_irq(chip->irq, chip); 1161 free_irq(chip->irq, chip);
@@ -1236,7 +1241,6 @@ static int __devinit snd_fm801_create(struct snd_card *card,
1236 (tea575x_tuner & TUNER_TYPE_MASK) < 4) { 1241 (tea575x_tuner & TUNER_TYPE_MASK) < 4) {
1237 if (snd_tea575x_init(&chip->tea)) { 1242 if (snd_tea575x_init(&chip->tea)) {
1238 snd_printk(KERN_ERR "TEA575x radio not found\n"); 1243 snd_printk(KERN_ERR "TEA575x radio not found\n");
1239 snd_fm801_free(chip);
1240 return -ENODEV; 1244 return -ENODEV;
1241 } 1245 }
1242 } else if ((tea575x_tuner & TUNER_TYPE_MASK) == 0) { 1246 } else if ((tea575x_tuner & TUNER_TYPE_MASK) == 0) {
@@ -1245,17 +1249,19 @@ static int __devinit snd_fm801_create(struct snd_card *card,
1245 chip->tea575x_tuner = tea575x_tuner; 1249 chip->tea575x_tuner = tea575x_tuner;
1246 if (!snd_tea575x_init(&chip->tea)) { 1250 if (!snd_tea575x_init(&chip->tea)) {
1247 snd_printk(KERN_INFO "detected TEA575x radio type %s\n", 1251 snd_printk(KERN_INFO "detected TEA575x radio type %s\n",
1248 snd_fm801_tea575x_gpios[tea575x_tuner - 1].name); 1252 get_tea575x_gpio(chip)->name);
1249 break; 1253 break;
1250 } 1254 }
1251 } 1255 }
1252 if (tea575x_tuner == 4) { 1256 if (tea575x_tuner == 4) {
1253 snd_printk(KERN_ERR "TEA575x radio not found\n"); 1257 snd_printk(KERN_ERR "TEA575x radio not found\n");
1254 snd_fm801_free(chip); 1258 chip->tea575x_tuner = TUNER_DISABLED;
1255 return -ENODEV;
1256 } 1259 }
1257 } 1260 }
1258 strlcpy(chip->tea.card, snd_fm801_tea575x_gpios[(tea575x_tuner & TUNER_TYPE_MASK) - 1].name, sizeof(chip->tea.card)); 1261 if (!(chip->tea575x_tuner & TUNER_DISABLED)) {
1262 strlcpy(chip->tea.card, get_tea575x_gpio(chip)->name,
1263 sizeof(chip->tea.card));
1264 }
1259#endif 1265#endif
1260 1266
1261 *rchip = chip; 1267 *rchip = chip;
@@ -1306,8 +1312,9 @@ static int __devinit snd_card_fm801_probe(struct pci_dev *pci,
1306 } 1312 }
1307 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801, 1313 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_FM801,
1308 FM801_REG(chip, MPU401_DATA), 1314 FM801_REG(chip, MPU401_DATA),
1309 MPU401_INFO_INTEGRATED, 1315 MPU401_INFO_INTEGRATED |
1310 chip->irq, 0, &chip->rmidi)) < 0) { 1316 MPU401_INFO_IRQ_HOOK,
1317 -1, &chip->rmidi)) < 0) {
1311 snd_card_free(card); 1318 snd_card_free(card);
1312 return err; 1319 return err;
1313 } 1320 }
diff --git a/sound/pci/hda/Makefile b/sound/pci/hda/Makefile
index 87365d5ea2a9..f928d6634723 100644
--- a/sound/pci/hda/Makefile
+++ b/sound/pci/hda/Makefile
@@ -6,6 +6,9 @@ snd-hda-codec-$(CONFIG_PROC_FS) += hda_proc.o
6snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o 6snd-hda-codec-$(CONFIG_SND_HDA_HWDEP) += hda_hwdep.o
7snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o 7snd-hda-codec-$(CONFIG_SND_HDA_INPUT_BEEP) += hda_beep.o
8 8
9# for trace-points
10CFLAGS_hda_codec.o := -I$(src)
11
9snd-hda-codec-realtek-objs := patch_realtek.o 12snd-hda-codec-realtek-objs := patch_realtek.o
10snd-hda-codec-cmedia-objs := patch_cmedia.o 13snd-hda-codec-cmedia-objs := patch_cmedia.o
11snd-hda-codec-analog-objs := patch_analog.o 14snd-hda-codec-analog-objs := patch_analog.o
diff --git a/sound/pci/hda/alc260_quirks.c b/sound/pci/hda/alc260_quirks.c
index 21ec2cb100b0..3b5170b9700f 100644
--- a/sound/pci/hda/alc260_quirks.c
+++ b/sound/pci/hda/alc260_quirks.c
@@ -7,9 +7,6 @@
7enum { 7enum {
8 ALC260_AUTO, 8 ALC260_AUTO,
9 ALC260_BASIC, 9 ALC260_BASIC,
10 ALC260_HP,
11 ALC260_HP_DC7600,
12 ALC260_HP_3013,
13 ALC260_FUJITSU_S702X, 10 ALC260_FUJITSU_S702X,
14 ALC260_ACER, 11 ALC260_ACER,
15 ALC260_WILL, 12 ALC260_WILL,
@@ -142,8 +139,6 @@ static const struct hda_channel_mode alc260_modes[1] = {
142/* Mixer combinations 139/* Mixer combinations
143 * 140 *
144 * basic: base_output + input + pc_beep + capture 141 * basic: base_output + input + pc_beep + capture
145 * HP: base_output + input + capture_alt
146 * HP_3013: hp_3013 + input + capture
147 * fujitsu: fujitsu + capture 142 * fujitsu: fujitsu + capture
148 * acer: acer + capture 143 * acer: acer + capture
149 */ 144 */
@@ -170,145 +165,6 @@ static const struct snd_kcontrol_new alc260_input_mixer[] = {
170 { } /* end */ 165 { } /* end */
171}; 166};
172 167
173/* update HP, line and mono out pins according to the master switch */
174static void alc260_hp_master_update(struct hda_codec *codec)
175{
176 update_speakers(codec);
177}
178
179static int alc260_hp_master_sw_get(struct snd_kcontrol *kcontrol,
180 struct snd_ctl_elem_value *ucontrol)
181{
182 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
183 struct alc_spec *spec = codec->spec;
184 *ucontrol->value.integer.value = !spec->master_mute;
185 return 0;
186}
187
188static int alc260_hp_master_sw_put(struct snd_kcontrol *kcontrol,
189 struct snd_ctl_elem_value *ucontrol)
190{
191 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
192 struct alc_spec *spec = codec->spec;
193 int val = !*ucontrol->value.integer.value;
194
195 if (val == spec->master_mute)
196 return 0;
197 spec->master_mute = val;
198 alc260_hp_master_update(codec);
199 return 1;
200}
201
202static const struct snd_kcontrol_new alc260_hp_output_mixer[] = {
203 {
204 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
205 .name = "Master Playback Switch",
206 .subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
207 .info = snd_ctl_boolean_mono_info,
208 .get = alc260_hp_master_sw_get,
209 .put = alc260_hp_master_sw_put,
210 },
211 HDA_CODEC_VOLUME("Front Playback Volume", 0x08, 0x0, HDA_OUTPUT),
212 HDA_BIND_MUTE("Front Playback Switch", 0x08, 2, HDA_INPUT),
213 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x09, 0x0, HDA_OUTPUT),
214 HDA_BIND_MUTE("Headphone Playback Switch", 0x09, 2, HDA_INPUT),
215 HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0,
216 HDA_OUTPUT),
217 HDA_BIND_MUTE_MONO("Speaker Playback Switch", 0x0a, 1, 2, HDA_INPUT),
218 { } /* end */
219};
220
221static const struct hda_verb alc260_hp_unsol_verbs[] = {
222 {0x10, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
223 {},
224};
225
226static void alc260_hp_setup(struct hda_codec *codec)
227{
228 struct alc_spec *spec = codec->spec;
229
230 spec->autocfg.hp_pins[0] = 0x0f;
231 spec->autocfg.speaker_pins[0] = 0x10;
232 spec->autocfg.speaker_pins[1] = 0x11;
233 spec->automute = 1;
234 spec->automute_mode = ALC_AUTOMUTE_PIN;
235}
236
237static const struct snd_kcontrol_new alc260_hp_3013_mixer[] = {
238 {
239 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
240 .name = "Master Playback Switch",
241 .subdevice = HDA_SUBDEV_NID_FLAG | 0x11,
242 .info = snd_ctl_boolean_mono_info,
243 .get = alc260_hp_master_sw_get,
244 .put = alc260_hp_master_sw_put,
245 },
246 HDA_CODEC_VOLUME("Front Playback Volume", 0x09, 0x0, HDA_OUTPUT),
247 HDA_CODEC_MUTE("Front Playback Switch", 0x10, 0x0, HDA_OUTPUT),
248 HDA_CODEC_VOLUME("Aux-In Playback Volume", 0x07, 0x06, HDA_INPUT),
249 HDA_CODEC_MUTE("Aux-In Playback Switch", 0x07, 0x06, HDA_INPUT),
250 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x08, 0x0, HDA_OUTPUT),
251 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
252 HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0a, 1, 0x0, HDA_OUTPUT),
253 HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x11, 1, 0x0, HDA_OUTPUT),
254 { } /* end */
255};
256
257static void alc260_hp_3013_setup(struct hda_codec *codec)
258{
259 struct alc_spec *spec = codec->spec;
260
261 spec->autocfg.hp_pins[0] = 0x15;
262 spec->autocfg.speaker_pins[0] = 0x10;
263 spec->autocfg.speaker_pins[1] = 0x11;
264 spec->automute = 1;
265 spec->automute_mode = ALC_AUTOMUTE_PIN;
266}
267
268static const struct hda_bind_ctls alc260_dc7600_bind_master_vol = {
269 .ops = &snd_hda_bind_vol,
270 .values = {
271 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_OUTPUT),
272 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_OUTPUT),
273 HDA_COMPOSE_AMP_VAL(0x0a, 3, 0, HDA_OUTPUT),
274 0
275 },
276};
277
278static const struct hda_bind_ctls alc260_dc7600_bind_switch = {
279 .ops = &snd_hda_bind_sw,
280 .values = {
281 HDA_COMPOSE_AMP_VAL(0x11, 3, 0, HDA_OUTPUT),
282 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
283 0
284 },
285};
286
287static const struct snd_kcontrol_new alc260_hp_dc7600_mixer[] = {
288 HDA_BIND_VOL("Master Playback Volume", &alc260_dc7600_bind_master_vol),
289 HDA_BIND_SW("LineOut Playback Switch", &alc260_dc7600_bind_switch),
290 HDA_CODEC_MUTE("Speaker Playback Switch", 0x0f, 0x0, HDA_OUTPUT),
291 HDA_CODEC_MUTE("Headphone Playback Switch", 0x10, 0x0, HDA_OUTPUT),
292 { } /* end */
293};
294
295static const struct hda_verb alc260_hp_3013_unsol_verbs[] = {
296 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
297 {},
298};
299
300static void alc260_hp_3012_setup(struct hda_codec *codec)
301{
302 struct alc_spec *spec = codec->spec;
303
304 spec->autocfg.hp_pins[0] = 0x10;
305 spec->autocfg.speaker_pins[0] = 0x0f;
306 spec->autocfg.speaker_pins[1] = 0x11;
307 spec->autocfg.speaker_pins[2] = 0x15;
308 spec->automute = 1;
309 spec->automute_mode = ALC_AUTOMUTE_PIN;
310}
311
312/* Fujitsu S702x series laptops. ALC260 pin usage: Mic/Line jack = 0x12, 168/* Fujitsu S702x series laptops. ALC260 pin usage: Mic/Line jack = 0x12,
313 * HP jack = 0x14, CD audio = 0x16, internal speaker = 0x10. 169 * HP jack = 0x14, CD audio = 0x16, internal speaker = 0x10.
314 */ 170 */
@@ -480,106 +336,6 @@ static const struct hda_verb alc260_init_verbs[] = {
480 { } 336 { }
481}; 337};
482 338
483#if 0 /* should be identical with alc260_init_verbs? */
484static const struct hda_verb alc260_hp_init_verbs[] = {
485 /* Headphone and output */
486 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
487 /* mono output */
488 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
489 /* Mic1 (rear panel) pin widget for input and vref at 80% */
490 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
491 /* Mic2 (front panel) pin widget for input and vref at 80% */
492 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
493 /* Line In pin widget for input */
494 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
495 /* Line-2 pin widget for output */
496 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
497 /* CD pin widget for input */
498 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
499 /* unmute amp left and right */
500 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
501 /* set connection select to line in (default select for this ADC) */
502 {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
503 /* unmute Line-Out mixer amp left and right (volume = 0) */
504 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
505 /* mute pin widget amp left and right (no gain on this amp) */
506 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
507 /* unmute HP mixer amp left and right (volume = 0) */
508 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
509 /* mute pin widget amp left and right (no gain on this amp) */
510 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
511 /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
512 * Line In 2 = 0x03
513 */
514 /* mute analog inputs */
515 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
516 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
517 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
518 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
519 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
520 /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
521 /* Unmute Front out path */
522 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
523 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
524 /* Unmute Headphone out path */
525 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
526 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
527 /* Unmute Mono out path */
528 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
529 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
530 { }
531};
532#endif
533
534static const struct hda_verb alc260_hp_3013_init_verbs[] = {
535 /* Line out and output */
536 {0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
537 /* mono output */
538 {0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
539 /* Mic1 (rear panel) pin widget for input and vref at 80% */
540 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
541 /* Mic2 (front panel) pin widget for input and vref at 80% */
542 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
543 /* Line In pin widget for input */
544 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
545 /* Headphone pin widget for output */
546 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
547 /* CD pin widget for input */
548 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
549 /* unmute amp left and right */
550 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000},
551 /* set connection select to line in (default select for this ADC) */
552 {0x04, AC_VERB_SET_CONNECT_SEL, 0x02},
553 /* unmute Line-Out mixer amp left and right (volume = 0) */
554 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
555 /* mute pin widget amp left and right (no gain on this amp) */
556 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
557 /* unmute HP mixer amp left and right (volume = 0) */
558 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0xb000},
559 /* mute pin widget amp left and right (no gain on this amp) */
560 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, 0x0000},
561 /* Amp Indexes: CD = 0x04, Line In 1 = 0x02, Mic 1 = 0x00 &
562 * Line In 2 = 0x03
563 */
564 /* mute analog inputs */
565 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
566 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
567 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
568 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
569 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
570 /* Amp Indexes: DAC = 0x01 & mixer = 0x00 */
571 /* Unmute Front out path */
572 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
573 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
574 /* Unmute Headphone out path */
575 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
576 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
577 /* Unmute Mono out path */
578 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
579 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
580 { }
581};
582
583/* Initialisation sequence for ALC260 as configured in Fujitsu S702x 339/* Initialisation sequence for ALC260 as configured in Fujitsu S702x
584 * laptops. ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD 340 * laptops. ALC260 pin usage: Mic/Line jack = 0x12, HP jack = 0x14, CD
585 * audio = 0x16, internal speaker = 0x10. 341 * audio = 0x16, internal speaker = 0x10.
@@ -1093,9 +849,6 @@ static const struct hda_verb alc260_test_init_verbs[] = {
1093 */ 849 */
1094static const char * const alc260_models[ALC260_MODEL_LAST] = { 850static const char * const alc260_models[ALC260_MODEL_LAST] = {
1095 [ALC260_BASIC] = "basic", 851 [ALC260_BASIC] = "basic",
1096 [ALC260_HP] = "hp",
1097 [ALC260_HP_3013] = "hp-3013",
1098 [ALC260_HP_DC7600] = "hp-dc7600",
1099 [ALC260_FUJITSU_S702X] = "fujitsu", 852 [ALC260_FUJITSU_S702X] = "fujitsu",
1100 [ALC260_ACER] = "acer", 853 [ALC260_ACER] = "acer",
1101 [ALC260_WILL] = "will", 854 [ALC260_WILL] = "will",
@@ -1112,15 +865,6 @@ static const struct snd_pci_quirk alc260_cfg_tbl[] = {
1112 SND_PCI_QUIRK(0x1025, 0x007f, "Acer", ALC260_WILL), 865 SND_PCI_QUIRK(0x1025, 0x007f, "Acer", ALC260_WILL),
1113 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER), 866 SND_PCI_QUIRK(0x1025, 0x008f, "Acer", ALC260_ACER),
1114 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100), 867 SND_PCI_QUIRK(0x1509, 0x4540, "Favorit 100XS", ALC260_FAVORIT100),
1115 SND_PCI_QUIRK(0x103c, 0x2808, "HP d5700", ALC260_HP_3013),
1116 SND_PCI_QUIRK(0x103c, 0x280a, "HP d5750", ALC260_AUTO), /* no quirk */
1117 SND_PCI_QUIRK(0x103c, 0x3010, "HP", ALC260_HP_3013),
1118 SND_PCI_QUIRK(0x103c, 0x3011, "HP", ALC260_HP_3013),
1119 SND_PCI_QUIRK(0x103c, 0x3012, "HP", ALC260_HP_DC7600),
1120 SND_PCI_QUIRK(0x103c, 0x3013, "HP", ALC260_HP_3013),
1121 SND_PCI_QUIRK(0x103c, 0x3014, "HP", ALC260_HP),
1122 SND_PCI_QUIRK(0x103c, 0x3015, "HP", ALC260_HP),
1123 SND_PCI_QUIRK(0x103c, 0x3016, "HP", ALC260_HP),
1124 SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC), 868 SND_PCI_QUIRK(0x104d, 0x81bb, "Sony VAIO", ALC260_BASIC),
1125 SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC), 869 SND_PCI_QUIRK(0x104d, 0x81cc, "Sony VAIO", ALC260_BASIC),
1126 SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC), 870 SND_PCI_QUIRK(0x104d, 0x81cd, "Sony VAIO", ALC260_BASIC),
@@ -1144,54 +888,6 @@ static const struct alc_config_preset alc260_presets[] = {
1144 .channel_mode = alc260_modes, 888 .channel_mode = alc260_modes,
1145 .input_mux = &alc260_capture_source, 889 .input_mux = &alc260_capture_source,
1146 }, 890 },
1147 [ALC260_HP] = {
1148 .mixers = { alc260_hp_output_mixer,
1149 alc260_input_mixer },
1150 .init_verbs = { alc260_init_verbs,
1151 alc260_hp_unsol_verbs },
1152 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
1153 .dac_nids = alc260_dac_nids,
1154 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
1155 .adc_nids = alc260_adc_nids_alt,
1156 .num_channel_mode = ARRAY_SIZE(alc260_modes),
1157 .channel_mode = alc260_modes,
1158 .input_mux = &alc260_capture_source,
1159 .unsol_event = alc_sku_unsol_event,
1160 .setup = alc260_hp_setup,
1161 .init_hook = alc_inithook,
1162 },
1163 [ALC260_HP_DC7600] = {
1164 .mixers = { alc260_hp_dc7600_mixer,
1165 alc260_input_mixer },
1166 .init_verbs = { alc260_init_verbs,
1167 alc260_hp_dc7600_verbs },
1168 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
1169 .dac_nids = alc260_dac_nids,
1170 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
1171 .adc_nids = alc260_adc_nids_alt,
1172 .num_channel_mode = ARRAY_SIZE(alc260_modes),
1173 .channel_mode = alc260_modes,
1174 .input_mux = &alc260_capture_source,
1175 .unsol_event = alc_sku_unsol_event,
1176 .setup = alc260_hp_3012_setup,
1177 .init_hook = alc_inithook,
1178 },
1179 [ALC260_HP_3013] = {
1180 .mixers = { alc260_hp_3013_mixer,
1181 alc260_input_mixer },
1182 .init_verbs = { alc260_hp_3013_init_verbs,
1183 alc260_hp_3013_unsol_verbs },
1184 .num_dacs = ARRAY_SIZE(alc260_dac_nids),
1185 .dac_nids = alc260_dac_nids,
1186 .num_adc_nids = ARRAY_SIZE(alc260_adc_nids_alt),
1187 .adc_nids = alc260_adc_nids_alt,
1188 .num_channel_mode = ARRAY_SIZE(alc260_modes),
1189 .channel_mode = alc260_modes,
1190 .input_mux = &alc260_capture_source,
1191 .unsol_event = alc_sku_unsol_event,
1192 .setup = alc260_hp_3013_setup,
1193 .init_hook = alc_inithook,
1194 },
1195 [ALC260_FUJITSU_S702X] = { 891 [ALC260_FUJITSU_S702X] = {
1196 .mixers = { alc260_fujitsu_mixer }, 892 .mixers = { alc260_fujitsu_mixer },
1197 .init_verbs = { alc260_fujitsu_init_verbs }, 893 .init_verbs = { alc260_fujitsu_init_verbs },
diff --git a/sound/pci/hda/alc262_quirks.c b/sound/pci/hda/alc262_quirks.c
index 8d2097d77642..7894b2b5aacf 100644
--- a/sound/pci/hda/alc262_quirks.c
+++ b/sound/pci/hda/alc262_quirks.c
@@ -10,13 +10,7 @@ enum {
10 ALC262_HIPPO, 10 ALC262_HIPPO,
11 ALC262_HIPPO_1, 11 ALC262_HIPPO_1,
12 ALC262_FUJITSU, 12 ALC262_FUJITSU,
13 ALC262_HP_BPC,
14 ALC262_HP_BPC_D7000_WL,
15 ALC262_HP_BPC_D7000_WF,
16 ALC262_HP_TC_T5735,
17 ALC262_HP_RP5700,
18 ALC262_BENQ_ED8, 13 ALC262_BENQ_ED8,
19 ALC262_SONY_ASSAMD,
20 ALC262_BENQ_T31, 14 ALC262_BENQ_T31,
21 ALC262_ULTRA, 15 ALC262_ULTRA,
22 ALC262_LENOVO_3000, 16 ALC262_LENOVO_3000,
@@ -66,164 +60,31 @@ static const struct snd_kcontrol_new alc262_base_mixer[] = {
66 { } /* end */ 60 { } /* end */
67}; 61};
68 62
69/* update HP, line and mono-out pins according to the master switch */ 63/* bind hp and internal speaker mute (with plug check) as master switch */
70#define alc262_hp_master_update alc260_hp_master_update
71 64
72static void alc262_hp_bpc_setup(struct hda_codec *codec) 65static int alc262_hippo_master_sw_get(struct snd_kcontrol *kcontrol,
66 struct snd_ctl_elem_value *ucontrol)
73{ 67{
68 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
74 struct alc_spec *spec = codec->spec; 69 struct alc_spec *spec = codec->spec;
75 70 *ucontrol->value.integer.value = !spec->master_mute;
76 spec->autocfg.hp_pins[0] = 0x1b; 71 return 0;
77 spec->autocfg.speaker_pins[0] = 0x16;
78 spec->automute = 1;
79 spec->automute_mode = ALC_AUTOMUTE_PIN;
80} 72}
81 73
82static void alc262_hp_wildwest_setup(struct hda_codec *codec) 74static int alc262_hippo_master_sw_put(struct snd_kcontrol *kcontrol,
83{ 75 struct snd_ctl_elem_value *ucontrol)
84 struct alc_spec *spec = codec->spec;
85
86 spec->autocfg.hp_pins[0] = 0x15;
87 spec->autocfg.speaker_pins[0] = 0x16;
88 spec->automute = 1;
89 spec->automute_mode = ALC_AUTOMUTE_PIN;
90}
91
92#define alc262_hp_master_sw_get alc260_hp_master_sw_get
93#define alc262_hp_master_sw_put alc260_hp_master_sw_put
94
95#define ALC262_HP_MASTER_SWITCH \
96 { \
97 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
98 .name = "Master Playback Switch", \
99 .info = snd_ctl_boolean_mono_info, \
100 .get = alc262_hp_master_sw_get, \
101 .put = alc262_hp_master_sw_put, \
102 }, \
103 { \
104 .iface = NID_MAPPING, \
105 .name = "Master Playback Switch", \
106 .private_value = 0x15 | (0x16 << 8) | (0x1b << 16), \
107 }
108
109
110static const struct snd_kcontrol_new alc262_HP_BPC_mixer[] = {
111 ALC262_HP_MASTER_SWITCH,
112 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
113 HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
114 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
115 HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
116 HDA_OUTPUT),
117 HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
118 HDA_OUTPUT),
119 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
120 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
121 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
122 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
123 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
124 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
125 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
126 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
127 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
128 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
129 HDA_CODEC_VOLUME("AUX IN Playback Volume", 0x0b, 0x06, HDA_INPUT),
130 HDA_CODEC_MUTE("AUX IN Playback Switch", 0x0b, 0x06, HDA_INPUT),
131 { } /* end */
132};
133
134static const struct snd_kcontrol_new alc262_HP_BPC_WildWest_mixer[] = {
135 ALC262_HP_MASTER_SWITCH,
136 HDA_CODEC_VOLUME("Front Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
137 HDA_CODEC_MUTE("Front Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
138 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
139 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
140 HDA_CODEC_VOLUME_MONO("Speaker Playback Volume", 0x0e, 2, 0x0,
141 HDA_OUTPUT),
142 HDA_CODEC_MUTE_MONO("Speaker Playback Switch", 0x16, 2, 0x0,
143 HDA_OUTPUT),
144 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x02, HDA_INPUT),
145 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x02, HDA_INPUT),
146 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x1a, 0, HDA_INPUT),
147 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
148 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
149 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
150 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
151 { } /* end */
152};
153
154static const struct snd_kcontrol_new alc262_HP_BPC_WildWest_option_mixer[] = {
155 HDA_CODEC_VOLUME("Rear Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
156 HDA_CODEC_MUTE("Rear Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
157 HDA_CODEC_VOLUME("Rear Mic Boost Volume", 0x18, 0, HDA_INPUT),
158 { } /* end */
159};
160
161/* mute/unmute internal speaker according to the hp jack and mute state */
162static void alc262_hp_t5735_setup(struct hda_codec *codec)
163{ 76{
77 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
164 struct alc_spec *spec = codec->spec; 78 struct alc_spec *spec = codec->spec;
79 int val = !*ucontrol->value.integer.value;
165 80
166 spec->autocfg.hp_pins[0] = 0x15; 81 if (val == spec->master_mute)
167 spec->autocfg.speaker_pins[0] = 0x14; 82 return 0;
168 spec->automute = 1; 83 spec->master_mute = val;
169 spec->automute_mode = ALC_AUTOMUTE_PIN; 84 update_outputs(codec);
85 return 1;
170} 86}
171 87
172static const struct snd_kcontrol_new alc262_hp_t5735_mixer[] = {
173 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
174 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
175 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0d, 0x0, HDA_OUTPUT),
176 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
177 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
178 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
179 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
180 { } /* end */
181};
182
183static const struct hda_verb alc262_hp_t5735_verbs[] = {
184 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
185 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
186
187 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
188 { }
189};
190
191static const struct snd_kcontrol_new alc262_hp_rp5700_mixer[] = {
192 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
193 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
194 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0e, 0x0, HDA_OUTPUT),
195 HDA_CODEC_MUTE("Speaker Playback Switch", 0x16, 0x0, HDA_OUTPUT),
196 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x01, HDA_INPUT),
197 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x01, HDA_INPUT),
198 { } /* end */
199};
200
201static const struct hda_verb alc262_hp_rp5700_verbs[] = {
202 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
203 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
204 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
205 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
206 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
207 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
208 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
209 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
210 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
211 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x00 << 8))},
212 {}
213};
214
215static const struct hda_input_mux alc262_hp_rp5700_capture_source = {
216 .num_items = 1,
217 .items = {
218 { "Line", 0x1 },
219 },
220};
221
222/* bind hp and internal speaker mute (with plug check) as master switch */
223#define alc262_hippo_master_update alc262_hp_master_update
224#define alc262_hippo_master_sw_get alc262_hp_master_sw_get
225#define alc262_hippo_master_sw_put alc262_hp_master_sw_put
226
227#define ALC262_HIPPO_MASTER_SWITCH \ 88#define ALC262_HIPPO_MASTER_SWITCH \
228 { \ 89 { \
229 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \ 90 .iface = SNDRV_CTL_ELEM_IFACE_MIXER, \
@@ -239,6 +100,9 @@ static const struct hda_input_mux alc262_hp_rp5700_capture_source = {
239 (SUBDEV_SPEAKER(0) << 16), \ 100 (SUBDEV_SPEAKER(0) << 16), \
240 } 101 }
241 102
103#define alc262_hp_master_sw_get alc262_hippo_master_sw_get
104#define alc262_hp_master_sw_put alc262_hippo_master_sw_put
105
242static const struct snd_kcontrol_new alc262_hippo_mixer[] = { 106static const struct snd_kcontrol_new alc262_hippo_mixer[] = {
243 ALC262_HIPPO_MASTER_SWITCH, 107 ALC262_HIPPO_MASTER_SWITCH,
244 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT), 108 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x0c, 0x0, HDA_OUTPUT),
@@ -279,8 +143,7 @@ static void alc262_hippo_setup(struct hda_codec *codec)
279 143
280 spec->autocfg.hp_pins[0] = 0x15; 144 spec->autocfg.hp_pins[0] = 0x15;
281 spec->autocfg.speaker_pins[0] = 0x14; 145 spec->autocfg.speaker_pins[0] = 0x14;
282 spec->automute = 1; 146 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
283 spec->automute_mode = ALC_AUTOMUTE_AMP;
284} 147}
285 148
286static void alc262_hippo1_setup(struct hda_codec *codec) 149static void alc262_hippo1_setup(struct hda_codec *codec)
@@ -289,8 +152,7 @@ static void alc262_hippo1_setup(struct hda_codec *codec)
289 152
290 spec->autocfg.hp_pins[0] = 0x1b; 153 spec->autocfg.hp_pins[0] = 0x1b;
291 spec->autocfg.speaker_pins[0] = 0x14; 154 spec->autocfg.speaker_pins[0] = 0x14;
292 spec->automute = 1; 155 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
293 spec->automute_mode = ALC_AUTOMUTE_AMP;
294} 156}
295 157
296 158
@@ -353,8 +215,7 @@ static void alc262_tyan_setup(struct hda_codec *codec)
353 215
354 spec->autocfg.hp_pins[0] = 0x1b; 216 spec->autocfg.hp_pins[0] = 0x1b;
355 spec->autocfg.speaker_pins[0] = 0x15; 217 spec->autocfg.speaker_pins[0] = 0x15;
356 spec->automute = 1; 218 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
357 spec->automute_mode = ALC_AUTOMUTE_AMP;
358} 219}
359 220
360 221
@@ -496,8 +357,7 @@ static void alc262_toshiba_s06_setup(struct hda_codec *codec)
496 spec->ext_mic_pin = 0x18; 357 spec->ext_mic_pin = 0x18;
497 spec->int_mic_pin = 0x12; 358 spec->int_mic_pin = 0x12;
498 spec->auto_mic = 1; 359 spec->auto_mic = 1;
499 spec->automute = 1; 360 alc_simple_setup_automute(spec, ALC_AUTOMUTE_PIN);
500 spec->automute_mode = ALC_AUTOMUTE_PIN;
501} 361}
502 362
503/* 363/*
@@ -571,27 +431,6 @@ static const struct hda_input_mux alc262_fujitsu_capture_source = {
571 }, 431 },
572}; 432};
573 433
574static const struct hda_input_mux alc262_HP_capture_source = {
575 .num_items = 5,
576 .items = {
577 { "Mic", 0x0 },
578 { "Front Mic", 0x1 },
579 { "Line", 0x2 },
580 { "CD", 0x4 },
581 { "AUX IN", 0x6 },
582 },
583};
584
585static const struct hda_input_mux alc262_HP_D7000_capture_source = {
586 .num_items = 4,
587 .items = {
588 { "Mic", 0x0 },
589 { "Front Mic", 0x2 },
590 { "Line", 0x1 },
591 { "CD", 0x4 },
592 },
593};
594
595static void alc262_fujitsu_setup(struct hda_codec *codec) 434static void alc262_fujitsu_setup(struct hda_codec *codec)
596{ 435{
597 struct alc_spec *spec = codec->spec; 436 struct alc_spec *spec = codec->spec;
@@ -599,8 +438,7 @@ static void alc262_fujitsu_setup(struct hda_codec *codec)
599 spec->autocfg.hp_pins[0] = 0x14; 438 spec->autocfg.hp_pins[0] = 0x14;
600 spec->autocfg.hp_pins[1] = 0x1b; 439 spec->autocfg.hp_pins[1] = 0x1b;
601 spec->autocfg.speaker_pins[0] = 0x15; 440 spec->autocfg.speaker_pins[0] = 0x15;
602 spec->automute = 1; 441 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
603 spec->automute_mode = ALC_AUTOMUTE_AMP;
604} 442}
605 443
606/* bind volumes of both NID 0x0c and 0x0d */ 444/* bind volumes of both NID 0x0c and 0x0d */
@@ -646,8 +484,7 @@ static void alc262_lenovo_3000_setup(struct hda_codec *codec)
646 spec->autocfg.hp_pins[0] = 0x1b; 484 spec->autocfg.hp_pins[0] = 0x1b;
647 spec->autocfg.speaker_pins[0] = 0x14; 485 spec->autocfg.speaker_pins[0] = 0x14;
648 spec->autocfg.speaker_pins[1] = 0x16; 486 spec->autocfg.speaker_pins[1] = 0x16;
649 spec->automute = 1; 487 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
650 spec->automute_mode = ALC_AUTOMUTE_AMP;
651} 488}
652 489
653static const struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = { 490static const struct snd_kcontrol_new alc262_lenovo_3000_mixer[] = {
@@ -752,8 +589,8 @@ static void alc262_ultra_automute(struct hda_codec *codec)
752 mute = 0; 589 mute = 0;
753 /* auto-mute only when HP is used as HP */ 590 /* auto-mute only when HP is used as HP */
754 if (!spec->cur_mux[0]) { 591 if (!spec->cur_mux[0]) {
755 spec->jack_present = snd_hda_jack_detect(codec, 0x15); 592 spec->hp_jack_present = snd_hda_jack_detect(codec, 0x15);
756 if (spec->jack_present) 593 if (spec->hp_jack_present)
757 mute = HDA_AMP_MUTE; 594 mute = HDA_AMP_MUTE;
758 } 595 }
759 /* mute/unmute internal speaker */ 596 /* mute/unmute internal speaker */
@@ -817,206 +654,6 @@ static const struct snd_kcontrol_new alc262_ultra_capture_mixer[] = {
817 { } /* end */ 654 { } /* end */
818}; 655};
819 656
820static const struct hda_verb alc262_HP_BPC_init_verbs[] = {
821 /*
822 * Unmute ADC0-2 and set the default input to mic-in
823 */
824 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
825 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
826 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
827 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
828 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
829 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
830
831 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
832 * mixer widget
833 * Note: PASD motherboards uses the Line In 2 as the input for
834 * front panel mic (mic 2)
835 */
836 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
837 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
838 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
839 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
840 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
841 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
842 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
843 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
844
845 /*
846 * Set up output mixers (0x0c - 0x0e)
847 */
848 /* set vol=0 to output mixers */
849 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
850 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
851 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
852
853 /* set up input amps for analog loopback */
854 /* Amp Indices: DAC = 0, mixer = 1 */
855 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
856 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
857 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
858 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
859 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
860 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
861
862 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
863 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
864 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
865
866 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
867 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
868
869 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
870 {0x15, AC_VERB_SET_CONNECT_SEL, 0x00},
871
872 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
873 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
874 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
875 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
876 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
877
878 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
879 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
880 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
881 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
882 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
883 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
884
885
886 /* FIXME: use matrix-type input source selection */
887 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 0b, 12 */
888 /* Input mixer1: only unmute Mic */
889 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
890 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
891 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
892 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
893 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
894 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
895 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
896 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
897 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
898 /* Input mixer2 */
899 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
900 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
901 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
902 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
903 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
904 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
905 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
906 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
907 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
908 /* Input mixer3 */
909 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
910 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8))},
911 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8))},
912 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x03 << 8))},
913 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x04 << 8))},
914 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x05 << 8))},
915 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x06 << 8))},
916 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x07 << 8))},
917 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x08 << 8))},
918
919 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
920
921 { }
922};
923
924static const struct hda_verb alc262_HP_BPC_WildWest_init_verbs[] = {
925 /*
926 * Unmute ADC0-2 and set the default input to mic-in
927 */
928 {0x07, AC_VERB_SET_CONNECT_SEL, 0x00},
929 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
930 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
931 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
932 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
933 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
934
935 /* Mute input amps (CD, Line In, Mic 1 & Mic 2) of the analog-loopback
936 * mixer widget
937 * Note: PASD motherboards uses the Line In 2 as the input for front
938 * panel mic (mic 2)
939 */
940 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
941 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
942 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
943 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
944 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
945 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
946 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
947 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(6)},
948 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(7)},
949 /*
950 * Set up output mixers (0x0c - 0x0e)
951 */
952 /* set vol=0 to output mixers */
953 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
954 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
955 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
956
957 /* set up input amps for analog loopback */
958 /* Amp Indices: DAC = 0, mixer = 1 */
959 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
960 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
961 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
962 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
963 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
964 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
965
966
967 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP }, /* HP */
968 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Mono */
969 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* rear MIC */
970 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* Line in */
971 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 }, /* Front MIC */
972 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Line out */
973 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN }, /* CD in */
974
975 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
976 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
977
978 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
979 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
980
981 /* {0x14, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 }, */
982 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
983 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
984 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, 0x7023 },
985 {0x1c, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
986 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, 0x7000 },
987
988 /* FIXME: use matrix-type input source selection */
989 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
990 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
991 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))}, /*rear MIC*/
992 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))}, /*Line in*/
993 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))}, /*F MIC*/
994 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))}, /*Front*/
995 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))}, /*CD*/
996 /* {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
997 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))}, /*HP*/
998 /* Input mixer2 */
999 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1000 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1001 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
1002 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
1003 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
1004 /* {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
1005 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
1006 /* Input mixer3 */
1007 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x00 << 8))},
1008 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8))},
1009 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8))},
1010 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x03 << 8))},
1011 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x04 << 8))},
1012 /* {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x06 << 8))}, */
1013 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x07 << 8))},
1014
1015 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
1016
1017 { }
1018};
1019
1020static const struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = { 657static const struct hda_verb alc262_toshiba_rx1_unsol_verbs[] = {
1021 658
1022 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Front Speaker */ 659 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT }, /* Front Speaker */
@@ -1042,13 +679,8 @@ static const char * const alc262_models[ALC262_MODEL_LAST] = {
1042 [ALC262_HIPPO] = "hippo", 679 [ALC262_HIPPO] = "hippo",
1043 [ALC262_HIPPO_1] = "hippo_1", 680 [ALC262_HIPPO_1] = "hippo_1",
1044 [ALC262_FUJITSU] = "fujitsu", 681 [ALC262_FUJITSU] = "fujitsu",
1045 [ALC262_HP_BPC] = "hp-bpc",
1046 [ALC262_HP_BPC_D7000_WL]= "hp-bpc-d7000",
1047 [ALC262_HP_TC_T5735] = "hp-tc-t5735",
1048 [ALC262_HP_RP5700] = "hp-rp5700",
1049 [ALC262_BENQ_ED8] = "benq", 682 [ALC262_BENQ_ED8] = "benq",
1050 [ALC262_BENQ_T31] = "benq-t31", 683 [ALC262_BENQ_T31] = "benq-t31",
1051 [ALC262_SONY_ASSAMD] = "sony-assamd",
1052 [ALC262_TOSHIBA_S06] = "toshiba-s06", 684 [ALC262_TOSHIBA_S06] = "toshiba-s06",
1053 [ALC262_TOSHIBA_RX1] = "toshiba-rx1", 685 [ALC262_TOSHIBA_RX1] = "toshiba-rx1",
1054 [ALC262_ULTRA] = "ultra", 686 [ALC262_ULTRA] = "ultra",
@@ -1061,41 +693,6 @@ static const char * const alc262_models[ALC262_MODEL_LAST] = {
1061static const struct snd_pci_quirk alc262_cfg_tbl[] = { 693static const struct snd_pci_quirk alc262_cfg_tbl[] = {
1062 SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO), 694 SND_PCI_QUIRK(0x1002, 0x437b, "Hippo", ALC262_HIPPO),
1063 SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC), 695 SND_PCI_QUIRK(0x1033, 0x8895, "NEC Versa S9100", ALC262_NEC),
1064 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1200, "HP xw series",
1065 ALC262_HP_BPC),
1066 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1300, "HP xw series",
1067 ALC262_HP_BPC),
1068 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1500, "HP z series",
1069 ALC262_HP_BPC),
1070 SND_PCI_QUIRK(0x103c, 0x170b, "HP Z200",
1071 ALC262_AUTO),
1072 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x1700, "HP xw series",
1073 ALC262_HP_BPC),
1074 SND_PCI_QUIRK(0x103c, 0x2800, "HP D7000", ALC262_HP_BPC_D7000_WL),
1075 SND_PCI_QUIRK(0x103c, 0x2801, "HP D7000", ALC262_HP_BPC_D7000_WF),
1076 SND_PCI_QUIRK(0x103c, 0x2802, "HP D7000", ALC262_HP_BPC_D7000_WL),
1077 SND_PCI_QUIRK(0x103c, 0x2803, "HP D7000", ALC262_HP_BPC_D7000_WF),
1078 SND_PCI_QUIRK(0x103c, 0x2804, "HP D7000", ALC262_HP_BPC_D7000_WL),
1079 SND_PCI_QUIRK(0x103c, 0x2805, "HP D7000", ALC262_HP_BPC_D7000_WF),
1080 SND_PCI_QUIRK(0x103c, 0x2806, "HP D7000", ALC262_HP_BPC_D7000_WL),
1081 SND_PCI_QUIRK(0x103c, 0x2807, "HP D7000", ALC262_HP_BPC_D7000_WF),
1082 SND_PCI_QUIRK(0x103c, 0x280c, "HP xw4400", ALC262_HP_BPC),
1083 SND_PCI_QUIRK(0x103c, 0x3014, "HP xw6400", ALC262_HP_BPC),
1084 SND_PCI_QUIRK(0x103c, 0x3015, "HP xw8400", ALC262_HP_BPC),
1085 SND_PCI_QUIRK(0x103c, 0x302f, "HP Thin Client T5735",
1086 ALC262_HP_TC_T5735),
1087 SND_PCI_QUIRK(0x103c, 0x2817, "HP RP5700", ALC262_HP_RP5700),
1088 SND_PCI_QUIRK(0x104d, 0x1f00, "Sony ASSAMD", ALC262_SONY_ASSAMD),
1089 SND_PCI_QUIRK(0x104d, 0x8203, "Sony UX-90", ALC262_HIPPO),
1090 SND_PCI_QUIRK(0x104d, 0x820f, "Sony ASSAMD", ALC262_SONY_ASSAMD),
1091 SND_PCI_QUIRK(0x104d, 0x9016, "Sony VAIO", ALC262_AUTO), /* dig-only */
1092 SND_PCI_QUIRK(0x104d, 0x9025, "Sony VAIO Z21MN", ALC262_TOSHIBA_S06),
1093 SND_PCI_QUIRK(0x104d, 0x9035, "Sony VAIO VGN-FW170J", ALC262_AUTO),
1094 SND_PCI_QUIRK(0x104d, 0x9047, "Sony VAIO Type G", ALC262_AUTO),
1095#if 0 /* disable the quirk since model=auto works better in recent versions */
1096 SND_PCI_QUIRK_MASK(0x104d, 0xff00, 0x9000, "Sony VAIO",
1097 ALC262_SONY_ASSAMD),
1098#endif
1099 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1", 696 SND_PCI_QUIRK(0x1179, 0x0001, "Toshiba dynabook SS RX1",
1100 ALC262_TOSHIBA_RX1), 697 ALC262_TOSHIBA_RX1),
1101 SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06), 698 SND_PCI_QUIRK(0x1179, 0xff7b, "Toshiba S06", ALC262_TOSHIBA_S06),
@@ -1166,68 +763,6 @@ static const struct alc_config_preset alc262_presets[] = {
1166 .setup = alc262_fujitsu_setup, 763 .setup = alc262_fujitsu_setup,
1167 .init_hook = alc_inithook, 764 .init_hook = alc_inithook,
1168 }, 765 },
1169 [ALC262_HP_BPC] = {
1170 .mixers = { alc262_HP_BPC_mixer },
1171 .init_verbs = { alc262_HP_BPC_init_verbs },
1172 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
1173 .dac_nids = alc262_dac_nids,
1174 .hp_nid = 0x03,
1175 .num_channel_mode = ARRAY_SIZE(alc262_modes),
1176 .channel_mode = alc262_modes,
1177 .input_mux = &alc262_HP_capture_source,
1178 .unsol_event = alc_sku_unsol_event,
1179 .setup = alc262_hp_bpc_setup,
1180 .init_hook = alc_inithook,
1181 },
1182 [ALC262_HP_BPC_D7000_WF] = {
1183 .mixers = { alc262_HP_BPC_WildWest_mixer },
1184 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
1185 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
1186 .dac_nids = alc262_dac_nids,
1187 .hp_nid = 0x03,
1188 .num_channel_mode = ARRAY_SIZE(alc262_modes),
1189 .channel_mode = alc262_modes,
1190 .input_mux = &alc262_HP_D7000_capture_source,
1191 .unsol_event = alc_sku_unsol_event,
1192 .setup = alc262_hp_wildwest_setup,
1193 .init_hook = alc_inithook,
1194 },
1195 [ALC262_HP_BPC_D7000_WL] = {
1196 .mixers = { alc262_HP_BPC_WildWest_mixer,
1197 alc262_HP_BPC_WildWest_option_mixer },
1198 .init_verbs = { alc262_HP_BPC_WildWest_init_verbs },
1199 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
1200 .dac_nids = alc262_dac_nids,
1201 .hp_nid = 0x03,
1202 .num_channel_mode = ARRAY_SIZE(alc262_modes),
1203 .channel_mode = alc262_modes,
1204 .input_mux = &alc262_HP_D7000_capture_source,
1205 .unsol_event = alc_sku_unsol_event,
1206 .setup = alc262_hp_wildwest_setup,
1207 .init_hook = alc_inithook,
1208 },
1209 [ALC262_HP_TC_T5735] = {
1210 .mixers = { alc262_hp_t5735_mixer },
1211 .init_verbs = { alc262_init_verbs, alc262_hp_t5735_verbs },
1212 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
1213 .dac_nids = alc262_dac_nids,
1214 .hp_nid = 0x03,
1215 .num_channel_mode = ARRAY_SIZE(alc262_modes),
1216 .channel_mode = alc262_modes,
1217 .input_mux = &alc262_capture_source,
1218 .unsol_event = alc_sku_unsol_event,
1219 .setup = alc262_hp_t5735_setup,
1220 .init_hook = alc_inithook,
1221 },
1222 [ALC262_HP_RP5700] = {
1223 .mixers = { alc262_hp_rp5700_mixer },
1224 .init_verbs = { alc262_init_verbs, alc262_hp_rp5700_verbs },
1225 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
1226 .dac_nids = alc262_dac_nids,
1227 .num_channel_mode = ARRAY_SIZE(alc262_modes),
1228 .channel_mode = alc262_modes,
1229 .input_mux = &alc262_hp_rp5700_capture_source,
1230 },
1231 [ALC262_BENQ_ED8] = { 766 [ALC262_BENQ_ED8] = {
1232 .mixers = { alc262_base_mixer }, 767 .mixers = { alc262_base_mixer },
1233 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs }, 768 .init_verbs = { alc262_init_verbs, alc262_EAPD_verbs },
@@ -1238,19 +773,6 @@ static const struct alc_config_preset alc262_presets[] = {
1238 .channel_mode = alc262_modes, 773 .channel_mode = alc262_modes,
1239 .input_mux = &alc262_capture_source, 774 .input_mux = &alc262_capture_source,
1240 }, 775 },
1241 [ALC262_SONY_ASSAMD] = {
1242 .mixers = { alc262_sony_mixer },
1243 .init_verbs = { alc262_init_verbs, alc262_sony_unsol_verbs},
1244 .num_dacs = ARRAY_SIZE(alc262_dac_nids),
1245 .dac_nids = alc262_dac_nids,
1246 .hp_nid = 0x02,
1247 .num_channel_mode = ARRAY_SIZE(alc262_modes),
1248 .channel_mode = alc262_modes,
1249 .input_mux = &alc262_capture_source,
1250 .unsol_event = alc_sku_unsol_event,
1251 .setup = alc262_hippo_setup,
1252 .init_hook = alc_inithook,
1253 },
1254 [ALC262_BENQ_T31] = { 776 [ALC262_BENQ_T31] = {
1255 .mixers = { alc262_benq_t31_mixer }, 777 .mixers = { alc262_benq_t31_mixer },
1256 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs, 778 .init_verbs = { alc262_init_verbs, alc262_benq_t31_EAPD_verbs,
diff --git a/sound/pci/hda/alc268_quirks.c b/sound/pci/hda/alc268_quirks.c
deleted file mode 100644
index be58bf2f3aec..000000000000
--- a/sound/pci/hda/alc268_quirks.c
+++ /dev/null
@@ -1,636 +0,0 @@
1/*
2 * ALC267/ALC268 quirk models
3 * included by patch_realtek.c
4 */
5
6/* ALC268 models */
7enum {
8 ALC268_AUTO,
9 ALC267_QUANTA_IL1,
10 ALC268_3ST,
11 ALC268_TOSHIBA,
12 ALC268_ACER,
13 ALC268_ACER_DMIC,
14 ALC268_ACER_ASPIRE_ONE,
15 ALC268_DELL,
16 ALC268_ZEPTO,
17#ifdef CONFIG_SND_DEBUG
18 ALC268_TEST,
19#endif
20 ALC268_MODEL_LAST /* last tag */
21};
22
23/*
24 * ALC268 channel source setting (2 channel)
25 */
26#define ALC268_DIGOUT_NID ALC880_DIGOUT_NID
27#define alc268_modes alc260_modes
28
29static const hda_nid_t alc268_dac_nids[2] = {
30 /* front, hp */
31 0x02, 0x03
32};
33
34static const hda_nid_t alc268_adc_nids[2] = {
35 /* ADC0-1 */
36 0x08, 0x07
37};
38
39static const hda_nid_t alc268_adc_nids_alt[1] = {
40 /* ADC0 */
41 0x08
42};
43
44static const hda_nid_t alc268_capsrc_nids[2] = { 0x23, 0x24 };
45
46static const struct snd_kcontrol_new alc268_base_mixer[] = {
47 /* output mixer control */
48 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
49 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
50 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
51 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
52 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
53 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
54 HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
55 { }
56};
57
58static const struct snd_kcontrol_new alc268_toshiba_mixer[] = {
59 /* output mixer control */
60 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
61 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
62 ALC262_HIPPO_MASTER_SWITCH,
63 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
64 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
65 HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
66 { }
67};
68
69static const struct hda_verb alc268_eapd_verbs[] = {
70 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
71 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
72 { }
73};
74
75/* Toshiba specific */
76static const struct hda_verb alc268_toshiba_verbs[] = {
77 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
78 { } /* end */
79};
80
81/* Acer specific */
82/* bind volumes of both NID 0x02 and 0x03 */
83static const struct hda_bind_ctls alc268_acer_bind_master_vol = {
84 .ops = &snd_hda_bind_vol,
85 .values = {
86 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
87 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
88 0
89 },
90};
91
92static void alc268_acer_setup(struct hda_codec *codec)
93{
94 struct alc_spec *spec = codec->spec;
95
96 spec->autocfg.hp_pins[0] = 0x14;
97 spec->autocfg.speaker_pins[0] = 0x15;
98 spec->automute = 1;
99 spec->automute_mode = ALC_AUTOMUTE_AMP;
100}
101
102#define alc268_acer_master_sw_get alc262_hp_master_sw_get
103#define alc268_acer_master_sw_put alc262_hp_master_sw_put
104
105static const struct snd_kcontrol_new alc268_acer_aspire_one_mixer[] = {
106 /* output mixer control */
107 HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
108 {
109 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
110 .name = "Master Playback Switch",
111 .subdevice = HDA_SUBDEV_NID_FLAG | 0x15,
112 .info = snd_ctl_boolean_mono_info,
113 .get = alc268_acer_master_sw_get,
114 .put = alc268_acer_master_sw_put,
115 },
116 HDA_CODEC_VOLUME("Mic Boost Capture Volume", 0x18, 0, HDA_INPUT),
117 { }
118};
119
120static const struct snd_kcontrol_new alc268_acer_mixer[] = {
121 /* output mixer control */
122 HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
123 {
124 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
125 .name = "Master Playback Switch",
126 .subdevice = HDA_SUBDEV_NID_FLAG | 0x14,
127 .info = snd_ctl_boolean_mono_info,
128 .get = alc268_acer_master_sw_get,
129 .put = alc268_acer_master_sw_put,
130 },
131 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
132 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
133 HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
134 { }
135};
136
137static const struct snd_kcontrol_new alc268_acer_dmic_mixer[] = {
138 /* output mixer control */
139 HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
140 {
141 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
142 .name = "Master Playback Switch",
143 .subdevice = HDA_SUBDEV_NID_FLAG | 0x14,
144 .info = snd_ctl_boolean_mono_info,
145 .get = alc268_acer_master_sw_get,
146 .put = alc268_acer_master_sw_put,
147 },
148 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
149 HDA_CODEC_VOLUME("Line In Boost Volume", 0x1a, 0, HDA_INPUT),
150 { }
151};
152
153static const struct hda_verb alc268_acer_aspire_one_verbs[] = {
154 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
155 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
156 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
157 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
158 {0x23, AC_VERB_SET_CONNECT_SEL, 0x06},
159 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, 0xa017},
160 { }
161};
162
163static const struct hda_verb alc268_acer_verbs[] = {
164 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN}, /* internal dmic? */
165 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
166 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
167 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
168 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
169 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
170 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
171 { }
172};
173
174/* unsolicited event for HP jack sensing */
175#define alc268_toshiba_setup alc262_hippo_setup
176
177static void alc268_acer_lc_setup(struct hda_codec *codec)
178{
179 struct alc_spec *spec = codec->spec;
180 spec->autocfg.hp_pins[0] = 0x15;
181 spec->autocfg.speaker_pins[0] = 0x14;
182 spec->automute = 1;
183 spec->automute_mode = ALC_AUTOMUTE_AMP;
184 spec->ext_mic_pin = 0x18;
185 spec->int_mic_pin = 0x12;
186 spec->auto_mic = 1;
187}
188
189static const struct snd_kcontrol_new alc268_dell_mixer[] = {
190 /* output mixer control */
191 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
192 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
193 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
194 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
195 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
196 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
197 { }
198};
199
200static const struct hda_verb alc268_dell_verbs[] = {
201 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
202 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
203 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
204 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_MIC_EVENT | AC_USRSP_EN},
205 { }
206};
207
208/* mute/unmute internal speaker according to the hp jack and mute state */
209static void alc268_dell_setup(struct hda_codec *codec)
210{
211 struct alc_spec *spec = codec->spec;
212
213 spec->autocfg.hp_pins[0] = 0x15;
214 spec->autocfg.speaker_pins[0] = 0x14;
215 spec->ext_mic_pin = 0x18;
216 spec->int_mic_pin = 0x19;
217 spec->auto_mic = 1;
218 spec->automute = 1;
219 spec->automute_mode = ALC_AUTOMUTE_PIN;
220}
221
222static const struct snd_kcontrol_new alc267_quanta_il1_mixer[] = {
223 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x2, 0x0, HDA_OUTPUT),
224 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
225 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x3, 0x0, HDA_OUTPUT),
226 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
227 HDA_CODEC_VOLUME("Mic Capture Volume", 0x23, 0x0, HDA_OUTPUT),
228 HDA_BIND_MUTE("Mic Capture Switch", 0x23, 2, HDA_OUTPUT),
229 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
230 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
231 { }
232};
233
234static const struct hda_verb alc267_quanta_il1_verbs[] = {
235 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
236 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_MIC_EVENT | AC_USRSP_EN},
237 { }
238};
239
240static void alc267_quanta_il1_setup(struct hda_codec *codec)
241{
242 struct alc_spec *spec = codec->spec;
243 spec->autocfg.hp_pins[0] = 0x15;
244 spec->autocfg.speaker_pins[0] = 0x14;
245 spec->ext_mic_pin = 0x18;
246 spec->int_mic_pin = 0x19;
247 spec->auto_mic = 1;
248 spec->automute = 1;
249 spec->automute_mode = ALC_AUTOMUTE_PIN;
250}
251
252/*
253 * generic initialization of ADC, input mixers and output mixers
254 */
255static const struct hda_verb alc268_base_init_verbs[] = {
256 /* Unmute DAC0-1 and set vol = 0 */
257 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
258 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
259
260 /*
261 * Set up output mixers (0x0c - 0x0e)
262 */
263 /* set vol=0 to output mixers */
264 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
265 {0x0e, AC_VERB_SET_CONNECT_SEL, 0x00},
266
267 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
268 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
269
270 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
271 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0},
272 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40},
273 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
274 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
275 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
276 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
277 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
278
279 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
280 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
281 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
282 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
283 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
284
285 /* set PCBEEP vol = 0, mute connections */
286 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
287 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
288 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
289
290 /* Unmute Selector 23h,24h and set the default input to mic-in */
291
292 {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
293 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
294 {0x24, AC_VERB_SET_CONNECT_SEL, 0x00},
295 {0x24, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
296
297 { }
298};
299
300/* only for model=test */
301#ifdef CONFIG_SND_DEBUG
302/*
303 * generic initialization of ADC, input mixers and output mixers
304 */
305static const struct hda_verb alc268_volume_init_verbs[] = {
306 /* set output DAC */
307 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
308 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
309
310 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
311 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24},
312 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
313 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
314 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20},
315
316 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
317 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
318 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
319
320 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
321 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
322 { }
323};
324#endif /* CONFIG_SND_DEBUG */
325
326static const struct snd_kcontrol_new alc268_capture_nosrc_mixer[] = {
327 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
328 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
329 { } /* end */
330};
331
332static const struct snd_kcontrol_new alc268_capture_alt_mixer[] = {
333 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
334 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
335 _DEFINE_CAPSRC(1),
336 { } /* end */
337};
338
339static const struct snd_kcontrol_new alc268_capture_mixer[] = {
340 HDA_CODEC_VOLUME("Capture Volume", 0x23, 0x0, HDA_OUTPUT),
341 HDA_CODEC_MUTE("Capture Switch", 0x23, 0x0, HDA_OUTPUT),
342 HDA_CODEC_VOLUME_IDX("Capture Volume", 1, 0x24, 0x0, HDA_OUTPUT),
343 HDA_CODEC_MUTE_IDX("Capture Switch", 1, 0x24, 0x0, HDA_OUTPUT),
344 _DEFINE_CAPSRC(2),
345 { } /* end */
346};
347
348static const struct hda_input_mux alc268_capture_source = {
349 .num_items = 4,
350 .items = {
351 { "Mic", 0x0 },
352 { "Front Mic", 0x1 },
353 { "Line", 0x2 },
354 { "CD", 0x3 },
355 },
356};
357
358static const struct hda_input_mux alc268_acer_capture_source = {
359 .num_items = 3,
360 .items = {
361 { "Mic", 0x0 },
362 { "Internal Mic", 0x1 },
363 { "Line", 0x2 },
364 },
365};
366
367static const struct hda_input_mux alc268_acer_dmic_capture_source = {
368 .num_items = 3,
369 .items = {
370 { "Mic", 0x0 },
371 { "Internal Mic", 0x6 },
372 { "Line", 0x2 },
373 },
374};
375
376#ifdef CONFIG_SND_DEBUG
377static const struct snd_kcontrol_new alc268_test_mixer[] = {
378 /* Volume widgets */
379 HDA_CODEC_VOLUME("LOUT1 Playback Volume", 0x02, 0x0, HDA_OUTPUT),
380 HDA_CODEC_VOLUME("LOUT2 Playback Volume", 0x03, 0x0, HDA_OUTPUT),
381 HDA_BIND_MUTE_MONO("Mono sum Playback Switch", 0x0e, 1, 2, HDA_INPUT),
382 HDA_BIND_MUTE("LINE-OUT sum Playback Switch", 0x0f, 2, HDA_INPUT),
383 HDA_BIND_MUTE("HP-OUT sum Playback Switch", 0x10, 2, HDA_INPUT),
384 HDA_BIND_MUTE("LINE-OUT Playback Switch", 0x14, 2, HDA_OUTPUT),
385 HDA_BIND_MUTE("HP-OUT Playback Switch", 0x15, 2, HDA_OUTPUT),
386 HDA_BIND_MUTE("Mono Playback Switch", 0x16, 2, HDA_OUTPUT),
387 HDA_CODEC_VOLUME("MIC1 Capture Volume", 0x18, 0x0, HDA_INPUT),
388 HDA_BIND_MUTE("MIC1 Capture Switch", 0x18, 2, HDA_OUTPUT),
389 HDA_CODEC_VOLUME("MIC2 Capture Volume", 0x19, 0x0, HDA_INPUT),
390 HDA_CODEC_VOLUME("LINE1 Capture Volume", 0x1a, 0x0, HDA_INPUT),
391 HDA_BIND_MUTE("LINE1 Capture Switch", 0x1a, 2, HDA_OUTPUT),
392 /* The below appears problematic on some hardwares */
393 /*HDA_CODEC_VOLUME("PCBEEP Playback Volume", 0x1d, 0x0, HDA_INPUT),*/
394 HDA_CODEC_VOLUME("PCM-IN1 Capture Volume", 0x23, 0x0, HDA_OUTPUT),
395 HDA_BIND_MUTE("PCM-IN1 Capture Switch", 0x23, 2, HDA_OUTPUT),
396 HDA_CODEC_VOLUME("PCM-IN2 Capture Volume", 0x24, 0x0, HDA_OUTPUT),
397 HDA_BIND_MUTE("PCM-IN2 Capture Switch", 0x24, 2, HDA_OUTPUT),
398
399 /* Modes for retasking pin widgets */
400 ALC_PIN_MODE("LINE-OUT pin mode", 0x14, ALC_PIN_DIR_INOUT),
401 ALC_PIN_MODE("HP-OUT pin mode", 0x15, ALC_PIN_DIR_INOUT),
402 ALC_PIN_MODE("MIC1 pin mode", 0x18, ALC_PIN_DIR_INOUT),
403 ALC_PIN_MODE("LINE1 pin mode", 0x1a, ALC_PIN_DIR_INOUT),
404
405 /* Controls for GPIO pins, assuming they are configured as outputs */
406 ALC_GPIO_DATA_SWITCH("GPIO pin 0", 0x01, 0x01),
407 ALC_GPIO_DATA_SWITCH("GPIO pin 1", 0x01, 0x02),
408 ALC_GPIO_DATA_SWITCH("GPIO pin 2", 0x01, 0x04),
409 ALC_GPIO_DATA_SWITCH("GPIO pin 3", 0x01, 0x08),
410
411 /* Switches to allow the digital SPDIF output pin to be enabled.
412 * The ALC268 does not have an SPDIF input.
413 */
414 ALC_SPDIF_CTRL_SWITCH("SPDIF Playback Switch", 0x06, 0x01),
415
416 /* A switch allowing EAPD to be enabled. Some laptops seem to use
417 * this output to turn on an external amplifier.
418 */
419 ALC_EAPD_CTRL_SWITCH("LINE-OUT EAPD Enable Switch", 0x0f, 0x02),
420 ALC_EAPD_CTRL_SWITCH("HP-OUT EAPD Enable Switch", 0x10, 0x02),
421
422 { } /* end */
423};
424#endif
425
426/*
427 * configuration and preset
428 */
429static const char * const alc268_models[ALC268_MODEL_LAST] = {
430 [ALC267_QUANTA_IL1] = "quanta-il1",
431 [ALC268_3ST] = "3stack",
432 [ALC268_TOSHIBA] = "toshiba",
433 [ALC268_ACER] = "acer",
434 [ALC268_ACER_DMIC] = "acer-dmic",
435 [ALC268_ACER_ASPIRE_ONE] = "acer-aspire",
436 [ALC268_DELL] = "dell",
437 [ALC268_ZEPTO] = "zepto",
438#ifdef CONFIG_SND_DEBUG
439 [ALC268_TEST] = "test",
440#endif
441 [ALC268_AUTO] = "auto",
442};
443
444static const struct snd_pci_quirk alc268_cfg_tbl[] = {
445 SND_PCI_QUIRK(0x1025, 0x011e, "Acer Aspire 5720z", ALC268_ACER),
446 SND_PCI_QUIRK(0x1025, 0x0126, "Acer", ALC268_ACER),
447 SND_PCI_QUIRK(0x1025, 0x012e, "Acer Aspire 5310", ALC268_ACER),
448 SND_PCI_QUIRK(0x1025, 0x0130, "Acer Extensa 5210", ALC268_ACER),
449 SND_PCI_QUIRK(0x1025, 0x0136, "Acer Aspire 5315", ALC268_ACER),
450 SND_PCI_QUIRK(0x1025, 0x015b, "Acer Aspire One",
451 ALC268_ACER_ASPIRE_ONE),
452 SND_PCI_QUIRK(0x1028, 0x0253, "Dell OEM", ALC268_DELL),
453 SND_PCI_QUIRK(0x1028, 0x02b0, "Dell Inspiron 910", ALC268_AUTO),
454 SND_PCI_QUIRK_MASK(0x1028, 0xfff0, 0x02b0,
455 "Dell Inspiron Mini9/Vostro A90", ALC268_DELL),
456 /* almost compatible with toshiba but with optional digital outs;
457 * auto-probing seems working fine
458 */
459 SND_PCI_QUIRK_MASK(0x103c, 0xff00, 0x3000, "HP TX25xx series",
460 ALC268_AUTO),
461 SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC268_3ST),
462 SND_PCI_QUIRK(0x1170, 0x0040, "ZEPTO", ALC268_ZEPTO),
463 SND_PCI_QUIRK(0x14c0, 0x0025, "COMPAL IFL90/JFL-92", ALC268_TOSHIBA),
464 SND_PCI_QUIRK(0x152d, 0x0771, "Quanta IL1", ALC267_QUANTA_IL1),
465 {}
466};
467
468/* Toshiba laptops have no unique PCI SSID but only codec SSID */
469static const struct snd_pci_quirk alc268_ssid_cfg_tbl[] = {
470 SND_PCI_QUIRK(0x1179, 0xff0a, "TOSHIBA X-200", ALC268_AUTO),
471 SND_PCI_QUIRK(0x1179, 0xff0e, "TOSHIBA X-200 HDMI", ALC268_AUTO),
472 SND_PCI_QUIRK_MASK(0x1179, 0xff00, 0xff00, "TOSHIBA A/Lx05",
473 ALC268_TOSHIBA),
474 {}
475};
476
477static const struct alc_config_preset alc268_presets[] = {
478 [ALC267_QUANTA_IL1] = {
479 .mixers = { alc267_quanta_il1_mixer, alc268_beep_mixer,
480 alc268_capture_nosrc_mixer },
481 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
482 alc267_quanta_il1_verbs },
483 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
484 .dac_nids = alc268_dac_nids,
485 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
486 .adc_nids = alc268_adc_nids_alt,
487 .hp_nid = 0x03,
488 .num_channel_mode = ARRAY_SIZE(alc268_modes),
489 .channel_mode = alc268_modes,
490 .unsol_event = alc_sku_unsol_event,
491 .setup = alc267_quanta_il1_setup,
492 .init_hook = alc_inithook,
493 },
494 [ALC268_3ST] = {
495 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
496 alc268_beep_mixer },
497 .init_verbs = { alc268_base_init_verbs },
498 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
499 .dac_nids = alc268_dac_nids,
500 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
501 .adc_nids = alc268_adc_nids_alt,
502 .capsrc_nids = alc268_capsrc_nids,
503 .hp_nid = 0x03,
504 .dig_out_nid = ALC268_DIGOUT_NID,
505 .num_channel_mode = ARRAY_SIZE(alc268_modes),
506 .channel_mode = alc268_modes,
507 .input_mux = &alc268_capture_source,
508 },
509 [ALC268_TOSHIBA] = {
510 .mixers = { alc268_toshiba_mixer, alc268_capture_alt_mixer,
511 alc268_beep_mixer },
512 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
513 alc268_toshiba_verbs },
514 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
515 .dac_nids = alc268_dac_nids,
516 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
517 .adc_nids = alc268_adc_nids_alt,
518 .capsrc_nids = alc268_capsrc_nids,
519 .hp_nid = 0x03,
520 .num_channel_mode = ARRAY_SIZE(alc268_modes),
521 .channel_mode = alc268_modes,
522 .input_mux = &alc268_capture_source,
523 .unsol_event = alc_sku_unsol_event,
524 .setup = alc268_toshiba_setup,
525 .init_hook = alc_inithook,
526 },
527 [ALC268_ACER] = {
528 .mixers = { alc268_acer_mixer, alc268_capture_alt_mixer,
529 alc268_beep_mixer },
530 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
531 alc268_acer_verbs },
532 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
533 .dac_nids = alc268_dac_nids,
534 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
535 .adc_nids = alc268_adc_nids_alt,
536 .capsrc_nids = alc268_capsrc_nids,
537 .hp_nid = 0x02,
538 .num_channel_mode = ARRAY_SIZE(alc268_modes),
539 .channel_mode = alc268_modes,
540 .input_mux = &alc268_acer_capture_source,
541 .unsol_event = alc_sku_unsol_event,
542 .setup = alc268_acer_setup,
543 .init_hook = alc_inithook,
544 },
545 [ALC268_ACER_DMIC] = {
546 .mixers = { alc268_acer_dmic_mixer, alc268_capture_alt_mixer,
547 alc268_beep_mixer },
548 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
549 alc268_acer_verbs },
550 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
551 .dac_nids = alc268_dac_nids,
552 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
553 .adc_nids = alc268_adc_nids_alt,
554 .capsrc_nids = alc268_capsrc_nids,
555 .hp_nid = 0x02,
556 .num_channel_mode = ARRAY_SIZE(alc268_modes),
557 .channel_mode = alc268_modes,
558 .input_mux = &alc268_acer_dmic_capture_source,
559 .unsol_event = alc_sku_unsol_event,
560 .setup = alc268_acer_setup,
561 .init_hook = alc_inithook,
562 },
563 [ALC268_ACER_ASPIRE_ONE] = {
564 .mixers = { alc268_acer_aspire_one_mixer,
565 alc268_beep_mixer,
566 alc268_capture_nosrc_mixer },
567 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
568 alc268_acer_aspire_one_verbs },
569 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
570 .dac_nids = alc268_dac_nids,
571 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
572 .adc_nids = alc268_adc_nids_alt,
573 .capsrc_nids = alc268_capsrc_nids,
574 .hp_nid = 0x03,
575 .num_channel_mode = ARRAY_SIZE(alc268_modes),
576 .channel_mode = alc268_modes,
577 .unsol_event = alc_sku_unsol_event,
578 .setup = alc268_acer_lc_setup,
579 .init_hook = alc_inithook,
580 },
581 [ALC268_DELL] = {
582 .mixers = { alc268_dell_mixer, alc268_beep_mixer,
583 alc268_capture_nosrc_mixer },
584 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
585 alc268_dell_verbs },
586 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
587 .dac_nids = alc268_dac_nids,
588 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
589 .adc_nids = alc268_adc_nids_alt,
590 .capsrc_nids = alc268_capsrc_nids,
591 .hp_nid = 0x02,
592 .num_channel_mode = ARRAY_SIZE(alc268_modes),
593 .channel_mode = alc268_modes,
594 .unsol_event = alc_sku_unsol_event,
595 .setup = alc268_dell_setup,
596 .init_hook = alc_inithook,
597 },
598 [ALC268_ZEPTO] = {
599 .mixers = { alc268_base_mixer, alc268_capture_alt_mixer,
600 alc268_beep_mixer },
601 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
602 alc268_toshiba_verbs },
603 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
604 .dac_nids = alc268_dac_nids,
605 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
606 .adc_nids = alc268_adc_nids_alt,
607 .capsrc_nids = alc268_capsrc_nids,
608 .hp_nid = 0x03,
609 .dig_out_nid = ALC268_DIGOUT_NID,
610 .num_channel_mode = ARRAY_SIZE(alc268_modes),
611 .channel_mode = alc268_modes,
612 .input_mux = &alc268_capture_source,
613 .unsol_event = alc_sku_unsol_event,
614 .setup = alc268_toshiba_setup,
615 .init_hook = alc_inithook,
616 },
617#ifdef CONFIG_SND_DEBUG
618 [ALC268_TEST] = {
619 .mixers = { alc268_test_mixer, alc268_capture_mixer },
620 .init_verbs = { alc268_base_init_verbs, alc268_eapd_verbs,
621 alc268_volume_init_verbs,
622 alc268_beep_init_verbs },
623 .num_dacs = ARRAY_SIZE(alc268_dac_nids),
624 .dac_nids = alc268_dac_nids,
625 .num_adc_nids = ARRAY_SIZE(alc268_adc_nids_alt),
626 .adc_nids = alc268_adc_nids_alt,
627 .capsrc_nids = alc268_capsrc_nids,
628 .hp_nid = 0x03,
629 .dig_out_nid = ALC268_DIGOUT_NID,
630 .num_channel_mode = ARRAY_SIZE(alc268_modes),
631 .channel_mode = alc268_modes,
632 .input_mux = &alc268_capture_source,
633 },
634#endif
635};
636
diff --git a/sound/pci/hda/alc269_quirks.c b/sound/pci/hda/alc269_quirks.c
deleted file mode 100644
index 14fdcf29b154..000000000000
--- a/sound/pci/hda/alc269_quirks.c
+++ /dev/null
@@ -1,681 +0,0 @@
1/*
2 * ALC269/ALC270/ALC275/ALC276 quirk models
3 * included by patch_realtek.c
4 */
5
6/* ALC269 models */
7enum {
8 ALC269_AUTO,
9 ALC269_BASIC,
10 ALC269_QUANTA_FL1,
11 ALC269_AMIC,
12 ALC269_DMIC,
13 ALC269VB_AMIC,
14 ALC269VB_DMIC,
15 ALC269_FUJITSU,
16 ALC269_LIFEBOOK,
17 ALC271_ACER,
18 ALC269_MODEL_LAST /* last tag */
19};
20
21/*
22 * ALC269 channel source setting (2 channel)
23 */
24#define ALC269_DIGOUT_NID ALC880_DIGOUT_NID
25
26#define alc269_dac_nids alc260_dac_nids
27
28static const hda_nid_t alc269_adc_nids[1] = {
29 /* ADC1 */
30 0x08,
31};
32
33static const hda_nid_t alc269_capsrc_nids[1] = {
34 0x23,
35};
36
37static const hda_nid_t alc269vb_adc_nids[1] = {
38 /* ADC1 */
39 0x09,
40};
41
42static const hda_nid_t alc269vb_capsrc_nids[1] = {
43 0x22,
44};
45
46#define alc269_modes alc260_modes
47#define alc269_capture_source alc880_lg_lw_capture_source
48
49static const struct snd_kcontrol_new alc269_base_mixer[] = {
50 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
51 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
52 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
53 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
54 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
55 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
56 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
57 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
58 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
59 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
60 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
61 HDA_CODEC_MUTE_MONO("Mono Playback Switch", 0x16, 2, 0x0, HDA_OUTPUT),
62 { } /* end */
63};
64
65static const struct snd_kcontrol_new alc269_quanta_fl1_mixer[] = {
66 /* output mixer control */
67 HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
68 {
69 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
70 .name = "Master Playback Switch",
71 .subdevice = HDA_SUBDEV_AMP_FLAG,
72 .info = snd_hda_mixer_amp_switch_info,
73 .get = snd_hda_mixer_amp_switch_get,
74 .put = alc268_acer_master_sw_put,
75 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
76 },
77 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
78 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
79 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
80 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
81 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
82 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
83 { }
84};
85
86static const struct snd_kcontrol_new alc269_lifebook_mixer[] = {
87 /* output mixer control */
88 HDA_BIND_VOL("Master Playback Volume", &alc268_acer_bind_master_vol),
89 {
90 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
91 .name = "Master Playback Switch",
92 .subdevice = HDA_SUBDEV_AMP_FLAG,
93 .info = snd_hda_mixer_amp_switch_info,
94 .get = snd_hda_mixer_amp_switch_get,
95 .put = alc268_acer_master_sw_put,
96 .private_value = HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
97 },
98 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
99 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
100 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
101 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x01, HDA_INPUT),
102 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x01, HDA_INPUT),
103 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
104 HDA_CODEC_VOLUME("Dock Mic Playback Volume", 0x0b, 0x03, HDA_INPUT),
105 HDA_CODEC_MUTE("Dock Mic Playback Switch", 0x0b, 0x03, HDA_INPUT),
106 HDA_CODEC_VOLUME("Dock Mic Boost Volume", 0x1b, 0, HDA_INPUT),
107 { }
108};
109
110static const struct snd_kcontrol_new alc269_laptop_mixer[] = {
111 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
112 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
113 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
114 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
115 { } /* end */
116};
117
118static const struct snd_kcontrol_new alc269vb_laptop_mixer[] = {
119 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
120 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
121 HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
122 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
123 { } /* end */
124};
125
126static const struct snd_kcontrol_new alc269_asus_mixer[] = {
127 HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
128 HDA_CODEC_MUTE("Master Playback Switch", 0x0c, 0x0, HDA_INPUT),
129 { } /* end */
130};
131
132/* capture mixer elements */
133static const struct snd_kcontrol_new alc269_laptop_analog_capture_mixer[] = {
134 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
135 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
136 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
137 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
138 { } /* end */
139};
140
141static const struct snd_kcontrol_new alc269_laptop_digital_capture_mixer[] = {
142 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
143 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
144 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
145 { } /* end */
146};
147
148static const struct snd_kcontrol_new alc269vb_laptop_analog_capture_mixer[] = {
149 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
150 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
151 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
152 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
153 { } /* end */
154};
155
156static const struct snd_kcontrol_new alc269vb_laptop_digital_capture_mixer[] = {
157 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
158 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
159 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
160 { } /* end */
161};
162
163/* FSC amilo */
164#define alc269_fujitsu_mixer alc269_laptop_mixer
165
166static const struct hda_verb alc269_quanta_fl1_verbs[] = {
167 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
168 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
169 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
170 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
171 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
172 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
173 { }
174};
175
176static const struct hda_verb alc269_lifebook_verbs[] = {
177 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
178 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x01},
179 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
180 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
181 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
182 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
183 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
184 {0x1a, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
185 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
186 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
187 { }
188};
189
190/* toggle speaker-output according to the hp-jack state */
191static void alc269_quanta_fl1_speaker_automute(struct hda_codec *codec)
192{
193 alc_hp_automute(codec);
194
195 snd_hda_codec_write(codec, 0x20, 0,
196 AC_VERB_SET_COEF_INDEX, 0x0c);
197 snd_hda_codec_write(codec, 0x20, 0,
198 AC_VERB_SET_PROC_COEF, 0x680);
199
200 snd_hda_codec_write(codec, 0x20, 0,
201 AC_VERB_SET_COEF_INDEX, 0x0c);
202 snd_hda_codec_write(codec, 0x20, 0,
203 AC_VERB_SET_PROC_COEF, 0x480);
204}
205
206#define alc269_lifebook_speaker_automute \
207 alc269_quanta_fl1_speaker_automute
208
209static void alc269_lifebook_mic_autoswitch(struct hda_codec *codec)
210{
211 unsigned int present_laptop;
212 unsigned int present_dock;
213
214 present_laptop = snd_hda_jack_detect(codec, 0x18);
215 present_dock = snd_hda_jack_detect(codec, 0x1b);
216
217 /* Laptop mic port overrides dock mic port, design decision */
218 if (present_dock)
219 snd_hda_codec_write(codec, 0x23, 0,
220 AC_VERB_SET_CONNECT_SEL, 0x3);
221 if (present_laptop)
222 snd_hda_codec_write(codec, 0x23, 0,
223 AC_VERB_SET_CONNECT_SEL, 0x0);
224 if (!present_dock && !present_laptop)
225 snd_hda_codec_write(codec, 0x23, 0,
226 AC_VERB_SET_CONNECT_SEL, 0x1);
227}
228
229static void alc269_quanta_fl1_unsol_event(struct hda_codec *codec,
230 unsigned int res)
231{
232 switch (res >> 26) {
233 case ALC_HP_EVENT:
234 alc269_quanta_fl1_speaker_automute(codec);
235 break;
236 case ALC_MIC_EVENT:
237 alc_mic_automute(codec);
238 break;
239 }
240}
241
242static void alc269_lifebook_unsol_event(struct hda_codec *codec,
243 unsigned int res)
244{
245 if ((res >> 26) == ALC_HP_EVENT)
246 alc269_lifebook_speaker_automute(codec);
247 if ((res >> 26) == ALC_MIC_EVENT)
248 alc269_lifebook_mic_autoswitch(codec);
249}
250
251static void alc269_quanta_fl1_setup(struct hda_codec *codec)
252{
253 struct alc_spec *spec = codec->spec;
254 spec->autocfg.hp_pins[0] = 0x15;
255 spec->autocfg.speaker_pins[0] = 0x14;
256 spec->automute_mixer_nid[0] = 0x0c;
257 spec->automute = 1;
258 spec->automute_mode = ALC_AUTOMUTE_MIXER;
259 spec->ext_mic_pin = 0x18;
260 spec->int_mic_pin = 0x19;
261 spec->auto_mic = 1;
262}
263
264static void alc269_quanta_fl1_init_hook(struct hda_codec *codec)
265{
266 alc269_quanta_fl1_speaker_automute(codec);
267 alc_mic_automute(codec);
268}
269
270static void alc269_lifebook_setup(struct hda_codec *codec)
271{
272 struct alc_spec *spec = codec->spec;
273 spec->autocfg.hp_pins[0] = 0x15;
274 spec->autocfg.hp_pins[1] = 0x1a;
275 spec->autocfg.speaker_pins[0] = 0x14;
276 spec->automute_mixer_nid[0] = 0x0c;
277 spec->automute = 1;
278 spec->automute_mode = ALC_AUTOMUTE_MIXER;
279}
280
281static void alc269_lifebook_init_hook(struct hda_codec *codec)
282{
283 alc269_lifebook_speaker_automute(codec);
284 alc269_lifebook_mic_autoswitch(codec);
285}
286
287static const struct hda_verb alc269_laptop_dmic_init_verbs[] = {
288 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
289 {0x23, AC_VERB_SET_CONNECT_SEL, 0x05},
290 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
291 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
292 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
293 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
294 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
295 {}
296};
297
298static const struct hda_verb alc269_laptop_amic_init_verbs[] = {
299 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
300 {0x23, AC_VERB_SET_CONNECT_SEL, 0x01},
301 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
302 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, (0x701b | (0x00 << 8))},
303 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
304 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
305 {}
306};
307
308static const struct hda_verb alc269vb_laptop_dmic_init_verbs[] = {
309 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},
310 {0x22, AC_VERB_SET_CONNECT_SEL, 0x06},
311 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
312 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
313 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
314 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
315 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
316 {}
317};
318
319static const struct hda_verb alc269vb_laptop_amic_init_verbs[] = {
320 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01},
321 {0x22, AC_VERB_SET_CONNECT_SEL, 0x01},
322 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, 0xb026 },
323 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, (0x7019 | (0x00 << 8))},
324 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
325 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
326 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
327 {}
328};
329
330static const struct hda_verb alc271_acer_dmic_verbs[] = {
331 {0x20, AC_VERB_SET_COEF_INDEX, 0x0d},
332 {0x20, AC_VERB_SET_PROC_COEF, 0x4000},
333 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
334 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
335 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
336 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
337 {0x21, AC_VERB_SET_CONNECT_SEL, 0x00},
338 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
339 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
340 {0x22, AC_VERB_SET_CONNECT_SEL, 6},
341 { }
342};
343
344static void alc269_laptop_amic_setup(struct hda_codec *codec)
345{
346 struct alc_spec *spec = codec->spec;
347 spec->autocfg.hp_pins[0] = 0x15;
348 spec->autocfg.speaker_pins[0] = 0x14;
349 spec->automute_mixer_nid[0] = 0x0c;
350 spec->automute = 1;
351 spec->automute_mode = ALC_AUTOMUTE_MIXER;
352 spec->ext_mic_pin = 0x18;
353 spec->int_mic_pin = 0x19;
354 spec->auto_mic = 1;
355}
356
357static void alc269_laptop_dmic_setup(struct hda_codec *codec)
358{
359 struct alc_spec *spec = codec->spec;
360 spec->autocfg.hp_pins[0] = 0x15;
361 spec->autocfg.speaker_pins[0] = 0x14;
362 spec->automute_mixer_nid[0] = 0x0c;
363 spec->automute = 1;
364 spec->automute_mode = ALC_AUTOMUTE_MIXER;
365 spec->ext_mic_pin = 0x18;
366 spec->int_mic_pin = 0x12;
367 spec->auto_mic = 1;
368}
369
370static void alc269vb_laptop_amic_setup(struct hda_codec *codec)
371{
372 struct alc_spec *spec = codec->spec;
373 spec->autocfg.hp_pins[0] = 0x21;
374 spec->autocfg.speaker_pins[0] = 0x14;
375 spec->automute_mixer_nid[0] = 0x0c;
376 spec->automute = 1;
377 spec->automute_mode = ALC_AUTOMUTE_MIXER;
378 spec->ext_mic_pin = 0x18;
379 spec->int_mic_pin = 0x19;
380 spec->auto_mic = 1;
381}
382
383static void alc269vb_laptop_dmic_setup(struct hda_codec *codec)
384{
385 struct alc_spec *spec = codec->spec;
386 spec->autocfg.hp_pins[0] = 0x21;
387 spec->autocfg.speaker_pins[0] = 0x14;
388 spec->automute_mixer_nid[0] = 0x0c;
389 spec->automute = 1;
390 spec->automute_mode = ALC_AUTOMUTE_MIXER;
391 spec->ext_mic_pin = 0x18;
392 spec->int_mic_pin = 0x12;
393 spec->auto_mic = 1;
394}
395
396/*
397 * generic initialization of ADC, input mixers and output mixers
398 */
399static const struct hda_verb alc269_init_verbs[] = {
400 /*
401 * Unmute ADC0 and set the default input to mic-in
402 */
403 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
404
405 /*
406 * Set up output mixers (0x02 - 0x03)
407 */
408 /* set vol=0 to output mixers */
409 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
410 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
411
412 /* set up input amps for analog loopback */
413 /* Amp Indices: DAC = 0, mixer = 1 */
414 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
415 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
416 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
417 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
418 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
419 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
420
421 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
422 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
423 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
424 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
425 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
426 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
427 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
428
429 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
430 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
431
432 /* FIXME: use Mux-type input source selection */
433 /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
434 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
435 {0x23, AC_VERB_SET_CONNECT_SEL, 0x00},
436
437 /* set EAPD */
438 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
439 { }
440};
441
442static const struct hda_verb alc269vb_init_verbs[] = {
443 /*
444 * Unmute ADC0 and set the default input to mic-in
445 */
446 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
447
448 /*
449 * Set up output mixers (0x02 - 0x03)
450 */
451 /* set vol=0 to output mixers */
452 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
453 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
454
455 /* set up input amps for analog loopback */
456 /* Amp Indices: DAC = 0, mixer = 1 */
457 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
458 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
459 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
460 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
461 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
462 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
463
464 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
465 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
466 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
467 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
468 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
469 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
470 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
471
472 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
473 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
474
475 /* FIXME: use Mux-type input source selection */
476 /* Mixer elements: 0x18, 19, 1a, 1b, 1d, 0b */
477 /* Input mixer1: unmute Mic, F-Mic, Line, CD inputs */
478 {0x22, AC_VERB_SET_CONNECT_SEL, 0x00},
479
480 /* set EAPD */
481 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
482 { }
483};
484
485/*
486 * configuration and preset
487 */
488static const char * const alc269_models[ALC269_MODEL_LAST] = {
489 [ALC269_BASIC] = "basic",
490 [ALC269_QUANTA_FL1] = "quanta",
491 [ALC269_AMIC] = "laptop-amic",
492 [ALC269_DMIC] = "laptop-dmic",
493 [ALC269_FUJITSU] = "fujitsu",
494 [ALC269_LIFEBOOK] = "lifebook",
495 [ALC269_AUTO] = "auto",
496};
497
498static const struct snd_pci_quirk alc269_cfg_tbl[] = {
499 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_QUANTA_FL1),
500 SND_PCI_QUIRK(0x1025, 0x047c, "ACER ZGA", ALC271_ACER),
501 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
502 ALC269_AMIC),
503 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269VB_AMIC),
504 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269VB_AMIC),
505 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269VB_AMIC),
506 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_AMIC),
507 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269VB_AMIC),
508 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269VB_AMIC),
509 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269VB_AMIC),
510 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269VB_AMIC),
511 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_AMIC),
512 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269VB_AMIC),
513 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_AMIC),
514 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_AMIC),
515 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_AMIC),
516 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_AMIC),
517 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_AMIC),
518 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_AMIC),
519 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_AMIC),
520 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_AMIC),
521 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_AMIC),
522 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_AMIC),
523 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_AMIC),
524 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_AMIC),
525 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_AMIC),
526 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_AMIC),
527 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_AMIC),
528 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_AMIC),
529 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_AMIC),
530 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_AMIC),
531 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_AMIC),
532 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_AMIC),
533 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_AMIC),
534 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_DMIC),
535 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_AMIC),
536 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_AMIC),
537 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_AMIC),
538 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_AMIC),
539 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS Eeepc P901",
540 ALC269_DMIC),
541 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS Eeepc S101",
542 ALC269_DMIC),
543 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005HA", ALC269_DMIC),
544 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005HA", ALC269_DMIC),
545 SND_PCI_QUIRK(0x104d, 0x9071, "Sony VAIO", ALC269_AUTO),
546 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook ICH9M-based", ALC269_LIFEBOOK),
547 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_DMIC),
548 SND_PCI_QUIRK(0x1734, 0x115d, "FSC Amilo", ALC269_FUJITSU),
549 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_AMIC),
550 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_AMIC),
551 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_DMIC),
552 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_DMIC),
553 {}
554};
555
556static const struct alc_config_preset alc269_presets[] = {
557 [ALC269_BASIC] = {
558 .mixers = { alc269_base_mixer },
559 .init_verbs = { alc269_init_verbs },
560 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
561 .dac_nids = alc269_dac_nids,
562 .hp_nid = 0x03,
563 .num_channel_mode = ARRAY_SIZE(alc269_modes),
564 .channel_mode = alc269_modes,
565 .input_mux = &alc269_capture_source,
566 },
567 [ALC269_QUANTA_FL1] = {
568 .mixers = { alc269_quanta_fl1_mixer },
569 .init_verbs = { alc269_init_verbs, alc269_quanta_fl1_verbs },
570 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
571 .dac_nids = alc269_dac_nids,
572 .hp_nid = 0x03,
573 .num_channel_mode = ARRAY_SIZE(alc269_modes),
574 .channel_mode = alc269_modes,
575 .input_mux = &alc269_capture_source,
576 .unsol_event = alc269_quanta_fl1_unsol_event,
577 .setup = alc269_quanta_fl1_setup,
578 .init_hook = alc269_quanta_fl1_init_hook,
579 },
580 [ALC269_AMIC] = {
581 .mixers = { alc269_laptop_mixer },
582 .cap_mixer = alc269_laptop_analog_capture_mixer,
583 .init_verbs = { alc269_init_verbs,
584 alc269_laptop_amic_init_verbs },
585 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
586 .dac_nids = alc269_dac_nids,
587 .hp_nid = 0x03,
588 .num_channel_mode = ARRAY_SIZE(alc269_modes),
589 .channel_mode = alc269_modes,
590 .unsol_event = alc_sku_unsol_event,
591 .setup = alc269_laptop_amic_setup,
592 .init_hook = alc_inithook,
593 },
594 [ALC269_DMIC] = {
595 .mixers = { alc269_laptop_mixer },
596 .cap_mixer = alc269_laptop_digital_capture_mixer,
597 .init_verbs = { alc269_init_verbs,
598 alc269_laptop_dmic_init_verbs },
599 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
600 .dac_nids = alc269_dac_nids,
601 .hp_nid = 0x03,
602 .num_channel_mode = ARRAY_SIZE(alc269_modes),
603 .channel_mode = alc269_modes,
604 .unsol_event = alc_sku_unsol_event,
605 .setup = alc269_laptop_dmic_setup,
606 .init_hook = alc_inithook,
607 },
608 [ALC269VB_AMIC] = {
609 .mixers = { alc269vb_laptop_mixer },
610 .cap_mixer = alc269vb_laptop_analog_capture_mixer,
611 .init_verbs = { alc269vb_init_verbs,
612 alc269vb_laptop_amic_init_verbs },
613 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
614 .dac_nids = alc269_dac_nids,
615 .hp_nid = 0x03,
616 .num_channel_mode = ARRAY_SIZE(alc269_modes),
617 .channel_mode = alc269_modes,
618 .unsol_event = alc_sku_unsol_event,
619 .setup = alc269vb_laptop_amic_setup,
620 .init_hook = alc_inithook,
621 },
622 [ALC269VB_DMIC] = {
623 .mixers = { alc269vb_laptop_mixer },
624 .cap_mixer = alc269vb_laptop_digital_capture_mixer,
625 .init_verbs = { alc269vb_init_verbs,
626 alc269vb_laptop_dmic_init_verbs },
627 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
628 .dac_nids = alc269_dac_nids,
629 .hp_nid = 0x03,
630 .num_channel_mode = ARRAY_SIZE(alc269_modes),
631 .channel_mode = alc269_modes,
632 .unsol_event = alc_sku_unsol_event,
633 .setup = alc269vb_laptop_dmic_setup,
634 .init_hook = alc_inithook,
635 },
636 [ALC269_FUJITSU] = {
637 .mixers = { alc269_fujitsu_mixer },
638 .cap_mixer = alc269_laptop_digital_capture_mixer,
639 .init_verbs = { alc269_init_verbs,
640 alc269_laptop_dmic_init_verbs },
641 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
642 .dac_nids = alc269_dac_nids,
643 .hp_nid = 0x03,
644 .num_channel_mode = ARRAY_SIZE(alc269_modes),
645 .channel_mode = alc269_modes,
646 .unsol_event = alc_sku_unsol_event,
647 .setup = alc269_laptop_dmic_setup,
648 .init_hook = alc_inithook,
649 },
650 [ALC269_LIFEBOOK] = {
651 .mixers = { alc269_lifebook_mixer },
652 .init_verbs = { alc269_init_verbs, alc269_lifebook_verbs },
653 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
654 .dac_nids = alc269_dac_nids,
655 .hp_nid = 0x03,
656 .num_channel_mode = ARRAY_SIZE(alc269_modes),
657 .channel_mode = alc269_modes,
658 .input_mux = &alc269_capture_source,
659 .unsol_event = alc269_lifebook_unsol_event,
660 .setup = alc269_lifebook_setup,
661 .init_hook = alc269_lifebook_init_hook,
662 },
663 [ALC271_ACER] = {
664 .mixers = { alc269_asus_mixer },
665 .cap_mixer = alc269vb_laptop_digital_capture_mixer,
666 .init_verbs = { alc269_init_verbs, alc271_acer_dmic_verbs },
667 .num_dacs = ARRAY_SIZE(alc269_dac_nids),
668 .dac_nids = alc269_dac_nids,
669 .adc_nids = alc262_dmic_adc_nids,
670 .num_adc_nids = ARRAY_SIZE(alc262_dmic_adc_nids),
671 .capsrc_nids = alc262_dmic_capsrc_nids,
672 .num_channel_mode = ARRAY_SIZE(alc269_modes),
673 .channel_mode = alc269_modes,
674 .input_mux = &alc269_capture_source,
675 .dig_out_nid = ALC880_DIGOUT_NID,
676 .unsol_event = alc_sku_unsol_event,
677 .setup = alc269vb_laptop_dmic_setup,
678 .init_hook = alc_inithook,
679 },
680};
681
diff --git a/sound/pci/hda/alc662_quirks.c b/sound/pci/hda/alc662_quirks.c
deleted file mode 100644
index e69a6ea3083a..000000000000
--- a/sound/pci/hda/alc662_quirks.c
+++ /dev/null
@@ -1,1408 +0,0 @@
1/*
2 * ALC662/ALC663/ALC665/ALC670 quirk models
3 * included by patch_realtek.c
4 */
5
6/* ALC662 models */
7enum {
8 ALC662_AUTO,
9 ALC662_3ST_2ch_DIG,
10 ALC662_3ST_6ch_DIG,
11 ALC662_3ST_6ch,
12 ALC662_5ST_DIG,
13 ALC662_LENOVO_101E,
14 ALC662_ASUS_EEEPC_P701,
15 ALC662_ASUS_EEEPC_EP20,
16 ALC663_ASUS_M51VA,
17 ALC663_ASUS_G71V,
18 ALC663_ASUS_H13,
19 ALC663_ASUS_G50V,
20 ALC662_ECS,
21 ALC663_ASUS_MODE1,
22 ALC662_ASUS_MODE2,
23 ALC663_ASUS_MODE3,
24 ALC663_ASUS_MODE4,
25 ALC663_ASUS_MODE5,
26 ALC663_ASUS_MODE6,
27 ALC663_ASUS_MODE7,
28 ALC663_ASUS_MODE8,
29 ALC272_DELL,
30 ALC272_DELL_ZM1,
31 ALC272_SAMSUNG_NC10,
32 ALC662_MODEL_LAST,
33};
34
35#define ALC662_DIGOUT_NID 0x06
36#define ALC662_DIGIN_NID 0x0a
37
38static const hda_nid_t alc662_dac_nids[3] = {
39 /* front, rear, clfe */
40 0x02, 0x03, 0x04
41};
42
43static const hda_nid_t alc272_dac_nids[2] = {
44 0x02, 0x03
45};
46
47static const hda_nid_t alc662_adc_nids[2] = {
48 /* ADC1-2 */
49 0x09, 0x08
50};
51
52static const hda_nid_t alc272_adc_nids[1] = {
53 /* ADC1-2 */
54 0x08,
55};
56
57static const hda_nid_t alc662_capsrc_nids[2] = { 0x22, 0x23 };
58static const hda_nid_t alc272_capsrc_nids[1] = { 0x23 };
59
60
61/* input MUX */
62/* FIXME: should be a matrix-type input source selection */
63static const struct hda_input_mux alc662_capture_source = {
64 .num_items = 4,
65 .items = {
66 { "Mic", 0x0 },
67 { "Front Mic", 0x1 },
68 { "Line", 0x2 },
69 { "CD", 0x4 },
70 },
71};
72
73static const struct hda_input_mux alc662_lenovo_101e_capture_source = {
74 .num_items = 2,
75 .items = {
76 { "Mic", 0x1 },
77 { "Line", 0x2 },
78 },
79};
80
81static const struct hda_input_mux alc663_capture_source = {
82 .num_items = 3,
83 .items = {
84 { "Mic", 0x0 },
85 { "Front Mic", 0x1 },
86 { "Line", 0x2 },
87 },
88};
89
90#if 0 /* set to 1 for testing other input sources below */
91static const struct hda_input_mux alc272_nc10_capture_source = {
92 .num_items = 16,
93 .items = {
94 { "Autoselect Mic", 0x0 },
95 { "Internal Mic", 0x1 },
96 { "In-0x02", 0x2 },
97 { "In-0x03", 0x3 },
98 { "In-0x04", 0x4 },
99 { "In-0x05", 0x5 },
100 { "In-0x06", 0x6 },
101 { "In-0x07", 0x7 },
102 { "In-0x08", 0x8 },
103 { "In-0x09", 0x9 },
104 { "In-0x0a", 0x0a },
105 { "In-0x0b", 0x0b },
106 { "In-0x0c", 0x0c },
107 { "In-0x0d", 0x0d },
108 { "In-0x0e", 0x0e },
109 { "In-0x0f", 0x0f },
110 },
111};
112#endif
113
114/*
115 * 2ch mode
116 */
117static const struct hda_channel_mode alc662_3ST_2ch_modes[1] = {
118 { 2, NULL }
119};
120
121/*
122 * 2ch mode
123 */
124static const struct hda_verb alc662_3ST_ch2_init[] = {
125 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80 },
126 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
127 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN },
128 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE },
129 { } /* end */
130};
131
132/*
133 * 6ch mode
134 */
135static const struct hda_verb alc662_3ST_ch6_init[] = {
136 { 0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
137 { 0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
138 { 0x18, AC_VERB_SET_CONNECT_SEL, 0x02 },
139 { 0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
140 { 0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE },
141 { 0x1a, AC_VERB_SET_CONNECT_SEL, 0x01 },
142 { } /* end */
143};
144
145static const struct hda_channel_mode alc662_3ST_6ch_modes[2] = {
146 { 2, alc662_3ST_ch2_init },
147 { 6, alc662_3ST_ch6_init },
148};
149
150/*
151 * 2ch mode
152 */
153static const struct hda_verb alc662_sixstack_ch6_init[] = {
154 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
155 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
156 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
157 { } /* end */
158};
159
160/*
161 * 6ch mode
162 */
163static const struct hda_verb alc662_sixstack_ch8_init[] = {
164 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
165 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
166 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
167 { } /* end */
168};
169
170static const struct hda_channel_mode alc662_5stack_modes[2] = {
171 { 2, alc662_sixstack_ch6_init },
172 { 6, alc662_sixstack_ch8_init },
173};
174
175/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
176 * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
177 */
178
179static const struct snd_kcontrol_new alc662_base_mixer[] = {
180 /* output mixer control */
181 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
182 HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
183 HDA_CODEC_VOLUME("Surround Playback Volume", 0x3, 0x0, HDA_OUTPUT),
184 HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
185 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
186 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
187 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
188 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
189 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
190
191 /*Input mixer control */
192 HDA_CODEC_VOLUME("CD Playback Volume", 0xb, 0x4, HDA_INPUT),
193 HDA_CODEC_MUTE("CD Playback Switch", 0xb, 0x4, HDA_INPUT),
194 HDA_CODEC_VOLUME("Line Playback Volume", 0xb, 0x02, HDA_INPUT),
195 HDA_CODEC_MUTE("Line Playback Switch", 0xb, 0x02, HDA_INPUT),
196 HDA_CODEC_VOLUME("Mic Playback Volume", 0xb, 0x0, HDA_INPUT),
197 HDA_CODEC_MUTE("Mic Playback Switch", 0xb, 0x0, HDA_INPUT),
198 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0xb, 0x01, HDA_INPUT),
199 HDA_CODEC_MUTE("Front Mic Playback Switch", 0xb, 0x01, HDA_INPUT),
200 { } /* end */
201};
202
203static const struct snd_kcontrol_new alc662_3ST_2ch_mixer[] = {
204 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
205 HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
206 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
207 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
208 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
209 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
210 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
211 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
212 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
213 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
214 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
215 { } /* end */
216};
217
218static const struct snd_kcontrol_new alc662_3ST_6ch_mixer[] = {
219 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
220 HDA_CODEC_MUTE("Front Playback Switch", 0x0c, 0x0, HDA_INPUT),
221 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
222 HDA_CODEC_MUTE("Surround Playback Switch", 0x0d, 0x0, HDA_INPUT),
223 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
224 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
225 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x0e, 1, 0x0, HDA_INPUT),
226 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 0x0, HDA_INPUT),
227 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
228 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
229 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
230 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
231 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
232 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
233 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
234 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
235 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
236 { } /* end */
237};
238
239static const struct snd_kcontrol_new alc662_lenovo_101e_mixer[] = {
240 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
241 HDA_BIND_MUTE("Front Playback Switch", 0x02, 2, HDA_INPUT),
242 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x03, 0x0, HDA_OUTPUT),
243 HDA_BIND_MUTE("Speaker Playback Switch", 0x03, 2, HDA_INPUT),
244 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
245 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
246 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
247 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
248 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
249 { } /* end */
250};
251
252static const struct snd_kcontrol_new alc662_eeepc_p701_mixer[] = {
253 HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
254 ALC262_HIPPO_MASTER_SWITCH,
255
256 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
257 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
258 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
259
260 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
261 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
262 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
263 { } /* end */
264};
265
266static const struct snd_kcontrol_new alc662_eeepc_ep20_mixer[] = {
267 ALC262_HIPPO_MASTER_SWITCH,
268 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
269 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
270 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0, HDA_OUTPUT),
271 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0, HDA_OUTPUT),
272 HDA_BIND_MUTE("MuteCtrl Playback Switch", 0x0c, 2, HDA_INPUT),
273 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
274 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
275 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
276 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
277 { } /* end */
278};
279
280static const struct hda_bind_ctls alc663_asus_bind_master_vol = {
281 .ops = &snd_hda_bind_vol,
282 .values = {
283 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
284 HDA_COMPOSE_AMP_VAL(0x03, 3, 0, HDA_OUTPUT),
285 0
286 },
287};
288
289static const struct hda_bind_ctls alc663_asus_one_bind_switch = {
290 .ops = &snd_hda_bind_sw,
291 .values = {
292 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
293 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
294 0
295 },
296};
297
298static const struct snd_kcontrol_new alc663_m51va_mixer[] = {
299 HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
300 HDA_BIND_SW("Master Playback Switch", &alc663_asus_one_bind_switch),
301 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
302 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
303 { } /* end */
304};
305
306static const struct hda_bind_ctls alc663_asus_tree_bind_switch = {
307 .ops = &snd_hda_bind_sw,
308 .values = {
309 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
310 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
311 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
312 0
313 },
314};
315
316static const struct snd_kcontrol_new alc663_two_hp_m1_mixer[] = {
317 HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
318 HDA_BIND_SW("Master Playback Switch", &alc663_asus_tree_bind_switch),
319 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
320 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
321 HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
322 HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
323
324 { } /* end */
325};
326
327static const struct hda_bind_ctls alc663_asus_four_bind_switch = {
328 .ops = &snd_hda_bind_sw,
329 .values = {
330 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
331 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
332 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
333 0
334 },
335};
336
337static const struct snd_kcontrol_new alc663_two_hp_m2_mixer[] = {
338 HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
339 HDA_BIND_SW("Master Playback Switch", &alc663_asus_four_bind_switch),
340 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
341 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
342 HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
343 HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
344 { } /* end */
345};
346
347static const struct snd_kcontrol_new alc662_1bjd_mixer[] = {
348 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
349 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
350 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
351 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
352 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
353 HDA_CODEC_VOLUME("F-Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
354 HDA_CODEC_MUTE("F-Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
355 { } /* end */
356};
357
358static const struct hda_bind_ctls alc663_asus_two_bind_master_vol = {
359 .ops = &snd_hda_bind_vol,
360 .values = {
361 HDA_COMPOSE_AMP_VAL(0x02, 3, 0, HDA_OUTPUT),
362 HDA_COMPOSE_AMP_VAL(0x04, 3, 0, HDA_OUTPUT),
363 0
364 },
365};
366
367static const struct hda_bind_ctls alc663_asus_two_bind_switch = {
368 .ops = &snd_hda_bind_sw,
369 .values = {
370 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
371 HDA_COMPOSE_AMP_VAL(0x16, 3, 0, HDA_OUTPUT),
372 0
373 },
374};
375
376static const struct snd_kcontrol_new alc663_asus_21jd_clfe_mixer[] = {
377 HDA_BIND_VOL("Master Playback Volume",
378 &alc663_asus_two_bind_master_vol),
379 HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
380 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
381 HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
382 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
383 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
384 { } /* end */
385};
386
387static const struct snd_kcontrol_new alc663_asus_15jd_clfe_mixer[] = {
388 HDA_BIND_VOL("Master Playback Volume", &alc663_asus_bind_master_vol),
389 HDA_BIND_SW("Master Playback Switch", &alc663_asus_two_bind_switch),
390 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
391 HDA_CODEC_MUTE("Headphone Playback Switch", 0x15, 0x0, HDA_OUTPUT),
392 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
393 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
394 { } /* end */
395};
396
397static const struct snd_kcontrol_new alc663_g71v_mixer[] = {
398 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
399 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
400 HDA_CODEC_VOLUME("Front Playback Volume", 0x03, 0x0, HDA_OUTPUT),
401 HDA_CODEC_MUTE("Front Playback Switch", 0x15, 0x0, HDA_OUTPUT),
402 HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
403
404 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
405 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
406 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
407 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
408 { } /* end */
409};
410
411static const struct snd_kcontrol_new alc663_g50v_mixer[] = {
412 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
413 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
414 HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
415
416 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
417 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
418 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
419 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
420 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
421 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
422 { } /* end */
423};
424
425static const struct hda_bind_ctls alc663_asus_mode7_8_all_bind_switch = {
426 .ops = &snd_hda_bind_sw,
427 .values = {
428 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
429 HDA_COMPOSE_AMP_VAL(0x15, 3, 0, HDA_OUTPUT),
430 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
431 HDA_COMPOSE_AMP_VAL(0x1b, 3, 0, HDA_OUTPUT),
432 HDA_COMPOSE_AMP_VAL(0x21, 3, 0, HDA_OUTPUT),
433 0
434 },
435};
436
437static const struct hda_bind_ctls alc663_asus_mode7_8_sp_bind_switch = {
438 .ops = &snd_hda_bind_sw,
439 .values = {
440 HDA_COMPOSE_AMP_VAL(0x14, 3, 0, HDA_OUTPUT),
441 HDA_COMPOSE_AMP_VAL(0x17, 3, 0, HDA_OUTPUT),
442 0
443 },
444};
445
446static const struct snd_kcontrol_new alc663_mode7_mixer[] = {
447 HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
448 HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
449 HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
450 HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
451 HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
452 HDA_CODEC_VOLUME("IntMic Playback Volume", 0x0b, 0x0, HDA_INPUT),
453 HDA_CODEC_MUTE("IntMic Playback Switch", 0x0b, 0x0, HDA_INPUT),
454 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
455 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
456 { } /* end */
457};
458
459static const struct snd_kcontrol_new alc663_mode8_mixer[] = {
460 HDA_BIND_SW("Master Playback Switch", &alc663_asus_mode7_8_all_bind_switch),
461 HDA_BIND_VOL("Speaker Playback Volume", &alc663_asus_bind_master_vol),
462 HDA_BIND_SW("Speaker Playback Switch", &alc663_asus_mode7_8_sp_bind_switch),
463 HDA_CODEC_MUTE("Headphone1 Playback Switch", 0x15, 0x0, HDA_OUTPUT),
464 HDA_CODEC_MUTE("Headphone2 Playback Switch", 0x21, 0x0, HDA_OUTPUT),
465 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
466 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
467 { } /* end */
468};
469
470
471static const struct snd_kcontrol_new alc662_chmode_mixer[] = {
472 {
473 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
474 .name = "Channel Mode",
475 .info = alc_ch_mode_info,
476 .get = alc_ch_mode_get,
477 .put = alc_ch_mode_put,
478 },
479 { } /* end */
480};
481
482static const struct hda_verb alc662_init_verbs[] = {
483 /* ADC: mute amp left and right */
484 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
485 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
486
487 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
488 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
489 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
490 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
491 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
492 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
493
494 /* Front Pin: output 0 (0x0c) */
495 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
496 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
497
498 /* Rear Pin: output 1 (0x0d) */
499 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
500 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
501
502 /* CLFE Pin: output 2 (0x0e) */
503 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
504 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
505
506 /* Mic (rear) pin: input vref at 80% */
507 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
508 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
509 /* Front Mic pin: input vref at 80% */
510 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
511 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
512 /* Line In pin: input */
513 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
514 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
515 /* Line-2 In: Headphone output (output 0 - 0x0c) */
516 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
517 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
518 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
519 /* CD pin widget for input */
520 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
521
522 /* FIXME: use matrix-type input source selection */
523 /* Mixer elements: 0x18, 19, 1a, 1b, 1c, 1d, 14, 15, 16, 17, 0b */
524 /* Input mixer */
525 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
526 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
527
528 { }
529};
530
531static const struct hda_verb alc662_eapd_init_verbs[] = {
532 /* always trun on EAPD */
533 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
534 {0x15, AC_VERB_SET_EAPD_BTLENABLE, 2},
535 { }
536};
537
538static const struct hda_verb alc662_sue_init_verbs[] = {
539 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC_FRONT_EVENT},
540 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC_HP_EVENT},
541 {}
542};
543
544static const struct hda_verb alc662_eeepc_sue_init_verbs[] = {
545 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
546 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
547 {}
548};
549
550/* Set Unsolicited Event*/
551static const struct hda_verb alc662_eeepc_ep20_sue_init_verbs[] = {
552 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
553 {0x14, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
554 {}
555};
556
557static const struct hda_verb alc663_m51va_init_verbs[] = {
558 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
559 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
560 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
561 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
562 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
563 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
564 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
565 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
566 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
567 {}
568};
569
570static const struct hda_verb alc663_21jd_amic_init_verbs[] = {
571 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
572 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
573 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
574 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
575 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
576 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
577 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
578 {}
579};
580
581static const struct hda_verb alc662_1bjd_amic_init_verbs[] = {
582 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
583 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
584 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
585 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Headphone */
586 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
587 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
588 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
589 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
590 {}
591};
592
593static const struct hda_verb alc663_15jd_amic_init_verbs[] = {
594 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
595 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
596 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
597 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
598 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
599 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
600 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
601 {}
602};
603
604static const struct hda_verb alc663_two_hp_amic_m1_init_verbs[] = {
605 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
606 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
607 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
608 {0x21, AC_VERB_SET_CONNECT_SEL, 0x0}, /* Headphone */
609 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
610 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
611 {0x15, AC_VERB_SET_CONNECT_SEL, 0x0}, /* Headphone */
612 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
613 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
614 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
615 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
616 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
617 {}
618};
619
620static const struct hda_verb alc663_two_hp_amic_m2_init_verbs[] = {
621 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
622 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
623 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
624 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
625 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
626 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
627 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
628 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
629 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
630 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
631 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
632 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
633 {}
634};
635
636static const struct hda_verb alc663_g71v_init_verbs[] = {
637 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
638 /* {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, */
639 /* {0x15, AC_VERB_SET_CONNECT_SEL, 0x01}, */ /* Headphone */
640
641 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
642 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
643 {0x21, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Headphone */
644
645 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC_FRONT_EVENT},
646 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC_MIC_EVENT},
647 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|ALC_HP_EVENT},
648 {}
649};
650
651static const struct hda_verb alc663_g50v_init_verbs[] = {
652 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
653 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
654 {0x21, AC_VERB_SET_CONNECT_SEL, 0x00}, /* Headphone */
655
656 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
657 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
658 {}
659};
660
661static const struct hda_verb alc662_ecs_init_verbs[] = {
662 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, 0x701f},
663 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
664 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
665 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
666 {}
667};
668
669static const struct hda_verb alc272_dell_zm1_init_verbs[] = {
670 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
671 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
672 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
673 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
674 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
675 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
676 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
677 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
678 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
679 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
680 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
681 {}
682};
683
684static const struct hda_verb alc272_dell_init_verbs[] = {
685 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
686 {0x13, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
687 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
688 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
689 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
690 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
691 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
692 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
693 {0x23, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
694 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
695 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
696 {}
697};
698
699static const struct hda_verb alc663_mode7_init_verbs[] = {
700 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
701 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
702 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
703 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
704 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
705 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
706 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x01},
707 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
708 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
709 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
710 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
711 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
712 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
713 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
714 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
715 {}
716};
717
718static const struct hda_verb alc663_mode8_init_verbs[] = {
719 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
720 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
721 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
722 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
723 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
724 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
725 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
726 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
727 {0x21, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
728 {0x21, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
729 {0x21, AC_VERB_SET_CONNECT_SEL, 0x01}, /* Headphone */
730 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
731 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(9)},
732 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
733 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
734 {0x21, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
735 {}
736};
737
738static const struct snd_kcontrol_new alc662_auto_capture_mixer[] = {
739 HDA_CODEC_VOLUME("Capture Volume", 0x09, 0x0, HDA_INPUT),
740 HDA_CODEC_MUTE("Capture Switch", 0x09, 0x0, HDA_INPUT),
741 { } /* end */
742};
743
744static const struct snd_kcontrol_new alc272_auto_capture_mixer[] = {
745 HDA_CODEC_VOLUME("Capture Volume", 0x08, 0x0, HDA_INPUT),
746 HDA_CODEC_MUTE("Capture Switch", 0x08, 0x0, HDA_INPUT),
747 { } /* end */
748};
749
750static void alc662_lenovo_101e_setup(struct hda_codec *codec)
751{
752 struct alc_spec *spec = codec->spec;
753
754 spec->autocfg.hp_pins[0] = 0x1b;
755 spec->autocfg.line_out_pins[0] = 0x14;
756 spec->autocfg.speaker_pins[0] = 0x15;
757 spec->automute = 1;
758 spec->detect_line = 1;
759 spec->automute_lines = 1;
760 spec->automute_mode = ALC_AUTOMUTE_AMP;
761}
762
763static void alc662_eeepc_setup(struct hda_codec *codec)
764{
765 struct alc_spec *spec = codec->spec;
766
767 alc262_hippo1_setup(codec);
768 spec->ext_mic_pin = 0x18;
769 spec->int_mic_pin = 0x19;
770 spec->auto_mic = 1;
771}
772
773static void alc662_eeepc_ep20_setup(struct hda_codec *codec)
774{
775 struct alc_spec *spec = codec->spec;
776
777 spec->autocfg.hp_pins[0] = 0x14;
778 spec->autocfg.speaker_pins[0] = 0x1b;
779 spec->automute = 1;
780 spec->automute_mode = ALC_AUTOMUTE_AMP;
781}
782
783static void alc663_m51va_setup(struct hda_codec *codec)
784{
785 struct alc_spec *spec = codec->spec;
786 spec->autocfg.hp_pins[0] = 0x21;
787 spec->autocfg.speaker_pins[0] = 0x14;
788 spec->automute_mixer_nid[0] = 0x0c;
789 spec->automute = 1;
790 spec->automute_mode = ALC_AUTOMUTE_MIXER;
791 spec->ext_mic_pin = 0x18;
792 spec->int_mic_pin = 0x12;
793 spec->auto_mic = 1;
794}
795
796/* ***************** Mode1 ******************************/
797static void alc663_mode1_setup(struct hda_codec *codec)
798{
799 struct alc_spec *spec = codec->spec;
800 spec->autocfg.hp_pins[0] = 0x21;
801 spec->autocfg.speaker_pins[0] = 0x14;
802 spec->automute_mixer_nid[0] = 0x0c;
803 spec->automute = 1;
804 spec->automute_mode = ALC_AUTOMUTE_MIXER;
805 spec->ext_mic_pin = 0x18;
806 spec->int_mic_pin = 0x19;
807 spec->auto_mic = 1;
808}
809
810/* ***************** Mode2 ******************************/
811static void alc662_mode2_setup(struct hda_codec *codec)
812{
813 struct alc_spec *spec = codec->spec;
814 spec->autocfg.hp_pins[0] = 0x1b;
815 spec->autocfg.speaker_pins[0] = 0x14;
816 spec->automute = 1;
817 spec->automute_mode = ALC_AUTOMUTE_PIN;
818 spec->ext_mic_pin = 0x18;
819 spec->int_mic_pin = 0x19;
820 spec->auto_mic = 1;
821}
822
823/* ***************** Mode3 ******************************/
824static void alc663_mode3_setup(struct hda_codec *codec)
825{
826 struct alc_spec *spec = codec->spec;
827 spec->autocfg.hp_pins[0] = 0x21;
828 spec->autocfg.hp_pins[0] = 0x15;
829 spec->autocfg.speaker_pins[0] = 0x14;
830 spec->automute = 1;
831 spec->automute_mode = ALC_AUTOMUTE_PIN;
832 spec->ext_mic_pin = 0x18;
833 spec->int_mic_pin = 0x19;
834 spec->auto_mic = 1;
835}
836
837/* ***************** Mode4 ******************************/
838static void alc663_mode4_setup(struct hda_codec *codec)
839{
840 struct alc_spec *spec = codec->spec;
841 spec->autocfg.hp_pins[0] = 0x21;
842 spec->autocfg.speaker_pins[0] = 0x14;
843 spec->autocfg.speaker_pins[1] = 0x16;
844 spec->automute_mixer_nid[0] = 0x0c;
845 spec->automute_mixer_nid[1] = 0x0e;
846 spec->automute = 1;
847 spec->automute_mode = ALC_AUTOMUTE_MIXER;
848 spec->ext_mic_pin = 0x18;
849 spec->int_mic_pin = 0x19;
850 spec->auto_mic = 1;
851}
852
853/* ***************** Mode5 ******************************/
854static void alc663_mode5_setup(struct hda_codec *codec)
855{
856 struct alc_spec *spec = codec->spec;
857 spec->autocfg.hp_pins[0] = 0x15;
858 spec->autocfg.speaker_pins[0] = 0x14;
859 spec->autocfg.speaker_pins[1] = 0x16;
860 spec->automute_mixer_nid[0] = 0x0c;
861 spec->automute_mixer_nid[1] = 0x0e;
862 spec->automute = 1;
863 spec->automute_mode = ALC_AUTOMUTE_MIXER;
864 spec->ext_mic_pin = 0x18;
865 spec->int_mic_pin = 0x19;
866 spec->auto_mic = 1;
867}
868
869/* ***************** Mode6 ******************************/
870static void alc663_mode6_setup(struct hda_codec *codec)
871{
872 struct alc_spec *spec = codec->spec;
873 spec->autocfg.hp_pins[0] = 0x1b;
874 spec->autocfg.hp_pins[0] = 0x15;
875 spec->autocfg.speaker_pins[0] = 0x14;
876 spec->automute_mixer_nid[0] = 0x0c;
877 spec->automute = 1;
878 spec->automute_mode = ALC_AUTOMUTE_MIXER;
879 spec->ext_mic_pin = 0x18;
880 spec->int_mic_pin = 0x19;
881 spec->auto_mic = 1;
882}
883
884/* ***************** Mode7 ******************************/
885static void alc663_mode7_setup(struct hda_codec *codec)
886{
887 struct alc_spec *spec = codec->spec;
888 spec->autocfg.hp_pins[0] = 0x1b;
889 spec->autocfg.hp_pins[0] = 0x21;
890 spec->autocfg.speaker_pins[0] = 0x14;
891 spec->autocfg.speaker_pins[0] = 0x17;
892 spec->automute = 1;
893 spec->automute_mode = ALC_AUTOMUTE_PIN;
894 spec->ext_mic_pin = 0x18;
895 spec->int_mic_pin = 0x19;
896 spec->auto_mic = 1;
897}
898
899/* ***************** Mode8 ******************************/
900static void alc663_mode8_setup(struct hda_codec *codec)
901{
902 struct alc_spec *spec = codec->spec;
903 spec->autocfg.hp_pins[0] = 0x21;
904 spec->autocfg.hp_pins[1] = 0x15;
905 spec->autocfg.speaker_pins[0] = 0x14;
906 spec->autocfg.speaker_pins[0] = 0x17;
907 spec->automute = 1;
908 spec->automute_mode = ALC_AUTOMUTE_PIN;
909 spec->ext_mic_pin = 0x18;
910 spec->int_mic_pin = 0x12;
911 spec->auto_mic = 1;
912}
913
914static void alc663_g71v_setup(struct hda_codec *codec)
915{
916 struct alc_spec *spec = codec->spec;
917 spec->autocfg.hp_pins[0] = 0x21;
918 spec->autocfg.line_out_pins[0] = 0x15;
919 spec->autocfg.speaker_pins[0] = 0x14;
920 spec->automute = 1;
921 spec->automute_mode = ALC_AUTOMUTE_AMP;
922 spec->detect_line = 1;
923 spec->automute_lines = 1;
924 spec->ext_mic_pin = 0x18;
925 spec->int_mic_pin = 0x12;
926 spec->auto_mic = 1;
927}
928
929#define alc663_g50v_setup alc663_m51va_setup
930
931static const struct snd_kcontrol_new alc662_ecs_mixer[] = {
932 HDA_CODEC_VOLUME("Master Playback Volume", 0x02, 0x0, HDA_OUTPUT),
933 ALC262_HIPPO_MASTER_SWITCH,
934
935 HDA_CODEC_VOLUME("Mic/LineIn Boost Volume", 0x18, 0, HDA_INPUT),
936 HDA_CODEC_VOLUME("Mic/LineIn Playback Volume", 0x0b, 0x0, HDA_INPUT),
937 HDA_CODEC_MUTE("Mic/LineIn Playback Switch", 0x0b, 0x0, HDA_INPUT),
938
939 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
940 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
941 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
942 { } /* end */
943};
944
945static const struct snd_kcontrol_new alc272_nc10_mixer[] = {
946 /* Master Playback automatically created from Speaker and Headphone */
947 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
948 HDA_CODEC_MUTE("Speaker Playback Switch", 0x14, 0x0, HDA_OUTPUT),
949 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
950 HDA_CODEC_MUTE("Headphone Playback Switch", 0x21, 0x0, HDA_OUTPUT),
951
952 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
953 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
954 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
955
956 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
957 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
958 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
959 { } /* end */
960};
961
962
963/*
964 * configuration and preset
965 */
966static const char * const alc662_models[ALC662_MODEL_LAST] = {
967 [ALC662_3ST_2ch_DIG] = "3stack-dig",
968 [ALC662_3ST_6ch_DIG] = "3stack-6ch-dig",
969 [ALC662_3ST_6ch] = "3stack-6ch",
970 [ALC662_5ST_DIG] = "5stack-dig",
971 [ALC662_LENOVO_101E] = "lenovo-101e",
972 [ALC662_ASUS_EEEPC_P701] = "eeepc-p701",
973 [ALC662_ASUS_EEEPC_EP20] = "eeepc-ep20",
974 [ALC662_ECS] = "ecs",
975 [ALC663_ASUS_M51VA] = "m51va",
976 [ALC663_ASUS_G71V] = "g71v",
977 [ALC663_ASUS_H13] = "h13",
978 [ALC663_ASUS_G50V] = "g50v",
979 [ALC663_ASUS_MODE1] = "asus-mode1",
980 [ALC662_ASUS_MODE2] = "asus-mode2",
981 [ALC663_ASUS_MODE3] = "asus-mode3",
982 [ALC663_ASUS_MODE4] = "asus-mode4",
983 [ALC663_ASUS_MODE5] = "asus-mode5",
984 [ALC663_ASUS_MODE6] = "asus-mode6",
985 [ALC663_ASUS_MODE7] = "asus-mode7",
986 [ALC663_ASUS_MODE8] = "asus-mode8",
987 [ALC272_DELL] = "dell",
988 [ALC272_DELL_ZM1] = "dell-zm1",
989 [ALC272_SAMSUNG_NC10] = "samsung-nc10",
990 [ALC662_AUTO] = "auto",
991};
992
993static const struct snd_pci_quirk alc662_cfg_tbl[] = {
994 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_ECS),
995 SND_PCI_QUIRK(0x1028, 0x02d6, "DELL", ALC272_DELL),
996 SND_PCI_QUIRK(0x1028, 0x02f4, "DELL ZM1", ALC272_DELL_ZM1),
997 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC663_ASUS_MODE1),
998 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC663_ASUS_MODE3),
999 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC663_ASUS_MODE1),
1000 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC663_ASUS_MODE3),
1001 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC663_ASUS_MODE1),
1002 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_ASUS_MODE2),
1003 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC663_ASUS_MODE1),
1004 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC663_ASUS_MODE1),
1005 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC663_ASUS_MODE1),
1006 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_ASUS_MODE2),
1007 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC663_ASUS_MODE7),
1008 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC663_ASUS_MODE7),
1009 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC663_ASUS_MODE8),
1010 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC663_ASUS_MODE3),
1011 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC663_ASUS_MODE1),
1012 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_ASUS_MODE2),
1013 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_ASUS_MODE2),
1014 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC663_ASUS_MODE1),
1015 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_ASUS_MODE2),
1016 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC663_ASUS_MODE6),
1017 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC663_ASUS_MODE6),
1018 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_ASUS_MODE2),
1019 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC663_ASUS_MODE1),
1020 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC663_ASUS_MODE3),
1021 SND_PCI_QUIRK(0x1043, 0x17c3, "ASUS UX20", ALC663_ASUS_M51VA),
1022 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_ASUS_MODE2),
1023 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_ASUS_MODE2),
1024 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC663_ASUS_MODE5),
1025 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC663_ASUS_MODE6),
1026 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_ASUS_MODE2),
1027 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC663_ASUS_MODE1),
1028 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_ASUS_MODE2),
1029 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_ASUS_MODE2),
1030 SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M51VA", ALC663_ASUS_M51VA),
1031 /*SND_PCI_QUIRK(0x1043, 0x1878, "ASUS M50Vr", ALC663_ASUS_MODE1),*/
1032 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC663_ASUS_MODE3),
1033 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC663_ASUS_MODE3),
1034 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC663_ASUS_MODE1),
1035 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC663_ASUS_MODE1),
1036 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC663_ASUS_MODE1),
1037 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC663_ASUS_MODE1),
1038 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC663_ASUS_MODE1),
1039 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_ASUS_MODE2),
1040 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_ASUS_MODE2),
1041 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC663_ASUS_MODE1),
1042 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC663_ASUS_MODE1),
1043 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC663_ASUS_MODE3),
1044 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC663_ASUS_MODE1),
1045 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC663_ASUS_MODE1),
1046 SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS G50V", ALC663_ASUS_G50V),
1047 /*SND_PCI_QUIRK(0x1043, 0x19a3, "ASUS NB", ALC663_ASUS_MODE1),*/
1048 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC663_ASUS_MODE1),
1049 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_ASUS_MODE2),
1050 SND_PCI_QUIRK(0x1043, 0x19d3, "ASUS NB", ALC663_ASUS_M51VA),
1051 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC663_ASUS_MODE1),
1052 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC663_ASUS_MODE4),
1053 SND_PCI_QUIRK(0x1043, 0x8290, "ASUS P5GC-MX", ALC662_3ST_6ch_DIG),
1054 SND_PCI_QUIRK(0x1043, 0x82a1, "ASUS Eeepc", ALC662_ASUS_EEEPC_P701),
1055 SND_PCI_QUIRK(0x1043, 0x82d1, "ASUS Eeepc EP20", ALC662_ASUS_EEEPC_EP20),
1056 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_ECS),
1057 SND_PCI_QUIRK(0x105b, 0x0d47, "Foxconn 45CMX/45GMX/45CMX-K",
1058 ALC662_3ST_6ch_DIG),
1059 SND_PCI_QUIRK(0x1179, 0xff6e, "Toshiba NB20x", ALC662_AUTO),
1060 SND_PCI_QUIRK(0x144d, 0xca00, "Samsung NC10", ALC272_SAMSUNG_NC10),
1061 SND_PCI_QUIRK(0x1458, 0xa002, "Gigabyte 945GCM-S2L",
1062 ALC662_3ST_6ch_DIG),
1063 SND_PCI_QUIRK(0x152d, 0x2304, "Quanta WH1", ALC663_ASUS_H13),
1064 SND_PCI_QUIRK(0x1565, 0x820f, "Biostar TA780G M2+", ALC662_3ST_6ch_DIG),
1065 SND_PCI_QUIRK(0x1631, 0xc10c, "PB RS65", ALC663_ASUS_M51VA),
1066 SND_PCI_QUIRK(0x17aa, 0x101e, "Lenovo", ALC662_LENOVO_101E),
1067 SND_PCI_QUIRK(0x1849, 0x3662, "ASROCK K10N78FullHD-hSLI R3.0",
1068 ALC662_3ST_6ch_DIG),
1069 SND_PCI_QUIRK_MASK(0x1854, 0xf000, 0x2000, "ASUS H13-200x",
1070 ALC663_ASUS_H13),
1071 SND_PCI_QUIRK(0x1991, 0x5628, "Ordissimo EVE", ALC662_LENOVO_101E),
1072 {}
1073};
1074
1075static const struct alc_config_preset alc662_presets[] = {
1076 [ALC662_3ST_2ch_DIG] = {
1077 .mixers = { alc662_3ST_2ch_mixer },
1078 .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
1079 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1080 .dac_nids = alc662_dac_nids,
1081 .dig_out_nid = ALC662_DIGOUT_NID,
1082 .dig_in_nid = ALC662_DIGIN_NID,
1083 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1084 .channel_mode = alc662_3ST_2ch_modes,
1085 .input_mux = &alc662_capture_source,
1086 },
1087 [ALC662_3ST_6ch_DIG] = {
1088 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
1089 .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
1090 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1091 .dac_nids = alc662_dac_nids,
1092 .dig_out_nid = ALC662_DIGOUT_NID,
1093 .dig_in_nid = ALC662_DIGIN_NID,
1094 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
1095 .channel_mode = alc662_3ST_6ch_modes,
1096 .need_dac_fix = 1,
1097 .input_mux = &alc662_capture_source,
1098 },
1099 [ALC662_3ST_6ch] = {
1100 .mixers = { alc662_3ST_6ch_mixer, alc662_chmode_mixer },
1101 .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
1102 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1103 .dac_nids = alc662_dac_nids,
1104 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
1105 .channel_mode = alc662_3ST_6ch_modes,
1106 .need_dac_fix = 1,
1107 .input_mux = &alc662_capture_source,
1108 },
1109 [ALC662_5ST_DIG] = {
1110 .mixers = { alc662_base_mixer, alc662_chmode_mixer },
1111 .init_verbs = { alc662_init_verbs, alc662_eapd_init_verbs },
1112 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1113 .dac_nids = alc662_dac_nids,
1114 .dig_out_nid = ALC662_DIGOUT_NID,
1115 .dig_in_nid = ALC662_DIGIN_NID,
1116 .num_channel_mode = ARRAY_SIZE(alc662_5stack_modes),
1117 .channel_mode = alc662_5stack_modes,
1118 .input_mux = &alc662_capture_source,
1119 },
1120 [ALC662_LENOVO_101E] = {
1121 .mixers = { alc662_lenovo_101e_mixer },
1122 .init_verbs = { alc662_init_verbs,
1123 alc662_eapd_init_verbs,
1124 alc662_sue_init_verbs },
1125 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1126 .dac_nids = alc662_dac_nids,
1127 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1128 .channel_mode = alc662_3ST_2ch_modes,
1129 .input_mux = &alc662_lenovo_101e_capture_source,
1130 .unsol_event = alc_sku_unsol_event,
1131 .setup = alc662_lenovo_101e_setup,
1132 .init_hook = alc_inithook,
1133 },
1134 [ALC662_ASUS_EEEPC_P701] = {
1135 .mixers = { alc662_eeepc_p701_mixer },
1136 .init_verbs = { alc662_init_verbs,
1137 alc662_eapd_init_verbs,
1138 alc662_eeepc_sue_init_verbs },
1139 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1140 .dac_nids = alc662_dac_nids,
1141 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1142 .channel_mode = alc662_3ST_2ch_modes,
1143 .unsol_event = alc_sku_unsol_event,
1144 .setup = alc662_eeepc_setup,
1145 .init_hook = alc_inithook,
1146 },
1147 [ALC662_ASUS_EEEPC_EP20] = {
1148 .mixers = { alc662_eeepc_ep20_mixer,
1149 alc662_chmode_mixer },
1150 .init_verbs = { alc662_init_verbs,
1151 alc662_eapd_init_verbs,
1152 alc662_eeepc_ep20_sue_init_verbs },
1153 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1154 .dac_nids = alc662_dac_nids,
1155 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
1156 .channel_mode = alc662_3ST_6ch_modes,
1157 .input_mux = &alc662_lenovo_101e_capture_source,
1158 .unsol_event = alc_sku_unsol_event,
1159 .setup = alc662_eeepc_ep20_setup,
1160 .init_hook = alc_inithook,
1161 },
1162 [ALC662_ECS] = {
1163 .mixers = { alc662_ecs_mixer },
1164 .init_verbs = { alc662_init_verbs,
1165 alc662_eapd_init_verbs,
1166 alc662_ecs_init_verbs },
1167 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1168 .dac_nids = alc662_dac_nids,
1169 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1170 .channel_mode = alc662_3ST_2ch_modes,
1171 .unsol_event = alc_sku_unsol_event,
1172 .setup = alc662_eeepc_setup,
1173 .init_hook = alc_inithook,
1174 },
1175 [ALC663_ASUS_M51VA] = {
1176 .mixers = { alc663_m51va_mixer },
1177 .init_verbs = { alc662_init_verbs,
1178 alc662_eapd_init_verbs,
1179 alc663_m51va_init_verbs },
1180 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1181 .dac_nids = alc662_dac_nids,
1182 .dig_out_nid = ALC662_DIGOUT_NID,
1183 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1184 .channel_mode = alc662_3ST_2ch_modes,
1185 .unsol_event = alc_sku_unsol_event,
1186 .setup = alc663_m51va_setup,
1187 .init_hook = alc_inithook,
1188 },
1189 [ALC663_ASUS_G71V] = {
1190 .mixers = { alc663_g71v_mixer },
1191 .init_verbs = { alc662_init_verbs,
1192 alc662_eapd_init_verbs,
1193 alc663_g71v_init_verbs },
1194 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1195 .dac_nids = alc662_dac_nids,
1196 .dig_out_nid = ALC662_DIGOUT_NID,
1197 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1198 .channel_mode = alc662_3ST_2ch_modes,
1199 .unsol_event = alc_sku_unsol_event,
1200 .setup = alc663_g71v_setup,
1201 .init_hook = alc_inithook,
1202 },
1203 [ALC663_ASUS_H13] = {
1204 .mixers = { alc663_m51va_mixer },
1205 .init_verbs = { alc662_init_verbs,
1206 alc662_eapd_init_verbs,
1207 alc663_m51va_init_verbs },
1208 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1209 .dac_nids = alc662_dac_nids,
1210 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1211 .channel_mode = alc662_3ST_2ch_modes,
1212 .setup = alc663_m51va_setup,
1213 .unsol_event = alc_sku_unsol_event,
1214 .init_hook = alc_inithook,
1215 },
1216 [ALC663_ASUS_G50V] = {
1217 .mixers = { alc663_g50v_mixer },
1218 .init_verbs = { alc662_init_verbs,
1219 alc662_eapd_init_verbs,
1220 alc663_g50v_init_verbs },
1221 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1222 .dac_nids = alc662_dac_nids,
1223 .dig_out_nid = ALC662_DIGOUT_NID,
1224 .num_channel_mode = ARRAY_SIZE(alc662_3ST_6ch_modes),
1225 .channel_mode = alc662_3ST_6ch_modes,
1226 .input_mux = &alc663_capture_source,
1227 .unsol_event = alc_sku_unsol_event,
1228 .setup = alc663_g50v_setup,
1229 .init_hook = alc_inithook,
1230 },
1231 [ALC663_ASUS_MODE1] = {
1232 .mixers = { alc663_m51va_mixer },
1233 .cap_mixer = alc662_auto_capture_mixer,
1234 .init_verbs = { alc662_init_verbs,
1235 alc662_eapd_init_verbs,
1236 alc663_21jd_amic_init_verbs },
1237 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1238 .hp_nid = 0x03,
1239 .dac_nids = alc662_dac_nids,
1240 .dig_out_nid = ALC662_DIGOUT_NID,
1241 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1242 .channel_mode = alc662_3ST_2ch_modes,
1243 .unsol_event = alc_sku_unsol_event,
1244 .setup = alc663_mode1_setup,
1245 .init_hook = alc_inithook,
1246 },
1247 [ALC662_ASUS_MODE2] = {
1248 .mixers = { alc662_1bjd_mixer },
1249 .cap_mixer = alc662_auto_capture_mixer,
1250 .init_verbs = { alc662_init_verbs,
1251 alc662_eapd_init_verbs,
1252 alc662_1bjd_amic_init_verbs },
1253 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1254 .dac_nids = alc662_dac_nids,
1255 .dig_out_nid = ALC662_DIGOUT_NID,
1256 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1257 .channel_mode = alc662_3ST_2ch_modes,
1258 .unsol_event = alc_sku_unsol_event,
1259 .setup = alc662_mode2_setup,
1260 .init_hook = alc_inithook,
1261 },
1262 [ALC663_ASUS_MODE3] = {
1263 .mixers = { alc663_two_hp_m1_mixer },
1264 .cap_mixer = alc662_auto_capture_mixer,
1265 .init_verbs = { alc662_init_verbs,
1266 alc662_eapd_init_verbs,
1267 alc663_two_hp_amic_m1_init_verbs },
1268 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1269 .hp_nid = 0x03,
1270 .dac_nids = alc662_dac_nids,
1271 .dig_out_nid = ALC662_DIGOUT_NID,
1272 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1273 .channel_mode = alc662_3ST_2ch_modes,
1274 .unsol_event = alc_sku_unsol_event,
1275 .setup = alc663_mode3_setup,
1276 .init_hook = alc_inithook,
1277 },
1278 [ALC663_ASUS_MODE4] = {
1279 .mixers = { alc663_asus_21jd_clfe_mixer },
1280 .cap_mixer = alc662_auto_capture_mixer,
1281 .init_verbs = { alc662_init_verbs,
1282 alc662_eapd_init_verbs,
1283 alc663_21jd_amic_init_verbs},
1284 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1285 .hp_nid = 0x03,
1286 .dac_nids = alc662_dac_nids,
1287 .dig_out_nid = ALC662_DIGOUT_NID,
1288 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1289 .channel_mode = alc662_3ST_2ch_modes,
1290 .unsol_event = alc_sku_unsol_event,
1291 .setup = alc663_mode4_setup,
1292 .init_hook = alc_inithook,
1293 },
1294 [ALC663_ASUS_MODE5] = {
1295 .mixers = { alc663_asus_15jd_clfe_mixer },
1296 .cap_mixer = alc662_auto_capture_mixer,
1297 .init_verbs = { alc662_init_verbs,
1298 alc662_eapd_init_verbs,
1299 alc663_15jd_amic_init_verbs },
1300 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1301 .hp_nid = 0x03,
1302 .dac_nids = alc662_dac_nids,
1303 .dig_out_nid = ALC662_DIGOUT_NID,
1304 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1305 .channel_mode = alc662_3ST_2ch_modes,
1306 .unsol_event = alc_sku_unsol_event,
1307 .setup = alc663_mode5_setup,
1308 .init_hook = alc_inithook,
1309 },
1310 [ALC663_ASUS_MODE6] = {
1311 .mixers = { alc663_two_hp_m2_mixer },
1312 .cap_mixer = alc662_auto_capture_mixer,
1313 .init_verbs = { alc662_init_verbs,
1314 alc662_eapd_init_verbs,
1315 alc663_two_hp_amic_m2_init_verbs },
1316 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1317 .hp_nid = 0x03,
1318 .dac_nids = alc662_dac_nids,
1319 .dig_out_nid = ALC662_DIGOUT_NID,
1320 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1321 .channel_mode = alc662_3ST_2ch_modes,
1322 .unsol_event = alc_sku_unsol_event,
1323 .setup = alc663_mode6_setup,
1324 .init_hook = alc_inithook,
1325 },
1326 [ALC663_ASUS_MODE7] = {
1327 .mixers = { alc663_mode7_mixer },
1328 .cap_mixer = alc662_auto_capture_mixer,
1329 .init_verbs = { alc662_init_verbs,
1330 alc662_eapd_init_verbs,
1331 alc663_mode7_init_verbs },
1332 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1333 .hp_nid = 0x03,
1334 .dac_nids = alc662_dac_nids,
1335 .dig_out_nid = ALC662_DIGOUT_NID,
1336 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1337 .channel_mode = alc662_3ST_2ch_modes,
1338 .unsol_event = alc_sku_unsol_event,
1339 .setup = alc663_mode7_setup,
1340 .init_hook = alc_inithook,
1341 },
1342 [ALC663_ASUS_MODE8] = {
1343 .mixers = { alc663_mode8_mixer },
1344 .cap_mixer = alc662_auto_capture_mixer,
1345 .init_verbs = { alc662_init_verbs,
1346 alc662_eapd_init_verbs,
1347 alc663_mode8_init_verbs },
1348 .num_dacs = ARRAY_SIZE(alc662_dac_nids),
1349 .hp_nid = 0x03,
1350 .dac_nids = alc662_dac_nids,
1351 .dig_out_nid = ALC662_DIGOUT_NID,
1352 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1353 .channel_mode = alc662_3ST_2ch_modes,
1354 .unsol_event = alc_sku_unsol_event,
1355 .setup = alc663_mode8_setup,
1356 .init_hook = alc_inithook,
1357 },
1358 [ALC272_DELL] = {
1359 .mixers = { alc663_m51va_mixer },
1360 .cap_mixer = alc272_auto_capture_mixer,
1361 .init_verbs = { alc662_init_verbs,
1362 alc662_eapd_init_verbs,
1363 alc272_dell_init_verbs },
1364 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
1365 .dac_nids = alc272_dac_nids,
1366 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1367 .adc_nids = alc272_adc_nids,
1368 .num_adc_nids = ARRAY_SIZE(alc272_adc_nids),
1369 .capsrc_nids = alc272_capsrc_nids,
1370 .channel_mode = alc662_3ST_2ch_modes,
1371 .unsol_event = alc_sku_unsol_event,
1372 .setup = alc663_m51va_setup,
1373 .init_hook = alc_inithook,
1374 },
1375 [ALC272_DELL_ZM1] = {
1376 .mixers = { alc663_m51va_mixer },
1377 .cap_mixer = alc662_auto_capture_mixer,
1378 .init_verbs = { alc662_init_verbs,
1379 alc662_eapd_init_verbs,
1380 alc272_dell_zm1_init_verbs },
1381 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
1382 .dac_nids = alc272_dac_nids,
1383 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1384 .adc_nids = alc662_adc_nids,
1385 .num_adc_nids = 1,
1386 .capsrc_nids = alc662_capsrc_nids,
1387 .channel_mode = alc662_3ST_2ch_modes,
1388 .unsol_event = alc_sku_unsol_event,
1389 .setup = alc663_m51va_setup,
1390 .init_hook = alc_inithook,
1391 },
1392 [ALC272_SAMSUNG_NC10] = {
1393 .mixers = { alc272_nc10_mixer },
1394 .init_verbs = { alc662_init_verbs,
1395 alc662_eapd_init_verbs,
1396 alc663_21jd_amic_init_verbs },
1397 .num_dacs = ARRAY_SIZE(alc272_dac_nids),
1398 .dac_nids = alc272_dac_nids,
1399 .num_channel_mode = ARRAY_SIZE(alc662_3ST_2ch_modes),
1400 .channel_mode = alc662_3ST_2ch_modes,
1401 /*.input_mux = &alc272_nc10_capture_source,*/
1402 .unsol_event = alc_sku_unsol_event,
1403 .setup = alc663_mode4_setup,
1404 .init_hook = alc_inithook,
1405 },
1406};
1407
1408
diff --git a/sound/pci/hda/alc680_quirks.c b/sound/pci/hda/alc680_quirks.c
deleted file mode 100644
index 0eeb227c7bc2..000000000000
--- a/sound/pci/hda/alc680_quirks.c
+++ /dev/null
@@ -1,222 +0,0 @@
1/*
2 * ALC680 quirk models
3 * included by patch_realtek.c
4 */
5
6/* ALC680 models */
7enum {
8 ALC680_AUTO,
9 ALC680_BASE,
10 ALC680_MODEL_LAST,
11};
12
13#define ALC680_DIGIN_NID ALC880_DIGIN_NID
14#define ALC680_DIGOUT_NID ALC880_DIGOUT_NID
15#define alc680_modes alc260_modes
16
17static const hda_nid_t alc680_dac_nids[3] = {
18 /* Lout1, Lout2, hp */
19 0x02, 0x03, 0x04
20};
21
22static const hda_nid_t alc680_adc_nids[3] = {
23 /* ADC0-2 */
24 /* DMIC, MIC, Line-in*/
25 0x07, 0x08, 0x09
26};
27
28/*
29 * Analog capture ADC cgange
30 */
31static hda_nid_t alc680_get_cur_adc(struct hda_codec *codec)
32{
33 static hda_nid_t pins[] = {0x18, 0x19};
34 static hda_nid_t adcs[] = {0x08, 0x09};
35 int i;
36
37 for (i = 0; i < ARRAY_SIZE(pins); i++) {
38 if (!is_jack_detectable(codec, pins[i]))
39 continue;
40 if (snd_hda_jack_detect(codec, pins[i]))
41 return adcs[i];
42 }
43 return 0x07;
44}
45
46static void alc680_rec_autoswitch(struct hda_codec *codec)
47{
48 struct alc_spec *spec = codec->spec;
49 hda_nid_t nid = alc680_get_cur_adc(codec);
50 if (spec->cur_adc && nid != spec->cur_adc) {
51 __snd_hda_codec_cleanup_stream(codec, spec->cur_adc, 1);
52 spec->cur_adc = nid;
53 snd_hda_codec_setup_stream(codec, nid,
54 spec->cur_adc_stream_tag, 0,
55 spec->cur_adc_format);
56 }
57}
58
59static int alc680_capture_pcm_prepare(struct hda_pcm_stream *hinfo,
60 struct hda_codec *codec,
61 unsigned int stream_tag,
62 unsigned int format,
63 struct snd_pcm_substream *substream)
64{
65 struct alc_spec *spec = codec->spec;
66 hda_nid_t nid = alc680_get_cur_adc(codec);
67
68 spec->cur_adc = nid;
69 spec->cur_adc_stream_tag = stream_tag;
70 spec->cur_adc_format = format;
71 snd_hda_codec_setup_stream(codec, nid, stream_tag, 0, format);
72 return 0;
73}
74
75static int alc680_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
76 struct hda_codec *codec,
77 struct snd_pcm_substream *substream)
78{
79 struct alc_spec *spec = codec->spec;
80 snd_hda_codec_cleanup_stream(codec, spec->cur_adc);
81 spec->cur_adc = 0;
82 return 0;
83}
84
85static const struct hda_pcm_stream alc680_pcm_analog_auto_capture = {
86 .substreams = 1, /* can be overridden */
87 .channels_min = 2,
88 .channels_max = 2,
89 /* NID is set in alc_build_pcms */
90 .ops = {
91 .prepare = alc680_capture_pcm_prepare,
92 .cleanup = alc680_capture_pcm_cleanup
93 },
94};
95
96static const struct snd_kcontrol_new alc680_base_mixer[] = {
97 /* output mixer control */
98 HDA_CODEC_VOLUME("Front Playback Volume", 0x2, 0x0, HDA_OUTPUT),
99 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
100 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x4, 0x0, HDA_OUTPUT),
101 HDA_CODEC_MUTE("Headphone Playback Switch", 0x16, 0x0, HDA_OUTPUT),
102 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x12, 0, HDA_INPUT),
103 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
104 HDA_CODEC_VOLUME("Line In Boost Volume", 0x19, 0, HDA_INPUT),
105 { }
106};
107
108static const struct hda_bind_ctls alc680_bind_cap_vol = {
109 .ops = &snd_hda_bind_vol,
110 .values = {
111 HDA_COMPOSE_AMP_VAL(0x07, 3, 0, HDA_INPUT),
112 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
113 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
114 0
115 },
116};
117
118static const struct hda_bind_ctls alc680_bind_cap_switch = {
119 .ops = &snd_hda_bind_sw,
120 .values = {
121 HDA_COMPOSE_AMP_VAL(0x07, 3, 0, HDA_INPUT),
122 HDA_COMPOSE_AMP_VAL(0x08, 3, 0, HDA_INPUT),
123 HDA_COMPOSE_AMP_VAL(0x09, 3, 0, HDA_INPUT),
124 0
125 },
126};
127
128static const struct snd_kcontrol_new alc680_master_capture_mixer[] = {
129 HDA_BIND_VOL("Capture Volume", &alc680_bind_cap_vol),
130 HDA_BIND_SW("Capture Switch", &alc680_bind_cap_switch),
131 { } /* end */
132};
133
134/*
135 * generic initialization of ADC, input mixers and output mixers
136 */
137static const struct hda_verb alc680_init_verbs[] = {
138 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
139 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
140 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
141
142 {0x12, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
143 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
144 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
145 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
146 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
147 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
148
149 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
150 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
151 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
152 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
153 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
154
155 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_HP_EVENT | AC_USRSP_EN},
156 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_MIC_EVENT | AC_USRSP_EN},
157 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, ALC_MIC_EVENT | AC_USRSP_EN},
158
159 { }
160};
161
162/* toggle speaker-output according to the hp-jack state */
163static void alc680_base_setup(struct hda_codec *codec)
164{
165 struct alc_spec *spec = codec->spec;
166
167 spec->autocfg.hp_pins[0] = 0x16;
168 spec->autocfg.speaker_pins[0] = 0x14;
169 spec->autocfg.speaker_pins[1] = 0x15;
170 spec->autocfg.num_inputs = 2;
171 spec->autocfg.inputs[0].pin = 0x18;
172 spec->autocfg.inputs[0].type = AUTO_PIN_MIC;
173 spec->autocfg.inputs[1].pin = 0x19;
174 spec->autocfg.inputs[1].type = AUTO_PIN_LINE_IN;
175 spec->automute = 1;
176 spec->automute_mode = ALC_AUTOMUTE_AMP;
177}
178
179static void alc680_unsol_event(struct hda_codec *codec,
180 unsigned int res)
181{
182 if ((res >> 26) == ALC_HP_EVENT)
183 alc_hp_automute(codec);
184 if ((res >> 26) == ALC_MIC_EVENT)
185 alc680_rec_autoswitch(codec);
186}
187
188static void alc680_inithook(struct hda_codec *codec)
189{
190 alc_hp_automute(codec);
191 alc680_rec_autoswitch(codec);
192}
193
194/*
195 * configuration and preset
196 */
197static const char * const alc680_models[ALC680_MODEL_LAST] = {
198 [ALC680_BASE] = "base",
199 [ALC680_AUTO] = "auto",
200};
201
202static const struct snd_pci_quirk alc680_cfg_tbl[] = {
203 SND_PCI_QUIRK(0x1043, 0x12f3, "ASUS NX90", ALC680_BASE),
204 {}
205};
206
207static const struct alc_config_preset alc680_presets[] = {
208 [ALC680_BASE] = {
209 .mixers = { alc680_base_mixer },
210 .cap_mixer = alc680_master_capture_mixer,
211 .init_verbs = { alc680_init_verbs },
212 .num_dacs = ARRAY_SIZE(alc680_dac_nids),
213 .dac_nids = alc680_dac_nids,
214 .dig_out_nid = ALC680_DIGOUT_NID,
215 .num_channel_mode = ARRAY_SIZE(alc680_modes),
216 .channel_mode = alc680_modes,
217 .unsol_event = alc680_unsol_event,
218 .setup = alc680_base_setup,
219 .init_hook = alc680_inithook,
220
221 },
222};
diff --git a/sound/pci/hda/alc861_quirks.c b/sound/pci/hda/alc861_quirks.c
deleted file mode 100644
index d719ec6350eb..000000000000
--- a/sound/pci/hda/alc861_quirks.c
+++ /dev/null
@@ -1,725 +0,0 @@
1/*
2 * ALC660/ALC861 quirk models
3 * included by patch_realtek.c
4 */
5
6/* ALC861 models */
7enum {
8 ALC861_AUTO,
9 ALC861_3ST,
10 ALC660_3ST,
11 ALC861_3ST_DIG,
12 ALC861_6ST_DIG,
13 ALC861_UNIWILL_M31,
14 ALC861_TOSHIBA,
15 ALC861_ASUS,
16 ALC861_ASUS_LAPTOP,
17 ALC861_MODEL_LAST,
18};
19
20/*
21 * ALC861 channel source setting (2/6 channel selection for 3-stack)
22 */
23
24/*
25 * set the path ways for 2 channel output
26 * need to set the codec line out and mic 1 pin widgets to inputs
27 */
28static const struct hda_verb alc861_threestack_ch2_init[] = {
29 /* set pin widget 1Ah (line in) for input */
30 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
31 /* set pin widget 18h (mic1/2) for input, for mic also enable
32 * the vref
33 */
34 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
35
36 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
37#if 0
38 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
39 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
40#endif
41 { } /* end */
42};
43/*
44 * 6ch mode
45 * need to set the codec line out and mic 1 pin widgets to outputs
46 */
47static const struct hda_verb alc861_threestack_ch6_init[] = {
48 /* set pin widget 1Ah (line in) for output (Back Surround)*/
49 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
50 /* set pin widget 18h (mic1) for output (CLFE)*/
51 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
52
53 { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
54 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
55
56 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
57#if 0
58 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
59 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
60#endif
61 { } /* end */
62};
63
64static const struct hda_channel_mode alc861_threestack_modes[2] = {
65 { 2, alc861_threestack_ch2_init },
66 { 6, alc861_threestack_ch6_init },
67};
68/* Set mic1 as input and unmute the mixer */
69static const struct hda_verb alc861_uniwill_m31_ch2_init[] = {
70 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
71 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
72 { } /* end */
73};
74/* Set mic1 as output and mute mixer */
75static const struct hda_verb alc861_uniwill_m31_ch4_init[] = {
76 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
77 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
78 { } /* end */
79};
80
81static const struct hda_channel_mode alc861_uniwill_m31_modes[2] = {
82 { 2, alc861_uniwill_m31_ch2_init },
83 { 4, alc861_uniwill_m31_ch4_init },
84};
85
86/* Set mic1 and line-in as input and unmute the mixer */
87static const struct hda_verb alc861_asus_ch2_init[] = {
88 /* set pin widget 1Ah (line in) for input */
89 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
90 /* set pin widget 18h (mic1/2) for input, for mic also enable
91 * the vref
92 */
93 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
94
95 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c },
96#if 0
97 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x01 << 8)) }, /*mic*/
98 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7000 | (0x02 << 8)) }, /*line-in*/
99#endif
100 { } /* end */
101};
102/* Set mic1 nad line-in as output and mute mixer */
103static const struct hda_verb alc861_asus_ch6_init[] = {
104 /* set pin widget 1Ah (line in) for output (Back Surround)*/
105 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
106 /* { 0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
107 /* set pin widget 18h (mic1) for output (CLFE)*/
108 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
109 /* { 0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE }, */
110 { 0x0c, AC_VERB_SET_CONNECT_SEL, 0x00 },
111 { 0x0d, AC_VERB_SET_CONNECT_SEL, 0x00 },
112
113 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb080 },
114#if 0
115 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x01 << 8)) }, /*mic*/
116 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, (0x7080 | (0x02 << 8)) }, /*line in*/
117#endif
118 { } /* end */
119};
120
121static const struct hda_channel_mode alc861_asus_modes[2] = {
122 { 2, alc861_asus_ch2_init },
123 { 6, alc861_asus_ch6_init },
124};
125
126/* patch-ALC861 */
127
128static const struct snd_kcontrol_new alc861_base_mixer[] = {
129 /* output mixer control */
130 HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
131 HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
132 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
133 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
134 HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
135
136 /*Input mixer control */
137 /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
138 HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
139 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
140 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
141 HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
142 HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
143 HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
144 HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
145 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
146 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
147
148 { } /* end */
149};
150
151static const struct snd_kcontrol_new alc861_3ST_mixer[] = {
152 /* output mixer control */
153 HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
154 HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
155 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
156 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
157 /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
158
159 /* Input mixer control */
160 /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
161 HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
162 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
163 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
164 HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
165 HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
166 HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
167 HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
168 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
169 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
170
171 {
172 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
173 .name = "Channel Mode",
174 .info = alc_ch_mode_info,
175 .get = alc_ch_mode_get,
176 .put = alc_ch_mode_put,
177 .private_value = ARRAY_SIZE(alc861_threestack_modes),
178 },
179 { } /* end */
180};
181
182static const struct snd_kcontrol_new alc861_toshiba_mixer[] = {
183 /* output mixer control */
184 HDA_CODEC_MUTE("Master Playback Switch", 0x03, 0x0, HDA_OUTPUT),
185 HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
186 HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
187
188 { } /* end */
189};
190
191static const struct snd_kcontrol_new alc861_uniwill_m31_mixer[] = {
192 /* output mixer control */
193 HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
194 HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
195 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
196 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
197 /*HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT), */
198
199 /* Input mixer control */
200 /* HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
201 HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT), */
202 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
203 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
204 HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
205 HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
206 HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
207 HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
208 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
209 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_INPUT),
210
211 {
212 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
213 .name = "Channel Mode",
214 .info = alc_ch_mode_info,
215 .get = alc_ch_mode_get,
216 .put = alc_ch_mode_put,
217 .private_value = ARRAY_SIZE(alc861_uniwill_m31_modes),
218 },
219 { } /* end */
220};
221
222static const struct snd_kcontrol_new alc861_asus_mixer[] = {
223 /* output mixer control */
224 HDA_CODEC_MUTE("Front Playback Switch", 0x03, 0x0, HDA_OUTPUT),
225 HDA_CODEC_MUTE("Surround Playback Switch", 0x06, 0x0, HDA_OUTPUT),
226 HDA_CODEC_MUTE_MONO("Center Playback Switch", 0x05, 1, 0x0, HDA_OUTPUT),
227 HDA_CODEC_MUTE_MONO("LFE Playback Switch", 0x05, 2, 0x0, HDA_OUTPUT),
228 HDA_CODEC_MUTE("Side Playback Switch", 0x04, 0x0, HDA_OUTPUT),
229
230 /* Input mixer control */
231 HDA_CODEC_VOLUME("Input Playback Volume", 0x15, 0x0, HDA_OUTPUT),
232 HDA_CODEC_MUTE("Input Playback Switch", 0x15, 0x0, HDA_OUTPUT),
233 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
234 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
235 HDA_CODEC_VOLUME("Line Playback Volume", 0x15, 0x02, HDA_INPUT),
236 HDA_CODEC_MUTE("Line Playback Switch", 0x15, 0x02, HDA_INPUT),
237 HDA_CODEC_VOLUME("Mic Playback Volume", 0x15, 0x01, HDA_INPUT),
238 HDA_CODEC_MUTE("Mic Playback Switch", 0x15, 0x01, HDA_INPUT),
239 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x10, 0x01, HDA_OUTPUT),
240 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1a, 0x03, HDA_OUTPUT),
241
242 {
243 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
244 .name = "Channel Mode",
245 .info = alc_ch_mode_info,
246 .get = alc_ch_mode_get,
247 .put = alc_ch_mode_put,
248 .private_value = ARRAY_SIZE(alc861_asus_modes),
249 },
250 { }
251};
252
253/* additional mixer */
254static const struct snd_kcontrol_new alc861_asus_laptop_mixer[] = {
255 HDA_CODEC_VOLUME("CD Playback Volume", 0x15, 0x0, HDA_INPUT),
256 HDA_CODEC_MUTE("CD Playback Switch", 0x15, 0x0, HDA_INPUT),
257 { }
258};
259
260/*
261 * generic initialization of ADC, input mixers and output mixers
262 */
263static const struct hda_verb alc861_base_init_verbs[] = {
264 /*
265 * Unmute ADC0 and set the default input to mic-in
266 */
267 /* port-A for surround (rear panel) */
268 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
269 { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x00 },
270 /* port-B for mic-in (rear panel) with vref */
271 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
272 /* port-C for line-in (rear panel) */
273 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
274 /* port-D for Front */
275 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
276 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
277 /* port-E for HP out (front panel) */
278 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
279 /* route front PCM to HP */
280 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
281 /* port-F for mic-in (front panel) with vref */
282 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
283 /* port-G for CLFE (rear panel) */
284 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
285 { 0x1f, AC_VERB_SET_CONNECT_SEL, 0x00 },
286 /* port-H for side (rear panel) */
287 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
288 { 0x20, AC_VERB_SET_CONNECT_SEL, 0x00 },
289 /* CD-in */
290 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
291 /* route front mic to ADC1*/
292 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
293 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
294
295 /* Unmute DAC0~3 & spdif out*/
296 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
297 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
298 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
299 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
300 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
301
302 /* Unmute Mixer 14 (mic) 1c (Line in)*/
303 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
304 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
305 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
306 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
307
308 /* Unmute Stereo Mixer 15 */
309 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
310 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
311 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
312 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
313
314 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
315 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
316 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
317 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
318 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
319 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
320 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
321 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
322 /* hp used DAC 3 (Front) */
323 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
324 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
325
326 { }
327};
328
329static const struct hda_verb alc861_threestack_init_verbs[] = {
330 /*
331 * Unmute ADC0 and set the default input to mic-in
332 */
333 /* port-A for surround (rear panel) */
334 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
335 /* port-B for mic-in (rear panel) with vref */
336 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
337 /* port-C for line-in (rear panel) */
338 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
339 /* port-D for Front */
340 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
341 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
342 /* port-E for HP out (front panel) */
343 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 },
344 /* route front PCM to HP */
345 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
346 /* port-F for mic-in (front panel) with vref */
347 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
348 /* port-G for CLFE (rear panel) */
349 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
350 /* port-H for side (rear panel) */
351 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
352 /* CD-in */
353 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
354 /* route front mic to ADC1*/
355 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
356 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
357 /* Unmute DAC0~3 & spdif out*/
358 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
359 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
360 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
361 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
362 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
363
364 /* Unmute Mixer 14 (mic) 1c (Line in)*/
365 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
366 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
367 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
368 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
369
370 /* Unmute Stereo Mixer 15 */
371 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
372 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
373 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
374 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
375
376 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
377 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
378 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
379 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
380 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
381 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
382 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
383 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
384 /* hp used DAC 3 (Front) */
385 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
386 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
387 { }
388};
389
390static const struct hda_verb alc861_uniwill_m31_init_verbs[] = {
391 /*
392 * Unmute ADC0 and set the default input to mic-in
393 */
394 /* port-A for surround (rear panel) */
395 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
396 /* port-B for mic-in (rear panel) with vref */
397 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
398 /* port-C for line-in (rear panel) */
399 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
400 /* port-D for Front */
401 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
402 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
403 /* port-E for HP out (front panel) */
404 /* this has to be set to VREF80 */
405 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
406 /* route front PCM to HP */
407 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
408 /* port-F for mic-in (front panel) with vref */
409 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
410 /* port-G for CLFE (rear panel) */
411 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
412 /* port-H for side (rear panel) */
413 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
414 /* CD-in */
415 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
416 /* route front mic to ADC1*/
417 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
418 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
419 /* Unmute DAC0~3 & spdif out*/
420 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
421 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
422 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
423 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
424 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
425
426 /* Unmute Mixer 14 (mic) 1c (Line in)*/
427 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
428 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
429 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
430 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
431
432 /* Unmute Stereo Mixer 15 */
433 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
434 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
435 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
436 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
437
438 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
439 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
440 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
441 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
442 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
443 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
444 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
445 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
446 /* hp used DAC 3 (Front) */
447 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
448 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
449 { }
450};
451
452static const struct hda_verb alc861_asus_init_verbs[] = {
453 /*
454 * Unmute ADC0 and set the default input to mic-in
455 */
456 /* port-A for surround (rear panel)
457 * according to codec#0 this is the HP jack
458 */
459 { 0x0e, AC_VERB_SET_PIN_WIDGET_CONTROL, 0xc0 }, /* was 0x00 */
460 /* route front PCM to HP */
461 { 0x0e, AC_VERB_SET_CONNECT_SEL, 0x01 },
462 /* port-B for mic-in (rear panel) with vref */
463 { 0x0d, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
464 /* port-C for line-in (rear panel) */
465 { 0x0c, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
466 /* port-D for Front */
467 { 0x0b, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
468 { 0x0b, AC_VERB_SET_CONNECT_SEL, 0x00 },
469 /* port-E for HP out (front panel) */
470 /* this has to be set to VREF80 */
471 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
472 /* route front PCM to HP */
473 { 0x0f, AC_VERB_SET_CONNECT_SEL, 0x00 },
474 /* port-F for mic-in (front panel) with vref */
475 { 0x10, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x24 },
476 /* port-G for CLFE (rear panel) */
477 { 0x1f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
478 /* port-H for side (rear panel) */
479 { 0x20, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x40 },
480 /* CD-in */
481 { 0x11, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x20 },
482 /* route front mic to ADC1*/
483 {0x08, AC_VERB_SET_CONNECT_SEL, 0x00},
484 {0x08, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
485 /* Unmute DAC0~3 & spdif out*/
486 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
487 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
488 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
489 {0x06, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
490 {0x07, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
491 /* Unmute Mixer 14 (mic) 1c (Line in)*/
492 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
493 {0x014, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
494 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
495 {0x01c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
496
497 /* Unmute Stereo Mixer 15 */
498 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
499 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
500 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
501 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, 0xb00c}, /* Output 0~12 step */
502
503 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
504 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
505 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
506 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
507 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
508 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
509 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
510 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
511 /* hp used DAC 3 (Front) */
512 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(3)},
513 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
514 { }
515};
516
517/* additional init verbs for ASUS laptops */
518static const struct hda_verb alc861_asus_laptop_init_verbs[] = {
519 { 0x0f, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x45 }, /* HP-out */
520 { 0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2) }, /* mute line-in */
521 { }
522};
523
524static const struct hda_verb alc861_toshiba_init_verbs[] = {
525 {0x0f, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
526
527 { }
528};
529
530/* toggle speaker-output according to the hp-jack state */
531static void alc861_toshiba_automute(struct hda_codec *codec)
532{
533 unsigned int present = snd_hda_jack_detect(codec, 0x0f);
534
535 snd_hda_codec_amp_stereo(codec, 0x16, HDA_INPUT, 0,
536 HDA_AMP_MUTE, present ? HDA_AMP_MUTE : 0);
537 snd_hda_codec_amp_stereo(codec, 0x1a, HDA_INPUT, 3,
538 HDA_AMP_MUTE, present ? 0 : HDA_AMP_MUTE);
539}
540
541static void alc861_toshiba_unsol_event(struct hda_codec *codec,
542 unsigned int res)
543{
544 if ((res >> 26) == ALC_HP_EVENT)
545 alc861_toshiba_automute(codec);
546}
547
548#define ALC861_DIGOUT_NID 0x07
549
550static const struct hda_channel_mode alc861_8ch_modes[1] = {
551 { 8, NULL }
552};
553
554static const hda_nid_t alc861_dac_nids[4] = {
555 /* front, surround, clfe, side */
556 0x03, 0x06, 0x05, 0x04
557};
558
559static const hda_nid_t alc660_dac_nids[3] = {
560 /* front, clfe, surround */
561 0x03, 0x05, 0x06
562};
563
564static const hda_nid_t alc861_adc_nids[1] = {
565 /* ADC0-2 */
566 0x08,
567};
568
569static const struct hda_input_mux alc861_capture_source = {
570 .num_items = 5,
571 .items = {
572 { "Mic", 0x0 },
573 { "Front Mic", 0x3 },
574 { "Line", 0x1 },
575 { "CD", 0x4 },
576 { "Mixer", 0x5 },
577 },
578};
579
580/*
581 * configuration and preset
582 */
583static const char * const alc861_models[ALC861_MODEL_LAST] = {
584 [ALC861_3ST] = "3stack",
585 [ALC660_3ST] = "3stack-660",
586 [ALC861_3ST_DIG] = "3stack-dig",
587 [ALC861_6ST_DIG] = "6stack-dig",
588 [ALC861_UNIWILL_M31] = "uniwill-m31",
589 [ALC861_TOSHIBA] = "toshiba",
590 [ALC861_ASUS] = "asus",
591 [ALC861_ASUS_LAPTOP] = "asus-laptop",
592 [ALC861_AUTO] = "auto",
593};
594
595static const struct snd_pci_quirk alc861_cfg_tbl[] = {
596 SND_PCI_QUIRK(0x1043, 0x1205, "ASUS W7J", ALC861_3ST),
597 SND_PCI_QUIRK(0x1043, 0x1335, "ASUS F2/3", ALC861_ASUS_LAPTOP),
598 SND_PCI_QUIRK(0x1043, 0x1338, "ASUS F2/3", ALC861_ASUS_LAPTOP),
599 SND_PCI_QUIRK(0x1043, 0x1393, "ASUS", ALC861_ASUS),
600 SND_PCI_QUIRK(0x1043, 0x13d7, "ASUS A9rp", ALC861_ASUS_LAPTOP),
601 SND_PCI_QUIRK(0x1043, 0x81cb, "ASUS P1-AH2", ALC861_3ST_DIG),
602 SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba", ALC861_TOSHIBA),
603 /* FIXME: the entry below breaks Toshiba A100 (model=auto works!)
604 * Any other models that need this preset?
605 */
606 /* SND_PCI_QUIRK(0x1179, 0xff10, "Toshiba", ALC861_TOSHIBA), */
607 SND_PCI_QUIRK(0x1462, 0x7254, "HP dx2200 (MSI MS-7254)", ALC861_3ST),
608 SND_PCI_QUIRK(0x1462, 0x7297, "HP dx2250 (MSI MS-7297)", ALC861_3ST),
609 SND_PCI_QUIRK(0x1584, 0x2b01, "Uniwill X40AIx", ALC861_UNIWILL_M31),
610 SND_PCI_QUIRK(0x1584, 0x9072, "Uniwill m31", ALC861_UNIWILL_M31),
611 SND_PCI_QUIRK(0x1584, 0x9075, "Airis Praxis N1212", ALC861_ASUS_LAPTOP),
612 /* FIXME: the below seems conflict */
613 /* SND_PCI_QUIRK(0x1584, 0x9075, "Uniwill", ALC861_UNIWILL_M31), */
614 SND_PCI_QUIRK(0x1849, 0x0660, "Asrock 939SLI32", ALC660_3ST),
615 SND_PCI_QUIRK(0x8086, 0xd600, "Intel", ALC861_3ST),
616 {}
617};
618
619static const struct alc_config_preset alc861_presets[] = {
620 [ALC861_3ST] = {
621 .mixers = { alc861_3ST_mixer },
622 .init_verbs = { alc861_threestack_init_verbs },
623 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
624 .dac_nids = alc861_dac_nids,
625 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
626 .channel_mode = alc861_threestack_modes,
627 .need_dac_fix = 1,
628 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
629 .adc_nids = alc861_adc_nids,
630 .input_mux = &alc861_capture_source,
631 },
632 [ALC861_3ST_DIG] = {
633 .mixers = { alc861_base_mixer },
634 .init_verbs = { alc861_threestack_init_verbs },
635 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
636 .dac_nids = alc861_dac_nids,
637 .dig_out_nid = ALC861_DIGOUT_NID,
638 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
639 .channel_mode = alc861_threestack_modes,
640 .need_dac_fix = 1,
641 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
642 .adc_nids = alc861_adc_nids,
643 .input_mux = &alc861_capture_source,
644 },
645 [ALC861_6ST_DIG] = {
646 .mixers = { alc861_base_mixer },
647 .init_verbs = { alc861_base_init_verbs },
648 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
649 .dac_nids = alc861_dac_nids,
650 .dig_out_nid = ALC861_DIGOUT_NID,
651 .num_channel_mode = ARRAY_SIZE(alc861_8ch_modes),
652 .channel_mode = alc861_8ch_modes,
653 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
654 .adc_nids = alc861_adc_nids,
655 .input_mux = &alc861_capture_source,
656 },
657 [ALC660_3ST] = {
658 .mixers = { alc861_3ST_mixer },
659 .init_verbs = { alc861_threestack_init_verbs },
660 .num_dacs = ARRAY_SIZE(alc660_dac_nids),
661 .dac_nids = alc660_dac_nids,
662 .num_channel_mode = ARRAY_SIZE(alc861_threestack_modes),
663 .channel_mode = alc861_threestack_modes,
664 .need_dac_fix = 1,
665 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
666 .adc_nids = alc861_adc_nids,
667 .input_mux = &alc861_capture_source,
668 },
669 [ALC861_UNIWILL_M31] = {
670 .mixers = { alc861_uniwill_m31_mixer },
671 .init_verbs = { alc861_uniwill_m31_init_verbs },
672 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
673 .dac_nids = alc861_dac_nids,
674 .dig_out_nid = ALC861_DIGOUT_NID,
675 .num_channel_mode = ARRAY_SIZE(alc861_uniwill_m31_modes),
676 .channel_mode = alc861_uniwill_m31_modes,
677 .need_dac_fix = 1,
678 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
679 .adc_nids = alc861_adc_nids,
680 .input_mux = &alc861_capture_source,
681 },
682 [ALC861_TOSHIBA] = {
683 .mixers = { alc861_toshiba_mixer },
684 .init_verbs = { alc861_base_init_verbs,
685 alc861_toshiba_init_verbs },
686 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
687 .dac_nids = alc861_dac_nids,
688 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
689 .channel_mode = alc883_3ST_2ch_modes,
690 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
691 .adc_nids = alc861_adc_nids,
692 .input_mux = &alc861_capture_source,
693 .unsol_event = alc861_toshiba_unsol_event,
694 .init_hook = alc861_toshiba_automute,
695 },
696 [ALC861_ASUS] = {
697 .mixers = { alc861_asus_mixer },
698 .init_verbs = { alc861_asus_init_verbs },
699 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
700 .dac_nids = alc861_dac_nids,
701 .dig_out_nid = ALC861_DIGOUT_NID,
702 .num_channel_mode = ARRAY_SIZE(alc861_asus_modes),
703 .channel_mode = alc861_asus_modes,
704 .need_dac_fix = 1,
705 .hp_nid = 0x06,
706 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
707 .adc_nids = alc861_adc_nids,
708 .input_mux = &alc861_capture_source,
709 },
710 [ALC861_ASUS_LAPTOP] = {
711 .mixers = { alc861_toshiba_mixer, alc861_asus_laptop_mixer },
712 .init_verbs = { alc861_asus_init_verbs,
713 alc861_asus_laptop_init_verbs },
714 .num_dacs = ARRAY_SIZE(alc861_dac_nids),
715 .dac_nids = alc861_dac_nids,
716 .dig_out_nid = ALC861_DIGOUT_NID,
717 .num_channel_mode = ARRAY_SIZE(alc883_3ST_2ch_modes),
718 .channel_mode = alc883_3ST_2ch_modes,
719 .need_dac_fix = 1,
720 .num_adc_nids = ARRAY_SIZE(alc861_adc_nids),
721 .adc_nids = alc861_adc_nids,
722 .input_mux = &alc861_capture_source,
723 },
724};
725
diff --git a/sound/pci/hda/alc861vd_quirks.c b/sound/pci/hda/alc861vd_quirks.c
deleted file mode 100644
index 8f28450f41f8..000000000000
--- a/sound/pci/hda/alc861vd_quirks.c
+++ /dev/null
@@ -1,605 +0,0 @@
1/*
2 * ALC660-VD/ALC861-VD quirk models
3 * included by patch_realtek.c
4 */
5
6/* ALC861-VD models */
7enum {
8 ALC861VD_AUTO,
9 ALC660VD_3ST,
10 ALC660VD_3ST_DIG,
11 ALC660VD_ASUS_V1S,
12 ALC861VD_3ST,
13 ALC861VD_3ST_DIG,
14 ALC861VD_6ST_DIG,
15 ALC861VD_LENOVO,
16 ALC861VD_DALLAS,
17 ALC861VD_HP,
18 ALC861VD_MODEL_LAST,
19};
20
21#define ALC861VD_DIGOUT_NID 0x06
22
23static const hda_nid_t alc861vd_dac_nids[4] = {
24 /* front, surr, clfe, side surr */
25 0x02, 0x03, 0x04, 0x05
26};
27
28/* dac_nids for ALC660vd are in a different order - according to
29 * Realtek's driver.
30 * This should probably result in a different mixer for 6stack models
31 * of ALC660vd codecs, but for now there is only 3stack mixer
32 * - and it is the same as in 861vd.
33 * adc_nids in ALC660vd are (is) the same as in 861vd
34 */
35static const hda_nid_t alc660vd_dac_nids[3] = {
36 /* front, rear, clfe, rear_surr */
37 0x02, 0x04, 0x03
38};
39
40static const hda_nid_t alc861vd_adc_nids[1] = {
41 /* ADC0 */
42 0x09,
43};
44
45static const hda_nid_t alc861vd_capsrc_nids[1] = { 0x22 };
46
47/* input MUX */
48/* FIXME: should be a matrix-type input source selection */
49static const struct hda_input_mux alc861vd_capture_source = {
50 .num_items = 4,
51 .items = {
52 { "Mic", 0x0 },
53 { "Front Mic", 0x1 },
54 { "Line", 0x2 },
55 { "CD", 0x4 },
56 },
57};
58
59static const struct hda_input_mux alc861vd_dallas_capture_source = {
60 .num_items = 2,
61 .items = {
62 { "Mic", 0x0 },
63 { "Internal Mic", 0x1 },
64 },
65};
66
67static const struct hda_input_mux alc861vd_hp_capture_source = {
68 .num_items = 2,
69 .items = {
70 { "Front Mic", 0x0 },
71 { "ATAPI Mic", 0x1 },
72 },
73};
74
75/*
76 * 2ch mode
77 */
78static const struct hda_channel_mode alc861vd_3stack_2ch_modes[1] = {
79 { 2, NULL }
80};
81
82/*
83 * 6ch mode
84 */
85static const struct hda_verb alc861vd_6stack_ch6_init[] = {
86 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, 0x00 },
87 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
88 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
89 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
90 { } /* end */
91};
92
93/*
94 * 8ch mode
95 */
96static const struct hda_verb alc861vd_6stack_ch8_init[] = {
97 { 0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
98 { 0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
99 { 0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
100 { 0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT },
101 { } /* end */
102};
103
104static const struct hda_channel_mode alc861vd_6stack_modes[2] = {
105 { 6, alc861vd_6stack_ch6_init },
106 { 8, alc861vd_6stack_ch8_init },
107};
108
109static const struct snd_kcontrol_new alc861vd_chmode_mixer[] = {
110 {
111 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
112 .name = "Channel Mode",
113 .info = alc_ch_mode_info,
114 .get = alc_ch_mode_get,
115 .put = alc_ch_mode_put,
116 },
117 { } /* end */
118};
119
120/* Pin assignment: Front=0x14, Rear=0x15, CLFE=0x16, Side=0x17
121 * Mic=0x18, Front Mic=0x19, Line-In=0x1a, HP=0x1b
122 */
123static const struct snd_kcontrol_new alc861vd_6st_mixer[] = {
124 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
125 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
126
127 HDA_CODEC_VOLUME("Surround Playback Volume", 0x03, 0x0, HDA_OUTPUT),
128 HDA_BIND_MUTE("Surround Playback Switch", 0x0d, 2, HDA_INPUT),
129
130 HDA_CODEC_VOLUME_MONO("Center Playback Volume", 0x04, 1, 0x0,
131 HDA_OUTPUT),
132 HDA_CODEC_VOLUME_MONO("LFE Playback Volume", 0x04, 2, 0x0,
133 HDA_OUTPUT),
134 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x0e, 1, 2, HDA_INPUT),
135 HDA_BIND_MUTE_MONO("LFE Playback Switch", 0x0e, 2, 2, HDA_INPUT),
136
137 HDA_CODEC_VOLUME("Side Playback Volume", 0x05, 0x0, HDA_OUTPUT),
138 HDA_BIND_MUTE("Side Playback Switch", 0x0f, 2, HDA_INPUT),
139
140 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
141
142 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
143 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
144 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
145
146 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
147 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
148 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
149
150 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
151 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
152
153 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
154 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
155
156 { } /* end */
157};
158
159static const struct snd_kcontrol_new alc861vd_3st_mixer[] = {
160 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
161 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
162
163 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
164
165 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
166 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
167 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
168
169 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
170 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
171 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
172
173 HDA_CODEC_VOLUME("Line Playback Volume", 0x0b, 0x02, HDA_INPUT),
174 HDA_CODEC_MUTE("Line Playback Switch", 0x0b, 0x02, HDA_INPUT),
175
176 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
177 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
178
179 { } /* end */
180};
181
182static const struct snd_kcontrol_new alc861vd_lenovo_mixer[] = {
183 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
184 /*HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),*/
185 HDA_CODEC_MUTE("Front Playback Switch", 0x14, 0x0, HDA_OUTPUT),
186
187 HDA_CODEC_MUTE("Headphone Playback Switch", 0x1b, 0x0, HDA_OUTPUT),
188
189 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
190 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
191 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
192
193 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x19, 0, HDA_INPUT),
194 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
195 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
196
197 HDA_CODEC_VOLUME("CD Playback Volume", 0x0b, 0x04, HDA_INPUT),
198 HDA_CODEC_MUTE("CD Playback Switch", 0x0b, 0x04, HDA_INPUT),
199
200 { } /* end */
201};
202
203/* Pin assignment: Speaker=0x14, HP = 0x15,
204 * Mic=0x18, Internal Mic = 0x19, CD = 0x1c, PC Beep = 0x1d
205 */
206static const struct snd_kcontrol_new alc861vd_dallas_mixer[] = {
207 HDA_CODEC_VOLUME("Speaker Playback Volume", 0x02, 0x0, HDA_OUTPUT),
208 HDA_BIND_MUTE("Speaker Playback Switch", 0x0c, 2, HDA_INPUT),
209 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
210 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
211 HDA_CODEC_VOLUME("Mic Boost Volume", 0x18, 0, HDA_INPUT),
212 HDA_CODEC_VOLUME("Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
213 HDA_CODEC_MUTE("Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
214 HDA_CODEC_VOLUME("Internal Mic Boost Volume", 0x19, 0, HDA_INPUT),
215 HDA_CODEC_VOLUME("Internal Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
216 HDA_CODEC_MUTE("Internal Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
217 { } /* end */
218};
219
220/* Pin assignment: Speaker=0x14, Line-out = 0x15,
221 * Front Mic=0x18, ATAPI Mic = 0x19,
222 */
223static const struct snd_kcontrol_new alc861vd_hp_mixer[] = {
224 HDA_CODEC_VOLUME("Front Playback Volume", 0x02, 0x0, HDA_OUTPUT),
225 HDA_BIND_MUTE("Front Playback Switch", 0x0c, 2, HDA_INPUT),
226 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
227 HDA_BIND_MUTE("Headphone Playback Switch", 0x0d, 2, HDA_INPUT),
228 HDA_CODEC_VOLUME("Front Mic Playback Volume", 0x0b, 0x0, HDA_INPUT),
229 HDA_CODEC_MUTE("Front Mic Playback Switch", 0x0b, 0x0, HDA_INPUT),
230 HDA_CODEC_VOLUME("ATAPI Mic Playback Volume", 0x0b, 0x1, HDA_INPUT),
231 HDA_CODEC_MUTE("ATAPI Mic Playback Switch", 0x0b, 0x1, HDA_INPUT),
232
233 { } /* end */
234};
235
236/*
237 * generic initialization of ADC, input mixers and output mixers
238 */
239static const struct hda_verb alc861vd_volume_init_verbs[] = {
240 /*
241 * Unmute ADC0 and set the default input to mic-in
242 */
243 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
244 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
245
246 /* Unmute input amps (CD, Line In, Mic 1 & Mic 2) of
247 * the analog-loopback mixer widget
248 */
249 /* Amp Indices: Mic1 = 0, Mic2 = 1, Line1 = 2, Line2 = 3, CD = 4 */
250 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
251 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
252 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
253 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
254 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
255
256 /* Capture mixer: unmute Mic, F-Mic, Line, CD inputs */
257 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
258 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
259 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(2)},
260 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(4)},
261
262 /*
263 * Set up output mixers (0x02 - 0x05)
264 */
265 /* set vol=0 to output mixers */
266 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
267 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
268 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
269 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
270
271 /* set up input amps for analog loopback */
272 /* Amp Indices: DAC = 0, mixer = 1 */
273 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
274 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
275 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
276 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
277 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
278 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
279 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
280 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
281
282 { }
283};
284
285/*
286 * 3-stack pin configuration:
287 * front = 0x14, mic/clfe = 0x18, HP = 0x19, line/surr = 0x1a, f-mic = 0x1b
288 */
289static const struct hda_verb alc861vd_3stack_init_verbs[] = {
290 /*
291 * Set pin mode and muting
292 */
293 /* set front pin widgets 0x14 for output */
294 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
295 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
296 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
297
298 /* Mic (rear) pin: input vref at 80% */
299 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
300 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
301 /* Front Mic pin: input vref at 80% */
302 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
303 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
304 /* Line In pin: input */
305 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
306 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
307 /* Line-2 In: Headphone output (output 0 - 0x0c) */
308 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
309 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
310 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
311 /* CD pin widget for input */
312 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
313
314 { }
315};
316
317/*
318 * 6-stack pin configuration:
319 */
320static const struct hda_verb alc861vd_6stack_init_verbs[] = {
321 /*
322 * Set pin mode and muting
323 */
324 /* set front pin widgets 0x14 for output */
325 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
326 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
327 {0x14, AC_VERB_SET_CONNECT_SEL, 0x00},
328
329 /* Rear Pin: output 1 (0x0d) */
330 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
331 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
332 {0x15, AC_VERB_SET_CONNECT_SEL, 0x01},
333 /* CLFE Pin: output 2 (0x0e) */
334 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
335 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
336 {0x16, AC_VERB_SET_CONNECT_SEL, 0x02},
337 /* Side Pin: output 3 (0x0f) */
338 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
339 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
340 {0x17, AC_VERB_SET_CONNECT_SEL, 0x03},
341
342 /* Mic (rear) pin: input vref at 80% */
343 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
344 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
345 /* Front Mic pin: input vref at 80% */
346 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
347 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
348 /* Line In pin: input */
349 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
350 {0x1a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
351 /* Line-2 In: Headphone output (output 0 - 0x0c) */
352 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
353 {0x1b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
354 {0x1b, AC_VERB_SET_CONNECT_SEL, 0x00},
355 /* CD pin widget for input */
356 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
357
358 { }
359};
360
361static const struct hda_verb alc861vd_eapd_verbs[] = {
362 {0x14, AC_VERB_SET_EAPD_BTLENABLE, 2},
363 { }
364};
365
366static const struct hda_verb alc861vd_lenovo_unsol_verbs[] = {
367 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
368 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
369 {0x0b, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(5)},
370 {0x1b, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
371 {0x18, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_MIC_EVENT},
372 {}
373};
374
375static void alc861vd_lenovo_setup(struct hda_codec *codec)
376{
377 struct alc_spec *spec = codec->spec;
378 spec->autocfg.hp_pins[0] = 0x1b;
379 spec->autocfg.speaker_pins[0] = 0x14;
380 spec->automute = 1;
381 spec->automute_mode = ALC_AUTOMUTE_AMP;
382}
383
384static void alc861vd_lenovo_init_hook(struct hda_codec *codec)
385{
386 alc_hp_automute(codec);
387 alc88x_simple_mic_automute(codec);
388}
389
390static void alc861vd_lenovo_unsol_event(struct hda_codec *codec,
391 unsigned int res)
392{
393 switch (res >> 26) {
394 case ALC_MIC_EVENT:
395 alc88x_simple_mic_automute(codec);
396 break;
397 default:
398 alc_sku_unsol_event(codec, res);
399 break;
400 }
401}
402
403static const struct hda_verb alc861vd_dallas_verbs[] = {
404 {0x02, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
405 {0x03, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
406 {0x04, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
407 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_ZERO},
408
409 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
410 {0x0c, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1)},
411 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
412 {0x0d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
413 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
414 {0x0e, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
415 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
416 {0x0f, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
417
418 {0x14, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
419 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
420 {0x15, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
421 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
422 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
423 {0x16, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
424 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
425 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
426
427 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
428 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
429 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF50},
430 {0x19, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_MUTE},
431 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
432 {0x1b, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
433 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
434 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
435
436 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0)},
437 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(3)},
438 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(2)},
439 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(4)},
440
441 {0x09, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
442 {0x09, AC_VERB_SET_CONNECT_SEL, 0x00},
443 {0x15, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN | ALC_HP_EVENT},
444
445 { } /* end */
446};
447
448/* toggle speaker-output according to the hp-jack state */
449static void alc861vd_dallas_setup(struct hda_codec *codec)
450{
451 struct alc_spec *spec = codec->spec;
452
453 spec->autocfg.hp_pins[0] = 0x15;
454 spec->autocfg.speaker_pins[0] = 0x14;
455 spec->automute = 1;
456 spec->automute_mode = ALC_AUTOMUTE_AMP;
457}
458
459/*
460 * configuration and preset
461 */
462static const char * const alc861vd_models[ALC861VD_MODEL_LAST] = {
463 [ALC660VD_3ST] = "3stack-660",
464 [ALC660VD_3ST_DIG] = "3stack-660-digout",
465 [ALC660VD_ASUS_V1S] = "asus-v1s",
466 [ALC861VD_3ST] = "3stack",
467 [ALC861VD_3ST_DIG] = "3stack-digout",
468 [ALC861VD_6ST_DIG] = "6stack-digout",
469 [ALC861VD_LENOVO] = "lenovo",
470 [ALC861VD_DALLAS] = "dallas",
471 [ALC861VD_HP] = "hp",
472 [ALC861VD_AUTO] = "auto",
473};
474
475static const struct snd_pci_quirk alc861vd_cfg_tbl[] = {
476 SND_PCI_QUIRK(0x1019, 0xa88d, "Realtek ALC660 demo", ALC660VD_3ST),
477 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_HP),
478 SND_PCI_QUIRK(0x1043, 0x12e2, "Asus z35m", ALC660VD_3ST),
479 /*SND_PCI_QUIRK(0x1043, 0x1339, "Asus G1", ALC660VD_3ST),*/ /* auto */
480 SND_PCI_QUIRK(0x1043, 0x1633, "Asus V1Sn", ALC660VD_ASUS_V1S),
481 SND_PCI_QUIRK(0x1043, 0x81e7, "ASUS", ALC660VD_3ST_DIG),
482 SND_PCI_QUIRK(0x10de, 0x03f0, "Realtek ALC660 demo", ALC660VD_3ST),
483 SND_PCI_QUIRK(0x1179, 0xff00, "Toshiba A135", ALC861VD_LENOVO),
484 /*SND_PCI_QUIRK(0x1179, 0xff00, "DALLAS", ALC861VD_DALLAS),*/ /*lenovo*/
485 SND_PCI_QUIRK(0x1179, 0xff01, "Toshiba A135", ALC861VD_LENOVO),
486 SND_PCI_QUIRK(0x1179, 0xff03, "Toshiba P205", ALC861VD_LENOVO),
487 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_DALLAS),
488 SND_PCI_QUIRK(0x1565, 0x820d, "Biostar NF61S SE", ALC861VD_6ST_DIG),
489 SND_PCI_QUIRK_VENDOR(0x17aa, "Lenovo", ALC861VD_LENOVO),
490 SND_PCI_QUIRK(0x1849, 0x0862, "ASRock K8NF6G-VSTA", ALC861VD_6ST_DIG),
491 {}
492};
493
494static const struct alc_config_preset alc861vd_presets[] = {
495 [ALC660VD_3ST] = {
496 .mixers = { alc861vd_3st_mixer },
497 .init_verbs = { alc861vd_volume_init_verbs,
498 alc861vd_3stack_init_verbs },
499 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
500 .dac_nids = alc660vd_dac_nids,
501 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
502 .channel_mode = alc861vd_3stack_2ch_modes,
503 .input_mux = &alc861vd_capture_source,
504 },
505 [ALC660VD_3ST_DIG] = {
506 .mixers = { alc861vd_3st_mixer },
507 .init_verbs = { alc861vd_volume_init_verbs,
508 alc861vd_3stack_init_verbs },
509 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
510 .dac_nids = alc660vd_dac_nids,
511 .dig_out_nid = ALC861VD_DIGOUT_NID,
512 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
513 .channel_mode = alc861vd_3stack_2ch_modes,
514 .input_mux = &alc861vd_capture_source,
515 },
516 [ALC861VD_3ST] = {
517 .mixers = { alc861vd_3st_mixer },
518 .init_verbs = { alc861vd_volume_init_verbs,
519 alc861vd_3stack_init_verbs },
520 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
521 .dac_nids = alc861vd_dac_nids,
522 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
523 .channel_mode = alc861vd_3stack_2ch_modes,
524 .input_mux = &alc861vd_capture_source,
525 },
526 [ALC861VD_3ST_DIG] = {
527 .mixers = { alc861vd_3st_mixer },
528 .init_verbs = { alc861vd_volume_init_verbs,
529 alc861vd_3stack_init_verbs },
530 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
531 .dac_nids = alc861vd_dac_nids,
532 .dig_out_nid = ALC861VD_DIGOUT_NID,
533 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
534 .channel_mode = alc861vd_3stack_2ch_modes,
535 .input_mux = &alc861vd_capture_source,
536 },
537 [ALC861VD_6ST_DIG] = {
538 .mixers = { alc861vd_6st_mixer, alc861vd_chmode_mixer },
539 .init_verbs = { alc861vd_volume_init_verbs,
540 alc861vd_6stack_init_verbs },
541 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
542 .dac_nids = alc861vd_dac_nids,
543 .dig_out_nid = ALC861VD_DIGOUT_NID,
544 .num_channel_mode = ARRAY_SIZE(alc861vd_6stack_modes),
545 .channel_mode = alc861vd_6stack_modes,
546 .input_mux = &alc861vd_capture_source,
547 },
548 [ALC861VD_LENOVO] = {
549 .mixers = { alc861vd_lenovo_mixer },
550 .init_verbs = { alc861vd_volume_init_verbs,
551 alc861vd_3stack_init_verbs,
552 alc861vd_eapd_verbs,
553 alc861vd_lenovo_unsol_verbs },
554 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
555 .dac_nids = alc660vd_dac_nids,
556 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
557 .channel_mode = alc861vd_3stack_2ch_modes,
558 .input_mux = &alc861vd_capture_source,
559 .unsol_event = alc861vd_lenovo_unsol_event,
560 .setup = alc861vd_lenovo_setup,
561 .init_hook = alc861vd_lenovo_init_hook,
562 },
563 [ALC861VD_DALLAS] = {
564 .mixers = { alc861vd_dallas_mixer },
565 .init_verbs = { alc861vd_dallas_verbs },
566 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
567 .dac_nids = alc861vd_dac_nids,
568 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
569 .channel_mode = alc861vd_3stack_2ch_modes,
570 .input_mux = &alc861vd_dallas_capture_source,
571 .unsol_event = alc_sku_unsol_event,
572 .setup = alc861vd_dallas_setup,
573 .init_hook = alc_hp_automute,
574 },
575 [ALC861VD_HP] = {
576 .mixers = { alc861vd_hp_mixer },
577 .init_verbs = { alc861vd_dallas_verbs, alc861vd_eapd_verbs },
578 .num_dacs = ARRAY_SIZE(alc861vd_dac_nids),
579 .dac_nids = alc861vd_dac_nids,
580 .dig_out_nid = ALC861VD_DIGOUT_NID,
581 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
582 .channel_mode = alc861vd_3stack_2ch_modes,
583 .input_mux = &alc861vd_hp_capture_source,
584 .unsol_event = alc_sku_unsol_event,
585 .setup = alc861vd_dallas_setup,
586 .init_hook = alc_hp_automute,
587 },
588 [ALC660VD_ASUS_V1S] = {
589 .mixers = { alc861vd_lenovo_mixer },
590 .init_verbs = { alc861vd_volume_init_verbs,
591 alc861vd_3stack_init_verbs,
592 alc861vd_eapd_verbs,
593 alc861vd_lenovo_unsol_verbs },
594 .num_dacs = ARRAY_SIZE(alc660vd_dac_nids),
595 .dac_nids = alc660vd_dac_nids,
596 .dig_out_nid = ALC861VD_DIGOUT_NID,
597 .num_channel_mode = ARRAY_SIZE(alc861vd_3stack_2ch_modes),
598 .channel_mode = alc861vd_3stack_2ch_modes,
599 .input_mux = &alc861vd_capture_source,
600 .unsol_event = alc861vd_lenovo_unsol_event,
601 .setup = alc861vd_lenovo_setup,
602 .init_hook = alc861vd_lenovo_init_hook,
603 },
604};
605
diff --git a/sound/pci/hda/alc880_quirks.c b/sound/pci/hda/alc880_quirks.c
index c844d2b59988..bea22edcfd8c 100644
--- a/sound/pci/hda/alc880_quirks.c
+++ b/sound/pci/hda/alc880_quirks.c
@@ -749,8 +749,7 @@ static void alc880_uniwill_setup(struct hda_codec *codec)
749 spec->autocfg.hp_pins[0] = 0x14; 749 spec->autocfg.hp_pins[0] = 0x14;
750 spec->autocfg.speaker_pins[0] = 0x15; 750 spec->autocfg.speaker_pins[0] = 0x15;
751 spec->autocfg.speaker_pins[0] = 0x16; 751 spec->autocfg.speaker_pins[0] = 0x16;
752 spec->automute = 1; 752 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
753 spec->automute_mode = ALC_AUTOMUTE_AMP;
754} 753}
755 754
756static void alc880_uniwill_init_hook(struct hda_codec *codec) 755static void alc880_uniwill_init_hook(struct hda_codec *codec)
@@ -781,8 +780,7 @@ static void alc880_uniwill_p53_setup(struct hda_codec *codec)
781 780
782 spec->autocfg.hp_pins[0] = 0x14; 781 spec->autocfg.hp_pins[0] = 0x14;
783 spec->autocfg.speaker_pins[0] = 0x15; 782 spec->autocfg.speaker_pins[0] = 0x15;
784 spec->automute = 1; 783 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
785 spec->automute_mode = ALC_AUTOMUTE_AMP;
786} 784}
787 785
788static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec) 786static void alc880_uniwill_p53_dcvol_automute(struct hda_codec *codec)
@@ -1051,8 +1049,7 @@ static void alc880_lg_setup(struct hda_codec *codec)
1051 1049
1052 spec->autocfg.hp_pins[0] = 0x1b; 1050 spec->autocfg.hp_pins[0] = 0x1b;
1053 spec->autocfg.speaker_pins[0] = 0x17; 1051 spec->autocfg.speaker_pins[0] = 0x17;
1054 spec->automute = 1; 1052 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
1055 spec->automute_mode = ALC_AUTOMUTE_AMP;
1056} 1053}
1057 1054
1058/* 1055/*
@@ -1137,8 +1134,7 @@ static void alc880_lg_lw_setup(struct hda_codec *codec)
1137 1134
1138 spec->autocfg.hp_pins[0] = 0x1b; 1135 spec->autocfg.hp_pins[0] = 0x1b;
1139 spec->autocfg.speaker_pins[0] = 0x14; 1136 spec->autocfg.speaker_pins[0] = 0x14;
1140 spec->automute = 1; 1137 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
1141 spec->automute_mode = ALC_AUTOMUTE_AMP;
1142} 1138}
1143 1139
1144static const struct snd_kcontrol_new alc880_medion_rim_mixer[] = { 1140static const struct snd_kcontrol_new alc880_medion_rim_mixer[] = {
@@ -1188,7 +1184,7 @@ static void alc880_medion_rim_automute(struct hda_codec *codec)
1188 struct alc_spec *spec = codec->spec; 1184 struct alc_spec *spec = codec->spec;
1189 alc_hp_automute(codec); 1185 alc_hp_automute(codec);
1190 /* toggle EAPD */ 1186 /* toggle EAPD */
1191 if (spec->jack_present) 1187 if (spec->hp_jack_present)
1192 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0); 1188 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 0);
1193 else 1189 else
1194 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2); 1190 snd_hda_codec_write(codec, 0x01, 0, AC_VERB_SET_GPIO_DATA, 2);
@@ -1210,8 +1206,7 @@ static void alc880_medion_rim_setup(struct hda_codec *codec)
1210 1206
1211 spec->autocfg.hp_pins[0] = 0x14; 1207 spec->autocfg.hp_pins[0] = 0x14;
1212 spec->autocfg.speaker_pins[0] = 0x1b; 1208 spec->autocfg.speaker_pins[0] = 0x1b;
1213 spec->automute = 1; 1209 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
1214 spec->automute_mode = ALC_AUTOMUTE_AMP;
1215} 1210}
1216 1211
1217#ifdef CONFIG_SND_HDA_POWER_SAVE 1212#ifdef CONFIG_SND_HDA_POWER_SAVE
diff --git a/sound/pci/hda/alc882_quirks.c b/sound/pci/hda/alc882_quirks.c
index 617d04723b82..e251514a26a4 100644
--- a/sound/pci/hda/alc882_quirks.c
+++ b/sound/pci/hda/alc882_quirks.c
@@ -173,8 +173,7 @@ static void alc889_automute_setup(struct hda_codec *codec)
173 spec->autocfg.speaker_pins[2] = 0x17; 173 spec->autocfg.speaker_pins[2] = 0x17;
174 spec->autocfg.speaker_pins[3] = 0x19; 174 spec->autocfg.speaker_pins[3] = 0x19;
175 spec->autocfg.speaker_pins[4] = 0x1a; 175 spec->autocfg.speaker_pins[4] = 0x1a;
176 spec->automute = 1; 176 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
177 spec->automute_mode = ALC_AUTOMUTE_AMP;
178} 177}
179 178
180static void alc889_intel_init_hook(struct hda_codec *codec) 179static void alc889_intel_init_hook(struct hda_codec *codec)
@@ -191,8 +190,7 @@ static void alc888_fujitsu_xa3530_setup(struct hda_codec *codec)
191 spec->autocfg.hp_pins[1] = 0x1b; /* hp */ 190 spec->autocfg.hp_pins[1] = 0x1b; /* hp */
192 spec->autocfg.speaker_pins[0] = 0x14; /* speaker */ 191 spec->autocfg.speaker_pins[0] = 0x14; /* speaker */
193 spec->autocfg.speaker_pins[1] = 0x15; /* bass */ 192 spec->autocfg.speaker_pins[1] = 0x15; /* bass */
194 spec->automute = 1; 193 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
195 spec->automute_mode = ALC_AUTOMUTE_AMP;
196} 194}
197 195
198/* 196/*
@@ -475,8 +473,7 @@ static void alc888_acer_aspire_4930g_setup(struct hda_codec *codec)
475 spec->autocfg.speaker_pins[0] = 0x14; 473 spec->autocfg.speaker_pins[0] = 0x14;
476 spec->autocfg.speaker_pins[1] = 0x16; 474 spec->autocfg.speaker_pins[1] = 0x16;
477 spec->autocfg.speaker_pins[2] = 0x17; 475 spec->autocfg.speaker_pins[2] = 0x17;
478 spec->automute = 1; 476 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
479 spec->automute_mode = ALC_AUTOMUTE_AMP;
480} 477}
481 478
482static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec) 479static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
@@ -487,8 +484,7 @@ static void alc888_acer_aspire_6530g_setup(struct hda_codec *codec)
487 spec->autocfg.speaker_pins[0] = 0x14; 484 spec->autocfg.speaker_pins[0] = 0x14;
488 spec->autocfg.speaker_pins[1] = 0x16; 485 spec->autocfg.speaker_pins[1] = 0x16;
489 spec->autocfg.speaker_pins[2] = 0x17; 486 spec->autocfg.speaker_pins[2] = 0x17;
490 spec->automute = 1; 487 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
491 spec->automute_mode = ALC_AUTOMUTE_AMP;
492} 488}
493 489
494static void alc888_acer_aspire_7730g_setup(struct hda_codec *codec) 490static void alc888_acer_aspire_7730g_setup(struct hda_codec *codec)
@@ -499,8 +495,7 @@ static void alc888_acer_aspire_7730g_setup(struct hda_codec *codec)
499 spec->autocfg.speaker_pins[0] = 0x14; 495 spec->autocfg.speaker_pins[0] = 0x14;
500 spec->autocfg.speaker_pins[1] = 0x16; 496 spec->autocfg.speaker_pins[1] = 0x16;
501 spec->autocfg.speaker_pins[2] = 0x17; 497 spec->autocfg.speaker_pins[2] = 0x17;
502 spec->automute = 1; 498 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
503 spec->automute_mode = ALC_AUTOMUTE_AMP;
504} 499}
505 500
506static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec) 501static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
@@ -511,8 +506,7 @@ static void alc889_acer_aspire_8930g_setup(struct hda_codec *codec)
511 spec->autocfg.speaker_pins[0] = 0x14; 506 spec->autocfg.speaker_pins[0] = 0x14;
512 spec->autocfg.speaker_pins[1] = 0x16; 507 spec->autocfg.speaker_pins[1] = 0x16;
513 spec->autocfg.speaker_pins[2] = 0x1b; 508 spec->autocfg.speaker_pins[2] = 0x1b;
514 spec->automute = 1; 509 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
515 spec->automute_mode = ALC_AUTOMUTE_AMP;
516} 510}
517 511
518#define ALC882_DIGOUT_NID 0x06 512#define ALC882_DIGOUT_NID 0x06
@@ -1711,8 +1705,7 @@ static void alc885_imac24_setup(struct hda_codec *codec)
1711 spec->autocfg.hp_pins[0] = 0x14; 1705 spec->autocfg.hp_pins[0] = 0x14;
1712 spec->autocfg.speaker_pins[0] = 0x18; 1706 spec->autocfg.speaker_pins[0] = 0x18;
1713 spec->autocfg.speaker_pins[1] = 0x1a; 1707 spec->autocfg.speaker_pins[1] = 0x1a;
1714 spec->automute = 1; 1708 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
1715 spec->automute_mode = ALC_AUTOMUTE_AMP;
1716} 1709}
1717 1710
1718#define alc885_mb5_setup alc885_imac24_setup 1711#define alc885_mb5_setup alc885_imac24_setup
@@ -1721,12 +1714,11 @@ static void alc885_imac24_setup(struct hda_codec *codec)
1721/* Macbook Air 2,1 */ 1714/* Macbook Air 2,1 */
1722static void alc885_mba21_setup(struct hda_codec *codec) 1715static void alc885_mba21_setup(struct hda_codec *codec)
1723{ 1716{
1724 struct alc_spec *spec = codec->spec; 1717 struct alc_spec *spec = codec->spec;
1725 1718
1726 spec->autocfg.hp_pins[0] = 0x14; 1719 spec->autocfg.hp_pins[0] = 0x14;
1727 spec->autocfg.speaker_pins[0] = 0x18; 1720 spec->autocfg.speaker_pins[0] = 0x18;
1728 spec->automute = 1; 1721 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
1729 spec->automute_mode = ALC_AUTOMUTE_AMP;
1730} 1722}
1731 1723
1732 1724
@@ -1737,8 +1729,7 @@ static void alc885_mbp3_setup(struct hda_codec *codec)
1737 1729
1738 spec->autocfg.hp_pins[0] = 0x15; 1730 spec->autocfg.hp_pins[0] = 0x15;
1739 spec->autocfg.speaker_pins[0] = 0x14; 1731 spec->autocfg.speaker_pins[0] = 0x14;
1740 spec->automute = 1; 1732 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
1741 spec->automute_mode = ALC_AUTOMUTE_AMP;
1742} 1733}
1743 1734
1744static void alc885_imac91_setup(struct hda_codec *codec) 1735static void alc885_imac91_setup(struct hda_codec *codec)
@@ -1748,8 +1739,7 @@ static void alc885_imac91_setup(struct hda_codec *codec)
1748 spec->autocfg.hp_pins[0] = 0x14; 1739 spec->autocfg.hp_pins[0] = 0x14;
1749 spec->autocfg.speaker_pins[0] = 0x18; 1740 spec->autocfg.speaker_pins[0] = 0x18;
1750 spec->autocfg.speaker_pins[1] = 0x1a; 1741 spec->autocfg.speaker_pins[1] = 0x1a;
1751 spec->automute = 1; 1742 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
1752 spec->automute_mode = ALC_AUTOMUTE_AMP;
1753} 1743}
1754 1744
1755static const struct hda_verb alc882_targa_verbs[] = { 1745static const struct hda_verb alc882_targa_verbs[] = {
@@ -1773,7 +1763,7 @@ static void alc882_targa_automute(struct hda_codec *codec)
1773 struct alc_spec *spec = codec->spec; 1763 struct alc_spec *spec = codec->spec;
1774 alc_hp_automute(codec); 1764 alc_hp_automute(codec);
1775 snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA, 1765 snd_hda_codec_write_cache(codec, 1, 0, AC_VERB_SET_GPIO_DATA,
1776 spec->jack_present ? 1 : 3); 1766 spec->hp_jack_present ? 1 : 3);
1777} 1767}
1778 1768
1779static void alc882_targa_setup(struct hda_codec *codec) 1769static void alc882_targa_setup(struct hda_codec *codec)
@@ -1782,8 +1772,7 @@ static void alc882_targa_setup(struct hda_codec *codec)
1782 1772
1783 spec->autocfg.hp_pins[0] = 0x14; 1773 spec->autocfg.hp_pins[0] = 0x14;
1784 spec->autocfg.speaker_pins[0] = 0x1b; 1774 spec->autocfg.speaker_pins[0] = 0x1b;
1785 spec->automute = 1; 1775 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
1786 spec->automute_mode = ALC_AUTOMUTE_AMP;
1787} 1776}
1788 1777
1789static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res) 1778static void alc882_targa_unsol_event(struct hda_codec *codec, unsigned int res)
@@ -2187,8 +2176,7 @@ static void alc883_medion_wim2160_setup(struct hda_codec *codec)
2187 2176
2188 spec->autocfg.hp_pins[0] = 0x1a; 2177 spec->autocfg.hp_pins[0] = 0x1a;
2189 spec->autocfg.speaker_pins[0] = 0x15; 2178 spec->autocfg.speaker_pins[0] = 0x15;
2190 spec->automute = 1; 2179 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2191 spec->automute_mode = ALC_AUTOMUTE_AMP;
2192} 2180}
2193 2181
2194static const struct snd_kcontrol_new alc883_acer_aspire_mixer[] = { 2182static const struct snd_kcontrol_new alc883_acer_aspire_mixer[] = {
@@ -2341,8 +2329,7 @@ static void alc883_mitac_setup(struct hda_codec *codec)
2341 spec->autocfg.hp_pins[0] = 0x15; 2329 spec->autocfg.hp_pins[0] = 0x15;
2342 spec->autocfg.speaker_pins[0] = 0x14; 2330 spec->autocfg.speaker_pins[0] = 0x14;
2343 spec->autocfg.speaker_pins[1] = 0x17; 2331 spec->autocfg.speaker_pins[1] = 0x17;
2344 spec->automute = 1; 2332 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2345 spec->automute_mode = ALC_AUTOMUTE_AMP;
2346} 2333}
2347 2334
2348static const struct hda_verb alc883_mitac_verbs[] = { 2335static const struct hda_verb alc883_mitac_verbs[] = {
@@ -2507,8 +2494,7 @@ static void alc888_3st_hp_setup(struct hda_codec *codec)
2507 spec->autocfg.speaker_pins[0] = 0x14; 2494 spec->autocfg.speaker_pins[0] = 0x14;
2508 spec->autocfg.speaker_pins[1] = 0x16; 2495 spec->autocfg.speaker_pins[1] = 0x16;
2509 spec->autocfg.speaker_pins[2] = 0x18; 2496 spec->autocfg.speaker_pins[2] = 0x18;
2510 spec->automute = 1; 2497 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2511 spec->automute_mode = ALC_AUTOMUTE_AMP;
2512} 2498}
2513 2499
2514static const struct hda_verb alc888_3st_hp_verbs[] = { 2500static const struct hda_verb alc888_3st_hp_verbs[] = {
@@ -2568,8 +2554,7 @@ static void alc888_lenovo_ms7195_setup(struct hda_codec *codec)
2568 spec->autocfg.hp_pins[0] = 0x1b; 2554 spec->autocfg.hp_pins[0] = 0x1b;
2569 spec->autocfg.line_out_pins[0] = 0x14; 2555 spec->autocfg.line_out_pins[0] = 0x14;
2570 spec->autocfg.speaker_pins[0] = 0x15; 2556 spec->autocfg.speaker_pins[0] = 0x15;
2571 spec->automute = 1; 2557 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2572 spec->automute_mode = ALC_AUTOMUTE_AMP;
2573} 2558}
2574 2559
2575/* toggle speaker-output according to the hp-jack state */ 2560/* toggle speaker-output according to the hp-jack state */
@@ -2579,8 +2564,7 @@ static void alc883_lenovo_nb0763_setup(struct hda_codec *codec)
2579 2564
2580 spec->autocfg.hp_pins[0] = 0x14; 2565 spec->autocfg.hp_pins[0] = 0x14;
2581 spec->autocfg.speaker_pins[0] = 0x15; 2566 spec->autocfg.speaker_pins[0] = 0x15;
2582 spec->automute = 1; 2567 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2583 spec->automute_mode = ALC_AUTOMUTE_AMP;
2584} 2568}
2585 2569
2586/* toggle speaker-output according to the hp-jack state */ 2570/* toggle speaker-output according to the hp-jack state */
@@ -2593,8 +2577,7 @@ static void alc883_clevo_m720_setup(struct hda_codec *codec)
2593 2577
2594 spec->autocfg.hp_pins[0] = 0x15; 2578 spec->autocfg.hp_pins[0] = 0x15;
2595 spec->autocfg.speaker_pins[0] = 0x14; 2579 spec->autocfg.speaker_pins[0] = 0x14;
2596 spec->automute = 1; 2580 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2597 spec->automute_mode = ALC_AUTOMUTE_AMP;
2598} 2581}
2599 2582
2600static void alc883_clevo_m720_init_hook(struct hda_codec *codec) 2583static void alc883_clevo_m720_init_hook(struct hda_codec *codec)
@@ -2623,8 +2606,7 @@ static void alc883_2ch_fujitsu_pi2515_setup(struct hda_codec *codec)
2623 2606
2624 spec->autocfg.hp_pins[0] = 0x14; 2607 spec->autocfg.hp_pins[0] = 0x14;
2625 spec->autocfg.speaker_pins[0] = 0x15; 2608 spec->autocfg.speaker_pins[0] = 0x15;
2626 spec->automute = 1; 2609 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2627 spec->automute_mode = ALC_AUTOMUTE_AMP;
2628} 2610}
2629 2611
2630static void alc883_haier_w66_setup(struct hda_codec *codec) 2612static void alc883_haier_w66_setup(struct hda_codec *codec)
@@ -2633,8 +2615,7 @@ static void alc883_haier_w66_setup(struct hda_codec *codec)
2633 2615
2634 spec->autocfg.hp_pins[0] = 0x1b; 2616 spec->autocfg.hp_pins[0] = 0x1b;
2635 spec->autocfg.speaker_pins[0] = 0x14; 2617 spec->autocfg.speaker_pins[0] = 0x14;
2636 spec->automute = 1; 2618 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2637 spec->automute_mode = ALC_AUTOMUTE_AMP;
2638} 2619}
2639 2620
2640static void alc883_lenovo_101e_setup(struct hda_codec *codec) 2621static void alc883_lenovo_101e_setup(struct hda_codec *codec)
@@ -2644,10 +2625,7 @@ static void alc883_lenovo_101e_setup(struct hda_codec *codec)
2644 spec->autocfg.hp_pins[0] = 0x1b; 2625 spec->autocfg.hp_pins[0] = 0x1b;
2645 spec->autocfg.line_out_pins[0] = 0x14; 2626 spec->autocfg.line_out_pins[0] = 0x14;
2646 spec->autocfg.speaker_pins[0] = 0x15; 2627 spec->autocfg.speaker_pins[0] = 0x15;
2647 spec->automute = 1; 2628 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2648 spec->detect_line = 1;
2649 spec->automute_lines = 1;
2650 spec->automute_mode = ALC_AUTOMUTE_AMP;
2651} 2629}
2652 2630
2653/* toggle speaker-output according to the hp-jack state */ 2631/* toggle speaker-output according to the hp-jack state */
@@ -2658,8 +2636,7 @@ static void alc883_acer_aspire_setup(struct hda_codec *codec)
2658 spec->autocfg.hp_pins[0] = 0x14; 2636 spec->autocfg.hp_pins[0] = 0x14;
2659 spec->autocfg.speaker_pins[0] = 0x15; 2637 spec->autocfg.speaker_pins[0] = 0x15;
2660 spec->autocfg.speaker_pins[1] = 0x16; 2638 spec->autocfg.speaker_pins[1] = 0x16;
2661 spec->automute = 1; 2639 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2662 spec->automute_mode = ALC_AUTOMUTE_AMP;
2663} 2640}
2664 2641
2665static const struct hda_verb alc883_acer_eapd_verbs[] = { 2642static const struct hda_verb alc883_acer_eapd_verbs[] = {
@@ -2689,8 +2666,7 @@ static void alc888_6st_dell_setup(struct hda_codec *codec)
2689 spec->autocfg.speaker_pins[1] = 0x15; 2666 spec->autocfg.speaker_pins[1] = 0x15;
2690 spec->autocfg.speaker_pins[2] = 0x16; 2667 spec->autocfg.speaker_pins[2] = 0x16;
2691 spec->autocfg.speaker_pins[3] = 0x17; 2668 spec->autocfg.speaker_pins[3] = 0x17;
2692 spec->automute = 1; 2669 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2693 spec->automute_mode = ALC_AUTOMUTE_AMP;
2694} 2670}
2695 2671
2696static void alc888_lenovo_sky_setup(struct hda_codec *codec) 2672static void alc888_lenovo_sky_setup(struct hda_codec *codec)
@@ -2703,8 +2679,7 @@ static void alc888_lenovo_sky_setup(struct hda_codec *codec)
2703 spec->autocfg.speaker_pins[2] = 0x16; 2679 spec->autocfg.speaker_pins[2] = 0x16;
2704 spec->autocfg.speaker_pins[3] = 0x17; 2680 spec->autocfg.speaker_pins[3] = 0x17;
2705 spec->autocfg.speaker_pins[4] = 0x1a; 2681 spec->autocfg.speaker_pins[4] = 0x1a;
2706 spec->automute = 1; 2682 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2707 spec->automute_mode = ALC_AUTOMUTE_AMP;
2708} 2683}
2709 2684
2710static void alc883_vaiott_setup(struct hda_codec *codec) 2685static void alc883_vaiott_setup(struct hda_codec *codec)
@@ -2714,8 +2689,7 @@ static void alc883_vaiott_setup(struct hda_codec *codec)
2714 spec->autocfg.hp_pins[0] = 0x15; 2689 spec->autocfg.hp_pins[0] = 0x15;
2715 spec->autocfg.speaker_pins[0] = 0x14; 2690 spec->autocfg.speaker_pins[0] = 0x14;
2716 spec->autocfg.speaker_pins[1] = 0x17; 2691 spec->autocfg.speaker_pins[1] = 0x17;
2717 spec->automute = 1; 2692 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2718 spec->automute_mode = ALC_AUTOMUTE_AMP;
2719} 2693}
2720 2694
2721static const struct hda_verb alc888_asus_m90v_verbs[] = { 2695static const struct hda_verb alc888_asus_m90v_verbs[] = {
@@ -2739,8 +2713,7 @@ static void alc883_mode2_setup(struct hda_codec *codec)
2739 spec->ext_mic_pin = 0x18; 2713 spec->ext_mic_pin = 0x18;
2740 spec->int_mic_pin = 0x19; 2714 spec->int_mic_pin = 0x19;
2741 spec->auto_mic = 1; 2715 spec->auto_mic = 1;
2742 spec->automute = 1; 2716 alc_simple_setup_automute(spec, ALC_AUTOMUTE_AMP);
2743 spec->automute_mode = ALC_AUTOMUTE_AMP;
2744} 2717}
2745 2718
2746static const struct hda_verb alc888_asus_eee1601_verbs[] = { 2719static const struct hda_verb alc888_asus_eee1601_verbs[] = {
diff --git a/sound/pci/hda/alc_quirks.c b/sound/pci/hda/alc_quirks.c
index 2be1129cf458..a18952ed4311 100644
--- a/sound/pci/hda/alc_quirks.c
+++ b/sound/pci/hda/alc_quirks.c
@@ -453,6 +453,19 @@ static void setup_preset(struct hda_codec *codec,
453 alc_fixup_autocfg_pin_nums(codec); 453 alc_fixup_autocfg_pin_nums(codec);
454} 454}
455 455
456static void alc_simple_setup_automute(struct alc_spec *spec, int mode)
457{
458 int lo_pin = spec->autocfg.line_out_pins[0];
459
460 if (lo_pin == spec->autocfg.speaker_pins[0] ||
461 lo_pin == spec->autocfg.hp_pins[0])
462 lo_pin = 0;
463 spec->automute_mode = mode;
464 spec->detect_hp = !!spec->autocfg.hp_pins[0];
465 spec->detect_lo = !!lo_pin;
466 spec->automute_lo = spec->automute_lo_possible = !!lo_pin;
467 spec->automute_speaker = spec->automute_speaker_possible = !!spec->autocfg.speaker_pins[0];
468}
456 469
457/* auto-toggle front mic */ 470/* auto-toggle front mic */
458static void alc88x_simple_mic_automute(struct hda_codec *codec) 471static void alc88x_simple_mic_automute(struct hda_codec *codec)
diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
index 3e7850c238c3..1715e8b24ff0 100644
--- a/sound/pci/hda/hda_codec.c
+++ b/sound/pci/hda/hda_codec.c
@@ -34,6 +34,9 @@
34#include "hda_beep.h" 34#include "hda_beep.h"
35#include <sound/hda_hwdep.h> 35#include <sound/hda_hwdep.h>
36 36
37#define CREATE_TRACE_POINTS
38#include "hda_trace.h"
39
37/* 40/*
38 * vendor / preset table 41 * vendor / preset table
39 */ 42 */
@@ -208,15 +211,19 @@ static int codec_exec_verb(struct hda_codec *codec, unsigned int cmd,
208 again: 211 again:
209 snd_hda_power_up(codec); 212 snd_hda_power_up(codec);
210 mutex_lock(&bus->cmd_mutex); 213 mutex_lock(&bus->cmd_mutex);
214 trace_hda_send_cmd(codec, cmd);
211 err = bus->ops.command(bus, cmd); 215 err = bus->ops.command(bus, cmd);
212 if (!err && res) 216 if (!err && res) {
213 *res = bus->ops.get_response(bus, codec->addr); 217 *res = bus->ops.get_response(bus, codec->addr);
218 trace_hda_get_response(codec, *res);
219 }
214 mutex_unlock(&bus->cmd_mutex); 220 mutex_unlock(&bus->cmd_mutex);
215 snd_hda_power_down(codec); 221 snd_hda_power_down(codec);
216 if (res && *res == -1 && bus->rirb_error) { 222 if (res && *res == -1 && bus->rirb_error) {
217 if (bus->response_reset) { 223 if (bus->response_reset) {
218 snd_printd("hda_codec: resetting BUS due to " 224 snd_printd("hda_codec: resetting BUS due to "
219 "fatal communication error\n"); 225 "fatal communication error\n");
226 trace_hda_bus_reset(bus);
220 bus->ops.bus_reset(bus); 227 bus->ops.bus_reset(bus);
221 } 228 }
222 goto again; 229 goto again;
@@ -579,9 +586,13 @@ int snd_hda_get_conn_index(struct hda_codec *codec, hda_nid_t mux,
579 return -1; 586 return -1;
580 } 587 }
581 recursive++; 588 recursive++;
582 for (i = 0; i < nums; i++) 589 for (i = 0; i < nums; i++) {
590 unsigned int type = get_wcaps_type(get_wcaps(codec, conn[i]));
591 if (type == AC_WID_PIN || type == AC_WID_AUD_OUT)
592 continue;
583 if (snd_hda_get_conn_index(codec, conn[i], nid, recursive) >= 0) 593 if (snd_hda_get_conn_index(codec, conn[i], nid, recursive) >= 0)
584 return i; 594 return i;
595 }
585 return -1; 596 return -1;
586} 597}
587EXPORT_SYMBOL_HDA(snd_hda_get_conn_index); 598EXPORT_SYMBOL_HDA(snd_hda_get_conn_index);
@@ -603,6 +614,7 @@ int snd_hda_queue_unsol_event(struct hda_bus *bus, u32 res, u32 res_ex)
603 struct hda_bus_unsolicited *unsol; 614 struct hda_bus_unsolicited *unsol;
604 unsigned int wp; 615 unsigned int wp;
605 616
617 trace_hda_unsol_event(bus, res, res_ex);
606 unsol = bus->unsol; 618 unsol = bus->unsol;
607 if (!unsol) 619 if (!unsol)
608 return 0; 620 return 0;
@@ -1479,8 +1491,11 @@ static void really_cleanup_stream(struct hda_codec *codec,
1479 struct hda_cvt_setup *q) 1491 struct hda_cvt_setup *q)
1480{ 1492{
1481 hda_nid_t nid = q->nid; 1493 hda_nid_t nid = q->nid;
1482 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0); 1494 if (q->stream_tag || q->channel_id)
1483 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0); 1495 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_CHANNEL_STREAMID, 0);
1496 if (q->format_id)
1497 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_STREAM_FORMAT, 0
1498);
1484 memset(q, 0, sizeof(*q)); 1499 memset(q, 0, sizeof(*q));
1485 q->nid = nid; 1500 q->nid = nid;
1486} 1501}
@@ -1685,6 +1700,29 @@ u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid)
1685EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps); 1700EXPORT_SYMBOL_HDA(snd_hda_query_pin_caps);
1686 1701
1687/** 1702/**
1703 * snd_hda_override_pin_caps - Override the pin capabilities
1704 * @codec: the CODEC
1705 * @nid: the NID to override
1706 * @caps: the capability bits to set
1707 *
1708 * Override the cached PIN capabilitiy bits value by the given one.
1709 *
1710 * Returns zero if successful or a negative error code.
1711 */
1712int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
1713 unsigned int caps)
1714{
1715 struct hda_amp_info *info;
1716 info = get_alloc_amp_hash(codec, HDA_HASH_PINCAP_KEY(nid));
1717 if (!info)
1718 return -ENOMEM;
1719 info->amp_caps = caps;
1720 info->head.val |= INFO_AMP_CAPS;
1721 return 0;
1722}
1723EXPORT_SYMBOL_HDA(snd_hda_override_pin_caps);
1724
1725/**
1688 * snd_hda_pin_sense - execute pin sense measurement 1726 * snd_hda_pin_sense - execute pin sense measurement
1689 * @codec: the CODEC to sense 1727 * @codec: the CODEC to sense
1690 * @nid: the pin NID to sense 1728 * @nid: the pin NID to sense
@@ -4083,6 +4121,7 @@ static void hda_power_work(struct work_struct *work)
4083 return; 4121 return;
4084 } 4122 }
4085 4123
4124 trace_hda_power_down(codec);
4086 hda_call_codec_suspend(codec); 4125 hda_call_codec_suspend(codec);
4087 if (bus->ops.pm_notify) 4126 if (bus->ops.pm_notify)
4088 bus->ops.pm_notify(bus); 4127 bus->ops.pm_notify(bus);
@@ -4121,6 +4160,7 @@ void snd_hda_power_up(struct hda_codec *codec)
4121 if (codec->power_on || codec->power_transition) 4160 if (codec->power_on || codec->power_transition)
4122 return; 4161 return;
4123 4162
4163 trace_hda_power_up(codec);
4124 snd_hda_update_power_acct(codec); 4164 snd_hda_update_power_acct(codec);
4125 codec->power_on = 1; 4165 codec->power_on = 1;
4126 codec->power_jiffies = jiffies; 4166 codec->power_jiffies = jiffies;
@@ -4533,6 +4573,11 @@ int snd_hda_multi_out_analog_prepare(struct hda_codec *codec,
4533 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag, 4573 snd_hda_codec_setup_stream(codec, mout->hp_nid, stream_tag,
4534 0, format); 4574 0, format);
4535 /* extra outputs copied from front */ 4575 /* extra outputs copied from front */
4576 for (i = 0; i < ARRAY_SIZE(mout->hp_out_nid); i++)
4577 if (!mout->no_share_stream && mout->hp_out_nid[i])
4578 snd_hda_codec_setup_stream(codec,
4579 mout->hp_out_nid[i],
4580 stream_tag, 0, format);
4536 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) 4581 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
4537 if (!mout->no_share_stream && mout->extra_out_nid[i]) 4582 if (!mout->no_share_stream && mout->extra_out_nid[i])
4538 snd_hda_codec_setup_stream(codec, 4583 snd_hda_codec_setup_stream(codec,
@@ -4565,6 +4610,10 @@ int snd_hda_multi_out_analog_cleanup(struct hda_codec *codec,
4565 snd_hda_codec_cleanup_stream(codec, nids[i]); 4610 snd_hda_codec_cleanup_stream(codec, nids[i]);
4566 if (mout->hp_nid) 4611 if (mout->hp_nid)
4567 snd_hda_codec_cleanup_stream(codec, mout->hp_nid); 4612 snd_hda_codec_cleanup_stream(codec, mout->hp_nid);
4613 for (i = 0; i < ARRAY_SIZE(mout->hp_out_nid); i++)
4614 if (mout->hp_out_nid[i])
4615 snd_hda_codec_cleanup_stream(codec,
4616 mout->hp_out_nid[i]);
4568 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++) 4617 for (i = 0; i < ARRAY_SIZE(mout->extra_out_nid); i++)
4569 if (mout->extra_out_nid[i]) 4618 if (mout->extra_out_nid[i])
4570 snd_hda_codec_cleanup_stream(codec, 4619 snd_hda_codec_cleanup_stream(codec,
@@ -4645,6 +4694,27 @@ static void sort_autocfg_input_pins(struct auto_pin_cfg *cfg)
4645 } 4694 }
4646} 4695}
4647 4696
4697/* Reorder the surround channels
4698 * ALSA sequence is front/surr/clfe/side
4699 * HDA sequence is:
4700 * 4-ch: front/surr => OK as it is
4701 * 6-ch: front/clfe/surr
4702 * 8-ch: front/clfe/rear/side|fc
4703 */
4704static void reorder_outputs(unsigned int nums, hda_nid_t *pins)
4705{
4706 hda_nid_t nid;
4707
4708 switch (nums) {
4709 case 3:
4710 case 4:
4711 nid = pins[1];
4712 pins[1] = pins[2];
4713 pins[2] = nid;
4714 break;
4715 }
4716}
4717
4648/* 4718/*
4649 * Parse all pin widgets and store the useful pin nids to cfg 4719 * Parse all pin widgets and store the useful pin nids to cfg
4650 * 4720 *
@@ -4662,12 +4732,13 @@ static void sort_autocfg_input_pins(struct auto_pin_cfg *cfg)
4662 * The digital input/output pins are assigned to dig_in_pin and dig_out_pin, 4732 * The digital input/output pins are assigned to dig_in_pin and dig_out_pin,
4663 * respectively. 4733 * respectively.
4664 */ 4734 */
4665int snd_hda_parse_pin_def_config(struct hda_codec *codec, 4735int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
4666 struct auto_pin_cfg *cfg, 4736 struct auto_pin_cfg *cfg,
4667 const hda_nid_t *ignore_nids) 4737 const hda_nid_t *ignore_nids,
4738 unsigned int cond_flags)
4668{ 4739{
4669 hda_nid_t nid, end_nid; 4740 hda_nid_t nid, end_nid;
4670 short seq, assoc_line_out, assoc_speaker; 4741 short seq, assoc_line_out;
4671 short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)]; 4742 short sequences_line_out[ARRAY_SIZE(cfg->line_out_pins)];
4672 short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)]; 4743 short sequences_speaker[ARRAY_SIZE(cfg->speaker_pins)];
4673 short sequences_hp[ARRAY_SIZE(cfg->hp_pins)]; 4744 short sequences_hp[ARRAY_SIZE(cfg->hp_pins)];
@@ -4678,7 +4749,7 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
4678 memset(sequences_line_out, 0, sizeof(sequences_line_out)); 4749 memset(sequences_line_out, 0, sizeof(sequences_line_out));
4679 memset(sequences_speaker, 0, sizeof(sequences_speaker)); 4750 memset(sequences_speaker, 0, sizeof(sequences_speaker));
4680 memset(sequences_hp, 0, sizeof(sequences_hp)); 4751 memset(sequences_hp, 0, sizeof(sequences_hp));
4681 assoc_line_out = assoc_speaker = 0; 4752 assoc_line_out = 0;
4682 4753
4683 end_nid = codec->start_nid + codec->num_nodes; 4754 end_nid = codec->start_nid + codec->num_nodes;
4684 for (nid = codec->start_nid; nid < end_nid; nid++) { 4755 for (nid = codec->start_nid; nid < end_nid; nid++) {
@@ -4730,16 +4801,10 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
4730 case AC_JACK_SPEAKER: 4801 case AC_JACK_SPEAKER:
4731 seq = get_defcfg_sequence(def_conf); 4802 seq = get_defcfg_sequence(def_conf);
4732 assoc = get_defcfg_association(def_conf); 4803 assoc = get_defcfg_association(def_conf);
4733 if (!assoc)
4734 continue;
4735 if (!assoc_speaker)
4736 assoc_speaker = assoc;
4737 else if (assoc_speaker != assoc)
4738 continue;
4739 if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins)) 4804 if (cfg->speaker_outs >= ARRAY_SIZE(cfg->speaker_pins))
4740 continue; 4805 continue;
4741 cfg->speaker_pins[cfg->speaker_outs] = nid; 4806 cfg->speaker_pins[cfg->speaker_outs] = nid;
4742 sequences_speaker[cfg->speaker_outs] = seq; 4807 sequences_speaker[cfg->speaker_outs] = (assoc << 4) | seq;
4743 cfg->speaker_outs++; 4808 cfg->speaker_outs++;
4744 break; 4809 break;
4745 case AC_JACK_HP_OUT: 4810 case AC_JACK_HP_OUT:
@@ -4788,7 +4853,8 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
4788 * If no line-out is defined but multiple HPs are found, 4853 * If no line-out is defined but multiple HPs are found,
4789 * some of them might be the real line-outs. 4854 * some of them might be the real line-outs.
4790 */ 4855 */
4791 if (!cfg->line_outs && cfg->hp_outs > 1) { 4856 if (!cfg->line_outs && cfg->hp_outs > 1 &&
4857 !(cond_flags & HDA_PINCFG_NO_HP_FIXUP)) {
4792 int i = 0; 4858 int i = 0;
4793 while (i < cfg->hp_outs) { 4859 while (i < cfg->hp_outs) {
4794 /* The real HPs should have the sequence 0x0f */ 4860 /* The real HPs should have the sequence 0x0f */
@@ -4825,7 +4891,8 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
4825 * FIX-UP: if no line-outs are detected, try to use speaker or HP pin 4891 * FIX-UP: if no line-outs are detected, try to use speaker or HP pin
4826 * as a primary output 4892 * as a primary output
4827 */ 4893 */
4828 if (!cfg->line_outs) { 4894 if (!cfg->line_outs &&
4895 !(cond_flags & HDA_PINCFG_NO_LO_FIXUP)) {
4829 if (cfg->speaker_outs) { 4896 if (cfg->speaker_outs) {
4830 cfg->line_outs = cfg->speaker_outs; 4897 cfg->line_outs = cfg->speaker_outs;
4831 memcpy(cfg->line_out_pins, cfg->speaker_pins, 4898 memcpy(cfg->line_out_pins, cfg->speaker_pins,
@@ -4843,21 +4910,9 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
4843 } 4910 }
4844 } 4911 }
4845 4912
4846 /* Reorder the surround channels 4913 reorder_outputs(cfg->line_outs, cfg->line_out_pins);
4847 * ALSA sequence is front/surr/clfe/side 4914 reorder_outputs(cfg->hp_outs, cfg->hp_pins);
4848 * HDA sequence is: 4915 reorder_outputs(cfg->speaker_outs, cfg->speaker_pins);
4849 * 4-ch: front/surr => OK as it is
4850 * 6-ch: front/clfe/surr
4851 * 8-ch: front/clfe/rear/side|fc
4852 */
4853 switch (cfg->line_outs) {
4854 case 3:
4855 case 4:
4856 nid = cfg->line_out_pins[1];
4857 cfg->line_out_pins[1] = cfg->line_out_pins[2];
4858 cfg->line_out_pins[2] = nid;
4859 break;
4860 }
4861 4916
4862 sort_autocfg_input_pins(cfg); 4917 sort_autocfg_input_pins(cfg);
4863 4918
@@ -4895,7 +4950,7 @@ int snd_hda_parse_pin_def_config(struct hda_codec *codec,
4895 4950
4896 return 0; 4951 return 0;
4897} 4952}
4898EXPORT_SYMBOL_HDA(snd_hda_parse_pin_def_config); 4953EXPORT_SYMBOL_HDA(snd_hda_parse_pin_defcfg);
4899 4954
4900int snd_hda_get_input_pin_attr(unsigned int def_conf) 4955int snd_hda_get_input_pin_attr(unsigned int def_conf)
4901{ 4956{
@@ -5154,30 +5209,6 @@ void snd_array_free(struct snd_array *array)
5154EXPORT_SYMBOL_HDA(snd_array_free); 5209EXPORT_SYMBOL_HDA(snd_array_free);
5155 5210
5156/** 5211/**
5157 * snd_print_pcm_rates - Print the supported PCM rates to the string buffer
5158 * @pcm: PCM caps bits
5159 * @buf: the string buffer to write
5160 * @buflen: the max buffer length
5161 *
5162 * used by hda_proc.c and hda_eld.c
5163 */
5164void snd_print_pcm_rates(int pcm, char *buf, int buflen)
5165{
5166 static unsigned int rates[] = {
5167 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
5168 96000, 176400, 192000, 384000
5169 };
5170 int i, j;
5171
5172 for (i = 0, j = 0; i < ARRAY_SIZE(rates); i++)
5173 if (pcm & (1 << i))
5174 j += snprintf(buf + j, buflen - j, " %d", rates[i]);
5175
5176 buf[j] = '\0'; /* necessary when j == 0 */
5177}
5178EXPORT_SYMBOL_HDA(snd_print_pcm_rates);
5179
5180/**
5181 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer 5212 * snd_print_pcm_bits - Print the supported PCM fmt bits to the string buffer
5182 * @pcm: PCM caps bits 5213 * @pcm: PCM caps bits
5183 * @buf: the string buffer to write 5214 * @buf: the string buffer to write
@@ -5218,6 +5249,8 @@ static const char *get_jack_default_name(struct hda_codec *codec, hda_nid_t nid,
5218 return "Mic"; 5249 return "Mic";
5219 case SND_JACK_LINEOUT: 5250 case SND_JACK_LINEOUT:
5220 return "Line-out"; 5251 return "Line-out";
5252 case SND_JACK_LINEIN:
5253 return "Line-in";
5221 case SND_JACK_HEADSET: 5254 case SND_JACK_HEADSET:
5222 return "Headset"; 5255 return "Headset";
5223 case SND_JACK_VIDEOOUT: 5256 case SND_JACK_VIDEOOUT:
diff --git a/sound/pci/hda/hda_eld.c b/sound/pci/hda/hda_eld.c
index 28ce17d09c33..1c8ddf547a2d 100644
--- a/sound/pci/hda/hda_eld.c
+++ b/sound/pci/hda/hda_eld.c
@@ -144,25 +144,17 @@ static int cea_sampling_frequencies[8] = {
144 SNDRV_PCM_RATE_192000, /* 7: 192000Hz */ 144 SNDRV_PCM_RATE_192000, /* 7: 192000Hz */
145}; 145};
146 146
147static unsigned char hdmi_get_eld_byte(struct hda_codec *codec, hda_nid_t nid, 147static unsigned int hdmi_get_eld_data(struct hda_codec *codec, hda_nid_t nid,
148 int byte_index) 148 int byte_index)
149{ 149{
150 unsigned int val; 150 unsigned int val;
151 151
152 val = snd_hda_codec_read(codec, nid, 0, 152 val = snd_hda_codec_read(codec, nid, 0,
153 AC_VERB_GET_HDMI_ELDD, byte_index); 153 AC_VERB_GET_HDMI_ELDD, byte_index);
154
155#ifdef BE_PARANOID 154#ifdef BE_PARANOID
156 printk(KERN_INFO "HDMI: ELD data byte %d: 0x%x\n", byte_index, val); 155 printk(KERN_INFO "HDMI: ELD data byte %d: 0x%x\n", byte_index, val);
157#endif 156#endif
158 157 return val;
159 if ((val & AC_ELDD_ELD_VALID) == 0) {
160 snd_printd(KERN_INFO "HDMI: invalid ELD data byte %d\n",
161 byte_index);
162 val = 0;
163 }
164
165 return val & AC_ELDD_ELD_DATA;
166} 158}
167 159
168#define GRAB_BITS(buf, byte, lowbit, bits) \ 160#define GRAB_BITS(buf, byte, lowbit, bits) \
@@ -326,6 +318,11 @@ int snd_hdmi_get_eld(struct hdmi_eld *eld,
326 int size; 318 int size;
327 unsigned char *buf; 319 unsigned char *buf;
328 320
321 /*
322 * ELD size is initialized to zero in caller function. If no errors and
323 * ELD is valid, actual eld_size is assigned in hdmi_update_eld()
324 */
325
329 if (!eld->eld_valid) 326 if (!eld->eld_valid)
330 return -ENOENT; 327 return -ENOENT;
331 328
@@ -335,24 +332,59 @@ int snd_hdmi_get_eld(struct hdmi_eld *eld,
335 snd_printd(KERN_INFO "HDMI: ELD buf size is 0, force 128\n"); 332 snd_printd(KERN_INFO "HDMI: ELD buf size is 0, force 128\n");
336 size = 128; 333 size = 128;
337 } 334 }
338 if (size < ELD_FIXED_BYTES || size > PAGE_SIZE) { 335 if (size < ELD_FIXED_BYTES || size > ELD_MAX_SIZE) {
339 snd_printd(KERN_INFO "HDMI: invalid ELD buf size %d\n", size); 336 snd_printd(KERN_INFO "HDMI: invalid ELD buf size %d\n", size);
340 return -ERANGE; 337 return -ERANGE;
341 } 338 }
342 339
343 buf = kmalloc(size, GFP_KERNEL); 340 /* set ELD buffer */
344 if (!buf) 341 buf = eld->eld_buffer;
345 return -ENOMEM; 342
346 343 for (i = 0; i < size; i++) {
347 for (i = 0; i < size; i++) 344 unsigned int val = hdmi_get_eld_data(codec, nid, i);
348 buf[i] = hdmi_get_eld_byte(codec, nid, i); 345 if (!(val & AC_ELDD_ELD_VALID)) {
346 if (!i) {
347 snd_printd(KERN_INFO
348 "HDMI: invalid ELD data\n");
349 ret = -EINVAL;
350 goto error;
351 }
352 snd_printd(KERN_INFO
353 "HDMI: invalid ELD data byte %d\n", i);
354 val = 0;
355 } else
356 val &= AC_ELDD_ELD_DATA;
357 buf[i] = val;
358 }
349 359
350 ret = hdmi_update_eld(eld, buf, size); 360 ret = hdmi_update_eld(eld, buf, size);
351 361
352 kfree(buf); 362error:
353 return ret; 363 return ret;
354} 364}
355 365
366/**
367 * SNDRV_PCM_RATE_* and AC_PAR_PCM values don't match, print correct rates with
368 * hdmi-specific routine.
369 */
370static void hdmi_print_pcm_rates(int pcm, char *buf, int buflen)
371{
372 static unsigned int alsa_rates[] = {
373 5512, 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
374 96000, 176400, 192000, 384000
375 };
376 int i, j;
377
378 for (i = 0, j = 0; i < ARRAY_SIZE(alsa_rates); i++)
379 if (pcm & (1 << i))
380 j += snprintf(buf + j, buflen - j, " %d",
381 alsa_rates[i]);
382
383 buf[j] = '\0'; /* necessary when j == 0 */
384}
385
386#define SND_PRINT_RATES_ADVISED_BUFSIZE 80
387
356static void hdmi_show_short_audio_desc(struct cea_sad *a) 388static void hdmi_show_short_audio_desc(struct cea_sad *a)
357{ 389{
358 char buf[SND_PRINT_RATES_ADVISED_BUFSIZE]; 390 char buf[SND_PRINT_RATES_ADVISED_BUFSIZE];
@@ -361,7 +393,7 @@ static void hdmi_show_short_audio_desc(struct cea_sad *a)
361 if (!a->format) 393 if (!a->format)
362 return; 394 return;
363 395
364 snd_print_pcm_rates(a->rates, buf, sizeof(buf)); 396 hdmi_print_pcm_rates(a->rates, buf, sizeof(buf));
365 397
366 if (a->format == AUDIO_CODING_TYPE_LPCM) 398 if (a->format == AUDIO_CODING_TYPE_LPCM)
367 snd_print_pcm_bits(a->sample_bits, buf2 + 8, sizeof(buf2) - 8); 399 snd_print_pcm_bits(a->sample_bits, buf2 + 8, sizeof(buf2) - 8);
@@ -420,7 +452,7 @@ static void hdmi_print_sad_info(int i, struct cea_sad *a,
420 i, a->format, cea_audio_coding_type_names[a->format]); 452 i, a->format, cea_audio_coding_type_names[a->format]);
421 snd_iprintf(buffer, "sad%d_channels\t\t%d\n", i, a->channels); 453 snd_iprintf(buffer, "sad%d_channels\t\t%d\n", i, a->channels);
422 454
423 snd_print_pcm_rates(a->rates, buf, sizeof(buf)); 455 hdmi_print_pcm_rates(a->rates, buf, sizeof(buf));
424 snd_iprintf(buffer, "sad%d_rates\t\t[0x%x]%s\n", i, a->rates, buf); 456 snd_iprintf(buffer, "sad%d_rates\t\t[0x%x]%s\n", i, a->rates, buf);
425 457
426 if (a->format == AUDIO_CODING_TYPE_LPCM) { 458 if (a->format == AUDIO_CODING_TYPE_LPCM) {
diff --git a/sound/pci/hda/hda_hwdep.c b/sound/pci/hda/hda_hwdep.c
index bf3ced51e0f8..7e7d0788ddcf 100644
--- a/sound/pci/hda/hda_hwdep.c
+++ b/sound/pci/hda/hda_hwdep.c
@@ -643,14 +643,14 @@ static inline int strmatch(const char *a, const char *b)
643static void parse_codec_mode(char *buf, struct hda_bus *bus, 643static void parse_codec_mode(char *buf, struct hda_bus *bus,
644 struct hda_codec **codecp) 644 struct hda_codec **codecp)
645{ 645{
646 unsigned int vendorid, subid, caddr; 646 int vendorid, subid, caddr;
647 struct hda_codec *codec; 647 struct hda_codec *codec;
648 648
649 *codecp = NULL; 649 *codecp = NULL;
650 if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) { 650 if (sscanf(buf, "%i %i %i", &vendorid, &subid, &caddr) == 3) {
651 list_for_each_entry(codec, &bus->codec_list, list) { 651 list_for_each_entry(codec, &bus->codec_list, list) {
652 if (codec->vendor_id == vendorid && 652 if ((vendorid <= 0 || codec->vendor_id == vendorid) &&
653 codec->subsystem_id == subid && 653 (subid <= 0 || codec->subsystem_id == subid) &&
654 codec->addr == caddr) { 654 codec->addr == caddr) {
655 *codecp = codec; 655 *codecp = codec;
656 break; 656 break;
@@ -756,8 +756,6 @@ static int get_line_from_fw(char *buf, int size, struct firmware *fw)
756 } 756 }
757 if (!fw->size) 757 if (!fw->size)
758 return 0; 758 return 0;
759 if (size < fw->size)
760 size = fw->size;
761 759
762 for (len = 0; len < fw->size; len++) { 760 for (len = 0; len < fw->size; len++) {
763 if (!*p) 761 if (!*p)
diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c
index be6982289c0d..bd7fc99af187 100644
--- a/sound/pci/hda/hda_intel.c
+++ b/sound/pci/hda/hda_intel.c
@@ -34,7 +34,6 @@
34 * 34 *
35 */ 35 */
36 36
37#include <asm/io.h>
38#include <linux/delay.h> 37#include <linux/delay.h>
39#include <linux/interrupt.h> 38#include <linux/interrupt.h>
40#include <linux/kernel.h> 39#include <linux/kernel.h>
@@ -46,6 +45,12 @@
46#include <linux/pci.h> 45#include <linux/pci.h>
47#include <linux/mutex.h> 46#include <linux/mutex.h>
48#include <linux/reboot.h> 47#include <linux/reboot.h>
48#include <linux/io.h>
49#ifdef CONFIG_X86
50/* for snoop control */
51#include <asm/pgtable.h>
52#include <asm/cacheflush.h>
53#endif
49#include <sound/core.h> 54#include <sound/core.h>
50#include <sound/initval.h> 55#include <sound/initval.h>
51#include "hda_codec.h" 56#include "hda_codec.h"
@@ -116,6 +121,22 @@ module_param(power_save_controller, bool, 0644);
116MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode."); 121MODULE_PARM_DESC(power_save_controller, "Reset controller in power save mode.");
117#endif 122#endif
118 123
124static int align_buffer_size = 1;
125module_param(align_buffer_size, bool, 0644);
126MODULE_PARM_DESC(align_buffer_size,
127 "Force buffer and period sizes to be multiple of 128 bytes.");
128
129#ifdef CONFIG_X86
130static bool hda_snoop = true;
131module_param_named(snoop, hda_snoop, bool, 0444);
132MODULE_PARM_DESC(snoop, "Enable/disable snooping");
133#define azx_snoop(chip) (chip)->snoop
134#else
135#define hda_snoop true
136#define azx_snoop(chip) true
137#endif
138
139
119MODULE_LICENSE("GPL"); 140MODULE_LICENSE("GPL");
120MODULE_SUPPORTED_DEVICE("{{Intel, ICH6}," 141MODULE_SUPPORTED_DEVICE("{{Intel, ICH6},"
121 "{Intel, ICH6M}," 142 "{Intel, ICH6M},"
@@ -360,7 +381,7 @@ struct azx_dev {
360 */ 381 */
361 unsigned char stream_tag; /* assigned stream */ 382 unsigned char stream_tag; /* assigned stream */
362 unsigned char index; /* stream index */ 383 unsigned char index; /* stream index */
363 int device; /* last device number assigned to */ 384 int assigned_key; /* last device# key assigned to */
364 385
365 unsigned int opened :1; 386 unsigned int opened :1;
366 unsigned int running :1; 387 unsigned int running :1;
@@ -371,6 +392,7 @@ struct azx_dev {
371 * when link position is not greater than FIFO size 392 * when link position is not greater than FIFO size
372 */ 393 */
373 unsigned int insufficient :1; 394 unsigned int insufficient :1;
395 unsigned int wc_marked:1;
374}; 396};
375 397
376/* CORB/RIRB */ 398/* CORB/RIRB */
@@ -438,6 +460,7 @@ struct azx {
438 unsigned int msi :1; 460 unsigned int msi :1;
439 unsigned int irq_pending_warned :1; 461 unsigned int irq_pending_warned :1;
440 unsigned int probing :1; /* codec probing phase */ 462 unsigned int probing :1; /* codec probing phase */
463 unsigned int snoop:1;
441 464
442 /* for debugging */ 465 /* for debugging */
443 unsigned int last_cmd[AZX_MAX_CODECS]; 466 unsigned int last_cmd[AZX_MAX_CODECS];
@@ -481,6 +504,7 @@ enum {
481#define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */ 504#define AZX_DCAPS_NO_64BIT (1 << 18) /* No 64bit address */
482#define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */ 505#define AZX_DCAPS_SYNC_WRITE (1 << 19) /* sync each cmd write */
483#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */ 506#define AZX_DCAPS_OLD_SSYNC (1 << 20) /* Old SSYNC reg for ICH */
507#define AZX_DCAPS_BUFSIZE (1 << 21) /* no buffer size alignment */
484 508
485/* quirks for ATI SB / AMD Hudson */ 509/* quirks for ATI SB / AMD Hudson */
486#define AZX_DCAPS_PRESET_ATI_SB \ 510#define AZX_DCAPS_PRESET_ATI_SB \
@@ -542,6 +566,45 @@ static char *driver_short_names[] __devinitdata = {
542/* for pcm support */ 566/* for pcm support */
543#define get_azx_dev(substream) (substream->runtime->private_data) 567#define get_azx_dev(substream) (substream->runtime->private_data)
544 568
569#ifdef CONFIG_X86
570static void __mark_pages_wc(struct azx *chip, void *addr, size_t size, bool on)
571{
572 if (azx_snoop(chip))
573 return;
574 if (addr && size) {
575 int pages = (size + PAGE_SIZE - 1) >> PAGE_SHIFT;
576 if (on)
577 set_memory_wc((unsigned long)addr, pages);
578 else
579 set_memory_wb((unsigned long)addr, pages);
580 }
581}
582
583static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf,
584 bool on)
585{
586 __mark_pages_wc(chip, buf->area, buf->bytes, on);
587}
588static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev,
589 struct snd_pcm_runtime *runtime, bool on)
590{
591 if (azx_dev->wc_marked != on) {
592 __mark_pages_wc(chip, runtime->dma_area, runtime->dma_bytes, on);
593 azx_dev->wc_marked = on;
594 }
595}
596#else
597/* NOP for other archs */
598static inline void mark_pages_wc(struct azx *chip, struct snd_dma_buffer *buf,
599 bool on)
600{
601}
602static inline void mark_runtime_wc(struct azx *chip, struct azx_dev *azx_dev,
603 struct snd_pcm_runtime *runtime, bool on)
604{
605}
606#endif
607
545static int azx_acquire_irq(struct azx *chip, int do_disconnect); 608static int azx_acquire_irq(struct azx *chip, int do_disconnect);
546static int azx_send_cmd(struct hda_bus *bus, unsigned int val); 609static int azx_send_cmd(struct hda_bus *bus, unsigned int val);
547/* 610/*
@@ -563,6 +626,7 @@ static int azx_alloc_cmd_io(struct azx *chip)
563 snd_printk(KERN_ERR SFX "cannot allocate CORB/RIRB\n"); 626 snd_printk(KERN_ERR SFX "cannot allocate CORB/RIRB\n");
564 return err; 627 return err;
565 } 628 }
629 mark_pages_wc(chip, &chip->rb, true);
566 return 0; 630 return 0;
567} 631}
568 632
@@ -1079,7 +1143,15 @@ static void update_pci_byte(struct pci_dev *pci, unsigned int reg,
1079 1143
1080static void azx_init_pci(struct azx *chip) 1144static void azx_init_pci(struct azx *chip)
1081{ 1145{
1082 unsigned short snoop; 1146 /* force to non-snoop mode for a new VIA controller when BIOS is set */
1147 if (chip->snoop && chip->driver_type == AZX_DRIVER_VIA) {
1148 u8 snoop;
1149 pci_read_config_byte(chip->pci, 0x42, &snoop);
1150 if (!(snoop & 0x80) && chip->pci->revision == 0x30) {
1151 chip->snoop = 0;
1152 snd_printdd(SFX "Force to non-snoop mode\n");
1153 }
1154 }
1083 1155
1084 /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44) 1156 /* Clear bits 0-2 of PCI register TCSEL (at offset 0x44)
1085 * TCSEL == Traffic Class Select Register, which sets PCI express QOS 1157 * TCSEL == Traffic Class Select Register, which sets PCI express QOS
@@ -1096,15 +1168,15 @@ static void azx_init_pci(struct azx *chip)
1096 * we need to enable snoop. 1168 * we need to enable snoop.
1097 */ 1169 */
1098 if (chip->driver_caps & AZX_DCAPS_ATI_SNOOP) { 1170 if (chip->driver_caps & AZX_DCAPS_ATI_SNOOP) {
1099 snd_printdd(SFX "Enabling ATI snoop\n"); 1171 snd_printdd(SFX "Setting ATI snoop: %d\n", azx_snoop(chip));
1100 update_pci_byte(chip->pci, 1172 update_pci_byte(chip->pci,
1101 ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 1173 ATI_SB450_HDAUDIO_MISC_CNTR2_ADDR, 0x07,
1102 0x07, ATI_SB450_HDAUDIO_ENABLE_SNOOP); 1174 azx_snoop(chip) ? ATI_SB450_HDAUDIO_ENABLE_SNOOP : 0);
1103 } 1175 }
1104 1176
1105 /* For NVIDIA HDA, enable snoop */ 1177 /* For NVIDIA HDA, enable snoop */
1106 if (chip->driver_caps & AZX_DCAPS_NVIDIA_SNOOP) { 1178 if (chip->driver_caps & AZX_DCAPS_NVIDIA_SNOOP) {
1107 snd_printdd(SFX "Enabling Nvidia snoop\n"); 1179 snd_printdd(SFX "Setting Nvidia snoop: %d\n", azx_snoop(chip));
1108 update_pci_byte(chip->pci, 1180 update_pci_byte(chip->pci,
1109 NVIDIA_HDA_TRANSREG_ADDR, 1181 NVIDIA_HDA_TRANSREG_ADDR,
1110 0x0f, NVIDIA_HDA_ENABLE_COHBITS); 1182 0x0f, NVIDIA_HDA_ENABLE_COHBITS);
@@ -1118,16 +1190,20 @@ static void azx_init_pci(struct azx *chip)
1118 1190
1119 /* Enable SCH/PCH snoop if needed */ 1191 /* Enable SCH/PCH snoop if needed */
1120 if (chip->driver_caps & AZX_DCAPS_SCH_SNOOP) { 1192 if (chip->driver_caps & AZX_DCAPS_SCH_SNOOP) {
1193 unsigned short snoop;
1121 pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop); 1194 pci_read_config_word(chip->pci, INTEL_SCH_HDA_DEVC, &snoop);
1122 if (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP) { 1195 if ((!azx_snoop(chip) && !(snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)) ||
1123 pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC, 1196 (azx_snoop(chip) && (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP))) {
1124 snoop & (~INTEL_SCH_HDA_DEVC_NOSNOOP)); 1197 snoop &= ~INTEL_SCH_HDA_DEVC_NOSNOOP;
1198 if (!azx_snoop(chip))
1199 snoop |= INTEL_SCH_HDA_DEVC_NOSNOOP;
1200 pci_write_config_word(chip->pci, INTEL_SCH_HDA_DEVC, snoop);
1125 pci_read_config_word(chip->pci, 1201 pci_read_config_word(chip->pci,
1126 INTEL_SCH_HDA_DEVC, &snoop); 1202 INTEL_SCH_HDA_DEVC, &snoop);
1127 snd_printdd(SFX "HDA snoop disabled, enabling ... %s\n",
1128 (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)
1129 ? "Failed" : "OK");
1130 } 1203 }
1204 snd_printdd(SFX "SCH snoop: %s\n",
1205 (snoop & INTEL_SCH_HDA_DEVC_NOSNOOP)
1206 ? "Disabled" : "Enabled");
1131 } 1207 }
1132} 1208}
1133 1209
@@ -1334,12 +1410,16 @@ static void azx_stream_reset(struct azx *chip, struct azx_dev *azx_dev)
1334 */ 1410 */
1335static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev) 1411static int azx_setup_controller(struct azx *chip, struct azx_dev *azx_dev)
1336{ 1412{
1413 unsigned int val;
1337 /* make sure the run bit is zero for SD */ 1414 /* make sure the run bit is zero for SD */
1338 azx_stream_clear(chip, azx_dev); 1415 azx_stream_clear(chip, azx_dev);
1339 /* program the stream_tag */ 1416 /* program the stream_tag */
1340 azx_sd_writel(azx_dev, SD_CTL, 1417 val = azx_sd_readl(azx_dev, SD_CTL);
1341 (azx_sd_readl(azx_dev, SD_CTL) & ~SD_CTL_STREAM_TAG_MASK)| 1418 val = (val & ~SD_CTL_STREAM_TAG_MASK) |
1342 (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT)); 1419 (azx_dev->stream_tag << SD_CTL_STREAM_TAG_SHIFT);
1420 if (!azx_snoop(chip))
1421 val |= SD_CTL_TRAFFIC_PRIO;
1422 azx_sd_writel(azx_dev, SD_CTL, val);
1343 1423
1344 /* program the length of samples in cyclic buffer */ 1424 /* program the length of samples in cyclic buffer */
1345 azx_sd_writel(azx_dev, SD_CBL, azx_dev->bufsize); 1425 azx_sd_writel(azx_dev, SD_CBL, azx_dev->bufsize);
@@ -1533,6 +1613,9 @@ azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
1533{ 1613{
1534 int dev, i, nums; 1614 int dev, i, nums;
1535 struct azx_dev *res = NULL; 1615 struct azx_dev *res = NULL;
1616 /* make a non-zero unique key for the substream */
1617 int key = (substream->pcm->device << 16) | (substream->number << 2) |
1618 (substream->stream + 1);
1536 1619
1537 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) { 1620 if (substream->stream == SNDRV_PCM_STREAM_PLAYBACK) {
1538 dev = chip->playback_index_offset; 1621 dev = chip->playback_index_offset;
@@ -1544,12 +1627,12 @@ azx_assign_device(struct azx *chip, struct snd_pcm_substream *substream)
1544 for (i = 0; i < nums; i++, dev++) 1627 for (i = 0; i < nums; i++, dev++)
1545 if (!chip->azx_dev[dev].opened) { 1628 if (!chip->azx_dev[dev].opened) {
1546 res = &chip->azx_dev[dev]; 1629 res = &chip->azx_dev[dev];
1547 if (res->device == substream->pcm->device) 1630 if (res->assigned_key == key)
1548 break; 1631 break;
1549 } 1632 }
1550 if (res) { 1633 if (res) {
1551 res->opened = 1; 1634 res->opened = 1;
1552 res->device = substream->pcm->device; 1635 res->assigned_key = key;
1553 } 1636 }
1554 return res; 1637 return res;
1555} 1638}
@@ -1599,6 +1682,7 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
1599 struct snd_pcm_runtime *runtime = substream->runtime; 1682 struct snd_pcm_runtime *runtime = substream->runtime;
1600 unsigned long flags; 1683 unsigned long flags;
1601 int err; 1684 int err;
1685 int buff_step;
1602 1686
1603 mutex_lock(&chip->open_mutex); 1687 mutex_lock(&chip->open_mutex);
1604 azx_dev = azx_assign_device(chip, substream); 1688 azx_dev = azx_assign_device(chip, substream);
@@ -1613,10 +1697,25 @@ static int azx_pcm_open(struct snd_pcm_substream *substream)
1613 runtime->hw.rates = hinfo->rates; 1697 runtime->hw.rates = hinfo->rates;
1614 snd_pcm_limit_hw_rates(runtime); 1698 snd_pcm_limit_hw_rates(runtime);
1615 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS); 1699 snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS);
1700 if (align_buffer_size)
1701 /* constrain buffer sizes to be multiple of 128
1702 bytes. This is more efficient in terms of memory
1703 access but isn't required by the HDA spec and
1704 prevents users from specifying exact period/buffer
1705 sizes. For example for 44.1kHz, a period size set
1706 to 20ms will be rounded to 19.59ms. */
1707 buff_step = 128;
1708 else
1709 /* Don't enforce steps on buffer sizes, still need to
1710 be multiple of 4 bytes (HDA spec). Tested on Intel
1711 HDA controllers, may not work on all devices where
1712 option needs to be disabled */
1713 buff_step = 4;
1714
1616 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES, 1715 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_BUFFER_BYTES,
1617 128); 1716 buff_step);
1618 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES, 1717 snd_pcm_hw_constraint_step(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_BYTES,
1619 128); 1718 buff_step);
1620 snd_hda_power_up(apcm->codec); 1719 snd_hda_power_up(apcm->codec);
1621 err = hinfo->ops.open(hinfo, apcm->codec, substream); 1720 err = hinfo->ops.open(hinfo, apcm->codec, substream);
1622 if (err < 0) { 1721 if (err < 0) {
@@ -1671,19 +1770,30 @@ static int azx_pcm_close(struct snd_pcm_substream *substream)
1671static int azx_pcm_hw_params(struct snd_pcm_substream *substream, 1770static int azx_pcm_hw_params(struct snd_pcm_substream *substream,
1672 struct snd_pcm_hw_params *hw_params) 1771 struct snd_pcm_hw_params *hw_params)
1673{ 1772{
1773 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1774 struct azx *chip = apcm->chip;
1775 struct snd_pcm_runtime *runtime = substream->runtime;
1674 struct azx_dev *azx_dev = get_azx_dev(substream); 1776 struct azx_dev *azx_dev = get_azx_dev(substream);
1777 int ret;
1675 1778
1779 mark_runtime_wc(chip, azx_dev, runtime, false);
1676 azx_dev->bufsize = 0; 1780 azx_dev->bufsize = 0;
1677 azx_dev->period_bytes = 0; 1781 azx_dev->period_bytes = 0;
1678 azx_dev->format_val = 0; 1782 azx_dev->format_val = 0;
1679 return snd_pcm_lib_malloc_pages(substream, 1783 ret = snd_pcm_lib_malloc_pages(substream,
1680 params_buffer_bytes(hw_params)); 1784 params_buffer_bytes(hw_params));
1785 if (ret < 0)
1786 return ret;
1787 mark_runtime_wc(chip, azx_dev, runtime, true);
1788 return ret;
1681} 1789}
1682 1790
1683static int azx_pcm_hw_free(struct snd_pcm_substream *substream) 1791static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
1684{ 1792{
1685 struct azx_pcm *apcm = snd_pcm_substream_chip(substream); 1793 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
1686 struct azx_dev *azx_dev = get_azx_dev(substream); 1794 struct azx_dev *azx_dev = get_azx_dev(substream);
1795 struct azx *chip = apcm->chip;
1796 struct snd_pcm_runtime *runtime = substream->runtime;
1687 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream]; 1797 struct hda_pcm_stream *hinfo = apcm->hinfo[substream->stream];
1688 1798
1689 /* reset BDL address */ 1799 /* reset BDL address */
@@ -1696,6 +1806,7 @@ static int azx_pcm_hw_free(struct snd_pcm_substream *substream)
1696 1806
1697 snd_hda_codec_cleanup(apcm->codec, hinfo, substream); 1807 snd_hda_codec_cleanup(apcm->codec, hinfo, substream);
1698 1808
1809 mark_runtime_wc(chip, azx_dev, runtime, false);
1699 return snd_pcm_lib_free_pages(substream); 1810 return snd_pcm_lib_free_pages(substream);
1700} 1811}
1701 1812
@@ -1924,7 +2035,8 @@ static unsigned int azx_via_get_position(struct azx *chip,
1924} 2035}
1925 2036
1926static unsigned int azx_get_position(struct azx *chip, 2037static unsigned int azx_get_position(struct azx *chip,
1927 struct azx_dev *azx_dev) 2038 struct azx_dev *azx_dev,
2039 bool with_check)
1928{ 2040{
1929 unsigned int pos; 2041 unsigned int pos;
1930 int stream = azx_dev->substream->stream; 2042 int stream = azx_dev->substream->stream;
@@ -1940,7 +2052,7 @@ static unsigned int azx_get_position(struct azx *chip,
1940 default: 2052 default:
1941 /* use the position buffer */ 2053 /* use the position buffer */
1942 pos = le32_to_cpu(*azx_dev->posbuf); 2054 pos = le32_to_cpu(*azx_dev->posbuf);
1943 if (chip->position_fix[stream] == POS_FIX_AUTO) { 2055 if (with_check && chip->position_fix[stream] == POS_FIX_AUTO) {
1944 if (!pos || pos == (u32)-1) { 2056 if (!pos || pos == (u32)-1) {
1945 printk(KERN_WARNING 2057 printk(KERN_WARNING
1946 "hda-intel: Invalid position buffer, " 2058 "hda-intel: Invalid position buffer, "
@@ -1964,7 +2076,7 @@ static snd_pcm_uframes_t azx_pcm_pointer(struct snd_pcm_substream *substream)
1964 struct azx *chip = apcm->chip; 2076 struct azx *chip = apcm->chip;
1965 struct azx_dev *azx_dev = get_azx_dev(substream); 2077 struct azx_dev *azx_dev = get_azx_dev(substream);
1966 return bytes_to_frames(substream->runtime, 2078 return bytes_to_frames(substream->runtime,
1967 azx_get_position(chip, azx_dev)); 2079 azx_get_position(chip, azx_dev, false));
1968} 2080}
1969 2081
1970/* 2082/*
@@ -1987,7 +2099,7 @@ static int azx_position_ok(struct azx *chip, struct azx_dev *azx_dev)
1987 return -1; /* bogus (too early) interrupt */ 2099 return -1; /* bogus (too early) interrupt */
1988 2100
1989 stream = azx_dev->substream->stream; 2101 stream = azx_dev->substream->stream;
1990 pos = azx_get_position(chip, azx_dev); 2102 pos = azx_get_position(chip, azx_dev, true);
1991 2103
1992 if (WARN_ONCE(!azx_dev->period_bytes, 2104 if (WARN_ONCE(!azx_dev->period_bytes,
1993 "hda-intel: zero azx_dev->period_bytes")) 2105 "hda-intel: zero azx_dev->period_bytes"))
@@ -2054,6 +2166,20 @@ static void azx_clear_irq_pending(struct azx *chip)
2054 spin_unlock_irq(&chip->reg_lock); 2166 spin_unlock_irq(&chip->reg_lock);
2055} 2167}
2056 2168
2169#ifdef CONFIG_X86
2170static int azx_pcm_mmap(struct snd_pcm_substream *substream,
2171 struct vm_area_struct *area)
2172{
2173 struct azx_pcm *apcm = snd_pcm_substream_chip(substream);
2174 struct azx *chip = apcm->chip;
2175 if (!azx_snoop(chip))
2176 area->vm_page_prot = pgprot_writecombine(area->vm_page_prot);
2177 return snd_pcm_lib_default_mmap(substream, area);
2178}
2179#else
2180#define azx_pcm_mmap NULL
2181#endif
2182
2057static struct snd_pcm_ops azx_pcm_ops = { 2183static struct snd_pcm_ops azx_pcm_ops = {
2058 .open = azx_pcm_open, 2184 .open = azx_pcm_open,
2059 .close = azx_pcm_close, 2185 .close = azx_pcm_close,
@@ -2063,6 +2189,7 @@ static struct snd_pcm_ops azx_pcm_ops = {
2063 .prepare = azx_pcm_prepare, 2189 .prepare = azx_pcm_prepare,
2064 .trigger = azx_pcm_trigger, 2190 .trigger = azx_pcm_trigger,
2065 .pointer = azx_pcm_pointer, 2191 .pointer = azx_pcm_pointer,
2192 .mmap = azx_pcm_mmap,
2066 .page = snd_pcm_sgbuf_ops_page, 2193 .page = snd_pcm_sgbuf_ops_page,
2067}; 2194};
2068 2195
@@ -2343,13 +2470,19 @@ static int azx_free(struct azx *chip)
2343 2470
2344 if (chip->azx_dev) { 2471 if (chip->azx_dev) {
2345 for (i = 0; i < chip->num_streams; i++) 2472 for (i = 0; i < chip->num_streams; i++)
2346 if (chip->azx_dev[i].bdl.area) 2473 if (chip->azx_dev[i].bdl.area) {
2474 mark_pages_wc(chip, &chip->azx_dev[i].bdl, false);
2347 snd_dma_free_pages(&chip->azx_dev[i].bdl); 2475 snd_dma_free_pages(&chip->azx_dev[i].bdl);
2476 }
2348 } 2477 }
2349 if (chip->rb.area) 2478 if (chip->rb.area) {
2479 mark_pages_wc(chip, &chip->rb, false);
2350 snd_dma_free_pages(&chip->rb); 2480 snd_dma_free_pages(&chip->rb);
2351 if (chip->posbuf.area) 2481 }
2482 if (chip->posbuf.area) {
2483 mark_pages_wc(chip, &chip->posbuf, false);
2352 snd_dma_free_pages(&chip->posbuf); 2484 snd_dma_free_pages(&chip->posbuf);
2485 }
2353 pci_release_regions(chip->pci); 2486 pci_release_regions(chip->pci);
2354 pci_disable_device(chip->pci); 2487 pci_disable_device(chip->pci);
2355 kfree(chip->azx_dev); 2488 kfree(chip->azx_dev);
@@ -2369,6 +2502,7 @@ static int azx_dev_free(struct snd_device *device)
2369static struct snd_pci_quirk position_fix_list[] __devinitdata = { 2502static struct snd_pci_quirk position_fix_list[] __devinitdata = {
2370 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB), 2503 SND_PCI_QUIRK(0x1028, 0x01cc, "Dell D820", POS_FIX_LPIB),
2371 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB), 2504 SND_PCI_QUIRK(0x1028, 0x01de, "Dell Precision 390", POS_FIX_LPIB),
2505 SND_PCI_QUIRK(0x1028, 0x02c6, "Dell Inspiron 1010", POS_FIX_LPIB),
2372 SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB), 2506 SND_PCI_QUIRK(0x103c, 0x306d, "HP dv3", POS_FIX_LPIB),
2373 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB), 2507 SND_PCI_QUIRK(0x1043, 0x813d, "ASUS P5AD2", POS_FIX_LPIB),
2374 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB), 2508 SND_PCI_QUIRK(0x1043, 0x81b3, "ASUS", POS_FIX_LPIB),
@@ -2544,6 +2678,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
2544 check_probe_mask(chip, dev); 2678 check_probe_mask(chip, dev);
2545 2679
2546 chip->single_cmd = single_cmd; 2680 chip->single_cmd = single_cmd;
2681 chip->snoop = hda_snoop;
2547 2682
2548 if (bdl_pos_adj[dev] < 0) { 2683 if (bdl_pos_adj[dev] < 0) {
2549 switch (chip->driver_type) { 2684 switch (chip->driver_type) {
@@ -2616,6 +2751,10 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
2616 gcap &= ~ICH6_GCAP_64OK; 2751 gcap &= ~ICH6_GCAP_64OK;
2617 } 2752 }
2618 2753
2754 /* disable buffer size rounding to 128-byte multiples if supported */
2755 if (chip->driver_caps & AZX_DCAPS_BUFSIZE)
2756 align_buffer_size = 0;
2757
2619 /* allow 64bit DMA address if supported by H/W */ 2758 /* allow 64bit DMA address if supported by H/W */
2620 if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64))) 2759 if ((gcap & ICH6_GCAP_64OK) && !pci_set_dma_mask(pci, DMA_BIT_MASK(64)))
2621 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64)); 2760 pci_set_consistent_dma_mask(pci, DMA_BIT_MASK(64));
@@ -2667,6 +2806,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
2667 snd_printk(KERN_ERR SFX "cannot allocate BDL\n"); 2806 snd_printk(KERN_ERR SFX "cannot allocate BDL\n");
2668 goto errout; 2807 goto errout;
2669 } 2808 }
2809 mark_pages_wc(chip, &chip->azx_dev[i].bdl, true);
2670 } 2810 }
2671 /* allocate memory for the position buffer */ 2811 /* allocate memory for the position buffer */
2672 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV, 2812 err = snd_dma_alloc_pages(SNDRV_DMA_TYPE_DEV,
@@ -2676,6 +2816,7 @@ static int __devinit azx_create(struct snd_card *card, struct pci_dev *pci,
2676 snd_printk(KERN_ERR SFX "cannot allocate posbuf\n"); 2816 snd_printk(KERN_ERR SFX "cannot allocate posbuf\n");
2677 goto errout; 2817 goto errout;
2678 } 2818 }
2819 mark_pages_wc(chip, &chip->posbuf, true);
2679 /* allocate CORB/RIRB */ 2820 /* allocate CORB/RIRB */
2680 err = azx_alloc_cmd_io(chip); 2821 err = azx_alloc_cmd_io(chip);
2681 if (err < 0) 2822 if (err < 0)
@@ -2817,37 +2958,49 @@ static void __devexit azx_remove(struct pci_dev *pci)
2817static DEFINE_PCI_DEVICE_TABLE(azx_ids) = { 2958static DEFINE_PCI_DEVICE_TABLE(azx_ids) = {
2818 /* CPT */ 2959 /* CPT */
2819 { PCI_DEVICE(0x8086, 0x1c20), 2960 { PCI_DEVICE(0x8086, 0x1c20),
2820 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_SCH_SNOOP }, 2961 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_SCH_SNOOP |
2962 AZX_DCAPS_BUFSIZE },
2821 /* PBG */ 2963 /* PBG */
2822 { PCI_DEVICE(0x8086, 0x1d20), 2964 { PCI_DEVICE(0x8086, 0x1d20),
2823 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_SCH_SNOOP }, 2965 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_SCH_SNOOP |
2966 AZX_DCAPS_BUFSIZE},
2824 /* Panther Point */ 2967 /* Panther Point */
2825 { PCI_DEVICE(0x8086, 0x1e20), 2968 { PCI_DEVICE(0x8086, 0x1e20),
2826 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_SCH_SNOOP }, 2969 .driver_data = AZX_DRIVER_PCH | AZX_DCAPS_SCH_SNOOP |
2970 AZX_DCAPS_BUFSIZE},
2827 /* SCH */ 2971 /* SCH */
2828 { PCI_DEVICE(0x8086, 0x811b), 2972 { PCI_DEVICE(0x8086, 0x811b),
2829 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_SCH_SNOOP }, 2973 .driver_data = AZX_DRIVER_SCH | AZX_DCAPS_SCH_SNOOP |
2974 AZX_DCAPS_BUFSIZE},
2830 { PCI_DEVICE(0x8086, 0x2668), 2975 { PCI_DEVICE(0x8086, 0x2668),
2831 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC }, /* ICH6 */ 2976 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2977 AZX_DCAPS_BUFSIZE }, /* ICH6 */
2832 { PCI_DEVICE(0x8086, 0x27d8), 2978 { PCI_DEVICE(0x8086, 0x27d8),
2833 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC }, /* ICH7 */ 2979 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2980 AZX_DCAPS_BUFSIZE }, /* ICH7 */
2834 { PCI_DEVICE(0x8086, 0x269a), 2981 { PCI_DEVICE(0x8086, 0x269a),
2835 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC }, /* ESB2 */ 2982 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2983 AZX_DCAPS_BUFSIZE }, /* ESB2 */
2836 { PCI_DEVICE(0x8086, 0x284b), 2984 { PCI_DEVICE(0x8086, 0x284b),
2837 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC }, /* ICH8 */ 2985 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2986 AZX_DCAPS_BUFSIZE }, /* ICH8 */
2838 { PCI_DEVICE(0x8086, 0x293e), 2987 { PCI_DEVICE(0x8086, 0x293e),
2839 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC }, /* ICH9 */ 2988 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2989 AZX_DCAPS_BUFSIZE }, /* ICH9 */
2840 { PCI_DEVICE(0x8086, 0x293f), 2990 { PCI_DEVICE(0x8086, 0x293f),
2841 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC }, /* ICH9 */ 2991 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2992 AZX_DCAPS_BUFSIZE }, /* ICH9 */
2842 { PCI_DEVICE(0x8086, 0x3a3e), 2993 { PCI_DEVICE(0x8086, 0x3a3e),
2843 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC }, /* ICH10 */ 2994 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2995 AZX_DCAPS_BUFSIZE }, /* ICH10 */
2844 { PCI_DEVICE(0x8086, 0x3a6e), 2996 { PCI_DEVICE(0x8086, 0x3a6e),
2845 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC }, /* ICH10 */ 2997 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_OLD_SSYNC |
2998 AZX_DCAPS_BUFSIZE }, /* ICH10 */
2846 /* Generic Intel */ 2999 /* Generic Intel */
2847 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID), 3000 { PCI_DEVICE(PCI_VENDOR_ID_INTEL, PCI_ANY_ID),
2848 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8, 3001 .class = PCI_CLASS_MULTIMEDIA_HD_AUDIO << 8,
2849 .class_mask = 0xffffff, 3002 .class_mask = 0xffffff,
2850 .driver_data = AZX_DRIVER_ICH }, 3003 .driver_data = AZX_DRIVER_ICH | AZX_DCAPS_BUFSIZE },
2851 /* ATI SB 450/600/700/800/900 */ 3004 /* ATI SB 450/600/700/800/900 */
2852 { PCI_DEVICE(0x1002, 0x437b), 3005 { PCI_DEVICE(0x1002, 0x437b),
2853 .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB }, 3006 .driver_data = AZX_DRIVER_ATI | AZX_DCAPS_PRESET_ATI_SB },
diff --git a/sound/pci/hda/hda_local.h b/sound/pci/hda/hda_local.h
index 2e7ac31afa8d..79f49e2e8cbc 100644
--- a/sound/pci/hda/hda_local.h
+++ b/sound/pci/hda/hda_local.h
@@ -267,11 +267,14 @@ int snd_hda_ch_mode_put(struct hda_codec *codec,
267enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */ 267enum { HDA_FRONT, HDA_REAR, HDA_CLFE, HDA_SIDE }; /* index for dac_nidx */
268enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */ 268enum { HDA_DIG_NONE, HDA_DIG_EXCLUSIVE, HDA_DIG_ANALOG_DUP }; /* dig_out_used */
269 269
270#define HDA_MAX_OUTS 5
271
270struct hda_multi_out { 272struct hda_multi_out {
271 int num_dacs; /* # of DACs, must be more than 1 */ 273 int num_dacs; /* # of DACs, must be more than 1 */
272 const hda_nid_t *dac_nids; /* DAC list */ 274 const hda_nid_t *dac_nids; /* DAC list */
273 hda_nid_t hp_nid; /* optional DAC for HP, 0 when not exists */ 275 hda_nid_t hp_nid; /* optional DAC for HP, 0 when not exists */
274 hda_nid_t extra_out_nid[3]; /* optional DACs, 0 when not exists */ 276 hda_nid_t hp_out_nid[HDA_MAX_OUTS]; /* DACs for multiple HPs */
277 hda_nid_t extra_out_nid[HDA_MAX_OUTS]; /* other (e.g. speaker) DACs */
275 hda_nid_t dig_out_nid; /* digital out audio widget */ 278 hda_nid_t dig_out_nid; /* digital out audio widget */
276 const hda_nid_t *slave_dig_outs; 279 const hda_nid_t *slave_dig_outs;
277 int max_channels; /* currently supported analog channels */ 280 int max_channels; /* currently supported analog channels */
@@ -333,9 +336,6 @@ int snd_hda_codec_proc_new(struct hda_codec *codec);
333static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; } 336static inline int snd_hda_codec_proc_new(struct hda_codec *codec) { return 0; }
334#endif 337#endif
335 338
336#define SND_PRINT_RATES_ADVISED_BUFSIZE 80
337void snd_print_pcm_rates(int pcm, char *buf, int buflen);
338
339#define SND_PRINT_BITS_ADVISED_BUFSIZE 16 339#define SND_PRINT_BITS_ADVISED_BUFSIZE 16
340void snd_print_pcm_bits(int pcm, char *buf, int buflen); 340void snd_print_pcm_bits(int pcm, char *buf, int buflen);
341 341
@@ -385,7 +385,7 @@ enum {
385 AUTO_PIN_HP_OUT 385 AUTO_PIN_HP_OUT
386}; 386};
387 387
388#define AUTO_CFG_MAX_OUTS 5 388#define AUTO_CFG_MAX_OUTS HDA_MAX_OUTS
389#define AUTO_CFG_MAX_INS 8 389#define AUTO_CFG_MAX_INS 8
390 390
391struct auto_pin_cfg_item { 391struct auto_pin_cfg_item {
@@ -442,10 +442,21 @@ struct auto_pin_cfg {
442 (cfg & AC_DEFCFG_SEQUENCE) 442 (cfg & AC_DEFCFG_SEQUENCE)
443#define get_defcfg_device(cfg) \ 443#define get_defcfg_device(cfg) \
444 ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT) 444 ((cfg & AC_DEFCFG_DEVICE) >> AC_DEFCFG_DEVICE_SHIFT)
445#define get_defcfg_misc(cfg) \
446 ((cfg & AC_DEFCFG_MISC) >> AC_DEFCFG_MISC_SHIFT)
447
448/* bit-flags for snd_hda_parse_pin_def_config() behavior */
449#define HDA_PINCFG_NO_HP_FIXUP (1 << 0) /* no HP-split */
450#define HDA_PINCFG_NO_LO_FIXUP (1 << 1) /* don't take other outs as LO */
445 451
446int snd_hda_parse_pin_def_config(struct hda_codec *codec, 452int snd_hda_parse_pin_defcfg(struct hda_codec *codec,
447 struct auto_pin_cfg *cfg, 453 struct auto_pin_cfg *cfg,
448 const hda_nid_t *ignore_nids); 454 const hda_nid_t *ignore_nids,
455 unsigned int cond_flags);
456
457/* older function */
458#define snd_hda_parse_pin_def_config(codec, cfg, ignore) \
459 snd_hda_parse_pin_defcfg(codec, cfg, ignore, 0)
449 460
450/* amp values */ 461/* amp values */
451#define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8)) 462#define AMP_IN_MUTE(idx) (0x7080 | ((idx)<<8))
@@ -492,12 +503,16 @@ u32 query_amp_caps(struct hda_codec *codec, hda_nid_t nid, int direction);
492int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir, 503int snd_hda_override_amp_caps(struct hda_codec *codec, hda_nid_t nid, int dir,
493 unsigned int caps); 504 unsigned int caps);
494u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid); 505u32 snd_hda_query_pin_caps(struct hda_codec *codec, hda_nid_t nid);
506int snd_hda_override_pin_caps(struct hda_codec *codec, hda_nid_t nid,
507 unsigned int caps);
495u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid); 508u32 snd_hda_pin_sense(struct hda_codec *codec, hda_nid_t nid);
496int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid); 509int snd_hda_jack_detect(struct hda_codec *codec, hda_nid_t nid);
497 510
498static inline bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid) 511static inline bool is_jack_detectable(struct hda_codec *codec, hda_nid_t nid)
499{ 512{
500 return (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_PRES_DETECT) && 513 return (snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_PRES_DETECT) &&
514 !(get_defcfg_misc(snd_hda_codec_get_pincfg(codec, nid) &
515 AC_DEFCFG_MISC_NO_PRESENCE)) &&
501 (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP); 516 (get_wcaps(codec, nid) & AC_WCAP_UNSOL_CAP);
502} 517}
503 518
@@ -589,7 +604,8 @@ int snd_hda_check_amp_list_power(struct hda_codec *codec,
589#define get_amp_nid_(pv) ((pv) & 0xffff) 604#define get_amp_nid_(pv) ((pv) & 0xffff)
590#define get_amp_nid(kc) get_amp_nid_((kc)->private_value) 605#define get_amp_nid(kc) get_amp_nid_((kc)->private_value)
591#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3) 606#define get_amp_channels(kc) (((kc)->private_value >> 16) & 0x3)
592#define get_amp_direction(kc) (((kc)->private_value >> 18) & 0x1) 607#define get_amp_direction_(pv) (((pv) >> 18) & 0x1)
608#define get_amp_direction(kc) get_amp_direction_((kc)->private_value)
593#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf) 609#define get_amp_index(kc) (((kc)->private_value >> 19) & 0xf)
594#define get_amp_offset(kc) (((kc)->private_value >> 23) & 0x3f) 610#define get_amp_offset(kc) (((kc)->private_value >> 23) & 0x3f)
595#define get_amp_min_mute(kc) (((kc)->private_value >> 29) & 0x1) 611#define get_amp_min_mute(kc) (((kc)->private_value >> 29) & 0x1)
@@ -607,6 +623,7 @@ struct cea_sad {
607}; 623};
608 624
609#define ELD_FIXED_BYTES 20 625#define ELD_FIXED_BYTES 20
626#define ELD_MAX_SIZE 256
610#define ELD_MAX_MNL 16 627#define ELD_MAX_MNL 16
611#define ELD_MAX_SAD 16 628#define ELD_MAX_SAD 16
612 629
@@ -631,6 +648,7 @@ struct hdmi_eld {
631 int spk_alloc; 648 int spk_alloc;
632 int sad_count; 649 int sad_count;
633 struct cea_sad sad[ELD_MAX_SAD]; 650 struct cea_sad sad[ELD_MAX_SAD];
651 char eld_buffer[ELD_MAX_SIZE];
634#ifdef CONFIG_PROC_FS 652#ifdef CONFIG_PROC_FS
635 struct snd_info_entry *proc_entry; 653 struct snd_info_entry *proc_entry;
636#endif 654#endif
diff --git a/sound/pci/hda/hda_proc.c b/sound/pci/hda/hda_proc.c
index 2be57b051aa2..2c981b55940b 100644
--- a/sound/pci/hda/hda_proc.c
+++ b/sound/pci/hda/hda_proc.c
@@ -152,12 +152,18 @@ static void print_amp_vals(struct snd_info_buffer *buffer,
152 152
153static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm) 153static void print_pcm_rates(struct snd_info_buffer *buffer, unsigned int pcm)
154{ 154{
155 char buf[SND_PRINT_RATES_ADVISED_BUFSIZE]; 155 static unsigned int rates[] = {
156 8000, 11025, 16000, 22050, 32000, 44100, 48000, 88200,
157 96000, 176400, 192000, 384000
158 };
159 int i;
156 160
157 pcm &= AC_SUPPCM_RATES; 161 pcm &= AC_SUPPCM_RATES;
158 snd_iprintf(buffer, " rates [0x%x]:", pcm); 162 snd_iprintf(buffer, " rates [0x%x]:", pcm);
159 snd_print_pcm_rates(pcm, buf, sizeof(buf)); 163 for (i = 0; i < ARRAY_SIZE(rates); i++)
160 snd_iprintf(buffer, "%s\n", buf); 164 if (pcm & (1 << i))
165 snd_iprintf(buffer, " %d", rates[i]);
166 snd_iprintf(buffer, "\n");
161} 167}
162 168
163static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm) 169static void print_pcm_bits(struct snd_info_buffer *buffer, unsigned int pcm)
diff --git a/sound/pci/hda/hda_trace.h b/sound/pci/hda/hda_trace.h
new file mode 100644
index 000000000000..9884871ddb00
--- /dev/null
+++ b/sound/pci/hda/hda_trace.h
@@ -0,0 +1,117 @@
1#undef TRACE_SYSTEM
2#define TRACE_SYSTEM hda
3#define TRACE_INCLUDE_FILE hda_trace
4
5#if !defined(_TRACE_HDA_H) || defined(TRACE_HEADER_MULTI_READ)
6#define _TRACE_HDA_H
7
8#include <linux/tracepoint.h>
9
10struct hda_bus;
11struct hda_codec;
12
13DECLARE_EVENT_CLASS(hda_cmd,
14
15 TP_PROTO(struct hda_codec *codec, unsigned int val),
16
17 TP_ARGS(codec, val),
18
19 TP_STRUCT__entry(
20 __field( unsigned int, card )
21 __field( unsigned int, addr )
22 __field( unsigned int, val )
23 ),
24
25 TP_fast_assign(
26 __entry->card = (codec)->bus->card->number;
27 __entry->addr = (codec)->addr;
28 __entry->val = (val);
29 ),
30
31 TP_printk("[%d:%d] val=%x", __entry->card, __entry->addr, __entry->val)
32);
33
34DEFINE_EVENT(hda_cmd, hda_send_cmd,
35 TP_PROTO(struct hda_codec *codec, unsigned int val),
36 TP_ARGS(codec, val)
37);
38
39DEFINE_EVENT(hda_cmd, hda_get_response,
40 TP_PROTO(struct hda_codec *codec, unsigned int val),
41 TP_ARGS(codec, val)
42);
43
44TRACE_EVENT(hda_bus_reset,
45
46 TP_PROTO(struct hda_bus *bus),
47
48 TP_ARGS(bus),
49
50 TP_STRUCT__entry(
51 __field( unsigned int, card )
52 ),
53
54 TP_fast_assign(
55 __entry->card = (bus)->card->number;
56 ),
57
58 TP_printk("[%d]", __entry->card)
59);
60
61DECLARE_EVENT_CLASS(hda_power,
62
63 TP_PROTO(struct hda_codec *codec),
64
65 TP_ARGS(codec),
66
67 TP_STRUCT__entry(
68 __field( unsigned int, card )
69 __field( unsigned int, addr )
70 ),
71
72 TP_fast_assign(
73 __entry->card = (codec)->bus->card->number;
74 __entry->addr = (codec)->addr;
75 ),
76
77 TP_printk("[%d:%d]", __entry->card, __entry->addr)
78);
79
80DEFINE_EVENT(hda_power, hda_power_down,
81 TP_PROTO(struct hda_codec *codec),
82 TP_ARGS(codec)
83);
84
85DEFINE_EVENT(hda_power, hda_power_up,
86 TP_PROTO(struct hda_codec *codec),
87 TP_ARGS(codec)
88);
89
90TRACE_EVENT(hda_unsol_event,
91
92 TP_PROTO(struct hda_bus *bus, u32 res, u32 res_ex),
93
94 TP_ARGS(bus, res, res_ex),
95
96 TP_STRUCT__entry(
97 __field( unsigned int, card )
98 __field( u32, res )
99 __field( u32, res_ex )
100 ),
101
102 TP_fast_assign(
103 __entry->card = (bus)->card->number;
104 __entry->res = res;
105 __entry->res_ex = res_ex;
106 ),
107
108 TP_printk("[%d] res=%x, res_ex=%x", __entry->card,
109 __entry->res, __entry->res_ex)
110);
111
112#endif /* _TRACE_HDA_H */
113
114/* This part must be outside protection */
115#undef TRACE_INCLUDE_PATH
116#define TRACE_INCLUDE_PATH .
117#include <trace/define_trace.h>
diff --git a/sound/pci/hda/patch_analog.c b/sound/pci/hda/patch_analog.c
index 8648917acffb..d8aac588f23b 100644
--- a/sound/pci/hda/patch_analog.c
+++ b/sound/pci/hda/patch_analog.c
@@ -48,6 +48,8 @@ struct ad198x_spec {
48 48
49 const hda_nid_t *alt_dac_nid; 49 const hda_nid_t *alt_dac_nid;
50 const struct hda_pcm_stream *stream_analog_alt_playback; 50 const struct hda_pcm_stream *stream_analog_alt_playback;
51 int independent_hp;
52 int num_active_streams;
51 53
52 /* capture */ 54 /* capture */
53 unsigned int num_adc_nids; 55 unsigned int num_adc_nids;
@@ -302,6 +304,72 @@ static int ad198x_check_power_status(struct hda_codec *codec, hda_nid_t nid)
302} 304}
303#endif 305#endif
304 306
307static void activate_ctl(struct hda_codec *codec, const char *name, int active)
308{
309 struct snd_kcontrol *ctl = snd_hda_find_mixer_ctl(codec, name);
310 if (ctl) {
311 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_INACTIVE;
312 ctl->vd[0].access |= active ? 0 :
313 SNDRV_CTL_ELEM_ACCESS_INACTIVE;
314 ctl->vd[0].access &= ~SNDRV_CTL_ELEM_ACCESS_WRITE;
315 ctl->vd[0].access |= active ?
316 SNDRV_CTL_ELEM_ACCESS_WRITE : 0;
317 snd_ctl_notify(codec->bus->card,
318 SNDRV_CTL_EVENT_MASK_INFO, &ctl->id);
319 }
320}
321
322static void set_stream_active(struct hda_codec *codec, bool active)
323{
324 struct ad198x_spec *spec = codec->spec;
325 if (active)
326 spec->num_active_streams++;
327 else
328 spec->num_active_streams--;
329 activate_ctl(codec, "Independent HP", spec->num_active_streams == 0);
330}
331
332static int ad1988_independent_hp_info(struct snd_kcontrol *kcontrol,
333 struct snd_ctl_elem_info *uinfo)
334{
335 static const char * const texts[] = { "OFF", "ON", NULL};
336 int index;
337 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
338 uinfo->count = 1;
339 uinfo->value.enumerated.items = 2;
340 index = uinfo->value.enumerated.item;
341 if (index >= 2)
342 index = 1;
343 strcpy(uinfo->value.enumerated.name, texts[index]);
344 return 0;
345}
346
347static int ad1988_independent_hp_get(struct snd_kcontrol *kcontrol,
348 struct snd_ctl_elem_value *ucontrol)
349{
350 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
351 struct ad198x_spec *spec = codec->spec;
352 ucontrol->value.enumerated.item[0] = spec->independent_hp;
353 return 0;
354}
355
356static int ad1988_independent_hp_put(struct snd_kcontrol *kcontrol,
357 struct snd_ctl_elem_value *ucontrol)
358{
359 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
360 struct ad198x_spec *spec = codec->spec;
361 unsigned int select = ucontrol->value.enumerated.item[0];
362 if (spec->independent_hp != select) {
363 spec->independent_hp = select;
364 if (spec->independent_hp)
365 spec->multiout.hp_nid = 0;
366 else
367 spec->multiout.hp_nid = spec->alt_dac_nid[0];
368 return 1;
369 }
370 return 0;
371}
372
305/* 373/*
306 * Analog playback callbacks 374 * Analog playback callbacks
307 */ 375 */
@@ -310,8 +378,15 @@ static int ad198x_playback_pcm_open(struct hda_pcm_stream *hinfo,
310 struct snd_pcm_substream *substream) 378 struct snd_pcm_substream *substream)
311{ 379{
312 struct ad198x_spec *spec = codec->spec; 380 struct ad198x_spec *spec = codec->spec;
313 return snd_hda_multi_out_analog_open(codec, &spec->multiout, substream, 381 int err;
382 set_stream_active(codec, true);
383 err = snd_hda_multi_out_analog_open(codec, &spec->multiout, substream,
314 hinfo); 384 hinfo);
385 if (err < 0) {
386 set_stream_active(codec, false);
387 return err;
388 }
389 return 0;
315} 390}
316 391
317static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo, 392static int ad198x_playback_pcm_prepare(struct hda_pcm_stream *hinfo,
@@ -333,11 +408,41 @@ static int ad198x_playback_pcm_cleanup(struct hda_pcm_stream *hinfo,
333 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout); 408 return snd_hda_multi_out_analog_cleanup(codec, &spec->multiout);
334} 409}
335 410
411static int ad198x_playback_pcm_close(struct hda_pcm_stream *hinfo,
412 struct hda_codec *codec,
413 struct snd_pcm_substream *substream)
414{
415 set_stream_active(codec, false);
416 return 0;
417}
418
419static int ad1988_alt_playback_pcm_open(struct hda_pcm_stream *hinfo,
420 struct hda_codec *codec,
421 struct snd_pcm_substream *substream)
422{
423 struct ad198x_spec *spec = codec->spec;
424 if (!spec->independent_hp)
425 return -EBUSY;
426 set_stream_active(codec, true);
427 return 0;
428}
429
430static int ad1988_alt_playback_pcm_close(struct hda_pcm_stream *hinfo,
431 struct hda_codec *codec,
432 struct snd_pcm_substream *substream)
433{
434 set_stream_active(codec, false);
435 return 0;
436}
437
336static const struct hda_pcm_stream ad198x_pcm_analog_alt_playback = { 438static const struct hda_pcm_stream ad198x_pcm_analog_alt_playback = {
337 .substreams = 1, 439 .substreams = 1,
338 .channels_min = 2, 440 .channels_min = 2,
339 .channels_max = 2, 441 .channels_max = 2,
340 /* NID is set in ad198x_build_pcms */ 442 .ops = {
443 .open = ad1988_alt_playback_pcm_open,
444 .close = ad1988_alt_playback_pcm_close
445 },
341}; 446};
342 447
343/* 448/*
@@ -402,7 +507,6 @@ static int ad198x_capture_pcm_cleanup(struct hda_pcm_stream *hinfo,
402 return 0; 507 return 0;
403} 508}
404 509
405
406/* 510/*
407 */ 511 */
408static const struct hda_pcm_stream ad198x_pcm_analog_playback = { 512static const struct hda_pcm_stream ad198x_pcm_analog_playback = {
@@ -413,7 +517,8 @@ static const struct hda_pcm_stream ad198x_pcm_analog_playback = {
413 .ops = { 517 .ops = {
414 .open = ad198x_playback_pcm_open, 518 .open = ad198x_playback_pcm_open,
415 .prepare = ad198x_playback_pcm_prepare, 519 .prepare = ad198x_playback_pcm_prepare,
416 .cleanup = ad198x_playback_pcm_cleanup 520 .cleanup = ad198x_playback_pcm_cleanup,
521 .close = ad198x_playback_pcm_close
417 }, 522 },
418}; 523};
419 524
@@ -2058,7 +2163,6 @@ static int patch_ad1981(struct hda_codec *codec)
2058enum { 2163enum {
2059 AD1988_6STACK, 2164 AD1988_6STACK,
2060 AD1988_6STACK_DIG, 2165 AD1988_6STACK_DIG,
2061 AD1988_6STACK_DIG_FP,
2062 AD1988_3STACK, 2166 AD1988_3STACK,
2063 AD1988_3STACK_DIG, 2167 AD1988_3STACK_DIG,
2064 AD1988_LAPTOP, 2168 AD1988_LAPTOP,
@@ -2168,6 +2272,17 @@ static int ad198x_ch_mode_put(struct snd_kcontrol *kcontrol,
2168 return err; 2272 return err;
2169} 2273}
2170 2274
2275static const struct snd_kcontrol_new ad1988_hp_mixers[] = {
2276 {
2277 .iface = SNDRV_CTL_ELEM_IFACE_MIXER,
2278 .name = "Independent HP",
2279 .info = ad1988_independent_hp_info,
2280 .get = ad1988_independent_hp_get,
2281 .put = ad1988_independent_hp_put,
2282 },
2283 { } /* end */
2284};
2285
2171/* 6-stack mode */ 2286/* 6-stack mode */
2172static const struct snd_kcontrol_new ad1988_6stack_mixers1[] = { 2287static const struct snd_kcontrol_new ad1988_6stack_mixers1[] = {
2173 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT), 2288 HDA_CODEC_VOLUME("Front Playback Volume", 0x04, 0x0, HDA_OUTPUT),
@@ -2188,6 +2303,7 @@ static const struct snd_kcontrol_new ad1988_6stack_mixers1_rev2[] = {
2188}; 2303};
2189 2304
2190static const struct snd_kcontrol_new ad1988_6stack_mixers2[] = { 2305static const struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
2306 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
2191 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT), 2307 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2192 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT), 2308 HDA_BIND_MUTE("Surround Playback Switch", 0x2a, 2, HDA_INPUT),
2193 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT), 2309 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x27, 1, 2, HDA_INPUT),
@@ -2210,13 +2326,6 @@ static const struct snd_kcontrol_new ad1988_6stack_mixers2[] = {
2210 2326
2211 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT), 2327 HDA_CODEC_VOLUME("Front Mic Boost Volume", 0x39, 0x0, HDA_OUTPUT),
2212 HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT), 2328 HDA_CODEC_VOLUME("Mic Boost Volume", 0x3c, 0x0, HDA_OUTPUT),
2213
2214 { } /* end */
2215};
2216
2217static const struct snd_kcontrol_new ad1988_6stack_fp_mixers[] = {
2218 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
2219
2220 { } /* end */ 2329 { } /* end */
2221}; 2330};
2222 2331
@@ -2238,6 +2347,7 @@ static const struct snd_kcontrol_new ad1988_3stack_mixers1_rev2[] = {
2238}; 2347};
2239 2348
2240static const struct snd_kcontrol_new ad1988_3stack_mixers2[] = { 2349static const struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
2350 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
2241 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT), 2351 HDA_BIND_MUTE("Front Playback Switch", 0x29, 2, HDA_INPUT),
2242 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT), 2352 HDA_BIND_MUTE("Surround Playback Switch", 0x2c, 2, HDA_INPUT),
2243 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT), 2353 HDA_BIND_MUTE_MONO("Center Playback Switch", 0x26, 1, 2, HDA_INPUT),
@@ -2272,6 +2382,7 @@ static const struct snd_kcontrol_new ad1988_3stack_mixers2[] = {
2272 2382
2273/* laptop mode */ 2383/* laptop mode */
2274static const struct snd_kcontrol_new ad1988_laptop_mixers[] = { 2384static const struct snd_kcontrol_new ad1988_laptop_mixers[] = {
2385 HDA_CODEC_VOLUME("Headphone Playback Volume", 0x03, 0x0, HDA_OUTPUT),
2275 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT), 2386 HDA_CODEC_VOLUME("PCM Playback Volume", 0x04, 0x0, HDA_OUTPUT),
2276 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT), 2387 HDA_CODEC_MUTE("PCM Playback Switch", 0x29, 0x0, HDA_INPUT),
2277 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT), 2388 HDA_BIND_MUTE("Mono Playback Switch", 0x1e, 2, HDA_INPUT),
@@ -2446,7 +2557,7 @@ static const struct hda_verb ad1988_6stack_init_verbs[] = {
2446 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2557 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2447 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2558 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2448 /* Port-A front headphon path */ 2559 /* Port-A front headphon path */
2449 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */ 2560 {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
2450 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 2561 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2451 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2562 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2452 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2563 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
@@ -2594,7 +2705,7 @@ static const struct hda_verb ad1988_3stack_init_verbs[] = {
2594 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2705 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2595 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2706 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2596 /* Port-A front headphon path */ 2707 /* Port-A front headphon path */
2597 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */ 2708 {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
2598 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 2709 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2599 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2710 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2600 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2711 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
@@ -2669,7 +2780,7 @@ static const struct hda_verb ad1988_laptop_init_verbs[] = {
2669 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2780 {0x05, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2670 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2781 {0x0a, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
2671 /* Port-A front headphon path */ 2782 /* Port-A front headphon path */
2672 {0x37, AC_VERB_SET_CONNECT_SEL, 0x01}, /* DAC1:04h */ 2783 {0x37, AC_VERB_SET_CONNECT_SEL, 0x00}, /* DAC0:03h */
2673 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)}, 2784 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(0)},
2674 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)}, 2785 {0x22, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_MUTE(1)},
2675 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE}, 2786 {0x11, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
@@ -2782,11 +2893,11 @@ static inline hda_nid_t ad1988_idx_to_dac(struct hda_codec *codec, int idx)
2782{ 2893{
2783 static const hda_nid_t idx_to_dac[8] = { 2894 static const hda_nid_t idx_to_dac[8] = {
2784 /* A B C D E F G H */ 2895 /* A B C D E F G H */
2785 0x04, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a 2896 0x03, 0x06, 0x05, 0x04, 0x0a, 0x06, 0x05, 0x0a
2786 }; 2897 };
2787 static const hda_nid_t idx_to_dac_rev2[8] = { 2898 static const hda_nid_t idx_to_dac_rev2[8] = {
2788 /* A B C D E F G H */ 2899 /* A B C D E F G H */
2789 0x04, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06 2900 0x03, 0x05, 0x0a, 0x04, 0x06, 0x05, 0x0a, 0x06
2790 }; 2901 };
2791 if (is_rev2(codec)) 2902 if (is_rev2(codec))
2792 return idx_to_dac_rev2[idx]; 2903 return idx_to_dac_rev2[idx];
@@ -3023,8 +3134,8 @@ static void ad1988_auto_set_output_and_unmute(struct hda_codec *codec,
3023 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type); 3134 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_PIN_WIDGET_CONTROL, pin_type);
3024 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE); 3135 snd_hda_codec_write(codec, nid, 0, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE);
3025 switch (nid) { 3136 switch (nid) {
3026 case 0x11: /* port-A - DAC 04 */ 3137 case 0x11: /* port-A - DAC 03 */
3027 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x01); 3138 snd_hda_codec_write(codec, 0x37, 0, AC_VERB_SET_CONNECT_SEL, 0x00);
3028 break; 3139 break;
3029 case 0x14: /* port-B - DAC 06 */ 3140 case 0x14: /* port-B - DAC 06 */
3030 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02); 3141 snd_hda_codec_write(codec, 0x30, 0, AC_VERB_SET_CONNECT_SEL, 0x02);
@@ -3150,7 +3261,6 @@ static int ad1988_auto_init(struct hda_codec *codec)
3150static const char * const ad1988_models[AD1988_MODEL_LAST] = { 3261static const char * const ad1988_models[AD1988_MODEL_LAST] = {
3151 [AD1988_6STACK] = "6stack", 3262 [AD1988_6STACK] = "6stack",
3152 [AD1988_6STACK_DIG] = "6stack-dig", 3263 [AD1988_6STACK_DIG] = "6stack-dig",
3153 [AD1988_6STACK_DIG_FP] = "6stack-dig-fp",
3154 [AD1988_3STACK] = "3stack", 3264 [AD1988_3STACK] = "3stack",
3155 [AD1988_3STACK_DIG] = "3stack-dig", 3265 [AD1988_3STACK_DIG] = "3stack-dig",
3156 [AD1988_LAPTOP] = "laptop", 3266 [AD1988_LAPTOP] = "laptop",
@@ -3208,10 +3318,11 @@ static int patch_ad1988(struct hda_codec *codec)
3208 } 3318 }
3209 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT); 3319 set_beep_amp(spec, 0x10, 0, HDA_OUTPUT);
3210 3320
3321 if (!spec->multiout.hp_nid)
3322 spec->multiout.hp_nid = ad1988_alt_dac_nid[0];
3211 switch (board_config) { 3323 switch (board_config) {
3212 case AD1988_6STACK: 3324 case AD1988_6STACK:
3213 case AD1988_6STACK_DIG: 3325 case AD1988_6STACK_DIG:
3214 case AD1988_6STACK_DIG_FP:
3215 spec->multiout.max_channels = 8; 3326 spec->multiout.max_channels = 8;
3216 spec->multiout.num_dacs = 4; 3327 spec->multiout.num_dacs = 4;
3217 if (is_rev2(codec)) 3328 if (is_rev2(codec))
@@ -3227,19 +3338,7 @@ static int patch_ad1988(struct hda_codec *codec)
3227 spec->mixers[1] = ad1988_6stack_mixers2; 3338 spec->mixers[1] = ad1988_6stack_mixers2;
3228 spec->num_init_verbs = 1; 3339 spec->num_init_verbs = 1;
3229 spec->init_verbs[0] = ad1988_6stack_init_verbs; 3340 spec->init_verbs[0] = ad1988_6stack_init_verbs;
3230 if (board_config == AD1988_6STACK_DIG_FP) { 3341 if (board_config == AD1988_6STACK_DIG) {
3231 spec->num_mixers++;
3232 spec->mixers[2] = ad1988_6stack_fp_mixers;
3233 spec->num_init_verbs++;
3234 spec->init_verbs[1] = ad1988_6stack_fp_init_verbs;
3235 spec->slave_vols = ad1988_6stack_fp_slave_vols;
3236 spec->slave_sws = ad1988_6stack_fp_slave_sws;
3237 spec->alt_dac_nid = ad1988_alt_dac_nid;
3238 spec->stream_analog_alt_playback =
3239 &ad198x_pcm_analog_alt_playback;
3240 }
3241 if ((board_config == AD1988_6STACK_DIG) ||
3242 (board_config == AD1988_6STACK_DIG_FP)) {
3243 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT; 3342 spec->multiout.dig_out_nid = AD1988_SPDIF_OUT;
3244 spec->dig_in_nid = AD1988_SPDIF_IN; 3343 spec->dig_in_nid = AD1988_SPDIF_IN;
3245 } 3344 }
@@ -3282,6 +3381,15 @@ static int patch_ad1988(struct hda_codec *codec)
3282 break; 3381 break;
3283 } 3382 }
3284 3383
3384 if (spec->autocfg.hp_pins[0]) {
3385 spec->mixers[spec->num_mixers++] = ad1988_hp_mixers;
3386 spec->slave_vols = ad1988_6stack_fp_slave_vols;
3387 spec->slave_sws = ad1988_6stack_fp_slave_sws;
3388 spec->alt_dac_nid = ad1988_alt_dac_nid;
3389 spec->stream_analog_alt_playback =
3390 &ad198x_pcm_analog_alt_playback;
3391 }
3392
3285 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids); 3393 spec->num_adc_nids = ARRAY_SIZE(ad1988_adc_nids);
3286 spec->adc_nids = ad1988_adc_nids; 3394 spec->adc_nids = ad1988_adc_nids;
3287 spec->capsrc_nids = ad1988_capsrc_nids; 3395 spec->capsrc_nids = ad1988_capsrc_nids;
diff --git a/sound/pci/hda/patch_cirrus.c b/sound/pci/hda/patch_cirrus.c
index 47d6ffc9b5b5..c45f3e69bcf0 100644
--- a/sound/pci/hda/patch_cirrus.c
+++ b/sound/pci/hda/patch_cirrus.c
@@ -375,7 +375,7 @@ static int is_ext_mic(struct hda_codec *codec, unsigned int idx)
375static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin, 375static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin,
376 unsigned int *idxp) 376 unsigned int *idxp)
377{ 377{
378 int i; 378 int i, idx;
379 hda_nid_t nid; 379 hda_nid_t nid;
380 380
381 nid = codec->start_nid; 381 nid = codec->start_nid;
@@ -384,9 +384,11 @@ static hda_nid_t get_adc(struct hda_codec *codec, hda_nid_t pin,
384 type = get_wcaps_type(get_wcaps(codec, nid)); 384 type = get_wcaps_type(get_wcaps(codec, nid));
385 if (type != AC_WID_AUD_IN) 385 if (type != AC_WID_AUD_IN)
386 continue; 386 continue;
387 *idxp = snd_hda_get_conn_index(codec, nid, pin, false); 387 idx = snd_hda_get_conn_index(codec, nid, pin, false);
388 if (*idxp >= 0) 388 if (idx >= 0) {
389 *idxp = idx;
389 return nid; 390 return nid;
391 }
390 } 392 }
391 return 0; 393 return 0;
392} 394}
@@ -533,7 +535,7 @@ static int add_volume(struct hda_codec *codec, const char *name,
533 int index, unsigned int pval, int dir, 535 int index, unsigned int pval, int dir,
534 struct snd_kcontrol **kctlp) 536 struct snd_kcontrol **kctlp)
535{ 537{
536 char tmp[32]; 538 char tmp[44];
537 struct snd_kcontrol_new knew = 539 struct snd_kcontrol_new knew =
538 HDA_CODEC_VOLUME_IDX(tmp, index, 0, 0, HDA_OUTPUT); 540 HDA_CODEC_VOLUME_IDX(tmp, index, 0, 0, HDA_OUTPUT);
539 knew.private_value = pval; 541 knew.private_value = pval;
diff --git a/sound/pci/hda/patch_conexant.c b/sound/pci/hda/patch_conexant.c
index 502fc9499453..0c8b5a1993ed 100644
--- a/sound/pci/hda/patch_conexant.c
+++ b/sound/pci/hda/patch_conexant.c
@@ -136,6 +136,8 @@ struct conexant_spec {
136 unsigned int thinkpad:1; 136 unsigned int thinkpad:1;
137 unsigned int hp_laptop:1; 137 unsigned int hp_laptop:1;
138 unsigned int asus:1; 138 unsigned int asus:1;
139 unsigned int pin_eapd_ctrls:1;
140 unsigned int single_adc_amp:1;
139 141
140 unsigned int adc_switching:1; 142 unsigned int adc_switching:1;
141 143
@@ -1867,39 +1869,6 @@ static const struct hda_verb cxt5051_hp_dv6736_init_verbs[] = {
1867 { } /* end */ 1869 { } /* end */
1868}; 1870};
1869 1871
1870static const struct hda_verb cxt5051_lenovo_x200_init_verbs[] = {
1871 /* Line in, Mic */
1872 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1873 {0x17, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1874 {0x18, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1875 {0x18, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_VREF80},
1876 {0x1d, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_IN},
1877 {0x1d, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
1878 /* SPK */
1879 {0x1a, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT},
1880 {0x1a, AC_VERB_SET_CONNECT_SEL, 0x00},
1881 /* HP, Amp */
1882 {0x16, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1883 {0x16, AC_VERB_SET_CONNECT_SEL, 0x00},
1884 /* Docking HP */
1885 {0x19, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_HP},
1886 {0x19, AC_VERB_SET_CONNECT_SEL, 0x00},
1887 /* DAC1 */
1888 {0x10, AC_VERB_SET_AMP_GAIN_MUTE, AMP_OUT_UNMUTE},
1889 /* Record selector: Internal mic */
1890 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1891 {0x14, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(1) | 0x44},
1892 {0x15, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x44},
1893 /* SPDIF route: PCM */
1894 {0x1c, AC_VERB_SET_PIN_WIDGET_CONTROL, PIN_OUT}, /* needed for W500 Advanced Mini Dock 250410 */
1895 {0x1c, AC_VERB_SET_CONNECT_SEL, 0x0},
1896 /* EAPD */
1897 {0x1a, AC_VERB_SET_EAPD_BTLENABLE, 0x2}, /* default on */
1898 {0x16, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1899 {0x19, AC_VERB_SET_UNSOLICITED_ENABLE, AC_USRSP_EN|CONEXANT_HP_EVENT},
1900 { } /* end */
1901};
1902
1903static const struct hda_verb cxt5051_f700_init_verbs[] = { 1872static const struct hda_verb cxt5051_f700_init_verbs[] = {
1904 /* Line in, Mic */ 1873 /* Line in, Mic */
1905 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03}, 1874 {0x17, AC_VERB_SET_AMP_GAIN_MUTE, AMP_IN_UNMUTE(0) | 0x03},
@@ -1968,7 +1937,6 @@ enum {
1968 CXT5051_LAPTOP, /* Laptops w/ EAPD support */ 1937 CXT5051_LAPTOP, /* Laptops w/ EAPD support */
1969 CXT5051_HP, /* no docking */ 1938 CXT5051_HP, /* no docking */
1970 CXT5051_HP_DV6736, /* HP without mic switch */ 1939 CXT5051_HP_DV6736, /* HP without mic switch */
1971 CXT5051_LENOVO_X200, /* Lenovo X200 laptop, also used for Advanced Mini Dock 250410 */
1972 CXT5051_F700, /* HP Compaq Presario F700 */ 1940 CXT5051_F700, /* HP Compaq Presario F700 */
1973 CXT5051_TOSHIBA, /* Toshiba M300 & co */ 1941 CXT5051_TOSHIBA, /* Toshiba M300 & co */
1974 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */ 1942 CXT5051_IDEAPAD, /* Lenovo IdeaPad Y430 */
@@ -1980,7 +1948,6 @@ static const char *const cxt5051_models[CXT5051_MODELS] = {
1980 [CXT5051_LAPTOP] = "laptop", 1948 [CXT5051_LAPTOP] = "laptop",
1981 [CXT5051_HP] = "hp", 1949 [CXT5051_HP] = "hp",
1982 [CXT5051_HP_DV6736] = "hp-dv6736", 1950 [CXT5051_HP_DV6736] = "hp-dv6736",
1983 [CXT5051_LENOVO_X200] = "lenovo-x200",
1984 [CXT5051_F700] = "hp-700", 1951 [CXT5051_F700] = "hp-700",
1985 [CXT5051_TOSHIBA] = "toshiba", 1952 [CXT5051_TOSHIBA] = "toshiba",
1986 [CXT5051_IDEAPAD] = "ideapad", 1953 [CXT5051_IDEAPAD] = "ideapad",
@@ -1995,7 +1962,6 @@ static const struct snd_pci_quirk cxt5051_cfg_tbl[] = {
1995 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board", 1962 SND_PCI_QUIRK(0x14f1, 0x0101, "Conexant Reference board",
1996 CXT5051_LAPTOP), 1963 CXT5051_LAPTOP),
1997 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP), 1964 SND_PCI_QUIRK(0x14f1, 0x5051, "HP Spartan 1.1", CXT5051_HP),
1998 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT5051_LENOVO_X200),
1999 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD), 1965 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo IdeaPad", CXT5051_IDEAPAD),
2000 {} 1966 {}
2001}; 1967};
@@ -2053,13 +2019,6 @@ static int patch_cxt5051(struct hda_codec *codec)
2053 spec->mixers[0] = cxt5051_hp_dv6736_mixers; 2019 spec->mixers[0] = cxt5051_hp_dv6736_mixers;
2054 spec->auto_mic = 0; 2020 spec->auto_mic = 0;
2055 break; 2021 break;
2056 case CXT5051_LENOVO_X200:
2057 spec->init_verbs[0] = cxt5051_lenovo_x200_init_verbs;
2058 /* Thinkpad X301 does not have S/PDIF wired and no ability
2059 to use a docking station. */
2060 if (codec->subsystem_id == 0x17aa211f)
2061 spec->multiout.dig_out_nid = 0;
2062 break;
2063 case CXT5051_F700: 2022 case CXT5051_F700:
2064 spec->init_verbs[0] = cxt5051_f700_init_verbs; 2023 spec->init_verbs[0] = cxt5051_f700_init_verbs;
2065 spec->mixers[0] = cxt5051_f700_mixers; 2024 spec->mixers[0] = cxt5051_f700_mixers;
@@ -3110,6 +3069,7 @@ static const struct snd_pci_quirk cxt5066_cfg_tbl[] = {
3110 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD), 3069 SND_PCI_QUIRK(0x17aa, 0x21c5, "Thinkpad Edge 13", CXT5066_THINKPAD),
3111 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS), 3070 SND_PCI_QUIRK(0x17aa, 0x21c6, "Thinkpad Edge 13", CXT5066_ASUS),
3112 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD), 3071 SND_PCI_QUIRK(0x17aa, 0x215e, "Lenovo Thinkpad", CXT5066_THINKPAD),
3072 SND_PCI_QUIRK(0x17aa, 0x21cf, "Lenovo T520 & W520", CXT5066_AUTO),
3113 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD), 3073 SND_PCI_QUIRK(0x17aa, 0x21da, "Lenovo X220", CXT5066_THINKPAD),
3114 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD), 3074 SND_PCI_QUIRK(0x17aa, 0x21db, "Lenovo X220-tablet", CXT5066_THINKPAD),
3115 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS), 3075 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo U350", CXT5066_ASUS),
@@ -3348,6 +3308,8 @@ static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t pin,
3348 3308
3349#define MAX_AUTO_DACS 5 3309#define MAX_AUTO_DACS 5
3350 3310
3311#define DAC_SLAVE_FLAG 0x8000 /* filled dac is a slave */
3312
3351/* fill analog DAC list from the widget tree */ 3313/* fill analog DAC list from the widget tree */
3352static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs) 3314static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3353{ 3315{
@@ -3370,16 +3332,26 @@ static int fill_cx_auto_dacs(struct hda_codec *codec, hda_nid_t *dacs)
3370/* fill pin_dac_pair list from the pin and dac list */ 3332/* fill pin_dac_pair list from the pin and dac list */
3371static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins, 3333static int fill_dacs_for_pins(struct hda_codec *codec, hda_nid_t *pins,
3372 int num_pins, hda_nid_t *dacs, int *rest, 3334 int num_pins, hda_nid_t *dacs, int *rest,
3373 struct pin_dac_pair *filled, int type) 3335 struct pin_dac_pair *filled, int nums,
3336 int type)
3374{ 3337{
3375 int i, nums; 3338 int i, start = nums;
3376 3339
3377 nums = 0; 3340 for (i = 0; i < num_pins; i++, nums++) {
3378 for (i = 0; i < num_pins; i++) {
3379 filled[nums].pin = pins[i]; 3341 filled[nums].pin = pins[i];
3380 filled[nums].type = type; 3342 filled[nums].type = type;
3381 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest); 3343 filled[nums].dac = get_unassigned_dac(codec, pins[i], dacs, rest);
3382 nums++; 3344 if (filled[nums].dac)
3345 continue;
3346 if (filled[start].dac && get_connection_index(codec, pins[i], filled[start].dac) >= 0) {
3347 filled[nums].dac = filled[start].dac | DAC_SLAVE_FLAG;
3348 continue;
3349 }
3350 if (filled[0].dac && get_connection_index(codec, pins[i], filled[0].dac) >= 0) {
3351 filled[nums].dac = filled[0].dac | DAC_SLAVE_FLAG;
3352 continue;
3353 }
3354 snd_printdd("Failed to find a DAC for pin 0x%x", pins[i]);
3383 } 3355 }
3384 return nums; 3356 return nums;
3385} 3357}
@@ -3395,19 +3367,19 @@ static void cx_auto_parse_output(struct hda_codec *codec)
3395 rest = fill_cx_auto_dacs(codec, dacs); 3367 rest = fill_cx_auto_dacs(codec, dacs);
3396 /* parse all analog output pins */ 3368 /* parse all analog output pins */
3397 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs, 3369 nums = fill_dacs_for_pins(codec, cfg->line_out_pins, cfg->line_outs,
3398 dacs, &rest, spec->dac_info, 3370 dacs, &rest, spec->dac_info, 0,
3399 AUTO_PIN_LINE_OUT); 3371 AUTO_PIN_LINE_OUT);
3400 nums += fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs, 3372 nums = fill_dacs_for_pins(codec, cfg->hp_pins, cfg->hp_outs,
3401 dacs, &rest, spec->dac_info + nums, 3373 dacs, &rest, spec->dac_info, nums,
3402 AUTO_PIN_HP_OUT); 3374 AUTO_PIN_HP_OUT);
3403 nums += fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs, 3375 nums = fill_dacs_for_pins(codec, cfg->speaker_pins, cfg->speaker_outs,
3404 dacs, &rest, spec->dac_info + nums, 3376 dacs, &rest, spec->dac_info, nums,
3405 AUTO_PIN_SPEAKER_OUT); 3377 AUTO_PIN_SPEAKER_OUT);
3406 spec->dac_info_filled = nums; 3378 spec->dac_info_filled = nums;
3407 /* fill multiout struct */ 3379 /* fill multiout struct */
3408 for (i = 0; i < nums; i++) { 3380 for (i = 0; i < nums; i++) {
3409 hda_nid_t dac = spec->dac_info[i].dac; 3381 hda_nid_t dac = spec->dac_info[i].dac;
3410 if (!dac) 3382 if (!dac || (dac & DAC_SLAVE_FLAG))
3411 continue; 3383 continue;
3412 switch (spec->dac_info[i].type) { 3384 switch (spec->dac_info[i].type) {
3413 case AUTO_PIN_LINE_OUT: 3385 case AUTO_PIN_LINE_OUT:
@@ -3460,12 +3432,14 @@ static void cx_auto_turn_eapd(struct hda_codec *codec, int num_pins,
3460static void do_automute(struct hda_codec *codec, int num_pins, 3432static void do_automute(struct hda_codec *codec, int num_pins,
3461 hda_nid_t *pins, bool on) 3433 hda_nid_t *pins, bool on)
3462{ 3434{
3435 struct conexant_spec *spec = codec->spec;
3463 int i; 3436 int i;
3464 for (i = 0; i < num_pins; i++) 3437 for (i = 0; i < num_pins; i++)
3465 snd_hda_codec_write(codec, pins[i], 0, 3438 snd_hda_codec_write(codec, pins[i], 0,
3466 AC_VERB_SET_PIN_WIDGET_CONTROL, 3439 AC_VERB_SET_PIN_WIDGET_CONTROL,
3467 on ? PIN_OUT : 0); 3440 on ? PIN_OUT : 0);
3468 cx_auto_turn_eapd(codec, num_pins, pins, on); 3441 if (spec->pin_eapd_ctrls)
3442 cx_auto_turn_eapd(codec, num_pins, pins, on);
3469} 3443}
3470 3444
3471static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins) 3445static int detect_jacks(struct hda_codec *codec, int num_pins, hda_nid_t *pins)
@@ -3490,9 +3464,12 @@ static void cx_auto_update_speakers(struct hda_codec *codec)
3490 int on = 1; 3464 int on = 1;
3491 3465
3492 /* turn on HP EAPD when HP jacks are present */ 3466 /* turn on HP EAPD when HP jacks are present */
3493 if (spec->auto_mute) 3467 if (spec->pin_eapd_ctrls) {
3494 on = spec->hp_present; 3468 if (spec->auto_mute)
3495 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on); 3469 on = spec->hp_present;
3470 cx_auto_turn_eapd(codec, cfg->hp_outs, cfg->hp_pins, on);
3471 }
3472
3496 /* mute speakers in auto-mode if HP or LO jacks are plugged */ 3473 /* mute speakers in auto-mode if HP or LO jacks are plugged */
3497 if (spec->auto_mute) 3474 if (spec->auto_mute)
3498 on = !(spec->hp_present || 3475 on = !(spec->hp_present ||
@@ -3862,7 +3839,7 @@ static void cx_auto_parse_input(struct hda_codec *codec)
3862 } 3839 }
3863 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items) 3840 if (imux->num_items >= 2 && cfg->num_inputs == imux->num_items)
3864 cx_auto_check_auto_mic(codec); 3841 cx_auto_check_auto_mic(codec);
3865 if (imux->num_items > 1 && !spec->auto_mic) { 3842 if (imux->num_items > 1) {
3866 for (i = 1; i < imux->num_items; i++) { 3843 for (i = 1; i < imux->num_items; i++) {
3867 if (spec->imux_info[i].adc != spec->imux_info[0].adc) { 3844 if (spec->imux_info[i].adc != spec->imux_info[0].adc) {
3868 spec->adc_switching = 1; 3845 spec->adc_switching = 1;
@@ -3919,20 +3896,10 @@ static void cx_auto_parse_beep(struct hda_codec *codec)
3919#define cx_auto_parse_beep(codec) 3896#define cx_auto_parse_beep(codec)
3920#endif 3897#endif
3921 3898
3922static bool found_in_nid_list(hda_nid_t nid, const hda_nid_t *list, int nums) 3899/* parse EAPDs */
3923{
3924 int i;
3925 for (i = 0; i < nums; i++)
3926 if (list[i] == nid)
3927 return true;
3928 return false;
3929}
3930
3931/* parse extra-EAPD that aren't assigned to any pins */
3932static void cx_auto_parse_eapd(struct hda_codec *codec) 3900static void cx_auto_parse_eapd(struct hda_codec *codec)
3933{ 3901{
3934 struct conexant_spec *spec = codec->spec; 3902 struct conexant_spec *spec = codec->spec;
3935 struct auto_pin_cfg *cfg = &spec->autocfg;
3936 hda_nid_t nid, end_nid; 3903 hda_nid_t nid, end_nid;
3937 3904
3938 end_nid = codec->start_nid + codec->num_nodes; 3905 end_nid = codec->start_nid + codec->num_nodes;
@@ -3941,14 +3908,18 @@ static void cx_auto_parse_eapd(struct hda_codec *codec)
3941 continue; 3908 continue;
3942 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD)) 3909 if (!(snd_hda_query_pin_caps(codec, nid) & AC_PINCAP_EAPD))
3943 continue; 3910 continue;
3944 if (found_in_nid_list(nid, cfg->line_out_pins, cfg->line_outs) ||
3945 found_in_nid_list(nid, cfg->hp_pins, cfg->hp_outs) ||
3946 found_in_nid_list(nid, cfg->speaker_pins, cfg->speaker_outs))
3947 continue;
3948 spec->eapds[spec->num_eapds++] = nid; 3911 spec->eapds[spec->num_eapds++] = nid;
3949 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds)) 3912 if (spec->num_eapds >= ARRAY_SIZE(spec->eapds))
3950 break; 3913 break;
3951 } 3914 }
3915
3916 /* NOTE: below is a wild guess; if we have more than two EAPDs,
3917 * it's a new chip, where EAPDs are supposed to be associated to
3918 * pins, and we can control EAPD per pin.
3919 * OTOH, if only one or two EAPDs are found, it's an old chip,
3920 * thus it might control over all pins.
3921 */
3922 spec->pin_eapd_ctrls = spec->num_eapds > 2;
3952} 3923}
3953 3924
3954static int cx_auto_parse_auto_config(struct hda_codec *codec) 3925static int cx_auto_parse_auto_config(struct hda_codec *codec)
@@ -4035,6 +4006,8 @@ static void cx_auto_init_output(struct hda_codec *codec)
4035 nid = spec->dac_info[i].dac; 4006 nid = spec->dac_info[i].dac;
4036 if (!nid) 4007 if (!nid)
4037 nid = spec->multiout.dac_nids[0]; 4008 nid = spec->multiout.dac_nids[0];
4009 else if (nid & DAC_SLAVE_FLAG)
4010 nid &= ~DAC_SLAVE_FLAG;
4038 select_connection(codec, spec->dac_info[i].pin, nid); 4011 select_connection(codec, spec->dac_info[i].pin, nid);
4039 } 4012 }
4040 if (spec->auto_mute) { 4013 if (spec->auto_mute) {
@@ -4052,8 +4025,9 @@ static void cx_auto_init_output(struct hda_codec *codec)
4052 } 4025 }
4053 } 4026 }
4054 cx_auto_update_speakers(codec); 4027 cx_auto_update_speakers(codec);
4055 /* turn on/off extra EAPDs, too */ 4028 /* turn on all EAPDs if no individual EAPD control is available */
4056 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true); 4029 if (!spec->pin_eapd_ctrls)
4030 cx_auto_turn_eapd(codec, spec->num_eapds, spec->eapds, true);
4057} 4031}
4058 4032
4059static void cx_auto_init_input(struct hda_codec *codec) 4033static void cx_auto_init_input(struct hda_codec *codec)
@@ -4167,9 +4141,11 @@ static int try_add_pb_volume(struct hda_codec *codec, hda_nid_t dac,
4167 hda_nid_t pin, const char *name, int idx) 4141 hda_nid_t pin, const char *name, int idx)
4168{ 4142{
4169 unsigned int caps; 4143 unsigned int caps;
4170 caps = query_amp_caps(codec, dac, HDA_OUTPUT); 4144 if (dac && !(dac & DAC_SLAVE_FLAG)) {
4171 if (caps & AC_AMPCAP_NUM_STEPS) 4145 caps = query_amp_caps(codec, dac, HDA_OUTPUT);
4172 return cx_auto_add_pb_volume(codec, dac, name, idx); 4146 if (caps & AC_AMPCAP_NUM_STEPS)
4147 return cx_auto_add_pb_volume(codec, dac, name, idx);
4148 }
4173 caps = query_amp_caps(codec, pin, HDA_OUTPUT); 4149 caps = query_amp_caps(codec, pin, HDA_OUTPUT);
4174 if (caps & AC_AMPCAP_NUM_STEPS) 4150 if (caps & AC_AMPCAP_NUM_STEPS)
4175 return cx_auto_add_pb_volume(codec, pin, name, idx); 4151 return cx_auto_add_pb_volume(codec, pin, name, idx);
@@ -4191,8 +4167,7 @@ static int cx_auto_build_output_controls(struct hda_codec *codec)
4191 for (i = 0; i < spec->dac_info_filled; i++) { 4167 for (i = 0; i < spec->dac_info_filled; i++) {
4192 const char *label; 4168 const char *label;
4193 int idx, type; 4169 int idx, type;
4194 if (!spec->dac_info[i].dac) 4170 hda_nid_t dac = spec->dac_info[i].dac;
4195 continue;
4196 type = spec->dac_info[i].type; 4171 type = spec->dac_info[i].type;
4197 if (type == AUTO_PIN_LINE_OUT) 4172 if (type == AUTO_PIN_LINE_OUT)
4198 type = spec->autocfg.line_out_type; 4173 type = spec->autocfg.line_out_type;
@@ -4211,7 +4186,7 @@ static int cx_auto_build_output_controls(struct hda_codec *codec)
4211 idx = num_spk++; 4186 idx = num_spk++;
4212 break; 4187 break;
4213 } 4188 }
4214 err = try_add_pb_volume(codec, spec->dac_info[i].dac, 4189 err = try_add_pb_volume(codec, dac,
4215 spec->dac_info[i].pin, 4190 spec->dac_info[i].pin,
4216 label, idx); 4191 label, idx);
4217 if (err < 0) 4192 if (err < 0)
@@ -4239,6 +4214,8 @@ static int cx_auto_add_capture_volume(struct hda_codec *codec, hda_nid_t nid,
4239 int idx = get_input_connection(codec, adc_nid, nid); 4214 int idx = get_input_connection(codec, adc_nid, nid);
4240 if (idx < 0) 4215 if (idx < 0)
4241 continue; 4216 continue;
4217 if (spec->single_adc_amp)
4218 idx = 0;
4242 return cx_auto_add_volume_idx(codec, label, pfx, 4219 return cx_auto_add_volume_idx(codec, label, pfx,
4243 cidx, adc_nid, HDA_INPUT, idx); 4220 cidx, adc_nid, HDA_INPUT, idx);
4244 } 4221 }
@@ -4279,14 +4256,21 @@ static int cx_auto_build_input_controls(struct hda_codec *codec)
4279 struct hda_input_mux *imux = &spec->private_imux; 4256 struct hda_input_mux *imux = &spec->private_imux;
4280 const char *prev_label; 4257 const char *prev_label;
4281 int input_conn[HDA_MAX_NUM_INPUTS]; 4258 int input_conn[HDA_MAX_NUM_INPUTS];
4282 int i, err, cidx; 4259 int i, j, err, cidx;
4283 int multi_connection; 4260 int multi_connection;
4284 4261
4262 if (!imux->num_items)
4263 return 0;
4264
4285 multi_connection = 0; 4265 multi_connection = 0;
4286 for (i = 0; i < imux->num_items; i++) { 4266 for (i = 0; i < imux->num_items; i++) {
4287 cidx = get_input_connection(codec, spec->imux_info[i].adc, 4267 cidx = get_input_connection(codec, spec->imux_info[i].adc,
4288 spec->imux_info[i].pin); 4268 spec->imux_info[i].pin);
4289 input_conn[i] = (spec->imux_info[i].adc << 8) | cidx; 4269 if (cidx < 0)
4270 continue;
4271 input_conn[i] = spec->imux_info[i].adc;
4272 if (!spec->single_adc_amp)
4273 input_conn[i] |= cidx << 8;
4290 if (i > 0 && input_conn[i] != input_conn[0]) 4274 if (i > 0 && input_conn[i] != input_conn[0])
4291 multi_connection = 1; 4275 multi_connection = 1;
4292 } 4276 }
@@ -4315,6 +4299,15 @@ static int cx_auto_build_input_controls(struct hda_codec *codec)
4315 err = cx_auto_add_capture_volume(codec, nid, 4299 err = cx_auto_add_capture_volume(codec, nid,
4316 "Capture", "", cidx); 4300 "Capture", "", cidx);
4317 } else { 4301 } else {
4302 bool dup_found = false;
4303 for (j = 0; j < i; j++) {
4304 if (input_conn[j] == input_conn[i]) {
4305 dup_found = true;
4306 break;
4307 }
4308 }
4309 if (dup_found)
4310 continue;
4318 err = cx_auto_add_capture_volume(codec, nid, 4311 err = cx_auto_add_capture_volume(codec, nid,
4319 label, " Capture", cidx); 4312 label, " Capture", cidx);
4320 } 4313 }
@@ -4378,6 +4371,53 @@ static const struct hda_codec_ops cx_auto_patch_ops = {
4378 .reboot_notify = snd_hda_shutup_pins, 4371 .reboot_notify = snd_hda_shutup_pins,
4379}; 4372};
4380 4373
4374/*
4375 * pin fix-up
4376 */
4377struct cxt_pincfg {
4378 hda_nid_t nid;
4379 u32 val;
4380};
4381
4382static void apply_pincfg(struct hda_codec *codec, const struct cxt_pincfg *cfg)
4383{
4384 for (; cfg->nid; cfg++)
4385 snd_hda_codec_set_pincfg(codec, cfg->nid, cfg->val);
4386
4387}
4388
4389static void apply_pin_fixup(struct hda_codec *codec,
4390 const struct snd_pci_quirk *quirk,
4391 const struct cxt_pincfg **table)
4392{
4393 quirk = snd_pci_quirk_lookup(codec->bus->pci, quirk);
4394 if (quirk) {
4395 snd_printdd(KERN_INFO "hda_codec: applying pincfg for %s\n",
4396 quirk->name);
4397 apply_pincfg(codec, table[quirk->value]);
4398 }
4399}
4400
4401enum {
4402 CXT_PINCFG_LENOVO_X200,
4403};
4404
4405static const struct cxt_pincfg cxt_pincfg_lenovo_x200[] = {
4406 { 0x16, 0x042140ff }, /* HP (seq# overridden) */
4407 { 0x17, 0x21a11000 }, /* dock-mic */
4408 { 0x19, 0x2121103f }, /* dock-HP */
4409 {}
4410};
4411
4412static const struct cxt_pincfg *cxt_pincfg_tbl[] = {
4413 [CXT_PINCFG_LENOVO_X200] = cxt_pincfg_lenovo_x200,
4414};
4415
4416static const struct snd_pci_quirk cxt_fixups[] = {
4417 SND_PCI_QUIRK(0x17aa, 0x20f2, "Lenovo X200", CXT_PINCFG_LENOVO_X200),
4418 {}
4419};
4420
4381static int patch_conexant_auto(struct hda_codec *codec) 4421static int patch_conexant_auto(struct hda_codec *codec)
4382{ 4422{
4383 struct conexant_spec *spec; 4423 struct conexant_spec *spec;
@@ -4391,6 +4431,15 @@ static int patch_conexant_auto(struct hda_codec *codec)
4391 return -ENOMEM; 4431 return -ENOMEM;
4392 codec->spec = spec; 4432 codec->spec = spec;
4393 codec->pin_amp_workaround = 1; 4433 codec->pin_amp_workaround = 1;
4434
4435 switch (codec->vendor_id) {
4436 case 0x14f15045:
4437 spec->single_adc_amp = 1;
4438 break;
4439 }
4440
4441 apply_pin_fixup(codec, cxt_fixups, cxt_pincfg_tbl);
4442
4394 err = cx_auto_search_adcs(codec); 4443 err = cx_auto_search_adcs(codec);
4395 if (err < 0) 4444 if (err < 0)
4396 return err; 4445 return err;
diff --git a/sound/pci/hda/patch_hdmi.c b/sound/pci/hda/patch_hdmi.c
index 19cb72db9c38..aac3bfacda3f 100644
--- a/sound/pci/hda/patch_hdmi.c
+++ b/sound/pci/hda/patch_hdmi.c
@@ -324,6 +324,66 @@ static int cvt_nid_to_cvt_index(struct hdmi_spec *spec, hda_nid_t cvt_nid)
324 return -EINVAL; 324 return -EINVAL;
325} 325}
326 326
327static int hdmi_eld_ctl_info(struct snd_kcontrol *kcontrol,
328 struct snd_ctl_elem_info *uinfo)
329{
330 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
331 struct hdmi_spec *spec;
332 int pin_idx;
333
334 spec = codec->spec;
335 uinfo->type = SNDRV_CTL_ELEM_TYPE_BYTES;
336
337 pin_idx = kcontrol->private_value;
338 uinfo->count = spec->pins[pin_idx].sink_eld.eld_size;
339
340 return 0;
341}
342
343static int hdmi_eld_ctl_get(struct snd_kcontrol *kcontrol,
344 struct snd_ctl_elem_value *ucontrol)
345{
346 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
347 struct hdmi_spec *spec;
348 int pin_idx;
349
350 spec = codec->spec;
351 pin_idx = kcontrol->private_value;
352
353 memcpy(ucontrol->value.bytes.data,
354 spec->pins[pin_idx].sink_eld.eld_buffer, ELD_MAX_SIZE);
355
356 return 0;
357}
358
359static struct snd_kcontrol_new eld_bytes_ctl = {
360 .access = SNDRV_CTL_ELEM_ACCESS_READ | SNDRV_CTL_ELEM_ACCESS_VOLATILE,
361 .iface = SNDRV_CTL_ELEM_IFACE_PCM,
362 .name = "ELD",
363 .info = hdmi_eld_ctl_info,
364 .get = hdmi_eld_ctl_get,
365};
366
367static int hdmi_create_eld_ctl(struct hda_codec *codec, int pin_idx,
368 int device)
369{
370 struct snd_kcontrol *kctl;
371 struct hdmi_spec *spec = codec->spec;
372 int err;
373
374 kctl = snd_ctl_new1(&eld_bytes_ctl, codec);
375 if (!kctl)
376 return -ENOMEM;
377 kctl->private_value = pin_idx;
378 kctl->id.device = device;
379
380 err = snd_hda_ctl_add(codec, spec->pins[pin_idx].pin_nid, kctl);
381 if (err < 0)
382 return err;
383
384 return 0;
385}
386
327#ifdef BE_PARANOID 387#ifdef BE_PARANOID
328static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid, 388static void hdmi_get_dip_index(struct hda_codec *codec, hda_nid_t pin_nid,
329 int *packet_index, int *byte_index) 389 int *packet_index, int *byte_index)
@@ -946,7 +1006,6 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
946 unsigned int caps, config; 1006 unsigned int caps, config;
947 int pin_idx; 1007 int pin_idx;
948 struct hdmi_spec_per_pin *per_pin; 1008 struct hdmi_spec_per_pin *per_pin;
949 struct hdmi_eld *eld;
950 int err; 1009 int err;
951 1010
952 caps = snd_hda_param_read(codec, pin_nid, AC_PAR_PIN_CAP); 1011 caps = snd_hda_param_read(codec, pin_nid, AC_PAR_PIN_CAP);
@@ -963,23 +1022,15 @@ static int hdmi_add_pin(struct hda_codec *codec, hda_nid_t pin_nid)
963 1022
964 pin_idx = spec->num_pins; 1023 pin_idx = spec->num_pins;
965 per_pin = &spec->pins[pin_idx]; 1024 per_pin = &spec->pins[pin_idx];
966 eld = &per_pin->sink_eld;
967 1025
968 per_pin->pin_nid = pin_nid; 1026 per_pin->pin_nid = pin_nid;
969 1027
970 err = snd_hda_input_jack_add(codec, pin_nid,
971 SND_JACK_VIDEOOUT, NULL);
972 if (err < 0)
973 return err;
974
975 err = hdmi_read_pin_conn(codec, pin_idx); 1028 err = hdmi_read_pin_conn(codec, pin_idx);
976 if (err < 0) 1029 if (err < 0)
977 return err; 1030 return err;
978 1031
979 spec->num_pins++; 1032 spec->num_pins++;
980 1033
981 hdmi_present_sense(codec, pin_nid, eld);
982
983 return 0; 1034 return 0;
984} 1035}
985 1036
@@ -1162,6 +1213,25 @@ static int generic_hdmi_build_pcms(struct hda_codec *codec)
1162 return 0; 1213 return 0;
1163} 1214}
1164 1215
1216static int generic_hdmi_build_jack(struct hda_codec *codec, int pin_idx)
1217{
1218 int err;
1219 char hdmi_str[32];
1220 struct hdmi_spec *spec = codec->spec;
1221 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1222 int pcmdev = spec->pcm_rec[pin_idx].device;
1223
1224 snprintf(hdmi_str, sizeof(hdmi_str), "HDMI/DP,pcm=%d", pcmdev);
1225
1226 err = snd_hda_input_jack_add(codec, per_pin->pin_nid,
1227 SND_JACK_VIDEOOUT, pcmdev > 0 ? hdmi_str : NULL);
1228 if (err < 0)
1229 return err;
1230
1231 hdmi_present_sense(codec, per_pin->pin_nid, &per_pin->sink_eld);
1232 return 0;
1233}
1234
1165static int generic_hdmi_build_controls(struct hda_codec *codec) 1235static int generic_hdmi_build_controls(struct hda_codec *codec)
1166{ 1236{
1167 struct hdmi_spec *spec = codec->spec; 1237 struct hdmi_spec *spec = codec->spec;
@@ -1170,12 +1240,25 @@ static int generic_hdmi_build_controls(struct hda_codec *codec)
1170 1240
1171 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) { 1241 for (pin_idx = 0; pin_idx < spec->num_pins; pin_idx++) {
1172 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx]; 1242 struct hdmi_spec_per_pin *per_pin = &spec->pins[pin_idx];
1243
1244 err = generic_hdmi_build_jack(codec, pin_idx);
1245 if (err < 0)
1246 return err;
1247
1173 err = snd_hda_create_spdif_out_ctls(codec, 1248 err = snd_hda_create_spdif_out_ctls(codec,
1174 per_pin->pin_nid, 1249 per_pin->pin_nid,
1175 per_pin->mux_nids[0]); 1250 per_pin->mux_nids[0]);
1176 if (err < 0) 1251 if (err < 0)
1177 return err; 1252 return err;
1178 snd_hda_spdif_ctls_unassign(codec, pin_idx); 1253 snd_hda_spdif_ctls_unassign(codec, pin_idx);
1254
1255 /* add control for ELD Bytes */
1256 err = hdmi_create_eld_ctl(codec,
1257 pin_idx,
1258 spec->pcm_rec[pin_idx].device);
1259
1260 if (err < 0)
1261 return err;
1179 } 1262 }
1180 1263
1181 return 0; 1264 return 0;
@@ -1491,7 +1574,7 @@ static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
1491 struct snd_pcm_substream *substream) 1574 struct snd_pcm_substream *substream)
1492{ 1575{
1493 int chs; 1576 int chs;
1494 unsigned int dataDCC1, dataDCC2, channel_id; 1577 unsigned int dataDCC2, channel_id;
1495 int i; 1578 int i;
1496 struct hdmi_spec *spec = codec->spec; 1579 struct hdmi_spec *spec = codec->spec;
1497 struct hda_spdif_out *spdif = 1580 struct hda_spdif_out *spdif =
@@ -1501,7 +1584,6 @@ static int nvhdmi_8ch_7x_pcm_prepare(struct hda_pcm_stream *hinfo,
1501 1584
1502 chs = substream->runtime->channels; 1585 chs = substream->runtime->channels;
1503 1586
1504 dataDCC1 = AC_DIG1_ENABLE | AC_DIG1_COPYRIGHT;
1505 dataDCC2 = 0x2; 1587 dataDCC2 = 0x2;
1506 1588
1507 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */ 1589 /* turn off SPDIF once; otherwise the IEC958 bits won't be updated */
diff --git a/sound/pci/hda/patch_realtek.c b/sound/pci/hda/patch_realtek.c
index e125c60fe352..80d6add8a620 100644
--- a/sound/pci/hda/patch_realtek.c
+++ b/sound/pci/hda/patch_realtek.c
@@ -116,6 +116,8 @@ struct alc_spec {
116 const hda_nid_t *capsrc_nids; 116 const hda_nid_t *capsrc_nids;
117 hda_nid_t dig_in_nid; /* digital-in NID; optional */ 117 hda_nid_t dig_in_nid; /* digital-in NID; optional */
118 hda_nid_t mixer_nid; /* analog-mixer NID */ 118 hda_nid_t mixer_nid; /* analog-mixer NID */
119 DECLARE_BITMAP(vol_ctls, 0x20 << 1);
120 DECLARE_BITMAP(sw_ctls, 0x20 << 1);
119 121
120 /* capture setup for dynamic dual-adc switch */ 122 /* capture setup for dynamic dual-adc switch */
121 hda_nid_t cur_adc; 123 hda_nid_t cur_adc;
@@ -159,23 +161,27 @@ struct alc_spec {
159 void (*power_hook)(struct hda_codec *codec); 161 void (*power_hook)(struct hda_codec *codec);
160#endif 162#endif
161 void (*shutup)(struct hda_codec *codec); 163 void (*shutup)(struct hda_codec *codec);
164 void (*automute_hook)(struct hda_codec *codec);
162 165
163 /* for pin sensing */ 166 /* for pin sensing */
164 unsigned int jack_present: 1; 167 unsigned int hp_jack_present:1;
165 unsigned int line_jack_present:1; 168 unsigned int line_jack_present:1;
166 unsigned int master_mute:1; 169 unsigned int master_mute:1;
167 unsigned int auto_mic:1; 170 unsigned int auto_mic:1;
168 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */ 171 unsigned int auto_mic_valid_imux:1; /* valid imux for auto-mic */
169 unsigned int automute:1; /* HP automute enabled */ 172 unsigned int automute_speaker:1; /* automute speaker outputs */
170 unsigned int detect_line:1; /* Line-out detection enabled */ 173 unsigned int automute_lo:1; /* automute LO outputs */
171 unsigned int automute_lines:1; /* automute line-out as well */ 174 unsigned int detect_hp:1; /* Headphone detection enabled */
172 unsigned int automute_hp_lo:1; /* both HP and LO available */ 175 unsigned int detect_lo:1; /* Line-out detection enabled */
176 unsigned int automute_speaker_possible:1; /* there are speakers and either LO or HP */
177 unsigned int automute_lo_possible:1; /* there are line outs and HP */
173 178
174 /* other flags */ 179 /* other flags */
175 unsigned int no_analog :1; /* digital I/O only */ 180 unsigned int no_analog :1; /* digital I/O only */
176 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */ 181 unsigned int dyn_adc_switch:1; /* switch ADCs (for ALC275) */
177 unsigned int single_input_src:1; 182 unsigned int single_input_src:1;
178 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */ 183 unsigned int vol_in_capsrc:1; /* use capsrc volume (ADC has no vol) */
184 unsigned int parse_flags; /* passed to snd_hda_parse_pin_defcfg() */
179 185
180 /* auto-mute control */ 186 /* auto-mute control */
181 int automute_mode; 187 int automute_mode;
@@ -193,6 +199,7 @@ struct alc_spec {
193 /* for PLL fix */ 199 /* for PLL fix */
194 hda_nid_t pll_nid; 200 hda_nid_t pll_nid;
195 unsigned int pll_coef_idx, pll_coef_bit; 201 unsigned int pll_coef_idx, pll_coef_bit;
202 unsigned int coef0;
196 203
197 /* fix-up list */ 204 /* fix-up list */
198 int fixup_id; 205 int fixup_id;
@@ -202,6 +209,9 @@ struct alc_spec {
202 /* multi-io */ 209 /* multi-io */
203 int multi_ios; 210 int multi_ios;
204 struct alc_multi_io multi_io[4]; 211 struct alc_multi_io multi_io[4];
212
213 /* bind volumes */
214 struct snd_array bind_ctls;
205}; 215};
206 216
207#define ALC_MODEL_AUTO 0 /* common for all chips */ 217#define ALC_MODEL_AUTO 0 /* common for all chips */
@@ -525,8 +535,8 @@ static void do_automute(struct hda_codec *codec, int num_pins, hda_nid_t *pins,
525 } 535 }
526} 536}
527 537
528/* Toggle internal speakers muting */ 538/* Toggle outputs muting */
529static void update_speakers(struct hda_codec *codec) 539static void update_outputs(struct hda_codec *codec)
530{ 540{
531 struct alc_spec *spec = codec->spec; 541 struct alc_spec *spec = codec->spec;
532 int on; 542 int on;
@@ -538,10 +548,10 @@ static void update_speakers(struct hda_codec *codec)
538 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins), 548 do_automute(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
539 spec->autocfg.hp_pins, spec->master_mute, true); 549 spec->autocfg.hp_pins, spec->master_mute, true);
540 550
541 if (!spec->automute) 551 if (!spec->automute_speaker)
542 on = 0; 552 on = 0;
543 else 553 else
544 on = spec->jack_present | spec->line_jack_present; 554 on = spec->hp_jack_present | spec->line_jack_present;
545 on |= spec->master_mute; 555 on |= spec->master_mute;
546 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins), 556 do_automute(codec, ARRAY_SIZE(spec->autocfg.speaker_pins),
547 spec->autocfg.speaker_pins, on, false); 557 spec->autocfg.speaker_pins, on, false);
@@ -551,26 +561,35 @@ static void update_speakers(struct hda_codec *codec)
551 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] || 561 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0] ||
552 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0]) 562 spec->autocfg.line_out_pins[0] == spec->autocfg.speaker_pins[0])
553 return; 563 return;
554 if (!spec->automute_lines || !spec->automute) 564 if (!spec->automute_lo)
555 on = 0; 565 on = 0;
556 else 566 else
557 on = spec->jack_present; 567 on = spec->hp_jack_present;
558 on |= spec->master_mute; 568 on |= spec->master_mute;
559 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), 569 do_automute(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
560 spec->autocfg.line_out_pins, on, false); 570 spec->autocfg.line_out_pins, on, false);
561} 571}
562 572
573static void call_update_outputs(struct hda_codec *codec)
574{
575 struct alc_spec *spec = codec->spec;
576 if (spec->automute_hook)
577 spec->automute_hook(codec);
578 else
579 update_outputs(codec);
580}
581
563/* standard HP-automute helper */ 582/* standard HP-automute helper */
564static void alc_hp_automute(struct hda_codec *codec) 583static void alc_hp_automute(struct hda_codec *codec)
565{ 584{
566 struct alc_spec *spec = codec->spec; 585 struct alc_spec *spec = codec->spec;
567 586
568 if (!spec->automute) 587 spec->hp_jack_present =
569 return;
570 spec->jack_present =
571 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins), 588 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.hp_pins),
572 spec->autocfg.hp_pins); 589 spec->autocfg.hp_pins);
573 update_speakers(codec); 590 if (!spec->detect_hp || (!spec->automute_speaker && !spec->automute_lo))
591 return;
592 call_update_outputs(codec);
574} 593}
575 594
576/* standard line-out-automute helper */ 595/* standard line-out-automute helper */
@@ -578,12 +597,16 @@ static void alc_line_automute(struct hda_codec *codec)
578{ 597{
579 struct alc_spec *spec = codec->spec; 598 struct alc_spec *spec = codec->spec;
580 599
581 if (!spec->automute || !spec->detect_line) 600 /* check LO jack only when it's different from HP */
601 if (spec->autocfg.line_out_pins[0] == spec->autocfg.hp_pins[0])
582 return; 602 return;
603
583 spec->line_jack_present = 604 spec->line_jack_present =
584 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins), 605 detect_jacks(codec, ARRAY_SIZE(spec->autocfg.line_out_pins),
585 spec->autocfg.line_out_pins); 606 spec->autocfg.line_out_pins);
586 update_speakers(codec); 607 if (!spec->automute_speaker || !spec->detect_lo)
608 return;
609 call_update_outputs(codec);
587} 610}
588 611
589#define get_connection_index(codec, mux, nid) \ 612#define get_connection_index(codec, mux, nid) \
@@ -781,7 +804,7 @@ static int alc_automute_mode_info(struct snd_kcontrol *kcontrol,
781 804
782 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED; 805 uinfo->type = SNDRV_CTL_ELEM_TYPE_ENUMERATED;
783 uinfo->count = 1; 806 uinfo->count = 1;
784 if (spec->automute_hp_lo) { 807 if (spec->automute_speaker_possible && spec->automute_lo_possible) {
785 uinfo->value.enumerated.items = 3; 808 uinfo->value.enumerated.items = 3;
786 texts = texts3; 809 texts = texts3;
787 } else { 810 } else {
@@ -800,13 +823,12 @@ static int alc_automute_mode_get(struct snd_kcontrol *kcontrol,
800{ 823{
801 struct hda_codec *codec = snd_kcontrol_chip(kcontrol); 824 struct hda_codec *codec = snd_kcontrol_chip(kcontrol);
802 struct alc_spec *spec = codec->spec; 825 struct alc_spec *spec = codec->spec;
803 unsigned int val; 826 unsigned int val = 0;
804 if (!spec->automute) 827 if (spec->automute_speaker)
805 val = 0; 828 val++;
806 else if (!spec->automute_lines) 829 if (spec->automute_lo)
807 val = 1; 830 val++;
808 else 831
809 val = 2;
810 ucontrol->value.enumerated.item[0] = val; 832 ucontrol->value.enumerated.item[0] = val;
811 return 0; 833 return 0;
812} 834}
@@ -819,28 +841,36 @@ static int alc_automute_mode_put(struct snd_kcontrol *kcontrol,
819 841
820 switch (ucontrol->value.enumerated.item[0]) { 842 switch (ucontrol->value.enumerated.item[0]) {
821 case 0: 843 case 0:
822 if (!spec->automute) 844 if (!spec->automute_speaker && !spec->automute_lo)
823 return 0; 845 return 0;
824 spec->automute = 0; 846 spec->automute_speaker = 0;
847 spec->automute_lo = 0;
825 break; 848 break;
826 case 1: 849 case 1:
827 if (spec->automute && !spec->automute_lines) 850 if (spec->automute_speaker_possible) {
828 return 0; 851 if (!spec->automute_lo && spec->automute_speaker)
829 spec->automute = 1; 852 return 0;
830 spec->automute_lines = 0; 853 spec->automute_speaker = 1;
854 spec->automute_lo = 0;
855 } else if (spec->automute_lo_possible) {
856 if (spec->automute_lo)
857 return 0;
858 spec->automute_lo = 1;
859 } else
860 return -EINVAL;
831 break; 861 break;
832 case 2: 862 case 2:
833 if (!spec->automute_hp_lo) 863 if (!spec->automute_lo_possible || !spec->automute_speaker_possible)
834 return -EINVAL; 864 return -EINVAL;
835 if (spec->automute && spec->automute_lines) 865 if (spec->automute_speaker && spec->automute_lo)
836 return 0; 866 return 0;
837 spec->automute = 1; 867 spec->automute_speaker = 1;
838 spec->automute_lines = 1; 868 spec->automute_lo = 1;
839 break; 869 break;
840 default: 870 default:
841 return -EINVAL; 871 return -EINVAL;
842 } 872 }
843 update_speakers(codec); 873 call_update_outputs(codec);
844 return 1; 874 return 1;
845} 875}
846 876
@@ -877,7 +907,7 @@ static int alc_add_automute_mode_enum(struct hda_codec *codec)
877 * Check the availability of HP/line-out auto-mute; 907 * Check the availability of HP/line-out auto-mute;
878 * Set up appropriately if really supported 908 * Set up appropriately if really supported
879 */ 909 */
880static void alc_init_auto_hp(struct hda_codec *codec) 910static void alc_init_automute(struct hda_codec *codec)
881{ 911{
882 struct alc_spec *spec = codec->spec; 912 struct alc_spec *spec = codec->spec;
883 struct auto_pin_cfg *cfg = &spec->autocfg; 913 struct auto_pin_cfg *cfg = &spec->autocfg;
@@ -892,8 +922,6 @@ static void alc_init_auto_hp(struct hda_codec *codec)
892 present++; 922 present++;
893 if (present < 2) /* need two different output types */ 923 if (present < 2) /* need two different output types */
894 return; 924 return;
895 if (present == 3)
896 spec->automute_hp_lo = 1; /* both HP and LO automute */
897 925
898 if (!cfg->speaker_pins[0] && 926 if (!cfg->speaker_pins[0] &&
899 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) { 927 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT) {
@@ -909,6 +937,8 @@ static void alc_init_auto_hp(struct hda_codec *codec)
909 cfg->hp_outs = cfg->line_outs; 937 cfg->hp_outs = cfg->line_outs;
910 } 938 }
911 939
940 spec->automute_mode = ALC_AUTOMUTE_PIN;
941
912 for (i = 0; i < cfg->hp_outs; i++) { 942 for (i = 0; i < cfg->hp_outs; i++) {
913 hda_nid_t nid = cfg->hp_pins[i]; 943 hda_nid_t nid = cfg->hp_pins[i];
914 if (!is_jack_detectable(codec, nid)) 944 if (!is_jack_detectable(codec, nid))
@@ -918,28 +948,32 @@ static void alc_init_auto_hp(struct hda_codec *codec)
918 snd_hda_codec_write_cache(codec, nid, 0, 948 snd_hda_codec_write_cache(codec, nid, 0,
919 AC_VERB_SET_UNSOLICITED_ENABLE, 949 AC_VERB_SET_UNSOLICITED_ENABLE,
920 AC_USRSP_EN | ALC_HP_EVENT); 950 AC_USRSP_EN | ALC_HP_EVENT);
921 spec->automute = 1; 951 spec->detect_hp = 1;
922 spec->automute_mode = ALC_AUTOMUTE_PIN; 952 }
923 } 953
924 if (spec->automute && cfg->line_out_pins[0] && 954 if (cfg->line_out_type == AUTO_PIN_LINE_OUT && cfg->line_outs) {
925 cfg->speaker_pins[0] && 955 if (cfg->speaker_outs)
926 cfg->line_out_pins[0] != cfg->hp_pins[0] && 956 for (i = 0; i < cfg->line_outs; i++) {
927 cfg->line_out_pins[0] != cfg->speaker_pins[0]) { 957 hda_nid_t nid = cfg->line_out_pins[i];
928 for (i = 0; i < cfg->line_outs; i++) { 958 if (!is_jack_detectable(codec, nid))
929 hda_nid_t nid = cfg->line_out_pins[i]; 959 continue;
930 if (!is_jack_detectable(codec, nid)) 960 snd_printdd("realtek: Enable Line-Out "
931 continue; 961 "auto-muting on NID 0x%x\n", nid);
932 snd_printdd("realtek: Enable Line-Out auto-muting " 962 snd_hda_codec_write_cache(codec, nid, 0,
933 "on NID 0x%x\n", nid); 963 AC_VERB_SET_UNSOLICITED_ENABLE,
934 snd_hda_codec_write_cache(codec, nid, 0, 964 AC_USRSP_EN | ALC_FRONT_EVENT);
935 AC_VERB_SET_UNSOLICITED_ENABLE, 965 spec->detect_lo = 1;
936 AC_USRSP_EN | ALC_FRONT_EVENT);
937 spec->detect_line = 1;
938 } 966 }
939 spec->automute_lines = spec->detect_line; 967 spec->automute_lo_possible = spec->detect_hp;
940 } 968 }
941 969
942 if (spec->automute) { 970 spec->automute_speaker_possible = cfg->speaker_outs &&
971 (spec->detect_hp || spec->detect_lo);
972
973 spec->automute_lo = spec->automute_lo_possible;
974 spec->automute_speaker = spec->automute_speaker_possible;
975
976 if (spec->automute_speaker_possible || spec->automute_lo_possible) {
943 /* create a control for automute mode */ 977 /* create a control for automute mode */
944 alc_add_automute_mode_enum(codec); 978 alc_add_automute_mode_enum(codec);
945 spec->unsol_event = alc_sku_unsol_event; 979 spec->unsol_event = alc_sku_unsol_event;
@@ -1140,7 +1174,7 @@ static void alc_init_auto_mic(struct hda_codec *codec)
1140/* check the availabilities of auto-mute and auto-mic switches */ 1174/* check the availabilities of auto-mute and auto-mic switches */
1141static void alc_auto_check_switches(struct hda_codec *codec) 1175static void alc_auto_check_switches(struct hda_codec *codec)
1142{ 1176{
1143 alc_init_auto_hp(codec); 1177 alc_init_automute(codec);
1144 alc_init_auto_mic(codec); 1178 alc_init_auto_mic(codec);
1145} 1179}
1146 1180
@@ -1320,7 +1354,9 @@ do_sku:
1320 * 15 : 1 --> enable the function "Mute internal speaker 1354 * 15 : 1 --> enable the function "Mute internal speaker
1321 * when the external headphone out jack is plugged" 1355 * when the external headphone out jack is plugged"
1322 */ 1356 */
1323 if (!spec->autocfg.hp_pins[0]) { 1357 if (!spec->autocfg.hp_pins[0] &&
1358 !(spec->autocfg.line_out_pins[0] &&
1359 spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)) {
1324 hda_nid_t nid; 1360 hda_nid_t nid;
1325 tmp = (ass >> 11) & 0x3; /* HP to chassis */ 1361 tmp = (ass >> 11) & 0x3; /* HP to chassis */
1326 if (tmp == 0) 1362 if (tmp == 0)
@@ -1521,6 +1557,15 @@ static void alc_write_coef_idx(struct hda_codec *codec, unsigned int coef_idx,
1521 coef_val); 1557 coef_val);
1522} 1558}
1523 1559
1560/* a special bypass for COEF 0; read the cached value at the second time */
1561static unsigned int alc_get_coef0(struct hda_codec *codec)
1562{
1563 struct alc_spec *spec = codec->spec;
1564 if (!spec->coef0)
1565 spec->coef0 = alc_read_coef_idx(codec, 0);
1566 return spec->coef0;
1567}
1568
1524/* 1569/*
1525 * Digital I/O handling 1570 * Digital I/O handling
1526 */ 1571 */
@@ -1559,27 +1604,29 @@ static void alc_auto_init_digital(struct hda_codec *codec)
1559static void alc_auto_parse_digital(struct hda_codec *codec) 1604static void alc_auto_parse_digital(struct hda_codec *codec)
1560{ 1605{
1561 struct alc_spec *spec = codec->spec; 1606 struct alc_spec *spec = codec->spec;
1562 int i, err; 1607 int i, err, nums;
1563 hda_nid_t dig_nid; 1608 hda_nid_t dig_nid;
1564 1609
1565 /* support multiple SPDIFs; the secondary is set up as a slave */ 1610 /* support multiple SPDIFs; the secondary is set up as a slave */
1611 nums = 0;
1566 for (i = 0; i < spec->autocfg.dig_outs; i++) { 1612 for (i = 0; i < spec->autocfg.dig_outs; i++) {
1567 hda_nid_t conn[4]; 1613 hda_nid_t conn[4];
1568 err = snd_hda_get_connections(codec, 1614 err = snd_hda_get_connections(codec,
1569 spec->autocfg.dig_out_pins[i], 1615 spec->autocfg.dig_out_pins[i],
1570 conn, ARRAY_SIZE(conn)); 1616 conn, ARRAY_SIZE(conn));
1571 if (err < 0) 1617 if (err <= 0)
1572 continue; 1618 continue;
1573 dig_nid = conn[0]; /* assume the first element is audio-out */ 1619 dig_nid = conn[0]; /* assume the first element is audio-out */
1574 if (!i) { 1620 if (!nums) {
1575 spec->multiout.dig_out_nid = dig_nid; 1621 spec->multiout.dig_out_nid = dig_nid;
1576 spec->dig_out_type = spec->autocfg.dig_out_type[0]; 1622 spec->dig_out_type = spec->autocfg.dig_out_type[0];
1577 } else { 1623 } else {
1578 spec->multiout.slave_dig_outs = spec->slave_dig_outs; 1624 spec->multiout.slave_dig_outs = spec->slave_dig_outs;
1579 if (i >= ARRAY_SIZE(spec->slave_dig_outs) - 1) 1625 if (nums >= ARRAY_SIZE(spec->slave_dig_outs) - 1)
1580 break; 1626 break;
1581 spec->slave_dig_outs[i - 1] = dig_nid; 1627 spec->slave_dig_outs[nums - 1] = dig_nid;
1582 } 1628 }
1629 nums++;
1583 } 1630 }
1584 1631
1585 if (spec->autocfg.dig_in_pin) { 1632 if (spec->autocfg.dig_in_pin) {
@@ -1784,6 +1831,7 @@ static const char * const alc_slave_vols[] = {
1784 "Speaker Playback Volume", 1831 "Speaker Playback Volume",
1785 "Mono Playback Volume", 1832 "Mono Playback Volume",
1786 "Line-Out Playback Volume", 1833 "Line-Out Playback Volume",
1834 "PCM Playback Volume",
1787 NULL, 1835 NULL,
1788}; 1836};
1789 1837
@@ -1798,6 +1846,7 @@ static const char * const alc_slave_sws[] = {
1798 "Mono Playback Switch", 1846 "Mono Playback Switch",
1799 "IEC958 Playback Switch", 1847 "IEC958 Playback Switch",
1800 "Line-Out Playback Switch", 1848 "Line-Out Playback Switch",
1849 "PCM Playback Switch",
1801 NULL, 1850 NULL,
1802}; 1851};
1803 1852
@@ -2223,6 +2272,7 @@ static int alc_build_pcms(struct hda_codec *codec)
2223 struct alc_spec *spec = codec->spec; 2272 struct alc_spec *spec = codec->spec;
2224 struct hda_pcm *info = spec->pcm_rec; 2273 struct hda_pcm *info = spec->pcm_rec;
2225 const struct hda_pcm_stream *p; 2274 const struct hda_pcm_stream *p;
2275 bool have_multi_adcs;
2226 int i; 2276 int i;
2227 2277
2228 codec->num_pcms = 1; 2278 codec->num_pcms = 1;
@@ -2301,8 +2351,11 @@ static int alc_build_pcms(struct hda_codec *codec)
2301 /* If the use of more than one ADC is requested for the current 2351 /* If the use of more than one ADC is requested for the current
2302 * model, configure a second analog capture-only PCM. 2352 * model, configure a second analog capture-only PCM.
2303 */ 2353 */
2354 have_multi_adcs = (spec->num_adc_nids > 1) &&
2355 !spec->dyn_adc_switch && !spec->auto_mic &&
2356 (!spec->input_mux || spec->input_mux->num_items > 1);
2304 /* Additional Analaog capture for index #2 */ 2357 /* Additional Analaog capture for index #2 */
2305 if (spec->alt_dac_nid || spec->num_adc_nids > 1) { 2358 if (spec->alt_dac_nid || have_multi_adcs) {
2306 codec->num_pcms = 3; 2359 codec->num_pcms = 3;
2307 info = spec->pcm_rec + 2; 2360 info = spec->pcm_rec + 2;
2308 info->name = spec->stream_name_analog; 2361 info->name = spec->stream_name_analog;
@@ -2318,7 +2371,7 @@ static int alc_build_pcms(struct hda_codec *codec)
2318 alc_pcm_null_stream; 2371 alc_pcm_null_stream;
2319 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0; 2372 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 0;
2320 } 2373 }
2321 if (spec->num_adc_nids > 1) { 2374 if (have_multi_adcs) {
2322 p = spec->stream_analog_alt_capture; 2375 p = spec->stream_analog_alt_capture;
2323 if (!p) 2376 if (!p)
2324 p = &alc_pcm_analog_alt_capture; 2377 p = &alc_pcm_analog_alt_capture;
@@ -2359,6 +2412,18 @@ static void alc_free_kctls(struct hda_codec *codec)
2359 snd_array_free(&spec->kctls); 2412 snd_array_free(&spec->kctls);
2360} 2413}
2361 2414
2415static void alc_free_bind_ctls(struct hda_codec *codec)
2416{
2417 struct alc_spec *spec = codec->spec;
2418 if (spec->bind_ctls.list) {
2419 struct hda_bind_ctls **ctl = spec->bind_ctls.list;
2420 int i;
2421 for (i = 0; i < spec->bind_ctls.used; i++)
2422 kfree(ctl[i]);
2423 }
2424 snd_array_free(&spec->bind_ctls);
2425}
2426
2362static void alc_free(struct hda_codec *codec) 2427static void alc_free(struct hda_codec *codec)
2363{ 2428{
2364 struct alc_spec *spec = codec->spec; 2429 struct alc_spec *spec = codec->spec;
@@ -2369,6 +2434,7 @@ static void alc_free(struct hda_codec *codec)
2369 alc_shutup(codec); 2434 alc_shutup(codec);
2370 snd_hda_input_jack_free(codec); 2435 snd_hda_input_jack_free(codec);
2371 alc_free_kctls(codec); 2436 alc_free_kctls(codec);
2437 alc_free_bind_ctls(codec);
2372 kfree(spec); 2438 kfree(spec);
2373 snd_hda_detach_beep_device(codec); 2439 snd_hda_detach_beep_device(codec);
2374} 2440}
@@ -2432,6 +2498,47 @@ static int alc_codec_rename(struct hda_codec *codec, const char *name)
2432} 2498}
2433 2499
2434/* 2500/*
2501 * Rename codecs appropriately from COEF value
2502 */
2503struct alc_codec_rename_table {
2504 unsigned int vendor_id;
2505 unsigned short coef_mask;
2506 unsigned short coef_bits;
2507 const char *name;
2508};
2509
2510static struct alc_codec_rename_table rename_tbl[] = {
2511 { 0x10ec0269, 0xfff0, 0x3010, "ALC277" },
2512 { 0x10ec0269, 0xf0f0, 0x2010, "ALC259" },
2513 { 0x10ec0269, 0xf0f0, 0x3010, "ALC258" },
2514 { 0x10ec0269, 0x00f0, 0x0010, "ALC269VB" },
2515 { 0x10ec0269, 0xffff, 0xa023, "ALC259" },
2516 { 0x10ec0269, 0xffff, 0x6023, "ALC281X" },
2517 { 0x10ec0269, 0x00f0, 0x0020, "ALC269VC" },
2518 { 0x10ec0887, 0x00f0, 0x0030, "ALC887-VD" },
2519 { 0x10ec0888, 0x00f0, 0x0030, "ALC888-VD" },
2520 { 0x10ec0888, 0xf0f0, 0x3020, "ALC886" },
2521 { 0x10ec0899, 0x2000, 0x2000, "ALC899" },
2522 { 0x10ec0892, 0xffff, 0x8020, "ALC661" },
2523 { 0x10ec0892, 0xffff, 0x8011, "ALC661" },
2524 { 0x10ec0892, 0xffff, 0x4011, "ALC656" },
2525 { } /* terminator */
2526};
2527
2528static int alc_codec_rename_from_preset(struct hda_codec *codec)
2529{
2530 const struct alc_codec_rename_table *p;
2531
2532 for (p = rename_tbl; p->vendor_id; p++) {
2533 if (p->vendor_id != codec->vendor_id)
2534 continue;
2535 if ((alc_get_coef0(codec) & p->coef_mask) == p->coef_bits)
2536 return alc_codec_rename(codec, p->name);
2537 }
2538 return 0;
2539}
2540
2541/*
2435 * Automatic parse of I/O pins from the BIOS configuration 2542 * Automatic parse of I/O pins from the BIOS configuration
2436 */ 2543 */
2437 2544
@@ -2439,11 +2546,15 @@ enum {
2439 ALC_CTL_WIDGET_VOL, 2546 ALC_CTL_WIDGET_VOL,
2440 ALC_CTL_WIDGET_MUTE, 2547 ALC_CTL_WIDGET_MUTE,
2441 ALC_CTL_BIND_MUTE, 2548 ALC_CTL_BIND_MUTE,
2549 ALC_CTL_BIND_VOL,
2550 ALC_CTL_BIND_SW,
2442}; 2551};
2443static const struct snd_kcontrol_new alc_control_templates[] = { 2552static const struct snd_kcontrol_new alc_control_templates[] = {
2444 HDA_CODEC_VOLUME(NULL, 0, 0, 0), 2553 HDA_CODEC_VOLUME(NULL, 0, 0, 0),
2445 HDA_CODEC_MUTE(NULL, 0, 0, 0), 2554 HDA_CODEC_MUTE(NULL, 0, 0, 0),
2446 HDA_BIND_MUTE(NULL, 0, 0, 0), 2555 HDA_BIND_MUTE(NULL, 0, 0, 0),
2556 HDA_BIND_VOL(NULL, 0),
2557 HDA_BIND_SW(NULL, 0),
2447}; 2558};
2448 2559
2449/* add dynamic controls */ 2560/* add dynamic controls */
@@ -2484,13 +2595,14 @@ static int add_control_with_pfx(struct alc_spec *spec, int type,
2484#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \ 2595#define __add_pb_sw_ctrl(spec, type, pfx, cidx, val) \
2485 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val) 2596 add_control_with_pfx(spec, type, pfx, "Playback", "Switch", cidx, val)
2486 2597
2598static const char * const channel_name[4] = {
2599 "Front", "Surround", "CLFE", "Side"
2600};
2601
2487static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch, 2602static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2488 bool can_be_master, int *index) 2603 bool can_be_master, int *index)
2489{ 2604{
2490 struct auto_pin_cfg *cfg = &spec->autocfg; 2605 struct auto_pin_cfg *cfg = &spec->autocfg;
2491 static const char * const chname[4] = {
2492 "Front", "Surround", NULL /*CLFE*/, "Side"
2493 };
2494 2606
2495 *index = 0; 2607 *index = 0;
2496 if (cfg->line_outs == 1 && !spec->multi_ios && 2608 if (cfg->line_outs == 1 && !spec->multi_ios &&
@@ -2513,7 +2625,10 @@ static const char *alc_get_line_out_pfx(struct alc_spec *spec, int ch,
2513 return "PCM"; 2625 return "PCM";
2514 break; 2626 break;
2515 } 2627 }
2516 return chname[ch]; 2628 if (snd_BUG_ON(ch >= ARRAY_SIZE(channel_name)))
2629 return "PCM";
2630
2631 return channel_name[ch];
2517} 2632}
2518 2633
2519/* create input playback/capture controls for the given pin */ 2634/* create input playback/capture controls for the given pin */
@@ -2548,7 +2663,6 @@ static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2548 hda_nid_t *adc_nids = spec->private_adc_nids; 2663 hda_nid_t *adc_nids = spec->private_adc_nids;
2549 hda_nid_t *cap_nids = spec->private_capsrc_nids; 2664 hda_nid_t *cap_nids = spec->private_capsrc_nids;
2550 int max_nums = ARRAY_SIZE(spec->private_adc_nids); 2665 int max_nums = ARRAY_SIZE(spec->private_adc_nids);
2551 bool indep_capsrc = false;
2552 int i, nums = 0; 2666 int i, nums = 0;
2553 2667
2554 nid = codec->start_nid; 2668 nid = codec->start_nid;
@@ -2570,13 +2684,11 @@ static int alc_auto_fill_adc_caps(struct hda_codec *codec)
2570 break; 2684 break;
2571 if (type == AC_WID_AUD_SEL) { 2685 if (type == AC_WID_AUD_SEL) {
2572 cap_nids[nums] = src; 2686 cap_nids[nums] = src;
2573 indep_capsrc = true;
2574 break; 2687 break;
2575 } 2688 }
2576 n = snd_hda_get_conn_list(codec, src, &list); 2689 n = snd_hda_get_conn_list(codec, src, &list);
2577 if (n > 1) { 2690 if (n > 1) {
2578 cap_nids[nums] = src; 2691 cap_nids[nums] = src;
2579 indep_capsrc = true;
2580 break; 2692 break;
2581 } else if (n != 1) 2693 } else if (n != 1)
2582 break; 2694 break;
@@ -2777,8 +2889,9 @@ static hda_nid_t alc_auto_look_for_dac(struct hda_codec *codec, hda_nid_t pin)
2777 if (found_in_nid_list(nid, spec->multiout.dac_nids, 2889 if (found_in_nid_list(nid, spec->multiout.dac_nids,
2778 spec->multiout.num_dacs)) 2890 spec->multiout.num_dacs))
2779 continue; 2891 continue;
2780 if (spec->multiout.hp_nid == nid) 2892 if (found_in_nid_list(nid, spec->multiout.hp_out_nid,
2781 continue; 2893 ARRAY_SIZE(spec->multiout.hp_out_nid)))
2894 continue;
2782 if (found_in_nid_list(nid, spec->multiout.extra_out_nid, 2895 if (found_in_nid_list(nid, spec->multiout.extra_out_nid,
2783 ARRAY_SIZE(spec->multiout.extra_out_nid))) 2896 ARRAY_SIZE(spec->multiout.extra_out_nid)))
2784 continue; 2897 continue;
@@ -2795,6 +2908,29 @@ static hda_nid_t get_dac_if_single(struct hda_codec *codec, hda_nid_t pin)
2795 return 0; 2908 return 0;
2796} 2909}
2797 2910
2911static int alc_auto_fill_extra_dacs(struct hda_codec *codec, int num_outs,
2912 const hda_nid_t *pins, hda_nid_t *dacs)
2913{
2914 int i;
2915
2916 if (num_outs && !dacs[0]) {
2917 dacs[0] = alc_auto_look_for_dac(codec, pins[0]);
2918 if (!dacs[0])
2919 return 0;
2920 }
2921
2922 for (i = 1; i < num_outs; i++)
2923 dacs[i] = get_dac_if_single(codec, pins[i]);
2924 for (i = 1; i < num_outs; i++) {
2925 if (!dacs[i])
2926 dacs[i] = alc_auto_look_for_dac(codec, pins[i]);
2927 }
2928 return 0;
2929}
2930
2931static int alc_auto_fill_multi_ios(struct hda_codec *codec,
2932 unsigned int location);
2933
2798/* fill in the dac_nids table from the parsed pin configuration */ 2934/* fill in the dac_nids table from the parsed pin configuration */
2799static int alc_auto_fill_dac_nids(struct hda_codec *codec) 2935static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2800{ 2936{
@@ -2806,7 +2942,7 @@ static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2806 again: 2942 again:
2807 /* set num_dacs once to full for alc_auto_look_for_dac() */ 2943 /* set num_dacs once to full for alc_auto_look_for_dac() */
2808 spec->multiout.num_dacs = cfg->line_outs; 2944 spec->multiout.num_dacs = cfg->line_outs;
2809 spec->multiout.hp_nid = 0; 2945 spec->multiout.hp_out_nid[0] = 0;
2810 spec->multiout.extra_out_nid[0] = 0; 2946 spec->multiout.extra_out_nid[0] = 0;
2811 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids)); 2947 memset(spec->private_dac_nids, 0, sizeof(spec->private_dac_nids));
2812 spec->multiout.dac_nids = spec->private_dac_nids; 2948 spec->multiout.dac_nids = spec->private_dac_nids;
@@ -2817,7 +2953,7 @@ static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2817 spec->private_dac_nids[i] = 2953 spec->private_dac_nids[i] =
2818 get_dac_if_single(codec, cfg->line_out_pins[i]); 2954 get_dac_if_single(codec, cfg->line_out_pins[i]);
2819 if (cfg->hp_outs) 2955 if (cfg->hp_outs)
2820 spec->multiout.hp_nid = 2956 spec->multiout.hp_out_nid[0] =
2821 get_dac_if_single(codec, cfg->hp_pins[0]); 2957 get_dac_if_single(codec, cfg->hp_pins[0]);
2822 if (cfg->speaker_outs) 2958 if (cfg->speaker_outs)
2823 spec->multiout.extra_out_nid[0] = 2959 spec->multiout.extra_out_nid[0] =
@@ -2849,24 +2985,58 @@ static int alc_auto_fill_dac_nids(struct hda_codec *codec)
2849 sizeof(hda_nid_t) * (cfg->line_outs - i - 1)); 2985 sizeof(hda_nid_t) * (cfg->line_outs - i - 1));
2850 } 2986 }
2851 2987
2852 if (cfg->hp_outs && !spec->multiout.hp_nid) 2988 if (cfg->line_outs == 1 && cfg->line_out_type != AUTO_PIN_SPEAKER_OUT) {
2853 spec->multiout.hp_nid = 2989 /* try to fill multi-io first */
2854 alc_auto_look_for_dac(codec, cfg->hp_pins[0]); 2990 unsigned int location, defcfg;
2855 if (cfg->speaker_outs && !spec->multiout.extra_out_nid[0]) 2991 int num_pins;
2856 spec->multiout.extra_out_nid[0] = 2992
2857 alc_auto_look_for_dac(codec, cfg->speaker_pins[0]); 2993 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
2994 location = get_defcfg_location(defcfg);
2995
2996 num_pins = alc_auto_fill_multi_ios(codec, location);
2997 if (num_pins > 0) {
2998 spec->multi_ios = num_pins;
2999 spec->ext_channel_count = 2;
3000 spec->multiout.num_dacs = num_pins + 1;
3001 }
3002 }
3003
3004 if (cfg->line_out_type != AUTO_PIN_HP_OUT)
3005 alc_auto_fill_extra_dacs(codec, cfg->hp_outs, cfg->hp_pins,
3006 spec->multiout.hp_out_nid);
3007 if (cfg->line_out_type != AUTO_PIN_SPEAKER_OUT)
3008 alc_auto_fill_extra_dacs(codec, cfg->speaker_outs, cfg->speaker_pins,
3009 spec->multiout.extra_out_nid);
2858 3010
2859 return 0; 3011 return 0;
2860} 3012}
2861 3013
3014static inline unsigned int get_ctl_pos(unsigned int data)
3015{
3016 hda_nid_t nid = get_amp_nid_(data);
3017 unsigned int dir = get_amp_direction_(data);
3018 return (nid << 1) | dir;
3019}
3020
3021#define is_ctl_used(bits, data) \
3022 test_bit(get_ctl_pos(data), bits)
3023#define mark_ctl_usage(bits, data) \
3024 set_bit(get_ctl_pos(data), bits)
3025
2862static int alc_auto_add_vol_ctl(struct hda_codec *codec, 3026static int alc_auto_add_vol_ctl(struct hda_codec *codec,
2863 const char *pfx, int cidx, 3027 const char *pfx, int cidx,
2864 hda_nid_t nid, unsigned int chs) 3028 hda_nid_t nid, unsigned int chs)
2865{ 3029{
3030 struct alc_spec *spec = codec->spec;
3031 unsigned int val;
2866 if (!nid) 3032 if (!nid)
2867 return 0; 3033 return 0;
3034 val = HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT);
3035 if (is_ctl_used(spec->vol_ctls, val) && chs != 2) /* exclude LFE */
3036 return 0;
3037 mark_ctl_usage(spec->vol_ctls, val);
2868 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx, 3038 return __add_pb_vol_ctrl(codec->spec, ALC_CTL_WIDGET_VOL, pfx, cidx,
2869 HDA_COMPOSE_AMP_VAL(nid, chs, 0, HDA_OUTPUT)); 3039 val);
2870} 3040}
2871 3041
2872#define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \ 3042#define alc_auto_add_stereo_vol(codec, pfx, cidx, nid) \
@@ -2879,6 +3049,7 @@ static int alc_auto_add_sw_ctl(struct hda_codec *codec,
2879 const char *pfx, int cidx, 3049 const char *pfx, int cidx,
2880 hda_nid_t nid, unsigned int chs) 3050 hda_nid_t nid, unsigned int chs)
2881{ 3051{
3052 struct alc_spec *spec = codec->spec;
2882 int wid_type; 3053 int wid_type;
2883 int type; 3054 int type;
2884 unsigned long val; 3055 unsigned long val;
@@ -2895,6 +3066,9 @@ static int alc_auto_add_sw_ctl(struct hda_codec *codec,
2895 type = ALC_CTL_BIND_MUTE; 3066 type = ALC_CTL_BIND_MUTE;
2896 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT); 3067 val = HDA_COMPOSE_AMP_VAL(nid, chs, 2, HDA_INPUT);
2897 } 3068 }
3069 if (is_ctl_used(spec->sw_ctls, val) && chs != 2) /* exclude LFE */
3070 return 0;
3071 mark_ctl_usage(spec->sw_ctls, val);
2898 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val); 3072 return __add_pb_sw_ctrl(codec->spec, type, pfx, cidx, val);
2899} 3073}
2900 3074
@@ -2955,7 +3129,7 @@ static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
2955 sw = alc_look_for_out_mute_nid(codec, pin, dac); 3129 sw = alc_look_for_out_mute_nid(codec, pin, dac);
2956 vol = alc_look_for_out_vol_nid(codec, pin, dac); 3130 vol = alc_look_for_out_vol_nid(codec, pin, dac);
2957 name = alc_get_line_out_pfx(spec, i, true, &index); 3131 name = alc_get_line_out_pfx(spec, i, true, &index);
2958 if (!name) { 3132 if (!name || !strcmp(name, "CLFE")) {
2959 /* Center/LFE */ 3133 /* Center/LFE */
2960 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1); 3134 err = alc_auto_add_vol_ctl(codec, "Center", 0, vol, 1);
2961 if (err < 0) 3135 if (err < 0)
@@ -2981,23 +3155,24 @@ static int alc_auto_create_multi_out_ctls(struct hda_codec *codec,
2981 return 0; 3155 return 0;
2982} 3156}
2983 3157
2984/* add playback controls for speaker and HP outputs */
2985static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin, 3158static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
2986 hda_nid_t dac, const char *pfx) 3159 hda_nid_t dac, const char *pfx)
2987{ 3160{
2988 struct alc_spec *spec = codec->spec; 3161 struct alc_spec *spec = codec->spec;
2989 hda_nid_t sw, vol; 3162 hda_nid_t sw, vol;
2990 int err; 3163 int err;
2991 3164
2992 if (!pin)
2993 return 0;
2994 if (!dac) { 3165 if (!dac) {
3166 unsigned int val;
2995 /* the corresponding DAC is already occupied */ 3167 /* the corresponding DAC is already occupied */
2996 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP)) 3168 if (!(get_wcaps(codec, pin) & AC_WCAP_OUT_AMP))
2997 return 0; /* no way */ 3169 return 0; /* no way */
2998 /* create a switch only */ 3170 /* create a switch only */
2999 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, 3171 val = HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT);
3000 HDA_COMPOSE_AMP_VAL(pin, 3, 0, HDA_OUTPUT)); 3172 if (is_ctl_used(spec->sw_ctls, val))
3173 return 0; /* already created */
3174 mark_ctl_usage(spec->sw_ctls, val);
3175 return add_pb_sw_ctrl(spec, ALC_CTL_WIDGET_MUTE, pfx, val);
3001 } 3176 }
3002 3177
3003 sw = alc_look_for_out_mute_nid(codec, pin, dac); 3178 sw = alc_look_for_out_mute_nid(codec, pin, dac);
@@ -3011,20 +3186,112 @@ static int alc_auto_create_extra_out(struct hda_codec *codec, hda_nid_t pin,
3011 return 0; 3186 return 0;
3012} 3187}
3013 3188
3189static struct hda_bind_ctls *new_bind_ctl(struct hda_codec *codec,
3190 unsigned int nums,
3191 struct hda_ctl_ops *ops)
3192{
3193 struct alc_spec *spec = codec->spec;
3194 struct hda_bind_ctls **ctlp, *ctl;
3195 snd_array_init(&spec->bind_ctls, sizeof(ctl), 8);
3196 ctlp = snd_array_new(&spec->bind_ctls);
3197 if (!ctlp)
3198 return NULL;
3199 ctl = kzalloc(sizeof(*ctl) + sizeof(long) * (nums + 1), GFP_KERNEL);
3200 *ctlp = ctl;
3201 if (ctl)
3202 ctl->ops = ops;
3203 return ctl;
3204}
3205
3206/* add playback controls for speaker and HP outputs */
3207static int alc_auto_create_extra_outs(struct hda_codec *codec, int num_pins,
3208 const hda_nid_t *pins,
3209 const hda_nid_t *dacs,
3210 const char *pfx)
3211{
3212 struct alc_spec *spec = codec->spec;
3213 struct hda_bind_ctls *ctl;
3214 char name[32];
3215 int i, n, err;
3216
3217 if (!num_pins || !pins[0])
3218 return 0;
3219
3220 if (num_pins == 1) {
3221 hda_nid_t dac = *dacs;
3222 if (!dac)
3223 dac = spec->multiout.dac_nids[0];
3224 return alc_auto_create_extra_out(codec, *pins, dac, pfx);
3225 }
3226
3227 if (dacs[num_pins - 1]) {
3228 /* OK, we have a multi-output system with individual volumes */
3229 for (i = 0; i < num_pins; i++) {
3230 snprintf(name, sizeof(name), "%s %s",
3231 pfx, channel_name[i]);
3232 err = alc_auto_create_extra_out(codec, pins[i], dacs[i],
3233 name);
3234 if (err < 0)
3235 return err;
3236 }
3237 return 0;
3238 }
3239
3240 /* Let's create a bind-controls */
3241 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_sw);
3242 if (!ctl)
3243 return -ENOMEM;
3244 n = 0;
3245 for (i = 0; i < num_pins; i++) {
3246 if (get_wcaps(codec, pins[i]) & AC_WCAP_OUT_AMP)
3247 ctl->values[n++] =
3248 HDA_COMPOSE_AMP_VAL(pins[i], 3, 0, HDA_OUTPUT);
3249 }
3250 if (n) {
3251 snprintf(name, sizeof(name), "%s Playback Switch", pfx);
3252 err = add_control(spec, ALC_CTL_BIND_SW, name, 0, (long)ctl);
3253 if (err < 0)
3254 return err;
3255 }
3256
3257 ctl = new_bind_ctl(codec, num_pins, &snd_hda_bind_vol);
3258 if (!ctl)
3259 return -ENOMEM;
3260 n = 0;
3261 for (i = 0; i < num_pins; i++) {
3262 hda_nid_t vol;
3263 if (!pins[i] || !dacs[i])
3264 continue;
3265 vol = alc_look_for_out_vol_nid(codec, pins[i], dacs[i]);
3266 if (vol)
3267 ctl->values[n++] =
3268 HDA_COMPOSE_AMP_VAL(vol, 3, 0, HDA_OUTPUT);
3269 }
3270 if (n) {
3271 snprintf(name, sizeof(name), "%s Playback Volume", pfx);
3272 err = add_control(spec, ALC_CTL_BIND_VOL, name, 0, (long)ctl);
3273 if (err < 0)
3274 return err;
3275 }
3276 return 0;
3277}
3278
3014static int alc_auto_create_hp_out(struct hda_codec *codec) 3279static int alc_auto_create_hp_out(struct hda_codec *codec)
3015{ 3280{
3016 struct alc_spec *spec = codec->spec; 3281 struct alc_spec *spec = codec->spec;
3017 return alc_auto_create_extra_out(codec, spec->autocfg.hp_pins[0], 3282 return alc_auto_create_extra_outs(codec, spec->autocfg.hp_outs,
3018 spec->multiout.hp_nid, 3283 spec->autocfg.hp_pins,
3019 "Headphone"); 3284 spec->multiout.hp_out_nid,
3285 "Headphone");
3020} 3286}
3021 3287
3022static int alc_auto_create_speaker_out(struct hda_codec *codec) 3288static int alc_auto_create_speaker_out(struct hda_codec *codec)
3023{ 3289{
3024 struct alc_spec *spec = codec->spec; 3290 struct alc_spec *spec = codec->spec;
3025 return alc_auto_create_extra_out(codec, spec->autocfg.speaker_pins[0], 3291 return alc_auto_create_extra_outs(codec, spec->autocfg.speaker_outs,
3026 spec->multiout.extra_out_nid[0], 3292 spec->autocfg.speaker_pins,
3027 "Speaker"); 3293 spec->multiout.extra_out_nid,
3294 "Speaker");
3028} 3295}
3029 3296
3030static void alc_auto_set_output_and_unmute(struct hda_codec *codec, 3297static void alc_auto_set_output_and_unmute(struct hda_codec *codec,
@@ -3081,16 +3348,39 @@ static void alc_auto_init_multi_out(struct hda_codec *codec)
3081static void alc_auto_init_extra_out(struct hda_codec *codec) 3348static void alc_auto_init_extra_out(struct hda_codec *codec)
3082{ 3349{
3083 struct alc_spec *spec = codec->spec; 3350 struct alc_spec *spec = codec->spec;
3084 hda_nid_t pin; 3351 int i;
3352 hda_nid_t pin, dac;
3085 3353
3086 pin = spec->autocfg.hp_pins[0]; 3354 for (i = 0; i < spec->autocfg.hp_outs; i++) {
3087 if (pin) 3355 if (spec->autocfg.line_out_type == AUTO_PIN_HP_OUT)
3088 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, 3356 break;
3089 spec->multiout.hp_nid); 3357 pin = spec->autocfg.hp_pins[i];
3090 pin = spec->autocfg.speaker_pins[0]; 3358 if (!pin)
3091 if (pin) 3359 break;
3092 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, 3360 dac = spec->multiout.hp_out_nid[i];
3093 spec->multiout.extra_out_nid[0]); 3361 if (!dac) {
3362 if (i > 0 && spec->multiout.hp_out_nid[0])
3363 dac = spec->multiout.hp_out_nid[0];
3364 else
3365 dac = spec->multiout.dac_nids[0];
3366 }
3367 alc_auto_set_output_and_unmute(codec, pin, PIN_HP, dac);
3368 }
3369 for (i = 0; i < spec->autocfg.speaker_outs; i++) {
3370 if (spec->autocfg.line_out_type == AUTO_PIN_SPEAKER_OUT)
3371 break;
3372 pin = spec->autocfg.speaker_pins[i];
3373 if (!pin)
3374 break;
3375 dac = spec->multiout.extra_out_nid[i];
3376 if (!dac) {
3377 if (i > 0 && spec->multiout.extra_out_nid[0])
3378 dac = spec->multiout.extra_out_nid[0];
3379 else
3380 dac = spec->multiout.dac_nids[0];
3381 }
3382 alc_auto_set_output_and_unmute(codec, pin, PIN_OUT, dac);
3383 }
3094} 3384}
3095 3385
3096/* 3386/*
@@ -3101,6 +3391,7 @@ static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3101{ 3391{
3102 struct alc_spec *spec = codec->spec; 3392 struct alc_spec *spec = codec->spec;
3103 struct auto_pin_cfg *cfg = &spec->autocfg; 3393 struct auto_pin_cfg *cfg = &spec->autocfg;
3394 hda_nid_t prime_dac = spec->private_dac_nids[0];
3104 int type, i, num_pins = 0; 3395 int type, i, num_pins = 0;
3105 3396
3106 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) { 3397 for (type = AUTO_PIN_LINE_IN; type >= AUTO_PIN_MIC; type--) {
@@ -3128,8 +3419,13 @@ static int alc_auto_fill_multi_ios(struct hda_codec *codec,
3128 } 3419 }
3129 } 3420 }
3130 spec->multiout.num_dacs = 1; 3421 spec->multiout.num_dacs = 1;
3131 if (num_pins < 2) 3422 if (num_pins < 2) {
3423 /* clear up again */
3424 memset(spec->private_dac_nids, 0,
3425 sizeof(spec->private_dac_nids));
3426 spec->private_dac_nids[0] = prime_dac;
3132 return 0; 3427 return 0;
3428 }
3133 return num_pins; 3429 return num_pins;
3134} 3430}
3135 3431
@@ -3215,36 +3511,11 @@ static const struct snd_kcontrol_new alc_auto_channel_mode_enum = {
3215 .put = alc_auto_ch_mode_put, 3511 .put = alc_auto_ch_mode_put,
3216}; 3512};
3217 3513
3218static int alc_auto_add_multi_channel_mode(struct hda_codec *codec, 3514static int alc_auto_add_multi_channel_mode(struct hda_codec *codec)
3219 int (*fill_dac)(struct hda_codec *))
3220{ 3515{
3221 struct alc_spec *spec = codec->spec; 3516 struct alc_spec *spec = codec->spec;
3222 struct auto_pin_cfg *cfg = &spec->autocfg;
3223 unsigned int location, defcfg;
3224 int num_pins;
3225
3226 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT && cfg->hp_outs == 1) {
3227 /* use HP as primary out */
3228 cfg->speaker_outs = cfg->line_outs;
3229 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3230 sizeof(cfg->speaker_pins));
3231 cfg->line_outs = cfg->hp_outs;
3232 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3233 cfg->hp_outs = 0;
3234 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3235 cfg->line_out_type = AUTO_PIN_HP_OUT;
3236 if (fill_dac)
3237 fill_dac(codec);
3238 }
3239 if (cfg->line_outs != 1 ||
3240 cfg->line_out_type == AUTO_PIN_SPEAKER_OUT)
3241 return 0;
3242
3243 defcfg = snd_hda_codec_get_pincfg(codec, cfg->line_out_pins[0]);
3244 location = get_defcfg_location(defcfg);
3245 3517
3246 num_pins = alc_auto_fill_multi_ios(codec, location); 3518 if (spec->multi_ios > 0) {
3247 if (num_pins > 0) {
3248 struct snd_kcontrol_new *knew; 3519 struct snd_kcontrol_new *knew;
3249 3520
3250 knew = alc_kcontrol_new(spec); 3521 knew = alc_kcontrol_new(spec);
@@ -3254,10 +3525,6 @@ static int alc_auto_add_multi_channel_mode(struct hda_codec *codec,
3254 knew->name = kstrdup("Channel Mode", GFP_KERNEL); 3525 knew->name = kstrdup("Channel Mode", GFP_KERNEL);
3255 if (!knew->name) 3526 if (!knew->name)
3256 return -ENOMEM; 3527 return -ENOMEM;
3257
3258 spec->multi_ios = num_pins;
3259 spec->ext_channel_count = 2;
3260 spec->multiout.num_dacs = num_pins + 1;
3261 } 3528 }
3262 return 0; 3529 return 0;
3263} 3530}
@@ -3540,27 +3807,42 @@ static int alc_parse_auto_config(struct hda_codec *codec,
3540 const hda_nid_t *ssid_nids) 3807 const hda_nid_t *ssid_nids)
3541{ 3808{
3542 struct alc_spec *spec = codec->spec; 3809 struct alc_spec *spec = codec->spec;
3810 struct auto_pin_cfg *cfg = &spec->autocfg;
3543 int err; 3811 int err;
3544 3812
3545 err = snd_hda_parse_pin_def_config(codec, &spec->autocfg, 3813 err = snd_hda_parse_pin_defcfg(codec, cfg, ignore_nids,
3546 ignore_nids); 3814 spec->parse_flags);
3547 if (err < 0) 3815 if (err < 0)
3548 return err; 3816 return err;
3549 if (!spec->autocfg.line_outs) { 3817 if (!cfg->line_outs) {
3550 if (spec->autocfg.dig_outs || spec->autocfg.dig_in_pin) { 3818 if (cfg->dig_outs || cfg->dig_in_pin) {
3551 spec->multiout.max_channels = 2; 3819 spec->multiout.max_channels = 2;
3552 spec->no_analog = 1; 3820 spec->no_analog = 1;
3553 goto dig_only; 3821 goto dig_only;
3554 } 3822 }
3555 return 0; /* can't find valid BIOS pin config */ 3823 return 0; /* can't find valid BIOS pin config */
3556 } 3824 }
3825
3826 if (cfg->line_out_type == AUTO_PIN_SPEAKER_OUT &&
3827 cfg->line_outs <= cfg->hp_outs) {
3828 /* use HP as primary out */
3829 cfg->speaker_outs = cfg->line_outs;
3830 memcpy(cfg->speaker_pins, cfg->line_out_pins,
3831 sizeof(cfg->speaker_pins));
3832 cfg->line_outs = cfg->hp_outs;
3833 memcpy(cfg->line_out_pins, cfg->hp_pins, sizeof(cfg->hp_pins));
3834 cfg->hp_outs = 0;
3835 memset(cfg->hp_pins, 0, sizeof(cfg->hp_pins));
3836 cfg->line_out_type = AUTO_PIN_HP_OUT;
3837 }
3838
3557 err = alc_auto_fill_dac_nids(codec); 3839 err = alc_auto_fill_dac_nids(codec);
3558 if (err < 0) 3840 if (err < 0)
3559 return err; 3841 return err;
3560 err = alc_auto_add_multi_channel_mode(codec, alc_auto_fill_dac_nids); 3842 err = alc_auto_add_multi_channel_mode(codec);
3561 if (err < 0) 3843 if (err < 0)
3562 return err; 3844 return err;
3563 err = alc_auto_create_multi_out_ctls(codec, &spec->autocfg); 3845 err = alc_auto_create_multi_out_ctls(codec, cfg);
3564 if (err < 0) 3846 if (err < 0)
3565 return err; 3847 return err;
3566 err = alc_auto_create_hp_out(codec); 3848 err = alc_auto_create_hp_out(codec);
@@ -3663,10 +3945,8 @@ static int patch_alc880(struct hda_codec *codec)
3663 if (board_config == ALC_MODEL_AUTO) { 3945 if (board_config == ALC_MODEL_AUTO) {
3664 /* automatic parse from the BIOS config */ 3946 /* automatic parse from the BIOS config */
3665 err = alc880_parse_auto_config(codec); 3947 err = alc880_parse_auto_config(codec);
3666 if (err < 0) { 3948 if (err < 0)
3667 alc_free(codec); 3949 goto error;
3668 return err;
3669 }
3670#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS 3950#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3671 else if (!err) { 3951 else if (!err) {
3672 printk(KERN_INFO 3952 printk(KERN_INFO
@@ -3691,10 +3971,8 @@ static int patch_alc880(struct hda_codec *codec)
3691 3971
3692 if (!spec->no_analog) { 3972 if (!spec->no_analog) {
3693 err = snd_hda_attach_beep_device(codec, 0x1); 3973 err = snd_hda_attach_beep_device(codec, 0x1);
3694 if (err < 0) { 3974 if (err < 0)
3695 alc_free(codec); 3975 goto error;
3696 return err;
3697 }
3698 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 3976 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
3699 } 3977 }
3700 3978
@@ -3709,6 +3987,10 @@ static int patch_alc880(struct hda_codec *codec)
3709#endif 3987#endif
3710 3988
3711 return 0; 3989 return 0;
3990
3991 error:
3992 alc_free(codec);
3993 return err;
3712} 3994}
3713 3995
3714 3996
@@ -3790,10 +4072,8 @@ static int patch_alc260(struct hda_codec *codec)
3790 if (board_config == ALC_MODEL_AUTO) { 4072 if (board_config == ALC_MODEL_AUTO) {
3791 /* automatic parse from the BIOS config */ 4073 /* automatic parse from the BIOS config */
3792 err = alc260_parse_auto_config(codec); 4074 err = alc260_parse_auto_config(codec);
3793 if (err < 0) { 4075 if (err < 0)
3794 alc_free(codec); 4076 goto error;
3795 return err;
3796 }
3797#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS 4077#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3798 else if (!err) { 4078 else if (!err) {
3799 printk(KERN_INFO 4079 printk(KERN_INFO
@@ -3818,10 +4098,8 @@ static int patch_alc260(struct hda_codec *codec)
3818 4098
3819 if (!spec->no_analog) { 4099 if (!spec->no_analog) {
3820 err = snd_hda_attach_beep_device(codec, 0x1); 4100 err = snd_hda_attach_beep_device(codec, 0x1);
3821 if (err < 0) { 4101 if (err < 0)
3822 alc_free(codec); 4102 goto error;
3823 return err;
3824 }
3825 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT); 4103 set_beep_amp(spec, 0x07, 0x05, HDA_INPUT);
3826 } 4104 }
3827 4105
@@ -3839,6 +4117,10 @@ static int patch_alc260(struct hda_codec *codec)
3839#endif 4117#endif
3840 4118
3841 return 0; 4119 return 0;
4120
4121 error:
4122 alc_free(codec);
4123 return err;
3842} 4124}
3843 4125
3844 4126
@@ -3865,6 +4147,7 @@ enum {
3865 PINFIX_LENOVO_Y530, 4147 PINFIX_LENOVO_Y530,
3866 PINFIX_PB_M5210, 4148 PINFIX_PB_M5210,
3867 PINFIX_ACER_ASPIRE_7736, 4149 PINFIX_ACER_ASPIRE_7736,
4150 PINFIX_ASUS_W90V,
3868}; 4151};
3869 4152
3870static const struct alc_fixup alc882_fixups[] = { 4153static const struct alc_fixup alc882_fixups[] = {
@@ -3896,10 +4179,18 @@ static const struct alc_fixup alc882_fixups[] = {
3896 .type = ALC_FIXUP_SKU, 4179 .type = ALC_FIXUP_SKU,
3897 .v.sku = ALC_FIXUP_SKU_IGNORE, 4180 .v.sku = ALC_FIXUP_SKU_IGNORE,
3898 }, 4181 },
4182 [PINFIX_ASUS_W90V] = {
4183 .type = ALC_FIXUP_PINS,
4184 .v.pins = (const struct alc_pincfg[]) {
4185 { 0x16, 0x99130110 }, /* fix sequence for CLFE */
4186 { }
4187 }
4188 },
3899}; 4189};
3900 4190
3901static const struct snd_pci_quirk alc882_fixup_tbl[] = { 4191static const struct snd_pci_quirk alc882_fixup_tbl[] = {
3902 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210), 4192 SND_PCI_QUIRK(0x1025, 0x0155, "Packard-Bell M5120", PINFIX_PB_M5210),
4193 SND_PCI_QUIRK(0x1043, 0x1873, "ASUS W90V", PINFIX_ASUS_W90V),
3903 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530), 4194 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Y530", PINFIX_LENOVO_Y530),
3904 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX), 4195 SND_PCI_QUIRK(0x147b, 0x107a, "Abit AW9D-MAX", PINFIX_ABIT_AW9D_MAX),
3905 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736), 4196 SND_PCI_QUIRK(0x1025, 0x0296, "Acer Aspire 7736z", PINFIX_ACER_ASPIRE_7736),
@@ -3946,6 +4237,10 @@ static int patch_alc882(struct hda_codec *codec)
3946 break; 4237 break;
3947 } 4238 }
3948 4239
4240 err = alc_codec_rename_from_preset(codec);
4241 if (err < 0)
4242 goto error;
4243
3949 board_config = alc_board_config(codec, ALC882_MODEL_LAST, 4244 board_config = alc_board_config(codec, ALC882_MODEL_LAST,
3950 alc882_models, alc882_cfg_tbl); 4245 alc882_models, alc882_cfg_tbl);
3951 4246
@@ -3969,10 +4264,8 @@ static int patch_alc882(struct hda_codec *codec)
3969 if (board_config == ALC_MODEL_AUTO) { 4264 if (board_config == ALC_MODEL_AUTO) {
3970 /* automatic parse from the BIOS config */ 4265 /* automatic parse from the BIOS config */
3971 err = alc882_parse_auto_config(codec); 4266 err = alc882_parse_auto_config(codec);
3972 if (err < 0) { 4267 if (err < 0)
3973 alc_free(codec); 4268 goto error;
3974 return err;
3975 }
3976#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS 4269#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
3977 else if (!err) { 4270 else if (!err) {
3978 printk(KERN_INFO 4271 printk(KERN_INFO
@@ -3997,10 +4290,8 @@ static int patch_alc882(struct hda_codec *codec)
3997 4290
3998 if (!spec->no_analog && has_cdefine_beep(codec)) { 4291 if (!spec->no_analog && has_cdefine_beep(codec)) {
3999 err = snd_hda_attach_beep_device(codec, 0x1); 4292 err = snd_hda_attach_beep_device(codec, 0x1);
4000 if (err < 0) { 4293 if (err < 0)
4001 alc_free(codec); 4294 goto error;
4002 return err;
4003 }
4004 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 4295 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4005 } 4296 }
4006 4297
@@ -4019,6 +4310,10 @@ static int patch_alc882(struct hda_codec *codec)
4019#endif 4310#endif
4020 4311
4021 return 0; 4312 return 0;
4313
4314 error:
4315 alc_free(codec);
4316 return err;
4022} 4317}
4023 4318
4024 4319
@@ -4123,10 +4418,8 @@ static int patch_alc262(struct hda_codec *codec)
4123 if (board_config == ALC_MODEL_AUTO) { 4418 if (board_config == ALC_MODEL_AUTO) {
4124 /* automatic parse from the BIOS config */ 4419 /* automatic parse from the BIOS config */
4125 err = alc262_parse_auto_config(codec); 4420 err = alc262_parse_auto_config(codec);
4126 if (err < 0) { 4421 if (err < 0)
4127 alc_free(codec); 4422 goto error;
4128 return err;
4129 }
4130#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS 4423#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4131 else if (!err) { 4424 else if (!err) {
4132 printk(KERN_INFO 4425 printk(KERN_INFO
@@ -4151,10 +4444,8 @@ static int patch_alc262(struct hda_codec *codec)
4151 4444
4152 if (!spec->no_analog && has_cdefine_beep(codec)) { 4445 if (!spec->no_analog && has_cdefine_beep(codec)) {
4153 err = snd_hda_attach_beep_device(codec, 0x1); 4446 err = snd_hda_attach_beep_device(codec, 0x1);
4154 if (err < 0) { 4447 if (err < 0)
4155 alc_free(codec); 4448 goto error;
4156 return err;
4157 }
4158 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 4449 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
4159 } 4450 }
4160 4451
@@ -4174,6 +4465,10 @@ static int patch_alc262(struct hda_codec *codec)
4174#endif 4465#endif
4175 4466
4176 return 0; 4467 return 0;
4468
4469 error:
4470 alc_free(codec);
4471 return err;
4177} 4472}
4178 4473
4179/* 4474/*
@@ -4222,14 +4517,9 @@ static int alc268_parse_auto_config(struct hda_codec *codec)
4222 4517
4223/* 4518/*
4224 */ 4519 */
4225#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4226#include "alc268_quirks.c"
4227#endif
4228
4229static int patch_alc268(struct hda_codec *codec) 4520static int patch_alc268(struct hda_codec *codec)
4230{ 4521{
4231 struct alc_spec *spec; 4522 struct alc_spec *spec;
4232 int board_config;
4233 int i, has_beep, err; 4523 int i, has_beep, err;
4234 4524
4235 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 4525 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
@@ -4240,38 +4530,10 @@ static int patch_alc268(struct hda_codec *codec)
4240 4530
4241 /* ALC268 has no aa-loopback mixer */ 4531 /* ALC268 has no aa-loopback mixer */
4242 4532
4243 board_config = alc_board_config(codec, ALC268_MODEL_LAST, 4533 /* automatic parse from the BIOS config */
4244 alc268_models, alc268_cfg_tbl); 4534 err = alc268_parse_auto_config(codec);
4245 4535 if (err < 0)
4246 if (board_config < 0) 4536 goto error;
4247 board_config = alc_board_codec_sid_config(codec,
4248 ALC268_MODEL_LAST, alc268_models, alc268_ssid_cfg_tbl);
4249
4250 if (board_config < 0) {
4251 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4252 codec->chip_name);
4253 board_config = ALC_MODEL_AUTO;
4254 }
4255
4256 if (board_config == ALC_MODEL_AUTO) {
4257 /* automatic parse from the BIOS config */
4258 err = alc268_parse_auto_config(codec);
4259 if (err < 0) {
4260 alc_free(codec);
4261 return err;
4262 }
4263#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4264 else if (!err) {
4265 printk(KERN_INFO
4266 "hda_codec: Cannot set up configuration "
4267 "from BIOS. Using base mode...\n");
4268 board_config = ALC268_3ST;
4269 }
4270#endif
4271 }
4272
4273 if (board_config != ALC_MODEL_AUTO)
4274 setup_preset(codec, &alc268_presets[board_config]);
4275 4537
4276 has_beep = 0; 4538 has_beep = 0;
4277 for (i = 0; i < spec->num_mixers; i++) { 4539 for (i = 0; i < spec->num_mixers; i++) {
@@ -4283,10 +4545,8 @@ static int patch_alc268(struct hda_codec *codec)
4283 4545
4284 if (has_beep) { 4546 if (has_beep) {
4285 err = snd_hda_attach_beep_device(codec, 0x1); 4547 err = snd_hda_attach_beep_device(codec, 0x1);
4286 if (err < 0) { 4548 if (err < 0)
4287 alc_free(codec); 4549 goto error;
4288 return err;
4289 }
4290 if (!query_amp_caps(codec, 0x1d, HDA_INPUT)) 4550 if (!query_amp_caps(codec, 0x1d, HDA_INPUT))
4291 /* override the amp caps for beep generator */ 4551 /* override the amp caps for beep generator */
4292 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT, 4552 snd_hda_override_amp_caps(codec, 0x1d, HDA_INPUT,
@@ -4308,13 +4568,16 @@ static int patch_alc268(struct hda_codec *codec)
4308 spec->vmaster_nid = 0x02; 4568 spec->vmaster_nid = 0x02;
4309 4569
4310 codec->patch_ops = alc_patch_ops; 4570 codec->patch_ops = alc_patch_ops;
4311 if (board_config == ALC_MODEL_AUTO) 4571 spec->init_hook = alc_auto_init_std;
4312 spec->init_hook = alc_auto_init_std;
4313 spec->shutup = alc_eapd_shutup; 4572 spec->shutup = alc_eapd_shutup;
4314 4573
4315 alc_init_jacks(codec); 4574 alc_init_jacks(codec);
4316 4575
4317 return 0; 4576 return 0;
4577
4578 error:
4579 alc_free(codec);
4580 return err;
4318} 4581}
4319 4582
4320/* 4583/*
@@ -4408,9 +4671,9 @@ static void alc269_toggle_power_output(struct hda_codec *codec, int power_up)
4408 4671
4409static void alc269_shutup(struct hda_codec *codec) 4672static void alc269_shutup(struct hda_codec *codec)
4410{ 4673{
4411 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) 4674 if ((alc_get_coef0(codec) & 0x00ff) == 0x017)
4412 alc269_toggle_power_output(codec, 0); 4675 alc269_toggle_power_output(codec, 0);
4413 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) { 4676 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
4414 alc269_toggle_power_output(codec, 0); 4677 alc269_toggle_power_output(codec, 0);
4415 msleep(150); 4678 msleep(150);
4416 } 4679 }
@@ -4419,19 +4682,19 @@ static void alc269_shutup(struct hda_codec *codec)
4419#ifdef CONFIG_PM 4682#ifdef CONFIG_PM
4420static int alc269_resume(struct hda_codec *codec) 4683static int alc269_resume(struct hda_codec *codec)
4421{ 4684{
4422 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) { 4685 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
4423 alc269_toggle_power_output(codec, 0); 4686 alc269_toggle_power_output(codec, 0);
4424 msleep(150); 4687 msleep(150);
4425 } 4688 }
4426 4689
4427 codec->patch_ops.init(codec); 4690 codec->patch_ops.init(codec);
4428 4691
4429 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) { 4692 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
4430 alc269_toggle_power_output(codec, 1); 4693 alc269_toggle_power_output(codec, 1);
4431 msleep(200); 4694 msleep(200);
4432 } 4695 }
4433 4696
4434 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) 4697 if ((alc_get_coef0(codec) & 0x00ff) == 0x018)
4435 alc269_toggle_power_output(codec, 1); 4698 alc269_toggle_power_output(codec, 1);
4436 4699
4437 snd_hda_codec_resume_amp(codec); 4700 snd_hda_codec_resume_amp(codec);
@@ -4484,6 +4747,46 @@ static void alc269_fixup_pcm_44k(struct hda_codec *codec,
4484 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture; 4747 spec->stream_analog_capture = &alc269_44k_pcm_analog_capture;
4485} 4748}
4486 4749
4750static void alc269_fixup_stereo_dmic(struct hda_codec *codec,
4751 const struct alc_fixup *fix, int action)
4752{
4753 int coef;
4754
4755 if (action != ALC_FIXUP_ACT_INIT)
4756 return;
4757 /* The digital-mic unit sends PDM (differential signal) instead of
4758 * the standard PCM, thus you can't record a valid mono stream as is.
4759 * Below is a workaround specific to ALC269 to control the dmic
4760 * signal source as mono.
4761 */
4762 coef = alc_read_coef_idx(codec, 0x07);
4763 alc_write_coef_idx(codec, 0x07, coef | 0x80);
4764}
4765
4766static void alc269_quanta_automute(struct hda_codec *codec)
4767{
4768 update_outputs(codec);
4769
4770 snd_hda_codec_write(codec, 0x20, 0,
4771 AC_VERB_SET_COEF_INDEX, 0x0c);
4772 snd_hda_codec_write(codec, 0x20, 0,
4773 AC_VERB_SET_PROC_COEF, 0x680);
4774
4775 snd_hda_codec_write(codec, 0x20, 0,
4776 AC_VERB_SET_COEF_INDEX, 0x0c);
4777 snd_hda_codec_write(codec, 0x20, 0,
4778 AC_VERB_SET_PROC_COEF, 0x480);
4779}
4780
4781static void alc269_fixup_quanta_mute(struct hda_codec *codec,
4782 const struct alc_fixup *fix, int action)
4783{
4784 struct alc_spec *spec = codec->spec;
4785 if (action != ALC_FIXUP_ACT_PROBE)
4786 return;
4787 spec->automute_hook = alc269_quanta_automute;
4788}
4789
4487enum { 4790enum {
4488 ALC269_FIXUP_SONY_VAIO, 4791 ALC269_FIXUP_SONY_VAIO,
4489 ALC275_FIXUP_SONY_VAIO_GPIO2, 4792 ALC275_FIXUP_SONY_VAIO_GPIO2,
@@ -4494,6 +4797,13 @@ enum {
4494 ALC275_FIXUP_SONY_HWEQ, 4797 ALC275_FIXUP_SONY_HWEQ,
4495 ALC271_FIXUP_DMIC, 4798 ALC271_FIXUP_DMIC,
4496 ALC269_FIXUP_PCM_44K, 4799 ALC269_FIXUP_PCM_44K,
4800 ALC269_FIXUP_STEREO_DMIC,
4801 ALC269_FIXUP_QUANTA_MUTE,
4802 ALC269_FIXUP_LIFEBOOK,
4803 ALC269_FIXUP_AMIC,
4804 ALC269_FIXUP_DMIC,
4805 ALC269VB_FIXUP_AMIC,
4806 ALC269VB_FIXUP_DMIC,
4497}; 4807};
4498 4808
4499static const struct alc_fixup alc269_fixups[] = { 4809static const struct alc_fixup alc269_fixups[] = {
@@ -4556,23 +4866,144 @@ static const struct alc_fixup alc269_fixups[] = {
4556 .type = ALC_FIXUP_FUNC, 4866 .type = ALC_FIXUP_FUNC,
4557 .v.func = alc269_fixup_pcm_44k, 4867 .v.func = alc269_fixup_pcm_44k,
4558 }, 4868 },
4869 [ALC269_FIXUP_STEREO_DMIC] = {
4870 .type = ALC_FIXUP_FUNC,
4871 .v.func = alc269_fixup_stereo_dmic,
4872 },
4873 [ALC269_FIXUP_QUANTA_MUTE] = {
4874 .type = ALC_FIXUP_FUNC,
4875 .v.func = alc269_fixup_quanta_mute,
4876 },
4877 [ALC269_FIXUP_LIFEBOOK] = {
4878 .type = ALC_FIXUP_PINS,
4879 .v.pins = (const struct alc_pincfg[]) {
4880 { 0x1a, 0x2101103f }, /* dock line-out */
4881 { 0x1b, 0x23a11040 }, /* dock mic-in */
4882 { }
4883 },
4884 .chained = true,
4885 .chain_id = ALC269_FIXUP_QUANTA_MUTE
4886 },
4887 [ALC269_FIXUP_AMIC] = {
4888 .type = ALC_FIXUP_PINS,
4889 .v.pins = (const struct alc_pincfg[]) {
4890 { 0x14, 0x99130110 }, /* speaker */
4891 { 0x15, 0x0121401f }, /* HP out */
4892 { 0x18, 0x01a19c20 }, /* mic */
4893 { 0x19, 0x99a3092f }, /* int-mic */
4894 { }
4895 },
4896 },
4897 [ALC269_FIXUP_DMIC] = {
4898 .type = ALC_FIXUP_PINS,
4899 .v.pins = (const struct alc_pincfg[]) {
4900 { 0x12, 0x99a3092f }, /* int-mic */
4901 { 0x14, 0x99130110 }, /* speaker */
4902 { 0x15, 0x0121401f }, /* HP out */
4903 { 0x18, 0x01a19c20 }, /* mic */
4904 { }
4905 },
4906 },
4907 [ALC269VB_FIXUP_AMIC] = {
4908 .type = ALC_FIXUP_PINS,
4909 .v.pins = (const struct alc_pincfg[]) {
4910 { 0x14, 0x99130110 }, /* speaker */
4911 { 0x18, 0x01a19c20 }, /* mic */
4912 { 0x19, 0x99a3092f }, /* int-mic */
4913 { 0x21, 0x0121401f }, /* HP out */
4914 { }
4915 },
4916 },
4917 [ALC269_FIXUP_DMIC] = {
4918 .type = ALC_FIXUP_PINS,
4919 .v.pins = (const struct alc_pincfg[]) {
4920 { 0x12, 0x99a3092f }, /* int-mic */
4921 { 0x14, 0x99130110 }, /* speaker */
4922 { 0x18, 0x01a19c20 }, /* mic */
4923 { 0x21, 0x0121401f }, /* HP out */
4924 { }
4925 },
4926 },
4559}; 4927};
4560 4928
4561static const struct snd_pci_quirk alc269_fixup_tbl[] = { 4929static const struct snd_pci_quirk alc269_fixup_tbl[] = {
4562 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW), 4930 SND_PCI_QUIRK(0x1043, 0x1a13, "Asus G73Jw", ALC269_FIXUP_ASUS_G73JW),
4931 SND_PCI_QUIRK(0x1043, 0x16e3, "ASUS UX50", ALC269_FIXUP_STEREO_DMIC),
4932 SND_PCI_QUIRK(0x1043, 0x831a, "ASUS P901", ALC269_FIXUP_STEREO_DMIC),
4933 SND_PCI_QUIRK(0x1043, 0x834a, "ASUS S101", ALC269_FIXUP_STEREO_DMIC),
4934 SND_PCI_QUIRK(0x1043, 0x8398, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4935 SND_PCI_QUIRK(0x1043, 0x83ce, "ASUS P1005", ALC269_FIXUP_STEREO_DMIC),
4563 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2), 4936 SND_PCI_QUIRK(0x104d, 0x9073, "Sony VAIO", ALC275_FIXUP_SONY_VAIO_GPIO2),
4564 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), 4937 SND_PCI_QUIRK(0x104d, 0x907b, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4565 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ), 4938 SND_PCI_QUIRK(0x104d, 0x9084, "Sony VAIO", ALC275_FIXUP_SONY_HWEQ),
4566 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO), 4939 SND_PCI_QUIRK_VENDOR(0x104d, "Sony VAIO", ALC269_FIXUP_SONY_VAIO),
4567 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z), 4940 SND_PCI_QUIRK(0x1028, 0x0470, "Dell M101z", ALC269_FIXUP_DELL_M101Z),
4568 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC), 4941 SND_PCI_QUIRK_VENDOR(0x1025, "Acer Aspire", ALC271_FIXUP_DMIC),
4942 SND_PCI_QUIRK(0x10cf, 0x1475, "Lifebook", ALC269_FIXUP_LIFEBOOK),
4569 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE), 4943 SND_PCI_QUIRK(0x17aa, 0x20f2, "Thinkpad SL410/510", ALC269_FIXUP_SKU_IGNORE),
4570 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE), 4944 SND_PCI_QUIRK(0x17aa, 0x215e, "Thinkpad L512", ALC269_FIXUP_SKU_IGNORE),
4571 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE), 4945 SND_PCI_QUIRK(0x17aa, 0x21b8, "Thinkpad Edge 14", ALC269_FIXUP_SKU_IGNORE),
4572 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE), 4946 SND_PCI_QUIRK(0x17aa, 0x21ca, "Thinkpad L412", ALC269_FIXUP_SKU_IGNORE),
4573 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE), 4947 SND_PCI_QUIRK(0x17aa, 0x21e9, "Thinkpad Edge 15", ALC269_FIXUP_SKU_IGNORE),
4948 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_QUANTA_MUTE),
4574 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K), 4949 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Lenovo Ideapd", ALC269_FIXUP_PCM_44K),
4575 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD), 4950 SND_PCI_QUIRK(0x17aa, 0x9e54, "LENOVO NB", ALC269_FIXUP_LENOVO_EAPD),
4951
4952#if 1
4953 /* Below is a quirk table taken from the old code.
4954 * Basically the device should work as is without the fixup table.
4955 * If BIOS doesn't give a proper info, enable the corresponding
4956 * fixup entry.
4957 */
4958 SND_PCI_QUIRK(0x1043, 0x8330, "ASUS Eeepc P703 P900A",
4959 ALC269_FIXUP_AMIC),
4960 SND_PCI_QUIRK(0x1043, 0x1013, "ASUS N61Da", ALC269_FIXUP_AMIC),
4961 SND_PCI_QUIRK(0x1043, 0x1113, "ASUS N63Jn", ALC269_FIXUP_AMIC),
4962 SND_PCI_QUIRK(0x1043, 0x1143, "ASUS B53f", ALC269_FIXUP_AMIC),
4963 SND_PCI_QUIRK(0x1043, 0x1133, "ASUS UJ20ft", ALC269_FIXUP_AMIC),
4964 SND_PCI_QUIRK(0x1043, 0x1183, "ASUS K72DR", ALC269_FIXUP_AMIC),
4965 SND_PCI_QUIRK(0x1043, 0x11b3, "ASUS K52DR", ALC269_FIXUP_AMIC),
4966 SND_PCI_QUIRK(0x1043, 0x11e3, "ASUS U33Jc", ALC269_FIXUP_AMIC),
4967 SND_PCI_QUIRK(0x1043, 0x1273, "ASUS UL80Jt", ALC269_FIXUP_AMIC),
4968 SND_PCI_QUIRK(0x1043, 0x1283, "ASUS U53Jc", ALC269_FIXUP_AMIC),
4969 SND_PCI_QUIRK(0x1043, 0x12b3, "ASUS N82JV", ALC269_FIXUP_AMIC),
4970 SND_PCI_QUIRK(0x1043, 0x12d3, "ASUS N61Jv", ALC269_FIXUP_AMIC),
4971 SND_PCI_QUIRK(0x1043, 0x13a3, "ASUS UL30Vt", ALC269_FIXUP_AMIC),
4972 SND_PCI_QUIRK(0x1043, 0x1373, "ASUS G73JX", ALC269_FIXUP_AMIC),
4973 SND_PCI_QUIRK(0x1043, 0x1383, "ASUS UJ30Jc", ALC269_FIXUP_AMIC),
4974 SND_PCI_QUIRK(0x1043, 0x13d3, "ASUS N61JA", ALC269_FIXUP_AMIC),
4975 SND_PCI_QUIRK(0x1043, 0x1413, "ASUS UL50", ALC269_FIXUP_AMIC),
4976 SND_PCI_QUIRK(0x1043, 0x1443, "ASUS UL30", ALC269_FIXUP_AMIC),
4977 SND_PCI_QUIRK(0x1043, 0x1453, "ASUS M60Jv", ALC269_FIXUP_AMIC),
4978 SND_PCI_QUIRK(0x1043, 0x1483, "ASUS UL80", ALC269_FIXUP_AMIC),
4979 SND_PCI_QUIRK(0x1043, 0x14f3, "ASUS F83Vf", ALC269_FIXUP_AMIC),
4980 SND_PCI_QUIRK(0x1043, 0x14e3, "ASUS UL20", ALC269_FIXUP_AMIC),
4981 SND_PCI_QUIRK(0x1043, 0x1513, "ASUS UX30", ALC269_FIXUP_AMIC),
4982 SND_PCI_QUIRK(0x1043, 0x1593, "ASUS N51Vn", ALC269_FIXUP_AMIC),
4983 SND_PCI_QUIRK(0x1043, 0x15a3, "ASUS N60Jv", ALC269_FIXUP_AMIC),
4984 SND_PCI_QUIRK(0x1043, 0x15b3, "ASUS N60Dp", ALC269_FIXUP_AMIC),
4985 SND_PCI_QUIRK(0x1043, 0x15c3, "ASUS N70De", ALC269_FIXUP_AMIC),
4986 SND_PCI_QUIRK(0x1043, 0x15e3, "ASUS F83T", ALC269_FIXUP_AMIC),
4987 SND_PCI_QUIRK(0x1043, 0x1643, "ASUS M60J", ALC269_FIXUP_AMIC),
4988 SND_PCI_QUIRK(0x1043, 0x1653, "ASUS U50", ALC269_FIXUP_AMIC),
4989 SND_PCI_QUIRK(0x1043, 0x1693, "ASUS F50N", ALC269_FIXUP_AMIC),
4990 SND_PCI_QUIRK(0x1043, 0x16a3, "ASUS F5Q", ALC269_FIXUP_AMIC),
4991 SND_PCI_QUIRK(0x1043, 0x1723, "ASUS P80", ALC269_FIXUP_AMIC),
4992 SND_PCI_QUIRK(0x1043, 0x1743, "ASUS U80", ALC269_FIXUP_AMIC),
4993 SND_PCI_QUIRK(0x1043, 0x1773, "ASUS U20A", ALC269_FIXUP_AMIC),
4994 SND_PCI_QUIRK(0x1043, 0x1883, "ASUS F81Se", ALC269_FIXUP_AMIC),
4995 SND_PCI_QUIRK(0x152d, 0x1778, "Quanta ON1", ALC269_FIXUP_DMIC),
4996 SND_PCI_QUIRK(0x17aa, 0x3be9, "Quanta Wistron", ALC269_FIXUP_AMIC),
4997 SND_PCI_QUIRK(0x17aa, 0x3bf8, "Quanta FL1", ALC269_FIXUP_AMIC),
4998 SND_PCI_QUIRK(0x17ff, 0x059a, "Quanta EL3", ALC269_FIXUP_DMIC),
4999 SND_PCI_QUIRK(0x17ff, 0x059b, "Quanta JR1", ALC269_FIXUP_DMIC),
5000#endif
5001 {}
5002};
5003
5004static const struct alc_model_fixup alc269_fixup_models[] = {
5005 {.id = ALC269_FIXUP_AMIC, .name = "laptop-amic"},
5006 {.id = ALC269_FIXUP_DMIC, .name = "laptop-dmic"},
4576 {} 5007 {}
4577}; 5008};
4578 5009
@@ -4581,23 +5012,23 @@ static int alc269_fill_coef(struct hda_codec *codec)
4581{ 5012{
4582 int val; 5013 int val;
4583 5014
4584 if ((alc_read_coef_idx(codec, 0) & 0x00ff) < 0x015) { 5015 if ((alc_get_coef0(codec) & 0x00ff) < 0x015) {
4585 alc_write_coef_idx(codec, 0xf, 0x960b); 5016 alc_write_coef_idx(codec, 0xf, 0x960b);
4586 alc_write_coef_idx(codec, 0xe, 0x8817); 5017 alc_write_coef_idx(codec, 0xe, 0x8817);
4587 } 5018 }
4588 5019
4589 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x016) { 5020 if ((alc_get_coef0(codec) & 0x00ff) == 0x016) {
4590 alc_write_coef_idx(codec, 0xf, 0x960b); 5021 alc_write_coef_idx(codec, 0xf, 0x960b);
4591 alc_write_coef_idx(codec, 0xe, 0x8814); 5022 alc_write_coef_idx(codec, 0xe, 0x8814);
4592 } 5023 }
4593 5024
4594 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x017) { 5025 if ((alc_get_coef0(codec) & 0x00ff) == 0x017) {
4595 val = alc_read_coef_idx(codec, 0x04); 5026 val = alc_read_coef_idx(codec, 0x04);
4596 /* Power up output pin */ 5027 /* Power up output pin */
4597 alc_write_coef_idx(codec, 0x04, val | (1<<11)); 5028 alc_write_coef_idx(codec, 0x04, val | (1<<11));
4598 } 5029 }
4599 5030
4600 if ((alc_read_coef_idx(codec, 0) & 0x00ff) == 0x018) { 5031 if ((alc_get_coef0(codec) & 0x00ff) == 0x018) {
4601 val = alc_read_coef_idx(codec, 0xd); 5032 val = alc_read_coef_idx(codec, 0xd);
4602 if ((val & 0x0c00) >> 10 != 0x1) { 5033 if ((val & 0x0c00) >> 10 != 0x1) {
4603 /* Capless ramp up clock control */ 5034 /* Capless ramp up clock control */
@@ -4621,15 +5052,10 @@ static int alc269_fill_coef(struct hda_codec *codec)
4621 5052
4622/* 5053/*
4623 */ 5054 */
4624#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4625#include "alc269_quirks.c"
4626#endif
4627
4628static int patch_alc269(struct hda_codec *codec) 5055static int patch_alc269(struct hda_codec *codec)
4629{ 5056{
4630 struct alc_spec *spec; 5057 struct alc_spec *spec;
4631 int board_config, coef; 5058 int err = 0;
4632 int err;
4633 5059
4634 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5060 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4635 if (spec == NULL) 5061 if (spec == NULL)
@@ -4641,72 +5067,41 @@ static int patch_alc269(struct hda_codec *codec)
4641 5067
4642 alc_auto_parse_customize_define(codec); 5068 alc_auto_parse_customize_define(codec);
4643 5069
5070 err = alc_codec_rename_from_preset(codec);
5071 if (err < 0)
5072 goto error;
5073
4644 if (codec->vendor_id == 0x10ec0269) { 5074 if (codec->vendor_id == 0x10ec0269) {
4645 spec->codec_variant = ALC269_TYPE_ALC269VA; 5075 spec->codec_variant = ALC269_TYPE_ALC269VA;
4646 coef = alc_read_coef_idx(codec, 0); 5076 switch (alc_get_coef0(codec) & 0x00f0) {
4647 if ((coef & 0x00f0) == 0x0010) { 5077 case 0x0010:
4648 if (codec->bus->pci->subsystem_vendor == 0x1025 && 5078 if (codec->bus->pci->subsystem_vendor == 0x1025 &&
4649 spec->cdefine.platform_type == 1) { 5079 spec->cdefine.platform_type == 1)
4650 alc_codec_rename(codec, "ALC271X"); 5080 err = alc_codec_rename(codec, "ALC271X");
4651 } else if ((coef & 0xf000) == 0x2000) {
4652 alc_codec_rename(codec, "ALC259");
4653 } else if ((coef & 0xf000) == 0x3000) {
4654 alc_codec_rename(codec, "ALC258");
4655 } else if ((coef & 0xfff0) == 0x3010) {
4656 alc_codec_rename(codec, "ALC277");
4657 } else {
4658 alc_codec_rename(codec, "ALC269VB");
4659 }
4660 spec->codec_variant = ALC269_TYPE_ALC269VB; 5081 spec->codec_variant = ALC269_TYPE_ALC269VB;
4661 } else if ((coef & 0x00f0) == 0x0020) { 5082 break;
4662 if (coef == 0xa023) 5083 case 0x0020:
4663 alc_codec_rename(codec, "ALC259"); 5084 if (codec->bus->pci->subsystem_vendor == 0x17aa &&
4664 else if (coef == 0x6023) 5085 codec->bus->pci->subsystem_device == 0x21f3)
4665 alc_codec_rename(codec, "ALC281X"); 5086 err = alc_codec_rename(codec, "ALC3202");
4666 else if (codec->bus->pci->subsystem_vendor == 0x17aa &&
4667 codec->bus->pci->subsystem_device == 0x21f3)
4668 alc_codec_rename(codec, "ALC3202");
4669 else
4670 alc_codec_rename(codec, "ALC269VC");
4671 spec->codec_variant = ALC269_TYPE_ALC269VC; 5087 spec->codec_variant = ALC269_TYPE_ALC269VC;
4672 } else 5088 break;
5089 default:
4673 alc_fix_pll_init(codec, 0x20, 0x04, 15); 5090 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5091 }
5092 if (err < 0)
5093 goto error;
4674 alc269_fill_coef(codec); 5094 alc269_fill_coef(codec);
4675 } 5095 }
4676 5096
4677 board_config = alc_board_config(codec, ALC269_MODEL_LAST, 5097 alc_pick_fixup(codec, alc269_fixup_models,
4678 alc269_models, alc269_cfg_tbl); 5098 alc269_fixup_tbl, alc269_fixups);
4679 5099 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4680 if (board_config < 0) {
4681 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4682 codec->chip_name);
4683 board_config = ALC_MODEL_AUTO;
4684 }
4685
4686 if (board_config == ALC_MODEL_AUTO) {
4687 alc_pick_fixup(codec, NULL, alc269_fixup_tbl, alc269_fixups);
4688 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4689 }
4690 5100
4691 if (board_config == ALC_MODEL_AUTO) { 5101 /* automatic parse from the BIOS config */
4692 /* automatic parse from the BIOS config */ 5102 err = alc269_parse_auto_config(codec);
4693 err = alc269_parse_auto_config(codec); 5103 if (err < 0)
4694 if (err < 0) { 5104 goto error;
4695 alc_free(codec);
4696 return err;
4697 }
4698#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4699 else if (!err) {
4700 printk(KERN_INFO
4701 "hda_codec: Cannot set up configuration "
4702 "from BIOS. Using base mode...\n");
4703 board_config = ALC269_BASIC;
4704 }
4705#endif
4706 }
4707
4708 if (board_config != ALC_MODEL_AUTO)
4709 setup_preset(codec, &alc269_presets[board_config]);
4710 5105
4711 if (!spec->no_analog && !spec->adc_nids) { 5106 if (!spec->no_analog && !spec->adc_nids) {
4712 alc_auto_fill_adc_caps(codec); 5107 alc_auto_fill_adc_caps(codec);
@@ -4719,10 +5114,8 @@ static int patch_alc269(struct hda_codec *codec)
4719 5114
4720 if (!spec->no_analog && has_cdefine_beep(codec)) { 5115 if (!spec->no_analog && has_cdefine_beep(codec)) {
4721 err = snd_hda_attach_beep_device(codec, 0x1); 5116 err = snd_hda_attach_beep_device(codec, 0x1);
4722 if (err < 0) { 5117 if (err < 0)
4723 alc_free(codec); 5118 goto error;
4724 return err;
4725 }
4726 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT); 5119 set_beep_amp(spec, 0x0b, 0x04, HDA_INPUT);
4727 } 5120 }
4728 5121
@@ -4734,8 +5127,7 @@ static int patch_alc269(struct hda_codec *codec)
4734#ifdef CONFIG_PM 5127#ifdef CONFIG_PM
4735 codec->patch_ops.resume = alc269_resume; 5128 codec->patch_ops.resume = alc269_resume;
4736#endif 5129#endif
4737 if (board_config == ALC_MODEL_AUTO) 5130 spec->init_hook = alc_auto_init_std;
4738 spec->init_hook = alc_auto_init_std;
4739 spec->shutup = alc269_shutup; 5131 spec->shutup = alc269_shutup;
4740 5132
4741 alc_init_jacks(codec); 5133 alc_init_jacks(codec);
@@ -4747,6 +5139,10 @@ static int patch_alc269(struct hda_codec *codec)
4747#endif 5139#endif
4748 5140
4749 return 0; 5141 return 0;
5142
5143 error:
5144 alc_free(codec);
5145 return err;
4750} 5146}
4751 5147
4752/* 5148/*
@@ -4794,14 +5190,9 @@ static const struct snd_pci_quirk alc861_fixup_tbl[] = {
4794 5190
4795/* 5191/*
4796 */ 5192 */
4797#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4798#include "alc861_quirks.c"
4799#endif
4800
4801static int patch_alc861(struct hda_codec *codec) 5193static int patch_alc861(struct hda_codec *codec)
4802{ 5194{
4803 struct alc_spec *spec; 5195 struct alc_spec *spec;
4804 int board_config;
4805 int err; 5196 int err;
4806 5197
4807 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5198 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
@@ -4812,39 +5203,13 @@ static int patch_alc861(struct hda_codec *codec)
4812 5203
4813 spec->mixer_nid = 0x15; 5204 spec->mixer_nid = 0x15;
4814 5205
4815 board_config = alc_board_config(codec, ALC861_MODEL_LAST, 5206 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
4816 alc861_models, alc861_cfg_tbl); 5207 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4817
4818 if (board_config < 0) {
4819 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4820 codec->chip_name);
4821 board_config = ALC_MODEL_AUTO;
4822 }
4823
4824 if (board_config == ALC_MODEL_AUTO) {
4825 alc_pick_fixup(codec, NULL, alc861_fixup_tbl, alc861_fixups);
4826 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4827 }
4828
4829 if (board_config == ALC_MODEL_AUTO) {
4830 /* automatic parse from the BIOS config */
4831 err = alc861_parse_auto_config(codec);
4832 if (err < 0) {
4833 alc_free(codec);
4834 return err;
4835 }
4836#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4837 else if (!err) {
4838 printk(KERN_INFO
4839 "hda_codec: Cannot set up configuration "
4840 "from BIOS. Using base mode...\n");
4841 board_config = ALC861_3ST_DIG;
4842 }
4843#endif
4844 }
4845 5208
4846 if (board_config != ALC_MODEL_AUTO) 5209 /* automatic parse from the BIOS config */
4847 setup_preset(codec, &alc861_presets[board_config]); 5210 err = alc861_parse_auto_config(codec);
5211 if (err < 0)
5212 goto error;
4848 5213
4849 if (!spec->no_analog && !spec->adc_nids) { 5214 if (!spec->no_analog && !spec->adc_nids) {
4850 alc_auto_fill_adc_caps(codec); 5215 alc_auto_fill_adc_caps(codec);
@@ -4857,10 +5222,8 @@ static int patch_alc861(struct hda_codec *codec)
4857 5222
4858 if (!spec->no_analog) { 5223 if (!spec->no_analog) {
4859 err = snd_hda_attach_beep_device(codec, 0x23); 5224 err = snd_hda_attach_beep_device(codec, 0x23);
4860 if (err < 0) { 5225 if (err < 0)
4861 alc_free(codec); 5226 goto error;
4862 return err;
4863 }
4864 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT); 5227 set_beep_amp(spec, 0x23, 0, HDA_OUTPUT);
4865 } 5228 }
4866 5229
@@ -4869,18 +5232,18 @@ static int patch_alc861(struct hda_codec *codec)
4869 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 5232 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
4870 5233
4871 codec->patch_ops = alc_patch_ops; 5234 codec->patch_ops = alc_patch_ops;
4872 if (board_config == ALC_MODEL_AUTO) { 5235 spec->init_hook = alc_auto_init_std;
4873 spec->init_hook = alc_auto_init_std;
4874#ifdef CONFIG_SND_HDA_POWER_SAVE
4875 spec->power_hook = alc_power_eapd;
4876#endif
4877 }
4878#ifdef CONFIG_SND_HDA_POWER_SAVE 5236#ifdef CONFIG_SND_HDA_POWER_SAVE
5237 spec->power_hook = alc_power_eapd;
4879 if (!spec->loopback.amplist) 5238 if (!spec->loopback.amplist)
4880 spec->loopback.amplist = alc861_loopbacks; 5239 spec->loopback.amplist = alc861_loopbacks;
4881#endif 5240#endif
4882 5241
4883 return 0; 5242 return 0;
5243
5244 error:
5245 alc_free(codec);
5246 return err;
4884} 5247}
4885 5248
4886/* 5249/*
@@ -4902,24 +5265,41 @@ static int alc861vd_parse_auto_config(struct hda_codec *codec)
4902} 5265}
4903 5266
4904enum { 5267enum {
4905 ALC660VD_FIX_ASUS_GPIO1 5268 ALC660VD_FIX_ASUS_GPIO1,
5269 ALC861VD_FIX_DALLAS,
4906}; 5270};
4907 5271
4908/* reset GPIO1 */ 5272/* exclude VREF80 */
5273static void alc861vd_fixup_dallas(struct hda_codec *codec,
5274 const struct alc_fixup *fix, int action)
5275{
5276 if (action == ALC_FIXUP_ACT_PRE_PROBE) {
5277 snd_hda_override_pin_caps(codec, 0x18, 0x00001714);
5278 snd_hda_override_pin_caps(codec, 0x19, 0x0000171c);
5279 }
5280}
5281
4909static const struct alc_fixup alc861vd_fixups[] = { 5282static const struct alc_fixup alc861vd_fixups[] = {
4910 [ALC660VD_FIX_ASUS_GPIO1] = { 5283 [ALC660VD_FIX_ASUS_GPIO1] = {
4911 .type = ALC_FIXUP_VERBS, 5284 .type = ALC_FIXUP_VERBS,
4912 .v.verbs = (const struct hda_verb[]) { 5285 .v.verbs = (const struct hda_verb[]) {
5286 /* reset GPIO1 */
4913 {0x01, AC_VERB_SET_GPIO_MASK, 0x03}, 5287 {0x01, AC_VERB_SET_GPIO_MASK, 0x03},
4914 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01}, 5288 {0x01, AC_VERB_SET_GPIO_DIRECTION, 0x01},
4915 {0x01, AC_VERB_SET_GPIO_DATA, 0x01}, 5289 {0x01, AC_VERB_SET_GPIO_DATA, 0x01},
4916 { } 5290 { }
4917 } 5291 }
4918 }, 5292 },
5293 [ALC861VD_FIX_DALLAS] = {
5294 .type = ALC_FIXUP_FUNC,
5295 .v.func = alc861vd_fixup_dallas,
5296 },
4919}; 5297};
4920 5298
4921static const struct snd_pci_quirk alc861vd_fixup_tbl[] = { 5299static const struct snd_pci_quirk alc861vd_fixup_tbl[] = {
5300 SND_PCI_QUIRK(0x103c, 0x30bf, "HP TX1000", ALC861VD_FIX_DALLAS),
4922 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1), 5301 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS A7-K", ALC660VD_FIX_ASUS_GPIO1),
5302 SND_PCI_QUIRK(0x1179, 0xff31, "Toshiba L30-149", ALC861VD_FIX_DALLAS),
4923 {} 5303 {}
4924}; 5304};
4925 5305
@@ -4931,14 +5311,10 @@ static const struct hda_verb alc660vd_eapd_verbs[] = {
4931 5311
4932/* 5312/*
4933 */ 5313 */
4934#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4935#include "alc861vd_quirks.c"
4936#endif
4937
4938static int patch_alc861vd(struct hda_codec *codec) 5314static int patch_alc861vd(struct hda_codec *codec)
4939{ 5315{
4940 struct alc_spec *spec; 5316 struct alc_spec *spec;
4941 int err, board_config; 5317 int err;
4942 5318
4943 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5319 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
4944 if (spec == NULL) 5320 if (spec == NULL)
@@ -4948,39 +5324,13 @@ static int patch_alc861vd(struct hda_codec *codec)
4948 5324
4949 spec->mixer_nid = 0x0b; 5325 spec->mixer_nid = 0x0b;
4950 5326
4951 board_config = alc_board_config(codec, ALC861VD_MODEL_LAST, 5327 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
4952 alc861vd_models, alc861vd_cfg_tbl); 5328 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4953
4954 if (board_config < 0) {
4955 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
4956 codec->chip_name);
4957 board_config = ALC_MODEL_AUTO;
4958 }
4959
4960 if (board_config == ALC_MODEL_AUTO) {
4961 alc_pick_fixup(codec, NULL, alc861vd_fixup_tbl, alc861vd_fixups);
4962 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
4963 }
4964
4965 if (board_config == ALC_MODEL_AUTO) {
4966 /* automatic parse from the BIOS config */
4967 err = alc861vd_parse_auto_config(codec);
4968 if (err < 0) {
4969 alc_free(codec);
4970 return err;
4971 }
4972#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
4973 else if (!err) {
4974 printk(KERN_INFO
4975 "hda_codec: Cannot set up configuration "
4976 "from BIOS. Using base mode...\n");
4977 board_config = ALC861VD_3ST;
4978 }
4979#endif
4980 }
4981 5329
4982 if (board_config != ALC_MODEL_AUTO) 5330 /* automatic parse from the BIOS config */
4983 setup_preset(codec, &alc861vd_presets[board_config]); 5331 err = alc861vd_parse_auto_config(codec);
5332 if (err < 0)
5333 goto error;
4984 5334
4985 if (codec->vendor_id == 0x10ec0660) { 5335 if (codec->vendor_id == 0x10ec0660) {
4986 /* always turn on EAPD */ 5336 /* always turn on EAPD */
@@ -4998,10 +5348,8 @@ static int patch_alc861vd(struct hda_codec *codec)
4998 5348
4999 if (!spec->no_analog) { 5349 if (!spec->no_analog) {
5000 err = snd_hda_attach_beep_device(codec, 0x23); 5350 err = snd_hda_attach_beep_device(codec, 0x23);
5001 if (err < 0) { 5351 if (err < 0)
5002 alc_free(codec); 5352 goto error;
5003 return err;
5004 }
5005 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 5353 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
5006 } 5354 }
5007 5355
@@ -5011,8 +5359,7 @@ static int patch_alc861vd(struct hda_codec *codec)
5011 5359
5012 codec->patch_ops = alc_patch_ops; 5360 codec->patch_ops = alc_patch_ops;
5013 5361
5014 if (board_config == ALC_MODEL_AUTO) 5362 spec->init_hook = alc_auto_init_std;
5015 spec->init_hook = alc_auto_init_std;
5016 spec->shutup = alc_eapd_shutup; 5363 spec->shutup = alc_eapd_shutup;
5017#ifdef CONFIG_SND_HDA_POWER_SAVE 5364#ifdef CONFIG_SND_HDA_POWER_SAVE
5018 if (!spec->loopback.amplist) 5365 if (!spec->loopback.amplist)
@@ -5020,6 +5367,10 @@ static int patch_alc861vd(struct hda_codec *codec)
5020#endif 5367#endif
5021 5368
5022 return 0; 5369 return 0;
5370
5371 error:
5372 alc_free(codec);
5373 return err;
5023} 5374}
5024 5375
5025/* 5376/*
@@ -5077,6 +5428,14 @@ enum {
5077 ALC662_FIXUP_CZC_P10T, 5428 ALC662_FIXUP_CZC_P10T,
5078 ALC662_FIXUP_SKU_IGNORE, 5429 ALC662_FIXUP_SKU_IGNORE,
5079 ALC662_FIXUP_HP_RP5800, 5430 ALC662_FIXUP_HP_RP5800,
5431 ALC662_FIXUP_ASUS_MODE1,
5432 ALC662_FIXUP_ASUS_MODE2,
5433 ALC662_FIXUP_ASUS_MODE3,
5434 ALC662_FIXUP_ASUS_MODE4,
5435 ALC662_FIXUP_ASUS_MODE5,
5436 ALC662_FIXUP_ASUS_MODE6,
5437 ALC662_FIXUP_ASUS_MODE7,
5438 ALC662_FIXUP_ASUS_MODE8,
5080}; 5439};
5081 5440
5082static const struct alc_fixup alc662_fixups[] = { 5441static const struct alc_fixup alc662_fixups[] = {
@@ -5118,37 +5477,204 @@ static const struct alc_fixup alc662_fixups[] = {
5118 .chained = true, 5477 .chained = true,
5119 .chain_id = ALC662_FIXUP_SKU_IGNORE 5478 .chain_id = ALC662_FIXUP_SKU_IGNORE
5120 }, 5479 },
5480 [ALC662_FIXUP_ASUS_MODE1] = {
5481 .type = ALC_FIXUP_PINS,
5482 .v.pins = (const struct alc_pincfg[]) {
5483 { 0x14, 0x99130110 }, /* speaker */
5484 { 0x18, 0x01a19c20 }, /* mic */
5485 { 0x19, 0x99a3092f }, /* int-mic */
5486 { 0x21, 0x0121401f }, /* HP out */
5487 { }
5488 },
5489 .chained = true,
5490 .chain_id = ALC662_FIXUP_SKU_IGNORE
5491 },
5492 [ALC662_FIXUP_ASUS_MODE2] = {
5493 .type = ALC_FIXUP_PINS,
5494 .v.pins = (const struct alc_pincfg[]) {
5495 { 0x14, 0x99130110 }, /* speaker */
5496 { 0x18, 0x01a19820 }, /* mic */
5497 { 0x19, 0x99a3092f }, /* int-mic */
5498 { 0x1b, 0x0121401f }, /* HP out */
5499 { }
5500 },
5501 .chained = true,
5502 .chain_id = ALC662_FIXUP_SKU_IGNORE
5503 },
5504 [ALC662_FIXUP_ASUS_MODE3] = {
5505 .type = ALC_FIXUP_PINS,
5506 .v.pins = (const struct alc_pincfg[]) {
5507 { 0x14, 0x99130110 }, /* speaker */
5508 { 0x15, 0x0121441f }, /* HP */
5509 { 0x18, 0x01a19840 }, /* mic */
5510 { 0x19, 0x99a3094f }, /* int-mic */
5511 { 0x21, 0x01211420 }, /* HP2 */
5512 { }
5513 },
5514 .chained = true,
5515 .chain_id = ALC662_FIXUP_SKU_IGNORE
5516 },
5517 [ALC662_FIXUP_ASUS_MODE4] = {
5518 .type = ALC_FIXUP_PINS,
5519 .v.pins = (const struct alc_pincfg[]) {
5520 { 0x14, 0x99130110 }, /* speaker */
5521 { 0x16, 0x99130111 }, /* speaker */
5522 { 0x18, 0x01a19840 }, /* mic */
5523 { 0x19, 0x99a3094f }, /* int-mic */
5524 { 0x21, 0x0121441f }, /* HP */
5525 { }
5526 },
5527 .chained = true,
5528 .chain_id = ALC662_FIXUP_SKU_IGNORE
5529 },
5530 [ALC662_FIXUP_ASUS_MODE5] = {
5531 .type = ALC_FIXUP_PINS,
5532 .v.pins = (const struct alc_pincfg[]) {
5533 { 0x14, 0x99130110 }, /* speaker */
5534 { 0x15, 0x0121441f }, /* HP */
5535 { 0x16, 0x99130111 }, /* speaker */
5536 { 0x18, 0x01a19840 }, /* mic */
5537 { 0x19, 0x99a3094f }, /* int-mic */
5538 { }
5539 },
5540 .chained = true,
5541 .chain_id = ALC662_FIXUP_SKU_IGNORE
5542 },
5543 [ALC662_FIXUP_ASUS_MODE6] = {
5544 .type = ALC_FIXUP_PINS,
5545 .v.pins = (const struct alc_pincfg[]) {
5546 { 0x14, 0x99130110 }, /* speaker */
5547 { 0x15, 0x01211420 }, /* HP2 */
5548 { 0x18, 0x01a19840 }, /* mic */
5549 { 0x19, 0x99a3094f }, /* int-mic */
5550 { 0x1b, 0x0121441f }, /* HP */
5551 { }
5552 },
5553 .chained = true,
5554 .chain_id = ALC662_FIXUP_SKU_IGNORE
5555 },
5556 [ALC662_FIXUP_ASUS_MODE7] = {
5557 .type = ALC_FIXUP_PINS,
5558 .v.pins = (const struct alc_pincfg[]) {
5559 { 0x14, 0x99130110 }, /* speaker */
5560 { 0x17, 0x99130111 }, /* speaker */
5561 { 0x18, 0x01a19840 }, /* mic */
5562 { 0x19, 0x99a3094f }, /* int-mic */
5563 { 0x1b, 0x01214020 }, /* HP */
5564 { 0x21, 0x0121401f }, /* HP */
5565 { }
5566 },
5567 .chained = true,
5568 .chain_id = ALC662_FIXUP_SKU_IGNORE
5569 },
5570 [ALC662_FIXUP_ASUS_MODE8] = {
5571 .type = ALC_FIXUP_PINS,
5572 .v.pins = (const struct alc_pincfg[]) {
5573 { 0x14, 0x99130110 }, /* speaker */
5574 { 0x12, 0x99a30970 }, /* int-mic */
5575 { 0x15, 0x01214020 }, /* HP */
5576 { 0x17, 0x99130111 }, /* speaker */
5577 { 0x18, 0x01a19840 }, /* mic */
5578 { 0x21, 0x0121401f }, /* HP */
5579 { }
5580 },
5581 .chained = true,
5582 .chain_id = ALC662_FIXUP_SKU_IGNORE
5583 },
5121}; 5584};
5122 5585
5123static const struct snd_pci_quirk alc662_fixup_tbl[] = { 5586static const struct snd_pci_quirk alc662_fixup_tbl[] = {
5587 SND_PCI_QUIRK(0x1019, 0x9087, "ECS", ALC662_FIXUP_ASUS_MODE2),
5124 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE), 5588 SND_PCI_QUIRK(0x1025, 0x0308, "Acer Aspire 8942G", ALC662_FIXUP_ASPIRE),
5125 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE), 5589 SND_PCI_QUIRK(0x1025, 0x031c, "Gateway NV79", ALC662_FIXUP_SKU_IGNORE),
5126 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE), 5590 SND_PCI_QUIRK(0x1025, 0x038b, "Acer Aspire 8943G", ALC662_FIXUP_ASPIRE),
5127 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800), 5591 SND_PCI_QUIRK(0x103c, 0x1632, "HP RP5800", ALC662_FIXUP_HP_RP5800),
5592 SND_PCI_QUIRK(0x105b, 0x0cd6, "Foxconn", ALC662_FIXUP_ASUS_MODE2),
5128 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD), 5593 SND_PCI_QUIRK(0x144d, 0xc051, "Samsung R720", ALC662_FIXUP_IDEAPAD),
5129 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD), 5594 SND_PCI_QUIRK(0x17aa, 0x38af, "Lenovo Ideapad Y550P", ALC662_FIXUP_IDEAPAD),
5130 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD), 5595 SND_PCI_QUIRK(0x17aa, 0x3a0d, "Lenovo Ideapad Y550", ALC662_FIXUP_IDEAPAD),
5131 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T), 5596 SND_PCI_QUIRK(0x1b35, 0x2206, "CZC P10T", ALC662_FIXUP_CZC_P10T),
5597
5598#if 0
5599 /* Below is a quirk table taken from the old code.
5600 * Basically the device should work as is without the fixup table.
5601 * If BIOS doesn't give a proper info, enable the corresponding
5602 * fixup entry.
5603 */
5604 SND_PCI_QUIRK(0x1043, 0x1000, "ASUS N50Vm", ALC662_FIXUP_ASUS_MODE1),
5605 SND_PCI_QUIRK(0x1043, 0x1092, "ASUS NB", ALC662_FIXUP_ASUS_MODE3),
5606 SND_PCI_QUIRK(0x1043, 0x1173, "ASUS K73Jn", ALC662_FIXUP_ASUS_MODE1),
5607 SND_PCI_QUIRK(0x1043, 0x11c3, "ASUS M70V", ALC662_FIXUP_ASUS_MODE3),
5608 SND_PCI_QUIRK(0x1043, 0x11d3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5609 SND_PCI_QUIRK(0x1043, 0x11f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5610 SND_PCI_QUIRK(0x1043, 0x1203, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5611 SND_PCI_QUIRK(0x1043, 0x1303, "ASUS G60J", ALC662_FIXUP_ASUS_MODE1),
5612 SND_PCI_QUIRK(0x1043, 0x1333, "ASUS G60Jx", ALC662_FIXUP_ASUS_MODE1),
5613 SND_PCI_QUIRK(0x1043, 0x1339, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5614 SND_PCI_QUIRK(0x1043, 0x13e3, "ASUS N71JA", ALC662_FIXUP_ASUS_MODE7),
5615 SND_PCI_QUIRK(0x1043, 0x1463, "ASUS N71", ALC662_FIXUP_ASUS_MODE7),
5616 SND_PCI_QUIRK(0x1043, 0x14d3, "ASUS G72", ALC662_FIXUP_ASUS_MODE8),
5617 SND_PCI_QUIRK(0x1043, 0x1563, "ASUS N90", ALC662_FIXUP_ASUS_MODE3),
5618 SND_PCI_QUIRK(0x1043, 0x15d3, "ASUS N50SF F50SF", ALC662_FIXUP_ASUS_MODE1),
5619 SND_PCI_QUIRK(0x1043, 0x16c3, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5620 SND_PCI_QUIRK(0x1043, 0x16f3, "ASUS K40C K50C", ALC662_FIXUP_ASUS_MODE2),
5621 SND_PCI_QUIRK(0x1043, 0x1733, "ASUS N81De", ALC662_FIXUP_ASUS_MODE1),
5622 SND_PCI_QUIRK(0x1043, 0x1753, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5623 SND_PCI_QUIRK(0x1043, 0x1763, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5624 SND_PCI_QUIRK(0x1043, 0x1765, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5625 SND_PCI_QUIRK(0x1043, 0x1783, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5626 SND_PCI_QUIRK(0x1043, 0x1793, "ASUS F50GX", ALC662_FIXUP_ASUS_MODE1),
5627 SND_PCI_QUIRK(0x1043, 0x17b3, "ASUS F70SL", ALC662_FIXUP_ASUS_MODE3),
5628 SND_PCI_QUIRK(0x1043, 0x17f3, "ASUS X58LE", ALC662_FIXUP_ASUS_MODE2),
5629 SND_PCI_QUIRK(0x1043, 0x1813, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5630 SND_PCI_QUIRK(0x1043, 0x1823, "ASUS NB", ALC662_FIXUP_ASUS_MODE5),
5631 SND_PCI_QUIRK(0x1043, 0x1833, "ASUS NB", ALC662_FIXUP_ASUS_MODE6),
5632 SND_PCI_QUIRK(0x1043, 0x1843, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5633 SND_PCI_QUIRK(0x1043, 0x1853, "ASUS F50Z", ALC662_FIXUP_ASUS_MODE1),
5634 SND_PCI_QUIRK(0x1043, 0x1864, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5635 SND_PCI_QUIRK(0x1043, 0x1876, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5636 SND_PCI_QUIRK(0x1043, 0x1893, "ASUS M50Vm", ALC662_FIXUP_ASUS_MODE3),
5637 SND_PCI_QUIRK(0x1043, 0x1894, "ASUS X55", ALC662_FIXUP_ASUS_MODE3),
5638 SND_PCI_QUIRK(0x1043, 0x18b3, "ASUS N80Vc", ALC662_FIXUP_ASUS_MODE1),
5639 SND_PCI_QUIRK(0x1043, 0x18c3, "ASUS VX5", ALC662_FIXUP_ASUS_MODE1),
5640 SND_PCI_QUIRK(0x1043, 0x18d3, "ASUS N81Te", ALC662_FIXUP_ASUS_MODE1),
5641 SND_PCI_QUIRK(0x1043, 0x18f3, "ASUS N505Tp", ALC662_FIXUP_ASUS_MODE1),
5642 SND_PCI_QUIRK(0x1043, 0x1903, "ASUS F5GL", ALC662_FIXUP_ASUS_MODE1),
5643 SND_PCI_QUIRK(0x1043, 0x1913, "ASUS NB", ALC662_FIXUP_ASUS_MODE2),
5644 SND_PCI_QUIRK(0x1043, 0x1933, "ASUS F80Q", ALC662_FIXUP_ASUS_MODE2),
5645 SND_PCI_QUIRK(0x1043, 0x1943, "ASUS Vx3V", ALC662_FIXUP_ASUS_MODE1),
5646 SND_PCI_QUIRK(0x1043, 0x1953, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5647 SND_PCI_QUIRK(0x1043, 0x1963, "ASUS X71C", ALC662_FIXUP_ASUS_MODE3),
5648 SND_PCI_QUIRK(0x1043, 0x1983, "ASUS N5051A", ALC662_FIXUP_ASUS_MODE1),
5649 SND_PCI_QUIRK(0x1043, 0x1993, "ASUS N20", ALC662_FIXUP_ASUS_MODE1),
5650 SND_PCI_QUIRK(0x1043, 0x19b3, "ASUS F7Z", ALC662_FIXUP_ASUS_MODE1),
5651 SND_PCI_QUIRK(0x1043, 0x19c3, "ASUS F5Z/F6x", ALC662_FIXUP_ASUS_MODE2),
5652 SND_PCI_QUIRK(0x1043, 0x19e3, "ASUS NB", ALC662_FIXUP_ASUS_MODE1),
5653 SND_PCI_QUIRK(0x1043, 0x19f3, "ASUS NB", ALC662_FIXUP_ASUS_MODE4),
5654#endif
5132 {} 5655 {}
5133}; 5656};
5134 5657
5135static const struct alc_model_fixup alc662_fixup_models[] = { 5658static const struct alc_model_fixup alc662_fixup_models[] = {
5136 {.id = ALC272_FIXUP_MARIO, .name = "mario"}, 5659 {.id = ALC272_FIXUP_MARIO, .name = "mario"},
5660 {.id = ALC662_FIXUP_ASUS_MODE1, .name = "asus-mode1"},
5661 {.id = ALC662_FIXUP_ASUS_MODE2, .name = "asus-mode2"},
5662 {.id = ALC662_FIXUP_ASUS_MODE3, .name = "asus-mode3"},
5663 {.id = ALC662_FIXUP_ASUS_MODE4, .name = "asus-mode4"},
5664 {.id = ALC662_FIXUP_ASUS_MODE5, .name = "asus-mode5"},
5665 {.id = ALC662_FIXUP_ASUS_MODE6, .name = "asus-mode6"},
5666 {.id = ALC662_FIXUP_ASUS_MODE7, .name = "asus-mode7"},
5667 {.id = ALC662_FIXUP_ASUS_MODE8, .name = "asus-mode8"},
5137 {} 5668 {}
5138}; 5669};
5139 5670
5140 5671
5141/* 5672/*
5142 */ 5673 */
5143#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5144#include "alc662_quirks.c"
5145#endif
5146
5147static int patch_alc662(struct hda_codec *codec) 5674static int patch_alc662(struct hda_codec *codec)
5148{ 5675{
5149 struct alc_spec *spec; 5676 struct alc_spec *spec;
5150 int err, board_config; 5677 int err = 0;
5151 int coef;
5152 5678
5153 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5679 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5154 if (!spec) 5680 if (!spec)
@@ -5158,50 +5684,31 @@ static int patch_alc662(struct hda_codec *codec)
5158 5684
5159 spec->mixer_nid = 0x0b; 5685 spec->mixer_nid = 0x0b;
5160 5686
5687 /* handle multiple HPs as is */
5688 spec->parse_flags = HDA_PINCFG_NO_HP_FIXUP;
5689
5161 alc_auto_parse_customize_define(codec); 5690 alc_auto_parse_customize_define(codec);
5162 5691
5163 alc_fix_pll_init(codec, 0x20, 0x04, 15); 5692 alc_fix_pll_init(codec, 0x20, 0x04, 15);
5164 5693
5165 coef = alc_read_coef_idx(codec, 0); 5694 err = alc_codec_rename_from_preset(codec);
5166 if (coef == 0x8020 || coef == 0x8011) 5695 if (err < 0)
5167 alc_codec_rename(codec, "ALC661"); 5696 goto error;
5168 else if (coef & (1 << 14) &&
5169 codec->bus->pci->subsystem_vendor == 0x1025 &&
5170 spec->cdefine.platform_type == 1)
5171 alc_codec_rename(codec, "ALC272X");
5172 else if (coef == 0x4011)
5173 alc_codec_rename(codec, "ALC656");
5174
5175 board_config = alc_board_config(codec, ALC662_MODEL_LAST,
5176 alc662_models, alc662_cfg_tbl);
5177 if (board_config < 0) {
5178 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n",
5179 codec->chip_name);
5180 board_config = ALC_MODEL_AUTO;
5181 }
5182 5697
5183 if (board_config == ALC_MODEL_AUTO) { 5698 if ((alc_get_coef0(codec) & (1 << 14)) &&
5184 alc_pick_fixup(codec, alc662_fixup_models, 5699 codec->bus->pci->subsystem_vendor == 0x1025 &&
5185 alc662_fixup_tbl, alc662_fixups); 5700 spec->cdefine.platform_type == 1) {
5186 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE); 5701 if (alc_codec_rename(codec, "ALC272X") < 0)
5187 /* automatic parse from the BIOS config */ 5702 goto error;
5188 err = alc662_parse_auto_config(codec);
5189 if (err < 0) {
5190 alc_free(codec);
5191 return err;
5192 }
5193#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5194 else if (!err) {
5195 printk(KERN_INFO
5196 "hda_codec: Cannot set up configuration "
5197 "from BIOS. Using base mode...\n");
5198 board_config = ALC662_3ST_2ch_DIG;
5199 }
5200#endif
5201 } 5703 }
5202 5704
5203 if (board_config != ALC_MODEL_AUTO) 5705 alc_pick_fixup(codec, alc662_fixup_models,
5204 setup_preset(codec, &alc662_presets[board_config]); 5706 alc662_fixup_tbl, alc662_fixups);
5707 alc_apply_fixup(codec, ALC_FIXUP_ACT_PRE_PROBE);
5708 /* automatic parse from the BIOS config */
5709 err = alc662_parse_auto_config(codec);
5710 if (err < 0)
5711 goto error;
5205 5712
5206 if (!spec->no_analog && !spec->adc_nids) { 5713 if (!spec->no_analog && !spec->adc_nids) {
5207 alc_auto_fill_adc_caps(codec); 5714 alc_auto_fill_adc_caps(codec);
@@ -5214,10 +5721,8 @@ static int patch_alc662(struct hda_codec *codec)
5214 5721
5215 if (!spec->no_analog && has_cdefine_beep(codec)) { 5722 if (!spec->no_analog && has_cdefine_beep(codec)) {
5216 err = snd_hda_attach_beep_device(codec, 0x1); 5723 err = snd_hda_attach_beep_device(codec, 0x1);
5217 if (err < 0) { 5724 if (err < 0)
5218 alc_free(codec); 5725 goto error;
5219 return err;
5220 }
5221 switch (codec->vendor_id) { 5726 switch (codec->vendor_id) {
5222 case 0x10ec0662: 5727 case 0x10ec0662:
5223 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT); 5728 set_beep_amp(spec, 0x0b, 0x05, HDA_INPUT);
@@ -5237,8 +5742,7 @@ static int patch_alc662(struct hda_codec *codec)
5237 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE); 5742 alc_apply_fixup(codec, ALC_FIXUP_ACT_PROBE);
5238 5743
5239 codec->patch_ops = alc_patch_ops; 5744 codec->patch_ops = alc_patch_ops;
5240 if (board_config == ALC_MODEL_AUTO) 5745 spec->init_hook = alc_auto_init_std;
5241 spec->init_hook = alc_auto_init_std;
5242 spec->shutup = alc_eapd_shutup; 5746 spec->shutup = alc_eapd_shutup;
5243 5747
5244 alc_init_jacks(codec); 5748 alc_init_jacks(codec);
@@ -5249,32 +5753,10 @@ static int patch_alc662(struct hda_codec *codec)
5249#endif 5753#endif
5250 5754
5251 return 0; 5755 return 0;
5252}
5253
5254static int patch_alc888(struct hda_codec *codec)
5255{
5256 if ((alc_read_coef_idx(codec, 0) & 0x00f0)==0x0030){
5257 kfree(codec->chip_name);
5258 if (codec->vendor_id == 0x10ec0887)
5259 codec->chip_name = kstrdup("ALC887-VD", GFP_KERNEL);
5260 else
5261 codec->chip_name = kstrdup("ALC888-VD", GFP_KERNEL);
5262 if (!codec->chip_name) {
5263 alc_free(codec);
5264 return -ENOMEM;
5265 }
5266 return patch_alc662(codec);
5267 }
5268 return patch_alc882(codec);
5269}
5270 5756
5271static int patch_alc899(struct hda_codec *codec) 5757 error:
5272{ 5758 alc_free(codec);
5273 if ((alc_read_coef_idx(codec, 0) & 0x2000) != 0x2000) { 5759 return err;
5274 kfree(codec->chip_name);
5275 codec->chip_name = kstrdup("ALC898", GFP_KERNEL);
5276 }
5277 return patch_alc882(codec);
5278} 5760}
5279 5761
5280/* 5762/*
@@ -5288,14 +5770,9 @@ static int alc680_parse_auto_config(struct hda_codec *codec)
5288 5770
5289/* 5771/*
5290 */ 5772 */
5291#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5292#include "alc680_quirks.c"
5293#endif
5294
5295static int patch_alc680(struct hda_codec *codec) 5773static int patch_alc680(struct hda_codec *codec)
5296{ 5774{
5297 struct alc_spec *spec; 5775 struct alc_spec *spec;
5298 int board_config;
5299 int err; 5776 int err;
5300 5777
5301 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5778 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
@@ -5306,43 +5783,11 @@ static int patch_alc680(struct hda_codec *codec)
5306 5783
5307 /* ALC680 has no aa-loopback mixer */ 5784 /* ALC680 has no aa-loopback mixer */
5308 5785
5309 board_config = alc_board_config(codec, ALC680_MODEL_LAST, 5786 /* automatic parse from the BIOS config */
5310 alc680_models, alc680_cfg_tbl); 5787 err = alc680_parse_auto_config(codec);
5311 5788 if (err < 0) {
5312 if (board_config < 0) { 5789 alc_free(codec);
5313 printk(KERN_INFO "hda_codec: %s: BIOS auto-probing.\n", 5790 return err;
5314 codec->chip_name);
5315 board_config = ALC_MODEL_AUTO;
5316 }
5317
5318 if (board_config == ALC_MODEL_AUTO) {
5319 /* automatic parse from the BIOS config */
5320 err = alc680_parse_auto_config(codec);
5321 if (err < 0) {
5322 alc_free(codec);
5323 return err;
5324 }
5325#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5326 else if (!err) {
5327 printk(KERN_INFO
5328 "hda_codec: Cannot set up configuration "
5329 "from BIOS. Using base mode...\n");
5330 board_config = ALC680_BASE;
5331 }
5332#endif
5333 }
5334
5335 if (board_config != ALC_MODEL_AUTO) {
5336 setup_preset(codec, &alc680_presets[board_config]);
5337#ifdef CONFIG_SND_HDA_ENABLE_REALTEK_QUIRKS
5338 spec->stream_analog_capture = &alc680_pcm_analog_auto_capture;
5339#endif
5340 }
5341
5342 if (!spec->no_analog && !spec->adc_nids) {
5343 alc_auto_fill_adc_caps(codec);
5344 alc_rebuild_imux_for_auto_mic(codec);
5345 alc_remove_invalid_adc_nids(codec);
5346 } 5791 }
5347 5792
5348 if (!spec->no_analog && !spec->cap_mixer) 5793 if (!spec->no_analog && !spec->cap_mixer)
@@ -5351,8 +5796,7 @@ static int patch_alc680(struct hda_codec *codec)
5351 spec->vmaster_nid = 0x02; 5796 spec->vmaster_nid = 0x02;
5352 5797
5353 codec->patch_ops = alc_patch_ops; 5798 codec->patch_ops = alc_patch_ops;
5354 if (board_config == ALC_MODEL_AUTO) 5799 spec->init_hook = alc_auto_init_std;
5355 spec->init_hook = alc_auto_init_std;
5356 5800
5357 return 0; 5801 return 0;
5358} 5802}
@@ -5380,6 +5824,8 @@ static const struct hda_codec_preset snd_hda_preset_realtek[] = {
5380 .patch = patch_alc882 }, 5824 .patch = patch_alc882 },
5381 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1", 5825 { .id = 0x10ec0662, .rev = 0x100101, .name = "ALC662 rev1",
5382 .patch = patch_alc662 }, 5826 .patch = patch_alc662 },
5827 { .id = 0x10ec0662, .rev = 0x100300, .name = "ALC662 rev3",
5828 .patch = patch_alc662 },
5383 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 }, 5829 { .id = 0x10ec0663, .name = "ALC663", .patch = patch_alc662 },
5384 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 }, 5830 { .id = 0x10ec0665, .name = "ALC665", .patch = patch_alc662 },
5385 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 }, 5831 { .id = 0x10ec0670, .name = "ALC670", .patch = patch_alc662 },
@@ -5392,13 +5838,13 @@ static const struct hda_codec_preset snd_hda_preset_realtek[] = {
5392 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A", 5838 { .id = 0x10ec0885, .rev = 0x100103, .name = "ALC889A",
5393 .patch = patch_alc882 }, 5839 .patch = patch_alc882 },
5394 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 }, 5840 { .id = 0x10ec0885, .name = "ALC885", .patch = patch_alc882 },
5395 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc888 }, 5841 { .id = 0x10ec0887, .name = "ALC887", .patch = patch_alc882 },
5396 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200", 5842 { .id = 0x10ec0888, .rev = 0x100101, .name = "ALC1200",
5397 .patch = patch_alc882 }, 5843 .patch = patch_alc882 },
5398 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc888 }, 5844 { .id = 0x10ec0888, .name = "ALC888", .patch = patch_alc882 },
5399 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 }, 5845 { .id = 0x10ec0889, .name = "ALC889", .patch = patch_alc882 },
5400 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 }, 5846 { .id = 0x10ec0892, .name = "ALC892", .patch = patch_alc662 },
5401 { .id = 0x10ec0899, .name = "ALC899", .patch = patch_alc899 }, 5847 { .id = 0x10ec0899, .name = "ALC898", .patch = patch_alc882 },
5402 {} /* terminator */ 5848 {} /* terminator */
5403}; 5849};
5404 5850
diff --git a/sound/pci/hda/patch_sigmatel.c b/sound/pci/hda/patch_sigmatel.c
index aa376b59c006..de4c36027cbe 100644
--- a/sound/pci/hda/patch_sigmatel.c
+++ b/sound/pci/hda/patch_sigmatel.c
@@ -673,6 +673,7 @@ static int stac92xx_smux_enum_put(struct snd_kcontrol *kcontrol,
673 return 0; 673 return 0;
674} 674}
675 675
676#ifdef CONFIG_SND_HDA_POWER_SAVE
676static int stac_vrefout_set(struct hda_codec *codec, 677static int stac_vrefout_set(struct hda_codec *codec,
677 hda_nid_t nid, unsigned int new_vref) 678 hda_nid_t nid, unsigned int new_vref)
678{ 679{
@@ -696,6 +697,7 @@ static int stac_vrefout_set(struct hda_codec *codec,
696 697
697 return 1; 698 return 1;
698} 699}
700#endif
699 701
700static unsigned int stac92xx_vref_set(struct hda_codec *codec, 702static unsigned int stac92xx_vref_set(struct hda_codec *codec,
701 hda_nid_t nid, unsigned int new_vref) 703 hda_nid_t nid, unsigned int new_vref)
@@ -2970,8 +2972,9 @@ static int check_all_dac_nids(struct sigmatel_spec *spec, hda_nid_t nid)
2970static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid) 2972static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2971{ 2973{
2972 struct sigmatel_spec *spec = codec->spec; 2974 struct sigmatel_spec *spec = codec->spec;
2975 struct auto_pin_cfg *cfg = &spec->autocfg;
2973 int j, conn_len; 2976 int j, conn_len;
2974 hda_nid_t conn[HDA_MAX_CONNECTIONS]; 2977 hda_nid_t conn[HDA_MAX_CONNECTIONS], fallback_dac;
2975 unsigned int wcaps, wtype; 2978 unsigned int wcaps, wtype;
2976 2979
2977 conn_len = snd_hda_get_connections(codec, nid, conn, 2980 conn_len = snd_hda_get_connections(codec, nid, conn,
@@ -2999,10 +3002,21 @@ static hda_nid_t get_unassigned_dac(struct hda_codec *codec, hda_nid_t nid)
2999 return conn[j]; 3002 return conn[j];
3000 } 3003 }
3001 } 3004 }
3002 /* if all DACs are already assigned, connect to the primary DAC */ 3005
3006 /* if all DACs are already assigned, connect to the primary DAC,
3007 unless we're assigning a secondary headphone */
3008 fallback_dac = spec->multiout.dac_nids[0];
3009 if (spec->multiout.hp_nid) {
3010 for (j = 0; j < cfg->hp_outs; j++)
3011 if (cfg->hp_pins[j] == nid) {
3012 fallback_dac = spec->multiout.hp_nid;
3013 break;
3014 }
3015 }
3016
3003 if (conn_len > 1) { 3017 if (conn_len > 1) {
3004 for (j = 0; j < conn_len; j++) { 3018 for (j = 0; j < conn_len; j++) {
3005 if (conn[j] == spec->multiout.dac_nids[0]) { 3019 if (conn[j] == fallback_dac) {
3006 snd_hda_codec_write_cache(codec, nid, 0, 3020 snd_hda_codec_write_cache(codec, nid, 0,
3007 AC_VERB_SET_CONNECT_SEL, j); 3021 AC_VERB_SET_CONNECT_SEL, j);
3008 break; 3022 break;
@@ -3777,9 +3791,10 @@ static int is_dual_headphones(struct hda_codec *codec)
3777} 3791}
3778 3792
3779 3793
3780static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out, hda_nid_t dig_in) 3794static int stac92xx_parse_auto_config(struct hda_codec *codec)
3781{ 3795{
3782 struct sigmatel_spec *spec = codec->spec; 3796 struct sigmatel_spec *spec = codec->spec;
3797 hda_nid_t dig_out = 0, dig_in = 0;
3783 int hp_swap = 0; 3798 int hp_swap = 0;
3784 int i, err; 3799 int i, err;
3785 3800
@@ -3962,6 +3977,22 @@ static int stac92xx_parse_auto_config(struct hda_codec *codec, hda_nid_t dig_out
3962 if (spec->multiout.max_channels > 2) 3977 if (spec->multiout.max_channels > 2)
3963 spec->surr_switch = 1; 3978 spec->surr_switch = 1;
3964 3979
3980 /* find digital out and in converters */
3981 for (i = codec->start_nid; i < codec->start_nid + codec->num_nodes; i++) {
3982 unsigned int wid_caps = get_wcaps(codec, i);
3983 if (wid_caps & AC_WCAP_DIGITAL) {
3984 switch (get_wcaps_type(wid_caps)) {
3985 case AC_WID_AUD_OUT:
3986 if (!dig_out)
3987 dig_out = i;
3988 break;
3989 case AC_WID_AUD_IN:
3990 if (!dig_in)
3991 dig_in = i;
3992 break;
3993 }
3994 }
3995 }
3965 if (spec->autocfg.dig_outs) 3996 if (spec->autocfg.dig_outs)
3966 spec->multiout.dig_out_nid = dig_out; 3997 spec->multiout.dig_out_nid = dig_out;
3967 if (dig_in && spec->autocfg.dig_in_pin) 3998 if (dig_in && spec->autocfg.dig_in_pin)
@@ -4128,22 +4159,14 @@ static int stac92xx_add_jack(struct hda_codec *codec,
4128#ifdef CONFIG_SND_HDA_INPUT_JACK 4159#ifdef CONFIG_SND_HDA_INPUT_JACK
4129 int def_conf = snd_hda_codec_get_pincfg(codec, nid); 4160 int def_conf = snd_hda_codec_get_pincfg(codec, nid);
4130 int connectivity = get_defcfg_connect(def_conf); 4161 int connectivity = get_defcfg_connect(def_conf);
4131 char name[32];
4132 int err;
4133 4162
4134 if (connectivity && connectivity != AC_JACK_PORT_FIXED) 4163 if (connectivity && connectivity != AC_JACK_PORT_FIXED)
4135 return 0; 4164 return 0;
4136 4165
4137 snprintf(name, sizeof(name), "%s at %s %s Jack", 4166 return snd_hda_input_jack_add(codec, nid, type, NULL);
4138 snd_hda_get_jack_type(def_conf), 4167#else
4139 snd_hda_get_jack_connectivity(def_conf),
4140 snd_hda_get_jack_location(def_conf));
4141
4142 err = snd_hda_input_jack_add(codec, nid, type, name);
4143 if (err < 0)
4144 return err;
4145#endif /* CONFIG_SND_HDA_INPUT_JACK */
4146 return 0; 4168 return 0;
4169#endif /* CONFIG_SND_HDA_INPUT_JACK */
4147} 4170}
4148 4171
4149static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid, 4172static int stac_add_event(struct sigmatel_spec *spec, hda_nid_t nid,
@@ -5273,7 +5296,7 @@ static int patch_stac925x(struct hda_codec *codec)
5273 spec->capvols = stac925x_capvols; 5296 spec->capvols = stac925x_capvols;
5274 spec->capsws = stac925x_capsws; 5297 spec->capsws = stac925x_capsws;
5275 5298
5276 err = stac92xx_parse_auto_config(codec, 0x8, 0x7); 5299 err = stac92xx_parse_auto_config(codec);
5277 if (!err) { 5300 if (!err) {
5278 if (spec->board_config < 0) { 5301 if (spec->board_config < 0) {
5279 printk(KERN_WARNING "hda_codec: No auto-config is " 5302 printk(KERN_WARNING "hda_codec: No auto-config is "
@@ -5414,7 +5437,7 @@ again:
5414 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids); 5437 spec->num_pwrs = ARRAY_SIZE(stac92hd73xx_pwr_nids);
5415 spec->pwr_nids = stac92hd73xx_pwr_nids; 5438 spec->pwr_nids = stac92hd73xx_pwr_nids;
5416 5439
5417 err = stac92xx_parse_auto_config(codec, 0x25, 0x27); 5440 err = stac92xx_parse_auto_config(codec);
5418 5441
5419 if (!err) { 5442 if (!err) {
5420 if (spec->board_config < 0) { 5443 if (spec->board_config < 0) {
@@ -5583,9 +5606,7 @@ static void stac92hd8x_fill_auto_spec(struct hda_codec *codec)
5583static int patch_stac92hd83xxx(struct hda_codec *codec) 5606static int patch_stac92hd83xxx(struct hda_codec *codec)
5584{ 5607{
5585 struct sigmatel_spec *spec; 5608 struct sigmatel_spec *spec;
5586 hda_nid_t conn[STAC92HD83_DAC_COUNT + 1];
5587 int err; 5609 int err;
5588 int num_dacs;
5589 5610
5590 spec = kzalloc(sizeof(*spec), GFP_KERNEL); 5611 spec = kzalloc(sizeof(*spec), GFP_KERNEL);
5591 if (spec == NULL) 5612 if (spec == NULL)
@@ -5625,25 +5646,8 @@ again:
5625 stac92xx_set_config_regs(codec, 5646 stac92xx_set_config_regs(codec,
5626 stac92hd83xxx_brd_tbl[spec->board_config]); 5647 stac92hd83xxx_brd_tbl[spec->board_config]);
5627 5648
5628 switch (codec->vendor_id) { 5649 if (spec->board_config != STAC_92HD83XXX_PWR_REF)
5629 case 0x111d76d1:
5630 case 0x111d76d9:
5631 case 0x111d76e5:
5632 case 0x111d7666:
5633 case 0x111d7667:
5634 case 0x111d7668:
5635 case 0x111d7669:
5636 case 0x111d76e3:
5637 case 0x111d7604:
5638 case 0x111d76d4:
5639 case 0x111d7605:
5640 case 0x111d76d5:
5641 case 0x111d76e7:
5642 if (spec->board_config == STAC_92HD83XXX_PWR_REF)
5643 break;
5644 spec->num_pwrs = 0; 5650 spec->num_pwrs = 0;
5645 break;
5646 }
5647 5651
5648 codec->patch_ops = stac92xx_patch_ops; 5652 codec->patch_ops = stac92xx_patch_ops;
5649 5653
@@ -5670,7 +5674,7 @@ again:
5670 } 5674 }
5671#endif 5675#endif
5672 5676
5673 err = stac92xx_parse_auto_config(codec, 0x1d, 0); 5677 err = stac92xx_parse_auto_config(codec);
5674 if (!err) { 5678 if (!err) {
5675 if (spec->board_config < 0) { 5679 if (spec->board_config < 0) {
5676 printk(KERN_WARNING "hda_codec: No auto-config is " 5680 printk(KERN_WARNING "hda_codec: No auto-config is "
@@ -5686,22 +5690,6 @@ again:
5686 return err; 5690 return err;
5687 } 5691 }
5688 5692
5689 /* docking output support */
5690 num_dacs = snd_hda_get_connections(codec, 0xF,
5691 conn, STAC92HD83_DAC_COUNT + 1) - 1;
5692 /* skip non-DAC connections */
5693 while (num_dacs >= 0 &&
5694 (get_wcaps_type(get_wcaps(codec, conn[num_dacs]))
5695 != AC_WID_AUD_OUT))
5696 num_dacs--;
5697 /* set port E and F to select the last DAC */
5698 if (num_dacs >= 0) {
5699 snd_hda_codec_write_cache(codec, 0xE, 0,
5700 AC_VERB_SET_CONNECT_SEL, num_dacs);
5701 snd_hda_codec_write_cache(codec, 0xF, 0,
5702 AC_VERB_SET_CONNECT_SEL, num_dacs);
5703 }
5704
5705 codec->proc_widget_hook = stac92hd_proc_hook; 5693 codec->proc_widget_hook = stac92hd_proc_hook;
5706 5694
5707 return 0; 5695 return 0;
@@ -6007,7 +5995,7 @@ again:
6007 5995
6008 spec->multiout.dac_nids = spec->dac_nids; 5996 spec->multiout.dac_nids = spec->dac_nids;
6009 5997
6010 err = stac92xx_parse_auto_config(codec, 0x21, 0); 5998 err = stac92xx_parse_auto_config(codec);
6011 if (!err) { 5999 if (!err) {
6012 if (spec->board_config < 0) { 6000 if (spec->board_config < 0) {
6013 printk(KERN_WARNING "hda_codec: No auto-config is " 6001 printk(KERN_WARNING "hda_codec: No auto-config is "
@@ -6116,7 +6104,7 @@ static int patch_stac922x(struct hda_codec *codec)
6116 6104
6117 spec->multiout.dac_nids = spec->dac_nids; 6105 spec->multiout.dac_nids = spec->dac_nids;
6118 6106
6119 err = stac92xx_parse_auto_config(codec, 0x08, 0x09); 6107 err = stac92xx_parse_auto_config(codec);
6120 if (!err) { 6108 if (!err) {
6121 if (spec->board_config < 0) { 6109 if (spec->board_config < 0) {
6122 printk(KERN_WARNING "hda_codec: No auto-config is " 6110 printk(KERN_WARNING "hda_codec: No auto-config is "
@@ -6241,7 +6229,7 @@ static int patch_stac927x(struct hda_codec *codec)
6241 spec->aloopback_shift = 0; 6229 spec->aloopback_shift = 0;
6242 spec->eapd_switch = 1; 6230 spec->eapd_switch = 1;
6243 6231
6244 err = stac92xx_parse_auto_config(codec, 0x1e, 0x20); 6232 err = stac92xx_parse_auto_config(codec);
6245 if (!err) { 6233 if (!err) {
6246 if (spec->board_config < 0) { 6234 if (spec->board_config < 0) {
6247 printk(KERN_WARNING "hda_codec: No auto-config is " 6235 printk(KERN_WARNING "hda_codec: No auto-config is "
@@ -6366,7 +6354,7 @@ static int patch_stac9205(struct hda_codec *codec)
6366 break; 6354 break;
6367 } 6355 }
6368 6356
6369 err = stac92xx_parse_auto_config(codec, 0x1f, 0x20); 6357 err = stac92xx_parse_auto_config(codec);
6370 if (!err) { 6358 if (!err) {
6371 if (spec->board_config < 0) { 6359 if (spec->board_config < 0) {
6372 printk(KERN_WARNING "hda_codec: No auto-config is " 6360 printk(KERN_WARNING "hda_codec: No auto-config is "
@@ -6471,7 +6459,7 @@ static int patch_stac9872(struct hda_codec *codec)
6471 spec->capvols = stac9872_capvols; 6459 spec->capvols = stac9872_capvols;
6472 spec->capsws = stac9872_capsws; 6460 spec->capsws = stac9872_capsws;
6473 6461
6474 err = stac92xx_parse_auto_config(codec, 0x10, 0x12); 6462 err = stac92xx_parse_auto_config(codec);
6475 if (err < 0) { 6463 if (err < 0) {
6476 stac92xx_free(codec); 6464 stac92xx_free(codec);
6477 return -EINVAL; 6465 return -EINVAL;
@@ -6571,10 +6559,23 @@ static const struct hda_codec_preset snd_hda_preset_sigmatel[] = {
6571 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx }, 6559 { .id = 0x111d76cc, .name = "92HD89F3", .patch = patch_stac92hd73xx },
6572 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx }, 6560 { .id = 0x111d76cd, .name = "92HD89F2", .patch = patch_stac92hd73xx },
6573 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx }, 6561 { .id = 0x111d76ce, .name = "92HD89F1", .patch = patch_stac92hd73xx },
6562 { .id = 0x111d76df, .name = "92HD93BXX", .patch = patch_stac92hd83xxx},
6574 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx}, 6563 { .id = 0x111d76e0, .name = "92HD91BXX", .patch = patch_stac92hd83xxx},
6575 { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx}, 6564 { .id = 0x111d76e3, .name = "92HD98BXX", .patch = patch_stac92hd83xxx},
6576 { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx}, 6565 { .id = 0x111d76e5, .name = "92HD99BXX", .patch = patch_stac92hd83xxx},
6577 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx}, 6566 { .id = 0x111d76e7, .name = "92HD90BXX", .patch = patch_stac92hd83xxx},
6567 { .id = 0x111d76e8, .name = "92HD66B1X5", .patch = patch_stac92hd83xxx},
6568 { .id = 0x111d76e9, .name = "92HD66B2X5", .patch = patch_stac92hd83xxx},
6569 { .id = 0x111d76ea, .name = "92HD66B3X5", .patch = patch_stac92hd83xxx},
6570 { .id = 0x111d76eb, .name = "92HD66C1X5", .patch = patch_stac92hd83xxx},
6571 { .id = 0x111d76ec, .name = "92HD66C2X5", .patch = patch_stac92hd83xxx},
6572 { .id = 0x111d76ed, .name = "92HD66C3X5", .patch = patch_stac92hd83xxx},
6573 { .id = 0x111d76ee, .name = "92HD66B1X3", .patch = patch_stac92hd83xxx},
6574 { .id = 0x111d76ef, .name = "92HD66B2X3", .patch = patch_stac92hd83xxx},
6575 { .id = 0x111d76f0, .name = "92HD66B3X3", .patch = patch_stac92hd83xxx},
6576 { .id = 0x111d76f1, .name = "92HD66C1X3", .patch = patch_stac92hd83xxx},
6577 { .id = 0x111d76f2, .name = "92HD66C2X3", .patch = patch_stac92hd83xxx},
6578 { .id = 0x111d76f3, .name = "92HD66C3/65", .patch = patch_stac92hd83xxx},
6578 {} /* terminator */ 6579 {} /* terminator */
6579}; 6580};
6580 6581
diff --git a/sound/pci/hda/patch_via.c b/sound/pci/hda/patch_via.c
index 84d8798bf33a..0b020a93a8ed 100644
--- a/sound/pci/hda/patch_via.c
+++ b/sound/pci/hda/patch_via.c
@@ -1506,39 +1506,49 @@ static int via_build_pcms(struct hda_codec *codec)
1506 struct via_spec *spec = codec->spec; 1506 struct via_spec *spec = codec->spec;
1507 struct hda_pcm *info = spec->pcm_rec; 1507 struct hda_pcm *info = spec->pcm_rec;
1508 1508
1509 codec->num_pcms = 1; 1509 codec->num_pcms = 0;
1510 codec->pcm_info = info; 1510 codec->pcm_info = info;
1511 1511
1512 snprintf(spec->stream_name_analog, sizeof(spec->stream_name_analog), 1512 if (spec->multiout.num_dacs || spec->num_adc_nids) {
1513 "%s Analog", codec->chip_name); 1513 snprintf(spec->stream_name_analog,
1514 info->name = spec->stream_name_analog; 1514 sizeof(spec->stream_name_analog),
1515 "%s Analog", codec->chip_name);
1516 info->name = spec->stream_name_analog;
1515 1517
1516 if (!spec->stream_analog_playback) 1518 if (spec->multiout.num_dacs) {
1517 spec->stream_analog_playback = &via_pcm_analog_playback; 1519 if (!spec->stream_analog_playback)
1518 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = 1520 spec->stream_analog_playback =
1519 *spec->stream_analog_playback; 1521 &via_pcm_analog_playback;
1520 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 1522 info->stream[SNDRV_PCM_STREAM_PLAYBACK] =
1521 spec->multiout.dac_nids[0]; 1523 *spec->stream_analog_playback;
1522 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max = 1524 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1523 spec->multiout.max_channels; 1525 spec->multiout.dac_nids[0];
1526 info->stream[SNDRV_PCM_STREAM_PLAYBACK].channels_max =
1527 spec->multiout.max_channels;
1528 }
1524 1529
1525 if (!spec->stream_analog_capture) { 1530 if (!spec->stream_analog_capture) {
1526 if (spec->dyn_adc_switch) 1531 if (spec->dyn_adc_switch)
1527 spec->stream_analog_capture = 1532 spec->stream_analog_capture =
1528 &via_pcm_dyn_adc_analog_capture; 1533 &via_pcm_dyn_adc_analog_capture;
1529 else 1534 else
1530 spec->stream_analog_capture = &via_pcm_analog_capture; 1535 spec->stream_analog_capture =
1536 &via_pcm_analog_capture;
1537 }
1538 if (spec->num_adc_nids) {
1539 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1540 *spec->stream_analog_capture;
1541 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1542 spec->adc_nids[0];
1543 if (!spec->dyn_adc_switch)
1544 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1545 spec->num_adc_nids;
1546 }
1547 codec->num_pcms++;
1548 info++;
1531 } 1549 }
1532 info->stream[SNDRV_PCM_STREAM_CAPTURE] =
1533 *spec->stream_analog_capture;
1534 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = spec->adc_nids[0];
1535 if (!spec->dyn_adc_switch)
1536 info->stream[SNDRV_PCM_STREAM_CAPTURE].substreams =
1537 spec->num_adc_nids;
1538 1550
1539 if (spec->multiout.dig_out_nid || spec->dig_in_nid) { 1551 if (spec->multiout.dig_out_nid || spec->dig_in_nid) {
1540 codec->num_pcms++;
1541 info++;
1542 snprintf(spec->stream_name_digital, 1552 snprintf(spec->stream_name_digital,
1543 sizeof(spec->stream_name_digital), 1553 sizeof(spec->stream_name_digital),
1544 "%s Digital", codec->chip_name); 1554 "%s Digital", codec->chip_name);
@@ -1562,17 +1572,19 @@ static int via_build_pcms(struct hda_codec *codec)
1562 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid = 1572 info->stream[SNDRV_PCM_STREAM_CAPTURE].nid =
1563 spec->dig_in_nid; 1573 spec->dig_in_nid;
1564 } 1574 }
1575 codec->num_pcms++;
1576 info++;
1565 } 1577 }
1566 1578
1567 if (spec->hp_dac_nid) { 1579 if (spec->hp_dac_nid) {
1568 codec->num_pcms++;
1569 info++;
1570 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp), 1580 snprintf(spec->stream_name_hp, sizeof(spec->stream_name_hp),
1571 "%s HP", codec->chip_name); 1581 "%s HP", codec->chip_name);
1572 info->name = spec->stream_name_hp; 1582 info->name = spec->stream_name_hp;
1573 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback; 1583 info->stream[SNDRV_PCM_STREAM_PLAYBACK] = via_pcm_hp_playback;
1574 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid = 1584 info->stream[SNDRV_PCM_STREAM_PLAYBACK].nid =
1575 spec->hp_dac_nid; 1585 spec->hp_dac_nid;
1586 codec->num_pcms++;
1587 info++;
1576 } 1588 }
1577 return 0; 1589 return 0;
1578} 1590}
@@ -2084,7 +2096,7 @@ static int via_auto_create_speaker_ctls(struct hda_codec *codec)
2084 struct via_spec *spec = codec->spec; 2096 struct via_spec *spec = codec->spec;
2085 struct nid_path *path; 2097 struct nid_path *path;
2086 bool check_dac; 2098 bool check_dac;
2087 hda_nid_t pin, dac; 2099 hda_nid_t pin, dac = 0;
2088 int err; 2100 int err;
2089 2101
2090 pin = spec->autocfg.speaker_pins[0]; 2102 pin = spec->autocfg.speaker_pins[0];
@@ -3688,13 +3700,8 @@ static const struct hda_verb vt1812_init_verbs[] = {
3688static void set_widgets_power_state_vt1812(struct hda_codec *codec) 3700static void set_widgets_power_state_vt1812(struct hda_codec *codec)
3689{ 3701{
3690 struct via_spec *spec = codec->spec; 3702 struct via_spec *spec = codec->spec;
3691 int imux_is_smixer =
3692 snd_hda_codec_read(codec, 0x13, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 3;
3693 unsigned int parm; 3703 unsigned int parm;
3694 unsigned int present; 3704 unsigned int present;
3695 /* MUX10 (1eh) = stereo mixer */
3696 imux_is_smixer =
3697 snd_hda_codec_read(codec, 0x1e, 0, AC_VERB_GET_CONNECT_SEL, 0x00) == 5;
3698 /* inputs */ 3705 /* inputs */
3699 /* PW 5/6/7 (29h/2ah/2bh) */ 3706 /* PW 5/6/7 (29h/2ah/2bh) */
3700 parm = AC_PWRST_D3; 3707 parm = AC_PWRST_D3;
diff --git a/sound/pci/ice1712/ice1712.c b/sound/pci/ice1712/ice1712.c
index 0ccc0eb75775..8531b983f3af 100644
--- a/sound/pci/ice1712/ice1712.c
+++ b/sound/pci/ice1712/ice1712.c
@@ -2748,8 +2748,9 @@ static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2748 if (!c->no_mpu401) { 2748 if (!c->no_mpu401) {
2749 err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712, 2749 err = snd_mpu401_uart_new(card, 0, MPU401_HW_ICE1712,
2750 ICEREG(ice, MPU1_CTRL), 2750 ICEREG(ice, MPU1_CTRL),
2751 (c->mpu401_1_info_flags | MPU401_INFO_INTEGRATED), 2751 c->mpu401_1_info_flags |
2752 ice->irq, 0, &ice->rmidi[0]); 2752 MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
2753 -1, &ice->rmidi[0]);
2753 if (err < 0) { 2754 if (err < 0) {
2754 snd_card_free(card); 2755 snd_card_free(card);
2755 return err; 2756 return err;
@@ -2764,8 +2765,9 @@ static int __devinit snd_ice1712_probe(struct pci_dev *pci,
2764 /* 2nd port used */ 2765 /* 2nd port used */
2765 err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712, 2766 err = snd_mpu401_uart_new(card, 1, MPU401_HW_ICE1712,
2766 ICEREG(ice, MPU2_CTRL), 2767 ICEREG(ice, MPU2_CTRL),
2767 (c->mpu401_2_info_flags | MPU401_INFO_INTEGRATED), 2768 c->mpu401_2_info_flags |
2768 ice->irq, 0, &ice->rmidi[1]); 2769 MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
2770 -1, &ice->rmidi[1]);
2769 2771
2770 if (err < 0) { 2772 if (err < 0) {
2771 snd_card_free(card); 2773 snd_card_free(card);
diff --git a/sound/pci/intel8x0.c b/sound/pci/intel8x0.c
index 6a5b387b97fd..45b2055f5a76 100644
--- a/sound/pci/intel8x0.c
+++ b/sound/pci/intel8x0.c
@@ -42,6 +42,12 @@
42#include <asm/pgtable.h> 42#include <asm/pgtable.h>
43#include <asm/cacheflush.h> 43#include <asm/cacheflush.h>
44 44
45#ifdef CONFIG_KVM_GUEST
46#include <linux/kvm_para.h>
47#else
48#define kvm_para_available() (0)
49#endif
50
45MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>"); 51MODULE_AUTHOR("Jaroslav Kysela <perex@perex.cz>");
46MODULE_DESCRIPTION("Intel 82801AA,82901AB,i810,i820,i830,i840,i845,MX440; SiS 7012; Ali 5455"); 52MODULE_DESCRIPTION("Intel 82801AA,82901AB,i810,i820,i830,i840,i845,MX440; SiS 7012; Ali 5455");
47MODULE_LICENSE("GPL"); 53MODULE_LICENSE("GPL");
@@ -77,6 +83,7 @@ static int buggy_semaphore;
77static int buggy_irq = -1; /* auto-check */ 83static int buggy_irq = -1; /* auto-check */
78static int xbox; 84static int xbox;
79static int spdif_aclink = -1; 85static int spdif_aclink = -1;
86static int inside_vm = -1;
80 87
81module_param(index, int, 0444); 88module_param(index, int, 0444);
82MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard."); 89MODULE_PARM_DESC(index, "Index value for Intel i8x0 soundcard.");
@@ -94,6 +101,8 @@ module_param(xbox, bool, 0444);
94MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection."); 101MODULE_PARM_DESC(xbox, "Set to 1 for Xbox, if you have problems with the AC'97 codec detection.");
95module_param(spdif_aclink, int, 0444); 102module_param(spdif_aclink, int, 0444);
96MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link."); 103MODULE_PARM_DESC(spdif_aclink, "S/PDIF over AC-link.");
104module_param(inside_vm, bool, 0444);
105MODULE_PARM_DESC(inside_vm, "KVM/Parallels optimization.");
97 106
98/* just for backward compatibility */ 107/* just for backward compatibility */
99static int enable; 108static int enable;
@@ -400,6 +409,7 @@ struct intel8x0 {
400 unsigned buggy_irq: 1; /* workaround for buggy mobos */ 409 unsigned buggy_irq: 1; /* workaround for buggy mobos */
401 unsigned xbox: 1; /* workaround for Xbox AC'97 detection */ 410 unsigned xbox: 1; /* workaround for Xbox AC'97 detection */
402 unsigned buggy_semaphore: 1; /* workaround for buggy codec semaphore */ 411 unsigned buggy_semaphore: 1; /* workaround for buggy codec semaphore */
412 unsigned inside_vm: 1; /* enable VM optimization */
403 413
404 int spdif_idx; /* SPDIF BAR index; *_SPBAR or -1 if use PCMOUT */ 414 int spdif_idx; /* SPDIF BAR index; *_SPBAR or -1 if use PCMOUT */
405 unsigned int sdm_saved; /* SDM reg value */ 415 unsigned int sdm_saved; /* SDM reg value */
@@ -1065,8 +1075,11 @@ static snd_pcm_uframes_t snd_intel8x0_pcm_pointer(struct snd_pcm_substream *subs
1065 udelay(10); 1075 udelay(10);
1066 continue; 1076 continue;
1067 } 1077 }
1068 if (civ == igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV) && 1078 if (civ != igetbyte(chip, ichdev->reg_offset + ICH_REG_OFF_CIV))
1069 ptr1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb)) 1079 continue;
1080 if (chip->inside_vm)
1081 break;
1082 if (ptr1 == igetword(chip, ichdev->reg_offset + ichdev->roff_picb))
1070 break; 1083 break;
1071 } while (timeout--); 1084 } while (timeout--);
1072 ptr = ichdev->last_pos; 1085 ptr = ichdev->last_pos;
@@ -2984,6 +2997,10 @@ static int __devinit snd_intel8x0_create(struct snd_card *card,
2984 if (xbox) 2997 if (xbox)
2985 chip->xbox = 1; 2998 chip->xbox = 1;
2986 2999
3000 chip->inside_vm = inside_vm;
3001 if (inside_vm)
3002 printk(KERN_INFO "intel8x0: enable KVM optimization\n");
3003
2987 if (pci->vendor == PCI_VENDOR_ID_INTEL && 3004 if (pci->vendor == PCI_VENDOR_ID_INTEL &&
2988 pci->device == PCI_DEVICE_ID_INTEL_440MX) 3005 pci->device == PCI_DEVICE_ID_INTEL_440MX)
2989 chip->fix_nocache = 1; /* enable workaround */ 3006 chip->fix_nocache = 1; /* enable workaround */
@@ -3226,6 +3243,14 @@ static int __devinit snd_intel8x0_probe(struct pci_dev *pci,
3226 buggy_irq = 0; 3243 buggy_irq = 0;
3227 } 3244 }
3228 3245
3246 if (inside_vm < 0) {
3247 /* detect KVM and Parallels virtual environments */
3248 inside_vm = kvm_para_available();
3249#if defined(__i386__) || defined(__x86_64__)
3250 inside_vm = inside_vm || boot_cpu_has(X86_FEATURE_HYPERVISOR);
3251#endif
3252 }
3253
3229 if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data, 3254 if ((err = snd_intel8x0_create(card, pci, pci_id->driver_data,
3230 &chip)) < 0) { 3255 &chip)) < 0) {
3231 snd_card_free(card); 3256 snd_card_free(card);
diff --git a/sound/pci/maestro3.c b/sound/pci/maestro3.c
index 0378126e6272..2fd4bf2d6653 100644
--- a/sound/pci/maestro3.c
+++ b/sound/pci/maestro3.c
@@ -2820,8 +2820,8 @@ snd_m3_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2820 /* TODO enable MIDI IRQ and I/O */ 2820 /* TODO enable MIDI IRQ and I/O */
2821 err = snd_mpu401_uart_new(chip->card, 0, MPU401_HW_MPU401, 2821 err = snd_mpu401_uart_new(chip->card, 0, MPU401_HW_MPU401,
2822 chip->iobase + MPU401_DATA_PORT, 2822 chip->iobase + MPU401_DATA_PORT,
2823 MPU401_INFO_INTEGRATED, 2823 MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK,
2824 chip->irq, 0, &chip->rmidi); 2824 -1, &chip->rmidi);
2825 if (err < 0) 2825 if (err < 0)
2826 printk(KERN_WARNING "maestro3: no MIDI support.\n"); 2826 printk(KERN_WARNING "maestro3: no MIDI support.\n");
2827#endif 2827#endif
diff --git a/sound/pci/oxygen/oxygen_lib.c b/sound/pci/oxygen/oxygen_lib.c
index 82311fcb86f6..53e5508abcbf 100644
--- a/sound/pci/oxygen/oxygen_lib.c
+++ b/sound/pci/oxygen/oxygen_lib.c
@@ -678,15 +678,15 @@ int oxygen_pci_probe(struct pci_dev *pci, int index, char *id,
678 goto err_card; 678 goto err_card;
679 679
680 if (chip->model.device_config & (MIDI_OUTPUT | MIDI_INPUT)) { 680 if (chip->model.device_config & (MIDI_OUTPUT | MIDI_INPUT)) {
681 unsigned int info_flags = MPU401_INFO_INTEGRATED; 681 unsigned int info_flags =
682 MPU401_INFO_INTEGRATED | MPU401_INFO_IRQ_HOOK;
682 if (chip->model.device_config & MIDI_OUTPUT) 683 if (chip->model.device_config & MIDI_OUTPUT)
683 info_flags |= MPU401_INFO_OUTPUT; 684 info_flags |= MPU401_INFO_OUTPUT;
684 if (chip->model.device_config & MIDI_INPUT) 685 if (chip->model.device_config & MIDI_INPUT)
685 info_flags |= MPU401_INFO_INPUT; 686 info_flags |= MPU401_INFO_INPUT;
686 err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI, 687 err = snd_mpu401_uart_new(card, 0, MPU401_HW_CMIPCI,
687 chip->addr + OXYGEN_MPU401, 688 chip->addr + OXYGEN_MPU401,
688 info_flags, 0, 0, 689 info_flags, -1, &chip->midi);
689 &chip->midi);
690 if (err < 0) 690 if (err < 0)
691 goto err_card; 691 goto err_card;
692 } 692 }
diff --git a/sound/pci/oxygen/xonar_pcm179x.c b/sound/pci/oxygen/xonar_pcm179x.c
index 32d096c98f5b..8433aa7c3d75 100644
--- a/sound/pci/oxygen/xonar_pcm179x.c
+++ b/sound/pci/oxygen/xonar_pcm179x.c
@@ -1074,6 +1074,7 @@ static const struct oxygen_model model_xonar_st = {
1074 .device_config = PLAYBACK_0_TO_I2S | 1074 .device_config = PLAYBACK_0_TO_I2S |
1075 PLAYBACK_1_TO_SPDIF | 1075 PLAYBACK_1_TO_SPDIF |
1076 CAPTURE_0_FROM_I2S_2 | 1076 CAPTURE_0_FROM_I2S_2 |
1077 CAPTURE_1_FROM_SPDIF |
1077 AC97_FMIC_SWITCH, 1078 AC97_FMIC_SWITCH,
1078 .dac_channels_pcm = 2, 1079 .dac_channels_pcm = 2,
1079 .dac_channels_mixer = 2, 1080 .dac_channels_mixer = 2,
diff --git a/sound/pci/riptide/riptide.c b/sound/pci/riptide/riptide.c
index e34ae14908b3..88cc776aa38b 100644
--- a/sound/pci/riptide/riptide.c
+++ b/sound/pci/riptide/riptide.c
@@ -2109,7 +2109,7 @@ snd_card_riptide_probe(struct pci_dev *pci, const struct pci_device_id *pci_id)
2109 val = mpu_port[dev]; 2109 val = mpu_port[dev];
2110 pci_write_config_word(chip->pci, PCI_EXT_MPU_Base, val); 2110 pci_write_config_word(chip->pci, PCI_EXT_MPU_Base, val);
2111 err = snd_mpu401_uart_new(card, 0, MPU401_HW_RIPTIDE, 2111 err = snd_mpu401_uart_new(card, 0, MPU401_HW_RIPTIDE,
2112 val, 0, chip->irq, 0, 2112 val, MPU401_INFO_IRQ_HOOK, -1,
2113 &chip->rmidi); 2113 &chip->rmidi);
2114 if (err < 0) 2114 if (err < 0)
2115 snd_printk(KERN_WARNING 2115 snd_printk(KERN_WARNING
diff --git a/sound/pci/rme9652/hdsp.c b/sound/pci/rme9652/hdsp.c
index 1c6d1e1c27c1..f74220292254 100644
--- a/sound/pci/rme9652/hdsp.c
+++ b/sound/pci/rme9652/hdsp.c
@@ -151,7 +151,7 @@ MODULE_FIRMWARE("digiface_firmware_rev11.bin");
151#define HDSP_PROGRAM 0x020 151#define HDSP_PROGRAM 0x020
152#define HDSP_CONFIG_MODE_0 0x040 152#define HDSP_CONFIG_MODE_0 0x040
153#define HDSP_CONFIG_MODE_1 0x080 153#define HDSP_CONFIG_MODE_1 0x080
154#define HDSP_VERSION_BIT 0x100 154#define HDSP_VERSION_BIT (0x100 | HDSP_S_LOAD)
155#define HDSP_BIGENDIAN_MODE 0x200 155#define HDSP_BIGENDIAN_MODE 0x200
156#define HDSP_RD_MULTIPLE 0x400 156#define HDSP_RD_MULTIPLE 0x400
157#define HDSP_9652_ENABLE_MIXER 0x800 157#define HDSP_9652_ENABLE_MIXER 0x800
diff --git a/sound/pci/rme9652/hdspm.c b/sound/pci/rme9652/hdspm.c
index 6edc67ced905..15a6c3b9bc9a 100644
--- a/sound/pci/rme9652/hdspm.c
+++ b/sound/pci/rme9652/hdspm.c
@@ -520,16 +520,9 @@ MODULE_SUPPORTED_DEVICE("{{RME HDSPM-MADI}}");
520#define HDSPM_DMA_AREA_BYTES (HDSPM_MAX_CHANNELS * HDSPM_CHANNEL_BUFFER_BYTES) 520#define HDSPM_DMA_AREA_BYTES (HDSPM_MAX_CHANNELS * HDSPM_CHANNEL_BUFFER_BYTES)
521#define HDSPM_DMA_AREA_KILOBYTES (HDSPM_DMA_AREA_BYTES/1024) 521#define HDSPM_DMA_AREA_KILOBYTES (HDSPM_DMA_AREA_BYTES/1024)
522 522
523/* revisions >= 230 indicate AES32 card */
524#define HDSPM_MADI_ANCIENT_REV 204
525#define HDSPM_MADI_OLD_REV 207
526#define HDSPM_MADI_REV 210
527#define HDSPM_RAYDAT_REV 211 523#define HDSPM_RAYDAT_REV 211
528#define HDSPM_AIO_REV 212 524#define HDSPM_AIO_REV 212
529#define HDSPM_MADIFACE_REV 213 525#define HDSPM_MADIFACE_REV 213
530#define HDSPM_AES_REV 240
531#define HDSPM_AES32_REV 234
532#define HDSPM_AES32_OLD_REV 233
533 526
534/* speed factor modes */ 527/* speed factor modes */
535#define HDSPM_SPEED_SINGLE 0 528#define HDSPM_SPEED_SINGLE 0
@@ -1241,10 +1234,30 @@ static int hdspm_external_sample_rate(struct hdspm *hdspm)
1241 return rate; 1234 return rate;
1242} 1235}
1243 1236
1237/* return latency in samples per period */
1238static int hdspm_get_latency(struct hdspm *hdspm)
1239{
1240 int n;
1241
1242 n = hdspm_decode_latency(hdspm->control_register);
1243
1244 /* Special case for new RME cards with 32 samples period size.
1245 * The three latency bits in the control register
1246 * (HDSP_LatencyMask) encode latency values of 64 samples as
1247 * 0, 128 samples as 1 ... 4096 samples as 6. For old cards, 7
1248 * denotes 8192 samples, but on new cards like RayDAT or AIO,
1249 * it corresponds to 32 samples.
1250 */
1251 if ((7 == n) && (RayDAT == hdspm->io_type || AIO == hdspm->io_type))
1252 n = -1;
1253
1254 return 1 << (n + 6);
1255}
1256
1244/* Latency function */ 1257/* Latency function */
1245static inline void hdspm_compute_period_size(struct hdspm *hdspm) 1258static inline void hdspm_compute_period_size(struct hdspm *hdspm)
1246{ 1259{
1247 hdspm->period_bytes = 1 << ((hdspm_decode_latency(hdspm->control_register) + 8)); 1260 hdspm->period_bytes = 4 * hdspm_get_latency(hdspm);
1248} 1261}
1249 1262
1250 1263
@@ -1303,12 +1316,27 @@ static int hdspm_set_interrupt_interval(struct hdspm *s, unsigned int frames)
1303 1316
1304 spin_lock_irq(&s->lock); 1317 spin_lock_irq(&s->lock);
1305 1318
1306 frames >>= 7; 1319 if (32 == frames) {
1307 n = 0; 1320 /* Special case for new RME cards like RayDAT/AIO which
1308 while (frames) { 1321 * support period sizes of 32 samples. Since latency is
1309 n++; 1322 * encoded in the three bits of HDSP_LatencyMask, we can only
1310 frames >>= 1; 1323 * have values from 0 .. 7. While 0 still means 64 samples and
1324 * 6 represents 4096 samples on all cards, 7 represents 8192
1325 * on older cards and 32 samples on new cards.
1326 *
1327 * In other words, period size in samples is calculated by
1328 * 2^(n+6) with n ranging from 0 .. 7.
1329 */
1330 n = 7;
1331 } else {
1332 frames >>= 7;
1333 n = 0;
1334 while (frames) {
1335 n++;
1336 frames >>= 1;
1337 }
1311 } 1338 }
1339
1312 s->control_register &= ~HDSPM_LatencyMask; 1340 s->control_register &= ~HDSPM_LatencyMask;
1313 s->control_register |= hdspm_encode_latency(n); 1341 s->control_register |= hdspm_encode_latency(n);
1314 1342
@@ -1339,6 +1367,10 @@ static u64 hdspm_calc_dds_value(struct hdspm *hdspm, u64 period)
1339 break; 1367 break;
1340 case MADIface: 1368 case MADIface:
1341 freq_const = 131072000000000ULL; 1369 freq_const = 131072000000000ULL;
1370 break;
1371 default:
1372 snd_BUG();
1373 return 0;
1342 } 1374 }
1343 1375
1344 return div_u64(freq_const, period); 1376 return div_u64(freq_const, period);
@@ -1356,16 +1388,19 @@ static void hdspm_set_dds_value(struct hdspm *hdspm, int rate)
1356 1388
1357 switch (hdspm->io_type) { 1389 switch (hdspm->io_type) {
1358 case MADIface: 1390 case MADIface:
1359 n = 131072000000000ULL; /* 125 MHz */ 1391 n = 131072000000000ULL; /* 125 MHz */
1360 break; 1392 break;
1361 case MADI: 1393 case MADI:
1362 case AES32: 1394 case AES32:
1363 n = 110069313433624ULL; /* 105 MHz */ 1395 n = 110069313433624ULL; /* 105 MHz */
1364 break; 1396 break;
1365 case RayDAT: 1397 case RayDAT:
1366 case AIO: 1398 case AIO:
1367 n = 104857600000000ULL; /* 100 MHz */ 1399 n = 104857600000000ULL; /* 100 MHz */
1368 break; 1400 break;
1401 default:
1402 snd_BUG();
1403 return;
1369 } 1404 }
1370 1405
1371 n = div_u64(n, rate); 1406 n = div_u64(n, rate);
@@ -4794,8 +4829,7 @@ snd_hdspm_proc_read_madi(struct snd_info_entry * entry,
4794 4829
4795 snd_iprintf(buffer, "--- Settings ---\n"); 4830 snd_iprintf(buffer, "--- Settings ---\n");
4796 4831
4797 x = 1 << (6 + hdspm_decode_latency(hdspm->control_register & 4832 x = hdspm_get_latency(hdspm);
4798 HDSPM_LatencyMask));
4799 4833
4800 snd_iprintf(buffer, 4834 snd_iprintf(buffer,
4801 "Size (Latency): %d samples (2 periods of %lu bytes)\n", 4835 "Size (Latency): %d samples (2 periods of %lu bytes)\n",
@@ -4958,8 +4992,7 @@ snd_hdspm_proc_read_aes32(struct snd_info_entry * entry,
4958 4992
4959 snd_iprintf(buffer, "--- Settings ---\n"); 4993 snd_iprintf(buffer, "--- Settings ---\n");
4960 4994
4961 x = 1 << (6 + hdspm_decode_latency(hdspm->control_register & 4995 x = hdspm_get_latency(hdspm);
4962 HDSPM_LatencyMask));
4963 4996
4964 snd_iprintf(buffer, 4997 snd_iprintf(buffer,
4965 "Size (Latency): %d samples (2 periods of %lu bytes)\n", 4998 "Size (Latency): %d samples (2 periods of %lu bytes)\n",
@@ -5665,19 +5698,6 @@ static int snd_hdspm_prepare(struct snd_pcm_substream *substream)
5665 return 0; 5698 return 0;
5666} 5699}
5667 5700
5668static unsigned int period_sizes_old[] = {
5669 64, 128, 256, 512, 1024, 2048, 4096
5670};
5671
5672static unsigned int period_sizes_new[] = {
5673 32, 64, 128, 256, 512, 1024, 2048, 4096
5674};
5675
5676/* RayDAT and AIO always have a buffer of 16384 samples per channel */
5677static unsigned int raydat_aio_buffer_sizes[] = {
5678 16384
5679};
5680
5681static struct snd_pcm_hardware snd_hdspm_playback_subinfo = { 5701static struct snd_pcm_hardware snd_hdspm_playback_subinfo = {
5682 .info = (SNDRV_PCM_INFO_MMAP | 5702 .info = (SNDRV_PCM_INFO_MMAP |
5683 SNDRV_PCM_INFO_MMAP_VALID | 5703 SNDRV_PCM_INFO_MMAP_VALID |
@@ -5696,8 +5716,8 @@ static struct snd_pcm_hardware snd_hdspm_playback_subinfo = {
5696 .channels_max = HDSPM_MAX_CHANNELS, 5716 .channels_max = HDSPM_MAX_CHANNELS,
5697 .buffer_bytes_max = 5717 .buffer_bytes_max =
5698 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, 5718 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
5699 .period_bytes_min = (64 * 4), 5719 .period_bytes_min = (32 * 4),
5700 .period_bytes_max = (4096 * 4) * HDSPM_MAX_CHANNELS, 5720 .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
5701 .periods_min = 2, 5721 .periods_min = 2,
5702 .periods_max = 512, 5722 .periods_max = 512,
5703 .fifo_size = 0 5723 .fifo_size = 0
@@ -5721,31 +5741,13 @@ static struct snd_pcm_hardware snd_hdspm_capture_subinfo = {
5721 .channels_max = HDSPM_MAX_CHANNELS, 5741 .channels_max = HDSPM_MAX_CHANNELS,
5722 .buffer_bytes_max = 5742 .buffer_bytes_max =
5723 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS, 5743 HDSPM_CHANNEL_BUFFER_BYTES * HDSPM_MAX_CHANNELS,
5724 .period_bytes_min = (64 * 4), 5744 .period_bytes_min = (32 * 4),
5725 .period_bytes_max = (4096 * 4) * HDSPM_MAX_CHANNELS, 5745 .period_bytes_max = (8192 * 4) * HDSPM_MAX_CHANNELS,
5726 .periods_min = 2, 5746 .periods_min = 2,
5727 .periods_max = 512, 5747 .periods_max = 512,
5728 .fifo_size = 0 5748 .fifo_size = 0
5729}; 5749};
5730 5750
5731static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_old = {
5732 .count = ARRAY_SIZE(period_sizes_old),
5733 .list = period_sizes_old,
5734 .mask = 0
5735};
5736
5737static struct snd_pcm_hw_constraint_list hw_constraints_period_sizes_new = {
5738 .count = ARRAY_SIZE(period_sizes_new),
5739 .list = period_sizes_new,
5740 .mask = 0
5741};
5742
5743static struct snd_pcm_hw_constraint_list hw_constraints_raydat_io_buffer = {
5744 .count = ARRAY_SIZE(raydat_aio_buffer_sizes),
5745 .list = raydat_aio_buffer_sizes,
5746 .mask = 0
5747};
5748
5749static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params, 5751static int snd_hdspm_hw_rule_in_channels_rate(struct snd_pcm_hw_params *params,
5750 struct snd_pcm_hw_rule *rule) 5752 struct snd_pcm_hw_rule *rule)
5751{ 5753{
@@ -5946,26 +5948,29 @@ static int snd_hdspm_playback_open(struct snd_pcm_substream *substream)
5946 spin_unlock_irq(&hdspm->lock); 5948 spin_unlock_irq(&hdspm->lock);
5947 5949
5948 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); 5950 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
5951 snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
5949 5952
5950 switch (hdspm->io_type) { 5953 switch (hdspm->io_type) {
5951 case AIO: 5954 case AIO:
5952 case RayDAT: 5955 case RayDAT:
5953 snd_pcm_hw_constraint_list(runtime, 0, 5956 snd_pcm_hw_constraint_minmax(runtime,
5954 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 5957 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
5955 &hw_constraints_period_sizes_new); 5958 32, 4096);
5956 snd_pcm_hw_constraint_list(runtime, 0, 5959 /* RayDAT & AIO have a fixed buffer of 16384 samples per channel */
5957 SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 5960 snd_pcm_hw_constraint_minmax(runtime,
5958 &hw_constraints_raydat_io_buffer); 5961 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
5959 5962 16384, 16384);
5960 break; 5963 break;
5961 5964
5962 default: 5965 default:
5963 snd_pcm_hw_constraint_list(runtime, 0, 5966 snd_pcm_hw_constraint_minmax(runtime,
5964 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 5967 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
5965 &hw_constraints_period_sizes_old); 5968 64, 8192);
5969 break;
5966 } 5970 }
5967 5971
5968 if (AES32 == hdspm->io_type) { 5972 if (AES32 == hdspm->io_type) {
5973 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
5969 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 5974 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
5970 &hdspm_hw_constraints_aes32_sample_rates); 5975 &hdspm_hw_constraints_aes32_sample_rates);
5971 } else { 5976 } else {
@@ -6018,24 +6023,28 @@ static int snd_hdspm_capture_open(struct snd_pcm_substream *substream)
6018 spin_unlock_irq(&hdspm->lock); 6023 spin_unlock_irq(&hdspm->lock);
6019 6024
6020 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24); 6025 snd_pcm_hw_constraint_msbits(runtime, 0, 32, 24);
6026 snd_pcm_hw_constraint_pow2(runtime, 0, SNDRV_PCM_HW_PARAM_PERIOD_SIZE);
6027
6021 switch (hdspm->io_type) { 6028 switch (hdspm->io_type) {
6022 case AIO: 6029 case AIO:
6023 case RayDAT: 6030 case RayDAT:
6024 snd_pcm_hw_constraint_list(runtime, 0, 6031 snd_pcm_hw_constraint_minmax(runtime,
6025 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 6032 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6026 &hw_constraints_period_sizes_new); 6033 32, 4096);
6027 snd_pcm_hw_constraint_list(runtime, 0, 6034 snd_pcm_hw_constraint_minmax(runtime,
6028 SNDRV_PCM_HW_PARAM_BUFFER_SIZE, 6035 SNDRV_PCM_HW_PARAM_BUFFER_SIZE,
6029 &hw_constraints_raydat_io_buffer); 6036 16384, 16384);
6030 break; 6037 break;
6031 6038
6032 default: 6039 default:
6033 snd_pcm_hw_constraint_list(runtime, 0, 6040 snd_pcm_hw_constraint_minmax(runtime,
6034 SNDRV_PCM_HW_PARAM_PERIOD_SIZE, 6041 SNDRV_PCM_HW_PARAM_PERIOD_SIZE,
6035 &hw_constraints_period_sizes_old); 6042 64, 8192);
6043 break;
6036 } 6044 }
6037 6045
6038 if (AES32 == hdspm->io_type) { 6046 if (AES32 == hdspm->io_type) {
6047 runtime->hw.rates |= SNDRV_PCM_RATE_KNOT;
6039 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE, 6048 snd_pcm_hw_constraint_list(runtime, 0, SNDRV_PCM_HW_PARAM_RATE,
6040 &hdspm_hw_constraints_aes32_sample_rates); 6049 &hdspm_hw_constraints_aes32_sample_rates);
6041 } else { 6050 } else {
@@ -6081,7 +6090,7 @@ static inline int copy_u32_le(void __user *dest, void __iomem *src)
6081} 6090}
6082 6091
6083static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file, 6092static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6084 unsigned int cmd, unsigned long __user arg) 6093 unsigned int cmd, unsigned long arg)
6085{ 6094{
6086 void __user *argp = (void __user *)arg; 6095 void __user *argp = (void __user *)arg;
6087 struct hdspm *hdspm = hw->private_data; 6096 struct hdspm *hdspm = hw->private_data;
@@ -6206,11 +6215,13 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6206 info.line_out = hdspm_line_out(hdspm); 6215 info.line_out = hdspm_line_out(hdspm);
6207 info.passthru = 0; 6216 info.passthru = 0;
6208 spin_unlock_irq(&hdspm->lock); 6217 spin_unlock_irq(&hdspm->lock);
6209 if (copy_to_user((void __user *) arg, &info, sizeof(info))) 6218 if (copy_to_user(argp, &info, sizeof(info)))
6210 return -EFAULT; 6219 return -EFAULT;
6211 break; 6220 break;
6212 6221
6213 case SNDRV_HDSPM_IOCTL_GET_STATUS: 6222 case SNDRV_HDSPM_IOCTL_GET_STATUS:
6223 memset(&status, 0, sizeof(status));
6224
6214 status.card_type = hdspm->io_type; 6225 status.card_type = hdspm->io_type;
6215 6226
6216 status.autosync_source = hdspm_autosync_ref(hdspm); 6227 status.autosync_source = hdspm_autosync_ref(hdspm);
@@ -6235,7 +6246,7 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6235 status.card_specific.madi.madi_input = 6246 status.card_specific.madi.madi_input =
6236 (statusregister & HDSPM_AB_int) ? 1 : 0; 6247 (statusregister & HDSPM_AB_int) ? 1 : 0;
6237 status.card_specific.madi.channel_format = 6248 status.card_specific.madi.channel_format =
6238 (statusregister & HDSPM_TX_64ch) ? 1 : 0; 6249 (statusregister & HDSPM_RX_64ch) ? 1 : 0;
6239 /* TODO: Mac driver sets it when f_s>48kHz */ 6250 /* TODO: Mac driver sets it when f_s>48kHz */
6240 status.card_specific.madi.frame_format = 0; 6251 status.card_specific.madi.frame_format = 0;
6241 6252
@@ -6243,13 +6254,15 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6243 break; 6254 break;
6244 } 6255 }
6245 6256
6246 if (copy_to_user((void __user *) arg, &status, sizeof(status))) 6257 if (copy_to_user(argp, &status, sizeof(status)))
6247 return -EFAULT; 6258 return -EFAULT;
6248 6259
6249 6260
6250 break; 6261 break;
6251 6262
6252 case SNDRV_HDSPM_IOCTL_GET_VERSION: 6263 case SNDRV_HDSPM_IOCTL_GET_VERSION:
6264 memset(&hdspm_version, 0, sizeof(hdspm_version));
6265
6253 hdspm_version.card_type = hdspm->io_type; 6266 hdspm_version.card_type = hdspm->io_type;
6254 strncpy(hdspm_version.cardname, hdspm->card_name, 6267 strncpy(hdspm_version.cardname, hdspm->card_name,
6255 sizeof(hdspm_version.cardname)); 6268 sizeof(hdspm_version.cardname));
@@ -6260,13 +6273,13 @@ static int snd_hdspm_hwdep_ioctl(struct snd_hwdep *hw, struct file *file,
6260 if (hdspm->tco) 6273 if (hdspm->tco)
6261 hdspm_version.addons |= HDSPM_ADDON_TCO; 6274 hdspm_version.addons |= HDSPM_ADDON_TCO;
6262 6275
6263 if (copy_to_user((void __user *) arg, &hdspm_version, 6276 if (copy_to_user(argp, &hdspm_version,
6264 sizeof(hdspm_version))) 6277 sizeof(hdspm_version)))
6265 return -EFAULT; 6278 return -EFAULT;
6266 break; 6279 break;
6267 6280
6268 case SNDRV_HDSPM_IOCTL_GET_MIXER: 6281 case SNDRV_HDSPM_IOCTL_GET_MIXER:
6269 if (copy_from_user(&mixer, (void __user *)arg, sizeof(mixer))) 6282 if (copy_from_user(&mixer, argp, sizeof(mixer)))
6270 return -EFAULT; 6283 return -EFAULT;
6271 if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer, 6284 if (copy_to_user((void __user *)mixer.mixer, hdspm->mixer,
6272 sizeof(struct hdspm_mixer))) 6285 sizeof(struct hdspm_mixer)))
@@ -6483,13 +6496,6 @@ static int __devinit snd_hdspm_create(struct snd_card *card,
6483 strcpy(card->driver, "HDSPM"); 6496 strcpy(card->driver, "HDSPM");
6484 6497
6485 switch (hdspm->firmware_rev) { 6498 switch (hdspm->firmware_rev) {
6486 case HDSPM_MADI_REV:
6487 case HDSPM_MADI_OLD_REV:
6488 case HDSPM_MADI_ANCIENT_REV:
6489 hdspm->io_type = MADI;
6490 hdspm->card_name = "RME MADI";
6491 hdspm->midiPorts = 3;
6492 break;
6493 case HDSPM_RAYDAT_REV: 6499 case HDSPM_RAYDAT_REV:
6494 hdspm->io_type = RayDAT; 6500 hdspm->io_type = RayDAT;
6495 hdspm->card_name = "RME RayDAT"; 6501 hdspm->card_name = "RME RayDAT";
@@ -6505,17 +6511,25 @@ static int __devinit snd_hdspm_create(struct snd_card *card,
6505 hdspm->card_name = "RME MADIface"; 6511 hdspm->card_name = "RME MADIface";
6506 hdspm->midiPorts = 1; 6512 hdspm->midiPorts = 1;
6507 break; 6513 break;
6508 case HDSPM_AES_REV:
6509 case HDSPM_AES32_REV:
6510 case HDSPM_AES32_OLD_REV:
6511 hdspm->io_type = AES32;
6512 hdspm->card_name = "RME AES32";
6513 hdspm->midiPorts = 2;
6514 break;
6515 default: 6514 default:
6516 snd_printk(KERN_ERR "HDSPM: unknown firmware revision %x\n", 6515 if ((hdspm->firmware_rev == 0xf0) ||
6516 ((hdspm->firmware_rev >= 0xe6) &&
6517 (hdspm->firmware_rev <= 0xea))) {
6518 hdspm->io_type = AES32;
6519 hdspm->card_name = "RME AES32";
6520 hdspm->midiPorts = 2;
6521 } else if ((hdspm->firmware_rev == 0xd5) ||
6522 ((hdspm->firmware_rev >= 0xc8) &&
6523 (hdspm->firmware_rev <= 0xcf))) {
6524 hdspm->io_type = MADI;
6525 hdspm->card_name = "RME MADI";
6526 hdspm->midiPorts = 3;
6527 } else {
6528 snd_printk(KERN_ERR
6529 "HDSPM: unknown firmware revision %x\n",
6517 hdspm->firmware_rev); 6530 hdspm->firmware_rev);
6518 return -ENODEV; 6531 return -ENODEV;
6532 }
6519 } 6533 }
6520 6534
6521 err = pci_enable_device(pci); 6535 err = pci_enable_device(pci);
diff --git a/sound/pci/sis7019.c b/sound/pci/sis7019.c
index bcf61524a13f..5ffb20b18786 100644
--- a/sound/pci/sis7019.c
+++ b/sound/pci/sis7019.c
@@ -1234,7 +1234,7 @@ static int sis_resume(struct pci_dev *pci)
1234 goto error; 1234 goto error;
1235 } 1235 }
1236 1236
1237 if (request_irq(pci->irq, sis_interrupt, IRQF_DISABLED|IRQF_SHARED, 1237 if (request_irq(pci->irq, sis_interrupt, IRQF_SHARED,
1238 KBUILD_MODNAME, sis)) { 1238 KBUILD_MODNAME, sis)) {
1239 printk(KERN_ERR "sis7019: unable to regain IRQ %d\n", pci->irq); 1239 printk(KERN_ERR "sis7019: unable to regain IRQ %d\n", pci->irq);
1240 goto error; 1240 goto error;
@@ -1340,7 +1340,7 @@ static int __devinit sis_chip_create(struct snd_card *card,
1340 if (rc) 1340 if (rc)
1341 goto error_out_cleanup; 1341 goto error_out_cleanup;
1342 1342
1343 if (request_irq(pci->irq, sis_interrupt, IRQF_DISABLED|IRQF_SHARED, 1343 if (request_irq(pci->irq, sis_interrupt, IRQF_SHARED,
1344 KBUILD_MODNAME, sis)) { 1344 KBUILD_MODNAME, sis)) {
1345 printk(KERN_ERR "unable to allocate irq %d\n", sis->irq); 1345 printk(KERN_ERR "unable to allocate irq %d\n", sis->irq);
1346 goto error_out_cleanup; 1346 goto error_out_cleanup;
diff --git a/sound/pci/sonicvibes.c b/sound/pci/sonicvibes.c
index 2571a67b389a..c5008166cf1f 100644
--- a/sound/pci/sonicvibes.c
+++ b/sound/pci/sonicvibes.c
@@ -1493,9 +1493,10 @@ static int __devinit snd_sonic_probe(struct pci_dev *pci,
1493 return err; 1493 return err;
1494 } 1494 }
1495 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SONICVIBES, 1495 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_SONICVIBES,
1496 sonic->midi_port, MPU401_INFO_INTEGRATED, 1496 sonic->midi_port,
1497 sonic->irq, 0, 1497 MPU401_INFO_INTEGRATED |
1498 &midi_uart)) < 0) { 1498 MPU401_INFO_IRQ_HOOK,
1499 -1, &midi_uart)) < 0) {
1499 snd_card_free(card); 1500 snd_card_free(card);
1500 return err; 1501 return err;
1501 } 1502 }
diff --git a/sound/pci/trident/trident.c b/sound/pci/trident/trident.c
index d8a128f6fc02..5e707effdc7c 100644
--- a/sound/pci/trident/trident.c
+++ b/sound/pci/trident/trident.c
@@ -148,8 +148,9 @@ static int __devinit snd_trident_probe(struct pci_dev *pci,
148 if (trident->device != TRIDENT_DEVICE_ID_SI7018 && 148 if (trident->device != TRIDENT_DEVICE_ID_SI7018 &&
149 (err = snd_mpu401_uart_new(card, 0, MPU401_HW_TRID4DWAVE, 149 (err = snd_mpu401_uart_new(card, 0, MPU401_HW_TRID4DWAVE,
150 trident->midi_port, 150 trident->midi_port,
151 MPU401_INFO_INTEGRATED, 151 MPU401_INFO_INTEGRATED |
152 trident->irq, 0, &trident->rmidi)) < 0) { 152 MPU401_INFO_IRQ_HOOK,
153 -1, &trident->rmidi)) < 0) {
153 snd_card_free(card); 154 snd_card_free(card);
154 return err; 155 return err;
155 } 156 }
diff --git a/sound/pci/via82xx.c b/sound/pci/via82xx.c
index f03fd620a2a0..c3656fffdb50 100644
--- a/sound/pci/via82xx.c
+++ b/sound/pci/via82xx.c
@@ -1175,6 +1175,7 @@ static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev,
1175 struct snd_pcm_runtime *runtime = substream->runtime; 1175 struct snd_pcm_runtime *runtime = substream->runtime;
1176 int err; 1176 int err;
1177 struct via_rate_lock *ratep; 1177 struct via_rate_lock *ratep;
1178 bool use_src = false;
1178 1179
1179 runtime->hw = snd_via82xx_hw; 1180 runtime->hw = snd_via82xx_hw;
1180 1181
@@ -1196,6 +1197,7 @@ static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev,
1196 SNDRV_PCM_RATE_8000_48000); 1197 SNDRV_PCM_RATE_8000_48000);
1197 runtime->hw.rate_min = 8000; 1198 runtime->hw.rate_min = 8000;
1198 runtime->hw.rate_max = 48000; 1199 runtime->hw.rate_max = 48000;
1200 use_src = true;
1199 } else if (! ratep->rate) { 1201 } else if (! ratep->rate) {
1200 int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC; 1202 int idx = viadev->direction ? AC97_RATES_ADC : AC97_RATES_FRONT_DAC;
1201 runtime->hw.rates = chip->ac97->rates[idx]; 1203 runtime->hw.rates = chip->ac97->rates[idx];
@@ -1212,6 +1214,12 @@ static int snd_via82xx_pcm_open(struct via82xx *chip, struct viadev *viadev,
1212 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0) 1214 if ((err = snd_pcm_hw_constraint_integer(runtime, SNDRV_PCM_HW_PARAM_PERIODS)) < 0)
1213 return err; 1215 return err;
1214 1216
1217 if (use_src) {
1218 err = snd_pcm_hw_rule_noresample(runtime, 48000);
1219 if (err < 0)
1220 return err;
1221 }
1222
1215 runtime->private_data = viadev; 1223 runtime->private_data = viadev;
1216 viadev->substream = substream; 1224 viadev->substream = substream;
1217 1225
@@ -2068,8 +2076,9 @@ static int __devinit snd_via686_init_misc(struct via82xx *chip)
2068 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg); 2076 pci_write_config_byte(chip->pci, VIA_PNP_CONTROL, legacy_cfg);
2069 if (chip->mpu_res) { 2077 if (chip->mpu_res) {
2070 if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A, 2078 if (snd_mpu401_uart_new(chip->card, 0, MPU401_HW_VIA686A,
2071 mpu_port, MPU401_INFO_INTEGRATED, 2079 mpu_port, MPU401_INFO_INTEGRATED |
2072 chip->irq, 0, &chip->rmidi) < 0) { 2080 MPU401_INFO_IRQ_HOOK, -1,
2081 &chip->rmidi) < 0) {
2073 printk(KERN_WARNING "unable to initialize MPU-401" 2082 printk(KERN_WARNING "unable to initialize MPU-401"
2074 " at 0x%lx, skipping\n", mpu_port); 2083 " at 0x%lx, skipping\n", mpu_port);
2075 legacy &= ~VIA_FUNC_ENABLE_MIDI; 2084 legacy &= ~VIA_FUNC_ENABLE_MIDI;
diff --git a/sound/pci/ymfpci/ymfpci.c b/sound/pci/ymfpci/ymfpci.c
index 511d57653124..3253b04da184 100644
--- a/sound/pci/ymfpci/ymfpci.c
+++ b/sound/pci/ymfpci/ymfpci.c
@@ -305,8 +305,9 @@ static int __devinit snd_card_ymfpci_probe(struct pci_dev *pci,
305 if (chip->mpu_res) { 305 if (chip->mpu_res) {
306 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_YMFPCI, 306 if ((err = snd_mpu401_uart_new(card, 0, MPU401_HW_YMFPCI,
307 mpu_port[dev], 307 mpu_port[dev],
308 MPU401_INFO_INTEGRATED, 308 MPU401_INFO_INTEGRATED |
309 pci->irq, 0, &chip->rawmidi)) < 0) { 309 MPU401_INFO_IRQ_HOOK,
310 -1, &chip->rawmidi)) < 0) {
310 printk(KERN_WARNING "ymfpci: cannot initialize MPU401 at 0x%lx, skipping...\n", mpu_port[dev]); 311 printk(KERN_WARNING "ymfpci: cannot initialize MPU401 at 0x%lx, skipping...\n", mpu_port[dev]);
311 legacy_ctrl &= ~YMFPCI_LEGACY_MIEN; /* disable MPU401 irq */ 312 legacy_ctrl &= ~YMFPCI_LEGACY_MIEN; /* disable MPU401 irq */
312 pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl); 313 pci_write_config_word(pci, PCIR_DSXG_LEGACY, legacy_ctrl);
diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
index f3260e658b8a..66ea71b2a70d 100644
--- a/sound/pci/ymfpci/ymfpci_main.c
+++ b/sound/pci/ymfpci/ymfpci_main.c
@@ -897,6 +897,18 @@ static int snd_ymfpci_playback_open_1(struct snd_pcm_substream *substream)
897 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); 897 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
898 struct snd_pcm_runtime *runtime = substream->runtime; 898 struct snd_pcm_runtime *runtime = substream->runtime;
899 struct snd_ymfpci_pcm *ypcm; 899 struct snd_ymfpci_pcm *ypcm;
900 int err;
901
902 runtime->hw = snd_ymfpci_playback;
903 /* FIXME? True value is 256/48 = 5.33333 ms */
904 err = snd_pcm_hw_constraint_minmax(runtime,
905 SNDRV_PCM_HW_PARAM_PERIOD_TIME,
906 5334, UINT_MAX);
907 if (err < 0)
908 return err;
909 err = snd_pcm_hw_rule_noresample(runtime, 48000);
910 if (err < 0)
911 return err;
900 912
901 ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL); 913 ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL);
902 if (ypcm == NULL) 914 if (ypcm == NULL)
@@ -904,11 +916,8 @@ static int snd_ymfpci_playback_open_1(struct snd_pcm_substream *substream)
904 ypcm->chip = chip; 916 ypcm->chip = chip;
905 ypcm->type = PLAYBACK_VOICE; 917 ypcm->type = PLAYBACK_VOICE;
906 ypcm->substream = substream; 918 ypcm->substream = substream;
907 runtime->hw = snd_ymfpci_playback;
908 runtime->private_data = ypcm; 919 runtime->private_data = ypcm;
909 runtime->private_free = snd_ymfpci_pcm_free_substream; 920 runtime->private_free = snd_ymfpci_pcm_free_substream;
910 /* FIXME? True value is 256/48 = 5.33333 ms */
911 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 5333, UINT_MAX);
912 return 0; 921 return 0;
913} 922}
914 923
@@ -1013,6 +1022,18 @@ static int snd_ymfpci_capture_open(struct snd_pcm_substream *substream,
1013 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream); 1022 struct snd_ymfpci *chip = snd_pcm_substream_chip(substream);
1014 struct snd_pcm_runtime *runtime = substream->runtime; 1023 struct snd_pcm_runtime *runtime = substream->runtime;
1015 struct snd_ymfpci_pcm *ypcm; 1024 struct snd_ymfpci_pcm *ypcm;
1025 int err;
1026
1027 runtime->hw = snd_ymfpci_capture;
1028 /* FIXME? True value is 256/48 = 5.33333 ms */
1029 err = snd_pcm_hw_constraint_minmax(runtime,
1030 SNDRV_PCM_HW_PARAM_PERIOD_TIME,
1031 5334, UINT_MAX);
1032 if (err < 0)
1033 return err;
1034 err = snd_pcm_hw_rule_noresample(runtime, 48000);
1035 if (err < 0)
1036 return err;
1016 1037
1017 ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL); 1038 ypcm = kzalloc(sizeof(*ypcm), GFP_KERNEL);
1018 if (ypcm == NULL) 1039 if (ypcm == NULL)
@@ -1022,9 +1043,6 @@ static int snd_ymfpci_capture_open(struct snd_pcm_substream *substream,
1022 ypcm->substream = substream; 1043 ypcm->substream = substream;
1023 ypcm->capture_bank_number = capture_bank_number; 1044 ypcm->capture_bank_number = capture_bank_number;
1024 chip->capture_substream[capture_bank_number] = substream; 1045 chip->capture_substream[capture_bank_number] = substream;
1025 runtime->hw = snd_ymfpci_capture;
1026 /* FIXME? True value is 256/48 = 5.33333 ms */
1027 snd_pcm_hw_constraint_minmax(runtime, SNDRV_PCM_HW_PARAM_PERIOD_TIME, 5333, UINT_MAX);
1028 runtime->private_data = ypcm; 1046 runtime->private_data = ypcm;
1029 runtime->private_free = snd_ymfpci_pcm_free_substream; 1047 runtime->private_free = snd_ymfpci_pcm_free_substream;
1030 snd_ymfpci_hw_start(chip); 1048 snd_ymfpci_hw_start(chip);
@@ -1615,7 +1633,7 @@ YMFPCI_DOUBLE("ADC Playback Volume", 0, YDSXGR_PRIADCOUTVOL),
1615YMFPCI_DOUBLE("ADC Capture Volume", 0, YDSXGR_PRIADCLOOPVOL), 1633YMFPCI_DOUBLE("ADC Capture Volume", 0, YDSXGR_PRIADCLOOPVOL),
1616YMFPCI_DOUBLE("ADC Playback Volume", 1, YDSXGR_SECADCOUTVOL), 1634YMFPCI_DOUBLE("ADC Playback Volume", 1, YDSXGR_SECADCOUTVOL),
1617YMFPCI_DOUBLE("ADC Capture Volume", 1, YDSXGR_SECADCLOOPVOL), 1635YMFPCI_DOUBLE("ADC Capture Volume", 1, YDSXGR_SECADCLOOPVOL),
1618YMFPCI_DOUBLE("FM Legacy Volume", 0, YDSXGR_LEGACYOUTVOL), 1636YMFPCI_DOUBLE("FM Legacy Playback Volume", 0, YDSXGR_LEGACYOUTVOL),
1619YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ", PLAYBACK,VOLUME), 0, YDSXGR_ZVOUTVOL), 1637YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ", PLAYBACK,VOLUME), 0, YDSXGR_ZVOUTVOL),
1620YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("", CAPTURE,VOLUME), 0, YDSXGR_ZVLOOPVOL), 1638YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("", CAPTURE,VOLUME), 0, YDSXGR_ZVLOOPVOL),
1621YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ",PLAYBACK,VOLUME), 1, YDSXGR_SPDIFOUTVOL), 1639YMFPCI_DOUBLE(SNDRV_CTL_NAME_IEC958("AC97 ",PLAYBACK,VOLUME), 1, YDSXGR_SPDIFOUTVOL),
diff --git a/sound/ppc/keywest.c b/sound/ppc/keywest.c
index 8f064c7ce745..4080becf4cef 100644
--- a/sound/ppc/keywest.c
+++ b/sound/ppc/keywest.c
@@ -82,7 +82,6 @@ static int keywest_attach_adapter(struct i2c_adapter *adapter)
82 82
83static int keywest_remove(struct i2c_client *client) 83static int keywest_remove(struct i2c_client *client)
84{ 84{
85 i2c_set_clientdata(client, NULL);
86 if (! keywest_ctx) 85 if (! keywest_ctx)
87 return 0; 86 return 0;
88 if (client == keywest_ctx->client) 87 if (client == keywest_ctx->client)
diff --git a/sound/ppc/snd_ps3.c b/sound/ppc/snd_ps3.c
index bc823a547550..775bd95d4be6 100644
--- a/sound/ppc/snd_ps3.c
+++ b/sound/ppc/snd_ps3.c
@@ -845,7 +845,7 @@ static int __devinit snd_ps3_allocate_irq(void)
845 return ret; 845 return ret;
846 } 846 }
847 847
848 ret = request_irq(the_card.irq_no, snd_ps3_interrupt, IRQF_DISABLED, 848 ret = request_irq(the_card.irq_no, snd_ps3_interrupt, 0,
849 SND_PS3_DRIVER_NAME, &the_card); 849 SND_PS3_DRIVER_NAME, &the_card);
850 if (ret) { 850 if (ret) {
851 pr_info("%s: request_irq failed (%d)\n", __func__, ret); 851 pr_info("%s: request_irq failed (%d)\n", __func__, ret);
diff --git a/sound/soc/au1x/dma.c b/sound/soc/au1x/dma.c
index 7aa5b7606777..177f7137a9c8 100644
--- a/sound/soc/au1x/dma.c
+++ b/sound/soc/au1x/dma.c
@@ -211,7 +211,7 @@ static int alchemy_pcm_open(struct snd_pcm_substream *substream)
211 /* DMA setup */ 211 /* DMA setup */
212 name = (s == SNDRV_PCM_STREAM_PLAYBACK) ? "audio-tx" : "audio-rx"; 212 name = (s == SNDRV_PCM_STREAM_PLAYBACK) ? "audio-tx" : "audio-rx";
213 ctx->stream[s].dma = request_au1000_dma(dmaids[s], name, 213 ctx->stream[s].dma = request_au1000_dma(dmaids[s], name,
214 au1000_dma_interrupt, IRQF_DISABLED, 214 au1000_dma_interrupt, 0,
215 &ctx->stream[s]); 215 &ctx->stream[s]);
216 set_dma_mode(ctx->stream[s].dma, 216 set_dma_mode(ctx->stream[s].dma,
217 get_dma_mode(ctx->stream[s].dma) & ~DMA_NC); 217 get_dma_mode(ctx->stream[s].dma) & ~DMA_NC);
diff --git a/sound/soc/codecs/tlv320dac33.c b/sound/soc/codecs/tlv320dac33.c
index 3f4920d5456d..dc8a2b2bdc1c 100644
--- a/sound/soc/codecs/tlv320dac33.c
+++ b/sound/soc/codecs/tlv320dac33.c
@@ -1419,7 +1419,7 @@ static int dac33_soc_probe(struct snd_soc_codec *codec)
1419 /* Check if the IRQ number is valid and request it */ 1419 /* Check if the IRQ number is valid and request it */
1420 if (dac33->irq >= 0) { 1420 if (dac33->irq >= 0) {
1421 ret = request_irq(dac33->irq, dac33_interrupt_handler, 1421 ret = request_irq(dac33->irq, dac33_interrupt_handler,
1422 IRQF_TRIGGER_RISING | IRQF_DISABLED, 1422 IRQF_TRIGGER_RISING,
1423 codec->name, codec); 1423 codec->name, codec);
1424 if (ret < 0) { 1424 if (ret < 0) {
1425 dev_err(codec->dev, "Could not request IRQ%d (%d)\n", 1425 dev_err(codec->dev, "Could not request IRQ%d (%d)\n",
diff --git a/sound/soc/nuc900/nuc900-pcm.c b/sound/soc/nuc900/nuc900-pcm.c
index 4e3626b9d8f9..ae8d6806966b 100644
--- a/sound/soc/nuc900/nuc900-pcm.c
+++ b/sound/soc/nuc900/nuc900-pcm.c
@@ -268,7 +268,7 @@ static int nuc900_dma_open(struct snd_pcm_substream *substream)
268 nuc900_audio = nuc900_ac97_data; 268 nuc900_audio = nuc900_ac97_data;
269 269
270 if (request_irq(nuc900_audio->irq_num, nuc900_dma_interrupt, 270 if (request_irq(nuc900_audio->irq_num, nuc900_dma_interrupt,
271 IRQF_DISABLED, "nuc900-dma", substream)) 271 0, "nuc900-dma", substream))
272 return -EBUSY; 272 return -EBUSY;
273 273
274 runtime->private_data = nuc900_audio; 274 runtime->private_data = nuc900_audio;
diff --git a/sound/soc/samsung/ac97.c b/sound/soc/samsung/ac97.c
index 65ea53884806..b5e922f469d5 100644
--- a/sound/soc/samsung/ac97.c
+++ b/sound/soc/samsung/ac97.c
@@ -444,7 +444,7 @@ static __devinit int s3c_ac97_probe(struct platform_device *pdev)
444 } 444 }
445 445
446 ret = request_irq(irq_res->start, s3c_ac97_irq, 446 ret = request_irq(irq_res->start, s3c_ac97_irq,
447 IRQF_DISABLED, "AC97", NULL); 447 0, "AC97", NULL);
448 if (ret < 0) { 448 if (ret < 0) {
449 dev_err(&pdev->dev, "ac97: interrupt request failed.\n"); 449 dev_err(&pdev->dev, "ac97: interrupt request failed.\n");
450 goto err4; 450 goto err4;
diff --git a/sound/soc/sh/fsi.c b/sound/soc/sh/fsi.c
index 916b9f99b7e7..a32fd16ad668 100644
--- a/sound/soc/sh/fsi.c
+++ b/sound/soc/sh/fsi.c
@@ -1285,7 +1285,7 @@ static int fsi_probe(struct platform_device *pdev)
1285 pm_runtime_enable(&pdev->dev); 1285 pm_runtime_enable(&pdev->dev);
1286 dev_set_drvdata(&pdev->dev, master); 1286 dev_set_drvdata(&pdev->dev, master);
1287 1287
1288 ret = request_irq(irq, &fsi_interrupt, IRQF_DISABLED, 1288 ret = request_irq(irq, &fsi_interrupt, 0,
1289 id_entry->name, master); 1289 id_entry->name, master);
1290 if (ret) { 1290 if (ret) {
1291 dev_err(&pdev->dev, "irq request err\n"); 1291 dev_err(&pdev->dev, "irq request err\n");
diff --git a/sound/soc/txx9/txx9aclc-ac97.c b/sound/soc/txx9/txx9aclc-ac97.c
index 743d07b82c06..a4e3f5501847 100644
--- a/sound/soc/txx9/txx9aclc-ac97.c
+++ b/sound/soc/txx9/txx9aclc-ac97.c
@@ -201,7 +201,7 @@ static int __devinit txx9aclc_ac97_dev_probe(struct platform_device *pdev)
201 if (!drvdata->base) 201 if (!drvdata->base)
202 return -EBUSY; 202 return -EBUSY;
203 err = devm_request_irq(&pdev->dev, irq, txx9aclc_ac97_irq, 203 err = devm_request_irq(&pdev->dev, irq, txx9aclc_ac97_irq,
204 IRQF_DISABLED, dev_name(&pdev->dev), drvdata); 204 0, dev_name(&pdev->dev), drvdata);
205 if (err < 0) 205 if (err < 0)
206 return err; 206 return err;
207 207
diff --git a/sound/sparc/amd7930.c b/sound/sparc/amd7930.c
index ad7d4d7d9237..f036776380b5 100644
--- a/sound/sparc/amd7930.c
+++ b/sound/sparc/amd7930.c
@@ -962,7 +962,7 @@ static int __devinit snd_amd7930_create(struct snd_card *card,
962 amd7930_idle(amd); 962 amd7930_idle(amd);
963 963
964 if (request_irq(irq, snd_amd7930_interrupt, 964 if (request_irq(irq, snd_amd7930_interrupt,
965 IRQF_DISABLED | IRQF_SHARED, "amd7930", amd)) { 965 IRQF_SHARED, "amd7930", amd)) {
966 snd_printk(KERN_ERR "amd7930-%d: Unable to grab IRQ %d\n", 966 snd_printk(KERN_ERR "amd7930-%d: Unable to grab IRQ %d\n",
967 dev, irq); 967 dev, irq);
968 snd_amd7930_free(amd); 968 snd_amd7930_free(amd);
diff --git a/sound/usb/6fire/firmware.c b/sound/usb/6fire/firmware.c
index 1e3ae3327dd3..07bcfe4d18a7 100644
--- a/sound/usb/6fire/firmware.c
+++ b/sound/usb/6fire/firmware.c
@@ -16,6 +16,7 @@
16 16
17#include <linux/firmware.h> 17#include <linux/firmware.h>
18#include <linux/bitrev.h> 18#include <linux/bitrev.h>
19#include <linux/kernel.h>
19 20
20#include "firmware.h" 21#include "firmware.h"
21#include "chip.h" 22#include "chip.h"
@@ -59,21 +60,19 @@ struct ihex_record {
59 unsigned int txt_offset; /* current position in txt_data */ 60 unsigned int txt_offset; /* current position in txt_data */
60}; 61};
61 62
62static u8 usb6fire_fw_ihex_nibble(const u8 n)
63{
64 if (n >= '0' && n <= '9')
65 return n - '0';
66 else if (n >= 'A' && n <= 'F')
67 return n - ('A' - 10);
68 else if (n >= 'a' && n <= 'f')
69 return n - ('a' - 10);
70 return 0;
71}
72
73static u8 usb6fire_fw_ihex_hex(const u8 *data, u8 *crc) 63static u8 usb6fire_fw_ihex_hex(const u8 *data, u8 *crc)
74{ 64{
75 u8 val = (usb6fire_fw_ihex_nibble(data[0]) << 4) | 65 u8 val = 0;
76 usb6fire_fw_ihex_nibble(data[1]); 66 int hval;
67
68 hval = hex_to_bin(data[0]);
69 if (hval >= 0)
70 val |= (hval << 4);
71
72 hval = hex_to_bin(data[1]);
73 if (hval >= 0)
74 val |= hval;
75
77 *crc += val; 76 *crc += val;
78 return val; 77 return val;
79} 78}
diff --git a/sound/usb/Kconfig b/sound/usb/Kconfig
index 8beb77563da2..3efc21c3d67c 100644
--- a/sound/usb/Kconfig
+++ b/sound/usb/Kconfig
@@ -67,6 +67,7 @@ config SND_USB_CAIAQ
67 * Native Instruments Guitar Rig mobile 67 * Native Instruments Guitar Rig mobile
68 * Native Instruments Traktor Kontrol X1 68 * Native Instruments Traktor Kontrol X1
69 * Native Instruments Traktor Kontrol S4 69 * Native Instruments Traktor Kontrol S4
70 * Native Instruments Maschine Controller
70 71
71 To compile this driver as a module, choose M here: the module 72 To compile this driver as a module, choose M here: the module
72 will be called snd-usb-caiaq. 73 will be called snd-usb-caiaq.
@@ -85,6 +86,7 @@ config SND_USB_CAIAQ_INPUT
85 * Native Instruments Kore Controller 2 86 * Native Instruments Kore Controller 2
86 * Native Instruments Audio Kontrol 1 87 * Native Instruments Audio Kontrol 1
87 * Native Instruments Traktor Kontrol S4 88 * Native Instruments Traktor Kontrol S4
89 * Native Instruments Maschine Controller
88 90
89config SND_USB_US122L 91config SND_USB_US122L
90 tristate "Tascam US-122L USB driver" 92 tristate "Tascam US-122L USB driver"
diff --git a/sound/usb/Makefile b/sound/usb/Makefile
index cf9ed66445fa..ac256dc4c6be 100644
--- a/sound/usb/Makefile
+++ b/sound/usb/Makefile
@@ -3,16 +3,16 @@
3# 3#
4 4
5snd-usb-audio-objs := card.o \ 5snd-usb-audio-objs := card.o \
6 clock.o \
7 endpoint.o \
8 format.o \
9 helper.o \
6 mixer.o \ 10 mixer.o \
7 mixer_quirks.o \ 11 mixer_quirks.o \
12 pcm.o \
8 proc.o \ 13 proc.o \
9 quirks.o \ 14 quirks.o \
10 format.o \ 15 stream.o
11 endpoint.o \
12 urb.o \
13 pcm.o \
14 helper.o \
15 clock.o
16 16
17snd-usbmidi-lib-objs := midi.o 17snd-usbmidi-lib-objs := midi.o
18 18
diff --git a/sound/usb/caiaq/audio.c b/sound/usb/caiaq/audio.c
index d0d493ca28ae..2cf87f5afed4 100644
--- a/sound/usb/caiaq/audio.c
+++ b/sound/usb/caiaq/audio.c
@@ -139,8 +139,12 @@ static void stream_stop(struct snd_usb_caiaqdev *dev)
139 139
140 for (i = 0; i < N_URBS; i++) { 140 for (i = 0; i < N_URBS; i++) {
141 usb_kill_urb(dev->data_urbs_in[i]); 141 usb_kill_urb(dev->data_urbs_in[i]);
142 usb_kill_urb(dev->data_urbs_out[i]); 142
143 if (test_bit(i, &dev->outurb_active_mask))
144 usb_kill_urb(dev->data_urbs_out[i]);
143 } 145 }
146
147 dev->outurb_active_mask = 0;
144} 148}
145 149
146static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream) 150static int snd_usb_caiaq_substream_open(struct snd_pcm_substream *substream)
@@ -612,8 +616,9 @@ static void read_completed(struct urb *urb)
612{ 616{
613 struct snd_usb_caiaq_cb_info *info = urb->context; 617 struct snd_usb_caiaq_cb_info *info = urb->context;
614 struct snd_usb_caiaqdev *dev; 618 struct snd_usb_caiaqdev *dev;
615 struct urb *out; 619 struct urb *out = NULL;
616 int frame, len, send_it = 0, outframe = 0; 620 int i, frame, len, send_it = 0, outframe = 0;
621 size_t offset = 0;
617 622
618 if (urb->status || !info) 623 if (urb->status || !info)
619 return; 624 return;
@@ -623,7 +628,17 @@ static void read_completed(struct urb *urb)
623 if (!dev->streaming) 628 if (!dev->streaming)
624 return; 629 return;
625 630
626 out = dev->data_urbs_out[info->index]; 631 /* find an unused output urb that is unused */
632 for (i = 0; i < N_URBS; i++)
633 if (test_and_set_bit(i, &dev->outurb_active_mask) == 0) {
634 out = dev->data_urbs_out[i];
635 break;
636 }
637
638 if (!out) {
639 log("Unable to find an output urb to use\n");
640 goto requeue;
641 }
627 642
628 /* read the recently received packet and send back one which has 643 /* read the recently received packet and send back one which has
629 * the same layout */ 644 * the same layout */
@@ -634,7 +649,8 @@ static void read_completed(struct urb *urb)
634 len = urb->iso_frame_desc[outframe].actual_length; 649 len = urb->iso_frame_desc[outframe].actual_length;
635 out->iso_frame_desc[outframe].length = len; 650 out->iso_frame_desc[outframe].length = len;
636 out->iso_frame_desc[outframe].actual_length = 0; 651 out->iso_frame_desc[outframe].actual_length = 0;
637 out->iso_frame_desc[outframe].offset = BYTES_PER_FRAME * frame; 652 out->iso_frame_desc[outframe].offset = offset;
653 offset += len;
638 654
639 if (len > 0) { 655 if (len > 0) {
640 spin_lock(&dev->spinlock); 656 spin_lock(&dev->spinlock);
@@ -650,11 +666,15 @@ static void read_completed(struct urb *urb)
650 } 666 }
651 667
652 if (send_it) { 668 if (send_it) {
653 out->number_of_packets = FRAMES_PER_URB; 669 out->number_of_packets = outframe;
654 out->transfer_flags = URB_ISO_ASAP; 670 out->transfer_flags = URB_ISO_ASAP;
655 usb_submit_urb(out, GFP_ATOMIC); 671 usb_submit_urb(out, GFP_ATOMIC);
672 } else {
673 struct snd_usb_caiaq_cb_info *oinfo = out->context;
674 clear_bit(oinfo->index, &dev->outurb_active_mask);
656 } 675 }
657 676
677requeue:
658 /* re-submit inbound urb */ 678 /* re-submit inbound urb */
659 for (frame = 0; frame < FRAMES_PER_URB; frame++) { 679 for (frame = 0; frame < FRAMES_PER_URB; frame++) {
660 urb->iso_frame_desc[frame].offset = BYTES_PER_FRAME * frame; 680 urb->iso_frame_desc[frame].offset = BYTES_PER_FRAME * frame;
@@ -676,6 +696,8 @@ static void write_completed(struct urb *urb)
676 dev->output_running = 1; 696 dev->output_running = 1;
677 wake_up(&dev->prepare_wait_queue); 697 wake_up(&dev->prepare_wait_queue);
678 } 698 }
699
700 clear_bit(info->index, &dev->outurb_active_mask);
679} 701}
680 702
681static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret) 703static struct urb **alloc_urbs(struct snd_usb_caiaqdev *dev, int dir, int *ret)
@@ -827,6 +849,9 @@ int snd_usb_caiaq_audio_init(struct snd_usb_caiaqdev *dev)
827 if (!dev->data_cb_info) 849 if (!dev->data_cb_info)
828 return -ENOMEM; 850 return -ENOMEM;
829 851
852 dev->outurb_active_mask = 0;
853 BUILD_BUG_ON(N_URBS > (sizeof(dev->outurb_active_mask) * 8));
854
830 for (i = 0; i < N_URBS; i++) { 855 for (i = 0; i < N_URBS; i++) {
831 dev->data_cb_info[i].dev = dev; 856 dev->data_cb_info[i].dev = dev;
832 dev->data_cb_info[i].index = i; 857 dev->data_cb_info[i].index = i;
diff --git a/sound/usb/caiaq/device.c b/sound/usb/caiaq/device.c
index 45bc4a2dc6f0..3eb605bd9503 100644
--- a/sound/usb/caiaq/device.c
+++ b/sound/usb/caiaq/device.c
@@ -50,7 +50,8 @@ MODULE_SUPPORTED_DEVICE("{{Native Instruments, RigKontrol2},"
50 "{Native Instruments, Session I/O}," 50 "{Native Instruments, Session I/O},"
51 "{Native Instruments, GuitarRig mobile}" 51 "{Native Instruments, GuitarRig mobile}"
52 "{Native Instruments, Traktor Kontrol X1}" 52 "{Native Instruments, Traktor Kontrol X1}"
53 "{Native Instruments, Traktor Kontrol S4}"); 53 "{Native Instruments, Traktor Kontrol S4}"
54 "{Native Instruments, Maschine Controller}");
54 55
55static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */ 56static int index[SNDRV_CARDS] = SNDRV_DEFAULT_IDX; /* Index 0-max */
56static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */ 57static char* id[SNDRV_CARDS] = SNDRV_DEFAULT_STR; /* Id for this card */
@@ -146,6 +147,11 @@ static struct usb_device_id snd_usb_id_table[] = {
146 .idVendor = USB_VID_NATIVEINSTRUMENTS, 147 .idVendor = USB_VID_NATIVEINSTRUMENTS,
147 .idProduct = USB_PID_TRAKTORAUDIO2 148 .idProduct = USB_PID_TRAKTORAUDIO2
148 }, 149 },
150 {
151 .match_flags = USB_DEVICE_ID_MATCH_DEVICE,
152 .idVendor = USB_VID_NATIVEINSTRUMENTS,
153 .idProduct = USB_PID_MASCHINECONTROLLER
154 },
149 { /* terminator */ } 155 { /* terminator */ }
150}; 156};
151 157
diff --git a/sound/usb/caiaq/device.h b/sound/usb/caiaq/device.h
index b2b310194ffa..562b0bff9c41 100644
--- a/sound/usb/caiaq/device.h
+++ b/sound/usb/caiaq/device.h
@@ -18,6 +18,7 @@
18#define USB_PID_TRAKTORKONTROLX1 0x2305 18#define USB_PID_TRAKTORKONTROLX1 0x2305
19#define USB_PID_TRAKTORKONTROLS4 0xbaff 19#define USB_PID_TRAKTORKONTROLS4 0xbaff
20#define USB_PID_TRAKTORAUDIO2 0x041d 20#define USB_PID_TRAKTORAUDIO2 0x041d
21#define USB_PID_MASCHINECONTROLLER 0x0808
21 22
22#define EP1_BUFSIZE 64 23#define EP1_BUFSIZE 64
23#define EP4_BUFSIZE 512 24#define EP4_BUFSIZE 512
@@ -96,6 +97,7 @@ struct snd_usb_caiaqdev {
96 int input_panic, output_panic, warned; 97 int input_panic, output_panic, warned;
97 char *audio_in_buf, *audio_out_buf; 98 char *audio_in_buf, *audio_out_buf;
98 unsigned int samplerates, bpp; 99 unsigned int samplerates, bpp;
100 unsigned long outurb_active_mask;
99 101
100 struct snd_pcm_substream *sub_playback[MAX_STREAMS]; 102 struct snd_pcm_substream *sub_playback[MAX_STREAMS];
101 struct snd_pcm_substream *sub_capture[MAX_STREAMS]; 103 struct snd_pcm_substream *sub_capture[MAX_STREAMS];
diff --git a/sound/usb/caiaq/input.c b/sound/usb/caiaq/input.c
index 4432ef7a70a9..26a121b42c3c 100644
--- a/sound/usb/caiaq/input.c
+++ b/sound/usb/caiaq/input.c
@@ -30,7 +30,7 @@ static unsigned short keycode_ak1[] = { KEY_C, KEY_B, KEY_A };
30static unsigned short keycode_rk2[] = { KEY_1, KEY_2, KEY_3, KEY_4, 30static unsigned short keycode_rk2[] = { KEY_1, KEY_2, KEY_3, KEY_4,
31 KEY_5, KEY_6, KEY_7 }; 31 KEY_5, KEY_6, KEY_7 };
32static unsigned short keycode_rk3[] = { KEY_1, KEY_2, KEY_3, KEY_4, 32static unsigned short keycode_rk3[] = { KEY_1, KEY_2, KEY_3, KEY_4,
33 KEY_5, KEY_6, KEY_7, KEY_5, KEY_6 }; 33 KEY_5, KEY_6, KEY_7, KEY_8, KEY_9 };
34 34
35static unsigned short keycode_kore[] = { 35static unsigned short keycode_kore[] = {
36 KEY_FN_F1, /* "menu" */ 36 KEY_FN_F1, /* "menu" */
@@ -67,6 +67,61 @@ static unsigned short keycode_kore[] = {
67 KEY_BRL_DOT5 67 KEY_BRL_DOT5
68}; 68};
69 69
70#define MASCHINE_BUTTONS (42)
71#define MASCHINE_BUTTON(X) ((X) + BTN_MISC)
72#define MASCHINE_PADS (16)
73#define MASCHINE_PAD(X) ((X) + ABS_PRESSURE)
74
75static unsigned short keycode_maschine[] = {
76 MASCHINE_BUTTON(40), /* mute */
77 MASCHINE_BUTTON(39), /* solo */
78 MASCHINE_BUTTON(38), /* select */
79 MASCHINE_BUTTON(37), /* duplicate */
80 MASCHINE_BUTTON(36), /* navigate */
81 MASCHINE_BUTTON(35), /* pad mode */
82 MASCHINE_BUTTON(34), /* pattern */
83 MASCHINE_BUTTON(33), /* scene */
84 KEY_RESERVED, /* spacer */
85
86 MASCHINE_BUTTON(30), /* rec */
87 MASCHINE_BUTTON(31), /* erase */
88 MASCHINE_BUTTON(32), /* shift */
89 MASCHINE_BUTTON(28), /* grid */
90 MASCHINE_BUTTON(27), /* > */
91 MASCHINE_BUTTON(26), /* < */
92 MASCHINE_BUTTON(25), /* restart */
93
94 MASCHINE_BUTTON(21), /* E */
95 MASCHINE_BUTTON(22), /* F */
96 MASCHINE_BUTTON(23), /* G */
97 MASCHINE_BUTTON(24), /* H */
98 MASCHINE_BUTTON(20), /* D */
99 MASCHINE_BUTTON(19), /* C */
100 MASCHINE_BUTTON(18), /* B */
101 MASCHINE_BUTTON(17), /* A */
102
103 MASCHINE_BUTTON(0), /* control */
104 MASCHINE_BUTTON(2), /* browse */
105 MASCHINE_BUTTON(4), /* < */
106 MASCHINE_BUTTON(6), /* snap */
107 MASCHINE_BUTTON(7), /* autowrite */
108 MASCHINE_BUTTON(5), /* > */
109 MASCHINE_BUTTON(3), /* sampling */
110 MASCHINE_BUTTON(1), /* step */
111
112 MASCHINE_BUTTON(15), /* 8 softkeys */
113 MASCHINE_BUTTON(14),
114 MASCHINE_BUTTON(13),
115 MASCHINE_BUTTON(12),
116 MASCHINE_BUTTON(11),
117 MASCHINE_BUTTON(10),
118 MASCHINE_BUTTON(9),
119 MASCHINE_BUTTON(8),
120
121 MASCHINE_BUTTON(16), /* note repeat */
122 MASCHINE_BUTTON(29) /* play */
123};
124
70#define KONTROLX1_INPUTS (40) 125#define KONTROLX1_INPUTS (40)
71#define KONTROLS4_BUTTONS (12 * 8) 126#define KONTROLS4_BUTTONS (12 * 8)
72#define KONTROLS4_AXIS (46) 127#define KONTROLS4_AXIS (46)
@@ -218,6 +273,29 @@ static void snd_caiaq_input_read_erp(struct snd_usb_caiaqdev *dev,
218 input_report_abs(input_dev, ABS_HAT3Y, i); 273 input_report_abs(input_dev, ABS_HAT3Y, i);
219 input_sync(input_dev); 274 input_sync(input_dev);
220 break; 275 break;
276
277 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
278 /* 4 under the left screen */
279 input_report_abs(input_dev, ABS_HAT0X, decode_erp(buf[21], buf[20]));
280 input_report_abs(input_dev, ABS_HAT0Y, decode_erp(buf[15], buf[14]));
281 input_report_abs(input_dev, ABS_HAT1X, decode_erp(buf[9], buf[8]));
282 input_report_abs(input_dev, ABS_HAT1Y, decode_erp(buf[3], buf[2]));
283
284 /* 4 under the right screen */
285 input_report_abs(input_dev, ABS_HAT2X, decode_erp(buf[19], buf[18]));
286 input_report_abs(input_dev, ABS_HAT2Y, decode_erp(buf[13], buf[12]));
287 input_report_abs(input_dev, ABS_HAT3X, decode_erp(buf[7], buf[6]));
288 input_report_abs(input_dev, ABS_HAT3Y, decode_erp(buf[1], buf[0]));
289
290 /* volume */
291 input_report_abs(input_dev, ABS_RX, decode_erp(buf[17], buf[16]));
292 /* tempo */
293 input_report_abs(input_dev, ABS_RY, decode_erp(buf[11], buf[10]));
294 /* swing */
295 input_report_abs(input_dev, ABS_RZ, decode_erp(buf[5], buf[4]));
296
297 input_sync(input_dev);
298 break;
221 } 299 }
222} 300}
223 301
@@ -400,6 +478,25 @@ static void snd_usb_caiaq_tks4_dispatch(struct snd_usb_caiaqdev *dev,
400 input_sync(dev->input_dev); 478 input_sync(dev->input_dev);
401} 479}
402 480
481#define MASCHINE_MSGBLOCK_SIZE 2
482
483static void snd_usb_caiaq_maschine_dispatch(struct snd_usb_caiaqdev *dev,
484 const unsigned char *buf,
485 unsigned int len)
486{
487 unsigned int i, pad_id;
488 uint16_t pressure;
489
490 for (i = 0; i < MASCHINE_PADS; i++) {
491 pressure = be16_to_cpu(buf[i * 2] << 8 | buf[(i * 2) + 1]);
492 pad_id = pressure >> 12;
493
494 input_report_abs(dev->input_dev, MASCHINE_PAD(pad_id), pressure & 0xfff);
495 }
496
497 input_sync(dev->input_dev);
498}
499
403static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb) 500static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb)
404{ 501{
405 struct snd_usb_caiaqdev *dev = urb->context; 502 struct snd_usb_caiaqdev *dev = urb->context;
@@ -425,6 +522,13 @@ static void snd_usb_caiaq_ep4_reply_dispatch(struct urb *urb)
425 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): 522 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
426 snd_usb_caiaq_tks4_dispatch(dev, buf, urb->actual_length); 523 snd_usb_caiaq_tks4_dispatch(dev, buf, urb->actual_length);
427 break; 524 break;
525
526 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
527 if (urb->actual_length < (MASCHINE_PADS * MASCHINE_MSGBLOCK_SIZE))
528 goto requeue;
529
530 snd_usb_caiaq_maschine_dispatch(dev, buf, urb->actual_length);
531 break;
428 } 532 }
429 533
430requeue: 534requeue:
@@ -444,6 +548,7 @@ static int snd_usb_caiaq_input_open(struct input_dev *idev)
444 switch (dev->chip.usb_id) { 548 switch (dev->chip.usb_id) {
445 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 549 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
446 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): 550 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
551 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
447 if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0) 552 if (usb_submit_urb(dev->ep4_in_urb, GFP_KERNEL) != 0)
448 return -EIO; 553 return -EIO;
449 break; 554 break;
@@ -462,6 +567,7 @@ static void snd_usb_caiaq_input_close(struct input_dev *idev)
462 switch (dev->chip.usb_id) { 567 switch (dev->chip.usb_id) {
463 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1): 568 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLX1):
464 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4): 569 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_TRAKTORKONTROLS4):
570 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
465 usb_kill_urb(dev->ep4_in_urb); 571 usb_kill_urb(dev->ep4_in_urb);
466 break; 572 break;
467 } 573 }
@@ -652,6 +758,50 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
652 758
653 break; 759 break;
654 760
761 case USB_ID(USB_VID_NATIVEINSTRUMENTS, USB_PID_MASCHINECONTROLLER):
762 input->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS);
763 input->absbit[0] = BIT_MASK(ABS_HAT0X) | BIT_MASK(ABS_HAT0Y) |
764 BIT_MASK(ABS_HAT1X) | BIT_MASK(ABS_HAT1Y) |
765 BIT_MASK(ABS_HAT2X) | BIT_MASK(ABS_HAT2Y) |
766 BIT_MASK(ABS_HAT3X) | BIT_MASK(ABS_HAT3Y) |
767 BIT_MASK(ABS_RX) | BIT_MASK(ABS_RY) |
768 BIT_MASK(ABS_RZ);
769
770 BUILD_BUG_ON(sizeof(dev->keycode) < sizeof(keycode_maschine));
771 memcpy(dev->keycode, keycode_maschine, sizeof(keycode_maschine));
772 input->keycodemax = ARRAY_SIZE(keycode_maschine);
773
774 for (i = 0; i < MASCHINE_PADS; i++) {
775 input->absbit[0] |= MASCHINE_PAD(i);
776 input_set_abs_params(input, MASCHINE_PAD(i), 0, 0xfff, 5, 10);
777 }
778
779 input_set_abs_params(input, ABS_HAT0X, 0, 999, 0, 10);
780 input_set_abs_params(input, ABS_HAT0Y, 0, 999, 0, 10);
781 input_set_abs_params(input, ABS_HAT1X, 0, 999, 0, 10);
782 input_set_abs_params(input, ABS_HAT1Y, 0, 999, 0, 10);
783 input_set_abs_params(input, ABS_HAT2X, 0, 999, 0, 10);
784 input_set_abs_params(input, ABS_HAT2Y, 0, 999, 0, 10);
785 input_set_abs_params(input, ABS_HAT3X, 0, 999, 0, 10);
786 input_set_abs_params(input, ABS_HAT3Y, 0, 999, 0, 10);
787 input_set_abs_params(input, ABS_RX, 0, 999, 0, 10);
788 input_set_abs_params(input, ABS_RY, 0, 999, 0, 10);
789 input_set_abs_params(input, ABS_RZ, 0, 999, 0, 10);
790
791 dev->ep4_in_urb = usb_alloc_urb(0, GFP_KERNEL);
792 if (!dev->ep4_in_urb) {
793 ret = -ENOMEM;
794 goto exit_free_idev;
795 }
796
797 usb_fill_bulk_urb(dev->ep4_in_urb, usb_dev,
798 usb_rcvbulkpipe(usb_dev, 0x4),
799 dev->ep4_in_buf, EP4_BUFSIZE,
800 snd_usb_caiaq_ep4_reply_dispatch, dev);
801
802 snd_usb_caiaq_set_auto_msg(dev, 1, 10, 5);
803 break;
804
655 default: 805 default:
656 /* no input methods supported on this device */ 806 /* no input methods supported on this device */
657 goto exit_free_idev; 807 goto exit_free_idev;
@@ -664,15 +814,17 @@ int snd_usb_caiaq_input_init(struct snd_usb_caiaqdev *dev)
664 for (i = 0; i < input->keycodemax; i++) 814 for (i = 0; i < input->keycodemax; i++)
665 __set_bit(dev->keycode[i], input->keybit); 815 __set_bit(dev->keycode[i], input->keybit);
666 816
817 dev->input_dev = input;
818
667 ret = input_register_device(input); 819 ret = input_register_device(input);
668 if (ret < 0) 820 if (ret < 0)
669 goto exit_free_idev; 821 goto exit_free_idev;
670 822
671 dev->input_dev = input;
672 return 0; 823 return 0;
673 824
674exit_free_idev: 825exit_free_idev:
675 input_free_device(input); 826 input_free_device(input);
827 dev->input_dev = NULL;
676 return ret; 828 return ret;
677} 829}
678 830
@@ -688,4 +840,3 @@ void snd_usb_caiaq_input_free(struct snd_usb_caiaqdev *dev)
688 input_unregister_device(dev->input_dev); 840 input_unregister_device(dev->input_dev);
689 dev->input_dev = NULL; 841 dev->input_dev = NULL;
690} 842}
691
diff --git a/sound/usb/card.c b/sound/usb/card.c
index 781d9e61adfb..c1575eafff12 100644
--- a/sound/usb/card.c
+++ b/sound/usb/card.c
@@ -65,9 +65,9 @@
65#include "helper.h" 65#include "helper.h"
66#include "debug.h" 66#include "debug.h"
67#include "pcm.h" 67#include "pcm.h"
68#include "urb.h"
69#include "format.h" 68#include "format.h"
70#include "power.h" 69#include "power.h"
70#include "stream.h"
71 71
72MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>"); 72MODULE_AUTHOR("Takashi Iwai <tiwai@suse.de>");
73MODULE_DESCRIPTION("USB Audio"); 73MODULE_DESCRIPTION("USB Audio");
@@ -185,7 +185,7 @@ static int snd_usb_create_stream(struct snd_usb_audio *chip, int ctrlif, int int
185 return -EINVAL; 185 return -EINVAL;
186 } 186 }
187 187
188 if (! snd_usb_parse_audio_endpoints(chip, interface)) { 188 if (! snd_usb_parse_audio_interface(chip, interface)) {
189 usb_set_interface(dev, interface, 0); /* reset the current interface */ 189 usb_set_interface(dev, interface, 0); /* reset the current interface */
190 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L); 190 usb_driver_claim_interface(&usb_audio_driver, iface, (void *)-1L);
191 return -EINVAL; 191 return -EINVAL;
@@ -530,8 +530,11 @@ snd_usb_audio_probe(struct usb_device *dev,
530 return chip; 530 return chip;
531 531
532 __error: 532 __error:
533 if (chip && !chip->num_interfaces) 533 if (chip) {
534 snd_card_free(chip->card); 534 if (!chip->num_interfaces)
535 snd_card_free(chip->card);
536 chip->probing = 0;
537 }
535 mutex_unlock(&register_mutex); 538 mutex_unlock(&register_mutex);
536 __err_val: 539 __err_val:
537 return NULL; 540 return NULL;
diff --git a/sound/usb/card.h b/sound/usb/card.h
index ae4251d5abf7..a39edcc32a93 100644
--- a/sound/usb/card.h
+++ b/sound/usb/card.h
@@ -94,6 +94,8 @@ struct snd_usb_substream {
94 spinlock_t lock; 94 spinlock_t lock;
95 95
96 struct snd_urb_ops ops; /* callbacks (must be filled at init) */ 96 struct snd_urb_ops ops; /* callbacks (must be filled at init) */
97 int last_frame_number; /* stored frame number */
98 int last_delay; /* stored delay */
97}; 99};
98 100
99struct snd_usb_stream { 101struct snd_usb_stream {
diff --git a/sound/usb/clock.c b/sound/usb/clock.c
index 075195e8661a..379baad3d5ad 100644
--- a/sound/usb/clock.c
+++ b/sound/usb/clock.c
@@ -91,7 +91,7 @@ static int uac_clock_selector_get_val(struct snd_usb_audio *chip, int selector_i
91 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 91 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
92 UAC2_CX_CLOCK_SELECTOR << 8, 92 UAC2_CX_CLOCK_SELECTOR << 8,
93 snd_usb_ctrl_intf(chip) | (selector_id << 8), 93 snd_usb_ctrl_intf(chip) | (selector_id << 8),
94 &buf, sizeof(buf), 1000); 94 &buf, sizeof(buf));
95 95
96 if (ret < 0) 96 if (ret < 0)
97 return ret; 97 return ret;
@@ -118,7 +118,7 @@ static bool uac_clock_source_is_valid(struct snd_usb_audio *chip, int source_id)
118 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 118 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
119 UAC2_CS_CONTROL_CLOCK_VALID << 8, 119 UAC2_CS_CONTROL_CLOCK_VALID << 8,
120 snd_usb_ctrl_intf(chip) | (source_id << 8), 120 snd_usb_ctrl_intf(chip) | (source_id << 8),
121 &data, sizeof(data), 1000); 121 &data, sizeof(data));
122 122
123 if (err < 0) { 123 if (err < 0) {
124 snd_printk(KERN_WARNING "%s(): cannot get clock validity for id %d\n", 124 snd_printk(KERN_WARNING "%s(): cannot get clock validity for id %d\n",
@@ -222,7 +222,7 @@ static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
222 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, 222 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
223 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT, 223 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT,
224 UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, 224 UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep,
225 data, sizeof(data), 1000)) < 0) { 225 data, sizeof(data))) < 0) {
226 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n", 226 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d to ep %#x\n",
227 dev->devnum, iface, fmt->altsetting, rate, ep); 227 dev->devnum, iface, fmt->altsetting, rate, ep);
228 return err; 228 return err;
@@ -231,7 +231,7 @@ static int set_sample_rate_v1(struct snd_usb_audio *chip, int iface,
231 if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR, 231 if ((err = snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), UAC_GET_CUR,
232 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN, 232 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_IN,
233 UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep, 233 UAC_EP_CS_ATTR_SAMPLE_RATE << 8, ep,
234 data, sizeof(data), 1000)) < 0) { 234 data, sizeof(data))) < 0) {
235 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n", 235 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq at ep %#x\n",
236 dev->devnum, iface, fmt->altsetting, ep); 236 dev->devnum, iface, fmt->altsetting, ep);
237 return 0; /* some devices don't support reading */ 237 return 0; /* some devices don't support reading */
@@ -273,7 +273,7 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
273 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT, 273 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_OUT,
274 UAC2_CS_CONTROL_SAM_FREQ << 8, 274 UAC2_CS_CONTROL_SAM_FREQ << 8,
275 snd_usb_ctrl_intf(chip) | (clock << 8), 275 snd_usb_ctrl_intf(chip) | (clock << 8),
276 data, sizeof(data), 1000)) < 0) { 276 data, sizeof(data))) < 0) {
277 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2)\n", 277 snd_printk(KERN_ERR "%d:%d:%d: cannot set freq %d (v2)\n",
278 dev->devnum, iface, fmt->altsetting, rate); 278 dev->devnum, iface, fmt->altsetting, rate);
279 return err; 279 return err;
@@ -283,7 +283,7 @@ static int set_sample_rate_v2(struct snd_usb_audio *chip, int iface,
283 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 283 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
284 UAC2_CS_CONTROL_SAM_FREQ << 8, 284 UAC2_CS_CONTROL_SAM_FREQ << 8,
285 snd_usb_ctrl_intf(chip) | (clock << 8), 285 snd_usb_ctrl_intf(chip) | (clock << 8),
286 data, sizeof(data), 1000)) < 0) { 286 data, sizeof(data))) < 0) {
287 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n", 287 snd_printk(KERN_WARNING "%d:%d:%d: cannot get freq (v2)\n",
288 dev->devnum, iface, fmt->altsetting); 288 dev->devnum, iface, fmt->altsetting);
289 return err; 289 return err;
diff --git a/sound/usb/endpoint.c b/sound/usb/endpoint.c
index 7c0d21ecd821..81c6edecd862 100644
--- a/sound/usb/endpoint.c
+++ b/sound/usb/endpoint.c
@@ -15,436 +15,951 @@
15 * 15 *
16 */ 16 */
17 17
18#include <linux/gfp.h>
18#include <linux/init.h> 19#include <linux/init.h>
19#include <linux/slab.h>
20#include <linux/usb.h> 20#include <linux/usb.h>
21#include <linux/usb/audio.h> 21#include <linux/usb/audio.h>
22#include <linux/usb/audio-v2.h>
23 22
24#include <sound/core.h> 23#include <sound/core.h>
25#include <sound/pcm.h> 24#include <sound/pcm.h>
26 25
27#include "usbaudio.h" 26#include "usbaudio.h"
27#include "helper.h"
28#include "card.h" 28#include "card.h"
29#include "proc.h"
30#include "quirks.h"
31#include "endpoint.h" 29#include "endpoint.h"
32#include "urb.h"
33#include "pcm.h" 30#include "pcm.h"
34#include "helper.h"
35#include "format.h"
36#include "clock.h"
37 31
38/* 32/*
39 * free a substream 33 * convert a sampling rate into our full speed format (fs/1000 in Q16.16)
34 * this will overflow at approx 524 kHz
40 */ 35 */
41static void free_substream(struct snd_usb_substream *subs) 36static inline unsigned get_usb_full_speed_rate(unsigned int rate)
42{ 37{
43 struct list_head *p, *n; 38 return ((rate << 13) + 62) / 125;
44
45 if (!subs->num_formats)
46 return; /* not initialized */
47 list_for_each_safe(p, n, &subs->fmt_list) {
48 struct audioformat *fp = list_entry(p, struct audioformat, list);
49 kfree(fp->rate_table);
50 kfree(fp);
51 }
52 kfree(subs->rate_list.list);
53} 39}
54 40
41/*
42 * convert a sampling rate into USB high speed format (fs/8000 in Q16.16)
43 * this will overflow at approx 4 MHz
44 */
45static inline unsigned get_usb_high_speed_rate(unsigned int rate)
46{
47 return ((rate << 10) + 62) / 125;
48}
55 49
56/* 50/*
57 * free a usb stream instance 51 * unlink active urbs.
58 */ 52 */
59static void snd_usb_audio_stream_free(struct snd_usb_stream *stream) 53static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sleep)
60{ 54{
61 free_substream(&stream->substream[0]); 55 struct snd_usb_audio *chip = subs->stream->chip;
62 free_substream(&stream->substream[1]); 56 unsigned int i;
63 list_del(&stream->list); 57 int async;
64 kfree(stream); 58
59 subs->running = 0;
60
61 if (!force && subs->stream->chip->shutdown) /* to be sure... */
62 return -EBADFD;
63
64 async = !can_sleep && chip->async_unlink;
65
66 if (!async && in_interrupt())
67 return 0;
68
69 for (i = 0; i < subs->nurbs; i++) {
70 if (test_bit(i, &subs->active_mask)) {
71 if (!test_and_set_bit(i, &subs->unlink_mask)) {
72 struct urb *u = subs->dataurb[i].urb;
73 if (async)
74 usb_unlink_urb(u);
75 else
76 usb_kill_urb(u);
77 }
78 }
79 }
80 if (subs->syncpipe) {
81 for (i = 0; i < SYNC_URBS; i++) {
82 if (test_bit(i+16, &subs->active_mask)) {
83 if (!test_and_set_bit(i+16, &subs->unlink_mask)) {
84 struct urb *u = subs->syncurb[i].urb;
85 if (async)
86 usb_unlink_urb(u);
87 else
88 usb_kill_urb(u);
89 }
90 }
91 }
92 }
93 return 0;
65} 94}
66 95
67static void snd_usb_audio_pcm_free(struct snd_pcm *pcm) 96
97/*
98 * release a urb data
99 */
100static void release_urb_ctx(struct snd_urb_ctx *u)
68{ 101{
69 struct snd_usb_stream *stream = pcm->private_data; 102 if (u->urb) {
70 if (stream) { 103 if (u->buffer_size)
71 stream->pcm = NULL; 104 usb_free_coherent(u->subs->dev, u->buffer_size,
72 snd_usb_audio_stream_free(stream); 105 u->urb->transfer_buffer,
106 u->urb->transfer_dma);
107 usb_free_urb(u->urb);
108 u->urb = NULL;
73 } 109 }
74} 110}
75 111
112/*
113 * wait until all urbs are processed.
114 */
115static int wait_clear_urbs(struct snd_usb_substream *subs)
116{
117 unsigned long end_time = jiffies + msecs_to_jiffies(1000);
118 unsigned int i;
119 int alive;
120
121 do {
122 alive = 0;
123 for (i = 0; i < subs->nurbs; i++) {
124 if (test_bit(i, &subs->active_mask))
125 alive++;
126 }
127 if (subs->syncpipe) {
128 for (i = 0; i < SYNC_URBS; i++) {
129 if (test_bit(i + 16, &subs->active_mask))
130 alive++;
131 }
132 }
133 if (! alive)
134 break;
135 schedule_timeout_uninterruptible(1);
136 } while (time_before(jiffies, end_time));
137 if (alive)
138 snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive);
139 return 0;
140}
76 141
77/* 142/*
78 * add this endpoint to the chip instance. 143 * release a substream
79 * if a stream with the same endpoint already exists, append to it.
80 * if not, create a new pcm stream.
81 */ 144 */
82int snd_usb_add_audio_endpoint(struct snd_usb_audio *chip, int stream, struct audioformat *fp) 145void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force)
83{ 146{
84 struct list_head *p; 147 int i;
85 struct snd_usb_stream *as; 148
86 struct snd_usb_substream *subs; 149 /* stop urbs (to be sure) */
87 struct snd_pcm *pcm; 150 deactivate_urbs(subs, force, 1);
88 int err; 151 wait_clear_urbs(subs);
152
153 for (i = 0; i < MAX_URBS; i++)
154 release_urb_ctx(&subs->dataurb[i]);
155 for (i = 0; i < SYNC_URBS; i++)
156 release_urb_ctx(&subs->syncurb[i]);
157 usb_free_coherent(subs->dev, SYNC_URBS * 4,
158 subs->syncbuf, subs->sync_dma);
159 subs->syncbuf = NULL;
160 subs->nurbs = 0;
161}
89 162
90 list_for_each(p, &chip->pcm_list) { 163/*
91 as = list_entry(p, struct snd_usb_stream, list); 164 * complete callback from data urb
92 if (as->fmt_type != fp->fmt_type) 165 */
93 continue; 166static void snd_complete_urb(struct urb *urb)
94 subs = &as->substream[stream]; 167{
95 if (!subs->endpoint) 168 struct snd_urb_ctx *ctx = urb->context;
96 continue; 169 struct snd_usb_substream *subs = ctx->subs;
97 if (subs->endpoint == fp->endpoint) { 170 struct snd_pcm_substream *substream = ctx->subs->pcm_substream;
98 list_add_tail(&fp->list, &subs->fmt_list); 171 int err = 0;
99 subs->num_formats++; 172
100 subs->formats |= fp->formats; 173 if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) ||
101 return 0; 174 !subs->running || /* can be stopped during retire callback */
175 (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 ||
176 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
177 clear_bit(ctx->index, &subs->active_mask);
178 if (err < 0) {
179 snd_printd(KERN_ERR "cannot submit urb (err = %d)\n", err);
180 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
102 } 181 }
103 } 182 }
104 /* look for an empty stream */ 183}
105 list_for_each(p, &chip->pcm_list) { 184
106 as = list_entry(p, struct snd_usb_stream, list); 185
107 if (as->fmt_type != fp->fmt_type) 186/*
108 continue; 187 * complete callback from sync urb
109 subs = &as->substream[stream]; 188 */
110 if (subs->endpoint) 189static void snd_complete_sync_urb(struct urb *urb)
111 continue; 190{
112 err = snd_pcm_new_stream(as->pcm, stream, 1); 191 struct snd_urb_ctx *ctx = urb->context;
113 if (err < 0) 192 struct snd_usb_substream *subs = ctx->subs;
114 return err; 193 struct snd_pcm_substream *substream = ctx->subs->pcm_substream;
115 snd_usb_init_substream(as, stream, fp); 194 int err = 0;
116 return 0; 195
196 if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) ||
197 !subs->running || /* can be stopped during retire callback */
198 (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 ||
199 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
200 clear_bit(ctx->index + 16, &subs->active_mask);
201 if (err < 0) {
202 snd_printd(KERN_ERR "cannot submit sync urb (err = %d)\n", err);
203 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
204 }
117 } 205 }
206}
207
118 208
119 /* create a new pcm */ 209/*
120 as = kzalloc(sizeof(*as), GFP_KERNEL); 210 * initialize a substream for plaback/capture
121 if (!as) 211 */
122 return -ENOMEM; 212int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
123 as->pcm_index = chip->pcm_devs; 213 unsigned int period_bytes,
124 as->chip = chip; 214 unsigned int rate,
125 as->fmt_type = fp->fmt_type; 215 unsigned int frame_bits)
126 err = snd_pcm_new(chip->card, "USB Audio", chip->pcm_devs, 216{
127 stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : 0, 217 unsigned int maxsize, i;
128 stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1, 218 int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
129 &pcm); 219 unsigned int urb_packs, total_packs, packs_per_ms;
130 if (err < 0) { 220 struct snd_usb_audio *chip = subs->stream->chip;
131 kfree(as); 221
132 return err; 222 /* calculate the frequency in 16.16 format */
223 if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL)
224 subs->freqn = get_usb_full_speed_rate(rate);
225 else
226 subs->freqn = get_usb_high_speed_rate(rate);
227 subs->freqm = subs->freqn;
228 subs->freqshift = INT_MIN;
229 /* calculate max. frequency */
230 if (subs->maxpacksize) {
231 /* whatever fits into a max. size packet */
232 maxsize = subs->maxpacksize;
233 subs->freqmax = (maxsize / (frame_bits >> 3))
234 << (16 - subs->datainterval);
235 } else {
236 /* no max. packet size: just take 25% higher than nominal */
237 subs->freqmax = subs->freqn + (subs->freqn >> 2);
238 maxsize = ((subs->freqmax + 0xffff) * (frame_bits >> 3))
239 >> (16 - subs->datainterval);
133 } 240 }
134 as->pcm = pcm; 241 subs->phase = 0;
135 pcm->private_data = as; 242
136 pcm->private_free = snd_usb_audio_pcm_free; 243 if (subs->fill_max)
137 pcm->info_flags = 0; 244 subs->curpacksize = subs->maxpacksize;
138 if (chip->pcm_devs > 0)
139 sprintf(pcm->name, "USB Audio #%d", chip->pcm_devs);
140 else 245 else
141 strcpy(pcm->name, "USB Audio"); 246 subs->curpacksize = maxsize;
142 247
143 snd_usb_init_substream(as, stream, fp); 248 if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL)
249 packs_per_ms = 8 >> subs->datainterval;
250 else
251 packs_per_ms = 1;
252
253 if (is_playback) {
254 urb_packs = max(chip->nrpacks, 1);
255 urb_packs = min(urb_packs, (unsigned int)MAX_PACKS);
256 } else
257 urb_packs = 1;
258 urb_packs *= packs_per_ms;
259 if (subs->syncpipe)
260 urb_packs = min(urb_packs, 1U << subs->syncinterval);
261
262 /* decide how many packets to be used */
263 if (is_playback) {
264 unsigned int minsize, maxpacks;
265 /* determine how small a packet can be */
266 minsize = (subs->freqn >> (16 - subs->datainterval))
267 * (frame_bits >> 3);
268 /* with sync from device, assume it can be 12% lower */
269 if (subs->syncpipe)
270 minsize -= minsize >> 3;
271 minsize = max(minsize, 1u);
272 total_packs = (period_bytes + minsize - 1) / minsize;
273 /* we need at least two URBs for queueing */
274 if (total_packs < 2) {
275 total_packs = 2;
276 } else {
277 /* and we don't want too long a queue either */
278 maxpacks = max(MAX_QUEUE * packs_per_ms, urb_packs * 2);
279 total_packs = min(total_packs, maxpacks);
280 }
281 } else {
282 while (urb_packs > 1 && urb_packs * maxsize >= period_bytes)
283 urb_packs >>= 1;
284 total_packs = MAX_URBS * urb_packs;
285 }
286 subs->nurbs = (total_packs + urb_packs - 1) / urb_packs;
287 if (subs->nurbs > MAX_URBS) {
288 /* too much... */
289 subs->nurbs = MAX_URBS;
290 total_packs = MAX_URBS * urb_packs;
291 } else if (subs->nurbs < 2) {
292 /* too little - we need at least two packets
293 * to ensure contiguous playback/capture
294 */
295 subs->nurbs = 2;
296 }
144 297
145 list_add(&as->list, &chip->pcm_list); 298 /* allocate and initialize data urbs */
146 chip->pcm_devs++; 299 for (i = 0; i < subs->nurbs; i++) {
300 struct snd_urb_ctx *u = &subs->dataurb[i];
301 u->index = i;
302 u->subs = subs;
303 u->packets = (i + 1) * total_packs / subs->nurbs
304 - i * total_packs / subs->nurbs;
305 u->buffer_size = maxsize * u->packets;
306 if (subs->fmt_type == UAC_FORMAT_TYPE_II)
307 u->packets++; /* for transfer delimiter */
308 u->urb = usb_alloc_urb(u->packets, GFP_KERNEL);
309 if (!u->urb)
310 goto out_of_memory;
311 u->urb->transfer_buffer =
312 usb_alloc_coherent(subs->dev, u->buffer_size,
313 GFP_KERNEL, &u->urb->transfer_dma);
314 if (!u->urb->transfer_buffer)
315 goto out_of_memory;
316 u->urb->pipe = subs->datapipe;
317 u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
318 u->urb->interval = 1 << subs->datainterval;
319 u->urb->context = u;
320 u->urb->complete = snd_complete_urb;
321 }
322
323 if (subs->syncpipe) {
324 /* allocate and initialize sync urbs */
325 subs->syncbuf = usb_alloc_coherent(subs->dev, SYNC_URBS * 4,
326 GFP_KERNEL, &subs->sync_dma);
327 if (!subs->syncbuf)
328 goto out_of_memory;
329 for (i = 0; i < SYNC_URBS; i++) {
330 struct snd_urb_ctx *u = &subs->syncurb[i];
331 u->index = i;
332 u->subs = subs;
333 u->packets = 1;
334 u->urb = usb_alloc_urb(1, GFP_KERNEL);
335 if (!u->urb)
336 goto out_of_memory;
337 u->urb->transfer_buffer = subs->syncbuf + i * 4;
338 u->urb->transfer_dma = subs->sync_dma + i * 4;
339 u->urb->transfer_buffer_length = 4;
340 u->urb->pipe = subs->syncpipe;
341 u->urb->transfer_flags = URB_ISO_ASAP |
342 URB_NO_TRANSFER_DMA_MAP;
343 u->urb->number_of_packets = 1;
344 u->urb->interval = 1 << subs->syncinterval;
345 u->urb->context = u;
346 u->urb->complete = snd_complete_sync_urb;
347 }
348 }
349 return 0;
147 350
148 snd_usb_proc_pcm_format_add(as); 351out_of_memory:
352 snd_usb_release_substream_urbs(subs, 0);
353 return -ENOMEM;
354}
149 355
356/*
357 * prepare urb for full speed capture sync pipe
358 *
359 * fill the length and offset of each urb descriptor.
360 * the fixed 10.14 frequency is passed through the pipe.
361 */
362static int prepare_capture_sync_urb(struct snd_usb_substream *subs,
363 struct snd_pcm_runtime *runtime,
364 struct urb *urb)
365{
366 unsigned char *cp = urb->transfer_buffer;
367 struct snd_urb_ctx *ctx = urb->context;
368
369 urb->dev = ctx->subs->dev; /* we need to set this at each time */
370 urb->iso_frame_desc[0].length = 3;
371 urb->iso_frame_desc[0].offset = 0;
372 cp[0] = subs->freqn >> 2;
373 cp[1] = subs->freqn >> 10;
374 cp[2] = subs->freqn >> 18;
150 return 0; 375 return 0;
151} 376}
152 377
153static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip, 378/*
154 struct usb_host_interface *alts, 379 * prepare urb for high speed capture sync pipe
155 int protocol, int iface_no) 380 *
381 * fill the length and offset of each urb descriptor.
382 * the fixed 12.13 frequency is passed as 16.16 through the pipe.
383 */
384static int prepare_capture_sync_urb_hs(struct snd_usb_substream *subs,
385 struct snd_pcm_runtime *runtime,
386 struct urb *urb)
156{ 387{
157 /* parsed with a v1 header here. that's ok as we only look at the 388 unsigned char *cp = urb->transfer_buffer;
158 * header first which is the same for both versions */ 389 struct snd_urb_ctx *ctx = urb->context;
159 struct uac_iso_endpoint_descriptor *csep; 390
160 struct usb_interface_descriptor *altsd = get_iface_desc(alts); 391 urb->dev = ctx->subs->dev; /* we need to set this at each time */
161 int attributes = 0; 392 urb->iso_frame_desc[0].length = 4;
162 393 urb->iso_frame_desc[0].offset = 0;
163 csep = snd_usb_find_desc(alts->endpoint[0].extra, alts->endpoint[0].extralen, NULL, USB_DT_CS_ENDPOINT); 394 cp[0] = subs->freqn;
164 395 cp[1] = subs->freqn >> 8;
165 /* Creamware Noah has this descriptor after the 2nd endpoint */ 396 cp[2] = subs->freqn >> 16;
166 if (!csep && altsd->bNumEndpoints >= 2) 397 cp[3] = subs->freqn >> 24;
167 csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT); 398 return 0;
168 399}
169 if (!csep || csep->bLength < 7 ||
170 csep->bDescriptorSubtype != UAC_EP_GENERAL) {
171 snd_printk(KERN_WARNING "%d:%u:%d : no or invalid"
172 " class specific endpoint descriptor\n",
173 chip->dev->devnum, iface_no,
174 altsd->bAlternateSetting);
175 return 0;
176 }
177 400
178 if (protocol == UAC_VERSION_1) { 401/*
179 attributes = csep->bmAttributes; 402 * process after capture sync complete
180 } else { 403 * - nothing to do
181 struct uac2_iso_endpoint_descriptor *csep2 = 404 */
182 (struct uac2_iso_endpoint_descriptor *) csep; 405static int retire_capture_sync_urb(struct snd_usb_substream *subs,
406 struct snd_pcm_runtime *runtime,
407 struct urb *urb)
408{
409 return 0;
410}
183 411
184 attributes = csep->bmAttributes & UAC_EP_CS_ATTR_FILL_MAX; 412/*
413 * prepare urb for capture data pipe
414 *
415 * fill the offset and length of each descriptor.
416 *
417 * we use a temporary buffer to write the captured data.
418 * since the length of written data is determined by host, we cannot
419 * write onto the pcm buffer directly... the data is thus copied
420 * later at complete callback to the global buffer.
421 */
422static int prepare_capture_urb(struct snd_usb_substream *subs,
423 struct snd_pcm_runtime *runtime,
424 struct urb *urb)
425{
426 int i, offs;
427 struct snd_urb_ctx *ctx = urb->context;
428
429 offs = 0;
430 urb->dev = ctx->subs->dev; /* we need to set this at each time */
431 for (i = 0; i < ctx->packets; i++) {
432 urb->iso_frame_desc[i].offset = offs;
433 urb->iso_frame_desc[i].length = subs->curpacksize;
434 offs += subs->curpacksize;
435 }
436 urb->transfer_buffer_length = offs;
437 urb->number_of_packets = ctx->packets;
438 return 0;
439}
185 440
186 /* emulate the endpoint attributes of a v1 device */ 441/*
187 if (csep2->bmControls & UAC2_CONTROL_PITCH) 442 * process after capture complete
188 attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL; 443 *
444 * copy the data from each desctiptor to the pcm buffer, and
445 * update the current position.
446 */
447static int retire_capture_urb(struct snd_usb_substream *subs,
448 struct snd_pcm_runtime *runtime,
449 struct urb *urb)
450{
451 unsigned long flags;
452 unsigned char *cp;
453 int i;
454 unsigned int stride, frames, bytes, oldptr;
455 int period_elapsed = 0;
456
457 stride = runtime->frame_bits >> 3;
458
459 for (i = 0; i < urb->number_of_packets; i++) {
460 cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset;
461 if (urb->iso_frame_desc[i].status) {
462 snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status);
463 // continue;
464 }
465 bytes = urb->iso_frame_desc[i].actual_length;
466 frames = bytes / stride;
467 if (!subs->txfr_quirk)
468 bytes = frames * stride;
469 if (bytes % (runtime->sample_bits >> 3) != 0) {
470#ifdef CONFIG_SND_DEBUG_VERBOSE
471 int oldbytes = bytes;
472#endif
473 bytes = frames * stride;
474 snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n",
475 oldbytes, bytes);
476 }
477 /* update the current pointer */
478 spin_lock_irqsave(&subs->lock, flags);
479 oldptr = subs->hwptr_done;
480 subs->hwptr_done += bytes;
481 if (subs->hwptr_done >= runtime->buffer_size * stride)
482 subs->hwptr_done -= runtime->buffer_size * stride;
483 frames = (bytes + (oldptr % stride)) / stride;
484 subs->transfer_done += frames;
485 if (subs->transfer_done >= runtime->period_size) {
486 subs->transfer_done -= runtime->period_size;
487 period_elapsed = 1;
488 }
489 spin_unlock_irqrestore(&subs->lock, flags);
490 /* copy a data chunk */
491 if (oldptr + bytes > runtime->buffer_size * stride) {
492 unsigned int bytes1 =
493 runtime->buffer_size * stride - oldptr;
494 memcpy(runtime->dma_area + oldptr, cp, bytes1);
495 memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1);
496 } else {
497 memcpy(runtime->dma_area + oldptr, cp, bytes);
498 }
189 } 499 }
500 if (period_elapsed)
501 snd_pcm_period_elapsed(subs->pcm_substream);
502 return 0;
503}
190 504
191 return attributes; 505/*
506 * Process after capture complete when paused. Nothing to do.
507 */
508static int retire_paused_capture_urb(struct snd_usb_substream *subs,
509 struct snd_pcm_runtime *runtime,
510 struct urb *urb)
511{
512 return 0;
192} 513}
193 514
194static struct uac2_input_terminal_descriptor * 515
195 snd_usb_find_input_terminal_descriptor(struct usb_host_interface *ctrl_iface, 516/*
196 int terminal_id) 517 * prepare urb for playback sync pipe
518 *
519 * set up the offset and length to receive the current frequency.
520 */
521static int prepare_playback_sync_urb(struct snd_usb_substream *subs,
522 struct snd_pcm_runtime *runtime,
523 struct urb *urb)
197{ 524{
198 struct uac2_input_terminal_descriptor *term = NULL; 525 struct snd_urb_ctx *ctx = urb->context;
526
527 urb->dev = ctx->subs->dev; /* we need to set this at each time */
528 urb->iso_frame_desc[0].length = min(4u, ctx->subs->syncmaxsize);
529 urb->iso_frame_desc[0].offset = 0;
530 return 0;
531}
199 532
200 while ((term = snd_usb_find_csint_desc(ctrl_iface->extra, 533/*
201 ctrl_iface->extralen, 534 * process after playback sync complete
202 term, UAC_INPUT_TERMINAL))) { 535 *
203 if (term->bTerminalID == terminal_id) 536 * Full speed devices report feedback values in 10.14 format as samples per
204 return term; 537 * frame, high speed devices in 16.16 format as samples per microframe.
538 * Because the Audio Class 1 spec was written before USB 2.0, many high speed
539 * devices use a wrong interpretation, some others use an entirely different
540 * format. Therefore, we cannot predict what format any particular device uses
541 * and must detect it automatically.
542 */
543static int retire_playback_sync_urb(struct snd_usb_substream *subs,
544 struct snd_pcm_runtime *runtime,
545 struct urb *urb)
546{
547 unsigned int f;
548 int shift;
549 unsigned long flags;
550
551 if (urb->iso_frame_desc[0].status != 0 ||
552 urb->iso_frame_desc[0].actual_length < 3)
553 return 0;
554
555 f = le32_to_cpup(urb->transfer_buffer);
556 if (urb->iso_frame_desc[0].actual_length == 3)
557 f &= 0x00ffffff;
558 else
559 f &= 0x0fffffff;
560 if (f == 0)
561 return 0;
562
563 if (unlikely(subs->freqshift == INT_MIN)) {
564 /*
565 * The first time we see a feedback value, determine its format
566 * by shifting it left or right until it matches the nominal
567 * frequency value. This assumes that the feedback does not
568 * differ from the nominal value more than +50% or -25%.
569 */
570 shift = 0;
571 while (f < subs->freqn - subs->freqn / 4) {
572 f <<= 1;
573 shift++;
574 }
575 while (f > subs->freqn + subs->freqn / 2) {
576 f >>= 1;
577 shift--;
578 }
579 subs->freqshift = shift;
580 }
581 else if (subs->freqshift >= 0)
582 f <<= subs->freqshift;
583 else
584 f >>= -subs->freqshift;
585
586 if (likely(f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax)) {
587 /*
588 * If the frequency looks valid, set it.
589 * This value is referred to in prepare_playback_urb().
590 */
591 spin_lock_irqsave(&subs->lock, flags);
592 subs->freqm = f;
593 spin_unlock_irqrestore(&subs->lock, flags);
594 } else {
595 /*
596 * Out of range; maybe the shift value is wrong.
597 * Reset it so that we autodetect again the next time.
598 */
599 subs->freqshift = INT_MIN;
205 } 600 }
206 601
207 return NULL; 602 return 0;
208} 603}
209 604
210static struct uac2_output_terminal_descriptor * 605/* determine the number of frames in the next packet */
211 snd_usb_find_output_terminal_descriptor(struct usb_host_interface *ctrl_iface, 606static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs)
212 int terminal_id)
213{ 607{
214 struct uac2_output_terminal_descriptor *term = NULL; 608 if (subs->fill_max)
215 609 return subs->maxframesize;
216 while ((term = snd_usb_find_csint_desc(ctrl_iface->extra, 610 else {
217 ctrl_iface->extralen, 611 subs->phase = (subs->phase & 0xffff)
218 term, UAC_OUTPUT_TERMINAL))) { 612 + (subs->freqm << subs->datainterval);
219 if (term->bTerminalID == terminal_id) 613 return min(subs->phase >> 16, subs->maxframesize);
220 return term;
221 } 614 }
615}
222 616
223 return NULL; 617/*
618 * Prepare urb for streaming before playback starts or when paused.
619 *
620 * We don't have any data, so we send silence.
621 */
622static int prepare_nodata_playback_urb(struct snd_usb_substream *subs,
623 struct snd_pcm_runtime *runtime,
624 struct urb *urb)
625{
626 unsigned int i, offs, counts;
627 struct snd_urb_ctx *ctx = urb->context;
628 int stride = runtime->frame_bits >> 3;
629
630 offs = 0;
631 urb->dev = ctx->subs->dev;
632 for (i = 0; i < ctx->packets; ++i) {
633 counts = snd_usb_audio_next_packet_size(subs);
634 urb->iso_frame_desc[i].offset = offs * stride;
635 urb->iso_frame_desc[i].length = counts * stride;
636 offs += counts;
637 }
638 urb->number_of_packets = ctx->packets;
639 urb->transfer_buffer_length = offs * stride;
640 memset(urb->transfer_buffer,
641 runtime->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0,
642 offs * stride);
643 return 0;
224} 644}
225 645
226int snd_usb_parse_audio_endpoints(struct snd_usb_audio *chip, int iface_no) 646/*
647 * prepare urb for playback data pipe
648 *
649 * Since a URB can handle only a single linear buffer, we must use double
650 * buffering when the data to be transferred overflows the buffer boundary.
651 * To avoid inconsistencies when updating hwptr_done, we use double buffering
652 * for all URBs.
653 */
654static int prepare_playback_urb(struct snd_usb_substream *subs,
655 struct snd_pcm_runtime *runtime,
656 struct urb *urb)
227{ 657{
228 struct usb_device *dev; 658 int i, stride;
229 struct usb_interface *iface; 659 unsigned int counts, frames, bytes;
230 struct usb_host_interface *alts; 660 unsigned long flags;
231 struct usb_interface_descriptor *altsd; 661 int period_elapsed = 0;
232 int i, altno, err, stream; 662 struct snd_urb_ctx *ctx = urb->context;
233 int format = 0, num_channels = 0; 663
234 struct audioformat *fp = NULL; 664 stride = runtime->frame_bits >> 3;
235 int num, protocol, clock = 0; 665
236 struct uac_format_type_i_continuous_descriptor *fmt; 666 frames = 0;
667 urb->dev = ctx->subs->dev; /* we need to set this at each time */
668 urb->number_of_packets = 0;
669 spin_lock_irqsave(&subs->lock, flags);
670 for (i = 0; i < ctx->packets; i++) {
671 counts = snd_usb_audio_next_packet_size(subs);
672 /* set up descriptor */
673 urb->iso_frame_desc[i].offset = frames * stride;
674 urb->iso_frame_desc[i].length = counts * stride;
675 frames += counts;
676 urb->number_of_packets++;
677 subs->transfer_done += counts;
678 if (subs->transfer_done >= runtime->period_size) {
679 subs->transfer_done -= runtime->period_size;
680 period_elapsed = 1;
681 if (subs->fmt_type == UAC_FORMAT_TYPE_II) {
682 if (subs->transfer_done > 0) {
683 /* FIXME: fill-max mode is not
684 * supported yet */
685 frames -= subs->transfer_done;
686 counts -= subs->transfer_done;
687 urb->iso_frame_desc[i].length =
688 counts * stride;
689 subs->transfer_done = 0;
690 }
691 i++;
692 if (i < ctx->packets) {
693 /* add a transfer delimiter */
694 urb->iso_frame_desc[i].offset =
695 frames * stride;
696 urb->iso_frame_desc[i].length = 0;
697 urb->number_of_packets++;
698 }
699 break;
700 }
701 }
702 if (period_elapsed) /* finish at the period boundary */
703 break;
704 }
705 bytes = frames * stride;
706 if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
707 /* err, the transferred area goes over buffer boundary. */
708 unsigned int bytes1 =
709 runtime->buffer_size * stride - subs->hwptr_done;
710 memcpy(urb->transfer_buffer,
711 runtime->dma_area + subs->hwptr_done, bytes1);
712 memcpy(urb->transfer_buffer + bytes1,
713 runtime->dma_area, bytes - bytes1);
714 } else {
715 memcpy(urb->transfer_buffer,
716 runtime->dma_area + subs->hwptr_done, bytes);
717 }
718 subs->hwptr_done += bytes;
719 if (subs->hwptr_done >= runtime->buffer_size * stride)
720 subs->hwptr_done -= runtime->buffer_size * stride;
721
722 /* update delay with exact number of samples queued */
723 runtime->delay = subs->last_delay;
724 runtime->delay += frames;
725 subs->last_delay = runtime->delay;
726
727 /* realign last_frame_number */
728 subs->last_frame_number = usb_get_current_frame_number(subs->dev);
729 subs->last_frame_number &= 0xFF; /* keep 8 LSBs */
730
731 spin_unlock_irqrestore(&subs->lock, flags);
732 urb->transfer_buffer_length = bytes;
733 if (period_elapsed)
734 snd_pcm_period_elapsed(subs->pcm_substream);
735 return 0;
736}
237 737
238 dev = chip->dev; 738/*
739 * process after playback data complete
740 * - decrease the delay count again
741 */
742static int retire_playback_urb(struct snd_usb_substream *subs,
743 struct snd_pcm_runtime *runtime,
744 struct urb *urb)
745{
746 unsigned long flags;
747 int stride = runtime->frame_bits >> 3;
748 int processed = urb->transfer_buffer_length / stride;
749 int est_delay;
239 750
240 /* parse the interface's altsettings */ 751 spin_lock_irqsave(&subs->lock, flags);
241 iface = usb_ifnum_to_if(dev, iface_no);
242 752
243 num = iface->num_altsetting; 753 est_delay = snd_usb_pcm_delay(subs, runtime->rate);
754 /* update delay with exact number of samples played */
755 if (processed > subs->last_delay)
756 subs->last_delay = 0;
757 else
758 subs->last_delay -= processed;
759 runtime->delay = subs->last_delay;
244 760
245 /* 761 /*
246 * Dallas DS4201 workaround: It presents 5 altsettings, but the last 762 * Report when delay estimate is off by more than 2ms.
247 * one misses syncpipe, and does not produce any sound. 763 * The error should be lower than 2ms since the estimate relies
764 * on two reads of a counter updated every ms.
248 */ 765 */
249 if (chip->usb_id == USB_ID(0x04fa, 0x4201)) 766 if (abs(est_delay - subs->last_delay) * 1000 > runtime->rate * 2)
250 num = 4; 767 snd_printk(KERN_DEBUG "delay: estimated %d, actual %d\n",
251 768 est_delay, subs->last_delay);
252 for (i = 0; i < num; i++) {
253 alts = &iface->altsetting[i];
254 altsd = get_iface_desc(alts);
255 protocol = altsd->bInterfaceProtocol;
256 /* skip invalid one */
257 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
258 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
259 (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING &&
260 altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) ||
261 altsd->bNumEndpoints < 1 ||
262 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0)
263 continue;
264 /* must be isochronous */
265 if ((get_endpoint(alts, 0)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
266 USB_ENDPOINT_XFER_ISOC)
267 continue;
268 /* check direction */
269 stream = (get_endpoint(alts, 0)->bEndpointAddress & USB_DIR_IN) ?
270 SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
271 altno = altsd->bAlternateSetting;
272
273 if (snd_usb_apply_interface_quirk(chip, iface_no, altno))
274 continue;
275
276 /* get audio formats */
277 switch (protocol) {
278 default:
279 snd_printdd(KERN_WARNING "%d:%u:%d: unknown interface protocol %#02x, assuming v1\n",
280 dev->devnum, iface_no, altno, protocol);
281 protocol = UAC_VERSION_1;
282 /* fall through */
283
284 case UAC_VERSION_1: {
285 struct uac1_as_header_descriptor *as =
286 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
287
288 if (!as) {
289 snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
290 dev->devnum, iface_no, altno);
291 continue;
292 }
293 769
294 if (as->bLength < sizeof(*as)) { 770 spin_unlock_irqrestore(&subs->lock, flags);
295 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n", 771 return 0;
296 dev->devnum, iface_no, altno); 772}
297 continue;
298 }
299 773
300 format = le16_to_cpu(as->wFormatTag); /* remember the format value */ 774static const char *usb_error_string(int err)
301 break; 775{
302 } 776 switch (err) {
777 case -ENODEV:
778 return "no device";
779 case -ENOENT:
780 return "endpoint not enabled";
781 case -EPIPE:
782 return "endpoint stalled";
783 case -ENOSPC:
784 return "not enough bandwidth";
785 case -ESHUTDOWN:
786 return "device disabled";
787 case -EHOSTUNREACH:
788 return "device suspended";
789 case -EINVAL:
790 case -EAGAIN:
791 case -EFBIG:
792 case -EMSGSIZE:
793 return "internal error";
794 default:
795 return "unknown error";
796 }
797}
303 798
304 case UAC_VERSION_2: { 799/*
305 struct uac2_input_terminal_descriptor *input_term; 800 * set up and start data/sync urbs
306 struct uac2_output_terminal_descriptor *output_term; 801 */
307 struct uac2_as_header_descriptor *as = 802static int start_urbs(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime)
308 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL); 803{
804 unsigned int i;
805 int err;
309 806
310 if (!as) { 807 if (subs->stream->chip->shutdown)
311 snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n", 808 return -EBADFD;
312 dev->devnum, iface_no, altno); 809
313 continue; 810 for (i = 0; i < subs->nurbs; i++) {
811 if (snd_BUG_ON(!subs->dataurb[i].urb))
812 return -EINVAL;
813 if (subs->ops.prepare(subs, runtime, subs->dataurb[i].urb) < 0) {
814 snd_printk(KERN_ERR "cannot prepare datapipe for urb %d\n", i);
815 goto __error;
816 }
817 }
818 if (subs->syncpipe) {
819 for (i = 0; i < SYNC_URBS; i++) {
820 if (snd_BUG_ON(!subs->syncurb[i].urb))
821 return -EINVAL;
822 if (subs->ops.prepare_sync(subs, runtime, subs->syncurb[i].urb) < 0) {
823 snd_printk(KERN_ERR "cannot prepare syncpipe for urb %d\n", i);
824 goto __error;
314 } 825 }
826 }
827 }
315 828
316 if (as->bLength < sizeof(*as)) { 829 subs->active_mask = 0;
317 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n", 830 subs->unlink_mask = 0;
318 dev->devnum, iface_no, altno); 831 subs->running = 1;
319 continue; 832 for (i = 0; i < subs->nurbs; i++) {
833 err = usb_submit_urb(subs->dataurb[i].urb, GFP_ATOMIC);
834 if (err < 0) {
835 snd_printk(KERN_ERR "cannot submit datapipe "
836 "for urb %d, error %d: %s\n",
837 i, err, usb_error_string(err));
838 goto __error;
839 }
840 set_bit(i, &subs->active_mask);
841 }
842 if (subs->syncpipe) {
843 for (i = 0; i < SYNC_URBS; i++) {
844 err = usb_submit_urb(subs->syncurb[i].urb, GFP_ATOMIC);
845 if (err < 0) {
846 snd_printk(KERN_ERR "cannot submit syncpipe "
847 "for urb %d, error %d: %s\n",
848 i, err, usb_error_string(err));
849 goto __error;
320 } 850 }
851 set_bit(i + 16, &subs->active_mask);
852 }
853 }
854 return 0;
321 855
322 num_channels = as->bNrChannels; 856 __error:
323 format = le32_to_cpu(as->bmFormats); 857 // snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN);
858 deactivate_urbs(subs, 0, 0);
859 return -EPIPE;
860}
324 861
325 /* lookup the terminal associated to this interface
326 * to extract the clock */
327 input_term = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf,
328 as->bTerminalLink);
329 if (input_term) {
330 clock = input_term->bCSourceID;
331 break;
332 }
333 862
334 output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf, 863/*
335 as->bTerminalLink); 864 */
336 if (output_term) { 865static struct snd_urb_ops audio_urb_ops[2] = {
337 clock = output_term->bCSourceID; 866 {
338 break; 867 .prepare = prepare_nodata_playback_urb,
339 } 868 .retire = retire_playback_urb,
869 .prepare_sync = prepare_playback_sync_urb,
870 .retire_sync = retire_playback_sync_urb,
871 },
872 {
873 .prepare = prepare_capture_urb,
874 .retire = retire_capture_urb,
875 .prepare_sync = prepare_capture_sync_urb,
876 .retire_sync = retire_capture_sync_urb,
877 },
878};
340 879
341 snd_printk(KERN_ERR "%d:%u:%d : bogus bTerminalLink %d\n", 880/*
342 dev->devnum, iface_no, altno, as->bTerminalLink); 881 * initialize the substream instance.
343 continue; 882 */
344 }
345 }
346 883
347 /* get format type */ 884void snd_usb_init_substream(struct snd_usb_stream *as,
348 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE); 885 int stream, struct audioformat *fp)
349 if (!fmt) { 886{
350 snd_printk(KERN_ERR "%d:%u:%d : no UAC_FORMAT_TYPE desc\n", 887 struct snd_usb_substream *subs = &as->substream[stream];
351 dev->devnum, iface_no, altno); 888
352 continue; 889 INIT_LIST_HEAD(&subs->fmt_list);
353 } 890 spin_lock_init(&subs->lock);
354 if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8)) || 891
355 ((protocol == UAC_VERSION_2) && (fmt->bLength != 6))) { 892 subs->stream = as;
356 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n", 893 subs->direction = stream;
357 dev->devnum, iface_no, altno); 894 subs->dev = as->chip->dev;
358 continue; 895 subs->txfr_quirk = as->chip->txfr_quirk;
359 } 896 subs->ops = audio_urb_ops[stream];
897 if (snd_usb_get_speed(subs->dev) >= USB_SPEED_HIGH)
898 subs->ops.prepare_sync = prepare_capture_sync_urb_hs;
899
900 snd_usb_set_pcm_ops(as->pcm, stream);
901
902 list_add_tail(&fp->list, &subs->fmt_list);
903 subs->formats |= fp->formats;
904 subs->endpoint = fp->endpoint;
905 subs->num_formats++;
906 subs->fmt_type = fp->fmt_type;
907}
360 908
361 /* 909int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd)
362 * Blue Microphones workaround: The last altsetting is identical 910{
363 * with the previous one, except for a larger packet size, but 911 struct snd_usb_substream *subs = substream->runtime->private_data;
364 * is actually a mislabeled two-channel setting; ignore it.
365 */
366 if (fmt->bNrChannels == 1 &&
367 fmt->bSubframeSize == 2 &&
368 altno == 2 && num == 3 &&
369 fp && fp->altsetting == 1 && fp->channels == 1 &&
370 fp->formats == SNDRV_PCM_FMTBIT_S16_LE &&
371 protocol == UAC_VERSION_1 &&
372 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
373 fp->maxpacksize * 2)
374 continue;
375
376 fp = kzalloc(sizeof(*fp), GFP_KERNEL);
377 if (! fp) {
378 snd_printk(KERN_ERR "cannot malloc\n");
379 return -ENOMEM;
380 }
381 912
382 fp->iface = iface_no; 913 switch (cmd) {
383 fp->altsetting = altno; 914 case SNDRV_PCM_TRIGGER_START:
384 fp->altset_idx = i; 915 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
385 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress; 916 subs->ops.prepare = prepare_playback_urb;
386 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes; 917 return 0;
387 fp->datainterval = snd_usb_parse_datainterval(chip, alts); 918 case SNDRV_PCM_TRIGGER_STOP:
388 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize); 919 return deactivate_urbs(subs, 0, 0);
389 /* num_channels is only set for v2 interfaces */ 920 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
390 fp->channels = num_channels; 921 subs->ops.prepare = prepare_nodata_playback_urb;
391 if (snd_usb_get_speed(dev) == USB_SPEED_HIGH) 922 return 0;
392 fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1) 923 }
393 * (fp->maxpacksize & 0x7ff);
394 fp->attributes = parse_uac_endpoint_attributes(chip, alts, protocol, iface_no);
395 fp->clock = clock;
396
397 /* some quirks for attributes here */
398
399 switch (chip->usb_id) {
400 case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */
401 /* Optoplay sets the sample rate attribute although
402 * it seems not supporting it in fact.
403 */
404 fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE;
405 break;
406 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
407 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
408 /* doesn't set the sample rate attribute, but supports it */
409 fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
410 break;
411 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */
412 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
413 case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
414 case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
415 an older model 77d:223) */
416 /*
417 * plantronics headset and Griffin iMic have set adaptive-in
418 * although it's really not...
419 */
420 fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE;
421 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
422 fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE;
423 else
424 fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC;
425 break;
426 }
427 924
428 /* ok, let's parse further... */ 925 return -EINVAL;
429 if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) { 926}
430 kfree(fp->rate_table);
431 kfree(fp);
432 fp = NULL;
433 continue;
434 }
435 927
436 snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint %#x\n", dev->devnum, iface_no, altno, fp->endpoint); 928int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd)
437 err = snd_usb_add_audio_endpoint(chip, stream, fp); 929{
438 if (err < 0) { 930 struct snd_usb_substream *subs = substream->runtime->private_data;
439 kfree(fp->rate_table); 931
440 kfree(fp); 932 switch (cmd) {
441 return err; 933 case SNDRV_PCM_TRIGGER_START:
442 } 934 subs->ops.retire = retire_capture_urb;
443 /* try to set the interface... */ 935 return start_urbs(subs, substream->runtime);
444 usb_set_interface(chip->dev, iface_no, altno); 936 case SNDRV_PCM_TRIGGER_STOP:
445 snd_usb_init_pitch(chip, iface_no, alts, fp); 937 return deactivate_urbs(subs, 0, 0);
446 snd_usb_init_sample_rate(chip, iface_no, alts, fp, fp->rate_max); 938 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
939 subs->ops.retire = retire_paused_capture_urb;
940 return 0;
941 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
942 subs->ops.retire = retire_capture_urb;
943 return 0;
447 } 944 }
945
946 return -EINVAL;
947}
948
949int snd_usb_substream_prepare(struct snd_usb_substream *subs,
950 struct snd_pcm_runtime *runtime)
951{
952 /* clear urbs (to be sure) */
953 deactivate_urbs(subs, 0, 1);
954 wait_clear_urbs(subs);
955
956 /* for playback, submit the URBs now; otherwise, the first hwptr_done
957 * updates for all URBs would happen at the same time when starting */
958 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
959 subs->ops.prepare = prepare_nodata_playback_urb;
960 return start_urbs(subs, runtime);
961 }
962
448 return 0; 963 return 0;
449} 964}
450 965
diff --git a/sound/usb/endpoint.h b/sound/usb/endpoint.h
index 64dd0db023b2..88eb63a636eb 100644
--- a/sound/usb/endpoint.h
+++ b/sound/usb/endpoint.h
@@ -1,11 +1,21 @@
1#ifndef __USBAUDIO_ENDPOINT_H 1#ifndef __USBAUDIO_ENDPOINT_H
2#define __USBAUDIO_ENDPOINT_H 2#define __USBAUDIO_ENDPOINT_H
3 3
4int snd_usb_parse_audio_endpoints(struct snd_usb_audio *chip, 4void snd_usb_init_substream(struct snd_usb_stream *as,
5 int iface_no); 5 int stream,
6 struct audioformat *fp);
6 7
7int snd_usb_add_audio_endpoint(struct snd_usb_audio *chip, 8int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
8 int stream, 9 unsigned int period_bytes,
9 struct audioformat *fp); 10 unsigned int rate,
11 unsigned int frame_bits);
12
13void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force);
14
15int snd_usb_substream_prepare(struct snd_usb_substream *subs,
16 struct snd_pcm_runtime *runtime);
17
18int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd);
19int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd);
10 20
11#endif /* __USBAUDIO_ENDPOINT_H */ 21#endif /* __USBAUDIO_ENDPOINT_H */
diff --git a/sound/usb/format.c b/sound/usb/format.c
index 8d042dce0d16..89421d176570 100644
--- a/sound/usb/format.c
+++ b/sound/usb/format.c
@@ -286,7 +286,7 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
286 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 286 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
287 UAC2_CS_CONTROL_SAM_FREQ << 8, 287 UAC2_CS_CONTROL_SAM_FREQ << 8,
288 snd_usb_ctrl_intf(chip) | (clock << 8), 288 snd_usb_ctrl_intf(chip) | (clock << 8),
289 tmp, sizeof(tmp), 1000); 289 tmp, sizeof(tmp));
290 290
291 if (ret < 0) { 291 if (ret < 0) {
292 snd_printk(KERN_ERR "%s(): unable to retrieve number of sample rates (clock %d)\n", 292 snd_printk(KERN_ERR "%s(): unable to retrieve number of sample rates (clock %d)\n",
@@ -307,7 +307,7 @@ static int parse_audio_format_rates_v2(struct snd_usb_audio *chip,
307 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN, 307 USB_TYPE_CLASS | USB_RECIP_INTERFACE | USB_DIR_IN,
308 UAC2_CS_CONTROL_SAM_FREQ << 8, 308 UAC2_CS_CONTROL_SAM_FREQ << 8,
309 snd_usb_ctrl_intf(chip) | (clock << 8), 309 snd_usb_ctrl_intf(chip) | (clock << 8),
310 data, data_size, 1000); 310 data, data_size);
311 311
312 if (ret < 0) { 312 if (ret < 0) {
313 snd_printk(KERN_ERR "%s(): unable to retrieve sample rate range (clock %d)\n", 313 snd_printk(KERN_ERR "%s(): unable to retrieve sample rate range (clock %d)\n",
diff --git a/sound/usb/helper.c b/sound/usb/helper.c
index f280c1903c25..9eed8f40b179 100644
--- a/sound/usb/helper.c
+++ b/sound/usb/helper.c
@@ -81,7 +81,7 @@ void *snd_usb_find_csint_desc(void *buffer, int buflen, void *after, u8 dsubtype
81 */ 81 */
82int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request, 82int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
83 __u8 requesttype, __u16 value, __u16 index, void *data, 83 __u8 requesttype, __u16 value, __u16 index, void *data,
84 __u16 size, int timeout) 84 __u16 size)
85{ 85{
86 int err; 86 int err;
87 void *buf = NULL; 87 void *buf = NULL;
@@ -92,7 +92,7 @@ int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
92 return -ENOMEM; 92 return -ENOMEM;
93 } 93 }
94 err = usb_control_msg(dev, pipe, request, requesttype, 94 err = usb_control_msg(dev, pipe, request, requesttype,
95 value, index, buf, size, timeout); 95 value, index, buf, size, 1000);
96 if (size > 0) { 96 if (size > 0) {
97 memcpy(data, buf, size); 97 memcpy(data, buf, size);
98 kfree(buf); 98 kfree(buf);
diff --git a/sound/usb/helper.h b/sound/usb/helper.h
index 09bd943c43bf..805c300dd004 100644
--- a/sound/usb/helper.h
+++ b/sound/usb/helper.h
@@ -8,7 +8,7 @@ void *snd_usb_find_csint_desc(void *descstart, int desclen, void *after, u8 dsub
8 8
9int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe, 9int snd_usb_ctl_msg(struct usb_device *dev, unsigned int pipe,
10 __u8 request, __u8 requesttype, __u16 value, __u16 index, 10 __u8 request, __u8 requesttype, __u16 value, __u16 index,
11 void *data, __u16 size, int timeout); 11 void *data, __u16 size);
12 12
13unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip, 13unsigned char snd_usb_parse_datainterval(struct snd_usb_audio *chip,
14 struct usb_host_interface *alts); 14 struct usb_host_interface *alts);
diff --git a/sound/usb/midi.c b/sound/usb/midi.c
index f9289102886a..e21f026d9577 100644
--- a/sound/usb/midi.c
+++ b/sound/usb/midi.c
@@ -816,6 +816,22 @@ static struct usb_protocol_ops snd_usbmidi_raw_ops = {
816 .output = snd_usbmidi_raw_output, 816 .output = snd_usbmidi_raw_output,
817}; 817};
818 818
819/*
820 * FTDI protocol: raw MIDI bytes, but input packets have two modem status bytes.
821 */
822
823static void snd_usbmidi_ftdi_input(struct snd_usb_midi_in_endpoint* ep,
824 uint8_t* buffer, int buffer_length)
825{
826 if (buffer_length > 2)
827 snd_usbmidi_input_data(ep, 0, buffer + 2, buffer_length - 2);
828}
829
830static struct usb_protocol_ops snd_usbmidi_ftdi_ops = {
831 .input = snd_usbmidi_ftdi_input,
832 .output = snd_usbmidi_raw_output,
833};
834
819static void snd_usbmidi_us122l_input(struct snd_usb_midi_in_endpoint *ep, 835static void snd_usbmidi_us122l_input(struct snd_usb_midi_in_endpoint *ep,
820 uint8_t *buffer, int buffer_length) 836 uint8_t *buffer, int buffer_length)
821{ 837{
@@ -2163,6 +2179,17 @@ int snd_usbmidi_create(struct snd_card *card,
2163 /* endpoint 1 is input-only */ 2179 /* endpoint 1 is input-only */
2164 endpoints[1].out_cables = 0; 2180 endpoints[1].out_cables = 0;
2165 break; 2181 break;
2182 case QUIRK_MIDI_FTDI:
2183 umidi->usb_protocol_ops = &snd_usbmidi_ftdi_ops;
2184
2185 /* set baud rate to 31250 (48 MHz / 16 / 96) */
2186 err = usb_control_msg(umidi->dev, usb_sndctrlpipe(umidi->dev, 0),
2187 3, 0x40, 0x60, 0, NULL, 0, 1000);
2188 if (err < 0)
2189 break;
2190
2191 err = snd_usbmidi_detect_per_port_endpoints(umidi, endpoints);
2192 break;
2166 default: 2193 default:
2167 snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type); 2194 snd_printd(KERN_ERR "invalid quirk type %d\n", quirk->type);
2168 err = -ENXIO; 2195 err = -ENXIO;
diff --git a/sound/usb/mixer.c b/sound/usb/mixer.c
index c22fa76e363a..60f65ace7474 100644
--- a/sound/usb/mixer.c
+++ b/sound/usb/mixer.c
@@ -152,6 +152,7 @@ static inline void check_mapped_dB(const struct usbmix_name_map *p,
152 if (p && p->dB) { 152 if (p && p->dB) {
153 cval->dBmin = p->dB->min; 153 cval->dBmin = p->dB->min;
154 cval->dBmax = p->dB->max; 154 cval->dBmax = p->dB->max;
155 cval->initialized = 1;
155 } 156 }
156} 157}
157 158
@@ -295,7 +296,7 @@ static int get_ctl_value_v1(struct usb_mixer_elem_info *cval, int request, int v
295 if (snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), request, 296 if (snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), request,
296 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 297 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
297 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), 298 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
298 buf, val_len, 100) >= val_len) { 299 buf, val_len) >= val_len) {
299 *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len)); 300 *value_ret = convert_signed_value(cval, snd_usb_combine_bytes(buf, val_len));
300 snd_usb_autosuspend(cval->mixer->chip); 301 snd_usb_autosuspend(cval->mixer->chip);
301 return 0; 302 return 0;
@@ -332,7 +333,7 @@ static int get_ctl_value_v2(struct usb_mixer_elem_info *cval, int request, int v
332 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), bRequest, 333 ret = snd_usb_ctl_msg(chip->dev, usb_rcvctrlpipe(chip->dev, 0), bRequest,
333 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN, 334 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_IN,
334 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), 335 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
335 buf, size, 1000); 336 buf, size);
336 snd_usb_autosuspend(chip); 337 snd_usb_autosuspend(chip);
337 338
338 if (ret < 0) { 339 if (ret < 0) {
@@ -444,7 +445,7 @@ int snd_usb_mixer_set_ctl_value(struct usb_mixer_elem_info *cval,
444 usb_sndctrlpipe(chip->dev, 0), request, 445 usb_sndctrlpipe(chip->dev, 0), request,
445 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT, 446 USB_RECIP_INTERFACE | USB_TYPE_CLASS | USB_DIR_OUT,
446 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8), 447 validx, snd_usb_ctrl_intf(chip) | (cval->id << 8),
447 buf, val_len, 100) >= 0) { 448 buf, val_len) >= 0) {
448 snd_usb_autosuspend(chip); 449 snd_usb_autosuspend(chip);
449 return 0; 450 return 0;
450 } 451 }
@@ -880,8 +881,17 @@ static int mixer_ctl_feature_info(struct snd_kcontrol *kcontrol, struct snd_ctl_
880 uinfo->value.integer.min = 0; 881 uinfo->value.integer.min = 0;
881 uinfo->value.integer.max = 1; 882 uinfo->value.integer.max = 1;
882 } else { 883 } else {
883 if (! cval->initialized) 884 if (!cval->initialized) {
884 get_min_max(cval, 0); 885 get_min_max(cval, 0);
886 if (cval->initialized && cval->dBmin >= cval->dBmax) {
887 kcontrol->vd[0].access &=
888 ~(SNDRV_CTL_ELEM_ACCESS_TLV_READ |
889 SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK);
890 snd_ctl_notify(cval->mixer->chip->card,
891 SNDRV_CTL_EVENT_MASK_INFO,
892 &kcontrol->id);
893 }
894 }
885 uinfo->value.integer.min = 0; 895 uinfo->value.integer.min = 0;
886 uinfo->value.integer.max = 896 uinfo->value.integer.max =
887 (cval->max - cval->min + cval->res - 1) / cval->res; 897 (cval->max - cval->min + cval->res - 1) / cval->res;
@@ -1092,7 +1102,7 @@ static void build_feature_ctl(struct mixer_build *state, void *raw_desc,
1092 " Switch" : " Volume"); 1102 " Switch" : " Volume");
1093 if (control == UAC_FU_VOLUME) { 1103 if (control == UAC_FU_VOLUME) {
1094 check_mapped_dB(map, cval); 1104 check_mapped_dB(map, cval);
1095 if (cval->dBmin < cval->dBmax) { 1105 if (cval->dBmin < cval->dBmax || !cval->initialized) {
1096 kctl->tlv.c = mixer_vol_tlv; 1106 kctl->tlv.c = mixer_vol_tlv;
1097 kctl->vd[0].access |= 1107 kctl->vd[0].access |=
1098 SNDRV_CTL_ELEM_ACCESS_TLV_READ | 1108 SNDRV_CTL_ELEM_ACCESS_TLV_READ |
@@ -1191,6 +1201,11 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void
1191 1201
1192 if (state->mixer->protocol == UAC_VERSION_1) { 1202 if (state->mixer->protocol == UAC_VERSION_1) {
1193 csize = hdr->bControlSize; 1203 csize = hdr->bControlSize;
1204 if (!csize) {
1205 snd_printdd(KERN_ERR "usbaudio: unit %u: "
1206 "invalid bControlSize == 0\n", unitid);
1207 return -EINVAL;
1208 }
1194 channels = (hdr->bLength - 7) / csize - 1; 1209 channels = (hdr->bLength - 7) / csize - 1;
1195 bmaControls = hdr->bmaControls; 1210 bmaControls = hdr->bmaControls;
1196 } else { 1211 } else {
@@ -1244,7 +1259,7 @@ static int parse_audio_feature_unit(struct mixer_build *state, int unitid, void
1244 build_feature_ctl(state, _ftr, 0, i, &iterm, unitid, 0); 1259 build_feature_ctl(state, _ftr, 0, i, &iterm, unitid, 0);
1245 } 1260 }
1246 } else { /* UAC_VERSION_2 */ 1261 } else { /* UAC_VERSION_2 */
1247 for (i = 0; i < 30/2; i++) { 1262 for (i = 0; i < ARRAY_SIZE(audio_feature_info); i++) {
1248 unsigned int ch_bits = 0; 1263 unsigned int ch_bits = 0;
1249 unsigned int ch_read_only = 0; 1264 unsigned int ch_read_only = 0;
1250 1265
@@ -1934,15 +1949,13 @@ static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
1934 struct mixer_build state; 1949 struct mixer_build state;
1935 int err; 1950 int err;
1936 const struct usbmix_ctl_map *map; 1951 const struct usbmix_ctl_map *map;
1937 struct usb_host_interface *hostif;
1938 void *p; 1952 void *p;
1939 1953
1940 hostif = mixer->chip->ctrl_intf;
1941 memset(&state, 0, sizeof(state)); 1954 memset(&state, 0, sizeof(state));
1942 state.chip = mixer->chip; 1955 state.chip = mixer->chip;
1943 state.mixer = mixer; 1956 state.mixer = mixer;
1944 state.buffer = hostif->extra; 1957 state.buffer = mixer->hostif->extra;
1945 state.buflen = hostif->extralen; 1958 state.buflen = mixer->hostif->extralen;
1946 1959
1947 /* check the mapping table */ 1960 /* check the mapping table */
1948 for (map = usbmix_ctl_maps; map->id; map++) { 1961 for (map = usbmix_ctl_maps; map->id; map++) {
@@ -1955,7 +1968,8 @@ static int snd_usb_mixer_controls(struct usb_mixer_interface *mixer)
1955 } 1968 }
1956 1969
1957 p = NULL; 1970 p = NULL;
1958 while ((p = snd_usb_find_csint_desc(hostif->extra, hostif->extralen, p, UAC_OUTPUT_TERMINAL)) != NULL) { 1971 while ((p = snd_usb_find_csint_desc(mixer->hostif->extra, mixer->hostif->extralen,
1972 p, UAC_OUTPUT_TERMINAL)) != NULL) {
1959 if (mixer->protocol == UAC_VERSION_1) { 1973 if (mixer->protocol == UAC_VERSION_1) {
1960 struct uac1_output_terminal_descriptor *desc = p; 1974 struct uac1_output_terminal_descriptor *desc = p;
1961 1975
@@ -2162,17 +2176,15 @@ int snd_usb_mixer_activate(struct usb_mixer_interface *mixer)
2162/* create the handler for the optional status interrupt endpoint */ 2176/* create the handler for the optional status interrupt endpoint */
2163static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer) 2177static int snd_usb_mixer_status_create(struct usb_mixer_interface *mixer)
2164{ 2178{
2165 struct usb_host_interface *hostif;
2166 struct usb_endpoint_descriptor *ep; 2179 struct usb_endpoint_descriptor *ep;
2167 void *transfer_buffer; 2180 void *transfer_buffer;
2168 int buffer_length; 2181 int buffer_length;
2169 unsigned int epnum; 2182 unsigned int epnum;
2170 2183
2171 hostif = mixer->chip->ctrl_intf;
2172 /* we need one interrupt input endpoint */ 2184 /* we need one interrupt input endpoint */
2173 if (get_iface_desc(hostif)->bNumEndpoints < 1) 2185 if (get_iface_desc(mixer->hostif)->bNumEndpoints < 1)
2174 return 0; 2186 return 0;
2175 ep = get_endpoint(hostif, 0); 2187 ep = get_endpoint(mixer->hostif, 0);
2176 if (!usb_endpoint_dir_in(ep) || !usb_endpoint_xfer_int(ep)) 2188 if (!usb_endpoint_dir_in(ep) || !usb_endpoint_xfer_int(ep))
2177 return 0; 2189 return 0;
2178 2190
@@ -2202,7 +2214,6 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2202 }; 2214 };
2203 struct usb_mixer_interface *mixer; 2215 struct usb_mixer_interface *mixer;
2204 struct snd_info_entry *entry; 2216 struct snd_info_entry *entry;
2205 struct usb_host_interface *host_iface;
2206 int err; 2217 int err;
2207 2218
2208 strcpy(chip->card->mixername, "USB Mixer"); 2219 strcpy(chip->card->mixername, "USB Mixer");
@@ -2219,8 +2230,8 @@ int snd_usb_create_mixer(struct snd_usb_audio *chip, int ctrlif,
2219 return -ENOMEM; 2230 return -ENOMEM;
2220 } 2231 }
2221 2232
2222 host_iface = &usb_ifnum_to_if(chip->dev, ctrlif)->altsetting[0]; 2233 mixer->hostif = &usb_ifnum_to_if(chip->dev, ctrlif)->altsetting[0];
2223 switch (get_iface_desc(host_iface)->bInterfaceProtocol) { 2234 switch (get_iface_desc(mixer->hostif)->bInterfaceProtocol) {
2224 case UAC_VERSION_1: 2235 case UAC_VERSION_1:
2225 default: 2236 default:
2226 mixer->protocol = UAC_VERSION_1; 2237 mixer->protocol = UAC_VERSION_1;
diff --git a/sound/usb/mixer.h b/sound/usb/mixer.h
index ae1a14dcfe82..81b2d8a32fb0 100644
--- a/sound/usb/mixer.h
+++ b/sound/usb/mixer.h
@@ -3,6 +3,7 @@
3 3
4struct usb_mixer_interface { 4struct usb_mixer_interface {
5 struct snd_usb_audio *chip; 5 struct snd_usb_audio *chip;
6 struct usb_host_interface *hostif;
6 struct list_head list; 7 struct list_head list;
7 unsigned int ignore_ctl_error; 8 unsigned int ignore_ctl_error;
8 struct urb *urb; 9 struct urb *urb;
diff --git a/sound/usb/mixer_quirks.c b/sound/usb/mixer_quirks.c
index 3d0f4873112b..ab125ee0b0f0 100644
--- a/sound/usb/mixer_quirks.c
+++ b/sound/usb/mixer_quirks.c
@@ -190,18 +190,18 @@ static int snd_audigy2nx_led_put(struct snd_kcontrol *kcontrol, struct snd_ctl_e
190 err = snd_usb_ctl_msg(mixer->chip->dev, 190 err = snd_usb_ctl_msg(mixer->chip->dev,
191 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, 191 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
192 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 192 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
193 !value, 0, NULL, 0, 100); 193 !value, 0, NULL, 0);
194 /* USB X-Fi S51 Pro */ 194 /* USB X-Fi S51 Pro */
195 if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df)) 195 if (mixer->chip->usb_id == USB_ID(0x041e, 0x30df))
196 err = snd_usb_ctl_msg(mixer->chip->dev, 196 err = snd_usb_ctl_msg(mixer->chip->dev,
197 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, 197 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
198 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 198 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
199 !value, 0, NULL, 0, 100); 199 !value, 0, NULL, 0);
200 else 200 else
201 err = snd_usb_ctl_msg(mixer->chip->dev, 201 err = snd_usb_ctl_msg(mixer->chip->dev,
202 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24, 202 usb_sndctrlpipe(mixer->chip->dev, 0), 0x24,
203 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 203 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
204 value, index + 2, NULL, 0, 100); 204 value, index + 2, NULL, 0);
205 if (err < 0) 205 if (err < 0)
206 return err; 206 return err;
207 mixer->audigy2nx_leds[index] = value; 207 mixer->audigy2nx_leds[index] = value;
@@ -299,7 +299,7 @@ static void snd_audigy2nx_proc_read(struct snd_info_entry *entry,
299 usb_rcvctrlpipe(mixer->chip->dev, 0), 299 usb_rcvctrlpipe(mixer->chip->dev, 0),
300 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS | 300 UAC_GET_MEM, USB_DIR_IN | USB_TYPE_CLASS |
301 USB_RECIP_INTERFACE, 0, 301 USB_RECIP_INTERFACE, 0,
302 jacks[i].unitid << 8, buf, 3, 100); 302 jacks[i].unitid << 8, buf, 3);
303 if (err == 3 && (buf[0] == 3 || buf[0] == 6)) 303 if (err == 3 && (buf[0] == 3 || buf[0] == 6))
304 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]); 304 snd_iprintf(buffer, "%02x %02x\n", buf[1], buf[2]);
305 else 305 else
@@ -332,7 +332,7 @@ static int snd_xonar_u1_switch_put(struct snd_kcontrol *kcontrol,
332 err = snd_usb_ctl_msg(mixer->chip->dev, 332 err = snd_usb_ctl_msg(mixer->chip->dev,
333 usb_sndctrlpipe(mixer->chip->dev, 0), 0x08, 333 usb_sndctrlpipe(mixer->chip->dev, 0), 0x08,
334 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 334 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
335 50, 0, &new_status, 1, 100); 335 50, 0, &new_status, 1);
336 if (err < 0) 336 if (err < 0)
337 return err; 337 return err;
338 mixer->xonar_u1_status = new_status; 338 mixer->xonar_u1_status = new_status;
diff --git a/sound/usb/pcm.c b/sound/usb/pcm.c
index b8dcbf407bbb..0220b0f335b9 100644
--- a/sound/usb/pcm.c
+++ b/sound/usb/pcm.c
@@ -28,12 +28,36 @@
28#include "card.h" 28#include "card.h"
29#include "quirks.h" 29#include "quirks.h"
30#include "debug.h" 30#include "debug.h"
31#include "urb.h" 31#include "endpoint.h"
32#include "helper.h" 32#include "helper.h"
33#include "pcm.h" 33#include "pcm.h"
34#include "clock.h" 34#include "clock.h"
35#include "power.h" 35#include "power.h"
36 36
37/* return the estimated delay based on USB frame counters */
38snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs,
39 unsigned int rate)
40{
41 int current_frame_number;
42 int frame_diff;
43 int est_delay;
44
45 current_frame_number = usb_get_current_frame_number(subs->dev);
46 /*
47 * HCD implementations use different widths, use lower 8 bits.
48 * The delay will be managed up to 256ms, which is more than
49 * enough
50 */
51 frame_diff = (current_frame_number - subs->last_frame_number) & 0xff;
52
53 /* Approximation based on number of samples per USB frame (ms),
54 some truncation for 44.1 but the estimate is good enough */
55 est_delay = subs->last_delay - (frame_diff * rate / 1000);
56 if (est_delay < 0)
57 est_delay = 0;
58 return est_delay;
59}
60
37/* 61/*
38 * return the current pcm pointer. just based on the hwptr_done value. 62 * return the current pcm pointer. just based on the hwptr_done value.
39 */ 63 */
@@ -45,6 +69,8 @@ static snd_pcm_uframes_t snd_usb_pcm_pointer(struct snd_pcm_substream *substream
45 subs = (struct snd_usb_substream *)substream->runtime->private_data; 69 subs = (struct snd_usb_substream *)substream->runtime->private_data;
46 spin_lock(&subs->lock); 70 spin_lock(&subs->lock);
47 hwptr_done = subs->hwptr_done; 71 hwptr_done = subs->hwptr_done;
72 substream->runtime->delay = snd_usb_pcm_delay(subs,
73 substream->runtime->rate);
48 spin_unlock(&subs->lock); 74 spin_unlock(&subs->lock);
49 return hwptr_done / (substream->runtime->frame_bits >> 3); 75 return hwptr_done / (substream->runtime->frame_bits >> 3);
50} 76}
@@ -126,7 +152,7 @@ static int init_pitch_v1(struct snd_usb_audio *chip, int iface,
126 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR, 152 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC_SET_CUR,
127 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT, 153 USB_TYPE_CLASS|USB_RECIP_ENDPOINT|USB_DIR_OUT,
128 UAC_EP_CS_ATTR_PITCH_CONTROL << 8, ep, 154 UAC_EP_CS_ATTR_PITCH_CONTROL << 8, ep,
129 data, sizeof(data), 1000)) < 0) { 155 data, sizeof(data))) < 0) {
130 snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n", 156 snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH\n",
131 dev->devnum, iface, ep); 157 dev->devnum, iface, ep);
132 return err; 158 return err;
@@ -150,7 +176,7 @@ static int init_pitch_v2(struct snd_usb_audio *chip, int iface,
150 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR, 176 if ((err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), UAC2_CS_CUR,
151 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT, 177 USB_TYPE_CLASS | USB_RECIP_ENDPOINT | USB_DIR_OUT,
152 UAC2_EP_CS_PITCH << 8, 0, 178 UAC2_EP_CS_PITCH << 8, 0,
153 data, sizeof(data), 1000)) < 0) { 179 data, sizeof(data))) < 0) {
154 snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH (v2)\n", 180 snd_printk(KERN_ERR "%d:%d:%d: cannot set enable PITCH (v2)\n",
155 dev->devnum, iface, fmt->altsetting); 181 dev->devnum, iface, fmt->altsetting);
156 return err; 182 return err;
@@ -417,6 +443,8 @@ static int snd_usb_pcm_prepare(struct snd_pcm_substream *substream)
417 subs->hwptr_done = 0; 443 subs->hwptr_done = 0;
418 subs->transfer_done = 0; 444 subs->transfer_done = 0;
419 subs->phase = 0; 445 subs->phase = 0;
446 subs->last_delay = 0;
447 subs->last_frame_number = 0;
420 runtime->delay = 0; 448 runtime->delay = 0;
421 449
422 return snd_usb_substream_prepare(subs, runtime); 450 return snd_usb_substream_prepare(subs, runtime);
diff --git a/sound/usb/pcm.h b/sound/usb/pcm.h
index ed3e283f618d..df7a003682ad 100644
--- a/sound/usb/pcm.h
+++ b/sound/usb/pcm.h
@@ -1,6 +1,9 @@
1#ifndef __USBAUDIO_PCM_H 1#ifndef __USBAUDIO_PCM_H
2#define __USBAUDIO_PCM_H 2#define __USBAUDIO_PCM_H
3 3
4snd_pcm_uframes_t snd_usb_pcm_delay(struct snd_usb_substream *subs,
5 unsigned int rate);
6
4void snd_usb_set_pcm_ops(struct snd_pcm *pcm, int stream); 7void snd_usb_set_pcm_ops(struct snd_pcm *pcm, int stream);
5 8
6int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface, 9int snd_usb_init_pitch(struct snd_usb_audio *chip, int iface,
diff --git a/sound/usb/quirks-table.h b/sound/usb/quirks-table.h
index dba0b7f11c54..b61945f3af9e 100644
--- a/sound/usb/quirks-table.h
+++ b/sound/usb/quirks-table.h
@@ -39,6 +39,17 @@
39 .idProduct = prod, \ 39 .idProduct = prod, \
40 .bInterfaceClass = USB_CLASS_VENDOR_SPEC 40 .bInterfaceClass = USB_CLASS_VENDOR_SPEC
41 41
42/* FTDI devices */
43{
44 USB_DEVICE(0x0403, 0xb8d8),
45 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
46 /* .vendor_name = "STARR LABS", */
47 /* .product_name = "Starr Labs MIDI USB device", */
48 .ifnum = 0,
49 .type = QUIRK_MIDI_FTDI
50 }
51},
52
42/* Creative/Toshiba Multimedia Center SB-0500 */ 53/* Creative/Toshiba Multimedia Center SB-0500 */
43{ 54{
44 USB_DEVICE(0x041e, 0x3048), 55 USB_DEVICE(0x041e, 0x3048),
@@ -1678,6 +1689,20 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1678 } 1689 }
1679}, 1690},
1680{ 1691{
1692 /* Added support for Roland UM-ONE which differs from UM-1 */
1693 USB_DEVICE(0x0582, 0x012a),
1694 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1695 /* .vendor_name = "ROLAND", */
1696 /* .product_name = "UM-ONE", */
1697 .ifnum = 0,
1698 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1699 .data = & (const struct snd_usb_midi_endpoint_info) {
1700 .out_cables = 0x0001,
1701 .in_cables = 0x0003
1702 }
1703 }
1704},
1705{
1681 USB_DEVICE(0x0582, 0x011e), 1706 USB_DEVICE(0x0582, 0x011e),
1682 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) { 1707 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1683 /* .vendor_name = "BOSS", */ 1708 /* .vendor_name = "BOSS", */
@@ -1707,6 +1732,40 @@ YAMAHA_DEVICE(0x7010, "UB99"),
1707 } 1732 }
1708 } 1733 }
1709}, 1734},
1735{
1736 USB_DEVICE(0x0582, 0x0130),
1737 .driver_info = (unsigned long) & (const struct snd_usb_audio_quirk) {
1738 /* .vendor_name = "BOSS", */
1739 /* .product_name = "MICRO BR-80", */
1740 .ifnum = QUIRK_ANY_INTERFACE,
1741 .type = QUIRK_COMPOSITE,
1742 .data = (const struct snd_usb_audio_quirk[]) {
1743 {
1744 .ifnum = 0,
1745 .type = QUIRK_IGNORE_INTERFACE
1746 },
1747 {
1748 .ifnum = 1,
1749 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1750 },
1751 {
1752 .ifnum = 2,
1753 .type = QUIRK_AUDIO_STANDARD_INTERFACE
1754 },
1755 {
1756 .ifnum = 3,
1757 .type = QUIRK_MIDI_FIXED_ENDPOINT,
1758 .data = & (const struct snd_usb_midi_endpoint_info) {
1759 .out_cables = 0x0001,
1760 .in_cables = 0x0001
1761 }
1762 },
1763 {
1764 .ifnum = -1
1765 }
1766 }
1767 }
1768},
1710 1769
1711/* Guillemot devices */ 1770/* Guillemot devices */
1712{ 1771{
@@ -2417,6 +2476,12 @@ YAMAHA_DEVICE(0x7010, "UB99"),
2417 .idProduct = 0x1020, 2476 .idProduct = 0x1020,
2418}, 2477},
2419 2478
2479/* KeithMcMillen Stringport */
2480{
2481 USB_DEVICE(0x1f38, 0x0001),
2482 .bInterfaceClass = USB_CLASS_AUDIO,
2483},
2484
2420/* Miditech devices */ 2485/* Miditech devices */
2421{ 2486{
2422 USB_DEVICE(0x4752, 0x0011), 2487 USB_DEVICE(0x4752, 0x0011),
diff --git a/sound/usb/quirks.c b/sound/usb/quirks.c
index 77762c99afbe..2e5bc7344026 100644
--- a/sound/usb/quirks.c
+++ b/sound/usb/quirks.c
@@ -34,6 +34,7 @@
34#include "endpoint.h" 34#include "endpoint.h"
35#include "pcm.h" 35#include "pcm.h"
36#include "clock.h" 36#include "clock.h"
37#include "stream.h"
37 38
38/* 39/*
39 * handle the quirks for the contained interfaces 40 * handle the quirks for the contained interfaces
@@ -106,7 +107,7 @@ static int create_standard_audio_quirk(struct snd_usb_audio *chip,
106 107
107 alts = &iface->altsetting[0]; 108 alts = &iface->altsetting[0];
108 altsd = get_iface_desc(alts); 109 altsd = get_iface_desc(alts);
109 err = snd_usb_parse_audio_endpoints(chip, altsd->bInterfaceNumber); 110 err = snd_usb_parse_audio_interface(chip, altsd->bInterfaceNumber);
110 if (err < 0) { 111 if (err < 0) {
111 snd_printk(KERN_ERR "cannot setup if %d: error %d\n", 112 snd_printk(KERN_ERR "cannot setup if %d: error %d\n",
112 altsd->bInterfaceNumber, err); 113 altsd->bInterfaceNumber, err);
@@ -147,7 +148,7 @@ static int create_fixed_stream_quirk(struct snd_usb_audio *chip,
147 148
148 stream = (fp->endpoint & USB_DIR_IN) 149 stream = (fp->endpoint & USB_DIR_IN)
149 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; 150 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
150 err = snd_usb_add_audio_endpoint(chip, stream, fp); 151 err = snd_usb_add_audio_stream(chip, stream, fp);
151 if (err < 0) { 152 if (err < 0) {
152 kfree(fp); 153 kfree(fp);
153 kfree(rate_table); 154 kfree(rate_table);
@@ -254,7 +255,7 @@ static int create_uaxx_quirk(struct snd_usb_audio *chip,
254 255
255 stream = (fp->endpoint & USB_DIR_IN) 256 stream = (fp->endpoint & USB_DIR_IN)
256 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK; 257 ? SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
257 err = snd_usb_add_audio_endpoint(chip, stream, fp); 258 err = snd_usb_add_audio_stream(chip, stream, fp);
258 if (err < 0) { 259 if (err < 0) {
259 kfree(fp); 260 kfree(fp);
260 return err; 261 return err;
@@ -306,6 +307,7 @@ int snd_usb_create_quirk(struct snd_usb_audio *chip,
306 [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk, 307 [QUIRK_MIDI_EMAGIC] = create_any_midi_quirk,
307 [QUIRK_MIDI_CME] = create_any_midi_quirk, 308 [QUIRK_MIDI_CME] = create_any_midi_quirk,
308 [QUIRK_MIDI_AKAI] = create_any_midi_quirk, 309 [QUIRK_MIDI_AKAI] = create_any_midi_quirk,
310 [QUIRK_MIDI_FTDI] = create_any_midi_quirk,
309 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk, 311 [QUIRK_AUDIO_STANDARD_INTERFACE] = create_standard_audio_quirk,
310 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk, 312 [QUIRK_AUDIO_FIXED_ENDPOINT] = create_fixed_stream_quirk,
311 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk, 313 [QUIRK_AUDIO_EDIROL_UAXX] = create_uaxx_quirk,
@@ -338,7 +340,7 @@ static int snd_usb_extigy_boot_quirk(struct usb_device *dev, struct usb_interfac
338 snd_printdd("sending Extigy boot sequence...\n"); 340 snd_printdd("sending Extigy boot sequence...\n");
339 /* Send message to force it to reconnect with full interface. */ 341 /* Send message to force it to reconnect with full interface. */
340 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0), 342 err = snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev,0),
341 0x10, 0x43, 0x0001, 0x000a, NULL, 0, 1000); 343 0x10, 0x43, 0x0001, 0x000a, NULL, 0);
342 if (err < 0) snd_printdd("error sending boot message: %d\n", err); 344 if (err < 0) snd_printdd("error sending boot message: %d\n", err);
343 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0, 345 err = usb_get_descriptor(dev, USB_DT_DEVICE, 0,
344 &dev->descriptor, sizeof(dev->descriptor)); 346 &dev->descriptor, sizeof(dev->descriptor));
@@ -359,11 +361,11 @@ static int snd_usb_audigy2nx_boot_quirk(struct usb_device *dev)
359 361
360 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a, 362 snd_usb_ctl_msg(dev, usb_rcvctrlpipe(dev, 0), 0x2a,
361 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER, 363 USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_OTHER,
362 0, 0, &buf, 1, 1000); 364 0, 0, &buf, 1);
363 if (buf == 0) { 365 if (buf == 0) {
364 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29, 366 snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), 0x29,
365 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER, 367 USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_OTHER,
366 1, 2000, NULL, 0, 1000); 368 1, 2000, NULL, 0);
367 return -ENODEV; 369 return -ENODEV;
368 } 370 }
369 return 0; 371 return 0;
@@ -406,7 +408,7 @@ static int snd_usb_cm106_write_int_reg(struct usb_device *dev, int reg, u16 valu
406 buf[3] = reg; 408 buf[3] = reg;
407 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION, 409 return snd_usb_ctl_msg(dev, usb_sndctrlpipe(dev, 0), USB_REQ_SET_CONFIGURATION,
408 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT, 410 USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_ENDPOINT,
409 0, 0, &buf, 4, 1000); 411 0, 0, &buf, 4);
410} 412}
411 413
412static int snd_usb_cm106_boot_quirk(struct usb_device *dev) 414static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
@@ -426,7 +428,7 @@ static int snd_usb_cm106_boot_quirk(struct usb_device *dev)
426 */ 428 */
427static int snd_usb_cm6206_boot_quirk(struct usb_device *dev) 429static int snd_usb_cm6206_boot_quirk(struct usb_device *dev)
428{ 430{
429 int err, reg; 431 int err = 0, reg;
430 int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000}; 432 int val[] = {0x2004, 0x3000, 0xf800, 0x143f, 0x0000, 0x3000};
431 433
432 for (reg = 0; reg < ARRAY_SIZE(val); reg++) { 434 for (reg = 0; reg < ARRAY_SIZE(val); reg++) {
diff --git a/sound/usb/stream.c b/sound/usb/stream.c
new file mode 100644
index 000000000000..5ff8010b2d6f
--- /dev/null
+++ b/sound/usb/stream.c
@@ -0,0 +1,452 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 */
16
17
18#include <linux/init.h>
19#include <linux/slab.h>
20#include <linux/usb.h>
21#include <linux/usb/audio.h>
22#include <linux/usb/audio-v2.h>
23
24#include <sound/core.h>
25#include <sound/pcm.h>
26
27#include "usbaudio.h"
28#include "card.h"
29#include "proc.h"
30#include "quirks.h"
31#include "endpoint.h"
32#include "pcm.h"
33#include "helper.h"
34#include "format.h"
35#include "clock.h"
36#include "stream.h"
37
38/*
39 * free a substream
40 */
41static void free_substream(struct snd_usb_substream *subs)
42{
43 struct list_head *p, *n;
44
45 if (!subs->num_formats)
46 return; /* not initialized */
47 list_for_each_safe(p, n, &subs->fmt_list) {
48 struct audioformat *fp = list_entry(p, struct audioformat, list);
49 kfree(fp->rate_table);
50 kfree(fp);
51 }
52 kfree(subs->rate_list.list);
53}
54
55
56/*
57 * free a usb stream instance
58 */
59static void snd_usb_audio_stream_free(struct snd_usb_stream *stream)
60{
61 free_substream(&stream->substream[0]);
62 free_substream(&stream->substream[1]);
63 list_del(&stream->list);
64 kfree(stream);
65}
66
67static void snd_usb_audio_pcm_free(struct snd_pcm *pcm)
68{
69 struct snd_usb_stream *stream = pcm->private_data;
70 if (stream) {
71 stream->pcm = NULL;
72 snd_usb_audio_stream_free(stream);
73 }
74}
75
76
77/*
78 * add this endpoint to the chip instance.
79 * if a stream with the same endpoint already exists, append to it.
80 * if not, create a new pcm stream.
81 */
82int snd_usb_add_audio_stream(struct snd_usb_audio *chip,
83 int stream,
84 struct audioformat *fp)
85{
86 struct list_head *p;
87 struct snd_usb_stream *as;
88 struct snd_usb_substream *subs;
89 struct snd_pcm *pcm;
90 int err;
91
92 list_for_each(p, &chip->pcm_list) {
93 as = list_entry(p, struct snd_usb_stream, list);
94 if (as->fmt_type != fp->fmt_type)
95 continue;
96 subs = &as->substream[stream];
97 if (!subs->endpoint)
98 continue;
99 if (subs->endpoint == fp->endpoint) {
100 list_add_tail(&fp->list, &subs->fmt_list);
101 subs->num_formats++;
102 subs->formats |= fp->formats;
103 return 0;
104 }
105 }
106 /* look for an empty stream */
107 list_for_each(p, &chip->pcm_list) {
108 as = list_entry(p, struct snd_usb_stream, list);
109 if (as->fmt_type != fp->fmt_type)
110 continue;
111 subs = &as->substream[stream];
112 if (subs->endpoint)
113 continue;
114 err = snd_pcm_new_stream(as->pcm, stream, 1);
115 if (err < 0)
116 return err;
117 snd_usb_init_substream(as, stream, fp);
118 return 0;
119 }
120
121 /* create a new pcm */
122 as = kzalloc(sizeof(*as), GFP_KERNEL);
123 if (!as)
124 return -ENOMEM;
125 as->pcm_index = chip->pcm_devs;
126 as->chip = chip;
127 as->fmt_type = fp->fmt_type;
128 err = snd_pcm_new(chip->card, "USB Audio", chip->pcm_devs,
129 stream == SNDRV_PCM_STREAM_PLAYBACK ? 1 : 0,
130 stream == SNDRV_PCM_STREAM_PLAYBACK ? 0 : 1,
131 &pcm);
132 if (err < 0) {
133 kfree(as);
134 return err;
135 }
136 as->pcm = pcm;
137 pcm->private_data = as;
138 pcm->private_free = snd_usb_audio_pcm_free;
139 pcm->info_flags = 0;
140 if (chip->pcm_devs > 0)
141 sprintf(pcm->name, "USB Audio #%d", chip->pcm_devs);
142 else
143 strcpy(pcm->name, "USB Audio");
144
145 snd_usb_init_substream(as, stream, fp);
146
147 list_add(&as->list, &chip->pcm_list);
148 chip->pcm_devs++;
149
150 snd_usb_proc_pcm_format_add(as);
151
152 return 0;
153}
154
155static int parse_uac_endpoint_attributes(struct snd_usb_audio *chip,
156 struct usb_host_interface *alts,
157 int protocol, int iface_no)
158{
159 /* parsed with a v1 header here. that's ok as we only look at the
160 * header first which is the same for both versions */
161 struct uac_iso_endpoint_descriptor *csep;
162 struct usb_interface_descriptor *altsd = get_iface_desc(alts);
163 int attributes = 0;
164
165 csep = snd_usb_find_desc(alts->endpoint[0].extra, alts->endpoint[0].extralen, NULL, USB_DT_CS_ENDPOINT);
166
167 /* Creamware Noah has this descriptor after the 2nd endpoint */
168 if (!csep && altsd->bNumEndpoints >= 2)
169 csep = snd_usb_find_desc(alts->endpoint[1].extra, alts->endpoint[1].extralen, NULL, USB_DT_CS_ENDPOINT);
170
171 if (!csep || csep->bLength < 7 ||
172 csep->bDescriptorSubtype != UAC_EP_GENERAL) {
173 snd_printk(KERN_WARNING "%d:%u:%d : no or invalid"
174 " class specific endpoint descriptor\n",
175 chip->dev->devnum, iface_no,
176 altsd->bAlternateSetting);
177 return 0;
178 }
179
180 if (protocol == UAC_VERSION_1) {
181 attributes = csep->bmAttributes;
182 } else {
183 struct uac2_iso_endpoint_descriptor *csep2 =
184 (struct uac2_iso_endpoint_descriptor *) csep;
185
186 attributes = csep->bmAttributes & UAC_EP_CS_ATTR_FILL_MAX;
187
188 /* emulate the endpoint attributes of a v1 device */
189 if (csep2->bmControls & UAC2_CONTROL_PITCH)
190 attributes |= UAC_EP_CS_ATTR_PITCH_CONTROL;
191 }
192
193 return attributes;
194}
195
196static struct uac2_input_terminal_descriptor *
197 snd_usb_find_input_terminal_descriptor(struct usb_host_interface *ctrl_iface,
198 int terminal_id)
199{
200 struct uac2_input_terminal_descriptor *term = NULL;
201
202 while ((term = snd_usb_find_csint_desc(ctrl_iface->extra,
203 ctrl_iface->extralen,
204 term, UAC_INPUT_TERMINAL))) {
205 if (term->bTerminalID == terminal_id)
206 return term;
207 }
208
209 return NULL;
210}
211
212static struct uac2_output_terminal_descriptor *
213 snd_usb_find_output_terminal_descriptor(struct usb_host_interface *ctrl_iface,
214 int terminal_id)
215{
216 struct uac2_output_terminal_descriptor *term = NULL;
217
218 while ((term = snd_usb_find_csint_desc(ctrl_iface->extra,
219 ctrl_iface->extralen,
220 term, UAC_OUTPUT_TERMINAL))) {
221 if (term->bTerminalID == terminal_id)
222 return term;
223 }
224
225 return NULL;
226}
227
228int snd_usb_parse_audio_interface(struct snd_usb_audio *chip, int iface_no)
229{
230 struct usb_device *dev;
231 struct usb_interface *iface;
232 struct usb_host_interface *alts;
233 struct usb_interface_descriptor *altsd;
234 int i, altno, err, stream;
235 int format = 0, num_channels = 0;
236 struct audioformat *fp = NULL;
237 int num, protocol, clock = 0;
238 struct uac_format_type_i_continuous_descriptor *fmt;
239
240 dev = chip->dev;
241
242 /* parse the interface's altsettings */
243 iface = usb_ifnum_to_if(dev, iface_no);
244
245 num = iface->num_altsetting;
246
247 /*
248 * Dallas DS4201 workaround: It presents 5 altsettings, but the last
249 * one misses syncpipe, and does not produce any sound.
250 */
251 if (chip->usb_id == USB_ID(0x04fa, 0x4201))
252 num = 4;
253
254 for (i = 0; i < num; i++) {
255 alts = &iface->altsetting[i];
256 altsd = get_iface_desc(alts);
257 protocol = altsd->bInterfaceProtocol;
258 /* skip invalid one */
259 if ((altsd->bInterfaceClass != USB_CLASS_AUDIO &&
260 altsd->bInterfaceClass != USB_CLASS_VENDOR_SPEC) ||
261 (altsd->bInterfaceSubClass != USB_SUBCLASS_AUDIOSTREAMING &&
262 altsd->bInterfaceSubClass != USB_SUBCLASS_VENDOR_SPEC) ||
263 altsd->bNumEndpoints < 1 ||
264 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) == 0)
265 continue;
266 /* must be isochronous */
267 if ((get_endpoint(alts, 0)->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) !=
268 USB_ENDPOINT_XFER_ISOC)
269 continue;
270 /* check direction */
271 stream = (get_endpoint(alts, 0)->bEndpointAddress & USB_DIR_IN) ?
272 SNDRV_PCM_STREAM_CAPTURE : SNDRV_PCM_STREAM_PLAYBACK;
273 altno = altsd->bAlternateSetting;
274
275 if (snd_usb_apply_interface_quirk(chip, iface_no, altno))
276 continue;
277
278 /* get audio formats */
279 switch (protocol) {
280 default:
281 snd_printdd(KERN_WARNING "%d:%u:%d: unknown interface protocol %#02x, assuming v1\n",
282 dev->devnum, iface_no, altno, protocol);
283 protocol = UAC_VERSION_1;
284 /* fall through */
285
286 case UAC_VERSION_1: {
287 struct uac1_as_header_descriptor *as =
288 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
289
290 if (!as) {
291 snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
292 dev->devnum, iface_no, altno);
293 continue;
294 }
295
296 if (as->bLength < sizeof(*as)) {
297 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
298 dev->devnum, iface_no, altno);
299 continue;
300 }
301
302 format = le16_to_cpu(as->wFormatTag); /* remember the format value */
303 break;
304 }
305
306 case UAC_VERSION_2: {
307 struct uac2_input_terminal_descriptor *input_term;
308 struct uac2_output_terminal_descriptor *output_term;
309 struct uac2_as_header_descriptor *as =
310 snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_AS_GENERAL);
311
312 if (!as) {
313 snd_printk(KERN_ERR "%d:%u:%d : UAC_AS_GENERAL descriptor not found\n",
314 dev->devnum, iface_no, altno);
315 continue;
316 }
317
318 if (as->bLength < sizeof(*as)) {
319 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_AS_GENERAL desc\n",
320 dev->devnum, iface_no, altno);
321 continue;
322 }
323
324 num_channels = as->bNrChannels;
325 format = le32_to_cpu(as->bmFormats);
326
327 /* lookup the terminal associated to this interface
328 * to extract the clock */
329 input_term = snd_usb_find_input_terminal_descriptor(chip->ctrl_intf,
330 as->bTerminalLink);
331 if (input_term) {
332 clock = input_term->bCSourceID;
333 break;
334 }
335
336 output_term = snd_usb_find_output_terminal_descriptor(chip->ctrl_intf,
337 as->bTerminalLink);
338 if (output_term) {
339 clock = output_term->bCSourceID;
340 break;
341 }
342
343 snd_printk(KERN_ERR "%d:%u:%d : bogus bTerminalLink %d\n",
344 dev->devnum, iface_no, altno, as->bTerminalLink);
345 continue;
346 }
347 }
348
349 /* get format type */
350 fmt = snd_usb_find_csint_desc(alts->extra, alts->extralen, NULL, UAC_FORMAT_TYPE);
351 if (!fmt) {
352 snd_printk(KERN_ERR "%d:%u:%d : no UAC_FORMAT_TYPE desc\n",
353 dev->devnum, iface_no, altno);
354 continue;
355 }
356 if (((protocol == UAC_VERSION_1) && (fmt->bLength < 8)) ||
357 ((protocol == UAC_VERSION_2) && (fmt->bLength < 6))) {
358 snd_printk(KERN_ERR "%d:%u:%d : invalid UAC_FORMAT_TYPE desc\n",
359 dev->devnum, iface_no, altno);
360 continue;
361 }
362
363 /*
364 * Blue Microphones workaround: The last altsetting is identical
365 * with the previous one, except for a larger packet size, but
366 * is actually a mislabeled two-channel setting; ignore it.
367 */
368 if (fmt->bNrChannels == 1 &&
369 fmt->bSubframeSize == 2 &&
370 altno == 2 && num == 3 &&
371 fp && fp->altsetting == 1 && fp->channels == 1 &&
372 fp->formats == SNDRV_PCM_FMTBIT_S16_LE &&
373 protocol == UAC_VERSION_1 &&
374 le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize) ==
375 fp->maxpacksize * 2)
376 continue;
377
378 fp = kzalloc(sizeof(*fp), GFP_KERNEL);
379 if (! fp) {
380 snd_printk(KERN_ERR "cannot malloc\n");
381 return -ENOMEM;
382 }
383
384 fp->iface = iface_no;
385 fp->altsetting = altno;
386 fp->altset_idx = i;
387 fp->endpoint = get_endpoint(alts, 0)->bEndpointAddress;
388 fp->ep_attr = get_endpoint(alts, 0)->bmAttributes;
389 fp->datainterval = snd_usb_parse_datainterval(chip, alts);
390 fp->maxpacksize = le16_to_cpu(get_endpoint(alts, 0)->wMaxPacketSize);
391 /* num_channels is only set for v2 interfaces */
392 fp->channels = num_channels;
393 if (snd_usb_get_speed(dev) == USB_SPEED_HIGH)
394 fp->maxpacksize = (((fp->maxpacksize >> 11) & 3) + 1)
395 * (fp->maxpacksize & 0x7ff);
396 fp->attributes = parse_uac_endpoint_attributes(chip, alts, protocol, iface_no);
397 fp->clock = clock;
398
399 /* some quirks for attributes here */
400
401 switch (chip->usb_id) {
402 case USB_ID(0x0a92, 0x0053): /* AudioTrak Optoplay */
403 /* Optoplay sets the sample rate attribute although
404 * it seems not supporting it in fact.
405 */
406 fp->attributes &= ~UAC_EP_CS_ATTR_SAMPLE_RATE;
407 break;
408 case USB_ID(0x041e, 0x3020): /* Creative SB Audigy 2 NX */
409 case USB_ID(0x0763, 0x2003): /* M-Audio Audiophile USB */
410 /* doesn't set the sample rate attribute, but supports it */
411 fp->attributes |= UAC_EP_CS_ATTR_SAMPLE_RATE;
412 break;
413 case USB_ID(0x0763, 0x2001): /* M-Audio Quattro USB */
414 case USB_ID(0x0763, 0x2012): /* M-Audio Fast Track Pro USB */
415 case USB_ID(0x047f, 0x0ca1): /* plantronics headset */
416 case USB_ID(0x077d, 0x07af): /* Griffin iMic (note that there is
417 an older model 77d:223) */
418 /*
419 * plantronics headset and Griffin iMic have set adaptive-in
420 * although it's really not...
421 */
422 fp->ep_attr &= ~USB_ENDPOINT_SYNCTYPE;
423 if (stream == SNDRV_PCM_STREAM_PLAYBACK)
424 fp->ep_attr |= USB_ENDPOINT_SYNC_ADAPTIVE;
425 else
426 fp->ep_attr |= USB_ENDPOINT_SYNC_SYNC;
427 break;
428 }
429
430 /* ok, let's parse further... */
431 if (snd_usb_parse_audio_format(chip, fp, format, fmt, stream, alts) < 0) {
432 kfree(fp->rate_table);
433 kfree(fp);
434 fp = NULL;
435 continue;
436 }
437
438 snd_printdd(KERN_INFO "%d:%u:%d: add audio endpoint %#x\n", dev->devnum, iface_no, altno, fp->endpoint);
439 err = snd_usb_add_audio_stream(chip, stream, fp);
440 if (err < 0) {
441 kfree(fp->rate_table);
442 kfree(fp);
443 return err;
444 }
445 /* try to set the interface... */
446 usb_set_interface(chip->dev, iface_no, altno);
447 snd_usb_init_pitch(chip, iface_no, alts, fp);
448 snd_usb_init_sample_rate(chip, iface_no, alts, fp, fp->rate_max);
449 }
450 return 0;
451}
452
diff --git a/sound/usb/stream.h b/sound/usb/stream.h
new file mode 100644
index 000000000000..c97f679fc84f
--- /dev/null
+++ b/sound/usb/stream.h
@@ -0,0 +1,12 @@
1#ifndef __USBAUDIO_STREAM_H
2#define __USBAUDIO_STREAM_H
3
4int snd_usb_parse_audio_interface(struct snd_usb_audio *chip,
5 int iface_no);
6
7int snd_usb_add_audio_stream(struct snd_usb_audio *chip,
8 int stream,
9 struct audioformat *fp);
10
11#endif /* __USBAUDIO_STREAM_H */
12
diff --git a/sound/usb/urb.c b/sound/usb/urb.c
deleted file mode 100644
index e184349aee83..000000000000
--- a/sound/usb/urb.c
+++ /dev/null
@@ -1,941 +0,0 @@
1/*
2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or
5 * (at your option) any later version.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
15 *
16 */
17
18#include <linux/gfp.h>
19#include <linux/init.h>
20#include <linux/usb.h>
21#include <linux/usb/audio.h>
22
23#include <sound/core.h>
24#include <sound/pcm.h>
25
26#include "usbaudio.h"
27#include "helper.h"
28#include "card.h"
29#include "urb.h"
30#include "pcm.h"
31
32/*
33 * convert a sampling rate into our full speed format (fs/1000 in Q16.16)
34 * this will overflow at approx 524 kHz
35 */
36static inline unsigned get_usb_full_speed_rate(unsigned int rate)
37{
38 return ((rate << 13) + 62) / 125;
39}
40
41/*
42 * convert a sampling rate into USB high speed format (fs/8000 in Q16.16)
43 * this will overflow at approx 4 MHz
44 */
45static inline unsigned get_usb_high_speed_rate(unsigned int rate)
46{
47 return ((rate << 10) + 62) / 125;
48}
49
50/*
51 * unlink active urbs.
52 */
53static int deactivate_urbs(struct snd_usb_substream *subs, int force, int can_sleep)
54{
55 struct snd_usb_audio *chip = subs->stream->chip;
56 unsigned int i;
57 int async;
58
59 subs->running = 0;
60
61 if (!force && subs->stream->chip->shutdown) /* to be sure... */
62 return -EBADFD;
63
64 async = !can_sleep && chip->async_unlink;
65
66 if (!async && in_interrupt())
67 return 0;
68
69 for (i = 0; i < subs->nurbs; i++) {
70 if (test_bit(i, &subs->active_mask)) {
71 if (!test_and_set_bit(i, &subs->unlink_mask)) {
72 struct urb *u = subs->dataurb[i].urb;
73 if (async)
74 usb_unlink_urb(u);
75 else
76 usb_kill_urb(u);
77 }
78 }
79 }
80 if (subs->syncpipe) {
81 for (i = 0; i < SYNC_URBS; i++) {
82 if (test_bit(i+16, &subs->active_mask)) {
83 if (!test_and_set_bit(i+16, &subs->unlink_mask)) {
84 struct urb *u = subs->syncurb[i].urb;
85 if (async)
86 usb_unlink_urb(u);
87 else
88 usb_kill_urb(u);
89 }
90 }
91 }
92 }
93 return 0;
94}
95
96
97/*
98 * release a urb data
99 */
100static void release_urb_ctx(struct snd_urb_ctx *u)
101{
102 if (u->urb) {
103 if (u->buffer_size)
104 usb_free_coherent(u->subs->dev, u->buffer_size,
105 u->urb->transfer_buffer,
106 u->urb->transfer_dma);
107 usb_free_urb(u->urb);
108 u->urb = NULL;
109 }
110}
111
112/*
113 * wait until all urbs are processed.
114 */
115static int wait_clear_urbs(struct snd_usb_substream *subs)
116{
117 unsigned long end_time = jiffies + msecs_to_jiffies(1000);
118 unsigned int i;
119 int alive;
120
121 do {
122 alive = 0;
123 for (i = 0; i < subs->nurbs; i++) {
124 if (test_bit(i, &subs->active_mask))
125 alive++;
126 }
127 if (subs->syncpipe) {
128 for (i = 0; i < SYNC_URBS; i++) {
129 if (test_bit(i + 16, &subs->active_mask))
130 alive++;
131 }
132 }
133 if (! alive)
134 break;
135 schedule_timeout_uninterruptible(1);
136 } while (time_before(jiffies, end_time));
137 if (alive)
138 snd_printk(KERN_ERR "timeout: still %d active urbs..\n", alive);
139 return 0;
140}
141
142/*
143 * release a substream
144 */
145void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force)
146{
147 int i;
148
149 /* stop urbs (to be sure) */
150 deactivate_urbs(subs, force, 1);
151 wait_clear_urbs(subs);
152
153 for (i = 0; i < MAX_URBS; i++)
154 release_urb_ctx(&subs->dataurb[i]);
155 for (i = 0; i < SYNC_URBS; i++)
156 release_urb_ctx(&subs->syncurb[i]);
157 usb_free_coherent(subs->dev, SYNC_URBS * 4,
158 subs->syncbuf, subs->sync_dma);
159 subs->syncbuf = NULL;
160 subs->nurbs = 0;
161}
162
163/*
164 * complete callback from data urb
165 */
166static void snd_complete_urb(struct urb *urb)
167{
168 struct snd_urb_ctx *ctx = urb->context;
169 struct snd_usb_substream *subs = ctx->subs;
170 struct snd_pcm_substream *substream = ctx->subs->pcm_substream;
171 int err = 0;
172
173 if ((subs->running && subs->ops.retire(subs, substream->runtime, urb)) ||
174 !subs->running || /* can be stopped during retire callback */
175 (err = subs->ops.prepare(subs, substream->runtime, urb)) < 0 ||
176 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
177 clear_bit(ctx->index, &subs->active_mask);
178 if (err < 0) {
179 snd_printd(KERN_ERR "cannot submit urb (err = %d)\n", err);
180 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
181 }
182 }
183}
184
185
186/*
187 * complete callback from sync urb
188 */
189static void snd_complete_sync_urb(struct urb *urb)
190{
191 struct snd_urb_ctx *ctx = urb->context;
192 struct snd_usb_substream *subs = ctx->subs;
193 struct snd_pcm_substream *substream = ctx->subs->pcm_substream;
194 int err = 0;
195
196 if ((subs->running && subs->ops.retire_sync(subs, substream->runtime, urb)) ||
197 !subs->running || /* can be stopped during retire callback */
198 (err = subs->ops.prepare_sync(subs, substream->runtime, urb)) < 0 ||
199 (err = usb_submit_urb(urb, GFP_ATOMIC)) < 0) {
200 clear_bit(ctx->index + 16, &subs->active_mask);
201 if (err < 0) {
202 snd_printd(KERN_ERR "cannot submit sync urb (err = %d)\n", err);
203 snd_pcm_stop(substream, SNDRV_PCM_STATE_XRUN);
204 }
205 }
206}
207
208
209/*
210 * initialize a substream for plaback/capture
211 */
212int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
213 unsigned int period_bytes,
214 unsigned int rate,
215 unsigned int frame_bits)
216{
217 unsigned int maxsize, i;
218 int is_playback = subs->direction == SNDRV_PCM_STREAM_PLAYBACK;
219 unsigned int urb_packs, total_packs, packs_per_ms;
220 struct snd_usb_audio *chip = subs->stream->chip;
221
222 /* calculate the frequency in 16.16 format */
223 if (snd_usb_get_speed(subs->dev) == USB_SPEED_FULL)
224 subs->freqn = get_usb_full_speed_rate(rate);
225 else
226 subs->freqn = get_usb_high_speed_rate(rate);
227 subs->freqm = subs->freqn;
228 subs->freqshift = INT_MIN;
229 /* calculate max. frequency */
230 if (subs->maxpacksize) {
231 /* whatever fits into a max. size packet */
232 maxsize = subs->maxpacksize;
233 subs->freqmax = (maxsize / (frame_bits >> 3))
234 << (16 - subs->datainterval);
235 } else {
236 /* no max. packet size: just take 25% higher than nominal */
237 subs->freqmax = subs->freqn + (subs->freqn >> 2);
238 maxsize = ((subs->freqmax + 0xffff) * (frame_bits >> 3))
239 >> (16 - subs->datainterval);
240 }
241 subs->phase = 0;
242
243 if (subs->fill_max)
244 subs->curpacksize = subs->maxpacksize;
245 else
246 subs->curpacksize = maxsize;
247
248 if (snd_usb_get_speed(subs->dev) != USB_SPEED_FULL)
249 packs_per_ms = 8 >> subs->datainterval;
250 else
251 packs_per_ms = 1;
252
253 if (is_playback) {
254 urb_packs = max(chip->nrpacks, 1);
255 urb_packs = min(urb_packs, (unsigned int)MAX_PACKS);
256 } else
257 urb_packs = 1;
258 urb_packs *= packs_per_ms;
259 if (subs->syncpipe)
260 urb_packs = min(urb_packs, 1U << subs->syncinterval);
261
262 /* decide how many packets to be used */
263 if (is_playback) {
264 unsigned int minsize, maxpacks;
265 /* determine how small a packet can be */
266 minsize = (subs->freqn >> (16 - subs->datainterval))
267 * (frame_bits >> 3);
268 /* with sync from device, assume it can be 12% lower */
269 if (subs->syncpipe)
270 minsize -= minsize >> 3;
271 minsize = max(minsize, 1u);
272 total_packs = (period_bytes + minsize - 1) / minsize;
273 /* we need at least two URBs for queueing */
274 if (total_packs < 2) {
275 total_packs = 2;
276 } else {
277 /* and we don't want too long a queue either */
278 maxpacks = max(MAX_QUEUE * packs_per_ms, urb_packs * 2);
279 total_packs = min(total_packs, maxpacks);
280 }
281 } else {
282 while (urb_packs > 1 && urb_packs * maxsize >= period_bytes)
283 urb_packs >>= 1;
284 total_packs = MAX_URBS * urb_packs;
285 }
286 subs->nurbs = (total_packs + urb_packs - 1) / urb_packs;
287 if (subs->nurbs > MAX_URBS) {
288 /* too much... */
289 subs->nurbs = MAX_URBS;
290 total_packs = MAX_URBS * urb_packs;
291 } else if (subs->nurbs < 2) {
292 /* too little - we need at least two packets
293 * to ensure contiguous playback/capture
294 */
295 subs->nurbs = 2;
296 }
297
298 /* allocate and initialize data urbs */
299 for (i = 0; i < subs->nurbs; i++) {
300 struct snd_urb_ctx *u = &subs->dataurb[i];
301 u->index = i;
302 u->subs = subs;
303 u->packets = (i + 1) * total_packs / subs->nurbs
304 - i * total_packs / subs->nurbs;
305 u->buffer_size = maxsize * u->packets;
306 if (subs->fmt_type == UAC_FORMAT_TYPE_II)
307 u->packets++; /* for transfer delimiter */
308 u->urb = usb_alloc_urb(u->packets, GFP_KERNEL);
309 if (!u->urb)
310 goto out_of_memory;
311 u->urb->transfer_buffer =
312 usb_alloc_coherent(subs->dev, u->buffer_size,
313 GFP_KERNEL, &u->urb->transfer_dma);
314 if (!u->urb->transfer_buffer)
315 goto out_of_memory;
316 u->urb->pipe = subs->datapipe;
317 u->urb->transfer_flags = URB_ISO_ASAP | URB_NO_TRANSFER_DMA_MAP;
318 u->urb->interval = 1 << subs->datainterval;
319 u->urb->context = u;
320 u->urb->complete = snd_complete_urb;
321 }
322
323 if (subs->syncpipe) {
324 /* allocate and initialize sync urbs */
325 subs->syncbuf = usb_alloc_coherent(subs->dev, SYNC_URBS * 4,
326 GFP_KERNEL, &subs->sync_dma);
327 if (!subs->syncbuf)
328 goto out_of_memory;
329 for (i = 0; i < SYNC_URBS; i++) {
330 struct snd_urb_ctx *u = &subs->syncurb[i];
331 u->index = i;
332 u->subs = subs;
333 u->packets = 1;
334 u->urb = usb_alloc_urb(1, GFP_KERNEL);
335 if (!u->urb)
336 goto out_of_memory;
337 u->urb->transfer_buffer = subs->syncbuf + i * 4;
338 u->urb->transfer_dma = subs->sync_dma + i * 4;
339 u->urb->transfer_buffer_length = 4;
340 u->urb->pipe = subs->syncpipe;
341 u->urb->transfer_flags = URB_ISO_ASAP |
342 URB_NO_TRANSFER_DMA_MAP;
343 u->urb->number_of_packets = 1;
344 u->urb->interval = 1 << subs->syncinterval;
345 u->urb->context = u;
346 u->urb->complete = snd_complete_sync_urb;
347 }
348 }
349 return 0;
350
351out_of_memory:
352 snd_usb_release_substream_urbs(subs, 0);
353 return -ENOMEM;
354}
355
356/*
357 * prepare urb for full speed capture sync pipe
358 *
359 * fill the length and offset of each urb descriptor.
360 * the fixed 10.14 frequency is passed through the pipe.
361 */
362static int prepare_capture_sync_urb(struct snd_usb_substream *subs,
363 struct snd_pcm_runtime *runtime,
364 struct urb *urb)
365{
366 unsigned char *cp = urb->transfer_buffer;
367 struct snd_urb_ctx *ctx = urb->context;
368
369 urb->dev = ctx->subs->dev; /* we need to set this at each time */
370 urb->iso_frame_desc[0].length = 3;
371 urb->iso_frame_desc[0].offset = 0;
372 cp[0] = subs->freqn >> 2;
373 cp[1] = subs->freqn >> 10;
374 cp[2] = subs->freqn >> 18;
375 return 0;
376}
377
378/*
379 * prepare urb for high speed capture sync pipe
380 *
381 * fill the length and offset of each urb descriptor.
382 * the fixed 12.13 frequency is passed as 16.16 through the pipe.
383 */
384static int prepare_capture_sync_urb_hs(struct snd_usb_substream *subs,
385 struct snd_pcm_runtime *runtime,
386 struct urb *urb)
387{
388 unsigned char *cp = urb->transfer_buffer;
389 struct snd_urb_ctx *ctx = urb->context;
390
391 urb->dev = ctx->subs->dev; /* we need to set this at each time */
392 urb->iso_frame_desc[0].length = 4;
393 urb->iso_frame_desc[0].offset = 0;
394 cp[0] = subs->freqn;
395 cp[1] = subs->freqn >> 8;
396 cp[2] = subs->freqn >> 16;
397 cp[3] = subs->freqn >> 24;
398 return 0;
399}
400
401/*
402 * process after capture sync complete
403 * - nothing to do
404 */
405static int retire_capture_sync_urb(struct snd_usb_substream *subs,
406 struct snd_pcm_runtime *runtime,
407 struct urb *urb)
408{
409 return 0;
410}
411
412/*
413 * prepare urb for capture data pipe
414 *
415 * fill the offset and length of each descriptor.
416 *
417 * we use a temporary buffer to write the captured data.
418 * since the length of written data is determined by host, we cannot
419 * write onto the pcm buffer directly... the data is thus copied
420 * later at complete callback to the global buffer.
421 */
422static int prepare_capture_urb(struct snd_usb_substream *subs,
423 struct snd_pcm_runtime *runtime,
424 struct urb *urb)
425{
426 int i, offs;
427 struct snd_urb_ctx *ctx = urb->context;
428
429 offs = 0;
430 urb->dev = ctx->subs->dev; /* we need to set this at each time */
431 for (i = 0; i < ctx->packets; i++) {
432 urb->iso_frame_desc[i].offset = offs;
433 urb->iso_frame_desc[i].length = subs->curpacksize;
434 offs += subs->curpacksize;
435 }
436 urb->transfer_buffer_length = offs;
437 urb->number_of_packets = ctx->packets;
438 return 0;
439}
440
441/*
442 * process after capture complete
443 *
444 * copy the data from each desctiptor to the pcm buffer, and
445 * update the current position.
446 */
447static int retire_capture_urb(struct snd_usb_substream *subs,
448 struct snd_pcm_runtime *runtime,
449 struct urb *urb)
450{
451 unsigned long flags;
452 unsigned char *cp;
453 int i;
454 unsigned int stride, frames, bytes, oldptr;
455 int period_elapsed = 0;
456
457 stride = runtime->frame_bits >> 3;
458
459 for (i = 0; i < urb->number_of_packets; i++) {
460 cp = (unsigned char *)urb->transfer_buffer + urb->iso_frame_desc[i].offset;
461 if (urb->iso_frame_desc[i].status) {
462 snd_printd(KERN_ERR "frame %d active: %d\n", i, urb->iso_frame_desc[i].status);
463 // continue;
464 }
465 bytes = urb->iso_frame_desc[i].actual_length;
466 frames = bytes / stride;
467 if (!subs->txfr_quirk)
468 bytes = frames * stride;
469 if (bytes % (runtime->sample_bits >> 3) != 0) {
470#ifdef CONFIG_SND_DEBUG_VERBOSE
471 int oldbytes = bytes;
472#endif
473 bytes = frames * stride;
474 snd_printdd(KERN_ERR "Corrected urb data len. %d->%d\n",
475 oldbytes, bytes);
476 }
477 /* update the current pointer */
478 spin_lock_irqsave(&subs->lock, flags);
479 oldptr = subs->hwptr_done;
480 subs->hwptr_done += bytes;
481 if (subs->hwptr_done >= runtime->buffer_size * stride)
482 subs->hwptr_done -= runtime->buffer_size * stride;
483 frames = (bytes + (oldptr % stride)) / stride;
484 subs->transfer_done += frames;
485 if (subs->transfer_done >= runtime->period_size) {
486 subs->transfer_done -= runtime->period_size;
487 period_elapsed = 1;
488 }
489 spin_unlock_irqrestore(&subs->lock, flags);
490 /* copy a data chunk */
491 if (oldptr + bytes > runtime->buffer_size * stride) {
492 unsigned int bytes1 =
493 runtime->buffer_size * stride - oldptr;
494 memcpy(runtime->dma_area + oldptr, cp, bytes1);
495 memcpy(runtime->dma_area, cp + bytes1, bytes - bytes1);
496 } else {
497 memcpy(runtime->dma_area + oldptr, cp, bytes);
498 }
499 }
500 if (period_elapsed)
501 snd_pcm_period_elapsed(subs->pcm_substream);
502 return 0;
503}
504
505/*
506 * Process after capture complete when paused. Nothing to do.
507 */
508static int retire_paused_capture_urb(struct snd_usb_substream *subs,
509 struct snd_pcm_runtime *runtime,
510 struct urb *urb)
511{
512 return 0;
513}
514
515
516/*
517 * prepare urb for playback sync pipe
518 *
519 * set up the offset and length to receive the current frequency.
520 */
521static int prepare_playback_sync_urb(struct snd_usb_substream *subs,
522 struct snd_pcm_runtime *runtime,
523 struct urb *urb)
524{
525 struct snd_urb_ctx *ctx = urb->context;
526
527 urb->dev = ctx->subs->dev; /* we need to set this at each time */
528 urb->iso_frame_desc[0].length = min(4u, ctx->subs->syncmaxsize);
529 urb->iso_frame_desc[0].offset = 0;
530 return 0;
531}
532
533/*
534 * process after playback sync complete
535 *
536 * Full speed devices report feedback values in 10.14 format as samples per
537 * frame, high speed devices in 16.16 format as samples per microframe.
538 * Because the Audio Class 1 spec was written before USB 2.0, many high speed
539 * devices use a wrong interpretation, some others use an entirely different
540 * format. Therefore, we cannot predict what format any particular device uses
541 * and must detect it automatically.
542 */
543static int retire_playback_sync_urb(struct snd_usb_substream *subs,
544 struct snd_pcm_runtime *runtime,
545 struct urb *urb)
546{
547 unsigned int f;
548 int shift;
549 unsigned long flags;
550
551 if (urb->iso_frame_desc[0].status != 0 ||
552 urb->iso_frame_desc[0].actual_length < 3)
553 return 0;
554
555 f = le32_to_cpup(urb->transfer_buffer);
556 if (urb->iso_frame_desc[0].actual_length == 3)
557 f &= 0x00ffffff;
558 else
559 f &= 0x0fffffff;
560 if (f == 0)
561 return 0;
562
563 if (unlikely(subs->freqshift == INT_MIN)) {
564 /*
565 * The first time we see a feedback value, determine its format
566 * by shifting it left or right until it matches the nominal
567 * frequency value. This assumes that the feedback does not
568 * differ from the nominal value more than +50% or -25%.
569 */
570 shift = 0;
571 while (f < subs->freqn - subs->freqn / 4) {
572 f <<= 1;
573 shift++;
574 }
575 while (f > subs->freqn + subs->freqn / 2) {
576 f >>= 1;
577 shift--;
578 }
579 subs->freqshift = shift;
580 }
581 else if (subs->freqshift >= 0)
582 f <<= subs->freqshift;
583 else
584 f >>= -subs->freqshift;
585
586 if (likely(f >= subs->freqn - subs->freqn / 8 && f <= subs->freqmax)) {
587 /*
588 * If the frequency looks valid, set it.
589 * This value is referred to in prepare_playback_urb().
590 */
591 spin_lock_irqsave(&subs->lock, flags);
592 subs->freqm = f;
593 spin_unlock_irqrestore(&subs->lock, flags);
594 } else {
595 /*
596 * Out of range; maybe the shift value is wrong.
597 * Reset it so that we autodetect again the next time.
598 */
599 subs->freqshift = INT_MIN;
600 }
601
602 return 0;
603}
604
605/* determine the number of frames in the next packet */
606static int snd_usb_audio_next_packet_size(struct snd_usb_substream *subs)
607{
608 if (subs->fill_max)
609 return subs->maxframesize;
610 else {
611 subs->phase = (subs->phase & 0xffff)
612 + (subs->freqm << subs->datainterval);
613 return min(subs->phase >> 16, subs->maxframesize);
614 }
615}
616
617/*
618 * Prepare urb for streaming before playback starts or when paused.
619 *
620 * We don't have any data, so we send silence.
621 */
622static int prepare_nodata_playback_urb(struct snd_usb_substream *subs,
623 struct snd_pcm_runtime *runtime,
624 struct urb *urb)
625{
626 unsigned int i, offs, counts;
627 struct snd_urb_ctx *ctx = urb->context;
628 int stride = runtime->frame_bits >> 3;
629
630 offs = 0;
631 urb->dev = ctx->subs->dev;
632 for (i = 0; i < ctx->packets; ++i) {
633 counts = snd_usb_audio_next_packet_size(subs);
634 urb->iso_frame_desc[i].offset = offs * stride;
635 urb->iso_frame_desc[i].length = counts * stride;
636 offs += counts;
637 }
638 urb->number_of_packets = ctx->packets;
639 urb->transfer_buffer_length = offs * stride;
640 memset(urb->transfer_buffer,
641 runtime->format == SNDRV_PCM_FORMAT_U8 ? 0x80 : 0,
642 offs * stride);
643 return 0;
644}
645
646/*
647 * prepare urb for playback data pipe
648 *
649 * Since a URB can handle only a single linear buffer, we must use double
650 * buffering when the data to be transferred overflows the buffer boundary.
651 * To avoid inconsistencies when updating hwptr_done, we use double buffering
652 * for all URBs.
653 */
654static int prepare_playback_urb(struct snd_usb_substream *subs,
655 struct snd_pcm_runtime *runtime,
656 struct urb *urb)
657{
658 int i, stride;
659 unsigned int counts, frames, bytes;
660 unsigned long flags;
661 int period_elapsed = 0;
662 struct snd_urb_ctx *ctx = urb->context;
663
664 stride = runtime->frame_bits >> 3;
665
666 frames = 0;
667 urb->dev = ctx->subs->dev; /* we need to set this at each time */
668 urb->number_of_packets = 0;
669 spin_lock_irqsave(&subs->lock, flags);
670 for (i = 0; i < ctx->packets; i++) {
671 counts = snd_usb_audio_next_packet_size(subs);
672 /* set up descriptor */
673 urb->iso_frame_desc[i].offset = frames * stride;
674 urb->iso_frame_desc[i].length = counts * stride;
675 frames += counts;
676 urb->number_of_packets++;
677 subs->transfer_done += counts;
678 if (subs->transfer_done >= runtime->period_size) {
679 subs->transfer_done -= runtime->period_size;
680 period_elapsed = 1;
681 if (subs->fmt_type == UAC_FORMAT_TYPE_II) {
682 if (subs->transfer_done > 0) {
683 /* FIXME: fill-max mode is not
684 * supported yet */
685 frames -= subs->transfer_done;
686 counts -= subs->transfer_done;
687 urb->iso_frame_desc[i].length =
688 counts * stride;
689 subs->transfer_done = 0;
690 }
691 i++;
692 if (i < ctx->packets) {
693 /* add a transfer delimiter */
694 urb->iso_frame_desc[i].offset =
695 frames * stride;
696 urb->iso_frame_desc[i].length = 0;
697 urb->number_of_packets++;
698 }
699 break;
700 }
701 }
702 if (period_elapsed) /* finish at the period boundary */
703 break;
704 }
705 bytes = frames * stride;
706 if (subs->hwptr_done + bytes > runtime->buffer_size * stride) {
707 /* err, the transferred area goes over buffer boundary. */
708 unsigned int bytes1 =
709 runtime->buffer_size * stride - subs->hwptr_done;
710 memcpy(urb->transfer_buffer,
711 runtime->dma_area + subs->hwptr_done, bytes1);
712 memcpy(urb->transfer_buffer + bytes1,
713 runtime->dma_area, bytes - bytes1);
714 } else {
715 memcpy(urb->transfer_buffer,
716 runtime->dma_area + subs->hwptr_done, bytes);
717 }
718 subs->hwptr_done += bytes;
719 if (subs->hwptr_done >= runtime->buffer_size * stride)
720 subs->hwptr_done -= runtime->buffer_size * stride;
721 runtime->delay += frames;
722 spin_unlock_irqrestore(&subs->lock, flags);
723 urb->transfer_buffer_length = bytes;
724 if (period_elapsed)
725 snd_pcm_period_elapsed(subs->pcm_substream);
726 return 0;
727}
728
729/*
730 * process after playback data complete
731 * - decrease the delay count again
732 */
733static int retire_playback_urb(struct snd_usb_substream *subs,
734 struct snd_pcm_runtime *runtime,
735 struct urb *urb)
736{
737 unsigned long flags;
738 int stride = runtime->frame_bits >> 3;
739 int processed = urb->transfer_buffer_length / stride;
740
741 spin_lock_irqsave(&subs->lock, flags);
742 if (processed > runtime->delay)
743 runtime->delay = 0;
744 else
745 runtime->delay -= processed;
746 spin_unlock_irqrestore(&subs->lock, flags);
747 return 0;
748}
749
750static const char *usb_error_string(int err)
751{
752 switch (err) {
753 case -ENODEV:
754 return "no device";
755 case -ENOENT:
756 return "endpoint not enabled";
757 case -EPIPE:
758 return "endpoint stalled";
759 case -ENOSPC:
760 return "not enough bandwidth";
761 case -ESHUTDOWN:
762 return "device disabled";
763 case -EHOSTUNREACH:
764 return "device suspended";
765 case -EINVAL:
766 case -EAGAIN:
767 case -EFBIG:
768 case -EMSGSIZE:
769 return "internal error";
770 default:
771 return "unknown error";
772 }
773}
774
775/*
776 * set up and start data/sync urbs
777 */
778static int start_urbs(struct snd_usb_substream *subs, struct snd_pcm_runtime *runtime)
779{
780 unsigned int i;
781 int err;
782
783 if (subs->stream->chip->shutdown)
784 return -EBADFD;
785
786 for (i = 0; i < subs->nurbs; i++) {
787 if (snd_BUG_ON(!subs->dataurb[i].urb))
788 return -EINVAL;
789 if (subs->ops.prepare(subs, runtime, subs->dataurb[i].urb) < 0) {
790 snd_printk(KERN_ERR "cannot prepare datapipe for urb %d\n", i);
791 goto __error;
792 }
793 }
794 if (subs->syncpipe) {
795 for (i = 0; i < SYNC_URBS; i++) {
796 if (snd_BUG_ON(!subs->syncurb[i].urb))
797 return -EINVAL;
798 if (subs->ops.prepare_sync(subs, runtime, subs->syncurb[i].urb) < 0) {
799 snd_printk(KERN_ERR "cannot prepare syncpipe for urb %d\n", i);
800 goto __error;
801 }
802 }
803 }
804
805 subs->active_mask = 0;
806 subs->unlink_mask = 0;
807 subs->running = 1;
808 for (i = 0; i < subs->nurbs; i++) {
809 err = usb_submit_urb(subs->dataurb[i].urb, GFP_ATOMIC);
810 if (err < 0) {
811 snd_printk(KERN_ERR "cannot submit datapipe "
812 "for urb %d, error %d: %s\n",
813 i, err, usb_error_string(err));
814 goto __error;
815 }
816 set_bit(i, &subs->active_mask);
817 }
818 if (subs->syncpipe) {
819 for (i = 0; i < SYNC_URBS; i++) {
820 err = usb_submit_urb(subs->syncurb[i].urb, GFP_ATOMIC);
821 if (err < 0) {
822 snd_printk(KERN_ERR "cannot submit syncpipe "
823 "for urb %d, error %d: %s\n",
824 i, err, usb_error_string(err));
825 goto __error;
826 }
827 set_bit(i + 16, &subs->active_mask);
828 }
829 }
830 return 0;
831
832 __error:
833 // snd_pcm_stop(subs->pcm_substream, SNDRV_PCM_STATE_XRUN);
834 deactivate_urbs(subs, 0, 0);
835 return -EPIPE;
836}
837
838
839/*
840 */
841static struct snd_urb_ops audio_urb_ops[2] = {
842 {
843 .prepare = prepare_nodata_playback_urb,
844 .retire = retire_playback_urb,
845 .prepare_sync = prepare_playback_sync_urb,
846 .retire_sync = retire_playback_sync_urb,
847 },
848 {
849 .prepare = prepare_capture_urb,
850 .retire = retire_capture_urb,
851 .prepare_sync = prepare_capture_sync_urb,
852 .retire_sync = retire_capture_sync_urb,
853 },
854};
855
856/*
857 * initialize the substream instance.
858 */
859
860void snd_usb_init_substream(struct snd_usb_stream *as,
861 int stream, struct audioformat *fp)
862{
863 struct snd_usb_substream *subs = &as->substream[stream];
864
865 INIT_LIST_HEAD(&subs->fmt_list);
866 spin_lock_init(&subs->lock);
867
868 subs->stream = as;
869 subs->direction = stream;
870 subs->dev = as->chip->dev;
871 subs->txfr_quirk = as->chip->txfr_quirk;
872 subs->ops = audio_urb_ops[stream];
873 if (snd_usb_get_speed(subs->dev) >= USB_SPEED_HIGH)
874 subs->ops.prepare_sync = prepare_capture_sync_urb_hs;
875
876 snd_usb_set_pcm_ops(as->pcm, stream);
877
878 list_add_tail(&fp->list, &subs->fmt_list);
879 subs->formats |= fp->formats;
880 subs->endpoint = fp->endpoint;
881 subs->num_formats++;
882 subs->fmt_type = fp->fmt_type;
883}
884
885int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd)
886{
887 struct snd_usb_substream *subs = substream->runtime->private_data;
888
889 switch (cmd) {
890 case SNDRV_PCM_TRIGGER_START:
891 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
892 subs->ops.prepare = prepare_playback_urb;
893 return 0;
894 case SNDRV_PCM_TRIGGER_STOP:
895 return deactivate_urbs(subs, 0, 0);
896 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
897 subs->ops.prepare = prepare_nodata_playback_urb;
898 return 0;
899 }
900
901 return -EINVAL;
902}
903
904int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd)
905{
906 struct snd_usb_substream *subs = substream->runtime->private_data;
907
908 switch (cmd) {
909 case SNDRV_PCM_TRIGGER_START:
910 subs->ops.retire = retire_capture_urb;
911 return start_urbs(subs, substream->runtime);
912 case SNDRV_PCM_TRIGGER_STOP:
913 return deactivate_urbs(subs, 0, 0);
914 case SNDRV_PCM_TRIGGER_PAUSE_PUSH:
915 subs->ops.retire = retire_paused_capture_urb;
916 return 0;
917 case SNDRV_PCM_TRIGGER_PAUSE_RELEASE:
918 subs->ops.retire = retire_capture_urb;
919 return 0;
920 }
921
922 return -EINVAL;
923}
924
925int snd_usb_substream_prepare(struct snd_usb_substream *subs,
926 struct snd_pcm_runtime *runtime)
927{
928 /* clear urbs (to be sure) */
929 deactivate_urbs(subs, 0, 1);
930 wait_clear_urbs(subs);
931
932 /* for playback, submit the URBs now; otherwise, the first hwptr_done
933 * updates for all URBs would happen at the same time when starting */
934 if (subs->direction == SNDRV_PCM_STREAM_PLAYBACK) {
935 subs->ops.prepare = prepare_nodata_playback_urb;
936 return start_urbs(subs, runtime);
937 }
938
939 return 0;
940}
941
diff --git a/sound/usb/urb.h b/sound/usb/urb.h
deleted file mode 100644
index 888da38079cf..000000000000
--- a/sound/usb/urb.h
+++ /dev/null
@@ -1,21 +0,0 @@
1#ifndef __USBAUDIO_URB_H
2#define __USBAUDIO_URB_H
3
4void snd_usb_init_substream(struct snd_usb_stream *as,
5 int stream,
6 struct audioformat *fp);
7
8int snd_usb_init_substream_urbs(struct snd_usb_substream *subs,
9 unsigned int period_bytes,
10 unsigned int rate,
11 unsigned int frame_bits);
12
13void snd_usb_release_substream_urbs(struct snd_usb_substream *subs, int force);
14
15int snd_usb_substream_prepare(struct snd_usb_substream *subs,
16 struct snd_pcm_runtime *runtime);
17
18int snd_usb_substream_playback_trigger(struct snd_pcm_substream *substream, int cmd);
19int snd_usb_substream_capture_trigger(struct snd_pcm_substream *substream, int cmd);
20
21#endif /* __USBAUDIO_URB_H */
diff --git a/sound/usb/usbaudio.h b/sound/usb/usbaudio.h
index 1e79986b5777..3e2b03577936 100644
--- a/sound/usb/usbaudio.h
+++ b/sound/usb/usbaudio.h
@@ -80,6 +80,7 @@ enum quirk_type {
80 QUIRK_MIDI_CME, 80 QUIRK_MIDI_CME,
81 QUIRK_MIDI_AKAI, 81 QUIRK_MIDI_AKAI,
82 QUIRK_MIDI_US122L, 82 QUIRK_MIDI_US122L,
83 QUIRK_MIDI_FTDI,
83 QUIRK_AUDIO_STANDARD_INTERFACE, 84 QUIRK_AUDIO_STANDARD_INTERFACE,
84 QUIRK_AUDIO_FIXED_ENDPOINT, 85 QUIRK_AUDIO_FIXED_ENDPOINT,
85 QUIRK_AUDIO_EDIROL_UAXX, 86 QUIRK_AUDIO_EDIROL_UAXX,